]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
authorLinus Torvalds <torvalds@woody.linux-foundation.org>
Thu, 8 Feb 2007 03:22:26 +0000 (19:22 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Thu, 8 Feb 2007 03:22:26 +0000 (19:22 -0800)
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6: (28 commits)
  sysfs: Shadow directory support
  Driver Core: Increase the default timeout value of the firmware subsystem
  Driver core: allow to delay the uevent at device creation time
  Driver core: add device_type to struct device
  Driver core: add uevent vars for devices of a class
  SYSFS: Fix missing include of list.h in sysfs.h
  HOWTO: Add a reference to Harbison and Steele
  sysfs: error handling in sysfs, fill_read_buffer()
  kobject: kobject_put cleanup
  sysfs: kobject_put cleanup
  sysfs: suppress lockdep warnings
  Driver core: fix race in sysfs between sysfs_remove_file() and read()/write()
  driver core: Change function call order in device_bind_driver().
  driver core: Don't stop probing on ->probe errors.
  driver core fixes: device_register() retval check in platform.c
  driver core fixes: make_class_name() retval checks
  /sys/modules/*/holders
  USB: add the sysfs driver name to all modules
  SERIO: add the sysfs driver name to all modules
  PCI: add the sysfs driver name to all modules
  ...

345 files changed:
Documentation/feature-removal-schedule.txt
Documentation/video-output.txt [new file with mode: 0644]
MAINTAINERS
arch/i386/defconfig
arch/i386/kernel/acpi/boot.c
arch/i386/kernel/acpi/earlyquirk.c
arch/i386/kernel/cpu/cpufreq/longhaul.c
arch/i386/kernel/mpparse.c
arch/i386/kernel/srat.c
arch/i386/mach-es7000/es7000.h
arch/i386/mach-es7000/es7000plat.c
arch/i386/pci/mmconfig.c
arch/ia64/kernel/acpi.c
arch/ia64/sn/kernel/io_acpi_init.c
arch/ia64/sn/kernel/io_common.c
arch/ia64/sn/kernel/io_init.c
arch/ia64/sn/kernel/iomv.c
arch/ia64/sn/pci/pcibr/pcibr_provider.c
arch/x86_64/kernel/early-quirks.c
arch/x86_64/kernel/genapic.c
arch/x86_64/kernel/mpparse.c
arch/x86_64/kernel/time.c
arch/x86_64/mm/srat.c
arch/x86_64/pci/mmconfig.c
drivers/acpi/Kconfig
drivers/acpi/Makefile
drivers/acpi/asus_acpi.c
drivers/acpi/battery.c
drivers/acpi/bay.c [new file with mode: 0644]
drivers/acpi/blacklist.c
drivers/acpi/bus.c
drivers/acpi/button.c
drivers/acpi/container.c
drivers/acpi/debug.c
drivers/acpi/dispatcher/dsfield.c
drivers/acpi/dispatcher/dsinit.c
drivers/acpi/dispatcher/dsmethod.c
drivers/acpi/dispatcher/dsmthdat.c
drivers/acpi/dispatcher/dsobject.c
drivers/acpi/dispatcher/dsopcode.c
drivers/acpi/dispatcher/dsutils.c
drivers/acpi/dispatcher/dswexec.c
drivers/acpi/dispatcher/dswload.c
drivers/acpi/dispatcher/dswscope.c
drivers/acpi/dispatcher/dswstate.c
drivers/acpi/dock.c
drivers/acpi/ec.c
drivers/acpi/events/evevent.c
drivers/acpi/events/evgpe.c
drivers/acpi/events/evgpeblk.c
drivers/acpi/events/evmisc.c
drivers/acpi/events/evregion.c
drivers/acpi/events/evrgnini.c
drivers/acpi/events/evsci.c
drivers/acpi/events/evxface.c
drivers/acpi/events/evxfevnt.c
drivers/acpi/events/evxfregn.c
drivers/acpi/executer/exconfig.c
drivers/acpi/executer/exconvrt.c
drivers/acpi/executer/excreate.c
drivers/acpi/executer/exdump.c
drivers/acpi/executer/exfield.c
drivers/acpi/executer/exfldio.c
drivers/acpi/executer/exmisc.c
drivers/acpi/executer/exmutex.c
drivers/acpi/executer/exnames.c
drivers/acpi/executer/exoparg1.c
drivers/acpi/executer/exoparg2.c
drivers/acpi/executer/exoparg3.c
drivers/acpi/executer/exoparg6.c
drivers/acpi/executer/exprep.c
drivers/acpi/executer/exregion.c
drivers/acpi/executer/exresnte.c
drivers/acpi/executer/exresolv.c
drivers/acpi/executer/exresop.c
drivers/acpi/executer/exstore.c
drivers/acpi/executer/exstoren.c
drivers/acpi/executer/exstorob.c
drivers/acpi/executer/exsystem.c
drivers/acpi/executer/exutils.c
drivers/acpi/fan.c
drivers/acpi/glue.c
drivers/acpi/hardware/hwacpi.c
drivers/acpi/hardware/hwgpe.c
drivers/acpi/hardware/hwregs.c
drivers/acpi/hardware/hwsleep.c
drivers/acpi/hardware/hwtimer.c
drivers/acpi/motherboard.c [deleted file]
drivers/acpi/namespace/nsaccess.c
drivers/acpi/namespace/nsalloc.c
drivers/acpi/namespace/nsdump.c
drivers/acpi/namespace/nsdumpdv.c
drivers/acpi/namespace/nseval.c
drivers/acpi/namespace/nsinit.c
drivers/acpi/namespace/nsload.c
drivers/acpi/namespace/nsnames.c
drivers/acpi/namespace/nsobject.c
drivers/acpi/namespace/nsparse.c
drivers/acpi/namespace/nssearch.c
drivers/acpi/namespace/nsutils.c
drivers/acpi/namespace/nswalk.c
drivers/acpi/namespace/nsxfeval.c
drivers/acpi/namespace/nsxfname.c
drivers/acpi/namespace/nsxfobj.c
drivers/acpi/numa.c
drivers/acpi/osl.c
drivers/acpi/parser/psargs.c
drivers/acpi/parser/psloop.c
drivers/acpi/parser/psopcode.c
drivers/acpi/parser/psparse.c
drivers/acpi/parser/psscope.c
drivers/acpi/parser/pstree.c
drivers/acpi/parser/psutils.c
drivers/acpi/parser/pswalk.c
drivers/acpi/parser/psxface.c
drivers/acpi/pci_link.c
drivers/acpi/pci_root.c
drivers/acpi/processor_core.c
drivers/acpi/processor_idle.c
drivers/acpi/processor_perflib.c
drivers/acpi/processor_throttling.c
drivers/acpi/resources/rsaddr.c
drivers/acpi/resources/rscalc.c
drivers/acpi/resources/rscreate.c
drivers/acpi/resources/rsdump.c
drivers/acpi/resources/rsinfo.c
drivers/acpi/resources/rsio.c
drivers/acpi/resources/rsirq.c
drivers/acpi/resources/rslist.c
drivers/acpi/resources/rsmemory.c
drivers/acpi/resources/rsmisc.c
drivers/acpi/resources/rsutils.c
drivers/acpi/resources/rsxface.c
drivers/acpi/scan.c
drivers/acpi/sleep/proc.c
drivers/acpi/system.c
drivers/acpi/tables.c
drivers/acpi/tables/Makefile
drivers/acpi/tables/tbconvrt.c [deleted file]
drivers/acpi/tables/tbfadt.c [new file with mode: 0644]
drivers/acpi/tables/tbfind.c [new file with mode: 0644]
drivers/acpi/tables/tbget.c [deleted file]
drivers/acpi/tables/tbgetall.c [deleted file]
drivers/acpi/tables/tbinstal.c
drivers/acpi/tables/tbrsdt.c [deleted file]
drivers/acpi/tables/tbutils.c
drivers/acpi/tables/tbxface.c
drivers/acpi/tables/tbxfroot.c
drivers/acpi/thermal.c
drivers/acpi/utilities/utalloc.c
drivers/acpi/utilities/utcache.c
drivers/acpi/utilities/utcopy.c
drivers/acpi/utilities/utdebug.c
drivers/acpi/utilities/utdelete.c
drivers/acpi/utilities/uteval.c
drivers/acpi/utilities/utglobal.c
drivers/acpi/utilities/utinit.c
drivers/acpi/utilities/utmath.c
drivers/acpi/utilities/utmisc.c
drivers/acpi/utilities/utmutex.c
drivers/acpi/utilities/utobject.c
drivers/acpi/utilities/utresrc.c
drivers/acpi/utilities/utstate.c
drivers/acpi/utilities/utxface.c
drivers/acpi/video.c
drivers/char/ipmi/ipmi_si_intf.c
drivers/char/tpm/tpm_bios.c
drivers/firmware/pcdp.c
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/asus-laptop.c [new file with mode: 0644]
drivers/net/3c59x.c
drivers/net/Kconfig
drivers/net/Makefile
drivers/net/Space.c
drivers/net/amd8111e.c
drivers/net/b44.c
drivers/net/b44.h
drivers/net/bmac.c
drivers/net/bnx2.c
drivers/net/bonding/bond_main.c
drivers/net/bonding/bond_sysfs.c
drivers/net/bonding/bonding.h
drivers/net/chelsio/common.h
drivers/net/chelsio/cpl5_cmd.h
drivers/net/chelsio/cxgb2.c
drivers/net/chelsio/elmer0.h
drivers/net/chelsio/espi.c
drivers/net/chelsio/fpga_defs.h
drivers/net/chelsio/gmac.h
drivers/net/chelsio/ixf1010.c
drivers/net/chelsio/mv88e1xxx.c
drivers/net/chelsio/my3126.c
drivers/net/chelsio/pm3393.c
drivers/net/chelsio/sge.c
drivers/net/chelsio/subr.c
drivers/net/chelsio/tp.c
drivers/net/chelsio/vsc7326.c
drivers/net/chelsio/vsc7326_reg.h
drivers/net/chelsio/vsc8244.c
drivers/net/cxgb3/Makefile [new file with mode: 0644]
drivers/net/cxgb3/adapter.h [new file with mode: 0644]
drivers/net/cxgb3/ael1002.c [new file with mode: 0644]
drivers/net/cxgb3/common.h [new file with mode: 0644]
drivers/net/cxgb3/cxgb3_ctl_defs.h [new file with mode: 0644]
drivers/net/cxgb3/cxgb3_defs.h [new file with mode: 0644]
drivers/net/cxgb3/cxgb3_ioctl.h [new file with mode: 0644]
drivers/net/cxgb3/cxgb3_main.c [new file with mode: 0644]
drivers/net/cxgb3/cxgb3_offload.c [new file with mode: 0644]
drivers/net/cxgb3/cxgb3_offload.h [new file with mode: 0644]
drivers/net/cxgb3/firmware_exports.h [new file with mode: 0644]
drivers/net/cxgb3/l2t.c [new file with mode: 0644]
drivers/net/cxgb3/l2t.h [new file with mode: 0644]
drivers/net/cxgb3/mc5.c [new file with mode: 0644]
drivers/net/cxgb3/regs.h [new file with mode: 0644]
drivers/net/cxgb3/sge.c [new file with mode: 0644]
drivers/net/cxgb3/sge_defs.h [new file with mode: 0644]
drivers/net/cxgb3/t3_cpl.h [new file with mode: 0644]
drivers/net/cxgb3/t3_hw.c [new file with mode: 0644]
drivers/net/cxgb3/t3cdev.h [new file with mode: 0644]
drivers/net/cxgb3/version.h [new file with mode: 0644]
drivers/net/cxgb3/vsc8211.c [new file with mode: 0644]
drivers/net/cxgb3/xgmac.c [new file with mode: 0644]
drivers/net/declance.c
drivers/net/e1000/e1000.h
drivers/net/e1000/e1000_ethtool.c
drivers/net/e1000/e1000_main.c
drivers/net/e1000/e1000_osdep.h
drivers/net/e1000/e1000_param.c
drivers/net/forcedeth.c
drivers/net/hp100.c
drivers/net/ixgb/ixgb.h
drivers/net/ixgb/ixgb_ethtool.c
drivers/net/ixgb/ixgb_main.c
drivers/net/macb.c
drivers/net/macb.h
drivers/net/mace.c
drivers/net/macmace.c
drivers/net/macsonic.c
drivers/net/myri10ge/myri10ge.c
drivers/net/netxen/netxen_nic.h
drivers/net/netxen/netxen_nic_ethtool.c
drivers/net/netxen/netxen_nic_init.c
drivers/net/oaknet.c [deleted file]
drivers/net/pasemi_mac.c [new file with mode: 0644]
drivers/net/pasemi_mac.h [new file with mode: 0644]
drivers/net/qla3xxx.c [changed mode: 0644->0755]
drivers/net/qla3xxx.h [changed mode: 0644->0755]
drivers/net/s2io-regs.h
drivers/net/s2io.c
drivers/net/s2io.h
drivers/net/sc92031.c [new file with mode: 0644]
drivers/net/sk_mca.c [deleted file]
drivers/net/sk_mca.h [deleted file]
drivers/net/skfp/can.c [deleted file]
drivers/net/skfp/drvfbi.c
drivers/net/skfp/fplustm.c
drivers/net/skfp/smt.c
drivers/net/skge.c
drivers/net/skge.h
drivers/net/sky2.c
drivers/net/sky2.h
drivers/net/spider_net.c
drivers/net/spider_net.h
drivers/net/spider_net_ethtool.c
drivers/net/tg3.c
drivers/net/ucc_geth.c
drivers/net/wan/Kconfig
drivers/net/wan/Makefile
drivers/net/wan/hdlc.c
drivers/net/wan/pc300too.c [new file with mode: 0644]
drivers/net/wan/z85230.c
drivers/net/wireless/bcm43xx/bcm43xx.h
drivers/net/wireless/bcm43xx/bcm43xx_leds.c
drivers/net/wireless/bcm43xx/bcm43xx_main.c
drivers/net/wireless/bcm43xx/bcm43xx_radio.c
drivers/net/wireless/bcm43xx/bcm43xx_radio.h
drivers/net/wireless/ipw2200.c
drivers/net/wireless/orinoco.c
drivers/net/wireless/prism54/islpci_dev.c
drivers/net/wireless/prism54/islpci_dev.h
drivers/net/wireless/prism54/islpci_hotplug.c
drivers/net/wireless/zd1211rw/zd_chip.c
drivers/net/wireless/zd1211rw/zd_chip.h
drivers/net/wireless/zd1211rw/zd_def.h
drivers/net/wireless/zd1211rw/zd_ieee80211.h
drivers/net/wireless/zd1211rw/zd_rf.h
drivers/net/wireless/zd1211rw/zd_types.h [deleted file]
drivers/net/wireless/zd1211rw/zd_usb.c
drivers/net/wireless/zd1211rw/zd_usb.h
drivers/pci/hotplug/acpiphp_glue.c
drivers/pci/hotplug/sgi_hotplug.c
drivers/pnp/pnpacpi/Kconfig
drivers/pnp/system.c
drivers/usb/net/asix.c
drivers/usb/net/pegasus.h
drivers/video/output.c [new file with mode: 0644]
include/acpi/acconfig.h
include/acpi/acdebug.h
include/acpi/acdisasm.h
include/acpi/acdispat.h
include/acpi/acevents.h
include/acpi/acexcep.h
include/acpi/acglobal.h
include/acpi/achware.h
include/acpi/acinterp.h
include/acpi/aclocal.h
include/acpi/acmacros.h
include/acpi/acnames.h
include/acpi/acnamesp.h
include/acpi/acobject.h
include/acpi/acopcode.h
include/acpi/acoutput.h
include/acpi/acparser.h
include/acpi/acpi.h
include/acpi/acpi_bus.h
include/acpi/acpi_drivers.h
include/acpi/acpiosxf.h
include/acpi/acpixf.h
include/acpi/acresrc.h
include/acpi/acstruct.h
include/acpi/actables.h
include/acpi/actbl.h
include/acpi/actbl1.h
include/acpi/actbl2.h [deleted file]
include/acpi/actbl71.h [deleted file]
include/acpi/actypes.h
include/acpi/acutils.h
include/acpi/amlcode.h
include/acpi/amlresrc.h
include/acpi/platform/acenv.h
include/acpi/platform/acgcc.h
include/acpi/platform/aclinux.h
include/asm-i386/acpi.h
include/asm-i386/mach-es7000/mach_mpparse.h
include/asm-ia64/acpi.h
include/asm-ia64/sn/acpi.h
include/asm-ia64/sn/pcibr_provider.h
include/asm-ia64/sn/pcidev.h
include/asm-x86_64/acpi.h
include/linux/acpi.h
include/linux/pci_ids.h
include/linux/video_output.h [new file with mode: 0644]
net/ieee80211/softmac/ieee80211softmac_wx.c
scripts/Kbuild.include

index 0ba6af02cdaf9ce2b48b11767d54ad06d4ff918e..2dc5e5da8f88c69360e9f5e85b38861cd932f308 100644 (file)
@@ -274,6 +274,7 @@ Who:        Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
 
 ---------------------------
 
+<<<<<<< test:Documentation/feature-removal-schedule.txt
 What:  ACPI hotkey driver (CONFIG_ACPI_HOTKEY)
 When:  2.6.21
 Why:   hotkey.c was an attempt to consolidate multiple drivers that use
@@ -306,11 +307,18 @@ Why:      The ACPI namespace is effectively the symbol list for
        the BIOS can be extracted and disassembled with acpidump
        and iasl as documented in the pmtools package here:
        http://ftp.kernel.org/pub/linux/kernel/people/lenb/acpi/utils
-
 Who:   Len Brown <len.brown@intel.com>
 
 ---------------------------
 
+What:  ACPI procfs interface
+When:  July 2007
+Why:   After ACPI sysfs conversion, ACPI attributes will be duplicated
+       in sysfs and the ACPI procfs interface should be removed.
+Who:   Zhang Rui <rui.zhang@intel.com>
+
+---------------------------
+
 What:  /proc/acpi/button
 When:  August 2007
 Why:   /proc/acpi/button has been replaced by events to the input layer
@@ -325,3 +333,10 @@ Why:       Unmaintained for years, superceded by JFFS2 for years.
 Who:   Jeff Garzik <jeff@garzik.org>
 
 ---------------------------
+
+What:   sk98lin network driver
+When:   July 2007
+Why:    In kernel tree version of driver is unmaintained. Sk98lin driver
+       replaced by the skge driver. 
+Who:    Stephen Hemminger <shemminger@osdl.org>
+
diff --git a/Documentation/video-output.txt b/Documentation/video-output.txt
new file mode 100644 (file)
index 0000000..e517011
--- /dev/null
@@ -0,0 +1,34 @@
+
+               Video Output Switcher Control
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+               2006 luming.yu@intel.com
+
+The output sysfs class driver provides an abstract video output layer that
+can be used to hook platform specific methods to enable/disable video output
+device through common sysfs interface. For example, on my IBM ThinkPad T42
+laptop, The ACPI video driver registered its output devices and read/write
+method for 'state' with output sysfs class. The user interface under sysfs is:
+
+linux:/sys/class/video_output # tree .
+.
+|-- CRT0
+|   |-- device -> ../../../devices/pci0000:00/0000:00:01.0
+|   |-- state
+|   |-- subsystem -> ../../../class/video_output
+|   `-- uevent
+|-- DVI0
+|   |-- device -> ../../../devices/pci0000:00/0000:00:01.0
+|   |-- state
+|   |-- subsystem -> ../../../class/video_output
+|   `-- uevent
+|-- LCD0
+|   |-- device -> ../../../devices/pci0000:00/0000:00:01.0
+|   |-- state
+|   |-- subsystem -> ../../../class/video_output
+|   `-- uevent
+`-- TV0
+   |-- device -> ../../../devices/pci0000:00/0000:00:01.0
+   |-- state
+   |-- subsystem -> ../../../class/video_output
+   `-- uevent
+
index 16c0e15b5785699b9563679140c98f5760dc03b8..fe35f3ac4cd30c1bb8446071f1ec7c482cc2417e 100644 (file)
@@ -584,12 +584,30 @@ W:        http://sourceforge.net/projects/acpi4asus
 W:     http://xf.iksaif.net/acpi4asus
 S:     Maintained
 
+ASUS LAPTOP EXTRAS DRIVER
+P:     Corentin Chary
+M:     corentincj@iksaif.net
+L:     acpi4asus-user@lists.sourceforge.net
+W:     http://sourceforge.net/projects/acpi4asus
+W:     http://xf.iksaif.net/acpi4asus
+S:     Maintained
+
 ATA OVER ETHERNET DRIVER
 P:     Ed L. Cashin
 M:     ecashin@coraid.com
 W:     http://www.coraid.com/support/linux
 S:     Supported
 
+ATL1 ETHERNET DRIVER
+P:     Jay Cliburn
+M:     jcliburn@gmail.com
+P:     Chris Snook
+M:     csnook@redhat.com
+L:     atl1-devel@lists.sourceforge.net
+W:     http://sourceforge.net/projects/atl1
+W:     http://atl1.sourceforge.net
+S:     Maintained
+
 ATM
 P:     Chas Williams
 M:     chas@cmf.nrl.navy.mil
@@ -2477,6 +2495,12 @@ L:       orinoco-devel@lists.sourceforge.net
 W:     http://www.nongnu.org/orinoco/
 S:     Maintained
 
+PA SEMI ETHERNET DRIVER
+P:     Olof Johansson
+M:     olof@lixom.net
+L:     netdev@vger.kernel.org
+S:     Maintained
+
 PARALLEL PORT SUPPORT
 P:     Phil Blundell
 M:     philb@gnu.org
@@ -2646,7 +2670,7 @@ S:        Supported
 
 PRISM54 WIRELESS DRIVER
 P:     Prism54 Development Team
-M:     prism54-private@prism54.org
+M:     developers@islsm.org
 L:     netdev@vger.kernel.org
 W:     http://prism54.org
 S:     Maintained
index 5d80edfc61b7f61f36ed0183c886921c8a79ffd1..bb0c376b62b32fcc8ee934ce281676908b6fd150 100644 (file)
@@ -466,7 +466,8 @@ CONFIG_FW_LOADER=y
 #
 # Plug and Play support
 #
-# CONFIG_PNP is not set
+CONFIG_PNP=y
+CONFIG_PNPACPI=y
 
 #
 # Block devices
index cbcb2c27f48b8e796b87fc79b7f0fd3c92c5e81b..e94aff6888cab7aca553870d908aacf04526914f 100644 (file)
@@ -66,7 +66,7 @@ static inline int acpi_madt_oem_check(char *oem_id, char *oem_table_id) { return
 
 #define BAD_MADT_ENTRY(entry, end) (                                       \
                (!entry) || (unsigned long)entry + sizeof(*entry) > end ||  \
-               ((acpi_table_entry_header *)entry)->length < sizeof(*entry))
+               ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
 
 #define PREFIX                 "ACPI: "
 
@@ -79,7 +79,7 @@ int acpi_ioapic;
 int acpi_strict;
 EXPORT_SYMBOL(acpi_strict);
 
-acpi_interrupt_flags acpi_sci_flags __initdata;
+u8 acpi_sci_flags __initdata;
 int acpi_sci_override_gsi __initdata;
 int acpi_skip_timer_override __initdata;
 int acpi_use_timer_override __initdata;
@@ -92,11 +92,6 @@ static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
 #warning ACPI uses CMPXCHG, i486 and later hardware
 #endif
 
-#define MAX_MADT_ENTRIES       256
-u8 x86_acpiid_to_apicid[MAX_MADT_ENTRIES] =
-    {[0 ... MAX_MADT_ENTRIES - 1] = 0xff };
-EXPORT_SYMBOL(x86_acpiid_to_apicid);
-
 /* --------------------------------------------------------------------------
                               Boot-time Configuration
    -------------------------------------------------------------------------- */
@@ -166,30 +161,26 @@ char *__acpi_map_table(unsigned long phys, unsigned long size)
 
 #ifdef CONFIG_PCI_MMCONFIG
 /* The physical address of the MMCONFIG aperture.  Set from ACPI tables. */
-struct acpi_table_mcfg_config *pci_mmcfg_config;
+struct acpi_mcfg_allocation *pci_mmcfg_config;
 int pci_mmcfg_config_num;
 
-int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
+int __init acpi_parse_mcfg(struct acpi_table_header *header)
 {
        struct acpi_table_mcfg *mcfg;
        unsigned long i;
        int config_size;
 
-       if (!phys_addr || !size)
+       if (!header)
                return -EINVAL;
 
-       mcfg = (struct acpi_table_mcfg *)__acpi_map_table(phys_addr, size);
-       if (!mcfg) {
-               printk(KERN_WARNING PREFIX "Unable to map MCFG\n");
-               return -ENODEV;
-       }
+       mcfg = (struct acpi_table_mcfg *)header;
 
        /* how many config structures do we have */
        pci_mmcfg_config_num = 0;
-       i = size - sizeof(struct acpi_table_mcfg);
-       while (i >= sizeof(struct acpi_table_mcfg_config)) {
+       i = header->length - sizeof(struct acpi_table_mcfg);
+       while (i >= sizeof(struct acpi_mcfg_allocation)) {
                ++pci_mmcfg_config_num;
-               i -= sizeof(struct acpi_table_mcfg_config);
+               i -= sizeof(struct acpi_mcfg_allocation);
        };
        if (pci_mmcfg_config_num == 0) {
                printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
@@ -204,9 +195,9 @@ int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
                return -ENOMEM;
        }
 
-       memcpy(pci_mmcfg_config, &mcfg->config, config_size);
+       memcpy(pci_mmcfg_config, &mcfg[1], config_size);
        for (i = 0; i < pci_mmcfg_config_num; ++i) {
-               if (mcfg->config[i].base_reserved) {
+               if (pci_mmcfg_config[i].address > 0xFFFFFFFF) {
                        printk(KERN_ERR PREFIX
                               "MMCONFIG not in low 4GB of memory\n");
                        kfree(pci_mmcfg_config);
@@ -220,24 +211,24 @@ int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
 #endif                         /* CONFIG_PCI_MMCONFIG */
 
 #ifdef CONFIG_X86_LOCAL_APIC
-static int __init acpi_parse_madt(unsigned long phys_addr, unsigned long size)
+static int __init acpi_parse_madt(struct acpi_table_header *table)
 {
        struct acpi_table_madt *madt = NULL;
 
-       if (!phys_addr || !size || !cpu_has_apic)
+       if (!cpu_has_apic)
                return -EINVAL;
 
-       madt = (struct acpi_table_madt *)__acpi_map_table(phys_addr, size);
+       madt = (struct acpi_table_madt *)table;
        if (!madt) {
                printk(KERN_WARNING PREFIX "Unable to map MADT\n");
                return -ENODEV;
        }
 
-       if (madt->lapic_address) {
-               acpi_lapic_addr = (u64) madt->lapic_address;
+       if (madt->address) {
+               acpi_lapic_addr = (u64) madt->address;
 
                printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
-                      madt->lapic_address);
+                      madt->address);
        }
 
        acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
@@ -246,21 +237,17 @@ static int __init acpi_parse_madt(unsigned long phys_addr, unsigned long size)
 }
 
 static int __init
-acpi_parse_lapic(acpi_table_entry_header * header, const unsigned long end)
+acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
 {
-       struct acpi_table_lapic *processor = NULL;
+       struct acpi_madt_local_apic *processor = NULL;
 
-       processor = (struct acpi_table_lapic *)header;
+       processor = (struct acpi_madt_local_apic *)header;
 
        if (BAD_MADT_ENTRY(processor, end))
                return -EINVAL;
 
        acpi_table_print_madt_entry(header);
 
-       /* Record local apic id only when enabled */
-       if (processor->flags.enabled)
-               x86_acpiid_to_apicid[processor->acpi_id] = processor->id;
-
        /*
         * We need to register disabled CPU as well to permit
         * counting disabled CPUs. This allows us to size
@@ -269,18 +256,18 @@ acpi_parse_lapic(acpi_table_entry_header * header, const unsigned long end)
         * when we use CPU hotplug.
         */
        mp_register_lapic(processor->id,        /* APIC ID */
-                         processor->flags.enabled);    /* Enabled? */
+                         processor->lapic_flags & ACPI_MADT_ENABLED);  /* Enabled? */
 
        return 0;
 }
 
 static int __init
-acpi_parse_lapic_addr_ovr(acpi_table_entry_header * header,
+acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
                          const unsigned long end)
 {
-       struct acpi_table_lapic_addr_ovr *lapic_addr_ovr = NULL;
+       struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
 
-       lapic_addr_ovr = (struct acpi_table_lapic_addr_ovr *)header;
+       lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
 
        if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
                return -EINVAL;
@@ -291,11 +278,11 @@ acpi_parse_lapic_addr_ovr(acpi_table_entry_header * header,
 }
 
 static int __init
-acpi_parse_lapic_nmi(acpi_table_entry_header * header, const unsigned long end)
+acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
 {
-       struct acpi_table_lapic_nmi *lapic_nmi = NULL;
+       struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
 
-       lapic_nmi = (struct acpi_table_lapic_nmi *)header;
+       lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
 
        if (BAD_MADT_ENTRY(lapic_nmi, end))
                return -EINVAL;
@@ -313,11 +300,11 @@ acpi_parse_lapic_nmi(acpi_table_entry_header * header, const unsigned long end)
 #ifdef CONFIG_X86_IO_APIC
 
 static int __init
-acpi_parse_ioapic(acpi_table_entry_header * header, const unsigned long end)
+acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
 {
-       struct acpi_table_ioapic *ioapic = NULL;
+       struct acpi_madt_io_apic *ioapic = NULL;
 
-       ioapic = (struct acpi_table_ioapic *)header;
+       ioapic = (struct acpi_madt_io_apic *)header;
 
        if (BAD_MADT_ENTRY(ioapic, end))
                return -EINVAL;
@@ -342,11 +329,11 @@ static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
                polarity = 3;
 
        /* Command-line over-ride via acpi_sci= */
-       if (acpi_sci_flags.trigger)
-               trigger = acpi_sci_flags.trigger;
+       if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
+               trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
 
-       if (acpi_sci_flags.polarity)
-               polarity = acpi_sci_flags.polarity;
+       if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
+               polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
 
        /*
         * mp_config_acpi_legacy_irqs() already setup IRQs < 16
@@ -357,51 +344,52 @@ static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
 
        /*
         * stash over-ride to indicate we've been here
-        * and for later update of acpi_fadt
+        * and for later update of acpi_gbl_FADT
         */
        acpi_sci_override_gsi = gsi;
        return;
 }
 
 static int __init
-acpi_parse_int_src_ovr(acpi_table_entry_header * header,
+acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
                       const unsigned long end)
 {
-       struct acpi_table_int_src_ovr *intsrc = NULL;
+       struct acpi_madt_interrupt_override *intsrc = NULL;
 
-       intsrc = (struct acpi_table_int_src_ovr *)header;
+       intsrc = (struct acpi_madt_interrupt_override *)header;
 
        if (BAD_MADT_ENTRY(intsrc, end))
                return -EINVAL;
 
        acpi_table_print_madt_entry(header);
 
-       if (intsrc->bus_irq == acpi_fadt.sci_int) {
+       if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
                acpi_sci_ioapic_setup(intsrc->global_irq,
-                                     intsrc->flags.polarity,
-                                     intsrc->flags.trigger);
+                                     intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
+                                     (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
                return 0;
        }
 
        if (acpi_skip_timer_override &&
-           intsrc->bus_irq == 0 && intsrc->global_irq == 2) {
+           intsrc->source_irq == 0 && intsrc->global_irq == 2) {
                printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
                return 0;
        }
 
-       mp_override_legacy_irq(intsrc->bus_irq,
-                              intsrc->flags.polarity,
-                              intsrc->flags.trigger, intsrc->global_irq);
+       mp_override_legacy_irq(intsrc->source_irq,
+                               intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
+                               (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
+                               intsrc->global_irq);
 
        return 0;
 }
 
 static int __init
-acpi_parse_nmi_src(acpi_table_entry_header * header, const unsigned long end)
+acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
 {
-       struct acpi_table_nmi_src *nmi_src = NULL;
+       struct acpi_madt_nmi_source *nmi_src = NULL;
 
-       nmi_src = (struct acpi_table_nmi_src *)header;
+       nmi_src = (struct acpi_madt_nmi_source *)header;
 
        if (BAD_MADT_ENTRY(nmi_src, end))
                return -EINVAL;
@@ -417,7 +405,7 @@ acpi_parse_nmi_src(acpi_table_entry_header * header, const unsigned long end)
 
 /*
  * acpi_pic_sci_set_trigger()
- * 
+ *
  * use ELCR to set PIC-mode trigger type for SCI
  *
  * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
@@ -511,7 +499,7 @@ int acpi_map_lsapic(acpi_handle handle, int *pcpu)
 {
        struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
        union acpi_object *obj;
-       struct acpi_table_lapic *lapic;
+       struct acpi_madt_local_apic *lapic;
        cpumask_t tmp_map, new_map;
        u8 physid;
        int cpu;
@@ -529,10 +517,10 @@ int acpi_map_lsapic(acpi_handle handle, int *pcpu)
                return -EINVAL;
        }
 
-       lapic = (struct acpi_table_lapic *)obj->buffer.pointer;
+       lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
 
-       if ((lapic->header.type != ACPI_MADT_LAPIC) ||
-           (!lapic->flags.enabled)) {
+       if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
+           !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
                kfree(buffer.pointer);
                return -EINVAL;
        }
@@ -544,7 +532,7 @@ int acpi_map_lsapic(acpi_handle handle, int *pcpu)
        buffer.pointer = NULL;
 
        tmp_map = cpu_present_map;
-       mp_register_lapic(physid, lapic->flags.enabled);
+       mp_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
 
        /*
         * If mp_register_lapic successfully generates a new logical cpu
@@ -566,14 +554,6 @@ EXPORT_SYMBOL(acpi_map_lsapic);
 
 int acpi_unmap_lsapic(int cpu)
 {
-       int i;
-
-       for_each_possible_cpu(i) {
-               if (x86_acpiid_to_apicid[i] == x86_cpu_to_apicid[cpu]) {
-                       x86_acpiid_to_apicid[i] = -1;
-                       break;
-               }
-       }
        x86_cpu_to_apicid[cpu] = -1;
        cpu_clear(cpu, cpu_present_map);
        num_processors--;
@@ -619,42 +599,36 @@ acpi_scan_rsdp(unsigned long start, unsigned long length)
        return 0;
 }
 
-static int __init acpi_parse_sbf(unsigned long phys_addr, unsigned long size)
+static int __init acpi_parse_sbf(struct acpi_table_header *table)
 {
-       struct acpi_table_sbf *sb;
-
-       if (!phys_addr || !size)
-               return -EINVAL;
+       struct acpi_table_boot *sb;
 
-       sb = (struct acpi_table_sbf *)__acpi_map_table(phys_addr, size);
+       sb = (struct acpi_table_boot *)table;
        if (!sb) {
                printk(KERN_WARNING PREFIX "Unable to map SBF\n");
                return -ENODEV;
        }
 
-       sbf_port = sb->sbf_cmos;        /* Save CMOS port */
+       sbf_port = sb->cmos_index;      /* Save CMOS port */
 
        return 0;
 }
 
 #ifdef CONFIG_HPET_TIMER
 
-static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
+static int __init acpi_parse_hpet(struct acpi_table_header *table)
 {
        struct acpi_table_hpet *hpet_tbl;
        struct resource *hpet_res;
        resource_size_t res_start;
 
-       if (!phys || !size)
-               return -EINVAL;
-
-       hpet_tbl = (struct acpi_table_hpet *)__acpi_map_table(phys, size);
+       hpet_tbl = (struct acpi_table_hpet *)table;
        if (!hpet_tbl) {
                printk(KERN_WARNING PREFIX "Unable to map HPET\n");
                return -ENODEV;
        }
 
-       if (hpet_tbl->addr.space_id != ACPI_SPACE_MEM) {
+       if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
                printk(KERN_WARNING PREFIX "HPET timers must be located in "
                       "memory.\n");
                return -1;
@@ -667,29 +641,28 @@ static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
                hpet_res->name = (void *)&hpet_res[1];
                hpet_res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
                snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE,
-                        "HPET %u", hpet_tbl->number);
+                        "HPET %u", hpet_tbl->sequence);
                hpet_res->end = (1 * 1024) - 1;
        }
 
-#ifdef CONFIG_X86_64
-       vxtime.hpet_address = hpet_tbl->addr.addrl |
-           ((long)hpet_tbl->addr.addrh << 32);
+#ifdef CONFIG_X86_64
+       vxtime.hpet_address = hpet_tbl->address.address;
 
        printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
-              hpet_tbl->id, vxtime.hpet_address);
+               hpet_tbl->id, vxtime.hpet_address);
 
        res_start = vxtime.hpet_address;
-#else                          /* X86 */
+#else                          /* X86 */
        {
                extern unsigned long hpet_address;
 
-               hpet_address = hpet_tbl->addr.addrl;
+               hpet_address = hpet_tbl->address.address;
                printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
-                      hpet_tbl->id, hpet_address);
+                       hpet_tbl->id, hpet_address);
 
                res_start = hpet_address;
        }
-#endif                         /* X86 */
+#endif                         /* X86 */
 
        if (hpet_res) {
                hpet_res->start = res_start;
@@ -707,42 +680,28 @@ static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
 extern u32 pmtmr_ioport;
 #endif
 
-static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
+static int __init acpi_parse_fadt(struct acpi_table_header *table)
 {
-       struct fadt_descriptor *fadt = NULL;
-
-       fadt = (struct fadt_descriptor *)__acpi_map_table(phys, size);
-       if (!fadt) {
-               printk(KERN_WARNING PREFIX "Unable to map FADT\n");
-               return 0;
-       }
-       /* initialize sci_int early for INT_SRC_OVR MADT parsing */
-       acpi_fadt.sci_int = fadt->sci_int;
-
-       /* initialize rev and apic_phys_dest_mode for x86_64 genapic */
-       acpi_fadt.revision = fadt->revision;
-       acpi_fadt.force_apic_physical_destination_mode =
-           fadt->force_apic_physical_destination_mode;
 
 #ifdef CONFIG_X86_PM_TIMER
        /* detect the location of the ACPI PM Timer */
-       if (fadt->revision >= FADT2_REVISION_ID) {
+       if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
                /* FADT rev. 2 */
-               if (fadt->xpm_tmr_blk.address_space_id !=
+               if (acpi_gbl_FADT.xpm_timer_block.space_id !=
                    ACPI_ADR_SPACE_SYSTEM_IO)
                        return 0;
 
-               pmtmr_ioport = fadt->xpm_tmr_blk.address;
+               pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
                /*
                 * "X" fields are optional extensions to the original V1.0
                 * fields, so we must selectively expand V1.0 fields if the
                 * corresponding X field is zero.
                 */
                if (!pmtmr_ioport)
-                       pmtmr_ioport = fadt->V1_pm_tmr_blk;
+                       pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
        } else {
                /* FADT rev. 1 */
-               pmtmr_ioport = fadt->V1_pm_tmr_blk;
+               pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
        }
        if (pmtmr_ioport)
                printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
@@ -784,13 +743,13 @@ static int __init acpi_parse_madt_lapic_entries(void)
        if (!cpu_has_apic)
                return -ENODEV;
 
-       /* 
+       /*
         * Note that the LAPIC address is obtained from the MADT (32-bit value)
         * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
         */
 
        count =
-           acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR,
+           acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
                                  acpi_parse_lapic_addr_ovr, 0);
        if (count < 0) {
                printk(KERN_ERR PREFIX
@@ -800,7 +759,7 @@ static int __init acpi_parse_madt_lapic_entries(void)
 
        mp_register_lapic_address(acpi_lapic_addr);
 
-       count = acpi_table_parse_madt(ACPI_MADT_LAPIC, acpi_parse_lapic,
+       count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC, acpi_parse_lapic,
                                      MAX_APICS);
        if (!count) {
                printk(KERN_ERR PREFIX "No LAPIC entries present\n");
@@ -813,7 +772,7 @@ static int __init acpi_parse_madt_lapic_entries(void)
        }
 
        count =
-           acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0);
+           acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
        if (count < 0) {
                printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
                /* TBD: Cleanup to allow fallback to MPS */
@@ -842,7 +801,7 @@ static int __init acpi_parse_madt_ioapic_entries(void)
                return -ENODEV;
        }
 
-       if (!cpu_has_apic) 
+       if (!cpu_has_apic)
                return -ENODEV;
 
        /*
@@ -855,7 +814,7 @@ static int __init acpi_parse_madt_ioapic_entries(void)
        }
 
        count =
-           acpi_table_parse_madt(ACPI_MADT_IOAPIC, acpi_parse_ioapic,
+           acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
                                  MAX_IO_APICS);
        if (!count) {
                printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
@@ -866,7 +825,7 @@ static int __init acpi_parse_madt_ioapic_entries(void)
        }
 
        count =
-           acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr,
+           acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
                                  NR_IRQ_VECTORS);
        if (count < 0) {
                printk(KERN_ERR PREFIX
@@ -880,13 +839,13 @@ static int __init acpi_parse_madt_ioapic_entries(void)
         * pretend we got one so we can set the SCI flags.
         */
        if (!acpi_sci_override_gsi)
-               acpi_sci_ioapic_setup(acpi_fadt.sci_int, 0, 0);
+               acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
 
        /* Fill in identity legacy mapings where no override */
        mp_config_acpi_legacy_irqs();
 
        count =
-           acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src,
+           acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
                                  NR_IRQ_VECTORS);
        if (count < 0) {
                printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
@@ -908,7 +867,7 @@ static void __init acpi_process_madt(void)
 #ifdef CONFIG_X86_LOCAL_APIC
        int count, error;
 
-       count = acpi_table_parse(ACPI_APIC, acpi_parse_madt);
+       count = acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt);
        if (count >= 1) {
 
                /*
@@ -1195,7 +1154,7 @@ int __init acpi_boot_table_init(void)
        if (acpi_disabled && !acpi_ht)
                return 1;
 
-       /* 
+       /*
         * Initialize the ACPI boot-time table parser.
         */
        error = acpi_table_init();
@@ -1204,7 +1163,7 @@ int __init acpi_boot_table_init(void)
                return error;
        }
 
-       acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
+       acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
 
        /*
         * blacklist may disable ACPI entirely
@@ -1232,19 +1191,19 @@ int __init acpi_boot_init(void)
        if (acpi_disabled && !acpi_ht)
                return 1;
 
-       acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
+       acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
 
        /*
         * set sci_int and PM timer address
         */
-       acpi_table_parse(ACPI_FADT, acpi_parse_fadt);
+       acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
 
        /*
         * Process the Multiple APIC Description Table (MADT), if present
         */
        acpi_process_madt();
 
-       acpi_table_parse(ACPI_HPET, acpi_parse_hpet);
+       acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
 
        return 0;
 }
@@ -1315,13 +1274,17 @@ static int __init setup_acpi_sci(char *s)
        if (!s)
                return -EINVAL;
        if (!strcmp(s, "edge"))
-               acpi_sci_flags.trigger = 1;
+               acpi_sci_flags =  ACPI_MADT_TRIGGER_EDGE |
+                       (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
        else if (!strcmp(s, "level"))
-               acpi_sci_flags.trigger = 3;
+               acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
+                       (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
        else if (!strcmp(s, "high"))
-               acpi_sci_flags.polarity = 1;
+               acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
+                       (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
        else if (!strcmp(s, "low"))
-               acpi_sci_flags.polarity = 3;
+               acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
+                       (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
        else
                return -EINVAL;
        return 0;
index 4b60af7f91dd0c915c42f24d09976254b7c42353..bf86f7662d8b7a4c6210ff6e537502db624e27b6 100644 (file)
@@ -16,7 +16,7 @@
 
 static int nvidia_hpet_detected __initdata;
 
-static int __init nvidia_hpet_check(unsigned long phys, unsigned long size)
+static int __init nvidia_hpet_check(struct acpi_table_header *header)
 {
        nvidia_hpet_detected = 1;
        return 0;
@@ -30,7 +30,7 @@ static int __init check_bridge(int vendor, int device)
           is enabled. */
        if (!acpi_use_timer_override && vendor == PCI_VENDOR_ID_NVIDIA) {
                nvidia_hpet_detected = 0;
-               acpi_table_parse(ACPI_HPET, nvidia_hpet_check);
+               acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check);
                if (nvidia_hpet_detected == 0) {
                        acpi_skip_timer_override = 1;
                          printk(KERN_INFO "Nvidia board "
index e940e00b96c99df51836d78ef3ab54e290d59ffa..a3db9332d652eccbc9c3745b55aaf309c4eebbe7 100644 (file)
@@ -190,7 +190,7 @@ static void do_powersaver(int cx_address, unsigned int clock_ratio_index)
                /* Invoke C3 */
                inb(cx_address);
                /* Dummy op - must do something useless after P_LVL3 read */
-               t = inl(acpi_fadt.xpm_tmr_blk.address);
+               t = inl(acpi_gbl_FADT.xpm_timer_block.address);
        }
        /* Disable bus ratio bit */
        local_irq_disable();
@@ -250,8 +250,7 @@ static void longhaul_setstate(unsigned int clock_ratio_index)
                outb(3, 0x22);
        } else if ((pr != NULL) && pr->flags.bm_control) {
                /* Disable bus master arbitration */
-               acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1,
-                                 ACPI_MTX_DO_NOT_LOCK);
+               acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
        }
        switch (longhaul_version) {
 
@@ -281,8 +280,7 @@ static void longhaul_setstate(unsigned int clock_ratio_index)
        case TYPE_POWERSAVER:
                if (longhaul_flags & USE_ACPI_C3) {
                        /* Don't allow wakeup */
-                       acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0,
-                                         ACPI_MTX_DO_NOT_LOCK);
+                       acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
                        do_powersaver(cx->address, clock_ratio_index);
                } else {
                        do_powersaver(0, clock_ratio_index);
@@ -295,8 +293,7 @@ static void longhaul_setstate(unsigned int clock_ratio_index)
                outb(0, 0x22);
        } else if ((pr != NULL) && pr->flags.bm_control) {
                /* Enable bus master arbitration */
-               acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0,
-                                 ACPI_MTX_DO_NOT_LOCK);
+               acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
        }
        outb(pic2_mask,0xA1);   /* restore mask */
        outb(pic1_mask,0x21);
@@ -414,7 +411,7 @@ static int __init longhaul_get_ranges(void)
        highest_speed = calc_speed(maxmult);
        lowest_speed = calc_speed(minmult);
        dprintk ("FSB:%dMHz  Lowest speed: %s   Highest speed:%s\n", fsb,
-                print_speed(lowest_speed/1000), 
+                print_speed(lowest_speed/1000),
                 print_speed(highest_speed/1000));
 
        if (lowest_speed == highest_speed) {
@@ -498,7 +495,7 @@ static void __init longhaul_setup_voltagescaling(void)
                maxvid.mV/1000, maxvid.mV%1000,
                minvid.mV/1000, minvid.mV%1000,
                numvscales);
-       
+
        j = 0;
        while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) {
                speed = longhaul_table[j].frequency;
index 49bff3596bffd980862fcfd4480268a6b55131c1..4f5983c98669ad3ac42969c0fbc9b91ebd8e3472 100644 (file)
@@ -1057,7 +1057,7 @@ int mp_register_gsi(u32 gsi, int triggering, int polarity)
        static int              gsi_to_irq[MAX_GSI_NUM];
 
        /* Don't set up the ACPI SCI because it's already set up */
-       if (acpi_fadt.sci_int == gsi)
+       if (acpi_gbl_FADT.sci_interrupt == gsi)
                return gsi;
 
        ioapic = mp_find_ioapic(gsi);
@@ -1114,7 +1114,7 @@ int mp_register_gsi(u32 gsi, int triggering, int polarity)
                        /*
                         * Don't assign IRQ used by ACPI SCI
                         */
-                       if (gsi == acpi_fadt.sci_int)
+                       if (gsi == acpi_gbl_FADT.sci_interrupt)
                                gsi = pci_irq++;
                        gsi_to_irq[irq] = gsi;
                } else {
index f7e735c077c35df71c4ae0c2262113f3ea7a92e4..2a8713ec0f9aa7823ad0ec9a5cc53eadea4e8ecb 100644 (file)
@@ -62,19 +62,19 @@ extern void * boot_ioremap(unsigned long, unsigned long);
 /* Identify CPU proximity domains */
 static void __init parse_cpu_affinity_structure(char *p)
 {
-       struct acpi_table_processor_affinity *cpu_affinity = 
-                               (struct acpi_table_processor_affinity *) p;
+       struct acpi_srat_cpu_affinity *cpu_affinity =
+                               (struct acpi_srat_cpu_affinity *) p;
 
-       if (!cpu_affinity->flags.enabled)
+       if ((cpu_affinity->flags & ACPI_SRAT_CPU_ENABLED) == 0)
                return;         /* empty entry */
 
        /* mark this node as "seen" in node bitmap */
-       BMAP_SET(pxm_bitmap, cpu_affinity->proximity_domain);
+       BMAP_SET(pxm_bitmap, cpu_affinity->proximity_domain_lo);
 
-       apicid_to_pxm[cpu_affinity->apic_id] = cpu_affinity->proximity_domain;
+       apicid_to_pxm[cpu_affinity->apic_id] = cpu_affinity->proximity_domain_lo;
 
        printk("CPU 0x%02X in proximity domain 0x%02X\n",
-               cpu_affinity->apic_id, cpu_affinity->proximity_domain);
+               cpu_affinity->apic_id, cpu_affinity->proximity_domain_lo);
 }
 
 /*
@@ -84,28 +84,27 @@ static void __init parse_cpu_affinity_structure(char *p)
 static void __init parse_memory_affinity_structure (char *sratp)
 {
        unsigned long long paddr, size;
-       unsigned long start_pfn, end_pfn; 
+       unsigned long start_pfn, end_pfn;
        u8 pxm;
        struct node_memory_chunk_s *p, *q, *pend;
-       struct acpi_table_memory_affinity *memory_affinity =
-                       (struct acpi_table_memory_affinity *) sratp;
+       struct acpi_srat_mem_affinity *memory_affinity =
+                       (struct acpi_srat_mem_affinity *) sratp;
 
-       if (!memory_affinity->flags.enabled)
+       if ((memory_affinity->flags & ACPI_SRAT_MEM_ENABLED) == 0)
                return;         /* empty entry */
 
+       pxm = memory_affinity->proximity_domain & 0xff;
+
        /* mark this node as "seen" in node bitmap */
-       BMAP_SET(pxm_bitmap, memory_affinity->proximity_domain);
+       BMAP_SET(pxm_bitmap, pxm);
 
        /* calculate info for memory chunk structure */
-       paddr = memory_affinity->base_addr_hi;
-       paddr = (paddr << 32) | memory_affinity->base_addr_lo;
-       size = memory_affinity->length_hi;
-       size = (size << 32) | memory_affinity->length_lo;
-       
+       paddr = memory_affinity->base_address;
+       size = memory_affinity->length;
+
        start_pfn = paddr >> PAGE_SHIFT;
        end_pfn = (paddr + size) >> PAGE_SHIFT;
-       
-       pxm = memory_affinity->proximity_domain;
+
 
        if (num_memory_chunks >= MAXCHUNKS) {
                printk("Too many mem chunks in SRAT. Ignoring %lld MBytes at %llx\n",
@@ -132,8 +131,8 @@ static void __init parse_memory_affinity_structure (char *sratp)
        printk("Memory range 0x%lX to 0x%lX (type 0x%X) in proximity domain 0x%02X %s\n",
                start_pfn, end_pfn,
                memory_affinity->memory_type,
-               memory_affinity->proximity_domain,
-               (memory_affinity->flags.hot_pluggable ?
+               pxm,
+               ((memory_affinity->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) ?
                 "enabled and removable" : "enabled" ) );
 }
 
@@ -185,10 +184,10 @@ static int __init acpi20_parse_srat(struct acpi_table_srat *sratp)
        num_memory_chunks = 0;
        while (p < end) {
                switch (*p) {
-               case ACPI_SRAT_PROCESSOR_AFFINITY:
+               case ACPI_SRAT_TYPE_CPU_AFFINITY:
                        parse_cpu_affinity_structure(p);
                        break;
-               case ACPI_SRAT_MEMORY_AFFINITY:
+               case ACPI_SRAT_TYPE_MEMORY_AFFINITY:
                        parse_memory_affinity_structure(p);
                        break;
                default:
@@ -262,31 +261,30 @@ out_fail:
        return 0;
 }
 
+struct acpi_static_rsdt {
+       struct acpi_table_rsdt table;
+       u32 padding[7]; /* Allow for 7 more table entries */
+};
+
 int __init get_memcfg_from_srat(void)
 {
        struct acpi_table_header *header = NULL;
        struct acpi_table_rsdp *rsdp = NULL;
        struct acpi_table_rsdt *rsdt = NULL;
-       struct acpi_pointer *rsdp_address = NULL;
-       struct acpi_table_rsdt saved_rsdt;
+       acpi_native_uint rsdp_address = 0;
+       struct acpi_static_rsdt saved_rsdt;
        int tables = 0;
        int i = 0;
 
-       if (ACPI_FAILURE(acpi_find_root_pointer(ACPI_PHYSICAL_ADDRESSING,
-                                               rsdp_address))) {
+       rsdp_address = acpi_find_rsdp();
+       if (!rsdp_address) {
                printk("%s: System description tables not found\n",
                       __FUNCTION__);
                goto out_err;
        }
 
-       if (rsdp_address->pointer_type == ACPI_PHYSICAL_POINTER) {
-               printk("%s: assigning address to rsdp\n", __FUNCTION__);
-               rsdp = (struct acpi_table_rsdp *)
-                               (u32)rsdp_address->pointer.physical;
-       } else {
-               printk("%s: rsdp_address is not a physical pointer\n", __FUNCTION__);
-               goto out_err;
-       }
+       printk("%s: assigning address to rsdp\n", __FUNCTION__);
+       rsdp = (struct acpi_table_rsdp *)(u32)rsdp_address;
        if (!rsdp) {
                printk("%s: Didn't find ACPI root!\n", __FUNCTION__);
                goto out_err;
@@ -295,13 +293,13 @@ int __init get_memcfg_from_srat(void)
        printk(KERN_INFO "%.8s v%d [%.6s]\n", rsdp->signature, rsdp->revision,
                rsdp->oem_id);
 
-       if (strncmp(rsdp->signature, RSDP_SIG,strlen(RSDP_SIG))) {
+       if (strncmp(rsdp->signature, ACPI_SIG_RSDP,strlen(ACPI_SIG_RSDP))) {
                printk(KERN_WARNING "%s: RSDP table signature incorrect\n", __FUNCTION__);
                goto out_err;
        }
 
        rsdt = (struct acpi_table_rsdt *)
-           boot_ioremap(rsdp->rsdt_address, sizeof(struct acpi_table_rsdt));
+           boot_ioremap(rsdp->rsdt_physical_address, sizeof(struct acpi_table_rsdt));
 
        if (!rsdt) {
                printk(KERN_WARNING
@@ -310,9 +308,9 @@ int __init get_memcfg_from_srat(void)
                goto out_err;
        }
 
-       header = & rsdt->header;
+       header = &rsdt->header;
 
-       if (strncmp(header->signature, RSDT_SIG, strlen(RSDT_SIG))) {
+       if (strncmp(header->signature, ACPI_SIG_RSDT, strlen(ACPI_SIG_RSDT))) {
                printk(KERN_WARNING "ACPI: RSDT signature incorrect\n");
                goto out_err;
        }
@@ -330,9 +328,9 @@ int __init get_memcfg_from_srat(void)
 
        memcpy(&saved_rsdt, rsdt, sizeof(saved_rsdt));
 
-       if (saved_rsdt.header.length > sizeof(saved_rsdt)) {
+       if (saved_rsdt.table.header.length > sizeof(saved_rsdt)) {
                printk(KERN_WARNING "ACPI: Too big length in RSDT: %d\n",
-                      saved_rsdt.header.length);
+                      saved_rsdt.table.header.length);
                goto out_err;
        }
 
@@ -341,15 +339,15 @@ int __init get_memcfg_from_srat(void)
        for (i = 0; i < tables; i++) {
                /* Map in header, then map in full table length. */
                header = (struct acpi_table_header *)
-                       boot_ioremap(saved_rsdt.entry[i], sizeof(struct acpi_table_header));
+                       boot_ioremap(saved_rsdt.table.table_offset_entry[i], sizeof(struct acpi_table_header));
                if (!header)
                        break;
                header = (struct acpi_table_header *)
-                       boot_ioremap(saved_rsdt.entry[i], header->length);
+                       boot_ioremap(saved_rsdt.table.table_offset_entry[i], header->length);
                if (!header)
                        break;
 
-               if (strncmp((char *) &header->signature, "SRAT", 4))
+               if (strncmp((char *) &header->signature, ACPI_SIG_SRAT, 4))
                        continue;
 
                /* we've found the srat table. don't need to look at any more tables */
index 80566ca4a80a614ca9785af4f8d56e7e7782a11e..c8d5aa132fa078d9f21cd52d550432766f0e8aa6 100644 (file)
@@ -84,15 +84,6 @@ struct es7000_oem_table {
 };
 
 #ifdef CONFIG_ACPI
-struct acpi_table_sdt {
-       unsigned long pa;
-       unsigned long count;
-       struct {
-               unsigned long pa;
-               enum acpi_table_id id;
-               unsigned long size;
-       }       entry[50];
-};
 
 struct oem_table {
        struct acpi_table_header Header;
index 3d0fc853516d196eb379149dd33c58ff236b9507..9be6ceabf042fc64f8108c43c711cc1f475f96b7 100644 (file)
@@ -160,51 +160,14 @@ parse_unisys_oem (char *oemptr)
 int __init
 find_unisys_acpi_oem_table(unsigned long *oem_addr)
 {
-       struct acpi_table_rsdp          *rsdp = NULL;
-       unsigned long                   rsdp_phys = 0;
-       struct acpi_table_header        *header = NULL;
-       int                             i;
-       struct acpi_table_sdt           sdt;
-
-       rsdp_phys = acpi_find_rsdp();
-       rsdp = __va(rsdp_phys);
-       if (rsdp->rsdt_address) {
-               struct acpi_table_rsdt  *mapped_rsdt = NULL;
-               sdt.pa = rsdp->rsdt_address;
-
-               header = (struct acpi_table_header *)
-                       __acpi_map_table(sdt.pa, sizeof(struct acpi_table_header));
-               if (!header)
-                       return -ENODEV;
-
-               sdt.count = (header->length - sizeof(struct acpi_table_header)) >> 3;
-               mapped_rsdt = (struct acpi_table_rsdt *)
-                       __acpi_map_table(sdt.pa, header->length);
-               if (!mapped_rsdt)
-                       return -ENODEV;
-
-               header = &mapped_rsdt->header;
-
-               for (i = 0; i < sdt.count; i++)
-                       sdt.entry[i].pa = (unsigned long) mapped_rsdt->entry[i];
-       };
-       for (i = 0; i < sdt.count; i++) {
-
-               header = (struct acpi_table_header *)
-                       __acpi_map_table(sdt.entry[i].pa,
-                               sizeof(struct acpi_table_header));
-               if (!header)
-                       continue;
-               if (!strncmp((char *) &header->signature, "OEM1", 4)) {
-                       if (!strncmp((char *) &header->oem_id, "UNISYS", 6)) {
-                               void *addr;
-                               struct oem_table *t;
-                               acpi_table_print(header, sdt.entry[i].pa);
-                               t = (struct oem_table *) __acpi_map_table(sdt.entry[i].pa, header->length);
-                               addr = (void *) __acpi_map_table(t->OEMTableAddr, t->OEMTableSize);
-                               *oem_addr = (unsigned long) addr;
-                               return 0;
-                       }
+       struct acpi_table_header *header = NULL;
+       int i = 0;
+       while (ACPI_SUCCESS(acpi_get_table("OEM1", i++, &header))) {
+               if (!memcmp((char *) &header->oem_id, "UNISYS", 6)) {
+                       struct oem_table *t = (struct oem_table *)header;
+                       *oem_addr = (unsigned long)__acpi_map_table(t->OEMTableAddr,
+                                                                   t->OEMTableSize);
+                       return 0;
                }
        }
        return -1;
index e2616a266e13c50cea634238b2dbbb98c3cbb062..5700220dcf5fa15a4c0984128ce0c8e95735bd60 100644 (file)
@@ -36,7 +36,7 @@ static DECLARE_BITMAP(fallback_slots, MAX_CHECK_BUS*32);
 static u32 get_base_addr(unsigned int seg, int bus, unsigned devfn)
 {
        int cfg_num = -1;
-       struct acpi_table_mcfg_config *cfg;
+       struct acpi_mcfg_allocation *cfg;
 
        if (seg == 0 && bus < MAX_CHECK_BUS &&
            test_bit(PCI_SLOT(devfn) + 32*bus, fallback_slots))
@@ -48,11 +48,11 @@ static u32 get_base_addr(unsigned int seg, int bus, unsigned devfn)
                        break;
                }
                cfg = &pci_mmcfg_config[cfg_num];
-               if (cfg->pci_segment_group_number != seg)
+               if (cfg->pci_segment != seg)
                        continue;
                if ((cfg->start_bus_number <= bus) &&
                    (cfg->end_bus_number >= bus))
-                       return cfg->base_address;
+                       return cfg->address;
        }
 
        /* Handle more broken MCFG tables on Asus etc.
@@ -60,9 +60,9 @@ static u32 get_base_addr(unsigned int seg, int bus, unsigned devfn)
           this applies to all busses. */
        cfg = &pci_mmcfg_config[0];
        if (pci_mmcfg_config_num == 1 &&
-               cfg->pci_segment_group_number == 0 &&
+               cfg->pci_segment == 0 &&
                (cfg->start_bus_number | cfg->end_bus_number) == 0)
-               return cfg->base_address;
+               return cfg->address;
 
        /* Fall back to type 0 */
        return 0;
@@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
        unsigned long flags;
        u32 base;
 
-       if ((bus > 255) || (devfn > 255) || (reg > 4095)) 
+       if ((bus > 255) || (devfn > 255) || (reg > 4095))
                return -EINVAL;
 
        base = get_base_addr(seg, bus, devfn);
@@ -199,19 +199,19 @@ void __init pci_mmcfg_init(int type)
        if ((pci_probe & PCI_PROBE_MMCONF) == 0)
                return;
 
-       acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);
+       acpi_table_parse(ACPI_SIG_MCFG, acpi_parse_mcfg);
        if ((pci_mmcfg_config_num == 0) ||
            (pci_mmcfg_config == NULL) ||
-           (pci_mmcfg_config[0].base_address == 0))
+           (pci_mmcfg_config[0].address == 0))
                return;
 
        /* Only do this check when type 1 works. If it doesn't work
           assume we run on a Mac and always use MCFG */
-       if (type == 1 && !e820_all_mapped(pci_mmcfg_config[0].base_address,
-                       pci_mmcfg_config[0].base_address + MMCONFIG_APER_MIN,
+       if (type == 1 && !e820_all_mapped(pci_mmcfg_config[0].address,
+                       pci_mmcfg_config[0].address + MMCONFIG_APER_MIN,
                        E820_RESERVED)) {
-               printk(KERN_ERR "PCI: BIOS Bug: MCFG area at %x is not E820-reserved\n",
-                               pci_mmcfg_config[0].base_address);
+               printk(KERN_ERR "PCI: BIOS Bug: MCFG area at %lx is not E820-reserved\n",
+                               (unsigned long)pci_mmcfg_config[0].address);
                printk(KERN_ERR "PCI: Not using MMCONFIG.\n");
                return;
        }
index 29f05d4b68cdd7f17911f8b840838faa795be2c4..9197d7b361b33da914744bff7a2a393a799c9ba9 100644 (file)
@@ -55,7 +55,7 @@
 
 #define BAD_MADT_ENTRY(entry, end) (                                        \
                (!entry) || (unsigned long)entry + sizeof(*entry) > end ||  \
-               ((acpi_table_entry_header *)entry)->length < sizeof(*entry))
+               ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
 
 #define PREFIX                 "ACPI: "
 
@@ -67,16 +67,11 @@ EXPORT_SYMBOL(pm_power_off);
 unsigned int acpi_cpei_override;
 unsigned int acpi_cpei_phys_cpuid;
 
-#define MAX_SAPICS 256
-u16 ia64_acpiid_to_sapicid[MAX_SAPICS] = {[0 ... MAX_SAPICS - 1] = -1 };
-
-EXPORT_SYMBOL(ia64_acpiid_to_sapicid);
-
 const char *acpi_get_sysname(void)
 {
 #ifdef CONFIG_IA64_GENERIC
        unsigned long rsdp_phys;
-       struct acpi20_table_rsdp *rsdp;
+       struct acpi_table_rsdp *rsdp;
        struct acpi_table_xsdt *xsdt;
        struct acpi_table_header *hdr;
 
@@ -87,16 +82,16 @@ const char *acpi_get_sysname(void)
                return "dig";
        }
 
-       rsdp = (struct acpi20_table_rsdp *)__va(rsdp_phys);
-       if (strncmp(rsdp->signature, RSDP_SIG, sizeof(RSDP_SIG) - 1)) {
+       rsdp = (struct acpi_table_rsdp *)__va(rsdp_phys);
+       if (strncmp(rsdp->signature, ACPI_SIG_RSDP, sizeof(ACPI_SIG_RSDP) - 1)) {
                printk(KERN_ERR
                       "ACPI 2.0 RSDP signature incorrect, default to \"dig\"\n");
                return "dig";
        }
 
-       xsdt = (struct acpi_table_xsdt *)__va(rsdp->xsdt_address);
+       xsdt = (struct acpi_table_xsdt *)__va(rsdp->xsdt_physical_address);
        hdr = &xsdt->header;
-       if (strncmp(hdr->signature, XSDT_SIG, sizeof(XSDT_SIG) - 1)) {
+       if (strncmp(hdr->signature, ACPI_SIG_XSDT, sizeof(ACPI_SIG_XSDT) - 1)) {
                printk(KERN_ERR
                       "ACPI 2.0 XSDT signature incorrect, default to \"dig\"\n");
                return "dig";
@@ -169,12 +164,12 @@ struct acpi_table_madt *acpi_madt __initdata;
 static u8 has_8259;
 
 static int __init
-acpi_parse_lapic_addr_ovr(acpi_table_entry_header * header,
+acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
                          const unsigned long end)
 {
-       struct acpi_table_lapic_addr_ovr *lapic;
+       struct acpi_madt_local_apic_override *lapic;
 
-       lapic = (struct acpi_table_lapic_addr_ovr *)header;
+       lapic = (struct acpi_madt_local_apic_override *)header;
 
        if (BAD_MADT_ENTRY(lapic, end))
                return -EINVAL;
@@ -187,22 +182,19 @@ acpi_parse_lapic_addr_ovr(acpi_table_entry_header * header,
 }
 
 static int __init
-acpi_parse_lsapic(acpi_table_entry_header * header, const unsigned long end)
+acpi_parse_lsapic(struct acpi_subtable_header * header, const unsigned long end)
 {
-       struct acpi_table_lsapic *lsapic;
+       struct acpi_madt_local_sapic *lsapic;
 
-       lsapic = (struct acpi_table_lsapic *)header;
+       lsapic = (struct acpi_madt_local_sapic *)header;
 
-       if (BAD_MADT_ENTRY(lsapic, end))
-               return -EINVAL;
+       /*Skip BAD_MADT_ENTRY check, as lsapic size could vary */
 
-       if (lsapic->flags.enabled) {
+       if (lsapic->lapic_flags & ACPI_MADT_ENABLED) {
 #ifdef CONFIG_SMP
                smp_boot_data.cpu_phys_id[available_cpus] =
                    (lsapic->id << 8) | lsapic->eid;
 #endif
-               ia64_acpiid_to_sapicid[lsapic->acpi_id] =
-                   (lsapic->id << 8) | lsapic->eid;
                ++available_cpus;
        }
 
@@ -211,11 +203,11 @@ acpi_parse_lsapic(acpi_table_entry_header * header, const unsigned long end)
 }
 
 static int __init
-acpi_parse_lapic_nmi(acpi_table_entry_header * header, const unsigned long end)
+acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
 {
-       struct acpi_table_lapic_nmi *lacpi_nmi;
+       struct acpi_madt_local_apic_nmi *lacpi_nmi;
 
-       lacpi_nmi = (struct acpi_table_lapic_nmi *)header;
+       lacpi_nmi = (struct acpi_madt_local_apic_nmi *)header;
 
        if (BAD_MADT_ENTRY(lacpi_nmi, end))
                return -EINVAL;
@@ -225,11 +217,11 @@ acpi_parse_lapic_nmi(acpi_table_entry_header * header, const unsigned long end)
 }
 
 static int __init
-acpi_parse_iosapic(acpi_table_entry_header * header, const unsigned long end)
+acpi_parse_iosapic(struct acpi_subtable_header * header, const unsigned long end)
 {
-       struct acpi_table_iosapic *iosapic;
+       struct acpi_madt_io_sapic *iosapic;
 
-       iosapic = (struct acpi_table_iosapic *)header;
+       iosapic = (struct acpi_madt_io_sapic *)header;
 
        if (BAD_MADT_ENTRY(iosapic, end))
                return -EINVAL;
@@ -240,13 +232,13 @@ acpi_parse_iosapic(acpi_table_entry_header * header, const unsigned long end)
 static unsigned int __initdata acpi_madt_rev;
 
 static int __init
-acpi_parse_plat_int_src(acpi_table_entry_header * header,
+acpi_parse_plat_int_src(struct acpi_subtable_header * header,
                        const unsigned long end)
 {
-       struct acpi_table_plat_int_src *plintsrc;
+       struct acpi_madt_interrupt_source *plintsrc;
        int vector;
 
-       plintsrc = (struct acpi_table_plat_int_src *)header;
+       plintsrc = (struct acpi_madt_interrupt_source *)header;
 
        if (BAD_MADT_ENTRY(plintsrc, end))
                return -EINVAL;
@@ -257,19 +249,19 @@ acpi_parse_plat_int_src(acpi_table_entry_header * header,
         */
        vector = iosapic_register_platform_intr(plintsrc->type,
                                                plintsrc->global_irq,
-                                               plintsrc->iosapic_vector,
+                                               plintsrc->io_sapic_vector,
                                                plintsrc->eid,
                                                plintsrc->id,
-                                               (plintsrc->flags.polarity ==
-                                                1) ? IOSAPIC_POL_HIGH :
-                                               IOSAPIC_POL_LOW,
-                                               (plintsrc->flags.trigger ==
-                                                1) ? IOSAPIC_EDGE :
-                                               IOSAPIC_LEVEL);
+                                               ((plintsrc->inti_flags & ACPI_MADT_POLARITY_MASK) ==
+                                                ACPI_MADT_POLARITY_ACTIVE_HIGH) ?
+                                               IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
+                                               ((plintsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) ==
+                                                ACPI_MADT_TRIGGER_EDGE) ?
+                                               IOSAPIC_EDGE : IOSAPIC_LEVEL);
 
        platform_intr_list[plintsrc->type] = vector;
        if (acpi_madt_rev > 1) {
-               acpi_cpei_override = plintsrc->plint_flags.cpei_override_flag;
+               acpi_cpei_override = plintsrc->flags & ACPI_MADT_CPEI_OVERRIDE;
        }
 
        /*
@@ -324,30 +316,32 @@ unsigned int get_cpei_target_cpu(void)
 }
 
 static int __init
-acpi_parse_int_src_ovr(acpi_table_entry_header * header,
+acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
                       const unsigned long end)
 {
-       struct acpi_table_int_src_ovr *p;
+       struct acpi_madt_interrupt_override *p;
 
-       p = (struct acpi_table_int_src_ovr *)header;
+       p = (struct acpi_madt_interrupt_override *)header;
 
        if (BAD_MADT_ENTRY(p, end))
                return -EINVAL;
 
-       iosapic_override_isa_irq(p->bus_irq, p->global_irq,
-                                (p->flags.polarity ==
-                                 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
-                                (p->flags.trigger ==
-                                 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
+       iosapic_override_isa_irq(p->source_irq, p->global_irq,
+                                ((p->inti_flags & ACPI_MADT_POLARITY_MASK) ==
+                                 ACPI_MADT_POLARITY_ACTIVE_HIGH) ?
+                                IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
+                                ((p->inti_flags & ACPI_MADT_TRIGGER_MASK) ==
+                                ACPI_MADT_TRIGGER_EDGE) ?
+                                IOSAPIC_EDGE : IOSAPIC_LEVEL);
        return 0;
 }
 
 static int __init
-acpi_parse_nmi_src(acpi_table_entry_header * header, const unsigned long end)
+acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
 {
-       struct acpi_table_nmi_src *nmi_src;
+       struct acpi_madt_nmi_source *nmi_src;
 
-       nmi_src = (struct acpi_table_nmi_src *)header;
+       nmi_src = (struct acpi_madt_nmi_source *)header;
 
        if (BAD_MADT_ENTRY(nmi_src, end))
                return -EINVAL;
@@ -371,12 +365,12 @@ static void __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
        }
 }
 
-static int __init acpi_parse_madt(unsigned long phys_addr, unsigned long size)
+static int __init acpi_parse_madt(struct acpi_table_header *table)
 {
-       if (!phys_addr || !size)
+       if (!table)
                return -EINVAL;
 
-       acpi_madt = (struct acpi_table_madt *)__va(phys_addr);
+       acpi_madt = (struct acpi_table_madt *)table;
 
        acpi_madt_rev = acpi_madt->header.revision;
 
@@ -384,14 +378,14 @@ static int __init acpi_parse_madt(unsigned long phys_addr, unsigned long size)
 #ifdef CONFIG_ITANIUM
        has_8259 = 1;           /* Firmware on old Itanium systems is broken */
 #else
-       has_8259 = acpi_madt->flags.pcat_compat;
+       has_8259 = acpi_madt->flags & ACPI_MADT_PCAT_COMPAT;
 #endif
        iosapic_system_init(has_8259);
 
        /* Get base address of IPI Message Block */
 
-       if (acpi_madt->lapic_address)
-               ipi_base_addr = ioremap(acpi_madt->lapic_address, 0);
+       if (acpi_madt->address)
+               ipi_base_addr = ioremap(acpi_madt->address, 0);
 
        printk(KERN_INFO PREFIX "Local APIC address %p\n", ipi_base_addr);
 
@@ -413,23 +407,24 @@ static u32 __devinitdata pxm_flag[PXM_FLAG_LEN];
 #define pxm_bit_test(bit)      (test_bit(bit,(void *)pxm_flag))
 static struct acpi_table_slit __initdata *slit_table;
 
-static int get_processor_proximity_domain(struct acpi_table_processor_affinity *pa)
+static int get_processor_proximity_domain(struct acpi_srat_cpu_affinity *pa)
 {
        int pxm;
 
-       pxm = pa->proximity_domain;
+       pxm = pa->proximity_domain_lo;
        if (ia64_platform_is("sn2"))
-               pxm += pa->reserved[0] << 8;
+               pxm += pa->proximity_domain_hi[0] << 8;
        return pxm;
 }
 
-static int get_memory_proximity_domain(struct acpi_table_memory_affinity *ma)
+static int get_memory_proximity_domain(struct acpi_srat_mem_affinity *ma)
 {
        int pxm;
 
        pxm = ma->proximity_domain;
-       if (ia64_platform_is("sn2"))
-               pxm += ma->reserved1[0] << 8;
+       if (!ia64_platform_is("sn2"))
+               pxm &= 0xff;
+
        return pxm;
 }
 
@@ -442,7 +437,7 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
        u32 len;
 
        len = sizeof(struct acpi_table_header) + 8
-           + slit->localities * slit->localities;
+           + slit->locality_count * slit->locality_count;
        if (slit->header.length != len) {
                printk(KERN_ERR
                       "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
@@ -454,11 +449,11 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
 }
 
 void __init
-acpi_numa_processor_affinity_init(struct acpi_table_processor_affinity *pa)
+acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
 {
        int pxm;
 
-       if (!pa->flags.enabled)
+       if (!(pa->flags & ACPI_SRAT_CPU_ENABLED))
                return;
 
        pxm = get_processor_proximity_domain(pa);
@@ -467,14 +462,14 @@ acpi_numa_processor_affinity_init(struct acpi_table_processor_affinity *pa)
        pxm_bit_set(pxm);
 
        node_cpuid[srat_num_cpus].phys_id =
-           (pa->apic_id << 8) | (pa->lsapic_eid);
+           (pa->apic_id << 8) | (pa->local_sapic_eid);
        /* nid should be overridden as logical node id later */
        node_cpuid[srat_num_cpus].nid = pxm;
        srat_num_cpus++;
 }
 
 void __init
-acpi_numa_memory_affinity_init(struct acpi_table_memory_affinity *ma)
+acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
 {
        unsigned long paddr, size;
        int pxm;
@@ -483,13 +478,11 @@ acpi_numa_memory_affinity_init(struct acpi_table_memory_affinity *ma)
        pxm = get_memory_proximity_domain(ma);
 
        /* fill node memory chunk structure */
-       paddr = ma->base_addr_hi;
-       paddr = (paddr << 32) | ma->base_addr_lo;
-       size = ma->length_hi;
-       size = (size << 32) | ma->length_lo;
+       paddr = ma->base_address;
+       size = ma->length;
 
        /* Ignore disabled entries */
-       if (!ma->flags.enabled)
+       if (!(ma->flags & ACPI_SRAT_MEM_ENABLED))
                return;
 
        /* record this node in proximity bitmap */
@@ -560,16 +553,16 @@ void __init acpi_numa_arch_fixup(void)
        if (!slit_table)
                return;
        memset(numa_slit, -1, sizeof(numa_slit));
-       for (i = 0; i < slit_table->localities; i++) {
+       for (i = 0; i < slit_table->locality_count; i++) {
                if (!pxm_bit_test(i))
                        continue;
                node_from = pxm_to_node(i);
-               for (j = 0; j < slit_table->localities; j++) {
+               for (j = 0; j < slit_table->locality_count; j++) {
                        if (!pxm_bit_test(j))
                                continue;
                        node_to = pxm_to_node(j);
                        node_distance(node_from, node_to) =
-                           slit_table->entry[i * slit_table->localities + j];
+                           slit_table->entry[i * slit_table->locality_count + j];
                }
        }
 
@@ -617,21 +610,21 @@ void acpi_unregister_gsi(u32 gsi)
 
 EXPORT_SYMBOL(acpi_unregister_gsi);
 
-static int __init acpi_parse_fadt(unsigned long phys_addr, unsigned long size)
+static int __init acpi_parse_fadt(struct acpi_table_header *table)
 {
        struct acpi_table_header *fadt_header;
-       struct fadt_descriptor *fadt;
+       struct acpi_table_fadt *fadt;
 
-       if (!phys_addr || !size)
+       if (!table)
                return -EINVAL;
 
-       fadt_header = (struct acpi_table_header *)__va(phys_addr);
+       fadt_header = (struct acpi_table_header *)table;
        if (fadt_header->revision != 3)
                return -ENODEV; /* Only deal with ACPI 2.0 FADT */
 
-       fadt = (struct fadt_descriptor *)fadt_header;
+       fadt = (struct acpi_table_fadt *)fadt_header;
 
-       acpi_register_gsi(fadt->sci_int, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
+       acpi_register_gsi(fadt->sci_interrupt, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
        return 0;
 }
 
@@ -658,7 +651,7 @@ int __init acpi_boot_init(void)
         * information -- the successor to MPS tables.
         */
 
-       if (acpi_table_parse(ACPI_APIC, acpi_parse_madt) < 1) {
+       if (acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt) < 1) {
                printk(KERN_ERR PREFIX "Can't find MADT\n");
                goto skip_madt;
        }
@@ -666,40 +659,40 @@ int __init acpi_boot_init(void)
        /* Local APIC */
 
        if (acpi_table_parse_madt
-           (ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0) < 0)
+           (ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE, acpi_parse_lapic_addr_ovr, 0) < 0)
                printk(KERN_ERR PREFIX
                       "Error parsing LAPIC address override entry\n");
 
-       if (acpi_table_parse_madt(ACPI_MADT_LSAPIC, acpi_parse_lsapic, NR_CPUS)
+       if (acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC, acpi_parse_lsapic, NR_CPUS)
            < 1)
                printk(KERN_ERR PREFIX
                       "Error parsing MADT - no LAPIC entries\n");
 
-       if (acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0)
+       if (acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0)
            < 0)
                printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
 
        /* I/O APIC */
 
        if (acpi_table_parse_madt
-           (ACPI_MADT_IOSAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1)
+           (ACPI_MADT_TYPE_IO_SAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1)
                printk(KERN_ERR PREFIX
                       "Error parsing MADT - no IOSAPIC entries\n");
 
        /* System-Level Interrupt Routing */
 
        if (acpi_table_parse_madt
-           (ACPI_MADT_PLAT_INT_SRC, acpi_parse_plat_int_src,
+           (ACPI_MADT_TYPE_INTERRUPT_SOURCE, acpi_parse_plat_int_src,
             ACPI_MAX_PLATFORM_INTERRUPTS) < 0)
                printk(KERN_ERR PREFIX
                       "Error parsing platform interrupt source entry\n");
 
        if (acpi_table_parse_madt
-           (ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, 0) < 0)
+           (ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr, 0) < 0)
                printk(KERN_ERR PREFIX
                       "Error parsing interrupt source overrides entry\n");
 
-       if (acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, 0) < 0)
+       if (acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src, 0) < 0)
                printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
       skip_madt:
 
@@ -709,7 +702,7 @@ int __init acpi_boot_init(void)
         * gets interrupts such as power and sleep buttons.  If it's not
         * on a Legacy interrupt, it needs to be setup.
         */
-       if (acpi_table_parse(ACPI_FADT, acpi_parse_fadt) < 1)
+       if (acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt) < 1)
                printk(KERN_ERR PREFIX "Can't find FADT\n");
 
 #ifdef CONFIG_SMP
@@ -842,7 +835,7 @@ int acpi_map_lsapic(acpi_handle handle, int *pcpu)
 {
        struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
        union acpi_object *obj;
-       struct acpi_table_lsapic *lsapic;
+       struct acpi_madt_local_sapic *lsapic;
        cpumask_t tmp_map;
        long physid;
        int cpu;
@@ -854,16 +847,16 @@ int acpi_map_lsapic(acpi_handle handle, int *pcpu)
                return -EINVAL;
 
        obj = buffer.pointer;
-       if (obj->type != ACPI_TYPE_BUFFER ||
-           obj->buffer.length < sizeof(*lsapic)) {
+       if (obj->type != ACPI_TYPE_BUFFER)
+       {
                kfree(buffer.pointer);
                return -EINVAL;
        }
 
-       lsapic = (struct acpi_table_lsapic *)obj->buffer.pointer;
+       lsapic = (struct acpi_madt_local_sapic *)obj->buffer.pointer;
 
-       if ((lsapic->header.type != ACPI_MADT_LSAPIC) ||
-           (!lsapic->flags.enabled)) {
+       if ((lsapic->header.type != ACPI_MADT_TYPE_LOCAL_SAPIC) ||
+           (!lsapic->lapic_flags & ACPI_MADT_ENABLED)) {
                kfree(buffer.pointer);
                return -EINVAL;
        }
@@ -883,7 +876,6 @@ int acpi_map_lsapic(acpi_handle handle, int *pcpu)
 
        cpu_set(cpu, cpu_present_map);
        ia64_cpu_to_sapicid[cpu] = physid;
-       ia64_acpiid_to_sapicid[lsapic->acpi_id] = ia64_cpu_to_sapicid[cpu];
 
        *pcpu = cpu;
        return (0);
@@ -893,14 +885,6 @@ EXPORT_SYMBOL(acpi_map_lsapic);
 
 int acpi_unmap_lsapic(int cpu)
 {
-       int i;
-
-       for (i = 0; i < MAX_SAPICS; i++) {
-               if (ia64_acpiid_to_sapicid[i] == ia64_cpu_to_sapicid[cpu]) {
-                       ia64_acpiid_to_sapicid[i] = -1;
-                       break;
-               }
-       }
        ia64_cpu_to_sapicid[cpu] = -1;
        cpu_clear(cpu, cpu_present_map);
 
@@ -920,7 +904,7 @@ acpi_map_iosapic(acpi_handle handle, u32 depth, void *context, void **ret)
 {
        struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
        union acpi_object *obj;
-       struct acpi_table_iosapic *iosapic;
+       struct acpi_madt_io_sapic *iosapic;
        unsigned int gsi_base;
        int pxm, node;
 
@@ -938,9 +922,9 @@ acpi_map_iosapic(acpi_handle handle, u32 depth, void *context, void **ret)
                return AE_OK;
        }
 
-       iosapic = (struct acpi_table_iosapic *)obj->buffer.pointer;
+       iosapic = (struct acpi_madt_io_sapic *)obj->buffer.pointer;
 
-       if (iosapic->header.type != ACPI_MADT_IOSAPIC) {
+       if (iosapic->header.type != ACPI_MADT_TYPE_IO_SAPIC) {
                kfree(buffer.pointer);
                return AE_OK;
        }
index cb96b4ea7df6970825151bf3b5f0dd014a43c063..8c331ca6e5c9088a8a8542ebae195306f4d9a6bc 100644 (file)
@@ -13,6 +13,7 @@
 #include <asm/sn/sn_sal.h>
 #include "xtalk/hubdev.h"
 #include <linux/acpi.h>
+#include <acpi/acnamesp.h>
 
 
 /*
@@ -31,6 +32,12 @@ struct acpi_vendor_uuid sn_uuid = {
                    0xa2, 0x7c, 0x08, 0x00, 0x69, 0x13, 0xea, 0x51 },
 };
 
+struct sn_pcidev_match {
+       u8 bus;
+       unsigned int devfn;
+       acpi_handle handle;
+};
+
 /*
  * Perform the early IO init in PROM.
  */
@@ -119,9 +126,11 @@ sn_get_bussoft_ptr(struct pci_bus *bus)
        status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,
                                          &sn_uuid, &buffer);
        if (ACPI_FAILURE(status)) {
-               printk(KERN_ERR "get_acpi_pcibus_ptr: "
-                      "get_acpi_bussoft_info() failed: %d\n",
-                      status);
+               printk(KERN_ERR "%s: "
+                      "acpi_get_vendor_resource() failed (0x%x) for: ",
+                      __FUNCTION__, status);
+               acpi_ns_print_node_pathname(handle, NULL);
+               printk("\n");
                return NULL;
        }
        resource = buffer.pointer;
@@ -130,8 +139,8 @@ sn_get_bussoft_ptr(struct pci_bus *bus)
        if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=
             sizeof(struct pcibus_bussoft *)) {
                printk(KERN_ERR
-                      "get_acpi_bussoft_ptr: Invalid vendor data "
-                      "length %d\n", vendor->byte_length);
+                      "%s: Invalid vendor data length %d\n",
+                       __FUNCTION__, vendor->byte_length);
                kfree(buffer.pointer);
                return NULL;
        }
@@ -143,34 +152,254 @@ sn_get_bussoft_ptr(struct pci_bus *bus)
 }
 
 /*
- * sn_acpi_bus_fixup
+ * sn_extract_device_info - Extract the pcidev_info and the sn_irq_info
+ *                         pointers from the vendor resource using the
+ *                         provided acpi handle, and copy the structures
+ *                         into the argument buffers.
  */
-void
-sn_acpi_bus_fixup(struct pci_bus *bus)
+static int
+sn_extract_device_info(acpi_handle handle, struct pcidev_info **pcidev_info,
+                   struct sn_irq_info **sn_irq_info)
 {
-       struct pci_dev *pci_dev = NULL;
-       struct pcibus_bussoft *prom_bussoft_ptr;
-       extern void sn_common_bus_fixup(struct pci_bus *,
-                                       struct pcibus_bussoft *);
+       u64 addr;
+       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+       struct sn_irq_info *irq_info, *irq_info_prom;
+       struct pcidev_info *pcidev_ptr, *pcidev_prom_ptr;
+       struct acpi_resource *resource;
+       int ret = 0;
+       acpi_status status;
+       struct acpi_resource_vendor_typed *vendor;
 
-       if (!bus->parent) {     /* If root bus */
-               prom_bussoft_ptr = sn_get_bussoft_ptr(bus);
-               if (prom_bussoft_ptr == NULL) {
+       /*
+        * The pointer to this device's pcidev_info structure in
+        * the PROM, is in the vendor resource.
+        */
+       status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,
+                                         &sn_uuid, &buffer);
+       if (ACPI_FAILURE(status)) {
+               printk(KERN_ERR
+                      "%s: acpi_get_vendor_resource() failed (0x%x) for: ",
+                       __FUNCTION__, status);
+               acpi_ns_print_node_pathname(handle, NULL);
+               printk("\n");
+               return 1;
+       }
+
+       resource = buffer.pointer;
+       vendor = &resource->data.vendor_typed;
+       if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=
+           sizeof(struct pci_devdev_info *)) {
+               printk(KERN_ERR
+                      "%s: Invalid vendor data length: %d for: ",
+                       __FUNCTION__, vendor->byte_length);
+               acpi_ns_print_node_pathname(handle, NULL);
+               printk("\n");
+               ret = 1;
+               goto exit;
+       }
+
+       pcidev_ptr = kzalloc(sizeof(struct pcidev_info), GFP_KERNEL);
+       if (!pcidev_ptr)
+               panic("%s: Unable to alloc memory for pcidev_info", __FUNCTION__);
+
+       memcpy(&addr, vendor->byte_data, sizeof(struct pcidev_info *));
+       pcidev_prom_ptr = __va(addr);
+       memcpy(pcidev_ptr, pcidev_prom_ptr, sizeof(struct pcidev_info));
+
+       /* Get the IRQ info */
+       irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
+       if (!irq_info)
+                panic("%s: Unable to alloc memory for sn_irq_info", __FUNCTION__);
+
+       if (pcidev_ptr->pdi_sn_irq_info) {
+               irq_info_prom = __va(pcidev_ptr->pdi_sn_irq_info);
+               memcpy(irq_info, irq_info_prom, sizeof(struct sn_irq_info));
+       }
+
+       *pcidev_info = pcidev_ptr;
+       *sn_irq_info = irq_info;
+
+exit:
+       kfree(buffer.pointer);
+       return ret;
+}
+
+static unsigned int
+get_host_devfn(acpi_handle device_handle, acpi_handle rootbus_handle)
+{
+       unsigned long adr;
+       acpi_handle child;
+       unsigned int devfn;
+       int function;
+       acpi_handle parent;
+       int slot;
+       acpi_status status;
+
+       /*
+        * Do an upward search to find the root bus device, and
+        * obtain the host devfn from the previous child device.
+        */
+       child = device_handle;
+       while (child) {
+               status = acpi_get_parent(child, &parent);
+               if (ACPI_FAILURE(status)) {
+                       printk(KERN_ERR "%s: acpi_get_parent() failed "
+                              "(0x%x) for: ", __FUNCTION__, status);
+                       acpi_ns_print_node_pathname(child, NULL);
+                       printk("\n");
+                       panic("%s: Unable to find host devfn\n", __FUNCTION__);
+               }
+               if (parent == rootbus_handle)
+                       break;
+               child = parent;
+       }
+       if (!child) {
+               printk(KERN_ERR "%s: Unable to find root bus for: ",
+                      __FUNCTION__);
+               acpi_ns_print_node_pathname(device_handle, NULL);
+               printk("\n");
+               BUG();
+       }
+
+       status = acpi_evaluate_integer(child, METHOD_NAME__ADR, NULL, &adr);
+       if (ACPI_FAILURE(status)) {
+               printk(KERN_ERR "%s: Unable to get _ADR (0x%x) for: ",
+                      __FUNCTION__, status);
+               acpi_ns_print_node_pathname(child, NULL);
+               printk("\n");
+               panic("%s: Unable to find host devfn\n", __FUNCTION__);
+       }
+
+       slot = (adr >> 16) & 0xffff;
+       function = adr & 0xffff;
+       devfn = PCI_DEVFN(slot, function);
+       return devfn;
+}
+
+/*
+ * find_matching_device - Callback routine to find the ACPI device
+ *                       that matches up with our pci_dev device.
+ *                       Matching is done on bus number and devfn.
+ *                       To find the bus number for a particular
+ *                       ACPI device, we must look at the _BBN method
+ *                       of its parent.
+ */
+static acpi_status
+find_matching_device(acpi_handle handle, u32 lvl, void *context, void **rv)
+{
+       unsigned long bbn = -1;
+       unsigned long adr;
+       acpi_handle parent = NULL;
+       acpi_status status;
+       unsigned int devfn;
+       int function;
+       int slot;
+       struct sn_pcidev_match *info = context;
+
+        status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
+                                       &adr);
+        if (ACPI_SUCCESS(status)) {
+               status = acpi_get_parent(handle, &parent);
+               if (ACPI_FAILURE(status)) {
                        printk(KERN_ERR
-                              "sn_pci_fixup_bus: 0x%04x:0x%02x Unable to "
-                              "obtain prom_bussoft_ptr\n",
-                              pci_domain_nr(bus), bus->number);
-                       return;
+                              "%s: acpi_get_parent() failed (0x%x) for: ",
+                                       __FUNCTION__, status);
+                       acpi_ns_print_node_pathname(handle, NULL);
+                       printk("\n");
+                       return AE_OK;
+               }
+               status = acpi_evaluate_integer(parent, METHOD_NAME__BBN,
+                                              NULL, &bbn);
+               if (ACPI_FAILURE(status)) {
+                       printk(KERN_ERR
+                         "%s: Failed to find _BBN in parent of: ",
+                                       __FUNCTION__);
+                       acpi_ns_print_node_pathname(handle, NULL);
+                       printk("\n");
+                       return AE_OK;
+               }
+
+                slot = (adr >> 16) & 0xffff;
+                function = adr & 0xffff;
+                devfn = PCI_DEVFN(slot, function);
+                if ((info->devfn == devfn) && (info->bus == bbn)) {
+                       /* We have a match! */
+                       info->handle = handle;
+                       return 1;
                }
-               sn_common_bus_fixup(bus, prom_bussoft_ptr);
        }
-       list_for_each_entry(pci_dev, &bus->devices, bus_list) {
-               sn_pci_fixup_slot(pci_dev);
+       return AE_OK;
+}
+
+/*
+ * sn_acpi_get_pcidev_info - Search ACPI namespace for the acpi
+ *                          device matching the specified pci_dev,
+ *                          and return the pcidev info and irq info.
+ */
+int
+sn_acpi_get_pcidev_info(struct pci_dev *dev, struct pcidev_info **pcidev_info,
+                       struct sn_irq_info **sn_irq_info)
+{
+       unsigned int host_devfn;
+       struct sn_pcidev_match pcidev_match;
+       acpi_handle rootbus_handle;
+       unsigned long segment;
+       acpi_status status;
+
+       rootbus_handle = PCI_CONTROLLER(dev)->acpi_handle;
+        status = acpi_evaluate_integer(rootbus_handle, METHOD_NAME__SEG, NULL,
+                                       &segment);
+        if (ACPI_SUCCESS(status)) {
+               if (segment != pci_domain_nr(dev)) {
+                       printk(KERN_ERR
+                              "%s: Segment number mismatch, 0x%lx vs 0x%x for: ",
+                              __FUNCTION__, segment, pci_domain_nr(dev));
+                       acpi_ns_print_node_pathname(rootbus_handle, NULL);
+                       printk("\n");
+                       return 1;
+               }
+       } else {
+               printk(KERN_ERR "%s: Unable to get __SEG from: ",
+                      __FUNCTION__);
+               acpi_ns_print_node_pathname(rootbus_handle, NULL);
+               printk("\n");
+               return 1;
+       }
+
+       /*
+        * We want to search all devices in this segment/domain
+        * of the ACPI namespace for the matching ACPI device,
+        * which holds the pcidev_info pointer in its vendor resource.
+        */
+       pcidev_match.bus = dev->bus->number;
+       pcidev_match.devfn = dev->devfn;
+       pcidev_match.handle = NULL;
+
+       acpi_walk_namespace(ACPI_TYPE_DEVICE, rootbus_handle, ACPI_UINT32_MAX,
+                           find_matching_device, &pcidev_match, NULL);
+
+       if (!pcidev_match.handle) {
+               printk(KERN_ERR
+                      "%s: Could not find matching ACPI device for %s.\n",
+                      __FUNCTION__, pci_name(dev));
+               return 1;
        }
+
+       if (sn_extract_device_info(pcidev_match.handle, pcidev_info, sn_irq_info))
+               return 1;
+
+       /* Build up the pcidev_info.pdi_slot_host_handle */
+       host_devfn = get_host_devfn(pcidev_match.handle, rootbus_handle);
+       (*pcidev_info)->pdi_slot_host_handle =
+                       ((unsigned long) pci_domain_nr(dev) << 40) |
+                                       /* bus == 0 */
+                                       host_devfn;
+       return 0;
 }
 
 /*
- * sn_acpi_slot_fixup - Perform any SN specific slot fixup.
+ * sn_acpi_slot_fixup - Obtain the pcidev_info and sn_irq_info.
+ *                     Perform any SN specific slot fixup.
  *                     At present there does not appear to be
  *                     any generic way to handle a ROM image
  *                     that has been shadowed by the PROM, so
@@ -179,11 +408,18 @@ sn_acpi_bus_fixup(struct pci_bus *bus)
  */
 
 void
-sn_acpi_slot_fixup(struct pci_dev *dev, struct pcidev_info *pcidev_info)
+sn_acpi_slot_fixup(struct pci_dev *dev)
 {
        void __iomem *addr;
+       struct pcidev_info *pcidev_info = NULL;
+       struct sn_irq_info *sn_irq_info = NULL;
        size_t size;
 
+       if (sn_acpi_get_pcidev_info(dev, &pcidev_info, &sn_irq_info)) {
+               panic("%s:  Failure obtaining pcidev_info for %s\n",
+                     __FUNCTION__, pci_name(dev));
+       }
+
        if (pcidev_info->pdi_pio_mapped_addr[PCI_ROM_RESOURCE]) {
                /*
                 * A valid ROM image exists and has been shadowed by the
@@ -200,8 +436,11 @@ sn_acpi_slot_fixup(struct pci_dev *dev, struct pcidev_info *pcidev_info)
                                                (unsigned long) addr + size;
                dev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_BIOS_COPY;
        }
+       sn_pci_fixup_slot(dev, pcidev_info, sn_irq_info);
 }
 
+EXPORT_SYMBOL(sn_acpi_slot_fixup);
+
 static struct acpi_driver acpi_sn_hubdev_driver = {
        .name = "SGI HUBDEV Driver",
        .ids = "SGIHUB,SGITIO",
@@ -211,6 +450,33 @@ static struct acpi_driver acpi_sn_hubdev_driver = {
 };
 
 
+/*
+ * sn_acpi_bus_fixup -  Perform SN specific setup of software structs
+ *                     (pcibus_bussoft, pcidev_info) and hardware
+ *                     registers, for the specified bus and devices under it.
+ */
+void
+sn_acpi_bus_fixup(struct pci_bus *bus)
+{
+       struct pci_dev *pci_dev = NULL;
+       struct pcibus_bussoft *prom_bussoft_ptr;
+
+       if (!bus->parent) {     /* If root bus */
+               prom_bussoft_ptr = sn_get_bussoft_ptr(bus);
+               if (prom_bussoft_ptr == NULL) {
+                       printk(KERN_ERR
+                              "%s: 0x%04x:0x%02x Unable to "
+                              "obtain prom_bussoft_ptr\n",
+                              __FUNCTION__, pci_domain_nr(bus), bus->number);
+                       return;
+               }
+               sn_common_bus_fixup(bus, prom_bussoft_ptr);
+       }
+       list_for_each_entry(pci_dev, &bus->devices, bus_list) {
+               sn_acpi_slot_fixup(pci_dev);
+       }
+}
+
 /*
  * sn_io_acpi_init - PROM has ACPI support for IO, defining at a minimum the
  *                  nodes and root buses in the DSDT. As a result, bus scanning
index d4dd8f4b6b8da3b17de48d1fc23d796d6e555f5b..d48bcd83253c28073050377cbd5f937882a3f6a5 100644 (file)
 #include <linux/acpi.h>
 #include <asm/sn/sn2/sn_hwperf.h>
 #include <asm/sn/acpi.h>
+#include "acpi/acglobal.h"
 
 extern void sn_init_cpei_timer(void);
 extern void register_sn_procfs(void);
-extern void sn_acpi_bus_fixup(struct pci_bus *);
-extern void sn_bus_fixup(struct pci_bus *);
-extern void sn_acpi_slot_fixup(struct pci_dev *, struct pcidev_info *);
-extern void sn_more_slot_fixup(struct pci_dev *, struct pcidev_info *);
-extern void sn_legacy_pci_window_fixup(struct pci_controller *, u64, u64);
 extern void sn_io_acpi_init(void);
 extern void sn_io_init(void);
 
@@ -48,6 +44,9 @@ struct sysdata_el {
 
 int sn_ioif_inited;            /* SN I/O infrastructure initialized? */
 
+int sn_acpi_rev;               /* SN ACPI revision */
+EXPORT_SYMBOL_GPL(sn_acpi_rev);
+
 struct sn_pcibus_provider *sn_pci_provider[PCIIO_ASIC_MAX_TYPES];      /* indexed by asic type */
 
 /*
@@ -98,25 +97,6 @@ sal_get_device_dmaflush_list(u64 nasid, u64 widget_num, u64 device_num,
        return ret_stuff.status;
 }
 
-/*
- * Retrieve the pci device information given the bus and device|function number.
- */
-static inline u64
-sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
-                   u64 sn_irq_info)
-{
-       struct ia64_sal_retval ret_stuff;
-       ret_stuff.status = 0;
-       ret_stuff.v0 = 0;
-
-       SAL_CALL_NOLOCK(ret_stuff,
-                       (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
-                       (u64) segment, (u64) bus_number, (u64) devfn,
-                       (u64) pci_dev,
-                       sn_irq_info, 0, 0);
-       return ret_stuff.v0;
-}
-
 /*
  * sn_pcidev_info_get() - Retrieve the pcidev_info struct for the specified
  *                       device.
@@ -249,50 +229,25 @@ void sn_pci_unfixup_slot(struct pci_dev *dev)
 }
 
 /*
- * sn_pci_fixup_slot() - This routine sets up a slot's resources consistent
- *                      with the Linux PCI abstraction layer. Resources
- *                      acquired from our PCI provider include PIO maps
- *                      to BAR space and interrupt objects.
+ * sn_pci_fixup_slot()
  */
-void sn_pci_fixup_slot(struct pci_dev *dev)
+void sn_pci_fixup_slot(struct pci_dev *dev, struct pcidev_info *pcidev_info,
+                      struct sn_irq_info *sn_irq_info)
 {
        int segment = pci_domain_nr(dev->bus);
-       int status = 0;
        struct pcibus_bussoft *bs;
-       struct pci_bus *host_pci_bus;
-       struct pci_dev *host_pci_dev;
-       struct pcidev_info *pcidev_info;
-       struct sn_irq_info *sn_irq_info;
-       unsigned int bus_no, devfn;
+       struct pci_bus *host_pci_bus;
+       struct pci_dev *host_pci_dev;
+       unsigned int bus_no, devfn;
 
        pci_dev_get(dev); /* for the sysdata pointer */
-       pcidev_info = kzalloc(sizeof(struct pcidev_info), GFP_KERNEL);
-       if (!pcidev_info)
-               BUG();          /* Cannot afford to run out of memory */
-
-       sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
-       if (!sn_irq_info)
-               BUG();          /* Cannot afford to run out of memory */
-
-       /* Call to retrieve pci device information needed by kernel. */
-       status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
-                                    dev->devfn,
-                                    (u64) __pa(pcidev_info),
-                                    (u64) __pa(sn_irq_info));
-       if (status)
-               BUG(); /* Cannot get platform pci device information */
 
        /* Add pcidev_info to list in pci_controller.platform_data */
        list_add_tail(&pcidev_info->pdi_list,
                      &(SN_PLATFORM_DATA(dev->bus)->pcidev_info));
-
-       if (SN_ACPI_BASE_SUPPORT())
-               sn_acpi_slot_fixup(dev, pcidev_info);
-       else
-               sn_more_slot_fixup(dev, pcidev_info);
        /*
         * Using the PROMs values for the PCI host bus, get the Linux
-        * PCI host_pci_dev struct and set up host bus linkages
+        * PCI host_pci_dev struct and set up host bus linkages
         */
 
        bus_no = (pcidev_info->pdi_slot_host_handle >> 32) & 0xff;
@@ -489,11 +444,6 @@ void sn_generate_path(struct pci_bus *pci_bus, char *address)
                        sprintf(address, "%s^%d", address, geo_slot(geoid));
 }
 
-/*
- * sn_pci_fixup_bus() - Perform SN specific setup of software structs
- *                     (pcibus_bussoft, pcidev_info) and hardware
- *                     registers, for the specified bus and devices under it.
- */
 void __devinit
 sn_pci_fixup_bus(struct pci_bus *bus)
 {
@@ -519,6 +469,15 @@ sn_io_early_init(void)
        if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
                return 0;
 
+       /* we set the acpi revision to that of the DSDT table OEM rev. */
+       {
+               struct acpi_table_header *header = NULL;
+
+               acpi_get_table_by_index(ACPI_TABLE_INDEX_DSDT, &header);
+               BUG_ON(header == NULL);
+               sn_acpi_rev = header->oem_revision;
+       }
+
        /*
         * prime sn_pci_provider[].  Individial provider init routines will
         * override their respective default entries.
@@ -544,8 +503,12 @@ sn_io_early_init(void)
        register_sn_procfs();
 #endif
 
-       printk(KERN_INFO "ACPI  DSDT OEM Rev 0x%x\n",
-              acpi_gbl_DSDT->oem_revision);
+       {
+               struct acpi_table_header *header;
+               (void)acpi_get_table_by_index(ACPI_TABLE_INDEX_DSDT, &header);
+               printk(KERN_INFO "ACPI  DSDT OEM Rev 0x%x\n",
+                       header->oem_revision);
+       }
        if (SN_ACPI_BASE_SUPPORT())
                sn_io_acpi_init();
        else
@@ -605,7 +568,6 @@ sn_io_late_init(void)
 
 fs_initcall(sn_io_late_init);
 
-EXPORT_SYMBOL(sn_pci_fixup_slot);
 EXPORT_SYMBOL(sn_pci_unfixup_slot);
 EXPORT_SYMBOL(sn_bus_store_sysdata);
 EXPORT_SYMBOL(sn_bus_free_sysdata);
index 9ad843e0383b53a1745591defbf2497461a73471..600be3ebae05b660247050b2393057f22b49eda3 100644 (file)
@@ -56,6 +56,25 @@ static inline u64 sal_get_pcibus_info(u64 segment, u64 busnum, u64 address)
        return ret_stuff.v0;
 }
 
+/*
+ * Retrieve the pci device information given the bus and device|function number.
+ */
+static inline u64
+sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
+                   u64 sn_irq_info)
+{
+       struct ia64_sal_retval ret_stuff;
+       ret_stuff.status = 0;
+       ret_stuff.v0 = 0;
+
+       SAL_CALL_NOLOCK(ret_stuff,
+                       (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
+                       (u64) segment, (u64) bus_number, (u64) devfn,
+                       (u64) pci_dev,
+                       sn_irq_info, 0, 0);
+       return ret_stuff.v0;
+}
+
 
 /*
  * sn_fixup_ionodes() - This routine initializes the HUB data structure for
@@ -172,18 +191,40 @@ sn_pci_window_fixup(struct pci_dev *dev, unsigned int count,
 }
 
 /*
- * sn_more_slot_fixup() - We are not running with an ACPI capable PROM,
+ * sn_io_slot_fixup() -   We are not running with an ACPI capable PROM,
  *                       and need to convert the pci_dev->resource
  *                       'start' and 'end' addresses to mapped addresses,
  *                       and setup the pci_controller->window array entries.
  */
 void
-sn_more_slot_fixup(struct pci_dev *dev, struct pcidev_info *pcidev_info)
+sn_io_slot_fixup(struct pci_dev *dev)
 {
        unsigned int count = 0;
        int idx;
        s64 pci_addrs[PCI_ROM_RESOURCE + 1];
        unsigned long addr, end, size, start;
+       struct pcidev_info *pcidev_info;
+       struct sn_irq_info *sn_irq_info;
+       int status;
+
+       pcidev_info = kzalloc(sizeof(struct pcidev_info), GFP_KERNEL);
+       if (!pcidev_info)
+               panic("%s: Unable to alloc memory for pcidev_info", __FUNCTION__);
+
+       sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
+       if (!sn_irq_info)
+               panic("%s: Unable to alloc memory for sn_irq_info", __FUNCTION__);
+
+       /* Call to retrieve pci device information needed by kernel. */
+       status = sal_get_pcidev_info((u64) pci_domain_nr(dev),
+               (u64) dev->bus->number,
+               dev->devfn,
+               (u64) __pa(pcidev_info),
+               (u64) __pa(sn_irq_info));
+
+       if (status)
+               BUG(); /* Cannot get platform pci device information */
+
 
        /* Copy over PIO Mapped Addresses */
        for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
@@ -219,8 +260,12 @@ sn_more_slot_fixup(struct pci_dev *dev, struct pcidev_info *pcidev_info)
         */
        if (count > 0)
                sn_pci_window_fixup(dev, count, pci_addrs);
+
+       sn_pci_fixup_slot(dev, pcidev_info, sn_irq_info);
 }
 
+EXPORT_SYMBOL(sn_io_slot_fixup);
+
 /*
  * sn_pci_controller_fixup() - This routine sets up a bus's resources
  *                            consistent with the Linux PCI abstraction layer.
@@ -272,9 +317,6 @@ sn_bus_fixup(struct pci_bus *bus)
 {
        struct pci_dev *pci_dev = NULL;
        struct pcibus_bussoft *prom_bussoft_ptr;
-       extern void sn_common_bus_fixup(struct pci_bus *,
-                                       struct pcibus_bussoft *);
-
 
        if (!bus->parent) {  /* If root bus */
                prom_bussoft_ptr = PCI_CONTROLLER(bus)->platform_data;
@@ -291,7 +333,7 @@ sn_bus_fixup(struct pci_bus *bus)
                                           prom_bussoft_ptr->bs_legacy_mem);
         }
         list_for_each_entry(pci_dev, &bus->devices, bus_list) {
-                sn_pci_fixup_slot(pci_dev);
+                sn_io_slot_fixup(pci_dev);
         }
 
 }
index 4aa4f301d56d5a63aa114830b23328eefc034476..ab7e2fd40798ea8702d4b4c5bcd167b3310d0645 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  * @port: port to convert
  *
  * Legacy in/out instructions are converted to ld/st instructions
- * on IA64.  This routine will convert a port number into a valid 
+ * on IA64.  This routine will convert a port number into a valid
  * SN i/o address.  Used by sn_in*() and sn_out*().
  */
+
 void *sn_io_addr(unsigned long port)
 {
        if (!IS_RUNNING_ON_SIMULATOR()) {
index 6846dc9b432dc7a2582cf451a7a68c7c8bb2bb2b..04a8256017eb6ab8c0294580c52b12b584c15102 100644 (file)
@@ -20,7 +20,8 @@
 #include "xtalk/hubdev.h"
 
 int
-sal_pcibr_slot_enable(struct pcibus_info *soft, int device, void *resp)
+sal_pcibr_slot_enable(struct pcibus_info *soft, int device, void *resp,
+                      char **ssdt)
 {
        struct ia64_sal_retval ret_stuff;
        u64 busnum;
@@ -32,7 +33,8 @@ sal_pcibr_slot_enable(struct pcibus_info *soft, int device, void *resp)
        segment = soft->pbi_buscommon.bs_persist_segment;
        busnum = soft->pbi_buscommon.bs_persist_busnum;
        SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_SLOT_ENABLE, segment,
-                       busnum, (u64) device, (u64) resp, 0, 0, 0);
+                       busnum, (u64) device, (u64) resp, (u64)ia64_tpa(ssdt),
+                       0, 0);
 
        return (int)ret_stuff.v0;
 }
index 49802f1bee9487484b066915160388d5d683234a..bd30d138113fa9e270a8e7974df36f185db11d50 100644 (file)
@@ -32,7 +32,7 @@ static void via_bugs(void)
 
 static int nvidia_hpet_detected __initdata;
 
-static int __init nvidia_hpet_check(unsigned long phys, unsigned long size)
+static int __init nvidia_hpet_check(struct acpi_table_header *header)
 {
        nvidia_hpet_detected = 1;
        return 0;
@@ -53,7 +53,7 @@ static void nvidia_bugs(void)
                return;
 
        nvidia_hpet_detected = 0;
-       acpi_table_parse(ACPI_HPET, nvidia_hpet_check);
+       acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check);
        if (nvidia_hpet_detected == 0) {
                acpi_skip_timer_override = 1;
                printk(KERN_INFO "Nvidia board "
index b007433f96bbc540b2d71ef9b50f81d8349a2174..0b3603adf56d4e4f35aa4a5eb22dc97cb72243ed 100644 (file)
@@ -58,8 +58,8 @@ void __init clustered_apic_check(void)
         * Some x86_64 machines use physical APIC mode regardless of how many
         * procs/clusters are present (x86_64 ES7000 is an example).
         */
-       if (acpi_fadt.revision > FADT2_REVISION_ID)
-               if (acpi_fadt.force_apic_physical_destination_mode) {
+       if (acpi_gbl_FADT.header.revision > FADT2_REVISION_ID)
+               if (acpi_gbl_FADT.flags & ACPI_FADT_APIC_PHYSICAL) {
                        genapic = &apic_cluster;
                        goto print;
                }
index 08072568847d997ce0cc50d05ff3831ef33a07d9..50dd8bef850e92b1bc3451c17ab5ee17b1603760 100644 (file)
@@ -798,7 +798,7 @@ int mp_register_gsi(u32 gsi, int triggering, int polarity)
                return gsi;
 
        /* Don't set up the ACPI SCI because it's already set up */
-       if (acpi_fadt.sci_int == gsi)
+       if (acpi_gbl_FADT.sci_interrupt == gsi)
                return gsi;
 
        ioapic = mp_find_ioapic(gsi);
index 5cc76d0d331f0d0fe2b1f7913d7705887112b073..335cc91c49b722c87ba12e8b4040c1f0ee38869b 100644 (file)
@@ -498,7 +498,7 @@ static unsigned long get_cmos_time(void)
 {
        unsigned int year, mon, day, hour, min, sec;
        unsigned long flags;
-       unsigned extyear = 0;
+       unsigned century = 0;
 
        spin_lock_irqsave(&rtc_lock, flags);
 
@@ -510,9 +510,9 @@ static unsigned long get_cmos_time(void)
                mon = CMOS_READ(RTC_MONTH);
                year = CMOS_READ(RTC_YEAR);
 #ifdef CONFIG_ACPI
-               if (acpi_fadt.revision >= FADT2_REVISION_ID &&
-                                       acpi_fadt.century)
-                       extyear = CMOS_READ(acpi_fadt.century);
+               if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
+                                       acpi_gbl_FADT.century)
+                       century = CMOS_READ(acpi_gbl_FADT.century);
 #endif
        } while (sec != CMOS_READ(RTC_SECONDS));
 
@@ -530,10 +530,10 @@ static unsigned long get_cmos_time(void)
        BCD_TO_BIN(mon);
        BCD_TO_BIN(year);
 
-       if (extyear) {
-               BCD_TO_BIN(extyear);
-               year += extyear;
-               printk(KERN_INFO "Extended CMOS year: %d\n", extyear);
+       if (century) {
+               BCD_TO_BIN(century);
+               year += century * 100;
+               printk(KERN_INFO "Extended CMOS year: %d\n", century * 100);
        } else { 
                /*
                 * x86-64 systems only exists since 2002.
@@ -954,7 +954,7 @@ __cpuinit int unsynchronized_tsc(void)
        if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) {
 #ifdef CONFIG_ACPI
                /* But TSC doesn't tick in C3 so don't use it there */
-               if (acpi_fadt.length > 0 && acpi_fadt.plvl3_lat < 1000)
+               if (acpi_gbl_FADT.header.length > 0 && acpi_gbl_FADT.C3latency < 1000)
                        return 1;
 #endif
                return 0;
index 1087e150a21896d1abfaadfccfe7fc4de98728ef..2efe215fc76a1db4353edbe231bc12070954af6c 100644 (file)
@@ -101,7 +101,7 @@ static __init inline int srat_disabled(void)
 static __init int slit_valid(struct acpi_table_slit *slit)
 {
        int i, j;
-       int d = slit->localities;
+       int d = slit->locality_count;
        for (i = 0; i < d; i++) {
                for (j = 0; j < d; j++)  {
                        u8 val = slit->entry[d*i + j];
@@ -127,18 +127,18 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
 
 /* Callback for Proximity Domain -> LAPIC mapping */
 void __init
-acpi_numa_processor_affinity_init(struct acpi_table_processor_affinity *pa)
+acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
 {
        int pxm, node;
        if (srat_disabled())
                return;
-       if (pa->header.length != sizeof(struct acpi_table_processor_affinity)) {
+       if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) {
                bad_srat();
                return;
        }
-       if (pa->flags.enabled == 0)
+       if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
                return;
-       pxm = pa->proximity_domain;
+       pxm = pa->proximity_domain_lo;
        node = setup_node(pxm);
        if (node < 0) {
                printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
@@ -254,21 +254,21 @@ static int reserve_hotadd(int node, unsigned long start, unsigned long end)
        /* Looks good */
 
        if (nd->start == nd->end) {
-               nd->start = start;
-               nd->end = end;
+               nd->start = start;
+               nd->end = end;
                changed = 1;
-       } else {
-               if (nd->start == end) {
-                       nd->start = start;
+       } else {
+               if (nd->start == end) {
+                       nd->start = start;
                        changed = 1;
                }
-               if (nd->end == start) {
-                       nd->end = end;
+               if (nd->end == start) {
+                       nd->end = end;
                        changed = 1;
                }
                if (!changed)
                        printk(KERN_ERR "SRAT: Hotplug zone not continuous. Partly ignored\n");
-       }
+       }
 
        ret = update_end_of_memory(nd->end);
 
@@ -279,7 +279,7 @@ static int reserve_hotadd(int node, unsigned long start, unsigned long end)
 
 /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
 void __init
-acpi_numa_memory_affinity_init(struct acpi_table_memory_affinity *ma)
+acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
 {
        struct bootnode *nd, oldnode;
        unsigned long start, end;
@@ -288,16 +288,17 @@ acpi_numa_memory_affinity_init(struct acpi_table_memory_affinity *ma)
 
        if (srat_disabled())
                return;
-       if (ma->header.length != sizeof(struct acpi_table_memory_affinity)) {
+       if (ma->header.length != sizeof(struct acpi_srat_mem_affinity)) {
                bad_srat();
                return;
        }
-       if (ma->flags.enabled == 0)
+       if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0)
                return;
-       if (ma->flags.hot_pluggable && !save_add_info())
+
+       if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && !save_add_info())
                return;
-       start = ma->base_addr_lo | ((u64)ma->base_addr_hi << 32);
-       end = start + (ma->length_lo | ((u64)ma->length_hi << 32));
+       start = ma->base_address;
+       end = start + ma->length;
        pxm = ma->proximity_domain;
        node = setup_node(pxm);
        if (node < 0) {
@@ -337,7 +338,8 @@ acpi_numa_memory_affinity_init(struct acpi_table_memory_affinity *ma)
        push_node_boundaries(node, nd->start >> PAGE_SHIFT,
                                                nd->end >> PAGE_SHIFT);
 
-       if (ma->flags.hot_pluggable && (reserve_hotadd(node, start, end) < 0)) {
+       if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) &&
+           (reserve_hotadd(node, start, end) < 0)) {
                /* Ignore hotadd region. Undo damage */
                printk(KERN_NOTICE "SRAT: Hotplug region ignored\n");
                *nd = oldnode;
@@ -394,7 +396,7 @@ int __init acpi_scan_nodes(unsigned long start, unsigned long end)
 
        /* First clean up the node list */
        for (i = 0; i < MAX_NUMNODES; i++) {
-               cutoff_node(i, start, end);
+               cutoff_node(i, start, end);
                if ((nodes[i].end - nodes[i].start) < NODE_MIN_SIZE) {
                        unparse_node(i);
                        node_set_offline(i);
@@ -426,7 +428,7 @@ int __init acpi_scan_nodes(unsigned long start, unsigned long end)
                if (!node_online(i))
                        setup_node_bootmem(i, nodes[i].start, nodes[i].end);
 
-       for (i = 0; i < NR_CPUS; i++) { 
+       for (i = 0; i < NR_CPUS; i++) {
                if (cpu_to_node[i] == NUMA_NO_NODE)
                        continue;
                if (!node_isset(cpu_to_node[i], nodes_parsed))
@@ -461,7 +463,7 @@ int __node_distance(int a, int b)
 
        if (!acpi_slit)
                return a == b ? 10 : 20;
-       index = acpi_slit->localities * node_to_pxm(a);
+       index = acpi_slit->locality_count * node_to_pxm(a);
        return acpi_slit->entry[index + node_to_pxm(b)];
 }
 
index f8b6b2800a62c86641d94badfc5b1201951b2578..faabb6e87f12461de8c25bf4ec4f14f75216edaa 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * mmconfig.c - Low-level direct PCI config space access via MMCONFIG
- * 
+ *
  * This is an 64bit optimized version that always keeps the full mmconfig
  * space mapped. This allows lockless config space operation.
  */
@@ -25,7 +25,7 @@ static DECLARE_BITMAP(fallback_slots, 32*MAX_CHECK_BUS);
 
 /* Static virtual mapping of the MMCONFIG aperture */
 struct mmcfg_virt {
-       struct acpi_table_mcfg_config *cfg;
+       struct acpi_mcfg_allocation *cfg;
        char __iomem *virt;
 };
 static struct mmcfg_virt *pci_mmcfg_virt;
@@ -33,14 +33,14 @@ static struct mmcfg_virt *pci_mmcfg_virt;
 static char __iomem *get_virt(unsigned int seg, unsigned bus)
 {
        int cfg_num = -1;
-       struct acpi_table_mcfg_config *cfg;
+       struct acpi_mcfg_allocation *cfg;
 
        while (1) {
                ++cfg_num;
                if (cfg_num >= pci_mmcfg_config_num)
                        break;
                cfg = pci_mmcfg_virt[cfg_num].cfg;
-               if (cfg->pci_segment_group_number != seg)
+               if (cfg->pci_segment != seg)
                        continue;
                if ((cfg->start_bus_number <= bus) &&
                    (cfg->end_bus_number >= bus))
@@ -52,7 +52,7 @@ static char __iomem *get_virt(unsigned int seg, unsigned bus)
           this applies to all busses. */
        cfg = &pci_mmcfg_config[0];
        if (pci_mmcfg_config_num == 1 &&
-               cfg->pci_segment_group_number == 0 &&
+               cfg->pci_segment == 0 &&
                (cfg->start_bus_number | cfg->end_bus_number) == 0)
                return pci_mmcfg_virt[0].virt;
 
@@ -170,19 +170,19 @@ void __init pci_mmcfg_init(int type)
        if ((pci_probe & PCI_PROBE_MMCONF) == 0)
                return;
 
-       acpi_table_parse(ACPI_MCFG, acpi_parse_mcfg);
+       acpi_table_parse(ACPI_SIG_MCFG, acpi_parse_mcfg);
        if ((pci_mmcfg_config_num == 0) ||
            (pci_mmcfg_config == NULL) ||
-           (pci_mmcfg_config[0].base_address == 0))
+           (pci_mmcfg_config[0].address == 0))
                return;
 
        /* Only do this check when type 1 works. If it doesn't work
            assume we run on a Mac and always use MCFG */
-       if (type == 1 && !e820_all_mapped(pci_mmcfg_config[0].base_address,
-                       pci_mmcfg_config[0].base_address + MMCONFIG_APER_MIN,
+       if (type == 1 && !e820_all_mapped(pci_mmcfg_config[0].address,
+                       pci_mmcfg_config[0].address + MMCONFIG_APER_MIN,
                        E820_RESERVED)) {
-               printk(KERN_ERR "PCI: BIOS Bug: MCFG area at %x is not E820-reserved\n",
-                               pci_mmcfg_config[0].base_address);
+               printk(KERN_ERR "PCI: BIOS Bug: MCFG area at %lx is not E820-reserved\n",
+                               (unsigned long)pci_mmcfg_config[0].address);
                printk(KERN_ERR "PCI: Not using MMCONFIG.\n");
                return;
        }
@@ -194,15 +194,16 @@ void __init pci_mmcfg_init(int type)
        }
        for (i = 0; i < pci_mmcfg_config_num; ++i) {
                pci_mmcfg_virt[i].cfg = &pci_mmcfg_config[i];
-               pci_mmcfg_virt[i].virt = ioremap_nocache(pci_mmcfg_config[i].base_address,
+               pci_mmcfg_virt[i].virt = ioremap_nocache(pci_mmcfg_config[i].address,
                                                         MMCONFIG_APER_MAX);
                if (!pci_mmcfg_virt[i].virt) {
                        printk(KERN_ERR "PCI: Cannot map mmconfig aperture for "
                                        "segment %d\n",
-                              pci_mmcfg_config[i].pci_segment_group_number);
+                               pci_mmcfg_config[i].pci_segment);
                        return;
                }
-               printk(KERN_INFO "PCI: Using MMCONFIG at %x\n", pci_mmcfg_config[i].base_address);
+               printk(KERN_INFO "PCI: Using MMCONFIG at %lx\n",
+                       (unsigned long)pci_mmcfg_config[i].address);
        }
 
        unreachable_devices();
index f4f000abc4e9f497e08bb80c64af2a627e3bdb84..20eacc2c9e0e5223f27d9f979672a5ed031b350b 100644 (file)
@@ -3,6 +3,7 @@
 #
 
 menu "ACPI (Advanced Configuration and Power Interface) Support"
+       depends on !X86_NUMAQ
        depends on !X86_VISWS
        depends on !IA64_HP_SIM
        depends on IA64 || X86
@@ -77,6 +78,20 @@ config ACPI_SLEEP_PROC_SLEEP
          Create /proc/acpi/sleep
          Deprecated by /sys/power/state
 
+config ACPI_PROCFS
+       bool "Procfs interface (deprecated)"
+       depends on ACPI
+       default y
+       ---help---
+         Procfs interface for ACPI is made optional for back-compatible.
+         As the same functions are duplicated in sysfs interface
+         and this proc interface will be removed some time later,
+         it's marked as deprecated.
+         ( /proc/acpi/debug_layer && debug_level are deprecated by
+           /sys/module/acpi/parameters/debug_layer && debug_level.
+           /proc/acpi/info is deprecated by
+           /sys/module/acpi/parameters/acpica_version )
+
 config ACPI_AC
        tristate "AC Adapter"
        depends on X86
@@ -107,7 +122,7 @@ config ACPI_BUTTON
 
 config ACPI_VIDEO
        tristate "Video"
-       depends on X86
+       depends on X86 && BACKLIGHT_CLASS_DEVICE
        help
          This driver implement the ACPI Extensions For Display Adapters
          for integrated graphics devices on motherboard, as specified in
@@ -139,6 +154,13 @@ config ACPI_DOCK
        help
          This driver adds support for ACPI controlled docking stations
 
+config ACPI_BAY
+       tristate "Removable Drive Bay (EXPERIMENTAL)"
+       depends on EXPERIMENTAL
+       help
+         This driver adds support for ACPI controlled removable drive
+         bays such as the IBM ultrabay or the Dell Module Bay.
+
 config ACPI_PROCESSOR
        tristate "Processor"
        default y
@@ -186,19 +208,22 @@ config ACPI_ASUS
 
          Note: display switching code is currently considered EXPERIMENTAL,
          toying with these values may even lock your machine.
-          
+
           All settings are changed via /proc/acpi/asus directory entries. Owner
           and group for these entries can be set with asus_uid and asus_gid
           parameters.
-          
+
           More information and a userspace daemon for handling the extra buttons
           at <http://sourceforge.net/projects/acpi4asus/>.
-          
+
           If you have an ACPI-compatible ASUS laptop, say Y or M here. This
           driver is still under development, so if your laptop is unsupported or
           something works not quite as expected, please use the mailing list
-          available on the above page (acpi4asus-user@lists.sourceforge.net)
-          
+          available on the above page (acpi4asus-user@lists.sourceforge.net).
+
+         NOTE: This driver is deprecated and will probably be removed soon,
+         use asus-laptop instead.
+
 config ACPI_IBM
        tristate "IBM ThinkPad Laptop Extras"
        depends on X86
index bce7ca27b429e2874eb4e78a229dd65871070d6c..856c32bccacb04024b7036282bed0c865ef7395e 100644 (file)
@@ -37,13 +37,15 @@ endif
 
 obj-y                          += sleep/
 obj-y                          += bus.o glue.o
+obj-y                          += scan.o
 obj-$(CONFIG_ACPI_AC)          += ac.o
 obj-$(CONFIG_ACPI_BATTERY)     += battery.o
 obj-$(CONFIG_ACPI_BUTTON)      += button.o
 obj-$(CONFIG_ACPI_EC)          += ec.o
 obj-$(CONFIG_ACPI_FAN)         += fan.o
 obj-$(CONFIG_ACPI_DOCK)                += dock.o
-obj-$(CONFIG_ACPI_VIDEO)       += video.o 
+obj-$(CONFIG_ACPI_BAY)         += bay.o
+obj-$(CONFIG_ACPI_VIDEO)       += video.o
 obj-$(CONFIG_ACPI_HOTKEY)      += hotkey.o
 obj-y                          += pci_root.o pci_link.o pci_irq.o pci_bind.o
 obj-$(CONFIG_ACPI_POWER)       += power.o
@@ -56,7 +58,6 @@ obj-$(CONFIG_ACPI_NUMA)               += numa.o
 obj-$(CONFIG_ACPI_ASUS)                += asus_acpi.o
 obj-$(CONFIG_ACPI_IBM)         += ibm_acpi.o
 obj-$(CONFIG_ACPI_TOSHIBA)     += toshiba_acpi.o
-obj-y                          += scan.o motherboard.o
 obj-$(CONFIG_ACPI_HOTPLUG_MEMORY)      += acpi_memhotplug.o
 obj-y                          += cm_sbs.o
 obj-$(CONFIG_ACPI_SBS)         += i2c_ec.o sbs.o
index 396140bbbe576bc83f945896c32ad7d8dcc6ef38..31ad70a6e22eb3074261b757fc7d831b841c9bed 100644 (file)
@@ -26,7 +26,7 @@
  *  Pontus Fuchs   - Helper functions, cleanup
  *  Johann Wiesner - Small compile fixes
  *  John Belmonte  - ACPI code for Toshiba laptop was a good starting point.
- *  Ã‰ric Burghard  - LED display support for W1N
+ *  ï¿½ic Burghard  - LED display support for W1N
  *
  */
 
@@ -1128,7 +1128,6 @@ static int asus_model_match(char *model)
 static int asus_hotk_get_info(void)
 {
        struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-       struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
        union acpi_object *model = NULL;
        int bsts_result;
        char *string = NULL;
@@ -1142,11 +1141,9 @@ static int asus_hotk_get_info(void)
         * HID), this bit will be moved. A global variable asus_info contains
         * the DSDT header.
         */
-       status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
+       status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
        if (ACPI_FAILURE(status))
                printk(KERN_WARNING "  Couldn't get the DSDT table header\n");
-       else
-               asus_info = dsdt.pointer;
 
        /* We have to write 0 on init this far for all ASUS models */
        if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
@@ -1358,8 +1355,6 @@ static void __exit asus_acpi_exit(void)
        acpi_bus_unregister_driver(&asus_hotk_driver);
        remove_proc_entry(PROC_ASUS, acpi_root_dir);
 
-       kfree(asus_info);
-
        return;
 }
 
index 5f43e0d1489994673a75950838815acfe70c6704..2f4521a48fe7b6e3f66726d389cbe5c436540ef6 100644 (file)
@@ -64,7 +64,7 @@ extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
 
 static int acpi_battery_add(struct acpi_device *device);
 static int acpi_battery_remove(struct acpi_device *device, int type);
-static int acpi_battery_resume(struct acpi_device *device, int status);
+static int acpi_battery_resume(struct acpi_device *device);
 
 static struct acpi_driver acpi_battery_driver = {
        .name = ACPI_BATTERY_DRIVER_NAME,
@@ -753,7 +753,7 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
 }
 
 /* this is needed to learn about changes made in suspended state */
-static int acpi_battery_resume(struct acpi_device *device, int state)
+static int acpi_battery_resume(struct acpi_device *device)
 {
        struct acpi_battery *battery;
 
diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c
new file mode 100644 (file)
index 0000000..667fa1d
--- /dev/null
@@ -0,0 +1,490 @@
+/*
+ *  bay.c - ACPI removable drive bay driver
+ *
+ *  Copyright (C) 2006 Kristen Carlson Accardi <kristen.c.accardi@intel.com>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or (at
+ *  your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/notifier.h>
+#include <acpi/acpi_bus.h>
+#include <acpi/acpi_drivers.h>
+#include <linux/seq_file.h>
+#include <asm/uaccess.h>
+#include <linux/platform_device.h>
+
+#define ACPI_BAY_DRIVER_NAME "ACPI Removable Drive Bay Driver"
+
+ACPI_MODULE_NAME("bay")
+MODULE_AUTHOR("Kristen Carlson Accardi");
+MODULE_DESCRIPTION(ACPI_BAY_DRIVER_NAME);
+MODULE_LICENSE("GPL");
+#define ACPI_BAY_CLASS "bay"
+#define ACPI_BAY_COMPONENT     0x10000000
+#define _COMPONENT ACPI_BAY_COMPONENT
+#define bay_dprintk(h,s) {\
+       char prefix[80] = {'\0'};\
+       struct acpi_buffer buffer = {sizeof(prefix), prefix};\
+       acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\
+       printk(KERN_DEBUG PREFIX "%s: %s\n", prefix, s); }
+static void bay_notify(acpi_handle handle, u32 event, void *data);
+static int acpi_bay_add(struct acpi_device *device);
+static int acpi_bay_remove(struct acpi_device *device, int type);
+
+static struct acpi_driver acpi_bay_driver = {
+       .name = ACPI_BAY_DRIVER_NAME,
+       .class = ACPI_BAY_CLASS,
+       .ids = ACPI_BAY_HID,
+       .ops = {
+               .add = acpi_bay_add,
+               .remove = acpi_bay_remove,
+               },
+};
+
+struct bay {
+       acpi_handle handle;
+       char *name;
+       struct list_head list;
+       struct platform_device *pdev;
+};
+
+static LIST_HEAD(drive_bays);
+
+
+/*****************************************************************************
+ *                         Drive Bay functions                               *
+ *****************************************************************************/
+/**
+ * is_ejectable - see if a device is ejectable
+ * @handle: acpi handle of the device
+ *
+ * If an acpi object has a _EJ0 method, then it is ejectable
+ */
+static int is_ejectable(acpi_handle handle)
+{
+       acpi_status status;
+       acpi_handle tmp;
+
+       status = acpi_get_handle(handle, "_EJ0", &tmp);
+       if (ACPI_FAILURE(status))
+               return 0;
+       return 1;
+}
+
+/**
+ * bay_present - see if the bay device is present
+ * @bay: the drive bay
+ *
+ * execute the _STA method.
+ */
+static int bay_present(struct bay *bay)
+{
+       unsigned long sta;
+       acpi_status status;
+
+       if (bay) {
+               status = acpi_evaluate_integer(bay->handle, "_STA", NULL, &sta);
+               if (ACPI_SUCCESS(status) && sta)
+                       return 1;
+       }
+       return 0;
+}
+
+/**
+ * eject_device - respond to an eject request
+ * @handle - the device to eject
+ *
+ * Call this devices _EJ0 method.
+ */
+static void eject_device(acpi_handle handle)
+{
+       struct acpi_object_list arg_list;
+       union acpi_object arg;
+
+       bay_dprintk(handle, "Ejecting device");
+
+       arg_list.count = 1;
+       arg_list.pointer = &arg;
+       arg.type = ACPI_TYPE_INTEGER;
+       arg.integer.value = 1;
+
+       if (ACPI_FAILURE(acpi_evaluate_object(handle, "_EJ0",
+                                             &arg_list, NULL)))
+               pr_debug("Failed to evaluate _EJ0!\n");
+}
+
+/*
+ * show_present - read method for "present" file in sysfs
+ */
+static ssize_t show_present(struct device *dev,
+                          struct device_attribute *attr, char *buf)
+{
+       struct bay *bay = dev_get_drvdata(dev);
+       return snprintf(buf, PAGE_SIZE, "%d\n", bay_present(bay));
+
+}
+DEVICE_ATTR(present, S_IRUGO, show_present, NULL);
+
+/*
+ * write_eject - write method for "eject" file in sysfs
+ */
+static ssize_t write_eject(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
+{
+       struct bay *bay = dev_get_drvdata(dev);
+
+       if (!count)
+               return -EINVAL;
+
+       eject_device(bay->handle);
+       return count;
+}
+DEVICE_ATTR(eject, S_IWUSR, NULL, write_eject);
+
+/**
+ * is_ata - see if a device is an ata device
+ * @handle: acpi handle of the device
+ *
+ * If an acpi object has one of 4 ATA ACPI methods defined,
+ * then it is an ATA device
+ */
+static int is_ata(acpi_handle handle)
+{
+       acpi_handle tmp;
+
+       if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
+          (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
+          (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
+          (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
+               return 1;
+
+       return 0;
+}
+
+/**
+ * parent_is_ata(acpi_handle handle)
+ *
+ */
+static int parent_is_ata(acpi_handle handle)
+{
+       acpi_handle phandle;
+
+       if (acpi_get_parent(handle, &phandle))
+               return 0;
+
+       return is_ata(phandle);
+}
+
+/**
+ * is_ejectable_bay - see if a device is an ejectable drive bay
+ * @handle: acpi handle of the device
+ *
+ * If an acpi object is ejectable and has one of the ACPI ATA
+ * methods defined, then we can safely call it an ejectable
+ * drive bay
+ */
+static int is_ejectable_bay(acpi_handle handle)
+{
+       if ((is_ata(handle) || parent_is_ata(handle)) && is_ejectable(handle))
+               return 1;
+       return 0;
+}
+
+/**
+ * eject_removable_drive - try to eject this drive
+ * @dev : the device structure of the drive
+ *
+ * If a device is a removable drive that requires an _EJ0 method
+ * to be executed in order to safely remove from the system, do
+ * it.  ATM - always returns success
+ */
+int eject_removable_drive(struct device *dev)
+{
+       acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
+
+       if (handle) {
+               bay_dprintk(handle, "Got device handle");
+               if (is_ejectable_bay(handle))
+                       eject_device(handle);
+       } else {
+               printk("No acpi handle for device\n");
+       }
+
+       /* should I return an error code? */
+       return 0;
+}
+EXPORT_SYMBOL_GPL(eject_removable_drive);
+
+static int acpi_bay_add(struct acpi_device *device)
+{
+       bay_dprintk(device->handle, "adding bay device");
+       strcpy(acpi_device_name(device), "Dockable Bay");
+       strcpy(acpi_device_class(device), "bay");
+       return 0;
+}
+
+static int acpi_bay_add_fs(struct bay *bay)
+{
+       int ret;
+       struct device *dev = &bay->pdev->dev;
+
+       ret = device_create_file(dev, &dev_attr_present);
+       if (ret)
+               goto add_fs_err;
+       ret = device_create_file(dev, &dev_attr_eject);
+       if (ret) {
+               device_remove_file(dev, &dev_attr_present);
+               goto add_fs_err;
+       }
+       return 0;
+
+ add_fs_err:
+       bay_dprintk(bay->handle, "Error adding sysfs files\n");
+       return ret;
+}
+
+static void acpi_bay_remove_fs(struct bay *bay)
+{
+       struct device *dev = &bay->pdev->dev;
+
+       /* cleanup sysfs */
+       device_remove_file(dev, &dev_attr_present);
+       device_remove_file(dev, &dev_attr_eject);
+}
+
+static int bay_is_dock_device(acpi_handle handle)
+{
+       acpi_handle parent;
+
+       acpi_get_parent(handle, &parent);
+
+       /* if the device or it's parent is dependent on the
+        * dock, then we are a dock device
+        */
+       return (is_dock_device(handle) || is_dock_device(parent));
+}
+
+static int bay_add(acpi_handle handle, int id)
+{
+       acpi_status status;
+       struct bay *new_bay;
+       struct platform_device *pdev;
+       struct acpi_buffer nbuffer = {ACPI_ALLOCATE_BUFFER, NULL};
+       acpi_get_name(handle, ACPI_FULL_PATHNAME, &nbuffer);
+
+       bay_dprintk(handle, "Adding notify handler");
+
+       /*
+        * Initialize bay device structure
+        */
+       new_bay = kzalloc(GFP_ATOMIC, sizeof(*new_bay));
+       INIT_LIST_HEAD(&new_bay->list);
+       new_bay->handle = handle;
+       new_bay->name = (char *)nbuffer.pointer;
+
+       /* initialize platform device stuff */
+       pdev = platform_device_register_simple(ACPI_BAY_CLASS, id, NULL, 0);
+       if (pdev == NULL) {
+               printk(KERN_ERR PREFIX "Error registering bay device\n");
+               goto bay_add_err;
+       }
+       new_bay->pdev = pdev;
+       platform_set_drvdata(pdev, new_bay);
+
+       if (acpi_bay_add_fs(new_bay)) {
+               platform_device_unregister(new_bay->pdev);
+               goto bay_add_err;
+       }
+
+       /* register for events on this device */
+       status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
+                       bay_notify, new_bay);
+       if (ACPI_FAILURE(status)) {
+               printk(KERN_ERR PREFIX "Error installing bay notify handler\n");
+       }
+
+       /* if we are on a dock station, we should register for dock
+        * notifications.
+        */
+       if (bay_is_dock_device(handle)) {
+               bay_dprintk(handle, "Is dependent on dock\n");
+               register_hotplug_dock_device(handle, bay_notify, new_bay);
+       }
+       list_add(&new_bay->list, &drive_bays);
+       printk(KERN_INFO PREFIX "Bay [%s] Added\n", new_bay->name);
+       return 0;
+
+bay_add_err:
+       kfree(new_bay->name);
+       kfree(new_bay);
+       return -ENODEV;
+}
+
+static int acpi_bay_remove(struct acpi_device *device, int type)
+{
+       /*** FIXME: do something here */
+       return 0;
+}
+
+/**
+ * bay_create_acpi_device - add new devices to acpi
+ * @handle - handle of the device to add
+ *
+ *  This function will create a new acpi_device for the given
+ *  handle if one does not exist already.  This should cause
+ *  acpi to scan for drivers for the given devices, and call
+ *  matching driver's add routine.
+ *
+ *  Returns a pointer to the acpi_device corresponding to the handle.
+ */
+static struct acpi_device * bay_create_acpi_device(acpi_handle handle)
+{
+       struct acpi_device *device = NULL;
+       struct acpi_device *parent_device;
+       acpi_handle parent;
+       int ret;
+
+       bay_dprintk(handle, "Trying to get device");
+       if (acpi_bus_get_device(handle, &device)) {
+               /*
+                * no device created for this object,
+                * so we should create one.
+                */
+               bay_dprintk(handle, "No device for handle");
+               acpi_get_parent(handle, &parent);
+               if (acpi_bus_get_device(parent, &parent_device))
+                       parent_device = NULL;
+
+               ret = acpi_bus_add(&device, parent_device, handle,
+                       ACPI_BUS_TYPE_DEVICE);
+               if (ret) {
+                       pr_debug("error adding bus, %x\n",
+                               -ret);
+                       return NULL;
+               }
+       }
+       return device;
+}
+
+/**
+ * bay_notify - act upon an acpi bay notification
+ * @handle: the bay handle
+ * @event: the acpi event
+ * @data: our driver data struct
+ *
+ */
+static void bay_notify(acpi_handle handle, u32 event, void *data)
+{
+       struct acpi_device *dev;
+
+       bay_dprintk(handle, "Bay event");
+
+       switch(event) {
+       case ACPI_NOTIFY_BUS_CHECK:
+               printk("Bus Check\n");
+       case ACPI_NOTIFY_DEVICE_CHECK:
+               printk("Device Check\n");
+               dev = bay_create_acpi_device(handle);
+               if (dev)
+                       acpi_bus_generate_event(dev, event, 0);
+               else
+                       printk("No device for generating event\n");
+               /* wouldn't it be a good idea to just rescan SATA
+                * right here?
+                */
+               break;
+       case ACPI_NOTIFY_EJECT_REQUEST:
+               printk("Eject request\n");
+               dev = bay_create_acpi_device(handle);
+               if (dev)
+                       acpi_bus_generate_event(dev, event, 0);
+               else
+                       printk("No device for generating eventn");
+
+               /* wouldn't it be a good idea to just call the
+                * eject_device here if we were a SATA device?
+                */
+               break;
+       default:
+               printk("unknown event %d\n", event);
+       }
+}
+
+static acpi_status
+find_bay(acpi_handle handle, u32 lvl, void *context, void **rv)
+{
+       int *count = (int *)context;
+
+       /*
+        * there could be more than one ejectable bay.
+        * so, just return AE_OK always so that every object
+        * will be checked.
+        */
+       if (is_ejectable_bay(handle)) {
+               bay_dprintk(handle, "found ejectable bay");
+               if (!bay_add(handle, *count))
+                       (*count)++;
+       }
+       return AE_OK;
+}
+
+static int __init bay_init(void)
+{
+       int bays = 0;
+
+       INIT_LIST_HEAD(&drive_bays);
+
+       /* look for dockable drive bays */
+       acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+               ACPI_UINT32_MAX, find_bay, &bays, NULL);
+
+       if (bays)
+               if ((acpi_bus_register_driver(&acpi_bay_driver) < 0))
+                       printk(KERN_ERR "Unable to register bay driver\n");
+
+       if (!bays)
+               return -ENODEV;
+
+       return 0;
+}
+
+static void __exit bay_exit(void)
+{
+       struct bay *bay, *tmp;
+
+       list_for_each_entry_safe(bay, tmp, &drive_bays, list) {
+               if (is_dock_device(bay->handle))
+                       unregister_hotplug_dock_device(bay->handle);
+               acpi_bay_remove_fs(bay);
+               acpi_remove_notify_handler(bay->handle, ACPI_SYSTEM_NOTIFY,
+                       bay_notify);
+               platform_device_unregister(bay->pdev);
+               kfree(bay->name);
+               kfree(bay);
+       }
+
+       acpi_bus_unregister_driver(&acpi_bay_driver);
+}
+
+postcore_initcall(bay_init);
+module_exit(bay_exit);
+
index f9c972b26f4fd49bd883508736ad5c04633b885d..f289fd41e77d5ef1bdb8d4d44359b08a43651930 100644 (file)
@@ -44,7 +44,7 @@ struct acpi_blacklist_item {
        char oem_id[7];
        char oem_table_id[9];
        u32 oem_revision;
-       acpi_table_type table;
+       char *table;
        enum acpi_blacklist_predicates oem_revision_predicate;
        char *reason;
        u32 is_critical_error;
@@ -56,18 +56,18 @@ struct acpi_blacklist_item {
  */
 static struct acpi_blacklist_item acpi_blacklist[] __initdata = {
        /* Compaq Presario 1700 */
-       {"PTLTD ", "  DSDT  ", 0x06040000, ACPI_DSDT, less_than_or_equal,
+       {"PTLTD ", "  DSDT  ", 0x06040000, ACPI_SIG_DSDT, less_than_or_equal,
         "Multiple problems", 1},
        /* Sony FX120, FX140, FX150? */
-       {"SONY  ", "U0      ", 0x20010313, ACPI_DSDT, less_than_or_equal,
+       {"SONY  ", "U0      ", 0x20010313, ACPI_SIG_DSDT, less_than_or_equal,
         "ACPI driver problem", 1},
        /* Compaq Presario 800, Insyde BIOS */
-       {"INT440", "SYSFexxx", 0x00001001, ACPI_DSDT, less_than_or_equal,
+       {"INT440", "SYSFexxx", 0x00001001, ACPI_SIG_DSDT, less_than_or_equal,
         "Does not use _REG to protect EC OpRegions", 1},
        /* IBM 600E - _ADR should return 7, but it returns 1 */
-       {"IBM   ", "TP600E  ", 0x00000105, ACPI_DSDT, less_than_or_equal,
+       {"IBM   ", "TP600E  ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
         "Incorrect _ADR", 1},
-       {"ASUS\0\0", "P2B-S   ", 0, ACPI_DSDT, all_versions,
+       {"ASUS\0\0", "P2B-S   ", 0, ACPI_SIG_DSDT, all_versions,
         "Bogus PCI routing", 1},
 
        {""}
@@ -79,7 +79,7 @@ static int __init blacklist_by_year(void)
 {
        int year = dmi_get_year(DMI_BIOS_DATE);
        /* Doesn't exist? Likely an old system */
-       if (year == -1) 
+       if (year == -1)
                return 1;
        /* 0? Likely a buggy new BIOS */
        if (year == 0)
@@ -103,22 +103,21 @@ int __init acpi_blacklisted(void)
 {
        int i = 0;
        int blacklisted = 0;
-       struct acpi_table_header *table_header;
+       struct acpi_table_header table_header;
 
        while (acpi_blacklist[i].oem_id[0] != '\0') {
-               if (acpi_get_table_header_early
-                   (acpi_blacklist[i].table, &table_header)) {
+               if (acpi_get_table_header(acpi_blacklist[i].table, 0, &table_header)) {
                        i++;
                        continue;
                }
 
-               if (strncmp(acpi_blacklist[i].oem_id, table_header->oem_id, 6)) {
+               if (strncmp(acpi_blacklist[i].oem_id, table_header.oem_id, 6)) {
                        i++;
                        continue;
                }
 
                if (strncmp
-                   (acpi_blacklist[i].oem_table_id, table_header->oem_table_id,
+                   (acpi_blacklist[i].oem_table_id, table_header.oem_table_id,
                     8)) {
                        i++;
                        continue;
@@ -127,14 +126,14 @@ int __init acpi_blacklisted(void)
                if ((acpi_blacklist[i].oem_revision_predicate == all_versions)
                    || (acpi_blacklist[i].oem_revision_predicate ==
                        less_than_or_equal
-                       && table_header->oem_revision <=
+                       && table_header.oem_revision <=
                        acpi_blacklist[i].oem_revision)
                    || (acpi_blacklist[i].oem_revision_predicate ==
                        greater_than_or_equal
-                       && table_header->oem_revision >=
+                       && table_header.oem_revision >=
                        acpi_blacklist[i].oem_revision)
                    || (acpi_blacklist[i].oem_revision_predicate == equal
-                       && table_header->oem_revision ==
+                       && table_header.oem_revision ==
                        acpi_blacklist[i].oem_revision)) {
 
                        printk(KERN_ERR PREFIX
index 766332e4559212aa9c253ddf3723e65367487b96..c26468da429507be4ccef20e3f1b57165d860d85 100644 (file)
@@ -44,9 +44,6 @@ ACPI_MODULE_NAME("acpi_bus")
 extern void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger);
 #endif
 
-struct fadt_descriptor acpi_fadt;
-EXPORT_SYMBOL(acpi_fadt);
-
 struct acpi_device *acpi_root;
 struct proc_dir_entry *acpi_root_dir;
 EXPORT_SYMBOL(acpi_root_dir);
@@ -195,7 +192,7 @@ int acpi_bus_set_power(acpi_handle handle, int state)
 
        if (!device->flags.power_manageable) {
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
-                               device->kobj.name));
+                               device->dev.kobj.name));
                return -ENODEV;
        }
        /*
@@ -582,11 +579,12 @@ static int __init acpi_bus_init_irq(void)
        return 0;
 }
 
+acpi_native_uint acpi_gbl_permanent_mmap;
+
+
 void __init acpi_early_init(void)
 {
        acpi_status status = AE_OK;
-       struct acpi_buffer buffer = { sizeof(acpi_fadt), &acpi_fadt };
-
 
        if (acpi_disabled)
                return;
@@ -597,6 +595,15 @@ void __init acpi_early_init(void)
        if (!acpi_strict)
                acpi_gbl_enable_interpreter_slack = TRUE;
 
+       acpi_gbl_permanent_mmap = 1;
+
+       status = acpi_reallocate_root_table();
+       if (ACPI_FAILURE(status)) {
+               printk(KERN_ERR PREFIX
+                      "Unable to reallocate ACPI tables\n");
+               goto error0;
+       }
+
        status = acpi_initialize_subsystem();
        if (ACPI_FAILURE(status)) {
                printk(KERN_ERR PREFIX
@@ -611,32 +618,25 @@ void __init acpi_early_init(void)
                goto error0;
        }
 
-       /*
-        * Get a separate copy of the FADT for use by other drivers.
-        */
-       status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &buffer);
-       if (ACPI_FAILURE(status)) {
-               printk(KERN_ERR PREFIX "Unable to get the FADT\n");
-               goto error0;
-       }
 #ifdef CONFIG_X86
        if (!acpi_ioapic) {
-               extern acpi_interrupt_flags acpi_sci_flags;
+               extern u8 acpi_sci_flags;
 
                /* compatible (0) means level (3) */
-               if (acpi_sci_flags.trigger == 0)
-                       acpi_sci_flags.trigger = 3;
-
+               if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
+                       acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
+                       acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
+               }
                /* Set PIC-mode SCI trigger type */
-               acpi_pic_sci_set_trigger(acpi_fadt.sci_int,
-                                        acpi_sci_flags.trigger);
+               acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
+                                        (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
        } else {
                extern int acpi_sci_override_gsi;
                /*
-                * now that acpi_fadt is initialized,
+                * now that acpi_gbl_FADT is initialized,
                 * update it with result from INT_SRC_OVR parsing
                 */
-               acpi_fadt.sci_int = acpi_sci_override_gsi;
+               acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
        }
 #endif
 
index ac860583c2034a1fa7a8febbdd91cae0e279debd..c726612fafb606a6c7869666c7cd4af9dcd374c7 100644 (file)
@@ -75,7 +75,7 @@ static int acpi_button_state_open_fs(struct inode *inode, struct file *file);
 static struct acpi_driver acpi_button_driver = {
        .name = ACPI_BUTTON_DRIVER_NAME,
        .class = ACPI_BUTTON_CLASS,
-       .ids = "ACPI_FPB,ACPI_FSB,PNP0C0D,PNP0C0C,PNP0C0E",
+       .ids = "button_power,button_sleep,PNP0C0D,PNP0C0C,PNP0C0E",
        .ops = {
                .add = acpi_button_add,
                .remove = acpi_button_remove,
index 0a1863ec91f3f78092d5c56c8bc2e59c0ed2961b..69a68fd394cf6861c5e8bb9618604523fa08785d 100644 (file)
@@ -167,7 +167,7 @@ static void container_notify_cb(acpi_handle handle, u32 type, void *context)
                        if (ACPI_FAILURE(status) || !device) {
                                result = container_device_add(&device, handle);
                                if (!result)
-                                       kobject_uevent(&device->kobj,
+                                       kobject_uevent(&device->dev.kobj,
                                                       KOBJ_ONLINE);
                                else
                                        printk("Failed to add container\n");
@@ -175,13 +175,13 @@ static void container_notify_cb(acpi_handle handle, u32 type, void *context)
                } else {
                        if (ACPI_SUCCESS(status)) {
                                /* device exist and this is a remove request */
-                               kobject_uevent(&device->kobj, KOBJ_OFFLINE);
+                               kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
                        }
                }
                break;
        case ACPI_NOTIFY_EJECT_REQUEST:
                if (!acpi_bus_get_device(handle, &device) && device) {
-                       kobject_uevent(&device->kobj, KOBJ_OFFLINE);
+                       kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
                }
                break;
        default:
index 35c6af8a83cdd23c5d0d1082eb0465f7858ee290..d48f65a8f6587122be909ff286280203011f6bf5 100644 (file)
 
 #define _COMPONENT             ACPI_SYSTEM_COMPONENT
 ACPI_MODULE_NAME("debug")
-#define ACPI_SYSTEM_FILE_DEBUG_LAYER   "debug_layer"
-#define ACPI_SYSTEM_FILE_DEBUG_LEVEL   "debug_level"
+
 #ifdef MODULE_PARAM_PREFIX
 #undef MODULE_PARAM_PREFIX
 #endif
-#define MODULE_PARAM_PREFIX
-    module_param(acpi_dbg_layer, uint, 0400);
-module_param(acpi_dbg_level, uint, 0400);
+#define MODULE_PARAM_PREFIX "acpi."
 
 struct acpi_dlayer {
        const char *name;
@@ -86,6 +83,60 @@ static const struct acpi_dlevel acpi_debug_levels[] = {
        ACPI_DEBUG_INIT(ACPI_LV_EVENTS),
 };
 
+/* --------------------------------------------------------------------------
+                              FS Interface (/sys)
+   -------------------------------------------------------------------------- */
+static int param_get_debug_layer(char *buffer, struct kernel_param *kp) {
+       int result = 0;
+       int i;
+
+       result = sprintf(buffer, "%-25s\tHex        SET\n", "Description");
+
+       for(i = 0; i <ARRAY_SIZE(acpi_debug_layers); i++) {
+               result += sprintf(buffer+result, "%-25s\t0x%08lX [%c]\n",
+                                       acpi_debug_layers[i].name,
+                                       acpi_debug_layers[i].value,
+                                       (acpi_dbg_layer & acpi_debug_layers[i].value) ? '*' : ' ');
+       }
+       result += sprintf(buffer+result, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
+                                       ACPI_ALL_DRIVERS,
+                                       (acpi_dbg_layer & ACPI_ALL_DRIVERS) ==
+                                       ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer &
+                                       ACPI_ALL_DRIVERS) == 0 ? ' ' : '-');
+       result += sprintf(buffer+result, "--\ndebug_layer = 0x%08X ( * = enabled)\n", acpi_dbg_layer);
+
+       return result;
+}
+
+static int param_get_debug_level(char *buffer, struct kernel_param *kp) {
+       int result = 0;
+       int i;
+
+       result = sprintf(buffer, "%-25s\tHex        SET\n", "Description");
+
+       for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) {
+               result += sprintf(buffer+result, "%-25s\t0x%08lX [%c]\n",
+                                    acpi_debug_levels[i].name,
+                                    acpi_debug_levels[i].value,
+                                    (acpi_dbg_level & acpi_debug_levels[i].
+                                     value) ? '*' : ' ');
+       }
+       result += sprintf(buffer+result, "--\ndebug_level = 0x%08X (* = enabled)\n",
+                            acpi_dbg_level);
+
+       return result;
+}
+
+module_param_call(debug_layer, param_set_uint, param_get_debug_layer, &acpi_dbg_layer, 0644);
+module_param_call(debug_level, param_set_uint, param_get_debug_level, &acpi_dbg_level, 0644);
+
+/* --------------------------------------------------------------------------
+                              FS Interface (/proc)
+   -------------------------------------------------------------------------- */
+#ifdef CONFIG_ACPI_PROCFS
+#define ACPI_SYSTEM_FILE_DEBUG_LAYER   "debug_layer"
+#define ACPI_SYSTEM_FILE_DEBUG_LEVEL           "debug_level"
+
 static int
 acpi_system_read_debug(char *page,
                       char **start, off_t off, int count, int *eof, void *data)
@@ -221,3 +272,4 @@ static int __init acpi_debug_init(void)
 }
 
 subsys_initcall(acpi_debug_init);
+#endif
index a6d77efb41a0437f1a19e36c7c0683749c317e25..f049639bac355db3e6996505037624d0e742e92b 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -133,7 +133,8 @@ acpi_ds_create_buffer_field(union acpi_parse_object *op,
                }
        }
 
-       /* We could put the returned object (Node) on the object stack for later,
+       /*
+        * We could put the returned object (Node) on the object stack for later,
         * but for now, we will put it in the "op" object that the parser uses,
         * so we can get it again at the end of this scope
         */
@@ -514,8 +515,33 @@ acpi_ds_create_bank_field(union acpi_parse_object *op,
 
        /* Third arg is the bank_value */
 
+       /* TBD: This arg is a term_arg, not a constant, and must be evaluated */
+
        arg = arg->common.next;
-       info.bank_value = (u32) arg->common.value.integer;
+
+       /* Currently, only the following constants are supported */
+
+       switch (arg->common.aml_opcode) {
+       case AML_ZERO_OP:
+               info.bank_value = 0;
+               break;
+
+       case AML_ONE_OP:
+               info.bank_value = 1;
+               break;
+
+       case AML_BYTE_OP:
+       case AML_WORD_OP:
+       case AML_DWORD_OP:
+       case AML_QWORD_OP:
+               info.bank_value = (u32) arg->common.value.integer;
+               break;
+
+       default:
+               info.bank_value = 0;
+               ACPI_ERROR((AE_INFO,
+                           "Non-constant BankValue for BankField is not implemented"));
+       }
 
        /* Fourth arg is the field flags */
 
index 1888c055d10f47f73fbbc1cbb175864121eb5970..af923c3885205ef70c7313aee98611a9c3b7656c 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
 #include <acpi/acpi.h>
 #include <acpi/acdispat.h>
 #include <acpi/acnamesp.h>
+#include <acpi/actables.h>
 
 #define _COMPONENT          ACPI_DISPATCHER
 ACPI_MODULE_NAME("dsinit")
@@ -90,7 +91,7 @@ acpi_ds_init_one_object(acpi_handle obj_handle,
         * We are only interested in NS nodes owned by the table that
         * was just loaded
         */
-       if (node->owner_id != info->table_desc->owner_id) {
+       if (node->owner_id != info->owner_id) {
                return (AE_OK);
        }
 
@@ -150,14 +151,21 @@ acpi_ds_init_one_object(acpi_handle obj_handle,
  ******************************************************************************/
 
 acpi_status
-acpi_ds_initialize_objects(struct acpi_table_desc * table_desc,
+acpi_ds_initialize_objects(acpi_native_uint table_index,
                           struct acpi_namespace_node * start_node)
 {
        acpi_status status;
        struct acpi_init_walk_info info;
+       struct acpi_table_header *table;
+       acpi_owner_id owner_id;
 
        ACPI_FUNCTION_TRACE(ds_initialize_objects);
 
+       status = acpi_tb_get_owner_id(table_index, &owner_id);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
        ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
                          "**** Starting initialization of namespace objects ****\n"));
        ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Parsing all Control Methods:"));
@@ -166,7 +174,8 @@ acpi_ds_initialize_objects(struct acpi_table_desc * table_desc,
        info.op_region_count = 0;
        info.object_count = 0;
        info.device_count = 0;
-       info.table_desc = table_desc;
+       info.table_index = table_index;
+       info.owner_id = owner_id;
 
        /* Walk entire namespace from the supplied root */
 
@@ -176,10 +185,14 @@ acpi_ds_initialize_objects(struct acpi_table_desc * table_desc,
                ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
        }
 
+       status = acpi_get_table_by_index(table_index, &table);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
        ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
                              "\nTable [%4.4s](id %4.4X) - %hd Objects with %hd Devices %hd Methods %hd Regions\n",
-                             table_desc->pointer->signature,
-                             table_desc->owner_id, info.object_count,
+                             table->signature, owner_id, info.object_count,
                              info.device_count, info.method_count,
                              info.op_region_count));
 
index cf888add31917aa25a68429e46f700ebe0e462fa..1cbe6190582494ed9f3557c58a17b659644f4979 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -327,7 +327,7 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
        ACPI_FUNCTION_TRACE_PTR(ds_call_control_method, this_walk_state);
 
        ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
-                         "Execute method %p, currentstate=%p\n",
+                         "Calling method %p, currentstate=%p\n",
                          this_walk_state->prev_op, this_walk_state));
 
        /*
@@ -351,49 +351,7 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
                return_ACPI_STATUS(status);
        }
 
-       /*
-        * 1) Parse the method. All "normal" methods are parsed for each execution.
-        * Internal methods (_OSI, etc.) do not require parsing.
-        */
-       if (!(obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY)) {
-
-               /* Create a new walk state for the parse */
-
-               next_walk_state =
-                   acpi_ds_create_walk_state(obj_desc->method.owner_id, op,
-                                             obj_desc, NULL);
-               if (!next_walk_state) {
-                       status = AE_NO_MEMORY;
-                       goto cleanup;
-               }
-
-               /* Create and init a parse tree root */
-
-               op = acpi_ps_create_scope_op();
-               if (!op) {
-                       status = AE_NO_MEMORY;
-                       goto cleanup;
-               }
-
-               status = acpi_ds_init_aml_walk(next_walk_state, op, method_node,
-                                              obj_desc->method.aml_start,
-                                              obj_desc->method.aml_length,
-                                              NULL, 1);
-               if (ACPI_FAILURE(status)) {
-                       acpi_ps_delete_parse_tree(op);
-                       goto cleanup;
-               }
-
-               /* Begin AML parse (deletes next_walk_state) */
-
-               status = acpi_ps_parse_aml(next_walk_state);
-               acpi_ps_delete_parse_tree(op);
-               if (ACPI_FAILURE(status)) {
-                       goto cleanup;
-               }
-       }
-
-       /* 2) Begin method execution. Create a new walk state */
+       /* Begin method parse/execution. Create a new walk state */
 
        next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id,
                                                    NULL, obj_desc, thread);
@@ -424,7 +382,8 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
 
        status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node,
                                       obj_desc->method.aml_start,
-                                      obj_desc->method.aml_length, info, 3);
+                                      obj_desc->method.aml_length, info,
+                                      ACPI_IMODE_EXECUTE);
 
        ACPI_FREE(info);
        if (ACPI_FAILURE(status)) {
@@ -445,8 +404,8 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
        this_walk_state->num_operands = 0;
 
        ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
-                         "Starting nested execution, newstate=%p\n",
-                         next_walk_state));
+                         "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
+                         method_node->name.ascii, next_walk_state));
 
        /* Invoke an internal method if necessary */
 
index 459160ff90585108f6b3689a2b127975500c95b7..ba4626e06a5e816867a9e1a114a3edb485de1fa9 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 72190abb1d59cb9036484b9560cee9a6105f30b3..a474ca2334d536e3cd411adf8799b8897c647f28 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -260,7 +260,7 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
        }
 
        obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
-       op->common.node = (struct acpi_namespace_node *)obj_desc;
+       op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
        return_ACPI_STATUS(AE_OK);
 }
 
@@ -270,7 +270,8 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
  *
  * PARAMETERS:  walk_state      - Current walk state
  *              Op              - Parser object to be translated
- *              package_length  - Number of elements in the package
+ *              element_count   - Number of elements in the package - this is
+ *                                the num_elements argument to Package()
  *              obj_desc_ptr    - Where the ACPI internal object is returned
  *
  * RETURN:      Status
@@ -278,18 +279,29 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
  * DESCRIPTION: Translate a parser Op package object to the equivalent
  *              namespace object
  *
+ * NOTE: The number of elements in the package will be always be the num_elements
+ * count, regardless of the number of elements in the package list. If
+ * num_elements is smaller, only that many package list elements are used.
+ * if num_elements is larger, the Package object is padded out with
+ * objects of type Uninitialized (as per ACPI spec.)
+ *
+ * Even though the ASL compilers do not allow num_elements to be smaller
+ * than the Package list length (for the fixed length package opcode), some
+ * BIOS code modifies the AML on the fly to adjust the num_elements, and
+ * this code compensates for that. This also provides compatibility with
+ * other AML interpreters.
+ *
  ******************************************************************************/
 
 acpi_status
 acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
                                   union acpi_parse_object *op,
-                                  u32 package_length,
+                                  u32 element_count,
                                   union acpi_operand_object **obj_desc_ptr)
 {
        union acpi_parse_object *arg;
        union acpi_parse_object *parent;
        union acpi_operand_object *obj_desc = NULL;
-       u32 package_list_length;
        acpi_status status = AE_OK;
        acpi_native_uint i;
 
@@ -318,32 +330,13 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
                obj_desc->package.node = parent->common.node;
        }
 
-       obj_desc->package.count = package_length;
-
-       /* Count the number of items in the package list */
-
-       arg = op->common.value.arg;
-       arg = arg->common.next;
-       for (package_list_length = 0; arg; package_list_length++) {
-               arg = arg->common.next;
-       }
-
-       /*
-        * The package length (number of elements) will be the greater
-        * of the specified length and the length of the initializer list
-        */
-       if (package_list_length > package_length) {
-               obj_desc->package.count = package_list_length;
-       }
-
        /*
-        * Allocate the pointer array (array of pointers to the
-        * individual objects). Add an extra pointer slot so
-        * that the list is always null terminated.
+        * Allocate the element array (array of pointers to the individual
+        * objects) based on the num_elements parameter. Add an extra pointer slot
+        * so that the list is always null terminated.
         */
        obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
-                                                          obj_desc->package.
-                                                          count +
+                                                          element_count +
                                                           1) * sizeof(void *));
 
        if (!obj_desc->package.elements) {
@@ -351,15 +344,20 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
                return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
+       obj_desc->package.count = element_count;
+
        /*
-        * Initialize all elements of the package
+        * Initialize the elements of the package, up to the num_elements count.
+        * Package is automatically padded with uninitialized (NULL) elements
+        * if num_elements is greater than the package list length. Likewise,
+        * Package is truncated if num_elements is less than the list length.
         */
        arg = op->common.value.arg;
        arg = arg->common.next;
-       for (i = 0; arg; i++) {
+       for (i = 0; arg && (i < element_count); i++) {
                if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
 
-                       /* Object (package or buffer) is already built */
+                       /* This package element is already built, just get it */
 
                        obj_desc->package.elements[i] =
                            ACPI_CAST_PTR(union acpi_operand_object,
@@ -373,8 +371,14 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
                arg = arg->common.next;
        }
 
+       if (!arg) {
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+                                 "Package List length larger than NumElements count (%X), truncated\n",
+                                 element_count));
+       }
+
        obj_desc->package.flags |= AOPOBJ_DATA_VALID;
-       op->common.node = (struct acpi_namespace_node *)obj_desc;
+       op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
        return_ACPI_STATUS(status);
 }
 
@@ -488,8 +492,9 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
                /*
                 * Defer evaluation of Buffer term_arg operand
                 */
-               obj_desc->buffer.node = (struct acpi_namespace_node *)
-                   walk_state->operands[0];
+               obj_desc->buffer.node =
+                   ACPI_CAST_PTR(struct acpi_namespace_node,
+                                 walk_state->operands[0]);
                obj_desc->buffer.aml_start = op->named.data;
                obj_desc->buffer.aml_length = op->named.length;
                break;
@@ -499,8 +504,9 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
                /*
                 * Defer evaluation of Package term_arg operand
                 */
-               obj_desc->package.node = (struct acpi_namespace_node *)
-                   walk_state->operands[0];
+               obj_desc->package.node =
+                   ACPI_CAST_PTR(struct acpi_namespace_node,
+                                 walk_state->operands[0]);
                obj_desc->package.aml_start = op->named.data;
                obj_desc->package.aml_length = op->named.length;
                break;
index 5b974a8fe614162c3ec0242aaabe63fe0fc34290..6c6104a7a247ef6413ed817ea34c24edfaf96dda 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -114,7 +114,7 @@ acpi_ds_execute_arguments(struct acpi_namespace_node *node,
        }
 
        status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
-                                      aml_length, NULL, 1);
+                                      aml_length, NULL, ACPI_IMODE_LOAD_PASS1);
        if (ACPI_FAILURE(status)) {
                acpi_ds_delete_walk_state(walk_state);
                goto cleanup;
@@ -157,7 +157,7 @@ acpi_ds_execute_arguments(struct acpi_namespace_node *node,
        /* Execute the opcode and arguments */
 
        status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
-                                      aml_length, NULL, 3);
+                                      aml_length, NULL, ACPI_IMODE_EXECUTE);
        if (ACPI_FAILURE(status)) {
                acpi_ds_delete_walk_state(walk_state);
                goto cleanup;
index 05230baf5de8ed5e738c93e07a3ecd327a53946a..e4073e05a75ca1475bc39c03c3306028a8728622 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index d7a616c3104e9b8fe87394512b46f2c0ed0fac9c..69693fa07224b8514e5c6c05b3bb7e81a12ce7ed 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -219,7 +219,7 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
        if (!op) {
                status = acpi_ds_load2_begin_op(walk_state, out_op);
                if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
+                       goto error_exit;
                }
 
                op = *out_op;
@@ -238,7 +238,7 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
 
                        status = acpi_ds_scope_stack_pop(walk_state);
                        if (ACPI_FAILURE(status)) {
-                               return_ACPI_STATUS(status);
+                               goto error_exit;
                        }
                }
        }
@@ -287,7 +287,7 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
 
                status = acpi_ds_result_stack_push(walk_state);
                if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
+                       goto error_exit;
                }
 
                status = acpi_ds_exec_begin_control_op(walk_state, op);
@@ -328,6 +328,10 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
        /* Nothing to do here during method execution */
 
        return_ACPI_STATUS(status);
+
+      error_exit:
+       status = acpi_ds_method_error(status, walk_state);
+       return_ACPI_STATUS(status);
 }
 
 /*****************************************************************************
index e3ca7f6539c1318a4a5012ba28481ed6508e58e6..8ab9d1b29a4ce4062f1163ed746a16a258c4cd4f 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -196,6 +196,7 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
                 * one of the opcodes that actually opens a scope
                 */
                switch (node->type) {
+               case ACPI_TYPE_ANY:
                case ACPI_TYPE_LOCAL_SCOPE:     /* Scope  */
                case ACPI_TYPE_DEVICE:
                case ACPI_TYPE_POWER:
@@ -546,6 +547,7 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
        acpi_status status;
        acpi_object_type object_type;
        char *buffer_ptr;
+       u32 flags;
 
        ACPI_FUNCTION_TRACE(ds_load2_begin_op);
 
@@ -669,6 +671,7 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
                 * one of the opcodes that actually opens a scope
                 */
                switch (node->type) {
+               case ACPI_TYPE_ANY:
                case ACPI_TYPE_LOCAL_SCOPE:     /* Scope */
                case ACPI_TYPE_DEVICE:
                case ACPI_TYPE_POWER:
@@ -750,12 +753,20 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
                        break;
                }
 
-               /* Add new entry into namespace */
+               flags = ACPI_NS_NO_UPSEARCH;
+               if (walk_state->pass_number == ACPI_IMODE_EXECUTE) {
+
+                       /* Execution mode, node cannot already exist, node is temporary */
+
+                       flags |= (ACPI_NS_ERROR_IF_FOUND | ACPI_NS_TEMPORARY);
+               }
+
+               /* Add new entry or lookup existing entry */
 
                status =
                    acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
-                                  object_type, ACPI_IMODE_LOAD_PASS2,
-                                  ACPI_NS_NO_UPSEARCH, walk_state, &(node));
+                                  object_type, ACPI_IMODE_LOAD_PASS2, flags,
+                                  walk_state, &node);
                break;
        }
 
index c9228972f5f65a08a1ed6bb464dc255d9413c362..3927c495e4bfef7a12374f80e3aa0f672f2477ad 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 7817e552267962f56a3cd761f073efc9b8088d7e..16c8e38b51ef944de7a1c90c6ae96cf30d61cfee 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 90990a4b65264aa0522bf54017b433df357df4d2..688e83a169068836c9546564bce5c8e669f8f55b 100644 (file)
@@ -615,20 +615,28 @@ static acpi_status
 find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
        acpi_status status;
-       acpi_handle tmp;
+       acpi_handle tmp, parent;
        struct dock_station *ds = context;
        struct dock_dependent_device *dd;
 
        status = acpi_bus_get_ejd(handle, &tmp);
-       if (ACPI_FAILURE(status))
-               return AE_OK;
+       if (ACPI_FAILURE(status)) {
+               /* try the parent device as well */
+               status = acpi_get_parent(handle, &parent);
+               if (ACPI_FAILURE(status))
+                       goto fdd_out;
+               /* see if parent is dependent on dock */
+               status = acpi_bus_get_ejd(parent, &tmp);
+               if (ACPI_FAILURE(status))
+                       goto fdd_out;
+       }
 
        if (tmp == ds->handle) {
                dd = alloc_dock_dependent_device(handle);
                if (dd)
                        add_dock_dependent_device(ds, dd);
        }
-
+fdd_out:
        return AE_OK;
 }
 
index cbdf031f3c09a88cbacbb7e8e28ab737f4304049..743ce27fa0bbf2915c78f4d18fdefecb1fdf133a 100644 (file)
@@ -872,9 +872,8 @@ static int __init acpi_ec_get_real_ecdt(void)
        acpi_status status;
        struct acpi_table_ecdt *ecdt_ptr;
 
-       status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
-                                        (struct acpi_table_header **)
-                                        &ecdt_ptr);
+       status = acpi_get_table(ACPI_SIG_ECDT, 1,
+                               (struct acpi_table_header **)&ecdt_ptr);
        if (ACPI_FAILURE(status))
                return -ENODEV;
 
@@ -891,14 +890,14 @@ static int __init acpi_ec_get_real_ecdt(void)
        if (acpi_ec_mode == EC_INTR) {
                init_waitqueue_head(&ec_ecdt->wait);
        }
-       ec_ecdt->command_addr = ecdt_ptr->ec_control.address;
-       ec_ecdt->data_addr = ecdt_ptr->ec_data.address;
-       ec_ecdt->gpe = ecdt_ptr->gpe_bit;
+       ec_ecdt->command_addr = ecdt_ptr->control.address;
+       ec_ecdt->data_addr = ecdt_ptr->data.address;
+       ec_ecdt->gpe = ecdt_ptr->gpe;
        /* use the GL just to be safe */
        ec_ecdt->global_lock = TRUE;
        ec_ecdt->uid = ecdt_ptr->uid;
 
-       status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle);
+       status = acpi_get_handle(NULL, ecdt_ptr->id, &ec_ecdt->handle);
        if (ACPI_FAILURE(status)) {
                goto error;
        }
index 919037d6acff813f341e5ad3ef96675137dad258..a1f87b5def2abfd6eb0f382b7b7f4b43de0c44ba 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -70,13 +70,6 @@ acpi_status acpi_ev_initialize_events(void)
 
        ACPI_FUNCTION_TRACE(ev_initialize_events);
 
-       /* Make sure we have ACPI tables */
-
-       if (!acpi_gbl_DSDT) {
-               ACPI_WARNING((AE_INFO, "No ACPI tables present!"));
-               return_ACPI_STATUS(AE_NO_ACPI_TABLES);
-       }
-
        /*
         * Initialize the Fixed and General Purpose Events. This is done prior to
         * enabling SCIs to prevent interrupts from occurring before the handlers are
@@ -211,8 +204,7 @@ static acpi_status acpi_ev_fixed_event_initialize(void)
                if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
                        status =
                            acpi_set_register(acpi_gbl_fixed_event_info[i].
-                                             enable_register_id, 0,
-                                             ACPI_MTX_LOCK);
+                                             enable_register_id, 0);
                        if (ACPI_FAILURE(status)) {
                                return (status);
                        }
@@ -298,7 +290,7 @@ static u32 acpi_ev_fixed_event_dispatch(u32 event)
        /* Clear the status bit */
 
        (void)acpi_set_register(acpi_gbl_fixed_event_info[event].
-                               status_register_id, 1, ACPI_MTX_DO_NOT_LOCK);
+                               status_register_id, 1);
 
        /*
         * Make sure we've got a handler.  If not, report an error.
@@ -306,8 +298,7 @@ static u32 acpi_ev_fixed_event_dispatch(u32 event)
         */
        if (NULL == acpi_gbl_fixed_event_handlers[event].handler) {
                (void)acpi_set_register(acpi_gbl_fixed_event_info[event].
-                                       enable_register_id, 0,
-                                       ACPI_MTX_DO_NOT_LOCK);
+                                       enable_register_id, 0);
 
                ACPI_ERROR((AE_INFO,
                            "No installed handler for fixed event [%08X]",
index c76c0583ca6a2a02aa860a28d980d5d940af52bf..dfac3ecc596ebfd9314148d3a54ba80648c9d8b0 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -121,7 +121,9 @@ acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
        if (!gpe_register_info) {
                return_ACPI_STATUS(AE_NOT_EXIST);
        }
-       register_bit = gpe_event_info->register_bit;
+       register_bit = (u8)
+           (1 <<
+            (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number));
 
        /* 1) Disable case.  Simply clear all enable bits */
 
@@ -458,8 +460,7 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
 
                                /* Examine one GPE bit */
 
-                               if (enabled_status_byte &
-                                   acpi_gbl_decode_to8bit[j]) {
+                               if (enabled_status_byte & (1 << j)) {
                                        /*
                                         * Found an active GPE. Dispatch the event to a handler
                                         * or method.
@@ -570,7 +571,7 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
 
                if (ACPI_FAILURE(status)) {
                        ACPI_EXCEPTION((AE_INFO, status,
-                                       "While evaluating GPE method [%4.4s]",
+                                       "while evaluating GPE method [%4.4s]",
                                        acpi_ut_get_node_name
                                        (local_gpe_event_info.dispatch.
                                         method_node)));
@@ -618,6 +619,8 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
 
        ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
 
+       acpi_gpe_count++;
+
        /*
         * If edge-triggered, clear the GPE status bit now.  Note that
         * level-triggered events are cleared after the GPE is serviced.
@@ -633,20 +636,23 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
                }
        }
 
-       /* Save current system state */
-
-       if (acpi_gbl_system_awake_and_running) {
-               ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_SYSTEM_RUNNING);
-       } else {
-               ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_SYSTEM_RUNNING);
+       if (!acpi_gbl_system_awake_and_running) {
+               /*
+                * We just woke up because of a wake GPE. Disable any further GPEs
+                * until we are fully up and running (Only wake GPEs should be enabled
+                * at this time, but we just brute-force disable them all.)
+                * 1) We must disable this particular wake GPE so it won't fire again
+                * 2) We want to disable all wake GPEs, since we are now awake
+                */
+               (void)acpi_hw_disable_all_gpes();
        }
 
        /*
-        * Dispatch the GPE to either an installed handler, or the control
-        * method associated with this GPE (_Lxx or _Exx).
-        * If a handler exists, we invoke it and do not attempt to run the method.
-        * If there is neither a handler nor a method, we disable the level to
-        * prevent further events from coming in here.
+        * Dispatch the GPE to either an installed handler, or the control method
+        * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
+        * it and do not attempt to run the method. If there is neither a handler
+        * nor a method, we disable this GPE to prevent further such pointless
+        * events from firing.
         */
        switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
        case ACPI_GPE_DISPATCH_HANDLER:
@@ -677,8 +683,8 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
        case ACPI_GPE_DISPATCH_METHOD:
 
                /*
-                * Disable GPE, so it doesn't keep firing before the method has a
-                * chance to run.
+                * Disable the GPE, so it doesn't keep firing before the method has a
+                * chance to run (it runs asynchronously with interrupts enabled).
                 */
                status = acpi_ev_disable_gpe(gpe_event_info);
                if (ACPI_FAILURE(status)) {
@@ -711,7 +717,7 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
                            gpe_number));
 
                /*
-                * Disable the GPE.  The GPE will remain disabled until the ACPI
+                * Disable the GPE. The GPE will remain disabled until the ACPI
                 * Core Subsystem is restarted, or a handler is installed.
                 */
                status = acpi_ev_disable_gpe(gpe_event_info);
@@ -726,50 +732,3 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
 
        return_UINT32(ACPI_INTERRUPT_HANDLED);
 }
-
-#ifdef ACPI_GPE_NOTIFY_CHECK
-/*******************************************************************************
- * TBD: NOT USED, PROTOTYPE ONLY AND WILL PROBABLY BE REMOVED
- *
- * FUNCTION:    acpi_ev_check_for_wake_only_gpe
- *
- * PARAMETERS:  gpe_event_info  - info for this GPE
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Determine if a a GPE is "wake-only".
- *
- *              Called from Notify() code in interpreter when a "DeviceWake"
- *              Notify comes in.
- *
- ******************************************************************************/
-
-acpi_status
-acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info)
-{
-       acpi_status status;
-
-       ACPI_FUNCTION_TRACE(ev_check_for_wake_only_gpe);
-
-       if ((gpe_event_info) && /* Only >0 for _Lxx/_Exx */
-           ((gpe_event_info->flags & ACPI_GPE_SYSTEM_MASK) == ACPI_GPE_SYSTEM_RUNNING)) {      /* System state at GPE time */
-               /* This must be a wake-only GPE, disable it */
-
-               status = acpi_ev_disable_gpe(gpe_event_info);
-
-               /* Set GPE to wake-only.  Do not change wake disabled/enabled status */
-
-               acpi_ev_set_gpe_type(gpe_event_info, ACPI_GPE_TYPE_WAKE);
-
-               ACPI_INFO((AE_INFO,
-                          "GPE %p was updated from wake/run to wake-only",
-                          gpe_event_info));
-
-               /* This was a wake-only GPE */
-
-               return_ACPI_STATUS(AE_WAKE_ONLY_GPE);
-       }
-
-       return_ACPI_STATUS(AE_OK);
-}
-#endif
index 95ddeb48bc0f35bbd718a2b9adf2cc4f783c5c65..ad5bc76edf4660a43aa7ea624d9ef92905f020b9 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -529,7 +529,7 @@ static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
 
        /* Install new interrupt handler if not SCI_INT */
 
-       if (interrupt_number != acpi_gbl_FADT->sci_int) {
+       if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
                status = acpi_os_install_interrupt_handler(interrupt_number,
                                                           acpi_ev_gpe_xrupt_handler,
                                                           gpe_xrupt);
@@ -567,7 +567,7 @@ acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
 
        /* We never want to remove the SCI interrupt handler */
 
-       if (gpe_xrupt->interrupt_number == acpi_gbl_FADT->sci_int) {
+       if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
                gpe_xrupt->gpe_block_list_head = NULL;
                return_ACPI_STATUS(AE_OK);
        }
@@ -796,30 +796,31 @@ acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
                    (u8) (gpe_block->block_base_number +
                          (i * ACPI_GPE_REGISTER_WIDTH));
 
-               ACPI_STORE_ADDRESS(this_register->status_address.address,
-                                  (gpe_block->block_address.address + i));
+               this_register->status_address.address =
+                   gpe_block->block_address.address + i;
 
-               ACPI_STORE_ADDRESS(this_register->enable_address.address,
-                                  (gpe_block->block_address.address
-                                   + i + gpe_block->register_count));
+               this_register->enable_address.address =
+                   gpe_block->block_address.address + i +
+                   gpe_block->register_count;
 
-               this_register->status_address.address_space_id =
-                   gpe_block->block_address.address_space_id;
-               this_register->enable_address.address_space_id =
-                   gpe_block->block_address.address_space_id;
-               this_register->status_address.register_bit_width =
+               this_register->status_address.space_id =
+                   gpe_block->block_address.space_id;
+               this_register->enable_address.space_id =
+                   gpe_block->block_address.space_id;
+               this_register->status_address.bit_width =
                    ACPI_GPE_REGISTER_WIDTH;
-               this_register->enable_address.register_bit_width =
+               this_register->enable_address.bit_width =
                    ACPI_GPE_REGISTER_WIDTH;
-               this_register->status_address.register_bit_offset =
+               this_register->status_address.bit_offset =
                    ACPI_GPE_REGISTER_WIDTH;
-               this_register->enable_address.register_bit_offset =
+               this_register->enable_address.bit_offset =
                    ACPI_GPE_REGISTER_WIDTH;
 
                /* Init the event_info for each GPE within this register */
 
                for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
-                       this_event->register_bit = acpi_gbl_decode_to8bit[j];
+                       this_event->gpe_number =
+                           (u8) (this_register->base_gpe_number + j);
                        this_event->register_info = this_register;
                        this_event++;
                }
@@ -1109,11 +1110,12 @@ acpi_status acpi_ev_gpe_initialize(void)
         * If EITHER the register length OR the block address are zero, then that
         * particular block is not supported.
         */
-       if (acpi_gbl_FADT->gpe0_blk_len && acpi_gbl_FADT->xgpe0_blk.address) {
+       if (acpi_gbl_FADT.gpe0_block_length &&
+           acpi_gbl_FADT.xgpe0_block.address) {
 
                /* GPE block 0 exists (has both length and address > 0) */
 
-               register_count0 = (u16) (acpi_gbl_FADT->gpe0_blk_len / 2);
+               register_count0 = (u16) (acpi_gbl_FADT.gpe0_block_length / 2);
 
                gpe_number_max =
                    (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
@@ -1121,9 +1123,9 @@ acpi_status acpi_ev_gpe_initialize(void)
                /* Install GPE Block 0 */
 
                status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
-                                                 &acpi_gbl_FADT->xgpe0_blk,
+                                                 &acpi_gbl_FADT.xgpe0_block,
                                                  register_count0, 0,
-                                                 acpi_gbl_FADT->sci_int,
+                                                 acpi_gbl_FADT.sci_interrupt,
                                                  &acpi_gbl_gpe_fadt_blocks[0]);
 
                if (ACPI_FAILURE(status)) {
@@ -1132,20 +1134,21 @@ acpi_status acpi_ev_gpe_initialize(void)
                }
        }
 
-       if (acpi_gbl_FADT->gpe1_blk_len && acpi_gbl_FADT->xgpe1_blk.address) {
+       if (acpi_gbl_FADT.gpe1_block_length &&
+           acpi_gbl_FADT.xgpe1_block.address) {
 
                /* GPE block 1 exists (has both length and address > 0) */
 
-               register_count1 = (u16) (acpi_gbl_FADT->gpe1_blk_len / 2);
+               register_count1 = (u16) (acpi_gbl_FADT.gpe1_block_length / 2);
 
                /* Check for GPE0/GPE1 overlap (if both banks exist) */
 
                if ((register_count0) &&
-                   (gpe_number_max >= acpi_gbl_FADT->gpe1_base)) {
+                   (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
                        ACPI_ERROR((AE_INFO,
                                    "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1",
-                                   gpe_number_max, acpi_gbl_FADT->gpe1_base,
-                                   acpi_gbl_FADT->gpe1_base +
+                                   gpe_number_max, acpi_gbl_FADT.gpe1_base,
+                                   acpi_gbl_FADT.gpe1_base +
                                    ((register_count1 *
                                      ACPI_GPE_REGISTER_WIDTH) - 1)));
 
@@ -1157,10 +1160,11 @@ acpi_status acpi_ev_gpe_initialize(void)
 
                        status =
                            acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
-                                                    &acpi_gbl_FADT->xgpe1_blk,
+                                                    &acpi_gbl_FADT.xgpe1_block,
                                                     register_count1,
-                                                    acpi_gbl_FADT->gpe1_base,
-                                                    acpi_gbl_FADT->sci_int,
+                                                    acpi_gbl_FADT.gpe1_base,
+                                                    acpi_gbl_FADT.
+                                                    sci_interrupt,
                                                     &acpi_gbl_gpe_fadt_blocks
                                                     [1]);
 
@@ -1173,7 +1177,7 @@ acpi_status acpi_ev_gpe_initialize(void)
                         * GPE0 and GPE1 do not have to be contiguous in the GPE number
                         * space. However, GPE0 always starts at GPE number zero.
                         */
-                       gpe_number_max = acpi_gbl_FADT->gpe1_base +
+                       gpe_number_max = acpi_gbl_FADT.gpe1_base +
                            ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
                }
        }
index bf63edc6608d7732cdec84a92868a71a5277be81..1b784ffe54c3d3c5976a28c1fac2301bb9f47e3d 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -63,14 +63,18 @@ static const char *acpi_notify_value_names[] = {
 };
 #endif
 
+/* Pointer to FACS needed for the Global Lock */
+
+static struct acpi_table_facs *facs = NULL;
+
 /* Local prototypes */
 
 static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context);
 
-static void ACPI_SYSTEM_XFACE acpi_ev_global_lock_thread(void *context);
-
 static u32 acpi_ev_global_lock_handler(void *context);
 
+static acpi_status acpi_ev_remove_global_lock_handler(void);
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_is_notify_object
@@ -280,51 +284,21 @@ static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)
        acpi_ut_delete_generic_state(notify_info);
 }
 
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ev_global_lock_thread
- *
- * PARAMETERS:  Context         - From thread interface, not used
- *
- * RETURN:      None
- *
- * DESCRIPTION: Invoked by SCI interrupt handler upon acquisition of the
- *              Global Lock.  Simply signal all threads that are waiting
- *              for the lock.
- *
- ******************************************************************************/
-
-static void ACPI_SYSTEM_XFACE acpi_ev_global_lock_thread(void *context)
-{
-       acpi_status status;
-
-       /* Signal threads that are waiting for the lock */
-
-       if (acpi_gbl_global_lock_thread_count) {
-
-               /* Send sufficient units to the semaphore */
-
-               status =
-                   acpi_os_signal_semaphore(acpi_gbl_global_lock_semaphore,
-                                            acpi_gbl_global_lock_thread_count);
-               if (ACPI_FAILURE(status)) {
-                       ACPI_ERROR((AE_INFO,
-                                   "Could not signal Global Lock semaphore"));
-               }
-       }
-}
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_global_lock_handler
  *
  * PARAMETERS:  Context         - From thread interface, not used
  *
- * RETURN:      ACPI_INTERRUPT_HANDLED or ACPI_INTERRUPT_NOT_HANDLED
+ * RETURN:      ACPI_INTERRUPT_HANDLED
  *
  * DESCRIPTION: Invoked directly from the SCI handler when a global lock
- *              release interrupt occurs.  Grab the global lock and queue
- *              the global lock thread for execution
+ *              release interrupt occurs. Attempt to acquire the global lock,
+ *              if successful, signal the thread waiting for the lock.
+ *
+ * NOTE: Assumes that the semaphore can be signaled from interrupt level. If
+ * this is not possible for some reason, a separate thread will have to be
+ * scheduled to do this.
  *
  ******************************************************************************/
 
@@ -333,16 +307,24 @@ static u32 acpi_ev_global_lock_handler(void *context)
        u8 acquired = FALSE;
 
        /*
-        * Attempt to get the lock
+        * Attempt to get the lock.
+        *
         * If we don't get it now, it will be marked pending and we will
         * take another interrupt when it becomes free.
         */
-       ACPI_ACQUIRE_GLOBAL_LOCK(acpi_gbl_common_fACS.global_lock, acquired);
+       ACPI_ACQUIRE_GLOBAL_LOCK(facs, acquired);
        if (acquired) {
 
                /* Got the lock, now wake all threads waiting for it */
+
                acpi_gbl_global_lock_acquired = TRUE;
-               acpi_ev_global_lock_thread(context);
+               /* Send a unit to the semaphore */
+
+               if (ACPI_FAILURE(acpi_os_signal_semaphore(
+                       acpi_gbl_global_lock_semaphore, 1))) {
+                       ACPI_ERROR((AE_INFO,
+                                   "Could not signal Global Lock semaphore"));
+               }
        }
 
        return (ACPI_INTERRUPT_HANDLED);
@@ -366,6 +348,13 @@ acpi_status acpi_ev_init_global_lock_handler(void)
 
        ACPI_FUNCTION_TRACE(ev_init_global_lock_handler);
 
+       status =
+           acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
+                                   (struct acpi_table_header **)&facs);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
        acpi_gbl_global_lock_present = TRUE;
        status = acpi_install_fixed_event_handler(ACPI_EVENT_GLOBAL,
                                                  acpi_ev_global_lock_handler,
@@ -389,6 +378,31 @@ acpi_status acpi_ev_init_global_lock_handler(void)
        return_ACPI_STATUS(status);
 }
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_remove_global_lock_handler
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Remove the handler for the Global Lock
+ *
+ ******************************************************************************/
+
+static acpi_status acpi_ev_remove_global_lock_handler(void)
+{
+       acpi_status status;
+
+       ACPI_FUNCTION_TRACE(ev_remove_global_lock_handler);
+
+       acpi_gbl_global_lock_present = FALSE;
+       status = acpi_remove_fixed_event_handler(ACPI_EVENT_GLOBAL,
+                                                acpi_ev_global_lock_handler);
+
+       return_ACPI_STATUS(status);
+}
+
 /******************************************************************************
  *
  * FUNCTION:    acpi_ev_acquire_global_lock
@@ -399,6 +413,16 @@ acpi_status acpi_ev_init_global_lock_handler(void)
  *
  * DESCRIPTION: Attempt to gain ownership of the Global Lock.
  *
+ * MUTEX:       Interpreter must be locked
+ *
+ * Note: The original implementation allowed multiple threads to "acquire" the
+ * Global Lock, and the OS would hold the lock until the last thread had
+ * released it. However, this could potentially starve the BIOS out of the
+ * lock, especially in the case where there is a tight handshake between the
+ * Embedded Controller driver and the BIOS. Therefore, this implementation
+ * allows only one thread to acquire the HW Global Lock at a time, and makes
+ * the global lock appear as a standard mutex on the OS side.
+ *
  *****************************************************************************/
 
 acpi_status acpi_ev_acquire_global_lock(u16 timeout)
@@ -408,53 +432,51 @@ acpi_status acpi_ev_acquire_global_lock(u16 timeout)
 
        ACPI_FUNCTION_TRACE(ev_acquire_global_lock);
 
-#ifndef ACPI_APPLICATION
-       /* Make sure that we actually have a global lock */
-
-       if (!acpi_gbl_global_lock_present) {
-               return_ACPI_STATUS(AE_NO_GLOBAL_LOCK);
+       /*
+        * Only one thread can acquire the GL at a time, the global_lock_mutex
+        * enforces this. This interface releases the interpreter if we must wait.
+        */
+       status = acpi_ex_system_wait_mutex(acpi_gbl_global_lock_mutex, timeout);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
        }
-#endif
-
-       /* One more thread wants the global lock */
-
-       acpi_gbl_global_lock_thread_count++;
 
        /*
-        * If we (OS side vs. BIOS side) have the hardware lock already,
-        * we are done
+        * Make sure that a global lock actually exists. If not, just treat
+        * the lock as a standard mutex.
         */
-       if (acpi_gbl_global_lock_acquired) {
+       if (!acpi_gbl_global_lock_present) {
+               acpi_gbl_global_lock_acquired = TRUE;
                return_ACPI_STATUS(AE_OK);
        }
 
-       /* We must acquire the actual hardware lock */
+       /* Attempt to acquire the actual hardware lock */
 
-       ACPI_ACQUIRE_GLOBAL_LOCK(acpi_gbl_common_fACS.global_lock, acquired);
+       ACPI_ACQUIRE_GLOBAL_LOCK(facs, acquired);
        if (acquired) {
 
                /* We got the lock */
 
                ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
-                                 "Acquired the HW Global Lock\n"));
+                                 "Acquired hardware Global Lock\n"));
 
                acpi_gbl_global_lock_acquired = TRUE;
                return_ACPI_STATUS(AE_OK);
        }
 
        /*
-        * Did not get the lock.  The pending bit was set above, and we must now
+        * Did not get the lock. The pending bit was set above, and we must now
         * wait until we get the global lock released interrupt.
         */
-       ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Waiting for the HW Global Lock\n"));
+       ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Waiting for hardware Global Lock\n"));
 
        /*
-        * Acquire the global lock semaphore first.
-        * Since this wait will block, we must release the interpreter
+        * Wait for handshake with the global lock interrupt handler.
+        * This interface releases the interpreter if we must wait.
         */
-       status =
-           acpi_ex_system_wait_semaphore(acpi_gbl_global_lock_semaphore,
-                                         timeout);
+       status = acpi_ex_system_wait_semaphore(acpi_gbl_global_lock_semaphore,
+                                              ACPI_WAIT_FOREVER);
+
        return_ACPI_STATUS(status);
 }
 
@@ -477,38 +499,39 @@ acpi_status acpi_ev_release_global_lock(void)
 
        ACPI_FUNCTION_TRACE(ev_release_global_lock);
 
-       if (!acpi_gbl_global_lock_thread_count) {
+       /* Lock must be already acquired */
+
+       if (!acpi_gbl_global_lock_acquired) {
                ACPI_WARNING((AE_INFO,
-                             "Cannot release HW Global Lock, it has not been acquired"));
+                             "Cannot release the ACPI Global Lock, it has not been acquired"));
                return_ACPI_STATUS(AE_NOT_ACQUIRED);
        }
 
-       /* One fewer thread has the global lock */
+       if (acpi_gbl_global_lock_present) {
 
-       acpi_gbl_global_lock_thread_count--;
-       if (acpi_gbl_global_lock_thread_count) {
+               /* Allow any thread to release the lock */
 
-               /* There are still some threads holding the lock, cannot release */
+               ACPI_RELEASE_GLOBAL_LOCK(facs, pending);
 
-               return_ACPI_STATUS(AE_OK);
+               /*
+                * If the pending bit was set, we must write GBL_RLS to the control
+                * register
+                */
+               if (pending) {
+                       status =
+                           acpi_set_register(ACPI_BITREG_GLOBAL_LOCK_RELEASE,
+                                             1);
+               }
+
+               ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
+                                 "Released hardware Global Lock\n"));
        }
 
-       /*
-        * No more threads holding lock, we can do the actual hardware
-        * release
-        */
-       ACPI_RELEASE_GLOBAL_LOCK(acpi_gbl_common_fACS.global_lock, pending);
        acpi_gbl_global_lock_acquired = FALSE;
 
-       /*
-        * If the pending bit was set, we must write GBL_RLS to the control
-        * register
-        */
-       if (pending) {
-               status = acpi_set_register(ACPI_BITREG_GLOBAL_LOCK_RELEASE,
-                                          1, ACPI_MTX_LOCK);
-       }
+       /* Release the local GL mutex */
 
+       acpi_os_release_mutex(acpi_gbl_global_lock_mutex);
        return_ACPI_STATUS(status);
 }
 
@@ -558,6 +581,12 @@ void acpi_ev_terminate(void)
                if (ACPI_FAILURE(status)) {
                        ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));
                }
+
+               status = acpi_ev_remove_global_lock_handler();
+               if (ACPI_FAILURE(status)) {
+                       ACPI_ERROR((AE_INFO,
+                                   "Could not remove Global Lock handler"));
+               }
        }
 
        /* Deallocate all handler objects installed within GPE info structs */
index 21caae04fe85f868bcedddfc3e8ebc6a5b2f5c68..e99f0c435a4724006c9d204c69349733b91d763f 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -291,7 +291,6 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
                               u32 bit_width, acpi_integer * value)
 {
        acpi_status status;
-       acpi_status status2;
        acpi_adr_space_handler handler;
        acpi_adr_space_setup region_setup;
        union acpi_operand_object *handler_desc;
@@ -345,7 +344,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
                 * setup will potentially execute control methods
                 * (e.g., _REG method for this region)
                 */
-               acpi_ex_exit_interpreter();
+               acpi_ex_relinquish_interpreter();
 
                status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
                                      handler_desc->address_space.context,
@@ -353,10 +352,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
 
                /* Re-enter the interpreter */
 
-               status2 = acpi_ex_enter_interpreter();
-               if (ACPI_FAILURE(status2)) {
-                       return_ACPI_STATUS(status2);
-               }
+               acpi_ex_reacquire_interpreter();
 
                /* Check for failure of the Region Setup */
 
@@ -409,7 +405,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
                 * exit the interpreter because the handler *might* block -- we don't
                 * know what it will do, so we can't hold the lock on the intepreter.
                 */
-               acpi_ex_exit_interpreter();
+               acpi_ex_relinquish_interpreter();
        }
 
        /* Call the handler */
@@ -430,10 +426,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
                 * We just returned from a non-default handler, we must re-enter the
                 * interpreter
                 */
-               status2 = acpi_ex_enter_interpreter();
-               if (ACPI_FAILURE(status2)) {
-                       return_ACPI_STATUS(status2);
-               }
+               acpi_ex_reacquire_interpreter();
        }
 
        return_ACPI_STATUS(status);
index 203d1359190af2c8d52f694f506eda23d75de4bd..a4fa7e6822a30a7b40e3ff00abff1654af650174 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define _COMPONENT          ACPI_EVENTS
 ACPI_MODULE_NAME("evrgnini")
 
+/* Local prototypes */
+static u8 acpi_ev_match_pci_root_bridge(char *id);
+
+static u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node);
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_system_memory_region_setup
@@ -62,6 +67,7 @@ ACPI_MODULE_NAME("evrgnini")
  * DESCRIPTION: Setup a system_memory operation region
  *
  ******************************************************************************/
+
 acpi_status
 acpi_ev_system_memory_region_setup(acpi_handle handle,
                                   u32 function,
@@ -168,9 +174,9 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
        union acpi_operand_object *handler_obj;
        struct acpi_namespace_node *parent_node;
        struct acpi_namespace_node *pci_root_node;
+       struct acpi_namespace_node *pci_device_node;
        union acpi_operand_object *region_obj =
            (union acpi_operand_object *)handle;
-       struct acpi_device_id object_hID;
 
        ACPI_FUNCTION_TRACE(ev_pci_config_region_setup);
 
@@ -215,45 +221,30 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
 
                pci_root_node = parent_node;
                while (pci_root_node != acpi_gbl_root_node) {
-                       status =
-                           acpi_ut_execute_HID(pci_root_node, &object_hID);
-                       if (ACPI_SUCCESS(status)) {
-                               /*
-                                * Got a valid _HID string, check if this is a PCI root.
-                                * New for ACPI 3.0: check for a PCI Express root also.
-                                */
-                               if (!
-                                   (ACPI_STRNCMP
-                                    (object_hID.value, PCI_ROOT_HID_STRING,
-                                     sizeof(PCI_ROOT_HID_STRING)))
-                                   ||
-                                   !(ACPI_STRNCMP
-                                     (object_hID.value,
-                                      PCI_EXPRESS_ROOT_HID_STRING,
-                                      sizeof(PCI_EXPRESS_ROOT_HID_STRING)))) {
-
-                                       /* Install a handler for this PCI root bridge */
 
-                                       status =
-                                           acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
-                                       if (ACPI_FAILURE(status)) {
-                                               if (status == AE_SAME_HANDLER) {
-                                                       /*
-                                                        * It is OK if the handler is already installed on the root
-                                                        * bridge.  Still need to return a context object for the
-                                                        * new PCI_Config operation region, however.
-                                                        */
-                                                       status = AE_OK;
-                                               } else {
-                                                       ACPI_EXCEPTION((AE_INFO,
-                                                                       status,
-                                                                       "Could not install PciConfig handler for Root Bridge %4.4s",
-                                                                       acpi_ut_get_node_name
-                                                                       (pci_root_node)));
-                                               }
+                       /* Get the _HID/_CID in order to detect a root_bridge */
+
+                       if (acpi_ev_is_pci_root_bridge(pci_root_node)) {
+
+                               /* Install a handler for this PCI root bridge */
+
+                               status = acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
+                               if (ACPI_FAILURE(status)) {
+                                       if (status == AE_SAME_HANDLER) {
+                                               /*
+                                                * It is OK if the handler is already installed on the root
+                                                * bridge.  Still need to return a context object for the
+                                                * new PCI_Config operation region, however.
+                                                */
+                                               status = AE_OK;
+                                       } else {
+                                               ACPI_EXCEPTION((AE_INFO, status,
+                                                               "Could not install PciConfig handler for Root Bridge %4.4s",
+                                                               acpi_ut_get_node_name
+                                                               (pci_root_node)));
                                        }
-                                       break;
                                }
+                               break;
                        }
 
                        pci_root_node = acpi_ns_get_parent_node(pci_root_node);
@@ -282,14 +273,25 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
        /*
         * For PCI_Config space access, we need the segment, bus,
         * device and function numbers.  Acquire them here.
+        *
+        * Find the parent device object. (This allows the operation region to be
+        * within a subscope under the device, such as a control method.)
         */
+       pci_device_node = region_obj->region.node;
+       while (pci_device_node && (pci_device_node->type != ACPI_TYPE_DEVICE)) {
+               pci_device_node = acpi_ns_get_parent_node(pci_device_node);
+       }
+
+       if (!pci_device_node) {
+               return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
+       }
 
        /*
         * Get the PCI device and function numbers from the _ADR object
         * contained in the parent's scope.
         */
        status =
-           acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, parent_node,
+           acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, pci_device_node,
                                            &pci_value);
 
        /*
@@ -327,6 +329,91 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
        return_ACPI_STATUS(AE_OK);
 }
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_match_pci_root_bridge
+ *
+ * PARAMETERS:  Id              - The HID/CID in string format
+ *
+ * RETURN:      TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
+ *
+ * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
+ *
+ ******************************************************************************/
+
+static u8 acpi_ev_match_pci_root_bridge(char *id)
+{
+
+       /*
+        * Check if this is a PCI root.
+        * ACPI 3.0+: check for a PCI Express root also.
+        */
+       if (!(ACPI_STRNCMP(id,
+                          PCI_ROOT_HID_STRING,
+                          sizeof(PCI_ROOT_HID_STRING))) ||
+           !(ACPI_STRNCMP(id,
+                          PCI_EXPRESS_ROOT_HID_STRING,
+                          sizeof(PCI_EXPRESS_ROOT_HID_STRING)))) {
+               return (TRUE);
+       }
+
+       return (FALSE);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_is_pci_root_bridge
+ *
+ * PARAMETERS:  Node            - Device node being examined
+ *
+ * RETURN:      TRUE if device is a PCI/PCI-Express Root Bridge
+ *
+ * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
+ *              examining the _HID and _CID for the device.
+ *
+ ******************************************************************************/
+
+static u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node)
+{
+       acpi_status status;
+       struct acpi_device_id hid;
+       struct acpi_compatible_id_list *cid;
+       acpi_native_uint i;
+
+       /*
+        * Get the _HID and check for a PCI Root Bridge
+        */
+       status = acpi_ut_execute_HID(node, &hid);
+       if (ACPI_FAILURE(status)) {
+               return (FALSE);
+       }
+
+       if (acpi_ev_match_pci_root_bridge(hid.value)) {
+               return (TRUE);
+       }
+
+       /*
+        * The _HID did not match.
+        * Get the _CID and check for a PCI Root Bridge
+        */
+       status = acpi_ut_execute_CID(node, &cid);
+       if (ACPI_FAILURE(status)) {
+               return (FALSE);
+       }
+
+       /* Check all _CIDs in the returned list */
+
+       for (i = 0; i < cid->count; i++) {
+               if (acpi_ev_match_pci_root_bridge(cid->id[i].value)) {
+                       ACPI_FREE(cid);
+                       return (TRUE);
+               }
+       }
+
+       ACPI_FREE(cid);
+       return (FALSE);
+}
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_pci_bar_region_setup
@@ -432,6 +519,9 @@ acpi_ev_default_region_setup(acpi_handle handle,
  *              a PCI address in the scope of the definition.  This address is
  *              required to perform an access to PCI config space.
  *
+ * MUTEX:       Interpreter should be unlocked, because we may run the _REG
+ *              method for this region.
+ *
  ******************************************************************************/
 
 acpi_status
index 8106215ad55457a8898d7caf07b03f760761a022..7e5d15ce2395fd0cec232c0146ef8253c658495a 100644 (file)
@@ -6,7 +6,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -142,9 +142,10 @@ u32 acpi_ev_install_sci_handler(void)
 
        ACPI_FUNCTION_TRACE(ev_install_sci_handler);
 
-       status = acpi_os_install_interrupt_handler((u32) acpi_gbl_FADT->sci_int,
-                                                  acpi_ev_sci_xrupt_handler,
-                                                  acpi_gbl_gpe_xrupt_list_head);
+       status =
+           acpi_os_install_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
+                                             acpi_ev_sci_xrupt_handler,
+                                             acpi_gbl_gpe_xrupt_list_head);
        return_ACPI_STATUS(status);
 }
 
@@ -175,8 +176,9 @@ acpi_status acpi_ev_remove_sci_handler(void)
 
        /* Just let the OS remove the handler and disable the level */
 
-       status = acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT->sci_int,
-                                                 acpi_ev_sci_xrupt_handler);
+       status =
+           acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
+                                            acpi_ev_sci_xrupt_handler);
 
        return_ACPI_STATUS(status);
 }
index 923fd2b46955284a99a2baaa29eeec9c8086e45d..685a103a35873ee920e3d8e1c7783bed2b3ce1fd 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -768,11 +768,9 @@ acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
                return (AE_BAD_PARAMETER);
        }
 
-       status = acpi_ex_enter_interpreter();
-       if (ACPI_FAILURE(status)) {
-               return (status);
-       }
+       /* Must lock interpreter to prevent race conditions */
 
+       acpi_ex_enter_interpreter();
        status = acpi_ev_acquire_global_lock(timeout);
        acpi_ex_exit_interpreter();
 
index 7ebc2efac936ce5a2d3a7005a508fe658580af4c..17065e98807c1921d1fcee9aa51d5423fd84ffd3 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
 #include <acpi/acpi.h>
 #include <acpi/acevents.h>
 #include <acpi/acnamesp.h>
+#include <acpi/actables.h>
 
 #define _COMPONENT          ACPI_EVENTS
 ACPI_MODULE_NAME("evxfevnt")
@@ -65,13 +66,14 @@ acpi_status acpi_enable(void)
 
        ACPI_FUNCTION_TRACE(acpi_enable);
 
-       /* Make sure we have the FADT */
+       /* ACPI tables must be present */
 
-       if (!acpi_gbl_FADT) {
-               ACPI_WARNING((AE_INFO, "No FADT information present!"));
+       if (!acpi_tb_tables_loaded()) {
                return_ACPI_STATUS(AE_NO_ACPI_TABLES);
        }
 
+       /* Check current mode */
+
        if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
                ACPI_DEBUG_PRINT((ACPI_DB_INIT,
                                  "System is already in ACPI mode\n"));
@@ -111,11 +113,6 @@ acpi_status acpi_disable(void)
 
        ACPI_FUNCTION_TRACE(acpi_disable);
 
-       if (!acpi_gbl_FADT) {
-               ACPI_WARNING((AE_INFO, "No FADT information present!"));
-               return_ACPI_STATUS(AE_NO_ACPI_TABLES);
-       }
-
        if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
                ACPI_DEBUG_PRINT((ACPI_DB_INIT,
                                  "System is already in legacy (non-ACPI) mode\n"));
@@ -169,7 +166,7 @@ acpi_status acpi_enable_event(u32 event, u32 flags)
         */
        status =
            acpi_set_register(acpi_gbl_fixed_event_info[event].
-                             enable_register_id, 1, ACPI_MTX_LOCK);
+                             enable_register_id, 1);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
@@ -178,7 +175,7 @@ acpi_status acpi_enable_event(u32 event, u32 flags)
 
        status =
            acpi_get_register(acpi_gbl_fixed_event_info[event].
-                             enable_register_id, &value, ACPI_MTX_LOCK);
+                             enable_register_id, &value);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
@@ -368,14 +365,14 @@ acpi_status acpi_disable_event(u32 event, u32 flags)
         */
        status =
            acpi_set_register(acpi_gbl_fixed_event_info[event].
-                             enable_register_id, 0, ACPI_MTX_LOCK);
+                             enable_register_id, 0);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
 
        status =
            acpi_get_register(acpi_gbl_fixed_event_info[event].
-                             enable_register_id, &value, ACPI_MTX_LOCK);
+                             enable_register_id, &value);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
@@ -421,7 +418,7 @@ acpi_status acpi_clear_event(u32 event)
         */
        status =
            acpi_set_register(acpi_gbl_fixed_event_info[event].
-                             status_register_id, 1, ACPI_MTX_LOCK);
+                             status_register_id, 1);
 
        return_ACPI_STATUS(status);
 }
@@ -510,7 +507,7 @@ acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
 
        status =
            acpi_get_register(acpi_gbl_fixed_event_info[event].
-                             status_register_id, event_status, ACPI_MTX_LOCK);
+                             status_register_id, event_status);
 
        return_ACPI_STATUS(status);
 }
index 83b12a9afa325827fe6148588bc5034efa3ce860..7bf09c5fb2421a5fa42a6a9001115aa3f4490665 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index c8341fa5fe01b87b785432d8ee210392b121e105..25802f302ffe18c00608ff5ae347f79931b57645 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -54,7 +54,7 @@ ACPI_MODULE_NAME("exconfig")
 
 /* Local prototypes */
 static acpi_status
-acpi_ex_add_table(struct acpi_table_header *table,
+acpi_ex_add_table(acpi_native_uint table_index,
                  struct acpi_namespace_node *parent_node,
                  union acpi_operand_object **ddb_handle);
 
@@ -74,12 +74,11 @@ acpi_ex_add_table(struct acpi_table_header *table,
  ******************************************************************************/
 
 static acpi_status
-acpi_ex_add_table(struct acpi_table_header *table,
+acpi_ex_add_table(acpi_native_uint table_index,
                  struct acpi_namespace_node *parent_node,
                  union acpi_operand_object **ddb_handle)
 {
        acpi_status status;
-       struct acpi_table_desc table_info;
        union acpi_operand_object *obj_desc;
 
        ACPI_FUNCTION_TRACE(ex_add_table);
@@ -98,42 +97,16 @@ acpi_ex_add_table(struct acpi_table_header *table,
 
        /* Install the new table into the local data structures */
 
-       ACPI_MEMSET(&table_info, 0, sizeof(struct acpi_table_desc));
-
-       table_info.type = ACPI_TABLE_ID_SSDT;
-       table_info.pointer = table;
-       table_info.length = (acpi_size) table->length;
-       table_info.allocation = ACPI_MEM_ALLOCATED;
-
-       status = acpi_tb_install_table(&table_info);
-       obj_desc->reference.object = table_info.installed_desc;
-
-       if (ACPI_FAILURE(status)) {
-               if (status == AE_ALREADY_EXISTS) {
-
-                       /* Table already exists, just return the handle */
-
-                       return_ACPI_STATUS(AE_OK);
-               }
-               goto cleanup;
-       }
+       obj_desc->reference.object = ACPI_CAST_PTR(void, table_index);
 
        /* Add the table to the namespace */
 
-       status = acpi_ns_load_table(table_info.installed_desc, parent_node);
+       status = acpi_ns_load_table(table_index, parent_node);
        if (ACPI_FAILURE(status)) {
-
-               /* Uninstall table on error */
-
-               (void)acpi_tb_uninstall_table(table_info.installed_desc);
-               goto cleanup;
+               acpi_ut_remove_reference(obj_desc);
+               *ddb_handle = NULL;
        }
 
-       return_ACPI_STATUS(AE_OK);
-
-      cleanup:
-       acpi_ut_remove_reference(obj_desc);
-       *ddb_handle = NULL;
        return_ACPI_STATUS(status);
 }
 
@@ -146,7 +119,7 @@ acpi_ex_add_table(struct acpi_table_header *table,
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Load an ACPI table
+ * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
  *
  ******************************************************************************/
 
@@ -156,33 +129,20 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
 {
        acpi_status status;
        union acpi_operand_object **operand = &walk_state->operands[0];
-       struct acpi_table_header *table;
+       acpi_native_uint table_index;
        struct acpi_namespace_node *parent_node;
        struct acpi_namespace_node *start_node;
        struct acpi_namespace_node *parameter_node = NULL;
        union acpi_operand_object *ddb_handle;
+       struct acpi_table_header *table;
 
        ACPI_FUNCTION_TRACE(ex_load_table_op);
 
-#if 0
-       /*
-        * Make sure that the signature does not match one of the tables that
-        * is already loaded.
-        */
-       status = acpi_tb_match_signature(operand[0]->string.pointer, NULL);
-       if (status == AE_OK) {
-
-               /* Signature matched -- don't allow override */
-
-               return_ACPI_STATUS(AE_ALREADY_EXISTS);
-       }
-#endif
-
-       /* Find the ACPI table */
+       /* Find the ACPI table in the RSDT/XSDT */
 
        status = acpi_tb_find_table(operand[0]->string.pointer,
                                    operand[1]->string.pointer,
-                                   operand[2]->string.pointer, &table);
+                                   operand[2]->string.pointer, &table_index);
        if (ACPI_FAILURE(status)) {
                if (status != AE_NOT_FOUND) {
                        return_ACPI_STATUS(status);
@@ -245,7 +205,7 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
 
        /* Load the table into the namespace */
 
-       status = acpi_ex_add_table(table, parent_node, &ddb_handle);
+       status = acpi_ex_add_table(table_index, parent_node, &ddb_handle);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
@@ -266,9 +226,13 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
                }
        }
 
-       ACPI_INFO((AE_INFO,
-                  "Dynamic OEM Table Load - [%4.4s] OemId [%6.6s] OemTableId [%8.8s]",
-                  table->signature, table->oem_id, table->oem_table_id));
+       status = acpi_get_table_by_index(table_index, &table);
+       if (ACPI_SUCCESS(status)) {
+               ACPI_INFO((AE_INFO,
+                          "Dynamic OEM Table Load - [%4.4s] OemId [%6.6s] OemTableId [%8.8s]",
+                          table->signature, table->oem_id,
+                          table->oem_table_id));
+       }
 
        *return_desc = ddb_handle;
        return_ACPI_STATUS(status);
@@ -278,7 +242,7 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
  *
  * FUNCTION:    acpi_ex_load_op
  *
- * PARAMETERS:  obj_desc        - Region or Field where the table will be
+ * PARAMETERS:  obj_desc        - Region or Buffer/Field where the table will be
  *                                obtained
  *              Target          - Where a handle to the table will be stored
  *              walk_state      - Current state
@@ -287,6 +251,12 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
  *
  * DESCRIPTION: Load an ACPI table from a field or operation region
  *
+ * NOTE: Region Fields (Field, bank_field, index_fields) are resolved to buffer
+ *       objects before this code is reached.
+ *
+ *       If source is an operation region, it must refer to system_memory, as
+ *       per the ACPI specification.
+ *
  ******************************************************************************/
 
 acpi_status
@@ -294,22 +264,26 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
                union acpi_operand_object *target,
                struct acpi_walk_state *walk_state)
 {
-       acpi_status status;
        union acpi_operand_object *ddb_handle;
-       union acpi_operand_object *buffer_desc = NULL;
-       struct acpi_table_header *table_ptr = NULL;
-       acpi_physical_address address;
-       struct acpi_table_header table_header;
-       acpi_integer temp;
-       u32 i;
+       struct acpi_table_desc table_desc;
+       acpi_native_uint table_index;
+       acpi_status status;
 
        ACPI_FUNCTION_TRACE(ex_load_op);
 
-       /* Object can be either an op_region or a Field */
+       ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
+
+       /* Source Object can be either an op_region or a Buffer/Field */
 
        switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
        case ACPI_TYPE_REGION:
 
+               /* Region must be system_memory (from ACPI spec) */
+
+               if (obj_desc->region.space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) {
+                       return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
+               }
+
                ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Region %p %s\n",
                                  obj_desc,
                                  acpi_ut_get_object_type_name(obj_desc)));
@@ -325,113 +299,41 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
                        }
                }
 
-               /* Get the base physical address of the region */
-
-               address = obj_desc->region.address;
-
-               /* Get part of the table header to get the table length */
-
-               table_header.length = 0;
-               for (i = 0; i < 8; i++) {
-                       status =
-                           acpi_ev_address_space_dispatch(obj_desc, ACPI_READ,
-                                                          (acpi_physical_address)
-                                                          (i + address), 8,
-                                                          &temp);
-                       if (ACPI_FAILURE(status)) {
-                               return_ACPI_STATUS(status);
-                       }
-
-                       /* Get the one valid byte of the returned 64-bit value */
-
-                       ACPI_CAST_PTR(u8, &table_header)[i] = (u8) temp;
-               }
-
-               /* Sanity check the table length */
-
-               if (table_header.length < sizeof(struct acpi_table_header)) {
-                       return_ACPI_STATUS(AE_BAD_HEADER);
-               }
-
-               /* Allocate a buffer for the entire table */
-
-               table_ptr = ACPI_ALLOCATE(table_header.length);
-               if (!table_ptr) {
-                       return_ACPI_STATUS(AE_NO_MEMORY);
-               }
-
-               /* Get the entire table from the op region */
-
-               for (i = 0; i < table_header.length; i++) {
-                       status =
-                           acpi_ev_address_space_dispatch(obj_desc, ACPI_READ,
-                                                          (acpi_physical_address)
-                                                          (i + address), 8,
-                                                          &temp);
-                       if (ACPI_FAILURE(status)) {
-                               goto cleanup;
-                       }
-
-                       /* Get the one valid byte of the returned 64-bit value */
-
-                       ACPI_CAST_PTR(u8, table_ptr)[i] = (u8) temp;
-               }
+               table_desc.address = obj_desc->region.address;
+               table_desc.length = obj_desc->region.length;
+               table_desc.flags = ACPI_TABLE_ORIGIN_MAPPED;
                break;
 
-       case ACPI_TYPE_LOCAL_REGION_FIELD:
-       case ACPI_TYPE_LOCAL_BANK_FIELD:
-       case ACPI_TYPE_LOCAL_INDEX_FIELD:
+       case ACPI_TYPE_BUFFER:  /* Buffer or resolved region_field */
 
-               ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Field %p %s\n",
-                                 obj_desc,
-                                 acpi_ut_get_object_type_name(obj_desc)));
+               /* Simply extract the buffer from the buffer object */
 
-               /*
-                * The length of the field must be at least as large as the table.
-                * Read the entire field and thus the entire table.  Buffer is
-                * allocated during the read.
-                */
-               status =
-                   acpi_ex_read_data_from_field(walk_state, obj_desc,
-                                                &buffer_desc);
-               if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
-               }
-
-               table_ptr = ACPI_CAST_PTR(struct acpi_table_header,
-                                         buffer_desc->buffer.pointer);
-
-               /* All done with the buffer_desc, delete it */
-
-               buffer_desc->buffer.pointer = NULL;
-               acpi_ut_remove_reference(buffer_desc);
+               ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
+                                 "Load from Buffer or Field %p %s\n", obj_desc,
+                                 acpi_ut_get_object_type_name(obj_desc)));
 
-               /* Sanity check the table length */
+               table_desc.pointer = ACPI_CAST_PTR(struct acpi_table_header,
+                                                  obj_desc->buffer.pointer);
+               table_desc.length = table_desc.pointer->length;
+               table_desc.flags = ACPI_TABLE_ORIGIN_ALLOCATED;
 
-               if (table_ptr->length < sizeof(struct acpi_table_header)) {
-                       status = AE_BAD_HEADER;
-                       goto cleanup;
-               }
+               obj_desc->buffer.pointer = NULL;
                break;
 
        default:
                return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
        }
 
-       /* The table must be either an SSDT or a PSDT */
-
-       if ((!ACPI_COMPARE_NAME(table_ptr->signature, PSDT_SIG)) &&
-           (!ACPI_COMPARE_NAME(table_ptr->signature, SSDT_SIG))) {
-               ACPI_ERROR((AE_INFO,
-                           "Table has invalid signature [%4.4s], must be SSDT or PSDT",
-                           table_ptr->signature));
-               status = AE_BAD_SIGNATURE;
+       /*
+        * Install the new table into the local data structures
+        */
+       status = acpi_tb_add_table(&table_desc, &table_index);
+       if (ACPI_FAILURE(status)) {
                goto cleanup;
        }
 
-       /* Install the new table into the local data structures */
-
-       status = acpi_ex_add_table(table_ptr, acpi_gbl_root_node, &ddb_handle);
+       status =
+           acpi_ex_add_table(table_index, acpi_gbl_root_node, &ddb_handle);
        if (ACPI_FAILURE(status)) {
 
                /* On error, table_ptr was deallocated above */
@@ -450,13 +352,9 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
                return_ACPI_STATUS(status);
        }
 
-       ACPI_INFO((AE_INFO,
-                  "Dynamic SSDT Load - OemId [%6.6s] OemTableId [%8.8s]",
-                  table_ptr->oem_id, table_ptr->oem_table_id));
-
       cleanup:
        if (ACPI_FAILURE(status)) {
-               ACPI_FREE(table_ptr);
+               acpi_tb_delete_table(&table_desc);
        }
        return_ACPI_STATUS(status);
 }
@@ -477,7 +375,7 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
 {
        acpi_status status = AE_OK;
        union acpi_operand_object *table_desc = ddb_handle;
-       struct acpi_table_desc *table_info;
+       acpi_native_uint table_index;
 
        ACPI_FUNCTION_TRACE(ex_unload_table);
 
@@ -493,19 +391,18 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
-       /* Get the actual table descriptor from the ddb_handle */
+       /* Get the table index from the ddb_handle */
 
-       table_info = (struct acpi_table_desc *)table_desc->reference.object;
+       table_index = (acpi_native_uint) table_desc->reference.object;
 
        /*
         * Delete the entire namespace under this table Node
         * (Offset contains the table_id)
         */
-       acpi_ns_delete_namespace_by_owner(table_info->owner_id);
-
-       /* Delete the table itself */
+       acpi_tb_delete_namespace_by_owner(table_index);
+       acpi_tb_release_owner_id(table_index);
 
-       (void)acpi_tb_uninstall_table(table_info->installed_desc);
+       acpi_tb_set_table_loaded_flag(table_index, FALSE);
 
        /* Delete the table descriptor (ddb_handle) */
 
index 544e81a6a438a349212a61930faa7dc3f92077d4..d470e8b1f4ea6052a60643d45c800ce04aa2c7f6 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 34eec82c1b1e8902cce4eea96f193214771cbc64..7c38528a7e8336ef1ec3c57b2bc5c7741438281f 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -359,8 +359,9 @@ acpi_status acpi_ex_create_table_region(struct acpi_walk_state *walk_state)
        union acpi_operand_object **operand = &walk_state->operands[0];
        union acpi_operand_object *obj_desc;
        struct acpi_namespace_node *node;
-       struct acpi_table_header *table;
        union acpi_operand_object *region_obj2;
+       acpi_native_uint table_index;
+       struct acpi_table_header *table;
 
        ACPI_FUNCTION_TRACE(ex_create_table_region);
 
@@ -380,7 +381,7 @@ acpi_status acpi_ex_create_table_region(struct acpi_walk_state *walk_state)
 
        status = acpi_tb_find_table(operand[1]->string.pointer,
                                    operand[2]->string.pointer,
-                                   operand[3]->string.pointer, &table);
+                                   operand[3]->string.pointer, &table_index);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
@@ -395,6 +396,11 @@ acpi_status acpi_ex_create_table_region(struct acpi_walk_state *walk_state)
        region_obj2 = obj_desc->common.next_object;
        region_obj2->extra.region_context = NULL;
 
+       status = acpi_get_table_by_index(table_index, &table);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
        /* Init the region from the operands */
 
        obj_desc->region.space_id = REGION_DATA_TABLE;
@@ -553,7 +559,8 @@ acpi_ex_create_method(u8 * aml_start,
 
        obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
        if (!obj_desc) {
-               return_ACPI_STATUS(AE_NO_MEMORY);
+               status = AE_NO_MEMORY;
+               goto exit;
        }
 
        /* Save the method's AML pointer and length  */
@@ -576,10 +583,7 @@ acpi_ex_create_method(u8 * aml_start,
         * Get the sync_level. If method is serialized, a mutex will be
         * created for this method when it is parsed.
         */
-       if (acpi_gbl_all_methods_serialized) {
-               obj_desc->method.sync_level = 0;
-               obj_desc->method.method_flags |= AML_METHOD_SERIALIZED;
-       } else if (method_flags & AML_METHOD_SERIALIZED) {
+       if (method_flags & AML_METHOD_SERIALIZED) {
                /*
                 * ACPI 1.0: sync_level = 0
                 * ACPI 2.0: sync_level = sync_level in method declaration
@@ -597,6 +601,7 @@ acpi_ex_create_method(u8 * aml_start,
 
        acpi_ut_remove_reference(obj_desc);
 
+      exit:
        /* Remove a reference to the operand */
 
        acpi_ut_remove_reference(operand[1]);
index 2450943add3334cdc7be48cf3067b6b64c309ff5..68d283fd60e7d254d936b0850a63950a948dbad3 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -59,8 +59,6 @@ static void acpi_ex_out_string(char *title, char *value);
 
 static void acpi_ex_out_pointer(char *title, void *value);
 
-static void acpi_ex_out_address(char *title, acpi_physical_address value);
-
 static void
 acpi_ex_dump_object(union acpi_operand_object *obj_desc,
                    struct acpi_exdump_info *info);
@@ -92,10 +90,11 @@ static struct acpi_exdump_info acpi_ex_dump_string[4] = {
        {ACPI_EXD_STRING, 0, NULL}
 };
 
-static struct acpi_exdump_info acpi_ex_dump_buffer[4] = {
+static struct acpi_exdump_info acpi_ex_dump_buffer[5] = {
        {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_buffer), NULL},
        {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(buffer.length), "Length"},
        {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer.pointer), "Pointer"},
+       {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer.node), "Parent Node"},
        {ACPI_EXD_BUFFER, 0, NULL}
 };
 
@@ -165,8 +164,8 @@ static struct acpi_exdump_info acpi_ex_dump_power[5] = {
 
 static struct acpi_exdump_info acpi_ex_dump_processor[7] = {
        {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_processor), NULL},
-       {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(processor.proc_id), "Processor ID"},
-       {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(processor.length), "Length"},
+       {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(processor.proc_id), "Processor ID"},
+       {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(processor.length), "Length"},
        {ACPI_EXD_ADDRESS, ACPI_EXD_OFFSET(processor.address), "Address"},
        {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(processor.system_notify),
         "System Notify"},
@@ -379,18 +378,12 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
                        break;
 
                case ACPI_EXD_POINTER:
+               case ACPI_EXD_ADDRESS:
 
                        acpi_ex_out_pointer(name,
                                            *ACPI_CAST_PTR(void *, target));
                        break;
 
-               case ACPI_EXD_ADDRESS:
-
-                       acpi_ex_out_address(name,
-                                           *ACPI_CAST_PTR
-                                           (acpi_physical_address, target));
-                       break;
-
                case ACPI_EXD_STRING:
 
                        acpi_ut_print_string(obj_desc->string.pointer,
@@ -834,16 +827,6 @@ static void acpi_ex_out_pointer(char *title, void *value)
        acpi_os_printf("%20s : %p\n", title, value);
 }
 
-static void acpi_ex_out_address(char *title, acpi_physical_address value)
-{
-
-#if ACPI_MACHINE_WIDTH == 16
-       acpi_os_printf("%20s : %p\n", title, value);
-#else
-       acpi_os_printf("%20s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
-#endif
-}
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ex_dump_namespace_node
index 9ea9c3a67ca91c69a772a5291eec3cb0d0abe5ce..2d88a3d8d1ad5f75815c5b5fcf0f0aec9ef48927 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 40f0bee6faa57a25989e28573d1e2ca6b953013a..65a48b6170ee3c9803771cad7a58c2caecc04b77 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -257,14 +257,13 @@ acpi_ex_access_region(union acpi_operand_object *obj_desc,
        }
 
        ACPI_DEBUG_PRINT_RAW((ACPI_DB_BFIELD,
-                             " Region [%s:%X], Width %X, ByteBase %X, Offset %X at %8.8X%8.8X\n",
+                             " Region [%s:%X], Width %X, ByteBase %X, Offset %X at %p\n",
                              acpi_ut_get_region_name(rgn_desc->region.
                                                      space_id),
                              rgn_desc->region.space_id,
                              obj_desc->common_field.access_byte_width,
                              obj_desc->common_field.base_byte_offset,
-                             field_datum_byte_offset,
-                             ACPI_FORMAT_UINT64(address)));
+                             field_datum_byte_offset, (void *)address));
 
        /* Invoke the appropriate address_space/op_region handler */
 
index bd98aab017cf577768ad09f41b0634a3f8d3dc7f..f13d1cec2d6db1a3d277a916e10ea0f8564d4dda 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index bf90f04f2c605218effa13adf83273d056903e37..5101bad5baf8b3074d29156b8a47444b286e90f8 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
 
 #include <acpi/acpi.h>
 #include <acpi/acinterp.h>
+#include <acpi/acevents.h>
 
 #define _COMPONENT          ACPI_EXECUTER
 ACPI_MODULE_NAME("exmutex")
@@ -150,7 +151,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
-       /* Sanity check -- we must have a valid thread ID */
+       /* Sanity check: we must have a valid thread ID */
 
        if (!walk_state->thread) {
                ACPI_ERROR((AE_INFO,
@@ -174,24 +175,28 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
        /* Support for multiple acquires by the owning thread */
 
        if (obj_desc->mutex.owner_thread) {
-
-               /* Special case for Global Lock, allow all threads */
-
-               if ((obj_desc->mutex.owner_thread->thread_id ==
-                    walk_state->thread->thread_id) ||
-                   (obj_desc->mutex.os_mutex == ACPI_GLOBAL_LOCK)) {
+               if (obj_desc->mutex.owner_thread->thread_id ==
+                   walk_state->thread->thread_id) {
                        /*
-                        * The mutex is already owned by this thread,
-                        * just increment the acquisition depth
+                        * The mutex is already owned by this thread, just increment the
+                        * acquisition depth
                         */
                        obj_desc->mutex.acquisition_depth++;
                        return_ACPI_STATUS(AE_OK);
                }
        }
 
-       /* Acquire the mutex, wait if necessary */
+       /* Acquire the mutex, wait if necessary. Special case for Global Lock */
+
+       if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) {
+               status =
+                   acpi_ev_acquire_global_lock((u16) time_desc->integer.value);
+       } else {
+               status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex,
+                                                  (u16) time_desc->integer.
+                                                  value);
+       }
 
-       status = acpi_ex_system_acquire_mutex(time_desc, obj_desc);
        if (ACPI_FAILURE(status)) {
 
                /* Includes failure from a timeout on time_desc */
@@ -211,7 +216,6 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
        /* Link the mutex to the current thread for force-unlock at method exit */
 
        acpi_ex_link_mutex(obj_desc, walk_state->thread);
-
        return_ACPI_STATUS(AE_OK);
 }
 
@@ -232,7 +236,7 @@ acpi_status
 acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
                      struct acpi_walk_state *walk_state)
 {
-       acpi_status status;
+       acpi_status status = AE_OK;
 
        ACPI_FUNCTION_TRACE(ex_release_mutex);
 
@@ -249,7 +253,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
                return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED);
        }
 
-       /* Sanity check -- we must have a valid thread ID */
+       /* Sanity check: we must have a valid thread ID */
 
        if (!walk_state->thread) {
                ACPI_ERROR((AE_INFO,
@@ -264,7 +268,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
         */
        if ((obj_desc->mutex.owner_thread->thread_id !=
             walk_state->thread->thread_id)
-           && (obj_desc->mutex.os_mutex != ACPI_GLOBAL_LOCK)) {
+           && (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) {
                ACPI_ERROR((AE_INFO,
                            "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
                            (unsigned long)walk_state->thread->thread_id,
@@ -274,8 +278,8 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
        }
 
        /*
-        * The sync level of the mutex must be less than or
-        * equal to the current sync level
+        * The sync level of the mutex must be less than or equal to the current
+        * sync level
         */
        if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) {
                ACPI_ERROR((AE_INFO,
@@ -298,11 +302,15 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
 
        acpi_ex_unlink_mutex(obj_desc);
 
-       /* Release the mutex */
+       /* Release the mutex, special case for Global Lock */
 
-       status = acpi_ex_system_release_mutex(obj_desc);
+       if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) {
+               status = acpi_ev_release_global_lock();
+       } else {
+               acpi_os_release_mutex(obj_desc->mutex.os_mutex);
+       }
 
-       /* Update the mutex and walk state, restore sync_level before acquire */
+       /* Update the mutex and restore sync_level */
 
        obj_desc->mutex.owner_thread = NULL;
        walk_state->thread->current_sync_level =
@@ -321,39 +329,49 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
  *
  * DESCRIPTION: Release all mutexes held by this thread
  *
+ * NOTE: This function is called as the thread is exiting the interpreter.
+ * Mutexes are not released when an individual control method is exited, but
+ * only when the parent thread actually exits the interpreter. This allows one
+ * method to acquire a mutex, and a different method to release it, as long as
+ * this is performed underneath a single parent control method.
+ *
  ******************************************************************************/
 
 void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
 {
        union acpi_operand_object *next = thread->acquired_mutex_list;
-       union acpi_operand_object *this;
-       acpi_status status;
+       union acpi_operand_object *obj_desc;
 
        ACPI_FUNCTION_ENTRY();
 
        /* Traverse the list of owned mutexes, releasing each one */
 
        while (next) {
-               this = next;
-               next = this->mutex.next;
+               obj_desc = next;
+               next = obj_desc->mutex.next;
+
+               obj_desc->mutex.prev = NULL;
+               obj_desc->mutex.next = NULL;
+               obj_desc->mutex.acquisition_depth = 0;
+
+               /* Release the mutex, special case for Global Lock */
 
-               this->mutex.acquisition_depth = 1;
-               this->mutex.prev = NULL;
-               this->mutex.next = NULL;
+               if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) {
 
-               /* Release the mutex */
+                       /* Ignore errors */
 
-               status = acpi_ex_system_release_mutex(this);
-               if (ACPI_FAILURE(status)) {
-                       continue;
+                       (void)acpi_ev_release_global_lock();
+               } else {
+                       acpi_os_release_mutex(obj_desc->mutex.os_mutex);
                }
 
                /* Mark mutex unowned */
 
-               this->mutex.owner_thread = NULL;
+               obj_desc->mutex.owner_thread = NULL;
 
                /* Update Thread sync_level (Last mutex is the important one) */
 
-               thread->current_sync_level = this->mutex.original_sync_level;
+               thread->current_sync_level =
+                   obj_desc->mutex.original_sync_level;
        }
 }
index d3d70364626ccf26732fa2355027bd9347beb558..1ee4fb1175c680f5b8b7d3f706e467c5b73683ba 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 6374d8be88e0a5feb21d1fe2f73e100f915e6647..252f10acbbccc3436a4def9c1ac305509fc6f0e1 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -104,9 +104,7 @@ acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
                        status = AE_NO_MEMORY;
                        goto cleanup;
                }
-#if ACPI_MACHINE_WIDTH != 16
                return_desc->integer.value = acpi_os_get_timer();
-#endif
                break;
 
        default:                /*  Unknown opcode  */
index 7d2cbc113160f77a2f56dd77d242bb159227d1a5..17e652e653799f97c9d88de6fd9e3d1a166f0ce3 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index e2d945dfd5098b4015c652c3b36180e1020b7501..7fe67cf82cee016e47f3699aee0b2eb1d57ab407 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index f0c0ba6eb408999f0a66b4ca3b46b9f3697a8a55..bd80a9cb3d6529bce2a2804800639e4d0578d93c 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 44d064f427b907d0b67f6a80f77779c008dbb88e..a6696621ff1b567d18652e4a31e8a86d574e99ef 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 3cc97ba48b364262ccc47fe0a11bfa9ee7bf0345..2e9ce94798c7dbb59fd628f493bb0970cde6ed85 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -155,16 +155,15 @@ acpi_ex_system_memory_space_handler(u32 function,
 
                /* Create a new mapping starting at the address given */
 
-               status = acpi_os_map_memory(address, window_size,
-                                           (void **)&mem_info->
-                                           mapped_logical_address);
-               if (ACPI_FAILURE(status)) {
+               mem_info->mapped_logical_address =
+                   acpi_os_map_memory((acpi_native_uint) address, window_size);
+               if (!mem_info->mapped_logical_address) {
                        ACPI_ERROR((AE_INFO,
                                    "Could not map memory at %8.8X%8.8X, size %X",
                                    ACPI_FORMAT_UINT64(address),
                                    (u32) window_size));
                        mem_info->mapped_length = 0;
-                       return_ACPI_STATUS(status);
+                       return_ACPI_STATUS(AE_NO_MEMORY);
                }
 
                /* Save the physical address and mapping size */
@@ -210,11 +209,10 @@ acpi_ex_system_memory_space_handler(u32 function,
                        *value = (acpi_integer) ACPI_GET32(logical_addr_ptr);
                        break;
 
-#if ACPI_MACHINE_WIDTH != 16
                case 64:
                        *value = (acpi_integer) ACPI_GET64(logical_addr_ptr);
                        break;
-#endif
+
                default:
                        /* bit_width was already validated */
                        break;
@@ -236,11 +234,9 @@ acpi_ex_system_memory_space_handler(u32 function,
                        ACPI_SET32(logical_addr_ptr) = (u32) * value;
                        break;
 
-#if ACPI_MACHINE_WIDTH != 16
                case 64:
                        ACPI_SET64(logical_addr_ptr) = (u64) * value;
                        break;
-#endif
 
                default:
                        /* bit_width was already validated */
index 3089b05a13687553258c5c0bf8d2288b313ee0b7..2b3a01cc4929e2bf9b0dbd7c2f22707a89d3fdd2 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 6499de8780173f44e19a41ef7bf2ac9fb30d9531..6c64e55dab0e467178948fb8082fc7f9e4e89041 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -141,7 +141,7 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
        acpi_status status = AE_OK;
        union acpi_operand_object *stack_desc;
        void *temp_node;
-       union acpi_operand_object *obj_desc;
+       union acpi_operand_object *obj_desc = NULL;
        u16 opcode;
 
        ACPI_FUNCTION_TRACE(ex_resolve_object_to_value);
@@ -299,8 +299,6 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
                status = acpi_ds_get_package_arguments(stack_desc);
                break;
 
-               /* These cases may never happen here, but just in case.. */
-
        case ACPI_TYPE_BUFFER_FIELD:
        case ACPI_TYPE_LOCAL_REGION_FIELD:
        case ACPI_TYPE_LOCAL_BANK_FIELD:
@@ -314,6 +312,10 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
                status =
                    acpi_ex_read_data_from_field(walk_state, stack_desc,
                                                 &obj_desc);
+
+               /* Remove a reference to the original operand, then override */
+
+               acpi_ut_remove_reference(*stack_ptr);
                *stack_ptr = (void *)obj_desc;
                break;
 
index 4c93d0972333535ba31a9a7fe4c552724dfbf3c3..ba761862a5990c85551c41a9bebaeeedd24b67eb 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -611,22 +611,20 @@ acpi_ex_resolve_operands(u16 opcode,
                        }
                        goto next_operand;
 
-               case ARGI_REGION_OR_FIELD:
+               case ARGI_REGION_OR_BUFFER:     /* Used by Load() only */
 
-                       /* Need an operand of type REGION or a FIELD in a region */
+                       /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
 
                        switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
+                       case ACPI_TYPE_BUFFER:
                        case ACPI_TYPE_REGION:
-                       case ACPI_TYPE_LOCAL_REGION_FIELD:
-                       case ACPI_TYPE_LOCAL_BANK_FIELD:
-                       case ACPI_TYPE_LOCAL_INDEX_FIELD:
 
                                /* Valid operand */
                                break;
 
                        default:
                                ACPI_ERROR((AE_INFO,
-                                           "Needed [Region/RegionField], found [%s] %p",
+                                           "Needed [Region/Buffer], found [%s] %p",
                                            acpi_ut_get_object_type_name
                                            (obj_desc), obj_desc));
 
index 0456405ba0198a36a7505d0e22b14b4b9a396867..f4b69a63782091ffe4ba226c397793344bf6aede 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 591aaf0e18b3e0b0d5f58d73934f34427a4381dd..1d622c625c6406bc91a7e7b0f7542e4be107f955 100644 (file)
@@ -7,7 +7,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 99ebe5adfcda3b585c0eca2c141bc26cfa28d322..8233d40178eed88a5d6863578ff9f78451a7b2ea 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 28aef3e69ecceeff2a2855854d3f59167ea905c5..9460baff30328f4c5565e2c5d671eabfdf4f634c 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -66,7 +66,6 @@ ACPI_MODULE_NAME("exsystem")
 acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
 {
        acpi_status status;
-       acpi_status status2;
 
        ACPI_FUNCTION_TRACE(ex_system_wait_semaphore);
 
@@ -79,7 +78,7 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
 
                /* We must wait, so unlock the interpreter */
 
-               acpi_ex_exit_interpreter();
+               acpi_ex_relinquish_interpreter();
 
                status = acpi_os_wait_semaphore(semaphore, 1, timeout);
 
@@ -89,13 +88,7 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
 
                /* Reacquire the interpreter */
 
-               status2 = acpi_ex_enter_interpreter();
-               if (ACPI_FAILURE(status2)) {
-
-                       /* Report fatal error, could not acquire interpreter */
-
-                       return_ACPI_STATUS(status2);
-               }
+               acpi_ex_reacquire_interpreter();
        }
 
        return_ACPI_STATUS(status);
@@ -119,7 +112,6 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
 acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
 {
        acpi_status status;
-       acpi_status status2;
 
        ACPI_FUNCTION_TRACE(ex_system_wait_mutex);
 
@@ -132,7 +124,7 @@ acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
 
                /* We must wait, so unlock the interpreter */
 
-               acpi_ex_exit_interpreter();
+               acpi_ex_relinquish_interpreter();
 
                status = acpi_os_acquire_mutex(mutex, timeout);
 
@@ -142,13 +134,7 @@ acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
 
                /* Reacquire the interpreter */
 
-               status2 = acpi_ex_enter_interpreter();
-               if (ACPI_FAILURE(status2)) {
-
-                       /* Report fatal error, could not acquire interpreter */
-
-                       return_ACPI_STATUS(status2);
-               }
+               acpi_ex_reacquire_interpreter();
        }
 
        return_ACPI_STATUS(status);
@@ -209,96 +195,18 @@ acpi_status acpi_ex_system_do_stall(u32 how_long)
 
 acpi_status acpi_ex_system_do_suspend(acpi_integer how_long)
 {
-       acpi_status status;
-
        ACPI_FUNCTION_ENTRY();
 
        /* Since this thread will sleep, we must release the interpreter */
 
-       acpi_ex_exit_interpreter();
+       acpi_ex_relinquish_interpreter();
 
        acpi_os_sleep(how_long);
 
        /* And now we must get the interpreter again */
 
-       status = acpi_ex_enter_interpreter();
-       return (status);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ex_system_acquire_mutex
- *
- * PARAMETERS:  time_desc       - Maximum time to wait for the mutex
- *              obj_desc        - The object descriptor for this op
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Provides an access point to perform synchronization operations
- *              within the AML.  This function will cause a lock to be generated
- *              for the Mutex pointed to by obj_desc.
- *
- ******************************************************************************/
-
-acpi_status
-acpi_ex_system_acquire_mutex(union acpi_operand_object * time_desc,
-                            union acpi_operand_object * obj_desc)
-{
-       acpi_status status = AE_OK;
-
-       ACPI_FUNCTION_TRACE_PTR(ex_system_acquire_mutex, obj_desc);
-
-       if (!obj_desc) {
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-       }
-
-       /* Support for the _GL_ Mutex object -- go get the global lock */
-
-       if (obj_desc->mutex.os_mutex == ACPI_GLOBAL_LOCK) {
-               status =
-                   acpi_ev_acquire_global_lock((u16) time_desc->integer.value);
-               return_ACPI_STATUS(status);
-       }
-
-       status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex,
-                                          (u16) time_desc->integer.value);
-       return_ACPI_STATUS(status);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ex_system_release_mutex
- *
- * PARAMETERS:  obj_desc        - The object descriptor for this op
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Provides an access point to perform synchronization operations
- *              within the AML.  This operation is a request to release a
- *              previously acquired Mutex.  If the Mutex variable is set then
- *              it will be decremented.
- *
- ******************************************************************************/
-
-acpi_status acpi_ex_system_release_mutex(union acpi_operand_object *obj_desc)
-{
-       acpi_status status = AE_OK;
-
-       ACPI_FUNCTION_TRACE(ex_system_release_mutex);
-
-       if (!obj_desc) {
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-       }
-
-       /* Support for the _GL_ Mutex object -- release the global lock */
-
-       if (obj_desc->mutex.os_mutex == ACPI_GLOBAL_LOCK) {
-               status = acpi_ev_release_global_lock();
-               return_ACPI_STATUS(status);
-       }
-
-       acpi_os_release_mutex(obj_desc->mutex.os_mutex);
-       return_ACPI_STATUS(AE_OK);
+       acpi_ex_reacquire_interpreter();
+       return (AE_OK);
 }
 
 /*******************************************************************************
@@ -314,7 +222,7 @@ acpi_status acpi_ex_system_release_mutex(union acpi_operand_object *obj_desc)
  *
  ******************************************************************************/
 
-acpi_status acpi_ex_system_signal_event(union acpi_operand_object *obj_desc)
+acpi_status acpi_ex_system_signal_event(union acpi_operand_object * obj_desc)
 {
        acpi_status status = AE_OK;
 
index 982c8b65876f33d562294f60160564eb3f5a4f00..6b0aeccbb69b3f59738d5a9dd22fe875a1a2d018 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -76,14 +76,15 @@ static u32 acpi_ex_digits_needed(acpi_integer value, u32 base);
  *
  * PARAMETERS:  None
  *
- * RETURN:      Status
+ * RETURN:      None
  *
- * DESCRIPTION: Enter the interpreter execution region.  Failure to enter
- *              the interpreter region is a fatal system error
+ * DESCRIPTION: Enter the interpreter execution region. Failure to enter
+ *              the interpreter region is a fatal system error. Used in
+ *              conjunction with exit_interpreter.
  *
  ******************************************************************************/
 
-acpi_status acpi_ex_enter_interpreter(void)
+void acpi_ex_enter_interpreter(void)
 {
        acpi_status status;
 
@@ -91,31 +92,55 @@ acpi_status acpi_ex_enter_interpreter(void)
 
        status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
        if (ACPI_FAILURE(status)) {
-               ACPI_ERROR((AE_INFO, "Could not acquire interpreter mutex"));
+               ACPI_ERROR((AE_INFO,
+                           "Could not acquire AML Interpreter mutex"));
        }
 
-       return_ACPI_STATUS(status);
+       return_VOID;
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_ex_exit_interpreter
+ * FUNCTION:    acpi_ex_reacquire_interpreter
  *
  * PARAMETERS:  None
  *
  * RETURN:      None
  *
- * DESCRIPTION: Exit the interpreter execution region
+ * DESCRIPTION: Reacquire the interpreter execution region from within the
+ *              interpreter code. Failure to enter the interpreter region is a
+ *              fatal system error. Used in  conjuction with
+ *              relinquish_interpreter
+ *
+ ******************************************************************************/
+
+void acpi_ex_reacquire_interpreter(void)
+{
+       ACPI_FUNCTION_TRACE(ex_reacquire_interpreter);
+
+       /*
+        * If the global serialized flag is set, do not release the interpreter,
+        * since it was not actually released by acpi_ex_relinquish_interpreter.
+        * This forces the interpreter to be single threaded.
+        */
+       if (!acpi_gbl_all_methods_serialized) {
+               acpi_ex_enter_interpreter();
+       }
+
+       return_VOID;
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ex_exit_interpreter
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      None
  *
- * Cases where the interpreter is unlocked:
- *      1) Completion of the execution of a control method
- *      2) Method blocked on a Sleep() AML opcode
- *      3) Method blocked on an Acquire() AML opcode
- *      4) Method blocked on a Wait() AML opcode
- *      5) Method blocked to acquire the global lock
- *      6) Method blocked to execute a serialized control method that is
- *          already executing
- *      7) About to invoke a user-installed opregion handler
+ * DESCRIPTION: Exit the interpreter execution region. This is the top level
+ *              routine used to exit the interpreter when all processing has
+ *              been completed.
  *
  ******************************************************************************/
 
@@ -127,7 +152,46 @@ void acpi_ex_exit_interpreter(void)
 
        status = acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
        if (ACPI_FAILURE(status)) {
-               ACPI_ERROR((AE_INFO, "Could not release interpreter mutex"));
+               ACPI_ERROR((AE_INFO,
+                           "Could not release AML Interpreter mutex"));
+       }
+
+       return_VOID;
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ex_relinquish_interpreter
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Exit the interpreter execution region, from within the
+ *              interpreter - before attempting an operation that will possibly
+ *              block the running thread.
+ *
+ * Cases where the interpreter is unlocked internally
+ *      1) Method to be blocked on a Sleep() AML opcode
+ *      2) Method to be blocked on an Acquire() AML opcode
+ *      3) Method to be blocked on a Wait() AML opcode
+ *      4) Method to be blocked to acquire the global lock
+ *      5) Method to be blocked waiting to execute a serialized control method
+ *          that is currently executing
+ *      6) About to invoke a user-installed opregion handler
+ *
+ ******************************************************************************/
+
+void acpi_ex_relinquish_interpreter(void)
+{
+       ACPI_FUNCTION_TRACE(ex_relinquish_interpreter);
+
+       /*
+        * If the global serialized flag is set, do not release the interpreter.
+        * This forces the interpreter to be single threaded.
+        */
+       if (!acpi_gbl_all_methods_serialized) {
+               acpi_ex_exit_interpreter();
        }
 
        return_VOID;
@@ -141,8 +205,8 @@ void acpi_ex_exit_interpreter(void)
  *
  * RETURN:      none
  *
- * DESCRIPTION: Truncate a number to 32-bits if the currently executing method
- *              belongs to a 32-bit ACPI table.
+ * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
+ *              32-bit, as determined by the revision of the DSDT.
  *
  ******************************************************************************/
 
index f305a826ca2df46c1db4b1bb940c987d885e3672..af22fdf73413a5c342b7ac5ae8f1aae9234a5254 100644 (file)
@@ -48,8 +48,8 @@ MODULE_LICENSE("GPL");
 
 static int acpi_fan_add(struct acpi_device *device);
 static int acpi_fan_remove(struct acpi_device *device, int type);
-static int acpi_fan_suspend(struct acpi_device *device, int state);
-static int acpi_fan_resume(struct acpi_device *device, int state);
+static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state);
+static int acpi_fan_resume(struct acpi_device *device);
 
 static struct acpi_driver acpi_fan_driver = {
        .name = ACPI_FAN_DRIVER_NAME,
@@ -237,7 +237,7 @@ static int acpi_fan_remove(struct acpi_device *device, int type)
        return 0;
 }
 
-static int acpi_fan_suspend(struct acpi_device *device, int state)
+static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state)
 {
        if (!device)
                return -EINVAL;
@@ -247,7 +247,7 @@ static int acpi_fan_suspend(struct acpi_device *device, int state)
        return AE_OK;
 }
 
-static int acpi_fan_resume(struct acpi_device *device, int state)
+static int acpi_fan_resume(struct acpi_device *device)
 {
        int result = 0;
        int power_state = 0;
index 8a0324b43e53869adcf9f98a29c513a38b1c2d15..7b6c9ff9bebe17d92cb954bc1e6d34e2fac1d946 100644 (file)
@@ -86,129 +86,6 @@ static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
        return ret;
 }
 
-/* Get PCI root bridge's handle from its segment and bus number */
-struct acpi_find_pci_root {
-       unsigned int seg;
-       unsigned int bus;
-       acpi_handle handle;
-};
-
-static acpi_status
-do_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
-{
-       unsigned long *busnr = data;
-       struct acpi_resource_address64 address;
-
-       if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
-           resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
-           resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
-               return AE_OK;
-
-       acpi_resource_to_address64(resource, &address);
-       if ((address.address_length > 0) &&
-           (address.resource_type == ACPI_BUS_NUMBER_RANGE))
-               *busnr = address.minimum;
-
-       return AE_OK;
-}
-
-static int get_root_bridge_busnr(acpi_handle handle)
-{
-       acpi_status status;
-       unsigned long bus, bbn;
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-
-       acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-
-       status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL,
-                                      &bbn);
-       if (status == AE_NOT_FOUND) {
-               /* Assume bus = 0 */
-               printk(KERN_INFO PREFIX
-                      "Assume root bridge [%s] bus is 0\n",
-                      (char *)buffer.pointer);
-               status = AE_OK;
-               bbn = 0;
-       }
-       if (ACPI_FAILURE(status)) {
-               bbn = -ENODEV;
-               goto exit;
-       }
-       if (bbn > 0)
-               goto exit;
-
-       /* _BBN in some systems return 0 for all root bridges */
-       bus = -1;
-       status = acpi_walk_resources(handle, METHOD_NAME__CRS,
-                                    do_root_bridge_busnr_callback, &bus);
-       /* If _CRS failed, we just use _BBN */
-       if (ACPI_FAILURE(status) || (bus == -1))
-               goto exit;
-       /* We select _CRS */
-       if (bbn != bus) {
-               printk(KERN_INFO PREFIX
-                      "_BBN and _CRS returns different value for %s. Select _CRS\n",
-                      (char *)buffer.pointer);
-               bbn = bus;
-       }
-      exit:
-       kfree(buffer.pointer);
-       return (int)bbn;
-}
-
-static acpi_status
-find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
-{
-       struct acpi_find_pci_root *find = (struct acpi_find_pci_root *)context;
-       unsigned long seg, bus;
-       acpi_status status;
-       int tmp;
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-
-       acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-
-       status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL, &seg);
-       if (status == AE_NOT_FOUND) {
-               /* Assume seg = 0 */
-               status = AE_OK;
-               seg = 0;
-       }
-       if (ACPI_FAILURE(status)) {
-               status = AE_CTRL_DEPTH;
-               goto exit;
-       }
-
-       tmp = get_root_bridge_busnr(handle);
-       if (tmp < 0) {
-               printk(KERN_ERR PREFIX
-                      "Find root bridge failed for %s\n",
-                      (char *)buffer.pointer);
-               status = AE_CTRL_DEPTH;
-               goto exit;
-       }
-       bus = tmp;
-
-       if (seg == find->seg && bus == find->bus)
-       {
-               find->handle = handle;
-               status = AE_CTRL_TERMINATE;
-       }
-       else
-               status = AE_OK;
-      exit:
-       kfree(buffer.pointer);
-       return status;
-}
-
-acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
-{
-       struct acpi_find_pci_root find = { seg, bus, NULL };
-
-       acpi_get_devices(PCI_ROOT_HID_STRING, find_pci_rootbridge, &find, NULL);
-       return find.handle;
-}
-EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
-
 /* Get device's handler per its address under its parent */
 struct acpi_find_child {
        acpi_handle handle;
index de50fab2a91066f2c23afe2087a1bbc02ab0b9a2..6031ca13dd2f2b9c73b66abb56aca71edd5f1d3b 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define _COMPONENT          ACPI_HARDWARE
 ACPI_MODULE_NAME("hwacpi")
 
-/******************************************************************************
- *
- * FUNCTION:    acpi_hw_initialize
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Initialize and validate the various ACPI registers defined in
- *              the FADT.
- *
- ******************************************************************************/
-acpi_status acpi_hw_initialize(void)
-{
-       acpi_status status;
-
-       ACPI_FUNCTION_TRACE(hw_initialize);
-
-       /* We must have the ACPI tables by the time we get here */
-
-       if (!acpi_gbl_FADT) {
-               ACPI_ERROR((AE_INFO, "No FADT is present"));
-               return_ACPI_STATUS(AE_NO_ACPI_TABLES);
-       }
-
-       /* Sanity check the FADT for valid values */
-
-       status = acpi_ut_validate_fadt();
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       return_ACPI_STATUS(AE_OK);
-}
-
 /******************************************************************************
  *
  * FUNCTION:    acpi_hw_set_mode
@@ -93,7 +58,6 @@ acpi_status acpi_hw_initialize(void)
  * DESCRIPTION: Transitions the system into the requested mode.
  *
  ******************************************************************************/
-
 acpi_status acpi_hw_set_mode(u32 mode)
 {
 
@@ -106,7 +70,7 @@ acpi_status acpi_hw_set_mode(u32 mode)
         * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
         * system does not support mode transition.
         */
-       if (!acpi_gbl_FADT->smi_cmd) {
+       if (!acpi_gbl_FADT.smi_command) {
                ACPI_ERROR((AE_INFO,
                            "No SMI_CMD in FADT, mode transition failed"));
                return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
@@ -119,7 +83,7 @@ acpi_status acpi_hw_set_mode(u32 mode)
         * we make sure both the numbers are zero to determine these
         * transitions are not supported.
         */
-       if (!acpi_gbl_FADT->acpi_enable && !acpi_gbl_FADT->acpi_disable) {
+       if (!acpi_gbl_FADT.acpi_enable && !acpi_gbl_FADT.acpi_disable) {
                ACPI_ERROR((AE_INFO,
                            "No ACPI mode transition supported in this system (enable/disable both zero)"));
                return_ACPI_STATUS(AE_OK);
@@ -130,9 +94,8 @@ acpi_status acpi_hw_set_mode(u32 mode)
 
                /* BIOS should have disabled ALL fixed and GP events */
 
-               status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd,
-                                           (u32) acpi_gbl_FADT->acpi_enable,
-                                           8);
+               status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
+                                           (u32) acpi_gbl_FADT.acpi_enable, 8);
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                  "Attempting to enable ACPI mode\n"));
                break;
@@ -143,8 +106,8 @@ acpi_status acpi_hw_set_mode(u32 mode)
                 * BIOS should clear all fixed status bits and restore fixed event
                 * enable bits to default
                 */
-               status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd,
-                                           (u32) acpi_gbl_FADT->acpi_disable,
+               status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
+                                           (u32) acpi_gbl_FADT.acpi_disable,
                                            8);
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                  "Attempting to enable Legacy (non-ACPI) mode\n"));
@@ -204,12 +167,11 @@ u32 acpi_hw_get_mode(void)
         * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
         * system does not support mode transition.
         */
-       if (!acpi_gbl_FADT->smi_cmd) {
+       if (!acpi_gbl_FADT.smi_command) {
                return_UINT32(ACPI_SYS_MODE_ACPI);
        }
 
-       status =
-           acpi_get_register(ACPI_BITREG_SCI_ENABLE, &value, ACPI_MTX_LOCK);
+       status = acpi_get_register(ACPI_BITREG_SCI_ENABLE, &value);
        if (ACPI_FAILURE(status)) {
                return_UINT32(ACPI_SYS_MODE_LEGACY);
        }
index 608a3a60ee1132000bf77d6bc6569646e272bdb6..117a05cadaaa9014ca2a6c5b29a5fa566accca08 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -105,14 +105,20 @@ acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info *gpe_event_info)
 acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
 {
        acpi_status status;
+       u8 register_bit;
 
        ACPI_FUNCTION_ENTRY();
 
+       register_bit = (u8)
+           (1 <<
+            (gpe_event_info->gpe_number -
+             gpe_event_info->register_info->base_gpe_number));
+
        /*
         * Write a one to the appropriate bit in the status register to
         * clear this GPE.
         */
-       status = acpi_hw_low_level_write(8, gpe_event_info->register_bit,
+       status = acpi_hw_low_level_write(8, register_bit,
                                         &gpe_event_info->register_info->
                                         status_address);
 
@@ -155,7 +161,10 @@ acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
 
        /* Get the register bitmask for this GPE */
 
-       register_bit = gpe_event_info->register_bit;
+       register_bit = (u8)
+           (1 <<
+            (gpe_event_info->gpe_number -
+             gpe_event_info->register_info->base_gpe_number));
 
        /* GPE currently enabled? (enabled for runtime?) */
 
index fa58c1edce1e52f00c6b1cecebbe3f63a7a4af6f..1d371fa663f2492a23bb3ae7d4aa0585c80ba7c6 100644 (file)
@@ -7,7 +7,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -54,17 +54,15 @@ ACPI_MODULE_NAME("hwregs")
  *
  * FUNCTION:    acpi_hw_clear_acpi_status
  *
- * PARAMETERS:  Flags           - Lock the hardware or not
+ * PARAMETERS:  None
  *
- * RETURN:      none
+ * RETURN:      None
  *
  * DESCRIPTION: Clears all fixed and general purpose status bits
  *              THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
  *
- * NOTE: TBD: Flags parameter is obsolete, to be removed
- *
  ******************************************************************************/
-acpi_status acpi_hw_clear_acpi_status(u32 flags)
+acpi_status acpi_hw_clear_acpi_status(void)
 {
        acpi_status status;
        acpi_cpu_flags lock_flags = 0;
@@ -73,7 +71,7 @@ acpi_status acpi_hw_clear_acpi_status(u32 flags)
 
        ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n",
                          ACPI_BITMASK_ALL_FIXED_STATUS,
-                         (u16) acpi_gbl_FADT->xpm1a_evt_blk.address));
+                         (u16) acpi_gbl_FADT.xpm1a_event_block.address));
 
        lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
 
@@ -86,10 +84,10 @@ acpi_status acpi_hw_clear_acpi_status(u32 flags)
 
        /* Clear the fixed events */
 
-       if (acpi_gbl_FADT->xpm1b_evt_blk.address) {
+       if (acpi_gbl_FADT.xpm1b_event_block.address) {
                status =
                    acpi_hw_low_level_write(16, ACPI_BITMASK_ALL_FIXED_STATUS,
-                                           &acpi_gbl_FADT->xpm1b_evt_blk);
+                                           &acpi_gbl_FADT.xpm1b_event_block);
                if (ACPI_FAILURE(status)) {
                        goto unlock_and_exit;
                }
@@ -253,18 +251,15 @@ struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
  *
  * PARAMETERS:  register_id     - ID of ACPI bit_register to access
  *              return_value    - Value that was read from the register
- *              Flags           - Lock the hardware or not
  *
  * RETURN:      Status and the value read from specified Register. Value
  *              returned is normalized to bit0 (is shifted all the way right)
  *
  * DESCRIPTION: ACPI bit_register read function.
  *
- * NOTE: TBD: Flags parameter is obsolete, to be removed
- *
  ******************************************************************************/
 
-acpi_status acpi_get_register(u32 register_id, u32 * return_value, u32 flags)
+acpi_status acpi_get_register(u32 register_id, u32 * return_value)
 {
        u32 register_value = 0;
        struct acpi_bit_register_info *bit_reg_info;
@@ -312,16 +307,13 @@ ACPI_EXPORT_SYMBOL(acpi_get_register)
  * PARAMETERS:  register_id     - ID of ACPI bit_register to access
  *              Value           - (only used on write) value to write to the
  *                                Register, NOT pre-normalized to the bit pos
- *              Flags           - Lock the hardware or not
  *
  * RETURN:      Status
  *
  * DESCRIPTION: ACPI Bit Register write function.
  *
- * NOTE: TBD: Flags parameter is obsolete, to be removed
- *
  ******************************************************************************/
-acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags)
+acpi_status acpi_set_register(u32 register_id, u32 value)
 {
        u32 register_value = 0;
        struct acpi_bit_register_info *bit_reg_info;
@@ -422,8 +414,9 @@ acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags)
                ACPI_DEBUG_PRINT((ACPI_DB_IO,
                                  "PM2 control: Read %X from %8.8X%8.8X\n",
                                  register_value,
-                                 ACPI_FORMAT_UINT64(acpi_gbl_FADT->
-                                                    xpm2_cnt_blk.address)));
+                                 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
+                                                    xpm2_control_block.
+                                                    address)));
 
                ACPI_REGISTER_INSERT_VALUE(register_value,
                                           bit_reg_info->bit_position,
@@ -433,8 +426,9 @@ acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags)
                ACPI_DEBUG_PRINT((ACPI_DB_IO,
                                  "About to write %4.4X to %8.8X%8.8X\n",
                                  register_value,
-                                 ACPI_FORMAT_UINT64(acpi_gbl_FADT->
-                                                    xpm2_cnt_blk.address)));
+                                 ACPI_FORMAT_UINT64(acpi_gbl_FADT.
+                                                    xpm2_control_block.
+                                                    address)));
 
                status = acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
                                                ACPI_REGISTER_PM2_CONTROL,
@@ -495,7 +489,7 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
 
                status =
                    acpi_hw_low_level_read(16, &value1,
-                                          &acpi_gbl_FADT->xpm1a_evt_blk);
+                                          &acpi_gbl_FADT.xpm1a_event_block);
                if (ACPI_FAILURE(status)) {
                        goto unlock_and_exit;
                }
@@ -504,7 +498,7 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
 
                status =
                    acpi_hw_low_level_read(16, &value2,
-                                          &acpi_gbl_FADT->xpm1b_evt_blk);
+                                          &acpi_gbl_FADT.xpm1b_event_block);
                value1 |= value2;
                break;
 
@@ -527,14 +521,14 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
 
                status =
                    acpi_hw_low_level_read(16, &value1,
-                                          &acpi_gbl_FADT->xpm1a_cnt_blk);
+                                          &acpi_gbl_FADT.xpm1a_control_block);
                if (ACPI_FAILURE(status)) {
                        goto unlock_and_exit;
                }
 
                status =
                    acpi_hw_low_level_read(16, &value2,
-                                          &acpi_gbl_FADT->xpm1b_cnt_blk);
+                                          &acpi_gbl_FADT.xpm1b_control_block);
                value1 |= value2;
                break;
 
@@ -542,19 +536,20 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
 
                status =
                    acpi_hw_low_level_read(8, &value1,
-                                          &acpi_gbl_FADT->xpm2_cnt_blk);
+                                          &acpi_gbl_FADT.xpm2_control_block);
                break;
 
        case ACPI_REGISTER_PM_TIMER:    /* 32-bit access */
 
                status =
                    acpi_hw_low_level_read(32, &value1,
-                                          &acpi_gbl_FADT->xpm_tmr_blk);
+                                          &acpi_gbl_FADT.xpm_timer_block);
                break;
 
        case ACPI_REGISTER_SMI_COMMAND_BLOCK:   /* 8-bit access */
 
-               status = acpi_os_read_port(acpi_gbl_FADT->smi_cmd, &value1, 8);
+               status =
+                   acpi_os_read_port(acpi_gbl_FADT.smi_command, &value1, 8);
                break;
 
        default:
@@ -635,7 +630,7 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
 
                status =
                    acpi_hw_low_level_write(16, value,
-                                           &acpi_gbl_FADT->xpm1a_evt_blk);
+                                           &acpi_gbl_FADT.xpm1a_event_block);
                if (ACPI_FAILURE(status)) {
                        goto unlock_and_exit;
                }
@@ -644,7 +639,7 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
 
                status =
                    acpi_hw_low_level_write(16, value,
-                                           &acpi_gbl_FADT->xpm1b_evt_blk);
+                                           &acpi_gbl_FADT.xpm1b_event_block);
                break;
 
        case ACPI_REGISTER_PM1_ENABLE:  /* 16-bit access */
@@ -682,49 +677,50 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
 
                status =
                    acpi_hw_low_level_write(16, value,
-                                           &acpi_gbl_FADT->xpm1a_cnt_blk);
+                                           &acpi_gbl_FADT.xpm1a_control_block);
                if (ACPI_FAILURE(status)) {
                        goto unlock_and_exit;
                }
 
                status =
                    acpi_hw_low_level_write(16, value,
-                                           &acpi_gbl_FADT->xpm1b_cnt_blk);
+                                           &acpi_gbl_FADT.xpm1b_control_block);
                break;
 
        case ACPI_REGISTER_PM1A_CONTROL:        /* 16-bit access */
 
                status =
                    acpi_hw_low_level_write(16, value,
-                                           &acpi_gbl_FADT->xpm1a_cnt_blk);
+                                           &acpi_gbl_FADT.xpm1a_control_block);
                break;
 
        case ACPI_REGISTER_PM1B_CONTROL:        /* 16-bit access */
 
                status =
                    acpi_hw_low_level_write(16, value,
-                                           &acpi_gbl_FADT->xpm1b_cnt_blk);
+                                           &acpi_gbl_FADT.xpm1b_control_block);
                break;
 
        case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
 
                status =
                    acpi_hw_low_level_write(8, value,
-                                           &acpi_gbl_FADT->xpm2_cnt_blk);
+                                           &acpi_gbl_FADT.xpm2_control_block);
                break;
 
        case ACPI_REGISTER_PM_TIMER:    /* 32-bit access */
 
                status =
                    acpi_hw_low_level_write(32, value,
-                                           &acpi_gbl_FADT->xpm_tmr_blk);
+                                           &acpi_gbl_FADT.xpm_timer_block);
                break;
 
        case ACPI_REGISTER_SMI_COMMAND_BLOCK:   /* 8-bit access */
 
                /* SMI_CMD is currently always in IO space */
 
-               status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd, value, 8);
+               status =
+                   acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8);
                break;
 
        default:
@@ -783,7 +779,7 @@ acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
         * Two address spaces supported: Memory or IO.
         * PCI_Config is not supported here because the GAS struct is insufficient
         */
-       switch (reg->address_space_id) {
+       switch (reg->space_id) {
        case ACPI_ADR_SPACE_SYSTEM_MEMORY:
 
                status = acpi_os_read_memory((acpi_physical_address) address,
@@ -792,22 +788,20 @@ acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
 
        case ACPI_ADR_SPACE_SYSTEM_IO:
 
-               status = acpi_os_read_port((acpi_io_address) address,
-                                          value, width);
+               status =
+                   acpi_os_read_port((acpi_io_address) address, value, width);
                break;
 
        default:
                ACPI_ERROR((AE_INFO,
-                           "Unsupported address space: %X",
-                           reg->address_space_id));
+                           "Unsupported address space: %X", reg->space_id));
                return (AE_BAD_PARAMETER);
        }
 
        ACPI_DEBUG_PRINT((ACPI_DB_IO,
                          "Read:  %8.8X width %2d from %8.8X%8.8X (%s)\n",
-                         *value, width,
-                         ACPI_FORMAT_UINT64(address),
-                         acpi_ut_get_region_name(reg->address_space_id)));
+                         *value, width, ACPI_FORMAT_UINT64(address),
+                         acpi_ut_get_region_name(reg->space_id)));
 
        return (status);
 }
@@ -854,7 +848,7 @@ acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
         * Two address spaces supported: Memory or IO.
         * PCI_Config is not supported here because the GAS struct is insufficient
         */
-       switch (reg->address_space_id) {
+       switch (reg->space_id) {
        case ACPI_ADR_SPACE_SYSTEM_MEMORY:
 
                status = acpi_os_write_memory((acpi_physical_address) address,
@@ -863,22 +857,20 @@ acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
 
        case ACPI_ADR_SPACE_SYSTEM_IO:
 
-               status = acpi_os_write_port((acpi_io_address) address,
-                                           value, width);
+               status = acpi_os_write_port((acpi_io_address) address, value,
+                                           width);
                break;
 
        default:
                ACPI_ERROR((AE_INFO,
-                           "Unsupported address space: %X",
-                           reg->address_space_id));
+                           "Unsupported address space: %X", reg->space_id));
                return (AE_BAD_PARAMETER);
        }
 
        ACPI_DEBUG_PRINT((ACPI_DB_IO,
                          "Wrote: %8.8X width %2d   to %8.8X%8.8X (%s)\n",
-                         value, width,
-                         ACPI_FORMAT_UINT64(address),
-                         acpi_ut_get_region_name(reg->address_space_id)));
+                         value, width, ACPI_FORMAT_UINT64(address),
+                         acpi_ut_get_region_name(reg->space_id)));
 
        return (status);
 }
index 8bb43cae60c2e160037b31559270d1922d61ed99..57901ca3ade911fea9ae132dd7aa77844025372b 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,7 @@
  */
 
 #include <acpi/acpi.h>
+#include <acpi/actables.h>
 
 #define _COMPONENT          ACPI_HARDWARE
 ACPI_MODULE_NAME("hwsleep")
@@ -62,17 +63,32 @@ ACPI_MODULE_NAME("hwsleep")
 acpi_status
 acpi_set_firmware_waking_vector(acpi_physical_address physical_address)
 {
+       struct acpi_table_facs *facs;
+       acpi_status status;
 
        ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector);
 
+       /* Get the FACS */
+
+       status =
+           acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
+                                   (struct acpi_table_header **)&facs);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
        /* Set the vector */
 
-       if (acpi_gbl_common_fACS.vector_width == 32) {
-               *(ACPI_CAST_PTR
-                 (u32, acpi_gbl_common_fACS.firmware_waking_vector))
-                   = (u32) physical_address;
+       if ((facs->length < 32) || (!(facs->xfirmware_waking_vector))) {
+               /*
+                * ACPI 1.0 FACS or short table or optional X_ field is zero
+                */
+               facs->firmware_waking_vector = (u32) physical_address;
        } else {
-               *acpi_gbl_common_fACS.firmware_waking_vector = physical_address;
+               /*
+                * ACPI 2.0 FACS with valid X_ field
+                */
+               facs->xfirmware_waking_vector = physical_address;
        }
 
        return_ACPI_STATUS(AE_OK);
@@ -97,6 +113,8 @@ ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector)
 acpi_status
 acpi_get_firmware_waking_vector(acpi_physical_address * physical_address)
 {
+       struct acpi_table_facs *facs;
+       acpi_status status;
 
        ACPI_FUNCTION_TRACE(acpi_get_firmware_waking_vector);
 
@@ -104,16 +122,29 @@ acpi_get_firmware_waking_vector(acpi_physical_address * physical_address)
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
+       /* Get the FACS */
+
+       status =
+           acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
+                                   (struct acpi_table_header **)&facs);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
        /* Get the vector */
 
-       if (acpi_gbl_common_fACS.vector_width == 32) {
-               *physical_address = (acpi_physical_address)
-                   *
-                   (ACPI_CAST_PTR
-                    (u32, acpi_gbl_common_fACS.firmware_waking_vector));
+       if ((facs->length < 32) || (!(facs->xfirmware_waking_vector))) {
+               /*
+                * ACPI 1.0 FACS or short table or optional X_ field is zero
+                */
+               *physical_address =
+                   (acpi_physical_address) facs->firmware_waking_vector;
        } else {
+               /*
+                * ACPI 2.0 FACS with valid X_ field
+                */
                *physical_address =
-                   *acpi_gbl_common_fACS.firmware_waking_vector;
+                   (acpi_physical_address) facs->xfirmware_waking_vector;
        }
 
        return_ACPI_STATUS(AE_OK);
@@ -246,15 +277,14 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
 
        /* Clear wake status */
 
-       status =
-           acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
+       status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
 
        /* Clear all fixed and general purpose status bits */
 
-       status = acpi_hw_clear_acpi_status(ACPI_MTX_DO_NOT_LOCK);
+       status = acpi_hw_clear_acpi_status();
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
@@ -367,8 +397,7 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
        /* Wait until we enter sleep state */
 
        do {
-               status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value,
-                                          ACPI_MTX_DO_NOT_LOCK);
+               status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value);
                if (ACPI_FAILURE(status)) {
                        return_ACPI_STATUS(status);
                }
@@ -401,13 +430,12 @@ acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
 
        ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios);
 
-       status =
-           acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
+       status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
 
-       status = acpi_hw_clear_acpi_status(ACPI_MTX_DO_NOT_LOCK);
+       status = acpi_hw_clear_acpi_status();
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
@@ -429,13 +457,12 @@ acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
 
        ACPI_FLUSH_CPU_CACHE();
 
-       status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd,
-                                   (u32) acpi_gbl_FADT->S4bios_req, 8);
+       status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
+                                   (u32) acpi_gbl_FADT.S4bios_request, 8);
 
        do {
                acpi_os_stall(1000);
-               status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value,
-                                          ACPI_MTX_DO_NOT_LOCK);
+               status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value);
                if (ACPI_FAILURE(status)) {
                        return_ACPI_STATUS(status);
                }
@@ -568,13 +595,11 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state)
 
        (void)
            acpi_set_register(acpi_gbl_fixed_event_info
-                             [ACPI_EVENT_POWER_BUTTON].enable_register_id, 1,
-                             ACPI_MTX_DO_NOT_LOCK);
+                             [ACPI_EVENT_POWER_BUTTON].enable_register_id, 1);
 
        (void)
            acpi_set_register(acpi_gbl_fixed_event_info
-                             [ACPI_EVENT_POWER_BUTTON].status_register_id, 1,
-                             ACPI_MTX_DO_NOT_LOCK);
+                             [ACPI_EVENT_POWER_BUTTON].status_register_id, 1);
 
        arg.integer.value = ACPI_SST_WORKING;
        status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL);
index c4ec47c939fde51a08975c567742afe9230b23a2..c32eab696acd11f4fad79daab380c9d189faaf71 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -66,7 +66,7 @@ acpi_status acpi_get_timer_resolution(u32 * resolution)
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
-       if (acpi_gbl_FADT->tmr_val_ext == 0) {
+       if ((acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) == 0) {
                *resolution = 24;
        } else {
                *resolution = 32;
@@ -98,7 +98,8 @@ acpi_status acpi_get_timer(u32 * ticks)
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
-       status = acpi_hw_low_level_read(32, ticks, &acpi_gbl_FADT->xpm_tmr_blk);
+       status =
+           acpi_hw_low_level_read(32, ticks, &acpi_gbl_FADT.xpm_timer_block);
 
        return_ACPI_STATUS(status);
 }
@@ -153,7 +154,7 @@ acpi_get_timer_duration(u32 start_ticks, u32 end_ticks, u32 * time_elapsed)
        if (start_ticks < end_ticks) {
                delta_ticks = end_ticks - start_ticks;
        } else if (start_ticks > end_ticks) {
-               if (acpi_gbl_FADT->tmr_val_ext == 0) {
+               if ((acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) == 0) {
 
                        /* 24-bit Timer */
 
diff --git a/drivers/acpi/motherboard.c b/drivers/acpi/motherboard.c
deleted file mode 100644 (file)
index 2e17ec7..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-/* 
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or (at
- *  your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful, but
- *  WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- */
-
-/* Purpose: Prevent PCMCIA cards from using motherboard resources. */
-
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/types.h>
-#include <linux/pci.h>
-#include <linux/ioport.h>
-#include <asm/io.h>
-
-#include <acpi/acpi_bus.h>
-#include <acpi/acpi_drivers.h>
-
-#define _COMPONENT             ACPI_SYSTEM_COMPONENT
-ACPI_MODULE_NAME("acpi_motherboard")
-
-/* Dell use PNP0C01 instead of PNP0C02 */
-#define ACPI_MB_HID1                   "PNP0C01"
-#define ACPI_MB_HID2                   "PNP0C02"
-/**
- * Doesn't care about legacy IO ports, only IO ports beyond 0x1000 are reserved
- * Doesn't care about the failure of 'request_region', since other may reserve
- * the io ports as well
- */
-#define IS_RESERVED_ADDR(base, len) \
-       (((len) > 0) && ((base) > 0) && ((base) + (len) < IO_SPACE_LIMIT) \
-       && ((base) + (len) > PCIBIOS_MIN_IO))
-/*
- * Clearing the flag (IORESOURCE_BUSY) allows drivers to use
- * the io ports if they really know they can use it, while
- * still preventing hotplug PCI devices from using it.
- */
-
-/*
- * When CONFIG_PNP is enabled, pnp/system.c binds to PNP0C01
- * and PNP0C02, redundant with acpi_reserve_io_ranges().
- * But acpi_reserve_io_ranges() is necessary for !CONFIG_PNP.
- */
-static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data)
-{
-       struct resource *requested_res = NULL;
-
-
-       if (res->type == ACPI_RESOURCE_TYPE_IO) {
-               struct acpi_resource_io *io_res = &res->data.io;
-
-               if (io_res->minimum != io_res->maximum)
-                       return AE_OK;
-               if (IS_RESERVED_ADDR
-                   (io_res->minimum, io_res->address_length)) {
-                       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                         "Motherboard resources 0x%08x - 0x%08x\n",
-                                         io_res->minimum,
-                                         io_res->minimum +
-                                         io_res->address_length));
-                       requested_res =
-                           request_region(io_res->minimum,
-                                          io_res->address_length, "motherboard");
-               }
-       } else if (res->type == ACPI_RESOURCE_TYPE_FIXED_IO) {
-               struct acpi_resource_fixed_io *fixed_io_res =
-                   &res->data.fixed_io;
-
-               if (IS_RESERVED_ADDR
-                   (fixed_io_res->address, fixed_io_res->address_length)) {
-                       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                         "Motherboard resources 0x%08x - 0x%08x\n",
-                                         fixed_io_res->address,
-                                         fixed_io_res->address +
-                                         fixed_io_res->address_length));
-                       requested_res =
-                           request_region(fixed_io_res->address,
-                                          fixed_io_res->address_length,
-                                          "motherboard");
-               }
-       } else {
-               /* Memory mapped IO? */
-       }
-
-       if (requested_res)
-               requested_res->flags &= ~IORESOURCE_BUSY;
-       return AE_OK;
-}
-
-static int acpi_motherboard_add(struct acpi_device *device)
-{
-       if (!device)
-               return -EINVAL;
-       acpi_walk_resources(device->handle, METHOD_NAME__CRS,
-                           acpi_reserve_io_ranges, NULL);
-
-       return 0;
-}
-
-static struct acpi_driver acpi_motherboard_driver1 = {
-       .name = "motherboard",
-       .class = "",
-       .ids = ACPI_MB_HID1,
-       .ops = {
-               .add = acpi_motherboard_add,
-               },
-};
-
-static struct acpi_driver acpi_motherboard_driver2 = {
-       .name = "motherboard",
-       .class = "",
-       .ids = ACPI_MB_HID2,
-       .ops = {
-               .add = acpi_motherboard_add,
-               },
-};
-
-static void __init acpi_request_region (struct acpi_generic_address *addr,
-       unsigned int length, char *desc)
-{
-       if (!addr->address || !length)
-               return;
-
-       if (addr->address_space_id == ACPI_ADR_SPACE_SYSTEM_IO)
-               request_region(addr->address, length, desc);
-       else if (addr->address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
-               request_mem_region(addr->address, length, desc);
-}
-
-static void __init acpi_reserve_resources(void)
-{
-       acpi_request_region(&acpi_gbl_FADT->xpm1a_evt_blk,
-                              acpi_gbl_FADT->pm1_evt_len, "ACPI PM1a_EVT_BLK");
-
-       acpi_request_region(&acpi_gbl_FADT->xpm1b_evt_blk,
-                              acpi_gbl_FADT->pm1_evt_len, "ACPI PM1b_EVT_BLK");
-
-       acpi_request_region(&acpi_gbl_FADT->xpm1a_cnt_blk,
-                              acpi_gbl_FADT->pm1_cnt_len, "ACPI PM1a_CNT_BLK");
-
-       acpi_request_region(&acpi_gbl_FADT->xpm1b_cnt_blk,
-                              acpi_gbl_FADT->pm1_cnt_len, "ACPI PM1b_CNT_BLK");
-
-       if (acpi_gbl_FADT->pm_tm_len == 4)
-               acpi_request_region(&acpi_gbl_FADT->xpm_tmr_blk, 4, "ACPI PM_TMR");
-
-       acpi_request_region(&acpi_gbl_FADT->xpm2_cnt_blk,
-                              acpi_gbl_FADT->pm2_cnt_len, "ACPI PM2_CNT_BLK");
-
-       /* Length of GPE blocks must be a non-negative multiple of 2 */
-
-       if (!(acpi_gbl_FADT->gpe0_blk_len & 0x1))
-               acpi_request_region(&acpi_gbl_FADT->xgpe0_blk,
-                              acpi_gbl_FADT->gpe0_blk_len, "ACPI GPE0_BLK");
-
-       if (!(acpi_gbl_FADT->gpe1_blk_len & 0x1))
-               acpi_request_region(&acpi_gbl_FADT->xgpe1_blk,
-                              acpi_gbl_FADT->gpe1_blk_len, "ACPI GPE1_BLK");
-}
-
-static int __init acpi_motherboard_init(void)
-{
-       acpi_bus_register_driver(&acpi_motherboard_driver1);
-       acpi_bus_register_driver(&acpi_motherboard_driver2);
-       /*
-        * Guarantee motherboard IO reservation first
-        * This module must run after scan.c
-        */
-       if (!acpi_disabled)
-               acpi_reserve_resources();
-       return 0;
-}
-
-/**
- * Reserve motherboard resources after PCI claim BARs,
- * but before PCI assign resources for uninitialized PCI devices
- */
-fs_initcall(acpi_motherboard_init);
index c1c6c236df9affedc4ba07f0bbd161684b4053a6..57faf598bad8f2fe98055f34589f23a2c341d976 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -195,31 +195,27 @@ acpi_status acpi_ns_root_initialize(void)
                                obj_desc->mutex.sync_level =
                                    (u8) (ACPI_TO_INTEGER(val) - 1);
 
-                               if (ACPI_STRCMP(init_val->name, "_GL_") == 0) {
+                               /* Create a mutex */
 
-                                       /* Create a counting semaphore for the global lock */
+                               status =
+                                   acpi_os_create_mutex(&obj_desc->mutex.
+                                                        os_mutex);
+                               if (ACPI_FAILURE(status)) {
+                                       acpi_ut_remove_reference(obj_desc);
+                                       goto unlock_and_exit;
+                               }
 
-                                       status =
-                                           acpi_os_create_semaphore
-                                           (ACPI_NO_UNIT_LIMIT, 1,
-                                            &acpi_gbl_global_lock_semaphore);
-                                       if (ACPI_FAILURE(status)) {
-                                               acpi_ut_remove_reference
-                                                   (obj_desc);
-                                               goto unlock_and_exit;
-                                       }
+                               /* Special case for ACPI Global Lock */
 
-                                       /* Mark this mutex as very special */
+                               if (ACPI_STRCMP(init_val->name, "_GL_") == 0) {
+                                       acpi_gbl_global_lock_mutex =
+                                           obj_desc->mutex.os_mutex;
 
-                                       obj_desc->mutex.os_mutex =
-                                           ACPI_GLOBAL_LOCK;
-                               } else {
-                                       /* Create a mutex */
+                                       /* Create additional counting semaphore for global lock */
 
                                        status =
-                                           acpi_os_create_mutex(&obj_desc->
-                                                                mutex.
-                                                                os_mutex);
+                                           acpi_os_create_semaphore(1, 0,
+                                                                    &acpi_gbl_global_lock_semaphore);
                                        if (ACPI_FAILURE(status)) {
                                                acpi_ut_remove_reference
                                                    (obj_desc);
index 55b407aae26612372d52f61867d50226f129e673..1d693d8ad2d8a044e528920331513254738d98b1 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -61,6 +61,9 @@ ACPI_MODULE_NAME("nsalloc")
 struct acpi_namespace_node *acpi_ns_create_node(u32 name)
 {
        struct acpi_namespace_node *node;
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+       u32 temp;
+#endif
 
        ACPI_FUNCTION_TRACE(ns_create_node);
 
@@ -71,6 +74,15 @@ struct acpi_namespace_node *acpi_ns_create_node(u32 name)
 
        ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++);
 
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+       temp =
+           acpi_gbl_ns_node_list->total_allocated -
+           acpi_gbl_ns_node_list->total_freed;
+       if (temp > acpi_gbl_ns_node_list->max_occupied) {
+               acpi_gbl_ns_node_list->max_occupied = temp;
+       }
+#endif
+
        node->name.integer = name;
        ACPI_SET_DESCRIPTOR_TYPE(node, ACPI_DESC_TYPE_NAMED);
        return_PTR(node);
index d72df66aa96533605b94e54344be46603ebd0abb..1fc4f86676e1969b5981ef6ffae26a853ad74606 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -205,7 +205,7 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
 
                if (!acpi_ut_valid_acpi_name(this_node->name.integer)) {
                        this_node->name.integer =
-                           acpi_ut_repair_name(this_node->name.integer);
+                           acpi_ut_repair_name(this_node->name.ascii);
 
                        ACPI_WARNING((AE_INFO, "Invalid ACPI Name %08X",
                                      this_node->name.integer));
@@ -226,6 +226,12 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
        obj_desc = acpi_ns_get_attached_object(this_node);
        acpi_dbg_level = dbg_level;
 
+       /* Temp nodes are those nodes created by a control method */
+
+       if (this_node->flags & ANOBJ_TEMPORARY) {
+               acpi_os_printf("(T) ");
+       }
+
        switch (info->display_type & ACPI_DISPLAY_MASK) {
        case ACPI_DISPLAY_SUMMARY:
 
@@ -623,7 +629,8 @@ acpi_ns_dump_objects(acpi_object_type type,
        info.display_type = display_type;
 
        (void)acpi_ns_walk_namespace(type, start_handle, max_depth,
-                                    ACPI_NS_WALK_NO_UNLOCK,
+                                    ACPI_NS_WALK_NO_UNLOCK |
+                                    ACPI_NS_WALK_TEMP_NODES,
                                     acpi_ns_dump_one_object, (void *)&info,
                                     NULL);
 }
index c6bf5d30fca34c3e9199ae66c926dcdd0905ca26..5097e167939ea44101446d6a19e29f1e3ff02438 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 4b0a4a8c9843ce76a3a852440881a603a2606517..aa6370c67ec1628fd055186a630779109741ad42 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -154,11 +154,7 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info)
                 * Execute the method via the interpreter. The interpreter is locked
                 * here before calling into the AML parser
                 */
-               status = acpi_ex_enter_interpreter();
-               if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
-               }
-
+               acpi_ex_enter_interpreter();
                status = acpi_ps_execute_method(info);
                acpi_ex_exit_interpreter();
        } else {
@@ -182,10 +178,7 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info)
                 * resolution, we must lock it because we could access an opregion.
                 * The opregion access code assumes that the interpreter is locked.
                 */
-               status = acpi_ex_enter_interpreter();
-               if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
-               }
+               acpi_ex_enter_interpreter();
 
                /* Function has a strange interface */
 
index aec8488c001951b514b290784883e4e045ca7d72..326af8fc0ce7e83fd91d9d7fee21f6d854f25694 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -213,7 +213,7 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
                        u32 level, void *context, void **return_value)
 {
        acpi_object_type type;
-       acpi_status status;
+       acpi_status status = AE_OK;
        struct acpi_init_walk_info *info =
            (struct acpi_init_walk_info *)context;
        struct acpi_namespace_node *node =
@@ -267,10 +267,7 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
        /*
         * Must lock the interpreter before executing AML code
         */
-       status = acpi_ex_enter_interpreter();
-       if (ACPI_FAILURE(status)) {
-               return (status);
-       }
+       acpi_ex_enter_interpreter();
 
        /*
         * Each of these types can contain executable AML code within the
index fe75d888e1838693146718488305f530c1ef449d..d4f9654fd20f315289d02af1cdb33bd335088e38 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include <acpi/acpi.h>
 #include <acpi/acnamesp.h>
 #include <acpi/acdispat.h>
+#include <acpi/actables.h>
 
 #define _COMPONENT          ACPI_NAMESPACE
 ACPI_MODULE_NAME("nsload")
 
 /* Local prototypes */
-static acpi_status acpi_ns_load_table_by_type(acpi_table_type table_type);
-
 #ifdef ACPI_FUTURE_IMPLEMENTATION
 acpi_status acpi_ns_unload_namespace(acpi_handle handle);
 
@@ -62,7 +61,7 @@ static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
  *
  * FUNCTION:    acpi_ns_load_table
  *
- * PARAMETERS:  table_desc      - Descriptor for table to be loaded
+ * PARAMETERS:  table_index     - Index for table to be loaded
  *              Node            - Owning NS node
  *
  * RETURN:      Status
@@ -72,42 +71,13 @@ static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
  ******************************************************************************/
 
 acpi_status
-acpi_ns_load_table(struct acpi_table_desc *table_desc,
+acpi_ns_load_table(acpi_native_uint table_index,
                   struct acpi_namespace_node *node)
 {
        acpi_status status;
 
        ACPI_FUNCTION_TRACE(ns_load_table);
 
-       /* Check if table contains valid AML (must be DSDT, PSDT, SSDT, etc.) */
-
-       if (!
-           (acpi_gbl_table_data[table_desc->type].
-            flags & ACPI_TABLE_EXECUTABLE)) {
-
-               /* Just ignore this table */
-
-               return_ACPI_STATUS(AE_OK);
-       }
-
-       /* Check validity of the AML start and length */
-
-       if (!table_desc->aml_start) {
-               ACPI_ERROR((AE_INFO, "Null AML pointer"));
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-       }
-
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AML block at %p\n",
-                         table_desc->aml_start));
-
-       /* Ignore table if there is no AML contained within */
-
-       if (!table_desc->aml_length) {
-               ACPI_WARNING((AE_INFO, "Zero-length AML block in table [%4.4s]",
-                             table_desc->pointer->signature));
-               return_ACPI_STATUS(AE_OK);
-       }
-
        /*
         * Parse the table and load the namespace with all named
         * objects found within.  Control methods are NOT parsed
@@ -117,15 +87,34 @@ acpi_ns_load_table(struct acpi_table_desc *table_desc,
         * to another control method, we can't continue parsing
         * because we don't know how many arguments to parse next!
         */
+       status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
+       /* If table already loaded into namespace, just return */
+
+       if (acpi_tb_is_table_loaded(table_index)) {
+               status = AE_ALREADY_EXISTS;
+               goto unlock;
+       }
+
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                          "**** Loading table into namespace ****\n"));
 
-       status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
+       status = acpi_tb_allocate_owner_id(table_index);
        if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
+               goto unlock;
+       }
+
+       status = acpi_ns_parse_table(table_index, node->child);
+       if (ACPI_SUCCESS(status)) {
+               acpi_tb_set_table_loaded_flag(table_index, TRUE);
+       } else {
+               acpi_tb_release_owner_id(table_index);
        }
 
-       status = acpi_ns_parse_table(table_desc, node->child);
+      unlock:
        (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
 
        if (ACPI_FAILURE(status)) {
@@ -141,7 +130,7 @@ acpi_ns_load_table(struct acpi_table_desc *table_desc,
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                          "**** Begin Table Method Parsing and Object Initialization ****\n"));
 
-       status = acpi_ds_initialize_objects(table_desc, node);
+       status = acpi_ds_initialize_objects(table_index, node);
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                          "**** Completed Table Method Parsing and Object Initialization ****\n"));
@@ -149,99 +138,7 @@ acpi_ns_load_table(struct acpi_table_desc *table_desc,
        return_ACPI_STATUS(status);
 }
 
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ns_load_table_by_type
- *
- * PARAMETERS:  table_type          - Id of the table type to load
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Load an ACPI table or tables into the namespace.  All tables
- *              of the given type are loaded.  The mechanism allows this
- *              routine to be called repeatedly.
- *
- ******************************************************************************/
-
-static acpi_status acpi_ns_load_table_by_type(acpi_table_type table_type)
-{
-       u32 i;
-       acpi_status status;
-       struct acpi_table_desc *table_desc;
-
-       ACPI_FUNCTION_TRACE(ns_load_table_by_type);
-
-       status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /*
-        * Table types supported are:
-        * DSDT (one), SSDT/PSDT (multiple)
-        */
-       switch (table_type) {
-       case ACPI_TABLE_ID_DSDT:
-
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace load: DSDT\n"));
-
-               table_desc = acpi_gbl_table_lists[ACPI_TABLE_ID_DSDT].next;
-
-               /* If table already loaded into namespace, just return */
-
-               if (table_desc->loaded_into_namespace) {
-                       goto unlock_and_exit;
-               }
-
-               /* Now load the single DSDT */
-
-               status = acpi_ns_load_table(table_desc, acpi_gbl_root_node);
-               if (ACPI_SUCCESS(status)) {
-                       table_desc->loaded_into_namespace = TRUE;
-               }
-               break;
-
-       case ACPI_TABLE_ID_SSDT:
-       case ACPI_TABLE_ID_PSDT:
-
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                 "Namespace load: %d SSDT or PSDTs\n",
-                                 acpi_gbl_table_lists[table_type].count));
-
-               /*
-                * Traverse list of SSDT or PSDT tables
-                */
-               table_desc = acpi_gbl_table_lists[table_type].next;
-               for (i = 0; i < acpi_gbl_table_lists[table_type].count; i++) {
-                       /*
-                        * Only attempt to load table into namespace if it is not
-                        * already loaded!
-                        */
-                       if (!table_desc->loaded_into_namespace) {
-                               status =
-                                   acpi_ns_load_table(table_desc,
-                                                      acpi_gbl_root_node);
-                               if (ACPI_FAILURE(status)) {
-                                       break;
-                               }
-
-                               table_desc->loaded_into_namespace = TRUE;
-                       }
-
-                       table_desc = table_desc->next;
-               }
-               break;
-
-       default:
-               status = AE_SUPPORT;
-               break;
-       }
-
-      unlock_and_exit:
-       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
-       return_ACPI_STATUS(status);
-}
-
+#ifdef ACPI_OBSOLETE_FUNCTIONS
 /*******************************************************************************
  *
  * FUNCTION:    acpi_load_namespace
@@ -288,6 +185,7 @@ acpi_status acpi_ns_load_namespace(void)
 
        return_ACPI_STATUS(status);
 }
+#endif
 
 #ifdef ACPI_FUTURE_IMPLEMENTATION
 /*******************************************************************************
index 97b8332c97469c90a25dbc403e3bd098ce4bae9c..cbd94af08cc5e00aa07c8c1075591c0124194700 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index aabe8794b908bd5ff91b55043cb4ee3c97be9689..d9d7377bc6e6434bba2f36b1bf9ef8a9d5192caa 100644 (file)
@@ -6,7 +6,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 155505a4ef69fbfffab6d63b8679ccbfff528605..e696aa8479909a5cf273813d008fa2366e9d8fd7 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,7 @@
 #include <acpi/acnamesp.h>
 #include <acpi/acparser.h>
 #include <acpi/acdispat.h>
+#include <acpi/actables.h>
 
 #define _COMPONENT          ACPI_NAMESPACE
 ACPI_MODULE_NAME("nsparse")
@@ -62,14 +63,24 @@ ACPI_MODULE_NAME("nsparse")
  *
  ******************************************************************************/
 acpi_status
-acpi_ns_one_complete_parse(u8 pass_number, struct acpi_table_desc *table_desc)
+acpi_ns_one_complete_parse(acpi_native_uint pass_number,
+                          acpi_native_uint table_index)
 {
        union acpi_parse_object *parse_root;
        acpi_status status;
+       acpi_native_uint aml_length;
+       u8 *aml_start;
        struct acpi_walk_state *walk_state;
+       struct acpi_table_header *table;
+       acpi_owner_id owner_id;
 
        ACPI_FUNCTION_TRACE(ns_one_complete_parse);
 
+       status = acpi_tb_get_owner_id(table_index, &owner_id);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
        /* Create and init a Root Node */
 
        parse_root = acpi_ps_create_scope_op();
@@ -79,26 +90,41 @@ acpi_ns_one_complete_parse(u8 pass_number, struct acpi_table_desc *table_desc)
 
        /* Create and initialize a new walk state */
 
-       walk_state = acpi_ds_create_walk_state(table_desc->owner_id,
-                                              NULL, NULL, NULL);
+       walk_state = acpi_ds_create_walk_state(owner_id, NULL, NULL, NULL);
        if (!walk_state) {
                acpi_ps_free_op(parse_root);
                return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
-       status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL,
-                                      table_desc->aml_start,
-                                      table_desc->aml_length, NULL,
-                                      pass_number);
+       status = acpi_get_table_by_index(table_index, &table);
+       if (ACPI_FAILURE(status)) {
+               acpi_ds_delete_walk_state(walk_state);
+               acpi_ps_free_op(parse_root);
+               return_ACPI_STATUS(status);
+       }
+
+       /* Table must consist of at least a complete header */
+
+       if (table->length < sizeof(struct acpi_table_header)) {
+               status = AE_BAD_HEADER;
+       } else {
+               aml_start = (u8 *) table + sizeof(struct acpi_table_header);
+               aml_length = table->length - sizeof(struct acpi_table_header);
+               status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL,
+                                              aml_start, aml_length, NULL,
+                                              (u8) pass_number);
+       }
+
        if (ACPI_FAILURE(status)) {
                acpi_ds_delete_walk_state(walk_state);
+               acpi_ps_delete_parse_tree(parse_root);
                return_ACPI_STATUS(status);
        }
 
        /* Parse the AML */
 
        ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "*PARSE* pass %d parse\n",
-                         pass_number));
+                         (unsigned)pass_number));
        status = acpi_ps_parse_aml(walk_state);
 
        acpi_ps_delete_parse_tree(parse_root);
@@ -119,7 +145,7 @@ acpi_ns_one_complete_parse(u8 pass_number, struct acpi_table_desc *table_desc)
  ******************************************************************************/
 
 acpi_status
-acpi_ns_parse_table(struct acpi_table_desc *table_desc,
+acpi_ns_parse_table(acpi_native_uint table_index,
                    struct acpi_namespace_node *start_node)
 {
        acpi_status status;
@@ -134,10 +160,10 @@ acpi_ns_parse_table(struct acpi_table_desc *table_desc,
         * each Parser Op subtree is deleted when it is finished.  This saves
         * a great deal of memory, and allows a small cache of parse objects
         * to service the entire parse.  The second pass of the parse then
-        * performs another complete parse of the AML..
+        * performs another complete parse of the AML.
         */
        ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n"));
-       status = acpi_ns_one_complete_parse(1, table_desc);
+       status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS1, table_index);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
@@ -152,7 +178,7 @@ acpi_ns_parse_table(struct acpi_table_desc *table_desc,
         * parse objects are all cached.
         */
        ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n"));
-       status = acpi_ns_one_complete_parse(2, table_desc);
+       status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS2, table_index);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
index 500e2bbcfaf72647690f831504dec96bc6766435..e863be665ce8f6fc11464be35c2163b68cc2d22a 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -321,7 +321,8 @@ acpi_ns_search_and_enter(u32 target_name,
         * even though there are a few bad names.
         */
        if (!acpi_ut_valid_acpi_name(target_name)) {
-               target_name = acpi_ut_repair_name(target_name);
+               target_name =
+                   acpi_ut_repair_name(ACPI_CAST_PTR(char, &target_name));
 
                /* Report warning only if in strict mode or debug mode */
 
@@ -401,6 +402,10 @@ acpi_ns_search_and_enter(u32 target_name,
        }
 #endif
 
+       if (flags & ACPI_NS_TEMPORARY) {
+               new_node->flags |= ANOBJ_TEMPORARY;
+       }
+
        /* Install the new object into the parent's list of children */
 
        acpi_ns_install_node(walk_state, node, new_node, type);
index aa4e799d9a8c3123e297e9195c50749086b07906..90fd059615ff94632d4b543f00be23560c22b226 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -770,13 +770,6 @@ void acpi_ns_terminate(void)
        }
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace freed\n"));
-
-       /*
-        * 2) Now we can delete the ACPI tables
-        */
-       acpi_tb_delete_all_tables();
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
-
        return_VOID;
 }
 
index c8f6bef16ed05a1fcc3e1128162624a69041107e..94eb8f332d941bb67a0175e85f17d4560ecd4f4d 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -126,7 +126,7 @@ struct acpi_namespace_node *acpi_ns_get_next_node(acpi_object_type type,
  * PARAMETERS:  Type                - acpi_object_type to search for
  *              start_node          - Handle in namespace where search begins
  *              max_depth           - Depth to which search is to reach
- *              unlock_before_callback- Whether to unlock the NS before invoking
+ *              Flags               - Whether to unlock the NS before invoking
  *                                    the callback routine
  *              user_function       - Called when an object of "Type" is found
  *              Context             - Passed to user function
@@ -153,7 +153,7 @@ acpi_status
 acpi_ns_walk_namespace(acpi_object_type type,
                       acpi_handle start_node,
                       u32 max_depth,
-                      u8 unlock_before_callback,
+                      u32 flags,
                       acpi_walk_callback user_function,
                       void *context, void **return_value)
 {
@@ -193,20 +193,34 @@ acpi_ns_walk_namespace(acpi_object_type type,
                    acpi_ns_get_next_node(ACPI_TYPE_ANY, parent_node,
                                          child_node);
                if (child_node) {
-                       /*
-                        * Found node, Get the type if we are not
-                        * searching for ANY
-                        */
+
+                       /* Found next child, get the type if we are not searching for ANY */
+
                        if (type != ACPI_TYPE_ANY) {
                                child_type = child_node->type;
                        }
 
-                       if (child_type == type) {
+                       /*
+                        * Ignore all temporary namespace nodes (created during control
+                        * method execution) unless told otherwise. These temporary nodes
+                        * can cause a race condition because they can be deleted during the
+                        * execution of the user function (if the namespace is unlocked before
+                        * invocation of the user function.) Only the debugger namespace dump
+                        * will examine the temporary nodes.
+                        */
+                       if ((child_node->flags & ANOBJ_TEMPORARY) &&
+                           !(flags & ACPI_NS_WALK_TEMP_NODES)) {
+                               status = AE_CTRL_DEPTH;
+                       }
+
+                       /* Type must match requested type */
+
+                       else if (child_type == type) {
                                /*
-                                * Found a matching node, invoke the user
-                                * callback function
+                                * Found a matching node, invoke the user callback function.
+                                * Unlock the namespace if flag is set.
                                 */
-                               if (unlock_before_callback) {
+                               if (flags & ACPI_NS_WALK_UNLOCK) {
                                        mutex_status =
                                            acpi_ut_release_mutex
                                            (ACPI_MTX_NAMESPACE);
@@ -216,10 +230,11 @@ acpi_ns_walk_namespace(acpi_object_type type,
                                        }
                                }
 
-                               status = user_function(child_node, level,
-                                                      context, return_value);
+                               status =
+                                   user_function(child_node, level, context,
+                                                 return_value);
 
-                               if (unlock_before_callback) {
+                               if (flags & ACPI_NS_WALK_UNLOCK) {
                                        mutex_status =
                                            acpi_ut_acquire_mutex
                                            (ACPI_MTX_NAMESPACE);
@@ -251,20 +266,17 @@ acpi_ns_walk_namespace(acpi_object_type type,
                        }
 
                        /*
-                        * Depth first search:
-                        * Attempt to go down another level in the namespace
-                        * if we are allowed to.  Don't go any further if we
-                        * have reached the caller specified maximum depth
-                        * or if the user function has specified that the
-                        * maximum depth has been reached.
+                        * Depth first search: Attempt to go down another level in the
+                        * namespace if we are allowed to.  Don't go any further if we have
+                        * reached the caller specified maximum depth or if the user
+                        * function has specified that the maximum depth has been reached.
                         */
                        if ((level < max_depth) && (status != AE_CTRL_DEPTH)) {
                                if (acpi_ns_get_next_node
                                    (ACPI_TYPE_ANY, child_node, NULL)) {
-                                       /*
-                                        * There is at least one child of this
-                                        * node, visit the onde
-                                        */
+
+                                       /* There is at least one child of this node, visit it */
+
                                        level++;
                                        parent_node = child_node;
                                        child_node = NULL;
@@ -272,9 +284,8 @@ acpi_ns_walk_namespace(acpi_object_type type,
                        }
                } else {
                        /*
-                        * No more children of this node (acpi_ns_get_next_node
-                        * failed), go back upwards in the namespace tree to
-                        * the node's parent.
+                        * No more children of this node (acpi_ns_get_next_node failed), go
+                        * back upwards in the namespace tree to the node's parent.
                         */
                        level--;
                        child_node = parent_node;
index dca6799ac678a978df124150cee591c832f5c5c4..7ac6ace5005905f1fa191bbc13dd679311c9e6d4 100644 (file)
@@ -6,7 +6,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -170,7 +170,6 @@ acpi_evaluate_object(acpi_handle handle,
                     struct acpi_buffer *return_buffer)
 {
        acpi_status status;
-       acpi_status status2;
        struct acpi_evaluate_info *info;
        acpi_size buffer_space_needed;
        u32 i;
@@ -329,14 +328,12 @@ acpi_evaluate_object(acpi_handle handle,
                 * Delete the internal return object. NOTE: Interpreter must be
                 * locked to avoid race condition.
                 */
-               status2 = acpi_ex_enter_interpreter();
-               if (ACPI_SUCCESS(status2)) {
+               acpi_ex_enter_interpreter();
 
-                       /* Remove one reference on the return object (should delete it) */
+               /* Remove one reference on the return object (should delete it) */
 
-                       acpi_ut_remove_reference(info->return_object);
-                       acpi_ex_exit_interpreter();
-               }
+               acpi_ut_remove_reference(info->return_object);
+               acpi_ex_exit_interpreter();
        }
 
       cleanup:
index 978213a6c19f23063c47e37073ba7b5b401a166d..b489781b22a85e616e7bdb3c6a1b64d43e041037 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -84,38 +84,41 @@ acpi_get_handle(acpi_handle parent,
        /* Convert a parent handle to a prefix node */
 
        if (parent) {
-               status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
-               if (ACPI_FAILURE(status)) {
-                       return (status);
-               }
-
                prefix_node = acpi_ns_map_handle_to_node(parent);
                if (!prefix_node) {
-                       (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
                        return (AE_BAD_PARAMETER);
                }
+       }
+
+       /*
+        * Valid cases are:
+        * 1) Fully qualified pathname
+        * 2) Parent + Relative pathname
+        *
+        * Error for <null Parent + relative path>
+        */
+       if (acpi_ns_valid_root_prefix(pathname[0])) {
 
-               status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
-               if (ACPI_FAILURE(status)) {
-                       return (status);
+               /* Pathname is fully qualified (starts with '\') */
+
+               /* Special case for root-only, since we can't search for it */
+
+               if (!ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH)) {
+                       *ret_handle =
+                           acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
+                       return (AE_OK);
                }
-       }
+       } else if (!prefix_node) {
 
-       /* Special case for root, since we can't search for it */
+               /* Relative path with null prefix is disallowed */
 
-       if (ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH) == 0) {
-               *ret_handle =
-                   acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
-               return (AE_OK);
+               return (AE_BAD_PARAMETER);
        }
 
-       /*
-        *  Find the Node and convert to a handle
-        */
-       status = acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH,
-                                 &node);
+       /* Find the Node and convert to a handle */
 
-       *ret_handle = NULL;
+       status =
+           acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH, &node);
        if (ACPI_SUCCESS(status)) {
                *ret_handle = acpi_ns_convert_entry_to_handle(node);
        }
index a18b1c223129820da9513a78be11d1cbb1eb73e2..faa3758872012c9a208ec82a0a757f8e82092365 100644 (file)
@@ -6,7 +6,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index bd96a70459256953e405fd58b9a561828528641a..4a9faff4c01dc897bd113dabd50ec961024125a8 100644 (file)
@@ -45,7 +45,7 @@ int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS]
 int __cpuinitdata node_to_pxm_map[MAX_NUMNODES]
                                = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
 
-extern int __init acpi_table_parse_madt_family(enum acpi_table_id id,
+extern int __init acpi_table_parse_madt_family(char *id,
                                               unsigned long madt_size,
                                               int entry_id,
                                               acpi_madt_entry_handler handler,
@@ -89,7 +89,7 @@ void __cpuinit acpi_unmap_pxm_to_node(int node)
        node_clear(node, nodes_found_map);
 }
 
-void __init acpi_table_print_srat_entry(acpi_table_entry_header * header)
+void __init acpi_table_print_srat_entry(struct acpi_subtable_header * header)
 {
 
        ACPI_FUNCTION_NAME("acpi_table_print_srat_entry");
@@ -99,36 +99,35 @@ void __init acpi_table_print_srat_entry(acpi_table_entry_header * header)
 
        switch (header->type) {
 
-       case ACPI_SRAT_PROCESSOR_AFFINITY:
+       case ACPI_SRAT_TYPE_CPU_AFFINITY:
 #ifdef ACPI_DEBUG_OUTPUT
                {
-                       struct acpi_table_processor_affinity *p =
-                           (struct acpi_table_processor_affinity *)header;
+                       struct acpi_srat_cpu_affinity *p =
+                           (struct acpi_srat_cpu_affinity *)header;
                        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                          "SRAT Processor (id[0x%02x] eid[0x%02x]) in proximity domain %d %s\n",
-                                         p->apic_id, p->lsapic_eid,
-                                         p->proximity_domain,
-                                         p->flags.
-                                         enabled ? "enabled" : "disabled"));
+                                         p->apic_id, p->local_sapic_eid,
+                                         p->proximity_domain_lo,
+                                         (p->flags & ACPI_SRAT_CPU_ENABLED)?
+                                         "enabled" : "disabled"));
                }
 #endif                         /* ACPI_DEBUG_OUTPUT */
                break;
 
-       case ACPI_SRAT_MEMORY_AFFINITY:
+       case ACPI_SRAT_TYPE_MEMORY_AFFINITY:
 #ifdef ACPI_DEBUG_OUTPUT
                {
-                       struct acpi_table_memory_affinity *p =
-                           (struct acpi_table_memory_affinity *)header;
+                       struct acpi_srat_mem_affinity *p =
+                           (struct acpi_srat_mem_affinity *)header;
                        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                         "SRAT Memory (0x%08x%08x length 0x%08x%08x type 0x%x) in proximity domain %d %s%s\n",
-                                         p->base_addr_hi, p->base_addr_lo,
-                                         p->length_hi, p->length_lo,
+                                         "SRAT Memory (0x%lx length 0x%lx type 0x%x) in proximity domain %d %s%s\n",
+                                         (unsigned long)p->base_address,
+                                         (unsigned long)p->length,
                                          p->memory_type, p->proximity_domain,
-                                         p->flags.
-                                         enabled ? "enabled" : "disabled",
-                                         p->flags.
-                                         hot_pluggable ? " hot-pluggable" :
-                                         ""));
+                                         (p->flags & ACPI_SRAT_MEM_ENABLED)?
+                                         "enabled" : "disabled",
+                                         (p->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)?
+                                         " hot-pluggable" : ""));
                }
 #endif                         /* ACPI_DEBUG_OUTPUT */
                break;
@@ -141,18 +140,18 @@ void __init acpi_table_print_srat_entry(acpi_table_entry_header * header)
        }
 }
 
-static int __init acpi_parse_slit(unsigned long phys_addr, unsigned long size)
+static int __init acpi_parse_slit(struct acpi_table_header *table)
 {
        struct acpi_table_slit *slit;
        u32 localities;
 
-       if (!phys_addr || !size)
+       if (!table)
                return -EINVAL;
 
-       slit = (struct acpi_table_slit *)__va(phys_addr);
+       slit = (struct acpi_table_slit *)table;
 
        /* downcast just for %llu vs %lu for i386/ia64  */
-       localities = (u32) slit->localities;
+       localities = (u32) slit->locality_count;
 
        acpi_numa_slit_init(slit);
 
@@ -160,12 +159,12 @@ static int __init acpi_parse_slit(unsigned long phys_addr, unsigned long size)
 }
 
 static int __init
-acpi_parse_processor_affinity(acpi_table_entry_header * header,
+acpi_parse_processor_affinity(struct acpi_subtable_header * header,
                              const unsigned long end)
 {
-       struct acpi_table_processor_affinity *processor_affinity;
+       struct acpi_srat_cpu_affinity *processor_affinity;
 
-       processor_affinity = (struct acpi_table_processor_affinity *)header;
+       processor_affinity = (struct acpi_srat_cpu_affinity *)header;
        if (!processor_affinity)
                return -EINVAL;
 
@@ -178,12 +177,12 @@ acpi_parse_processor_affinity(acpi_table_entry_header * header,
 }
 
 static int __init
-acpi_parse_memory_affinity(acpi_table_entry_header * header,
+acpi_parse_memory_affinity(struct acpi_subtable_header * header,
                           const unsigned long end)
 {
-       struct acpi_table_memory_affinity *memory_affinity;
+       struct acpi_srat_mem_affinity *memory_affinity;
 
-       memory_affinity = (struct acpi_table_memory_affinity *)header;
+       memory_affinity = (struct acpi_srat_mem_affinity *)header;
        if (!memory_affinity)
                return -EINVAL;
 
@@ -195,23 +194,23 @@ acpi_parse_memory_affinity(acpi_table_entry_header * header,
        return 0;
 }
 
-static int __init acpi_parse_srat(unsigned long phys_addr, unsigned long size)
+static int __init acpi_parse_srat(struct acpi_table_header *table)
 {
        struct acpi_table_srat *srat;
 
-       if (!phys_addr || !size)
+       if (!table)
                return -EINVAL;
 
-       srat = (struct acpi_table_srat *)__va(phys_addr);
+       srat = (struct acpi_table_srat *)table;
 
        return 0;
 }
 
 int __init
-acpi_table_parse_srat(enum acpi_srat_entry_id id,
+acpi_table_parse_srat(enum acpi_srat_type id,
                      acpi_madt_entry_handler handler, unsigned int max_entries)
 {
-       return acpi_table_parse_madt_family(ACPI_SRAT,
+       return acpi_table_parse_madt_family(ACPI_SIG_SRAT,
                                            sizeof(struct acpi_table_srat), id,
                                            handler, max_entries);
 }
@@ -221,17 +220,17 @@ int __init acpi_numa_init(void)
        int result;
 
        /* SRAT: Static Resource Affinity Table */
-       result = acpi_table_parse(ACPI_SRAT, acpi_parse_srat);
+       result = acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat);
 
        if (result > 0) {
-               result = acpi_table_parse_srat(ACPI_SRAT_PROCESSOR_AFFINITY,
+               result = acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
                                               acpi_parse_processor_affinity,
                                               NR_CPUS);
-               result = acpi_table_parse_srat(ACPI_SRAT_MEMORY_AFFINITY, acpi_parse_memory_affinity, NR_NODE_MEMBLKS); // IA64 specific
+               result = acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY, acpi_parse_memory_affinity, NR_NODE_MEMBLKS);    // IA64 specific
        }
 
        /* SLIT: System Locality Information Table */
-       result = acpi_table_parse(ACPI_SLIT, acpi_parse_slit);
+       result = acpi_table_parse(ACPI_SIG_SLIT, acpi_parse_slit);
 
        acpi_numa_arch_fixup();
        return 0;
index 57ae1e5cde0a2400f8f060d88d7024dd89ba6ba1..0f6f3bcbc8ebc2d4b0c06cb8f1443d1fb5e6e9b6 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/delay.h>
 #include <linux/workqueue.h>
 #include <linux/nmi.h>
+#include <linux/acpi.h>
 #include <acpi/acpi.h>
 #include <asm/io.h>
 #include <acpi/acpi_bus.h>
@@ -75,6 +76,54 @@ static acpi_osd_handler acpi_irq_handler;
 static void *acpi_irq_context;
 static struct workqueue_struct *kacpid_wq;
 
+static void __init acpi_request_region (struct acpi_generic_address *addr,
+       unsigned int length, char *desc)
+{
+       struct resource *res;
+
+       if (!addr->address || !length)
+               return;
+
+       if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
+               res = request_region(addr->address, length, desc);
+       else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
+               res = request_mem_region(addr->address, length, desc);
+}
+
+static int __init acpi_reserve_resources(void)
+{
+       acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
+               "ACPI PM1a_EVT_BLK");
+
+       acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
+               "ACPI PM1b_EVT_BLK");
+
+       acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
+               "ACPI PM1a_CNT_BLK");
+
+       acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
+               "ACPI PM1b_CNT_BLK");
+
+       if (acpi_gbl_FADT.pm_timer_length == 4)
+               acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
+
+       acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
+               "ACPI PM2_CNT_BLK");
+
+       /* Length of GPE blocks must be a non-negative multiple of 2 */
+
+       if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
+               acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
+                              acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
+
+       if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
+               acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
+                              acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
+
+       return 0;
+}
+device_initcall(acpi_reserve_resources);
+
 acpi_status acpi_os_initialize(void)
 {
        return AE_OK;
@@ -136,53 +185,43 @@ void acpi_os_vprintf(const char *fmt, va_list args)
 #endif
 }
 
-acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
+acpi_physical_address __init acpi_os_get_root_pointer(void)
 {
        if (efi_enabled) {
-               addr->pointer_type = ACPI_PHYSICAL_POINTER;
                if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
-                       addr->pointer.physical = efi.acpi20;
+                       return efi.acpi20;
                else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
-                       addr->pointer.physical = efi.acpi;
+                       return efi.acpi;
                else {
                        printk(KERN_ERR PREFIX
                               "System description tables not found\n");
-                       return AE_NOT_FOUND;
+                       return 0;
                }
-       } else {
-               if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) {
-                       printk(KERN_ERR PREFIX
-                              "System description tables not found\n");
-                       return AE_NOT_FOUND;
-               }
-       }
-
-       return AE_OK;
+       } else
+               return acpi_find_rsdp();
 }
 
-acpi_status
-acpi_os_map_memory(acpi_physical_address phys, acpi_size size,
-                  void __iomem ** virt)
+void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
 {
        if (phys > ULONG_MAX) {
                printk(KERN_ERR PREFIX "Cannot map memory that high\n");
-               return AE_BAD_PARAMETER;
+               return 0;
        }
-       /*
-        * ioremap checks to ensure this is in reserved space
-        */
-       *virt = ioremap((unsigned long)phys, size);
-
-       if (!*virt)
-               return AE_NO_MEMORY;
-
-       return AE_OK;
+       if (acpi_gbl_permanent_mmap)
+               /*
+               * ioremap checks to ensure this is in reserved space
+               */
+               return ioremap((unsigned long)phys, size);
+       else
+               return __acpi_map_table((unsigned long)phys, size);
 }
 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
 
 void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
 {
-       iounmap(virt);
+       if (acpi_gbl_permanent_mmap) {
+               iounmap(virt);
+       }
 }
 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
 
@@ -254,7 +293,7 @@ acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
         * FADT. It may not be the same if an interrupt source override exists
         * for the SCI.
         */
-       gsi = acpi_fadt.sci_int;
+       gsi = acpi_gbl_FADT.sci_interrupt;
        if (acpi_gsi_to_irq(gsi, &irq) < 0) {
                printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
                       gsi);
index bf88e076c3e9c66d3ea2c6375731e060665522d8..c2b9835c890b892269e47079cf69a94fc6b9fe1e 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index e1541db3753a75a41a813171d741d3329a73a114..773aee82fbb8e18fb5edf7ed349c220935e0e4ea 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  */
 
 /*
- * Parse the AML and build an operation tree as most interpreters,
- * like Perl, do.  Parsing is done by hand rather than with a YACC
- * generated parser to tightly constrain stack and dynamic memory
- * usage.  At the same time, parsing is kept flexible and the code
- * fairly compact by parsing based on a list of AML opcode
- * templates in aml_op_info[]
+ * Parse the AML and build an operation tree as most interpreters, (such as
+ * Perl) do. Parsing is done by hand rather than with a YACC generated parser
+ * to tightly constrain stack and dynamic memory usage. Parsing is kept
+ * flexible and the code fairly compact by parsing based on a list of AML
+ * opcode templates in aml_op_info[].
  */
 
 #include <acpi/acpi.h>
@@ -60,6 +59,761 @@ ACPI_MODULE_NAME("psloop")
 
 static u32 acpi_gbl_depth = 0;
 
+/* Local prototypes */
+
+static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state);
+
+static acpi_status
+acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
+                      u8 * aml_op_start,
+                      union acpi_parse_object *unnamed_op,
+                      union acpi_parse_object **op);
+
+static acpi_status
+acpi_ps_create_op(struct acpi_walk_state *walk_state,
+                 u8 * aml_op_start, union acpi_parse_object **new_op);
+
+static acpi_status
+acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
+                     u8 * aml_op_start, union acpi_parse_object *op);
+
+static acpi_status
+acpi_ps_complete_op(struct acpi_walk_state *walk_state,
+                   union acpi_parse_object **op, acpi_status status);
+
+static acpi_status
+acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
+                         union acpi_parse_object *op, acpi_status status);
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ps_get_aml_opcode
+ *
+ * PARAMETERS:  walk_state          - Current state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Extract the next AML opcode from the input stream.
+ *
+ ******************************************************************************/
+
+static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state)
+{
+
+       ACPI_FUNCTION_TRACE_PTR(ps_get_aml_opcode, walk_state);
+
+       walk_state->aml_offset =
+           (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml,
+                               walk_state->parser_state.aml_start);
+       walk_state->opcode = acpi_ps_peek_opcode(&(walk_state->parser_state));
+
+       /*
+        * First cut to determine what we have found:
+        * 1) A valid AML opcode
+        * 2) A name string
+        * 3) An unknown/invalid opcode
+        */
+       walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
+
+       switch (walk_state->op_info->class) {
+       case AML_CLASS_ASCII:
+       case AML_CLASS_PREFIX:
+               /*
+                * Starts with a valid prefix or ASCII char, this is a name
+                * string. Convert the bare name string to a namepath.
+                */
+               walk_state->opcode = AML_INT_NAMEPATH_OP;
+               walk_state->arg_types = ARGP_NAMESTRING;
+               break;
+
+       case AML_CLASS_UNKNOWN:
+
+               /* The opcode is unrecognized. Just skip unknown opcodes */
+
+               ACPI_ERROR((AE_INFO,
+                           "Found unknown opcode %X at AML address %p offset %X, ignoring",
+                           walk_state->opcode, walk_state->parser_state.aml,
+                           walk_state->aml_offset));
+
+               ACPI_DUMP_BUFFER(walk_state->parser_state.aml, 128);
+
+               /* Assume one-byte bad opcode */
+
+               walk_state->parser_state.aml++;
+               return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
+
+       default:
+
+               /* Found opcode info, this is a normal opcode */
+
+               walk_state->parser_state.aml +=
+                   acpi_ps_get_opcode_size(walk_state->opcode);
+               walk_state->arg_types = walk_state->op_info->parse_args;
+               break;
+       }
+
+       return_ACPI_STATUS(AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ps_build_named_op
+ *
+ * PARAMETERS:  walk_state          - Current state
+ *              aml_op_start        - Begin of named Op in AML
+ *              unnamed_op          - Early Op (not a named Op)
+ *              Op                  - Returned Op
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Parse a named Op
+ *
+ ******************************************************************************/
+
+static acpi_status
+acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
+                      u8 * aml_op_start,
+                      union acpi_parse_object *unnamed_op,
+                      union acpi_parse_object **op)
+{
+       acpi_status status = AE_OK;
+       union acpi_parse_object *arg = NULL;
+
+       ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state);
+
+       unnamed_op->common.value.arg = NULL;
+       unnamed_op->common.aml_opcode = walk_state->opcode;
+
+       /*
+        * Get and append arguments until we find the node that contains
+        * the name (the type ARGP_NAME).
+        */
+       while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) &&
+              (GET_CURRENT_ARG_TYPE(walk_state->arg_types) != ARGP_NAME)) {
+               status =
+                   acpi_ps_get_next_arg(walk_state,
+                                        &(walk_state->parser_state),
+                                        GET_CURRENT_ARG_TYPE(walk_state->
+                                                             arg_types), &arg);
+               if (ACPI_FAILURE(status)) {
+                       return_ACPI_STATUS(status);
+               }
+
+               acpi_ps_append_arg(unnamed_op, arg);
+               INCREMENT_ARG_LIST(walk_state->arg_types);
+       }
+
+       /*
+        * Make sure that we found a NAME and didn't run out of arguments
+        */
+       if (!GET_CURRENT_ARG_TYPE(walk_state->arg_types)) {
+               return_ACPI_STATUS(AE_AML_NO_OPERAND);
+       }
+
+       /* We know that this arg is a name, move to next arg */
+
+       INCREMENT_ARG_LIST(walk_state->arg_types);
+
+       /*
+        * Find the object. This will either insert the object into
+        * the namespace or simply look it up
+        */
+       walk_state->op = NULL;
+
+       status = walk_state->descending_callback(walk_state, op);
+       if (ACPI_FAILURE(status)) {
+               ACPI_EXCEPTION((AE_INFO, status, "During name lookup/catalog"));
+               return_ACPI_STATUS(status);
+       }
+
+       if (!*op) {
+               return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
+       }
+
+       status = acpi_ps_next_parse_state(walk_state, *op, status);
+       if (ACPI_FAILURE(status)) {
+               if (status == AE_CTRL_PENDING) {
+                       return_ACPI_STATUS(AE_CTRL_PARSE_PENDING);
+               }
+               return_ACPI_STATUS(status);
+       }
+
+       acpi_ps_append_arg(*op, unnamed_op->common.value.arg);
+       acpi_gbl_depth++;
+
+       if ((*op)->common.aml_opcode == AML_REGION_OP) {
+               /*
+                * Defer final parsing of an operation_region body, because we don't
+                * have enough info in the first pass to parse it correctly (i.e.,
+                * there may be method calls within the term_arg elements of the body.)
+                *
+                * However, we must continue parsing because the opregion is not a
+                * standalone package -- we don't know where the end is at this point.
+                *
+                * (Length is unknown until parse of the body complete)
+                */
+               (*op)->named.data = aml_op_start;
+               (*op)->named.length = 0;
+       }
+
+       return_ACPI_STATUS(AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ps_create_op
+ *
+ * PARAMETERS:  walk_state          - Current state
+ *              aml_op_start        - Op start in AML
+ *              new_op              - Returned Op
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Get Op from AML
+ *
+ ******************************************************************************/
+
+static acpi_status
+acpi_ps_create_op(struct acpi_walk_state *walk_state,
+                 u8 * aml_op_start, union acpi_parse_object **new_op)
+{
+       acpi_status status = AE_OK;
+       union acpi_parse_object *op;
+       union acpi_parse_object *named_op = NULL;
+
+       ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state);
+
+       status = acpi_ps_get_aml_opcode(walk_state);
+       if (status == AE_CTRL_PARSE_CONTINUE) {
+               return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
+       }
+
+       /* Create Op structure and append to parent's argument list */
+
+       walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
+       op = acpi_ps_alloc_op(walk_state->opcode);
+       if (!op) {
+               return_ACPI_STATUS(AE_NO_MEMORY);
+       }
+
+       if (walk_state->op_info->flags & AML_NAMED) {
+               status =
+                   acpi_ps_build_named_op(walk_state, aml_op_start, op,
+                                          &named_op);
+               acpi_ps_free_op(op);
+               if (ACPI_FAILURE(status)) {
+                       return_ACPI_STATUS(status);
+               }
+
+               *new_op = named_op;
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       /* Not a named opcode, just allocate Op and append to parent */
+
+       if (walk_state->op_info->flags & AML_CREATE) {
+               /*
+                * Backup to beginning of create_xXXfield declaration
+                * body_length is unknown until we parse the body
+                */
+               op->named.data = aml_op_start;
+               op->named.length = 0;
+       }
+
+       acpi_ps_append_arg(acpi_ps_get_parent_scope
+                          (&(walk_state->parser_state)), op);
+
+       if (walk_state->descending_callback != NULL) {
+               /*
+                * Find the object. This will either insert the object into
+                * the namespace or simply look it up
+                */
+               walk_state->op = *new_op = op;
+
+               status = walk_state->descending_callback(walk_state, &op);
+               status = acpi_ps_next_parse_state(walk_state, op, status);
+               if (status == AE_CTRL_PENDING) {
+                       status = AE_CTRL_PARSE_PENDING;
+               }
+       }
+
+       return_ACPI_STATUS(status);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ps_get_arguments
+ *
+ * PARAMETERS:  walk_state          - Current state
+ *              aml_op_start        - Op start in AML
+ *              Op                  - Current Op
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Get arguments for passed Op.
+ *
+ ******************************************************************************/
+
+static acpi_status
+acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
+                     u8 * aml_op_start, union acpi_parse_object *op)
+{
+       acpi_status status = AE_OK;
+       union acpi_parse_object *arg = NULL;
+
+       ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state);
+
+       switch (op->common.aml_opcode) {
+       case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
+       case AML_WORD_OP:       /* AML_WORDDATA_ARG */
+       case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
+       case AML_QWORD_OP:      /* AML_QWORDATA_ARG */
+       case AML_STRING_OP:     /* AML_ASCIICHARLIST_ARG */
+
+               /* Fill in constant or string argument directly */
+
+               acpi_ps_get_next_simple_arg(&(walk_state->parser_state),
+                                           GET_CURRENT_ARG_TYPE(walk_state->
+                                                                arg_types),
+                                           op);
+               break;
+
+       case AML_INT_NAMEPATH_OP:       /* AML_NAMESTRING_ARG */
+
+               status =
+                   acpi_ps_get_next_namepath(walk_state,
+                                             &(walk_state->parser_state), op,
+                                             1);
+               if (ACPI_FAILURE(status)) {
+                       return_ACPI_STATUS(status);
+               }
+
+               walk_state->arg_types = 0;
+               break;
+
+       default:
+               /*
+                * Op is not a constant or string, append each argument to the Op
+                */
+               while (GET_CURRENT_ARG_TYPE(walk_state->arg_types)
+                      && !walk_state->arg_count) {
+                       walk_state->aml_offset =
+                           (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml,
+                                               walk_state->parser_state.
+                                               aml_start);
+
+                       status =
+                           acpi_ps_get_next_arg(walk_state,
+                                                &(walk_state->parser_state),
+                                                GET_CURRENT_ARG_TYPE
+                                                (walk_state->arg_types), &arg);
+                       if (ACPI_FAILURE(status)) {
+                               return_ACPI_STATUS(status);
+                       }
+
+                       if (arg) {
+                               arg->common.aml_offset = walk_state->aml_offset;
+                               acpi_ps_append_arg(op, arg);
+                       }
+
+                       INCREMENT_ARG_LIST(walk_state->arg_types);
+               }
+
+               /* Special processing for certain opcodes */
+
+               /* TBD (remove): Temporary mechanism to disable this code if needed */
+
+#ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
+
+               if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS1) &&
+                   ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) {
+                       /*
+                        * We want to skip If/Else/While constructs during Pass1 because we
+                        * want to actually conditionally execute the code during Pass2.
+                        *
+                        * Except for disassembly, where we always want to walk the
+                        * If/Else/While packages
+                        */
+                       switch (op->common.aml_opcode) {
+                       case AML_IF_OP:
+                       case AML_ELSE_OP:
+                       case AML_WHILE_OP:
+
+                               ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
+                                                 "Pass1: Skipping an If/Else/While body\n"));
+
+                               /* Skip body of if/else/while in pass 1 */
+
+                               walk_state->parser_state.aml =
+                                   walk_state->parser_state.pkg_end;
+                               walk_state->arg_count = 0;
+                               break;
+
+                       default:
+                               break;
+                       }
+               }
+#endif
+
+               switch (op->common.aml_opcode) {
+               case AML_METHOD_OP:
+                       /*
+                        * Skip parsing of control method because we don't have enough
+                        * info in the first pass to parse it correctly.
+                        *
+                        * Save the length and address of the body
+                        */
+                       op->named.data = walk_state->parser_state.aml;
+                       op->named.length = (u32)
+                           (walk_state->parser_state.pkg_end -
+                            walk_state->parser_state.aml);
+
+                       /* Skip body of method */
+
+                       walk_state->parser_state.aml =
+                           walk_state->parser_state.pkg_end;
+                       walk_state->arg_count = 0;
+                       break;
+
+               case AML_BUFFER_OP:
+               case AML_PACKAGE_OP:
+               case AML_VAR_PACKAGE_OP:
+
+                       if ((op->common.parent) &&
+                           (op->common.parent->common.aml_opcode ==
+                            AML_NAME_OP)
+                           && (walk_state->pass_number <=
+                               ACPI_IMODE_LOAD_PASS2)) {
+                               /*
+                                * Skip parsing of Buffers and Packages because we don't have
+                                * enough info in the first pass to parse them correctly.
+                                */
+                               op->named.data = aml_op_start;
+                               op->named.length = (u32)
+                                   (walk_state->parser_state.pkg_end -
+                                    aml_op_start);
+
+                               /* Skip body */
+
+                               walk_state->parser_state.aml =
+                                   walk_state->parser_state.pkg_end;
+                               walk_state->arg_count = 0;
+                       }
+                       break;
+
+               case AML_WHILE_OP:
+
+                       if (walk_state->control_state) {
+                               walk_state->control_state->control.package_end =
+                                   walk_state->parser_state.pkg_end;
+                       }
+                       break;
+
+               default:
+
+                       /* No action for all other opcodes */
+                       break;
+               }
+
+               break;
+       }
+
+       return_ACPI_STATUS(AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ps_complete_op
+ *
+ * PARAMETERS:  walk_state          - Current state
+ *              Op                  - Returned Op
+ *              Status              - Parse status before complete Op
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Complete Op
+ *
+ ******************************************************************************/
+
+static acpi_status
+acpi_ps_complete_op(struct acpi_walk_state *walk_state,
+                   union acpi_parse_object **op, acpi_status status)
+{
+       acpi_status status2;
+
+       ACPI_FUNCTION_TRACE_PTR(ps_complete_op, walk_state);
+
+       /*
+        * Finished one argument of the containing scope
+        */
+       walk_state->parser_state.scope->parse_scope.arg_count--;
+
+       /* Close this Op (will result in parse subtree deletion) */
+
+       status2 = acpi_ps_complete_this_op(walk_state, *op);
+       if (ACPI_FAILURE(status2)) {
+               return_ACPI_STATUS(status2);
+       }
+
+       *op = NULL;
+
+       switch (status) {
+       case AE_OK:
+               break;
+
+       case AE_CTRL_TRANSFER:
+
+               /* We are about to transfer to a called method */
+
+               walk_state->prev_op = NULL;
+               walk_state->prev_arg_types = walk_state->arg_types;
+               return_ACPI_STATUS(status);
+
+       case AE_CTRL_END:
+
+               acpi_ps_pop_scope(&(walk_state->parser_state), op,
+                                 &walk_state->arg_types,
+                                 &walk_state->arg_count);
+
+               if (*op) {
+                       walk_state->op = *op;
+                       walk_state->op_info =
+                           acpi_ps_get_opcode_info((*op)->common.aml_opcode);
+                       walk_state->opcode = (*op)->common.aml_opcode;
+
+                       status = walk_state->ascending_callback(walk_state);
+                       status =
+                           acpi_ps_next_parse_state(walk_state, *op, status);
+
+                       status2 = acpi_ps_complete_this_op(walk_state, *op);
+                       if (ACPI_FAILURE(status2)) {
+                               return_ACPI_STATUS(status2);
+                       }
+               }
+
+               status = AE_OK;
+               break;
+
+       case AE_CTRL_BREAK:
+       case AE_CTRL_CONTINUE:
+
+               /* Pop off scopes until we find the While */
+
+               while (!(*op) || ((*op)->common.aml_opcode != AML_WHILE_OP)) {
+                       acpi_ps_pop_scope(&(walk_state->parser_state), op,
+                                         &walk_state->arg_types,
+                                         &walk_state->arg_count);
+
+                       if ((*op)->common.aml_opcode != AML_WHILE_OP) {
+                               status2 = acpi_ds_result_stack_pop(walk_state);
+                               if (ACPI_FAILURE(status2)) {
+                                       return_ACPI_STATUS(status2);
+                               }
+                       }
+               }
+
+               /* Close this iteration of the While loop */
+
+               walk_state->op = *op;
+               walk_state->op_info =
+                   acpi_ps_get_opcode_info((*op)->common.aml_opcode);
+               walk_state->opcode = (*op)->common.aml_opcode;
+
+               status = walk_state->ascending_callback(walk_state);
+               status = acpi_ps_next_parse_state(walk_state, *op, status);
+
+               status2 = acpi_ps_complete_this_op(walk_state, *op);
+               if (ACPI_FAILURE(status2)) {
+                       return_ACPI_STATUS(status2);
+               }
+
+               status = AE_OK;
+               break;
+
+       case AE_CTRL_TERMINATE:
+
+               /* Clean up */
+               do {
+                       if (*op) {
+                               status2 =
+                                   acpi_ps_complete_this_op(walk_state, *op);
+                               if (ACPI_FAILURE(status2)) {
+                                       return_ACPI_STATUS(status2);
+                               }
+                               status2 = acpi_ds_result_stack_pop(walk_state);
+                               if (ACPI_FAILURE(status2)) {
+                                       return_ACPI_STATUS(status2);
+                               }
+
+                               acpi_ut_delete_generic_state
+                                   (acpi_ut_pop_generic_state
+                                    (&walk_state->control_state));
+                       }
+
+                       acpi_ps_pop_scope(&(walk_state->parser_state), op,
+                                         &walk_state->arg_types,
+                                         &walk_state->arg_count);
+
+               } while (*op);
+
+               return_ACPI_STATUS(AE_OK);
+
+       default:                /* All other non-AE_OK status */
+
+               do {
+                       if (*op) {
+                               status2 =
+                                   acpi_ps_complete_this_op(walk_state, *op);
+                               if (ACPI_FAILURE(status2)) {
+                                       return_ACPI_STATUS(status2);
+                               }
+                       }
+
+                       acpi_ps_pop_scope(&(walk_state->parser_state), op,
+                                         &walk_state->arg_types,
+                                         &walk_state->arg_count);
+
+               } while (*op);
+
+#if 0
+               /*
+                * TBD: Cleanup parse ops on error
+                */
+               if (*op == NULL) {
+                       acpi_ps_pop_scope(parser_state, op,
+                                         &walk_state->arg_types,
+                                         &walk_state->arg_count);
+               }
+#endif
+               walk_state->prev_op = NULL;
+               walk_state->prev_arg_types = walk_state->arg_types;
+               return_ACPI_STATUS(status);
+       }
+
+       /* This scope complete? */
+
+       if (acpi_ps_has_completed_scope(&(walk_state->parser_state))) {
+               acpi_ps_pop_scope(&(walk_state->parser_state), op,
+                                 &walk_state->arg_types,
+                                 &walk_state->arg_count);
+               ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *op));
+       } else {
+               *op = NULL;
+       }
+
+       return_ACPI_STATUS(AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ps_complete_final_op
+ *
+ * PARAMETERS:  walk_state          - Current state
+ *              Op                  - Current Op
+ *              Status              - Current parse status before complete last
+ *                                    Op
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Complete last Op.
+ *
+ ******************************************************************************/
+
+static acpi_status
+acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
+                         union acpi_parse_object *op, acpi_status status)
+{
+       acpi_status status2;
+
+       ACPI_FUNCTION_TRACE_PTR(ps_complete_final_op, walk_state);
+
+       /*
+        * Complete the last Op (if not completed), and clear the scope stack.
+        * It is easily possible to end an AML "package" with an unbounded number
+        * of open scopes (such as when several ASL blocks are closed with
+        * sequential closing braces). We want to terminate each one cleanly.
+        */
+       ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
+                         op));
+       do {
+               if (op) {
+                       if (walk_state->ascending_callback != NULL) {
+                               walk_state->op = op;
+                               walk_state->op_info =
+                                   acpi_ps_get_opcode_info(op->common.
+                                                           aml_opcode);
+                               walk_state->opcode = op->common.aml_opcode;
+
+                               status =
+                                   walk_state->ascending_callback(walk_state);
+                               status =
+                                   acpi_ps_next_parse_state(walk_state, op,
+                                                            status);
+                               if (status == AE_CTRL_PENDING) {
+                                       status =
+                                           acpi_ps_complete_op(walk_state, &op,
+                                                               AE_OK);
+                                       if (ACPI_FAILURE(status)) {
+                                               return_ACPI_STATUS(status);
+                                       }
+                               }
+
+                               if (status == AE_CTRL_TERMINATE) {
+                                       status = AE_OK;
+
+                                       /* Clean up */
+                                       do {
+                                               if (op) {
+                                                       status2 =
+                                                           acpi_ps_complete_this_op
+                                                           (walk_state, op);
+                                                       if (ACPI_FAILURE
+                                                           (status2)) {
+                                                               return_ACPI_STATUS
+                                                                   (status2);
+                                                       }
+                                               }
+
+                                               acpi_ps_pop_scope(&
+                                                                 (walk_state->
+                                                                  parser_state),
+                                                                 &op,
+                                                                 &walk_state->
+                                                                 arg_types,
+                                                                 &walk_state->
+                                                                 arg_count);
+
+                                       } while (op);
+
+                                       return_ACPI_STATUS(status);
+                               }
+
+                               else if (ACPI_FAILURE(status)) {
+
+                                       /* First error is most important */
+
+                                       (void)
+                                           acpi_ps_complete_this_op(walk_state,
+                                                                    op);
+                                       return_ACPI_STATUS(status);
+                               }
+                       }
+
+                       status2 = acpi_ps_complete_this_op(walk_state, op);
+                       if (ACPI_FAILURE(status2)) {
+                               return_ACPI_STATUS(status2);
+                       }
+               }
+
+               acpi_ps_pop_scope(&(walk_state->parser_state), &op,
+                                 &walk_state->arg_types,
+                                 &walk_state->arg_count);
+
+       } while (op);
+
+       return_ACPI_STATUS(status);
+}
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ps_parse_loop
@@ -76,10 +830,7 @@ static u32 acpi_gbl_depth = 0;
 acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
 {
        acpi_status status = AE_OK;
-       acpi_status status2;
        union acpi_parse_object *op = NULL;     /* current op */
-       union acpi_parse_object *arg = NULL;
-       union acpi_parse_object *pre_op = NULL;
        struct acpi_parse_state *parser_state;
        u8 *aml_op_start = NULL;
 
@@ -128,6 +879,7 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
                                                                "Invoked method did not return a value"));
 
                                        }
+
                                        ACPI_EXCEPTION((AE_INFO, status,
                                                        "GetPredicate Failed"));
                                        return_ACPI_STATUS(status);
@@ -147,228 +899,36 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
 
                        /* We were in the middle of an op */
 
-                       op = walk_state->prev_op;
-                       walk_state->arg_types = walk_state->prev_arg_types;
-               }
-       }
-#endif
-
-       /* Iterative parsing loop, while there is more AML to process: */
-
-       while ((parser_state->aml < parser_state->aml_end) || (op)) {
-               aml_op_start = parser_state->aml;
-               if (!op) {
-
-                       /* Get the next opcode from the AML stream */
-
-                       walk_state->aml_offset =
-                           (u32) ACPI_PTR_DIFF(parser_state->aml,
-                                               parser_state->aml_start);
-                       walk_state->opcode = acpi_ps_peek_opcode(parser_state);
-
-                       /*
-                        * First cut to determine what we have found:
-                        * 1) A valid AML opcode
-                        * 2) A name string
-                        * 3) An unknown/invalid opcode
-                        */
-                       walk_state->op_info =
-                           acpi_ps_get_opcode_info(walk_state->opcode);
-                       switch (walk_state->op_info->class) {
-                       case AML_CLASS_ASCII:
-                       case AML_CLASS_PREFIX:
-                               /*
-                                * Starts with a valid prefix or ASCII char, this is a name
-                                * string.  Convert the bare name string to a namepath.
-                                */
-                               walk_state->opcode = AML_INT_NAMEPATH_OP;
-                               walk_state->arg_types = ARGP_NAMESTRING;
-                               break;
-
-                       case AML_CLASS_UNKNOWN:
-
-                               /* The opcode is unrecognized.  Just skip unknown opcodes */
-
-                               ACPI_ERROR((AE_INFO,
-                                           "Found unknown opcode %X at AML address %p offset %X, ignoring",
-                                           walk_state->opcode,
-                                           parser_state->aml,
-                                           walk_state->aml_offset));
-
-                               ACPI_DUMP_BUFFER(parser_state->aml, 128);
-
-                               /* Assume one-byte bad opcode */
-
-                               parser_state->aml++;
-                               continue;
-
-                       default:
-
-                               /* Found opcode info, this is a normal opcode */
-
-                               parser_state->aml +=
-                                   acpi_ps_get_opcode_size(walk_state->opcode);
-                               walk_state->arg_types =
-                                   walk_state->op_info->parse_args;
-                               break;
-                       }
-
-                       /* Create Op structure and append to parent's argument list */
-
-                       if (walk_state->op_info->flags & AML_NAMED) {
-
-                               /* Allocate a new pre_op if necessary */
-
-                               if (!pre_op) {
-                                       pre_op =
-                                           acpi_ps_alloc_op(walk_state->
-                                                            opcode);
-                                       if (!pre_op) {
-                                               status = AE_NO_MEMORY;
-                                               goto close_this_op;
-                                       }
-                               }
-
-                               pre_op->common.value.arg = NULL;
-                               pre_op->common.aml_opcode = walk_state->opcode;
-
-                               /*
-                                * Get and append arguments until we find the node that contains
-                                * the name (the type ARGP_NAME).
-                                */
-                               while (GET_CURRENT_ARG_TYPE
-                                      (walk_state->arg_types)
-                                      &&
-                                      (GET_CURRENT_ARG_TYPE
-                                       (walk_state->arg_types) != ARGP_NAME)) {
-                                       status =
-                                           acpi_ps_get_next_arg(walk_state,
-                                                                parser_state,
-                                                                GET_CURRENT_ARG_TYPE
-                                                                (walk_state->
-                                                                 arg_types),
-                                                                &arg);
-                                       if (ACPI_FAILURE(status)) {
-                                               goto close_this_op;
-                                       }
-
-                                       acpi_ps_append_arg(pre_op, arg);
-                                       INCREMENT_ARG_LIST(walk_state->
-                                                          arg_types);
-                               }
-
-                               /*
-                                * Make sure that we found a NAME and didn't run out of
-                                * arguments
-                                */
-                               if (!GET_CURRENT_ARG_TYPE
-                                   (walk_state->arg_types)) {
-                                       status = AE_AML_NO_OPERAND;
-                                       goto close_this_op;
-                               }
-
-                               /* We know that this arg is a name, move to next arg */
-
-                               INCREMENT_ARG_LIST(walk_state->arg_types);
-
-                               /*
-                                * Find the object.  This will either insert the object into
-                                * the namespace or simply look it up
-                                */
-                               walk_state->op = NULL;
+                       op = walk_state->prev_op;
+                       walk_state->arg_types = walk_state->prev_arg_types;
+               }
+       }
+#endif
 
-                               status =
-                                   walk_state->descending_callback(walk_state,
-                                                                   &op);
-                               if (ACPI_FAILURE(status)) {
-                                       ACPI_EXCEPTION((AE_INFO, status,
-                                                       "During name lookup/catalog"));
-                                       goto close_this_op;
-                               }
+       /* Iterative parsing loop, while there is more AML to process: */
 
-                               if (!op) {
+       while ((parser_state->aml < parser_state->aml_end) || (op)) {
+               aml_op_start = parser_state->aml;
+               if (!op) {
+                       status =
+                           acpi_ps_create_op(walk_state, aml_op_start, &op);
+                       if (ACPI_FAILURE(status)) {
+                               if (status == AE_CTRL_PARSE_CONTINUE) {
                                        continue;
                                }
 
-                               status =
-                                   acpi_ps_next_parse_state(walk_state, op,
-                                                            status);
-                               if (status == AE_CTRL_PENDING) {
+                               if (status == AE_CTRL_PARSE_PENDING) {
                                        status = AE_OK;
-                                       goto close_this_op;
                                }
 
+                               status =
+                                   acpi_ps_complete_op(walk_state, &op,
+                                                       status);
                                if (ACPI_FAILURE(status)) {
-                                       goto close_this_op;
-                               }
-
-                               acpi_ps_append_arg(op,
-                                                  pre_op->common.value.arg);
-                               acpi_gbl_depth++;
-
-                               if (op->common.aml_opcode == AML_REGION_OP) {
-                                       /*
-                                        * Defer final parsing of an operation_region body,
-                                        * because we don't have enough info in the first pass
-                                        * to parse it correctly (i.e., there may be method
-                                        * calls within the term_arg elements of the body.)
-                                        *
-                                        * However, we must continue parsing because
-                                        * the opregion is not a standalone package --
-                                        * we don't know where the end is at this point.
-                                        *
-                                        * (Length is unknown until parse of the body complete)
-                                        */
-                                       op->named.data = aml_op_start;
-                                       op->named.length = 0;
-                               }
-                       } else {
-                               /* Not a named opcode, just allocate Op and append to parent */
-
-                               walk_state->op_info =
-                                   acpi_ps_get_opcode_info(walk_state->opcode);
-                               op = acpi_ps_alloc_op(walk_state->opcode);
-                               if (!op) {
-                                       status = AE_NO_MEMORY;
-                                       goto close_this_op;
-                               }
-
-                               if (walk_state->op_info->flags & AML_CREATE) {
-                                       /*
-                                        * Backup to beginning of create_xXXfield declaration
-                                        * body_length is unknown until we parse the body
-                                        */
-                                       op->named.data = aml_op_start;
-                                       op->named.length = 0;
+                                       return_ACPI_STATUS(status);
                                }
 
-                               acpi_ps_append_arg(acpi_ps_get_parent_scope
-                                                  (parser_state), op);
-
-                               if ((walk_state->descending_callback != NULL)) {
-                                       /*
-                                        * Find the object. This will either insert the object into
-                                        * the namespace or simply look it up
-                                        */
-                                       walk_state->op = op;
-
-                                       status =
-                                           walk_state->
-                                           descending_callback(walk_state,
-                                                               &op);
-                                       status =
-                                           acpi_ps_next_parse_state(walk_state,
-                                                                    op,
-                                                                    status);
-                                       if (status == AE_CTRL_PENDING) {
-                                               status = AE_OK;
-                                               goto close_this_op;
-                                       }
-
-                                       if (ACPI_FAILURE(status)) {
-                                               goto close_this_op;
-                                       }
-                               }
+                               continue;
                        }
 
                        op->common.aml_offset = walk_state->aml_offset;
@@ -395,172 +955,17 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
 
                        /* Get arguments */
 
-                       switch (op->common.aml_opcode) {
-                       case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
-                       case AML_WORD_OP:       /* AML_WORDDATA_ARG */
-                       case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
-                       case AML_QWORD_OP:      /* AML_QWORDATA_ARG */
-                       case AML_STRING_OP:     /* AML_ASCIICHARLIST_ARG */
-
-                               /* Fill in constant or string argument directly */
-
-                               acpi_ps_get_next_simple_arg(parser_state,
-                                                           GET_CURRENT_ARG_TYPE
-                                                           (walk_state->
-                                                            arg_types), op);
-                               break;
-
-                       case AML_INT_NAMEPATH_OP:       /* AML_NAMESTRING_ARG */
-
+                       status =
+                           acpi_ps_get_arguments(walk_state, aml_op_start, op);
+                       if (ACPI_FAILURE(status)) {
                                status =
-                                   acpi_ps_get_next_namepath(walk_state,
-                                                             parser_state, op,
-                                                             1);
+                                   acpi_ps_complete_op(walk_state, &op,
+                                                       status);
                                if (ACPI_FAILURE(status)) {
-                                       goto close_this_op;
-                               }
-
-                               walk_state->arg_types = 0;
-                               break;
-
-                       default:
-                               /*
-                                * Op is not a constant or string, append each argument
-                                * to the Op
-                                */
-                               while (GET_CURRENT_ARG_TYPE
-                                      (walk_state->arg_types)
-                                      && !walk_state->arg_count) {
-                                       walk_state->aml_offset = (u32)
-                                           ACPI_PTR_DIFF(parser_state->aml,
-                                                         parser_state->
-                                                         aml_start);
-
-                                       status =
-                                           acpi_ps_get_next_arg(walk_state,
-                                                                parser_state,
-                                                                GET_CURRENT_ARG_TYPE
-                                                                (walk_state->
-                                                                 arg_types),
-                                                                &arg);
-                                       if (ACPI_FAILURE(status)) {
-                                               goto close_this_op;
-                                       }
-
-                                       if (arg) {
-                                               arg->common.aml_offset =
-                                                   walk_state->aml_offset;
-                                               acpi_ps_append_arg(op, arg);
-                                       }
-                                       INCREMENT_ARG_LIST(walk_state->
-                                                          arg_types);
-                               }
-
-                               /* Special processing for certain opcodes */
-
-                               /* TBD (remove): Temporary mechanism to disable this code if needed */
-
-#ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
-
-                               if ((walk_state->pass_number <=
-                                    ACPI_IMODE_LOAD_PASS1)
-                                   &&
-                                   ((walk_state->
-                                     parse_flags & ACPI_PARSE_DISASSEMBLE) ==
-                                    0)) {
-                                       /*
-                                        * We want to skip If/Else/While constructs during Pass1
-                                        * because we want to actually conditionally execute the
-                                        * code during Pass2.
-                                        *
-                                        * Except for disassembly, where we always want to
-                                        * walk the If/Else/While packages
-                                        */
-                                       switch (op->common.aml_opcode) {
-                                       case AML_IF_OP:
-                                       case AML_ELSE_OP:
-                                       case AML_WHILE_OP:
-
-                                               ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
-                                                                 "Pass1: Skipping an If/Else/While body\n"));
-
-                                               /* Skip body of if/else/while in pass 1 */
-
-                                               parser_state->aml =
-                                                   parser_state->pkg_end;
-                                               walk_state->arg_count = 0;
-                                               break;
-
-                                       default:
-                                               break;
-                                       }
+                                       return_ACPI_STATUS(status);
                                }
-#endif
-                               switch (op->common.aml_opcode) {
-                               case AML_METHOD_OP:
-
-                                       /*
-                                        * Skip parsing of control method
-                                        * because we don't have enough info in the first pass
-                                        * to parse it correctly.
-                                        *
-                                        * Save the length and address of the body
-                                        */
-                                       op->named.data = parser_state->aml;
-                                       op->named.length =
-                                           (u32) (parser_state->pkg_end -
-                                                  parser_state->aml);
-
-                                       /* Skip body of method */
-
-                                       parser_state->aml =
-                                           parser_state->pkg_end;
-                                       walk_state->arg_count = 0;
-                                       break;
-
-                               case AML_BUFFER_OP:
-                               case AML_PACKAGE_OP:
-                               case AML_VAR_PACKAGE_OP:
-
-                                       if ((op->common.parent) &&
-                                           (op->common.parent->common.
-                                            aml_opcode == AML_NAME_OP)
-                                           && (walk_state->pass_number <=
-                                               ACPI_IMODE_LOAD_PASS2)) {
-                                               /*
-                                                * Skip parsing of Buffers and Packages
-                                                * because we don't have enough info in the first pass
-                                                * to parse them correctly.
-                                                */
-                                               op->named.data = aml_op_start;
-                                               op->named.length =
-                                                   (u32) (parser_state->
-                                                          pkg_end -
-                                                          aml_op_start);
-
-                                               /* Skip body */
-
-                                               parser_state->aml =
-                                                   parser_state->pkg_end;
-                                               walk_state->arg_count = 0;
-                                       }
-                                       break;
-
-                               case AML_WHILE_OP:
 
-                                       if (walk_state->control_state) {
-                                               walk_state->control_state->
-                                                   control.package_end =
-                                                   parser_state->pkg_end;
-                                       }
-                                       break;
-
-                               default:
-
-                                       /* No action for all other opcodes */
-                                       break;
-                               }
-                               break;
+                               continue;
                        }
                }
 
@@ -575,8 +980,16 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
                                                    walk_state->arg_types,
                                                    walk_state->arg_count);
                        if (ACPI_FAILURE(status)) {
-                               goto close_this_op;
+                               status =
+                                   acpi_ps_complete_op(walk_state, &op,
+                                                       status);
+                               if (ACPI_FAILURE(status)) {
+                                       return_ACPI_STATUS(status);
+                               }
+
+                               continue;
                        }
+
                        op = NULL;
                        continue;
                }
@@ -628,269 +1041,16 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
                            acpi_ps_next_parse_state(walk_state, op, status);
                        if (status == AE_CTRL_PENDING) {
                                status = AE_OK;
-                               goto close_this_op;
                        }
                }
 
-             close_this_op:
-               /*
-                * Finished one argument of the containing scope
-                */
-               parser_state->scope->parse_scope.arg_count--;
-
-               /* Finished with pre_op */
-
-               if (pre_op) {
-                       acpi_ps_free_op(pre_op);
-                       pre_op = NULL;
-               }
-
-               /* Close this Op (will result in parse subtree deletion) */
-
-               status2 = acpi_ps_complete_this_op(walk_state, op);
-               if (ACPI_FAILURE(status2)) {
-                       return_ACPI_STATUS(status2);
-               }
-               op = NULL;
-
-               switch (status) {
-               case AE_OK:
-                       break;
-
-               case AE_CTRL_TRANSFER:
-
-                       /* We are about to transfer to a called method. */
-
-                       walk_state->prev_op = op;
-                       walk_state->prev_arg_types = walk_state->arg_types;
-                       return_ACPI_STATUS(status);
-
-               case AE_CTRL_END:
-
-                       acpi_ps_pop_scope(parser_state, &op,
-                                         &walk_state->arg_types,
-                                         &walk_state->arg_count);
-
-                       if (op) {
-                               walk_state->op = op;
-                               walk_state->op_info =
-                                   acpi_ps_get_opcode_info(op->common.
-                                                           aml_opcode);
-                               walk_state->opcode = op->common.aml_opcode;
-
-                               status =
-                                   walk_state->ascending_callback(walk_state);
-                               status =
-                                   acpi_ps_next_parse_state(walk_state, op,
-                                                            status);
-
-                               status2 =
-                                   acpi_ps_complete_this_op(walk_state, op);
-                               if (ACPI_FAILURE(status2)) {
-                                       return_ACPI_STATUS(status2);
-                               }
-                               op = NULL;
-                       }
-                       status = AE_OK;
-                       break;
-
-               case AE_CTRL_BREAK:
-               case AE_CTRL_CONTINUE:
-
-                       /* Pop off scopes until we find the While */
-
-                       while (!op || (op->common.aml_opcode != AML_WHILE_OP)) {
-                               acpi_ps_pop_scope(parser_state, &op,
-                                                 &walk_state->arg_types,
-                                                 &walk_state->arg_count);
-
-                               if (op->common.aml_opcode != AML_WHILE_OP) {
-                                       status2 =
-                                           acpi_ds_result_stack_pop
-                                           (walk_state);
-                                       if (ACPI_FAILURE(status2)) {
-                                               return_ACPI_STATUS(status2);
-                                       }
-                               }
-                       }
-
-                       /* Close this iteration of the While loop */
-
-                       walk_state->op = op;
-                       walk_state->op_info =
-                           acpi_ps_get_opcode_info(op->common.aml_opcode);
-                       walk_state->opcode = op->common.aml_opcode;
-
-                       status = walk_state->ascending_callback(walk_state);
-                       status =
-                           acpi_ps_next_parse_state(walk_state, op, status);
-
-                       status2 = acpi_ps_complete_this_op(walk_state, op);
-                       if (ACPI_FAILURE(status2)) {
-                               return_ACPI_STATUS(status2);
-                       }
-                       op = NULL;
-
-                       status = AE_OK;
-                       break;
-
-               case AE_CTRL_TERMINATE:
-
-                       status = AE_OK;
-
-                       /* Clean up */
-                       do {
-                               if (op) {
-                                       status2 =
-                                           acpi_ps_complete_this_op(walk_state,
-                                                                    op);
-                                       if (ACPI_FAILURE(status2)) {
-                                               return_ACPI_STATUS(status2);
-                                       }
-
-                                       status2 =
-                                           acpi_ds_result_stack_pop
-                                           (walk_state);
-                                       if (ACPI_FAILURE(status2)) {
-                                               return_ACPI_STATUS(status2);
-                                       }
-
-                                       acpi_ut_delete_generic_state
-                                           (acpi_ut_pop_generic_state
-                                            (&walk_state->control_state));
-                               }
-
-                               acpi_ps_pop_scope(parser_state, &op,
-                                                 &walk_state->arg_types,
-                                                 &walk_state->arg_count);
-
-                       } while (op);
-
-                       return_ACPI_STATUS(status);
-
-               default:        /* All other non-AE_OK status */
-
-                       do {
-                               if (op) {
-                                       status2 =
-                                           acpi_ps_complete_this_op(walk_state,
-                                                                    op);
-                                       if (ACPI_FAILURE(status2)) {
-                                               return_ACPI_STATUS(status2);
-                                       }
-                               }
-
-                               acpi_ps_pop_scope(parser_state, &op,
-                                                 &walk_state->arg_types,
-                                                 &walk_state->arg_count);
-
-                       } while (op);
-
-                       /*
-                        * TBD: Cleanup parse ops on error
-                        */
-#if 0
-                       if (op == NULL) {
-                               acpi_ps_pop_scope(parser_state, &op,
-                                                 &walk_state->arg_types,
-                                                 &walk_state->arg_count);
-                       }
-#endif
-                       walk_state->prev_op = op;
-                       walk_state->prev_arg_types = walk_state->arg_types;
+               status = acpi_ps_complete_op(walk_state, &op, status);
+               if (ACPI_FAILURE(status)) {
                        return_ACPI_STATUS(status);
                }
 
-               /* This scope complete? */
-
-               if (acpi_ps_has_completed_scope(parser_state)) {
-                       acpi_ps_pop_scope(parser_state, &op,
-                                         &walk_state->arg_types,
-                                         &walk_state->arg_count);
-                       ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
-                                         "Popped scope, Op=%p\n", op));
-               } else {
-                       op = NULL;
-               }
-
        }                       /* while parser_state->Aml */
 
-       /*
-        * Complete the last Op (if not completed), and clear the scope stack.
-        * It is easily possible to end an AML "package" with an unbounded number
-        * of open scopes (such as when several ASL blocks are closed with
-        * sequential closing braces).  We want to terminate each one cleanly.
-        */
-       ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
-                         op));
-       do {
-               if (op) {
-                       if (walk_state->ascending_callback != NULL) {
-                               walk_state->op = op;
-                               walk_state->op_info =
-                                   acpi_ps_get_opcode_info(op->common.
-                                                           aml_opcode);
-                               walk_state->opcode = op->common.aml_opcode;
-
-                               status =
-                                   walk_state->ascending_callback(walk_state);
-                               status =
-                                   acpi_ps_next_parse_state(walk_state, op,
-                                                            status);
-                               if (status == AE_CTRL_PENDING) {
-                                       status = AE_OK;
-                                       goto close_this_op;
-                               }
-
-                               if (status == AE_CTRL_TERMINATE) {
-                                       status = AE_OK;
-
-                                       /* Clean up */
-                                       do {
-                                               if (op) {
-                                                       status2 =
-                                                           acpi_ps_complete_this_op
-                                                           (walk_state, op);
-                                                       if (ACPI_FAILURE
-                                                           (status2)) {
-                                                               return_ACPI_STATUS
-                                                                   (status2);
-                                                       }
-                                               }
-
-                                               acpi_ps_pop_scope(parser_state,
-                                                                 &op,
-                                                                 &walk_state->
-                                                                 arg_types,
-                                                                 &walk_state->
-                                                                 arg_count);
-
-                                       } while (op);
-
-                                       return_ACPI_STATUS(status);
-                               }
-
-                               else if (ACPI_FAILURE(status)) {
-
-                                       /* First error is most important */
-
-                                       (void)
-                                           acpi_ps_complete_this_op(walk_state,
-                                                                    op);
-                                       return_ACPI_STATUS(status);
-                               }
-                       }
-
-                       status2 = acpi_ps_complete_this_op(walk_state, op);
-                       if (ACPI_FAILURE(status2)) {
-                               return_ACPI_STATUS(status2);
-                       }
-               }
-
-               acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types,
-                                 &walk_state->arg_count);
-
-       } while (op);
-
+       status = acpi_ps_complete_final_op(walk_state, op, status);
        return_ACPI_STATUS(status);
 }
index 4bd25e32769f7443235d7831dbbb3aef1317f061..16d8b6cc3c220407917111204ba587f6164845aa 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index a02aa62fe1e5324f417e47d6c41bb8d67204311c..5d63f48e56b5cadc475b0af1206be28ba2c83d35 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -540,6 +540,11 @@ acpi_status acpi_ps_parse_aml(struct acpi_walk_state *walk_state)
 
                        if ((status == AE_ALREADY_EXISTS) &&
                            (!walk_state->method_desc->method.mutex)) {
+                               ACPI_INFO((AE_INFO,
+                                          "Marking method %4.4s as Serialized",
+                                          walk_state->method_node->name.
+                                          ascii));
+
                                /*
                                 * Method tried to create an object twice. The probable cause is
                                 * that the method cannot handle reentrancy.
index a3e0314de24d5443a4d7aa0d583409663b3102b1..77cfa4ed0cfeccfcc94e187fc0726a96e3df7006 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 0015717ef096b64417a0166573922a28232d3b7d..966e7ea2a0c49b2cdc9a25e76fb23f9c02a9a3d1 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index d405387b74146790fe3ba2f671fb0ef681cb1643..8ca52002db5523244f1e6f69a615e179982b557d 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index a84a547a0f1b469706cff58935750ed4ec05db56..49f9757434e4742bd5324c3e2c384af9be07f45e 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 5d996c1140af39ac64b1e30d2a8ba711a7a34f23..94103bced75e0044ac62820ac47a482665d04285 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -54,8 +54,6 @@ static void acpi_ps_start_trace(struct acpi_evaluate_info *info);
 
 static void acpi_ps_stop_trace(struct acpi_evaluate_info *info);
 
-static acpi_status acpi_ps_execute_pass(struct acpi_evaluate_info *info);
-
 static void
 acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action);
 
@@ -215,6 +213,8 @@ static void acpi_ps_stop_trace(struct acpi_evaluate_info *info)
 acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
 {
        acpi_status status;
+       union acpi_parse_object *op;
+       struct acpi_walk_state *walk_state;
 
        ACPI_FUNCTION_TRACE(ps_execute_method);
 
@@ -234,8 +234,7 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
        }
 
        /*
-        * The caller "owns" the parameters, so give each one an extra
-        * reference
+        * The caller "owns" the parameters, so give each one an extra reference
         */
        acpi_ps_update_parameter_list(info, REF_INCREMENT);
 
@@ -244,30 +243,50 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
        acpi_ps_start_trace(info);
 
        /*
-        * 1) Perform the first pass parse of the method to enter any
-        *    named objects that it creates into the namespace
+        * Execute the method. Performs parse simultaneously
         */
        ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
-                         "**** Begin Method Parse **** Entry=%p obj=%p\n",
-                         info->resolved_node, info->obj_desc));
+                         "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",
+                         info->resolved_node->name.ascii, info->resolved_node,
+                         info->obj_desc));
+
+       /* Create and init a Root Node */
+
+       op = acpi_ps_create_scope_op();
+       if (!op) {
+               status = AE_NO_MEMORY;
+               goto cleanup;
+       }
+
+       /* Create and initialize a new walk state */
+
+       info->pass_number = ACPI_IMODE_EXECUTE;
+       walk_state =
+           acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
+                                     NULL, NULL);
+       if (!walk_state) {
+               status = AE_NO_MEMORY;
+               goto cleanup;
+       }
 
-       info->pass_number = 1;
-       status = acpi_ps_execute_pass(info);
+       status = acpi_ds_init_aml_walk(walk_state, op, info->resolved_node,
+                                      info->obj_desc->method.aml_start,
+                                      info->obj_desc->method.aml_length, info,
+                                      info->pass_number);
        if (ACPI_FAILURE(status)) {
+               acpi_ds_delete_walk_state(walk_state);
                goto cleanup;
        }
 
-       /*
-        * 2) Execute the method. Performs second pass parse simultaneously
-        */
-       ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
-                         "**** Begin Method Execution **** Entry=%p obj=%p\n",
-                         info->resolved_node, info->obj_desc));
+       /* Parse the AML */
 
-       info->pass_number = 3;
-       status = acpi_ps_execute_pass(info);
+       status = acpi_ps_parse_aml(walk_state);
+
+       /* walk_state was deleted by parse_aml */
 
       cleanup:
+       acpi_ps_delete_parse_tree(op);
+
        /* End optional tracing */
 
        acpi_ps_stop_trace(info);
@@ -330,62 +349,3 @@ acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action)
                }
        }
 }
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ps_execute_pass
- *
- * PARAMETERS:  Info            - See struct acpi_evaluate_info
- *                                (Used: pass_number, Node, and obj_desc)
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Single AML pass: Parse or Execute a control method
- *
- ******************************************************************************/
-
-static acpi_status acpi_ps_execute_pass(struct acpi_evaluate_info *info)
-{
-       acpi_status status;
-       union acpi_parse_object *op;
-       struct acpi_walk_state *walk_state;
-
-       ACPI_FUNCTION_TRACE(ps_execute_pass);
-
-       /* Create and init a Root Node */
-
-       op = acpi_ps_create_scope_op();
-       if (!op) {
-               return_ACPI_STATUS(AE_NO_MEMORY);
-       }
-
-       /* Create and initialize a new walk state */
-
-       walk_state =
-           acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
-                                     NULL, NULL);
-       if (!walk_state) {
-               status = AE_NO_MEMORY;
-               goto cleanup;
-       }
-
-       status = acpi_ds_init_aml_walk(walk_state, op, info->resolved_node,
-                                      info->obj_desc->method.aml_start,
-                                      info->obj_desc->method.aml_length,
-                                      info->pass_number == 1 ? NULL : info,
-                                      info->pass_number);
-       if (ACPI_FAILURE(status)) {
-               acpi_ds_delete_walk_state(walk_state);
-               goto cleanup;
-       }
-
-       /* Parse the AML */
-
-       status = acpi_ps_parse_aml(walk_state);
-
-       /* Walk state was deleted by parse_aml */
-
-      cleanup:
-       acpi_ps_delete_parse_tree(op);
-       return_ACPI_STATUS(status);
-}
index 481e633bbf41b33c16b6c7def7ff16e8252592ea..0f683c8c6fbc76676b193241e5af457118c7915f 100644 (file)
@@ -513,7 +513,7 @@ int __init acpi_irq_penalty_init(void)
                }
        }
        /* Add a penalty for the SCI */
-       acpi_irq_penalty[acpi_fadt.sci_int] += PIRQ_PENALTY_PCI_USING;
+       acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING;
 
        return 0;
 }
@@ -785,7 +785,7 @@ static int irqrouter_resume(struct sys_device *dev)
 
 
        /* Make sure SCI is enabled again (Apple firmware bug?) */
-       acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1, ACPI_MTX_DO_NOT_LOCK);
+       acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1);
 
        list_for_each(node, &acpi_link.entries) {
                link = list_entry(node, struct acpi_pci_link, node);
index a860efa2c562670768e447ada93eea69b03277d1..4ecf701687e8768d23135796f3c818b0b68a213f 100644 (file)
@@ -117,6 +117,19 @@ void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
 
 EXPORT_SYMBOL(acpi_pci_unregister_driver);
 
+acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
+{
+       struct acpi_pci_root *tmp;
+       
+       list_for_each_entry(tmp, &acpi_pci_roots, node) {
+               if ((tmp->id.segment == (u16) seg) && (tmp->id.bus == (u16) bus))
+                       return tmp->device->handle;
+       }
+       return NULL;            
+}
+
+EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
+
 static acpi_status
 get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
 {
@@ -152,6 +165,21 @@ static acpi_status try_get_root_bridge_busnr(acpi_handle handle, int *busnum)
        return AE_OK;
 }
 
+static void acpi_pci_bridge_scan(struct acpi_device *device)
+{
+       int status;
+       struct acpi_device *child = NULL;
+
+       if (device->flags.bus_address)
+               if (device->parent && device->parent->ops.bind) {
+                       status = device->parent->ops.bind(device);
+                       if (!status) {
+                               list_for_each_entry(child, &device->children, node)
+                                       acpi_pci_bridge_scan(child);
+                       }
+               }
+}
+
 static int acpi_pci_root_add(struct acpi_device *device)
 {
        int result = 0;
@@ -160,6 +188,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
        acpi_status status = AE_OK;
        unsigned long value = 0;
        acpi_handle handle = NULL;
+       struct acpi_device *child;
 
 
        if (!device)
@@ -175,9 +204,6 @@ static int acpi_pci_root_add(struct acpi_device *device)
        strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
        acpi_driver_data(device) = root;
 
-       /*
-        * TBD: Doesn't the bus driver automatically set this?
-        */
        device->ops.bind = acpi_pci_bind;
 
        /* 
@@ -299,6 +325,12 @@ static int acpi_pci_root_add(struct acpi_device *device)
                result = acpi_pci_irq_add_prt(device->handle, root->id.segment,
                                              root->id.bus);
 
+       /*
+        * Scan and bind all _ADR-Based Devices
+        */
+       list_for_each_entry(child, &device->children, node)
+               acpi_pci_bridge_scan(child);
+
       end:
        if (result) {
                if (!list_empty(&root->node))
index 5f9496d59ed6e42a75dcc634312141609b08cd16..0079bc51082c723eb35ee5098159f1acf3574ba2 100644 (file)
@@ -375,30 +375,126 @@ static int acpi_processor_remove_fs(struct acpi_device *device)
 }
 
 /* Use the acpiid in MADT to map cpus in case of SMP */
+
 #ifndef CONFIG_SMP
-#define convert_acpiid_to_cpu(acpi_id) (-1)
+static int get_cpu_id(acpi_handle handle, u32 acpi_id) {return -1;}
 #else
 
+static struct acpi_table_madt *madt;
+
+static int map_lapic_id(struct acpi_subtable_header *entry,
+                u32 acpi_id, int *apic_id)
+{
+       struct acpi_madt_local_apic *lapic =
+               (struct acpi_madt_local_apic *)entry;
+       if ((lapic->lapic_flags & ACPI_MADT_ENABLED) &&
+           lapic->processor_id == acpi_id) {
+               *apic_id = lapic->id;
+               return 1;
+       }
+       return 0;
+}
+
+static int map_lsapic_id(struct acpi_subtable_header *entry,
+                 u32 acpi_id, int *apic_id)
+{
+       struct acpi_madt_local_sapic *lsapic =
+               (struct acpi_madt_local_sapic *)entry;
+       /* Only check enabled APICs*/
+       if (lsapic->lapic_flags & ACPI_MADT_ENABLED) {
+               /* First check against id */
+               if (lsapic->processor_id == acpi_id) {
+                       *apic_id = lsapic->id;
+                       return 1;
+               /* Check against optional uid */
+               } else if (entry->length >= 16 &&
+                       lsapic->uid == acpi_id) {
+                       *apic_id = lsapic->uid;
+                       return 1;
+               }
+       }
+       return 0;
+}
+
 #ifdef CONFIG_IA64
-#define arch_acpiid_to_apicid  ia64_acpiid_to_sapicid
 #define arch_cpu_to_apicid     ia64_cpu_to_sapicid
-#define ARCH_BAD_APICID                (0xffff)
 #else
-#define arch_acpiid_to_apicid  x86_acpiid_to_apicid
 #define arch_cpu_to_apicid     x86_cpu_to_apicid
-#define ARCH_BAD_APICID                (0xff)
 #endif
 
-static int convert_acpiid_to_cpu(u8 acpi_id)
+static int map_madt_entry(u32 acpi_id)
+{
+       unsigned long madt_end, entry;
+       int apic_id = -1;
+
+       if (!madt)
+               return apic_id;
+
+       entry = (unsigned long)madt;
+       madt_end = entry + madt->header.length;
+
+       /* Parse all entries looking for a match. */
+
+       entry += sizeof(struct acpi_table_madt);
+       while (entry + sizeof(struct acpi_subtable_header) < madt_end) {
+               struct acpi_subtable_header *header =
+                       (struct acpi_subtable_header *)entry;
+               if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
+                       if (map_lapic_id(header, acpi_id, &apic_id))
+                               break;
+               } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
+                       if (map_lsapic_id(header, acpi_id, &apic_id))
+                               break;
+               }
+               entry += header->length;
+       }
+       return apic_id;
+}
+
+static int map_mat_entry(acpi_handle handle, u32 acpi_id)
+{
+       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+       union acpi_object *obj;
+       struct acpi_subtable_header *header;
+       int apic_id = -1;
+
+       if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
+               goto exit;
+
+       if (!buffer.length || !buffer.pointer)
+               goto exit;
+
+       obj = buffer.pointer;
+       if (obj->type != ACPI_TYPE_BUFFER ||
+           obj->buffer.length < sizeof(struct acpi_subtable_header)) {
+               goto exit;
+       }
+
+       header = (struct acpi_subtable_header *)obj->buffer.pointer;
+       if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
+               map_lapic_id(header, acpi_id, &apic_id);
+       } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
+               map_lsapic_id(header, acpi_id, &apic_id);
+       }
+
+exit:
+       if (buffer.pointer)
+               kfree(buffer.pointer);
+       return apic_id;
+}
+
+static int get_cpu_id(acpi_handle handle, u32 acpi_id)
 {
-       u16 apic_id;
        int i;
+       int apic_id = -1;
 
-       apic_id = arch_acpiid_to_apicid[acpi_id];
-       if (apic_id == ARCH_BAD_APICID)
-               return -1;
+       apic_id = map_mat_entry(handle, acpi_id);
+       if (apic_id == -1)
+               apic_id = map_madt_entry(acpi_id);
+       if (apic_id == -1)
+               return apic_id;
 
-       for (i = 0; i < NR_CPUS; i++) {
+       for (i = 0; i < NR_CPUS; ++i) {
                if (arch_cpu_to_apicid[i] == apic_id)
                        return i;
        }
@@ -410,7 +506,7 @@ static int convert_acpiid_to_cpu(u8 acpi_id)
                                  Driver Interface
    -------------------------------------------------------------------------- */
 
-static int acpi_processor_get_info(struct acpi_processor *pr)
+static int acpi_processor_get_info(struct acpi_processor *pr, unsigned has_uid)
 {
        acpi_status status = 0;
        union acpi_object object = { 0 };
@@ -431,7 +527,7 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
         * Check to see if we have bus mastering arbitration control.  This
         * is required for proper C3 usage (to maintain cache coherency).
         */
-       if (acpi_fadt.V1_pm2_cnt_blk && acpi_fadt.pm2_cnt_len) {
+       if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
                pr->flags.bm_control = 1;
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                  "Bus mastering arbitration control present\n"));
@@ -439,24 +535,35 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                  "No bus mastering arbitration control\n"));
 
-       /*
-        * Evalute the processor object.  Note that it is common on SMP to
-        * have the first (boot) processor with a valid PBLK address while
-        * all others have a NULL address.
-        */
-       status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
-       if (ACPI_FAILURE(status)) {
-               printk(KERN_ERR PREFIX "Evaluating processor object\n");
-               return -ENODEV;
-       }
-
-       /*
-        * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
-        *      >>> 'acpi_get_processor_id(acpi_id, &id)' in arch/xxx/acpi.c
-        */
-       pr->acpi_id = object.processor.proc_id;
+       /* Check if it is a Device with HID and UID */
+       if (has_uid) {
+               unsigned long value;
+               status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
+                                               NULL, &value);
+               if (ACPI_FAILURE(status)) {
+                       printk(KERN_ERR PREFIX "Evaluating processor _UID\n");
+                       return -ENODEV;
+               }
+               pr->acpi_id = value;
+       } else {
+               /*
+               * Evalute the processor object.  Note that it is common on SMP to
+               * have the first (boot) processor with a valid PBLK address while
+               * all others have a NULL address.
+               */
+               status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
+               if (ACPI_FAILURE(status)) {
+                       printk(KERN_ERR PREFIX "Evaluating processor object\n");
+                       return -ENODEV;
+               }
 
-       cpu_index = convert_acpiid_to_cpu(pr->acpi_id);
+               /*
+               * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
+               *      >>> 'acpi_get_processor_id(acpi_id, &id)' in arch/xxx/acpi.c
+               */
+               pr->acpi_id = object.processor.proc_id;
+       }
+       cpu_index = get_cpu_id(pr->handle, pr->acpi_id);
 
        /* Handle UP system running SMP kernel, with no LAPIC in MADT */
        if (!cpu0_initialized && (cpu_index == -1) &&
@@ -473,7 +580,7 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
         *  less than the max # of CPUs. They should be ignored _iff
         *  they are physically not present.
         */
-       if (cpu_index == -1) {
+       if (pr->id == -1) {
                if (ACPI_FAILURE
                    (acpi_processor_hotadd_init(pr->handle, &pr->id))) {
                        return -ENODEV;
@@ -490,8 +597,8 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
                            object.processor.pblk_length);
        else {
                pr->throttling.address = object.processor.pblk_address;
-               pr->throttling.duty_offset = acpi_fadt.duty_offset;
-               pr->throttling.duty_width = acpi_fadt.duty_width;
+               pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
+               pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
 
                pr->pblk = object.processor.pblk_address;
 
@@ -525,7 +632,7 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
 
        pr = acpi_driver_data(device);
 
-       result = acpi_processor_get_info(pr);
+       result = acpi_processor_get_info(pr, device->flags.unique_id);
        if (result) {
                /* Processor is physically not present */
                return 0;
@@ -707,7 +814,7 @@ int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
                return -ENODEV;
 
        if ((pr->id >= 0) && (pr->id < NR_CPUS)) {
-               kobject_uevent(&(*device)->kobj, KOBJ_ONLINE);
+               kobject_uevent(&(*device)->dev.kobj, KOBJ_ONLINE);
        }
        return 0;
 }
@@ -745,13 +852,13 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
                }
 
                if (pr->id >= 0 && (pr->id < NR_CPUS)) {
-                       kobject_uevent(&device->kobj, KOBJ_OFFLINE);
+                       kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
                        break;
                }
 
                result = acpi_processor_start(device);
                if ((!result) && ((pr->id >= 0) && (pr->id < NR_CPUS))) {
-                       kobject_uevent(&device->kobj, KOBJ_ONLINE);
+                       kobject_uevent(&device->dev.kobj, KOBJ_ONLINE);
                } else {
                        printk(KERN_ERR PREFIX "Device [%s] failed to start\n",
                                    acpi_device_bid(device));
@@ -774,7 +881,7 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
                }
 
                if ((pr->id < NR_CPUS) && (cpu_present(pr->id)))
-                       kobject_uevent(&device->kobj, KOBJ_OFFLINE);
+                       kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
                break;
        default:
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -895,6 +1002,12 @@ static int __init acpi_processor_init(void)
        memset(&processors, 0, sizeof(processors));
        memset(&errata, 0, sizeof(errata));
 
+#ifdef CONFIG_SMP
+       if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
+                               (struct acpi_table_header **)&madt)))
+               madt = 0;
+#endif
+
        acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
        if (!acpi_processor_dir)
                return -ENOMEM;
index 3f30af21574ea37c3d443f54e2050fa4fb85c77f..6c6751b1405be5d7547a0e7f9010bc7dbaa82593 100644 (file)
@@ -160,7 +160,7 @@ static inline u32 ticks_elapsed(u32 t1, u32 t2)
 {
        if (t2 >= t1)
                return (t2 - t1);
-       else if (!acpi_fadt.tmr_val_ext)
+       else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER))
                return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
        else
                return ((0xFFFFFFFF - t1) + t2);
@@ -187,8 +187,7 @@ acpi_processor_power_activate(struct acpi_processor *pr,
                case ACPI_STATE_C3:
                        /* Disable bus master reload */
                        if (new->type != ACPI_STATE_C3 && pr->flags.bm_check)
-                               acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0,
-                                                 ACPI_MTX_DO_NOT_LOCK);
+                               acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
                        break;
                }
        }
@@ -198,8 +197,7 @@ acpi_processor_power_activate(struct acpi_processor *pr,
        case ACPI_STATE_C3:
                /* Enable bus master reload */
                if (old->type != ACPI_STATE_C3 && pr->flags.bm_check)
-                       acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1,
-                                         ACPI_MTX_DO_NOT_LOCK);
+                       acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
                break;
        }
 
@@ -236,7 +234,7 @@ static void acpi_cstate_enter(struct acpi_processor_cx *cstate)
                /* Dummy wait op - must do something useless after P_LVL2 read
                   because chipsets cannot guarantee that STPCLK# signal
                   gets asserted in time to freeze execution properly. */
-               unused = inl(acpi_fadt.xpm_tmr_blk.address);
+               unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
        }
 }
 
@@ -291,12 +289,10 @@ static void acpi_processor_idle(void)
 
                pr->power.bm_activity <<= diff;
 
-               acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS,
-                                 &bm_status, ACPI_MTX_DO_NOT_LOCK);
+               acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
                if (bm_status) {
                        pr->power.bm_activity |= 0x1;
-                       acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS,
-                                         1, ACPI_MTX_DO_NOT_LOCK);
+                       acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
                }
                /*
                 * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
@@ -338,7 +334,7 @@ static void acpi_processor_idle(void)
         * detection phase, to work cleanly with logical CPU hotplug.
         */
        if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) && 
-           !pr->flags.has_cst && !acpi_fadt.plvl2_up)
+           !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
                cx = &pr->power.states[ACPI_STATE_C1];
 #endif
 
@@ -384,11 +380,11 @@ static void acpi_processor_idle(void)
 
        case ACPI_STATE_C2:
                /* Get start time (ticks) */
-               t1 = inl(acpi_fadt.xpm_tmr_blk.address);
+               t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
                /* Invoke C2 */
                acpi_cstate_enter(cx);
                /* Get end time (ticks) */
-               t2 = inl(acpi_fadt.xpm_tmr_blk.address);
+               t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
 
 #ifdef CONFIG_GENERIC_TIME
                /* TSC halts in C2, so notify users */
@@ -411,8 +407,7 @@ static void acpi_processor_idle(void)
                                 * All CPUs are trying to go to C3
                                 * Disable bus master arbitration
                                 */
-                               acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1,
-                                                 ACPI_MTX_DO_NOT_LOCK);
+                               acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
                        }
                } else {
                        /* SMP with no shared cache... Invalidate cache  */
@@ -420,16 +415,15 @@ static void acpi_processor_idle(void)
                }
 
                /* Get start time (ticks) */
-               t1 = inl(acpi_fadt.xpm_tmr_blk.address);
+               t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
                /* Invoke C3 */
                acpi_cstate_enter(cx);
                /* Get end time (ticks) */
-               t2 = inl(acpi_fadt.xpm_tmr_blk.address);
+               t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
                if (pr->flags.bm_check) {
                        /* Enable bus master arbitration */
                        atomic_dec(&c3_cpu_count);
-                       acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0,
-                                         ACPI_MTX_DO_NOT_LOCK);
+                       acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
                }
 
 #ifdef CONFIG_GENERIC_TIME
@@ -457,7 +451,7 @@ static void acpi_processor_idle(void)
 #ifdef CONFIG_HOTPLUG_CPU
        /* Don't do promotion/demotion */
        if ((cx->type == ACPI_STATE_C1) && (num_online_cpus() > 1) &&
-           !pr->flags.has_cst && !acpi_fadt.plvl2_up) {
+           !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) {
                next_state = cx;
                goto end;
        }
@@ -627,7 +621,8 @@ static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
         * Check for P_LVL2_UP flag before entering C2 and above on
         * an SMP system. 
         */
-       if ((num_online_cpus() > 1) && !acpi_fadt.plvl2_up)
+       if ((num_online_cpus() > 1) &&
+           !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
                return -ENODEV;
 #endif
 
@@ -636,8 +631,8 @@ static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
        pr->power.states[ACPI_STATE_C3].address = pr->pblk + 5;
 
        /* determine latencies from FADT */
-       pr->power.states[ACPI_STATE_C2].latency = acpi_fadt.plvl2_lat;
-       pr->power.states[ACPI_STATE_C3].latency = acpi_fadt.plvl3_lat;
+       pr->power.states[ACPI_STATE_C2].latency = acpi_gbl_FADT.C2latency;
+       pr->power.states[ACPI_STATE_C3].latency = acpi_gbl_FADT.C3latency;
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                          "lvl2[0x%08x] lvl3[0x%08x]\n",
@@ -883,14 +878,13 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
                 * WBINVD should be set in fadt, for C3 state to be
                 * supported on when bm_check is not required.
                 */
-               if (acpi_fadt.wb_invd != 1) {
+               if (!(acpi_gbl_FADT.flags & ACPI_FADT_WBINVD)) {
                        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                          "Cache invalidation should work properly"
                                          " for C3 to be enabled on SMP systems\n"));
                        return;
                }
-               acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD,
-                                 0, ACPI_MTX_DO_NOT_LOCK);
+               acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
        }
 
        /*
@@ -1096,7 +1090,7 @@ static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
                seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n",
                           pr->power.states[i].latency,
                           pr->power.states[i].usage,
-                          pr->power.states[i].time);
+                          (unsigned long long)pr->power.states[i].time);
        }
 
       end:
@@ -1164,9 +1158,9 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
        if (!pr)
                return -EINVAL;
 
-       if (acpi_fadt.cst_cnt && !nocst) {
+       if (acpi_gbl_FADT.cst_control && !nocst) {
                status =
-                   acpi_os_write_port(acpi_fadt.smi_cmd, acpi_fadt.cst_cnt, 8);
+                   acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8);
                if (ACPI_FAILURE(status)) {
                        ACPI_EXCEPTION((AE_INFO, status,
                                        "Notifying BIOS of _CST ability failed"));
index cbb6f0814ce2dc706cb6b85e7ab3ae96b5d23e2e..058f13cf3b796208da3a801c7e81d5c6edd82e14 100644 (file)
@@ -352,31 +352,24 @@ int acpi_processor_notify_smm(struct module *calling_module)
 
        is_done = -EIO;
 
-       /* Can't write pstate_cnt to smi_cmd if either value is zero */
-       if ((!acpi_fadt.smi_cmd) || (!acpi_fadt.pstate_cnt)) {
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_cnt\n"));
+       /* Can't write pstate_control to smi_command if either value is zero */
+       if ((!acpi_gbl_FADT.smi_command) || (!acpi_gbl_FADT.pstate_control)) {
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_control\n"));
                module_put(calling_module);
                return 0;
        }
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                         "Writing pstate_cnt [0x%x] to smi_cmd [0x%x]\n",
-                         acpi_fadt.pstate_cnt, acpi_fadt.smi_cmd));
+                         "Writing pstate_control [0x%x] to smi_command [0x%x]\n",
+                         acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command));
 
-       /* FADT v1 doesn't support pstate_cnt, many BIOS vendors use
-        * it anyway, so we need to support it... */
-       if (acpi_fadt_is_v1) {
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                 "Using v1.0 FADT reserved value for pstate_cnt\n"));
-       }
-
-       status = acpi_os_write_port(acpi_fadt.smi_cmd,
-                                   (u32) acpi_fadt.pstate_cnt, 8);
+       status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
+                                   (u32) acpi_gbl_FADT.pstate_control, 8);
        if (ACPI_FAILURE(status)) {
                ACPI_EXCEPTION((AE_INFO, status,
-                               "Failed to write pstate_cnt [0x%x] to "
-                               "smi_cmd [0x%x]", acpi_fadt.pstate_cnt,
-                               acpi_fadt.smi_cmd));
+                               "Failed to write pstate_control [0x%x] to "
+                               "smi_command [0x%x]", acpi_gbl_FADT.pstate_control,
+                               acpi_gbl_FADT.smi_command));
                module_put(calling_module);
                return status;
        }
index 0ec7dcde00632945668cbcc1d6383f8c979b6cf0..89dff3639abef84e8880590d4eb1c8e742bd71b2 100644 (file)
@@ -125,7 +125,7 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
                /* Used to clear all duty_value bits */
                duty_mask = pr->throttling.state_count - 1;
 
-               duty_mask <<= acpi_fadt.duty_offset;
+               duty_mask <<= acpi_gbl_FADT.duty_offset;
                duty_mask = ~duty_mask;
        }
 
@@ -208,7 +208,7 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
                return 0;
        }
 
-       pr->throttling.state_count = 1 << acpi_fadt.duty_width;
+       pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width;
 
        /*
         * Compute state values. Note that throttling displays a linear power/
index 8fa3213ce000709af7c33a74c44efb397bfdc5c8..271e61509eebcde1bee47e5b60c02b15f56b8d5d 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index cf87b0230026db03f58fc2c5885cb8ceaa3ce2fa..8c6d3fdec38a7d08358a4cd7e60410b26510b5a8 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 008058acdd39cb0143883d9be1e2454a4fb5b3da..1358c06a969c2b2d8d2a795556c4f6f3d169575f 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 9c99a723a860da348f507e162404eca9fe8ed693..de20a5d6decf52053f33c63909f0ebef7972a814 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 9e7ae2f8a1d3993a03ad9576e6126c3a171de63f..7e3c335ab320a8aab6e26554921961fa93679289 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index ea567167c4f23f03cf7037056c6bc9d15315b0a2..b297bc3e441942b4b993faca1e0133b846e85e83 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 1fa63bc2e36f54dac2a03766a0dfc33fef2e094d..5657f7b950399f619023edced4baec792876bc74 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 29423ce030caa66a89ab99668987abe223913ea3..a92755c8877d63fd57a12d6cb4f3747a14499f23 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index a5131936d6904187f9d6d480a795f6d7f5ae3fa8..521eab7dd8df531d8af5fa0d24fc0ba91f60d25d 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index faf6e106b78502bbd7a9c648cdbcabb0711bb95c..3b63b561b94e506291a7d91bb5a6468d867fa024 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index a9cbee8e8b44c3a12145c6be17ed36657e9ba1a5..2442a8f8df576e240fb40323da8689655d1732b3 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 1999e2ab7daad1971559302ae9e0e05b21c33e3e..991f8901498c1166817c3922f982469932e07f5a 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 283d87522c5ddc6c96b1569872eeb435e77b9ddc..64f26db10c8efd765fcde8e8d0eb821b3a06efc2 100644 (file)
@@ -21,101 +21,305 @@ extern struct acpi_device *acpi_root;
 #define ACPI_BUS_DEVICE_NAME           "System Bus"
 
 static LIST_HEAD(acpi_device_list);
+static LIST_HEAD(acpi_bus_id_list);
 DEFINE_SPINLOCK(acpi_device_lock);
 LIST_HEAD(acpi_wakeup_device_list);
 
+struct acpi_device_bus_id{
+       char bus_id[15];
+       unsigned int instance_no;
+       struct list_head node;
+};
+static int acpi_eject_operation(acpi_handle handle, int lockable)
+{
+       struct acpi_object_list arg_list;
+       union acpi_object arg;
+       acpi_status status = AE_OK;
+
+       /*
+        * TBD: evaluate _PS3?
+        */
+
+       if (lockable) {
+               arg_list.count = 1;
+               arg_list.pointer = &arg;
+               arg.type = ACPI_TYPE_INTEGER;
+               arg.integer.value = 0;
+               acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
+       }
 
-static void acpi_device_release(struct kobject *kobj)
+       arg_list.count = 1;
+       arg_list.pointer = &arg;
+       arg.type = ACPI_TYPE_INTEGER;
+       arg.integer.value = 1;
+
+       /*
+        * TBD: _EJD support.
+        */
+
+       status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
+       if (ACPI_FAILURE(status)) {
+               return (-ENODEV);
+       }
+
+       return (0);
+}
+
+static ssize_t
+acpi_eject_store(struct device *d, struct device_attribute *attr,
+               const char *buf, size_t count)
 {
-       struct acpi_device *dev = container_of(kobj, struct acpi_device, kobj);
-       kfree(dev->pnp.cid_list);
-       kfree(dev);
+       int result;
+       int ret = count;
+       int islockable;
+       acpi_status status;
+       acpi_handle handle;
+       acpi_object_type type = 0;
+       struct acpi_device *acpi_device = to_acpi_device(d);
+
+       if ((!count) || (buf[0] != '1')) {
+               return -EINVAL;
+       }
+#ifndef FORCE_EJECT
+       if (acpi_device->driver == NULL) {
+               ret = -ENODEV;
+               goto err;
+       }
+#endif
+       status = acpi_get_type(acpi_device->handle, &type);
+       if (ACPI_FAILURE(status) || (!acpi_device->flags.ejectable)) {
+               ret = -ENODEV;
+               goto err;
+       }
+
+       islockable = acpi_device->flags.lockable;
+       handle = acpi_device->handle;
+
+       result = acpi_bus_trim(acpi_device, 1);
+
+       if (!result)
+               result = acpi_eject_operation(handle, islockable);
+
+       if (result) {
+               ret = -EBUSY;
+       }
+      err:
+       return ret;
 }
 
-struct acpi_device_attribute {
-       struct attribute attr;
-        ssize_t(*show) (struct acpi_device *, char *);
-        ssize_t(*store) (struct acpi_device *, const char *, size_t);
-};
+static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
 
-typedef void acpi_device_sysfs_files(struct kobject *,
-                                    const struct attribute *);
+static ssize_t
+acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) {
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
 
-static void setup_sys_fs_device_files(struct acpi_device *dev,
-                                     acpi_device_sysfs_files * func);
+       return sprintf(buf, "%s\n", acpi_dev->pnp.hardware_id);
+}
+static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
 
-#define create_sysfs_device_files(dev) \
-       setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_create_file)
-#define remove_sysfs_device_files(dev) \
-       setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_remove_file)
+static ssize_t
+acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *buf) {
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
+       int result;
 
-#define to_acpi_device(n) container_of(n, struct acpi_device, kobj)
-#define to_handle_attr(n) container_of(n, struct acpi_device_attribute, attr);
+       result = acpi_get_name(acpi_dev->handle, ACPI_FULL_PATHNAME, &path);
+       if(result)
+               goto end;
 
-static ssize_t acpi_device_attr_show(struct kobject *kobj,
-                                    struct attribute *attr, char *buf)
+       result = sprintf(buf, "%s\n", (char*)path.pointer);
+       kfree(path.pointer);
+  end:
+       return result;
+}
+static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
+
+static int acpi_device_setup_files(struct acpi_device *dev)
+{
+       acpi_status status;
+       acpi_handle temp;
+       int result = 0;
+
+       /*
+        * Devices gotten from FADT don't have a "path" attribute
+        */
+       if(dev->handle) {
+               result = device_create_file(&dev->dev, &dev_attr_path);
+               if(result)
+                       goto end;
+       }
+
+       if(dev->flags.hardware_id) {
+               result = device_create_file(&dev->dev, &dev_attr_hid);
+               if(result)
+                       goto end;
+       }
+
+        /*
+         * If device has _EJ0, 'eject' file is created that is used to trigger
+         * hot-removal function from userland.
+         */
+       status = acpi_get_handle(dev->handle, "_EJ0", &temp);
+       if (ACPI_SUCCESS(status))
+               result = device_create_file(&dev->dev, &dev_attr_eject);
+  end:
+       return result;
+}
+
+static void acpi_device_remove_files(struct acpi_device *dev)
 {
-       struct acpi_device *device = to_acpi_device(kobj);
-       struct acpi_device_attribute *attribute = to_handle_attr(attr);
-       return attribute->show ? attribute->show(device, buf) : -EIO;
+       acpi_status status;
+       acpi_handle temp;
+
+       /*
+        * If device has _EJ0, 'eject' file is created that is used to trigger
+        * hot-removal function from userland.
+        */
+       status = acpi_get_handle(dev->handle, "_EJ0", &temp);
+       if (ACPI_SUCCESS(status))
+               device_remove_file(&dev->dev, &dev_attr_eject);
+
+       if(dev->flags.hardware_id)
+               device_remove_file(&dev->dev, &dev_attr_hid);
+       if(dev->handle)
+               device_remove_file(&dev->dev, &dev_attr_path);
 }
-static ssize_t acpi_device_attr_store(struct kobject *kobj,
-                                     struct attribute *attr, const char *buf,
-                                     size_t len)
+/* --------------------------------------------------------------------------
+                       ACPI Bus operations
+   -------------------------------------------------------------------------- */
+static void acpi_device_release(struct device *dev)
 {
-       struct acpi_device *device = to_acpi_device(kobj);
-       struct acpi_device_attribute *attribute = to_handle_attr(attr);
-       return attribute->store ? attribute->store(device, buf, len) : -EIO;
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+
+       kfree(acpi_dev->pnp.cid_list);
+       kfree(acpi_dev);
 }
 
-static struct sysfs_ops acpi_device_sysfs_ops = {
-       .show = acpi_device_attr_show,
-       .store = acpi_device_attr_store,
-};
+static int acpi_device_suspend(struct device *dev, pm_message_t state)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = acpi_dev->driver;
 
-static struct kobj_type ktype_acpi_ns = {
-       .sysfs_ops = &acpi_device_sysfs_ops,
-       .release = acpi_device_release,
-};
+       if (acpi_drv && acpi_drv->ops.suspend)
+               return acpi_drv->ops.suspend(acpi_dev, state);
+       return 0;
+}
 
-static int namespace_uevent(struct kset *kset, struct kobject *kobj,
-                            char **envp, int num_envp, char *buffer,
-                            int buffer_size)
+static int acpi_device_resume(struct device *dev)
 {
-       struct acpi_device *dev = to_acpi_device(kobj);
-       int i = 0;
-       int len = 0;
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = acpi_dev->driver;
 
-       if (!dev->driver)
-               return 0;
+       if (acpi_drv && acpi_drv->ops.resume)
+               return acpi_drv->ops.resume(acpi_dev);
+       return 0;
+}
 
-       if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
-                          "PHYSDEVDRIVER=%s", dev->driver->name))
+static int acpi_bus_match(struct device *dev, struct device_driver *drv)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = to_acpi_driver(drv);
+
+       return !acpi_match_ids(acpi_dev, acpi_drv->ids);
+}
+
+static int acpi_device_uevent(struct device *dev, char **envp, int num_envp,
+       char *buffer, int buffer_size)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       int i = 0, length = 0, ret = 0;
+
+       if (acpi_dev->flags.hardware_id)
+               ret = add_uevent_var(envp, num_envp, &i,
+                       buffer, buffer_size, &length,
+                       "HWID=%s", acpi_dev->pnp.hardware_id);
+       if (ret)
                return -ENOMEM;
+       if (acpi_dev->flags.compatible_ids) {
+               int j;
+               struct acpi_compatible_id_list *cid_list;
+
+               cid_list = acpi_dev->pnp.cid_list;
+
+               for (j = 0; j < cid_list->count; j++) {
+                       ret = add_uevent_var(envp, num_envp, &i, buffer,
+                               buffer_size, &length, "COMPTID=%s",
+                               cid_list->id[j].value);
+                       if (ret)
+                               return -ENOMEM;
+               }
+       }
 
        envp[i] = NULL;
+       return 0;
+}
+
+static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
+static int acpi_start_single_object(struct acpi_device *);
+static int acpi_device_probe(struct device * dev)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
+       int ret;
+
+       ret = acpi_bus_driver_init(acpi_dev, acpi_drv);
+       if (!ret) {
+               if (acpi_dev->bus_ops.acpi_op_start)
+                       acpi_start_single_object(acpi_dev);
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+                       "Found driver [%s] for device [%s]\n",
+                       acpi_drv->name, acpi_dev->pnp.bus_id));
+               get_device(dev);
+       }
+       return ret;
+}
 
+static int acpi_device_remove(struct device * dev)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = acpi_dev->driver;
+
+       if (acpi_drv) {
+               if (acpi_drv->ops.stop)
+                       acpi_drv->ops.stop(acpi_dev, acpi_dev->removal_type);
+               if (acpi_drv->ops.remove)
+                       acpi_drv->ops.remove(acpi_dev, acpi_dev->removal_type);
+       }
+       acpi_dev->driver = NULL;
+       acpi_driver_data(dev) = NULL;
+
+       put_device(dev);
        return 0;
 }
 
-static struct kset_uevent_ops namespace_uevent_ops = {
-       .uevent = &namespace_uevent,
-};
+static void acpi_device_shutdown(struct device *dev)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = acpi_dev->driver;
 
-static struct kset acpi_namespace_kset = {
-       .kobj = {
-                .name = "namespace",
-                },
-       .subsys = &acpi_subsys,
-       .ktype = &ktype_acpi_ns,
-       .uevent_ops = &namespace_uevent_ops,
+       if (acpi_drv && acpi_drv->ops.shutdown)
+               acpi_drv->ops.shutdown(acpi_dev);
+
+       return ;
+}
+
+static struct bus_type acpi_bus_type = {
+       .name           = "acpi",
+       .suspend        = acpi_device_suspend,
+       .resume         = acpi_device_resume,
+       .shutdown       = acpi_device_shutdown,
+       .match          = acpi_bus_match,
+       .probe          = acpi_device_probe,
+       .remove         = acpi_device_remove,
+       .uevent         = acpi_device_uevent,
 };
 
-static void acpi_device_register(struct acpi_device *device,
+static int acpi_device_register(struct acpi_device *device,
                                 struct acpi_device *parent)
 {
-       int err;
-
+       int result;
+       struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
+       int found = 0;
        /*
         * Linkage
         * -------
@@ -126,7 +330,33 @@ static void acpi_device_register(struct acpi_device *device,
        INIT_LIST_HEAD(&device->g_list);
        INIT_LIST_HEAD(&device->wakeup_list);
 
+       new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
+       if (!new_bus_id) {
+               printk(KERN_ERR PREFIX "Memory allocation error\n");
+               return -ENOMEM;
+       }
+
        spin_lock(&acpi_device_lock);
+       /*
+        * Find suitable bus_id and instance number in acpi_bus_id_list
+        * If failed, create one and link it into acpi_bus_id_list
+        */
+       list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
+               if(!strcmp(acpi_device_bus_id->bus_id, device->flags.hardware_id? device->pnp.hardware_id : "device")) {
+                       acpi_device_bus_id->instance_no ++;
+                       found = 1;
+                       kfree(new_bus_id);
+                       break;
+               }
+       }
+       if(!found) {
+               acpi_device_bus_id = new_bus_id;
+               strcpy(acpi_device_bus_id->bus_id, device->flags.hardware_id ? device->pnp.hardware_id : "device");
+               acpi_device_bus_id->instance_no = 0;
+               list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
+       }
+       sprintf(device->dev.bus_id, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
+
        if (device->parent) {
                list_add_tail(&device->node, &device->parent->children);
                list_add_tail(&device->g_list, &device->parent->g_list);
@@ -136,16 +366,33 @@ static void acpi_device_register(struct acpi_device *device,
                list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
        spin_unlock(&acpi_device_lock);
 
-       strlcpy(device->kobj.name, device->pnp.bus_id, KOBJ_NAME_LEN);
-       if (parent)
-               device->kobj.parent = &parent->kobj;
-       device->kobj.ktype = &ktype_acpi_ns;
-       device->kobj.kset = &acpi_namespace_kset;
-       err = kobject_register(&device->kobj);
-       if (err < 0)
-               printk(KERN_WARNING "%s: kobject_register error: %d\n",
-                       __FUNCTION__, err);
-       create_sysfs_device_files(device);
+       if (device->parent)
+               device->dev.parent = &parent->dev;
+       device->dev.bus = &acpi_bus_type;
+       device_initialize(&device->dev);
+       device->dev.release = &acpi_device_release;
+       result = device_add(&device->dev);
+       if(result) {
+               printk("Error adding device %s", device->dev.bus_id);
+               goto end;
+       }
+
+       result = acpi_device_setup_files(device);
+       if(result)
+               ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error creating sysfs interface for device %s\n", device->dev.bus_id));
+
+       device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
+       return 0;
+  end:
+       spin_lock(&acpi_device_lock);
+       if (device->parent) {
+               list_del(&device->node);
+               list_del(&device->g_list);
+       } else
+               list_del(&device->g_list);
+       list_del(&device->wakeup_list);
+       spin_unlock(&acpi_device_lock);
+       return result;
 }
 
 static void acpi_device_unregister(struct acpi_device *device, int type)
@@ -158,81 +405,143 @@ static void acpi_device_unregister(struct acpi_device *device, int type)
                list_del(&device->g_list);
 
        list_del(&device->wakeup_list);
-
        spin_unlock(&acpi_device_lock);
 
        acpi_detach_data(device->handle, acpi_bus_data_handler);
-       remove_sysfs_device_files(device);
-       kobject_unregister(&device->kobj);
+
+       acpi_device_remove_files(device);
+       device_unregister(&device->dev);
 }
 
-void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
+/* --------------------------------------------------------------------------
+                                 Driver Management
+   -------------------------------------------------------------------------- */
+/**
+ * acpi_bus_driver_init - add a device to a driver
+ * @device: the device to add and initialize
+ * @driver: driver for the device
+ *
+ * Used to initialize a device via its device driver.  Called whenever a 
+ * driver is bound to a device.  Invokes the driver's add() ops.
+ */
+static int
+acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
 {
+       int result = 0;
 
-       /* TBD */
 
-       return;
-}
+       if (!device || !driver)
+               return -EINVAL;
 
-static int acpi_bus_get_power_flags(struct acpi_device *device)
-{
-       acpi_status status = 0;
-       acpi_handle handle = NULL;
-       u32 i = 0;
+       if (!driver->ops.add)
+               return -ENOSYS;
 
+       result = driver->ops.add(device);
+       if (result) {
+               device->driver = NULL;
+               acpi_driver_data(device) = NULL;
+               return result;
+       }
 
-       /*
-        * Power Management Flags
-        */
-       status = acpi_get_handle(device->handle, "_PSC", &handle);
-       if (ACPI_SUCCESS(status))
-               device->power.flags.explicit_get = 1;
-       status = acpi_get_handle(device->handle, "_IRC", &handle);
-       if (ACPI_SUCCESS(status))
-               device->power.flags.inrush_current = 1;
+       device->driver = driver;
 
        /*
-        * Enumerate supported power management states
+        * TBD - Configuration Management: Assign resources to device based
+        * upon possible configuration and currently allocated resources.
         */
-       for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
-               struct acpi_device_power_state *ps = &device->power.states[i];
-               char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
 
-               /* Evaluate "_PRx" to se if power resources are referenced */
-               acpi_evaluate_reference(device->handle, object_name, NULL,
-                                       &ps->resources);
-               if (ps->resources.count) {
-                       device->power.flags.power_resources = 1;
-                       ps->flags.valid = 1;
-               }
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+                         "Driver successfully bound to device\n"));
+       return 0;
+}
 
-               /* Evaluate "_PSx" to see if we can do explicit sets */
-               object_name[2] = 'S';
-               status = acpi_get_handle(device->handle, object_name, &handle);
-               if (ACPI_SUCCESS(status)) {
-                       ps->flags.explicit_set = 1;
-                       ps->flags.valid = 1;
-               }
+static int acpi_start_single_object(struct acpi_device *device)
+{
+       int result = 0;
+       struct acpi_driver *driver;
+
+
+       if (!(driver = device->driver))
+               return 0;
+
+       if (driver->ops.start) {
+               result = driver->ops.start(device);
+               if (result && driver->ops.remove)
+                       driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
+       }
+
+       return result;
+}
+
+/**
+ * acpi_bus_register_driver - register a driver with the ACPI bus
+ * @driver: driver being registered
+ *
+ * Registers a driver with the ACPI bus.  Searches the namespace for all
+ * devices that match the driver's criteria and binds.  Returns zero for
+ * success or a negative error status for failure.
+ */
+int acpi_bus_register_driver(struct acpi_driver *driver)
+{
+       int ret;
+
+       if (acpi_disabled)
+               return -ENODEV;
+       driver->drv.name = driver->name;
+       driver->drv.bus = &acpi_bus_type;
+       driver->drv.owner = driver->owner;
+
+       ret = driver_register(&driver->drv);
+       return ret;
+}
+
+EXPORT_SYMBOL(acpi_bus_register_driver);
+
+/**
+ * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
+ * @driver: driver to unregister
+ *
+ * Unregisters a driver with the ACPI bus.  Searches the namespace for all
+ * devices that match the driver's criteria and unbinds.
+ */
+void acpi_bus_unregister_driver(struct acpi_driver *driver)
+{
+       driver_unregister(&driver->drv);
+}
+
+EXPORT_SYMBOL(acpi_bus_unregister_driver);
+
+/* --------------------------------------------------------------------------
+                                 Device Enumeration
+   -------------------------------------------------------------------------- */
+acpi_status
+acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
+{
+       acpi_status status;
+       acpi_handle tmp;
+       struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+       union acpi_object *obj;
 
-               /* State is valid if we have some power control */
-               if (ps->resources.count || ps->flags.explicit_set)
-                       ps->flags.valid = 1;
+       status = acpi_get_handle(handle, "_EJD", &tmp);
+       if (ACPI_FAILURE(status))
+               return status;
 
-               ps->power = -1; /* Unknown - driver assigned */
-               ps->latency = -1;       /* Unknown - driver assigned */
+       status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
+       if (ACPI_SUCCESS(status)) {
+               obj = buffer.pointer;
+               status = acpi_get_handle(NULL, obj->string.pointer, ejd);
+               kfree(buffer.pointer);
        }
+       return status;
+}
+EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
 
-       /* Set defaults for D0 and D3 states (always valid) */
-       device->power.states[ACPI_STATE_D0].flags.valid = 1;
-       device->power.states[ACPI_STATE_D0].power = 100;
-       device->power.states[ACPI_STATE_D3].flags.valid = 1;
-       device->power.states[ACPI_STATE_D3].power = 0;
-
-       /* TBD: System wake support and resource requirements. */
+void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
+{
 
-       device->power.state = ACPI_STATE_UNKNOWN;
+       /* TBD */
 
-       return 0;
+       return;
 }
 
 int acpi_match_ids(struct acpi_device *device, char *ids)
@@ -254,6 +563,12 @@ int acpi_match_ids(struct acpi_device *device, char *ids)
        return -ENOENT;
 }
 
+static int acpi_bus_get_perf_flags(struct acpi_device *device)
+{
+       device->performance.state = ACPI_STATE_UNKNOWN;
+       return 0;
+}
+
 static acpi_status
 acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
                                             union acpi_object *package)
@@ -327,370 +642,77 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
 
        kfree(buffer.pointer);
 
-       device->wakeup.flags.valid = 1;
-       /* Power button, Lid switch always enable wakeup */
-       if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E"))
-               device->wakeup.flags.run_wake = 1;
-
-      end:
-       if (ACPI_FAILURE(status))
-               device->flags.wake_capable = 0;
-       return 0;
-}
-
-/* --------------------------------------------------------------------------
-               ACPI sysfs device file support
-   -------------------------------------------------------------------------- */
-static ssize_t acpi_eject_store(struct acpi_device *device,
-                               const char *buf, size_t count);
-
-#define ACPI_DEVICE_ATTR(_name,_mode,_show,_store) \
-static struct acpi_device_attribute acpi_device_attr_##_name = \
-               __ATTR(_name, _mode, _show, _store)
-
-ACPI_DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
-
-/**
- * setup_sys_fs_device_files - sets up the device files under device namespace
- * @dev:       acpi_device object
- * @func:      function pointer to create or destroy the device file
- */
-static void
-setup_sys_fs_device_files(struct acpi_device *dev,
-                         acpi_device_sysfs_files * func)
-{
-       acpi_status status;
-       acpi_handle temp = NULL;
-
-       /*
-        * If device has _EJ0, 'eject' file is created that is used to trigger
-        * hot-removal function from userland.
-        */
-       status = acpi_get_handle(dev->handle, "_EJ0", &temp);
-       if (ACPI_SUCCESS(status))
-               (*(func)) (&dev->kobj, &acpi_device_attr_eject.attr);
-}
-
-static int acpi_eject_operation(acpi_handle handle, int lockable)
-{
-       struct acpi_object_list arg_list;
-       union acpi_object arg;
-       acpi_status status = AE_OK;
-
-       /*
-        * TBD: evaluate _PS3?
-        */
-
-       if (lockable) {
-               arg_list.count = 1;
-               arg_list.pointer = &arg;
-               arg.type = ACPI_TYPE_INTEGER;
-               arg.integer.value = 0;
-               acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
-       }
-
-       arg_list.count = 1;
-       arg_list.pointer = &arg;
-       arg.type = ACPI_TYPE_INTEGER;
-       arg.integer.value = 1;
-
-       /*
-        * TBD: _EJD support.
-        */
-
-       status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
-       if (ACPI_FAILURE(status)) {
-               return (-ENODEV);
-       }
-
-       return (0);
-}
-
-static ssize_t
-acpi_eject_store(struct acpi_device *device, const char *buf, size_t count)
-{
-       int result;
-       int ret = count;
-       int islockable;
-       acpi_status status;
-       acpi_handle handle;
-       acpi_object_type type = 0;
-
-       if ((!count) || (buf[0] != '1')) {
-               return -EINVAL;
-       }
-#ifndef FORCE_EJECT
-       if (device->driver == NULL) {
-               ret = -ENODEV;
-               goto err;
-       }
-#endif
-       status = acpi_get_type(device->handle, &type);
-       if (ACPI_FAILURE(status) || (!device->flags.ejectable)) {
-               ret = -ENODEV;
-               goto err;
-       }
-
-       islockable = device->flags.lockable;
-       handle = device->handle;
-
-       result = acpi_bus_trim(device, 1);
-
-       if (!result)
-               result = acpi_eject_operation(handle, islockable);
-
-       if (result) {
-               ret = -EBUSY;
-       }
-      err:
-       return ret;
-}
-
-/* --------------------------------------------------------------------------
-                              Performance Management
-   -------------------------------------------------------------------------- */
-
-static int acpi_bus_get_perf_flags(struct acpi_device *device)
-{
-       device->performance.state = ACPI_STATE_UNKNOWN;
-       return 0;
-}
-
-/* --------------------------------------------------------------------------
-                                 Driver Management
-   -------------------------------------------------------------------------- */
-
-static LIST_HEAD(acpi_bus_drivers);
-
-/**
- * acpi_bus_match - match device IDs to driver's supported IDs
- * @device: the device that we are trying to match to a driver
- * @driver: driver whose device id table is being checked
- *
- * Checks the device's hardware (_HID) or compatible (_CID) ids to see if it
- * matches the specified driver's criteria.
- */
-static int
-acpi_bus_match(struct acpi_device *device, struct acpi_driver *driver)
-{
-       if (driver && driver->ops.match)
-               return driver->ops.match(device, driver);
-       return acpi_match_ids(device, driver->ids);
-}
-
-/**
- * acpi_bus_driver_init - add a device to a driver
- * @device: the device to add and initialize
- * @driver: driver for the device
- *
- * Used to initialize a device via its device driver.  Called whenever a 
- * driver is bound to a device.  Invokes the driver's add() and start() ops.
- */
-static int
-acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
-{
-       int result = 0;
-
-
-       if (!device || !driver)
-               return -EINVAL;
-
-       if (!driver->ops.add)
-               return -ENOSYS;
-
-       result = driver->ops.add(device);
-       if (result) {
-               device->driver = NULL;
-               acpi_driver_data(device) = NULL;
-               return result;
-       }
-
-       device->driver = driver;
-
-       /*
-        * TBD - Configuration Management: Assign resources to device based
-        * upon possible configuration and currently allocated resources.
-        */
-
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                         "Driver successfully bound to device\n"));
-       return 0;
-}
-
-static int acpi_start_single_object(struct acpi_device *device)
-{
-       int result = 0;
-       struct acpi_driver *driver;
-
-
-       if (!(driver = device->driver))
-               return 0;
-
-       if (driver->ops.start) {
-               result = driver->ops.start(device);
-               if (result && driver->ops.remove)
-                       driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
-       }
-
-       return result;
-}
-
-static void acpi_driver_attach(struct acpi_driver *drv)
-{
-       struct list_head *node, *next;
-
-
-       spin_lock(&acpi_device_lock);
-       list_for_each_safe(node, next, &acpi_device_list) {
-               struct acpi_device *dev =
-                   container_of(node, struct acpi_device, g_list);
-
-               if (dev->driver || !dev->status.present)
-                       continue;
-               spin_unlock(&acpi_device_lock);
-
-               if (!acpi_bus_match(dev, drv)) {
-                       if (!acpi_bus_driver_init(dev, drv)) {
-                               acpi_start_single_object(dev);
-                               atomic_inc(&drv->references);
-                               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                                 "Found driver [%s] for device [%s]\n",
-                                                 drv->name, dev->pnp.bus_id));
-                       }
-               }
-               spin_lock(&acpi_device_lock);
-       }
-       spin_unlock(&acpi_device_lock);
-}
-
-static void acpi_driver_detach(struct acpi_driver *drv)
-{
-       struct list_head *node, *next;
-
-
-       spin_lock(&acpi_device_lock);
-       list_for_each_safe(node, next, &acpi_device_list) {
-               struct acpi_device *dev =
-                   container_of(node, struct acpi_device, g_list);
-
-               if (dev->driver == drv) {
-                       spin_unlock(&acpi_device_lock);
-                       if (drv->ops.remove)
-                               drv->ops.remove(dev, ACPI_BUS_REMOVAL_NORMAL);
-                       spin_lock(&acpi_device_lock);
-                       dev->driver = NULL;
-                       dev->driver_data = NULL;
-                       atomic_dec(&drv->references);
-               }
-       }
-       spin_unlock(&acpi_device_lock);
-}
-
-/**
- * acpi_bus_register_driver - register a driver with the ACPI bus
- * @driver: driver being registered
- *
- * Registers a driver with the ACPI bus.  Searches the namespace for all
- * devices that match the driver's criteria and binds.  Returns zero for
- * success or a negative error status for failure.
- */
-int acpi_bus_register_driver(struct acpi_driver *driver)
-{
-
-       if (acpi_disabled)
-               return -ENODEV;
-
-       spin_lock(&acpi_device_lock);
-       list_add_tail(&driver->node, &acpi_bus_drivers);
-       spin_unlock(&acpi_device_lock);
-       acpi_driver_attach(driver);
-
+       device->wakeup.flags.valid = 1;
+       /* Power button, Lid switch always enable wakeup */
+       if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E"))
+               device->wakeup.flags.run_wake = 1;
+
+      end:
+       if (ACPI_FAILURE(status))
+               device->flags.wake_capable = 0;
        return 0;
 }
 
-EXPORT_SYMBOL(acpi_bus_register_driver);
-
-/**
- * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
- * @driver: driver to unregister
- *
- * Unregisters a driver with the ACPI bus.  Searches the namespace for all
- * devices that match the driver's criteria and unbinds.
- */
-void acpi_bus_unregister_driver(struct acpi_driver *driver)
+static int acpi_bus_get_power_flags(struct acpi_device *device)
 {
-       acpi_driver_detach(driver);
+       acpi_status status = 0;
+       acpi_handle handle = NULL;
+       u32 i = 0;
 
-       if (!atomic_read(&driver->references)) {
-               spin_lock(&acpi_device_lock);
-               list_del_init(&driver->node);
-               spin_unlock(&acpi_device_lock);
-       }
-       return;
-}
 
-EXPORT_SYMBOL(acpi_bus_unregister_driver);
+       /*
+        * Power Management Flags
+        */
+       status = acpi_get_handle(device->handle, "_PSC", &handle);
+       if (ACPI_SUCCESS(status))
+               device->power.flags.explicit_get = 1;
+       status = acpi_get_handle(device->handle, "_IRC", &handle);
+       if (ACPI_SUCCESS(status))
+               device->power.flags.inrush_current = 1;
 
-/**
- * acpi_bus_find_driver - check if there is a driver installed for the device
- * @device: device that we are trying to find a supporting driver for
- *
- * Parses the list of registered drivers looking for a driver applicable for
- * the specified device.
- */
-static int acpi_bus_find_driver(struct acpi_device *device)
-{
-       int result = 0;
-       struct list_head *node, *next;
+       /*
+        * Enumerate supported power management states
+        */
+       for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
+               struct acpi_device_power_state *ps = &device->power.states[i];
+               char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
 
+               /* Evaluate "_PRx" to se if power resources are referenced */
+               acpi_evaluate_reference(device->handle, object_name, NULL,
+                                       &ps->resources);
+               if (ps->resources.count) {
+                       device->power.flags.power_resources = 1;
+                       ps->flags.valid = 1;
+               }
 
-       spin_lock(&acpi_device_lock);
-       list_for_each_safe(node, next, &acpi_bus_drivers) {
-               struct acpi_driver *driver =
-                   container_of(node, struct acpi_driver, node);
-
-               atomic_inc(&driver->references);
-               spin_unlock(&acpi_device_lock);
-               if (!acpi_bus_match(device, driver)) {
-                       result = acpi_bus_driver_init(device, driver);
-                       if (!result)
-                               goto Done;
+               /* Evaluate "_PSx" to see if we can do explicit sets */
+               object_name[2] = 'S';
+               status = acpi_get_handle(device->handle, object_name, &handle);
+               if (ACPI_SUCCESS(status)) {
+                       ps->flags.explicit_set = 1;
+                       ps->flags.valid = 1;
                }
-               atomic_dec(&driver->references);
-               spin_lock(&acpi_device_lock);
-       }
-       spin_unlock(&acpi_device_lock);
 
-      Done:
-       return result;
-}
+               /* State is valid if we have some power control */
+               if (ps->resources.count || ps->flags.explicit_set)
+                       ps->flags.valid = 1;
 
-/* --------------------------------------------------------------------------
-                                 Device Enumeration
-   -------------------------------------------------------------------------- */
+               ps->power = -1; /* Unknown - driver assigned */
+               ps->latency = -1;       /* Unknown - driver assigned */
+       }
 
-acpi_status
-acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
-{
-       acpi_status status;
-       acpi_handle tmp;
-       struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
-       union acpi_object *obj;
+       /* Set defaults for D0 and D3 states (always valid) */
+       device->power.states[ACPI_STATE_D0].flags.valid = 1;
+       device->power.states[ACPI_STATE_D0].power = 100;
+       device->power.states[ACPI_STATE_D3].flags.valid = 1;
+       device->power.states[ACPI_STATE_D3].power = 0;
 
-       status = acpi_get_handle(handle, "_EJD", &tmp);
-       if (ACPI_FAILURE(status))
-               return status;
+       /* TBD: System wake support and resource requirements. */
 
-       status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
-       if (ACPI_SUCCESS(status)) {
-               obj = buffer.pointer;
-               status = acpi_get_handle(NULL, obj->string.pointer, ejd);
-               kfree(buffer.pointer);
-       }
-       return status;
-}
-EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
+       device->power.state = ACPI_STATE_UNKNOWN;
 
+       return 0;
+}
 
 static int acpi_bus_get_flags(struct acpi_device *device)
 {
@@ -782,6 +804,75 @@ static void acpi_device_get_busid(struct acpi_device *device,
        }
 }
 
+static int
+acpi_video_bus_match(struct acpi_device *device)
+{
+       acpi_handle h_dummy1;
+       acpi_handle h_dummy2;
+       acpi_handle h_dummy3;
+
+
+       if (!device)
+               return -EINVAL;
+
+       /* Since there is no HID, CID for ACPI Video drivers, we have
+        * to check well known required nodes for each feature we support.
+        */
+
+       /* Does this device able to support video switching ? */
+       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
+           ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
+               return 0;
+
+       /* Does this device able to retrieve a video ROM ? */
+       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
+               return 0;
+
+       /* Does this device able to configure which video head to be POSTed ? */
+       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
+           ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
+           ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
+               return 0;
+
+       return -ENODEV;
+}
+
+/*
+ * acpi_bay_match - see if a device is an ejectable driver bay
+ *
+ * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
+ * then we can safely call it an ejectable drive bay
+ */
+static int acpi_bay_match(struct acpi_device *device){
+       acpi_status status;
+       acpi_handle handle;
+       acpi_handle tmp;
+       acpi_handle phandle;
+
+       handle = device->handle;
+
+       status = acpi_get_handle(handle, "_EJ0", &tmp);
+       if (ACPI_FAILURE(status))
+               return -ENODEV;
+
+       if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
+               (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
+               (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
+               (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
+               return 0;
+
+       if (acpi_get_parent(handle, &phandle))
+               return -ENODEV;
+
+        if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) ||
+                (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) ||
+                (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) ||
+                (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp))))
+                return 0;
+
+       return -ENODEV;
+}
+
 static void acpi_device_set_id(struct acpi_device *device,
                               struct acpi_device *parent, acpi_handle handle,
                               int type)
@@ -812,6 +903,16 @@ static void acpi_device_set_id(struct acpi_device *device,
                        device->pnp.bus_address = info->address;
                        device->flags.bus_address = 1;
                }
+
+               if(!(info->valid & (ACPI_VALID_HID | ACPI_VALID_CID))){
+                       status = acpi_video_bus_match(device);
+                       if(ACPI_SUCCESS(status))
+                               hid = ACPI_VIDEO_HID;
+
+                       status = acpi_bay_match(device);
+                       if (ACPI_SUCCESS(status))
+                               hid = ACPI_BAY_HID;
+               }
                break;
        case ACPI_BUS_TYPE_POWER:
                hid = ACPI_POWER_HID;
@@ -888,86 +989,24 @@ static int acpi_device_set_context(struct acpi_device *device, int type)
        return result;
 }
 
-static void acpi_device_get_debug_info(struct acpi_device *device,
-                                      acpi_handle handle, int type)
-{
-#ifdef CONFIG_ACPI_DEBUG_OUTPUT
-       char *type_string = NULL;
-       char name[80] = { '?', '\0' };
-       struct acpi_buffer buffer = { sizeof(name), name };
-
-       switch (type) {
-       case ACPI_BUS_TYPE_DEVICE:
-               type_string = "Device";
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-               break;
-       case ACPI_BUS_TYPE_POWER:
-               type_string = "Power Resource";
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-               break;
-       case ACPI_BUS_TYPE_PROCESSOR:
-               type_string = "Processor";
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-               break;
-       case ACPI_BUS_TYPE_SYSTEM:
-               type_string = "System";
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-               break;
-       case ACPI_BUS_TYPE_THERMAL:
-               type_string = "Thermal Zone";
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-               break;
-       case ACPI_BUS_TYPE_POWER_BUTTON:
-               type_string = "Power Button";
-               sprintf(name, "PWRB");
-               break;
-       case ACPI_BUS_TYPE_SLEEP_BUTTON:
-               type_string = "Sleep Button";
-               sprintf(name, "SLPB");
-               break;
-       }
-
-       printk(KERN_DEBUG "Found %s %s [%p]\n", type_string, name, handle);
-#endif                         /*CONFIG_ACPI_DEBUG_OUTPUT */
-}
-
 static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
 {
-       int result = 0;
-       struct acpi_driver *driver;
-
-
        if (!dev)
                return -EINVAL;
 
-       driver = dev->driver;
-
-       if ((driver) && (driver->ops.remove)) {
-
-               if (driver->ops.stop) {
-                       result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT);
-                       if (result)
-                               return result;
-               }
-
-               result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT);
-               if (result) {
-                       return result;
-               }
-
-               atomic_dec(&dev->driver->references);
-               dev->driver = NULL;
-               acpi_driver_data(dev) = NULL;
-       }
+       dev->removal_type = ACPI_BUS_REMOVAL_EJECT;
+       device_release_driver(&dev->dev);
 
        if (!rmdevice)
                return 0;
 
+       /*
+        * unbind _ADR-Based Devices when hot removal
+        */
        if (dev->flags.bus_address) {
                if ((dev->parent) && (dev->parent->ops.unbind))
                        dev->parent->ops.unbind(dev);
        }
-
        acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);
 
        return 0;
@@ -975,7 +1014,8 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
 
 static int
 acpi_add_single_object(struct acpi_device **child,
-                      struct acpi_device *parent, acpi_handle handle, int type)
+                      struct acpi_device *parent, acpi_handle handle, int type,
+                       struct acpi_bus_ops *ops)
 {
        int result = 0;
        struct acpi_device *device = NULL;
@@ -992,6 +1032,8 @@ acpi_add_single_object(struct acpi_device **child,
 
        device->handle = handle;
        device->parent = parent;
+       device->bus_ops = *ops; /* workround for not call .start */
+
 
        acpi_device_get_busid(device, handle, type);
 
@@ -1076,33 +1118,16 @@ acpi_add_single_object(struct acpi_device **child,
        if ((result = acpi_device_set_context(device, type)))
                goto end;
 
-       acpi_device_get_debug_info(device, handle, type);
-
-       acpi_device_register(device, parent);
+       result = acpi_device_register(device, parent);
 
        /*
-        * Bind _ADR-Based Devices
-        * -----------------------
-        * If there's a a bus address (_ADR) then we utilize the parent's 
-        * 'bind' function (if exists) to bind the ACPI- and natively-
-        * enumerated device representations.
+        * Bind _ADR-Based Devices when hot add
         */
        if (device->flags.bus_address) {
                if (device->parent && device->parent->ops.bind)
                        device->parent->ops.bind(device);
        }
 
-       /*
-        * Locate & Attach Driver
-        * ----------------------
-        * If there's a hardware id (_HID) or compatible ids (_CID) we check
-        * to see if there's a driver installed for this kind of device.  Note
-        * that drivers can install before or after a device is enumerated.
-        *
-        * TBD: Assumes LDM provides driver hot-plug capability.
-        */
-       acpi_bus_find_driver(device);
-
       end:
        if (!result)
                *child = device;
@@ -1188,14 +1213,14 @@ static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
 
                if (ops->acpi_op_add)
                        status = acpi_add_single_object(&child, parent,
-                                                       chandle, type);
+                               chandle, type, ops);
                else
                        status = acpi_bus_get_device(chandle, &child);
 
                if (ACPI_FAILURE(status))
                        continue;
 
-               if (ops->acpi_op_start) {
+               if (ops->acpi_op_start && !(ops->acpi_op_add)) {
                        status = acpi_start_single_object(child);
                        if (ACPI_FAILURE(status))
                                continue;
@@ -1233,13 +1258,13 @@ acpi_bus_add(struct acpi_device **child,
        int result;
        struct acpi_bus_ops ops;
 
+       memset(&ops, 0, sizeof(ops));
+       ops.acpi_op_add = 1;
 
-       result = acpi_add_single_object(child, parent, handle, type);
-       if (!result) {
-               memset(&ops, 0, sizeof(ops));
-               ops.acpi_op_add = 1;
+       result = acpi_add_single_object(child, parent, handle, type, &ops);
+       if (!result)
                result = acpi_bus_scan(*child, &ops);
-       }
+
        return result;
 }
 
@@ -1325,127 +1350,35 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
 {
        int result = 0;
        struct acpi_device *device = NULL;
-
+       struct acpi_bus_ops ops;
 
        if (!root)
                return -ENODEV;
 
+       memset(&ops, 0, sizeof(ops));
+       ops.acpi_op_add = 1;
+       ops.acpi_op_start = 1;
+
        /*
         * Enumerate all fixed-feature devices.
         */
-       if (acpi_fadt.pwr_button == 0) {
+       if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) {
                result = acpi_add_single_object(&device, acpi_root,
                                                NULL,
-                                               ACPI_BUS_TYPE_POWER_BUTTON);
-               if (!result)
-                       result = acpi_start_single_object(device);
+                                               ACPI_BUS_TYPE_POWER_BUTTON,
+                                               &ops);
        }
 
-       if (acpi_fadt.sleep_button == 0) {
+       if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
                result = acpi_add_single_object(&device, acpi_root,
                                                NULL,
-                                               ACPI_BUS_TYPE_SLEEP_BUTTON);
-               if (!result)
-                       result = acpi_start_single_object(device);
+                                               ACPI_BUS_TYPE_SLEEP_BUTTON,
+                                               &ops);
        }
 
        return result;
 }
 
-
-static inline struct acpi_device * to_acpi_dev(struct device * dev)
-{
-       return container_of(dev, struct acpi_device, dev);
-}
-
-
-static int root_suspend(struct acpi_device * acpi_dev, pm_message_t state)
-{
-       struct acpi_device * dev, * next;
-       int result;
-
-       spin_lock(&acpi_device_lock);
-       list_for_each_entry_safe_reverse(dev, next, &acpi_device_list, g_list) {
-               if (dev->driver && dev->driver->ops.suspend) {
-                       spin_unlock(&acpi_device_lock);
-                       result = dev->driver->ops.suspend(dev, 0);
-                       if (result) {
-                               printk(KERN_ERR PREFIX "[%s - %s] Suspend failed: %d\n",
-                                      acpi_device_name(dev),
-                                      acpi_device_bid(dev), result);
-                       }
-                       spin_lock(&acpi_device_lock);
-               }
-       }
-       spin_unlock(&acpi_device_lock);
-       return 0;
-}
-
-
-static int acpi_device_suspend(struct device * dev, pm_message_t state)
-{
-       struct acpi_device * acpi_dev = to_acpi_dev(dev);
-
-       /*
-        * For now, we should only register 1 generic device -
-        * the ACPI root device - and from there, we walk the
-        * tree of ACPI devices to suspend each one using the
-        * ACPI driver methods.
-        */
-       if (acpi_dev->handle == ACPI_ROOT_OBJECT)
-               root_suspend(acpi_dev, state);
-       return 0;
-}
-
-
-
-static int root_resume(struct acpi_device * acpi_dev)
-{
-       struct acpi_device * dev, * next;
-       int result;
-
-       spin_lock(&acpi_device_lock);
-       list_for_each_entry_safe(dev, next, &acpi_device_list, g_list) {
-               if (dev->driver && dev->driver->ops.resume) {
-                       spin_unlock(&acpi_device_lock);
-                       result = dev->driver->ops.resume(dev, 0);
-                       if (result) {
-                               printk(KERN_ERR PREFIX "[%s - %s] resume failed: %d\n",
-                                      acpi_device_name(dev),
-                                      acpi_device_bid(dev), result);
-                       }
-                       spin_lock(&acpi_device_lock);
-               }
-       }
-       spin_unlock(&acpi_device_lock);
-       return 0;
-}
-
-
-static int acpi_device_resume(struct device * dev)
-{
-       struct acpi_device * acpi_dev = to_acpi_dev(dev);
-
-       /*
-        * For now, we should only register 1 generic device -
-        * the ACPI root device - and from there, we walk the
-        * tree of ACPI devices to resume each one using the
-        * ACPI driver methods.
-        */
-       if (acpi_dev->handle == ACPI_ROOT_OBJECT)
-               root_resume(acpi_dev);
-       return 0;
-}
-
-
-static struct bus_type acpi_bus_type = {
-       .name           = "acpi",
-       .suspend        = acpi_device_suspend,
-       .resume         = acpi_device_resume,
-};
-
-
-
 static int __init acpi_scan_init(void)
 {
        int result;
@@ -1455,9 +1388,9 @@ static int __init acpi_scan_init(void)
        if (acpi_disabled)
                return 0;
 
-       result = kset_register(&acpi_namespace_kset);
-       if (result < 0)
-               printk(KERN_ERR PREFIX "kset_register error: %d\n", result);
+       memset(&ops, 0, sizeof(ops));
+       ops.acpi_op_add = 1;
+       ops.acpi_op_start = 1;
 
        result = bus_register(&acpi_bus_type);
        if (result) {
@@ -1469,32 +1402,16 @@ static int __init acpi_scan_init(void)
         * Create the root device in the bus's device tree
         */
        result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT,
-                                       ACPI_BUS_TYPE_SYSTEM);
+                                       ACPI_BUS_TYPE_SYSTEM, &ops);
        if (result)
                goto Done;
 
-       result = acpi_start_single_object(acpi_root);
-       if (result)
-               goto Done;
-
-       acpi_root->dev.bus = &acpi_bus_type;
-       snprintf(acpi_root->dev.bus_id, BUS_ID_SIZE, "%s", acpi_bus_type.name);
-       result = device_register(&acpi_root->dev);
-       if (result) {
-               /* We don't want to quit even if we failed to add suspend/resume */
-               printk(KERN_ERR PREFIX "Could not register device\n");
-       }
-
        /*
         * Enumerate devices in the ACPI namespace.
         */
        result = acpi_bus_scan_fixed(acpi_root);
-       if (!result) {
-               memset(&ops, 0, sizeof(ops));
-               ops.acpi_op_add = 1;
-               ops.acpi_op_start = 1;
+       if (!result)
                result = acpi_bus_scan(acpi_root, &ops);
-       }
 
        if (result)
                acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
index 34962578039d9a69c40b4ccca113617105456690..ccc11b33d89cd713036ae2d0f5ad98bb9a4bd3f3 100644 (file)
@@ -73,7 +73,7 @@ acpi_system_write_sleep(struct file *file,
 static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
 {
        u32 sec, min, hr;
-       u32 day, mo, yr;
+       u32 day, mo, yr, cent = 0;
        unsigned char rtc_control = 0;
        unsigned long flags;
 
@@ -87,20 +87,19 @@ static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
        rtc_control = CMOS_READ(RTC_CONTROL);
 
        /* If we ever get an FACP with proper values... */
-       if (acpi_gbl_FADT->day_alrm)
+       if (acpi_gbl_FADT.day_alarm)
                /* ACPI spec: only low 6 its should be cared */
-               day = CMOS_READ(acpi_gbl_FADT->day_alrm) & 0x3F;
+               day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F;
        else
                day = CMOS_READ(RTC_DAY_OF_MONTH);
-       if (acpi_gbl_FADT->mon_alrm)
-               mo = CMOS_READ(acpi_gbl_FADT->mon_alrm);
+       if (acpi_gbl_FADT.month_alarm)
+               mo = CMOS_READ(acpi_gbl_FADT.month_alarm);
        else
                mo = CMOS_READ(RTC_MONTH);
-       if (acpi_gbl_FADT->century)
-               yr = CMOS_READ(acpi_gbl_FADT->century) * 100 +
-                   CMOS_READ(RTC_YEAR);
-       else
-               yr = CMOS_READ(RTC_YEAR);
+       if (acpi_gbl_FADT.century)
+               cent = CMOS_READ(acpi_gbl_FADT.century);
+
+       yr = CMOS_READ(RTC_YEAR);
 
        spin_unlock_irqrestore(&rtc_lock, flags);
 
@@ -111,10 +110,11 @@ static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
                BCD_TO_BIN(day);
                BCD_TO_BIN(mo);
                BCD_TO_BIN(yr);
+               BCD_TO_BIN(cent);
        }
 
        /* we're trusting the FADT (see above) */
-       if (!acpi_gbl_FADT->century)
+       if (!acpi_gbl_FADT.century)
                /* If we're not trusting the FADT, we should at least make it
                 * right for _this_ century... ehm, what is _this_ century?
                 *
@@ -134,6 +134,8 @@ static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
                 *
                 */
                yr += 2000;
+       else
+               yr += cent * 100;
 
        seq_printf(seq, "%4.4u-", yr);
        (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo);
@@ -317,12 +319,12 @@ acpi_system_write_alarm(struct file *file,
         * offsets into the CMOS RAM here -- which for some reason are pointing
         * to the RTC area of memory.
         */
-       if (acpi_gbl_FADT->day_alrm)
-               CMOS_WRITE(day, acpi_gbl_FADT->day_alrm);
-       if (acpi_gbl_FADT->mon_alrm)
-               CMOS_WRITE(mo, acpi_gbl_FADT->mon_alrm);
-       if (acpi_gbl_FADT->century)
-               CMOS_WRITE(yr / 100, acpi_gbl_FADT->century);
+       if (acpi_gbl_FADT.day_alarm)
+               CMOS_WRITE(day, acpi_gbl_FADT.day_alarm);
+       if (acpi_gbl_FADT.month_alarm)
+               CMOS_WRITE(mo, acpi_gbl_FADT.month_alarm);
+       if (acpi_gbl_FADT.century)
+               CMOS_WRITE(yr / 100, acpi_gbl_FADT.century);
        /* enable the rtc alarm interrupt */
        rtc_control |= RTC_AIE;
        CMOS_WRITE(rtc_control, RTC_CONTROL);
index d86dcb3c236601347689ee5307a7da42bc4bed38..7147b0bdab0a83f8581d79bf192ea986deea10f5 100644 (file)
 
 #define _COMPONENT             ACPI_SYSTEM_COMPONENT
 ACPI_MODULE_NAME("acpi_system")
+#ifdef MODULE_PARAM_PREFIX
+#undef MODULE_PARAM_PREFIX
+#endif
+#define MODULE_PARAM_PREFIX "acpi."
+
 #define ACPI_SYSTEM_CLASS              "system"
 #define ACPI_SYSTEM_DRIVER_NAME                "ACPI System Driver"
 #define ACPI_SYSTEM_DEVICE_NAME                "System"
@@ -39,11 +44,24 @@ ACPI_MODULE_NAME("acpi_system")
 #define ACPI_SYSTEM_FILE_EVENT         "event"
 #define ACPI_SYSTEM_FILE_DSDT          "dsdt"
 #define ACPI_SYSTEM_FILE_FADT          "fadt"
-extern struct fadt_descriptor acpi_fadt;
+
+/*
+ * Make ACPICA version work as module param
+ */
+static int param_get_acpica_version(char *buffer, struct kernel_param *kp) {
+       int result;
+
+       result = sprintf(buffer, "%x", ACPI_CA_VERSION);
+
+       return result;
+}
+
+module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
 
 /* --------------------------------------------------------------------------
                               FS Interface (/proc)
    -------------------------------------------------------------------------- */
+#ifdef CONFIG_ACPI_PROCFS
 
 static int acpi_system_read_info(struct seq_file *seq, void *offset)
 {
@@ -63,6 +81,7 @@ static const struct file_operations acpi_system_info_ops = {
        .llseek = seq_lseek,
        .release = single_release,
 };
+#endif
 
 static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
                                     loff_t *);
@@ -76,17 +95,16 @@ acpi_system_read_dsdt(struct file *file,
                      char __user * buffer, size_t count, loff_t * ppos)
 {
        acpi_status status = AE_OK;
-       struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
+       struct acpi_table_header *dsdt = NULL;
        ssize_t res;
 
 
-       status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
+       status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
        if (ACPI_FAILURE(status))
                return -ENODEV;
 
        res = simple_read_from_buffer(buffer, count, ppos,
-                                     dsdt.pointer, dsdt.length);
-       kfree(dsdt.pointer);
+                                     dsdt, dsdt->length);
 
        return res;
 }
@@ -103,17 +121,16 @@ acpi_system_read_fadt(struct file *file,
                      char __user * buffer, size_t count, loff_t * ppos)
 {
        acpi_status status = AE_OK;
-       struct acpi_buffer fadt = { ACPI_ALLOCATE_BUFFER, NULL };
+       struct acpi_table_header *fadt = NULL;
        ssize_t res;
 
 
-       status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &fadt);
+       status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
        if (ACPI_FAILURE(status))
                return -ENODEV;
 
        res = simple_read_from_buffer(buffer, count, ppos,
-                                     fadt.pointer, fadt.length);
-       kfree(fadt.pointer);
+                                     fadt, fadt->length);
 
        return res;
 }
@@ -128,6 +145,7 @@ static int __init acpi_system_init(void)
        if (acpi_disabled)
                return 0;
 
+#ifdef CONFIG_ACPI_PROCFS
        /* 'info' [R] */
        name = ACPI_SYSTEM_FILE_INFO;
        entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
@@ -136,6 +154,7 @@ static int __init acpi_system_init(void)
        else {
                entry->proc_fops = &acpi_system_info_ops;
        }
+#endif
 
        /* 'dsdt' [R] */
        name = ACPI_SYSTEM_FILE_DSDT;
@@ -159,7 +178,9 @@ static int __init acpi_system_init(void)
       Error:
        remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
        remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
+#ifdef CONFIG_ACPI_PROCFS
        remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
+#endif
 
        error = -EFAULT;
        goto Done;
index ffa30c9fccbfbfd7e5a9c069edab2ee0aa9d3ae0..ba4cb200314a12f50b66527140e7abada696fe91 100644 (file)
 
 #define ACPI_MAX_TABLES                128
 
-static char *acpi_table_signatures[ACPI_TABLE_COUNT] = {
-       [ACPI_TABLE_UNKNOWN] = "????",
-       [ACPI_APIC] = "APIC",
-       [ACPI_BOOT] = "BOOT",
-       [ACPI_DBGP] = "DBGP",
-       [ACPI_DSDT] = "DSDT",
-       [ACPI_ECDT] = "ECDT",
-       [ACPI_ETDT] = "ETDT",
-       [ACPI_FADT] = "FACP",
-       [ACPI_FACS] = "FACS",
-       [ACPI_OEMX] = "OEM",
-       [ACPI_PSDT] = "PSDT",
-       [ACPI_SBST] = "SBST",
-       [ACPI_SLIT] = "SLIT",
-       [ACPI_SPCR] = "SPCR",
-       [ACPI_SRAT] = "SRAT",
-       [ACPI_SSDT] = "SSDT",
-       [ACPI_SPMI] = "SPMI",
-       [ACPI_HPET] = "HPET",
-       [ACPI_MCFG] = "MCFG",
-};
-
 static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
 static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
 
-/* System Description Table (RSDT/XSDT) */
-struct acpi_table_sdt {
-       unsigned long pa;
-       enum acpi_table_id id;
-       unsigned long size;
-} __attribute__ ((packed));
-
-static unsigned long sdt_pa;   /* Physical Address */
-static unsigned long sdt_count;        /* Table count */
+static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata;
 
-static struct acpi_table_sdt sdt_entry[ACPI_MAX_TABLES] __initdata;
-
-void acpi_table_print(struct acpi_table_header *header, unsigned long phys_addr)
-{
-       char *name = NULL;
-
-       if (!header)
-               return;
-
-       /* Some table signatures aren't good table names */
-
-       if (!strncmp((char *)&header->signature,
-                    acpi_table_signatures[ACPI_APIC],
-                    sizeof(header->signature))) {
-               name = "MADT";
-       } else if (!strncmp((char *)&header->signature,
-                           acpi_table_signatures[ACPI_FADT],
-                           sizeof(header->signature))) {
-               name = "FADT";
-       } else
-               name = header->signature;
-
-       printk(KERN_DEBUG PREFIX
-              "%.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n", name,
-              header->revision, header->oem_id, header->oem_table_id,
-              header->oem_revision, header->asl_compiler_id,
-              header->asl_compiler_revision, (void *)phys_addr);
-}
-
-void acpi_table_print_madt_entry(acpi_table_entry_header * header)
+void acpi_table_print_madt_entry(struct acpi_subtable_header * header)
 {
        if (!header)
                return;
 
        switch (header->type) {
 
-       case ACPI_MADT_LAPIC:
+       case ACPI_MADT_TYPE_LOCAL_APIC:
                {
-                       struct acpi_table_lapic *p =
-                           (struct acpi_table_lapic *)header;
+                       struct acpi_madt_local_apic *p =
+                           (struct acpi_madt_local_apic *)header;
                        printk(KERN_INFO PREFIX
                               "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
-                              p->acpi_id, p->id,
-                              p->flags.enabled ? "enabled" : "disabled");
+                              p->processor_id, p->id,
+                              (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
                }
                break;
 
-       case ACPI_MADT_IOAPIC:
+       case ACPI_MADT_TYPE_IO_APIC:
                {
-                       struct acpi_table_ioapic *p =
-                           (struct acpi_table_ioapic *)header;
+                       struct acpi_madt_io_apic *p =
+                           (struct acpi_madt_io_apic *)header;
                        printk(KERN_INFO PREFIX
                               "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
                               p->id, p->address, p->global_irq_base);
                }
                break;
 
-       case ACPI_MADT_INT_SRC_OVR:
+       case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
                {
-                       struct acpi_table_int_src_ovr *p =
-                           (struct acpi_table_int_src_ovr *)header;
+                       struct acpi_madt_interrupt_override *p =
+                           (struct acpi_madt_interrupt_override *)header;
                        printk(KERN_INFO PREFIX
                               "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
-                              p->bus, p->bus_irq, p->global_irq,
-                              mps_inti_flags_polarity[p->flags.polarity],
-                              mps_inti_flags_trigger[p->flags.trigger]);
-                       if (p->flags.reserved)
+                              p->bus, p->source_irq, p->global_irq,
+                              mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
+                              mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2]);
+                       if (p->inti_flags  &
+                           ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK))
                                printk(KERN_INFO PREFIX
                                       "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
-                                      p->flags.reserved);
+                                      p->inti_flags  &
+                                       ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK));
 
                }
                break;
 
-       case ACPI_MADT_NMI_SRC:
+       case ACPI_MADT_TYPE_NMI_SOURCE:
                {
-                       struct acpi_table_nmi_src *p =
-                           (struct acpi_table_nmi_src *)header;
+                       struct acpi_madt_nmi_source *p =
+                           (struct acpi_madt_nmi_source *)header;
                        printk(KERN_INFO PREFIX
                               "NMI_SRC (%s %s global_irq %d)\n",
-                              mps_inti_flags_polarity[p->flags.polarity],
-                              mps_inti_flags_trigger[p->flags.trigger],
+                              mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
+                              mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
                               p->global_irq);
                }
                break;
 
-       case ACPI_MADT_LAPIC_NMI:
+       case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
                {
-                       struct acpi_table_lapic_nmi *p =
-                           (struct acpi_table_lapic_nmi *)header;
+                       struct acpi_madt_local_apic_nmi *p =
+                           (struct acpi_madt_local_apic_nmi *)header;
                        printk(KERN_INFO PREFIX
                               "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
-                              p->acpi_id,
-                              mps_inti_flags_polarity[p->flags.polarity],
-                              mps_inti_flags_trigger[p->flags.trigger],
+                              p->processor_id,
+                              mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK  ],
+                              mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
                               p->lint);
                }
                break;
 
-       case ACPI_MADT_LAPIC_ADDR_OVR:
+       case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
                {
-                       struct acpi_table_lapic_addr_ovr *p =
-                           (struct acpi_table_lapic_addr_ovr *)header;
+                       struct acpi_madt_local_apic_override *p =
+                           (struct acpi_madt_local_apic_override *)header;
                        printk(KERN_INFO PREFIX
                               "LAPIC_ADDR_OVR (address[%p])\n",
                               (void *)(unsigned long)p->address);
                }
                break;
 
-       case ACPI_MADT_IOSAPIC:
+       case ACPI_MADT_TYPE_IO_SAPIC:
                {
-                       struct acpi_table_iosapic *p =
-                           (struct acpi_table_iosapic *)header;
+                       struct acpi_madt_io_sapic *p =
+                           (struct acpi_madt_io_sapic *)header;
                        printk(KERN_INFO PREFIX
                               "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
                               p->id, (void *)(unsigned long)p->address,
@@ -193,26 +136,26 @@ void acpi_table_print_madt_entry(acpi_table_entry_header * header)
                }
                break;
 
-       case ACPI_MADT_LSAPIC:
+       case ACPI_MADT_TYPE_LOCAL_SAPIC:
                {
-                       struct acpi_table_lsapic *p =
-                           (struct acpi_table_lsapic *)header;
+                       struct acpi_madt_local_sapic *p =
+                           (struct acpi_madt_local_sapic *)header;
                        printk(KERN_INFO PREFIX
                               "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
-                              p->acpi_id, p->id, p->eid,
-                              p->flags.enabled ? "enabled" : "disabled");
+                              p->processor_id, p->id, p->eid,
+                              (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
                }
                break;
 
-       case ACPI_MADT_PLAT_INT_SRC:
+       case ACPI_MADT_TYPE_INTERRUPT_SOURCE:
                {
-                       struct acpi_table_plat_int_src *p =
-                           (struct acpi_table_plat_int_src *)header;
+                       struct acpi_madt_interrupt_source *p =
+                           (struct acpi_madt_interrupt_source *)header;
                        printk(KERN_INFO PREFIX
                               "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
-                              mps_inti_flags_polarity[p->flags.polarity],
-                              mps_inti_flags_trigger[p->flags.trigger],
-                              p->type, p->id, p->eid, p->iosapic_vector,
+                              mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
+                              mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
+                              p->type, p->id, p->eid, p->io_sapic_vector,
                               p->global_irq);
                }
                break;
@@ -225,342 +168,76 @@ void acpi_table_print_madt_entry(acpi_table_entry_header * header)
        }
 }
 
-static int
-acpi_table_compute_checksum(void *table_pointer, unsigned long length)
-{
-       u8 *p = table_pointer;
-       unsigned long remains = length;
-       unsigned long sum = 0;
-
-       if (!p || !length)
-               return -EINVAL;
-
-       while (remains--)
-               sum += *p++;
-
-       return (sum & 0xFF);
-}
 
-/*
- * acpi_get_table_header_early()
- * for acpi_blacklisted(), acpi_table_get_sdt()
- */
 int __init
-acpi_get_table_header_early(enum acpi_table_id id,
-                           struct acpi_table_header **header)
-{
-       unsigned int i;
-       enum acpi_table_id temp_id;
-
-       /* DSDT is different from the rest */
-       if (id == ACPI_DSDT)
-               temp_id = ACPI_FADT;
-       else
-               temp_id = id;
-
-       /* Locate the table. */
-
-       for (i = 0; i < sdt_count; i++) {
-               if (sdt_entry[i].id != temp_id)
-                       continue;
-               *header = (void *)
-                   __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
-               if (!*header) {
-                       printk(KERN_WARNING PREFIX "Unable to map %s\n",
-                              acpi_table_signatures[temp_id]);
-                       return -ENODEV;
-               }
-               break;
-       }
-
-       if (!*header) {
-               printk(KERN_WARNING PREFIX "%s not present\n",
-                      acpi_table_signatures[id]);
-               return -ENODEV;
-       }
-
-       /* Map the DSDT header via the pointer in the FADT */
-       if (id == ACPI_DSDT) {
-               struct fadt_descriptor *fadt =
-                   (struct fadt_descriptor *)*header;
-
-               if (fadt->revision == 3 && fadt->Xdsdt) {
-                       *header = (void *)__acpi_map_table(fadt->Xdsdt,
-                                                          sizeof(struct
-                                                                 acpi_table_header));
-               } else if (fadt->V1_dsdt) {
-                       *header = (void *)__acpi_map_table(fadt->V1_dsdt,
-                                                          sizeof(struct
-                                                                 acpi_table_header));
-               } else
-                       *header = NULL;
-
-               if (!*header) {
-                       printk(KERN_WARNING PREFIX "Unable to map DSDT\n");
-                       return -ENODEV;
-               }
-       }
-
-       return 0;
-}
-
-int __init
-acpi_table_parse_madt_family(enum acpi_table_id id,
+acpi_table_parse_madt_family(char *id,
                             unsigned long madt_size,
                             int entry_id,
                             acpi_madt_entry_handler handler,
                             unsigned int max_entries)
 {
-       void *madt = NULL;
-       acpi_table_entry_header *entry;
+       struct acpi_table_header *madt = NULL;
+       struct acpi_subtable_header *entry;
        unsigned int count = 0;
        unsigned long madt_end;
-       unsigned int i;
 
        if (!handler)
                return -EINVAL;
 
        /* Locate the MADT (if exists). There should only be one. */
-
-       for (i = 0; i < sdt_count; i++) {
-               if (sdt_entry[i].id != id)
-                       continue;
-               madt = (void *)
-                   __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
-               if (!madt) {
-                       printk(KERN_WARNING PREFIX "Unable to map %s\n",
-                              acpi_table_signatures[id]);
-                       return -ENODEV;
-               }
-               break;
-       }
+       acpi_get_table(id, 0, &madt);
 
        if (!madt) {
-               printk(KERN_WARNING PREFIX "%s not present\n",
-                      acpi_table_signatures[id]);
+               printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
                return -ENODEV;
        }
 
-       madt_end = (unsigned long)madt + sdt_entry[i].size;
+       madt_end = (unsigned long)madt + madt->length;
 
        /* Parse all entries looking for a match. */
 
-       entry = (acpi_table_entry_header *)
+       entry = (struct acpi_subtable_header *)
            ((unsigned long)madt + madt_size);
 
-       while (((unsigned long)entry) + sizeof(acpi_table_entry_header) <
+       while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
               madt_end) {
                if (entry->type == entry_id
                    && (!max_entries || count++ < max_entries))
                        if (handler(entry, madt_end))
                                return -EINVAL;
 
-               entry = (acpi_table_entry_header *)
+               entry = (struct acpi_subtable_header *)
                    ((unsigned long)entry + entry->length);
        }
        if (max_entries && count > max_entries) {
-               printk(KERN_WARNING PREFIX "[%s:0x%02x] ignored %i entries of "
-                      "%i found\n", acpi_table_signatures[id], entry_id,
-                      count - max_entries, count);
+               printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of "
+                      "%i found\n", id, entry_id, count - max_entries, count);
        }
 
        return count;
 }
 
 int __init
-acpi_table_parse_madt(enum acpi_madt_entry_id id,
+acpi_table_parse_madt(enum acpi_madt_type id,
                      acpi_madt_entry_handler handler, unsigned int max_entries)
 {
-       return acpi_table_parse_madt_family(ACPI_APIC,
+       return acpi_table_parse_madt_family(ACPI_SIG_MADT,
                                            sizeof(struct acpi_table_madt), id,
                                            handler, max_entries);
 }
 
-int __init acpi_table_parse(enum acpi_table_id id, acpi_table_handler handler)
+int __init acpi_table_parse(char *id, acpi_table_handler handler)
 {
-       int count = 0;
-       unsigned int i = 0;
-
+       struct acpi_table_header *table = NULL;
        if (!handler)
                return -EINVAL;
 
-       for (i = 0; i < sdt_count; i++) {
-               if (sdt_entry[i].id != id)
-                       continue;
-               count++;
-               if (count == 1)
-                       handler(sdt_entry[i].pa, sdt_entry[i].size);
-
-               else
-                       printk(KERN_WARNING PREFIX
-                              "%d duplicate %s table ignored.\n", count,
-                              acpi_table_signatures[id]);
-       }
-
-       return count;
-}
-
-static int __init acpi_table_get_sdt(struct acpi_table_rsdp *rsdp)
-{
-       struct acpi_table_header *header = NULL;
-       unsigned int i, id = 0;
-
-       if (!rsdp)
-               return -EINVAL;
-
-       /* First check XSDT (but only on ACPI 2.0-compatible systems) */
-
-       if ((rsdp->revision >= 2) &&
-           (((struct acpi20_table_rsdp *)rsdp)->xsdt_address)) {
-
-               struct acpi_table_xsdt *mapped_xsdt = NULL;
-
-               sdt_pa = ((struct acpi20_table_rsdp *)rsdp)->xsdt_address;
-
-               /* map in just the header */
-               header = (struct acpi_table_header *)
-                   __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
-
-               if (!header) {
-                       printk(KERN_WARNING PREFIX
-                              "Unable to map XSDT header\n");
-                       return -ENODEV;
-               }
-
-               /* remap in the entire table before processing */
-               mapped_xsdt = (struct acpi_table_xsdt *)
-                   __acpi_map_table(sdt_pa, header->length);
-               if (!mapped_xsdt) {
-                       printk(KERN_WARNING PREFIX "Unable to map XSDT\n");
-                       return -ENODEV;
-               }
-               header = &mapped_xsdt->header;
-
-               if (strncmp(header->signature, "XSDT", 4)) {
-                       printk(KERN_WARNING PREFIX
-                              "XSDT signature incorrect\n");
-                       return -ENODEV;
-               }
-
-               if (acpi_table_compute_checksum(header, header->length)) {
-                       printk(KERN_WARNING PREFIX "Invalid XSDT checksum\n");
-                       return -ENODEV;
-               }
-
-               sdt_count =
-                   (header->length - sizeof(struct acpi_table_header)) >> 3;
-               if (sdt_count > ACPI_MAX_TABLES) {
-                       printk(KERN_WARNING PREFIX
-                              "Truncated %lu XSDT entries\n",
-                              (sdt_count - ACPI_MAX_TABLES));
-                       sdt_count = ACPI_MAX_TABLES;
-               }
-
-               for (i = 0; i < sdt_count; i++)
-                       sdt_entry[i].pa = (unsigned long)mapped_xsdt->entry[i];
-       }
-
-       /* Then check RSDT */
-
-       else if (rsdp->rsdt_address) {
-
-               struct acpi_table_rsdt *mapped_rsdt = NULL;
-
-               sdt_pa = rsdp->rsdt_address;
-
-               /* map in just the header */
-               header = (struct acpi_table_header *)
-                   __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
-               if (!header) {
-                       printk(KERN_WARNING PREFIX
-                              "Unable to map RSDT header\n");
-                       return -ENODEV;
-               }
-
-               /* remap in the entire table before processing */
-               mapped_rsdt = (struct acpi_table_rsdt *)
-                   __acpi_map_table(sdt_pa, header->length);
-               if (!mapped_rsdt) {
-                       printk(KERN_WARNING PREFIX "Unable to map RSDT\n");
-                       return -ENODEV;
-               }
-               header = &mapped_rsdt->header;
-
-               if (strncmp(header->signature, "RSDT", 4)) {
-                       printk(KERN_WARNING PREFIX
-                              "RSDT signature incorrect\n");
-                       return -ENODEV;
-               }
-
-               if (acpi_table_compute_checksum(header, header->length)) {
-                       printk(KERN_WARNING PREFIX "Invalid RSDT checksum\n");
-                       return -ENODEV;
-               }
-
-               sdt_count =
-                   (header->length - sizeof(struct acpi_table_header)) >> 2;
-               if (sdt_count > ACPI_MAX_TABLES) {
-                       printk(KERN_WARNING PREFIX
-                              "Truncated %lu RSDT entries\n",
-                              (sdt_count - ACPI_MAX_TABLES));
-                       sdt_count = ACPI_MAX_TABLES;
-               }
-
-               for (i = 0; i < sdt_count; i++)
-                       sdt_entry[i].pa = (unsigned long)mapped_rsdt->entry[i];
-       }
-
-       else {
-               printk(KERN_WARNING PREFIX
-                      "No System Description Table (RSDT/XSDT) specified in RSDP\n");
-               return -ENODEV;
-       }
-
-       acpi_table_print(header, sdt_pa);
-
-       for (i = 0; i < sdt_count; i++) {
-
-               /* map in just the header */
-               header = (struct acpi_table_header *)
-                   __acpi_map_table(sdt_entry[i].pa,
-                                    sizeof(struct acpi_table_header));
-               if (!header)
-                       continue;
-
-               /* remap in the entire table before processing */
-               header = (struct acpi_table_header *)
-                   __acpi_map_table(sdt_entry[i].pa, header->length);
-               if (!header)
-                       continue;
-
-               acpi_table_print(header, sdt_entry[i].pa);
-
-               if (acpi_table_compute_checksum(header, header->length)) {
-                       printk(KERN_WARNING "  >>> ERROR: Invalid checksum\n");
-                       continue;
-               }
-
-               sdt_entry[i].size = header->length;
-
-               for (id = 0; id < ACPI_TABLE_COUNT; id++) {
-                       if (!strncmp((char *)&header->signature,
-                                    acpi_table_signatures[id],
-                                    sizeof(header->signature))) {
-                               sdt_entry[i].id = id;
-                       }
-               }
-       }
-
-       /* 
-        * The DSDT is *not* in the RSDT (why not? no idea.) but we want
-        * to print its info, because this is what people usually blacklist
-        * against. Unfortunately, we don't know the phys_addr, so just
-        * print 0. Maybe no one will notice.
-        */
-       if (!acpi_get_table_header_early(ACPI_DSDT, &header))
-               acpi_table_print(header, 0);
-
-       return 0;
+       acpi_get_table(id, 0, &table);
+       if (table) {
+               handler(table);
+               return 1;
+       } else
+               return 0;
 }
 
 /*
@@ -568,54 +245,13 @@ static int __init acpi_table_get_sdt(struct acpi_table_rsdp *rsdp)
  *
  * find RSDP, find and checksum SDT/XSDT.
  * checksum all tables, print SDT/XSDT
- * 
+ *
  * result: sdt_entry[] is initialized
  */
 
+
 int __init acpi_table_init(void)
 {
-       struct acpi_table_rsdp *rsdp = NULL;
-       unsigned long rsdp_phys = 0;
-       int result = 0;
-
-       /* Locate and map the Root System Description Table (RSDP) */
-
-       rsdp_phys = acpi_find_rsdp();
-       if (!rsdp_phys) {
-               printk(KERN_ERR PREFIX "Unable to locate RSDP\n");
-               return -ENODEV;
-       }
-
-       rsdp = (struct acpi_table_rsdp *)__acpi_map_table(rsdp_phys,
-               sizeof(struct acpi_table_rsdp));
-       if (!rsdp) {
-               printk(KERN_WARNING PREFIX "Unable to map RSDP\n");
-               return -ENODEV;
-       }
-
-       printk(KERN_DEBUG PREFIX
-              "RSDP (v%3.3d %6.6s                                ) @ 0x%p\n",
-              rsdp->revision, rsdp->oem_id, (void *)rsdp_phys);
-
-       if (rsdp->revision < 2)
-               result =
-                   acpi_table_compute_checksum(rsdp,
-                                               sizeof(struct acpi_table_rsdp));
-       else
-               result =
-                   acpi_table_compute_checksum(rsdp,
-                                               ((struct acpi20_table_rsdp *)
-                                                rsdp)->length);
-
-       if (result) {
-               printk(KERN_WARNING "  >>> ERROR: Invalid checksum\n");
-               return -ENODEV;
-       }
-
-       /* Locate and map the System Description table (RSDT/XSDT) */
-
-       if (acpi_table_get_sdt(rsdp))
-               return -ENODEV;
-
+       acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
        return 0;
 }
index aa4c69594d97f423767f3bb50dbbc98a3ff677f7..0a7d7afac255e505e1733c05a38c31a379344c70 100644 (file)
@@ -2,7 +2,6 @@
 # Makefile for all Linux ACPI interpreter subdirectories
 #
 
-obj-y := tbconvrt.o  tbget.o     tbrsdt.o   tbxface.o  \
-        tbgetall.o  tbinstal.o  tbutils.o  tbxfroot.o
+obj-y := tbxface.o tbinstal.o  tbutils.o tbfind.o tbfadt.o
 
 EXTRA_CFLAGS += $(ACPI_CFLAGS)
diff --git a/drivers/acpi/tables/tbconvrt.c b/drivers/acpi/tables/tbconvrt.c
deleted file mode 100644 (file)
index d697fcb..0000000
+++ /dev/null
@@ -1,622 +0,0 @@
-/******************************************************************************
- *
- * Module Name: tbconvrt - ACPI Table conversion utilities
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2006, R. Byron Moore
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include <acpi/acpi.h>
-#include <acpi/actables.h>
-
-#define _COMPONENT          ACPI_TABLES
-ACPI_MODULE_NAME("tbconvrt")
-
-/* Local prototypes */
-static void
-acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
-                            u8 register_bit_width,
-                            acpi_physical_address address);
-
-static void
-acpi_tb_convert_fadt1(struct fadt_descriptor *local_fadt,
-                     struct fadt_descriptor_rev1 *original_fadt);
-
-static void
-acpi_tb_convert_fadt2(struct fadt_descriptor *local_fadt,
-                     struct fadt_descriptor *original_fadt);
-
-u8 acpi_fadt_is_v1;
-ACPI_EXPORT_SYMBOL(acpi_fadt_is_v1)
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_table_count
- *
- * PARAMETERS:  RSDP            - Pointer to the RSDP
- *              RSDT            - Pointer to the RSDT/XSDT
- *
- * RETURN:      The number of tables pointed to by the RSDT or XSDT.
- *
- * DESCRIPTION: Calculate the number of tables.  Automatically handles either
- *              an RSDT or XSDT.
- *
- ******************************************************************************/
-
-u32
-acpi_tb_get_table_count(struct rsdp_descriptor *RSDP,
-                       struct acpi_table_header *RSDT)
-{
-       u32 pointer_size;
-
-       ACPI_FUNCTION_ENTRY();
-
-       /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */
-
-       if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
-               pointer_size = sizeof(u32);
-       } else {
-               pointer_size = sizeof(u64);
-       }
-
-       /*
-        * Determine the number of tables pointed to by the RSDT/XSDT.
-        * This is defined by the ACPI Specification to be the number of
-        * pointers contained within the RSDT/XSDT.  The size of the pointers
-        * is architecture-dependent.
-        */
-       return ((RSDT->length -
-                sizeof(struct acpi_table_header)) / pointer_size);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_convert_to_xsdt
- *
- * PARAMETERS:  table_info      - Info about the RSDT
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Convert an RSDT to an XSDT (internal common format)
- *
- ******************************************************************************/
-
-acpi_status acpi_tb_convert_to_xsdt(struct acpi_table_desc *table_info)
-{
-       acpi_size table_size;
-       u32 i;
-       struct xsdt_descriptor *new_table;
-
-       ACPI_FUNCTION_ENTRY();
-
-       /* Compute size of the converted XSDT */
-
-       table_size = ((acpi_size) acpi_gbl_rsdt_table_count * sizeof(u64)) +
-           sizeof(struct acpi_table_header);
-
-       /* Allocate an XSDT */
-
-       new_table = ACPI_ALLOCATE_ZEROED(table_size);
-       if (!new_table) {
-               return (AE_NO_MEMORY);
-       }
-
-       /* Copy the header and set the length */
-
-       ACPI_MEMCPY(new_table, table_info->pointer,
-                   sizeof(struct acpi_table_header));
-       new_table->length = (u32) table_size;
-
-       /* Copy the table pointers */
-
-       for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
-
-               /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */
-
-               if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
-                       ACPI_STORE_ADDRESS(new_table->table_offset_entry[i],
-                                          (ACPI_CAST_PTR
-                                           (struct rsdt_descriptor,
-                                            table_info->pointer))->
-                                          table_offset_entry[i]);
-               } else {
-                       new_table->table_offset_entry[i] =
-                           (ACPI_CAST_PTR(struct xsdt_descriptor,
-                                          table_info->pointer))->
-                           table_offset_entry[i];
-               }
-       }
-
-       /* Delete the original table (either mapped or in a buffer) */
-
-       acpi_tb_delete_single_table(table_info);
-
-       /* Point the table descriptor to the new table */
-
-       table_info->pointer =
-           ACPI_CAST_PTR(struct acpi_table_header, new_table);
-       table_info->length = table_size;
-       table_info->allocation = ACPI_MEM_ALLOCATED;
-
-       return (AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_init_generic_address
- *
- * PARAMETERS:  new_gas_struct      - GAS struct to be initialized
- *              register_bit_width  - Width of this register
- *              Address             - Address of the register
- *
- * RETURN:      None
- *
- * DESCRIPTION: Initialize a GAS structure.
- *
- ******************************************************************************/
-
-static void
-acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
-                            u8 register_bit_width,
-                            acpi_physical_address address)
-{
-
-       ACPI_STORE_ADDRESS(new_gas_struct->address, address);
-
-       new_gas_struct->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO;
-       new_gas_struct->register_bit_width = register_bit_width;
-       new_gas_struct->register_bit_offset = 0;
-       new_gas_struct->access_width = 0;
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_convert_fadt1
- *
- * PARAMETERS:  local_fadt      - Pointer to new FADT
- *              original_fadt   - Pointer to old FADT
- *
- * RETURN:      None, populates local_fadt
- *
- * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format
- *
- ******************************************************************************/
-
-static void
-acpi_tb_convert_fadt1(struct fadt_descriptor *local_fadt,
-                     struct fadt_descriptor_rev1 *original_fadt)
-{
-
-       /* ACPI 1.0 FACS */
-       /* The BIOS stored FADT should agree with Revision 1.0 */
-       acpi_fadt_is_v1 = 1;
-
-       /*
-        * Copy the table header and the common part of the tables.
-        *
-        * The 2.0 table is an extension of the 1.0 table, so the entire 1.0
-        * table can be copied first, then expand some fields to 64 bits.
-        */
-       ACPI_MEMCPY(local_fadt, original_fadt,
-                   sizeof(struct fadt_descriptor_rev1));
-
-       /* Convert table pointers to 64-bit fields */
-
-       ACPI_STORE_ADDRESS(local_fadt->xfirmware_ctrl,
-                          local_fadt->V1_firmware_ctrl);
-       ACPI_STORE_ADDRESS(local_fadt->Xdsdt, local_fadt->V1_dsdt);
-
-       /*
-        * System Interrupt Model isn't used in ACPI 2.0
-        * (local_fadt->Reserved1 = 0;)
-        */
-
-       /*
-        * This field is set by the OEM to convey the preferred power management
-        * profile to OSPM. It doesn't have any 1.0 equivalence.  Since we don't
-        * know what kind of 32-bit system this is, we will use "unspecified".
-        */
-       local_fadt->prefer_PM_profile = PM_UNSPECIFIED;
-
-       /*
-        * Processor Performance State Control. This is the value OSPM writes to
-        * the SMI_CMD register to assume processor performance state control
-        * responsibility. There isn't any equivalence in 1.0, but as many 1.x
-        * ACPI tables contain _PCT and _PSS we also keep this value, unless
-        * acpi_strict is set.
-        */
-       if (acpi_strict)
-               local_fadt->pstate_cnt = 0;
-
-       /*
-        * Support for the _CST object and C States change notification.
-        * This data item hasn't any 1.0 equivalence so leave it zero.
-        */
-       local_fadt->cst_cnt = 0;
-
-       /*
-        * FADT Rev 2 was an interim FADT released between ACPI 1.0 and ACPI 2.0.
-        * It primarily adds the FADT reset mechanism.
-        */
-       if ((original_fadt->revision == 2) &&
-           (original_fadt->length ==
-            sizeof(struct fadt_descriptor_rev2_minus))) {
-               /*
-                * Grab the entire generic address struct, plus the 1-byte reset value
-                * that immediately follows.
-                */
-               ACPI_MEMCPY(&local_fadt->reset_register,
-                           &(ACPI_CAST_PTR(struct fadt_descriptor_rev2_minus,
-                                           original_fadt))->reset_register,
-                           sizeof(struct acpi_generic_address) + 1);
-       } else {
-               /*
-                * Since there isn't any equivalence in 1.0 and since it is highly
-                * likely that a 1.0 system has legacy support.
-                */
-               local_fadt->iapc_boot_arch = BAF_LEGACY_DEVICES;
-       }
-
-       /*
-        * Convert the V1.0 block addresses to V2.0 GAS structures
-        */
-       acpi_tb_init_generic_address(&local_fadt->xpm1a_evt_blk,
-                                    local_fadt->pm1_evt_len,
-                                    (acpi_physical_address) local_fadt->
-                                    V1_pm1a_evt_blk);
-       acpi_tb_init_generic_address(&local_fadt->xpm1b_evt_blk,
-                                    local_fadt->pm1_evt_len,
-                                    (acpi_physical_address) local_fadt->
-                                    V1_pm1b_evt_blk);
-       acpi_tb_init_generic_address(&local_fadt->xpm1a_cnt_blk,
-                                    local_fadt->pm1_cnt_len,
-                                    (acpi_physical_address) local_fadt->
-                                    V1_pm1a_cnt_blk);
-       acpi_tb_init_generic_address(&local_fadt->xpm1b_cnt_blk,
-                                    local_fadt->pm1_cnt_len,
-                                    (acpi_physical_address) local_fadt->
-                                    V1_pm1b_cnt_blk);
-       acpi_tb_init_generic_address(&local_fadt->xpm2_cnt_blk,
-                                    local_fadt->pm2_cnt_len,
-                                    (acpi_physical_address) local_fadt->
-                                    V1_pm2_cnt_blk);
-       acpi_tb_init_generic_address(&local_fadt->xpm_tmr_blk,
-                                    local_fadt->pm_tm_len,
-                                    (acpi_physical_address) local_fadt->
-                                    V1_pm_tmr_blk);
-       acpi_tb_init_generic_address(&local_fadt->xgpe0_blk, 0,
-                                    (acpi_physical_address) local_fadt->
-                                    V1_gpe0_blk);
-       acpi_tb_init_generic_address(&local_fadt->xgpe1_blk, 0,
-                                    (acpi_physical_address) local_fadt->
-                                    V1_gpe1_blk);
-
-       /* Create separate GAS structs for the PM1 Enable registers */
-
-       acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
-                                    (u8) ACPI_DIV_2(acpi_gbl_FADT->
-                                                    pm1_evt_len),
-                                    (acpi_physical_address)
-                                    (local_fadt->xpm1a_evt_blk.address +
-                                     ACPI_DIV_2(acpi_gbl_FADT->pm1_evt_len)));
-
-       /* PM1B is optional; leave null if not present */
-
-       if (local_fadt->xpm1b_evt_blk.address) {
-               acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
-                                            (u8) ACPI_DIV_2(acpi_gbl_FADT->
-                                                            pm1_evt_len),
-                                            (acpi_physical_address)
-                                            (local_fadt->xpm1b_evt_blk.
-                                             address +
-                                             ACPI_DIV_2(acpi_gbl_FADT->
-                                                        pm1_evt_len)));
-       }
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_convert_fadt2
- *
- * PARAMETERS:  local_fadt      - Pointer to new FADT
- *              original_fadt   - Pointer to old FADT
- *
- * RETURN:      None, populates local_fadt
- *
- * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format.
- *              Handles optional "X" fields.
- *
- ******************************************************************************/
-
-static void
-acpi_tb_convert_fadt2(struct fadt_descriptor *local_fadt,
-                     struct fadt_descriptor *original_fadt)
-{
-
-       /* We have an ACPI 2.0 FADT but we must copy it to our local buffer */
-
-       ACPI_MEMCPY(local_fadt, original_fadt, sizeof(struct fadt_descriptor));
-
-       /*
-        * "X" fields are optional extensions to the original V1.0 fields, so
-        * we must selectively expand V1.0 fields if the corresponding X field
-        * is zero.
-        */
-       if (!(local_fadt->xfirmware_ctrl)) {
-               ACPI_STORE_ADDRESS(local_fadt->xfirmware_ctrl,
-                                  local_fadt->V1_firmware_ctrl);
-       }
-
-       if (!(local_fadt->Xdsdt)) {
-               ACPI_STORE_ADDRESS(local_fadt->Xdsdt, local_fadt->V1_dsdt);
-       }
-
-       if (!(local_fadt->xpm1a_evt_blk.address)) {
-               acpi_tb_init_generic_address(&local_fadt->xpm1a_evt_blk,
-                                            local_fadt->pm1_evt_len,
-                                            (acpi_physical_address)
-                                            local_fadt->V1_pm1a_evt_blk);
-       }
-
-       if (!(local_fadt->xpm1b_evt_blk.address)) {
-               acpi_tb_init_generic_address(&local_fadt->xpm1b_evt_blk,
-                                            local_fadt->pm1_evt_len,
-                                            (acpi_physical_address)
-                                            local_fadt->V1_pm1b_evt_blk);
-       }
-
-       if (!(local_fadt->xpm1a_cnt_blk.address)) {
-               acpi_tb_init_generic_address(&local_fadt->xpm1a_cnt_blk,
-                                            local_fadt->pm1_cnt_len,
-                                            (acpi_physical_address)
-                                            local_fadt->V1_pm1a_cnt_blk);
-       }
-
-       if (!(local_fadt->xpm1b_cnt_blk.address)) {
-               acpi_tb_init_generic_address(&local_fadt->xpm1b_cnt_blk,
-                                            local_fadt->pm1_cnt_len,
-                                            (acpi_physical_address)
-                                            local_fadt->V1_pm1b_cnt_blk);
-       }
-
-       if (!(local_fadt->xpm2_cnt_blk.address)) {
-               acpi_tb_init_generic_address(&local_fadt->xpm2_cnt_blk,
-                                            local_fadt->pm2_cnt_len,
-                                            (acpi_physical_address)
-                                            local_fadt->V1_pm2_cnt_blk);
-       }
-
-       if (!(local_fadt->xpm_tmr_blk.address)) {
-               acpi_tb_init_generic_address(&local_fadt->xpm_tmr_blk,
-                                            local_fadt->pm_tm_len,
-                                            (acpi_physical_address)
-                                            local_fadt->V1_pm_tmr_blk);
-       }
-
-       if (!(local_fadt->xgpe0_blk.address)) {
-               acpi_tb_init_generic_address(&local_fadt->xgpe0_blk,
-                                            0,
-                                            (acpi_physical_address)
-                                            local_fadt->V1_gpe0_blk);
-       }
-
-       if (!(local_fadt->xgpe1_blk.address)) {
-               acpi_tb_init_generic_address(&local_fadt->xgpe1_blk,
-                                            0,
-                                            (acpi_physical_address)
-                                            local_fadt->V1_gpe1_blk);
-       }
-
-       /* Create separate GAS structs for the PM1 Enable registers */
-
-       acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
-                                    (u8) ACPI_DIV_2(acpi_gbl_FADT->
-                                                    pm1_evt_len),
-                                    (acpi_physical_address)
-                                    (local_fadt->xpm1a_evt_blk.address +
-                                     ACPI_DIV_2(acpi_gbl_FADT->pm1_evt_len)));
-
-       acpi_gbl_xpm1a_enable.address_space_id =
-           local_fadt->xpm1a_evt_blk.address_space_id;
-
-       /* PM1B is optional; leave null if not present */
-
-       if (local_fadt->xpm1b_evt_blk.address) {
-               acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
-                                            (u8) ACPI_DIV_2(acpi_gbl_FADT->
-                                                            pm1_evt_len),
-                                            (acpi_physical_address)
-                                            (local_fadt->xpm1b_evt_blk.
-                                             address +
-                                             ACPI_DIV_2(acpi_gbl_FADT->
-                                                        pm1_evt_len)));
-
-               acpi_gbl_xpm1b_enable.address_space_id =
-                   local_fadt->xpm1b_evt_blk.address_space_id;
-       }
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_convert_table_fadt
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Converts a BIOS supplied ACPI 1.0 FADT to a local
- *              ACPI 2.0 FADT. If the BIOS supplied a 2.0 FADT then it is simply
- *              copied to the local FADT.  The ACPI CA software uses this
- *              local FADT. Thus a significant amount of special #ifdef
- *              type codeing is saved.
- *
- ******************************************************************************/
-
-acpi_status acpi_tb_convert_table_fadt(void)
-{
-       struct fadt_descriptor *local_fadt;
-       struct acpi_table_desc *table_desc;
-
-       ACPI_FUNCTION_TRACE(tb_convert_table_fadt);
-
-       /*
-        * acpi_gbl_FADT is valid. Validate the FADT length. The table must be
-        * at least as long as the version 1.0 FADT
-        */
-       if (acpi_gbl_FADT->length < sizeof(struct fadt_descriptor_rev1)) {
-               ACPI_ERROR((AE_INFO, "FADT is invalid, too short: 0x%X",
-                           acpi_gbl_FADT->length));
-               return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
-       }
-
-       /* Allocate buffer for the ACPI 2.0(+) FADT */
-
-       local_fadt = ACPI_ALLOCATE_ZEROED(sizeof(struct fadt_descriptor));
-       if (!local_fadt) {
-               return_ACPI_STATUS(AE_NO_MEMORY);
-       }
-
-       if (acpi_gbl_FADT->revision >= FADT2_REVISION_ID) {
-               if (acpi_gbl_FADT->length < sizeof(struct fadt_descriptor)) {
-
-                       /* Length is too short to be a V2.0 table */
-
-                       ACPI_WARNING((AE_INFO,
-                                     "Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table",
-                                     acpi_gbl_FADT->length,
-                                     acpi_gbl_FADT->revision));
-
-                       acpi_tb_convert_fadt1(local_fadt,
-                                             (void *)acpi_gbl_FADT);
-               } else {
-                       /* Valid V2.0 table */
-
-                       acpi_tb_convert_fadt2(local_fadt, acpi_gbl_FADT);
-               }
-       } else {
-               /* Valid V1.0 table */
-
-               acpi_tb_convert_fadt1(local_fadt, (void *)acpi_gbl_FADT);
-       }
-
-       /* Global FADT pointer will point to the new common V2.0 FADT */
-
-       acpi_gbl_FADT = local_fadt;
-       acpi_gbl_FADT->length = sizeof(struct fadt_descriptor);
-
-       /* Free the original table */
-
-       table_desc = acpi_gbl_table_lists[ACPI_TABLE_ID_FADT].next;
-       acpi_tb_delete_single_table(table_desc);
-
-       /* Install the new table */
-
-       table_desc->pointer =
-           ACPI_CAST_PTR(struct acpi_table_header, acpi_gbl_FADT);
-       table_desc->allocation = ACPI_MEM_ALLOCATED;
-       table_desc->length = sizeof(struct fadt_descriptor);
-
-       /* Dump the entire FADT */
-
-       ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
-                         "Hex dump of common internal FADT, size %d (%X)\n",
-                         acpi_gbl_FADT->length, acpi_gbl_FADT->length));
-
-       ACPI_DUMP_BUFFER(ACPI_CAST_PTR(u8, acpi_gbl_FADT),
-                        acpi_gbl_FADT->length);
-
-       return_ACPI_STATUS(AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_build_common_facs
- *
- * PARAMETERS:  table_info      - Info for currently installed FACS
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Convert ACPI 1.0 and ACPI 2.0 FACS to a common internal
- *              table format.
- *
- ******************************************************************************/
-
-acpi_status acpi_tb_build_common_facs(struct acpi_table_desc *table_info)
-{
-
-       ACPI_FUNCTION_TRACE(tb_build_common_facs);
-
-       /* Absolute minimum length is 24, but the ACPI spec says 64 */
-
-       if (acpi_gbl_FACS->length < 24) {
-               ACPI_ERROR((AE_INFO, "Invalid FACS table length: 0x%X",
-                           acpi_gbl_FACS->length));
-               return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
-       }
-
-       if (acpi_gbl_FACS->length < 64) {
-               ACPI_WARNING((AE_INFO,
-                             "FACS is shorter than the ACPI specification allows: 0x%X, using anyway",
-                             acpi_gbl_FACS->length));
-       }
-
-       /* Copy fields to the new FACS */
-
-       acpi_gbl_common_fACS.global_lock = &(acpi_gbl_FACS->global_lock);
-
-       if ((acpi_gbl_RSDP->revision < 2) ||
-           (acpi_gbl_FACS->length < 32) ||
-           (!(acpi_gbl_FACS->xfirmware_waking_vector))) {
-
-               /* ACPI 1.0 FACS or short table or optional X_ field is zero */
-
-               acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR(u64,
-                                                                           &
-                                                                           (acpi_gbl_FACS->
-                                                                            firmware_waking_vector));
-               acpi_gbl_common_fACS.vector_width = 32;
-       } else {
-               /* ACPI 2.0 FACS with valid X_ field */
-
-               acpi_gbl_common_fACS.firmware_waking_vector =
-                   &acpi_gbl_FACS->xfirmware_waking_vector;
-               acpi_gbl_common_fACS.vector_width = 64;
-       }
-
-       return_ACPI_STATUS(AE_OK);
-}
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c
new file mode 100644 (file)
index 0000000..807c711
--- /dev/null
@@ -0,0 +1,434 @@
+/******************************************************************************
+ *
+ * Module Name: tbfadt   - FADT table utilities
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2007, R. Byron Moore
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <acpi/acpi.h>
+#include <acpi/actables.h>
+
+#define _COMPONENT          ACPI_TABLES
+ACPI_MODULE_NAME("tbfadt")
+
+/* Local prototypes */
+static void inline
+acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
+                            u8 bit_width, u64 address);
+
+static void acpi_tb_convert_fadt(void);
+
+static void acpi_tb_validate_fadt(void);
+
+/* Table for conversion of FADT to common internal format and FADT validation */
+
+typedef struct acpi_fadt_info {
+       char *name;
+       u8 target;
+       u8 source;
+       u8 length;
+       u8 type;
+
+} acpi_fadt_info;
+
+#define ACPI_FADT_REQUIRED          1
+#define ACPI_FADT_SEPARATE_LENGTH   2
+
+static struct acpi_fadt_info fadt_info_table[] = {
+       {"Pm1aEventBlock", ACPI_FADT_OFFSET(xpm1a_event_block),
+        ACPI_FADT_OFFSET(pm1a_event_block),
+        ACPI_FADT_OFFSET(pm1_event_length), ACPI_FADT_REQUIRED},
+
+       {"Pm1bEventBlock", ACPI_FADT_OFFSET(xpm1b_event_block),
+        ACPI_FADT_OFFSET(pm1b_event_block),
+        ACPI_FADT_OFFSET(pm1_event_length), 0},
+
+       {"Pm1aControlBlock", ACPI_FADT_OFFSET(xpm1a_control_block),
+        ACPI_FADT_OFFSET(pm1a_control_block),
+        ACPI_FADT_OFFSET(pm1_control_length), ACPI_FADT_REQUIRED},
+
+       {"Pm1bControlBlock", ACPI_FADT_OFFSET(xpm1b_control_block),
+        ACPI_FADT_OFFSET(pm1b_control_block),
+        ACPI_FADT_OFFSET(pm1_control_length), 0},
+
+       {"Pm2ControlBlock", ACPI_FADT_OFFSET(xpm2_control_block),
+        ACPI_FADT_OFFSET(pm2_control_block),
+        ACPI_FADT_OFFSET(pm2_control_length), ACPI_FADT_SEPARATE_LENGTH},
+
+       {"PmTimerBlock", ACPI_FADT_OFFSET(xpm_timer_block),
+        ACPI_FADT_OFFSET(pm_timer_block),
+        ACPI_FADT_OFFSET(pm_timer_length), ACPI_FADT_REQUIRED},
+
+       {"Gpe0Block", ACPI_FADT_OFFSET(xgpe0_block),
+        ACPI_FADT_OFFSET(gpe0_block),
+        ACPI_FADT_OFFSET(gpe0_block_length), ACPI_FADT_SEPARATE_LENGTH},
+
+       {"Gpe1Block", ACPI_FADT_OFFSET(xgpe1_block),
+        ACPI_FADT_OFFSET(gpe1_block),
+        ACPI_FADT_OFFSET(gpe1_block_length), ACPI_FADT_SEPARATE_LENGTH}
+};
+
+#define ACPI_FADT_INFO_ENTRIES        (sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info))
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_init_generic_address
+ *
+ * PARAMETERS:  generic_address     - GAS struct to be initialized
+ *              bit_width           - Width of this register
+ *              Address             - Address of the register
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Initialize a Generic Address Structure (GAS)
+ *              See the ACPI specification for a full description and
+ *              definition of this structure.
+ *
+ ******************************************************************************/
+
+static void inline
+acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
+                            u8 bit_width, u64 address)
+{
+
+       /*
+        * The 64-bit Address field is non-aligned in the byte packed
+        * GAS struct.
+        */
+       ACPI_MOVE_64_TO_64(&generic_address->address, &address);
+
+       /* All other fields are byte-wide */
+
+       generic_address->space_id = ACPI_ADR_SPACE_SYSTEM_IO;
+       generic_address->bit_width = bit_width;
+       generic_address->bit_offset = 0;
+       generic_address->access_width = 0;
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_parse_fadt
+ *
+ * PARAMETERS:  table_index         - Index for the FADT
+ *              Flags               - Flags
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
+ *              (FADT contains the addresses of the DSDT and FACS)
+ *
+ ******************************************************************************/
+
+void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags)
+{
+       u32 length;
+       struct acpi_table_header *table;
+
+       /*
+        * The FADT has multiple versions with different lengths,
+        * and it contains pointers to both the DSDT and FACS tables.
+        *
+        * Get a local copy of the FADT and convert it to a common format
+        * Map entire FADT, assumed to be smaller than one page.
+        */
+       length = acpi_gbl_root_table_list.tables[table_index].length;
+
+       table =
+           acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index].
+                              address, length);
+       if (!table) {
+               return;
+       }
+
+       /*
+        * Validate the FADT checksum before we copy the table. Ignore
+        * checksum error as we want to try to get the DSDT and FACS.
+        */
+       (void)acpi_tb_verify_checksum(table, length);
+
+       /* Obtain a local copy of the FADT in common ACPI 2.0+ format */
+
+       acpi_tb_create_local_fadt(table, length);
+
+       /* All done with the real FADT, unmap it */
+
+       acpi_os_unmap_memory(table, length);
+
+       /* Obtain the DSDT and FACS tables via their addresses within the FADT */
+
+       acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
+                             flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
+
+       acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs,
+                             flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_create_local_fadt
+ *
+ * PARAMETERS:  Table               - Pointer to BIOS FADT
+ *              Length              - Length of the table
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
+ *              Performs validation on some important FADT fields.
+ *
+ ******************************************************************************/
+
+void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
+{
+
+       /*
+        * Check if the FADT is larger than what we know about (ACPI 2.0 version).
+        * Truncate the table, but make some noise.
+        */
+       if (length > sizeof(struct acpi_table_fadt)) {
+               ACPI_WARNING((AE_INFO,
+                             "FADT (revision %u) is longer than ACPI 2.0 version, truncating length 0x%X to 0x%zX",
+                             table->revision, (unsigned)length,
+                             sizeof(struct acpi_table_fadt)));
+       }
+
+       /* Copy the entire FADT locally. Zero first for tb_convert_fadt */
+
+       ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
+
+       ACPI_MEMCPY(&acpi_gbl_FADT, table,
+                   ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
+
+       /*
+        * 1) Convert the local copy of the FADT to the common internal format
+        * 2) Validate some of the important values within the FADT
+        */
+       acpi_tb_convert_fadt();
+       acpi_tb_validate_fadt();
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_convert_fadt
+ *
+ * PARAMETERS:  None, uses acpi_gbl_FADT
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Converts all versions of the FADT to a common internal format.
+ *              -> Expand all 32-bit addresses to 64-bit.
+ *
+ * NOTE:        acpi_gbl_FADT must be of size (struct acpi_table_fadt),
+ *              and must contain a copy of the actual FADT.
+ *
+ * ACPICA will use the "X" fields of the FADT for all addresses.
+ *
+ * "X" fields are optional extensions to the original V1.0 fields. Even if
+ * they are present in the structure, they can be optionally not used by
+ * setting them to zero. Therefore, we must selectively expand V1.0 fields
+ * if the corresponding X field is zero.
+ *
+ * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding
+ * "X" fields.
+ *
+ * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by
+ * expanding the corresponding ACPI 1.0 field.
+ *
+ ******************************************************************************/
+
+static void acpi_tb_convert_fadt(void)
+{
+       u8 pm1_register_length;
+       struct acpi_generic_address *target;
+       acpi_native_uint i;
+
+       /* Update the local FADT table header length */
+
+       acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
+
+       /* Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary */
+
+       if (!acpi_gbl_FADT.Xfacs) {
+               acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
+       }
+
+       if (!acpi_gbl_FADT.Xdsdt) {
+               acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
+       }
+
+       /*
+        * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address
+        * structures as necessary.
+        */
+       for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
+               target =
+                   ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
+                                fadt_info_table[i].target);
+
+               /* Expand only if the X target is null */
+
+               if (!target->address) {
+                       acpi_tb_init_generic_address(target,
+                                                    *ACPI_ADD_PTR(u8,
+                                                                  &acpi_gbl_FADT,
+                                                                  fadt_info_table
+                                                                  [i].length),
+                                                    (u64) * ACPI_ADD_PTR(u32,
+                                                                         &acpi_gbl_FADT,
+                                                                         fadt_info_table
+                                                                         [i].
+                                                                         source));
+               }
+       }
+
+       /*
+        * Calculate separate GAS structs for the PM1 Enable registers.
+        * These addresses do not appear (directly) in the FADT, so it is
+        * useful to calculate them once, here.
+        *
+        * The PM event blocks are split into two register blocks, first is the
+        * PM Status Register block, followed immediately by the PM Enable Register
+        * block. Each is of length (pm1_event_length/2)
+        */
+       pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
+
+       /* The PM1A register block is required */
+
+       acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
+                                    pm1_register_length,
+                                    (acpi_gbl_FADT.xpm1a_event_block.address +
+                                     pm1_register_length));
+       /* Don't forget to copy space_id of the GAS */
+       acpi_gbl_xpm1a_enable.space_id = acpi_gbl_FADT.xpm1a_event_block.space_id;
+
+       /* The PM1B register block is optional, ignore if not present */
+
+       if (acpi_gbl_FADT.xpm1b_event_block.address) {
+               acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
+                                            pm1_register_length,
+                                            (acpi_gbl_FADT.xpm1b_event_block.
+                                             address + pm1_register_length));
+               /* Don't forget to copy space_id of the GAS */
+               acpi_gbl_xpm1b_enable.space_id = acpi_gbl_FADT.xpm1a_event_block.space_id;
+
+       }
+}
+
+/******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_validate_fadt
+ *
+ * PARAMETERS:  Table           - Pointer to the FADT to be validated
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Validate various important fields within the FADT. If a problem
+ *              is found, issue a message, but no status is returned.
+ *              Used by both the table manager and the disassembler.
+ *
+ * Possible additional checks:
+ * (acpi_gbl_FADT.pm1_event_length >= 4)
+ * (acpi_gbl_FADT.pm1_control_length >= 2)
+ * (acpi_gbl_FADT.pm_timer_length >= 4)
+ * Gpe block lengths must be multiple of 2
+ *
+ ******************************************************************************/
+
+static void acpi_tb_validate_fadt(void)
+{
+       u32 *address32;
+       struct acpi_generic_address *address64;
+       u8 length;
+       acpi_native_uint i;
+
+       /* Examine all of the 64-bit extended address fields (X fields) */
+
+       for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
+
+               /* Generate pointers to the 32-bit and 64-bit addresses and get the length */
+
+               address64 =
+                   ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
+                                fadt_info_table[i].target);
+               address32 =
+                   ACPI_ADD_PTR(u32, &acpi_gbl_FADT,
+                                fadt_info_table[i].source);
+               length =
+                   *ACPI_ADD_PTR(u8, &acpi_gbl_FADT,
+                                 fadt_info_table[i].length);
+
+               if (fadt_info_table[i].type & ACPI_FADT_REQUIRED) {
+                       /*
+                        * Field is required (Pm1a_event, Pm1a_control, pm_timer).
+                        * Both the address and length must be non-zero.
+                        */
+                       if (!address64->address || !length) {
+                               ACPI_ERROR((AE_INFO,
+                                           "Required field \"%s\" has zero address and/or length: %8.8X%8.8X/%X",
+                                           fadt_info_table[i].name,
+                                           ACPI_FORMAT_UINT64(address64->
+                                                              address),
+                                           length));
+                       }
+               } else if (fadt_info_table[i].type & ACPI_FADT_SEPARATE_LENGTH) {
+                       /*
+                        * Field is optional (PM2Control, GPE0, GPE1) AND has its own
+                        * length field. If present, both the address and length must be valid.
+                        */
+                       if ((address64->address && !length)
+                           || (!address64->address && length)) {
+                               ACPI_WARNING((AE_INFO,
+                                             "Optional field \"%s\" has zero address or length: %8.8X%8.8X/%X",
+                                             fadt_info_table[i].name,
+                                             ACPI_FORMAT_UINT64(address64->
+                                                                address),
+                                             length));
+                       }
+               }
+
+               /* If both 32- and 64-bit addresses are valid (non-zero), they must match */
+
+               if (address64->address && *address32 &&
+                   (address64->address != (u64) * address32)) {
+                       ACPI_ERROR((AE_INFO,
+                                   "32/64X address mismatch in \"%s\": [%8.8X] [%8.8X%8.8X], using 64X",
+                                   fadt_info_table[i].name, *address32,
+                                   ACPI_FORMAT_UINT64(address64->address)));
+               }
+       }
+}
diff --git a/drivers/acpi/tables/tbfind.c b/drivers/acpi/tables/tbfind.c
new file mode 100644 (file)
index 0000000..058c064
--- /dev/null
@@ -0,0 +1,126 @@
+/******************************************************************************
+ *
+ * Module Name: tbfind   - find table
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2007, R. Byron Moore
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <acpi/acpi.h>
+#include <acpi/actables.h>
+
+#define _COMPONENT          ACPI_TABLES
+ACPI_MODULE_NAME("tbfind")
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_find_table
+ *
+ * PARAMETERS:  Signature           - String with ACPI table signature
+ *              oem_id              - String with the table OEM ID
+ *              oem_table_id        - String with the OEM Table ID
+ *              table_index         - Where the table index is returned
+ *
+ * RETURN:      Status and table index
+ *
+ * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
+ *              Signature, OEM ID and OEM Table ID. Returns an index that can
+ *              be used to get the table header or entire table.
+ *
+ ******************************************************************************/
+acpi_status
+acpi_tb_find_table(char *signature,
+                  char *oem_id,
+                  char *oem_table_id, acpi_native_uint * table_index)
+{
+       acpi_native_uint i;
+       acpi_status status;
+
+       ACPI_FUNCTION_TRACE(tb_find_table);
+
+       for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
+               if (ACPI_MEMCMP(&(acpi_gbl_root_table_list.tables[i].signature),
+                               signature, ACPI_NAME_SIZE)) {
+
+                       /* Not the requested table */
+
+                       continue;
+               }
+
+               /* Table with matching signature has been found */
+
+               if (!acpi_gbl_root_table_list.tables[i].pointer) {
+
+                       /* Table is not currently mapped, map it */
+
+                       status =
+                           acpi_tb_verify_table(&acpi_gbl_root_table_list.
+                                                tables[i]);
+                       if (ACPI_FAILURE(status)) {
+                               return_ACPI_STATUS(status);
+                       }
+
+                       if (!acpi_gbl_root_table_list.tables[i].pointer) {
+                               continue;
+                       }
+               }
+
+               /* Check for table match on all IDs */
+
+               if (!ACPI_MEMCMP
+                   (acpi_gbl_root_table_list.tables[i].pointer->signature,
+                    signature, ACPI_NAME_SIZE) && (!oem_id[0]
+                                                   ||
+                                                   !ACPI_MEMCMP
+                                                   (acpi_gbl_root_table_list.
+                                                    tables[i].pointer->oem_id,
+                                                    oem_id, ACPI_OEM_ID_SIZE))
+                   && (!oem_table_id[0]
+                       || !ACPI_MEMCMP(acpi_gbl_root_table_list.tables[i].
+                                       pointer->oem_table_id, oem_table_id,
+                                       ACPI_OEM_TABLE_ID_SIZE))) {
+                       *table_index = i;
+
+                       ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
+                                         "Found table [%4.4s]\n", signature));
+                       return_ACPI_STATUS(AE_OK);
+               }
+       }
+
+       return_ACPI_STATUS(AE_NOT_FOUND);
+}
diff --git a/drivers/acpi/tables/tbget.c b/drivers/acpi/tables/tbget.c
deleted file mode 100644 (file)
index 11e2d44..0000000
+++ /dev/null
@@ -1,471 +0,0 @@
-/******************************************************************************
- *
- * Module Name: tbget - ACPI Table get* routines
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2006, R. Byron Moore
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include <acpi/acpi.h>
-#include <acpi/actables.h>
-
-#define _COMPONENT          ACPI_TABLES
-ACPI_MODULE_NAME("tbget")
-
-/* Local prototypes */
-static acpi_status
-acpi_tb_get_this_table(struct acpi_pointer *address,
-                      struct acpi_table_header *header,
-                      struct acpi_table_desc *table_info);
-
-static acpi_status
-acpi_tb_table_override(struct acpi_table_header *header,
-                      struct acpi_table_desc *table_info);
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_table
- *
- * PARAMETERS:  Address             - Address of table to retrieve.  Can be
- *                                    Logical or Physical
- *              table_info          - Where table info is returned
- *
- * RETURN:      None
- *
- * DESCRIPTION: Get entire table of unknown size.
- *
- ******************************************************************************/
-
-acpi_status
-acpi_tb_get_table(struct acpi_pointer *address,
-                 struct acpi_table_desc *table_info)
-{
-       acpi_status status;
-       struct acpi_table_header header;
-
-       ACPI_FUNCTION_TRACE(tb_get_table);
-
-       /* Get the header in order to get signature and table size */
-
-       status = acpi_tb_get_table_header(address, &header);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /* Get the entire table */
-
-       status = acpi_tb_get_table_body(address, &header, table_info);
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status,
-                               "Could not get ACPI table (size %X)",
-                               header.length));
-               return_ACPI_STATUS(status);
-       }
-
-       return_ACPI_STATUS(AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_table_header
- *
- * PARAMETERS:  Address             - Address of table to retrieve.  Can be
- *                                    Logical or Physical
- *              return_header       - Where the table header is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get an ACPI table header.  Works in both physical or virtual
- *              addressing mode.  Works with both physical or logical pointers.
- *              Table is either copied or mapped, depending on the pointer
- *              type and mode of the processor.
- *
- ******************************************************************************/
-
-acpi_status
-acpi_tb_get_table_header(struct acpi_pointer *address,
-                        struct acpi_table_header *return_header)
-{
-       acpi_status status = AE_OK;
-       struct acpi_table_header *header = NULL;
-
-       ACPI_FUNCTION_TRACE(tb_get_table_header);
-
-       /*
-        * Flags contains the current processor mode (Virtual or Physical
-        * addressing) The pointer_type is either Logical or Physical
-        */
-       switch (address->pointer_type) {
-       case ACPI_PHYSMODE_PHYSPTR:
-       case ACPI_LOGMODE_LOGPTR:
-
-               /* Pointer matches processor mode, copy the header */
-
-               ACPI_MEMCPY(return_header, address->pointer.logical,
-                           sizeof(struct acpi_table_header));
-               break;
-
-       case ACPI_LOGMODE_PHYSPTR:
-
-               /* Create a logical address for the physical pointer */
-
-               status = acpi_os_map_memory(address->pointer.physical,
-                                           sizeof(struct acpi_table_header),
-                                           (void *)&header);
-               if (ACPI_FAILURE(status)) {
-                       ACPI_ERROR((AE_INFO,
-                                   "Could not map memory at %8.8X%8.8X for table header",
-                                   ACPI_FORMAT_UINT64(address->pointer.
-                                                      physical)));
-                       return_ACPI_STATUS(status);
-               }
-
-               /* Copy header and delete mapping */
-
-               ACPI_MEMCPY(return_header, header,
-                           sizeof(struct acpi_table_header));
-               acpi_os_unmap_memory(header, sizeof(struct acpi_table_header));
-               break;
-
-       default:
-
-               ACPI_ERROR((AE_INFO, "Invalid address flags %X",
-                           address->pointer_type));
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-       }
-
-       ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Table Signature: [%4.4s]\n",
-                         return_header->signature));
-
-       return_ACPI_STATUS(AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_table_body
- *
- * PARAMETERS:  Address             - Address of table to retrieve.  Can be
- *                                    Logical or Physical
- *              Header              - Header of the table to retrieve
- *              table_info          - Where the table info is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get an entire ACPI table with support to allow the host OS to
- *              replace the table with a newer version (table override.)
- *              Works in both physical or virtual
- *              addressing mode.  Works with both physical or logical pointers.
- *              Table is either copied or mapped, depending on the pointer
- *              type and mode of the processor.
- *
- ******************************************************************************/
-
-acpi_status
-acpi_tb_get_table_body(struct acpi_pointer *address,
-                      struct acpi_table_header *header,
-                      struct acpi_table_desc *table_info)
-{
-       acpi_status status;
-
-       ACPI_FUNCTION_TRACE(tb_get_table_body);
-
-       if (!table_info || !address) {
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-       }
-
-       /* Attempt table override. */
-
-       status = acpi_tb_table_override(header, table_info);
-       if (ACPI_SUCCESS(status)) {
-
-               /* Table was overridden by the host OS */
-
-               return_ACPI_STATUS(status);
-       }
-
-       /* No override, get the original table */
-
-       status = acpi_tb_get_this_table(address, header, table_info);
-       return_ACPI_STATUS(status);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_table_override
- *
- * PARAMETERS:  Header              - Pointer to table header
- *              table_info          - Return info if table is overridden
- *
- * RETURN:      None
- *
- * DESCRIPTION: Attempts override of current table with a new one if provided
- *              by the host OS.
- *
- ******************************************************************************/
-
-static acpi_status
-acpi_tb_table_override(struct acpi_table_header *header,
-                      struct acpi_table_desc *table_info)
-{
-       struct acpi_table_header *new_table;
-       acpi_status status;
-       struct acpi_pointer address;
-
-       ACPI_FUNCTION_TRACE(tb_table_override);
-
-       /*
-        * The OSL will examine the header and decide whether to override this
-        * table.  If it decides to override, a table will be returned in new_table,
-        * which we will then copy.
-        */
-       status = acpi_os_table_override(header, &new_table);
-       if (ACPI_FAILURE(status)) {
-
-               /* Some severe error from the OSL, but we basically ignore it */
-
-               ACPI_EXCEPTION((AE_INFO, status,
-                               "Could not override ACPI table"));
-               return_ACPI_STATUS(status);
-       }
-
-       if (!new_table) {
-
-               /* No table override */
-
-               return_ACPI_STATUS(AE_NO_ACPI_TABLES);
-       }
-
-       /*
-        * We have a new table to override the old one.  Get a copy of
-        * the new one.  We know that the new table has a logical pointer.
-        */
-       address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
-       address.pointer.logical = new_table;
-
-       status = acpi_tb_get_this_table(&address, new_table, table_info);
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status, "Could not copy ACPI table"));
-               return_ACPI_STATUS(status);
-       }
-
-       /* Copy the table info */
-
-       ACPI_INFO((AE_INFO, "Table [%4.4s] replaced by host OS",
-                  table_info->pointer->signature));
-
-       return_ACPI_STATUS(AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_this_table
- *
- * PARAMETERS:  Address             - Address of table to retrieve.  Can be
- *                                    Logical or Physical
- *              Header              - Header of the table to retrieve
- *              table_info          - Where the table info is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Get an entire ACPI table.  Works in both physical or virtual
- *              addressing mode.  Works with both physical or logical pointers.
- *              Table is either copied or mapped, depending on the pointer
- *              type and mode of the processor.
- *
- ******************************************************************************/
-
-static acpi_status
-acpi_tb_get_this_table(struct acpi_pointer *address,
-                      struct acpi_table_header *header,
-                      struct acpi_table_desc *table_info)
-{
-       struct acpi_table_header *full_table = NULL;
-       u8 allocation;
-       acpi_status status = AE_OK;
-
-       ACPI_FUNCTION_TRACE(tb_get_this_table);
-
-       /* Validate minimum length */
-
-       if (header->length < sizeof(struct acpi_table_header)) {
-               ACPI_ERROR((AE_INFO,
-                           "Table length (%X) is smaller than minimum (%zX)",
-                           header->length, sizeof(struct acpi_table_header)));
-
-               return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
-       }
-
-       /*
-        * Flags contains the current processor mode (Virtual or Physical
-        * addressing) The pointer_type is either Logical or Physical
-        */
-       switch (address->pointer_type) {
-       case ACPI_PHYSMODE_PHYSPTR:
-       case ACPI_LOGMODE_LOGPTR:
-
-               /* Pointer matches processor mode, copy the table to a new buffer */
-
-               full_table = ACPI_ALLOCATE(header->length);
-               if (!full_table) {
-                       ACPI_ERROR((AE_INFO,
-                                   "Could not allocate table memory for [%4.4s] length %X",
-                                   header->signature, header->length));
-                       return_ACPI_STATUS(AE_NO_MEMORY);
-               }
-
-               /* Copy the entire table (including header) to the local buffer */
-
-               ACPI_MEMCPY(full_table, address->pointer.logical,
-                           header->length);
-
-               /* Save allocation type */
-
-               allocation = ACPI_MEM_ALLOCATED;
-               break;
-
-       case ACPI_LOGMODE_PHYSPTR:
-
-               /*
-                * Just map the table's physical memory
-                * into our address space.
-                */
-               status = acpi_os_map_memory(address->pointer.physical,
-                                           (acpi_size) header->length,
-                                           ACPI_CAST_PTR(void, &full_table));
-               if (ACPI_FAILURE(status)) {
-                       ACPI_ERROR((AE_INFO,
-                                   "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X",
-                                   header->signature,
-                                   ACPI_FORMAT_UINT64(address->pointer.
-                                                      physical),
-                                   header->length));
-                       return (status);
-               }
-
-               /* Save allocation type */
-
-               allocation = ACPI_MEM_MAPPED;
-               break;
-
-       default:
-
-               ACPI_ERROR((AE_INFO, "Invalid address flags %X",
-                           address->pointer_type));
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-       }
-
-       /*
-        * Validate checksum for _most_ tables,
-        * even the ones whose signature we don't recognize
-        */
-       if (table_info->type != ACPI_TABLE_ID_FACS) {
-               status = acpi_tb_verify_table_checksum(full_table);
-
-#if (!ACPI_CHECKSUM_ABORT)
-               if (ACPI_FAILURE(status)) {
-
-                       /* Ignore the error if configuration says so */
-
-                       status = AE_OK;
-               }
-#endif
-       }
-
-       /* Return values */
-
-       table_info->pointer = full_table;
-       table_info->length = (acpi_size) header->length;
-       table_info->allocation = allocation;
-
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                         "Found table [%4.4s] at %8.8X%8.8X, mapped/copied to %p\n",
-                         full_table->signature,
-                         ACPI_FORMAT_UINT64(address->pointer.physical),
-                         full_table));
-
-       return_ACPI_STATUS(status);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_table_ptr
- *
- * PARAMETERS:  table_type      - one of the defined table types
- *              Instance        - Which table of this type
- *              return_table    - pointer to location to place the pointer for
- *                                return
- *
- * RETURN:      Status
- *
- * DESCRIPTION: This function is called to get the pointer to an ACPI table.
- *
- ******************************************************************************/
-
-acpi_status
-acpi_tb_get_table_ptr(acpi_table_type table_type,
-                     u32 instance, struct acpi_table_header **return_table)
-{
-       struct acpi_table_desc *table_desc;
-       u32 i;
-
-       ACPI_FUNCTION_TRACE(tb_get_table_ptr);
-
-       if (table_type > ACPI_TABLE_ID_MAX) {
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-       }
-
-       /* Check for instance out of range of the current table count */
-
-       if (instance > acpi_gbl_table_lists[table_type].count) {
-               return_ACPI_STATUS(AE_NOT_EXIST);
-       }
-
-       /*
-        * Walk the list to get the desired table
-        * Note: Instance is one-based
-        */
-       table_desc = acpi_gbl_table_lists[table_type].next;
-       for (i = 1; i < instance; i++) {
-               table_desc = table_desc->next;
-       }
-
-       /* We are now pointing to the requested table's descriptor */
-
-       *return_table = table_desc->pointer;
-       return_ACPI_STATUS(AE_OK);
-}
diff --git a/drivers/acpi/tables/tbgetall.c b/drivers/acpi/tables/tbgetall.c
deleted file mode 100644 (file)
index ad98211..0000000
+++ /dev/null
@@ -1,311 +0,0 @@
-/******************************************************************************
- *
- * Module Name: tbgetall - Get all required ACPI tables
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2006, R. Byron Moore
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include <acpi/acpi.h>
-#include <acpi/actables.h>
-
-#define _COMPONENT          ACPI_TABLES
-ACPI_MODULE_NAME("tbgetall")
-
-/* Local prototypes */
-static acpi_status
-acpi_tb_get_primary_table(struct acpi_pointer *address,
-                         struct acpi_table_desc *table_info);
-
-static acpi_status
-acpi_tb_get_secondary_table(struct acpi_pointer *address,
-                           acpi_string signature,
-                           struct acpi_table_desc *table_info);
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_primary_table
- *
- * PARAMETERS:  Address             - Physical address of table to retrieve
- *              *table_info         - Where the table info is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Maps the physical address of table into a logical address
- *
- ******************************************************************************/
-
-static acpi_status
-acpi_tb_get_primary_table(struct acpi_pointer *address,
-                         struct acpi_table_desc *table_info)
-{
-       acpi_status status;
-       struct acpi_table_header header;
-
-       ACPI_FUNCTION_TRACE(tb_get_primary_table);
-
-       /* Ignore a NULL address in the RSDT */
-
-       if (!address->pointer.value) {
-               return_ACPI_STATUS(AE_OK);
-       }
-
-       /* Get the header in order to get signature and table size */
-
-       status = acpi_tb_get_table_header(address, &header);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /* Clear the table_info */
-
-       ACPI_MEMSET(table_info, 0, sizeof(struct acpi_table_desc));
-
-       /*
-        * Check the table signature and make sure it is recognized.
-        * Also checks the header checksum
-        */
-       table_info->pointer = &header;
-       status = acpi_tb_recognize_table(table_info, ACPI_TABLE_PRIMARY);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /* Get the entire table */
-
-       status = acpi_tb_get_table_body(address, &header, table_info);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /* Install the table */
-
-       status = acpi_tb_install_table(table_info);
-       return_ACPI_STATUS(status);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_secondary_table
- *
- * PARAMETERS:  Address             - Physical address of table to retrieve
- *              *table_info         - Where the table info is returned
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Maps the physical address of table into a logical address
- *
- ******************************************************************************/
-
-static acpi_status
-acpi_tb_get_secondary_table(struct acpi_pointer *address,
-                           acpi_string signature,
-                           struct acpi_table_desc *table_info)
-{
-       acpi_status status;
-       struct acpi_table_header header;
-
-       ACPI_FUNCTION_TRACE_STR(tb_get_secondary_table, signature);
-
-       /* Get the header in order to match the signature */
-
-       status = acpi_tb_get_table_header(address, &header);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /* Signature must match request */
-
-       if (!ACPI_COMPARE_NAME(header.signature, signature)) {
-               ACPI_ERROR((AE_INFO,
-                           "Incorrect table signature - wanted [%s] found [%4.4s]",
-                           signature, header.signature));
-               return_ACPI_STATUS(AE_BAD_SIGNATURE);
-       }
-
-       /*
-        * Check the table signature and make sure it is recognized.
-        * Also checks the header checksum
-        */
-       table_info->pointer = &header;
-       status = acpi_tb_recognize_table(table_info, ACPI_TABLE_SECONDARY);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /* Get the entire table */
-
-       status = acpi_tb_get_table_body(address, &header, table_info);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /* Install the table */
-
-       status = acpi_tb_install_table(table_info);
-       return_ACPI_STATUS(status);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_required_tables
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Load and validate tables other than the RSDT.  The RSDT must
- *              already be loaded and validated.
- *
- *              Get the minimum set of ACPI tables, namely:
- *
- *              1) FADT (via RSDT in loop below)
- *              2) FACS (via FADT)
- *              3) DSDT (via FADT)
- *
- ******************************************************************************/
-
-acpi_status acpi_tb_get_required_tables(void)
-{
-       acpi_status status = AE_OK;
-       u32 i;
-       struct acpi_table_desc table_info;
-       struct acpi_pointer address;
-
-       ACPI_FUNCTION_TRACE(tb_get_required_tables);
-
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%d ACPI tables in RSDT\n",
-                         acpi_gbl_rsdt_table_count));
-
-       address.pointer_type = acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
-
-       /*
-        * Loop through all table pointers found in RSDT.
-        * This will NOT include the FACS and DSDT - we must get
-        * them after the loop.
-        *
-        * The only tables we are interested in getting here is the FADT and
-        * any SSDTs.
-        */
-       for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
-
-               /* Get the table address from the common internal XSDT */
-
-               address.pointer.value = acpi_gbl_XSDT->table_offset_entry[i];
-
-               /*
-                * Get the tables needed by this subsystem (FADT and any SSDTs).
-                * NOTE: All other tables are completely ignored at this time.
-                */
-               status = acpi_tb_get_primary_table(&address, &table_info);
-               if ((status != AE_OK) && (status != AE_TABLE_NOT_SUPPORTED)) {
-                       ACPI_WARNING((AE_INFO,
-                                     "%s, while getting table at %8.8X%8.8X",
-                                     acpi_format_exception(status),
-                                     ACPI_FORMAT_UINT64(address.pointer.
-                                                        value)));
-               }
-       }
-
-       /* We must have a FADT to continue */
-
-       if (!acpi_gbl_FADT) {
-               ACPI_ERROR((AE_INFO, "No FADT present in RSDT/XSDT"));
-               return_ACPI_STATUS(AE_NO_ACPI_TABLES);
-       }
-
-       /*
-        * Convert the FADT to a common format.  This allows earlier revisions of
-        * the table to coexist with newer versions, using common access code.
-        */
-       status = acpi_tb_convert_table_fadt();
-       if (ACPI_FAILURE(status)) {
-               ACPI_ERROR((AE_INFO,
-                           "Could not convert FADT to internal common format"));
-               return_ACPI_STATUS(status);
-       }
-
-       /* Get the FACS (Pointed to by the FADT) */
-
-       address.pointer.value = acpi_gbl_FADT->xfirmware_ctrl;
-
-       status = acpi_tb_get_secondary_table(&address, FACS_SIG, &table_info);
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status,
-                               "Could not get/install the FACS"));
-               return_ACPI_STATUS(status);
-       }
-
-       /*
-        * Create the common FACS pointer table
-        * (Contains pointers to the original table)
-        */
-       status = acpi_tb_build_common_facs(&table_info);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /* Get/install the DSDT (Pointed to by the FADT) */
-
-       address.pointer.value = acpi_gbl_FADT->Xdsdt;
-
-       status = acpi_tb_get_secondary_table(&address, DSDT_SIG, &table_info);
-       if (ACPI_FAILURE(status)) {
-               ACPI_ERROR((AE_INFO, "Could not get/install the DSDT"));
-               return_ACPI_STATUS(status);
-       }
-
-       /* Set Integer Width (32/64) based upon DSDT revision */
-
-       acpi_ut_set_integer_width(acpi_gbl_DSDT->revision);
-
-       /* Dump the entire DSDT */
-
-       ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
-                         "Hex dump of entire DSDT, size %d (0x%X), Integer width = %d\n",
-                         acpi_gbl_DSDT->length, acpi_gbl_DSDT->length,
-                         acpi_gbl_integer_bit_width));
-
-       ACPI_DUMP_BUFFER(ACPI_CAST_PTR(u8, acpi_gbl_DSDT),
-                        acpi_gbl_DSDT->length);
-
-       /* Always delete the RSDP mapping, we are done with it */
-
-       acpi_tb_delete_tables_by_type(ACPI_TABLE_ID_RSDP);
-       return_ACPI_STATUS(status);
-}
index 1668a232fb6754fb3a0d571cf32cb443863cefa0..0e7b121a99ce6b163961a61d16b8952d143ca497 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  */
 
 #include <acpi/acpi.h>
+#include <acpi/acnamesp.h>
 #include <acpi/actables.h>
 
 #define _COMPONENT          ACPI_TABLES
 ACPI_MODULE_NAME("tbinstal")
 
-/* Local prototypes */
-static acpi_status
-acpi_tb_match_signature(char *signature,
-                       struct acpi_table_desc *table_info, u8 search_type);
-
-/*******************************************************************************
+/******************************************************************************
  *
- * FUNCTION:    acpi_tb_match_signature
+ * FUNCTION:    acpi_tb_verify_table
  *
- * PARAMETERS:  Signature           - Table signature to match
- *              table_info          - Return data
- *              search_type         - Table type to match (primary/secondary)
+ * PARAMETERS:  table_desc          - table
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Compare signature against the list of "ACPI-subsystem-owned"
- *              tables (DSDT/FADT/SSDT, etc.) Returns the table_type_iD on match.
+ * DESCRIPTION: this function is called to verify and map table
  *
- ******************************************************************************/
-
-static acpi_status
-acpi_tb_match_signature(char *signature,
-                       struct acpi_table_desc *table_info, u8 search_type)
+ *****************************************************************************/
+acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
 {
-       acpi_native_uint i;
+       acpi_status status = AE_OK;
 
-       ACPI_FUNCTION_TRACE(tb_match_signature);
+       ACPI_FUNCTION_TRACE(tb_verify_table);
 
-       /* Search for a signature match among the known table types */
+       /* Map the table if necessary */
 
-       for (i = 0; i < (ACPI_TABLE_ID_MAX + 1); i++) {
-               if (!(acpi_gbl_table_data[i].flags & search_type)) {
-                       continue;
+       if (!table_desc->pointer) {
+               if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
+                   ACPI_TABLE_ORIGIN_MAPPED) {
+                       table_desc->pointer =
+                           acpi_os_map_memory(table_desc->address,
+                                              table_desc->length);
                }
+               if (!table_desc->pointer) {
+                       return_ACPI_STATUS(AE_NO_MEMORY);
+               }
+       }
 
-               if (!ACPI_STRNCMP(signature, acpi_gbl_table_data[i].signature,
-                                 acpi_gbl_table_data[i].sig_length)) {
-
-                       /* Found a signature match, return index if requested */
+       /* FACS is the odd table, has no standard ACPI header and no checksum */
 
-                       if (table_info) {
-                               table_info->type = (u8) i;
-                       }
+       if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) {
 
-                       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                         "Table [%4.4s] is an ACPI table consumed by the core subsystem\n",
-                                         (char *)acpi_gbl_table_data[i].
-                                         signature));
+               /* Always calculate checksum, ignore bad checksum if requested */
 
-                       return_ACPI_STATUS(AE_OK);
-               }
+               status =
+                   acpi_tb_verify_checksum(table_desc->pointer,
+                                           table_desc->length);
        }
 
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                         "Table [%4.4s] is not an ACPI table consumed by the core subsystem - ignored\n",
-                         (char *)signature));
-
-       return_ACPI_STATUS(AE_TABLE_NOT_SUPPORTED);
+       return_ACPI_STATUS(status);
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_install_table
+ * FUNCTION:    acpi_tb_add_table
  *
- * PARAMETERS:  table_info          - Return value from acpi_tb_get_table_body
+ * PARAMETERS:  table_desc          - Table descriptor
+ *              table_index         - Where the table index is returned
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Install the table into the global data structures.
+ * DESCRIPTION: This function is called to add the ACPI table
  *
  ******************************************************************************/
 
-acpi_status acpi_tb_install_table(struct acpi_table_desc *table_info)
+acpi_status
+acpi_tb_add_table(struct acpi_table_desc *table_desc,
+                 acpi_native_uint * table_index)
 {
-       acpi_status status;
-
-       ACPI_FUNCTION_TRACE(tb_install_table);
+       acpi_native_uint i;
+       acpi_native_uint length;
+       acpi_status status = AE_OK;
 
-       /* Lock tables while installing */
+       ACPI_FUNCTION_TRACE(tb_add_table);
 
-       status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status,
-                               "Could not acquire table mutex"));
-               return_ACPI_STATUS(status);
+       if (!table_desc->pointer) {
+               status = acpi_tb_verify_table(table_desc);
+               if (ACPI_FAILURE(status) || !table_desc->pointer) {
+                       return_ACPI_STATUS(status);
+               }
        }
 
-       /*
-        * Ignore a table that is already installed. For example, some BIOS
-        * ASL code will repeatedly attempt to load the same SSDT.
-        */
-       status = acpi_tb_is_table_installed(table_info);
-       if (ACPI_FAILURE(status)) {
-               goto unlock_and_exit;
+       /* The table must be either an SSDT or a PSDT */
+
+       if ((!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_PSDT))
+           &&
+           (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT)))
+       {
+               ACPI_ERROR((AE_INFO,
+                           "Table has invalid signature [%4.4s], must be SSDT or PSDT",
+                           table_desc->pointer->signature));
+               return_ACPI_STATUS(AE_BAD_SIGNATURE);
        }
 
-       /* Install the table into the global data structure */
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
+
+       /* Check if table is already registered */
+
+       for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
+               if (!acpi_gbl_root_table_list.tables[i].pointer) {
+                       status =
+                           acpi_tb_verify_table(&acpi_gbl_root_table_list.
+                                                tables[i]);
+                       if (ACPI_FAILURE(status)
+                           || !acpi_gbl_root_table_list.tables[i].pointer) {
+                               continue;
+                       }
+               }
+
+               length = ACPI_MIN(table_desc->length,
+                                 acpi_gbl_root_table_list.tables[i].length);
+               if (ACPI_MEMCMP(table_desc->pointer,
+                               acpi_gbl_root_table_list.tables[i].pointer,
+                               length)) {
+                       continue;
+               }
+
+               /* Table is already registered */
+
+               acpi_tb_delete_table(table_desc);
+               *table_index = i;
+               goto release;
+       }
 
-       status = acpi_tb_init_table_descriptor(table_info->type, table_info);
+       /*
+        * Add the table to the global table list
+        */
+       status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
+                                    table_desc->length, table_desc->flags,
+                                    table_index);
        if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status,
-                               "Could not install table [%4.4s]",
-                               table_info->pointer->signature));
+               goto release;
        }
 
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s located at %p\n",
-                         acpi_gbl_table_data[table_info->type].name,
-                         table_info->pointer));
+       acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
 
-      unlock_and_exit:
+      release:
        (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
        return_ACPI_STATUS(status);
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_recognize_table
+ * FUNCTION:    acpi_tb_resize_root_table_list
  *
- * PARAMETERS:  table_info          - Return value from acpi_tb_get_table_body
- *              search_type         - Table type to match (primary/secondary)
+ * PARAMETERS:  None
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Check a table signature for a match against known table types
- *
- * NOTE:  All table pointers are validated as follows:
- *          1) Table pointer must point to valid physical memory
- *          2) Signature must be 4 ASCII chars, even if we don't recognize the
- *             name
- *          3) Table must be readable for length specified in the header
- *          4) Table checksum must be valid (with the exception of the FACS
- *             which has no checksum for some odd reason)
+ * DESCRIPTION: Expand the size of global table array
  *
  ******************************************************************************/
 
-acpi_status
-acpi_tb_recognize_table(struct acpi_table_desc *table_info, u8 search_type)
+acpi_status acpi_tb_resize_root_table_list(void)
 {
-       struct acpi_table_header *table_header;
-       acpi_status status;
+       struct acpi_table_desc *tables;
 
-       ACPI_FUNCTION_TRACE(tb_recognize_table);
+       ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
 
-       /* Ensure that we have a valid table pointer */
+       /* allow_resize flag is a parameter to acpi_initialize_tables */
 
-       table_header = (struct acpi_table_header *)table_info->pointer;
-       if (!table_header) {
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
+       if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
+               ACPI_ERROR((AE_INFO,
+                           "Resize of Root Table Array is not allowed"));
+               return_ACPI_STATUS(AE_SUPPORT);
        }
 
-       /*
-        * We only "recognize" a limited number of ACPI tables -- namely, the
-        * ones that are used by the subsystem (DSDT, FADT, etc.)
-        *
-        * An AE_TABLE_NOT_SUPPORTED means that the table was not recognized.
-        * This can be any one of many valid ACPI tables, it just isn't one of
-        * the tables that is consumed by the core subsystem
-        */
-       status = acpi_tb_match_signature(table_header->signature,
-                                        table_info, search_type);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
+       /* Increase the Table Array size */
+
+       tables = ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list.size +
+                                      ACPI_ROOT_TABLE_SIZE_INCREMENT)
+                                     * sizeof(struct acpi_table_desc));
+       if (!tables) {
+               ACPI_ERROR((AE_INFO,
+                           "Could not allocate new root table array"));
+               return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
-       status = acpi_tb_validate_table_header(table_header);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
+       /* Copy and free the previous table array */
+
+       if (acpi_gbl_root_table_list.tables) {
+               ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
+                           acpi_gbl_root_table_list.size *
+                           sizeof(struct acpi_table_desc));
+
+               if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
+                       ACPI_FREE(acpi_gbl_root_table_list.tables);
+               }
        }
 
-       /* Return the table type and length via the info struct */
+       acpi_gbl_root_table_list.tables = tables;
+       acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
+       acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
 
-       table_info->length = (acpi_size) table_header->length;
-       return_ACPI_STATUS(status);
+       return_ACPI_STATUS(AE_OK);
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_init_table_descriptor
+ * FUNCTION:    acpi_tb_store_table
  *
- * PARAMETERS:  table_type          - The type of the table
- *              table_info          - A table info struct
+ * PARAMETERS:  Address             - Table address
+ *              Table               - Table header
+ *              Length              - Table length
+ *              Flags               - flags
  *
- * RETURN:      None.
+ * RETURN:      Status and table index.
  *
- * DESCRIPTION: Install a table into the global data structs.
+ * DESCRIPTION: Add an ACPI table to the global table list
  *
  ******************************************************************************/
 
 acpi_status
-acpi_tb_init_table_descriptor(acpi_table_type table_type,
-                             struct acpi_table_desc *table_info)
+acpi_tb_store_table(acpi_physical_address address,
+                   struct acpi_table_header *table,
+                   u32 length, u8 flags, acpi_native_uint * table_index)
 {
-       struct acpi_table_list *list_head;
-       struct acpi_table_desc *table_desc;
-       acpi_status status;
-
-       ACPI_FUNCTION_TRACE_U32(tb_init_table_descriptor, table_type);
+       acpi_status status = AE_OK;
 
-       /* Allocate a descriptor for this table */
+       /* Ensure that there is room for the table in the Root Table List */
 
-       table_desc = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_table_desc));
-       if (!table_desc) {
-               return_ACPI_STATUS(AE_NO_MEMORY);
+       if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
+               status = acpi_tb_resize_root_table_list();
+               if (ACPI_FAILURE(status)) {
+                       return (status);
+               }
        }
 
-       /* Get a new owner ID for the table */
+       /* Initialize added table */
+
+       acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
+           address = address;
+       acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
+           pointer = table;
+       acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
+           length;
+       acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
+           owner_id = 0;
+       acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
+           flags;
+
+       ACPI_MOVE_32_TO_32(&
+                          (acpi_gbl_root_table_list.
+                           tables[acpi_gbl_root_table_list.count].signature),
+                          table->signature);
+
+       *table_index = acpi_gbl_root_table_list.count;
+       acpi_gbl_root_table_list.count++;
+       return (status);
+}
 
-       status = acpi_ut_allocate_owner_id(&table_desc->owner_id);
-       if (ACPI_FAILURE(status)) {
-               goto error_exit1;
-       }
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_delete_table
+ *
+ * PARAMETERS:  table_index         - Table index
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Delete one internal ACPI table
+ *
+ ******************************************************************************/
 
-       /* Install the table into the global data structure */
+void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
+{
+       /* Table must be mapped or allocated */
+       if (!table_desc->pointer) {
+               return;
+       }
+       switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
+       case ACPI_TABLE_ORIGIN_MAPPED:
+               acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
+               break;
+       case ACPI_TABLE_ORIGIN_ALLOCATED:
+               ACPI_FREE(table_desc->pointer);
+               break;
+       default:;
+       }
 
-       list_head = &acpi_gbl_table_lists[table_type];
+       table_desc->pointer = NULL;
+}
 
-       /*
-        * Two major types of tables:  1) Only one instance is allowed.  This
-        * includes most ACPI tables such as the DSDT.  2) Multiple instances of
-        * the table are allowed.  This includes SSDT and PSDTs.
-        */
-       if (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags)) {
-               /*
-                * Only one table allowed, and a table has alread been installed
-                * at this location, so return an error.
-                */
-               if (list_head->next) {
-                       status = AE_ALREADY_EXISTS;
-                       goto error_exit2;
-               }
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_terminate
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Delete all internal ACPI tables
+ *
+ ******************************************************************************/
 
-               table_desc->next = list_head->next;
-               list_head->next = table_desc;
+void acpi_tb_terminate(void)
+{
+       acpi_native_uint i;
 
-               if (table_desc->next) {
-                       table_desc->next->prev = table_desc;
-               }
+       ACPI_FUNCTION_TRACE(tb_terminate);
 
-               list_head->count++;
-       } else {
-               /*
-                * Link the new table in to the list of tables of this type.
-                * Insert at the end of the list, order IS IMPORTANT.
-                *
-                * table_desc->Prev & Next are already NULL from calloc()
-                */
-               list_head->count++;
-
-               if (!list_head->next) {
-                       list_head->next = table_desc;
-               } else {
-                       table_desc->next = list_head->next;
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
 
-                       while (table_desc->next->next) {
-                               table_desc->next = table_desc->next->next;
-                       }
+       /* Delete the individual tables */
 
-                       table_desc->next->next = table_desc;
-                       table_desc->prev = table_desc->next;
-                       table_desc->next = NULL;
-               }
+       for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
+               acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
        }
 
-       /* Finish initialization of the table descriptor */
-
-       table_desc->loaded_into_namespace = FALSE;
-       table_desc->type = (u8) table_type;
-       table_desc->pointer = table_info->pointer;
-       table_desc->length = table_info->length;
-       table_desc->allocation = table_info->allocation;
-       table_desc->aml_start = (u8 *) (table_desc->pointer + 1),
-           table_desc->aml_length = (u32)
-           (table_desc->length - (u32) sizeof(struct acpi_table_header));
-
        /*
-        * Set the appropriate global pointer (if there is one) to point to the
-        * newly installed table
+        * Delete the root table array if allocated locally. Array cannot be
+        * mapped, so we don't need to check for that flag.
         */
-       if (acpi_gbl_table_data[table_type].global_ptr) {
-               *(acpi_gbl_table_data[table_type].global_ptr) =
-                   table_info->pointer;
+       if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
+               ACPI_FREE(acpi_gbl_root_table_list.tables);
        }
 
-       /* Return Data */
-
-       table_info->owner_id = table_desc->owner_id;
-       table_info->installed_desc = table_desc;
-       return_ACPI_STATUS(AE_OK);
-
-       /* Error exit with cleanup */
-
-      error_exit2:
-
-       acpi_ut_release_owner_id(&table_desc->owner_id);
+       acpi_gbl_root_table_list.tables = NULL;
+       acpi_gbl_root_table_list.flags = 0;
+       acpi_gbl_root_table_list.count = 0;
 
-      error_exit1:
-
-       ACPI_FREE(table_desc);
-       return_ACPI_STATUS(status);
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
+       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_delete_all_tables
+ * FUNCTION:    acpi_tb_delete_namespace_by_owner
  *
- * PARAMETERS:  None.
+ * PARAMETERS:  table_index         - Table index
  *
- * RETURN:      None.
+ * RETURN:      None
  *
- * DESCRIPTION: Delete all internal ACPI tables
+ * DESCRIPTION: Delete all namespace objects created when this table was loaded.
  *
  ******************************************************************************/
 
-void acpi_tb_delete_all_tables(void)
+void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index)
 {
-       acpi_table_type type;
+       acpi_owner_id owner_id;
 
-       /*
-        * Free memory allocated for ACPI tables
-        * Memory can either be mapped or allocated
-        */
-       for (type = 0; type < (ACPI_TABLE_ID_MAX + 1); type++) {
-               acpi_tb_delete_tables_by_type(type);
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
+       if (table_index < acpi_gbl_root_table_list.count) {
+               owner_id =
+                   acpi_gbl_root_table_list.tables[table_index].owner_id;
+       } else {
+               (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
+               return;
        }
+
+       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
+       acpi_ns_delete_namespace_by_owner(owner_id);
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_delete_tables_by_type
+ * FUNCTION:    acpi_tb_allocate_owner_id
  *
- * PARAMETERS:  Type                - The table type to be deleted
+ * PARAMETERS:  table_index         - Table index
  *
- * RETURN:      None.
+ * RETURN:      Status
  *
- * DESCRIPTION: Delete an internal ACPI table
- *              Locks the ACPI table mutex
+ * DESCRIPTION: Allocates owner_id in table_desc
  *
  ******************************************************************************/
 
-void acpi_tb_delete_tables_by_type(acpi_table_type type)
+acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index)
 {
-       struct acpi_table_desc *table_desc;
-       u32 count;
-       u32 i;
+       acpi_status status = AE_BAD_PARAMETER;
 
-       ACPI_FUNCTION_TRACE_U32(tb_delete_tables_by_type, type);
+       ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
 
-       if (type > ACPI_TABLE_ID_MAX) {
-               return_VOID;
-       }
-
-       if (ACPI_FAILURE(acpi_ut_acquire_mutex(ACPI_MTX_TABLES))) {
-               return;
-       }
-
-       /* Clear the appropriate "typed" global table pointer */
-
-       switch (type) {
-       case ACPI_TABLE_ID_RSDP:
-               acpi_gbl_RSDP = NULL;
-               break;
-
-       case ACPI_TABLE_ID_DSDT:
-               acpi_gbl_DSDT = NULL;
-               break;
-
-       case ACPI_TABLE_ID_FADT:
-               acpi_gbl_FADT = NULL;
-               break;
-
-       case ACPI_TABLE_ID_FACS:
-               acpi_gbl_FACS = NULL;
-               break;
-
-       case ACPI_TABLE_ID_XSDT:
-               acpi_gbl_XSDT = NULL;
-               break;
-
-       case ACPI_TABLE_ID_SSDT:
-       case ACPI_TABLE_ID_PSDT:
-       default:
-               break;
-       }
-
-       /*
-        * Free the table
-        * 1) Get the head of the list
-        */
-       table_desc = acpi_gbl_table_lists[type].next;
-       count = acpi_gbl_table_lists[type].count;
-
-       /*
-        * 2) Walk the entire list, deleting both the allocated tables
-        *    and the table descriptors
-        */
-       for (i = 0; i < count; i++) {
-               table_desc = acpi_tb_uninstall_table(table_desc);
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
+       if (table_index < acpi_gbl_root_table_list.count) {
+               status = acpi_ut_allocate_owner_id
+                   (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
        }
 
        (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
-       return_VOID;
+       return_ACPI_STATUS(status);
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_delete_single_table
+ * FUNCTION:    acpi_tb_release_owner_id
  *
- * PARAMETERS:  table_info          - A table info struct
+ * PARAMETERS:  table_index         - Table index
  *
- * RETURN:      None.
+ * RETURN:      Status
  *
- * DESCRIPTION: Low-level free for a single ACPI table.  Handles cases where
- *              the table was allocated a buffer or was mapped.
+ * DESCRIPTION: Releases owner_id in table_desc
  *
  ******************************************************************************/
 
-void acpi_tb_delete_single_table(struct acpi_table_desc *table_desc)
+acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index)
 {
+       acpi_status status = AE_BAD_PARAMETER;
 
-       /* Must have a valid table descriptor and pointer */
+       ACPI_FUNCTION_TRACE(tb_release_owner_id);
 
-       if ((!table_desc) || (!table_desc->pointer)) {
-               return;
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
+       if (table_index < acpi_gbl_root_table_list.count) {
+               acpi_ut_release_owner_id(&
+                                        (acpi_gbl_root_table_list.
+                                         tables[table_index].owner_id));
+               status = AE_OK;
        }
 
-       /* Valid table, determine type of memory allocation */
-
-       switch (table_desc->allocation) {
-       case ACPI_MEM_NOT_ALLOCATED:
-               break;
-
-       case ACPI_MEM_ALLOCATED:
-
-               ACPI_FREE(table_desc->pointer);
-               break;
-
-       case ACPI_MEM_MAPPED:
-
-               acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
-               break;
-
-       default:
-               break;
-       }
+       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
+       return_ACPI_STATUS(status);
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_uninstall_table
+ * FUNCTION:    acpi_tb_get_owner_id
  *
- * PARAMETERS:  table_info          - A table info struct
+ * PARAMETERS:  table_index         - Table index
+ *              owner_id            - Where the table owner_id is returned
  *
- * RETURN:      Pointer to the next table in the list (of same type)
+ * RETURN:      Status
  *
- * DESCRIPTION: Free the memory associated with an internal ACPI table that
- *              is either installed or has never been installed.
- *              Table mutex should be locked.
+ * DESCRIPTION: returns owner_id for the ACPI table
  *
  ******************************************************************************/
 
-struct acpi_table_desc *acpi_tb_uninstall_table(struct acpi_table_desc
-                                               *table_desc)
+acpi_status
+acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id)
 {
-       struct acpi_table_desc *next_desc;
+       acpi_status status = AE_BAD_PARAMETER;
 
-       ACPI_FUNCTION_TRACE_PTR(tb_uninstall_table, table_desc);
+       ACPI_FUNCTION_TRACE(tb_get_owner_id);
 
-       if (!table_desc) {
-               return_PTR(NULL);
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
+       if (table_index < acpi_gbl_root_table_list.count) {
+               *owner_id =
+                   acpi_gbl_root_table_list.tables[table_index].owner_id;
+               status = AE_OK;
        }
 
-       /* Unlink the descriptor from the doubly linked list */
+       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
+       return_ACPI_STATUS(status);
+}
 
-       if (table_desc->prev) {
-               table_desc->prev->next = table_desc->next;
-       } else {
-               /* Is first on list, update list head */
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_is_table_loaded
+ *
+ * PARAMETERS:  table_index         - Table index
+ *
+ * RETURN:      Table Loaded Flag
+ *
+ ******************************************************************************/
 
-               acpi_gbl_table_lists[table_desc->type].next = table_desc->next;
-       }
+u8 acpi_tb_is_table_loaded(acpi_native_uint table_index)
+{
+       u8 is_loaded = FALSE;
 
-       if (table_desc->next) {
-               table_desc->next->prev = table_desc->prev;
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
+       if (table_index < acpi_gbl_root_table_list.count) {
+               is_loaded = (u8)
+                   (acpi_gbl_root_table_list.tables[table_index].
+                    flags & ACPI_TABLE_IS_LOADED);
        }
 
-       /* Free the memory allocated for the table itself */
-
-       acpi_tb_delete_single_table(table_desc);
-
-       /* Free the owner ID associated with this table */
-
-       acpi_ut_release_owner_id(&table_desc->owner_id);
+       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
+       return (is_loaded);
+}
 
-       /* Free the table descriptor */
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_set_table_loaded_flag
+ *
+ * PARAMETERS:  table_index         - Table index
+ *              is_loaded           - TRUE if table is loaded, FALSE otherwise
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
+ *
+ ******************************************************************************/
 
-       next_desc = table_desc->next;
-       ACPI_FREE(table_desc);
+void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded)
+{
 
-       /* Return pointer to the next descriptor */
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
+       if (table_index < acpi_gbl_root_table_list.count) {
+               if (is_loaded) {
+                       acpi_gbl_root_table_list.tables[table_index].flags |=
+                           ACPI_TABLE_IS_LOADED;
+               } else {
+                       acpi_gbl_root_table_list.tables[table_index].flags &=
+                           ~ACPI_TABLE_IS_LOADED;
+               }
+       }
 
-       return_PTR(next_desc);
+       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
 }
diff --git a/drivers/acpi/tables/tbrsdt.c b/drivers/acpi/tables/tbrsdt.c
deleted file mode 100644 (file)
index 86a5fca..0000000
+++ /dev/null
@@ -1,307 +0,0 @@
-/******************************************************************************
- *
- * Module Name: tbrsdt - ACPI RSDT table utilities
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2006, R. Byron Moore
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#include <acpi/acpi.h>
-#include <acpi/actables.h>
-
-#define _COMPONENT          ACPI_TABLES
-ACPI_MODULE_NAME("tbrsdt")
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_verify_rsdp
- *
- * PARAMETERS:  Address         - RSDP (Pointer to RSDT)
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
- *
- ******************************************************************************/
-acpi_status acpi_tb_verify_rsdp(struct acpi_pointer *address)
-{
-       struct acpi_table_desc table_info;
-       acpi_status status;
-       struct rsdp_descriptor *rsdp;
-
-       ACPI_FUNCTION_TRACE(tb_verify_rsdp);
-
-       switch (address->pointer_type) {
-       case ACPI_LOGICAL_POINTER:
-
-               rsdp = address->pointer.logical;
-               break;
-
-       case ACPI_PHYSICAL_POINTER:
-               /*
-                * Obtain access to the RSDP structure
-                */
-               status = acpi_os_map_memory(address->pointer.physical,
-                                           sizeof(struct rsdp_descriptor),
-                                           ACPI_CAST_PTR(void, &rsdp));
-               if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
-               }
-               break;
-
-       default:
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-       }
-
-       /* Verify RSDP signature and checksum */
-
-       status = acpi_tb_validate_rsdp(rsdp);
-       if (ACPI_FAILURE(status)) {
-               goto cleanup;
-       }
-
-       /* RSDP is ok. Init the table info */
-
-       table_info.pointer = ACPI_CAST_PTR(struct acpi_table_header, rsdp);
-       table_info.length = sizeof(struct rsdp_descriptor);
-
-       if (address->pointer_type == ACPI_PHYSICAL_POINTER) {
-               table_info.allocation = ACPI_MEM_MAPPED;
-       } else {
-               table_info.allocation = ACPI_MEM_NOT_ALLOCATED;
-       }
-
-       /* Save the table pointers and allocation info */
-
-       status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_RSDP, &table_info);
-       if (ACPI_FAILURE(status)) {
-               goto cleanup;
-       }
-
-       /* Save the RSDP in a global for easy access */
-
-       acpi_gbl_RSDP =
-           ACPI_CAST_PTR(struct rsdp_descriptor, table_info.pointer);
-       return_ACPI_STATUS(status);
-
-       /* Error exit */
-      cleanup:
-
-       if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) {
-               acpi_os_unmap_memory(rsdp, sizeof(struct rsdp_descriptor));
-       }
-       return_ACPI_STATUS(status);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_rsdt_address
- *
- * PARAMETERS:  out_address         - Where the address is returned
- *
- * RETURN:      None, Address
- *
- * DESCRIPTION: Extract the address of either the RSDT or XSDT, depending on the
- *              version of the RSDP and whether the XSDT pointer is valid
- *
- ******************************************************************************/
-
-void acpi_tb_get_rsdt_address(struct acpi_pointer *out_address)
-{
-
-       ACPI_FUNCTION_ENTRY();
-
-       out_address->pointer_type =
-           acpi_gbl_table_flags | ACPI_LOGICAL_ADDRESSING;
-
-       /* Use XSDT if it is present */
-
-       if ((acpi_gbl_RSDP->revision >= 2) &&
-           acpi_gbl_RSDP->xsdt_physical_address) {
-               out_address->pointer.value =
-                   acpi_gbl_RSDP->xsdt_physical_address;
-               acpi_gbl_root_table_type = ACPI_TABLE_TYPE_XSDT;
-       } else {
-               /* No XSDT, use the RSDT */
-
-               out_address->pointer.value =
-                   acpi_gbl_RSDP->rsdt_physical_address;
-               acpi_gbl_root_table_type = ACPI_TABLE_TYPE_RSDT;
-       }
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_validate_rsdt
- *
- * PARAMETERS:  table_ptr       - Addressable pointer to the RSDT.
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Validate signature for the RSDT or XSDT
- *
- ******************************************************************************/
-
-acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr)
-{
-       char *signature;
-
-       ACPI_FUNCTION_ENTRY();
-
-       /* Validate minimum length */
-
-       if (table_ptr->length < sizeof(struct acpi_table_header)) {
-               ACPI_ERROR((AE_INFO,
-                           "RSDT/XSDT length (%X) is smaller than minimum (%zX)",
-                           table_ptr->length,
-                           sizeof(struct acpi_table_header)));
-
-               return (AE_INVALID_TABLE_LENGTH);
-       }
-
-       /* Search for appropriate signature, RSDT or XSDT */
-
-       if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
-               signature = RSDT_SIG;
-       } else {
-               signature = XSDT_SIG;
-       }
-
-       if (!ACPI_COMPARE_NAME(table_ptr->signature, signature)) {
-
-               /* Invalid RSDT or XSDT signature */
-
-               ACPI_ERROR((AE_INFO,
-                           "Invalid signature where RSDP indicates RSDT/XSDT should be located. RSDP:"));
-
-               ACPI_DUMP_BUFFER(acpi_gbl_RSDP, 20);
-
-               ACPI_ERROR((AE_INFO,
-                           "RSDT/XSDT signature at %X is invalid",
-                           acpi_gbl_RSDP->rsdt_physical_address));
-
-               if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
-                       ACPI_ERROR((AE_INFO, "Looking for RSDT"));
-               } else {
-                       ACPI_ERROR((AE_INFO, "Looking for XSDT"));
-               }
-
-               ACPI_DUMP_BUFFER(ACPI_CAST_PTR(char, table_ptr), 48);
-               return (AE_BAD_SIGNATURE);
-       }
-
-       return (AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_get_table_rsdt
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Load and validate the RSDP (ptr) and RSDT (table)
- *
- ******************************************************************************/
-
-acpi_status acpi_tb_get_table_rsdt(void)
-{
-       struct acpi_table_desc table_info;
-       acpi_status status;
-       struct acpi_pointer address;
-
-       ACPI_FUNCTION_TRACE(tb_get_table_rsdt);
-
-       /* Get the RSDT/XSDT via the RSDP */
-
-       acpi_tb_get_rsdt_address(&address);
-
-       table_info.type = ACPI_TABLE_ID_XSDT;
-       status = acpi_tb_get_table(&address, &table_info);
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status,
-                               "Could not get the RSDT/XSDT"));
-               return_ACPI_STATUS(status);
-       }
-
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                         "RSDP located at %p, points to RSDT physical=%8.8X%8.8X\n",
-                         acpi_gbl_RSDP,
-                         ACPI_FORMAT_UINT64(address.pointer.value)));
-
-       /* Check the RSDT or XSDT signature */
-
-       status = acpi_tb_validate_rsdt(table_info.pointer);
-       if (ACPI_FAILURE(status)) {
-               goto error_cleanup;
-       }
-
-       /* Get the number of tables defined in the RSDT or XSDT */
-
-       acpi_gbl_rsdt_table_count = acpi_tb_get_table_count(acpi_gbl_RSDP,
-                                                           table_info.pointer);
-
-       /* Convert and/or copy to an XSDT structure */
-
-       status = acpi_tb_convert_to_xsdt(&table_info);
-       if (ACPI_FAILURE(status)) {
-               goto error_cleanup;
-       }
-
-       /* Save the table pointers and allocation info */
-
-       status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_XSDT, &table_info);
-       if (ACPI_FAILURE(status)) {
-               goto error_cleanup;
-       }
-
-       acpi_gbl_XSDT =
-           ACPI_CAST_PTR(struct xsdt_descriptor, table_info.pointer);
-
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT));
-       return_ACPI_STATUS(status);
-
-      error_cleanup:
-
-       /* Free table allocated by acpi_tb_get_table */
-
-       acpi_tb_delete_single_table(&table_info);
-
-       return_ACPI_STATUS(status);
-}
index 209a401801e3aba9ad3715247c9efe0cc58ca59c..1da64b4518c0b390fab3a4a65625ca92b75cf32b 100644 (file)
@@ -1,11 +1,11 @@
 /******************************************************************************
  *
- * Module Name: tbutils - Table manipulation utilities
+ * Module Name: tbutils   - table utilities
  *
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 ACPI_MODULE_NAME("tbutils")
 
 /* Local prototypes */
-#ifdef ACPI_OBSOLETE_FUNCTIONS
-acpi_status
-acpi_tb_handle_to_object(u16 table_id, struct acpi_table_desc **table_desc);
-#endif
+static acpi_physical_address
+acpi_tb_get_root_table_entry(u8 * table_entry,
+                            acpi_native_uint table_entry_size);
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_is_table_installed
- *
- * PARAMETERS:  new_table_desc      - Descriptor for new table being installed
+ * FUNCTION:    acpi_tb_tables_loaded
  *
- * RETURN:      Status - AE_ALREADY_EXISTS if the table is already installed
+ * PARAMETERS:  None
  *
- * DESCRIPTION: Determine if an ACPI table is already installed
+ * RETURN:      TRUE if required ACPI tables are loaded
  *
- * MUTEX:       Table data structures should be locked
+ * DESCRIPTION: Determine if the minimum required ACPI tables are present
+ *              (FADT, FACS, DSDT)
  *
  ******************************************************************************/
 
-acpi_status acpi_tb_is_table_installed(struct acpi_table_desc *new_table_desc)
+u8 acpi_tb_tables_loaded(void)
 {
-       struct acpi_table_desc *table_desc;
-
-       ACPI_FUNCTION_TRACE(tb_is_table_installed);
 
-       /* Get the list descriptor and first table descriptor */
-
-       table_desc = acpi_gbl_table_lists[new_table_desc->type].next;
+       if (acpi_gbl_root_table_list.count >= 3) {
+               return (TRUE);
+       }
 
-       /* Examine all installed tables of this type */
+       return (FALSE);
+}
 
-       while (table_desc) {
-               /*
-                * If the table lengths match, perform a full bytewise compare. This
-                * means that we will allow tables with duplicate oem_table_id(s), as
-                * long as the tables are different in some way.
-                *
-                * Checking if the table has been loaded into the namespace means that
-                * we don't check for duplicate tables during the initial installation
-                * of tables within the RSDT/XSDT.
-                */
-               if ((table_desc->loaded_into_namespace) &&
-                   (table_desc->pointer->length ==
-                    new_table_desc->pointer->length)
-                   &&
-                   (!ACPI_MEMCMP
-                    (table_desc->pointer, new_table_desc->pointer,
-                     new_table_desc->pointer->length))) {
-
-                       /* Match: this table is already installed */
-
-                       ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
-                                         "Table [%4.4s] already installed: Rev %X OemTableId [%8.8s]\n",
-                                         new_table_desc->pointer->signature,
-                                         new_table_desc->pointer->revision,
-                                         new_table_desc->pointer->
-                                         oem_table_id));
-
-                       new_table_desc->owner_id = table_desc->owner_id;
-                       new_table_desc->installed_desc = table_desc;
-
-                       return_ACPI_STATUS(AE_ALREADY_EXISTS);
-               }
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_print_table_header
+ *
+ * PARAMETERS:  Address             - Table physical address
+ *              Header              - Table header
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
+ *
+ ******************************************************************************/
 
-               /* Get next table on the list */
+void
+acpi_tb_print_table_header(acpi_physical_address address,
+                          struct acpi_table_header *header)
+{
 
-               table_desc = table_desc->next;
+       if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
+
+               /* FACS only has signature and length fields of common table header */
+
+               ACPI_INFO((AE_INFO, "%4.4s %08lX, %04X",
+                          header->signature, (unsigned long)address,
+                          header->length));
+       } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
+
+               /* RSDP has no common fields */
+
+               ACPI_INFO((AE_INFO, "RSDP %08lX, %04X (r%d %6.6s)",
+                          (unsigned long)address,
+                          (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
+                           revision >
+                           0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
+                                              header)->length : 20,
+                          ACPI_CAST_PTR(struct acpi_table_rsdp,
+                                        header)->revision,
+                          ACPI_CAST_PTR(struct acpi_table_rsdp,
+                                        header)->oem_id));
+       } else {
+               /* Standard ACPI table with full common header */
+
+               ACPI_INFO((AE_INFO,
+                          "%4.4s %08lX, %04X (r%d %6.6s %8.8s %8X %4.4s %8X)",
+                          header->signature, (unsigned long)address,
+                          header->length, header->revision, header->oem_id,
+                          header->oem_table_id, header->oem_revision,
+                          header->asl_compiler_id,
+                          header->asl_compiler_revision));
        }
-
-       return_ACPI_STATUS(AE_OK);
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_validate_table_header
+ * FUNCTION:    acpi_tb_validate_checksum
  *
- * PARAMETERS:  table_header        - Logical pointer to the table
+ * PARAMETERS:  Table               - ACPI table to verify
+ *              Length              - Length of entire table
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Check an ACPI table header for validity
- *
- * NOTE:  Table pointers are validated as follows:
- *          1) Table pointer must point to valid physical memory
- *          2) Signature must be 4 ASCII chars, even if we don't recognize the
- *             name
- *          3) Table must be readable for length specified in the header
- *          4) Table checksum must be valid (with the exception of the FACS
- *              which has no checksum because it contains variable fields)
+ * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
+ *              exception on bad checksum.
  *
  ******************************************************************************/
 
-acpi_status
-acpi_tb_validate_table_header(struct acpi_table_header *table_header)
+acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
 {
-       acpi_name signature;
-
-       ACPI_FUNCTION_ENTRY();
-
-       /* Verify that this is a valid address */
-
-       if (!acpi_os_readable(table_header, sizeof(struct acpi_table_header))) {
-               ACPI_ERROR((AE_INFO,
-                           "Cannot read table header at %p", table_header));
-
-               return (AE_BAD_ADDRESS);
-       }
+       u8 checksum;
 
-       /* Ensure that the signature is 4 ASCII characters */
+       /* Compute the checksum on the table */
 
-       ACPI_MOVE_32_TO_32(&signature, table_header->signature);
-       if (!acpi_ut_valid_acpi_name(signature)) {
-               ACPI_ERROR((AE_INFO, "Invalid table signature 0x%8.8X",
-                           signature));
+       checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
 
-               ACPI_DUMP_BUFFER(table_header,
-                                sizeof(struct acpi_table_header));
-               return (AE_BAD_SIGNATURE);
-       }
+       /* Checksum ok? (should be zero) */
 
-       /* Validate the table length */
+       if (checksum) {
+               ACPI_WARNING((AE_INFO,
+                             "Incorrect checksum in table [%4.4s] -  %2.2X, should be %2.2X",
+                             table->signature, table->checksum,
+                             (u8) (table->checksum - checksum)));
 
-       if (table_header->length < sizeof(struct acpi_table_header)) {
-               ACPI_ERROR((AE_INFO,
-                           "Invalid length 0x%X in table with signature %4.4s",
-                           (u32) table_header->length,
-                           ACPI_CAST_PTR(char, &signature)));
+#if (ACPI_CHECKSUM_ABORT)
 
-               ACPI_DUMP_BUFFER(table_header,
-                                sizeof(struct acpi_table_header));
-               return (AE_BAD_HEADER);
+               return (AE_BAD_CHECKSUM);
+#endif
        }
 
        return (AE_OK);
@@ -186,157 +168,320 @@ acpi_tb_validate_table_header(struct acpi_table_header *table_header)
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_sum_table
+ * FUNCTION:    acpi_tb_checksum
  *
- * PARAMETERS:  Buffer              - Buffer to sum
- *              Length              - Size of the buffer
+ * PARAMETERS:  Buffer          - Pointer to memory region to be checked
+ *              Length          - Length of this memory region
  *
- * RETURN:      8 bit sum of buffer
+ * RETURN:      Checksum (u8)
  *
- * DESCRIPTION: Computes an 8 bit sum of the buffer(length) and returns it.
+ * DESCRIPTION: Calculates circular checksum of memory region.
  *
  ******************************************************************************/
 
-u8 acpi_tb_sum_table(void *buffer, u32 length)
+u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length)
 {
-       acpi_native_uint i;
        u8 sum = 0;
+       u8 *end = buffer + length;
 
-       if (!buffer || !length) {
-               return (0);
+       while (buffer < end) {
+               sum = (u8) (sum + *(buffer++));
        }
 
-       for (i = 0; i < length; i++) {
-               sum = (u8) (sum + ((u8 *) buffer)[i]);
-       }
-       return (sum);
+       return sum;
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_generate_checksum
+ * FUNCTION:    acpi_tb_install_table
  *
- * PARAMETERS:  Table               - Pointer to a valid ACPI table (with a
- *                                    standard ACPI header)
+ * PARAMETERS:  Address                 - Physical address of DSDT or FACS
+ *              Flags                   - Flags
+ *              Signature               - Table signature, NULL if no need to
+ *                                        match
+ *              table_index             - Index into root table array
  *
- * RETURN:      8 bit checksum of buffer
+ * RETURN:      None
  *
- * DESCRIPTION: Computes an 8 bit checksum of the table.
+ * DESCRIPTION: Install an ACPI table into the global data structure.
  *
  ******************************************************************************/
 
-u8 acpi_tb_generate_checksum(struct acpi_table_header * table)
+void
+acpi_tb_install_table(acpi_physical_address address,
+                     u8 flags, char *signature, acpi_native_uint table_index)
 {
-       u8 checksum;
+       struct acpi_table_header *table;
+
+       if (!address) {
+               ACPI_ERROR((AE_INFO,
+                           "Null physical address for ACPI table [%s]",
+                           signature));
+               return;
+       }
+
+       /* Map just the table header */
+
+       table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
+       if (!table) {
+               return;
+       }
+
+       /* If a particular signature is expected, signature must match */
+
+       if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) {
+               ACPI_ERROR((AE_INFO,
+                           "Invalid signature 0x%X for ACPI table [%s]",
+                           *ACPI_CAST_PTR(u32, table->signature), signature));
+               goto unmap_and_exit;
+       }
 
-       /* Sum the entire table as-is */
+       /* Initialize the table entry */
 
-       checksum = acpi_tb_sum_table(table, table->length);
+       acpi_gbl_root_table_list.tables[table_index].address = address;
+       acpi_gbl_root_table_list.tables[table_index].length = table->length;
+       acpi_gbl_root_table_list.tables[table_index].flags = flags;
 
-       /* Subtract off the existing checksum value in the table */
+       ACPI_MOVE_32_TO_32(&
+                          (acpi_gbl_root_table_list.tables[table_index].
+                           signature), table->signature);
 
-       checksum = (u8) (checksum - table->checksum);
+       acpi_tb_print_table_header(address, table);
 
-       /* Compute the final checksum */
+       if (table_index == ACPI_TABLE_INDEX_DSDT) {
 
-       checksum = (u8) (0 - checksum);
-       return (checksum);
+               /* Global integer width is based upon revision of the DSDT */
+
+               acpi_ut_set_integer_width(table->revision);
+       }
+
+      unmap_and_exit:
+       acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_set_checksum
+ * FUNCTION:    acpi_tb_get_root_table_entry
  *
- * PARAMETERS:  Table               - Pointer to a valid ACPI table (with a
- *                                    standard ACPI header)
+ * PARAMETERS:  table_entry         - Pointer to the RSDT/XSDT table entry
+ *              table_entry_size    - sizeof 32 or 64 (RSDT or XSDT)
  *
- * RETURN:      None. Sets the table checksum field
+ * RETURN:      Physical address extracted from the root table
  *
- * DESCRIPTION: Computes an 8 bit checksum of the table and inserts the
- *              checksum into the table header.
+ * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
+ *              both 32-bit and 64-bit platforms
+ *
+ * NOTE:        acpi_physical_address is 32-bit on 32-bit platforms, 64-bit on
+ *              64-bit platforms.
  *
  ******************************************************************************/
 
-void acpi_tb_set_checksum(struct acpi_table_header *table)
+static acpi_physical_address
+acpi_tb_get_root_table_entry(u8 * table_entry,
+                            acpi_native_uint table_entry_size)
 {
+       u64 address64;
+
+       /*
+        * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
+        * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
+        */
+       if (table_entry_size == sizeof(u32)) {
+               /*
+                * 32-bit platform, RSDT: Return 32-bit table entry
+                * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
+                */
+               return ((acpi_physical_address)
+                       (*ACPI_CAST_PTR(u32, table_entry)));
+       } else {
+               /*
+                * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
+                * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, return 64-bit
+                */
+               ACPI_MOVE_64_TO_64(&address64, table_entry);
 
-       table->checksum = acpi_tb_generate_checksum(table);
+#if ACPI_MACHINE_WIDTH == 32
+               if (address64 > ACPI_UINT32_MAX) {
+
+                       /* Will truncate 64-bit address to 32 bits, issue warning */
+
+                       ACPI_WARNING((AE_INFO,
+                                     "64-bit Physical Address in XSDT is too large (%8.8X%8.8X), truncating",
+                                     ACPI_FORMAT_UINT64(address64)));
+               }
+#endif
+               return ((acpi_physical_address) (address64));
+       }
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_verify_table_checksum
+ * FUNCTION:    acpi_tb_parse_root_table
+ *
+ * PARAMETERS:  Rsdp                    - Pointer to the RSDP
+ *              Flags                   - Flags
  *
- * PARAMETERS:  *table_header           - ACPI table to verify
+ * RETURN:      Status
  *
- * RETURN:      8 bit checksum of table
+ * DESCRIPTION: This function is called to parse the Root System Description
+ *              Table (RSDT or XSDT)
  *
- * DESCRIPTION: Generates an 8 bit checksum of table and returns and compares
- *              it to the existing checksum value.
+ * NOTE:        Tables are mapped (not copied) for efficiency. The FACS must
+ *              be mapped and cannot be copied because it contains the actual
+ *              memory location of the ACPI Global Lock.
  *
  ******************************************************************************/
 
-acpi_status
-acpi_tb_verify_table_checksum(struct acpi_table_header *table_header)
+acpi_status __init
+acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
 {
-       u8 checksum;
+       struct acpi_table_rsdp *rsdp;
+       acpi_native_uint table_entry_size;
+       acpi_native_uint i;
+       u32 table_count;
+       struct acpi_table_header *table;
+       acpi_physical_address address;
+       u32 length;
+       u8 *table_entry;
+       acpi_status status;
+
+       ACPI_FUNCTION_TRACE(tb_parse_root_table);
+
+       /*
+        * Map the entire RSDP and extract the address of the RSDT or XSDT
+        */
+       rsdp = acpi_os_map_memory(rsdp_address, sizeof(struct acpi_table_rsdp));
+       if (!rsdp) {
+               return_ACPI_STATUS(AE_NO_MEMORY);
+       }
 
-       ACPI_FUNCTION_TRACE(tb_verify_table_checksum);
+       acpi_tb_print_table_header(rsdp_address,
+                                  ACPI_CAST_PTR(struct acpi_table_header,
+                                                rsdp));
 
-       /* Compute the checksum on the table */
+       /* Differentiate between RSDT and XSDT root tables */
 
-       checksum = acpi_tb_generate_checksum(table_header);
+       if (rsdp->revision > 1 && rsdp->xsdt_physical_address) {
+               /*
+                * Root table is an XSDT (64-bit physical addresses). We must use the
+                * XSDT if the revision is > 1 and the XSDT pointer is present, as per
+                * the ACPI specification.
+                */
+               address = (acpi_physical_address) rsdp->xsdt_physical_address;
+               table_entry_size = sizeof(u64);
+       } else {
+               /* Root table is an RSDT (32-bit physical addresses) */
 
-       /* Checksum ok? */
+               address = (acpi_physical_address) rsdp->rsdt_physical_address;
+               table_entry_size = sizeof(u32);
+       }
 
-       if (checksum == table_header->checksum) {
-               return_ACPI_STATUS(AE_OK);
+       /*
+        * It is not possible to map more than one entry in some environments,
+        * so unmap the RSDP here before mapping other tables
+        */
+       acpi_os_unmap_memory(rsdp, sizeof(struct acpi_table_rsdp));
+
+       /* Map the RSDT/XSDT table header to get the full table length */
+
+       table = acpi_os_map_memory(address, sizeof(struct acpi_table_header));
+       if (!table) {
+               return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
-       ACPI_WARNING((AE_INFO,
-                     "Incorrect checksum in table [%4.4s] - is %2.2X, should be %2.2X",
-                     table_header->signature, table_header->checksum,
-                     checksum));
+       acpi_tb_print_table_header(address, table);
 
-       return_ACPI_STATUS(AE_BAD_CHECKSUM);
-}
+       /* Get the length of the full table, verify length and map entire table */
 
-#ifdef ACPI_OBSOLETE_FUNCTIONS
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_handle_to_object
- *
- * PARAMETERS:  table_id            - Id for which the function is searching
- *              table_desc          - Pointer to return the matching table
- *                                      descriptor.
- *
- * RETURN:      Search the tables to find one with a matching table_id and
- *              return a pointer to that table descriptor.
- *
- ******************************************************************************/
+       length = table->length;
+       acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
 
-acpi_status
-acpi_tb_handle_to_object(u16 table_id,
-                        struct acpi_table_desc **return_table_desc)
-{
-       u32 i;
-       struct acpi_table_desc *table_desc;
+       if (length < sizeof(struct acpi_table_header)) {
+               ACPI_ERROR((AE_INFO, "Invalid length 0x%X in RSDT/XSDT",
+                           length));
+               return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
+       }
 
-       ACPI_FUNCTION_NAME(tb_handle_to_object);
+       table = acpi_os_map_memory(address, length);
+       if (!table) {
+               return_ACPI_STATUS(AE_NO_MEMORY);
+       }
+
+       /* Validate the root table checksum */
+
+       status = acpi_tb_verify_checksum(table, length);
+       if (ACPI_FAILURE(status)) {
+               acpi_os_unmap_memory(table, length);
+               return_ACPI_STATUS(status);
+       }
 
-       for (i = 0; i < ACPI_TABLE_MAX; i++) {
-               table_desc = acpi_gbl_table_lists[i].next;
-               while (table_desc) {
-                       if (table_desc->table_id == table_id) {
-                               *return_table_desc = table_desc;
-                               return (AE_OK);
+       /* Calculate the number of tables described in the root table */
+
+       table_count =
+           (u32) ((table->length -
+                   sizeof(struct acpi_table_header)) / table_entry_size);
+
+       /*
+        * First two entries in the table array are reserved for the DSDT and FACS,
+        * which are not actually present in the RSDT/XSDT - they come from the FADT
+        */
+       table_entry =
+           ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
+       acpi_gbl_root_table_list.count = 2;
+
+       /*
+        * Initialize the root table array from the RSDT/XSDT
+        */
+       for (i = 0; i < table_count; i++) {
+               if (acpi_gbl_root_table_list.count >=
+                   acpi_gbl_root_table_list.size) {
+
+                       /* There is no more room in the root table array, attempt resize */
+
+                       status = acpi_tb_resize_root_table_list();
+                       if (ACPI_FAILURE(status)) {
+                               ACPI_WARNING((AE_INFO,
+                                             "Truncating %u table entries!",
+                                             (unsigned)
+                                             (acpi_gbl_root_table_list.size -
+                                              acpi_gbl_root_table_list.
+                                              count)));
+                               break;
                        }
+               }
+
+               /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
 
-                       table_desc = table_desc->next;
+               acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
+                   address =
+                   acpi_tb_get_root_table_entry(table_entry, table_entry_size);
+
+               table_entry += table_entry_size;
+               acpi_gbl_root_table_list.count++;
+       }
+
+       /*
+        * It is not possible to map more than one entry in some environments,
+        * so unmap the root table here before mapping other tables
+        */
+       acpi_os_unmap_memory(table, length);
+
+       /*
+        * Complete the initialization of the root table array by examining
+        * the header of each table
+        */
+       for (i = 2; i < acpi_gbl_root_table_list.count; i++) {
+               acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
+                                     address, flags, NULL, i);
+
+               /* Special case for FADT - get the DSDT and FACS */
+
+               if (ACPI_COMPARE_NAME
+                   (&acpi_gbl_root_table_list.tables[i].signature,
+                    ACPI_SIG_FADT)) {
+                       acpi_tb_parse_fadt(i, flags);
                }
        }
 
-       ACPI_ERROR((AE_INFO, "TableId=%X does not exist", table_id));
-       return (AE_BAD_PARAMETER);
+       return_ACPI_STATUS(AE_OK);
 }
-#endif
index 5ba9303293ad968c4366ca49c4044291cd4bf10c..807978d5381abb34767687de505600b0e8d6aa8a 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define _COMPONENT          ACPI_TABLES
 ACPI_MODULE_NAME("tbxface")
 
+/* Local prototypes */
+static acpi_status acpi_tb_load_namespace(void);
+
 /*******************************************************************************
  *
- * FUNCTION:    acpi_load_tables
+ * FUNCTION:    acpi_allocate_root_table
  *
- * PARAMETERS:  None
+ * PARAMETERS:  initial_table_count - Size of initial_table_array, in number of
+ *                                    struct acpi_table_desc structures
  *
  * RETURN:      Status
  *
- * DESCRIPTION: This function is called to load the ACPI tables from the
- *              provided RSDT
+ * DESCRIPTION: Allocate a root table array. Used by i_aSL compiler and
+ *              acpi_initialize_tables.
  *
  ******************************************************************************/
-acpi_status acpi_load_tables(void)
+
+acpi_status acpi_allocate_root_table(u32 initial_table_count)
 {
-       struct acpi_pointer rsdp_address;
-       acpi_status status;
 
-       ACPI_FUNCTION_TRACE(acpi_load_tables);
+       acpi_gbl_root_table_list.size = initial_table_count;
+       acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE;
 
-       /* Get the RSDP */
+       return (acpi_tb_resize_root_table_list());
+}
 
-       status = acpi_os_get_root_pointer(ACPI_LOGICAL_ADDRESSING,
-                                         &rsdp_address);
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status, "Could not get the RSDP"));
-               goto error_exit;
-       }
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_initialize_tables
+ *
+ * PARAMETERS:  initial_table_array - Pointer to an array of pre-allocated
+ *                                    struct acpi_table_desc structures. If NULL, the
+ *                                    array is dynamically allocated.
+ *              initial_table_count - Size of initial_table_array, in number of
+ *                                    struct acpi_table_desc structures
+ *              allow_realloc       - Flag to tell Table Manager if resize of
+ *                                    pre-allocated array is allowed. Ignored
+ *                                    if initial_table_array is NULL.
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
+ *
+ * NOTE:        Allows static allocation of the initial table array in order
+ *              to avoid the use of dynamic memory in confined environments
+ *              such as the kernel boot sequence where it may not be available.
+ *
+ *              If the host OS memory managers are initialized, use NULL for
+ *              initial_table_array, and the table will be dynamically allocated.
+ *
+ ******************************************************************************/
 
-       /* Map and validate the RSDP */
+acpi_status __init
+acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
+                      u32 initial_table_count, u8 allow_resize)
+{
+       acpi_physical_address rsdp_address;
+       acpi_status status;
 
-       acpi_gbl_table_flags = rsdp_address.pointer_type;
+       ACPI_FUNCTION_TRACE(acpi_initialize_tables);
 
-       status = acpi_tb_verify_rsdp(&rsdp_address);
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status, "During RSDP validation"));
-               goto error_exit;
+       /*
+        * Set up the Root Table Array
+        * Allocate the table array if requested
+        */
+       if (!initial_table_array) {
+               status = acpi_allocate_root_table(initial_table_count);
+               if (ACPI_FAILURE(status)) {
+                       return_ACPI_STATUS(status);
+               }
+       } else {
+               /* Root Table Array has been statically allocated by the host */
+
+               ACPI_MEMSET(initial_table_array, 0,
+                           initial_table_count *
+                           sizeof(struct acpi_table_desc));
+
+               acpi_gbl_root_table_list.tables = initial_table_array;
+               acpi_gbl_root_table_list.size = initial_table_count;
+               acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN;
+               if (allow_resize) {
+                       acpi_gbl_root_table_list.flags |=
+                           ACPI_ROOT_ALLOW_RESIZE;
+               }
        }
 
-       /* Get the RSDT via the RSDP */
+       /* Get the address of the RSDP */
 
-       status = acpi_tb_get_table_rsdt();
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status, "Could not load RSDT"));
-               goto error_exit;
+       rsdp_address = acpi_os_get_root_pointer();
+       if (!rsdp_address) {
+               return_ACPI_STATUS(AE_NOT_FOUND);
        }
 
-       /* Now get the tables needed by this subsystem (FADT, DSDT, etc.) */
+       /*
+        * Get the root table (RSDT or XSDT) and extract all entries to the local
+        * Root Table Array. This array contains the information of the RSDT/XSDT
+        * in a common, more useable format.
+        */
+       status =
+           acpi_tb_parse_root_table(rsdp_address, ACPI_TABLE_ORIGIN_MAPPED);
+       return_ACPI_STATUS(status);
+}
 
-       status = acpi_tb_get_required_tables();
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status,
-                               "Could not get all required tables (DSDT/FADT/FACS)"));
-               goto error_exit;
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_reallocate_root_table
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
+ *              root list from the previously provided scratch area. Should
+ *              be called once dynamic memory allocation is available in the
+ *              kernel
+ *
+ ******************************************************************************/
+acpi_status acpi_reallocate_root_table(void)
+{
+       struct acpi_table_desc *tables;
+       acpi_size new_size;
+
+       ACPI_FUNCTION_TRACE(acpi_reallocate_root_table);
+
+       /*
+        * Only reallocate the root table if the host provided a static buffer
+        * for the table array in the call to acpi_initialize_tables.
+        */
+       if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
+               return_ACPI_STATUS(AE_SUPPORT);
        }
 
-       ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
+       new_size =
+           (acpi_gbl_root_table_list.count +
+            ACPI_ROOT_TABLE_SIZE_INCREMENT) * sizeof(struct acpi_table_desc);
 
-       /* Load the namespace from the tables */
+       /* Create new array and copy the old array */
 
-       status = acpi_ns_load_namespace();
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status, "Could not load namespace"));
-               goto error_exit;
+       tables = ACPI_ALLOCATE_ZEROED(new_size);
+       if (!tables) {
+               return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
-       return_ACPI_STATUS(AE_OK);
+       ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, new_size);
 
-      error_exit:
-       ACPI_EXCEPTION((AE_INFO, status, "Could not load tables"));
-       return_ACPI_STATUS(status);
-}
-
-ACPI_EXPORT_SYMBOL(acpi_load_tables)
+       acpi_gbl_root_table_list.size = acpi_gbl_root_table_list.count;
+       acpi_gbl_root_table_list.tables = tables;
+       acpi_gbl_root_table_list.flags =
+           ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE;
 
+       return_ACPI_STATUS(AE_OK);
+}
 /*******************************************************************************
  *
  * FUNCTION:    acpi_load_table
@@ -141,342 +219,405 @@ ACPI_EXPORT_SYMBOL(acpi_load_tables)
 acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
 {
        acpi_status status;
-       struct acpi_table_desc table_info;
-       struct acpi_pointer address;
-
-       ACPI_FUNCTION_TRACE(acpi_load_table);
-
-       if (!table_ptr) {
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-       }
-
-       /* Copy the table to a local buffer */
+       acpi_native_uint table_index;
+       struct acpi_table_desc table_desc;
 
-       address.pointer_type = ACPI_LOGICAL_POINTER | ACPI_LOGICAL_ADDRESSING;
-       address.pointer.logical = table_ptr;
-
-       status = acpi_tb_get_table_body(&address, table_ptr, &table_info);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /* Check signature for a valid table type */
-
-       status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
+       if (!table_ptr)
+               return AE_BAD_PARAMETER;
 
-       /* Install the new table into the local data structures */
+       ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
+       table_desc.pointer = table_ptr;
+       table_desc.length = table_ptr->length;
+       table_desc.flags = ACPI_TABLE_ORIGIN_UNKNOWN;
 
-       status = acpi_tb_install_table(&table_info);
+       /*
+        * Install the new table into the local data structures
+        */
+       status = acpi_tb_add_table(&table_desc, &table_index);
        if (ACPI_FAILURE(status)) {
-               if (status == AE_ALREADY_EXISTS) {
-
-                       /* Table already exists, no error */
-
-                       status = AE_OK;
-               }
-
-               /* Free table allocated by acpi_tb_get_table_body */
-
-               acpi_tb_delete_single_table(&table_info);
-               return_ACPI_STATUS(status);
+               return status;
        }
+       status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
+       return status;
+}
 
-       /* Convert the table to common format if necessary */
-
-       switch (table_info.type) {
-       case ACPI_TABLE_ID_FADT:
-
-               status = acpi_tb_convert_table_fadt();
-               break;
-
-       case ACPI_TABLE_ID_FACS:
+ACPI_EXPORT_SYMBOL(acpi_load_table)
 
-               status = acpi_tb_build_common_facs(&table_info);
-               break;
+/******************************************************************************
+ *
+ * FUNCTION:    acpi_get_table_header
+ *
+ * PARAMETERS:  Signature           - ACPI signature of needed table
+ *              Instance            - Which instance (for SSDTs)
+ *              out_table_header    - The pointer to the table header to fill
+ *
+ * RETURN:      Status and pointer to mapped table header
+ *
+ * DESCRIPTION: Finds an ACPI table header.
+ *
+ * NOTE:        Caller is responsible in unmapping the header with
+ *              acpi_os_unmap_memory
+ *
+ *****************************************************************************/
+acpi_status
+acpi_get_table_header(char *signature,
+                     acpi_native_uint instance,
+                     struct acpi_table_header *out_table_header)
+{
+       acpi_native_uint i;
+       acpi_native_uint j;
+       struct acpi_table_header *header;
 
-       default:
-               /* Load table into namespace if it contains executable AML */
+       /* Parameter validation */
 
-               status =
-                   acpi_ns_load_table(table_info.installed_desc,
-                                      acpi_gbl_root_node);
-               break;
+       if (!signature || !out_table_header) {
+               return (AE_BAD_PARAMETER);
        }
 
-       if (ACPI_FAILURE(status)) {
+       /*
+        * Walk the root table list
+        */
+       for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
+               if (!ACPI_COMPARE_NAME
+                   (&(acpi_gbl_root_table_list.tables[i].signature),
+                    signature)) {
+                       continue;
+               }
 
-               /* Uninstall table and free the buffer */
+               if (++j < instance) {
+                       continue;
+               }
 
-               (void)acpi_tb_uninstall_table(table_info.installed_desc);
+               if (!acpi_gbl_root_table_list.tables[i].pointer) {
+                       if ((acpi_gbl_root_table_list.tables[i].
+                            flags & ACPI_TABLE_ORIGIN_MASK) ==
+                           ACPI_TABLE_ORIGIN_MAPPED) {
+                               header =
+                                   acpi_os_map_memory(acpi_gbl_root_table_list.
+                                                      tables[i].address,
+                                                      sizeof(struct
+                                                             acpi_table_header));
+                               if (!header) {
+                                       return AE_NO_MEMORY;
+                               }
+                               ACPI_MEMCPY(out_table_header, header,
+                                           sizeof(struct acpi_table_header));
+                               acpi_os_unmap_memory(header,
+                                                    sizeof(struct
+                                                           acpi_table_header));
+                       } else {
+                               return AE_NOT_FOUND;
+                       }
+               } else {
+                       ACPI_MEMCPY(out_table_header,
+                                   acpi_gbl_root_table_list.tables[i].pointer,
+                                   sizeof(struct acpi_table_header));
+               }
+               return (AE_OK);
        }
 
-       return_ACPI_STATUS(status);
+       return (AE_NOT_FOUND);
 }
 
-ACPI_EXPORT_SYMBOL(acpi_load_table)
+ACPI_EXPORT_SYMBOL(acpi_get_table_header)
 
-/*******************************************************************************
+
+/******************************************************************************
  *
  * FUNCTION:    acpi_unload_table_id
  *
- * PARAMETERS:  table_type    - Type of table to be unloaded
- *              id            - Owner ID of the table to be removed.
+ * PARAMETERS:  id            - Owner ID of the table to be removed.
  *
  * RETURN:      Status
  *
  * DESCRIPTION: This routine is used to force the unload of a table (by id)
  *
  ******************************************************************************/
-acpi_status acpi_unload_table_id(acpi_table_type table_type, acpi_owner_id id)
+acpi_status acpi_unload_table_id(acpi_owner_id id)
 {
-       struct acpi_table_desc *table_desc;
-       acpi_status status;
+       int i;
+       acpi_status status = AE_NOT_EXIST;
 
        ACPI_FUNCTION_TRACE(acpi_unload_table);
 
-       /* Parameter validation */
-       if (table_type > ACPI_TABLE_ID_MAX)
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-
        /* Find table from the requested type list */
-       table_desc = acpi_gbl_table_lists[table_type].next;
-       while (table_desc && table_desc->owner_id != id)
-               table_desc = table_desc->next;
-
-       if (!table_desc)
-               return_ACPI_STATUS(AE_NOT_EXIST);
-
-       /*
-        * Delete all namespace objects owned by this table. Note that these
-        * objects can appear anywhere in the namespace by virtue of the AML
-        * "Scope" operator. Thus, we need to track ownership by an ID, not
-        * simply a position within the hierarchy
-        */
-       acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
-
-       status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
-       if (ACPI_FAILURE(status))
-               return_ACPI_STATUS(status);
-
-       (void)acpi_tb_uninstall_table(table_desc);
-
-       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
-
-       return_ACPI_STATUS(AE_OK);
+       for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
+               if (id != acpi_gbl_root_table_list.tables[i].owner_id) {
+                       continue;
+               }
+               /*
+               * Delete all namespace objects owned by this table. Note that these
+               * objects can appear anywhere in the namespace by virtue of the AML
+               * "Scope" operator. Thus, we need to track ownership by an ID, not
+               * simply a position within the hierarchy
+               */
+               acpi_tb_delete_namespace_by_owner(i);
+               acpi_tb_release_owner_id(i);
+               acpi_tb_set_table_loaded_flag(i, FALSE);
+       }
+       return_ACPI_STATUS(status);
 }
 
 ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
 
-#ifdef ACPI_FUTURE_USAGE
 /*******************************************************************************
  *
- * FUNCTION:    acpi_unload_table
+ * FUNCTION:    acpi_get_table
  *
- * PARAMETERS:  table_type    - Type of table to be unloaded
+ * PARAMETERS:  Signature           - ACPI signature of needed table
+ *              Instance            - Which instance (for SSDTs)
+ *              out_table           - Where the pointer to the table is returned
  *
- * RETURN:      Status
+ * RETURN:      Status and pointer to table
  *
- * DESCRIPTION: This routine is used to force the unload of a table
+ * DESCRIPTION: Finds and verifies an ACPI table.
  *
- ******************************************************************************/
-acpi_status acpi_unload_table(acpi_table_type table_type)
+ *****************************************************************************/
+acpi_status
+acpi_get_table(char *signature,
+              acpi_native_uint instance, struct acpi_table_header ** out_table)
 {
-       struct acpi_table_desc *table_desc;
-
-       ACPI_FUNCTION_TRACE(acpi_unload_table);
+       acpi_native_uint i;
+       acpi_native_uint j;
+       acpi_status status;
 
        /* Parameter validation */
 
-       if (table_type > ACPI_TABLE_ID_MAX) {
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
+       if (!signature || !out_table) {
+               return (AE_BAD_PARAMETER);
        }
 
-       /* Find all tables of the requested type */
+       /*
+        * Walk the root table list
+        */
+       for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
+               if (!ACPI_COMPARE_NAME
+                   (&(acpi_gbl_root_table_list.tables[i].signature),
+                    signature)) {
+                       continue;
+               }
 
-       table_desc = acpi_gbl_table_lists[table_type].next;
-       if (!table_desc) {
-               return_ACPI_STATUS(AE_NOT_EXIST);
-       }
+               if (++j < instance) {
+                       continue;
+               }
 
-       while (table_desc) {
-               /*
-                * Delete all namespace objects owned by this table. Note that these
-                * objects can appear anywhere in the namespace by virtue of the AML
-                * "Scope" operator. Thus, we need to track ownership by an ID, not
-                * simply a position within the hierarchy
-                */
-               acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
-               table_desc = table_desc->next;
-       }
+               status =
+                   acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]);
+               if (ACPI_SUCCESS(status)) {
+                       *out_table = acpi_gbl_root_table_list.tables[i].pointer;
+               }
 
-       /* Delete (or unmap) all tables of this type */
+               if (!acpi_gbl_permanent_mmap) {
+                       acpi_gbl_root_table_list.tables[i].pointer = 0;
+               }
 
-       acpi_tb_delete_tables_by_type(table_type);
-       return_ACPI_STATUS(AE_OK);
+               return (status);
+       }
+
+       return (AE_NOT_FOUND);
 }
 
-ACPI_EXPORT_SYMBOL(acpi_unload_table)
+ACPI_EXPORT_SYMBOL(acpi_get_table)
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_get_table_header
+ * FUNCTION:    acpi_get_table_by_index
  *
- * PARAMETERS:  table_type      - one of the defined table types
- *              Instance        - the non zero instance of the table, allows
- *                                support for multiple tables of the same type
- *                                see acpi_gbl_acpi_table_flag
- *              out_table_header - pointer to the struct acpi_table_header if successful
+ * PARAMETERS:  table_index         - Table index
+ *              Table               - Where the pointer to the table is returned
  *
- * DESCRIPTION: This function is called to get an ACPI table header. The caller
- *              supplies an pointer to a data area sufficient to contain an ACPI
- *              struct acpi_table_header structure.
+ * RETURN:      Status and pointer to the table
  *
- *              The header contains a length field that can be used to determine
- *              the size of the buffer needed to contain the entire table. This
- *              function is not valid for the RSD PTR table since it does not
- *              have a standard header and is fixed length.
+ * DESCRIPTION: Obtain a table by an index into the global table list.
  *
  ******************************************************************************/
 acpi_status
-acpi_get_table_header(acpi_table_type table_type,
-                     u32 instance, struct acpi_table_header *out_table_header)
+acpi_get_table_by_index(acpi_native_uint table_index,
+                       struct acpi_table_header ** table)
 {
-       struct acpi_table_header *tbl_ptr;
        acpi_status status;
 
-       ACPI_FUNCTION_TRACE(acpi_get_table_header);
+       ACPI_FUNCTION_TRACE(acpi_get_table_by_index);
+
+       /* Parameter validation */
 
-       if ((instance == 0) ||
-           (table_type == ACPI_TABLE_ID_RSDP) || (!out_table_header)) {
+       if (!table) {
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
-       /* Check the table type and instance */
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
+
+       /* Validate index */
 
-       if ((table_type > ACPI_TABLE_ID_MAX) ||
-           (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
-            instance > 1)) {
+       if (table_index >= acpi_gbl_root_table_list.count) {
+               (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
-       /* Get a pointer to the entire table */
+       if (!acpi_gbl_root_table_list.tables[table_index].pointer) {
 
-       status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
+               /* Table is not mapped, map it */
 
-       /* The function will return a NULL pointer if the table is not loaded */
-
-       if (tbl_ptr == NULL) {
-               return_ACPI_STATUS(AE_NOT_EXIST);
+               status =
+                   acpi_tb_verify_table(&acpi_gbl_root_table_list.
+                                        tables[table_index]);
+               if (ACPI_FAILURE(status)) {
+                       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
+                       return_ACPI_STATUS(status);
+               }
        }
 
-       /* Copy the header to the caller's buffer */
-
-       ACPI_MEMCPY(ACPI_CAST_PTR(void, out_table_header),
-                   ACPI_CAST_PTR(void, tbl_ptr),
-                   sizeof(struct acpi_table_header));
-
-       return_ACPI_STATUS(status);
+       *table = acpi_gbl_root_table_list.tables[table_index].pointer;
+       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
+       return_ACPI_STATUS(AE_OK);
 }
 
-ACPI_EXPORT_SYMBOL(acpi_get_table_header)
-#endif                         /*  ACPI_FUTURE_USAGE  */
+ACPI_EXPORT_SYMBOL(acpi_get_table_by_index)
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_get_table
+ * FUNCTION:    acpi_tb_load_namespace
  *
- * PARAMETERS:  table_type      - one of the defined table types
- *              Instance        - the non zero instance of the table, allows
- *                                support for multiple tables of the same type
- *                                see acpi_gbl_acpi_table_flag
- *              ret_buffer      - pointer to a structure containing a buffer to
- *                                receive the table
+ * PARAMETERS:  None
  *
  * RETURN:      Status
  *
- * DESCRIPTION: This function is called to get an ACPI table. The caller
- *              supplies an out_buffer large enough to contain the entire ACPI
- *              table. The caller should call the acpi_get_table_header function
- *              first to determine the buffer size needed. Upon completion
- *              the out_buffer->Length field will indicate the number of bytes
- *              copied into the out_buffer->buf_ptr buffer. This table will be
- *              a complete table including the header.
+ * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
+ *              the RSDT/XSDT.
  *
  ******************************************************************************/
-acpi_status
-acpi_get_table(acpi_table_type table_type,
-              u32 instance, struct acpi_buffer *ret_buffer)
+static acpi_status acpi_tb_load_namespace(void)
 {
-       struct acpi_table_header *tbl_ptr;
        acpi_status status;
-       acpi_size table_length;
+       struct acpi_table_header *table;
+       acpi_native_uint i;
 
-       ACPI_FUNCTION_TRACE(acpi_get_table);
+       ACPI_FUNCTION_TRACE(tb_load_namespace);
 
-       /* Parameter validation */
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
 
-       if (instance == 0) {
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
+       /*
+        * Load the namespace. The DSDT is required, but any SSDT and PSDT tables
+        * are optional.
+        */
+       if (!acpi_gbl_root_table_list.count ||
+           !ACPI_COMPARE_NAME(&
+                              (acpi_gbl_root_table_list.
+                               tables[ACPI_TABLE_INDEX_DSDT].signature),
+                              ACPI_SIG_DSDT)
+           ||
+           ACPI_FAILURE(acpi_tb_verify_table
+                        (&acpi_gbl_root_table_list.
+                         tables[ACPI_TABLE_INDEX_DSDT]))) {
+               status = AE_NO_ACPI_TABLES;
+               goto unlock_and_exit;
        }
 
-       status = acpi_ut_validate_buffer(ret_buffer);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
+       /*
+        * Find DSDT table
+        */
+       status =
+           acpi_os_table_override(acpi_gbl_root_table_list.
+                                  tables[ACPI_TABLE_INDEX_DSDT].pointer,
+                                  &table);
+       if (ACPI_SUCCESS(status) && table) {
+               /*
+                * DSDT table has been found
+                */
+               acpi_tb_delete_table(&acpi_gbl_root_table_list.
+                                    tables[ACPI_TABLE_INDEX_DSDT]);
+               acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer =
+                   table;
+               acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].length =
+                   table->length;
+               acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].flags =
+                   ACPI_TABLE_ORIGIN_UNKNOWN;
+
+               ACPI_INFO((AE_INFO, "Table DSDT replaced by host OS"));
+               acpi_tb_print_table_header(0, table);
        }
 
-       /* Check the table type and instance */
+       status =
+           acpi_tb_verify_table(&acpi_gbl_root_table_list.
+                                tables[ACPI_TABLE_INDEX_DSDT]);
+       if (ACPI_FAILURE(status)) {
 
-       if ((table_type > ACPI_TABLE_ID_MAX) ||
-           (ACPI_IS_SINGLE_TABLE(acpi_gbl_table_data[table_type].flags) &&
-            instance > 1)) {
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
+               /* A valid DSDT is required */
+
+               status = AE_NO_ACPI_TABLES;
+               goto unlock_and_exit;
        }
 
-       /* Get a pointer to the entire table */
+       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
 
-       status = acpi_tb_get_table_ptr(table_type, instance, &tbl_ptr);
+       /*
+        * Load and parse tables.
+        */
+       status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node);
        if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
        }
 
        /*
-        * acpi_tb_get_table_ptr will return a NULL pointer if the
-        * table is not loaded.
+        * Load any SSDT or PSDT tables. Note: Loop leaves tables locked
         */
-       if (tbl_ptr == NULL) {
-               return_ACPI_STATUS(AE_NOT_EXIST);
+       (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
+       for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
+               if ((!ACPI_COMPARE_NAME
+                    (&(acpi_gbl_root_table_list.tables[i].signature),
+                     ACPI_SIG_SSDT)
+                    &&
+                    !ACPI_COMPARE_NAME(&
+                                       (acpi_gbl_root_table_list.tables[i].
+                                        signature), ACPI_SIG_PSDT))
+                   ||
+                   ACPI_FAILURE(acpi_tb_verify_table
+                                (&acpi_gbl_root_table_list.tables[i]))) {
+                       continue;
+               }
+
+               /* Ignore errors while loading tables, get as many as possible */
+
+               (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
+               (void)acpi_ns_load_table(i, acpi_gbl_root_node);
+               (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
        }
 
-       /* Get the table length */
+       ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
 
-       if (table_type == ACPI_TABLE_ID_RSDP) {
+      unlock_and_exit:
+       (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
+       return_ACPI_STATUS(status);
+}
 
-               /* RSD PTR is the only "table" without a header */
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_load_tables
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
+ *
+ ******************************************************************************/
 
-               table_length = sizeof(struct rsdp_descriptor);
-       } else {
-               table_length = (acpi_size) tbl_ptr->length;
-       }
+acpi_status acpi_load_tables(void)
+{
+       acpi_status status;
 
-       /* Validate/Allocate/Clear caller buffer */
+       ACPI_FUNCTION_TRACE(acpi_load_tables);
 
-       status = acpi_ut_initialize_buffer(ret_buffer, table_length);
+       /*
+        * Load the namespace from the tables
+        */
+       status = acpi_tb_load_namespace();
        if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
+               ACPI_EXCEPTION((AE_INFO, status,
+                               "While loading namespace from ACPI tables"));
        }
 
-       /* Copy the table to the buffer */
-
-       ACPI_MEMCPY(ACPI_CAST_PTR(void, ret_buffer->pointer),
-                   ACPI_CAST_PTR(void, tbl_ptr), table_length);
-
-       return_ACPI_STATUS(AE_OK);
+       return_ACPI_STATUS(status);
 }
 
-ACPI_EXPORT_SYMBOL(acpi_get_table)
+ACPI_EXPORT_SYMBOL(acpi_load_tables)
index da2648bbdbc013ea1de77775cf37e26671120ced..cf8fa514189f52b1be4f8bfb3b9782ed64d34564 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 ACPI_MODULE_NAME("tbxfroot")
 
 /* Local prototypes */
-static acpi_status
-acpi_tb_find_rsdp(struct acpi_table_desc *table_info, u32 flags);
-
 static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length);
 
+static acpi_status acpi_tb_validate_rsdp(struct acpi_table_rsdp *rsdp);
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_tb_validate_rsdp
  *
- * PARAMETERS:  Rsdp        - Pointer to unvalidated RSDP
+ * PARAMETERS:  Rsdp                - Pointer to unvalidated RSDP
  *
  * RETURN:      Status
  *
@@ -65,14 +64,18 @@ static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length);
  *
  ******************************************************************************/
 
-acpi_status acpi_tb_validate_rsdp(struct rsdp_descriptor *rsdp)
+static acpi_status acpi_tb_validate_rsdp(struct acpi_table_rsdp *rsdp)
 {
        ACPI_FUNCTION_ENTRY();
 
        /*
-        *  The signature and checksum must both be correct
+        * The signature and checksum must both be correct
+        *
+        * Note: Sometimes there exists more than one RSDP in memory; the valid
+        * RSDP has a valid checksum, all others have an invalid checksum.
         */
-       if (ACPI_STRNCMP((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0) {
+       if (ACPI_STRNCMP((char *)rsdp, ACPI_SIG_RSDP, sizeof(ACPI_SIG_RSDP) - 1)
+           != 0) {
 
                /* Nope, BAD Signature */
 
@@ -81,14 +84,14 @@ acpi_status acpi_tb_validate_rsdp(struct rsdp_descriptor *rsdp)
 
        /* Check the standard checksum */
 
-       if (acpi_tb_sum_table(rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) {
+       if (acpi_tb_checksum((u8 *) rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) {
                return (AE_BAD_CHECKSUM);
        }
 
        /* Check extended checksum if table version >= 2 */
 
        if ((rsdp->revision >= 2) &&
-           (acpi_tb_sum_table(rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0)) {
+           (acpi_tb_checksum((u8 *) rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0)) {
                return (AE_BAD_CHECKSUM);
        }
 
@@ -97,314 +100,123 @@ acpi_status acpi_tb_validate_rsdp(struct rsdp_descriptor *rsdp)
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_tb_find_table
- *
- * PARAMETERS:  Signature           - String with ACPI table signature
- *              oem_id              - String with the table OEM ID
- *              oem_table_id        - String with the OEM Table ID
- *              table_ptr           - Where the table pointer is returned
- *
- * RETURN:      Status
+ * FUNCTION:    acpi_tb_find_rsdp
  *
- * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
- *              Signature, OEM ID and OEM Table ID.
+ * PARAMETERS:  table_address           - Where the table pointer is returned
  *
- ******************************************************************************/
-
-acpi_status
-acpi_tb_find_table(char *signature,
-                  char *oem_id,
-                  char *oem_table_id, struct acpi_table_header ** table_ptr)
-{
-       acpi_status status;
-       struct acpi_table_header *table;
-
-       ACPI_FUNCTION_TRACE(tb_find_table);
-
-       /* Validate string lengths */
-
-       if ((ACPI_STRLEN(signature) > ACPI_NAME_SIZE) ||
-           (ACPI_STRLEN(oem_id) > sizeof(table->oem_id)) ||
-           (ACPI_STRLEN(oem_table_id) > sizeof(table->oem_table_id))) {
-               return_ACPI_STATUS(AE_AML_STRING_LIMIT);
-       }
-
-       if (ACPI_COMPARE_NAME(signature, DSDT_SIG)) {
-               /*
-                * The DSDT pointer is contained in the FADT, not the RSDT.
-                * This code should suffice, because the only code that would perform
-                * a "find" on the DSDT is the data_table_region() AML opcode -- in
-                * which case, the DSDT is guaranteed to be already loaded.
-                * If this becomes insufficient, the FADT will have to be found first.
-                */
-               if (!acpi_gbl_DSDT) {
-                       return_ACPI_STATUS(AE_NO_ACPI_TABLES);
-               }
-               table = acpi_gbl_DSDT;
-       } else {
-               /* Find the table */
-
-               status = acpi_get_firmware_table(signature, 1,
-                                                ACPI_LOGICAL_ADDRESSING,
-                                                &table);
-               if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
-               }
-       }
-
-       /* Check oem_id and oem_table_id */
-
-       if ((oem_id[0] &&
-            ACPI_STRNCMP(oem_id, table->oem_id,
-                         sizeof(table->oem_id))) ||
-           (oem_table_id[0] &&
-            ACPI_STRNCMP(oem_table_id, table->oem_table_id,
-                         sizeof(table->oem_table_id)))) {
-               return_ACPI_STATUS(AE_AML_NAME_NOT_FOUND);
-       }
-
-       ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Found table [%4.4s]\n",
-                         table->signature));
-
-       *table_ptr = table;
-       return_ACPI_STATUS(AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_get_firmware_table
+ * RETURN:      Status, RSDP physical address
  *
- * PARAMETERS:  Signature       - Any ACPI table signature
- *              Instance        - the non zero instance of the table, allows
- *                                support for multiple tables of the same type
- *              Flags           - Physical/Virtual support
- *              table_pointer   - Where a buffer containing the table is
- *                                returned
+ * DESCRIPTION: Search lower 1_mbyte of memory for the root system descriptor
+ *              pointer structure.  If it is found, set *RSDP to point to it.
  *
- * RETURN:      Status
+ * NOTE1:       The RSDP must be either in the first 1_k of the Extended
+ *              BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
+ *              Only a 32-bit physical address is necessary.
  *
- * DESCRIPTION: This function is called to get an ACPI table. A buffer is
- *              allocated for the table and returned in table_pointer.
- *              This table will be a complete table including the header.
+ * NOTE2:       This function is always available, regardless of the
+ *              initialization state of the rest of ACPI.
  *
  ******************************************************************************/
 
-acpi_status
-acpi_get_firmware_table(acpi_string signature,
-                       u32 instance,
-                       u32 flags, struct acpi_table_header **table_pointer)
+acpi_status acpi_find_root_pointer(acpi_native_uint * table_address)
 {
-       acpi_status status;
-       struct acpi_pointer address;
-       struct acpi_table_header *header = NULL;
-       struct acpi_table_desc *table_info = NULL;
-       struct acpi_table_desc *rsdt_info;
-       u32 table_count;
-       u32 i;
-       u32 j;
-
-       ACPI_FUNCTION_TRACE(acpi_get_firmware_table);
-
-       /*
-        * Ensure that at least the table manager is initialized.  We don't
-        * require that the entire ACPI subsystem is up for this interface.
-        * If we have a buffer, we must have a length too
-        */
-       if ((instance == 0) || (!signature) || (!table_pointer)) {
-               return_ACPI_STATUS(AE_BAD_PARAMETER);
-       }
-
-       /* Ensure that we have a RSDP */
-
-       if (!acpi_gbl_RSDP) {
-
-               /* Get the RSDP */
-
-               status = acpi_os_get_root_pointer(flags, &address);
-               if (ACPI_FAILURE(status)) {
-                       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "RSDP not found\n"));
-                       return_ACPI_STATUS(AE_NO_ACPI_TABLES);
-               }
-
-               /* Map and validate the RSDP */
-
-               if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
-                       status = acpi_os_map_memory(address.pointer.physical,
-                                                   sizeof(struct
-                                                          rsdp_descriptor),
-                                                   (void *)&acpi_gbl_RSDP);
-                       if (ACPI_FAILURE(status)) {
-                               return_ACPI_STATUS(status);
-                       }
-               } else {
-                       acpi_gbl_RSDP = address.pointer.logical;
-               }
-
-               /* The RDSP signature and checksum must both be correct */
-
-               status = acpi_tb_validate_rsdp(acpi_gbl_RSDP);
-               if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
-               }
-       }
-
-       /* Get the RSDT address via the RSDP */
-
-       acpi_tb_get_rsdt_address(&address);
-       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                         "RSDP located at %p, RSDT physical=%8.8X%8.8X\n",
-                         acpi_gbl_RSDP,
-                         ACPI_FORMAT_UINT64(address.pointer.value)));
+       u8 *table_ptr;
+       u8 *mem_rover;
+       u32 physical_address;
 
-       /* Insert processor_mode flags */
+       ACPI_FUNCTION_TRACE(acpi_find_root_pointer);
 
-       address.pointer_type |= flags;
+       /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
 
-       /* Get and validate the RSDT */
+       table_ptr = acpi_os_map_memory((acpi_physical_address)
+                                      ACPI_EBDA_PTR_LOCATION,
+                                      ACPI_EBDA_PTR_LENGTH);
+       if (!table_ptr) {
+               ACPI_ERROR((AE_INFO,
+                           "Could not map memory at %8.8X for length %X",
+                           ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
 
-       rsdt_info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_table_desc));
-       if (!rsdt_info) {
                return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
-       status = acpi_tb_get_table(&address, rsdt_info);
-       if (ACPI_FAILURE(status)) {
-               goto cleanup;
-       }
-
-       status = acpi_tb_validate_rsdt(rsdt_info->pointer);
-       if (ACPI_FAILURE(status)) {
-               goto cleanup;
-       }
+       ACPI_MOVE_16_TO_32(&physical_address, table_ptr);
 
-       /* Allocate a scratch table header and table descriptor */
+       /* Convert segment part to physical address */
 
-       header = ACPI_ALLOCATE(sizeof(struct acpi_table_header));
-       if (!header) {
-               status = AE_NO_MEMORY;
-               goto cleanup;
-       }
+       physical_address <<= 4;
+       acpi_os_unmap_memory(table_ptr, ACPI_EBDA_PTR_LENGTH);
 
-       table_info = ACPI_ALLOCATE(sizeof(struct acpi_table_desc));
-       if (!table_info) {
-               status = AE_NO_MEMORY;
-               goto cleanup;
-       }
+       /* EBDA present? */
 
-       /* Get the number of table pointers within the RSDT */
-
-       table_count =
-           acpi_tb_get_table_count(acpi_gbl_RSDP, rsdt_info->pointer);
-       address.pointer_type = acpi_gbl_table_flags | flags;
-
-       /*
-        * Search the RSDT/XSDT for the correct instance of the
-        * requested table
-        */
-       for (i = 0, j = 0; i < table_count; i++) {
+       if (physical_address > 0x400) {
                /*
-                * Get the next table pointer, handle RSDT vs. XSDT
-                * RSDT pointers are 32 bits, XSDT pointers are 64 bits
+                * 1b) Search EBDA paragraphs (EBDA is required to be a
+                *     minimum of 1_k length)
                 */
-               if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
-                       address.pointer.value =
-                           (ACPI_CAST_PTR
-                            (struct rsdt_descriptor,
-                             rsdt_info->pointer))->table_offset_entry[i];
-               } else {
-                       address.pointer.value =
-                           (ACPI_CAST_PTR
-                            (struct xsdt_descriptor,
-                             rsdt_info->pointer))->table_offset_entry[i];
-               }
-
-               /* Get the table header */
+               table_ptr = acpi_os_map_memory((acpi_native_uint)
+                                              physical_address,
+                                              ACPI_EBDA_WINDOW_SIZE);
+               if (!table_ptr) {
+                       ACPI_ERROR((AE_INFO,
+                                   "Could not map memory at %8.8X for length %X",
+                                   physical_address, ACPI_EBDA_WINDOW_SIZE));
 
-               status = acpi_tb_get_table_header(&address, header);
-               if (ACPI_FAILURE(status)) {
-                       goto cleanup;
+                       return_ACPI_STATUS(AE_NO_MEMORY);
                }
 
-               /* Compare table signatures and table instance */
-
-               if (ACPI_COMPARE_NAME(header->signature, signature)) {
-
-                       /* An instance of the table was found */
+               mem_rover =
+                   acpi_tb_scan_memory_for_rsdp(table_ptr,
+                                                ACPI_EBDA_WINDOW_SIZE);
+               acpi_os_unmap_memory(table_ptr, ACPI_EBDA_WINDOW_SIZE);
 
-                       j++;
-                       if (j >= instance) {
+               if (mem_rover) {
 
-                               /* Found the correct instance, get the entire table */
+                       /* Return the physical address */
 
-                               status =
-                                   acpi_tb_get_table_body(&address, header,
-                                                          table_info);
-                               if (ACPI_FAILURE(status)) {
-                                       goto cleanup;
-                               }
+                       physical_address +=
+                           (u32) ACPI_PTR_DIFF(mem_rover, table_ptr);
 
-                               *table_pointer = table_info->pointer;
-                               goto cleanup;
-                       }
+                       *table_address = physical_address;
+                       return_ACPI_STATUS(AE_OK);
                }
        }
 
-       /* Did not find the table */
+       /*
+        * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
+        */
+       table_ptr = acpi_os_map_memory((acpi_physical_address)
+                                      ACPI_HI_RSDP_WINDOW_BASE,
+                                      ACPI_HI_RSDP_WINDOW_SIZE);
 
-       status = AE_NOT_EXIST;
+       if (!table_ptr) {
+               ACPI_ERROR((AE_INFO,
+                           "Could not map memory at %8.8X for length %X",
+                           ACPI_HI_RSDP_WINDOW_BASE,
+                           ACPI_HI_RSDP_WINDOW_SIZE));
 
-      cleanup:
-       if (rsdt_info->pointer) {
-               acpi_os_unmap_memory(rsdt_info->pointer,
-                                    (acpi_size) rsdt_info->pointer->length);
+               return_ACPI_STATUS(AE_NO_MEMORY);
        }
-       ACPI_FREE(rsdt_info);
 
-       if (header) {
-               ACPI_FREE(header);
-       }
-       if (table_info) {
-               ACPI_FREE(table_info);
-       }
-       return_ACPI_STATUS(status);
-}
+       mem_rover =
+           acpi_tb_scan_memory_for_rsdp(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
+       acpi_os_unmap_memory(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
 
-ACPI_EXPORT_SYMBOL(acpi_get_firmware_table)
+       if (mem_rover) {
 
-/* TBD: Move to a new file */
-#if ACPI_MACHINE_WIDTH != 16
-/*******************************************************************************
- *
- * FUNCTION:    acpi_find_root_pointer
- *
- * PARAMETERS:  Flags                   - Logical/Physical addressing
- *              rsdp_address            - Where to place the RSDP address
- *
- * RETURN:      Status, Physical address of the RSDP
- *
- * DESCRIPTION: Find the RSDP
- *
- ******************************************************************************/
-acpi_status acpi_find_root_pointer(u32 flags, struct acpi_pointer *rsdp_address)
-{
-       struct acpi_table_desc table_info;
-       acpi_status status;
-
-       ACPI_FUNCTION_TRACE(acpi_find_root_pointer);
-
-       /* Get the RSDP */
+               /* Return the physical address */
 
-       status = acpi_tb_find_rsdp(&table_info, flags);
-       if (ACPI_FAILURE(status)) {
-               ACPI_EXCEPTION((AE_INFO, status,
-                               "RSDP structure not found - Flags=%X", flags));
+               physical_address = (u32)
+                   (ACPI_HI_RSDP_WINDOW_BASE +
+                    ACPI_PTR_DIFF(mem_rover, table_ptr));
 
-               return_ACPI_STATUS(AE_NO_ACPI_TABLES);
+               *table_address = physical_address;
+               return_ACPI_STATUS(AE_OK);
        }
 
-       rsdp_address->pointer_type = ACPI_PHYSICAL_POINTER;
-       rsdp_address->pointer.physical = table_info.physical_address;
-       return_ACPI_STATUS(AE_OK);
+       /* A valid RSDP was not found */
+
+       ACPI_ERROR((AE_INFO, "A valid RSDP was not found"));
+       return_ACPI_STATUS(AE_NOT_FOUND);
 }
 
 ACPI_EXPORT_SYMBOL(acpi_find_root_pointer)
@@ -440,7 +252,7 @@ static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length)
 
                status =
                    acpi_tb_validate_rsdp(ACPI_CAST_PTR
-                                         (struct rsdp_descriptor, mem_rover));
+                                         (struct acpi_table_rsdp, mem_rover));
                if (ACPI_SUCCESS(status)) {
 
                        /* Sig and checksum valid, we have found a real RSDP */
@@ -461,189 +273,3 @@ static u8 *acpi_tb_scan_memory_for_rsdp(u8 * start_address, u32 length)
                          start_address));
        return_PTR(NULL);
 }
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_tb_find_rsdp
- *
- * PARAMETERS:  table_info              - Where the table info is returned
- *              Flags                   - Current memory mode (logical vs.
- *                                        physical addressing)
- *
- * RETURN:      Status, RSDP physical address
- *
- * DESCRIPTION: Search lower 1_mbyte of memory for the root system descriptor
- *              pointer structure.  If it is found, set *RSDP to point to it.
- *
- *              NOTE1: The RSDP must be either in the first 1_k of the Extended
- *              BIOS Data Area or between E0000 and FFFFF (From ACPI Spec.)
- *              Only a 32-bit physical address is necessary.
- *
- *              NOTE2: This function is always available, regardless of the
- *              initialization state of the rest of ACPI.
- *
- ******************************************************************************/
-
-static acpi_status
-acpi_tb_find_rsdp(struct acpi_table_desc *table_info, u32 flags)
-{
-       u8 *table_ptr;
-       u8 *mem_rover;
-       u32 physical_address;
-       acpi_status status;
-
-       ACPI_FUNCTION_TRACE(tb_find_rsdp);
-
-       /*
-        * Scan supports either logical addressing or physical addressing
-        */
-       if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
-
-               /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
-
-               status = acpi_os_map_memory((acpi_physical_address)
-                                           ACPI_EBDA_PTR_LOCATION,
-                                           ACPI_EBDA_PTR_LENGTH,
-                                           (void *)&table_ptr);
-               if (ACPI_FAILURE(status)) {
-                       ACPI_ERROR((AE_INFO,
-                                   "Could not map memory at %8.8X for length %X",
-                                   ACPI_EBDA_PTR_LOCATION,
-                                   ACPI_EBDA_PTR_LENGTH));
-
-                       return_ACPI_STATUS(status);
-               }
-
-               ACPI_MOVE_16_TO_32(&physical_address, table_ptr);
-
-               /* Convert segment part to physical address */
-
-               physical_address <<= 4;
-               acpi_os_unmap_memory(table_ptr, ACPI_EBDA_PTR_LENGTH);
-
-               /* EBDA present? */
-
-               if (physical_address > 0x400) {
-                       /*
-                        * 1b) Search EBDA paragraphs (EBDA is required to be a
-                        *     minimum of 1_k length)
-                        */
-                       status = acpi_os_map_memory((acpi_physical_address)
-                                                   physical_address,
-                                                   ACPI_EBDA_WINDOW_SIZE,
-                                                   (void *)&table_ptr);
-                       if (ACPI_FAILURE(status)) {
-                               ACPI_ERROR((AE_INFO,
-                                           "Could not map memory at %8.8X for length %X",
-                                           physical_address,
-                                           ACPI_EBDA_WINDOW_SIZE));
-
-                               return_ACPI_STATUS(status);
-                       }
-
-                       mem_rover = acpi_tb_scan_memory_for_rsdp(table_ptr,
-                                                                ACPI_EBDA_WINDOW_SIZE);
-                       acpi_os_unmap_memory(table_ptr, ACPI_EBDA_WINDOW_SIZE);
-
-                       if (mem_rover) {
-
-                               /* Return the physical address */
-
-                               physical_address +=
-                                   (u32) ACPI_PTR_DIFF(mem_rover, table_ptr);
-
-                               table_info->physical_address =
-                                   (acpi_physical_address) physical_address;
-                               return_ACPI_STATUS(AE_OK);
-                       }
-               }
-
-               /*
-                * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
-                */
-               status = acpi_os_map_memory((acpi_physical_address)
-                                           ACPI_HI_RSDP_WINDOW_BASE,
-                                           ACPI_HI_RSDP_WINDOW_SIZE,
-                                           (void *)&table_ptr);
-
-               if (ACPI_FAILURE(status)) {
-                       ACPI_ERROR((AE_INFO,
-                                   "Could not map memory at %8.8X for length %X",
-                                   ACPI_HI_RSDP_WINDOW_BASE,
-                                   ACPI_HI_RSDP_WINDOW_SIZE));
-
-                       return_ACPI_STATUS(status);
-               }
-
-               mem_rover =
-                   acpi_tb_scan_memory_for_rsdp(table_ptr,
-                                                ACPI_HI_RSDP_WINDOW_SIZE);
-               acpi_os_unmap_memory(table_ptr, ACPI_HI_RSDP_WINDOW_SIZE);
-
-               if (mem_rover) {
-
-                       /* Return the physical address */
-
-                       physical_address = (u32)
-                           (ACPI_HI_RSDP_WINDOW_BASE +
-                            ACPI_PTR_DIFF(mem_rover, table_ptr));
-
-                       table_info->physical_address =
-                           (acpi_physical_address) physical_address;
-                       return_ACPI_STATUS(AE_OK);
-               }
-       }
-
-       /*
-        * Physical addressing
-        */
-       else {
-               /* 1a) Get the location of the EBDA */
-
-               ACPI_MOVE_16_TO_32(&physical_address, ACPI_EBDA_PTR_LOCATION);
-               physical_address <<= 4; /* Convert segment to physical address */
-
-               /* EBDA present? */
-
-               if (physical_address > 0x400) {
-                       /*
-                        * 1b) Search EBDA paragraphs (EBDA is required to be a minimum of
-                        *     1_k length)
-                        */
-                       mem_rover =
-                           acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
-                                                        (physical_address),
-                                                        ACPI_EBDA_WINDOW_SIZE);
-                       if (mem_rover) {
-
-                               /* Return the physical address */
-
-                               table_info->physical_address =
-                                   ACPI_TO_INTEGER(mem_rover);
-                               return_ACPI_STATUS(AE_OK);
-                       }
-               }
-
-               /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
-
-               mem_rover =
-                   acpi_tb_scan_memory_for_rsdp(ACPI_PHYSADDR_TO_PTR
-                                                (ACPI_HI_RSDP_WINDOW_BASE),
-                                                ACPI_HI_RSDP_WINDOW_SIZE);
-               if (mem_rover) {
-
-                       /* Found it, return the physical address */
-
-                       table_info->physical_address =
-                           ACPI_TO_INTEGER(mem_rover);
-                       return_ACPI_STATUS(AE_OK);
-               }
-       }
-
-       /* A valid RSDP was not found */
-
-       ACPI_ERROR((AE_INFO, "No valid RSDP was found"));
-       return_ACPI_STATUS(AE_NOT_FOUND);
-}
-
-#endif
index 40ddb4dd9631c20c6fc0d2695cb1126d6e9581b4..f76d3168c2b2d3e098ba0ca14883853dc6917b19 100644 (file)
@@ -82,7 +82,7 @@ MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n");
 
 static int acpi_thermal_add(struct acpi_device *device);
 static int acpi_thermal_remove(struct acpi_device *device, int type);
-static int acpi_thermal_resume(struct acpi_device *device, int state);
+static int acpi_thermal_resume(struct acpi_device *device);
 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
@@ -1353,7 +1353,7 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
        return 0;
 }
 
-static int acpi_thermal_resume(struct acpi_device *device, int state)
+static int acpi_thermal_resume(struct acpi_device *device)
 {
        struct acpi_thermal *tz = NULL;
        int i;
index f6cbc0b1bfd057f3d51257b7c1c35b12564ce708..55a764807499800b9f95c69c09c6ebaf9452a712 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -42,6 +42,7 @@
  */
 
 #include <acpi/acpi.h>
+#include <acpi/acdebug.h>
 
 #define _COMPONENT          ACPI_UTILITIES
 ACPI_MODULE_NAME("utalloc")
@@ -142,6 +143,14 @@ acpi_status acpi_ut_create_caches(void)
 
 acpi_status acpi_ut_delete_caches(void)
 {
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+       char buffer[7];
+
+       if (acpi_gbl_display_final_mem_stats) {
+               ACPI_STRCPY(buffer, "MEMORY");
+               acpi_db_display_statistics(buffer);
+       }
+#endif
 
        (void)acpi_os_delete_cache(acpi_gbl_namespace_cache);
        acpi_gbl_namespace_cache = NULL;
index 1a1f8109159cec3d9d988d1513a75cdb1638ecf4..870f6edeb5f28c6529889912c316459dcb1ae44e 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -289,6 +289,14 @@ void *acpi_os_acquire_object(struct acpi_memory_list *cache)
 
                ACPI_MEM_TRACKING(cache->total_allocated++);
 
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+               if ((cache->total_allocated - cache->total_freed) >
+                   cache->max_occupied) {
+                       cache->max_occupied =
+                           cache->total_allocated - cache->total_freed;
+               }
+#endif
+
                /* Avoid deadlock with ACPI_ALLOCATE_ZEROED */
 
                status = acpi_ut_release_mutex(ACPI_MTX_CACHES);
index 5e1a80d1bc369a280837a257c420b0e324e2b07d..84d529db0a6669234082d228ebc0f51f52a24f8f 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -719,6 +719,15 @@ acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
                acpi_ut_add_reference(source_desc->reference.object);
                break;
 
+       case ACPI_TYPE_REGION:
+               /*
+                * We copied the Region Handler, so we now must add a reference
+                */
+               if (dest_desc->region.handler) {
+                       acpi_ut_add_reference(dest_desc->region.handler);
+               }
+               break;
+
        default:
                /* Nothing to do for other simple objects */
                break;
index 9e9054e155c17837549049dfe4a4dfd186402e4a..61ad4f2daee2e8e4c8761e87de68eb5442b69601 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -181,8 +181,7 @@ acpi_ut_debug_print(u32 requested_debug_level,
                if (ACPI_LV_THREADS & acpi_dbg_level) {
                        acpi_os_printf
                            ("\n**** Context Switch from TID %lX to TID %lX ****\n\n",
-                            (unsigned long) acpi_gbl_prev_thread_id,
-                            (unsigned long) thread_id);
+                            (unsigned long)acpi_gbl_prev_thread_id, (unsigned long)thread_id);
                }
 
                acpi_gbl_prev_thread_id = thread_id;
@@ -195,7 +194,7 @@ acpi_ut_debug_print(u32 requested_debug_level,
        acpi_os_printf("%8s-%04ld ", module_name, line_number);
 
        if (ACPI_LV_THREADS & acpi_dbg_level) {
-               acpi_os_printf("[%04lX] ", thread_id);
+               acpi_os_printf("[%04lX] ", (unsigned long)thread_id);
        }
 
        acpi_os_printf("[%02ld] %-22.22s: ",
index 9d3f1149ba217736e5ff8b376445e522f6f8a79f..f777cebdc46dd85f8ec66b491096f9d2f20af1a3 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -158,16 +158,20 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
                                  "***** Mutex %p, OS Mutex %p\n",
                                  object, object->mutex.os_mutex));
 
-               if (object->mutex.os_mutex != ACPI_GLOBAL_LOCK) {
-                       acpi_ex_unlink_mutex(object);
-                       acpi_os_delete_mutex(object->mutex.os_mutex);
-               } else {
-                       /* Global Lock "mutex" is actually a counting semaphore */
+               if (object->mutex.os_mutex == acpi_gbl_global_lock_mutex) {
+
+                       /* Global Lock has extra semaphore */
 
                        (void)
                            acpi_os_delete_semaphore
                            (acpi_gbl_global_lock_semaphore);
                        acpi_gbl_global_lock_semaphore = NULL;
+
+                       acpi_os_delete_mutex(object->mutex.os_mutex);
+                       acpi_gbl_global_lock_mutex = NULL;
+               } else {
+                       acpi_ex_unlink_mutex(object);
+                       acpi_os_delete_mutex(object->mutex.os_mutex);
                }
                break;
 
index d6d7121583c0e96af0bee2f7222d4ab136e5ff28..13d5879cd98b92148acb215ac411a8280b862090 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 014030af8b5014f30415ede5cf3d5e9cf6d8f388..af33358a964b81f25ad0c404f61838ddbd1ba145 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include <acpi/acpi.h>
 #include <acpi/acnamesp.h>
 
+ACPI_EXPORT_SYMBOL(acpi_gbl_FADT)
 #define _COMPONENT          ACPI_UTILITIES
-ACPI_MODULE_NAME("utglobal")
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_format_exception
- *
- * PARAMETERS:  Status       - The acpi_status code to be formatted
- *
- * RETURN:      A string containing the exception text. A valid pointer is
- *              always returned.
- *
- * DESCRIPTION: This function translates an ACPI exception into an ASCII string.
- *
- ******************************************************************************/
-const char *acpi_format_exception(acpi_status status)
-{
-       acpi_status sub_status;
-       const char *exception = NULL;
-
-       ACPI_FUNCTION_ENTRY();
-
-       /*
-        * Status is composed of two parts, a "type" and an actual code
-        */
-       sub_status = (status & ~AE_CODE_MASK);
-
-       switch (status & AE_CODE_MASK) {
-       case AE_CODE_ENVIRONMENTAL:
-
-               if (sub_status <= AE_CODE_ENV_MAX) {
-                       exception = acpi_gbl_exception_names_env[sub_status];
-               }
-               break;
-
-       case AE_CODE_PROGRAMMER:
-
-               if (sub_status <= AE_CODE_PGM_MAX) {
-                       exception =
-                           acpi_gbl_exception_names_pgm[sub_status - 1];
-               }
-               break;
-
-       case AE_CODE_ACPI_TABLES:
-
-               if (sub_status <= AE_CODE_TBL_MAX) {
-                       exception =
-                           acpi_gbl_exception_names_tbl[sub_status - 1];
-               }
-               break;
-
-       case AE_CODE_AML:
-
-               if (sub_status <= AE_CODE_AML_MAX) {
-                       exception =
-                           acpi_gbl_exception_names_aml[sub_status - 1];
-               }
-               break;
-
-       case AE_CODE_CONTROL:
-
-               if (sub_status <= AE_CODE_CTRL_MAX) {
-                       exception =
-                           acpi_gbl_exception_names_ctrl[sub_status - 1];
-               }
-               break;
-
-       default:
-               break;
-       }
-
-       if (!exception) {
-
-               /* Exception code was not recognized */
-
-               ACPI_ERROR((AE_INFO,
-                           "Unknown exception code: 0x%8.8X", status));
-
-               exception = "UNKNOWN_STATUS_CODE";
-       }
-
-       return (ACPI_CAST_PTR(const char, exception));
-}
+    ACPI_MODULE_NAME("utglobal")
 
 /*******************************************************************************
  *
@@ -163,8 +83,6 @@ u32 acpi_gbl_startup_flags = 0;
 
 u8 acpi_gbl_shutdown = TRUE;
 
-const u8 acpi_gbl_decode_to8bit[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
-
 const char *acpi_gbl_sleep_state_names[ACPI_S_STATE_COUNT] = {
        "\\_S0_",
        "\\_S1_",
@@ -183,10 +101,45 @@ const char *acpi_gbl_highest_dstate_names[4] = {
 
 /*******************************************************************************
  *
- * Namespace globals
+ * FUNCTION:    acpi_format_exception
+ *
+ * PARAMETERS:  Status       - The acpi_status code to be formatted
+ *
+ * RETURN:      A string containing the exception text. A valid pointer is
+ *              always returned.
+ *
+ * DESCRIPTION: This function translates an ACPI exception into an ASCII string
+ *              It is here instead of utxface.c so it is always present.
  *
  ******************************************************************************/
 
+const char *acpi_format_exception(acpi_status status)
+{
+       const char *exception = NULL;
+
+       ACPI_FUNCTION_ENTRY();
+
+       exception = acpi_ut_validate_exception(status);
+       if (!exception) {
+
+               /* Exception code was not recognized */
+
+               ACPI_ERROR((AE_INFO,
+                           "Unknown exception code: 0x%8.8X", status));
+
+               exception = "UNKNOWN_STATUS_CODE";
+       }
+
+       return (ACPI_CAST_PTR(const char, exception));
+}
+
+ACPI_EXPORT_SYMBOL(acpi_format_exception)
+
+/*******************************************************************************
+ *
+ * Namespace globals
+ *
+ ******************************************************************************/
 /*
  * Predefined ACPI Names (Built-in to the Interpreter)
  *
@@ -280,53 +233,6 @@ char acpi_ut_hex_to_ascii_char(acpi_integer integer, u32 position)
        return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]);
 }
 
-/*******************************************************************************
- *
- * Table name globals
- *
- * NOTE: This table includes ONLY the ACPI tables that the subsystem consumes.
- * it is NOT an exhaustive list of all possible ACPI tables.  All ACPI tables
- * that are not used by the subsystem are simply ignored.
- *
- * Do NOT add any table to this list that is not consumed directly by this
- * subsystem (No MADT, ECDT, SBST, etc.)
- *
- ******************************************************************************/
-
-struct acpi_table_list acpi_gbl_table_lists[ACPI_TABLE_ID_MAX + 1];
-
-struct acpi_table_support acpi_gbl_table_data[ACPI_TABLE_ID_MAX + 1] = {
-       /***********    Name,   Signature, Global typed pointer     Signature size,      Type                  How many allowed?,    Contains valid AML? */
-
-       /* RSDP 0 */ {RSDP_NAME, RSDP_SIG, NULL, sizeof(RSDP_SIG) - 1,
-                     ACPI_TABLE_ROOT | ACPI_TABLE_SINGLE}
-       ,
-       /* DSDT 1 */ {DSDT_SIG, DSDT_SIG, (void *)&acpi_gbl_DSDT,
-                     sizeof(DSDT_SIG) - 1,
-                     ACPI_TABLE_SECONDARY | ACPI_TABLE_SINGLE |
-                     ACPI_TABLE_EXECUTABLE}
-       ,
-       /* FADT 2 */ {FADT_SIG, FADT_SIG, (void *)&acpi_gbl_FADT,
-                     sizeof(FADT_SIG) - 1,
-                     ACPI_TABLE_PRIMARY | ACPI_TABLE_SINGLE}
-       ,
-       /* FACS 3 */ {FACS_SIG, FACS_SIG, (void *)&acpi_gbl_FACS,
-                     sizeof(FACS_SIG) - 1,
-                     ACPI_TABLE_SECONDARY | ACPI_TABLE_SINGLE}
-       ,
-       /* PSDT 4 */ {PSDT_SIG, PSDT_SIG, NULL, sizeof(PSDT_SIG) - 1,
-                     ACPI_TABLE_PRIMARY | ACPI_TABLE_MULTIPLE |
-                     ACPI_TABLE_EXECUTABLE}
-       ,
-       /* SSDT 5 */ {SSDT_SIG, SSDT_SIG, NULL, sizeof(SSDT_SIG) - 1,
-                     ACPI_TABLE_PRIMARY | ACPI_TABLE_MULTIPLE |
-                     ACPI_TABLE_EXECUTABLE}
-       ,
-       /* XSDT 6 */ {XSDT_SIG, XSDT_SIG, NULL, sizeof(RSDT_SIG) - 1,
-                     ACPI_TABLE_ROOT | ACPI_TABLE_SINGLE}
-       ,
-};
-
 /******************************************************************************
  *
  * Event and Hardware globals
@@ -612,7 +518,7 @@ char *acpi_ut_get_node_name(void *object)
        /* Name must be a valid ACPI name */
 
        if (!acpi_ut_valid_acpi_name(node->name.integer)) {
-               node->name.integer = acpi_ut_repair_name(node->name.integer);
+               node->name.integer = acpi_ut_repair_name(node->name.ascii);
        }
 
        /* Return the name */
@@ -751,13 +657,6 @@ void acpi_ut_init_globals(void)
                return;
        }
 
-       /* ACPI table structure */
-
-       for (i = 0; i < (ACPI_TABLE_ID_MAX + 1); i++) {
-               acpi_gbl_table_lists[i].next = NULL;
-               acpi_gbl_table_lists[i].count = 0;
-       }
-
        /* Mutex locked flags */
 
        for (i = 0; i < ACPI_NUM_MUTEX; i++) {
@@ -773,6 +672,7 @@ void acpi_ut_init_globals(void)
 
        /* GPE support */
 
+       acpi_gpe_count = 0;
        acpi_gbl_gpe_xrupt_list_head = NULL;
        acpi_gbl_gpe_fadt_blocks[0] = NULL;
        acpi_gbl_gpe_fadt_blocks[1] = NULL;
@@ -784,25 +684,15 @@ void acpi_ut_init_globals(void)
        acpi_gbl_exception_handler = NULL;
        acpi_gbl_init_handler = NULL;
 
-       /* Global "typed" ACPI table pointers */
-
-       acpi_gbl_RSDP = NULL;
-       acpi_gbl_XSDT = NULL;
-       acpi_gbl_FACS = NULL;
-       acpi_gbl_FADT = NULL;
-       acpi_gbl_DSDT = NULL;
-
        /* Global Lock support */
 
        acpi_gbl_global_lock_semaphore = NULL;
+       acpi_gbl_global_lock_mutex = NULL;
        acpi_gbl_global_lock_acquired = FALSE;
-       acpi_gbl_global_lock_thread_count = 0;
        acpi_gbl_global_lock_handle = 0;
 
        /* Miscellaneous variables */
 
-       acpi_gbl_table_flags = ACPI_PHYSICAL_POINTER;
-       acpi_gbl_rsdp_original_location = 0;
        acpi_gbl_cm_single_step = FALSE;
        acpi_gbl_db_terminate_threads = FALSE;
        acpi_gbl_shutdown = FALSE;
@@ -837,8 +727,13 @@ void acpi_ut_init_globals(void)
        acpi_gbl_lowest_stack_pointer = ACPI_SIZE_MAX;
 #endif
 
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+       acpi_gbl_display_final_mem_stats = FALSE;
+#endif
+
        return_VOID;
 }
 
 ACPI_EXPORT_SYMBOL(acpi_dbg_level)
 ACPI_EXPORT_SYMBOL(acpi_dbg_layer)
+ACPI_EXPORT_SYMBOL(acpi_gpe_count)
index ff76055eb7d61a3e1b999b60e19d2de2507a1d23..ad3c0d0a5cf8fa67d40b5cea3b7e4bc311bd2cf9 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include <acpi/acpi.h>
 #include <acpi/acnamesp.h>
 #include <acpi/acevents.h>
+#include <acpi/actables.h>
 
 #define _COMPONENT          ACPI_UTILITIES
 ACPI_MODULE_NAME("utinit")
 
 /* Local prototypes */
-static void
-acpi_ut_fadt_register_error(char *register_name, u32 value, u8 offset);
-
 static void acpi_ut_terminate(void);
 
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ut_fadt_register_error
- *
- * PARAMETERS:  register_name           - Pointer to string identifying register
- *              Value                   - Actual register contents value
- *              Offset                  - Byte offset in the FADT
- *
- * RETURN:      AE_BAD_VALUE
- *
- * DESCRIPTION: Display failure message
- *
- ******************************************************************************/
-
-static void
-acpi_ut_fadt_register_error(char *register_name, u32 value, u8 offset)
-{
-
-       ACPI_WARNING((AE_INFO,
-                     "Invalid FADT value %s=%X at offset %X FADT=%p",
-                     register_name, value, offset, acpi_gbl_FADT));
-}
-
-/******************************************************************************
- *
- * FUNCTION:    acpi_ut_validate_fadt
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Validate various ACPI registers in the FADT
- *
- ******************************************************************************/
-
-acpi_status acpi_ut_validate_fadt(void)
-{
-
-       /*
-        * Verify Fixed ACPI Description Table fields,
-        * but don't abort on any problems, just display error
-        */
-       if (acpi_gbl_FADT->pm1_evt_len < 4) {
-               acpi_ut_fadt_register_error("PM1_EVT_LEN",
-                                           (u32) acpi_gbl_FADT->pm1_evt_len,
-                                           ACPI_FADT_OFFSET(pm1_evt_len));
-       }
-
-       if (!acpi_gbl_FADT->pm1_cnt_len) {
-               acpi_ut_fadt_register_error("PM1_CNT_LEN", 0,
-                                           ACPI_FADT_OFFSET(pm1_cnt_len));
-       }
-
-       if (!acpi_gbl_FADT->xpm1a_evt_blk.address) {
-               acpi_ut_fadt_register_error("X_PM1a_EVT_BLK", 0,
-                                           ACPI_FADT_OFFSET(xpm1a_evt_blk.
-                                                            address));
-       }
-
-       if (!acpi_gbl_FADT->xpm1a_cnt_blk.address) {
-               acpi_ut_fadt_register_error("X_PM1a_CNT_BLK", 0,
-                                           ACPI_FADT_OFFSET(xpm1a_cnt_blk.
-                                                            address));
-       }
-
-       if (!acpi_gbl_FADT->xpm_tmr_blk.address) {
-               acpi_ut_fadt_register_error("X_PM_TMR_BLK", 0,
-                                           ACPI_FADT_OFFSET(xpm_tmr_blk.
-                                                            address));
-       }
-
-       if ((acpi_gbl_FADT->xpm2_cnt_blk.address &&
-            !acpi_gbl_FADT->pm2_cnt_len)) {
-               acpi_ut_fadt_register_error("PM2_CNT_LEN",
-                                           (u32) acpi_gbl_FADT->pm2_cnt_len,
-                                           ACPI_FADT_OFFSET(pm2_cnt_len));
-       }
-
-       if (acpi_gbl_FADT->pm_tm_len < 4) {
-               acpi_ut_fadt_register_error("PM_TM_LEN",
-                                           (u32) acpi_gbl_FADT->pm_tm_len,
-                                           ACPI_FADT_OFFSET(pm_tm_len));
-       }
-
-       /* Length of GPE blocks must be a multiple of 2 */
-
-       if (acpi_gbl_FADT->xgpe0_blk.address &&
-           (acpi_gbl_FADT->gpe0_blk_len & 1)) {
-               acpi_ut_fadt_register_error("(x)GPE0_BLK_LEN",
-                                           (u32) acpi_gbl_FADT->gpe0_blk_len,
-                                           ACPI_FADT_OFFSET(gpe0_blk_len));
-       }
-
-       if (acpi_gbl_FADT->xgpe1_blk.address &&
-           (acpi_gbl_FADT->gpe1_blk_len & 1)) {
-               acpi_ut_fadt_register_error("(x)GPE1_BLK_LEN",
-                                           (u32) acpi_gbl_FADT->gpe1_blk_len,
-                                           ACPI_FADT_OFFSET(gpe1_blk_len));
-       }
-
-       return (AE_OK);
-}
-
 /******************************************************************************
  *
  * FUNCTION:    acpi_ut_terminate
@@ -178,7 +73,6 @@ static void acpi_ut_terminate(void)
 
        ACPI_FUNCTION_TRACE(ut_terminate);
 
-       /* Free global tables, etc. */
        /* Free global GPE blocks and related info structures */
 
        gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
@@ -239,6 +133,10 @@ void acpi_ut_subsystem_shutdown(void)
 
        acpi_ns_terminate();
 
+       /* Delete the ACPI tables */
+
+       acpi_tb_terminate();
+
        /* Close the globals */
 
        acpi_ut_terminate();
index 19d74bedce27485cc519d3168801cdaa63e0aa1b..0c56a0d20b29064fd375f50418feafc89fca1922 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 6d8a8211be90a4f84abf2ad8efb62c8a3c9cabfa..50133fffe42045f7b1155e2edb8edd2ca6900529 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define _COMPONENT          ACPI_UTILITIES
 ACPI_MODULE_NAME("utmisc")
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ut_validate_exception
+ *
+ * PARAMETERS:  Status       - The acpi_status code to be formatted
+ *
+ * RETURN:      A string containing the exception text. NULL if exception is
+ *              not valid.
+ *
+ * DESCRIPTION: This function validates and translates an ACPI exception into
+ *              an ASCII string.
+ *
+ ******************************************************************************/
+const char *acpi_ut_validate_exception(acpi_status status)
+{
+       acpi_status sub_status;
+       const char *exception = NULL;
+
+       ACPI_FUNCTION_ENTRY();
+
+       /*
+        * Status is composed of two parts, a "type" and an actual code
+        */
+       sub_status = (status & ~AE_CODE_MASK);
+
+       switch (status & AE_CODE_MASK) {
+       case AE_CODE_ENVIRONMENTAL:
+
+               if (sub_status <= AE_CODE_ENV_MAX) {
+                       exception = acpi_gbl_exception_names_env[sub_status];
+               }
+               break;
+
+       case AE_CODE_PROGRAMMER:
+
+               if (sub_status <= AE_CODE_PGM_MAX) {
+                       exception =
+                           acpi_gbl_exception_names_pgm[sub_status - 1];
+               }
+               break;
+
+       case AE_CODE_ACPI_TABLES:
+
+               if (sub_status <= AE_CODE_TBL_MAX) {
+                       exception =
+                           acpi_gbl_exception_names_tbl[sub_status - 1];
+               }
+               break;
+
+       case AE_CODE_AML:
+
+               if (sub_status <= AE_CODE_AML_MAX) {
+                       exception =
+                           acpi_gbl_exception_names_aml[sub_status - 1];
+               }
+               break;
+
+       case AE_CODE_CONTROL:
+
+               if (sub_status <= AE_CODE_CTRL_MAX) {
+                       exception =
+                           acpi_gbl_exception_names_ctrl[sub_status - 1];
+               }
+               break;
+
+       default:
+               break;
+       }
+
+       return (ACPI_CAST_PTR(const char, exception));
+}
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ut_is_aml_table
@@ -62,14 +134,15 @@ ACPI_MODULE_NAME("utmisc")
  *              data tables that do not contain AML code.
  *
  ******************************************************************************/
+
 u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
 {
 
        /* These are the only tables that contain executable AML */
 
-       if (ACPI_COMPARE_NAME(table->signature, DSDT_SIG) ||
-           ACPI_COMPARE_NAME(table->signature, PSDT_SIG) ||
-           ACPI_COMPARE_NAME(table->signature, SSDT_SIG)) {
+       if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) ||
+           ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) ||
+           ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
                return (TRUE);
        }
 
@@ -418,7 +491,7 @@ u32 acpi_ut_dword_byte_swap(u32 value)
 void acpi_ut_set_integer_width(u8 revision)
 {
 
-       if (revision <= 1) {
+       if (revision < 2) {
 
                /* 32-bit case */
 
@@ -582,26 +655,25 @@ u8 acpi_ut_valid_acpi_name(u32 name)
  *
  ******************************************************************************/
 
-acpi_name acpi_ut_repair_name(acpi_name name)
+acpi_name acpi_ut_repair_name(char *name)
 {
-       char *name_ptr = ACPI_CAST_PTR(char, &name);
-       char new_name[ACPI_NAME_SIZE];
        acpi_native_uint i;
+       char new_name[ACPI_NAME_SIZE];
 
        for (i = 0; i < ACPI_NAME_SIZE; i++) {
-               new_name[i] = name_ptr[i];
+               new_name[i] = name[i];
 
                /*
                 * Replace a bad character with something printable, yet technically
                 * still invalid. This prevents any collisions with existing "good"
                 * names in the namespace.
                 */
-               if (!acpi_ut_valid_acpi_char(name_ptr[i], i)) {
+               if (!acpi_ut_valid_acpi_char(name[i], i)) {
                        new_name[i] = '*';
                }
        }
 
-       return (*ACPI_CAST_PTR(u32, new_name));
+       return (*(u32 *) new_name);
 }
 
 /*******************************************************************************
@@ -996,9 +1068,13 @@ acpi_ut_info(char *module_name, u32 line_number, char *format, ...)
 {
        va_list args;
 
-       acpi_os_printf("ACPI (%s-%04d): ", module_name, line_number);
+       /*
+        * Removed module_name, line_number, and acpica version, not needed
+        * for info output
+        */
+       acpi_os_printf("ACPI: ");
 
        va_start(args, format);
        acpi_os_vprintf(format, args);
-       acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
+       acpi_os_printf("\n");
 }
index 180e73ceb6e2cc6566c7855563adc09e48bac8af..cbad2ef5987d1a52e9f89c3bd78a1c180447d33d 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index ba7d8ac702df959f7198038182f94af09efba3a6..4696124759e1546b16cde08d99d15bcc4515abb2 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 5a2de92831d317c5b04cc9138d37512c29539ecd..e8fe1ba6cc243f705caf9c940d472b9846dc7e46 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index eaa13d05c859cd0ec20ba6543984ada6da747ff3..edcaafad0a31f6f0af4cd03487555c99f0c193fe 100644 (file)
@@ -5,7 +5,7 @@
  ******************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 3538f69c82a1cac6de72067d5659cdfaaaa00fa1..de3276f4f4683ec4aee9fb4a794ec9ace654636f 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -67,6 +67,7 @@ acpi_status acpi_initialize_subsystem(void)
 
        ACPI_FUNCTION_TRACE(acpi_initialize_subsystem);
 
+       acpi_gbl_startup_flags = ACPI_SUBSYSTEM_INITIALIZE;
        ACPI_DEBUG_EXEC(acpi_ut_init_stack_ptr_trace());
 
        /* Initialize the OS-Dependent layer */
@@ -127,20 +128,6 @@ acpi_status acpi_enable_subsystem(u32 flags)
 
        ACPI_FUNCTION_TRACE(acpi_enable_subsystem);
 
-       /*
-        * We must initialize the hardware before we can enable ACPI.
-        * The values from the FADT are validated here.
-        */
-       if (!(flags & ACPI_NO_HARDWARE_INIT)) {
-               ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
-                                 "[Init] Initializing ACPI hardware\n"));
-
-               status = acpi_hw_initialize();
-               if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
-               }
-       }
-
        /* Enable ACPI mode */
 
        if (!(flags & ACPI_NO_ACPI_ENABLE)) {
@@ -398,7 +385,6 @@ acpi_status acpi_get_system_info(struct acpi_buffer * out_buffer)
 {
        struct acpi_system_info *info_ptr;
        acpi_status status;
-       u32 i;
 
        ACPI_FUNCTION_TRACE(acpi_get_system_info);
 
@@ -431,9 +417,7 @@ acpi_status acpi_get_system_info(struct acpi_buffer * out_buffer)
 
        /* Timer resolution - 24 or 32 bits  */
 
-       if (!acpi_gbl_FADT) {
-               info_ptr->timer_resolution = 0;
-       } else if (acpi_gbl_FADT->tmr_val_ext == 0) {
+       if (acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER) {
                info_ptr->timer_resolution = 24;
        } else {
                info_ptr->timer_resolution = 32;
@@ -449,13 +433,6 @@ acpi_status acpi_get_system_info(struct acpi_buffer * out_buffer)
        info_ptr->debug_layer = acpi_dbg_layer;
        info_ptr->debug_level = acpi_dbg_level;
 
-       /* Current status of the ACPI tables, per table type */
-
-       info_ptr->num_table_types = ACPI_TABLE_ID_MAX + 1;
-       for (i = 0; i < (ACPI_TABLE_ID_MAX + 1); i++) {
-               info_ptr->table_info[i].count = acpi_gbl_table_lists[i].count;
-       }
-
        return_ACPI_STATUS(AE_OK);
 }
 
index 3d54680d0333c34464b1df9e5fe2631b63050079..e0b97add8c6355274cb220b04352c9927263b5d2 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 
+#include <linux/backlight.h>
 #include <asm/uaccess.h>
 
 #include <acpi/acpi_bus.h>
 
 #define ACPI_VIDEO_HEAD_INVALID                (~0u - 1)
 #define ACPI_VIDEO_HEAD_END            (~0u)
+#define MAX_NAME_LEN   20
+
+#define ACPI_VIDEO_DISPLAY_CRT 1
+#define ACPI_VIDEO_DISPLAY_TV  2
+#define ACPI_VIDEO_DISPLAY_DVI 3
+#define ACPI_VIDEO_DISPLAY_LCD 4
 
 #define _COMPONENT             ACPI_VIDEO_COMPONENT
 ACPI_MODULE_NAME("acpi_video")
@@ -66,16 +73,14 @@ MODULE_LICENSE("GPL");
 
 static int acpi_video_bus_add(struct acpi_device *device);
 static int acpi_video_bus_remove(struct acpi_device *device, int type);
-static int acpi_video_bus_match(struct acpi_device *device,
-                               struct acpi_driver *driver);
 
 static struct acpi_driver acpi_video_bus = {
        .name = ACPI_VIDEO_DRIVER_NAME,
        .class = ACPI_VIDEO_CLASS,
+       .ids = ACPI_VIDEO_HID,
        .ops = {
                .add = acpi_video_bus_add,
                .remove = acpi_video_bus_remove,
-               .match = acpi_video_bus_match,
                },
 };
 
@@ -133,20 +138,21 @@ struct acpi_video_device_flags {
        u8 crt:1;
        u8 lcd:1;
        u8 tvout:1;
+       u8 dvi:1;
        u8 bios:1;
        u8 unknown:1;
-       u8 reserved:3;
+       u8 reserved:2;
 };
 
 struct acpi_video_device_cap {
        u8 _ADR:1;              /*Return the unique ID */
        u8 _BCL:1;              /*Query list of brightness control levels supported */
        u8 _BCM:1;              /*Set the brightness level */
+       u8 _BQC:1;              /* Get current brightness level */
        u8 _DDC:1;              /*Return the EDID for this device */
        u8 _DCS:1;              /*Return status of output device */
        u8 _DGS:1;              /*Query graphics state */
        u8 _DSS:1;              /*Device state set */
-       u8 _reserved:1;
 };
 
 struct acpi_video_device_brightness {
@@ -163,6 +169,8 @@ struct acpi_video_device {
        struct acpi_video_bus *video;
        struct acpi_device *dev;
        struct acpi_video_device_brightness *brightness;
+       struct backlight_device *backlight;
+       struct backlight_properties *data;
 };
 
 /* bus */
@@ -257,11 +265,35 @@ static void acpi_video_device_bind(struct acpi_video_bus *video,
                                   struct acpi_video_device *device);
 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
 static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
+static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
+                       int level);
+static int acpi_video_device_lcd_get_level_current(
+                       struct acpi_video_device *device,
+                       unsigned long *level);
 static int acpi_video_get_next_level(struct acpi_video_device *device,
                                     u32 level_current, u32 event);
 static void acpi_video_switch_brightness(struct acpi_video_device *device,
                                         int event);
 
+/*backlight device sysfs support*/
+static int acpi_video_get_brightness(struct backlight_device *bd)
+{
+       unsigned long cur_level;
+       struct acpi_video_device *vd =
+               (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
+       acpi_video_device_lcd_get_level_current(vd, &cur_level);
+       return (int) cur_level;
+}
+
+static int acpi_video_set_brightness(struct backlight_device *bd)
+{
+       int request_level = bd->props->brightness;
+       struct acpi_video_device *vd =
+               (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
+       acpi_video_device_lcd_set_level(vd, request_level);
+       return 0;
+}
+
 /* --------------------------------------------------------------------------
                                Video Management
    -------------------------------------------------------------------------- */
@@ -499,6 +531,7 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
        acpi_integer status;
        acpi_handle h_dummy1;
        int i;
+       u32 max_level = 0;
        union acpi_object *obj = NULL;
        struct acpi_video_device_brightness *br = NULL;
 
@@ -514,6 +547,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
        if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
                device->cap._BCM = 1;
        }
+       if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
+               device->cap._BQC = 1;
        if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
                device->cap._DDC = 1;
        }
@@ -550,6 +585,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
                                        continue;
                                }
                                br->levels[count] = (u32) o->integer.value;
+                               if (br->levels[count] > max_level)
+                                       max_level = br->levels[count];
                                count++;
                        }
                      out:
@@ -568,6 +605,37 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
 
        kfree(obj);
 
+       if (device->cap._BCL && device->cap._BCM && device->cap._BQC){
+               unsigned long tmp;
+               static int count = 0;
+               char *name;
+               struct backlight_properties *acpi_video_data;
+
+               name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
+               if (!name)
+                       return;
+
+               acpi_video_data = kzalloc(
+                       sizeof(struct backlight_properties),
+                       GFP_KERNEL);
+               if (!acpi_video_data){
+                       kfree(name);
+                       return;
+               }
+               acpi_video_data->owner = THIS_MODULE;
+               acpi_video_data->get_brightness =
+                       acpi_video_get_brightness;
+               acpi_video_data->update_status =
+                       acpi_video_set_brightness;
+               sprintf(name, "acpi_video%d", count++);
+               device->data = acpi_video_data;
+               acpi_video_data->max_brightness = max_level;
+               acpi_video_device_lcd_get_level_current(device, &tmp);
+               acpi_video_data->brightness = (int)tmp;
+               device->backlight = backlight_device_register(name,
+                       NULL, device, acpi_video_data);
+               kfree(name);
+       }
        return;
 }
 
@@ -668,6 +736,8 @@ static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
                seq_printf(seq, "LCD\n");
        else if (dev->flags.tvout)
                seq_printf(seq, "TVOUT\n");
+       else if (dev->flags.dvi)
+               seq_printf(seq, "DVI\n");
        else
                seq_printf(seq, "UNKNOWN\n");
 
@@ -1242,6 +1312,16 @@ static int acpi_video_bus_remove_fs(struct acpi_device *device)
    -------------------------------------------------------------------------- */
 
 /* device interface */
+static struct acpi_video_device_attrib*
+acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
+{
+       int count;
+
+       for(count = 0; count < video->attached_count; count++)
+               if((video->attached_array[count].value.int_val & 0xffff) == device_id)
+                       return &(video->attached_array[count].value.attrib);
+       return NULL;
+}
 
 static int
 acpi_video_bus_get_one_device(struct acpi_device *device,
@@ -1250,7 +1330,7 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
        unsigned long device_id;
        int status;
        struct acpi_video_device *data;
-
+       struct acpi_video_device_attrib* attribute;
 
        if (!device || !video)
                return -EINVAL;
@@ -1271,20 +1351,30 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
                data->video = video;
                data->dev = device;
 
-               switch (device_id & 0xffff) {
-               case 0x0100:
-                       data->flags.crt = 1;
-                       break;
-               case 0x0400:
-                       data->flags.lcd = 1;
-                       break;
-               case 0x0200:
-                       data->flags.tvout = 1;
-                       break;
-               default:
+               attribute = acpi_video_get_device_attr(video, device_id);
+
+               if((attribute != NULL) && attribute->device_id_scheme) {
+                       switch (attribute->display_type) {
+                       case ACPI_VIDEO_DISPLAY_CRT:
+                               data->flags.crt = 1;
+                               break;
+                       case ACPI_VIDEO_DISPLAY_TV:
+                               data->flags.tvout = 1;
+                               break;
+                       case ACPI_VIDEO_DISPLAY_DVI:
+                               data->flags.dvi = 1;
+                               break;
+                       case ACPI_VIDEO_DISPLAY_LCD:
+                               data->flags.lcd = 1;
+                               break;
+                       default:
+                               data->flags.unknown = 1;
+                               break;
+                       }
+                       if(attribute->bios_can_detect)
+                               data->flags.bios = 1;
+               } else
                        data->flags.unknown = 1;
-                       break;
-               }
 
                acpi_video_device_bind(video, data);
                acpi_video_device_find_cap(data);
@@ -1588,7 +1678,10 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
        status = acpi_remove_notify_handler(device->dev->handle,
                                            ACPI_DEVICE_NOTIFY,
                                            acpi_video_device_notify);
-
+       if (device->backlight){
+               backlight_device_unregister(device->backlight);
+               kfree(device->data);
+       }
        return 0;
 }
 
@@ -1790,39 +1883,6 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
        return 0;
 }
 
-static int
-acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver)
-{
-       acpi_handle h_dummy1;
-       acpi_handle h_dummy2;
-       acpi_handle h_dummy3;
-
-
-       if (!device || !driver)
-               return -EINVAL;
-
-       /* Since there is no HID, CID for ACPI Video drivers, we have
-        * to check well known required nodes for each feature we support.
-        */
-
-       /* Does this device able to support video switching ? */
-       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
-           ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
-               return 0;
-
-       /* Does this device able to retrieve a video ROM ? */
-       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
-               return 0;
-
-       /* Does this device able to configure which video head to be POSTed ? */
-       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
-           ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
-           ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
-               return 0;
-
-       return -ENODEV;
-}
-
 static int __init acpi_video_init(void)
 {
        int result = 0;
index f1afd26a509fa037b3e777a7d3dbe3c5d176bba1..a7b33d2f5991c84fd332ff15dab1145161c1c089 100644 (file)
@@ -1802,7 +1802,7 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
            return -ENODEV;
        }
 
-       if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
+       if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
                addr_space = IPMI_MEM_ADDR_SPACE;
        else
                addr_space = IPMI_IO_ADDR_SPACE;
@@ -1848,19 +1848,19 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
                info->irq_setup = NULL;
        }
 
-       if (spmi->addr.register_bit_width) {
+       if (spmi->addr.bit_width) {
                /* A (hopefully) properly formed register bit width. */
-               info->io.regspacing = spmi->addr.register_bit_width / 8;
+               info->io.regspacing = spmi->addr.bit_width / 8;
        } else {
                info->io.regspacing = DEFAULT_REGSPACING;
        }
        info->io.regsize = info->io.regspacing;
-       info->io.regshift = spmi->addr.register_bit_offset;
+       info->io.regshift = spmi->addr.bit_offset;
 
-       if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
+       if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
                info->io_setup = mem_setup;
                info->io.addr_type = IPMI_IO_ADDR_SPACE;
-       } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
+       } else if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
                info->io_setup = port_setup;
                info->io.addr_type = IPMI_MEM_ADDR_SPACE;
        } else {
@@ -1888,10 +1888,8 @@ static __devinit void acpi_find_bmc(void)
                return;
 
        for (i = 0; ; i++) {
-               status = acpi_get_firmware_table("SPMI", i+1,
-                                                ACPI_LOGICAL_ADDRESSING,
-                                                (struct acpi_table_header **)
-                                                &spmi);
+               status = acpi_get_table(ACPI_SIG_SPMI, i+1,
+                                       (struct acpi_table_header **)&spmi);
                if (status != AE_OK)
                        return;
 
index a611972024e65942edb58b23d8d176ec6ae456cb..7fca5f470bebf9109313b3e69a458cd6d8cf9003 100644 (file)
@@ -372,10 +372,8 @@ static int read_log(struct tpm_bios_log *log)
        }
 
        /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
-       status = acpi_get_firmware_table(ACPI_TCPA_SIG, 1,
-                                        ACPI_LOGICAL_ADDRESSING,
-                                        (struct acpi_table_header **)
-                                        &buff);
+       status = acpi_get_table(ACPI_SIG_TCPA, 1,
+                               (struct acpi_table_header **)&buff);
 
        if (ACPI_FAILURE(status)) {
                printk(KERN_ERR "%s: ERROR - Could not get TCPA table\n",
@@ -409,7 +407,7 @@ static int read_log(struct tpm_bios_log *log)
 
        log->bios_event_log_end = log->bios_event_log + len;
 
-       acpi_os_map_memory(start, len, (void *) &virt);
+       virt = acpi_os_map_memory(start, len);
 
        memcpy(log->bios_event_log, virt, len);
 
index c2ad72fefd9d50a8f447062ad8a3e1daf8489519..2b4b76e8bd723ac25b6aa57b55cf57e23736297a 100644 (file)
@@ -26,7 +26,7 @@ setup_serial_console(struct pcdp_uart *uart)
        static char options[64], *p = options;
        char parity;
 
-       mmio = (uart->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
+       mmio = (uart->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
        p += sprintf(p, "console=uart,%s,0x%lx",
                mmio ? "mmio" : "io", uart->addr.address);
        if (uart->baud) {
index 00db31c314e0d9d30a8287eed91cea12de375665..89bba277da5f9c81f1ba2a72c70a903bc1b288c7 100644 (file)
@@ -69,6 +69,25 @@ config TIFM_7XX1
           To compile this driver as a module, choose M here: the module will
          be called tifm_7xx1.
 
+config ASUS_LAPTOP
+        tristate "Asus Laptop Extras (EXPERIMENTAL)"
+        depends on X86
+        depends on ACPI
+       depends on EXPERIMENTAL && !ACPI_ASUS
+       depends on LEDS_CLASS
+       depends on BACKLIGHT_CLASS_DEVICE
+        ---help---
+         This is the new Linux driver for Asus laptops. It may also support some
+         MEDION, JVC or VICTOR laptops. It makes all the extra buttons generate
+         standard ACPI events that go through /proc/acpi/events. It also adds
+         support for video output switching, LCD backlight control, Bluetooth and
+         Wlan control, and most importantly, allows you to blink those fancy LEDs.
+
+         For more information and a userspace daemon for handling the extra
+         buttons see <http://acpi4asus.sf.net/>.
+
+         If you have an ACPI-compatible ASUS laptop, say Y or M here.
+
 config MSI_LAPTOP
         tristate "MSI Laptop Extras"
         depends on X86
index c9e98ab021c5b096658012057a8e58542bbb1eef..35da53c409c02c8f43b0bf81539e7988c2387c08 100644 (file)
@@ -6,6 +6,7 @@ obj- := misc.o  # Dummy rule to force built-in.o to be made
 obj-$(CONFIG_IBM_ASM)          += ibmasm/
 obj-$(CONFIG_HDPU_FEATURES)    += hdpuftrs/
 obj-$(CONFIG_MSI_LAPTOP)     += msi-laptop.o
+obj-$(CONFIG_ASUS_LAPTOP)     += asus-laptop.o
 obj-$(CONFIG_LKDTM)            += lkdtm.o
 obj-$(CONFIG_TIFM_CORE)        += tifm_core.o
 obj-$(CONFIG_TIFM_7XX1)        += tifm_7xx1.o
diff --git a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c
new file mode 100644 (file)
index 0000000..861c399
--- /dev/null
@@ -0,0 +1,1165 @@
+/*
+ *  asus-laptop.c - Asus Laptop Support
+ *
+ *
+ *  Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
+ *  Copyright (C) 2006 Corentin Chary
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *
+ *  The development page for this driver is located at
+ *  http://sourceforge.net/projects/acpi4asus/
+ *
+ *  Credits:
+ *  Pontus Fuchs   - Helper functions, cleanup
+ *  Johann Wiesner - Small compile fixes
+ *  John Belmonte  - ACPI code for Toshiba laptop was a good starting point.
+ *  Eric Burghard  - LED display support for W1N
+ *  Josh Green     - Light Sens support
+ *  Thomas Tuttle  - His first patch for led support was very helpfull
+ *
+ */
+
+#include <linux/autoconf.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/err.h>
+#include <linux/proc_fs.h>
+#include <linux/backlight.h>
+#include <linux/fb.h>
+#include <linux/leds.h>
+#include <linux/platform_device.h>
+#include <acpi/acpi_drivers.h>
+#include <acpi/acpi_bus.h>
+#include <asm/uaccess.h>
+
+#define ASUS_LAPTOP_VERSION "0.40"
+
+#define ASUS_HOTK_NAME          "Asus Laptop Support"
+#define ASUS_HOTK_CLASS         "hotkey"
+#define ASUS_HOTK_DEVICE_NAME   "Hotkey"
+#define ASUS_HOTK_HID           "ATK0100"
+#define ASUS_HOTK_FILE          "asus-laptop"
+#define ASUS_HOTK_PREFIX        "\\_SB.ATKD."
+
+/*
+ * Some events we use, same for all Asus
+ */
+#define ATKD_BR_UP       0x10
+#define ATKD_BR_DOWN     0x20
+#define ATKD_LCD_ON      0x33
+#define ATKD_LCD_OFF     0x34
+
+/*
+ * Known bits returned by \_SB.ATKD.HWRS
+ */
+#define WL_HWRS     0x80
+#define BT_HWRS     0x100
+
+/*
+ * Flags for hotk status
+ * WL_ON and BT_ON are also used for wireless_status()
+ */
+#define WL_ON       0x01       //internal Wifi
+#define BT_ON       0x02       //internal Bluetooth
+#define MLED_ON     0x04       //mail LED
+#define TLED_ON     0x08       //touchpad LED
+#define RLED_ON     0x10       //Record LED
+#define PLED_ON     0x20       //Phone LED
+#define LCD_ON      0x40       //LCD backlight
+
+#define ASUS_LOG    ASUS_HOTK_FILE ": "
+#define ASUS_ERR    KERN_ERR    ASUS_LOG
+#define ASUS_WARNING    KERN_WARNING    ASUS_LOG
+#define ASUS_NOTICE KERN_NOTICE ASUS_LOG
+#define ASUS_INFO   KERN_INFO   ASUS_LOG
+#define ASUS_DEBUG  KERN_DEBUG  ASUS_LOG
+
+MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
+MODULE_DESCRIPTION(ASUS_HOTK_NAME);
+MODULE_LICENSE("GPL");
+
+#define ASUS_HANDLE(object, paths...)                                  \
+       static acpi_handle  object##_handle = NULL;                     \
+       static char *object##_paths[] = { paths }
+
+/* LED */
+ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
+ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
+ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED");        /* W1JC */
+ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED");        /* A7J */
+
+/* LEDD */
+ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
+
+/* Bluetooth and WLAN
+ * WLED and BLED are not handled like other XLED, because in some dsdt
+ * they also control the WLAN/Bluetooth device.
+ */
+ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
+ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
+ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */
+
+/* Brightness */
+ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV");
+ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV");
+
+/* Backlight */
+ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10",    /* All new models */
+           "\\_SB.PCI0.ISA.EC0._Q10",  /* A1x */
+           "\\_SB.PCI0.PX40.ECD0._Q10",        /* L3C */
+           "\\_SB.PCI0.PX40.EC0.Q10",  /* M1A */
+           "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
+           "\\_SB.PCI0.PX40.Q10",      /* S1x */
+           "\\Q10");           /* A2x, L2D, L3D, M2E */
+
+/* Display */
+ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
+ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD",   /*  A6B, A6K A6R A7D F3JM L4R M6R A3G
+                                                          M6A M6V VX-1 V6J V6V W3Z */
+           "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V
+                                          S5A M5A z33A W1Jc W2V */
+           "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */
+           "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */
+           "\\_SB.PCI0.PCI1.VGAC.NMAP",        /* L3C */
+           "\\_SB.PCI0.VGA.GETD",      /* Z96F */
+           "\\ACTD",           /* A2D */
+           "\\ADVG",           /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
+           "\\DNXT",           /* P30 */
+           "\\INFB",           /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
+           "\\SSTE");          /* A3F A6F A3N A3L M6N W3N W6A */
+
+ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC");       /* Z71A Z71V */
+ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL");        /* Z71A Z71V */
+
+/*
+ * This is the main structure, we can use it to store anything interesting
+ * about the hotk device
+ */
+struct asus_hotk {
+       char *name;             //laptop name
+       struct acpi_device *device;     //the device we are in
+       acpi_handle handle;     //the handle of the hotk device
+       char status;            //status of the hotk, for LEDs, ...
+       u32 ledd_status;        //status of the LED display
+       u8 light_level;         //light sensor level
+       u8 light_switch;        //light sensor switch value
+       u16 event_count[128];   //count for each event TODO make this better
+};
+
+/*
+ * This header is made available to allow proper configuration given model,
+ * revision number , ... this info cannot go in struct asus_hotk because it is
+ * available before the hotk
+ */
+static struct acpi_table_header *asus_info;
+
+/* The actual device the driver binds to */
+static struct asus_hotk *hotk;
+
+/*
+ * The hotkey driver declaration
+ */
+static int asus_hotk_add(struct acpi_device *device);
+static int asus_hotk_remove(struct acpi_device *device, int type);
+static struct acpi_driver asus_hotk_driver = {
+       .name = ASUS_HOTK_NAME,
+       .class = ASUS_HOTK_CLASS,
+       .ids = ASUS_HOTK_HID,
+       .ops = {
+               .add = asus_hotk_add,
+               .remove = asus_hotk_remove,
+               },
+};
+
+/* The backlight device /sys/class/backlight */
+static struct backlight_device *asus_backlight_device;
+
+/*
+ * The backlight class declaration
+ */
+static int read_brightness(struct backlight_device *bd);
+static int update_bl_status(struct backlight_device *bd);
+static struct backlight_properties asusbl_data = {
+       .owner = THIS_MODULE,
+       .get_brightness = read_brightness,
+       .update_status = update_bl_status,
+       .max_brightness = 15,
+};
+
+/* These functions actually update the LED's, and are called from a
+ * workqueue. By doing this as separate work rather than when the LED
+ * subsystem asks, we avoid messing with the Asus ACPI stuff during a
+ * potentially bad time, such as a timer interrupt. */
+static struct workqueue_struct *led_workqueue;
+
+#define ASUS_LED(object, ledname)                                      \
+       static void object##_led_set(struct led_classdev *led_cdev,     \
+                                    enum led_brightness value);        \
+       static void object##_led_update(struct work_struct *ignored);   \
+       static int object##_led_wk;                                     \
+       DECLARE_WORK(object##_led_work, object##_led_update);           \
+       static struct led_classdev object##_led = {                     \
+               .name           = "asus:" ledname,                      \
+               .brightness_set = object##_led_set,                     \
+       }
+
+ASUS_LED(mled, "mail");
+ASUS_LED(tled, "touchpad");
+ASUS_LED(rled, "record");
+ASUS_LED(pled, "phone");
+
+/*
+ * This function evaluates an ACPI method, given an int as parameter, the
+ * method is searched within the scope of the handle, can be NULL. The output
+ * of the method is written is output, which can also be NULL
+ *
+ * returns 1 if write is successful, 0 else.
+ */
+static int write_acpi_int(acpi_handle handle, const char *method, int val,
+                         struct acpi_buffer *output)
+{
+       struct acpi_object_list params; //list of input parameters (an int here)
+       union acpi_object in_obj;       //the only param we use
+       acpi_status status;
+
+       params.count = 1;
+       params.pointer = &in_obj;
+       in_obj.type = ACPI_TYPE_INTEGER;
+       in_obj.integer.value = val;
+
+       status = acpi_evaluate_object(handle, (char *)method, &params, output);
+       return (status == AE_OK);
+}
+
+static int read_acpi_int(acpi_handle handle, const char *method, int *val,
+                        struct acpi_object_list *params)
+{
+       struct acpi_buffer output;
+       union acpi_object out_obj;
+       acpi_status status;
+
+       output.length = sizeof(out_obj);
+       output.pointer = &out_obj;
+
+       status = acpi_evaluate_object(handle, (char *)method, params, &output);
+       *val = out_obj.integer.value;
+       return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
+}
+
+static int read_wireless_status(int mask)
+{
+       int status;
+
+       if (!wireless_status_handle)
+               return (hotk->status & mask) ? 1 : 0;
+
+       if (read_acpi_int(wireless_status_handle, NULL, &status, NULL)) {
+               return (status & mask) ? 1 : 0;
+       } else
+               printk(ASUS_WARNING "Error reading Wireless status\n");
+
+       return (hotk->status & mask) ? 1 : 0;
+}
+
+/* Generic LED functions */
+static int read_status(int mask)
+{
+       /* There is a special method for both wireless devices */
+       if (mask == BT_ON || mask == WL_ON)
+               return read_wireless_status(mask);
+
+       return (hotk->status & mask) ? 1 : 0;
+}
+
+static void write_status(acpi_handle handle, int out, int mask, int invert)
+{
+       hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
+
+       if (invert)             /* invert target value */
+               out = !out & 0x1;
+
+       if (handle && !write_acpi_int(handle, NULL, out, NULL))
+               printk(ASUS_WARNING " write failed\n");
+}
+
+/* /sys/class/led handlers */
+#define ASUS_LED_HANDLER(object, mask, invert)                         \
+       static void object##_led_set(struct led_classdev *led_cdev,     \
+                                    enum led_brightness value)         \
+       {                                                               \
+               object##_led_wk = value;                                \
+               queue_work(led_workqueue, &object##_led_work);          \
+       }                                                               \
+       static void object##_led_update(struct work_struct *ignored)    \
+       {                                                               \
+               int value = object##_led_wk;                            \
+               write_status(object##_set_handle, value, (mask), (invert)); \
+       }
+
+ASUS_LED_HANDLER(mled, MLED_ON, 1);
+ASUS_LED_HANDLER(pled, PLED_ON, 0);
+ASUS_LED_HANDLER(rled, RLED_ON, 0);
+ASUS_LED_HANDLER(tled, TLED_ON, 0);
+
+static int get_lcd_state(void)
+{
+       return read_status(LCD_ON);
+}
+
+static int set_lcd_state(int value)
+{
+       int lcd = 0;
+       acpi_status status = 0;
+
+       lcd = value ? 1 : 0;
+
+       if (lcd == get_lcd_state())
+               return 0;
+
+       if (lcd_switch_handle) {
+               status = acpi_evaluate_object(lcd_switch_handle,
+                                             NULL, NULL, NULL);
+
+               if (ACPI_FAILURE(status))
+                       printk(ASUS_WARNING "Error switching LCD\n");
+       }
+
+       write_status(NULL, lcd, LCD_ON, 0);
+       return 0;
+}
+
+static void lcd_blank(int blank)
+{
+       struct backlight_device *bd = asus_backlight_device;
+
+       if (bd) {
+               down(&bd->sem);
+               if (likely(bd->props)) {
+                       bd->props->power = blank;
+                       if (likely(bd->props->update_status))
+                               bd->props->update_status(bd);
+               }
+               up(&bd->sem);
+       }
+}
+
+static int read_brightness(struct backlight_device *bd)
+{
+       int value;
+
+       if (!read_acpi_int(brightness_get_handle, NULL, &value, NULL))
+               printk(ASUS_WARNING "Error reading brightness\n");
+
+       return value;
+}
+
+static int set_brightness(struct backlight_device *bd, int value)
+{
+       int ret = 0;
+
+       value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
+       /* 0 <= value <= 15 */
+
+       if (!write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
+               printk(ASUS_WARNING "Error changing brightness\n");
+               ret = -EIO;
+       }
+
+       return ret;
+}
+
+static int update_bl_status(struct backlight_device *bd)
+{
+       int rv;
+       int value = bd->props->brightness;
+
+       rv = set_brightness(bd, value);
+       if (rv)
+               return rv;
+
+       value = (bd->props->power == FB_BLANK_UNBLANK) ? 1 : 0;
+       return set_lcd_state(value);
+}
+
+/*
+ * Platform device handlers
+ */
+
+/*
+ * We write our info in page, we begin at offset off and cannot write more
+ * than count bytes. We set eof to 1 if we handle those 2 values. We return the
+ * number of bytes written in page
+ */
+static ssize_t show_infos(struct device *dev,
+                         struct device_attribute *attr, char *page)
+{
+       int len = 0;
+       int temp;
+       char buf[16];           //enough for all info
+       /*
+        * We use the easy way, we don't care of off and count, so we don't set eof
+        * to 1
+        */
+
+       len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
+       len += sprintf(page + len, "Model reference    : %s\n", hotk->name);
+       /*
+        * The SFUN method probably allows the original driver to get the list
+        * of features supported by a given model. For now, 0x0100 or 0x0800
+        * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
+        * The significance of others is yet to be found.
+        */
+       if (read_acpi_int(hotk->handle, "SFUN", &temp, NULL))
+               len +=
+                   sprintf(page + len, "SFUN value         : 0x%04x\n", temp);
+       /*
+        * Another value for userspace: the ASYM method returns 0x02 for
+        * battery low and 0x04 for battery critical, its readings tend to be
+        * more accurate than those provided by _BST.
+        * Note: since not all the laptops provide this method, errors are
+        * silently ignored.
+        */
+       if (read_acpi_int(hotk->handle, "ASYM", &temp, NULL))
+               len +=
+                   sprintf(page + len, "ASYM value         : 0x%04x\n", temp);
+       if (asus_info) {
+               snprintf(buf, 16, "%d", asus_info->length);
+               len += sprintf(page + len, "DSDT length        : %s\n", buf);
+               snprintf(buf, 16, "%d", asus_info->checksum);
+               len += sprintf(page + len, "DSDT checksum      : %s\n", buf);
+               snprintf(buf, 16, "%d", asus_info->revision);
+               len += sprintf(page + len, "DSDT revision      : %s\n", buf);
+               snprintf(buf, 7, "%s", asus_info->oem_id);
+               len += sprintf(page + len, "OEM id             : %s\n", buf);
+               snprintf(buf, 9, "%s", asus_info->oem_table_id);
+               len += sprintf(page + len, "OEM table id       : %s\n", buf);
+               snprintf(buf, 16, "%x", asus_info->oem_revision);
+               len += sprintf(page + len, "OEM revision       : 0x%s\n", buf);
+               snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
+               len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
+               snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
+               len += sprintf(page + len, "ASL comp revision  : 0x%s\n", buf);
+       }
+
+       return len;
+}
+
+static int parse_arg(const char *buf, unsigned long count, int *val)
+{
+       if (!count)
+               return 0;
+       if (count > 31)
+               return -EINVAL;
+       if (sscanf(buf, "%i", val) != 1)
+               return -EINVAL;
+       return count;
+}
+
+static ssize_t store_status(const char *buf, size_t count,
+                           acpi_handle handle, int mask, int invert)
+{
+       int rv, value;
+       int out = 0;
+
+       rv = parse_arg(buf, count, &value);
+       if (rv > 0)
+               out = value ? 1 : 0;
+
+       write_status(handle, out, mask, invert);
+
+       return rv;
+}
+
+/*
+ * LEDD display
+ */
+static ssize_t show_ledd(struct device *dev,
+                        struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "0x%08x\n", hotk->ledd_status);
+}
+
+static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
+{
+       int rv, value;
+
+       rv = parse_arg(buf, count, &value);
+       if (rv > 0) {
+               if (!write_acpi_int(ledd_set_handle, NULL, value, NULL))
+                       printk(ASUS_WARNING "LED display write failed\n");
+               else
+                       hotk->ledd_status = (u32) value;
+       }
+       return rv;
+}
+
+/*
+ * WLAN
+ */
+static ssize_t show_wlan(struct device *dev,
+                        struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", read_status(WL_ON));
+}
+
+static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
+{
+       return store_status(buf, count, wl_switch_handle, WL_ON, 0);
+}
+
+/*
+ * Bluetooth
+ */
+static ssize_t show_bluetooth(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", read_status(BT_ON));
+}
+
+static ssize_t store_bluetooth(struct device *dev,
+                              struct device_attribute *attr, const char *buf,
+                              size_t count)
+{
+       return store_status(buf, count, bt_switch_handle, BT_ON, 0);
+}
+
+/*
+ * Display
+ */
+static void set_display(int value)
+{
+       /* no sanity check needed for now */
+       if (!write_acpi_int(display_set_handle, NULL, value, NULL))
+               printk(ASUS_WARNING "Error setting display\n");
+       return;
+}
+
+static int read_display(void)
+{
+       int value = 0;
+
+       /* In most of the case, we know how to set the display, but sometime
+          we can't read it */
+       if (display_get_handle) {
+               if (!read_acpi_int(display_get_handle, NULL, &value, NULL))
+                       printk(ASUS_WARNING "Error reading display status\n");
+       }
+
+       value &= 0x0F;          /* needed for some models, shouldn't hurt others */
+
+       return value;
+}
+
+/*
+ * Now, *this* one could be more user-friendly, but so far, no-one has
+ * complained. The significance of bits is the same as in store_disp()
+ */
+static ssize_t show_disp(struct device *dev,
+                        struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", read_display());
+}
+
+/*
+ * Experimental support for display switching. As of now: 1 should activate
+ * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
+ * Any combination (bitwise) of these will suffice. I never actually tested 4
+ * displays hooked up simultaneously, so be warned. See the acpi4asus README
+ * for more info.
+ */
+static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
+{
+       int rv, value;
+
+       rv = parse_arg(buf, count, &value);
+       if (rv > 0)
+               set_display(value);
+       return rv;
+}
+
+/*
+ * Light Sens
+ */
+static void set_light_sens_switch(int value)
+{
+       if (!write_acpi_int(ls_switch_handle, NULL, value, NULL))
+               printk(ASUS_WARNING "Error setting light sensor switch\n");
+       hotk->light_switch = value;
+}
+
+static ssize_t show_lssw(struct device *dev,
+                        struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", hotk->light_switch);
+}
+
+static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
+{
+       int rv, value;
+
+       rv = parse_arg(buf, count, &value);
+       if (rv > 0)
+               set_light_sens_switch(value ? 1 : 0);
+
+       return rv;
+}
+
+static void set_light_sens_level(int value)
+{
+       if (!write_acpi_int(ls_level_handle, NULL, value, NULL))
+               printk(ASUS_WARNING "Error setting light sensor level\n");
+       hotk->light_level = value;
+}
+
+static ssize_t show_lslvl(struct device *dev,
+                         struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", hotk->light_level);
+}
+
+static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
+{
+       int rv, value;
+
+       rv = parse_arg(buf, count, &value);
+       if (rv > 0) {
+               value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
+               /* 0 <= value <= 15 */
+               set_light_sens_level(value);
+       }
+
+       return rv;
+}
+
+static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
+{
+       /* TODO Find a better way to handle events count. */
+       if (!hotk)
+               return;
+
+       /*
+        * We need to tell the backlight device when the backlight power is
+        * switched
+        */
+       if (event == ATKD_LCD_ON) {
+               write_status(NULL, 1, LCD_ON, 0);
+               lcd_blank(FB_BLANK_UNBLANK);
+       } else if (event == ATKD_LCD_OFF) {
+               write_status(NULL, 0, LCD_ON, 0);
+               lcd_blank(FB_BLANK_POWERDOWN);
+       }
+
+       acpi_bus_generate_event(hotk->device, event,
+                               hotk->event_count[event % 128]++);
+
+       return;
+}
+
+#define ASUS_CREATE_DEVICE_ATTR(_name)                                 \
+       struct device_attribute dev_attr_##_name = {                    \
+               .attr = {                                               \
+                       .name = __stringify(_name),                     \
+                       .mode = 0,                                      \
+                       .owner = THIS_MODULE },                         \
+               .show   = NULL,                                         \
+               .store  = NULL,                                         \
+       }
+
+#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store)              \
+       do {                                                            \
+               dev_attr_##_name.attr.mode = _mode;                     \
+               dev_attr_##_name.show = _show;                          \
+               dev_attr_##_name.store = _store;                        \
+       } while(0)
+
+static ASUS_CREATE_DEVICE_ATTR(infos);
+static ASUS_CREATE_DEVICE_ATTR(wlan);
+static ASUS_CREATE_DEVICE_ATTR(bluetooth);
+static ASUS_CREATE_DEVICE_ATTR(display);
+static ASUS_CREATE_DEVICE_ATTR(ledd);
+static ASUS_CREATE_DEVICE_ATTR(ls_switch);
+static ASUS_CREATE_DEVICE_ATTR(ls_level);
+
+static struct attribute *asuspf_attributes[] = {
+       &dev_attr_infos.attr,
+       &dev_attr_wlan.attr,
+       &dev_attr_bluetooth.attr,
+       &dev_attr_display.attr,
+       &dev_attr_ledd.attr,
+       &dev_attr_ls_switch.attr,
+       &dev_attr_ls_level.attr,
+       NULL
+};
+
+static struct attribute_group asuspf_attribute_group = {
+       .attrs = asuspf_attributes
+};
+
+static struct platform_driver asuspf_driver = {
+       .driver = {
+                  .name = ASUS_HOTK_FILE,
+                  .owner = THIS_MODULE,
+                  }
+};
+
+static struct platform_device *asuspf_device;
+
+static void asus_hotk_add_fs(void)
+{
+       ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
+
+       if (wl_switch_handle)
+               ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
+
+       if (bt_switch_handle)
+               ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
+                                    show_bluetooth, store_bluetooth);
+
+       if (display_set_handle && display_get_handle)
+               ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
+       else if (display_set_handle)
+               ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
+
+       if (ledd_set_handle)
+               ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
+
+       if (ls_switch_handle && ls_level_handle) {
+               ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
+               ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
+       }
+}
+
+static int asus_handle_init(char *name, acpi_handle * handle,
+                           char **paths, int num_paths)
+{
+       int i;
+       acpi_status status;
+
+       for (i = 0; i < num_paths; i++) {
+               status = acpi_get_handle(NULL, paths[i], handle);
+               if (ACPI_SUCCESS(status))
+                       return 0;
+       }
+
+       *handle = NULL;
+       return -ENODEV;
+}
+
+#define ASUS_HANDLE_INIT(object)                                       \
+       asus_handle_init(#object, &object##_handle, object##_paths,     \
+                        ARRAY_SIZE(object##_paths))
+
+/*
+ * This function is used to initialize the hotk with right values. In this
+ * method, we can make all the detection we want, and modify the hotk struct
+ */
+static int asus_hotk_get_info(void)
+{
+       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+       union acpi_object *model = NULL;
+       int bsts_result, hwrs_result;
+       char *string = NULL;
+       acpi_status status;
+
+       /*
+        * Get DSDT headers early enough to allow for differentiating between
+        * models, but late enough to allow acpi_bus_register_driver() to fail
+        * before doing anything ACPI-specific. Should we encounter a machine,
+        * which needs special handling (i.e. its hotkey device has a different
+        * HID), this bit will be moved. A global variable asus_info contains
+        * the DSDT header.
+        */
+       status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
+       if (ACPI_FAILURE(status))
+               printk(ASUS_WARNING "Couldn't get the DSDT table header\n");
+
+       /* We have to write 0 on init this far for all ASUS models */
+       if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
+               printk(ASUS_ERR "Hotkey initialization failed\n");
+               return -ENODEV;
+       }
+
+       /* This needs to be called for some laptops to init properly */
+       if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result, NULL))
+               printk(ASUS_WARNING "Error calling BSTS\n");
+       else if (bsts_result)
+               printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n",
+                      bsts_result);
+
+       /*
+        * Try to match the object returned by INIT to the specific model.
+        * Handle every possible object (or the lack of thereof) the DSDT
+        * writers might throw at us. When in trouble, we pass NULL to
+        * asus_model_match() and try something completely different.
+        */
+       if (buffer.pointer) {
+               model = buffer.pointer;
+               switch (model->type) {
+               case ACPI_TYPE_STRING:
+                       string = model->string.pointer;
+                       break;
+               case ACPI_TYPE_BUFFER:
+                       string = model->buffer.pointer;
+                       break;
+               default:
+                       string = "";
+                       break;
+               }
+       }
+       hotk->name = kstrdup(string, GFP_KERNEL);
+       if (!hotk->name)
+               return -ENOMEM;
+
+       if (*string)
+               printk(ASUS_NOTICE "  %s model detected\n", string);
+
+       ASUS_HANDLE_INIT(mled_set);
+       ASUS_HANDLE_INIT(tled_set);
+       ASUS_HANDLE_INIT(rled_set);
+       ASUS_HANDLE_INIT(pled_set);
+
+       ASUS_HANDLE_INIT(ledd_set);
+
+       /*
+        * The HWRS method return informations about the hardware.
+        * 0x80 bit is for WLAN, 0x100 for Bluetooth.
+        * The significance of others is yet to be found.
+        * If we don't find the method, we assume the device are present.
+        */
+       if (!read_acpi_int(hotk->handle, "HRWS", &hwrs_result, NULL))
+               hwrs_result = WL_HWRS | BT_HWRS;
+
+       if (hwrs_result & WL_HWRS)
+               ASUS_HANDLE_INIT(wl_switch);
+       if (hwrs_result & BT_HWRS)
+               ASUS_HANDLE_INIT(bt_switch);
+
+       ASUS_HANDLE_INIT(wireless_status);
+
+       ASUS_HANDLE_INIT(brightness_set);
+       ASUS_HANDLE_INIT(brightness_get);
+
+       ASUS_HANDLE_INIT(lcd_switch);
+
+       ASUS_HANDLE_INIT(display_set);
+       ASUS_HANDLE_INIT(display_get);
+
+       /* There is a lot of models with "ALSL", but a few get
+          a real light sens, so we need to check it. */
+       if (ASUS_HANDLE_INIT(ls_switch))
+               ASUS_HANDLE_INIT(ls_level);
+
+       kfree(model);
+
+       return AE_OK;
+}
+
+static int asus_hotk_check(void)
+{
+       int result = 0;
+
+       result = acpi_bus_get_status(hotk->device);
+       if (result)
+               return result;
+
+       if (hotk->device->status.present) {
+               result = asus_hotk_get_info();
+       } else {
+               printk(ASUS_ERR "Hotkey device not present, aborting\n");
+               return -EINVAL;
+       }
+
+       return result;
+}
+
+static int asus_hotk_found;
+
+static int asus_hotk_add(struct acpi_device *device)
+{
+       acpi_status status = AE_OK;
+       int result;
+
+       if (!device)
+               return -EINVAL;
+
+       printk(ASUS_NOTICE "Asus Laptop Support version %s\n",
+              ASUS_LAPTOP_VERSION);
+
+       hotk = kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
+       if (!hotk)
+               return -ENOMEM;
+       memset(hotk, 0, sizeof(struct asus_hotk));
+
+       hotk->handle = device->handle;
+       strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
+       strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
+       acpi_driver_data(device) = hotk;
+       hotk->device = device;
+
+       result = asus_hotk_check();
+       if (result)
+               goto end;
+
+       asus_hotk_add_fs();
+
+       /*
+        * We install the handler, it will receive the hotk in parameter, so, we
+        * could add other data to the hotk struct
+        */
+       status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
+                                            asus_hotk_notify, hotk);
+       if (ACPI_FAILURE(status))
+               printk(ASUS_ERR "Error installing notify handler\n");
+
+       asus_hotk_found = 1;
+
+       /* WLED and BLED are on by default */
+       write_status(bt_switch_handle, 1, BT_ON, 0);
+       write_status(wl_switch_handle, 1, WL_ON, 0);
+
+       /* LCD Backlight is on by default */
+       write_status(NULL, 1, LCD_ON, 0);
+
+       /* LED display is off by default */
+       hotk->ledd_status = 0xFFF;
+
+       /* Set initial values of light sensor and level */
+       hotk->light_switch = 1; /* Default to light sensor disabled */
+       hotk->light_level = 0;  /* level 5 for sensor sensitivity */
+
+       if (ls_switch_handle)
+               set_light_sens_switch(hotk->light_switch);
+
+       if (ls_level_handle)
+               set_light_sens_level(hotk->light_level);
+
+      end:
+       if (result) {
+               kfree(hotk->name);
+               kfree(hotk);
+       }
+
+       return result;
+}
+
+static int asus_hotk_remove(struct acpi_device *device, int type)
+{
+       acpi_status status = 0;
+
+       if (!device || !acpi_driver_data(device))
+               return -EINVAL;
+
+       status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
+                                           asus_hotk_notify);
+       if (ACPI_FAILURE(status))
+               printk(ASUS_ERR "Error removing notify handler\n");
+
+       kfree(hotk->name);
+       kfree(hotk);
+
+       return 0;
+}
+
+static void asus_backlight_exit(void)
+{
+       if (asus_backlight_device)
+               backlight_device_unregister(asus_backlight_device);
+}
+
+#define  ASUS_LED_UNREGISTER(object)                           \
+       if(object##_led.class_dev                               \
+          && !IS_ERR(object##_led.class_dev))                  \
+               led_classdev_unregister(&object##_led)
+
+static void asus_led_exit(void)
+{
+       ASUS_LED_UNREGISTER(mled);
+       ASUS_LED_UNREGISTER(tled);
+       ASUS_LED_UNREGISTER(pled);
+       ASUS_LED_UNREGISTER(rled);
+
+       destroy_workqueue(led_workqueue);
+}
+
+static void __exit asus_laptop_exit(void)
+{
+       asus_backlight_exit();
+       asus_led_exit();
+
+       acpi_bus_unregister_driver(&asus_hotk_driver);
+       sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
+       platform_device_unregister(asuspf_device);
+       platform_driver_unregister(&asuspf_driver);
+}
+
+static int asus_backlight_init(struct device *dev)
+{
+       struct backlight_device *bd;
+
+       if (brightness_set_handle && lcd_switch_handle) {
+               bd = backlight_device_register(ASUS_HOTK_FILE, dev,
+                                              NULL, &asusbl_data);
+               if (IS_ERR(bd)) {
+                       printk(ASUS_ERR
+                              "Could not register asus backlight device\n");
+                       asus_backlight_device = NULL;
+                       return PTR_ERR(bd);
+               }
+
+               asus_backlight_device = bd;
+
+               down(&bd->sem);
+               if (likely(bd->props)) {
+                       bd->props->brightness = read_brightness(NULL);
+                       bd->props->power = FB_BLANK_UNBLANK;
+                       if (likely(bd->props->update_status))
+                               bd->props->update_status(bd);
+               }
+               up(&bd->sem);
+       }
+       return 0;
+}
+
+static int asus_led_register(acpi_handle handle,
+                            struct led_classdev *ldev, struct device *dev)
+{
+       if (!handle)
+               return 0;
+
+       return led_classdev_register(dev, ldev);
+}
+
+#define ASUS_LED_REGISTER(object, device)                              \
+       asus_led_register(object##_set_handle, &object##_led, device)
+
+static int asus_led_init(struct device *dev)
+{
+       int rv;
+
+       rv = ASUS_LED_REGISTER(mled, dev);
+       if (rv)
+               return rv;
+
+       rv = ASUS_LED_REGISTER(tled, dev);
+       if (rv)
+               return rv;
+
+       rv = ASUS_LED_REGISTER(rled, dev);
+       if (rv)
+               return rv;
+
+       rv = ASUS_LED_REGISTER(pled, dev);
+       if (rv)
+               return rv;
+
+       led_workqueue = create_singlethread_workqueue("led_workqueue");
+       if (!led_workqueue)
+               return -ENOMEM;
+
+       return 0;
+}
+
+static int __init asus_laptop_init(void)
+{
+       struct device *dev;
+       int result;
+
+       if (acpi_disabled)
+               return -ENODEV;
+
+       if (!acpi_specific_hotkey_enabled) {
+               printk(ASUS_ERR "Using generic hotkey driver\n");
+               return -ENODEV;
+       }
+
+       result = acpi_bus_register_driver(&asus_hotk_driver);
+       if (result < 0)
+               return result;
+
+       /*
+        * This is a bit of a kludge.  We only want this module loaded
+        * for ASUS systems, but there's currently no way to probe the
+        * ACPI namespace for ASUS HIDs.  So we just return failure if
+        * we didn't find one, which will cause the module to be
+        * unloaded.
+        */
+       if (!asus_hotk_found) {
+               acpi_bus_unregister_driver(&asus_hotk_driver);
+               return -ENODEV;
+       }
+
+       dev = acpi_get_physical_device(hotk->device->handle);
+
+       result = asus_backlight_init(dev);
+       if (result)
+               goto fail_backlight;
+
+       result = asus_led_init(dev);
+       if (result)
+               goto fail_led;
+
+       /* Register platform stuff */
+       result = platform_driver_register(&asuspf_driver);
+       if (result)
+               goto fail_platform_driver;
+
+       asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
+       if (!asuspf_device) {
+               result = -ENOMEM;
+               goto fail_platform_device1;
+       }
+
+       result = platform_device_add(asuspf_device);
+       if (result)
+               goto fail_platform_device2;
+
+       result = sysfs_create_group(&asuspf_device->dev.kobj,
+                                   &asuspf_attribute_group);
+       if (result)
+               goto fail_sysfs;
+
+       return 0;
+
+      fail_sysfs:
+       platform_device_del(asuspf_device);
+
+      fail_platform_device2:
+       platform_device_put(asuspf_device);
+
+      fail_platform_device1:
+       platform_driver_unregister(&asuspf_driver);
+
+      fail_platform_driver:
+       asus_led_exit();
+
+      fail_led:
+       asus_backlight_exit();
+
+      fail_backlight:
+
+       return result;
+}
+
+module_init(asus_laptop_init);
+module_exit(asus_laptop_exit);
index 80bdcf8462343434fae03cb3091dade3646854ee..716a47210aa326676df0c2945e5cf9d5e072ae29 100644 (file)
@@ -792,8 +792,7 @@ static void poll_vortex(struct net_device *dev)
 {
        struct vortex_private *vp = netdev_priv(dev);
        unsigned long flags;
-       local_save_flags(flags);
-       local_irq_disable();
+       local_irq_save(flags);
        (vp->full_bus_master_rx ? boomerang_interrupt:vortex_interrupt)(dev->irq,dev);
        local_irq_restore(flags);
 }
index 8aa8dd02b910cb4a2000f959ea175907c3525e04..ad92b6a76ee64bb8108eef5e0db2d8663ad3c672 100644 (file)
@@ -190,7 +190,7 @@ config MII
 
 config MACB
        tristate "Atmel MACB support"
-       depends on NET_ETHERNET && AVR32
+       depends on NET_ETHERNET && (AVR32 || ARCH_AT91SAM9260 || ARCH_AT91SAM9263)
        select MII
        help
          The Atmel MACB ethernet interface is found on many AT32 and AT91
@@ -235,16 +235,6 @@ config BMAC
          To compile this driver as a module, choose M here: the module
          will be called bmac.
 
-config OAKNET
-       tristate "National DP83902AV (Oak ethernet) support"
-       depends on NET_ETHERNET && PPC && BROKEN
-       select CRC32
-       help
-         Say Y if your machine has this type of Ethernet network card.
-
-         To compile this driver as a module, choose M here: the module
-         will be called oaknet.
-
 config ARIADNE
        tristate "Ariadne support"
        depends on NET_ETHERNET && ZORRO
@@ -1155,21 +1145,6 @@ config SEEQ8005
          <file:Documentation/networking/net-modules.txt>. The module
          will be called seeq8005.
 
-config SKMC
-       tristate "SKnet MCA support"
-       depends on NET_ETHERNET && MCA && BROKEN
-       ---help---
-         These are Micro Channel Ethernet adapters. You need to say Y to "MCA
-         support" in order to use this driver.  Supported cards are the SKnet
-         Junior MC2 and the SKnet MC2(+).  The driver automatically
-         distinguishes between the two cards. Note that using multiple boards
-         of different type hasn't been tested with this driver.  Say Y if you
-         have one of these Ethernet adapters.
-
-         To compile this driver as a module, choose M here and read
-         <file:Documentation/networking/net-modules.txt>. The module
-         will be called sk_mca.
-
 config NE2_MCA
        tristate "NE/2 (ne2000 MCA version) support"
        depends on NET_ETHERNET && MCA_LEGACY
@@ -1788,6 +1763,18 @@ config LAN_SAA9730
          workstations.
          See <http://www.semiconductors.philips.com/pip/SAA9730_flyer_1>.
 
+config SC92031
+       tristate "Silan SC92031 PCI Fast Ethernet Adapter driver (EXPERIMENTAL)"
+       depends on NET_PCI && PCI && EXPERIMENTAL
+       select CRC32
+       ---help---
+         This is a driver for the Fast Ethernet PCI network cards based on
+         the Silan SC92031 chip (sometimes also called Rsltek 8139D). If you
+         have one of these, say Y here.
+
+         To compile this driver as a module, choose M here: the module
+         will be called sc92031.  This is recommended.
+
 config NET_POCKET
        bool "Pocket and portable adapters"
        depends on NET_ETHERNET && PARPORT
@@ -2392,6 +2379,24 @@ config CHELSIO_T1_NAPI
          NAPI is a driver API designed to reduce CPU and interrupt load
          when the driver is receiving lots of packets from the card.
 
+config CHELSIO_T3
+        tristate "Chelsio Communications T3 10Gb Ethernet support"
+        depends on PCI
+        help
+          This driver supports Chelsio T3-based gigabit and 10Gb Ethernet
+          adapters.
+
+          For general information about Chelsio and our products, visit
+          our website at <http://www.chelsio.com>.
+
+          For customer support, please visit our customer support page at
+          <http://www.chelsio.com/support.htm>.
+
+          Please send feedback to <linux-bugs@chelsio.com>.
+
+          To compile this driver as a module, choose M here: the module
+          will be called cxgb3.
+
 config EHEA
        tristate "eHEA Ethernet support"
        depends on IBMEBUS
@@ -2488,6 +2493,13 @@ config NETXEN_NIC
        help
          This enables the support for NetXen's Gigabit Ethernet card.
 
+config PASEMI_MAC
+       tristate "PA Semi 1/10Gbit MAC"
+       depends on PPC64 && PCI
+       help
+         This driver supports the on-chip 1/10Gbit Ethernet controller on
+         PA Semi's PWRficient line of chips.
+
 endmenu
 
 source "drivers/net/tokenring/Kconfig"
@@ -2541,6 +2553,7 @@ config DEFXX
 config SKFP
        tristate "SysKonnect FDDI PCI support"
        depends on FDDI && PCI
+       select BITREVERSE
        ---help---
          Say Y here if you have a SysKonnect FDDI PCI adapter.
          The following adapters are supported by this driver:
index 4c0d4e5ce42b27b18ca8943dd6455261377349b1..0878e3df51746e74c4302190535173e36ae4d23b 100644 (file)
@@ -6,6 +6,7 @@ obj-$(CONFIG_E1000) += e1000/
 obj-$(CONFIG_IBM_EMAC) += ibm_emac/
 obj-$(CONFIG_IXGB) += ixgb/
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
+obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
@@ -36,8 +37,6 @@ obj-$(CONFIG_CASSINI) += cassini.o
 obj-$(CONFIG_MACE) += mace.o
 obj-$(CONFIG_BMAC) += bmac.o
 
-obj-$(CONFIG_OAKNET) += oaknet.o 8390.o
-
 obj-$(CONFIG_DGRS) += dgrs.o
 obj-$(CONFIG_VORTEX) += 3c59x.o
 obj-$(CONFIG_TYPHOON) += typhoon.o
@@ -137,7 +136,6 @@ obj-$(CONFIG_AT1700) += at1700.o
 obj-$(CONFIG_EL1) += 3c501.o
 obj-$(CONFIG_EL16) += 3c507.o
 obj-$(CONFIG_ELMC) += 3c523.o
-obj-$(CONFIG_SKMC) += sk_mca.o
 obj-$(CONFIG_IBMLANA) += ibmlana.o
 obj-$(CONFIG_ELMC_II) += 3c527.o
 obj-$(CONFIG_EL3) += 3c509.o
@@ -160,6 +158,7 @@ obj-$(CONFIG_APRICOT) += 82596.o
 obj-$(CONFIG_LASI_82596) += lasi_82596.o
 obj-$(CONFIG_MVME16x_NET) += 82596.o
 obj-$(CONFIG_BVME6000_NET) += 82596.o
+obj-$(CONFIG_SC92031) += sc92031.o
 
 # This is also a 82596 and should probably be merged
 obj-$(CONFIG_LP486E) += lp486e.o
@@ -196,6 +195,7 @@ obj-$(CONFIG_SMC91X) += smc91x.o
 obj-$(CONFIG_SMC911X) += smc911x.o
 obj-$(CONFIG_DM9000) += dm9000.o
 obj-$(CONFIG_FEC_8XX) += fec_8xx/
+obj-$(CONFIG_PASEMI_MAC) += pasemi_mac.o
 
 obj-$(CONFIG_MACB) += macb.o
 
index 9305eb9b1b98fde55e17e580f7997b2ea77129b6..dd8ed456c8b225c28e7bd843119d7813f017b3d0 100644 (file)
@@ -59,7 +59,6 @@ extern struct net_device *wavelan_probe(int unit);
 extern struct net_device *arlan_probe(int unit);
 extern struct net_device *el16_probe(int unit);
 extern struct net_device *elmc_probe(int unit);
-extern struct net_device *skmca_probe(int unit);
 extern struct net_device *elplus_probe(int unit);
 extern struct net_device *ac3200_probe(int unit);
 extern struct net_device *es_probe(int unit);
@@ -152,9 +151,6 @@ static struct devprobe2 mca_probes[] __initdata = {
 #endif
 #ifdef CONFIG_ELMC_II          /* 3c527 */
        {mc32_probe, 0},
-#endif
-#ifdef CONFIG_SKMC              /* SKnet Microchannel */
-        {skmca_probe, 0},
 #endif
        {NULL, 0},
 };
index 18896f24d407e26bbb8c3ba4fa63c42aeac1c280..9c399aaefbdd1b6b045c97fab94e28dfaef3b990 100644 (file)
@@ -1334,8 +1334,7 @@ err_no_interrupt:
 static void amd8111e_poll(struct net_device *dev)
 {
        unsigned long flags;
-       local_save_flags(flags);
-       local_irq_disable();
+       local_irq_save(flags);
        amd8111e_interrupt(0, dev);
        local_irq_restore(flags);
 }
index 303a8d94ad4b76cfbdd7c34c099c8b2064f29ee6..5ff7882297d66910c15db46406eda5e8a4a33e50 100644 (file)
@@ -721,7 +721,7 @@ static void b44_recycle_rx(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
        struct ring_info *src_map, *dest_map;
        struct rx_header *rh;
        int dest_idx;
-       u32 ctrl;
+       __le32 ctrl;
 
        dest_idx = dest_idx_unmasked & (B44_RX_RING_SIZE - 1);
        dest_desc = &bp->rx_ring[dest_idx];
@@ -783,7 +783,7 @@ static int b44_rx(struct b44 *bp, int budget)
                                            RX_PKT_BUF_SZ,
                                            PCI_DMA_FROMDEVICE);
                rh = (struct rx_header *) skb->data;
-               len = cpu_to_le16(rh->len);
+               len = le16_to_cpu(rh->len);
                if ((len > (RX_PKT_BUF_SZ - bp->rx_offset)) ||
                    (rh->flags & cpu_to_le16(RX_FLAG_ERRORS))) {
                drop_it:
@@ -799,7 +799,7 @@ static int b44_rx(struct b44 *bp, int budget)
                        do {
                                udelay(2);
                                barrier();
-                               len = cpu_to_le16(rh->len);
+                               len = le16_to_cpu(rh->len);
                        } while (len == 0 && i++ < 5);
                        if (len == 0)
                                goto drop_it;
@@ -2061,7 +2061,7 @@ out:
 static int b44_read_eeprom(struct b44 *bp, u8 *data)
 {
        long i;
-       u16 *ptr = (u16 *) data;
+       __le16 *ptr = (__le16 *) data;
 
        for (i = 0; i < 128; i += 2)
                ptr[i / 2] = cpu_to_le16(readw(bp->regs + 4096 + i));
index 4944507fad2381470d9084aad4c9b2b2ba3ebbce..18fc13336628fd5fa532ee822b9d0bcf378b4e7c 100644 (file)
 #define  MII_TLEDCTRL_ENABLE   0x0040
 
 struct dma_desc {
-       u32     ctrl;
-       u32     addr;
+       __le32  ctrl;
+       __le32  addr;
 };
 
 /* There are only 12 bits in the DMA engine for descriptor offsetting
@@ -327,9 +327,9 @@ struct dma_desc {
 #define RX_COPY_THRESHOLD      256
 
 struct rx_header {
-       u16     len;
-       u16     flags;
-       u16     pad[12];
+       __le16  len;
+       __le16  flags;
+       __le16  pad[12];
 };
 #define RX_HEADER_LEN  28
 
index 4528ce9c4e435f9312ff87f62b944bad45cc1073..c143304dcff58df4c7d54d08bfc936389d7673cb 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/init.h>
 #include <linux/spinlock.h>
 #include <linux/crc32.h>
+#include <linux/bitrev.h>
 #include <asm/prom.h>
 #include <asm/dbdma.h>
 #include <asm/io.h>
@@ -140,7 +141,6 @@ static unsigned char *bmac_emergency_rxbuf;
        + (N_RX_RING + N_TX_RING + 4) * sizeof(struct dbdma_cmd) \
        + sizeof(struct sk_buff_head))
 
-static unsigned char bitrev(unsigned char b);
 static int bmac_open(struct net_device *dev);
 static int bmac_close(struct net_device *dev);
 static int bmac_transmit_packet(struct sk_buff *skb, struct net_device *dev);
@@ -586,18 +586,6 @@ bmac_construct_rxbuff(struct sk_buff *skb, volatile struct dbdma_cmd *cp)
                     virt_to_bus(addr), 0);
 }
 
-/* Bit-reverse one byte of an ethernet hardware address. */
-static unsigned char
-bitrev(unsigned char b)
-{
-       int d = 0, i;
-
-       for (i = 0; i < 8; ++i, b >>= 1)
-               d = (d << 1) | (b & 1);
-       return d;
-}
-
-
 static void
 bmac_init_tx_ring(struct bmac_data *bp)
 {
@@ -1224,8 +1212,8 @@ bmac_get_station_address(struct net_device *dev, unsigned char *ea)
                {
                        reset_and_select_srom(dev);
                        data = read_srom(dev, i + EnetAddressOffset/2, SROMAddressBits);
-                       ea[2*i]   = bitrev(data & 0x0ff);
-                       ea[2*i+1] = bitrev((data >> 8) & 0x0ff);
+                       ea[2*i]   = bitrev8(data & 0x0ff);
+                       ea[2*i+1] = bitrev8((data >> 8) & 0x0ff);
                }
 }
 
@@ -1315,7 +1303,7 @@ static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_i
 
        rev = addr[0] == 0 && addr[1] == 0xA0;
        for (j = 0; j < 6; ++j)
-               dev->dev_addr[j] = rev? bitrev(addr[j]): addr[j];
+               dev->dev_addr[j] = rev ? bitrev8(addr[j]): addr[j];
 
        /* Enable chip without interrupts for now */
        bmac_enable_and_reset_chip(dev);
index ee7b75b976b5c60a41dc0ba3e76651cba42b113c..c416c18007dac16751dcae11d993ce05de7c91e2 100644 (file)
 #include <linux/if_vlan.h>
 #define BCM_VLAN 1
 #endif
-#ifdef NETIF_F_TSO
 #include <net/ip.h>
 #include <net/tcp.h>
 #include <net/checksum.h>
-#define BCM_TSO 1
-#endif
 #include <linux/workqueue.h>
 #include <linux/crc32.h>
 #include <linux/prefetch.h>
@@ -1728,7 +1725,7 @@ bnx2_tx_int(struct bnx2 *bp)
 
                tx_buf = &bp->tx_buf_ring[sw_ring_cons];
                skb = tx_buf->skb;
-#ifdef BCM_TSO
+
                /* partial BD completions possible with TSO packets */
                if (skb_is_gso(skb)) {
                        u16 last_idx, last_ring_idx;
@@ -1744,7 +1741,7 @@ bnx2_tx_int(struct bnx2 *bp)
                                break;
                        }
                }
-#endif
+
                pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
                        skb_headlen(skb), PCI_DMA_TODEVICE);
 
@@ -4514,7 +4511,6 @@ bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
                vlan_tag_flags |=
                        (TX_BD_FLAGS_VLAN_TAG | (vlan_tx_tag_get(skb) << 16));
        }
-#ifdef BCM_TSO
        if ((mss = skb_shinfo(skb)->gso_size) &&
                (skb->len > (bp->dev->mtu + ETH_HLEN))) {
                u32 tcp_opt_len, ip_tcp_len;
@@ -4547,7 +4543,6 @@ bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
                }
        }
        else
-#endif
        {
                mss = 0;
        }
@@ -5544,10 +5539,8 @@ static const struct ethtool_ops bnx2_ethtool_ops = {
        .set_tx_csum            = ethtool_op_set_tx_csum,
        .get_sg                 = ethtool_op_get_sg,
        .set_sg                 = ethtool_op_set_sg,
-#ifdef BCM_TSO
        .get_tso                = ethtool_op_get_tso,
        .set_tso                = bnx2_set_tso,
-#endif
        .self_test_count        = bnx2_self_test_count,
        .self_test              = bnx2_self_test,
        .get_strings            = bnx2_get_strings,
@@ -6104,9 +6097,7 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 #ifdef BCM_VLAN
        dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
 #endif
-#ifdef BCM_TSO
        dev->features |= NETIF_F_TSO | NETIF_F_TSO_ECN;
-#endif
 
        netif_carrier_off(bp->dev);
 
index 6482aed4bb7cddec1c6879e47a3a26a495332359..d3801a00d3d5152f6009024bb41248db950dc43f 100644 (file)
@@ -4704,6 +4704,7 @@ static int bond_check_params(struct bond_params *params)
 static struct lock_class_key bonding_netdev_xmit_lock_key;
 
 /* Create a new bond based on the specified name and bonding parameters.
+ * If name is NULL, obtain a suitable "bond%d" name for us.
  * Caller must NOT hold rtnl_lock; we need to release it here before we
  * set up our sysfs entries.
  */
@@ -4713,7 +4714,8 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
        int res;
 
        rtnl_lock();
-       bond_dev = alloc_netdev(sizeof(struct bonding), name, ether_setup);
+       bond_dev = alloc_netdev(sizeof(struct bonding), name ? name : "",
+                               ether_setup);
        if (!bond_dev) {
                printk(KERN_ERR DRV_NAME
                       ": %s: eek! can't alloc netdev!\n",
@@ -4722,6 +4724,12 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
                goto out_rtnl;
        }
 
+       if (!name) {
+               res = dev_alloc_name(bond_dev, "bond%d");
+               if (res < 0)
+                       goto out_netdev;
+       }
+
        /* bond_init() must be called after dev_alloc_name() (for the
         * /proc files), but before register_netdevice(), because we
         * need to set function pointers.
@@ -4748,14 +4756,19 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
 
        rtnl_unlock(); /* allows sysfs registration of net device */
        res = bond_create_sysfs_entry(bond_dev->priv);
-       goto done;
+       if (res < 0) {
+               rtnl_lock();
+               goto out_bond;
+       }
+
+       return 0;
+
 out_bond:
        bond_deinit(bond_dev);
 out_netdev:
        free_netdev(bond_dev);
 out_rtnl:
        rtnl_unlock();
-done:
        return res;
 }
 
@@ -4763,7 +4776,6 @@ static int __init bonding_init(void)
 {
        int i;
        int res;
-       char new_bond_name[8];  /* Enough room for 999 bonds at init. */
 
        printk(KERN_INFO "%s", version);
 
@@ -4776,8 +4788,7 @@ static int __init bonding_init(void)
        bond_create_proc_dir();
 #endif
        for (i = 0; i < max_bonds; i++) {
-               sprintf(new_bond_name, "bond%d",i);
-               res = bond_create(new_bond_name,&bonding_defaults, NULL);
+               res = bond_create(NULL, &bonding_defaults, NULL);
                if (res)
                        goto err;
        }
index 0e610aa1fdf916937a7955fb0c141514bd088f5f..878f7aabeeac2b1a27324e3a2a89bef0371343c4 100644 (file)
@@ -1433,6 +1433,21 @@ int bond_create_sysfs(void)
                return -ENODEV;
 
        ret = class_create_file(netdev_class, &class_attr_bonding_masters);
+       /*
+        * Permit multiple loads of the module by ignoring failures to
+        * create the bonding_masters sysfs file.  Bonding devices
+        * created by second or subsequent loads of the module will
+        * not be listed in, or controllable by, bonding_masters, but
+        * will have the usual "bonding" sysfs directory.
+        *
+        * This is done to preserve backwards compatibility for
+        * initscripts/sysconfig, which load bonding multiple times to
+        * configure multiple bonding devices.
+        */
+       if (ret == -EEXIST) {
+               netdev_class = NULL;
+               return 0;
+       }
 
        return ret;
 
index 0978c9ac6d2b75940b14301ab82441b1f59f6a15..41aa78bf1f783af9d86928db4c1216de406dd6d4 100644 (file)
@@ -22,8 +22,8 @@
 #include "bond_3ad.h"
 #include "bond_alb.h"
 
-#define DRV_VERSION    "3.1.1"
-#define DRV_RELDATE    "September 26, 2006"
+#define DRV_VERSION    "3.1.2"
+#define DRV_RELDATE    "January 20, 2007"
 #define DRV_NAME       "bonding"
 #define DRV_DESCRIPTION        "Ethernet Channel Bonding Driver"
 
@@ -237,12 +237,13 @@ static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
 #define BOND_ARP_VALIDATE_ALL          (BOND_ARP_VALIDATE_ACTIVE | \
                                         BOND_ARP_VALIDATE_BACKUP)
 
-extern inline int slave_do_arp_validate(struct bonding *bond, struct slave *slave)
+static inline int slave_do_arp_validate(struct bonding *bond,
+                                       struct slave *slave)
 {
        return bond->params.arp_validate & (1 << slave->state);
 }
 
-extern inline unsigned long slave_last_rx(struct bonding *bond,
+static inline unsigned long slave_last_rx(struct bonding *bond,
                                        struct slave *slave)
 {
        if (slave_do_arp_validate(bond, slave))
index 74758d2c7af8c368ff79b7ab4dc29aa04c7f0ffb..787f2f2820fe461625da7392c8c8b1af49d74314 100644 (file)
@@ -324,7 +324,7 @@ struct board_info {
        unsigned char           mdio_phybaseaddr;
        struct gmac            *gmac;
        struct gphy            *gphy;
-       struct mdio_ops        *mdio_ops;
+       struct mdio_ops        *mdio_ops;
        const char             *desc;
 };
 
index 35f565be4fd3cff67553269967e05c0b4179a49d..e36d45b78cc7fc45e6e0ff4749967f33eabb151a 100644 (file)
@@ -103,7 +103,7 @@ enum CPL_opcode {
        CPL_MIGRATE_C2T_RPL   = 0xDD,
        CPL_ERROR             = 0xD7,
 
-    /* internal: driver -> TOM */
+       /* internal: driver -> TOM */
        CPL_MSS_CHANGE        = 0xE1
 };
 
@@ -159,8 +159,8 @@ enum {                // TX_PKT_LSO ethernet types
 };
 
 union opcode_tid {
-    u32 opcode_tid;
-    u8 opcode;
+       u32 opcode_tid;
+       u8 opcode;
 };
 
 #define S_OPCODE 24
@@ -234,7 +234,7 @@ struct cpl_pass_accept_req {
        u32 local_ip;
        u32 peer_ip;
        u32 tos_tid;
-    struct tcp_options tcp_options;
+       struct tcp_options tcp_options;
        u8  dst_mac[6];
        u16 vlan_tag;
        u8  src_mac[6];
@@ -250,12 +250,12 @@ struct cpl_pass_accept_rpl {
        u32 peer_ip;
        u32 opt0h;
        union {
-       u32 opt0l;
-       struct {
-           u8 rsvd[3];
-           u8 status;
+               u32 opt0l;
+               struct {
+                   u8 rsvd[3];
+                   u8 status;
+               };
        };
-    };
 };
 
 struct cpl_act_open_req {
index fd5d821f3f2a3c550834b55988f4457fdd0e1392..7d0f24f697770c734701bb7c8f7a835a5d559a0b 100644 (file)
@@ -69,14 +69,14 @@ static inline void cancel_mac_stats_update(struct adapter *ap)
        cancel_delayed_work(&ap->stats_update_task);
 }
 
-#define MAX_CMDQ_ENTRIES 16384
-#define MAX_CMDQ1_ENTRIES 1024
-#define MAX_RX_BUFFERS 16384
-#define MAX_RX_JUMBO_BUFFERS 16384
+#define MAX_CMDQ_ENTRIES       16384
+#define MAX_CMDQ1_ENTRIES      1024
+#define MAX_RX_BUFFERS         16384
+#define MAX_RX_JUMBO_BUFFERS   16384
 #define MAX_TX_BUFFERS_HIGH    16384U
 #define MAX_TX_BUFFERS_LOW     1536U
 #define MAX_TX_BUFFERS         1460U
-#define MIN_FL_ENTRIES 32
+#define MIN_FL_ENTRIES         32
 
 #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
                         NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
@@ -143,7 +143,7 @@ static void link_report(struct port_info *p)
                        case SPEED_100:   s = "100Mbps"; break;
                }
 
-       printk(KERN_INFO "%s: link up, %s, %s-duplex\n",
+               printk(KERN_INFO "%s: link up, %s, %s-duplex\n",
                       p->dev->name, s,
                       p->link_config.duplex == DUPLEX_FULL ? "full" : "half");
        }
@@ -233,7 +233,7 @@ static int cxgb_up(struct adapter *adapter)
 
        t1_sge_start(adapter->sge);
        t1_interrupts_enable(adapter);
- out_err:
+out_err:
        return err;
 }
 
@@ -454,51 +454,21 @@ static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
        const struct cmac_statistics *s;
        const struct sge_intr_counts *t;
        struct sge_port_stats ss;
+       unsigned int len;
 
        s = mac->ops->statistics_update(mac, MAC_STATS_UPDATE_FULL);
 
-       *data++ = s->TxOctetsOK;
-       *data++ = s->TxOctetsBad;
-       *data++ = s->TxUnicastFramesOK;
-       *data++ = s->TxMulticastFramesOK;
-       *data++ = s->TxBroadcastFramesOK;
-       *data++ = s->TxPauseFrames;
-       *data++ = s->TxFramesWithDeferredXmissions;
-       *data++ = s->TxLateCollisions;
-       *data++ = s->TxTotalCollisions;
-       *data++ = s->TxFramesAbortedDueToXSCollisions;
-       *data++ = s->TxUnderrun;
-       *data++ = s->TxLengthErrors;
-       *data++ = s->TxInternalMACXmitError;
-       *data++ = s->TxFramesWithExcessiveDeferral;
-       *data++ = s->TxFCSErrors;
-
-       *data++ = s->RxOctetsOK;
-       *data++ = s->RxOctetsBad;
-       *data++ = s->RxUnicastFramesOK;
-       *data++ = s->RxMulticastFramesOK;
-       *data++ = s->RxBroadcastFramesOK;
-       *data++ = s->RxPauseFrames;
-       *data++ = s->RxFCSErrors;
-       *data++ = s->RxAlignErrors;
-       *data++ = s->RxSymbolErrors;
-       *data++ = s->RxDataErrors;
-       *data++ = s->RxSequenceErrors;
-       *data++ = s->RxRuntErrors;
-       *data++ = s->RxJabberErrors;
-       *data++ = s->RxInternalMACRcvError;
-       *data++ = s->RxInRangeLengthErrors;
-       *data++ = s->RxOutOfRangeLengthField;
-       *data++ = s->RxFrameTooLongErrors;
+       len = sizeof(u64)*(&s->TxFCSErrors + 1 - &s->TxOctetsOK);
+       memcpy(data, &s->TxOctetsOK, len);
+       data += len;
+
+       len = sizeof(u64)*(&s->RxFrameTooLongErrors + 1 - &s->RxOctetsOK);
+       memcpy(data, &s->RxOctetsOK, len);
+       data += len;
 
        t1_sge_get_port_stats(adapter->sge, dev->if_port, &ss);
-       *data++ = ss.rx_packets;
-       *data++ = ss.rx_cso_good;
-       *data++ = ss.tx_packets;
-       *data++ = ss.tx_cso;
-       *data++ = ss.tx_tso;
-       *data++ = ss.vlan_xtract;
-       *data++ = ss.vlan_insert;
+       memcpy(data, &ss, sizeof(ss));
+       data += sizeof(ss);
 
        t = t1_sge_get_intr_counts(adapter->sge);
        *data++ = t->rx_drops;
@@ -749,7 +719,7 @@ static int set_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
                return -EINVAL;
 
        if (adapter->flags & FULL_INIT_DONE)
-       return -EBUSY;
+               return -EBUSY;
 
        adapter->params.sge.freelQ_size[!jumbo_fl] = e->rx_pending;
        adapter->params.sge.freelQ_size[jumbo_fl] = e->rx_jumbo_pending;
@@ -764,7 +734,7 @@ static int set_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
        struct adapter *adapter = dev->priv;
 
        adapter->params.sge.rx_coalesce_usecs = c->rx_coalesce_usecs;
-       adapter->params.sge.coalesce_enable = c->use_adaptive_rx_coalesce;
+       adapter->params.sge.coalesce_enable = c->use_adaptive_rx_coalesce;
        adapter->params.sge.sample_interval_usecs = c->rate_sample_interval;
        t1_sge_set_coalesce_params(adapter->sge, &adapter->params.sge);
        return 0;
@@ -782,9 +752,9 @@ static int get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
 
 static int get_eeprom_len(struct net_device *dev)
 {
-       struct adapter *adapter = dev->priv;
+       struct adapter *adapter = dev->priv;
 
-       return t1_is_asic(adapter) ? EEPROM_SIZE : 0;
+       return t1_is_asic(adapter) ? EEPROM_SIZE : 0;
 }
 
 #define EEPROM_MAGIC(ap) \
@@ -848,7 +818,7 @@ static int t1_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
                u32 val;
 
                if (!phy->mdio_read)
-           return -EOPNOTSUPP;
+                       return -EOPNOTSUPP;
                phy->mdio_read(adapter, data->phy_id, 0, data->reg_num & 0x1f,
                               &val);
                data->val_out = val;
@@ -860,7 +830,7 @@ static int t1_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
                if (!capable(CAP_NET_ADMIN))
                    return -EPERM;
                if (!phy->mdio_write)
-           return -EOPNOTSUPP;
+                       return -EOPNOTSUPP;
                phy->mdio_write(adapter, data->phy_id, 0, data->reg_num & 0x1f,
                                data->val_in);
                break;
@@ -879,9 +849,9 @@ static int t1_change_mtu(struct net_device *dev, int new_mtu)
        struct cmac *mac = adapter->port[dev->if_port].mac;
 
        if (!mac->ops->set_mtu)
-       return -EOPNOTSUPP;
+               return -EOPNOTSUPP;
        if (new_mtu < 68)
-       return -EINVAL;
+               return -EINVAL;
        if ((ret = mac->ops->set_mtu(mac, new_mtu)))
                return ret;
        dev->mtu = new_mtu;
@@ -1211,9 +1181,9 @@ static int __devinit init_one(struct pci_dev *pdev,
 
        return 0;
 
- out_release_adapter_res:
+out_release_adapter_res:
        t1_free_sw_modules(adapter);
- out_free_dev:
+out_free_dev:
        if (adapter) {
                if (adapter->regs)
                        iounmap(adapter->regs);
@@ -1222,7 +1192,7 @@ static int __devinit init_one(struct pci_dev *pdev,
                                free_netdev(adapter->port[i].dev);
        }
        pci_release_regions(pdev);
- out_disable_pdev:
+out_disable_pdev:
        pci_disable_device(pdev);
        pci_set_drvdata(pdev, NULL);
        return err;
@@ -1273,28 +1243,27 @@ static int t1_clock(struct adapter *adapter, int mode)
        int M_MEM_VAL;
 
        enum {
-               M_CORE_BITS = 9,
-               T_CORE_VAL = 0,
-               T_CORE_BITS = 2,
-               N_CORE_VAL = 0,
-               N_CORE_BITS = 2,
-               M_MEM_BITS = 9,
-               T_MEM_VAL = 0,
-               T_MEM_BITS = 2,
-               N_MEM_VAL = 0,
-               N_MEM_BITS = 2,
-               NP_LOAD = 1 << 17,
-               S_LOAD_MEM = 1 << 5,
-               S_LOAD_CORE = 1 << 6,
-               S_CLOCK = 1 << 3
+               M_CORE_BITS     = 9,
+               T_CORE_VAL      = 0,
+               T_CORE_BITS     = 2,
+               N_CORE_VAL      = 0,
+               N_CORE_BITS     = 2,
+               M_MEM_BITS      = 9,
+               T_MEM_VAL       = 0,
+               T_MEM_BITS      = 2,
+               N_MEM_VAL       = 0,
+               N_MEM_BITS      = 2,
+               NP_LOAD         = 1 << 17,
+               S_LOAD_MEM      = 1 << 5,
+               S_LOAD_CORE     = 1 << 6,
+               S_CLOCK         = 1 << 3
        };
 
        if (!t1_is_T1B(adapter))
                return -ENODEV; /* Can't re-clock this chip. */
 
-       if (mode & 2) {
+       if (mode & 2)
                return 0;       /* show current mode. */
-       }
 
        if ((adapter->t1powersave & 1) == (mode & 1))
                return -EALREADY;       /* ASIC already running in mode. */
@@ -1386,26 +1355,26 @@ static inline void t1_sw_reset(struct pci_dev *pdev)
 static void __devexit remove_one(struct pci_dev *pdev)
 {
        struct net_device *dev = pci_get_drvdata(pdev);
+       struct adapter *adapter = dev->priv;
+       int i;
 
-       if (dev) {
-               int i;
-               struct adapter *adapter = dev->priv;
-
-               for_each_port(adapter, i)
-                       if (test_bit(i, &adapter->registered_device_map))
-                               unregister_netdev(adapter->port[i].dev);
+       for_each_port(adapter, i) {
+               if (test_bit(i, &adapter->registered_device_map))
+                       unregister_netdev(adapter->port[i].dev);
+       }
 
-               t1_free_sw_modules(adapter);
-               iounmap(adapter->regs);
-               while (--i >= 0)
-                       if (adapter->port[i].dev)
-                               free_netdev(adapter->port[i].dev);
+       t1_free_sw_modules(adapter);
+       iounmap(adapter->regs);
 
-               pci_release_regions(pdev);
-               pci_disable_device(pdev);
-               pci_set_drvdata(pdev, NULL);
-               t1_sw_reset(pdev);
+       while (--i >= 0) {
+               if (adapter->port[i].dev)
+                       free_netdev(adapter->port[i].dev);
        }
+
+       pci_release_regions(pdev);
+       pci_disable_device(pdev);
+       pci_set_drvdata(pdev, NULL);
+       t1_sw_reset(pdev);
 }
 
 static struct pci_driver driver = {
index 9ebecaa97d316f277212c72ab23b8771160b38d2..eef655c827d967f7dcc07f710caadb8554de577c 100644 (file)
@@ -46,14 +46,14 @@ enum {
 };
 
 /* ELMER0 registers */
-#define A_ELMER0_VERSION 0x100000
-#define A_ELMER0_PHY_CFG 0x100004
-#define A_ELMER0_INT_ENABLE 0x100008
-#define A_ELMER0_INT_CAUSE 0x10000c
-#define A_ELMER0_GPI_CFG 0x100010
-#define A_ELMER0_GPI_STAT 0x100014
-#define A_ELMER0_GPO 0x100018
-#define A_ELMER0_PORT0_MI1_CFG 0x400000
+#define A_ELMER0_VERSION       0x100000
+#define A_ELMER0_PHY_CFG       0x100004
+#define A_ELMER0_INT_ENABLE    0x100008
+#define A_ELMER0_INT_CAUSE     0x10000c
+#define A_ELMER0_GPI_CFG       0x100010
+#define A_ELMER0_GPI_STAT      0x100014
+#define A_ELMER0_GPO           0x100018
+#define A_ELMER0_PORT0_MI1_CFG 0x400000
 
 #define S_MI1_MDI_ENABLE    0
 #define V_MI1_MDI_ENABLE(x) ((x) << S_MI1_MDI_ENABLE)
@@ -111,18 +111,18 @@ enum {
 #define V_MI1_OP_BUSY(x) ((x) << S_MI1_OP_BUSY)
 #define F_MI1_OP_BUSY    V_MI1_OP_BUSY(1U)
 
-#define A_ELMER0_PORT1_MI1_CFG 0x500000
-#define A_ELMER0_PORT1_MI1_ADDR 0x500004
-#define A_ELMER0_PORT1_MI1_DATA 0x500008
-#define A_ELMER0_PORT1_MI1_OP 0x50000c
-#define A_ELMER0_PORT2_MI1_CFG 0x600000
-#define A_ELMER0_PORT2_MI1_ADDR 0x600004
-#define A_ELMER0_PORT2_MI1_DATA 0x600008
-#define A_ELMER0_PORT2_MI1_OP 0x60000c
-#define A_ELMER0_PORT3_MI1_CFG 0x700000
-#define A_ELMER0_PORT3_MI1_ADDR 0x700004
-#define A_ELMER0_PORT3_MI1_DATA 0x700008
-#define A_ELMER0_PORT3_MI1_OP 0x70000c
+#define A_ELMER0_PORT1_MI1_CFG 0x500000
+#define A_ELMER0_PORT1_MI1_ADDR        0x500004
+#define A_ELMER0_PORT1_MI1_DATA        0x500008
+#define A_ELMER0_PORT1_MI1_OP  0x50000c
+#define A_ELMER0_PORT2_MI1_CFG 0x600000
+#define A_ELMER0_PORT2_MI1_ADDR        0x600004
+#define A_ELMER0_PORT2_MI1_DATA        0x600008
+#define A_ELMER0_PORT2_MI1_OP  0x60000c
+#define A_ELMER0_PORT3_MI1_CFG 0x700000
+#define A_ELMER0_PORT3_MI1_ADDR        0x700004
+#define A_ELMER0_PORT3_MI1_DATA        0x700008
+#define A_ELMER0_PORT3_MI1_OP  0x70000c
 
 /* Simple bit definition for GPI and GP0 registers. */
 #define     ELMER0_GP_BIT0              0x0001
index 4192f0f5b3ee40c48257079ce65f93fede490c81..d7c5406a6c3f2cb759977d5a9cf11cb6226cbd53 100644 (file)
@@ -202,9 +202,9 @@ static void espi_setup_for_pm3393(adapter_t *adapter)
 
 static void espi_setup_for_vsc7321(adapter_t *adapter)
 {
-        writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN0);
-        writel(0x1f401f4, adapter->regs + A_ESPI_SCH_TOKEN1);
-        writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN2);
+       writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN0);
+       writel(0x1f401f4, adapter->regs + A_ESPI_SCH_TOKEN1);
+       writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN2);
        writel(0xa00, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
        writel(0x1ff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
        writel(1, adapter->regs + A_ESPI_CALENDAR_LENGTH);
@@ -247,10 +247,10 @@ int t1_espi_init(struct peespi *espi, int mac_type, int nports)
                writel(V_OUT_OF_SYNC_COUNT(4) |
                       V_DIP2_PARITY_ERR_THRES(3) |
                       V_DIP4_THRES(1), adapter->regs + A_ESPI_MISC_CONTROL);
-               writel(nports == 4 ? 0x200040 : 0x1000080,
+               writel(nports == 4 ? 0x200040 : 0x1000080,
                       adapter->regs + A_ESPI_MAXBURST1_MAXBURST2);
        } else
-               writel(0x800100, adapter->regs + A_ESPI_MAXBURST1_MAXBURST2);
+               writel(0x800100, adapter->regs + A_ESPI_MAXBURST1_MAXBURST2);
 
        if (mac_type == CHBT_MAC_PM3393)
                espi_setup_for_pm3393(adapter);
@@ -301,7 +301,8 @@ void t1_espi_set_misc_ctrl(adapter_t *adapter, u32 val)
 {
        struct peespi *espi = adapter->espi;
 
-       if (!is_T2(adapter)) return;
+       if (!is_T2(adapter))
+               return;
        spin_lock(&espi->lock);
        espi->misc_ctrl = (val & ~MON_MASK) |
                          (espi->misc_ctrl & MON_MASK);
@@ -340,32 +341,31 @@ u32 t1_espi_get_mon(adapter_t *adapter, u32 addr, u8 wait)
  * compare with t1_espi_get_mon(), it reads espiInTxSop[0 ~ 3] in
  * one shot, since there is no per port counter on the out side.
  */
-int
-t1_espi_get_mon_t204(adapter_t *adapter, u32 *valp, u8 wait)
+int t1_espi_get_mon_t204(adapter_t *adapter, u32 *valp, u8 wait)
 {
-        struct peespi *espi = adapter->espi;
+       struct peespi *espi = adapter->espi;
        u8 i, nport = (u8)adapter->params.nports;
 
-        if (!wait) {
-                if (!spin_trylock(&espi->lock))
-                        return -1;
-        } else
-                spin_lock(&espi->lock);
+       if (!wait) {
+               if (!spin_trylock(&espi->lock))
+                       return -1;
+       } else
+               spin_lock(&espi->lock);
 
-       if ( (espi->misc_ctrl & MON_MASK) != F_MONITORED_DIRECTION ) {
+       if ((espi->misc_ctrl & MON_MASK) != F_MONITORED_DIRECTION) {
                espi->misc_ctrl = (espi->misc_ctrl & ~MON_MASK) |
                                        F_MONITORED_DIRECTION;
-                writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
-       }
+               writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
+       }
        for (i = 0 ; i < nport; i++, valp++) {
                if (i) {
                        writel(espi->misc_ctrl | V_MONITORED_PORT_NUM(i),
                               adapter->regs + A_ESPI_MISC_CONTROL);
                }
-                *valp = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
-        }
+               *valp = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
+       }
 
-        writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
-        spin_unlock(&espi->lock);
-        return 0;
+       writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
+       spin_unlock(&espi->lock);
+       return 0;
 }
index 17a3c2ba36a30edb0a02cb79cce12531ffbee9c7..ccdb2bc9ae9824e63b9f774edb063ef117fbdfda 100644 (file)
@@ -98,9 +98,9 @@
 #define A_MI0_DATA_INT 0xb10
 
 /* GMAC registers */
-#define A_GMAC_MACID_LO 0x28
-#define A_GMAC_MACID_HI 0x2c
-#define A_GMAC_CSR 0x30
+#define A_GMAC_MACID_LO        0x28
+#define A_GMAC_MACID_HI        0x2c
+#define A_GMAC_CSR     0x30
 
 #define S_INTERFACE    0
 #define M_INTERFACE    0x3
index a2b8ad9b55350c808fcca32fc4561ad134b8765e..006a2eb2d3624a0aeeb28de15080dbdd1c8798a8 100644 (file)
 
 #include "common.h"
 
-enum { MAC_STATS_UPDATE_FAST, MAC_STATS_UPDATE_FULL };
-enum { MAC_DIRECTION_RX = 1, MAC_DIRECTION_TX = 2 };
+enum {
+       MAC_STATS_UPDATE_FAST,
+       MAC_STATS_UPDATE_FULL
+};
+
+enum {
+       MAC_DIRECTION_RX = 1,
+       MAC_DIRECTION_TX = 2
+};
 
 struct cmac_statistics {
        /* Transmit */
index 5b8f144e83d47f926b3164a5c71cd91a6fa1205b..10b2a9a190061b4e3ca94f708e784367404ab1de 100644 (file)
@@ -145,48 +145,61 @@ static void disable_port(struct cmac *mac)
        t1_tpi_write(mac->adapter, REG_PORT_ENABLE, val);
 }
 
-#define RMON_UPDATE(mac, name, stat_name) \
-       t1_tpi_read((mac)->adapter, MACREG(mac, REG_##name), &val); \
-       (mac)->stats.stat_name += val;
-
 /*
  * Read the current values of the RMON counters and add them to the cumulative
  * port statistics.  The HW RMON counters are cleared by this operation.
  */
 static void port_stats_update(struct cmac *mac)
 {
-       u32 val;
+       static struct {
+               unsigned int reg;
+               unsigned int offset;
+       } hw_stats[] = {
+
+#define HW_STAT(name, stat_name) \
+       { REG_##name, \
+         (&((struct cmac_statistics *)NULL)->stat_name) - (u64 *)NULL }
+
+               /* Rx stats */
+               HW_STAT(RxOctetsTotalOK, RxOctetsOK),
+               HW_STAT(RxOctetsBad, RxOctetsBad),
+               HW_STAT(RxUCPkts, RxUnicastFramesOK),
+               HW_STAT(RxMCPkts, RxMulticastFramesOK),
+               HW_STAT(RxBCPkts, RxBroadcastFramesOK),
+               HW_STAT(RxJumboPkts, RxJumboFramesOK),
+               HW_STAT(RxFCSErrors, RxFCSErrors),
+               HW_STAT(RxAlignErrors, RxAlignErrors),
+               HW_STAT(RxLongErrors, RxFrameTooLongErrors),
+               HW_STAT(RxVeryLongErrors, RxFrameTooLongErrors),
+               HW_STAT(RxPauseMacControlCounter, RxPauseFrames),
+               HW_STAT(RxDataErrors, RxDataErrors),
+               HW_STAT(RxJabberErrors, RxJabberErrors),
+               HW_STAT(RxRuntErrors, RxRuntErrors),
+               HW_STAT(RxShortErrors, RxRuntErrors),
+               HW_STAT(RxSequenceErrors, RxSequenceErrors),
+               HW_STAT(RxSymbolErrors, RxSymbolErrors),
+
+               /* Tx stats (skip collision stats as we are full-duplex only) */
+               HW_STAT(TxOctetsTotalOK, TxOctetsOK),
+               HW_STAT(TxOctetsBad, TxOctetsBad),
+               HW_STAT(TxUCPkts, TxUnicastFramesOK),
+               HW_STAT(TxMCPkts, TxMulticastFramesOK),
+               HW_STAT(TxBCPkts, TxBroadcastFramesOK),
+               HW_STAT(TxJumboPkts, TxJumboFramesOK),
+               HW_STAT(TxPauseFrames, TxPauseFrames),
+               HW_STAT(TxExcessiveLengthDrop, TxLengthErrors),
+               HW_STAT(TxUnderrun, TxUnderrun),
+               HW_STAT(TxCRCErrors, TxFCSErrors)
+       }, *p = hw_stats;
+       u64 *stats = (u64 *) &mac->stats;
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(hw_stats); i++) {
+               u32 val;
 
-       /* Rx stats */
-       RMON_UPDATE(mac, RxOctetsTotalOK, RxOctetsOK);
-       RMON_UPDATE(mac, RxOctetsBad, RxOctetsBad);
-       RMON_UPDATE(mac, RxUCPkts, RxUnicastFramesOK);
-       RMON_UPDATE(mac, RxMCPkts, RxMulticastFramesOK);
-       RMON_UPDATE(mac, RxBCPkts, RxBroadcastFramesOK);
-       RMON_UPDATE(mac, RxJumboPkts, RxJumboFramesOK);
-       RMON_UPDATE(mac, RxFCSErrors, RxFCSErrors);
-       RMON_UPDATE(mac, RxAlignErrors, RxAlignErrors);
-       RMON_UPDATE(mac, RxLongErrors, RxFrameTooLongErrors);
-       RMON_UPDATE(mac, RxVeryLongErrors, RxFrameTooLongErrors);
-       RMON_UPDATE(mac, RxPauseMacControlCounter, RxPauseFrames);
-       RMON_UPDATE(mac, RxDataErrors, RxDataErrors);
-       RMON_UPDATE(mac, RxJabberErrors, RxJabberErrors);
-       RMON_UPDATE(mac, RxRuntErrors, RxRuntErrors);
-       RMON_UPDATE(mac, RxShortErrors, RxRuntErrors);
-       RMON_UPDATE(mac, RxSequenceErrors, RxSequenceErrors);
-       RMON_UPDATE(mac, RxSymbolErrors, RxSymbolErrors);
-
-       /* Tx stats (skip collision stats as we are full-duplex only) */
-       RMON_UPDATE(mac, TxOctetsTotalOK, TxOctetsOK);
-       RMON_UPDATE(mac, TxOctetsBad, TxOctetsBad);
-       RMON_UPDATE(mac, TxUCPkts, TxUnicastFramesOK);
-       RMON_UPDATE(mac, TxMCPkts, TxMulticastFramesOK);
-       RMON_UPDATE(mac, TxBCPkts, TxBroadcastFramesOK);
-       RMON_UPDATE(mac, TxJumboPkts, TxJumboFramesOK);
-       RMON_UPDATE(mac, TxPauseFrames, TxPauseFrames);
-       RMON_UPDATE(mac, TxExcessiveLengthDrop, TxLengthErrors);
-       RMON_UPDATE(mac, TxUnderrun, TxUnderrun);
-       RMON_UPDATE(mac, TxCRCErrors, TxFCSErrors);
+               t1_tpi_read(mac->adapter, MACREG(mac, p->reg), &val);
+               stats[p->offset] += val;
+       }
 }
 
 /* No-op interrupt operation as this MAC does not support interrupts */
@@ -273,7 +286,8 @@ static int mac_set_rx_mode(struct cmac *mac, struct t1_rx_mode *rm)
 static int mac_set_mtu(struct cmac *mac, int mtu)
 {
        /* MAX_FRAME_SIZE inludes header + FCS, mtu doesn't */
-       if (mtu > (MAX_FRAME_SIZE - 14 - 4)) return -EINVAL;
+       if (mtu > (MAX_FRAME_SIZE - 14 - 4))
+               return -EINVAL;
        t1_tpi_write(mac->adapter, MACREG(mac, REG_MAX_FRAME_SIZE),
                     mtu + 14 + 4);
        return 0;
@@ -357,8 +371,8 @@ static void enable_port(struct cmac *mac)
        val |= (1 << index);
        t1_tpi_write(adapter, REG_PORT_ENABLE, val);
 
-               index <<= 2;
-        if (is_T2(adapter)) {
+       index <<= 2;
+       if (is_T2(adapter)) {
                /* T204: set the Fifo water level & threshold */
                t1_tpi_write(adapter, RX_FIFO_HIGH_WATERMARK_BASE + index, 0x740);
                t1_tpi_write(adapter, RX_FIFO_LOW_WATERMARK_BASE + index, 0x730);
@@ -389,6 +403,10 @@ static int mac_disable(struct cmac *mac, int which)
        return 0;
 }
 
+#define RMON_UPDATE(mac, name, stat_name) \
+       t1_tpi_read((mac)->adapter, MACREG(mac, REG_##name), &val); \
+       (mac)->stats.stat_name += val;
+
 /*
  * This function is called periodically to accumulate the current values of the
  * RMON counters into the port statistics.  Since the counters are only 32 bits
@@ -460,10 +478,12 @@ static struct cmac *ixf1010_mac_create(adapter_t *adapter, int index)
        struct cmac *mac;
        u32 val;
 
-       if (index > 9) return NULL;
+       if (index > 9)
+               return NULL;
 
        mac = kzalloc(sizeof(*mac) + sizeof(cmac_instance), GFP_KERNEL);
-       if (!mac) return NULL;
+       if (!mac)
+               return NULL;
 
        mac->ops = &ixf1010_ops;
        mac->instance = (cmac_instance *)(mac + 1);
index 28ac93ff7c4f6a04c2392a22e334186aa9bca7fd..5867e3b0a887fbf9496fb496ea11a494c8fb38cf 100644 (file)
@@ -73,9 +73,8 @@ static int mv88e1xxx_interrupt_enable(struct cphy *cphy)
 
                t1_tpi_read(cphy->adapter, A_ELMER0_INT_ENABLE, &elmer);
                elmer |= ELMER0_GP_BIT1;
-               if (is_T2(cphy->adapter)) {
-                   elmer |= ELMER0_GP_BIT2|ELMER0_GP_BIT3|ELMER0_GP_BIT4;
-                }
+               if (is_T2(cphy->adapter))
+                   elmer |= ELMER0_GP_BIT2 | ELMER0_GP_BIT3 | ELMER0_GP_BIT4;
                t1_tpi_write(cphy->adapter, A_ELMER0_INT_ENABLE, elmer);
        }
        return 0;
@@ -92,9 +91,8 @@ static int mv88e1xxx_interrupt_disable(struct cphy *cphy)
 
                t1_tpi_read(cphy->adapter, A_ELMER0_INT_ENABLE, &elmer);
                elmer &= ~ELMER0_GP_BIT1;
-               if (is_T2(cphy->adapter)) {
+               if (is_T2(cphy->adapter))
                    elmer &= ~(ELMER0_GP_BIT2|ELMER0_GP_BIT3|ELMER0_GP_BIT4);
-                }
                t1_tpi_write(cphy->adapter, A_ELMER0_INT_ENABLE, elmer);
        }
        return 0;
@@ -112,9 +110,8 @@ static int mv88e1xxx_interrupt_clear(struct cphy *cphy)
        if (t1_is_asic(cphy->adapter)) {
                t1_tpi_read(cphy->adapter, A_ELMER0_INT_CAUSE, &elmer);
                elmer |= ELMER0_GP_BIT1;
-               if (is_T2(cphy->adapter)) {
+               if (is_T2(cphy->adapter))
                    elmer |= ELMER0_GP_BIT2|ELMER0_GP_BIT3|ELMER0_GP_BIT4;
-                }
                t1_tpi_write(cphy->adapter, A_ELMER0_INT_CAUSE, elmer);
        }
        return 0;
@@ -300,7 +297,7 @@ static int mv88e1xxx_interrupt_handler(struct cphy *cphy)
 
        /*
         * Loop until cause reads zero. Need to handle bouncing interrupts.
-         */
+        */
        while (1) {
                u32 cause;
 
@@ -308,15 +305,16 @@ static int mv88e1xxx_interrupt_handler(struct cphy *cphy)
                                MV88E1XXX_INTERRUPT_STATUS_REGISTER,
                                &cause);
                cause &= INTR_ENABLE_MASK;
-               if (!cause) break;
+               if (!cause)
+                       break;
 
                if (cause & MV88E1XXX_INTR_LINK_CHNG) {
                        (void) simple_mdio_read(cphy,
                                MV88E1XXX_SPECIFIC_STATUS_REGISTER, &status);
 
-                       if (status & MV88E1XXX_INTR_LINK_CHNG) {
+                       if (status & MV88E1XXX_INTR_LINK_CHNG)
                                cphy->state |= PHY_LINK_UP;
-                       else {
+                       else {
                                cphy->state &= ~PHY_LINK_UP;
                                if (cphy->state & PHY_AUTONEG_EN)
                                        cphy->state &= ~PHY_AUTONEG_RDY;
@@ -360,7 +358,8 @@ static struct cphy *mv88e1xxx_phy_create(adapter_t *adapter, int phy_addr,
 {
        struct cphy *cphy = kzalloc(sizeof(*cphy), GFP_KERNEL);
 
-       if (!cphy) return NULL;
+       if (!cphy)
+               return NULL;
 
        cphy_init(cphy, adapter, phy_addr, &mv88e1xxx_ops, mdio_ops);
 
@@ -377,11 +376,11 @@ static struct cphy *mv88e1xxx_phy_create(adapter_t *adapter, int phy_addr,
        }
        (void) mv88e1xxx_downshift_set(cphy, 1);   /* Enable downshift */
 
-        /* LED */
+       /* LED */
        if (is_T2(adapter)) {
                (void) simple_mdio_write(cphy,
                                MV88E1XXX_LED_CONTROL_REGISTER, 0x1);
-        }
+       }
 
        return cphy;
 }
index 82fed1dd5005525b1fdbc44d78db6de46e33d6f6..87dde3e600468a465bfb6bc7c5b73ae01c45d85a 100644 (file)
@@ -10,25 +10,25 @@ static int my3126_reset(struct cphy *cphy, int wait)
         * This can be done through registers.  It is not required since
         * a full chip reset is used.
         */
-       return (0);
+       return 0;
 }
 
 static int my3126_interrupt_enable(struct cphy *cphy)
 {
        schedule_delayed_work(&cphy->phy_update, HZ/30);
        t1_tpi_read(cphy->adapter, A_ELMER0_GPO, &cphy->elmer_gpo);
-       return (0);
+       return 0;
 }
 
 static int my3126_interrupt_disable(struct cphy *cphy)
 {
        cancel_rearming_delayed_work(&cphy->phy_update);
-       return (0);
+       return 0;
 }
 
 static int my3126_interrupt_clear(struct cphy *cphy)
 {
-       return (0);
+       return 0;
 }
 
 #define OFFSET(REG_ADDR)    (REG_ADDR << 2)
@@ -102,7 +102,7 @@ static void my3216_poll(struct work_struct *work)
 
 static int my3126_set_loopback(struct cphy *cphy, int on)
 {
-       return (0);
+       return 0;
 }
 
 /* To check the activity LED */
@@ -146,7 +146,7 @@ static int my3126_get_link_status(struct cphy *cphy,
        if (fc)
                *fc = PAUSE_RX | PAUSE_TX;
 
-       return (0);
+       return 0;
 }
 
 static void my3126_destroy(struct cphy *cphy)
@@ -177,7 +177,7 @@ static struct cphy *my3126_phy_create(adapter_t *adapter,
        INIT_DELAYED_WORK(&cphy->phy_update, my3216_poll);
        cphy->bmsr = 0;
 
-       return (cphy);
+       return cphy;
 }
 
 /* Chip Reset */
@@ -198,7 +198,7 @@ static int my3126_phy_reset(adapter_t * adapter)
        val |= 0x8000;
        t1_tpi_write(adapter, A_ELMER0_GPO, val);
        udelay(100);
-       return (0);
+       return 0;
 }
 
 struct gphy t1_my3126_ops = {
index 63cabeb98afef66203a741803638ab90321bf7d7..69129edeefd64ad266e35785f346ed5171303bd2 100644 (file)
@@ -446,17 +446,51 @@ static void pm3393_rmon_update(struct adapter *adapter, u32 offs, u64 *val,
                *val += 1ull << 40;
 }
 
-#define RMON_UPDATE(mac, name, stat_name) \
-       pm3393_rmon_update((mac)->adapter, OFFSET(name),                \
-                          &(mac)->stats.stat_name,                     \
-                  (ro &((name - SUNI1x10GEXP_REG_MSTAT_COUNTER_0_LOW) >> 2)))
-
-
 static const struct cmac_statistics *pm3393_update_statistics(struct cmac *mac,
                                                              int flag)
 {
-       u64     ro;
-       u32     val0, val1, val2, val3;
+       static struct {
+               unsigned int reg;
+               unsigned int offset;
+       } hw_stats [] = {
+
+#define HW_STAT(name, stat_name) \
+       { name, (&((struct cmac_statistics *)NULL)->stat_name) - (u64 *)NULL }
+
+               /* Rx stats */
+               HW_STAT(RxOctetsReceivedOK, RxOctetsOK),
+               HW_STAT(RxUnicastFramesReceivedOK, RxUnicastFramesOK),
+               HW_STAT(RxMulticastFramesReceivedOK, RxMulticastFramesOK),
+               HW_STAT(RxBroadcastFramesReceivedOK, RxBroadcastFramesOK),
+               HW_STAT(RxPAUSEMACCtrlFramesReceived, RxPauseFrames),
+               HW_STAT(RxFrameCheckSequenceErrors, RxFCSErrors),
+               HW_STAT(RxFramesLostDueToInternalMACErrors,
+                               RxInternalMACRcvError),
+               HW_STAT(RxSymbolErrors, RxSymbolErrors),
+               HW_STAT(RxInRangeLengthErrors, RxInRangeLengthErrors),
+               HW_STAT(RxFramesTooLongErrors , RxFrameTooLongErrors),
+               HW_STAT(RxJabbers, RxJabberErrors),
+               HW_STAT(RxFragments, RxRuntErrors),
+               HW_STAT(RxUndersizedFrames, RxRuntErrors),
+               HW_STAT(RxJumboFramesReceivedOK, RxJumboFramesOK),
+               HW_STAT(RxJumboOctetsReceivedOK, RxJumboOctetsOK),
+
+               /* Tx stats */
+               HW_STAT(TxOctetsTransmittedOK, TxOctetsOK),
+               HW_STAT(TxFramesLostDueToInternalMACTransmissionError,
+                               TxInternalMACXmitError),
+               HW_STAT(TxTransmitSystemError, TxFCSErrors),
+               HW_STAT(TxUnicastFramesTransmittedOK, TxUnicastFramesOK),
+               HW_STAT(TxMulticastFramesTransmittedOK, TxMulticastFramesOK),
+               HW_STAT(TxBroadcastFramesTransmittedOK, TxBroadcastFramesOK),
+               HW_STAT(TxPAUSEMACCtrlFramesTransmitted, TxPauseFrames),
+               HW_STAT(TxJumboFramesReceivedOK, TxJumboFramesOK),
+               HW_STAT(TxJumboOctetsReceivedOK, TxJumboOctetsOK)
+       }, *p = hw_stats;
+       u64 ro;
+       u32 val0, val1, val2, val3;
+       u64 *stats = (u64 *) &mac->stats;
+       unsigned int i;
 
        /* Snap the counters */
        pmwrite(mac, SUNI1x10GEXP_REG_MSTAT_CONTROL,
@@ -470,35 +504,14 @@ static const struct cmac_statistics *pm3393_update_statistics(struct cmac *mac,
        ro = ((u64)val0 & 0xffff) | (((u64)val1 & 0xffff) << 16) |
                (((u64)val2 & 0xffff) << 32) | (((u64)val3 & 0xffff) << 48);
 
-       /* Rx stats */
-       RMON_UPDATE(mac, RxOctetsReceivedOK, RxOctetsOK);
-       RMON_UPDATE(mac, RxUnicastFramesReceivedOK, RxUnicastFramesOK);
-       RMON_UPDATE(mac, RxMulticastFramesReceivedOK, RxMulticastFramesOK);
-       RMON_UPDATE(mac, RxBroadcastFramesReceivedOK, RxBroadcastFramesOK);
-       RMON_UPDATE(mac, RxPAUSEMACCtrlFramesReceived, RxPauseFrames);
-       RMON_UPDATE(mac, RxFrameCheckSequenceErrors, RxFCSErrors);
-       RMON_UPDATE(mac, RxFramesLostDueToInternalMACErrors,
-                               RxInternalMACRcvError);
-       RMON_UPDATE(mac, RxSymbolErrors, RxSymbolErrors);
-       RMON_UPDATE(mac, RxInRangeLengthErrors, RxInRangeLengthErrors);
-       RMON_UPDATE(mac, RxFramesTooLongErrors , RxFrameTooLongErrors);
-       RMON_UPDATE(mac, RxJabbers, RxJabberErrors);
-       RMON_UPDATE(mac, RxFragments, RxRuntErrors);
-       RMON_UPDATE(mac, RxUndersizedFrames, RxRuntErrors);
-       RMON_UPDATE(mac, RxJumboFramesReceivedOK, RxJumboFramesOK);
-       RMON_UPDATE(mac, RxJumboOctetsReceivedOK, RxJumboOctetsOK);
-
-       /* Tx stats */
-       RMON_UPDATE(mac, TxOctetsTransmittedOK, TxOctetsOK);
-       RMON_UPDATE(mac, TxFramesLostDueToInternalMACTransmissionError,
-                               TxInternalMACXmitError);
-       RMON_UPDATE(mac, TxTransmitSystemError, TxFCSErrors);
-       RMON_UPDATE(mac, TxUnicastFramesTransmittedOK, TxUnicastFramesOK);
-       RMON_UPDATE(mac, TxMulticastFramesTransmittedOK, TxMulticastFramesOK);
-       RMON_UPDATE(mac, TxBroadcastFramesTransmittedOK, TxBroadcastFramesOK);
-       RMON_UPDATE(mac, TxPAUSEMACCtrlFramesTransmitted, TxPauseFrames);
-       RMON_UPDATE(mac, TxJumboFramesReceivedOK, TxJumboFramesOK);
-       RMON_UPDATE(mac, TxJumboOctetsReceivedOK, TxJumboOctetsOK);
+       for (i = 0; i < ARRAY_SIZE(hw_stats); i++) {
+               unsigned reg = p->reg - SUNI1x10GEXP_REG_MSTAT_COUNTER_0_LOW;
+
+               pm3393_rmon_update((mac)->adapter, OFFSET(p->reg),
+                                  stats + p->offset, ro & (reg >> 2));
+       }
+
+
 
        return &mac->stats;
 }
@@ -534,9 +547,9 @@ static int pm3393_macaddress_set(struct cmac *cmac, u8 ma[6])
        /* Store local copy */
        memcpy(cmac->instance->mac_addr, ma, 6);
 
-       lo = ((u32) ma[1] << 8) | (u32) ma[0];
+       lo  = ((u32) ma[1] << 8) | (u32) ma[0];
        mid = ((u32) ma[3] << 8) | (u32) ma[2];
-       hi = ((u32) ma[5] << 8) | (u32) ma[4];
+       hi  = ((u32) ma[5] << 8) | (u32) ma[4];
 
        /* Disable Rx/Tx MAC before configuring it. */
        if (enabled)
index 659cb2252e4439a77a00f90e8cb711c41c2be40c..89a682702fa90a57201a7b4fe463ffa2a6287efe 100644 (file)
 #define SGE_FREEL_REFILL_THRESH        16
 #define SGE_RESPQ_E_N          1024
 #define SGE_INTRTIMER_NRES     1000
-#define SGE_RX_COPY_THRES      256
 #define SGE_RX_SM_BUF_SIZE     1536
 #define SGE_TX_DESC_MAX_PLEN   16384
 
-# define SGE_RX_DROP_THRES 2
-
 #define SGE_RESPQ_REPLENISH_THRES (SGE_RESPQ_E_N / 4)
 
 /*
  */
 #define TX_RECLAIM_PERIOD (HZ / 4)
 
-#ifndef NET_IP_ALIGN
-# define NET_IP_ALIGN 2
-#endif
-
 #define M_CMD_LEN       0x7fffffff
 #define V_CMD_LEN(v)    (v)
 #define G_CMD_LEN(v)    ((v) & M_CMD_LEN)
@@ -195,7 +188,7 @@ struct cmdQ {
        struct cmdQ_e  *entries;        /* HW command descriptor Q */
        struct cmdQ_ce *centries;       /* SW command context descriptor Q */
        dma_addr_t      dma_addr;       /* DMA addr HW command descriptor Q */
-       spinlock_t      lock;           /* Lock to protect cmdQ enqueuing */
+       spinlock_t      lock;           /* Lock to protect cmdQ enqueuing */
 };
 
 struct freelQ {
@@ -241,9 +234,9 @@ struct sched_port {
 /* Per T204 device */
 struct sched {
        ktime_t         last_updated;   /* last time quotas were computed */
-       unsigned int    max_avail;      /* max bits to be sent to any port */
-       unsigned int    port;           /* port index (round robin ports) */
-       unsigned int    num;            /* num skbs in per port queues */
+       unsigned int    max_avail;      /* max bits to be sent to any port */
+       unsigned int    port;           /* port index (round robin ports) */
+       unsigned int    num;            /* num skbs in per port queues */
        struct sched_port p[MAX_NPORTS];
        struct tasklet_struct sched_tsk;/* tasklet used to run scheduler */
 };
@@ -259,10 +252,10 @@ static void restart_sched(unsigned long);
  * contention.
  */
 struct sge {
-       struct adapter *adapter;        /* adapter backpointer */
+       struct adapter *adapter;        /* adapter backpointer */
        struct net_device *netdev;      /* netdevice backpointer */
-       struct freelQ   freelQ[SGE_FREELQ_N]; /* buffer free lists */
-       struct respQ    respQ;          /* response Q */
+       struct freelQ   freelQ[SGE_FREELQ_N]; /* buffer free lists */
+       struct respQ    respQ;          /* response Q */
        unsigned long   stopped_tx_queues; /* bitmap of suspended Tx queues */
        unsigned int    rx_pkt_pad;     /* RX padding for L2 packets */
        unsigned int    jumbo_fl;       /* jumbo freelist Q index */
@@ -460,7 +453,7 @@ static struct sk_buff *sched_skb(struct sge *sge, struct sk_buff *skb,
        if (credits < MAX_SKB_FRAGS + 1)
                goto out;
 
- again:
+again:
        for (i = 0; i < MAX_NPORTS; i++) {
                s->port = ++s->port & (MAX_NPORTS - 1);
                skbq = &s->p[s->port].skbq;
@@ -483,8 +476,8 @@ static struct sk_buff *sched_skb(struct sge *sge, struct sk_buff *skb,
        if (update-- && sched_update_avail(sge))
                goto again;
 
- out:
-       /* If there are more pending skbs, we use the hardware to schedule us
+out:
+       /* If there are more pending skbs, we use the hardware to schedule us
         * again.
         */
        if (s->num && !skb) {
@@ -575,11 +568,10 @@ static int alloc_rx_resources(struct sge *sge, struct sge_params *p)
                q->size = p->freelQ_size[i];
                q->dma_offset = sge->rx_pkt_pad ? 0 : NET_IP_ALIGN;
                size = sizeof(struct freelQ_e) * q->size;
-               q->entries = (struct freelQ_e *)
-                             pci_alloc_consistent(pdev, size, &q->dma_addr);
+               q->entries = pci_alloc_consistent(pdev, size, &q->dma_addr);
                if (!q->entries)
                        goto err_no_mem;
-               memset(q->entries, 0, size);
+
                size = sizeof(struct freelQ_ce) * q->size;
                q->centries = kzalloc(size, GFP_KERNEL);
                if (!q->centries)
@@ -613,11 +605,10 @@ static int alloc_rx_resources(struct sge *sge, struct sge_params *p)
        sge->respQ.size = SGE_RESPQ_E_N;
        sge->respQ.credits = 0;
        size = sizeof(struct respQ_e) * sge->respQ.size;
-       sge->respQ.entries = (struct respQ_e *)
+       sge->respQ.entries =
                pci_alloc_consistent(pdev, size, &sge->respQ.dma_addr);
        if (!sge->respQ.entries)
                goto err_no_mem;
-       memset(sge->respQ.entries, 0, size);
        return 0;
 
 err_no_mem:
@@ -637,20 +628,12 @@ static void free_cmdQ_buffers(struct sge *sge, struct cmdQ *q, unsigned int n)
        q->in_use -= n;
        ce = &q->centries[cidx];
        while (n--) {
-               if (q->sop) {
-                       if (likely(pci_unmap_len(ce, dma_len))) {
-                               pci_unmap_single(pdev,
-                                                pci_unmap_addr(ce, dma_addr),
-                                                pci_unmap_len(ce, dma_len),
-                                                PCI_DMA_TODEVICE);
+               if (likely(pci_unmap_len(ce, dma_len))) {
+                       pci_unmap_single(pdev, pci_unmap_addr(ce, dma_addr),
+                                        pci_unmap_len(ce, dma_len),
+                                        PCI_DMA_TODEVICE);
+                       if (q->sop)
                                q->sop = 0;
-                       }
-               } else {
-                       if (likely(pci_unmap_len(ce, dma_len))) {
-                               pci_unmap_page(pdev, pci_unmap_addr(ce, dma_addr),
-                                              pci_unmap_len(ce, dma_len),
-                                              PCI_DMA_TODEVICE);
-                       }
                }
                if (ce->skb) {
                        dev_kfree_skb_any(ce->skb);
@@ -711,11 +694,10 @@ static int alloc_tx_resources(struct sge *sge, struct sge_params *p)
                q->stop_thres = 0;
                spin_lock_init(&q->lock);
                size = sizeof(struct cmdQ_e) * q->size;
-               q->entries = (struct cmdQ_e *)
-                             pci_alloc_consistent(pdev, size, &q->dma_addr);
+               q->entries = pci_alloc_consistent(pdev, size, &q->dma_addr);
                if (!q->entries)
                        goto err_no_mem;
-               memset(q->entries, 0, size);
+
                size = sizeof(struct cmdQ_ce) * q->size;
                q->centries = kzalloc(size, GFP_KERNEL);
                if (!q->centries)
@@ -770,7 +752,7 @@ void t1_set_vlan_accel(struct adapter *adapter, int on_off)
 static void configure_sge(struct sge *sge, struct sge_params *p)
 {
        struct adapter *ap = sge->adapter;
-       
+
        writel(0, ap->regs + A_SG_CONTROL);
        setup_ring_params(ap, sge->cmdQ[0].dma_addr, sge->cmdQ[0].size,
                          A_SG_CMD0BASELWR, A_SG_CMD0BASEUPR, A_SG_CMD0SIZE);
@@ -850,7 +832,6 @@ static void refill_free_list(struct sge *sge, struct freelQ *q)
        struct freelQ_e *e = &q->entries[q->pidx];
        unsigned int dma_len = q->rx_buffer_size - q->dma_offset;
 
-
        while (q->credits < q->size) {
                struct sk_buff *skb;
                dma_addr_t mapping;
@@ -862,6 +843,8 @@ static void refill_free_list(struct sge *sge, struct freelQ *q)
                skb_reserve(skb, q->dma_offset);
                mapping = pci_map_single(pdev, skb->data, dma_len,
                                         PCI_DMA_FROMDEVICE);
+               skb_reserve(skb, sge->rx_pkt_pad);
+
                ce->skb = skb;
                pci_unmap_addr_set(ce, dma_addr, mapping);
                pci_unmap_len_set(ce, dma_len, dma_len);
@@ -881,7 +864,6 @@ static void refill_free_list(struct sge *sge, struct freelQ *q)
                }
                q->credits++;
        }
-
 }
 
 /*
@@ -1041,6 +1023,10 @@ static void recycle_fl_buf(struct freelQ *fl, int idx)
        }
 }
 
+static int copybreak __read_mostly = 256;
+module_param(copybreak, int, 0);
+MODULE_PARM_DESC(copybreak, "Receive copy threshold");
+
 /**
  *     get_packet - return the next ingress packet buffer
  *     @pdev: the PCI device that received the packet
@@ -1060,45 +1046,42 @@ static void recycle_fl_buf(struct freelQ *fl, int idx)
  *     be copied but there is no memory for the copy.
  */
 static inline struct sk_buff *get_packet(struct pci_dev *pdev,
-                                        struct freelQ *fl, unsigned int len,
-                                        int dma_pad, int skb_pad,
-                                        unsigned int copy_thres,
-                                        unsigned int drop_thres)
+                                        struct freelQ *fl, unsigned int len)
 {
        struct sk_buff *skb;
-       struct freelQ_ce *ce = &fl->centries[fl->cidx];
+       const struct freelQ_ce *ce = &fl->centries[fl->cidx];
 
-       if (len < copy_thres) {
-               skb = alloc_skb(len + skb_pad, GFP_ATOMIC);
-               if (likely(skb != NULL)) {
-                       skb_reserve(skb, skb_pad);
-                       skb_put(skb, len);
-                       pci_dma_sync_single_for_cpu(pdev,
-                                           pci_unmap_addr(ce, dma_addr),
-                                           pci_unmap_len(ce, dma_len),
-                                           PCI_DMA_FROMDEVICE);
-                       memcpy(skb->data, ce->skb->data + dma_pad, len);
-                       pci_dma_sync_single_for_device(pdev,
-                                           pci_unmap_addr(ce, dma_addr),
-                                           pci_unmap_len(ce, dma_len),
-                                           PCI_DMA_FROMDEVICE);
-               } else if (!drop_thres)
+       if (len < copybreak) {
+               skb = alloc_skb(len + 2, GFP_ATOMIC);
+               if (!skb)
                        goto use_orig_buf;
 
+               skb_reserve(skb, 2);    /* align IP header */
+               skb_put(skb, len);
+               pci_dma_sync_single_for_cpu(pdev,
+                                           pci_unmap_addr(ce, dma_addr),
+                                           pci_unmap_len(ce, dma_len),
+                                           PCI_DMA_FROMDEVICE);
+               memcpy(skb->data, ce->skb->data, len);
+               pci_dma_sync_single_for_device(pdev,
+                                              pci_unmap_addr(ce, dma_addr),
+                                              pci_unmap_len(ce, dma_len),
+                                              PCI_DMA_FROMDEVICE);
                recycle_fl_buf(fl, fl->cidx);
                return skb;
        }
 
-       if (fl->credits < drop_thres) {
+use_orig_buf:
+       if (fl->credits < 2) {
                recycle_fl_buf(fl, fl->cidx);
                return NULL;
        }
 
-use_orig_buf:
        pci_unmap_single(pdev, pci_unmap_addr(ce, dma_addr),
                         pci_unmap_len(ce, dma_len), PCI_DMA_FROMDEVICE);
        skb = ce->skb;
-       skb_reserve(skb, dma_pad);
+       prefetch(skb->data);
+
        skb_put(skb, len);
        return skb;
 }
@@ -1137,6 +1120,7 @@ static void unexpected_offload(struct adapter *adapter, struct freelQ *fl)
 static inline unsigned int compute_large_page_tx_descs(struct sk_buff *skb)
 {
        unsigned int count = 0;
+
        if (PAGE_SIZE > SGE_TX_DESC_MAX_PLEN) {
                unsigned int nfrags = skb_shinfo(skb)->nr_frags;
                unsigned int i, len = skb->len - skb->data_len;
@@ -1343,7 +1327,7 @@ static void restart_sched(unsigned long arg)
        while ((skb = sched_skb(sge, NULL, credits)) != NULL) {
                unsigned int genbit, pidx, count;
                count = 1 + skb_shinfo(skb)->nr_frags;
-                       count += compute_large_page_tx_descs(skb);
+               count += compute_large_page_tx_descs(skb);
                q->in_use += count;
                genbit = q->genbit;
                pidx = q->pidx;
@@ -1375,27 +1359,25 @@ static void restart_sched(unsigned long arg)
  *
  *     Process an ingress ethernet pakcet and deliver it to the stack.
  */
-static int sge_rx(struct sge *sge, struct freelQ *fl, unsigned int len)
+static void sge_rx(struct sge *sge, struct freelQ *fl, unsigned int len)
 {
        struct sk_buff *skb;
-       struct cpl_rx_pkt *p;
+       const struct cpl_rx_pkt *p;
        struct adapter *adapter = sge->adapter;
        struct sge_port_stats *st;
 
-       skb = get_packet(adapter->pdev, fl, len - sge->rx_pkt_pad,
-                        sge->rx_pkt_pad, 2, SGE_RX_COPY_THRES,
-                        SGE_RX_DROP_THRES);
+       skb = get_packet(adapter->pdev, fl, len - sge->rx_pkt_pad);
        if (unlikely(!skb)) {
                sge->stats.rx_drops++;
-               return 0;
+               return;
        }
 
-       p = (struct cpl_rx_pkt *)skb->data;
-       skb_pull(skb, sizeof(*p));
+       p = (const struct cpl_rx_pkt *) skb->data;
        if (p->iff >= adapter->params.nports) {
                kfree_skb(skb);
-               return 0;
+               return;
        }
+       __skb_pull(skb, sizeof(*p));
 
        skb->dev = adapter->port[p->iff].dev;
        skb->dev->last_rx = jiffies;
@@ -1427,7 +1409,6 @@ static int sge_rx(struct sge *sge, struct freelQ *fl, unsigned int len)
                netif_rx(skb);
 #endif
        }
-       return 0;
 }
 
 /*
@@ -1448,29 +1429,28 @@ static inline int enough_free_Tx_descs(const struct cmdQ *q)
 static void restart_tx_queues(struct sge *sge)
 {
        struct adapter *adap = sge->adapter;
+       int i;
 
-       if (enough_free_Tx_descs(&sge->cmdQ[0])) {
-               int i;
+       if (!enough_free_Tx_descs(&sge->cmdQ[0]))
+               return;
 
-               for_each_port(adap, i) {
-                       struct net_device *nd = adap->port[i].dev;
+       for_each_port(adap, i) {
+               struct net_device *nd = adap->port[i].dev;
 
-                       if (test_and_clear_bit(nd->if_port,
-                                              &sge->stopped_tx_queues) &&
-                           netif_running(nd)) {
-                               sge->stats.cmdQ_restarted[2]++;
-                               netif_wake_queue(nd);
-                       }
+               if (test_and_clear_bit(nd->if_port, &sge->stopped_tx_queues) &&
+                   netif_running(nd)) {
+                       sge->stats.cmdQ_restarted[2]++;
+                       netif_wake_queue(nd);
                }
        }
 }
 
 /*
- * update_tx_info is called from the interrupt handler/NAPI to return cmdQ0 
+ * update_tx_info is called from the interrupt handler/NAPI to return cmdQ0
  * information.
  */
-static unsigned int update_tx_info(struct adapter *adapter, 
-                                         unsigned int flags, 
+static unsigned int update_tx_info(struct adapter *adapter,
+                                         unsigned int flags,
                                          unsigned int pr0)
 {
        struct sge *sge = adapter->sge;
@@ -1510,29 +1490,30 @@ static int process_responses(struct adapter *adapter, int budget)
        struct sge *sge = adapter->sge;
        struct respQ *q = &sge->respQ;
        struct respQ_e *e = &q->entries[q->cidx];
-       int budget_left = budget;
+       int done = 0;
        unsigned int flags = 0;
        unsigned int cmdq_processed[SGE_CMDQ_N] = {0, 0};
-       
 
-       while (likely(budget_left && e->GenerationBit == q->genbit)) {
+       while (done < budget && e->GenerationBit == q->genbit) {
                flags |= e->Qsleeping;
-               
+
                cmdq_processed[0] += e->Cmdq0CreditReturn;
                cmdq_processed[1] += e->Cmdq1CreditReturn;
-               
+
                /* We batch updates to the TX side to avoid cacheline
                 * ping-pong of TX state information on MP where the sender
                 * might run on a different CPU than this function...
                 */
-               if (unlikely(flags & F_CMDQ0_ENABLE || cmdq_processed[0] > 64)) {
+               if (unlikely((flags & F_CMDQ0_ENABLE) || cmdq_processed[0] > 64)) {
                        flags = update_tx_info(adapter, flags, cmdq_processed[0]);
                        cmdq_processed[0] = 0;
                }
+
                if (unlikely(cmdq_processed[1] > 16)) {
                        sge->cmdQ[1].processed += cmdq_processed[1];
                        cmdq_processed[1] = 0;
                }
+
                if (likely(e->DataValid)) {
                        struct freelQ *fl = &sge->freelQ[e->FreelistQid];
 
@@ -1542,12 +1523,16 @@ static int process_responses(struct adapter *adapter, int budget)
                        else
                                sge_rx(sge, fl, e->BufferLength);
 
+                       ++done;
+
                        /*
                         * Note: this depends on each packet consuming a
                         * single free-list buffer; cf. the BUG above.
                         */
                        if (++fl->cidx == fl->size)
                                fl->cidx = 0;
+                       prefetch(fl->centries[fl->cidx].skb);
+
                        if (unlikely(--fl->credits <
                                     fl->size - SGE_FREEL_REFILL_THRESH))
                                refill_free_list(sge, fl);
@@ -1566,14 +1551,20 @@ static int process_responses(struct adapter *adapter, int budget)
                        writel(q->credits, adapter->regs + A_SG_RSPQUEUECREDIT);
                        q->credits = 0;
                }
-               --budget_left;
        }
 
-       flags = update_tx_info(adapter, flags, cmdq_processed[0]); 
+       flags = update_tx_info(adapter, flags, cmdq_processed[0]);
        sge->cmdQ[1].processed += cmdq_processed[1];
 
-       budget -= budget_left;
-       return budget;
+       return done;
+}
+
+static inline int responses_pending(const struct adapter *adapter)
+{
+       const struct respQ *Q = &adapter->sge->respQ;
+       const struct respQ_e *e = &Q->entries[Q->cidx];
+
+       return (e->GenerationBit == Q->genbit);
 }
 
 #ifdef CONFIG_CHELSIO_T1_NAPI
@@ -1585,19 +1576,25 @@ static int process_responses(struct adapter *adapter, int budget)
  * which the caller must ensure is a valid pure response.  Returns 1 if it
  * encounters a valid data-carrying response, 0 otherwise.
  */
-static int process_pure_responses(struct adapter *adapter, struct respQ_e *e)
+static int process_pure_responses(struct adapter *adapter)
 {
        struct sge *sge = adapter->sge;
        struct respQ *q = &sge->respQ;
+       struct respQ_e *e = &q->entries[q->cidx];
+       const struct freelQ *fl = &sge->freelQ[e->FreelistQid];
        unsigned int flags = 0;
        unsigned int cmdq_processed[SGE_CMDQ_N] = {0, 0};
 
+       prefetch(fl->centries[fl->cidx].skb);
+       if (e->DataValid)
+               return 1;
+
        do {
                flags |= e->Qsleeping;
 
                cmdq_processed[0] += e->Cmdq0CreditReturn;
                cmdq_processed[1] += e->Cmdq1CreditReturn;
-               
+
                e++;
                if (unlikely(++q->cidx == q->size)) {
                        q->cidx = 0;
@@ -1613,7 +1610,7 @@ static int process_pure_responses(struct adapter *adapter, struct respQ_e *e)
                sge->stats.pure_rsps++;
        } while (e->GenerationBit == q->genbit && !e->DataValid);
 
-       flags = update_tx_info(adapter, flags, cmdq_processed[0]); 
+       flags = update_tx_info(adapter, flags, cmdq_processed[0]);
        sge->cmdQ[1].processed += cmdq_processed[1];
 
        return e->GenerationBit == q->genbit;
@@ -1627,23 +1624,20 @@ static int process_pure_responses(struct adapter *adapter, struct respQ_e *e)
 int t1_poll(struct net_device *dev, int *budget)
 {
        struct adapter *adapter = dev->priv;
-       int effective_budget = min(*budget, dev->quota);
-       int work_done = process_responses(adapter, effective_budget);
+       int work_done;
 
+       work_done = process_responses(adapter, min(*budget, dev->quota));
        *budget -= work_done;
        dev->quota -= work_done;
 
-       if (work_done >= effective_budget)
+       if (unlikely(responses_pending(adapter)))
                return 1;
 
-       spin_lock_irq(&adapter->async_lock);
-       __netif_rx_complete(dev);
+       netif_rx_complete(dev);
        writel(adapter->sge->respQ.cidx, adapter->regs + A_SG_SLEEPING);
-       writel(adapter->slow_intr_mask | F_PL_INTR_SGE_DATA,
-              adapter->regs + A_PL_ENABLE);
-       spin_unlock_irq(&adapter->async_lock);
 
        return 0;
+
 }
 
 /*
@@ -1652,44 +1646,33 @@ int t1_poll(struct net_device *dev, int *budget)
 irqreturn_t t1_interrupt(int irq, void *data)
 {
        struct adapter *adapter = data;
-       struct net_device *dev = adapter->sge->netdev;
        struct sge *sge = adapter->sge;
-       u32 cause;
-       int handled = 0;
+       int handled;
 
-       cause = readl(adapter->regs + A_PL_CAUSE);
-       if (cause == 0 || cause == ~0)
-               return IRQ_NONE;
+       if (likely(responses_pending(adapter))) {
+               struct net_device *dev = sge->netdev;
 
-       spin_lock(&adapter->async_lock);
-       if (cause & F_PL_INTR_SGE_DATA) {
-               struct respQ *q = &adapter->sge->respQ;
-               struct respQ_e *e = &q->entries[q->cidx];
-
-               handled = 1;
-               writel(F_PL_INTR_SGE_DATA, adapter->regs + A_PL_CAUSE);
-
-               if (e->GenerationBit == q->genbit &&
-                   __netif_rx_schedule_prep(dev)) {
-                       if (e->DataValid || process_pure_responses(adapter, e)) {
-                               /* mask off data IRQ */
-                               writel(adapter->slow_intr_mask,
-                                      adapter->regs + A_PL_ENABLE);
-                               __netif_rx_schedule(sge->netdev);
-                               goto unlock;
-                       }
-                       /* no data, no NAPI needed */
-                       netif_poll_enable(dev);
+               writel(F_PL_INTR_SGE_DATA, adapter->regs + A_PL_CAUSE);
 
+               if (__netif_rx_schedule_prep(dev)) {
+                       if (process_pure_responses(adapter))
+                               __netif_rx_schedule(dev);
+                       else {
+                               /* no data, no NAPI needed */
+                               writel(sge->respQ.cidx, adapter->regs + A_SG_SLEEPING);
+                               netif_poll_enable(dev); /* undo schedule_prep */
+                       }
                }
-               writel(q->cidx, adapter->regs + A_SG_SLEEPING);
-       } else
-               handled = t1_slow_intr_handler(adapter);
+               return IRQ_HANDLED;
+       }
+
+       spin_lock(&adapter->async_lock);
+       handled = t1_slow_intr_handler(adapter);
+       spin_unlock(&adapter->async_lock);
 
        if (!handled)
                sge->stats.unhandled_irqs++;
-unlock:
-       spin_unlock(&adapter->async_lock);
+
        return IRQ_RETVAL(handled != 0);
 }
 
@@ -1712,17 +1695,13 @@ unlock:
 irqreturn_t t1_interrupt(int irq, void *cookie)
 {
        int work_done;
-       struct respQ_e *e;
        struct adapter *adapter = cookie;
-       struct respQ *Q = &adapter->sge->respQ;
 
        spin_lock(&adapter->async_lock);
-       e = &Q->entries[Q->cidx];
-       prefetch(e);
 
        writel(F_PL_INTR_SGE_DATA, adapter->regs + A_PL_CAUSE);
 
-       if (likely(e->GenerationBit == Q->genbit))
+       if (likely(responses_pending(adapter)))
                work_done = process_responses(adapter, -1);
        else
                work_done = t1_slow_intr_handler(adapter);
@@ -1796,7 +1775,7 @@ static int t1_sge_tx(struct sk_buff *skb, struct adapter *adapter,
         * through the scheduler.
         */
        if (sge->tx_sched && !qid && skb->dev) {
-       use_sched:
+use_sched:
                use_sched_skb = 1;
                /* Note that the scheduler might return a different skb than
                 * the one passed in.
@@ -1900,7 +1879,7 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
                cpl = (struct cpl_tx_pkt *)hdr;
        } else {
                /*
-                * Packets shorter than ETH_HLEN can break the MAC, drop them
+                * Packets shorter than ETH_HLEN can break the MAC, drop them
                 * early.  Also, we may get oversized packets because some
                 * parts of the kernel don't handle our unusual hard_header_len
                 * right, drop those too.
@@ -1984,9 +1963,9 @@ send:
         * then silently discard to avoid leak.
         */
        if (unlikely(ret != NETDEV_TX_OK && skb != orig_skb)) {
-               dev_kfree_skb_any(skb);
+               dev_kfree_skb_any(skb);
                ret = NETDEV_TX_OK;
-       }
+       }
        return ret;
 }
 
@@ -2099,31 +2078,35 @@ static void espibug_workaround_t204(unsigned long data)
 
        if (adapter->open_device_map & PORT_MASK) {
                int i;
-               if (t1_espi_get_mon_t204(adapter, &(seop[0]), 0) < 0) {
+
+               if (t1_espi_get_mon_t204(adapter, &(seop[0]), 0) < 0)
                        return;
-               }
+
                for (i = 0; i < nports; i++) {
-                       struct sk_buff *skb = sge->espibug_skb[i];
-                       if ( (netif_running(adapter->port[i].dev)) &&
-                            !(netif_queue_stopped(adapter->port[i].dev)) &&
-                            (seop[i] && ((seop[i] & 0xfff) == 0)) &&
-                            skb ) {
-                               if (!skb->cb[0]) {
-                                       u8 ch_mac_addr[ETH_ALEN] =
-                                       {0x0, 0x7, 0x43, 0x0, 0x0, 0x0};
-                                       memcpy(skb->data + sizeof(struct cpl_tx_pkt),
-                                       ch_mac_addr, ETH_ALEN);
-                                       memcpy(skb->data + skb->len - 10,
-                                               ch_mac_addr, ETH_ALEN);
-                                       skb->cb[0] = 0xff;
-                               }
-
-                               /* bump the reference count to avoid freeing of
-                                * the skb once the DMA has completed.
-                                */
-                               skb = skb_get(skb);
-                               t1_sge_tx(skb, adapter, 0, adapter->port[i].dev);
+                       struct sk_buff *skb = sge->espibug_skb[i];
+
+                       if (!netif_running(adapter->port[i].dev) ||
+                           netif_queue_stopped(adapter->port[i].dev) ||
+                           !seop[i] || ((seop[i] & 0xfff) != 0) || !skb)
+                               continue;
+
+                       if (!skb->cb[0]) {
+                               u8 ch_mac_addr[ETH_ALEN] = {
+                                       0x0, 0x7, 0x43, 0x0, 0x0, 0x0
+                               };
+
+                               memcpy(skb->data + sizeof(struct cpl_tx_pkt),
+                                       ch_mac_addr, ETH_ALEN);
+                               memcpy(skb->data + skb->len - 10,
+                                       ch_mac_addr, ETH_ALEN);
+                               skb->cb[0] = 0xff;
                        }
+
+                       /* bump the reference count to avoid freeing of
+                        * the skb once the DMA has completed.
+                        */
+                       skb = skb_get(skb);
+                       t1_sge_tx(skb, adapter, 0, adapter->port[i].dev);
                }
        }
        mod_timer(&sge->espibug_timer, jiffies + sge->espibug_timeout);
@@ -2192,9 +2175,8 @@ struct sge * __devinit t1_sge_create(struct adapter *adapter,
                if (adapter->params.nports > 1) {
                        tx_sched_init(sge);
                        sge->espibug_timer.function = espibug_workaround_t204;
-               } else {
+               } else
                        sge->espibug_timer.function = espibug_workaround;
-               }
                sge->espibug_timer.data = (unsigned long)sge->adapter;
 
                sge->espibug_timeout = 1;
@@ -2202,7 +2184,7 @@ struct sge * __devinit t1_sge_create(struct adapter *adapter,
                if (adapter->params.nports > 1)
                        sge->espibug_timeout = HZ/100;
        }
-        
+
 
        p->cmdQ_size[0] = SGE_CMDQ0_E_N;
        p->cmdQ_size[1] = SGE_CMDQ1_E_N;
index 22ed9a383c0814cef941b5e0402e7e08a287e52c..c2522cdfab3759fbc3638d9a690062e53b288c42 100644 (file)
@@ -223,13 +223,13 @@ static int fpga_slow_intr(adapter_t *adapter)
                t1_sge_intr_error_handler(adapter->sge);
 
        if (cause & FPGA_PCIX_INTERRUPT_GMAC)
-                fpga_phy_intr_handler(adapter);
+               fpga_phy_intr_handler(adapter);
 
        if (cause & FPGA_PCIX_INTERRUPT_TP) {
-                /*
+               /*
                 * FPGA doesn't support MC4 interrupts and it requires
                 * this odd layer of indirection for MC5.
-                 */
+                */
                u32 tp_cause = readl(adapter->regs + FPGA_TP_ADDR_INTERRUPT_CAUSE);
 
                /* Clear TP interrupt */
@@ -262,8 +262,7 @@ static int mi1_wait_until_ready(adapter_t *adapter, int mi1_reg)
                        udelay(10);
        } while (busy && --attempts);
        if (busy)
-               CH_ALERT("%s: MDIO operation timed out\n",
-                        adapter->name);
+               CH_ALERT("%s: MDIO operation timed out\n", adapter->name);
        return busy;
 }
 
@@ -605,22 +604,23 @@ int t1_elmer0_ext_intr_handler(adapter_t *adapter)
 
        switch (board_info(adapter)->board) {
 #ifdef CONFIG_CHELSIO_T1_1G
-        case CHBT_BOARD_CHT204:
-        case CHBT_BOARD_CHT204E:
-        case CHBT_BOARD_CHN204:
-        case CHBT_BOARD_CHT204V: {
-                int i, port_bit;
+       case CHBT_BOARD_CHT204:
+       case CHBT_BOARD_CHT204E:
+       case CHBT_BOARD_CHN204:
+       case CHBT_BOARD_CHT204V: {
+               int i, port_bit;
                for_each_port(adapter, i) {
                        port_bit = i + 1;
-                       if (!(cause & (1 << port_bit))) continue;
+                       if (!(cause & (1 << port_bit)))
+                               continue;
 
-                       phy = adapter->port[i].phy;
+                       phy = adapter->port[i].phy;
                        phy_cause = phy->ops->interrupt_handler(phy);
                        if (phy_cause & cphy_cause_link_change)
                                t1_link_changed(adapter, i);
                }
-                break;
-        }
+               break;
+       }
        case CHBT_BOARD_CHT101:
                if (cause & ELMER0_GP_BIT1) { /* Marvell 88E1111 interrupt */
                        phy = adapter->port[0].phy;
@@ -631,13 +631,13 @@ int t1_elmer0_ext_intr_handler(adapter_t *adapter)
                break;
        case CHBT_BOARD_7500: {
                int p;
-               /*
+               /*
                 * Elmer0's interrupt cause isn't useful here because there is
                 * only one bit that can be set for all 4 ports.  This means
                 * we are forced to check every PHY's interrupt status
                 * register to see who initiated the interrupt.
-                */
-               for_each_port(adapter, p) {
+                */
+               for_each_port(adapter, p) {
                        phy = adapter->port[p].phy;
                        phy_cause = phy->ops->interrupt_handler(phy);
                        if (phy_cause & cphy_cause_link_change)
@@ -658,7 +658,7 @@ int t1_elmer0_ext_intr_handler(adapter_t *adapter)
                break;
        case CHBT_BOARD_8000:
        case CHBT_BOARD_CHT110:
-               CH_DBG(adapter, INTR, "External interrupt cause 0x%x\n",
+               CH_DBG(adapter, INTR, "External interrupt cause 0x%x\n",
                       cause);
                if (cause & ELMER0_GP_BIT1) {        /* PMC3393 INTB */
                        struct cmac *mac = adapter->port[0].mac;
@@ -670,9 +670,9 @@ int t1_elmer0_ext_intr_handler(adapter_t *adapter)
 
                        t1_tpi_read(adapter,
                                        A_ELMER0_GPI_STAT, &mod_detect);
-                       CH_MSG(adapter, INFO, LINK, "XPAK %s\n",
+                       CH_MSG(adapter, INFO, LINK, "XPAK %s\n",
                               mod_detect ? "removed" : "inserted");
-               }
+               }
                break;
 #ifdef CONFIG_CHELSIO_T1_COUGAR
        case CHBT_BOARD_COUGAR:
@@ -688,7 +688,8 @@ int t1_elmer0_ext_intr_handler(adapter_t *adapter)
 
                        for_each_port(adapter, i) {
                                port_bit = i ? i + 1 : 0;
-                               if (!(cause & (1 << port_bit))) continue;
+                               if (!(cause & (1 << port_bit)))
+                                       continue;
 
                                phy = adapter->port[i].phy;
                                phy_cause = phy->ops->interrupt_handler(phy);
@@ -755,7 +756,7 @@ void t1_interrupts_disable(adapter_t* adapter)
 
        /* Disable PCIX & external chip interrupts. */
        if (t1_is_asic(adapter))
-               writel(0, adapter->regs + A_PL_ENABLE);
+               writel(0, adapter->regs + A_PL_ENABLE);
 
        /* PCI-X interrupts */
        pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE, 0);
@@ -830,11 +831,11 @@ int t1_slow_intr_handler(adapter_t *adapter)
 /* Power sequencing is a work-around for Intel's XPAKs. */
 static void power_sequence_xpak(adapter_t* adapter)
 {
-       u32 mod_detect;
-       u32 gpo;
+       u32 mod_detect;
+       u32 gpo;
 
-       /* Check for XPAK */
-       t1_tpi_read(adapter, A_ELMER0_GPI_STAT, &mod_detect);
+       /* Check for XPAK */
+       t1_tpi_read(adapter, A_ELMER0_GPI_STAT, &mod_detect);
        if (!(ELMER0_GP_BIT5 & mod_detect)) {
                /* XPAK is present */
                t1_tpi_read(adapter, A_ELMER0_GPO, &gpo);
@@ -877,31 +878,31 @@ static int board_init(adapter_t *adapter, const struct board_info *bi)
        case CHBT_BOARD_N210:
        case CHBT_BOARD_CHT210:
        case CHBT_BOARD_COUGAR:
-               t1_tpi_par(adapter, 0xf);
-               t1_tpi_write(adapter, A_ELMER0_GPO, 0x800);
+               t1_tpi_par(adapter, 0xf);
+               t1_tpi_write(adapter, A_ELMER0_GPO, 0x800);
                break;
        case CHBT_BOARD_CHT110:
-               t1_tpi_par(adapter, 0xf);
-               t1_tpi_write(adapter, A_ELMER0_GPO, 0x1800);
+               t1_tpi_par(adapter, 0xf);
+               t1_tpi_write(adapter, A_ELMER0_GPO, 0x1800);
 
-               /* TBD XXX Might not need.  This fixes a problem
-                *         described in the Intel SR XPAK errata.
-                */
-               power_sequence_xpak(adapter);
+               /* TBD XXX Might not need.  This fixes a problem
+                *         described in the Intel SR XPAK errata.
+                */
+               power_sequence_xpak(adapter);
                break;
 #ifdef CONFIG_CHELSIO_T1_1G
-    case CHBT_BOARD_CHT204E:
-                       /* add config space write here */
+       case CHBT_BOARD_CHT204E:
+               /* add config space write here */
        case CHBT_BOARD_CHT204:
        case CHBT_BOARD_CHT204V:
        case CHBT_BOARD_CHN204:
-                t1_tpi_par(adapter, 0xf);
-                t1_tpi_write(adapter, A_ELMER0_GPO, 0x804);
-                break;
+               t1_tpi_par(adapter, 0xf);
+               t1_tpi_write(adapter, A_ELMER0_GPO, 0x804);
+               break;
        case CHBT_BOARD_CHT101:
        case CHBT_BOARD_7500:
-               t1_tpi_par(adapter, 0xf);
-               t1_tpi_write(adapter, A_ELMER0_GPO, 0x1804);
+               t1_tpi_par(adapter, 0xf);
+               t1_tpi_write(adapter, A_ELMER0_GPO, 0x1804);
                break;
 #endif
        }
@@ -941,7 +942,7 @@ int t1_init_hw_modules(adapter_t *adapter)
                goto out_err;
 
        err = 0;
- out_err:
+out_err:
        return err;
 }
 
@@ -983,7 +984,7 @@ void t1_free_sw_modules(adapter_t *adapter)
        if (adapter->espi)
                t1_espi_destroy(adapter->espi);
 #ifdef CONFIG_CHELSIO_T1_COUGAR
-        if (adapter->cspi)
+       if (adapter->cspi)
                t1_cspi_destroy(adapter->cspi);
 #endif
 }
@@ -1010,7 +1011,7 @@ static void __devinit init_link_config(struct link_config *lc,
                CH_ERR("%s: CSPI initialization failed\n",
                       adapter->name);
                goto error;
-        }
+       }
 #endif
 
 /*
index 0ca0b6e19e43c747242cca177e8befaff5f0b4c6..6222d585e4478e9057625ed6fdcbd854de543c2c 100644 (file)
@@ -17,39 +17,36 @@ struct petp {
 static void tp_init(adapter_t * ap, const struct tp_params *p,
                    unsigned int tp_clk)
 {
-       if (t1_is_asic(ap)) {
-               u32 val;
-
-               val = F_TP_IN_CSPI_CPL | F_TP_IN_CSPI_CHECK_IP_CSUM |
-                   F_TP_IN_CSPI_CHECK_TCP_CSUM | F_TP_IN_ESPI_ETHERNET;
-               if (!p->pm_size)
-                       val |= F_OFFLOAD_DISABLE;
-               else
-                       val |= F_TP_IN_ESPI_CHECK_IP_CSUM |
-                           F_TP_IN_ESPI_CHECK_TCP_CSUM;
-               writel(val, ap->regs + A_TP_IN_CONFIG);
-               writel(F_TP_OUT_CSPI_CPL |
-                      F_TP_OUT_ESPI_ETHERNET |
-                      F_TP_OUT_ESPI_GENERATE_IP_CSUM |
-                      F_TP_OUT_ESPI_GENERATE_TCP_CSUM,
-                      ap->regs + A_TP_OUT_CONFIG);
-               writel(V_IP_TTL(64) |
-                      F_PATH_MTU /* IP DF bit */  |
-                      V_5TUPLE_LOOKUP(p->use_5tuple_mode) |
-                      V_SYN_COOKIE_PARAMETER(29),
-                      ap->regs + A_TP_GLOBAL_CONFIG);
-               /*
-                * Enable pause frame deadlock prevention.
-                */
-               if (is_T2(ap) && ap->params.nports > 1) {
-                       u32 drop_ticks = DROP_MSEC * (tp_clk / 1000);
-
-                       writel(F_ENABLE_TX_DROP | F_ENABLE_TX_ERROR |
-                              V_DROP_TICKS_CNT(drop_ticks) |
-                              V_NUM_PKTS_DROPPED(DROP_PKTS_CNT),
-                              ap->regs + A_TP_TX_DROP_CONFIG);
-               }
+       u32 val;
 
+       if (!t1_is_asic(ap))
+               return;
+
+       val = F_TP_IN_CSPI_CPL | F_TP_IN_CSPI_CHECK_IP_CSUM |
+               F_TP_IN_CSPI_CHECK_TCP_CSUM | F_TP_IN_ESPI_ETHERNET;
+       if (!p->pm_size)
+               val |= F_OFFLOAD_DISABLE;
+       else
+               val |= F_TP_IN_ESPI_CHECK_IP_CSUM | F_TP_IN_ESPI_CHECK_TCP_CSUM;
+       writel(val, ap->regs + A_TP_IN_CONFIG);
+       writel(F_TP_OUT_CSPI_CPL |
+              F_TP_OUT_ESPI_ETHERNET |
+              F_TP_OUT_ESPI_GENERATE_IP_CSUM |
+              F_TP_OUT_ESPI_GENERATE_TCP_CSUM, ap->regs + A_TP_OUT_CONFIG);
+       writel(V_IP_TTL(64) |
+              F_PATH_MTU /* IP DF bit */  |
+              V_5TUPLE_LOOKUP(p->use_5tuple_mode) |
+              V_SYN_COOKIE_PARAMETER(29), ap->regs + A_TP_GLOBAL_CONFIG);
+       /*
+        * Enable pause frame deadlock prevention.
+        */
+       if (is_T2(ap) && ap->params.nports > 1) {
+               u32 drop_ticks = DROP_MSEC * (tp_clk / 1000);
+
+               writel(F_ENABLE_TX_DROP | F_ENABLE_TX_ERROR |
+                      V_DROP_TICKS_CNT(drop_ticks) |
+                      V_NUM_PKTS_DROPPED(DROP_PKTS_CNT),
+                      ap->regs + A_TP_TX_DROP_CONFIG);
        }
 }
 
@@ -61,6 +58,7 @@ void t1_tp_destroy(struct petp *tp)
 struct petp *__devinit t1_tp_create(adapter_t * adapter, struct tp_params *p)
 {
        struct petp *tp = kzalloc(sizeof(*tp), GFP_KERNEL);
+
        if (!tp)
                return NULL;
 
index 85dc3b1dc3096a832b7fd987040236f19633a973..534ffa0f616ec944ac3596dcbf3987a37b804ac8 100644 (file)
@@ -226,22 +226,21 @@ static void run_table(adapter_t *adapter, struct init_table *ib, int len)
                if (ib[i].addr == INITBLOCK_SLEEP) {
                        udelay( ib[i].data );
                        CH_ERR("sleep %d us\n",ib[i].data);
-               } else {
+               } else
                        vsc_write( adapter, ib[i].addr, ib[i].data );
-               }
        }
 }
 
 static int bist_rd(adapter_t *adapter, int moduleid, int address)
 {
-       int data=0;
-       u32 result=0;
-
-       if(     (address != 0x0) &&
-               (address != 0x1) &&
-               (address != 0x2) &&
-               (address != 0xd) &&
-               (address != 0xe))
+       int data = 0;
+       u32 result = 0;
+
+       if ((address != 0x0) &&
+           (address != 0x1) &&
+           (address != 0x2) &&
+           (address != 0xd) &&
+           (address != 0xe))
                        CH_ERR("No bist address: 0x%x\n", address);
 
        data = ((0x00 << 24) | ((address & 0xff) << 16) | (0x00 << 8) |
@@ -251,27 +250,27 @@ static int bist_rd(adapter_t *adapter, int moduleid, int address)
        udelay(10);
 
        vsc_read(adapter, REG_RAM_BIST_RESULT, &result);
-       if((result & (1<<9)) != 0x0)
+       if ((result & (1 << 9)) != 0x0)
                CH_ERR("Still in bist read: 0x%x\n", result);
-       else if((result & (1<<8)) != 0x0)
+       else if ((result & (1 << 8)) != 0x0)
                CH_ERR("bist read error: 0x%x\n", result);
 
-       return(result & 0xff);
+       return (result & 0xff);
 }
 
 static int bist_wr(adapter_t *adapter, int moduleid, int address, int value)
 {
-       int data=0;
-       u32 result=0;
-
-       if(     (address != 0x0) &&
-               (address != 0x1) &&
-               (address != 0x2) &&
-               (address != 0xd) &&
-               (address != 0xe))
+       int data = 0;
+       u32 result = 0;
+
+       if ((address != 0x0) &&
+           (address != 0x1) &&
+           (address != 0x2) &&
+           (address != 0xd) &&
+           (address != 0xe))
                        CH_ERR("No bist address: 0x%x\n", address);
 
-       if( value>255 )
+       if (value > 255)
                CH_ERR("Suspicious write out of range value: 0x%x\n", value);
 
        data = ((0x01 << 24) | ((address & 0xff) << 16) | (value << 8) |
@@ -281,12 +280,12 @@ static int bist_wr(adapter_t *adapter, int moduleid, int address, int value)
        udelay(5);
 
        vsc_read(adapter, REG_RAM_BIST_CMD, &result);
-       if((result & (1<<27)) != 0x0)
+       if ((result & (1 << 27)) != 0x0)
                CH_ERR("Still in bist write: 0x%x\n", result);
-       else if((result & (1<<26)) != 0x0)
+       else if ((result & (1 << 26)) != 0x0)
                CH_ERR("bist write error: 0x%x\n", result);
 
-       return(0);
+       return 0;
 }
 
 static int run_bist(adapter_t *adapter, int moduleid)
@@ -295,7 +294,7 @@ static int run_bist(adapter_t *adapter, int moduleid)
        (void) bist_wr(adapter,moduleid, 0x00, 0x02);
        (void) bist_wr(adapter,moduleid, 0x01, 0x01);
 
-       return(0);
+       return 0;
 }
 
 static int check_bist(adapter_t *adapter, int moduleid)
@@ -309,27 +308,26 @@ static int check_bist(adapter_t *adapter, int moduleid)
        if ((result & 3) != 0x3)
                CH_ERR("Result: 0x%x  BIST error in ram %d, column: 0x%04x\n",
                        result, moduleid, column);
-       return(0);
+       return 0;
 }
 
 static int enable_mem(adapter_t *adapter, int moduleid)
 {
        /*enable mem*/
        (void) bist_wr(adapter,moduleid, 0x00, 0x00);
-       return(0);
+       return 0;
 }
 
 static int run_bist_all(adapter_t *adapter)
 {
-       int port=0;
-       u32 val=0;
+       int port = 0;
+       u32 val = 0;
 
        vsc_write(adapter, REG_MEM_BIST, 0x5);
        vsc_read(adapter, REG_MEM_BIST, &val);
 
-       for(port=0; port<12; port++){
+       for (port = 0; port < 12; port++)
                vsc_write(adapter, REG_DEV_SETUP(port), 0x0);
-       }
 
        udelay(300);
        vsc_write(adapter, REG_SPI4_MISC, 0x00040409);
@@ -352,13 +350,13 @@ static int run_bist_all(adapter_t *adapter)
        udelay(300);
        vsc_write(adapter, REG_SPI4_MISC, 0x60040400);
        udelay(300);
-       for(port=0; port<12; port++){
+       for (port = 0; port < 12; port++)
                vsc_write(adapter, REG_DEV_SETUP(port), 0x1);
-       }
+
        udelay(300);
        vsc_write(adapter, REG_MEM_BIST, 0x0);
        mdelay(10);
-       return(0);
+       return 0;
 }
 
 static int mac_intr_handler(struct cmac *mac)
@@ -591,40 +589,46 @@ static void rmon_update(struct cmac *mac, unsigned int addr, u64 *stat)
 
 static void port_stats_update(struct cmac *mac)
 {
-       int port = mac->instance->index;
+       struct {
+               unsigned int reg;
+               unsigned int offset;
+       } hw_stats[] = {
+
+#define HW_STAT(reg, stat_name) \
+       { reg, (&((struct cmac_statistics *)NULL)->stat_name) - (u64 *)NULL }
+
+               /* Rx stats */
+               HW_STAT(RxUnicast, RxUnicastFramesOK),
+               HW_STAT(RxMulticast, RxMulticastFramesOK),
+               HW_STAT(RxBroadcast, RxBroadcastFramesOK),
+               HW_STAT(Crc, RxFCSErrors),
+               HW_STAT(RxAlignment, RxAlignErrors),
+               HW_STAT(RxOversize, RxFrameTooLongErrors),
+               HW_STAT(RxPause, RxPauseFrames),
+               HW_STAT(RxJabbers, RxJabberErrors),
+               HW_STAT(RxFragments, RxRuntErrors),
+               HW_STAT(RxUndersize, RxRuntErrors),
+               HW_STAT(RxSymbolCarrier, RxSymbolErrors),
+               HW_STAT(RxSize1519ToMax, RxJumboFramesOK),
+
+               /* Tx stats (skip collision stats as we are full-duplex only) */
+               HW_STAT(TxUnicast, TxUnicastFramesOK),
+               HW_STAT(TxMulticast, TxMulticastFramesOK),
+               HW_STAT(TxBroadcast, TxBroadcastFramesOK),
+               HW_STAT(TxPause, TxPauseFrames),
+               HW_STAT(TxUnderrun, TxUnderrun),
+               HW_STAT(TxSize1519ToMax, TxJumboFramesOK),
+       }, *p = hw_stats;
+       unsigned int port = mac->instance->index;
+       u64 *stats = (u64 *)&mac->stats;
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(hw_stats); i++)
+               rmon_update(mac, CRA(0x4, port, p->reg), stats + p->offset);
 
-       /* Rx stats */
+       rmon_update(mac, REG_TX_OK_BYTES(port), &mac->stats.TxOctetsOK);
        rmon_update(mac, REG_RX_OK_BYTES(port), &mac->stats.RxOctetsOK);
        rmon_update(mac, REG_RX_BAD_BYTES(port), &mac->stats.RxOctetsBad);
-       rmon_update(mac, REG_RX_UNICAST(port), &mac->stats.RxUnicastFramesOK);
-       rmon_update(mac, REG_RX_MULTICAST(port),
-                   &mac->stats.RxMulticastFramesOK);
-       rmon_update(mac, REG_RX_BROADCAST(port),
-                   &mac->stats.RxBroadcastFramesOK);
-       rmon_update(mac, REG_CRC(port), &mac->stats.RxFCSErrors);
-       rmon_update(mac, REG_RX_ALIGNMENT(port), &mac->stats.RxAlignErrors);
-       rmon_update(mac, REG_RX_OVERSIZE(port),
-                   &mac->stats.RxFrameTooLongErrors);
-       rmon_update(mac, REG_RX_PAUSE(port), &mac->stats.RxPauseFrames);
-       rmon_update(mac, REG_RX_JABBERS(port), &mac->stats.RxJabberErrors);
-       rmon_update(mac, REG_RX_FRAGMENTS(port), &mac->stats.RxRuntErrors);
-       rmon_update(mac, REG_RX_UNDERSIZE(port), &mac->stats.RxRuntErrors);
-       rmon_update(mac, REG_RX_SYMBOL_CARRIER(port),
-                   &mac->stats.RxSymbolErrors);
-       rmon_update(mac, REG_RX_SIZE_1519_TO_MAX(port),
-            &mac->stats.RxJumboFramesOK);
-
-       /* Tx stats (skip collision stats as we are full-duplex only) */
-       rmon_update(mac, REG_TX_OK_BYTES(port), &mac->stats.TxOctetsOK);
-       rmon_update(mac, REG_TX_UNICAST(port), &mac->stats.TxUnicastFramesOK);
-       rmon_update(mac, REG_TX_MULTICAST(port),
-                   &mac->stats.TxMulticastFramesOK);
-       rmon_update(mac, REG_TX_BROADCAST(port),
-                   &mac->stats.TxBroadcastFramesOK);
-       rmon_update(mac, REG_TX_PAUSE(port), &mac->stats.TxPauseFrames);
-       rmon_update(mac, REG_TX_UNDERRUN(port), &mac->stats.TxUnderrun);
-       rmon_update(mac, REG_TX_SIZE_1519_TO_MAX(port),
-            &mac->stats.TxJumboFramesOK);
 }
 
 /*
@@ -686,7 +690,8 @@ static struct cmac *vsc7326_mac_create(adapter_t *adapter, int index)
        int i;
 
        mac = kzalloc(sizeof(*mac) + sizeof(cmac_instance), GFP_KERNEL);
-       if (!mac) return NULL;
+       if (!mac)
+               return NULL;
 
        mac->ops = &vsc7326_ops;
        mac->instance = (cmac_instance *)(mac + 1);
index 491bcf75c4fb2d07c7020c644a114ba52c236a6f..479edbcabe689dc57c38985a5837ad24c9c3e697 100644 (file)
 #define REG_HDX(pn)            CRA(0x1,pn,0x19)        /* Half-duplex config */
 
 /* Statistics */
+/* CRA(0x4,pn,reg) */
+/* reg below */
 /* pn = port number, 0-a, a = 10GbE */
-#define REG_RX_IN_BYTES(pn)    CRA(0x4,pn,0x00)        /* # Rx in octets */
-#define REG_RX_SYMBOL_CARRIER(pn) CRA(0x4,pn,0x01)     /* Frames w/ symbol errors */
-#define REG_RX_PAUSE(pn)       CRA(0x4,pn,0x02)        /* # pause frames received */
-#define REG_RX_UNSUP_OPCODE(pn)        CRA(0x4,pn,0x03)        /* # control frames with unsupported opcode */
-#define REG_RX_OK_BYTES(pn)    CRA(0x4,pn,0x04)        /* # octets in good frames */
-#define REG_RX_BAD_BYTES(pn)   CRA(0x4,pn,0x05)        /* # octets in bad frames */
-#define REG_RX_UNICAST(pn)     CRA(0x4,pn,0x06)        /* # good unicast frames */
-#define REG_RX_MULTICAST(pn)   CRA(0x4,pn,0x07)        /* # good multicast frames */
-#define REG_RX_BROADCAST(pn)   CRA(0x4,pn,0x08)        /* # good broadcast frames */
-#define REG_CRC(pn)            CRA(0x4,pn,0x09)        /* # frames w/ bad CRC only */
-#define REG_RX_ALIGNMENT(pn)   CRA(0x4,pn,0x0a)        /* # frames w/ alignment err */
-#define REG_RX_UNDERSIZE(pn)   CRA(0x4,pn,0x0b)        /* # frames undersize */
-#define REG_RX_FRAGMENTS(pn)   CRA(0x4,pn,0x0c)        /* # frames undersize w/ crc err */
-#define REG_RX_IN_RANGE_LENGTH_ERROR(pn) CRA(0x4,pn,0x0d)      /* # frames with length error */
-#define REG_RX_OUT_OF_RANGE_ERROR(pn) CRA(0x4,pn,0x0e) /* # frames with illegal length field */
-#define REG_RX_OVERSIZE(pn)    CRA(0x4,pn,0x0f)        /* # frames oversize */
-#define REG_RX_JABBERS(pn)     CRA(0x4,pn,0x10)        /* # frames oversize w/ crc err */
-#define REG_RX_SIZE_64(pn)     CRA(0x4,pn,0x11)        /* # frames 64 octets long */
-#define REG_RX_SIZE_65_TO_127(pn) CRA(0x4,pn,0x12)     /* # frames 65-127 octets */
-#define REG_RX_SIZE_128_TO_255(pn) CRA(0x4,pn,0x13)    /* # frames 128-255 */
-#define REG_RX_SIZE_256_TO_511(pn) CRA(0x4,pn,0x14)    /* # frames 256-511 */
-#define REG_RX_SIZE_512_TO_1023(pn) CRA(0x4,pn,0x15)   /* # frames 512-1023 */
-#define REG_RX_SIZE_1024_TO_1518(pn) CRA(0x4,pn,0x16)  /* # frames 1024-1518 */
-#define REG_RX_SIZE_1519_TO_MAX(pn) CRA(0x4,pn,0x17)   /* # frames 1519-max */
 
-#define REG_TX_OUT_BYTES(pn)   CRA(0x4,pn,0x18)        /* # octets tx */
-#define REG_TX_PAUSE(pn)       CRA(0x4,pn,0x19)        /* # pause frames sent */
-#define REG_TX_OK_BYTES(pn)    CRA(0x4,pn,0x1a)        /* # octets tx OK */
-#define REG_TX_UNICAST(pn)     CRA(0x4,pn,0x1b)        /* # frames unicast */
-#define REG_TX_MULTICAST(pn)   CRA(0x4,pn,0x1c)        /* # frames multicast */
-#define REG_TX_BROADCAST(pn)   CRA(0x4,pn,0x1d)        /* # frames broadcast */
-#define REG_TX_MULTIPLE_COLL(pn) CRA(0x4,pn,0x1e)      /* # frames tx after multiple collisions */
-#define REG_TX_LATE_COLL(pn)   CRA(0x4,pn,0x1f)        /* # late collisions detected */
-#define REG_TX_XCOLL(pn)       CRA(0x4,pn,0x20)        /* # frames lost, excessive collisions */
-#define REG_TX_DEFER(pn)       CRA(0x4,pn,0x21)        /* # frames deferred on first tx attempt */
-#define REG_TX_XDEFER(pn)      CRA(0x4,pn,0x22)        /* # frames excessively deferred */
-#define REG_TX_CSENSE(pn)      CRA(0x4,pn,0x23)        /* carrier sense errors at frame end */
-#define REG_TX_SIZE_64(pn)     CRA(0x4,pn,0x24)        /* # frames 64 octets long */
-#define REG_TX_SIZE_65_TO_127(pn) CRA(0x4,pn,0x25)     /* # frames 65-127 octets */
-#define REG_TX_SIZE_128_TO_255(pn) CRA(0x4,pn,0x26)    /* # frames 128-255 */
-#define REG_TX_SIZE_256_TO_511(pn) CRA(0x4,pn,0x27)    /* # frames 256-511 */
-#define REG_TX_SIZE_512_TO_1023(pn) CRA(0x4,pn,0x28)   /* # frames 512-1023 */
-#define REG_TX_SIZE_1024_TO_1518(pn) CRA(0x4,pn,0x29)  /* # frames 1024-1518 */
-#define REG_TX_SIZE_1519_TO_MAX(pn) CRA(0x4,pn,0x2a)   /* # frames 1519-max */
-#define REG_TX_SINGLE_COLL(pn) CRA(0x4,pn,0x2b)        /* # frames tx after single collision */
-#define REG_TX_BACKOFF2(pn)    CRA(0x4,pn,0x2c)        /* # frames tx ok after 2 backoffs/collisions */
-#define REG_TX_BACKOFF3(pn)    CRA(0x4,pn,0x2d)        /*   after 3 backoffs/collisions */
-#define REG_TX_BACKOFF4(pn)    CRA(0x4,pn,0x2e)        /*   after 4 */
-#define REG_TX_BACKOFF5(pn)    CRA(0x4,pn,0x2f)        /*   after 5 */
-#define REG_TX_BACKOFF6(pn)    CRA(0x4,pn,0x30)        /*   after 6 */
-#define REG_TX_BACKOFF7(pn)    CRA(0x4,pn,0x31)        /*   after 7 */
-#define REG_TX_BACKOFF8(pn)    CRA(0x4,pn,0x32)        /*   after 8 */
-#define REG_TX_BACKOFF9(pn)    CRA(0x4,pn,0x33)        /*   after 9 */
-#define REG_TX_BACKOFF10(pn)   CRA(0x4,pn,0x34)        /*   after 10 */
-#define REG_TX_BACKOFF11(pn)   CRA(0x4,pn,0x35)        /*   after 11 */
-#define REG_TX_BACKOFF12(pn)   CRA(0x4,pn,0x36)        /*   after 12 */
-#define REG_TX_BACKOFF13(pn)   CRA(0x4,pn,0x37)        /*   after 13 */
-#define REG_TX_BACKOFF14(pn)   CRA(0x4,pn,0x38)        /*   after 14 */
-#define REG_TX_BACKOFF15(pn)   CRA(0x4,pn,0x39)        /*   after 15 */
-#define REG_TX_UNDERRUN(pn)    CRA(0x4,pn,0x3a)        /* # frames dropped from underrun */
-#define REG_RX_XGMII_PROT_ERR  CRA(0x4,0xa,0x3b)       /* # protocol errors detected on XGMII interface */
-#define REG_RX_IPG_SHRINK(pn)  CRA(0x4,pn,0x3c)        /* # of IPG shrinks detected */
+enum {
+       RxInBytes               = 0x00, // # Rx in octets
+       RxSymbolCarrier         = 0x01, // Frames w/ symbol errors
+       RxPause                 = 0x02, // # pause frames received
+       RxUnsupOpcode           = 0x03, // # control frames with unsupported opcode
+       RxOkBytes               = 0x04, // # octets in good frames
+       RxBadBytes              = 0x05, // # octets in bad frames
+       RxUnicast               = 0x06, // # good unicast frames
+       RxMulticast             = 0x07, // # good multicast frames
+       RxBroadcast             = 0x08, // # good broadcast frames
+       Crc                     = 0x09, // # frames w/ bad CRC only
+       RxAlignment             = 0x0a, // # frames w/ alignment err
+       RxUndersize             = 0x0b, // # frames undersize
+       RxFragments             = 0x0c, // # frames undersize w/ crc err
+       RxInRangeLengthError    = 0x0d, // # frames with length error
+       RxOutOfRangeError       = 0x0e, // # frames with illegal length field
+       RxOversize              = 0x0f, // # frames oversize
+       RxJabbers               = 0x10, // # frames oversize w/ crc err
+       RxSize64                = 0x11, // # frames 64 octets long
+       RxSize65To127           = 0x12, // # frames 65-127 octets
+       RxSize128To255          = 0x13, // # frames 128-255
+       RxSize256To511          = 0x14, // # frames 256-511
+       RxSize512To1023         = 0x15, // # frames 512-1023
+       RxSize1024To1518        = 0x16, // # frames 1024-1518
+       RxSize1519ToMax         = 0x17, // # frames 1519-max
 
-#define REG_STAT_STICKY1G(pn)  CRA(0x4,pn,0x3e)        /* tri-speed sticky bits */
-#define REG_STAT_STICKY10G     CRA(0x4,0xa,0x3e)       /* 10GbE sticky bits */
-#define REG_STAT_INIT(pn)      CRA(0x4,pn,0x3f)        /* Clear all statistics */
+       TxOutBytes              = 0x18, // # octets tx
+       TxPause                 = 0x19, // # pause frames sent
+       TxOkBytes               = 0x1a, // # octets tx OK
+       TxUnicast               = 0x1b, // # frames unicast
+       TxMulticast             = 0x1c, // # frames multicast
+       TxBroadcast             = 0x1d, // # frames broadcast
+       TxMultipleColl          = 0x1e, // # frames tx after multiple collisions
+       TxLateColl              = 0x1f, // # late collisions detected
+       TxXcoll                 = 0x20, // # frames lost, excessive collisions
+       TxDefer                 = 0x21, // # frames deferred on first tx attempt
+       TxXdefer                = 0x22, // # frames excessively deferred
+       TxCsense                = 0x23, // carrier sense errors at frame end
+       TxSize64                = 0x24, // # frames 64 octets long
+       TxSize65To127           = 0x25, // # frames 65-127 octets
+       TxSize128To255          = 0x26, // # frames 128-255
+       TxSize256To511          = 0x27, // # frames 256-511
+       TxSize512To1023         = 0x28, // # frames 512-1023
+       TxSize1024To1518        = 0x29, // # frames 1024-1518
+       TxSize1519ToMax         = 0x2a, // # frames 1519-max
+       TxSingleColl            = 0x2b, // # frames tx after single collision
+       TxBackoff2              = 0x2c, // # frames tx ok after 2 backoffs/collisions
+       TxBackoff3              = 0x2d, //   after 3 backoffs/collisions
+       TxBackoff4              = 0x2e, //   after 4
+       TxBackoff5              = 0x2f, //   after 5
+       TxBackoff6              = 0x30, //   after 6
+       TxBackoff7              = 0x31, //   after 7
+       TxBackoff8              = 0x32, //   after 8
+       TxBackoff9              = 0x33, //   after 9
+       TxBackoff10             = 0x34, //   after 10
+       TxBackoff11             = 0x35, //   after 11
+       TxBackoff12             = 0x36, //   after 12
+       TxBackoff13             = 0x37, //   after 13
+       TxBackoff14             = 0x38, //   after 14
+       TxBackoff15             = 0x39, //   after 15
+       TxUnderrun              = 0x3a, // # frames dropped from underrun
+       // Hole. See REG_RX_XGMII_PROT_ERR below.
+       RxIpgShrink             = 0x3c, // # of IPG shrinks detected
+       // Duplicate. See REG_STAT_STICKY10G below.
+       StatSticky1G            = 0x3e, // tri-speed sticky bits
+       StatInit                = 0x3f  // Clear all statistics
+};
+
+#define REG_RX_XGMII_PROT_ERR  CRA(0x4,0xa,0x3b)               /* # protocol errors detected on XGMII interface */
+#define REG_STAT_STICKY10G     CRA(0x4,0xa,StatSticky1G)       /* 10GbE sticky bits */
+
+#define REG_RX_OK_BYTES(pn)    CRA(0x4,pn,RxOkBytes)
+#define REG_RX_BAD_BYTES(pn)   CRA(0x4,pn,RxBadBytes)
+#define REG_TX_OK_BYTES(pn)    CRA(0x4,pn,TxOkBytes)
 
 /* MII-Management Block registers */
 /* These are for MII-M interface 0, which is the bidirectional LVTTL one.  If
index c493e783d459d560834772adc752a2f11ab80a7d..251d4859c91de8015a0c1860fcfe0a632ea97e39 100644 (file)
@@ -54,7 +54,7 @@ enum {
 };
 
 #define CFG_CHG_INTR_MASK (VSC_INTR_LINK_CHG | VSC_INTR_NEG_ERR | \
-                          VSC_INTR_NEG_DONE)
+                          VSC_INTR_NEG_DONE)
 #define INTR_MASK (CFG_CHG_INTR_MASK | VSC_INTR_TX_FIFO | VSC_INTR_RX_FIFO | \
                   VSC_INTR_ENABLE)
 
@@ -94,19 +94,18 @@ static int vsc8244_intr_enable(struct cphy *cphy)
 {
        simple_mdio_write(cphy, VSC8244_INTR_ENABLE, INTR_MASK);
 
-    /* Enable interrupts through Elmer */
+       /* Enable interrupts through Elmer */
        if (t1_is_asic(cphy->adapter)) {
                u32 elmer;
 
                t1_tpi_read(cphy->adapter, A_ELMER0_INT_ENABLE, &elmer);
                elmer |= ELMER0_GP_BIT1;
-               if (is_T2(cphy->adapter)) {
+               if (is_T2(cphy->adapter))
                    elmer |= ELMER0_GP_BIT2|ELMER0_GP_BIT3|ELMER0_GP_BIT4;
-                }
                t1_tpi_write(cphy->adapter, A_ELMER0_INT_ENABLE, elmer);
        }
 
-    return 0;
+       return 0;
 }
 
 static int vsc8244_intr_disable(struct cphy *cphy)
@@ -118,19 +117,18 @@ static int vsc8244_intr_disable(struct cphy *cphy)
 
                t1_tpi_read(cphy->adapter, A_ELMER0_INT_ENABLE, &elmer);
                elmer &= ~ELMER0_GP_BIT1;
-               if (is_T2(cphy->adapter)) {
+               if (is_T2(cphy->adapter))
                    elmer &= ~(ELMER0_GP_BIT2|ELMER0_GP_BIT3|ELMER0_GP_BIT4);
-                }
                t1_tpi_write(cphy->adapter, A_ELMER0_INT_ENABLE, elmer);
        }
 
-    return 0;
+       return 0;
 }
 
 static int vsc8244_intr_clear(struct cphy *cphy)
 {
        u32 val;
-    u32 elmer;
+       u32 elmer;
 
        /* Clear PHY interrupts by reading the register. */
        simple_mdio_read(cphy, VSC8244_INTR_ENABLE, &val);
@@ -138,13 +136,12 @@ static int vsc8244_intr_clear(struct cphy *cphy)
        if (t1_is_asic(cphy->adapter)) {
                t1_tpi_read(cphy->adapter, A_ELMER0_INT_CAUSE, &elmer);
                elmer |= ELMER0_GP_BIT1;
-               if (is_T2(cphy->adapter)) {
+               if (is_T2(cphy->adapter))
                    elmer |= ELMER0_GP_BIT2|ELMER0_GP_BIT3|ELMER0_GP_BIT4;
-                }
                t1_tpi_write(cphy->adapter, A_ELMER0_INT_CAUSE, elmer);
        }
 
-    return 0;
+       return 0;
 }
 
 /*
@@ -179,13 +176,13 @@ static int vsc8244_set_speed_duplex(struct cphy *phy, int speed, int duplex)
 
 int t1_mdio_set_bits(struct cphy *phy, int mmd, int reg, unsigned int bits)
 {
-    int ret;
-    unsigned int val;
+       int ret;
+       unsigned int val;
 
-    ret = mdio_read(phy, mmd, reg, &val);
-    if (!ret)
-        ret = mdio_write(phy, mmd, reg, val | bits);
-    return ret;
+       ret = mdio_read(phy, mmd, reg, &val);
+       if (!ret)
+               ret = mdio_write(phy, mmd, reg, val | bits);
+       return ret;
 }
 
 static int vsc8244_autoneg_enable(struct cphy *cphy)
@@ -235,7 +232,7 @@ static int vsc8244_advertise(struct cphy *phy, unsigned int advertise_map)
 }
 
 static int vsc8244_get_link_status(struct cphy *cphy, int *link_ok,
-                                    int *speed, int *duplex, int *fc)
+                                  int *speed, int *duplex, int *fc)
 {
        unsigned int bmcr, status, lpa, adv;
        int err, sp = -1, dplx = -1, pause = 0;
@@ -343,11 +340,13 @@ static struct cphy_ops vsc8244_ops = {
        .get_link_status      = vsc8244_get_link_status
 };
 
-static struct cphy* vsc8244_phy_create(adapter_t *adapter, int phy_addr, struct mdio_ops *mdio_ops)
+static struct cphy* vsc8244_phy_create(adapter_t *adapter, int phy_addr,
+                                      struct mdio_ops *mdio_ops)
 {
        struct cphy *cphy = kzalloc(sizeof(*cphy), GFP_KERNEL);
 
-       if (!cphy) return NULL;
+       if (!cphy)
+               return NULL;
 
        cphy_init(cphy, adapter, phy_addr, &vsc8244_ops, mdio_ops);
 
diff --git a/drivers/net/cxgb3/Makefile b/drivers/net/cxgb3/Makefile
new file mode 100644 (file)
index 0000000..3434679
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# Chelsio T3 driver
+#
+
+obj-$(CONFIG_CHELSIO_T3) += cxgb3.o
+
+cxgb3-objs := cxgb3_main.o ael1002.o vsc8211.o t3_hw.o mc5.o \
+             xgmac.o sge.o l2t.o cxgb3_offload.o
diff --git a/drivers/net/cxgb3/adapter.h b/drivers/net/cxgb3/adapter.h
new file mode 100644 (file)
index 0000000..5c97a64
--- /dev/null
@@ -0,0 +1,279 @@
+/*
+ * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/* This file should not be included directly.  Include common.h instead. */
+
+#ifndef __T3_ADAPTER_H__
+#define __T3_ADAPTER_H__
+
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/timer.h>
+#include <linux/cache.h>
+#include <linux/mutex.h>
+#include "t3cdev.h"
+#include <asm/semaphore.h>
+#include <asm/bitops.h>
+#include <asm/io.h>
+
+typedef irqreturn_t(*intr_handler_t) (int, void *);
+
+struct vlan_group;
+
+struct port_info {
+       struct vlan_group *vlan_grp;
+       const struct port_type_info *port_type;
+       u8 port_id;
+       u8 rx_csum_offload;
+       u8 nqsets;
+       u8 first_qset;
+       struct cphy phy;
+       struct cmac mac;
+       struct link_config link_config;
+       struct net_device_stats netstats;
+       int activity;
+};
+
+enum {                         /* adapter flags */
+       FULL_INIT_DONE = (1 << 0),
+       USING_MSI = (1 << 1),
+       USING_MSIX = (1 << 2),
+       QUEUES_BOUND = (1 << 3),
+};
+
+struct rx_desc;
+struct rx_sw_desc;
+
+struct sge_fl {                        /* SGE per free-buffer list state */
+       unsigned int buf_size;  /* size of each Rx buffer */
+       unsigned int credits;   /* # of available Rx buffers */
+       unsigned int size;      /* capacity of free list */
+       unsigned int cidx;      /* consumer index */
+       unsigned int pidx;      /* producer index */
+       unsigned int gen;       /* free list generation */
+       struct rx_desc *desc;   /* address of HW Rx descriptor ring */
+       struct rx_sw_desc *sdesc;       /* address of SW Rx descriptor ring */
+       dma_addr_t phys_addr;   /* physical address of HW ring start */
+       unsigned int cntxt_id;  /* SGE context id for the free list */
+       unsigned long empty;    /* # of times queue ran out of buffers */
+};
+
+/*
+ * Bundle size for grouping offload RX packets for delivery to the stack.
+ * Don't make this too big as we do prefetch on each packet in a bundle.
+ */
+# define RX_BUNDLE_SIZE 8
+
+struct rsp_desc;
+
+struct sge_rspq {              /* state for an SGE response queue */
+       unsigned int credits;   /* # of pending response credits */
+       unsigned int size;      /* capacity of response queue */
+       unsigned int cidx;      /* consumer index */
+       unsigned int gen;       /* current generation bit */
+       unsigned int polling;   /* is the queue serviced through NAPI? */
+       unsigned int holdoff_tmr;       /* interrupt holdoff timer in 100ns */
+       unsigned int next_holdoff;      /* holdoff time for next interrupt */
+       struct rsp_desc *desc;  /* address of HW response ring */
+       dma_addr_t phys_addr;   /* physical address of the ring */
+       unsigned int cntxt_id;  /* SGE context id for the response q */
+       spinlock_t lock;        /* guards response processing */
+       struct sk_buff *rx_head;        /* offload packet receive queue head */
+       struct sk_buff *rx_tail;        /* offload packet receive queue tail */
+
+       unsigned long offload_pkts;
+       unsigned long offload_bundles;
+       unsigned long eth_pkts; /* # of ethernet packets */
+       unsigned long pure_rsps;        /* # of pure (non-data) responses */
+       unsigned long imm_data; /* responses with immediate data */
+       unsigned long rx_drops; /* # of packets dropped due to no mem */
+       unsigned long async_notif; /* # of asynchronous notification events */
+       unsigned long empty;    /* # of times queue ran out of credits */
+       unsigned long nomem;    /* # of responses deferred due to no mem */
+       unsigned long unhandled_irqs;   /* # of spurious intrs */
+};
+
+struct tx_desc;
+struct tx_sw_desc;
+
+struct sge_txq {               /* state for an SGE Tx queue */
+       unsigned long flags;    /* HW DMA fetch status */
+       unsigned int in_use;    /* # of in-use Tx descriptors */
+       unsigned int size;      /* # of descriptors */
+       unsigned int processed; /* total # of descs HW has processed */
+       unsigned int cleaned;   /* total # of descs SW has reclaimed */
+       unsigned int stop_thres;        /* SW TX queue suspend threshold */
+       unsigned int cidx;      /* consumer index */
+       unsigned int pidx;      /* producer index */
+       unsigned int gen;       /* current value of generation bit */
+       unsigned int unacked;   /* Tx descriptors used since last COMPL */
+       struct tx_desc *desc;   /* address of HW Tx descriptor ring */
+       struct tx_sw_desc *sdesc;       /* address of SW Tx descriptor ring */
+       spinlock_t lock;        /* guards enqueueing of new packets */
+       unsigned int token;     /* WR token */
+       dma_addr_t phys_addr;   /* physical address of the ring */
+       struct sk_buff_head sendq;      /* List of backpressured offload packets */
+       struct tasklet_struct qresume_tsk;      /* restarts the queue */
+       unsigned int cntxt_id;  /* SGE context id for the Tx q */
+       unsigned long stops;    /* # of times q has been stopped */
+       unsigned long restarts; /* # of queue restarts */
+};
+
+enum {                         /* per port SGE statistics */
+       SGE_PSTAT_TSO,          /* # of TSO requests */
+       SGE_PSTAT_RX_CSUM_GOOD, /* # of successful RX csum offloads */
+       SGE_PSTAT_TX_CSUM,      /* # of TX checksum offloads */
+       SGE_PSTAT_VLANEX,       /* # of VLAN tag extractions */
+       SGE_PSTAT_VLANINS,      /* # of VLAN tag insertions */
+
+       SGE_PSTAT_MAX           /* must be last */
+};
+
+struct sge_qset {              /* an SGE queue set */
+       struct sge_rspq rspq;
+       struct sge_fl fl[SGE_RXQ_PER_SET];
+       struct sge_txq txq[SGE_TXQ_PER_SET];
+       struct net_device *netdev;      /* associated net device */
+       unsigned long txq_stopped;      /* which Tx queues are stopped */
+       struct timer_list tx_reclaim_timer;     /* reclaims TX buffers */
+       unsigned long port_stats[SGE_PSTAT_MAX];
+} ____cacheline_aligned;
+
+struct sge {
+       struct sge_qset qs[SGE_QSETS];
+       spinlock_t reg_lock;    /* guards non-atomic SGE registers (eg context) */
+};
+
+struct adapter {
+       struct t3cdev tdev;
+       struct list_head adapter_list;
+       void __iomem *regs;
+       struct pci_dev *pdev;
+       unsigned long registered_device_map;
+       unsigned long open_device_map;
+       unsigned long flags;
+
+       const char *name;
+       int msg_enable;
+       unsigned int mmio_len;
+
+       struct adapter_params params;
+       unsigned int slow_intr_mask;
+       unsigned long irq_stats[IRQ_NUM_STATS];
+
+       struct {
+               unsigned short vec;
+               char desc[22];
+       } msix_info[SGE_QSETS + 1];
+
+       /* T3 modules */
+       struct sge sge;
+       struct mc7 pmrx;
+       struct mc7 pmtx;
+       struct mc7 cm;
+       struct mc5 mc5;
+
+       struct net_device *port[MAX_NPORTS];
+       unsigned int check_task_cnt;
+       struct delayed_work adap_check_task;
+       struct work_struct ext_intr_handler_task;
+
+       /*
+        * Dummy netdevices are needed when using multiple receive queues with
+        * NAPI as each netdevice can service only one queue.
+        */
+       struct net_device *dummy_netdev[SGE_QSETS - 1];
+
+       struct dentry *debugfs_root;
+
+       struct mutex mdio_lock;
+       spinlock_t stats_lock;
+       spinlock_t work_lock;
+};
+
+static inline u32 t3_read_reg(struct adapter *adapter, u32 reg_addr)
+{
+       u32 val = readl(adapter->regs + reg_addr);
+
+       CH_DBG(adapter, MMIO, "read register 0x%x value 0x%x\n", reg_addr, val);
+       return val;
+}
+
+static inline void t3_write_reg(struct adapter *adapter, u32 reg_addr, u32 val)
+{
+       CH_DBG(adapter, MMIO, "setting register 0x%x to 0x%x\n", reg_addr, val);
+       writel(val, adapter->regs + reg_addr);
+}
+
+static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)
+{
+       return netdev_priv(adap->port[idx]);
+}
+
+/*
+ * We use the spare atalk_ptr to map a net device to its SGE queue set.
+ * This is a macro so it can be used as l-value.
+ */
+#define dev2qset(netdev) ((netdev)->atalk_ptr)
+
+#define OFFLOAD_DEVMAP_BIT 15
+
+#define tdev2adap(d) container_of(d, struct adapter, tdev)
+
+static inline int offload_running(struct adapter *adapter)
+{
+       return test_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map);
+}
+
+int t3_offload_tx(struct t3cdev *tdev, struct sk_buff *skb);
+
+void t3_os_ext_intr_handler(struct adapter *adapter);
+void t3_os_link_changed(struct adapter *adapter, int port_id, int link_status,
+                       int speed, int duplex, int fc);
+
+void t3_sge_start(struct adapter *adap);
+void t3_sge_stop(struct adapter *adap);
+void t3_free_sge_resources(struct adapter *adap);
+void t3_sge_err_intr_handler(struct adapter *adapter);
+intr_handler_t t3_intr_handler(struct adapter *adap, int polling);
+int t3_eth_xmit(struct sk_buff *skb, struct net_device *dev);
+int t3_mgmt_tx(struct adapter *adap, struct sk_buff *skb);
+void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p);
+int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
+                     int irq_vec_idx, const struct qset_params *p,
+                     int ntxq, struct net_device *netdev);
+int t3_get_desc(const struct sge_qset *qs, unsigned int qnum, unsigned int idx,
+               unsigned char *data);
+irqreturn_t t3_sge_intr_msix(int irq, void *cookie);
+
+#endif                         /* __T3_ADAPTER_H__ */
diff --git a/drivers/net/cxgb3/ael1002.c b/drivers/net/cxgb3/ael1002.c
new file mode 100644 (file)
index 0000000..73a41e6
--- /dev/null
@@ -0,0 +1,251 @@
+/*
+ * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "common.h"
+#include "regs.h"
+
+enum {
+       AEL100X_TX_DISABLE = 9,
+       AEL100X_TX_CONFIG1 = 0xc002,
+       AEL1002_PWR_DOWN_HI = 0xc011,
+       AEL1002_PWR_DOWN_LO = 0xc012,
+       AEL1002_XFI_EQL = 0xc015,
+       AEL1002_LB_EN = 0xc017,
+
+       LASI_CTRL = 0x9002,
+       LASI_STAT = 0x9005
+};
+
+static void ael100x_txon(struct cphy *phy)
+{
+       int tx_on_gpio = phy->addr == 0 ? F_GPIO7_OUT_VAL : F_GPIO2_OUT_VAL;
+
+       msleep(100);
+       t3_set_reg_field(phy->adapter, A_T3DBG_GPIO_EN, 0, tx_on_gpio);
+       msleep(30);
+}
+
+static int ael1002_power_down(struct cphy *phy, int enable)
+{
+       int err;
+
+       err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL100X_TX_DISABLE, !!enable);
+       if (!err)
+               err = t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR,
+                                         BMCR_PDOWN, enable ? BMCR_PDOWN : 0);
+       return err;
+}
+
+static int ael1002_reset(struct cphy *phy, int wait)
+{
+       int err;
+
+       if ((err = ael1002_power_down(phy, 0)) ||
+           (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL100X_TX_CONFIG1, 1)) ||
+           (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_PWR_DOWN_HI, 0)) ||
+           (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_PWR_DOWN_LO, 0)) ||
+           (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_XFI_EQL, 0x18)) ||
+           (err = t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, AEL1002_LB_EN,
+                                      0, 1 << 5)))
+               return err;
+       return 0;
+}
+
+static int ael1002_intr_noop(struct cphy *phy)
+{
+       return 0;
+}
+
+static int ael100x_get_link_status(struct cphy *phy, int *link_ok,
+                                  int *speed, int *duplex, int *fc)
+{
+       if (link_ok) {
+               unsigned int status;
+               int err = mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR, &status);
+
+               /*
+                * BMSR_LSTATUS is latch-low, so if it is 0 we need to read it
+                * once more to get the current link state.
+                */
+               if (!err && !(status & BMSR_LSTATUS))
+                       err = mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR,
+                                       &status);
+               if (err)
+                       return err;
+               *link_ok = !!(status & BMSR_LSTATUS);
+       }
+       if (speed)
+               *speed = SPEED_10000;
+       if (duplex)
+               *duplex = DUPLEX_FULL;
+       return 0;
+}
+
+static struct cphy_ops ael1002_ops = {
+       .reset = ael1002_reset,
+       .intr_enable = ael1002_intr_noop,
+       .intr_disable = ael1002_intr_noop,
+       .intr_clear = ael1002_intr_noop,
+       .intr_handler = ael1002_intr_noop,
+       .get_link_status = ael100x_get_link_status,
+       .power_down = ael1002_power_down,
+};
+
+void t3_ael1002_phy_prep(struct cphy *phy, struct adapter *adapter,
+                        int phy_addr, const struct mdio_ops *mdio_ops)
+{
+       cphy_init(phy, adapter, phy_addr, &ael1002_ops, mdio_ops);
+       ael100x_txon(phy);
+}
+
+static int ael1006_reset(struct cphy *phy, int wait)
+{
+       return t3_phy_reset(phy, MDIO_DEV_PMA_PMD, wait);
+}
+
+static int ael1006_intr_enable(struct cphy *phy)
+{
+       return mdio_write(phy, MDIO_DEV_PMA_PMD, LASI_CTRL, 1);
+}
+
+static int ael1006_intr_disable(struct cphy *phy)
+{
+       return mdio_write(phy, MDIO_DEV_PMA_PMD, LASI_CTRL, 0);
+}
+
+static int ael1006_intr_clear(struct cphy *phy)
+{
+       u32 val;
+
+       return mdio_read(phy, MDIO_DEV_PMA_PMD, LASI_STAT, &val);
+}
+
+static int ael1006_intr_handler(struct cphy *phy)
+{
+       unsigned int status;
+       int err = mdio_read(phy, MDIO_DEV_PMA_PMD, LASI_STAT, &status);
+
+       if (err)
+               return err;
+       return (status & 1) ? cphy_cause_link_change : 0;
+}
+
+static int ael1006_power_down(struct cphy *phy, int enable)
+{
+       return t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR,
+                                  BMCR_PDOWN, enable ? BMCR_PDOWN : 0);
+}
+
+static struct cphy_ops ael1006_ops = {
+       .reset = ael1006_reset,
+       .intr_enable = ael1006_intr_enable,
+       .intr_disable = ael1006_intr_disable,
+       .intr_clear = ael1006_intr_clear,
+       .intr_handler = ael1006_intr_handler,
+       .get_link_status = ael100x_get_link_status,
+       .power_down = ael1006_power_down,
+};
+
+void t3_ael1006_phy_prep(struct cphy *phy, struct adapter *adapter,
+                        int phy_addr, const struct mdio_ops *mdio_ops)
+{
+       cphy_init(phy, adapter, phy_addr, &ael1006_ops, mdio_ops);
+       ael100x_txon(phy);
+}
+
+static struct cphy_ops qt2045_ops = {
+       .reset = ael1006_reset,
+       .intr_enable = ael1006_intr_enable,
+       .intr_disable = ael1006_intr_disable,
+       .intr_clear = ael1006_intr_clear,
+       .intr_handler = ael1006_intr_handler,
+       .get_link_status = ael100x_get_link_status,
+       .power_down = ael1006_power_down,
+};
+
+void t3_qt2045_phy_prep(struct cphy *phy, struct adapter *adapter,
+                       int phy_addr, const struct mdio_ops *mdio_ops)
+{
+       unsigned int stat;
+
+       cphy_init(phy, adapter, phy_addr, &qt2045_ops, mdio_ops);
+
+       /*
+        * Some cards where the PHY is supposed to be at address 0 actually
+        * have it at 1.
+        */
+       if (!phy_addr && !mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR, &stat) &&
+           stat == 0xffff)
+               phy->addr = 1;
+}
+
+static int xaui_direct_reset(struct cphy *phy, int wait)
+{
+       return 0;
+}
+
+static int xaui_direct_get_link_status(struct cphy *phy, int *link_ok,
+                                      int *speed, int *duplex, int *fc)
+{
+       if (link_ok) {
+               unsigned int status;
+
+               status = t3_read_reg(phy->adapter,
+                                    XGM_REG(A_XGM_SERDES_STAT0, phy->addr));
+               *link_ok = !(status & F_LOWSIG0);
+       }
+       if (speed)
+               *speed = SPEED_10000;
+       if (duplex)
+               *duplex = DUPLEX_FULL;
+       return 0;
+}
+
+static int xaui_direct_power_down(struct cphy *phy, int enable)
+{
+       return 0;
+}
+
+static struct cphy_ops xaui_direct_ops = {
+       .reset = xaui_direct_reset,
+       .intr_enable = ael1002_intr_noop,
+       .intr_disable = ael1002_intr_noop,
+       .intr_clear = ael1002_intr_noop,
+       .intr_handler = ael1002_intr_noop,
+       .get_link_status = xaui_direct_get_link_status,
+       .power_down = xaui_direct_power_down,
+};
+
+void t3_xaui_direct_phy_prep(struct cphy *phy, struct adapter *adapter,
+                            int phy_addr, const struct mdio_ops *mdio_ops)
+{
+       cphy_init(phy, adapter, 1, &xaui_direct_ops, mdio_ops);
+}
diff --git a/drivers/net/cxgb3/common.h b/drivers/net/cxgb3/common.h
new file mode 100644 (file)
index 0000000..e23deeb
--- /dev/null
@@ -0,0 +1,729 @@
+/*
+ * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __CHELSIO_COMMON_H
+#define __CHELSIO_COMMON_H
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/ctype.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include "version.h"
+
+#define CH_ERR(adap, fmt, ...)   dev_err(&adap->pdev->dev, fmt, ## __VA_ARGS__)
+#define CH_WARN(adap, fmt, ...)  dev_warn(&adap->pdev->dev, fmt, ## __VA_ARGS__)
+#define CH_ALERT(adap, fmt, ...) \
+       dev_printk(KERN_ALERT, &adap->pdev->dev, fmt, ## __VA_ARGS__)
+
+/*
+ * More powerful macro that selectively prints messages based on msg_enable.
+ * For info and debugging messages.
+ */
+#define CH_MSG(adapter, level, category, fmt, ...) do { \
+       if ((adapter)->msg_enable & NETIF_MSG_##category) \
+               dev_printk(KERN_##level, &adapter->pdev->dev, fmt, \
+                          ## __VA_ARGS__); \
+} while (0)
+
+#ifdef DEBUG
+# define CH_DBG(adapter, category, fmt, ...) \
+       CH_MSG(adapter, DEBUG, category, fmt, ## __VA_ARGS__)
+#else
+# define CH_DBG(adapter, category, fmt, ...)
+#endif
+
+/* Additional NETIF_MSG_* categories */
+#define NETIF_MSG_MMIO 0x8000000
+
+struct t3_rx_mode {
+       struct net_device *dev;
+       struct dev_mc_list *mclist;
+       unsigned int idx;
+};
+
+static inline void init_rx_mode(struct t3_rx_mode *p, struct net_device *dev,
+                               struct dev_mc_list *mclist)
+{
+       p->dev = dev;
+       p->mclist = mclist;
+       p->idx = 0;
+}
+
+static inline u8 *t3_get_next_mcaddr(struct t3_rx_mode *rm)
+{
+       u8 *addr = NULL;
+
+       if (rm->mclist && rm->idx < rm->dev->mc_count) {
+               addr = rm->mclist->dmi_addr;
+               rm->mclist = rm->mclist->next;
+               rm->idx++;
+       }
+       return addr;
+}
+
+enum {
+       MAX_NPORTS = 2,         /* max # of ports */
+       MAX_FRAME_SIZE = 10240, /* max MAC frame size, including header + FCS */
+       EEPROMSIZE = 8192,      /* Serial EEPROM size */
+       RSS_TABLE_SIZE = 64,    /* size of RSS lookup and mapping tables */
+       TCB_SIZE = 128,         /* TCB size */
+       NMTUS = 16,             /* size of MTU table */
+       NCCTRL_WIN = 32,        /* # of congestion control windows */
+};
+
+#define MAX_RX_COALESCING_LEN 16224U
+
+enum {
+       PAUSE_RX = 1 << 0,
+       PAUSE_TX = 1 << 1,
+       PAUSE_AUTONEG = 1 << 2
+};
+
+enum {
+       SUPPORTED_OFFLOAD = 1 << 24,
+       SUPPORTED_IRQ = 1 << 25
+};
+
+enum {                         /* adapter interrupt-maintained statistics */
+       STAT_ULP_CH0_PBL_OOB,
+       STAT_ULP_CH1_PBL_OOB,
+       STAT_PCI_CORR_ECC,
+
+       IRQ_NUM_STATS           /* keep last */
+};
+
+enum {
+       SGE_QSETS = 8,          /* # of SGE Tx/Rx/RspQ sets */
+       SGE_RXQ_PER_SET = 2,    /* # of Rx queues per set */
+       SGE_TXQ_PER_SET = 3     /* # of Tx queues per set */
+};
+
+enum sge_context_type {                /* SGE egress context types */
+       SGE_CNTXT_RDMA = 0,
+       SGE_CNTXT_ETH = 2,
+       SGE_CNTXT_OFLD = 4,
+       SGE_CNTXT_CTRL = 5
+};
+
+enum {
+       AN_PKT_SIZE = 32,       /* async notification packet size */
+       IMMED_PKT_SIZE = 48     /* packet size for immediate data */
+};
+
+struct sg_ent {                        /* SGE scatter/gather entry */
+       u32 len[2];
+       u64 addr[2];
+};
+
+#ifndef SGE_NUM_GENBITS
+/* Must be 1 or 2 */
+# define SGE_NUM_GENBITS 2
+#endif
+
+#define TX_DESC_FLITS 16U
+#define WR_FLITS (TX_DESC_FLITS + 1 - SGE_NUM_GENBITS)
+
+struct cphy;
+struct adapter;
+
+struct mdio_ops {
+       int (*read)(struct adapter *adapter, int phy_addr, int mmd_addr,
+                   int reg_addr, unsigned int *val);
+       int (*write)(struct adapter *adapter, int phy_addr, int mmd_addr,
+                    int reg_addr, unsigned int val);
+};
+
+struct adapter_info {
+       unsigned char nports;   /* # of ports */
+       unsigned char phy_base_addr;    /* MDIO PHY base address */
+       unsigned char mdien;
+       unsigned char mdiinv;
+       unsigned int gpio_out;  /* GPIO output settings */
+       unsigned int gpio_intr; /* GPIO IRQ enable mask */
+       unsigned long caps;     /* adapter capabilities */
+       const struct mdio_ops *mdio_ops;        /* MDIO operations */
+       const char *desc;       /* product description */
+};
+
+struct port_type_info {
+       void (*phy_prep)(struct cphy *phy, struct adapter *adapter,
+                        int phy_addr, const struct mdio_ops *ops);
+       unsigned int caps;
+       const char *desc;
+};
+
+struct mc5_stats {
+       unsigned long parity_err;
+       unsigned long active_rgn_full;
+       unsigned long nfa_srch_err;
+       unsigned long unknown_cmd;
+       unsigned long reqq_parity_err;
+       unsigned long dispq_parity_err;
+       unsigned long del_act_empty;
+};
+
+struct mc7_stats {
+       unsigned long corr_err;
+       unsigned long uncorr_err;
+       unsigned long parity_err;
+       unsigned long addr_err;
+};
+
+struct mac_stats {
+       u64 tx_octets;          /* total # of octets in good frames */
+       u64 tx_octets_bad;      /* total # of octets in error frames */
+       u64 tx_frames;          /* all good frames */
+       u64 tx_mcast_frames;    /* good multicast frames */
+       u64 tx_bcast_frames;    /* good broadcast frames */
+       u64 tx_pause;           /* # of transmitted pause frames */
+       u64 tx_deferred;        /* frames with deferred transmissions */
+       u64 tx_late_collisions; /* # of late collisions */
+       u64 tx_total_collisions;        /* # of total collisions */
+       u64 tx_excess_collisions;       /* frame errors from excessive collissions */
+       u64 tx_underrun;        /* # of Tx FIFO underruns */
+       u64 tx_len_errs;        /* # of Tx length errors */
+       u64 tx_mac_internal_errs;       /* # of internal MAC errors on Tx */
+       u64 tx_excess_deferral; /* # of frames with excessive deferral */
+       u64 tx_fcs_errs;        /* # of frames with bad FCS */
+
+       u64 tx_frames_64;       /* # of Tx frames in a particular range */
+       u64 tx_frames_65_127;
+       u64 tx_frames_128_255;
+       u64 tx_frames_256_511;
+       u64 tx_frames_512_1023;
+       u64 tx_frames_1024_1518;
+       u64 tx_frames_1519_max;
+
+       u64 rx_octets;          /* total # of octets in good frames */
+       u64 rx_octets_bad;      /* total # of octets in error frames */
+       u64 rx_frames;          /* all good frames */
+       u64 rx_mcast_frames;    /* good multicast frames */
+       u64 rx_bcast_frames;    /* good broadcast frames */
+       u64 rx_pause;           /* # of received pause frames */
+       u64 rx_fcs_errs;        /* # of received frames with bad FCS */
+       u64 rx_align_errs;      /* alignment errors */
+       u64 rx_symbol_errs;     /* symbol errors */
+       u64 rx_data_errs;       /* data errors */
+       u64 rx_sequence_errs;   /* sequence errors */
+       u64 rx_runt;            /* # of runt frames */
+       u64 rx_jabber;          /* # of jabber frames */
+       u64 rx_short;           /* # of short frames */
+       u64 rx_too_long;        /* # of oversized frames */
+       u64 rx_mac_internal_errs;       /* # of internal MAC errors on Rx */
+
+       u64 rx_frames_64;       /* # of Rx frames in a particular range */
+       u64 rx_frames_65_127;
+       u64 rx_frames_128_255;
+       u64 rx_frames_256_511;
+       u64 rx_frames_512_1023;
+       u64 rx_frames_1024_1518;
+       u64 rx_frames_1519_max;
+
+       u64 rx_cong_drops;      /* # of Rx drops due to SGE congestion */
+
+       unsigned long tx_fifo_parity_err;
+       unsigned long rx_fifo_parity_err;
+       unsigned long tx_fifo_urun;
+       unsigned long rx_fifo_ovfl;
+       unsigned long serdes_signal_loss;
+       unsigned long xaui_pcs_ctc_err;
+       unsigned long xaui_pcs_align_change;
+};
+
+struct tp_mib_stats {
+       u32 ipInReceive_hi;
+       u32 ipInReceive_lo;
+       u32 ipInHdrErrors_hi;
+       u32 ipInHdrErrors_lo;
+       u32 ipInAddrErrors_hi;
+       u32 ipInAddrErrors_lo;
+       u32 ipInUnknownProtos_hi;
+       u32 ipInUnknownProtos_lo;
+       u32 ipInDiscards_hi;
+       u32 ipInDiscards_lo;
+       u32 ipInDelivers_hi;
+       u32 ipInDelivers_lo;
+       u32 ipOutRequests_hi;
+       u32 ipOutRequests_lo;
+       u32 ipOutDiscards_hi;
+       u32 ipOutDiscards_lo;
+       u32 ipOutNoRoutes_hi;
+       u32 ipOutNoRoutes_lo;
+       u32 ipReasmTimeout;
+       u32 ipReasmReqds;
+       u32 ipReasmOKs;
+       u32 ipReasmFails;
+
+       u32 reserved[8];
+
+       u32 tcpActiveOpens;
+       u32 tcpPassiveOpens;
+       u32 tcpAttemptFails;
+       u32 tcpEstabResets;
+       u32 tcpOutRsts;
+       u32 tcpCurrEstab;
+       u32 tcpInSegs_hi;
+       u32 tcpInSegs_lo;
+       u32 tcpOutSegs_hi;
+       u32 tcpOutSegs_lo;
+       u32 tcpRetransSeg_hi;
+       u32 tcpRetransSeg_lo;
+       u32 tcpInErrs_hi;
+       u32 tcpInErrs_lo;
+       u32 tcpRtoMin;
+       u32 tcpRtoMax;
+};
+
+struct tp_params {
+       unsigned int nchan;     /* # of channels */
+       unsigned int pmrx_size; /* total PMRX capacity */
+       unsigned int pmtx_size; /* total PMTX capacity */
+       unsigned int cm_size;   /* total CM capacity */
+       unsigned int chan_rx_size;      /* per channel Rx size */
+       unsigned int chan_tx_size;      /* per channel Tx size */
+       unsigned int rx_pg_size;        /* Rx page size */
+       unsigned int tx_pg_size;        /* Tx page size */
+       unsigned int rx_num_pgs;        /* # of Rx pages */
+       unsigned int tx_num_pgs;        /* # of Tx pages */
+       unsigned int ntimer_qs; /* # of timer queues */
+};
+
+struct qset_params {           /* SGE queue set parameters */
+       unsigned int polling;   /* polling/interrupt service for rspq */
+       unsigned int coalesce_usecs;    /* irq coalescing timer */
+       unsigned int rspq_size; /* # of entries in response queue */
+       unsigned int fl_size;   /* # of entries in regular free list */
+       unsigned int jumbo_size;        /* # of entries in jumbo free list */
+       unsigned int txq_size[SGE_TXQ_PER_SET]; /* Tx queue sizes */
+       unsigned int cong_thres;        /* FL congestion threshold */
+};
+
+struct sge_params {
+       unsigned int max_pkt_size;      /* max offload pkt size */
+       struct qset_params qset[SGE_QSETS];
+};
+
+struct mc5_params {
+       unsigned int mode;      /* selects MC5 width */
+       unsigned int nservers;  /* size of server region */
+       unsigned int nfilters;  /* size of filter region */
+       unsigned int nroutes;   /* size of routing region */
+};
+
+/* Default MC5 region sizes */
+enum {
+       DEFAULT_NSERVERS = 512,
+       DEFAULT_NFILTERS = 128
+};
+
+/* MC5 modes, these must be non-0 */
+enum {
+       MC5_MODE_144_BIT = 1,
+       MC5_MODE_72_BIT = 2
+};
+
+struct vpd_params {
+       unsigned int cclk;
+       unsigned int mclk;
+       unsigned int uclk;
+       unsigned int mdc;
+       unsigned int mem_timing;
+       u8 eth_base[6];
+       u8 port_type[MAX_NPORTS];
+       unsigned short xauicfg[2];
+};
+
+struct pci_params {
+       unsigned int vpd_cap_addr;
+       unsigned int pcie_cap_addr;
+       unsigned short speed;
+       unsigned char width;
+       unsigned char variant;
+};
+
+enum {
+       PCI_VARIANT_PCI,
+       PCI_VARIANT_PCIX_MODE1_PARITY,
+       PCI_VARIANT_PCIX_MODE1_ECC,
+       PCI_VARIANT_PCIX_266_MODE2,
+       PCI_VARIANT_PCIE
+};
+
+struct adapter_params {
+       struct sge_params sge;
+       struct mc5_params mc5;
+       struct tp_params tp;
+       struct vpd_params vpd;
+       struct pci_params pci;
+
+       const struct adapter_info *info;
+
+       unsigned short mtus[NMTUS];
+       unsigned short a_wnd[NCCTRL_WIN];
+       unsigned short b_wnd[NCCTRL_WIN];
+
+       unsigned int nports;    /* # of ethernet ports */
+       unsigned int stats_update_period;       /* MAC stats accumulation period */
+       unsigned int linkpoll_period;   /* link poll period in 0.1s */
+       unsigned int rev;       /* chip revision */
+};
+
+struct trace_params {
+       u32 sip;
+       u32 sip_mask;
+       u32 dip;
+       u32 dip_mask;
+       u16 sport;
+       u16 sport_mask;
+       u16 dport;
+       u16 dport_mask;
+       u32 vlan:12;
+       u32 vlan_mask:12;
+       u32 intf:4;
+       u32 intf_mask:4;
+       u8 proto;
+       u8 proto_mask;
+};
+
+struct link_config {
+       unsigned int supported; /* link capabilities */
+       unsigned int advertising;       /* advertised capabilities */
+       unsigned short requested_speed; /* speed user has requested */
+       unsigned short speed;   /* actual link speed */
+       unsigned char requested_duplex; /* duplex user has requested */
+       unsigned char duplex;   /* actual link duplex */
+       unsigned char requested_fc;     /* flow control user has requested */
+       unsigned char fc;       /* actual link flow control */
+       unsigned char autoneg;  /* autonegotiating? */
+       unsigned int link_ok;   /* link up? */
+};
+
+#define SPEED_INVALID   0xffff
+#define DUPLEX_INVALID  0xff
+
+struct mc5 {
+       struct adapter *adapter;
+       unsigned int tcam_size;
+       unsigned char part_type;
+       unsigned char parity_enabled;
+       unsigned char mode;
+       struct mc5_stats stats;
+};
+
+static inline unsigned int t3_mc5_size(const struct mc5 *p)
+{
+       return p->tcam_size;
+}
+
+struct mc7 {
+       struct adapter *adapter;        /* backpointer to adapter */
+       unsigned int size;      /* memory size in bytes */
+       unsigned int width;     /* MC7 interface width */
+       unsigned int offset;    /* register address offset for MC7 instance */
+       const char *name;       /* name of MC7 instance */
+       struct mc7_stats stats; /* MC7 statistics */
+};
+
+static inline unsigned int t3_mc7_size(const struct mc7 *p)
+{
+       return p->size;
+}
+
+struct cmac {
+       struct adapter *adapter;
+       unsigned int offset;
+       unsigned int nucast;    /* # of address filters for unicast MACs */
+       struct mac_stats stats;
+};
+
+enum {
+       MAC_DIRECTION_RX = 1,
+       MAC_DIRECTION_TX = 2,
+       MAC_RXFIFO_SIZE = 32768
+};
+
+/* IEEE 802.3ae specified MDIO devices */
+enum {
+       MDIO_DEV_PMA_PMD = 1,
+       MDIO_DEV_WIS = 2,
+       MDIO_DEV_PCS = 3,
+       MDIO_DEV_XGXS = 4
+};
+
+/* PHY loopback direction */
+enum {
+       PHY_LOOPBACK_TX = 1,
+       PHY_LOOPBACK_RX = 2
+};
+
+/* PHY interrupt types */
+enum {
+       cphy_cause_link_change = 1,
+       cphy_cause_fifo_error = 2
+};
+
+/* PHY operations */
+struct cphy_ops {
+       void (*destroy)(struct cphy *phy);
+       int (*reset)(struct cphy *phy, int wait);
+
+       int (*intr_enable)(struct cphy *phy);
+       int (*intr_disable)(struct cphy *phy);
+       int (*intr_clear)(struct cphy *phy);
+       int (*intr_handler)(struct cphy *phy);
+
+       int (*autoneg_enable)(struct cphy *phy);
+       int (*autoneg_restart)(struct cphy *phy);
+
+       int (*advertise)(struct cphy *phy, unsigned int advertise_map);
+       int (*set_loopback)(struct cphy *phy, int mmd, int dir, int enable);
+       int (*set_speed_duplex)(struct cphy *phy, int speed, int duplex);
+       int (*get_link_status)(struct cphy *phy, int *link_ok, int *speed,
+                              int *duplex, int *fc);
+       int (*power_down)(struct cphy *phy, int enable);
+};
+
+/* A PHY instance */
+struct cphy {
+       int addr;               /* PHY address */
+       struct adapter *adapter;        /* associated adapter */
+       unsigned long fifo_errors;      /* FIFO over/under-flows */
+       const struct cphy_ops *ops;     /* PHY operations */
+       int (*mdio_read)(struct adapter *adapter, int phy_addr, int mmd_addr,
+                        int reg_addr, unsigned int *val);
+       int (*mdio_write)(struct adapter *adapter, int phy_addr, int mmd_addr,
+                         int reg_addr, unsigned int val);
+};
+
+/* Convenience MDIO read/write wrappers */
+static inline int mdio_read(struct cphy *phy, int mmd, int reg,
+                           unsigned int *valp)
+{
+       return phy->mdio_read(phy->adapter, phy->addr, mmd, reg, valp);
+}
+
+static inline int mdio_write(struct cphy *phy, int mmd, int reg,
+                            unsigned int val)
+{
+       return phy->mdio_write(phy->adapter, phy->addr, mmd, reg, val);
+}
+
+/* Convenience initializer */
+static inline void cphy_init(struct cphy *phy, struct adapter *adapter,
+                            int phy_addr, struct cphy_ops *phy_ops,
+                            const struct mdio_ops *mdio_ops)
+{
+       phy->adapter = adapter;
+       phy->addr = phy_addr;
+       phy->ops = phy_ops;
+       if (mdio_ops) {
+               phy->mdio_read = mdio_ops->read;
+               phy->mdio_write = mdio_ops->write;
+       }
+}
+
+/* Accumulate MAC statistics every 180 seconds.  For 1G we multiply by 10. */
+#define MAC_STATS_ACCUM_SECS 180
+
+#define XGM_REG(reg_addr, idx) \
+       ((reg_addr) + (idx) * (XGMAC0_1_BASE_ADDR - XGMAC0_0_BASE_ADDR))
+
+struct addr_val_pair {
+       unsigned int reg_addr;
+       unsigned int val;
+};
+
+#include "adapter.h"
+
+#ifndef PCI_VENDOR_ID_CHELSIO
+# define PCI_VENDOR_ID_CHELSIO 0x1425
+#endif
+
+#define for_each_port(adapter, iter) \
+       for (iter = 0; iter < (adapter)->params.nports; ++iter)
+
+#define adapter_info(adap) ((adap)->params.info)
+
+static inline int uses_xaui(const struct adapter *adap)
+{
+       return adapter_info(adap)->caps & SUPPORTED_AUI;
+}
+
+static inline int is_10G(const struct adapter *adap)
+{
+       return adapter_info(adap)->caps & SUPPORTED_10000baseT_Full;
+}
+
+static inline int is_offload(const struct adapter *adap)
+{
+       return adapter_info(adap)->caps & SUPPORTED_OFFLOAD;
+}
+
+static inline unsigned int core_ticks_per_usec(const struct adapter *adap)
+{
+       return adap->params.vpd.cclk / 1000;
+}
+
+static inline unsigned int is_pcie(const struct adapter *adap)
+{
+       return adap->params.pci.variant == PCI_VARIANT_PCIE;
+}
+
+void t3_set_reg_field(struct adapter *adap, unsigned int addr, u32 mask,
+                     u32 val);
+void t3_write_regs(struct adapter *adapter, const struct addr_val_pair *p,
+                  int n, unsigned int offset);
+int t3_wait_op_done_val(struct adapter *adapter, int reg, u32 mask,
+                       int polarity, int attempts, int delay, u32 *valp);
+static inline int t3_wait_op_done(struct adapter *adapter, int reg, u32 mask,
+                                 int polarity, int attempts, int delay)
+{
+       return t3_wait_op_done_val(adapter, reg, mask, polarity, attempts,
+                                  delay, NULL);
+}
+int t3_mdio_change_bits(struct cphy *phy, int mmd, int reg, unsigned int clear,
+                       unsigned int set);
+int t3_phy_reset(struct cphy *phy, int mmd, int wait);
+int t3_phy_advertise(struct cphy *phy, unsigned int advert);
+int t3_set_phy_speed_duplex(struct cphy *phy, int speed, int duplex);
+
+void t3_intr_enable(struct adapter *adapter);
+void t3_intr_disable(struct adapter *adapter);
+void t3_intr_clear(struct adapter *adapter);
+void t3_port_intr_enable(struct adapter *adapter, int idx);
+void t3_port_intr_disable(struct adapter *adapter, int idx);
+void t3_port_intr_clear(struct adapter *adapter, int idx);
+int t3_slow_intr_handler(struct adapter *adapter);
+int t3_phy_intr_handler(struct adapter *adapter);
+
+void t3_link_changed(struct adapter *adapter, int port_id);
+int t3_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc);
+const struct adapter_info *t3_get_adapter_info(unsigned int board_id);
+int t3_seeprom_read(struct adapter *adapter, u32 addr, u32 *data);
+int t3_seeprom_write(struct adapter *adapter, u32 addr, u32 data);
+int t3_seeprom_wp(struct adapter *adapter, int enable);
+int t3_read_flash(struct adapter *adapter, unsigned int addr,
+                 unsigned int nwords, u32 *data, int byte_oriented);
+int t3_load_fw(struct adapter *adapter, const u8 * fw_data, unsigned int size);
+int t3_get_fw_version(struct adapter *adapter, u32 *vers);
+int t3_check_fw_version(struct adapter *adapter);
+int t3_init_hw(struct adapter *adapter, u32 fw_params);
+void mac_prep(struct cmac *mac, struct adapter *adapter, int index);
+void early_hw_init(struct adapter *adapter, const struct adapter_info *ai);
+int t3_prep_adapter(struct adapter *adapter, const struct adapter_info *ai,
+                   int reset);
+void t3_led_ready(struct adapter *adapter);
+void t3_fatal_err(struct adapter *adapter);
+void t3_set_vlan_accel(struct adapter *adapter, unsigned int ports, int on);
+void t3_config_rss(struct adapter *adapter, unsigned int rss_config,
+                  const u8 * cpus, const u16 *rspq);
+int t3_read_rss(struct adapter *adapter, u8 * lkup, u16 *map);
+int t3_mps_set_active_ports(struct adapter *adap, unsigned int port_mask);
+int t3_cim_ctl_blk_read(struct adapter *adap, unsigned int addr,
+                       unsigned int n, unsigned int *valp);
+int t3_mc7_bd_read(struct mc7 *mc7, unsigned int start, unsigned int n,
+                  u64 *buf);
+
+int t3_mac_reset(struct cmac *mac);
+void t3b_pcs_reset(struct cmac *mac);
+int t3_mac_enable(struct cmac *mac, int which);
+int t3_mac_disable(struct cmac *mac, int which);
+int t3_mac_set_mtu(struct cmac *mac, unsigned int mtu);
+int t3_mac_set_rx_mode(struct cmac *mac, struct t3_rx_mode *rm);
+int t3_mac_set_address(struct cmac *mac, unsigned int idx, u8 addr[6]);
+int t3_mac_set_num_ucast(struct cmac *mac, int n);
+const struct mac_stats *t3_mac_update_stats(struct cmac *mac);
+int t3_mac_set_speed_duplex_fc(struct cmac *mac, int speed, int duplex, int fc);
+
+void t3_mc5_prep(struct adapter *adapter, struct mc5 *mc5, int mode);
+int t3_mc5_init(struct mc5 *mc5, unsigned int nservers, unsigned int nfilters,
+               unsigned int nroutes);
+void t3_mc5_intr_handler(struct mc5 *mc5);
+int t3_read_mc5_range(const struct mc5 *mc5, unsigned int start, unsigned int n,
+                     u32 *buf);
+
+int t3_tp_set_coalescing_size(struct adapter *adap, unsigned int size, int psh);
+void t3_tp_set_max_rxsize(struct adapter *adap, unsigned int size);
+void t3_tp_set_offload_mode(struct adapter *adap, int enable);
+void t3_tp_get_mib_stats(struct adapter *adap, struct tp_mib_stats *tps);
+void t3_load_mtus(struct adapter *adap, unsigned short mtus[NMTUS],
+                 unsigned short alpha[NCCTRL_WIN],
+                 unsigned short beta[NCCTRL_WIN], unsigned short mtu_cap);
+void t3_read_hw_mtus(struct adapter *adap, unsigned short mtus[NMTUS]);
+void t3_get_cong_cntl_tab(struct adapter *adap,
+                         unsigned short incr[NMTUS][NCCTRL_WIN]);
+void t3_config_trace_filter(struct adapter *adapter,
+                           const struct trace_params *tp, int filter_index,
+                           int invert, int enable);
+int t3_config_sched(struct adapter *adap, unsigned int kbps, int sched);
+
+void t3_sge_prep(struct adapter *adap, struct sge_params *p);
+void t3_sge_init(struct adapter *adap, struct sge_params *p);
+int t3_sge_init_ecntxt(struct adapter *adapter, unsigned int id, int gts_enable,
+                      enum sge_context_type type, int respq, u64 base_addr,
+                      unsigned int size, unsigned int token, int gen,
+                      unsigned int cidx);
+int t3_sge_init_flcntxt(struct adapter *adapter, unsigned int id,
+                       int gts_enable, u64 base_addr, unsigned int size,
+                       unsigned int esize, unsigned int cong_thres, int gen,
+                       unsigned int cidx);
+int t3_sge_init_rspcntxt(struct adapter *adapter, unsigned int id,
+                        int irq_vec_idx, u64 base_addr, unsigned int size,
+                        unsigned int fl_thres, int gen, unsigned int cidx);
+int t3_sge_init_cqcntxt(struct adapter *adapter, unsigned int id, u64 base_addr,
+                       unsigned int size, int rspq, int ovfl_mode,
+                       unsigned int credits, unsigned int credit_thres);
+int t3_sge_enable_ecntxt(struct adapter *adapter, unsigned int id, int enable);
+int t3_sge_disable_fl(struct adapter *adapter, unsigned int id);
+int t3_sge_disable_rspcntxt(struct adapter *adapter, unsigned int id);
+int t3_sge_disable_cqcntxt(struct adapter *adapter, unsigned int id);
+int t3_sge_read_ecntxt(struct adapter *adapter, unsigned int id, u32 data[4]);
+int t3_sge_read_fl(struct adapter *adapter, unsigned int id, u32 data[4]);
+int t3_sge_read_cq(struct adapter *adapter, unsigned int id, u32 data[4]);
+int t3_sge_read_rspq(struct adapter *adapter, unsigned int id, u32 data[4]);
+int t3_sge_cqcntxt_op(struct adapter *adapter, unsigned int id, unsigned int op,
+                     unsigned int credits);
+
+void t3_vsc8211_phy_prep(struct cphy *phy, struct adapter *adapter,
+                        int phy_addr, const struct mdio_ops *mdio_ops);
+void t3_ael1002_phy_prep(struct cphy *phy, struct adapter *adapter,
+                        int phy_addr, const struct mdio_ops *mdio_ops);
+void t3_ael1006_phy_prep(struct cphy *phy, struct adapter *adapter,
+                        int phy_addr, const struct mdio_ops *mdio_ops);
+void t3_qt2045_phy_prep(struct cphy *phy, struct adapter *adapter, int phy_addr,
+                       const struct mdio_ops *mdio_ops);
+void t3_xaui_direct_phy_prep(struct cphy *phy, struct adapter *adapter,
+                            int phy_addr, const struct mdio_ops *mdio_ops);
+#endif                         /* __CHELSIO_COMMON_H */
diff --git a/drivers/net/cxgb3/cxgb3_ctl_defs.h b/drivers/net/cxgb3/cxgb3_ctl_defs.h
new file mode 100644 (file)
index 0000000..2095dda
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef _CXGB3_OFFLOAD_CTL_DEFS_H
+#define _CXGB3_OFFLOAD_CTL_DEFS_H
+
+enum {
+       GET_MAX_OUTSTANDING_WR,
+       GET_TX_MAX_CHUNK,
+       GET_TID_RANGE,
+       GET_STID_RANGE,
+       GET_RTBL_RANGE,
+       GET_L2T_CAPACITY,
+       GET_MTUS,
+       GET_WR_LEN,
+       GET_IFF_FROM_MAC,
+       GET_DDP_PARAMS,
+       GET_PORTS,
+
+       ULP_ISCSI_GET_PARAMS,
+       ULP_ISCSI_SET_PARAMS,
+
+       RDMA_GET_PARAMS,
+       RDMA_CQ_OP,
+       RDMA_CQ_SETUP,
+       RDMA_CQ_DISABLE,
+       RDMA_CTRL_QP_SETUP,
+       RDMA_GET_MEM,
+};
+
+/*
+ * Structure used to describe a TID range.  Valid TIDs are [base, base+num).
+ */
+struct tid_range {
+       unsigned int base;      /* first TID */
+       unsigned int num;       /* number of TIDs in range */
+};
+
+/*
+ * Structure used to request the size and contents of the MTU table.
+ */
+struct mtutab {
+       unsigned int size;      /* # of entries in the MTU table */
+       const unsigned short *mtus;     /* the MTU table values */
+};
+
+struct net_device;
+
+/*
+ * Structure used to request the adapter net_device owning a given MAC address.
+ */
+struct iff_mac {
+       struct net_device *dev; /* the net_device */
+       const unsigned char *mac_addr;  /* MAC address to lookup */
+       u16 vlan_tag;
+};
+
+struct pci_dev;
+
+/*
+ * Structure used to request the TCP DDP parameters.
+ */
+struct ddp_params {
+       unsigned int llimit;    /* TDDP region start address */
+       unsigned int ulimit;    /* TDDP region end address */
+       unsigned int tag_mask;  /* TDDP tag mask */
+       struct pci_dev *pdev;
+};
+
+struct adap_ports {
+       unsigned int nports;    /* number of ports on this adapter */
+       struct net_device *lldevs[2];
+};
+
+/*
+ * Structure used to return information to the iscsi layer.
+ */
+struct ulp_iscsi_info {
+       unsigned int offset;
+       unsigned int llimit;
+       unsigned int ulimit;
+       unsigned int tagmask;
+       unsigned int pgsz3;
+       unsigned int pgsz2;
+       unsigned int pgsz1;
+       unsigned int pgsz0;
+       unsigned int max_rxsz;
+       unsigned int max_txsz;
+       struct pci_dev *pdev;
+};
+
+/*
+ * Structure used to return information to the RDMA layer.
+ */
+struct rdma_info {
+       unsigned int tpt_base;  /* TPT base address */
+       unsigned int tpt_top;   /* TPT last entry address */
+       unsigned int pbl_base;  /* PBL base address */
+       unsigned int pbl_top;   /* PBL last entry address */
+       unsigned int rqt_base;  /* RQT base address */
+       unsigned int rqt_top;   /* RQT last entry address */
+       unsigned int udbell_len;        /* user doorbell region length */
+       unsigned long udbell_physbase;  /* user doorbell physical start addr */
+       void __iomem *kdb_addr; /* kernel doorbell register address */
+       struct pci_dev *pdev;   /* associated PCI device */
+};
+
+/*
+ * Structure used to request an operation on an RDMA completion queue.
+ */
+struct rdma_cq_op {
+       unsigned int id;
+       unsigned int op;
+       unsigned int credits;
+};
+
+/*
+ * Structure used to setup RDMA completion queues.
+ */
+struct rdma_cq_setup {
+       unsigned int id;
+       unsigned long long base_addr;
+       unsigned int size;
+       unsigned int credits;
+       unsigned int credit_thres;
+       unsigned int ovfl_mode;
+};
+
+/*
+ * Structure used to setup the RDMA control egress context.
+ */
+struct rdma_ctrlqp_setup {
+       unsigned long long base_addr;
+       unsigned int size;
+};
+#endif                         /* _CXGB3_OFFLOAD_CTL_DEFS_H */
diff --git a/drivers/net/cxgb3/cxgb3_defs.h b/drivers/net/cxgb3/cxgb3_defs.h
new file mode 100644 (file)
index 0000000..16e0049
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef _CHELSIO_DEFS_H
+#define _CHELSIO_DEFS_H
+
+#include <linux/skbuff.h>
+#include <net/tcp.h>
+
+#include "t3cdev.h"
+
+#include "cxgb3_offload.h"
+
+#define VALIDATE_TID 1
+
+void *cxgb_alloc_mem(unsigned long size);
+void cxgb_free_mem(void *addr);
+void cxgb_neigh_update(struct neighbour *neigh);
+void cxgb_redirect(struct dst_entry *old, struct dst_entry *new);
+
+/*
+ * Map an ATID or STID to their entries in the corresponding TID tables.
+ */
+static inline union active_open_entry *atid2entry(const struct tid_info *t,
+                                                 unsigned int atid)
+{
+       return &t->atid_tab[atid - t->atid_base];
+}
+
+static inline union listen_entry *stid2entry(const struct tid_info *t,
+                                            unsigned int stid)
+{
+       return &t->stid_tab[stid - t->stid_base];
+}
+
+/*
+ * Find the connection corresponding to a TID.
+ */
+static inline struct t3c_tid_entry *lookup_tid(const struct tid_info *t,
+                                              unsigned int tid)
+{
+       return tid < t->ntids ? &(t->tid_tab[tid]) : NULL;
+}
+
+/*
+ * Find the connection corresponding to a server TID.
+ */
+static inline struct t3c_tid_entry *lookup_stid(const struct tid_info *t,
+                                               unsigned int tid)
+{
+       if (tid < t->stid_base || tid >= t->stid_base + t->nstids)
+               return NULL;
+       return &(stid2entry(t, tid)->t3c_tid);
+}
+
+/*
+ * Find the connection corresponding to an active-open TID.
+ */
+static inline struct t3c_tid_entry *lookup_atid(const struct tid_info *t,
+                                               unsigned int tid)
+{
+       if (tid < t->atid_base || tid >= t->atid_base + t->natids)
+               return NULL;
+       return &(atid2entry(t, tid)->t3c_tid);
+}
+
+int process_rx(struct t3cdev *dev, struct sk_buff **skbs, int n);
+int attach_t3cdev(struct t3cdev *dev);
+void detach_t3cdev(struct t3cdev *dev);
+#endif
diff --git a/drivers/net/cxgb3/cxgb3_ioctl.h b/drivers/net/cxgb3/cxgb3_ioctl.h
new file mode 100644 (file)
index 0000000..a942818
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __CHIOCTL_H__
+#define __CHIOCTL_H__
+
+/*
+ * Ioctl commands specific to this driver.
+ */
+enum {
+       CHELSIO_SETREG = 1024,
+       CHELSIO_GETREG,
+       CHELSIO_SETTPI,
+       CHELSIO_GETTPI,
+       CHELSIO_GETMTUTAB,
+       CHELSIO_SETMTUTAB,
+       CHELSIO_GETMTU,
+       CHELSIO_SET_PM,
+       CHELSIO_GET_PM,
+       CHELSIO_GET_TCAM,
+       CHELSIO_SET_TCAM,
+       CHELSIO_GET_TCB,
+       CHELSIO_GET_MEM,
+       CHELSIO_LOAD_FW,
+       CHELSIO_GET_PROTO,
+       CHELSIO_SET_PROTO,
+       CHELSIO_SET_TRACE_FILTER,
+       CHELSIO_SET_QSET_PARAMS,
+       CHELSIO_GET_QSET_PARAMS,
+       CHELSIO_SET_QSET_NUM,
+       CHELSIO_GET_QSET_NUM,
+       CHELSIO_SET_PKTSCHED,
+};
+
+struct ch_reg {
+       uint32_t cmd;
+       uint32_t addr;
+       uint32_t val;
+};
+
+struct ch_cntxt {
+       uint32_t cmd;
+       uint32_t cntxt_type;
+       uint32_t cntxt_id;
+       uint32_t data[4];
+};
+
+/* context types */
+enum { CNTXT_TYPE_EGRESS, CNTXT_TYPE_FL, CNTXT_TYPE_RSP, CNTXT_TYPE_CQ };
+
+struct ch_desc {
+       uint32_t cmd;
+       uint32_t queue_num;
+       uint32_t idx;
+       uint32_t size;
+       uint8_t data[128];
+};
+
+struct ch_mem_range {
+       uint32_t cmd;
+       uint32_t mem_id;
+       uint32_t addr;
+       uint32_t len;
+       uint32_t version;
+       uint8_t buf[0];
+};
+
+struct ch_qset_params {
+       uint32_t cmd;
+       uint32_t qset_idx;
+       int32_t txq_size[3];
+       int32_t rspq_size;
+       int32_t fl_size[2];
+       int32_t intr_lat;
+       int32_t polling;
+       int32_t cong_thres;
+};
+
+struct ch_pktsched_params {
+       uint32_t cmd;
+       uint8_t sched;
+       uint8_t idx;
+       uint8_t min;
+       uint8_t max;
+       uint8_t binding;
+};
+
+#ifndef TCB_SIZE
+# define TCB_SIZE   128
+#endif
+
+/* TCB size in 32-bit words */
+#define TCB_WORDS (TCB_SIZE / 4)
+
+enum { MEM_CM, MEM_PMRX, MEM_PMTX };   /* ch_mem_range.mem_id values */
+
+struct ch_mtus {
+       uint32_t cmd;
+       uint32_t nmtus;
+       uint16_t mtus[NMTUS];
+};
+
+struct ch_pm {
+       uint32_t cmd;
+       uint32_t tx_pg_sz;
+       uint32_t tx_num_pg;
+       uint32_t rx_pg_sz;
+       uint32_t rx_num_pg;
+       uint32_t pm_total;
+};
+
+struct ch_tcam {
+       uint32_t cmd;
+       uint32_t tcam_size;
+       uint32_t nservers;
+       uint32_t nroutes;
+       uint32_t nfilters;
+};
+
+struct ch_tcb {
+       uint32_t cmd;
+       uint32_t tcb_index;
+       uint32_t tcb_data[TCB_WORDS];
+};
+
+struct ch_tcam_word {
+       uint32_t cmd;
+       uint32_t addr;
+       uint32_t buf[3];
+};
+
+struct ch_trace {
+       uint32_t cmd;
+       uint32_t sip;
+       uint32_t sip_mask;
+       uint32_t dip;
+       uint32_t dip_mask;
+       uint16_t sport;
+       uint16_t sport_mask;
+       uint16_t dport;
+       uint16_t dport_mask;
+       uint32_t vlan:12;
+       uint32_t vlan_mask:12;
+       uint32_t intf:4;
+       uint32_t intf_mask:4;
+       uint8_t proto;
+       uint8_t proto_mask;
+       uint8_t invert_match:1;
+       uint8_t config_tx:1;
+       uint8_t config_rx:1;
+       uint8_t trace_tx:1;
+       uint8_t trace_rx:1;
+};
+
+#define SIOCCHIOCTL SIOCDEVPRIVATE
+
+#endif
diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c
new file mode 100644 (file)
index 0000000..dfa035a
--- /dev/null
@@ -0,0 +1,2515 @@
+/*
+ * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/dma-mapping.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/if_vlan.h>
+#include <linux/mii.h>
+#include <linux/sockios.h>
+#include <linux/workqueue.h>
+#include <linux/proc_fs.h>
+#include <linux/rtnetlink.h>
+#include <asm/uaccess.h>
+
+#include "common.h"
+#include "cxgb3_ioctl.h"
+#include "regs.h"
+#include "cxgb3_offload.h"
+#include "version.h"
+
+#include "cxgb3_ctl_defs.h"
+#include "t3_cpl.h"
+#include "firmware_exports.h"
+
+enum {
+       MAX_TXQ_ENTRIES = 16384,
+       MAX_CTRL_TXQ_ENTRIES = 1024,
+       MAX_RSPQ_ENTRIES = 16384,
+       MAX_RX_BUFFERS = 16384,
+       MAX_RX_JUMBO_BUFFERS = 16384,
+       MIN_TXQ_ENTRIES = 4,
+       MIN_CTRL_TXQ_ENTRIES = 4,
+       MIN_RSPQ_ENTRIES = 32,
+       MIN_FL_ENTRIES = 32
+};
+
+#define PORT_MASK ((1 << MAX_NPORTS) - 1)
+
+#define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
+                        NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
+                        NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
+
+#define EEPROM_MAGIC 0x38E2F10C
+
+#define to_net_dev(class) container_of(class, struct net_device, class_dev)
+
+#define CH_DEVICE(devid, ssid, idx) \
+       { PCI_VENDOR_ID_CHELSIO, devid, PCI_ANY_ID, ssid, 0, 0, idx }
+
+static const struct pci_device_id cxgb3_pci_tbl[] = {
+       CH_DEVICE(0x20, 1, 0),  /* PE9000 */
+       CH_DEVICE(0x21, 1, 1),  /* T302E */
+       CH_DEVICE(0x22, 1, 2),  /* T310E */
+       CH_DEVICE(0x23, 1, 3),  /* T320X */
+       CH_DEVICE(0x24, 1, 1),  /* T302X */
+       CH_DEVICE(0x25, 1, 3),  /* T320E */
+       CH_DEVICE(0x26, 1, 2),  /* T310X */
+       CH_DEVICE(0x30, 1, 2),  /* T3B10 */
+       CH_DEVICE(0x31, 1, 3),  /* T3B20 */
+       CH_DEVICE(0x32, 1, 1),  /* T3B02 */
+       {0,}
+};
+
+MODULE_DESCRIPTION(DRV_DESC);
+MODULE_AUTHOR("Chelsio Communications");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_VERSION(DRV_VERSION);
+MODULE_DEVICE_TABLE(pci, cxgb3_pci_tbl);
+
+static int dflt_msg_enable = DFLT_MSG_ENABLE;
+
+module_param(dflt_msg_enable, int, 0644);
+MODULE_PARM_DESC(dflt_msg_enable, "Chelsio T3 default message enable bitmap");
+
+/*
+ * The driver uses the best interrupt scheme available on a platform in the
+ * order MSI-X, MSI, legacy pin interrupts.  This parameter determines which
+ * of these schemes the driver may consider as follows:
+ *
+ * msi = 2: choose from among all three options
+ * msi = 1: only consider MSI and pin interrupts
+ * msi = 0: force pin interrupts
+ */
+static int msi = 2;
+
+module_param(msi, int, 0644);
+MODULE_PARM_DESC(msi, "whether to use MSI or MSI-X");
+
+/*
+ * The driver enables offload as a default.
+ * To disable it, use ofld_disable = 1.
+ */
+
+static int ofld_disable = 0;
+
+module_param(ofld_disable, int, 0644);
+MODULE_PARM_DESC(ofld_disable, "whether to enable offload at init time or not");
+
+/*
+ * We have work elements that we need to cancel when an interface is taken
+ * down.  Normally the work elements would be executed by keventd but that
+ * can deadlock because of linkwatch.  If our close method takes the rtnl
+ * lock and linkwatch is ahead of our work elements in keventd, linkwatch
+ * will block keventd as it needs the rtnl lock, and we'll deadlock waiting
+ * for our work to complete.  Get our own work queue to solve this.
+ */
+static struct workqueue_struct *cxgb3_wq;
+
+/**
+ *     link_report - show link status and link speed/duplex
+ *     @p: the port whose settings are to be reported
+ *
+ *     Shows the link status, speed, and duplex of a port.
+ */
+static void link_report(struct net_device *dev)
+{
+       if (!netif_carrier_ok(dev))
+               printk(KERN_INFO "%s: link down\n", dev->name);
+       else {
+               const char *s = "10Mbps";
+               const struct port_info *p = netdev_priv(dev);
+
+               switch (p->link_config.speed) {
+               case SPEED_10000:
+                       s = "10Gbps";
+                       break;
+               case SPEED_1000:
+                       s = "1000Mbps";
+                       break;
+               case SPEED_100:
+                       s = "100Mbps";
+                       break;
+               }
+
+               printk(KERN_INFO "%s: link up, %s, %s-duplex\n", dev->name, s,
+                      p->link_config.duplex == DUPLEX_FULL ? "full" : "half");
+       }
+}
+
+/**
+ *     t3_os_link_changed - handle link status changes
+ *     @adapter: the adapter associated with the link change
+ *     @port_id: the port index whose limk status has changed
+ *     @link_stat: the new status of the link
+ *     @speed: the new speed setting
+ *     @duplex: the new duplex setting
+ *     @pause: the new flow-control setting
+ *
+ *     This is the OS-dependent handler for link status changes.  The OS
+ *     neutral handler takes care of most of the processing for these events,
+ *     then calls this handler for any OS-specific processing.
+ */
+void t3_os_link_changed(struct adapter *adapter, int port_id, int link_stat,
+                       int speed, int duplex, int pause)
+{
+       struct net_device *dev = adapter->port[port_id];
+
+       /* Skip changes from disabled ports. */
+       if (!netif_running(dev))
+               return;
+
+       if (link_stat != netif_carrier_ok(dev)) {
+               if (link_stat)
+                       netif_carrier_on(dev);
+               else
+                       netif_carrier_off(dev);
+               link_report(dev);
+       }
+}
+
+static void cxgb_set_rxmode(struct net_device *dev)
+{
+       struct t3_rx_mode rm;
+       struct port_info *pi = netdev_priv(dev);
+
+       init_rx_mode(&rm, dev, dev->mc_list);
+       t3_mac_set_rx_mode(&pi->mac, &rm);
+}
+
+/**
+ *     link_start - enable a port
+ *     @dev: the device to enable
+ *
+ *     Performs the MAC and PHY actions needed to enable a port.
+ */
+static void link_start(struct net_device *dev)
+{
+       struct t3_rx_mode rm;
+       struct port_info *pi = netdev_priv(dev);
+       struct cmac *mac = &pi->mac;
+
+       init_rx_mode(&rm, dev, dev->mc_list);
+       t3_mac_reset(mac);
+       t3_mac_set_mtu(mac, dev->mtu);
+       t3_mac_set_address(mac, 0, dev->dev_addr);
+       t3_mac_set_rx_mode(mac, &rm);
+       t3_link_start(&pi->phy, mac, &pi->link_config);
+       t3_mac_enable(mac, MAC_DIRECTION_RX | MAC_DIRECTION_TX);
+}
+
+static inline void cxgb_disable_msi(struct adapter *adapter)
+{
+       if (adapter->flags & USING_MSIX) {
+               pci_disable_msix(adapter->pdev);
+               adapter->flags &= ~USING_MSIX;
+       } else if (adapter->flags & USING_MSI) {
+               pci_disable_msi(adapter->pdev);
+               adapter->flags &= ~USING_MSI;
+       }
+}
+
+/*
+ * Interrupt handler for asynchronous events used with MSI-X.
+ */
+static irqreturn_t t3_async_intr_handler(int irq, void *cookie)
+{
+       t3_slow_intr_handler(cookie);
+       return IRQ_HANDLED;
+}
+
+/*
+ * Name the MSI-X interrupts.
+ */
+static void name_msix_vecs(struct adapter *adap)
+{
+       int i, j, msi_idx = 1, n = sizeof(adap->msix_info[0].desc) - 1;
+
+       snprintf(adap->msix_info[0].desc, n, "%s", adap->name);
+       adap->msix_info[0].desc[n] = 0;
+
+       for_each_port(adap, j) {
+               struct net_device *d = adap->port[j];
+               const struct port_info *pi = netdev_priv(d);
+
+               for (i = 0; i < pi->nqsets; i++, msi_idx++) {
+                       snprintf(adap->msix_info[msi_idx].desc, n,
+                                "%s (queue %d)", d->name, i);
+                       adap->msix_info[msi_idx].desc[n] = 0;
+               }
+       }
+}
+
+static int request_msix_data_irqs(struct adapter *adap)
+{
+       int i, j, err, qidx = 0;
+
+       for_each_port(adap, i) {
+               int nqsets = adap2pinfo(adap, i)->nqsets;
+
+               for (j = 0; j < nqsets; ++j) {
+                       err = request_irq(adap->msix_info[qidx + 1].vec,
+                                         t3_intr_handler(adap,
+                                                         adap->sge.qs[qidx].
+                                                         rspq.polling), 0,
+                                         adap->msix_info[qidx + 1].desc,
+                                         &adap->sge.qs[qidx]);
+                       if (err) {
+                               while (--qidx >= 0)
+                                       free_irq(adap->msix_info[qidx + 1].vec,
+                                                &adap->sge.qs[qidx]);
+                               return err;
+                       }
+                       qidx++;
+               }
+       }
+       return 0;
+}
+
+/**
+ *     setup_rss - configure RSS
+ *     @adap: the adapter
+ *
+ *     Sets up RSS to distribute packets to multiple receive queues.  We
+ *     configure the RSS CPU lookup table to distribute to the number of HW
+ *     receive queues, and the response queue lookup table to narrow that
+ *     down to the response queues actually configured for each port.
+ *     We always configure the RSS mapping for two ports since the mapping
+ *     table has plenty of entries.
+ */
+static void setup_rss(struct adapter *adap)
+{
+       int i;
+       unsigned int nq0 = adap2pinfo(adap, 0)->nqsets;
+       unsigned int nq1 = adap->port[1] ? adap2pinfo(adap, 1)->nqsets : 1;
+       u8 cpus[SGE_QSETS + 1];
+       u16 rspq_map[RSS_TABLE_SIZE];
+
+       for (i = 0; i < SGE_QSETS; ++i)
+               cpus[i] = i;
+       cpus[SGE_QSETS] = 0xff; /* terminator */
+
+       for (i = 0; i < RSS_TABLE_SIZE / 2; ++i) {
+               rspq_map[i] = i % nq0;
+               rspq_map[i + RSS_TABLE_SIZE / 2] = (i % nq1) + nq0;
+       }
+
+       t3_config_rss(adap, F_RQFEEDBACKENABLE | F_TNLLKPEN | F_TNLMAPEN |
+                     F_TNLPRTEN | F_TNL2TUPEN | F_TNL4TUPEN |
+                     V_RRCPLCPUSIZE(6), cpus, rspq_map);
+}
+
+/*
+ * If we have multiple receive queues per port serviced by NAPI we need one
+ * netdevice per queue as NAPI operates on netdevices.  We already have one
+ * netdevice, namely the one associated with the interface, so we use dummy
+ * ones for any additional queues.  Note that these netdevices exist purely
+ * so that NAPI has something to work with, they do not represent network
+ * ports and are not registered.
+ */
+static int init_dummy_netdevs(struct adapter *adap)
+{
+       int i, j, dummy_idx = 0;
+       struct net_device *nd;
+
+       for_each_port(adap, i) {
+               struct net_device *dev = adap->port[i];
+               const struct port_info *pi = netdev_priv(dev);
+
+               for (j = 0; j < pi->nqsets - 1; j++) {
+                       if (!adap->dummy_netdev[dummy_idx]) {
+                               nd = alloc_netdev(0, "", ether_setup);
+                               if (!nd)
+                                       goto free_all;
+
+                               nd->priv = adap;
+                               nd->weight = 64;
+                               set_bit(__LINK_STATE_START, &nd->state);
+                               adap->dummy_netdev[dummy_idx] = nd;
+                       }
+                       strcpy(adap->dummy_netdev[dummy_idx]->name, dev->name);
+                       dummy_idx++;
+               }
+       }
+       return 0;
+
+free_all:
+       while (--dummy_idx >= 0) {
+               free_netdev(adap->dummy_netdev[dummy_idx]);
+               adap->dummy_netdev[dummy_idx] = NULL;
+       }
+       return -ENOMEM;
+}
+
+/*
+ * Wait until all NAPI handlers are descheduled.  This includes the handlers of
+ * both netdevices representing interfaces and the dummy ones for the extra
+ * queues.
+ */
+static void quiesce_rx(struct adapter *adap)
+{
+       int i;
+       struct net_device *dev;
+
+       for_each_port(adap, i) {
+               dev = adap->port[i];
+               while (test_bit(__LINK_STATE_RX_SCHED, &dev->state))
+                       msleep(1);
+       }
+
+       for (i = 0; i < ARRAY_SIZE(adap->dummy_netdev); i++) {
+               dev = adap->dummy_netdev[i];
+               if (dev)
+                       while (test_bit(__LINK_STATE_RX_SCHED, &dev->state))
+                               msleep(1);
+       }
+}
+
+/**
+ *     setup_sge_qsets - configure SGE Tx/Rx/response queues
+ *     @adap: the adapter
+ *
+ *     Determines how many sets of SGE queues to use and initializes them.
+ *     We support multiple queue sets per port if we have MSI-X, otherwise
+ *     just one queue set per port.
+ */
+static int setup_sge_qsets(struct adapter *adap)
+{
+       int i, j, err, irq_idx = 0, qset_idx = 0, dummy_dev_idx = 0;
+       unsigned int ntxq = is_offload(adap) ? SGE_TXQ_PER_SET : 1;
+
+       if (adap->params.rev > 0 && !(adap->flags & USING_MSI))
+               irq_idx = -1;
+
+       for_each_port(adap, i) {
+               struct net_device *dev = adap->port[i];
+               const struct port_info *pi = netdev_priv(dev);
+
+               for (j = 0; j < pi->nqsets; ++j, ++qset_idx) {
+                       err = t3_sge_alloc_qset(adap, qset_idx, 1,
+                               (adap->flags & USING_MSIX) ? qset_idx + 1 :
+                                                            irq_idx,
+                               &adap->params.sge.qset[qset_idx], ntxq,
+                               j == 0 ? dev :
+                                        adap-> dummy_netdev[dummy_dev_idx++]);
+                       if (err) {
+                               t3_free_sge_resources(adap);
+                               return err;
+                       }
+               }
+       }
+
+       return 0;
+}
+
+static ssize_t attr_show(struct class_device *cd, char *buf,
+                        ssize_t(*format) (struct adapter *, char *))
+{
+       ssize_t len;
+       struct adapter *adap = to_net_dev(cd)->priv;
+
+       /* Synchronize with ioctls that may shut down the device */
+       rtnl_lock();
+       len = (*format) (adap, buf);
+       rtnl_unlock();
+       return len;
+}
+
+static ssize_t attr_store(struct class_device *cd, const char *buf, size_t len,
+                         ssize_t(*set) (struct adapter *, unsigned int),
+                         unsigned int min_val, unsigned int max_val)
+{
+       char *endp;
+       ssize_t ret;
+       unsigned int val;
+       struct adapter *adap = to_net_dev(cd)->priv;
+
+       if (!capable(CAP_NET_ADMIN))
+               return -EPERM;
+
+       val = simple_strtoul(buf, &endp, 0);
+       if (endp == buf || val < min_val || val > max_val)
+               return -EINVAL;
+
+       rtnl_lock();
+       ret = (*set) (adap, val);
+       if (!ret)
+               ret = len;
+       rtnl_unlock();
+       return ret;
+}
+
+#define CXGB3_SHOW(name, val_expr) \
+static ssize_t format_##name(struct adapter *adap, char *buf) \
+{ \
+       return sprintf(buf, "%u\n", val_expr); \
+} \
+static ssize_t show_##name(struct class_device *cd, char *buf) \
+{ \
+       return attr_show(cd, buf, format_##name); \
+}
+
+static ssize_t set_nfilters(struct adapter *adap, unsigned int val)
+{
+       if (adap->flags & FULL_INIT_DONE)
+               return -EBUSY;
+       if (val && adap->params.rev == 0)
+               return -EINVAL;
+       if (val > t3_mc5_size(&adap->mc5) - adap->params.mc5.nservers)
+               return -EINVAL;
+       adap->params.mc5.nfilters = val;
+       return 0;
+}
+
+static ssize_t store_nfilters(struct class_device *cd, const char *buf,
+                             size_t len)
+{
+       return attr_store(cd, buf, len, set_nfilters, 0, ~0);
+}
+
+static ssize_t set_nservers(struct adapter *adap, unsigned int val)
+{
+       if (adap->flags & FULL_INIT_DONE)
+               return -EBUSY;
+       if (val > t3_mc5_size(&adap->mc5) - adap->params.mc5.nfilters)
+               return -EINVAL;
+       adap->params.mc5.nservers = val;
+       return 0;
+}
+
+static ssize_t store_nservers(struct class_device *cd, const char *buf,
+                             size_t len)
+{
+       return attr_store(cd, buf, len, set_nservers, 0, ~0);
+}
+
+#define CXGB3_ATTR_R(name, val_expr) \
+CXGB3_SHOW(name, val_expr) \
+static CLASS_DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
+
+#define CXGB3_ATTR_RW(name, val_expr, store_method) \
+CXGB3_SHOW(name, val_expr) \
+static CLASS_DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show_##name, store_method)
+
+CXGB3_ATTR_R(cam_size, t3_mc5_size(&adap->mc5));
+CXGB3_ATTR_RW(nfilters, adap->params.mc5.nfilters, store_nfilters);
+CXGB3_ATTR_RW(nservers, adap->params.mc5.nservers, store_nservers);
+
+static struct attribute *cxgb3_attrs[] = {
+       &class_device_attr_cam_size.attr,
+       &class_device_attr_nfilters.attr,
+       &class_device_attr_nservers.attr,
+       NULL
+};
+
+static struct attribute_group cxgb3_attr_group = {.attrs = cxgb3_attrs };
+
+static ssize_t tm_attr_show(struct class_device *cd, char *buf, int sched)
+{
+       ssize_t len;
+       unsigned int v, addr, bpt, cpt;
+       struct adapter *adap = to_net_dev(cd)->priv;
+
+       addr = A_TP_TX_MOD_Q1_Q0_RATE_LIMIT - sched / 2;
+       rtnl_lock();
+       t3_write_reg(adap, A_TP_TM_PIO_ADDR, addr);
+       v = t3_read_reg(adap, A_TP_TM_PIO_DATA);
+       if (sched & 1)
+               v >>= 16;
+       bpt = (v >> 8) & 0xff;
+       cpt = v & 0xff;
+       if (!cpt)
+               len = sprintf(buf, "disabled\n");
+       else {
+               v = (adap->params.vpd.cclk * 1000) / cpt;
+               len = sprintf(buf, "%u Kbps\n", (v * bpt) / 125);
+       }
+       rtnl_unlock();
+       return len;
+}
+
+static ssize_t tm_attr_store(struct class_device *cd, const char *buf,
+                            size_t len, int sched)
+{
+       char *endp;
+       ssize_t ret;
+       unsigned int val;
+       struct adapter *adap = to_net_dev(cd)->priv;
+
+       if (!capable(CAP_NET_ADMIN))
+               return -EPERM;
+
+       val = simple_strtoul(buf, &endp, 0);
+       if (endp == buf || val > 10000000)
+               return -EINVAL;
+
+       rtnl_lock();
+       ret = t3_config_sched(adap, val, sched);
+       if (!ret)
+               ret = len;
+       rtnl_unlock();
+       return ret;
+}
+
+#define TM_ATTR(name, sched) \
+static ssize_t show_##name(struct class_device *cd, char *buf) \
+{ \
+       return tm_attr_show(cd, buf, sched); \
+} \
+static ssize_t store_##name(struct class_device *cd, const char *buf, size_t len) \
+{ \
+       return tm_attr_store(cd, buf, len, sched); \
+} \
+static CLASS_DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show_##name, store_##name)
+
+TM_ATTR(sched0, 0);
+TM_ATTR(sched1, 1);
+TM_ATTR(sched2, 2);
+TM_ATTR(sched3, 3);
+TM_ATTR(sched4, 4);
+TM_ATTR(sched5, 5);
+TM_ATTR(sched6, 6);
+TM_ATTR(sched7, 7);
+
+static struct attribute *offload_attrs[] = {
+       &class_device_attr_sched0.attr,
+       &class_device_attr_sched1.attr,
+       &class_device_attr_sched2.attr,
+       &class_device_attr_sched3.attr,
+       &class_device_attr_sched4.attr,
+       &class_device_attr_sched5.attr,
+       &class_device_attr_sched6.attr,
+       &class_device_attr_sched7.attr,
+       NULL
+};
+
+static struct attribute_group offload_attr_group = {.attrs = offload_attrs };
+
+/*
+ * Sends an sk_buff to an offload queue driver
+ * after dealing with any active network taps.
+ */
+static inline int offload_tx(struct t3cdev *tdev, struct sk_buff *skb)
+{
+       int ret;
+
+       local_bh_disable();
+       ret = t3_offload_tx(tdev, skb);
+       local_bh_enable();
+       return ret;
+}
+
+static int write_smt_entry(struct adapter *adapter, int idx)
+{
+       struct cpl_smt_write_req *req;
+       struct sk_buff *skb = alloc_skb(sizeof(*req), GFP_KERNEL);
+
+       if (!skb)
+               return -ENOMEM;
+
+       req = (struct cpl_smt_write_req *)__skb_put(skb, sizeof(*req));
+       req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
+       OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SMT_WRITE_REQ, idx));
+       req->mtu_idx = NMTUS - 1;       /* should be 0 but there's a T3 bug */
+       req->iff = idx;
+       memset(req->src_mac1, 0, sizeof(req->src_mac1));
+       memcpy(req->src_mac0, adapter->port[idx]->dev_addr, ETH_ALEN);
+       skb->priority = 1;
+       offload_tx(&adapter->tdev, skb);
+       return 0;
+}
+
+static int init_smt(struct adapter *adapter)
+{
+       int i;
+
+       for_each_port(adapter, i)
+           write_smt_entry(adapter, i);
+       return 0;
+}
+
+static void init_port_mtus(struct adapter *adapter)
+{
+       unsigned int mtus = adapter->port[0]->mtu;
+
+       if (adapter->port[1])
+               mtus |= adapter->port[1]->mtu << 16;
+       t3_write_reg(adapter, A_TP_MTU_PORT_TABLE, mtus);
+}
+
+static void send_pktsched_cmd(struct adapter *adap, int sched, int qidx, int lo,
+                             int hi, int port)
+{
+       struct sk_buff *skb;
+       struct mngt_pktsched_wr *req;
+
+       skb = alloc_skb(sizeof(*req), GFP_KERNEL | __GFP_NOFAIL);
+       req = (struct mngt_pktsched_wr *)skb_put(skb, sizeof(*req));
+       req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_MNGT));
+       req->mngt_opcode = FW_MNGTOPCODE_PKTSCHED_SET;
+       req->sched = sched;
+       req->idx = qidx;
+       req->min = lo;
+       req->max = hi;
+       req->binding = port;
+       t3_mgmt_tx(adap, skb);
+}
+
+static void bind_qsets(struct adapter *adap)
+{
+       int i, j;
+
+       for_each_port(adap, i) {
+               const struct port_info *pi = adap2pinfo(adap, i);
+
+               for (j = 0; j < pi->nqsets; ++j)
+                       send_pktsched_cmd(adap, 1, pi->first_qset + j, -1,
+                                         -1, i);
+       }
+}
+
+/**
+ *     cxgb_up - enable the adapter
+ *     @adapter: adapter being enabled
+ *
+ *     Called when the first port is enabled, this function performs the
+ *     actions necessary to make an adapter operational, such as completing
+ *     the initialization of HW modules, and enabling interrupts.
+ *
+ *     Must be called with the rtnl lock held.
+ */
+static int cxgb_up(struct adapter *adap)
+{
+       int err = 0;
+
+       if (!(adap->flags & FULL_INIT_DONE)) {
+               err = t3_check_fw_version(adap);
+               if (err)
+                       goto out;
+
+               err = init_dummy_netdevs(adap);
+               if (err)
+                       goto out;
+
+               err = t3_init_hw(adap, 0);
+               if (err)
+                       goto out;
+
+               err = setup_sge_qsets(adap);
+               if (err)
+                       goto out;
+
+               setup_rss(adap);
+               adap->flags |= FULL_INIT_DONE;
+       }
+
+       t3_intr_clear(adap);
+
+       if (adap->flags & USING_MSIX) {
+               name_msix_vecs(adap);
+               err = request_irq(adap->msix_info[0].vec,
+                                 t3_async_intr_handler, 0,
+                                 adap->msix_info[0].desc, adap);
+               if (err)
+                       goto irq_err;
+
+               if (request_msix_data_irqs(adap)) {
+                       free_irq(adap->msix_info[0].vec, adap);
+                       goto irq_err;
+               }
+       } else if ((err = request_irq(adap->pdev->irq,
+                                     t3_intr_handler(adap,
+                                                     adap->sge.qs[0].rspq.
+                                                     polling),
+                                     (adap->flags & USING_MSI) ? 0 : SA_SHIRQ,
+                                     adap->name, adap)))
+               goto irq_err;
+
+       t3_sge_start(adap);
+       t3_intr_enable(adap);
+
+       if ((adap->flags & (USING_MSIX | QUEUES_BOUND)) == USING_MSIX)
+               bind_qsets(adap);
+       adap->flags |= QUEUES_BOUND;
+
+out:
+       return err;
+irq_err:
+       CH_ERR(adap, "request_irq failed, err %d\n", err);
+       goto out;
+}
+
+/*
+ * Release resources when all the ports and offloading have been stopped.
+ */
+static void cxgb_down(struct adapter *adapter)
+{
+       t3_sge_stop(adapter);
+       spin_lock_irq(&adapter->work_lock);     /* sync with PHY intr task */
+       t3_intr_disable(adapter);
+       spin_unlock_irq(&adapter->work_lock);
+
+       if (adapter->flags & USING_MSIX) {
+               int i, n = 0;
+
+               free_irq(adapter->msix_info[0].vec, adapter);
+               for_each_port(adapter, i)
+                   n += adap2pinfo(adapter, i)->nqsets;
+
+               for (i = 0; i < n; ++i)
+                       free_irq(adapter->msix_info[i + 1].vec,
+                                &adapter->sge.qs[i]);
+       } else
+               free_irq(adapter->pdev->irq, adapter);
+
+       flush_workqueue(cxgb3_wq);      /* wait for external IRQ handler */
+       quiesce_rx(adapter);
+}
+
+static void schedule_chk_task(struct adapter *adap)
+{
+       unsigned int timeo;
+
+       timeo = adap->params.linkpoll_period ?
+           (HZ * adap->params.linkpoll_period) / 10 :
+           adap->params.stats_update_period * HZ;
+       if (timeo)
+               queue_delayed_work(cxgb3_wq, &adap->adap_check_task, timeo);
+}
+
+static int offload_open(struct net_device *dev)
+{
+       struct adapter *adapter = dev->priv;
+       struct t3cdev *tdev = T3CDEV(dev);
+       int adap_up = adapter->open_device_map & PORT_MASK;
+       int err = 0;
+
+       if (test_and_set_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map))
+               return 0;
+
+       if (!adap_up && (err = cxgb_up(adapter)) < 0)
+               return err;
+
+       t3_tp_set_offload_mode(adapter, 1);
+       tdev->lldev = adapter->port[0];
+       err = cxgb3_offload_activate(adapter);
+       if (err)
+               goto out;
+
+       init_port_mtus(adapter);
+       t3_load_mtus(adapter, adapter->params.mtus, adapter->params.a_wnd,
+                    adapter->params.b_wnd,
+                    adapter->params.rev == 0 ?
+                    adapter->port[0]->mtu : 0xffff);
+       init_smt(adapter);
+
+       /* Never mind if the next step fails */
+       sysfs_create_group(&tdev->lldev->class_dev.kobj, &offload_attr_group);
+
+       /* Call back all registered clients */
+       cxgb3_add_clients(tdev);
+
+out:
+       /* restore them in case the offload module has changed them */
+       if (err) {
+               t3_tp_set_offload_mode(adapter, 0);
+               clear_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map);
+               cxgb3_set_dummy_ops(tdev);
+       }
+       return err;
+}
+
+static int offload_close(struct t3cdev *tdev)
+{
+       struct adapter *adapter = tdev2adap(tdev);
+
+       if (!test_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map))
+               return 0;
+
+       /* Call back all registered clients */
+       cxgb3_remove_clients(tdev);
+
+       sysfs_remove_group(&tdev->lldev->class_dev.kobj, &offload_attr_group);
+
+       tdev->lldev = NULL;
+       cxgb3_set_dummy_ops(tdev);
+       t3_tp_set_offload_mode(adapter, 0);
+       clear_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map);
+
+       if (!adapter->open_device_map)
+               cxgb_down(adapter);
+
+       cxgb3_offload_deactivate(adapter);
+       return 0;
+}
+
+static int cxgb_open(struct net_device *dev)
+{
+       int err;
+       struct adapter *adapter = dev->priv;
+       struct port_info *pi = netdev_priv(dev);
+       int other_ports = adapter->open_device_map & PORT_MASK;
+
+       if (!adapter->open_device_map && (err = cxgb_up(adapter)) < 0)
+               return err;
+
+       set_bit(pi->port_id, &adapter->open_device_map);
+       if (!ofld_disable) {
+               err = offload_open(dev);
+               if (err)
+                       printk(KERN_WARNING
+                              "Could not initialize offload capabilities\n");
+       }
+
+       link_start(dev);
+       t3_port_intr_enable(adapter, pi->port_id);
+       netif_start_queue(dev);
+       if (!other_ports)
+               schedule_chk_task(adapter);
+
+       return 0;
+}
+
+static int cxgb_close(struct net_device *dev)
+{
+       struct adapter *adapter = dev->priv;
+       struct port_info *p = netdev_priv(dev);
+
+       t3_port_intr_disable(adapter, p->port_id);
+       netif_stop_queue(dev);
+       p->phy.ops->power_down(&p->phy, 1);
+       netif_carrier_off(dev);
+       t3_mac_disable(&p->mac, MAC_DIRECTION_TX | MAC_DIRECTION_RX);
+
+       spin_lock(&adapter->work_lock); /* sync with update task */
+       clear_bit(p->port_id, &adapter->open_device_map);
+       spin_unlock(&adapter->work_lock);
+
+       if (!(adapter->open_device_map & PORT_MASK))
+               cancel_rearming_delayed_workqueue(cxgb3_wq,
+                                                 &adapter->adap_check_task);
+
+       if (!adapter->open_device_map)
+               cxgb_down(adapter);
+
+       return 0;
+}
+
+static struct net_device_stats *cxgb_get_stats(struct net_device *dev)
+{
+       struct adapter *adapter = dev->priv;
+       struct port_info *p = netdev_priv(dev);
+       struct net_device_stats *ns = &p->netstats;
+       const struct mac_stats *pstats;
+
+       spin_lock(&adapter->stats_lock);
+       pstats = t3_mac_update_stats(&p->mac);
+       spin_unlock(&adapter->stats_lock);
+
+       ns->tx_bytes = pstats->tx_octets;
+       ns->tx_packets = pstats->tx_frames;
+       ns->rx_bytes = pstats->rx_octets;
+       ns->rx_packets = pstats->rx_frames;
+       ns->multicast = pstats->rx_mcast_frames;
+
+       ns->tx_errors = pstats->tx_underrun;
+       ns->rx_errors = pstats->rx_symbol_errs + pstats->rx_fcs_errs +
+           pstats->rx_too_long + pstats->rx_jabber + pstats->rx_short +
+           pstats->rx_fifo_ovfl;
+
+       /* detailed rx_errors */
+       ns->rx_length_errors = pstats->rx_jabber + pstats->rx_too_long;
+       ns->rx_over_errors = 0;
+       ns->rx_crc_errors = pstats->rx_fcs_errs;
+       ns->rx_frame_errors = pstats->rx_symbol_errs;
+       ns->rx_fifo_errors = pstats->rx_fifo_ovfl;
+       ns->rx_missed_errors = pstats->rx_cong_drops;
+
+       /* detailed tx_errors */
+       ns->tx_aborted_errors = 0;
+       ns->tx_carrier_errors = 0;
+       ns->tx_fifo_errors = pstats->tx_underrun;
+       ns->tx_heartbeat_errors = 0;
+       ns->tx_window_errors = 0;
+       return ns;
+}
+
+static u32 get_msglevel(struct net_device *dev)
+{
+       struct adapter *adapter = dev->priv;
+
+       return adapter->msg_enable;
+}
+
+static void set_msglevel(struct net_device *dev, u32 val)
+{
+       struct adapter *adapter = dev->priv;
+
+       adapter->msg_enable = val;
+}
+
+static char stats_strings[][ETH_GSTRING_LEN] = {
+       "TxOctetsOK         ",
+       "TxFramesOK         ",
+       "TxMulticastFramesOK",
+       "TxBroadcastFramesOK",
+       "TxPauseFrames      ",
+       "TxUnderrun         ",
+       "TxExtUnderrun      ",
+
+       "TxFrames64         ",
+       "TxFrames65To127    ",
+       "TxFrames128To255   ",
+       "TxFrames256To511   ",
+       "TxFrames512To1023  ",
+       "TxFrames1024To1518 ",
+       "TxFrames1519ToMax  ",
+
+       "RxOctetsOK         ",
+       "RxFramesOK         ",
+       "RxMulticastFramesOK",
+       "RxBroadcastFramesOK",
+       "RxPauseFrames      ",
+       "RxFCSErrors        ",
+       "RxSymbolErrors     ",
+       "RxShortErrors      ",
+       "RxJabberErrors     ",
+       "RxLengthErrors     ",
+       "RxFIFOoverflow     ",
+
+       "RxFrames64         ",
+       "RxFrames65To127    ",
+       "RxFrames128To255   ",
+       "RxFrames256To511   ",
+       "RxFrames512To1023  ",
+       "RxFrames1024To1518 ",
+       "RxFrames1519ToMax  ",
+
+       "PhyFIFOErrors      ",
+       "TSO                ",
+       "VLANextractions    ",
+       "VLANinsertions     ",
+       "TxCsumOffload      ",
+       "RxCsumGood         ",
+       "RxDrops            "
+};
+
+static int get_stats_count(struct net_device *dev)
+{
+       return ARRAY_SIZE(stats_strings);
+}
+
+#define T3_REGMAP_SIZE (3 * 1024)
+
+static int get_regs_len(struct net_device *dev)
+{
+       return T3_REGMAP_SIZE;
+}
+
+static int get_eeprom_len(struct net_device *dev)
+{
+       return EEPROMSIZE;
+}
+
+static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
+{
+       u32 fw_vers = 0;
+       struct adapter *adapter = dev->priv;
+
+       t3_get_fw_version(adapter, &fw_vers);
+
+       strcpy(info->driver, DRV_NAME);
+       strcpy(info->version, DRV_VERSION);
+       strcpy(info->bus_info, pci_name(adapter->pdev));
+       if (!fw_vers)
+               strcpy(info->fw_version, "N/A");
+       else {
+               snprintf(info->fw_version, sizeof(info->fw_version),
+                        "%s %u.%u.%u",
+                        G_FW_VERSION_TYPE(fw_vers) ? "T" : "N",
+                        G_FW_VERSION_MAJOR(fw_vers),
+                        G_FW_VERSION_MINOR(fw_vers),
+                        G_FW_VERSION_MICRO(fw_vers));
+       }
+}
+
+static void get_strings(struct net_device *dev, u32 stringset, u8 * data)
+{
+       if (stringset == ETH_SS_STATS)
+               memcpy(data, stats_strings, sizeof(stats_strings));
+}
+
+static unsigned long collect_sge_port_stats(struct adapter *adapter,
+                                           struct port_info *p, int idx)
+{
+       int i;
+       unsigned long tot = 0;
+
+       for (i = 0; i < p->nqsets; ++i)
+               tot += adapter->sge.qs[i + p->first_qset].port_stats[idx];
+       return tot;
+}
+
+static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
+                     u64 *data)
+{
+       struct adapter *adapter = dev->priv;
+       struct port_info *pi = netdev_priv(dev);
+       const struct mac_stats *s;
+
+       spin_lock(&adapter->stats_lock);
+       s = t3_mac_update_stats(&pi->mac);
+       spin_unlock(&adapter->stats_lock);
+
+       *data++ = s->tx_octets;
+       *data++ = s->tx_frames;
+       *data++ = s->tx_mcast_frames;
+       *data++ = s->tx_bcast_frames;
+       *data++ = s->tx_pause;
+       *data++ = s->tx_underrun;
+       *data++ = s->tx_fifo_urun;
+
+       *data++ = s->tx_frames_64;
+       *data++ = s->tx_frames_65_127;
+       *data++ = s->tx_frames_128_255;
+       *data++ = s->tx_frames_256_511;
+       *data++ = s->tx_frames_512_1023;
+       *data++ = s->tx_frames_1024_1518;
+       *data++ = s->tx_frames_1519_max;
+
+       *data++ = s->rx_octets;
+       *data++ = s->rx_frames;
+       *data++ = s->rx_mcast_frames;
+       *data++ = s->rx_bcast_frames;
+       *data++ = s->rx_pause;
+       *data++ = s->rx_fcs_errs;
+       *data++ = s->rx_symbol_errs;
+       *data++ = s->rx_short;
+       *data++ = s->rx_jabber;
+       *data++ = s->rx_too_long;
+       *data++ = s->rx_fifo_ovfl;
+
+       *data++ = s->rx_frames_64;
+       *data++ = s->rx_frames_65_127;
+       *data++ = s->rx_frames_128_255;
+       *data++ = s->rx_frames_256_511;
+       *data++ = s->rx_frames_512_1023;
+       *data++ = s->rx_frames_1024_1518;
+       *data++ = s->rx_frames_1519_max;
+
+       *data++ = pi->phy.fifo_errors;
+
+       *data++ = collect_sge_port_stats(adapter, pi, SGE_PSTAT_TSO);
+       *data++ = collect_sge_port_stats(adapter, pi, SGE_PSTAT_VLANEX);
+       *data++ = collect_sge_port_stats(adapter, pi, SGE_PSTAT_VLANINS);
+       *data++ = collect_sge_port_stats(adapter, pi, SGE_PSTAT_TX_CSUM);
+       *data++ = collect_sge_port_stats(adapter, pi, SGE_PSTAT_RX_CSUM_GOOD);
+       *data++ = s->rx_cong_drops;
+}
+
+static inline void reg_block_dump(struct adapter *ap, void *buf,
+                                 unsigned int start, unsigned int end)
+{
+       u32 *p = buf + start;
+
+       for (; start <= end; start += sizeof(u32))
+               *p++ = t3_read_reg(ap, start);
+}
+
+static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
+                    void *buf)
+{
+       struct adapter *ap = dev->priv;
+
+       /*
+        * Version scheme:
+        * bits 0..9: chip version
+        * bits 10..15: chip revision
+        * bit 31: set for PCIe cards
+        */
+       regs->version = 3 | (ap->params.rev << 10) | (is_pcie(ap) << 31);
+
+       /*
+        * We skip the MAC statistics registers because they are clear-on-read.
+        * Also reading multi-register stats would need to synchronize with the
+        * periodic mac stats accumulation.  Hard to justify the complexity.
+        */
+       memset(buf, 0, T3_REGMAP_SIZE);
+       reg_block_dump(ap, buf, 0, A_SG_RSPQ_CREDIT_RETURN);
+       reg_block_dump(ap, buf, A_SG_HI_DRB_HI_THRSH, A_ULPRX_PBL_ULIMIT);
+       reg_block_dump(ap, buf, A_ULPTX_CONFIG, A_MPS_INT_CAUSE);
+       reg_block_dump(ap, buf, A_CPL_SWITCH_CNTRL, A_CPL_MAP_TBL_DATA);
+       reg_block_dump(ap, buf, A_SMB_GLOBAL_TIME_CFG, A_XGM_SERDES_STAT3);
+       reg_block_dump(ap, buf, A_XGM_SERDES_STATUS0,
+                      XGM_REG(A_XGM_SERDES_STAT3, 1));
+       reg_block_dump(ap, buf, XGM_REG(A_XGM_SERDES_STATUS0, 1),
+                      XGM_REG(A_XGM_RX_SPI4_SOP_EOP_CNT, 1));
+}
+
+static int restart_autoneg(struct net_device *dev)
+{
+       struct port_info *p = netdev_priv(dev);
+
+       if (!netif_running(dev))
+               return -EAGAIN;
+       if (p->link_config.autoneg != AUTONEG_ENABLE)
+               return -EINVAL;
+       p->phy.ops->autoneg_restart(&p->phy);
+       return 0;
+}
+
+static int cxgb3_phys_id(struct net_device *dev, u32 data)
+{
+       int i;
+       struct adapter *adapter = dev->priv;
+
+       if (data == 0)
+               data = 2;
+
+       for (i = 0; i < data * 2; i++) {
+               t3_set_reg_field(adapter, A_T3DBG_GPIO_EN, F_GPIO0_OUT_VAL,
+                                (i & 1) ? F_GPIO0_OUT_VAL : 0);
+               if (msleep_interruptible(500))
+                       break;
+       }
+       t3_set_reg_field(adapter, A_T3DBG_GPIO_EN, F_GPIO0_OUT_VAL,
+                        F_GPIO0_OUT_VAL);
+       return 0;
+}
+
+static int get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+       struct port_info *p = netdev_priv(dev);
+
+       cmd->supported = p->link_config.supported;
+       cmd->advertising = p->link_config.advertising;
+
+       if (netif_carrier_ok(dev)) {
+               cmd->speed = p->link_config.speed;
+               cmd->duplex = p->link_config.duplex;
+       } else {
+               cmd->speed = -1;
+               cmd->duplex = -1;
+       }
+
+       cmd->port = (cmd->supported & SUPPORTED_TP) ? PORT_TP : PORT_FIBRE;
+       cmd->phy_address = p->phy.addr;
+       cmd->transceiver = XCVR_EXTERNAL;
+       cmd->autoneg = p->link_config.autoneg;
+       cmd->maxtxpkt = 0;
+       cmd->maxrxpkt = 0;
+       return 0;
+}
+
+static int speed_duplex_to_caps(int speed, int duplex)
+{
+       int cap = 0;
+
+       switch (speed) {
+       case SPEED_10:
+               if (duplex == DUPLEX_FULL)
+                       cap = SUPPORTED_10baseT_Full;
+               else
+                       cap = SUPPORTED_10baseT_Half;
+               break;
+       case SPEED_100:
+               if (duplex == DUPLEX_FULL)
+                       cap = SUPPORTED_100baseT_Full;
+               else
+                       cap = SUPPORTED_100baseT_Half;
+               break;
+       case SPEED_1000:
+               if (duplex == DUPLEX_FULL)
+                       cap = SUPPORTED_1000baseT_Full;
+               else
+                       cap = SUPPORTED_1000baseT_Half;
+               break;
+       case SPEED_10000:
+               if (duplex == DUPLEX_FULL)
+                       cap = SUPPORTED_10000baseT_Full;
+       }
+       return cap;
+}
+
+#define ADVERTISED_MASK (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
+                     ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
+                     ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full | \
+                     ADVERTISED_10000baseT_Full)
+
+static int set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+       struct port_info *p = netdev_priv(dev);
+       struct link_config *lc = &p->link_config;
+
+       if (!(lc->supported & SUPPORTED_Autoneg))
+               return -EOPNOTSUPP;     /* can't change speed/duplex */
+
+       if (cmd->autoneg == AUTONEG_DISABLE) {
+               int cap = speed_duplex_to_caps(cmd->speed, cmd->duplex);
+
+               if (!(lc->supported & cap) || cmd->speed == SPEED_1000)
+                       return -EINVAL;
+               lc->requested_speed = cmd->speed;
+               lc->requested_duplex = cmd->duplex;
+               lc->advertising = 0;
+       } else {
+               cmd->advertising &= ADVERTISED_MASK;
+               cmd->advertising &= lc->supported;
+               if (!cmd->advertising)
+                       return -EINVAL;
+               lc->requested_speed = SPEED_INVALID;
+               lc->requested_duplex = DUPLEX_INVALID;
+               lc->advertising = cmd->advertising | ADVERTISED_Autoneg;
+       }
+       lc->autoneg = cmd->autoneg;
+       if (netif_running(dev))
+               t3_link_start(&p->phy, &p->mac, lc);
+       return 0;
+}
+
+static void get_pauseparam(struct net_device *dev,
+                          struct ethtool_pauseparam *epause)
+{
+       struct port_info *p = netdev_priv(dev);
+
+       epause->autoneg = (p->link_config.requested_fc & PAUSE_AUTONEG) != 0;
+       epause->rx_pause = (p->link_config.fc & PAUSE_RX) != 0;
+       epause->tx_pause = (p->link_config.fc & PAUSE_TX) != 0;
+}
+
+static int set_pauseparam(struct net_device *dev,
+                         struct ethtool_pauseparam *epause)
+{
+       struct port_info *p = netdev_priv(dev);
+       struct link_config *lc = &p->link_config;
+
+       if (epause->autoneg == AUTONEG_DISABLE)
+               lc->requested_fc = 0;
+       else if (lc->supported & SUPPORTED_Autoneg)
+               lc->requested_fc = PAUSE_AUTONEG;
+       else
+               return -EINVAL;
+
+       if (epause->rx_pause)
+               lc->requested_fc |= PAUSE_RX;
+       if (epause->tx_pause)
+               lc->requested_fc |= PAUSE_TX;
+       if (lc->autoneg == AUTONEG_ENABLE) {
+               if (netif_running(dev))
+                       t3_link_start(&p->phy, &p->mac, lc);
+       } else {
+               lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
+               if (netif_running(dev))
+                       t3_mac_set_speed_duplex_fc(&p->mac, -1, -1, lc->fc);
+       }
+       return 0;
+}
+
+static u32 get_rx_csum(struct net_device *dev)
+{
+       struct port_info *p = netdev_priv(dev);
+
+       return p->rx_csum_offload;
+}
+
+static int set_rx_csum(struct net_device *dev, u32 data)
+{
+       struct port_info *p = netdev_priv(dev);
+
+       p->rx_csum_offload = data;
+       return 0;
+}
+
+static void get_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
+{
+       struct adapter *adapter = dev->priv;
+
+       e->rx_max_pending = MAX_RX_BUFFERS;
+       e->rx_mini_max_pending = 0;
+       e->rx_jumbo_max_pending = MAX_RX_JUMBO_BUFFERS;
+       e->tx_max_pending = MAX_TXQ_ENTRIES;
+
+       e->rx_pending = adapter->params.sge.qset[0].fl_size;
+       e->rx_mini_pending = adapter->params.sge.qset[0].rspq_size;
+       e->rx_jumbo_pending = adapter->params.sge.qset[0].jumbo_size;
+       e->tx_pending = adapter->params.sge.qset[0].txq_size[0];
+}
+
+static int set_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
+{
+       int i;
+       struct adapter *adapter = dev->priv;
+
+       if (e->rx_pending > MAX_RX_BUFFERS ||
+           e->rx_jumbo_pending > MAX_RX_JUMBO_BUFFERS ||
+           e->tx_pending > MAX_TXQ_ENTRIES ||
+           e->rx_mini_pending > MAX_RSPQ_ENTRIES ||
+           e->rx_mini_pending < MIN_RSPQ_ENTRIES ||
+           e->rx_pending < MIN_FL_ENTRIES ||
+           e->rx_jumbo_pending < MIN_FL_ENTRIES ||
+           e->tx_pending < adapter->params.nports * MIN_TXQ_ENTRIES)
+               return -EINVAL;
+
+       if (adapter->flags & FULL_INIT_DONE)
+               return -EBUSY;
+
+       for (i = 0; i < SGE_QSETS; ++i) {
+               struct qset_params *q = &adapter->params.sge.qset[i];
+
+               q->rspq_size = e->rx_mini_pending;
+               q->fl_size = e->rx_pending;
+               q->jumbo_size = e->rx_jumbo_pending;
+               q->txq_size[0] = e->tx_pending;
+               q->txq_size[1] = e->tx_pending;
+               q->txq_size[2] = e->tx_pending;
+       }
+       return 0;
+}
+
+static int set_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
+{
+       struct adapter *adapter = dev->priv;
+       struct qset_params *qsp = &adapter->params.sge.qset[0];
+       struct sge_qset *qs = &adapter->sge.qs[0];
+
+       if (c->rx_coalesce_usecs * 10 > M_NEWTIMER)
+               return -EINVAL;
+
+       qsp->coalesce_usecs = c->rx_coalesce_usecs;
+       t3_update_qset_coalesce(qs, qsp);
+       return 0;
+}
+
+static int get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
+{
+       struct adapter *adapter = dev->priv;
+       struct qset_params *q = adapter->params.sge.qset;
+
+       c->rx_coalesce_usecs = q->coalesce_usecs;
+       return 0;
+}
+
+static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *e,
+                     u8 * data)
+{
+       int i, err = 0;
+       struct adapter *adapter = dev->priv;
+
+       u8 *buf = kmalloc(EEPROMSIZE, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       e->magic = EEPROM_MAGIC;
+       for (i = e->offset & ~3; !err && i < e->offset + e->len; i += 4)
+               err = t3_seeprom_read(adapter, i, (u32 *) & buf[i]);
+
+       if (!err)
+               memcpy(data, buf + e->offset, e->len);
+       kfree(buf);
+       return err;
+}
+
+static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
+                     u8 * data)
+{
+       u8 *buf;
+       int err = 0;
+       u32 aligned_offset, aligned_len, *p;
+       struct adapter *adapter = dev->priv;
+
+       if (eeprom->magic != EEPROM_MAGIC)
+               return -EINVAL;
+
+       aligned_offset = eeprom->offset & ~3;
+       aligned_len = (eeprom->len + (eeprom->offset & 3) + 3) & ~3;
+
+       if (aligned_offset != eeprom->offset || aligned_len != eeprom->len) {
+               buf = kmalloc(aligned_len, GFP_KERNEL);
+               if (!buf)
+                       return -ENOMEM;
+               err = t3_seeprom_read(adapter, aligned_offset, (u32 *) buf);
+               if (!err && aligned_len > 4)
+                       err = t3_seeprom_read(adapter,
+                                             aligned_offset + aligned_len - 4,
+                                             (u32 *) & buf[aligned_len - 4]);
+               if (err)
+                       goto out;
+               memcpy(buf + (eeprom->offset & 3), data, eeprom->len);
+       } else
+               buf = data;
+
+       err = t3_seeprom_wp(adapter, 0);
+       if (err)
+               goto out;
+
+       for (p = (u32 *) buf; !err && aligned_len; aligned_len -= 4, p++) {
+               err = t3_seeprom_write(adapter, aligned_offset, *p);
+               aligned_offset += 4;
+       }
+
+       if (!err)
+               err = t3_seeprom_wp(adapter, 1);
+out:
+       if (buf != data)
+               kfree(buf);
+       return err;
+}
+
+static void get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+       wol->supported = 0;
+       wol->wolopts = 0;
+       memset(&wol->sopass, 0, sizeof(wol->sopass));
+}
+
+static const struct ethtool_ops cxgb_ethtool_ops = {
+       .get_settings = get_settings,
+       .set_settings = set_settings,
+       .get_drvinfo = get_drvinfo,
+       .get_msglevel = get_msglevel,
+       .set_msglevel = set_msglevel,
+       .get_ringparam = get_sge_param,
+       .set_ringparam = set_sge_param,
+       .get_coalesce = get_coalesce,
+       .set_coalesce = set_coalesce,
+       .get_eeprom_len = get_eeprom_len,
+       .get_eeprom = get_eeprom,
+       .set_eeprom = set_eeprom,
+       .get_pauseparam = get_pauseparam,
+       .set_pauseparam = set_pauseparam,
+       .get_rx_csum = get_rx_csum,
+       .set_rx_csum = set_rx_csum,
+       .get_tx_csum = ethtool_op_get_tx_csum,
+       .set_tx_csum = ethtool_op_set_tx_csum,
+       .get_sg = ethtool_op_get_sg,
+       .set_sg = ethtool_op_set_sg,
+       .get_link = ethtool_op_get_link,
+       .get_strings = get_strings,
+       .phys_id = cxgb3_phys_id,
+       .nway_reset = restart_autoneg,
+       .get_stats_count = get_stats_count,
+       .get_ethtool_stats = get_stats,
+       .get_regs_len = get_regs_len,
+       .get_regs = get_regs,
+       .get_wol = get_wol,
+       .get_tso = ethtool_op_get_tso,
+       .set_tso = ethtool_op_set_tso,
+       .get_perm_addr = ethtool_op_get_perm_addr
+};
+
+static int in_range(int val, int lo, int hi)
+{
+       return val < 0 || (val <= hi && val >= lo);
+}
+
+static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr)
+{
+       int ret;
+       u32 cmd;
+       struct adapter *adapter = dev->priv;
+
+       if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
+               return -EFAULT;
+
+       switch (cmd) {
+       case CHELSIO_SETREG:{
+               struct ch_reg edata;
+
+               if (!capable(CAP_NET_ADMIN))
+                       return -EPERM;
+               if (copy_from_user(&edata, useraddr, sizeof(edata)))
+                       return -EFAULT;
+               if ((edata.addr & 3) != 0
+                       || edata.addr >= adapter->mmio_len)
+                       return -EINVAL;
+               writel(edata.val, adapter->regs + edata.addr);
+               break;
+       }
+       case CHELSIO_GETREG:{
+               struct ch_reg edata;
+
+               if (copy_from_user(&edata, useraddr, sizeof(edata)))
+                       return -EFAULT;
+               if ((edata.addr & 3) != 0
+                       || edata.addr >= adapter->mmio_len)
+                       return -EINVAL;
+               edata.val = readl(adapter->regs + edata.addr);
+               if (copy_to_user(useraddr, &edata, sizeof(edata)))
+                       return -EFAULT;
+               break;
+       }
+       case CHELSIO_SET_QSET_PARAMS:{
+               int i;
+               struct qset_params *q;
+               struct ch_qset_params t;
+
+               if (!capable(CAP_NET_ADMIN))
+                       return -EPERM;
+               if (copy_from_user(&t, useraddr, sizeof(t)))
+                       return -EFAULT;
+               if (t.qset_idx >= SGE_QSETS)
+                       return -EINVAL;
+               if (!in_range(t.intr_lat, 0, M_NEWTIMER) ||
+                       !in_range(t.cong_thres, 0, 255) ||
+                       !in_range(t.txq_size[0], MIN_TXQ_ENTRIES,
+                               MAX_TXQ_ENTRIES) ||
+                       !in_range(t.txq_size[1], MIN_TXQ_ENTRIES,
+                               MAX_TXQ_ENTRIES) ||
+                       !in_range(t.txq_size[2], MIN_CTRL_TXQ_ENTRIES,
+                               MAX_CTRL_TXQ_ENTRIES) ||
+                       !in_range(t.fl_size[0], MIN_FL_ENTRIES,
+                               MAX_RX_BUFFERS)
+                       || !in_range(t.fl_size[1], MIN_FL_ENTRIES,
+                                       MAX_RX_JUMBO_BUFFERS)
+                       || !in_range(t.rspq_size, MIN_RSPQ_ENTRIES,
+                                       MAX_RSPQ_ENTRIES))
+                       return -EINVAL;
+               if ((adapter->flags & FULL_INIT_DONE) &&
+                       (t.rspq_size >= 0 || t.fl_size[0] >= 0 ||
+                       t.fl_size[1] >= 0 || t.txq_size[0] >= 0 ||
+                       t.txq_size[1] >= 0 || t.txq_size[2] >= 0 ||
+                       t.polling >= 0 || t.cong_thres >= 0))
+                       return -EBUSY;
+
+               q = &adapter->params.sge.qset[t.qset_idx];
+
+               if (t.rspq_size >= 0)
+                       q->rspq_size = t.rspq_size;
+               if (t.fl_size[0] >= 0)
+                       q->fl_size = t.fl_size[0];
+               if (t.fl_size[1] >= 0)
+                       q->jumbo_size = t.fl_size[1];
+               if (t.txq_size[0] >= 0)
+                       q->txq_size[0] = t.txq_size[0];
+               if (t.txq_size[1] >= 0)
+                       q->txq_size[1] = t.txq_size[1];
+               if (t.txq_size[2] >= 0)
+                       q->txq_size[2] = t.txq_size[2];
+               if (t.cong_thres >= 0)
+                       q->cong_thres = t.cong_thres;
+               if (t.intr_lat >= 0) {
+                       struct sge_qset *qs =
+                               &adapter->sge.qs[t.qset_idx];
+
+                       q->coalesce_usecs = t.intr_lat;
+                       t3_update_qset_coalesce(qs, q);
+               }
+               if (t.polling >= 0) {
+                       if (adapter->flags & USING_MSIX)
+                               q->polling = t.polling;
+                       else {
+                               /* No polling with INTx for T3A */
+                               if (adapter->params.rev == 0 &&
+                                       !(adapter->flags & USING_MSI))
+                                       t.polling = 0;
+
+                               for (i = 0; i < SGE_QSETS; i++) {
+                                       q = &adapter->params.sge.
+                                               qset[i];
+                                       q->polling = t.polling;
+                               }
+                       }
+               }
+               break;
+       }
+       case CHELSIO_GET_QSET_PARAMS:{
+               struct qset_params *q;
+               struct ch_qset_params t;
+
+               if (copy_from_user(&t, useraddr, sizeof(t)))
+                       return -EFAULT;
+               if (t.qset_idx >= SGE_QSETS)
+                       return -EINVAL;
+
+               q = &adapter->params.sge.qset[t.qset_idx];
+               t.rspq_size = q->rspq_size;
+               t.txq_size[0] = q->txq_size[0];
+               t.txq_size[1] = q->txq_size[1];
+               t.txq_size[2] = q->txq_size[2];
+               t.fl_size[0] = q->fl_size;
+               t.fl_size[1] = q->jumbo_size;
+               t.polling = q->polling;
+               t.intr_lat = q->coalesce_usecs;
+               t.cong_thres = q->cong_thres;
+
+               if (copy_to_user(useraddr, &t, sizeof(t)))
+                       return -EFAULT;
+               break;
+       }
+       case CHELSIO_SET_QSET_NUM:{
+               struct ch_reg edata;
+               struct port_info *pi = netdev_priv(dev);
+               unsigned int i, first_qset = 0, other_qsets = 0;
+
+               if (!capable(CAP_NET_ADMIN))
+                       return -EPERM;
+               if (adapter->flags & FULL_INIT_DONE)
+                       return -EBUSY;
+               if (copy_from_user(&edata, useraddr, sizeof(edata)))
+                       return -EFAULT;
+               if (edata.val < 1 ||
+                       (edata.val > 1 && !(adapter->flags & USING_MSIX)))
+                       return -EINVAL;
+
+               for_each_port(adapter, i)
+                       if (adapter->port[i] && adapter->port[i] != dev)
+                               other_qsets += adap2pinfo(adapter, i)->nqsets;
+
+               if (edata.val + other_qsets > SGE_QSETS)
+                       return -EINVAL;
+
+               pi->nqsets = edata.val;
+
+               for_each_port(adapter, i)
+                       if (adapter->port[i]) {
+                               pi = adap2pinfo(adapter, i);
+                               pi->first_qset = first_qset;
+                               first_qset += pi->nqsets;
+                       }
+               break;
+       }
+       case CHELSIO_GET_QSET_NUM:{
+               struct ch_reg edata;
+               struct port_info *pi = netdev_priv(dev);
+
+               edata.cmd = CHELSIO_GET_QSET_NUM;
+               edata.val = pi->nqsets;
+               if (copy_to_user(useraddr, &edata, sizeof(edata)))
+                       return -EFAULT;
+               break;
+       }
+       case CHELSIO_LOAD_FW:{
+               u8 *fw_data;
+               struct ch_mem_range t;
+
+               if (!capable(CAP_NET_ADMIN))
+                       return -EPERM;
+               if (copy_from_user(&t, useraddr, sizeof(t)))
+                       return -EFAULT;
+
+               fw_data = kmalloc(t.len, GFP_KERNEL);
+               if (!fw_data)
+                       return -ENOMEM;
+
+               if (copy_from_user
+                       (fw_data, useraddr + sizeof(t), t.len)) {
+                       kfree(fw_data);
+                       return -EFAULT;
+               }
+
+               ret = t3_load_fw(adapter, fw_data, t.len);
+               kfree(fw_data);
+               if (ret)
+                       return ret;
+               break;
+       }
+       case CHELSIO_SETMTUTAB:{
+               struct ch_mtus m;
+               int i;
+
+               if (!is_offload(adapter))
+                       return -EOPNOTSUPP;
+               if (!capable(CAP_NET_ADMIN))
+                       return -EPERM;
+               if (offload_running(adapter))
+                       return -EBUSY;
+               if (copy_from_user(&m, useraddr, sizeof(m)))
+                       return -EFAULT;
+               if (m.nmtus != NMTUS)
+                       return -EINVAL;
+               if (m.mtus[0] < 81)     /* accommodate SACK */
+                       return -EINVAL;
+
+               /* MTUs must be in ascending order */
+               for (i = 1; i < NMTUS; ++i)
+                       if (m.mtus[i] < m.mtus[i - 1])
+                               return -EINVAL;
+
+               memcpy(adapter->params.mtus, m.mtus,
+                       sizeof(adapter->params.mtus));
+               break;
+       }
+       case CHELSIO_GET_PM:{
+               struct tp_params *p = &adapter->params.tp;
+               struct ch_pm m = {.cmd = CHELSIO_GET_PM };
+
+               if (!is_offload(adapter))
+                       return -EOPNOTSUPP;
+               m.tx_pg_sz = p->tx_pg_size;
+               m.tx_num_pg = p->tx_num_pgs;
+               m.rx_pg_sz = p->rx_pg_size;
+               m.rx_num_pg = p->rx_num_pgs;
+               m.pm_total = p->pmtx_size + p->chan_rx_size * p->nchan;
+               if (copy_to_user(useraddr, &m, sizeof(m)))
+                       return -EFAULT;
+               break;
+       }
+       case CHELSIO_SET_PM:{
+               struct ch_pm m;
+               struct tp_params *p = &adapter->params.tp;
+
+               if (!is_offload(adapter))
+                       return -EOPNOTSUPP;
+               if (!capable(CAP_NET_ADMIN))
+                       return -EPERM;
+               if (adapter->flags & FULL_INIT_DONE)
+                       return -EBUSY;
+               if (copy_from_user(&m, useraddr, sizeof(m)))
+                       return -EFAULT;
+               if (!m.rx_pg_sz || (m.rx_pg_sz & (m.rx_pg_sz - 1)) ||
+                       !m.tx_pg_sz || (m.tx_pg_sz & (m.tx_pg_sz - 1)))
+                       return -EINVAL; /* not power of 2 */
+               if (!(m.rx_pg_sz & 0x14000))
+                       return -EINVAL; /* not 16KB or 64KB */
+               if (!(m.tx_pg_sz & 0x1554000))
+                       return -EINVAL;
+               if (m.tx_num_pg == -1)
+                       m.tx_num_pg = p->tx_num_pgs;
+               if (m.rx_num_pg == -1)
+                       m.rx_num_pg = p->rx_num_pgs;
+               if (m.tx_num_pg % 24 || m.rx_num_pg % 24)
+                       return -EINVAL;
+               if (m.rx_num_pg * m.rx_pg_sz > p->chan_rx_size ||
+                       m.tx_num_pg * m.tx_pg_sz > p->chan_tx_size)
+                       return -EINVAL;
+               p->rx_pg_size = m.rx_pg_sz;
+               p->tx_pg_size = m.tx_pg_sz;
+               p->rx_num_pgs = m.rx_num_pg;
+               p->tx_num_pgs = m.tx_num_pg;
+               break;
+       }
+       case CHELSIO_GET_MEM:{
+               struct ch_mem_range t;
+               struct mc7 *mem;
+               u64 buf[32];
+
+               if (!is_offload(adapter))
+                       return -EOPNOTSUPP;
+               if (!(adapter->flags & FULL_INIT_DONE))
+                       return -EIO;    /* need the memory controllers */
+               if (copy_from_user(&t, useraddr, sizeof(t)))
+                       return -EFAULT;
+               if ((t.addr & 7) || (t.len & 7))
+                       return -EINVAL;
+               if (t.mem_id == MEM_CM)
+                       mem = &adapter->cm;
+               else if (t.mem_id == MEM_PMRX)
+                       mem = &adapter->pmrx;
+               else if (t.mem_id == MEM_PMTX)
+                       mem = &adapter->pmtx;
+               else
+                       return -EINVAL;
+
+               /*
+                       * Version scheme:
+                       * bits 0..9: chip version
+                       * bits 10..15: chip revision
+                       */
+               t.version = 3 | (adapter->params.rev << 10);
+               if (copy_to_user(useraddr, &t, sizeof(t)))
+                       return -EFAULT;
+
+               /*
+                * Read 256 bytes at a time as len can be large and we don't
+                * want to use huge intermediate buffers.
+                */
+               useraddr += sizeof(t);  /* advance to start of buffer */
+               while (t.len) {
+                       unsigned int chunk =
+                               min_t(unsigned int, t.len, sizeof(buf));
+
+                       ret =
+                               t3_mc7_bd_read(mem, t.addr / 8, chunk / 8,
+                                               buf);
+                       if (ret)
+                               return ret;
+                       if (copy_to_user(useraddr, buf, chunk))
+                               return -EFAULT;
+                       useraddr += chunk;
+                       t.addr += chunk;
+                       t.len -= chunk;
+               }
+               break;
+       }
+       case CHELSIO_SET_TRACE_FILTER:{
+               struct ch_trace t;
+               const struct trace_params *tp;
+
+               if (!capable(CAP_NET_ADMIN))
+                       return -EPERM;
+               if (!offload_running(adapter))
+                       return -EAGAIN;
+               if (copy_from_user(&t, useraddr, sizeof(t)))
+                       return -EFAULT;
+
+               tp = (const struct trace_params *)&t.sip;
+               if (t.config_tx)
+                       t3_config_trace_filter(adapter, tp, 0,
+                                               t.invert_match,
+                                               t.trace_tx);
+               if (t.config_rx)
+                       t3_config_trace_filter(adapter, tp, 1,
+                                               t.invert_match,
+                                               t.trace_rx);
+               break;
+       }
+       case CHELSIO_SET_PKTSCHED:{
+               struct ch_pktsched_params p;
+
+               if (!capable(CAP_NET_ADMIN))
+                               return -EPERM;
+               if (!adapter->open_device_map)
+                               return -EAGAIN; /* uP and SGE must be running */
+               if (copy_from_user(&p, useraddr, sizeof(p)))
+                               return -EFAULT;
+               send_pktsched_cmd(adapter, p.sched, p.idx, p.min, p.max,
+                                 p.binding);
+               break;
+                       
+       }
+       default:
+               return -EOPNOTSUPP;
+       }
+       return 0;
+}
+
+static int cxgb_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
+{
+       int ret, mmd;
+       struct adapter *adapter = dev->priv;
+       struct port_info *pi = netdev_priv(dev);
+       struct mii_ioctl_data *data = if_mii(req);
+
+       switch (cmd) {
+       case SIOCGMIIPHY:
+               data->phy_id = pi->phy.addr;
+               /* FALLTHRU */
+       case SIOCGMIIREG:{
+               u32 val;
+               struct cphy *phy = &pi->phy;
+
+               if (!phy->mdio_read)
+                       return -EOPNOTSUPP;
+               if (is_10G(adapter)) {
+                       mmd = data->phy_id >> 8;
+                       if (!mmd)
+                               mmd = MDIO_DEV_PCS;
+                       else if (mmd > MDIO_DEV_XGXS)
+                               return -EINVAL;
+
+                       ret =
+                               phy->mdio_read(adapter, data->phy_id & 0x1f,
+                                               mmd, data->reg_num, &val);
+               } else
+                       ret =
+                               phy->mdio_read(adapter, data->phy_id & 0x1f,
+                                               0, data->reg_num & 0x1f,
+                                               &val);
+               if (!ret)
+                       data->val_out = val;
+               break;
+       }
+       case SIOCSMIIREG:{
+               struct cphy *phy = &pi->phy;
+
+               if (!capable(CAP_NET_ADMIN))
+                       return -EPERM;
+               if (!phy->mdio_write)
+                       return -EOPNOTSUPP;
+               if (is_10G(adapter)) {
+                       mmd = data->phy_id >> 8;
+                       if (!mmd)
+                               mmd = MDIO_DEV_PCS;
+                       else if (mmd > MDIO_DEV_XGXS)
+                               return -EINVAL;
+
+                       ret =
+                               phy->mdio_write(adapter,
+                                               data->phy_id & 0x1f, mmd,
+                                               data->reg_num,
+                                               data->val_in);
+               } else
+                       ret =
+                               phy->mdio_write(adapter,
+                                               data->phy_id & 0x1f, 0,
+                                               data->reg_num & 0x1f,
+                                               data->val_in);
+               break;
+       }
+       case SIOCCHIOCTL:
+               return cxgb_extension_ioctl(dev, req->ifr_data);
+       default:
+               return -EOPNOTSUPP;
+       }
+       return ret;
+}
+
+static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
+{
+       int ret;
+       struct adapter *adapter = dev->priv;
+       struct port_info *pi = netdev_priv(dev);
+
+       if (new_mtu < 81)       /* accommodate SACK */
+               return -EINVAL;
+       if ((ret = t3_mac_set_mtu(&pi->mac, new_mtu)))
+               return ret;
+       dev->mtu = new_mtu;
+       init_port_mtus(adapter);
+       if (adapter->params.rev == 0 && offload_running(adapter))
+               t3_load_mtus(adapter, adapter->params.mtus,
+                            adapter->params.a_wnd, adapter->params.b_wnd,
+                            adapter->port[0]->mtu);
+       return 0;
+}
+
+static int cxgb_set_mac_addr(struct net_device *dev, void *p)
+{
+       struct adapter *adapter = dev->priv;
+       struct port_info *pi = netdev_priv(dev);
+       struct sockaddr *addr = p;
+
+       if (!is_valid_ether_addr(addr->sa_data))
+               return -EINVAL;
+
+       memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+       t3_mac_set_address(&pi->mac, 0, dev->dev_addr);
+       if (offload_running(adapter))
+               write_smt_entry(adapter, pi->port_id);
+       return 0;
+}
+
+/**
+ * t3_synchronize_rx - wait for current Rx processing on a port to complete
+ * @adap: the adapter
+ * @p: the port
+ *
+ * Ensures that current Rx processing on any of the queues associated with
+ * the given port completes before returning.  We do this by acquiring and
+ * releasing the locks of the response queues associated with the port.
+ */
+static void t3_synchronize_rx(struct adapter *adap, const struct port_info *p)
+{
+       int i;
+
+       for (i = 0; i < p->nqsets; i++) {
+               struct sge_rspq *q = &adap->sge.qs[i + p->first_qset].rspq;
+
+               spin_lock_irq(&q->lock);
+               spin_unlock_irq(&q->lock);
+       }
+}
+
+static void vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
+{
+       struct adapter *adapter = dev->priv;
+       struct port_info *pi = netdev_priv(dev);
+
+       pi->vlan_grp = grp;
+       if (adapter->params.rev > 0)
+               t3_set_vlan_accel(adapter, 1 << pi->port_id, grp != NULL);
+       else {
+               /* single control for all ports */
+               unsigned int i, have_vlans = 0;
+               for_each_port(adapter, i)
+                   have_vlans |= adap2pinfo(adapter, i)->vlan_grp != NULL;
+
+               t3_set_vlan_accel(adapter, 1, have_vlans);
+       }
+       t3_synchronize_rx(adapter, pi);
+}
+
+static void vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
+{
+       /* nothing */
+}
+
+#ifdef CONFIG_NET_POLL_CONTROLLER
+static void cxgb_netpoll(struct net_device *dev)
+{
+       struct adapter *adapter = dev->priv;
+       struct sge_qset *qs = dev2qset(dev);
+
+       t3_intr_handler(adapter, qs->rspq.polling) (adapter->pdev->irq,
+                                                   adapter);
+}
+#endif
+
+/*
+ * Periodic accumulation of MAC statistics.
+ */
+static void mac_stats_update(struct adapter *adapter)
+{
+       int i;
+
+       for_each_port(adapter, i) {
+               struct net_device *dev = adapter->port[i];
+               struct port_info *p = netdev_priv(dev);
+
+               if (netif_running(dev)) {
+                       spin_lock(&adapter->stats_lock);
+                       t3_mac_update_stats(&p->mac);
+                       spin_unlock(&adapter->stats_lock);
+               }
+       }
+}
+
+static void check_link_status(struct adapter *adapter)
+{
+       int i;
+
+       for_each_port(adapter, i) {
+               struct net_device *dev = adapter->port[i];
+               struct port_info *p = netdev_priv(dev);
+
+               if (!(p->port_type->caps & SUPPORTED_IRQ) && netif_running(dev))
+                       t3_link_changed(adapter, i);
+       }
+}
+
+static void t3_adap_check_task(struct work_struct *work)
+{
+       struct adapter *adapter = container_of(work, struct adapter,
+                                              adap_check_task.work);
+       const struct adapter_params *p = &adapter->params;
+
+       adapter->check_task_cnt++;
+
+       /* Check link status for PHYs without interrupts */
+       if (p->linkpoll_period)
+               check_link_status(adapter);
+
+       /* Accumulate MAC stats if needed */
+       if (!p->linkpoll_period ||
+           (adapter->check_task_cnt * p->linkpoll_period) / 10 >=
+           p->stats_update_period) {
+               mac_stats_update(adapter);
+               adapter->check_task_cnt = 0;
+       }
+
+       /* Schedule the next check update if any port is active. */
+       spin_lock(&adapter->work_lock);
+       if (adapter->open_device_map & PORT_MASK)
+               schedule_chk_task(adapter);
+       spin_unlock(&adapter->work_lock);
+}
+
+/*
+ * Processes external (PHY) interrupts in process context.
+ */
+static void ext_intr_task(struct work_struct *work)
+{
+       struct adapter *adapter = container_of(work, struct adapter,
+                                              ext_intr_handler_task);
+
+       t3_phy_intr_handler(adapter);
+
+       /* Now reenable external interrupts */
+       spin_lock_irq(&adapter->work_lock);
+       if (adapter->slow_intr_mask) {
+               adapter->slow_intr_mask |= F_T3DBG;
+               t3_write_reg(adapter, A_PL_INT_CAUSE0, F_T3DBG);
+               t3_write_reg(adapter, A_PL_INT_ENABLE0,
+                            adapter->slow_intr_mask);
+       }
+       spin_unlock_irq(&adapter->work_lock);
+}
+
+/*
+ * Interrupt-context handler for external (PHY) interrupts.
+ */
+void t3_os_ext_intr_handler(struct adapter *adapter)
+{
+       /*
+        * Schedule a task to handle external interrupts as they may be slow
+        * and we use a mutex to protect MDIO registers.  We disable PHY
+        * interrupts in the meantime and let the task reenable them when
+        * it's done.
+        */
+       spin_lock(&adapter->work_lock);
+       if (adapter->slow_intr_mask) {
+               adapter->slow_intr_mask &= ~F_T3DBG;
+               t3_write_reg(adapter, A_PL_INT_ENABLE0,
+                            adapter->slow_intr_mask);
+               queue_work(cxgb3_wq, &adapter->ext_intr_handler_task);
+       }
+       spin_unlock(&adapter->work_lock);
+}
+
+void t3_fatal_err(struct adapter *adapter)
+{
+       unsigned int fw_status[4];
+
+       if (adapter->flags & FULL_INIT_DONE) {
+               t3_sge_stop(adapter);
+               t3_intr_disable(adapter);
+       }
+       CH_ALERT(adapter, "encountered fatal error, operation suspended\n");
+       if (!t3_cim_ctl_blk_read(adapter, 0xa0, 4, fw_status))
+               CH_ALERT(adapter, "FW status: 0x%x, 0x%x, 0x%x, 0x%x\n",
+                        fw_status[0], fw_status[1],
+                        fw_status[2], fw_status[3]);
+
+}
+
+static int __devinit cxgb_enable_msix(struct adapter *adap)
+{
+       struct msix_entry entries[SGE_QSETS + 1];
+       int i, err;
+
+       for (i = 0; i < ARRAY_SIZE(entries); ++i)
+               entries[i].entry = i;
+
+       err = pci_enable_msix(adap->pdev, entries, ARRAY_SIZE(entries));
+       if (!err) {
+               for (i = 0; i < ARRAY_SIZE(entries); ++i)
+                       adap->msix_info[i].vec = entries[i].vector;
+       } else if (err > 0)
+               dev_info(&adap->pdev->dev,
+                      "only %d MSI-X vectors left, not using MSI-X\n", err);
+       return err;
+}
+
+static void __devinit print_port_info(struct adapter *adap,
+                                     const struct adapter_info *ai)
+{
+       static const char *pci_variant[] = {
+               "PCI", "PCI-X", "PCI-X ECC", "PCI-X 266", "PCI Express"
+       };
+
+       int i;
+       char buf[80];
+
+       if (is_pcie(adap))
+               snprintf(buf, sizeof(buf), "%s x%d",
+                        pci_variant[adap->params.pci.variant],
+                        adap->params.pci.width);
+       else
+               snprintf(buf, sizeof(buf), "%s %dMHz/%d-bit",
+                        pci_variant[adap->params.pci.variant],
+                        adap->params.pci.speed, adap->params.pci.width);
+
+       for_each_port(adap, i) {
+               struct net_device *dev = adap->port[i];
+               const struct port_info *pi = netdev_priv(dev);
+
+               if (!test_bit(i, &adap->registered_device_map))
+                       continue;
+               printk(KERN_INFO "%s: %s %s RNIC (rev %d) %s%s\n",
+                      dev->name, ai->desc, pi->port_type->desc,
+                      adap->params.rev, buf,
+                      (adap->flags & USING_MSIX) ? " MSI-X" :
+                      (adap->flags & USING_MSI) ? " MSI" : "");
+               if (adap->name == dev->name && adap->params.vpd.mclk)
+                       printk(KERN_INFO "%s: %uMB CM, %uMB PMTX, %uMB PMRX\n",
+                              adap->name, t3_mc7_size(&adap->cm) >> 20,
+                              t3_mc7_size(&adap->pmtx) >> 20,
+                              t3_mc7_size(&adap->pmrx) >> 20);
+       }
+}
+
+static int __devinit init_one(struct pci_dev *pdev,
+                             const struct pci_device_id *ent)
+{
+       static int version_printed;
+
+       int i, err, pci_using_dac = 0;
+       unsigned long mmio_start, mmio_len;
+       const struct adapter_info *ai;
+       struct adapter *adapter = NULL;
+       struct port_info *pi;
+
+       if (!version_printed) {
+               printk(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
+               ++version_printed;
+       }
+
+       if (!cxgb3_wq) {
+               cxgb3_wq = create_singlethread_workqueue(DRV_NAME);
+               if (!cxgb3_wq) {
+                       printk(KERN_ERR DRV_NAME
+                              ": cannot initialize work queue\n");
+                       return -ENOMEM;
+               }
+       }
+
+       err = pci_request_regions(pdev, DRV_NAME);
+       if (err) {
+               /* Just info, some other driver may have claimed the device. */
+               dev_info(&pdev->dev, "cannot obtain PCI resources\n");
+               return err;
+       }
+
+       err = pci_enable_device(pdev);
+       if (err) {
+               dev_err(&pdev->dev, "cannot enable PCI device\n");
+               goto out_release_regions;
+       }
+
+       if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
+               pci_using_dac = 1;
+               err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
+               if (err) {
+                       dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
+                              "coherent allocations\n");
+                       goto out_disable_device;
+               }
+       } else if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) != 0) {
+               dev_err(&pdev->dev, "no usable DMA configuration\n");
+               goto out_disable_device;
+       }
+
+       pci_set_master(pdev);
+
+       mmio_start = pci_resource_start(pdev, 0);
+       mmio_len = pci_resource_len(pdev, 0);
+       ai = t3_get_adapter_info(ent->driver_data);
+
+       adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
+       if (!adapter) {
+               err = -ENOMEM;
+               goto out_disable_device;
+       }
+
+       adapter->regs = ioremap_nocache(mmio_start, mmio_len);
+       if (!adapter->regs) {
+               dev_err(&pdev->dev, "cannot map device registers\n");
+               err = -ENOMEM;
+               goto out_free_adapter;
+       }
+
+       adapter->pdev = pdev;
+       adapter->name = pci_name(pdev);
+       adapter->msg_enable = dflt_msg_enable;
+       adapter->mmio_len = mmio_len;
+
+       mutex_init(&adapter->mdio_lock);
+       spin_lock_init(&adapter->work_lock);
+       spin_lock_init(&adapter->stats_lock);
+
+       INIT_LIST_HEAD(&adapter->adapter_list);
+       INIT_WORK(&adapter->ext_intr_handler_task, ext_intr_task);
+       INIT_DELAYED_WORK(&adapter->adap_check_task, t3_adap_check_task);
+
+       for (i = 0; i < ai->nports; ++i) {
+               struct net_device *netdev;
+
+               netdev = alloc_etherdev(sizeof(struct port_info));
+               if (!netdev) {
+                       err = -ENOMEM;
+                       goto out_free_dev;
+               }
+
+               SET_MODULE_OWNER(netdev);
+               SET_NETDEV_DEV(netdev, &pdev->dev);
+
+               adapter->port[i] = netdev;
+               pi = netdev_priv(netdev);
+               pi->rx_csum_offload = 1;
+               pi->nqsets = 1;
+               pi->first_qset = i;
+               pi->activity = 0;
+               pi->port_id = i;
+               netif_carrier_off(netdev);
+               netdev->irq = pdev->irq;
+               netdev->mem_start = mmio_start;
+               netdev->mem_end = mmio_start + mmio_len - 1;
+               netdev->priv = adapter;
+               netdev->features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO;
+               netdev->features |= NETIF_F_LLTX;
+               if (pci_using_dac)
+                       netdev->features |= NETIF_F_HIGHDMA;
+
+               netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
+               netdev->vlan_rx_register = vlan_rx_register;
+               netdev->vlan_rx_kill_vid = vlan_rx_kill_vid;
+
+               netdev->open = cxgb_open;
+               netdev->stop = cxgb_close;
+               netdev->hard_start_xmit = t3_eth_xmit;
+               netdev->get_stats = cxgb_get_stats;
+               netdev->set_multicast_list = cxgb_set_rxmode;
+               netdev->do_ioctl = cxgb_ioctl;
+               netdev->change_mtu = cxgb_change_mtu;
+               netdev->set_mac_address = cxgb_set_mac_addr;
+#ifdef CONFIG_NET_POLL_CONTROLLER
+               netdev->poll_controller = cxgb_netpoll;
+#endif
+               netdev->weight = 64;
+
+               SET_ETHTOOL_OPS(netdev, &cxgb_ethtool_ops);
+       }
+
+       pci_set_drvdata(pdev, adapter->port[0]);
+       if (t3_prep_adapter(adapter, ai, 1) < 0) {
+               err = -ENODEV;
+               goto out_free_dev;
+       }
+
+       /*
+        * The card is now ready to go.  If any errors occur during device
+        * registration we do not fail the whole card but rather proceed only
+        * with the ports we manage to register successfully.  However we must
+        * register at least one net device.
+        */
+       for_each_port(adapter, i) {
+               err = register_netdev(adapter->port[i]);
+               if (err)
+                       dev_warn(&pdev->dev,
+                                "cannot register net device %s, skipping\n",
+                                adapter->port[i]->name);
+               else {
+                       /*
+                        * Change the name we use for messages to the name of
+                        * the first successfully registered interface.
+                        */
+                       if (!adapter->registered_device_map)
+                               adapter->name = adapter->port[i]->name;
+
+                       __set_bit(i, &adapter->registered_device_map);
+               }
+       }
+       if (!adapter->registered_device_map) {
+               dev_err(&pdev->dev, "could not register any net devices\n");
+               goto out_free_dev;
+       }
+
+       /* Driver's ready. Reflect it on LEDs */
+       t3_led_ready(adapter);
+
+       if (is_offload(adapter)) {
+               __set_bit(OFFLOAD_DEVMAP_BIT, &adapter->registered_device_map);
+               cxgb3_adapter_ofld(adapter);
+       }
+
+       /* See what interrupts we'll be using */
+       if (msi > 1 && cxgb_enable_msix(adapter) == 0)
+               adapter->flags |= USING_MSIX;
+       else if (msi > 0 && pci_enable_msi(pdev) == 0)
+               adapter->flags |= USING_MSI;
+
+       err = sysfs_create_group(&adapter->port[0]->class_dev.kobj,
+                                &cxgb3_attr_group);
+
+       print_port_info(adapter, ai);
+       return 0;
+
+out_free_dev:
+       iounmap(adapter->regs);
+       for (i = ai->nports - 1; i >= 0; --i)
+               if (adapter->port[i])
+                       free_netdev(adapter->port[i]);
+
+out_free_adapter:
+       kfree(adapter);
+
+out_disable_device:
+       pci_disable_device(pdev);
+out_release_regions:
+       pci_release_regions(pdev);
+       pci_set_drvdata(pdev, NULL);
+       return err;
+}
+
+static void __devexit remove_one(struct pci_dev *pdev)
+{
+       struct net_device *dev = pci_get_drvdata(pdev);
+
+       if (dev) {
+               int i;
+               struct adapter *adapter = dev->priv;
+
+               t3_sge_stop(adapter);
+               sysfs_remove_group(&adapter->port[0]->class_dev.kobj,
+                                  &cxgb3_attr_group);
+
+               for_each_port(adapter, i)
+                   if (test_bit(i, &adapter->registered_device_map))
+                       unregister_netdev(adapter->port[i]);
+
+               if (is_offload(adapter)) {
+                       cxgb3_adapter_unofld(adapter);
+                       if (test_bit(OFFLOAD_DEVMAP_BIT,
+                                    &adapter->open_device_map))
+                               offload_close(&adapter->tdev);
+               }
+
+               t3_free_sge_resources(adapter);
+               cxgb_disable_msi(adapter);
+
+               for (i = 0; i < ARRAY_SIZE(adapter->dummy_netdev); i++)
+                       if (adapter->dummy_netdev[i]) {
+                               free_netdev(adapter->dummy_netdev[i]);
+                               adapter->dummy_netdev[i] = NULL;
+                       }
+
+               for_each_port(adapter, i)
+                       if (adapter->port[i])
+                               free_netdev(adapter->port[i]);
+
+               iounmap(adapter->regs);
+               kfree(adapter);
+               pci_release_regions(pdev);
+               pci_disable_device(pdev);
+               pci_set_drvdata(pdev, NULL);
+       }
+}
+
+static struct pci_driver driver = {
+       .name = DRV_NAME,
+       .id_table = cxgb3_pci_tbl,
+       .probe = init_one,
+       .remove = __devexit_p(remove_one),
+};
+
+static int __init cxgb3_init_module(void)
+{
+       int ret;
+
+       cxgb3_offload_init();
+
+       ret = pci_register_driver(&driver);
+       return ret;
+}
+
+static void __exit cxgb3_cleanup_module(void)
+{
+       pci_unregister_driver(&driver);
+       if (cxgb3_wq)
+               destroy_workqueue(cxgb3_wq);
+}
+
+module_init(cxgb3_init_module);
+module_exit(cxgb3_cleanup_module);
diff --git a/drivers/net/cxgb3/cxgb3_offload.c b/drivers/net/cxgb3/cxgb3_offload.c
new file mode 100644 (file)
index 0000000..c3a02d6
--- /dev/null
@@ -0,0 +1,1222 @@
+/*
+ * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <linux/list.h>
+#include <net/neighbour.h>
+#include <linux/notifier.h>
+#include <asm/atomic.h>
+#include <linux/proc_fs.h>
+#include <linux/if_vlan.h>
+#include <net/netevent.h>
+#include <linux/highmem.h>
+#include <linux/vmalloc.h>
+
+#include "common.h"
+#include "regs.h"
+#include "cxgb3_ioctl.h"
+#include "cxgb3_ctl_defs.h"
+#include "cxgb3_defs.h"
+#include "l2t.h"
+#include "firmware_exports.h"
+#include "cxgb3_offload.h"
+
+static LIST_HEAD(client_list);
+static LIST_HEAD(ofld_dev_list);
+static DEFINE_MUTEX(cxgb3_db_lock);
+
+static DEFINE_RWLOCK(adapter_list_lock);
+static LIST_HEAD(adapter_list);
+
+static const unsigned int MAX_ATIDS = 64 * 1024;
+static const unsigned int ATID_BASE = 0x100000;
+
+static inline int offload_activated(struct t3cdev *tdev)
+{
+       const struct adapter *adapter = tdev2adap(tdev);
+
+       return (test_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map));
+}
+
+/**
+ *     cxgb3_register_client - register an offload client
+ *     @client: the client
+ *
+ *     Add the client to the client list,
+ *     and call backs the client for each activated offload device
+ */
+void cxgb3_register_client(struct cxgb3_client *client)
+{
+       struct t3cdev *tdev;
+
+       mutex_lock(&cxgb3_db_lock);
+       list_add_tail(&client->client_list, &client_list);
+
+       if (client->add) {
+               list_for_each_entry(tdev, &ofld_dev_list, ofld_dev_list) {
+                       if (offload_activated(tdev))
+                               client->add(tdev);
+               }
+       }
+       mutex_unlock(&cxgb3_db_lock);
+}
+
+EXPORT_SYMBOL(cxgb3_register_client);
+
+/**
+ *     cxgb3_unregister_client - unregister an offload client
+ *     @client: the client
+ *
+ *     Remove the client to the client list,
+ *     and call backs the client for each activated offload device.
+ */
+void cxgb3_unregister_client(struct cxgb3_client *client)
+{
+       struct t3cdev *tdev;
+
+       mutex_lock(&cxgb3_db_lock);
+       list_del(&client->client_list);
+
+       if (client->remove) {
+               list_for_each_entry(tdev, &ofld_dev_list, ofld_dev_list) {
+                       if (offload_activated(tdev))
+                               client->remove(tdev);
+               }
+       }
+       mutex_unlock(&cxgb3_db_lock);
+}
+
+EXPORT_SYMBOL(cxgb3_unregister_client);
+
+/**
+ *     cxgb3_add_clients - activate registered clients for an offload device
+ *     @tdev: the offload device
+ *
+ *     Call backs all registered clients once a offload device is activated
+ */
+void cxgb3_add_clients(struct t3cdev *tdev)
+{
+       struct cxgb3_client *client;
+
+       mutex_lock(&cxgb3_db_lock);
+       list_for_each_entry(client, &client_list, client_list) {
+               if (client->add)
+                       client->add(tdev);
+       }
+       mutex_unlock(&cxgb3_db_lock);
+}
+
+/**
+ *     cxgb3_remove_clients - deactivates registered clients
+ *                            for an offload device
+ *     @tdev: the offload device
+ *
+ *     Call backs all registered clients once a offload device is deactivated
+ */
+void cxgb3_remove_clients(struct t3cdev *tdev)
+{
+       struct cxgb3_client *client;
+
+       mutex_lock(&cxgb3_db_lock);
+       list_for_each_entry(client, &client_list, client_list) {
+               if (client->remove)
+                       client->remove(tdev);
+       }
+       mutex_unlock(&cxgb3_db_lock);
+}
+
+static struct net_device *get_iff_from_mac(struct adapter *adapter,
+                                          const unsigned char *mac,
+                                          unsigned int vlan)
+{
+       int i;
+
+       for_each_port(adapter, i) {
+               const struct vlan_group *grp;
+               struct net_device *dev = adapter->port[i];
+               const struct port_info *p = netdev_priv(dev);
+
+               if (!memcmp(dev->dev_addr, mac, ETH_ALEN)) {
+                       if (vlan && vlan != VLAN_VID_MASK) {
+                               grp = p->vlan_grp;
+                               dev = grp ? grp->vlan_devices[vlan] : NULL;
+                       } else
+                               while (dev->master)
+                                       dev = dev->master;
+                       return dev;
+               }
+       }
+       return NULL;
+}
+
+static int cxgb_ulp_iscsi_ctl(struct adapter *adapter, unsigned int req,
+                             void *data)
+{
+       int ret = 0;
+       struct ulp_iscsi_info *uiip = data;
+
+       switch (req) {
+       case ULP_ISCSI_GET_PARAMS:
+               uiip->pdev = adapter->pdev;
+               uiip->llimit = t3_read_reg(adapter, A_ULPRX_ISCSI_LLIMIT);
+               uiip->ulimit = t3_read_reg(adapter, A_ULPRX_ISCSI_ULIMIT);
+               uiip->tagmask = t3_read_reg(adapter, A_ULPRX_ISCSI_TAGMASK);
+               /*
+                * On tx, the iscsi pdu has to be <= tx page size and has to
+                * fit into the Tx PM FIFO.
+                */
+               uiip->max_txsz = min(adapter->params.tp.tx_pg_size,
+                                    t3_read_reg(adapter, A_PM1_TX_CFG) >> 17);
+               /* on rx, the iscsi pdu has to be < rx page size and the
+                  whole pdu + cpl headers has to fit into one sge buffer */
+               uiip->max_rxsz = min_t(unsigned int,
+                                      adapter->params.tp.rx_pg_size,
+                                      (adapter->sge.qs[0].fl[1].buf_size -
+                                       sizeof(struct cpl_rx_data) * 2 -
+                                       sizeof(struct cpl_rx_data_ddp)));
+               break;
+       case ULP_ISCSI_SET_PARAMS:
+               t3_write_reg(adapter, A_ULPRX_ISCSI_TAGMASK, uiip->tagmask);
+               break;
+       default:
+               ret = -EOPNOTSUPP;
+       }
+       return ret;
+}
+
+/* Response queue used for RDMA events. */
+#define ASYNC_NOTIF_RSPQ 0
+
+static int cxgb_rdma_ctl(struct adapter *adapter, unsigned int req, void *data)
+{
+       int ret = 0;
+
+       switch (req) {
+       case RDMA_GET_PARAMS:{
+               struct rdma_info *req = data;
+               struct pci_dev *pdev = adapter->pdev;
+
+               req->udbell_physbase = pci_resource_start(pdev, 2);
+               req->udbell_len = pci_resource_len(pdev, 2);
+               req->tpt_base =
+                       t3_read_reg(adapter, A_ULPTX_TPT_LLIMIT);
+               req->tpt_top = t3_read_reg(adapter, A_ULPTX_TPT_ULIMIT);
+               req->pbl_base =
+                       t3_read_reg(adapter, A_ULPTX_PBL_LLIMIT);
+               req->pbl_top = t3_read_reg(adapter, A_ULPTX_PBL_ULIMIT);
+               req->rqt_base = t3_read_reg(adapter, A_ULPRX_RQ_LLIMIT);
+               req->rqt_top = t3_read_reg(adapter, A_ULPRX_RQ_ULIMIT);
+               req->kdb_addr = adapter->regs + A_SG_KDOORBELL;
+               req->pdev = pdev;
+               break;
+       }
+       case RDMA_CQ_OP:{
+               unsigned long flags;
+               struct rdma_cq_op *req = data;
+
+               /* may be called in any context */
+               spin_lock_irqsave(&adapter->sge.reg_lock, flags);
+               ret = t3_sge_cqcntxt_op(adapter, req->id, req->op,
+                                       req->credits);
+               spin_unlock_irqrestore(&adapter->sge.reg_lock, flags);
+               break;
+       }
+       case RDMA_GET_MEM:{
+               struct ch_mem_range *t = data;
+               struct mc7 *mem;
+
+               if ((t->addr & 7) || (t->len & 7))
+                       return -EINVAL;
+               if (t->mem_id == MEM_CM)
+                       mem = &adapter->cm;
+               else if (t->mem_id == MEM_PMRX)
+                       mem = &adapter->pmrx;
+               else if (t->mem_id == MEM_PMTX)
+                       mem = &adapter->pmtx;
+               else
+                       return -EINVAL;
+
+               ret =
+                       t3_mc7_bd_read(mem, t->addr / 8, t->len / 8,
+                                       (u64 *) t->buf);
+               if (ret)
+                       return ret;
+               break;
+       }
+       case RDMA_CQ_SETUP:{
+               struct rdma_cq_setup *req = data;
+
+               spin_lock_irq(&adapter->sge.reg_lock);
+               ret =
+                       t3_sge_init_cqcntxt(adapter, req->id,
+                                       req->base_addr, req->size,
+                                       ASYNC_NOTIF_RSPQ,
+                                       req->ovfl_mode, req->credits,
+                                       req->credit_thres);
+               spin_unlock_irq(&adapter->sge.reg_lock);
+               break;
+       }
+       case RDMA_CQ_DISABLE:
+               spin_lock_irq(&adapter->sge.reg_lock);
+               ret = t3_sge_disable_cqcntxt(adapter, *(unsigned int *)data);
+               spin_unlock_irq(&adapter->sge.reg_lock);
+               break;
+       case RDMA_CTRL_QP_SETUP:{
+               struct rdma_ctrlqp_setup *req = data;
+
+               spin_lock_irq(&adapter->sge.reg_lock);
+               ret = t3_sge_init_ecntxt(adapter, FW_RI_SGEEC_START, 0,
+                                               SGE_CNTXT_RDMA,
+                                               ASYNC_NOTIF_RSPQ,
+                                               req->base_addr, req->size,
+                                               FW_RI_TID_START, 1, 0);
+               spin_unlock_irq(&adapter->sge.reg_lock);
+               break;
+       }
+       default:
+               ret = -EOPNOTSUPP;
+       }
+       return ret;
+}
+
+static int cxgb_offload_ctl(struct t3cdev *tdev, unsigned int req, void *data)
+{
+       struct adapter *adapter = tdev2adap(tdev);
+       struct tid_range *tid;
+       struct mtutab *mtup;
+       struct iff_mac *iffmacp;
+       struct ddp_params *ddpp;
+       struct adap_ports *ports;
+       int i;
+
+       switch (req) {
+       case GET_MAX_OUTSTANDING_WR:
+               *(unsigned int *)data = FW_WR_NUM;
+               break;
+       case GET_WR_LEN:
+               *(unsigned int *)data = WR_FLITS;
+               break;
+       case GET_TX_MAX_CHUNK:
+               *(unsigned int *)data = 1 << 20;        /* 1MB */
+               break;
+       case GET_TID_RANGE:
+               tid = data;
+               tid->num = t3_mc5_size(&adapter->mc5) -
+                   adapter->params.mc5.nroutes -
+                   adapter->params.mc5.nfilters - adapter->params.mc5.nservers;
+               tid->base = 0;
+               break;
+       case GET_STID_RANGE:
+               tid = data;
+               tid->num = adapter->params.mc5.nservers;
+               tid->base = t3_mc5_size(&adapter->mc5) - tid->num -
+                   adapter->params.mc5.nfilters - adapter->params.mc5.nroutes;
+               break;
+       case GET_L2T_CAPACITY:
+               *(unsigned int *)data = 2048;
+               break;
+       case GET_MTUS:
+               mtup = data;
+               mtup->size = NMTUS;
+               mtup->mtus = adapter->params.mtus;
+               break;
+       case GET_IFF_FROM_MAC:
+               iffmacp = data;
+               iffmacp->dev = get_iff_from_mac(adapter, iffmacp->mac_addr,
+                                               iffmacp->vlan_tag &
+                                               VLAN_VID_MASK);
+               break;
+       case GET_DDP_PARAMS:
+               ddpp = data;
+               ddpp->llimit = t3_read_reg(adapter, A_ULPRX_TDDP_LLIMIT);
+               ddpp->ulimit = t3_read_reg(adapter, A_ULPRX_TDDP_ULIMIT);
+               ddpp->tag_mask = t3_read_reg(adapter, A_ULPRX_TDDP_TAGMASK);
+               break;
+       case GET_PORTS:
+               ports = data;
+               ports->nports = adapter->params.nports;
+               for_each_port(adapter, i)
+                       ports->lldevs[i] = adapter->port[i];
+               break;
+       case ULP_ISCSI_GET_PARAMS:
+       case ULP_ISCSI_SET_PARAMS:
+               if (!offload_running(adapter))
+                       return -EAGAIN;
+               return cxgb_ulp_iscsi_ctl(adapter, req, data);
+       case RDMA_GET_PARAMS:
+       case RDMA_CQ_OP:
+       case RDMA_CQ_SETUP:
+       case RDMA_CQ_DISABLE:
+       case RDMA_CTRL_QP_SETUP:
+       case RDMA_GET_MEM:
+               if (!offload_running(adapter))
+                       return -EAGAIN;
+               return cxgb_rdma_ctl(adapter, req, data);
+       default:
+               return -EOPNOTSUPP;
+       }
+       return 0;
+}
+
+/*
+ * Dummy handler for Rx offload packets in case we get an offload packet before
+ * proper processing is setup.  This complains and drops the packet as it isn't
+ * normal to get offload packets at this stage.
+ */
+static int rx_offload_blackhole(struct t3cdev *dev, struct sk_buff **skbs,
+                               int n)
+{
+       CH_ERR(tdev2adap(dev), "%d unexpected offload packets, first data %u\n",
+              n, ntohl(*(u32 *)skbs[0]->data));
+       while (n--)
+               dev_kfree_skb_any(skbs[n]);
+       return 0;
+}
+
+static void dummy_neigh_update(struct t3cdev *dev, struct neighbour *neigh)
+{
+}
+
+void cxgb3_set_dummy_ops(struct t3cdev *dev)
+{
+       dev->recv = rx_offload_blackhole;
+       dev->neigh_update = dummy_neigh_update;
+}
+
+/*
+ * Free an active-open TID.
+ */
+void *cxgb3_free_atid(struct t3cdev *tdev, int atid)
+{
+       struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
+       union active_open_entry *p = atid2entry(t, atid);
+       void *ctx = p->t3c_tid.ctx;
+
+       spin_lock_bh(&t->atid_lock);
+       p->next = t->afree;
+       t->afree = p;
+       t->atids_in_use--;
+       spin_unlock_bh(&t->atid_lock);
+
+       return ctx;
+}
+
+EXPORT_SYMBOL(cxgb3_free_atid);
+
+/*
+ * Free a server TID and return it to the free pool.
+ */
+void cxgb3_free_stid(struct t3cdev *tdev, int stid)
+{
+       struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
+       union listen_entry *p = stid2entry(t, stid);
+
+       spin_lock_bh(&t->stid_lock);
+       p->next = t->sfree;
+       t->sfree = p;
+       t->stids_in_use--;
+       spin_unlock_bh(&t->stid_lock);
+}
+
+EXPORT_SYMBOL(cxgb3_free_stid);
+
+void cxgb3_insert_tid(struct t3cdev *tdev, struct cxgb3_client *client,
+                     void *ctx, unsigned int tid)
+{
+       struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
+
+       t->tid_tab[tid].client = client;
+       t->tid_tab[tid].ctx = ctx;
+       atomic_inc(&t->tids_in_use);
+}
+
+EXPORT_SYMBOL(cxgb3_insert_tid);
+
+/*
+ * Populate a TID_RELEASE WR.  The skb must be already propely sized.
+ */
+static inline void mk_tid_release(struct sk_buff *skb, unsigned int tid)
+{
+       struct cpl_tid_release *req;
+
+       skb->priority = CPL_PRIORITY_SETUP;
+       req = (struct cpl_tid_release *)__skb_put(skb, sizeof(*req));
+       req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
+       OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
+}
+
+static void t3_process_tid_release_list(struct work_struct *work)
+{
+       struct t3c_data *td = container_of(work, struct t3c_data,
+                                          tid_release_task);
+       struct sk_buff *skb;
+       struct t3cdev *tdev = td->dev;
+       
+
+       spin_lock_bh(&td->tid_release_lock);
+       while (td->tid_release_list) {
+               struct t3c_tid_entry *p = td->tid_release_list;
+
+               td->tid_release_list = (struct t3c_tid_entry *)p->ctx;
+               spin_unlock_bh(&td->tid_release_lock);
+
+               skb = alloc_skb(sizeof(struct cpl_tid_release),
+                               GFP_KERNEL | __GFP_NOFAIL);
+               mk_tid_release(skb, p - td->tid_maps.tid_tab);
+               cxgb3_ofld_send(tdev, skb);
+               p->ctx = NULL;
+               spin_lock_bh(&td->tid_release_lock);
+       }
+       spin_unlock_bh(&td->tid_release_lock);
+}
+
+/* use ctx as a next pointer in the tid release list */
+void cxgb3_queue_tid_release(struct t3cdev *tdev, unsigned int tid)
+{
+       struct t3c_data *td = T3C_DATA(tdev);
+       struct t3c_tid_entry *p = &td->tid_maps.tid_tab[tid];
+
+       spin_lock_bh(&td->tid_release_lock);
+       p->ctx = (void *)td->tid_release_list;
+       td->tid_release_list = p;
+       if (!p->ctx)
+               schedule_work(&td->tid_release_task);
+       spin_unlock_bh(&td->tid_release_lock);
+}
+
+EXPORT_SYMBOL(cxgb3_queue_tid_release);
+
+/*
+ * Remove a tid from the TID table.  A client may defer processing its last
+ * CPL message if it is locked at the time it arrives, and while the message
+ * sits in the client's backlog the TID may be reused for another connection.
+ * To handle this we atomically switch the TID association if it still points
+ * to the original client context.
+ */
+void cxgb3_remove_tid(struct t3cdev *tdev, void *ctx, unsigned int tid)
+{
+       struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
+
+       BUG_ON(tid >= t->ntids);
+       if (tdev->type == T3A)
+               (void)cmpxchg(&t->tid_tab[tid].ctx, ctx, NULL);
+       else {
+               struct sk_buff *skb;
+
+               skb = alloc_skb(sizeof(struct cpl_tid_release), GFP_ATOMIC);
+               if (likely(skb)) {
+                       mk_tid_release(skb, tid);
+                       cxgb3_ofld_send(tdev, skb);
+                       t->tid_tab[tid].ctx = NULL;
+               } else
+                       cxgb3_queue_tid_release(tdev, tid);
+       }
+       atomic_dec(&t->tids_in_use);
+}
+
+EXPORT_SYMBOL(cxgb3_remove_tid);
+
+int cxgb3_alloc_atid(struct t3cdev *tdev, struct cxgb3_client *client,
+                    void *ctx)
+{
+       int atid = -1;
+       struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
+
+       spin_lock_bh(&t->atid_lock);
+       if (t->afree) {
+               union active_open_entry *p = t->afree;
+
+               atid = (p - t->atid_tab) + t->atid_base;
+               t->afree = p->next;
+               p->t3c_tid.ctx = ctx;
+               p->t3c_tid.client = client;
+               t->atids_in_use++;
+       }
+       spin_unlock_bh(&t->atid_lock);
+       return atid;
+}
+
+EXPORT_SYMBOL(cxgb3_alloc_atid);
+
+int cxgb3_alloc_stid(struct t3cdev *tdev, struct cxgb3_client *client,
+                    void *ctx)
+{
+       int stid = -1;
+       struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
+
+       spin_lock_bh(&t->stid_lock);
+       if (t->sfree) {
+               union listen_entry *p = t->sfree;
+
+               stid = (p - t->stid_tab) + t->stid_base;
+               t->sfree = p->next;
+               p->t3c_tid.ctx = ctx;
+               p->t3c_tid.client = client;
+               t->stids_in_use++;
+       }
+       spin_unlock_bh(&t->stid_lock);
+       return stid;
+}
+
+EXPORT_SYMBOL(cxgb3_alloc_stid);
+
+static int do_smt_write_rpl(struct t3cdev *dev, struct sk_buff *skb)
+{
+       struct cpl_smt_write_rpl *rpl = cplhdr(skb);
+
+       if (rpl->status != CPL_ERR_NONE)
+               printk(KERN_ERR
+                      "Unexpected SMT_WRITE_RPL status %u for entry %u\n",
+                      rpl->status, GET_TID(rpl));
+
+       return CPL_RET_BUF_DONE;
+}
+
+static int do_l2t_write_rpl(struct t3cdev *dev, struct sk_buff *skb)
+{
+       struct cpl_l2t_write_rpl *rpl = cplhdr(skb);
+
+       if (rpl->status != CPL_ERR_NONE)
+               printk(KERN_ERR
+                      "Unexpected L2T_WRITE_RPL status %u for entry %u\n",
+                      rpl->status, GET_TID(rpl));
+
+       return CPL_RET_BUF_DONE;
+}
+
+static int do_act_open_rpl(struct t3cdev *dev, struct sk_buff *skb)
+{
+       struct cpl_act_open_rpl *rpl = cplhdr(skb);
+       unsigned int atid = G_TID(ntohl(rpl->atid));
+       struct t3c_tid_entry *t3c_tid;
+
+       t3c_tid = lookup_atid(&(T3C_DATA(dev))->tid_maps, atid);
+       if (t3c_tid->ctx && t3c_tid->client && t3c_tid->client->handlers &&
+           t3c_tid->client->handlers[CPL_ACT_OPEN_RPL]) {
+               return t3c_tid->client->handlers[CPL_ACT_OPEN_RPL] (dev, skb,
+                                                                   t3c_tid->
+                                                                   ctx);
+       } else {
+               printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
+                      dev->name, CPL_ACT_OPEN_RPL);
+               return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
+       }
+}
+
+static int do_stid_rpl(struct t3cdev *dev, struct sk_buff *skb)
+{
+       union opcode_tid *p = cplhdr(skb);
+       unsigned int stid = G_TID(ntohl(p->opcode_tid));
+       struct t3c_tid_entry *t3c_tid;
+
+       t3c_tid = lookup_stid(&(T3C_DATA(dev))->tid_maps, stid);
+       if (t3c_tid->ctx && t3c_tid->client->handlers &&
+           t3c_tid->client->handlers[p->opcode]) {
+               return t3c_tid->client->handlers[p->opcode] (dev, skb,
+                                                            t3c_tid->ctx);
+       } else {
+               printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
+                      dev->name, p->opcode);
+               return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
+       }
+}
+
+static int do_hwtid_rpl(struct t3cdev *dev, struct sk_buff *skb)
+{
+       union opcode_tid *p = cplhdr(skb);
+       unsigned int hwtid = G_TID(ntohl(p->opcode_tid));
+       struct t3c_tid_entry *t3c_tid;
+
+       t3c_tid = lookup_tid(&(T3C_DATA(dev))->tid_maps, hwtid);
+       if (t3c_tid->ctx && t3c_tid->client->handlers &&
+           t3c_tid->client->handlers[p->opcode]) {
+               return t3c_tid->client->handlers[p->opcode]
+                   (dev, skb, t3c_tid->ctx);
+       } else {
+               printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
+                      dev->name, p->opcode);
+               return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
+       }
+}
+
+static int do_cr(struct t3cdev *dev, struct sk_buff *skb)
+{
+       struct cpl_pass_accept_req *req = cplhdr(skb);
+       unsigned int stid = G_PASS_OPEN_TID(ntohl(req->tos_tid));
+       struct t3c_tid_entry *t3c_tid;
+
+       t3c_tid = lookup_stid(&(T3C_DATA(dev))->tid_maps, stid);
+       if (t3c_tid->ctx && t3c_tid->client->handlers &&
+           t3c_tid->client->handlers[CPL_PASS_ACCEPT_REQ]) {
+               return t3c_tid->client->handlers[CPL_PASS_ACCEPT_REQ]
+                   (dev, skb, t3c_tid->ctx);
+       } else {
+               printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
+                      dev->name, CPL_PASS_ACCEPT_REQ);
+               return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
+       }
+}
+
+static int do_abort_req_rss(struct t3cdev *dev, struct sk_buff *skb)
+{
+       union opcode_tid *p = cplhdr(skb);
+       unsigned int hwtid = G_TID(ntohl(p->opcode_tid));
+       struct t3c_tid_entry *t3c_tid;
+
+       t3c_tid = lookup_tid(&(T3C_DATA(dev))->tid_maps, hwtid);
+       if (t3c_tid->ctx && t3c_tid->client->handlers &&
+           t3c_tid->client->handlers[p->opcode]) {
+               return t3c_tid->client->handlers[p->opcode]
+                   (dev, skb, t3c_tid->ctx);
+       } else {
+               struct cpl_abort_req_rss *req = cplhdr(skb);
+               struct cpl_abort_rpl *rpl;
+
+               struct sk_buff *skb =
+                   alloc_skb(sizeof(struct cpl_abort_rpl), GFP_ATOMIC);
+               if (!skb) {
+                       printk("do_abort_req_rss: couldn't get skb!\n");
+                       goto out;
+               }
+               skb->priority = CPL_PRIORITY_DATA;
+               __skb_put(skb, sizeof(struct cpl_abort_rpl));
+               rpl = cplhdr(skb);
+               rpl->wr.wr_hi =
+                   htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL));
+               rpl->wr.wr_lo = htonl(V_WR_TID(GET_TID(req)));
+               OPCODE_TID(rpl) =
+                   htonl(MK_OPCODE_TID(CPL_ABORT_RPL, GET_TID(req)));
+               rpl->cmd = req->status;
+               cxgb3_ofld_send(dev, skb);
+out:
+               return CPL_RET_BUF_DONE;
+       }
+}
+
+static int do_act_establish(struct t3cdev *dev, struct sk_buff *skb)
+{
+       struct cpl_act_establish *req = cplhdr(skb);
+       unsigned int atid = G_PASS_OPEN_TID(ntohl(req->tos_tid));
+       struct t3c_tid_entry *t3c_tid;
+
+       t3c_tid = lookup_atid(&(T3C_DATA(dev))->tid_maps, atid);
+       if (t3c_tid->ctx && t3c_tid->client->handlers &&
+           t3c_tid->client->handlers[CPL_ACT_ESTABLISH]) {
+               return t3c_tid->client->handlers[CPL_ACT_ESTABLISH]
+                   (dev, skb, t3c_tid->ctx);
+       } else {
+               printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
+                      dev->name, CPL_PASS_ACCEPT_REQ);
+               return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
+       }
+}
+
+static int do_set_tcb_rpl(struct t3cdev *dev, struct sk_buff *skb)
+{
+       struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
+
+       if (rpl->status != CPL_ERR_NONE)
+               printk(KERN_ERR
+                      "Unexpected SET_TCB_RPL status %u for tid %u\n",
+                      rpl->status, GET_TID(rpl));
+       return CPL_RET_BUF_DONE;
+}
+
+static int do_trace(struct t3cdev *dev, struct sk_buff *skb)
+{
+       struct cpl_trace_pkt *p = cplhdr(skb);
+
+       skb->protocol = 0xffff;
+       skb->dev = dev->lldev;
+       skb_pull(skb, sizeof(*p));
+       skb->mac.raw = skb->data;
+       netif_receive_skb(skb);
+       return 0;
+}
+
+static int do_term(struct t3cdev *dev, struct sk_buff *skb)
+{
+       unsigned int hwtid = ntohl(skb->priority) >> 8 & 0xfffff;
+       unsigned int opcode = G_OPCODE(ntohl(skb->csum));
+       struct t3c_tid_entry *t3c_tid;
+
+       t3c_tid = lookup_tid(&(T3C_DATA(dev))->tid_maps, hwtid);
+       if (t3c_tid->ctx && t3c_tid->client->handlers &&
+           t3c_tid->client->handlers[opcode]) {
+               return t3c_tid->client->handlers[opcode] (dev, skb,
+                                                         t3c_tid->ctx);
+       } else {
+               printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
+                      dev->name, opcode);
+               return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
+       }
+}
+
+static int nb_callback(struct notifier_block *self, unsigned long event,
+                      void *ctx)
+{
+       switch (event) {
+       case (NETEVENT_NEIGH_UPDATE):{
+               cxgb_neigh_update((struct neighbour *)ctx);
+               break;
+       }
+       case (NETEVENT_PMTU_UPDATE):
+               break;
+       case (NETEVENT_REDIRECT):{
+               struct netevent_redirect *nr = ctx;
+               cxgb_redirect(nr->old, nr->new);
+               cxgb_neigh_update(nr->new->neighbour);
+               break;
+       }
+       default:
+               break;
+       }
+       return 0;
+}
+
+static struct notifier_block nb = {
+       .notifier_call = nb_callback
+};
+
+/*
+ * Process a received packet with an unknown/unexpected CPL opcode.
+ */
+static int do_bad_cpl(struct t3cdev *dev, struct sk_buff *skb)
+{
+       printk(KERN_ERR "%s: received bad CPL command 0x%x\n", dev->name,
+              *skb->data);
+       return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
+}
+
+/*
+ * Handlers for each CPL opcode
+ */
+static cpl_handler_func cpl_handlers[NUM_CPL_CMDS];
+
+/*
+ * Add a new handler to the CPL dispatch table.  A NULL handler may be supplied
+ * to unregister an existing handler.
+ */
+void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h)
+{
+       if (opcode < NUM_CPL_CMDS)
+               cpl_handlers[opcode] = h ? h : do_bad_cpl;
+       else
+               printk(KERN_ERR "T3C: handler registration for "
+                      "opcode %x failed\n", opcode);
+}
+
+EXPORT_SYMBOL(t3_register_cpl_handler);
+
+/*
+ * T3CDEV's receive method.
+ */
+int process_rx(struct t3cdev *dev, struct sk_buff **skbs, int n)
+{
+       while (n--) {
+               struct sk_buff *skb = *skbs++;
+               unsigned int opcode = G_OPCODE(ntohl(skb->csum));
+               int ret = cpl_handlers[opcode] (dev, skb);
+
+#if VALIDATE_TID
+               if (ret & CPL_RET_UNKNOWN_TID) {
+                       union opcode_tid *p = cplhdr(skb);
+
+                       printk(KERN_ERR "%s: CPL message (opcode %u) had "
+                              "unknown TID %u\n", dev->name, opcode,
+                              G_TID(ntohl(p->opcode_tid)));
+               }
+#endif
+               if (ret & CPL_RET_BUF_DONE)
+                       kfree_skb(skb);
+       }
+       return 0;
+}
+
+/*
+ * Sends an sk_buff to a T3C driver after dealing with any active network taps.
+ */
+int cxgb3_ofld_send(struct t3cdev *dev, struct sk_buff *skb)
+{
+       int r;
+
+       local_bh_disable();
+       r = dev->send(dev, skb);
+       local_bh_enable();
+       return r;
+}
+
+EXPORT_SYMBOL(cxgb3_ofld_send);
+
+static int is_offloading(struct net_device *dev)
+{
+       struct adapter *adapter;
+       int i;
+
+       read_lock_bh(&adapter_list_lock);
+       list_for_each_entry(adapter, &adapter_list, adapter_list) {
+               for_each_port(adapter, i) {
+                       if (dev == adapter->port[i]) {
+                               read_unlock_bh(&adapter_list_lock);
+                               return 1;
+                       }
+               }
+       }
+       read_unlock_bh(&adapter_list_lock);
+       return 0;
+}
+
+void cxgb_neigh_update(struct neighbour *neigh)
+{
+       struct net_device *dev = neigh->dev;
+
+       if (dev && (is_offloading(dev))) {
+               struct t3cdev *tdev = T3CDEV(dev);
+
+               BUG_ON(!tdev);
+               t3_l2t_update(tdev, neigh);
+       }
+}
+
+static void set_l2t_ix(struct t3cdev *tdev, u32 tid, struct l2t_entry *e)
+{
+       struct sk_buff *skb;
+       struct cpl_set_tcb_field *req;
+
+       skb = alloc_skb(sizeof(*req), GFP_ATOMIC);
+       if (!skb) {
+               printk(KERN_ERR "%s: cannot allocate skb!\n", __FUNCTION__);
+               return;
+       }
+       skb->priority = CPL_PRIORITY_CONTROL;
+       req = (struct cpl_set_tcb_field *)skb_put(skb, sizeof(*req));
+       req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
+       OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
+       req->reply = 0;
+       req->cpu_idx = 0;
+       req->word = htons(W_TCB_L2T_IX);
+       req->mask = cpu_to_be64(V_TCB_L2T_IX(M_TCB_L2T_IX));
+       req->val = cpu_to_be64(V_TCB_L2T_IX(e->idx));
+       tdev->send(tdev, skb);
+}
+
+void cxgb_redirect(struct dst_entry *old, struct dst_entry *new)
+{
+       struct net_device *olddev, *newdev;
+       struct tid_info *ti;
+       struct t3cdev *tdev;
+       u32 tid;
+       int update_tcb;
+       struct l2t_entry *e;
+       struct t3c_tid_entry *te;
+
+       olddev = old->neighbour->dev;
+       newdev = new->neighbour->dev;
+       if (!is_offloading(olddev))
+               return;
+       if (!is_offloading(newdev)) {
+               printk(KERN_WARNING "%s: Redirect to non-offload"
+                      "device ignored.\n", __FUNCTION__);
+               return;
+       }
+       tdev = T3CDEV(olddev);
+       BUG_ON(!tdev);
+       if (tdev != T3CDEV(newdev)) {
+               printk(KERN_WARNING "%s: Redirect to different "
+                      "offload device ignored.\n", __FUNCTION__);
+               return;
+       }
+
+       /* Add new L2T entry */
+       e = t3_l2t_get(tdev, new->neighbour, newdev);
+       if (!e) {
+               printk(KERN_ERR "%s: couldn't allocate new l2t entry!\n",
+                      __FUNCTION__);
+               return;
+       }
+
+       /* Walk tid table and notify clients of dst change. */
+       ti = &(T3C_DATA(tdev))->tid_maps;
+       for (tid = 0; tid < ti->ntids; tid++) {
+               te = lookup_tid(ti, tid);
+               BUG_ON(!te);
+               if (te->ctx && te->client && te->client->redirect) {
+                       update_tcb = te->client->redirect(te->ctx, old, new, e);
+                       if (update_tcb) {
+                               l2t_hold(L2DATA(tdev), e);
+                               set_l2t_ix(tdev, tid, e);
+                       }
+               }
+       }
+       l2t_release(L2DATA(tdev), e);
+}
+
+/*
+ * Allocate a chunk of memory using kmalloc or, if that fails, vmalloc.
+ * The allocated memory is cleared.
+ */
+void *cxgb_alloc_mem(unsigned long size)
+{
+       void *p = kmalloc(size, GFP_KERNEL);
+
+       if (!p)
+               p = vmalloc(size);
+       if (p)
+               memset(p, 0, size);
+       return p;
+}
+
+/*
+ * Free memory allocated through t3_alloc_mem().
+ */
+void cxgb_free_mem(void *addr)
+{
+       unsigned long p = (unsigned long)addr;
+
+       if (p >= VMALLOC_START && p < VMALLOC_END)
+               vfree(addr);
+       else
+               kfree(addr);
+}
+
+/*
+ * Allocate and initialize the TID tables.  Returns 0 on success.
+ */
+static int init_tid_tabs(struct tid_info *t, unsigned int ntids,
+                        unsigned int natids, unsigned int nstids,
+                        unsigned int atid_base, unsigned int stid_base)
+{
+       unsigned long size = ntids * sizeof(*t->tid_tab) +
+           natids * sizeof(*t->atid_tab) + nstids * sizeof(*t->stid_tab);
+
+       t->tid_tab = cxgb_alloc_mem(size);
+       if (!t->tid_tab)
+               return -ENOMEM;
+
+       t->stid_tab = (union listen_entry *)&t->tid_tab[ntids];
+       t->atid_tab = (union active_open_entry *)&t->stid_tab[nstids];
+       t->ntids = ntids;
+       t->nstids = nstids;
+       t->stid_base = stid_base;
+       t->sfree = NULL;
+       t->natids = natids;
+       t->atid_base = atid_base;
+       t->afree = NULL;
+       t->stids_in_use = t->atids_in_use = 0;
+       atomic_set(&t->tids_in_use, 0);
+       spin_lock_init(&t->stid_lock);
+       spin_lock_init(&t->atid_lock);
+
+       /*
+        * Setup the free lists for stid_tab and atid_tab.
+        */
+       if (nstids) {
+               while (--nstids)
+                       t->stid_tab[nstids - 1].next = &t->stid_tab[nstids];
+               t->sfree = t->stid_tab;
+       }
+       if (natids) {
+               while (--natids)
+                       t->atid_tab[natids - 1].next = &t->atid_tab[natids];
+               t->afree = t->atid_tab;
+       }
+       return 0;
+}
+
+static void free_tid_maps(struct tid_info *t)
+{
+       cxgb_free_mem(t->tid_tab);
+}
+
+static inline void add_adapter(struct adapter *adap)
+{
+       write_lock_bh(&adapter_list_lock);
+       list_add_tail(&adap->adapter_list, &adapter_list);
+       write_unlock_bh(&adapter_list_lock);
+}
+
+static inline void remove_adapter(struct adapter *adap)
+{
+       write_lock_bh(&adapter_list_lock);
+       list_del(&adap->adapter_list);
+       write_unlock_bh(&adapter_list_lock);
+}
+
+int cxgb3_offload_activate(struct adapter *adapter)
+{
+       struct t3cdev *dev = &adapter->tdev;
+       int natids, err;
+       struct t3c_data *t;
+       struct tid_range stid_range, tid_range;
+       struct mtutab mtutab;
+       unsigned int l2t_capacity;
+
+       t = kcalloc(1, sizeof(*t), GFP_KERNEL);
+       if (!t)
+               return -ENOMEM;
+
+       err = -EOPNOTSUPP;
+       if (dev->ctl(dev, GET_TX_MAX_CHUNK, &t->tx_max_chunk) < 0 ||
+           dev->ctl(dev, GET_MAX_OUTSTANDING_WR, &t->max_wrs) < 0 ||
+           dev->ctl(dev, GET_L2T_CAPACITY, &l2t_capacity) < 0 ||
+           dev->ctl(dev, GET_MTUS, &mtutab) < 0 ||
+           dev->ctl(dev, GET_TID_RANGE, &tid_range) < 0 ||
+           dev->ctl(dev, GET_STID_RANGE, &stid_range) < 0)
+               goto out_free;
+
+       err = -ENOMEM;
+       L2DATA(dev) = t3_init_l2t(l2t_capacity);
+       if (!L2DATA(dev))
+               goto out_free;
+
+       natids = min(tid_range.num / 2, MAX_ATIDS);
+       err = init_tid_tabs(&t->tid_maps, tid_range.num, natids,
+                           stid_range.num, ATID_BASE, stid_range.base);
+       if (err)
+               goto out_free_l2t;
+
+       t->mtus = mtutab.mtus;
+       t->nmtus = mtutab.size;
+
+       INIT_WORK(&t->tid_release_task, t3_process_tid_release_list);
+       spin_lock_init(&t->tid_release_lock);
+       INIT_LIST_HEAD(&t->list_node);
+       t->dev = dev;
+
+       T3C_DATA(dev) = t;
+       dev->recv = process_rx;
+       dev->neigh_update = t3_l2t_update;
+
+       /* Register netevent handler once */
+       if (list_empty(&adapter_list))
+               register_netevent_notifier(&nb);
+
+       add_adapter(adapter);
+       return 0;
+
+out_free_l2t:
+       t3_free_l2t(L2DATA(dev));
+       L2DATA(dev) = NULL;
+out_free:
+       kfree(t);
+       return err;
+}
+
+void cxgb3_offload_deactivate(struct adapter *adapter)
+{
+       struct t3cdev *tdev = &adapter->tdev;
+       struct t3c_data *t = T3C_DATA(tdev);
+
+       remove_adapter(adapter);
+       if (list_empty(&adapter_list))
+               unregister_netevent_notifier(&nb);
+
+       free_tid_maps(&t->tid_maps);
+       T3C_DATA(tdev) = NULL;
+       t3_free_l2t(L2DATA(tdev));
+       L2DATA(tdev) = NULL;
+       kfree(t);
+}
+
+static inline void register_tdev(struct t3cdev *tdev)
+{
+       static int unit;
+
+       mutex_lock(&cxgb3_db_lock);
+       snprintf(tdev->name, sizeof(tdev->name), "ofld_dev%d", unit++);
+       list_add_tail(&tdev->ofld_dev_list, &ofld_dev_list);
+       mutex_unlock(&cxgb3_db_lock);
+}
+
+static inline void unregister_tdev(struct t3cdev *tdev)
+{
+       mutex_lock(&cxgb3_db_lock);
+       list_del(&tdev->ofld_dev_list);
+       mutex_unlock(&cxgb3_db_lock);
+}
+
+void __devinit cxgb3_adapter_ofld(struct adapter *adapter)
+{
+       struct t3cdev *tdev = &adapter->tdev;
+
+       INIT_LIST_HEAD(&tdev->ofld_dev_list);
+
+       cxgb3_set_dummy_ops(tdev);
+       tdev->send = t3_offload_tx;
+       tdev->ctl = cxgb_offload_ctl;
+       tdev->type = adapter->params.rev == 0 ? T3A : T3B;
+
+       register_tdev(tdev);
+}
+
+void __devexit cxgb3_adapter_unofld(struct adapter *adapter)
+{
+       struct t3cdev *tdev = &adapter->tdev;
+
+       tdev->recv = NULL;
+       tdev->neigh_update = NULL;
+
+       unregister_tdev(tdev);
+}
+
+void __init cxgb3_offload_init(void)
+{
+       int i;
+
+       for (i = 0; i < NUM_CPL_CMDS; ++i)
+               cpl_handlers[i] = do_bad_cpl;
+
+       t3_register_cpl_handler(CPL_SMT_WRITE_RPL, do_smt_write_rpl);
+       t3_register_cpl_handler(CPL_L2T_WRITE_RPL, do_l2t_write_rpl);
+       t3_register_cpl_handler(CPL_PASS_OPEN_RPL, do_stid_rpl);
+       t3_register_cpl_handler(CPL_CLOSE_LISTSRV_RPL, do_stid_rpl);
+       t3_register_cpl_handler(CPL_PASS_ACCEPT_REQ, do_cr);
+       t3_register_cpl_handler(CPL_PASS_ESTABLISH, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_ABORT_RPL_RSS, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_ABORT_RPL, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_RX_URG_NOTIFY, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_RX_DATA, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_TX_DATA_ACK, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_TX_DMA_ACK, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_ACT_OPEN_RPL, do_act_open_rpl);
+       t3_register_cpl_handler(CPL_PEER_CLOSE, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_CLOSE_CON_RPL, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_ABORT_REQ_RSS, do_abort_req_rss);
+       t3_register_cpl_handler(CPL_ACT_ESTABLISH, do_act_establish);
+       t3_register_cpl_handler(CPL_SET_TCB_RPL, do_set_tcb_rpl);
+       t3_register_cpl_handler(CPL_RDMA_TERMINATE, do_term);
+       t3_register_cpl_handler(CPL_RDMA_EC_STATUS, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_TRACE_PKT, do_trace);
+       t3_register_cpl_handler(CPL_RX_DATA_DDP, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_RX_DDP_COMPLETE, do_hwtid_rpl);
+       t3_register_cpl_handler(CPL_ISCSI_HDR, do_hwtid_rpl);
+}
diff --git a/drivers/net/cxgb3/cxgb3_offload.h b/drivers/net/cxgb3/cxgb3_offload.h
new file mode 100644 (file)
index 0000000..0e6beb6
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef _CXGB3_OFFLOAD_H
+#define _CXGB3_OFFLOAD_H
+
+#include <linux/list.h>
+#include <linux/skbuff.h>
+
+#include "l2t.h"
+
+#include "t3cdev.h"
+#include "t3_cpl.h"
+
+struct adapter;
+
+void cxgb3_offload_init(void);
+
+void cxgb3_adapter_ofld(struct adapter *adapter);
+void cxgb3_adapter_unofld(struct adapter *adapter);
+int cxgb3_offload_activate(struct adapter *adapter);
+void cxgb3_offload_deactivate(struct adapter *adapter);
+
+void cxgb3_set_dummy_ops(struct t3cdev *dev);
+
+/*
+ * Client registration.  Users of T3 driver must register themselves.
+ * The T3 driver will call the add function of every client for each T3
+ * adapter activated, passing up the t3cdev ptr.  Each client fills out an
+ * array of callback functions to process CPL messages.
+ */
+
+void cxgb3_register_client(struct cxgb3_client *client);
+void cxgb3_unregister_client(struct cxgb3_client *client);
+void cxgb3_add_clients(struct t3cdev *tdev);
+void cxgb3_remove_clients(struct t3cdev *tdev);
+
+typedef int (*cxgb3_cpl_handler_func)(struct t3cdev *dev,
+                                     struct sk_buff *skb, void *ctx);
+
+struct cxgb3_client {
+       char *name;
+       void (*add) (struct t3cdev *);
+       void (*remove) (struct t3cdev *);
+       cxgb3_cpl_handler_func *handlers;
+       int (*redirect)(void *ctx, struct dst_entry *old,
+                       struct dst_entry *new, struct l2t_entry *l2t);
+       struct list_head client_list;
+};
+
+/*
+ * TID allocation services.
+ */
+int cxgb3_alloc_atid(struct t3cdev *dev, struct cxgb3_client *client,
+                    void *ctx);
+int cxgb3_alloc_stid(struct t3cdev *dev, struct cxgb3_client *client,
+                    void *ctx);
+void *cxgb3_free_atid(struct t3cdev *dev, int atid);
+void cxgb3_free_stid(struct t3cdev *dev, int stid);
+void cxgb3_insert_tid(struct t3cdev *dev, struct cxgb3_client *client,
+                     void *ctx, unsigned int tid);
+void cxgb3_queue_tid_release(struct t3cdev *dev, unsigned int tid);
+void cxgb3_remove_tid(struct t3cdev *dev, void *ctx, unsigned int tid);
+
+struct t3c_tid_entry {
+       struct cxgb3_client *client;
+       void *ctx;
+};
+
+/* CPL message priority levels */
+enum {
+       CPL_PRIORITY_DATA = 0,  /* data messages */
+       CPL_PRIORITY_SETUP = 1, /* connection setup messages */
+       CPL_PRIORITY_TEARDOWN = 0,      /* connection teardown messages */
+       CPL_PRIORITY_LISTEN = 1,        /* listen start/stop messages */
+       CPL_PRIORITY_ACK = 1,   /* RX ACK messages */
+       CPL_PRIORITY_CONTROL = 1        /* offload control messages */
+};
+
+/* Flags for return value of CPL message handlers */
+enum {
+       CPL_RET_BUF_DONE = 1, /* buffer processing done, buffer may be freed */
+       CPL_RET_BAD_MSG = 2,  /* bad CPL message (e.g., unknown opcode) */
+       CPL_RET_UNKNOWN_TID = 4 /* unexpected unknown TID */
+};
+
+typedef int (*cpl_handler_func)(struct t3cdev *dev, struct sk_buff *skb);
+
+/*
+ * Returns a pointer to the first byte of the CPL header in an sk_buff that
+ * contains a CPL message.
+ */
+static inline void *cplhdr(struct sk_buff *skb)
+{
+       return skb->data;
+}
+
+void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h);
+
+union listen_entry {
+       struct t3c_tid_entry t3c_tid;
+       union listen_entry *next;
+};
+
+union active_open_entry {
+       struct t3c_tid_entry t3c_tid;
+       union active_open_entry *next;
+};
+
+/*
+ * Holds the size, base address, free list start, etc of the TID, server TID,
+ * and active-open TID tables for a offload device.
+ * The tables themselves are allocated dynamically.
+ */
+struct tid_info {
+       struct t3c_tid_entry *tid_tab;
+       unsigned int ntids;
+       atomic_t tids_in_use;
+
+       union listen_entry *stid_tab;
+       unsigned int nstids;
+       unsigned int stid_base;
+
+       union active_open_entry *atid_tab;
+       unsigned int natids;
+       unsigned int atid_base;
+
+       /*
+        * The following members are accessed R/W so we put them in their own
+        * cache lines.
+        *
+        * XXX We could combine the atid fields above with the lock here since
+        * atids are use once (unlike other tids).  OTOH the above fields are
+        * usually in cache due to tid_tab.
+        */
+       spinlock_t atid_lock ____cacheline_aligned_in_smp;
+       union active_open_entry *afree;
+       unsigned int atids_in_use;
+
+       spinlock_t stid_lock ____cacheline_aligned;
+       union listen_entry *sfree;
+       unsigned int stids_in_use;
+};
+
+struct t3c_data {
+       struct list_head list_node;
+       struct t3cdev *dev;
+       unsigned int tx_max_chunk;      /* max payload for TX_DATA */
+       unsigned int max_wrs;   /* max in-flight WRs per connection */
+       unsigned int nmtus;
+       const unsigned short *mtus;
+       struct tid_info tid_maps;
+
+       struct t3c_tid_entry *tid_release_list;
+       spinlock_t tid_release_lock;
+       struct work_struct tid_release_task;
+};
+
+/*
+ * t3cdev -> t3c_data accessor
+ */
+#define T3C_DATA(dev) (*(struct t3c_data **)&(dev)->l4opt)
+
+#endif
diff --git a/drivers/net/cxgb3/firmware_exports.h b/drivers/net/cxgb3/firmware_exports.h
new file mode 100644 (file)
index 0000000..6a835f6
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2004-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef _FIRMWARE_EXPORTS_H_
+#define _FIRMWARE_EXPORTS_H_
+
+/* WR OPCODES supported by the firmware.
+ */
+#define        FW_WROPCODE_FORWARD                     0x01
+#define FW_WROPCODE_BYPASS                     0x05
+
+#define FW_WROPCODE_TUNNEL_TX_PKT              0x03
+
+#define FW_WROPOCDE_ULPTX_DATA_SGL             0x00
+#define FW_WROPCODE_ULPTX_MEM_READ             0x02
+#define FW_WROPCODE_ULPTX_PKT                  0x04
+#define FW_WROPCODE_ULPTX_INVALIDATE           0x06
+
+#define FW_WROPCODE_TUNNEL_RX_PKT              0x07
+
+#define FW_WROPCODE_OFLD_GETTCB_RPL            0x08
+#define FW_WROPCODE_OFLD_CLOSE_CON             0x09
+#define FW_WROPCODE_OFLD_TP_ABORT_CON_REQ      0x0A
+#define FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL    0x0F
+#define FW_WROPCODE_OFLD_HOST_ABORT_CON_REQ    0x0B
+#define FW_WROPCODE_OFLD_TP_ABORT_CON_RPL      0x0C
+#define FW_WROPCODE_OFLD_TX_DATA               0x0D
+#define FW_WROPCODE_OFLD_TX_DATA_ACK           0x0E
+
+#define FW_WROPCODE_RI_RDMA_INIT               0x10
+#define FW_WROPCODE_RI_RDMA_WRITE              0x11
+#define FW_WROPCODE_RI_RDMA_READ_REQ           0x12
+#define FW_WROPCODE_RI_RDMA_READ_RESP          0x13
+#define FW_WROPCODE_RI_SEND                    0x14
+#define FW_WROPCODE_RI_TERMINATE               0x15
+#define FW_WROPCODE_RI_RDMA_READ               0x16
+#define FW_WROPCODE_RI_RECEIVE                 0x17
+#define FW_WROPCODE_RI_BIND_MW                 0x18
+#define FW_WROPCODE_RI_FASTREGISTER_MR         0x19
+#define FW_WROPCODE_RI_LOCAL_INV               0x1A
+#define FW_WROPCODE_RI_MODIFY_QP               0x1B
+#define FW_WROPCODE_RI_BYPASS                  0x1C
+
+#define FW_WROPOCDE_RSVD                       0x1E
+
+#define FW_WROPCODE_SGE_EGRESSCONTEXT_RR       0x1F
+
+#define FW_WROPCODE_MNGT                       0x1D
+#define FW_MNGTOPCODE_PKTSCHED_SET             0x00
+
+/* Maximum size of a WR sent from the host, limited by the SGE. 
+ *
+ * Note: WR coming from ULP or TP are only limited by CIM. 
+ */
+#define FW_WR_SIZE                     128
+
+/* Maximum number of outstanding WRs sent from the host. Value must be
+ * programmed in the CTRL/TUNNEL/QP SGE Egress Context and used by 
+ * offload modules to limit the number of WRs per connection.
+ */
+#define FW_T3_WR_NUM                   16
+#define FW_N3_WR_NUM                   7
+
+#ifndef N3
+# define FW_WR_NUM                     FW_T3_WR_NUM
+#else
+# define FW_WR_NUM                     FW_N3_WR_NUM
+#endif
+
+/* FW_TUNNEL_NUM corresponds to the number of supported TUNNEL Queues. These
+ * queues must start at SGE Egress Context FW_TUNNEL_SGEEC_START and must
+ * start at 'TID' (or 'uP Token') FW_TUNNEL_TID_START.
+ *
+ * Ingress Traffic (e.g. DMA completion credit)  for TUNNEL Queue[i] is sent 
+ * to RESP Queue[i].
+ */
+#define FW_TUNNEL_NUM                  8
+#define FW_TUNNEL_SGEEC_START          8
+#define FW_TUNNEL_TID_START            65544
+
+/* FW_CTRL_NUM corresponds to the number of supported CTRL Queues. These queues
+ * must start at SGE Egress Context FW_CTRL_SGEEC_START and must start at 'TID'
+ * (or 'uP Token') FW_CTRL_TID_START.
+ *
+ * Ingress Traffic for CTRL Queue[i] is sent to RESP Queue[i].
+ */
+#define FW_CTRL_NUM                    8
+#define FW_CTRL_SGEEC_START            65528
+#define FW_CTRL_TID_START              65536
+
+/* FW_OFLD_NUM corresponds to the number of supported OFFLOAD Queues. These 
+ * queues must start at SGE Egress Context FW_OFLD_SGEEC_START. 
+ * 
+ * Note: the 'uP Token' in the SGE Egress Context fields is irrelevant for 
+ * OFFLOAD Queues, as the host is responsible for providing the correct TID in
+ * every WR.
+ *
+ * Ingress Trafffic for OFFLOAD Queue[i] is sent to RESP Queue[i].
+ */
+#define FW_OFLD_NUM                    8
+#define FW_OFLD_SGEEC_START            0
+
+/*
+ * 
+ */
+#define FW_RI_NUM                      1
+#define FW_RI_SGEEC_START              65527
+#define FW_RI_TID_START                        65552
+
+/*
+ * The RX_PKT_TID 
+ */
+#define FW_RX_PKT_NUM                  1
+#define FW_RX_PKT_TID_START            65553
+
+/* FW_WRC_NUM corresponds to the number of Work Request Context that supported
+ * by the firmware.
+ */
+#define FW_WRC_NUM                     \
+    (65536 + FW_TUNNEL_NUM + FW_CTRL_NUM + FW_RI_NUM + FW_RX_PKT_NUM)
+
+/*
+ * FW type and version.
+ */
+#define S_FW_VERSION_TYPE              28
+#define M_FW_VERSION_TYPE              0xF
+#define V_FW_VERSION_TYPE(x)           ((x) << S_FW_VERSION_TYPE)
+#define G_FW_VERSION_TYPE(x)           \
+    (((x) >> S_FW_VERSION_TYPE) & M_FW_VERSION_TYPE)
+
+#define S_FW_VERSION_MAJOR             16
+#define M_FW_VERSION_MAJOR             0xFFF
+#define V_FW_VERSION_MAJOR(x)          ((x) << S_FW_VERSION_MAJOR)
+#define G_FW_VERSION_MAJOR(x)          \
+    (((x) >> S_FW_VERSION_MAJOR) & M_FW_VERSION_MAJOR)
+
+#define S_FW_VERSION_MINOR             8
+#define M_FW_VERSION_MINOR             0xFF
+#define V_FW_VERSION_MINOR(x)          ((x) << S_FW_VERSION_MINOR)
+#define G_FW_VERSION_MINOR(x)          \
+    (((x) >> S_FW_VERSION_MINOR) & M_FW_VERSION_MINOR)
+
+#define S_FW_VERSION_MICRO             0
+#define M_FW_VERSION_MICRO             0xFF
+#define V_FW_VERSION_MICRO(x)          ((x) << S_FW_VERSION_MICRO)
+#define G_FW_VERSION_MICRO(x)          \
+    (((x) >> S_FW_VERSION_MICRO) & M_FW_VERSION_MICRO)
+
+#endif                         /* _FIRMWARE_EXPORTS_H_ */
diff --git a/drivers/net/cxgb3/l2t.c b/drivers/net/cxgb3/l2t.c
new file mode 100644 (file)
index 0000000..3c0cb85
--- /dev/null
@@ -0,0 +1,450 @@
+/*
+ * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include <linux/skbuff.h>
+#include <linux/netdevice.h>
+#include <linux/if.h>
+#include <linux/if_vlan.h>
+#include <linux/jhash.h>
+#include <net/neighbour.h>
+#include "common.h"
+#include "t3cdev.h"
+#include "cxgb3_defs.h"
+#include "l2t.h"
+#include "t3_cpl.h"
+#include "firmware_exports.h"
+
+#define VLAN_NONE 0xfff
+
+/*
+ * Module locking notes:  There is a RW lock protecting the L2 table as a
+ * whole plus a spinlock per L2T entry.  Entry lookups and allocations happen
+ * under the protection of the table lock, individual entry changes happen
+ * while holding that entry's spinlock.  The table lock nests outside the
+ * entry locks.  Allocations of new entries take the table lock as writers so
+ * no other lookups can happen while allocating new entries.  Entry updates
+ * take the table lock as readers so multiple entries can be updated in
+ * parallel.  An L2T entry can be dropped by decrementing its reference count
+ * and therefore can happen in parallel with entry allocation but no entry
+ * can change state or increment its ref count during allocation as both of
+ * these perform lookups.
+ */
+
+static inline unsigned int vlan_prio(const struct l2t_entry *e)
+{
+       return e->vlan >> 13;
+}
+
+static inline unsigned int arp_hash(u32 key, int ifindex,
+                                   const struct l2t_data *d)
+{
+       return jhash_2words(key, ifindex, 0) & (d->nentries - 1);
+}
+
+static inline void neigh_replace(struct l2t_entry *e, struct neighbour *n)
+{
+       neigh_hold(n);
+       if (e->neigh)
+               neigh_release(e->neigh);
+       e->neigh = n;
+}
+
+/*
+ * Set up an L2T entry and send any packets waiting in the arp queue.  The
+ * supplied skb is used for the CPL_L2T_WRITE_REQ.  Must be called with the
+ * entry locked.
+ */
+static int setup_l2e_send_pending(struct t3cdev *dev, struct sk_buff *skb,
+                                 struct l2t_entry *e)
+{
+       struct cpl_l2t_write_req *req;
+
+       if (!skb) {
+               skb = alloc_skb(sizeof(*req), GFP_ATOMIC);
+               if (!skb)
+                       return -ENOMEM;
+       }
+
+       req = (struct cpl_l2t_write_req *)__skb_put(skb, sizeof(*req));
+       req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
+       OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_L2T_WRITE_REQ, e->idx));
+       req->params = htonl(V_L2T_W_IDX(e->idx) | V_L2T_W_IFF(e->smt_idx) |
+                           V_L2T_W_VLAN(e->vlan & VLAN_VID_MASK) |
+                           V_L2T_W_PRIO(vlan_prio(e)));
+       memcpy(e->dmac, e->neigh->ha, sizeof(e->dmac));
+       memcpy(req->dst_mac, e->dmac, sizeof(req->dst_mac));
+       skb->priority = CPL_PRIORITY_CONTROL;
+       cxgb3_ofld_send(dev, skb);
+       while (e->arpq_head) {
+               skb = e->arpq_head;
+               e->arpq_head = skb->next;
+               skb->next = NULL;
+               cxgb3_ofld_send(dev, skb);
+       }
+       e->arpq_tail = NULL;
+       e->state = L2T_STATE_VALID;
+
+       return 0;
+}
+
+/*
+ * Add a packet to the an L2T entry's queue of packets awaiting resolution.
+ * Must be called with the entry's lock held.
+ */
+static inline void arpq_enqueue(struct l2t_entry *e, struct sk_buff *skb)
+{
+       skb->next = NULL;
+       if (e->arpq_head)
+               e->arpq_tail->next = skb;
+       else
+               e->arpq_head = skb;
+       e->arpq_tail = skb;
+}
+
+int t3_l2t_send_slow(struct t3cdev *dev, struct sk_buff *skb,
+                    struct l2t_entry *e)
+{
+again:
+       switch (e->state) {
+       case L2T_STATE_STALE:   /* entry is stale, kick off revalidation */
+               neigh_event_send(e->neigh, NULL);
+               spin_lock_bh(&e->lock);
+               if (e->state == L2T_STATE_STALE)
+                       e->state = L2T_STATE_VALID;
+               spin_unlock_bh(&e->lock);
+       case L2T_STATE_VALID:   /* fast-path, send the packet on */
+               return cxgb3_ofld_send(dev, skb);
+       case L2T_STATE_RESOLVING:
+               spin_lock_bh(&e->lock);
+               if (e->state != L2T_STATE_RESOLVING) {
+                       /* ARP already completed */
+                       spin_unlock_bh(&e->lock);
+                       goto again;
+               }
+               arpq_enqueue(e, skb);
+               spin_unlock_bh(&e->lock);
+
+               /*
+                * Only the first packet added to the arpq should kick off
+                * resolution.  However, because the alloc_skb below can fail,
+                * we allow each packet added to the arpq to retry resolution
+                * as a way of recovering from transient memory exhaustion.
+                * A better way would be to use a work request to retry L2T
+                * entries when there's no memory.
+                */
+               if (!neigh_event_send(e->neigh, NULL)) {
+                       skb = alloc_skb(sizeof(struct cpl_l2t_write_req),
+                                       GFP_ATOMIC);
+                       if (!skb)
+                               break;
+
+                       spin_lock_bh(&e->lock);
+                       if (e->arpq_head)
+                               setup_l2e_send_pending(dev, skb, e);
+                       else    /* we lost the race */
+                               __kfree_skb(skb);
+                       spin_unlock_bh(&e->lock);
+               }
+       }
+       return 0;
+}
+
+EXPORT_SYMBOL(t3_l2t_send_slow);
+
+void t3_l2t_send_event(struct t3cdev *dev, struct l2t_entry *e)
+{
+again:
+       switch (e->state) {
+       case L2T_STATE_STALE:   /* entry is stale, kick off revalidation */
+               neigh_event_send(e->neigh, NULL);
+               spin_lock_bh(&e->lock);
+               if (e->state == L2T_STATE_STALE) {
+                       e->state = L2T_STATE_VALID;
+               }
+               spin_unlock_bh(&e->lock);
+               return;
+       case L2T_STATE_VALID:   /* fast-path, send the packet on */
+               return;
+       case L2T_STATE_RESOLVING:
+               spin_lock_bh(&e->lock);
+               if (e->state != L2T_STATE_RESOLVING) {
+                       /* ARP already completed */
+                       spin_unlock_bh(&e->lock);
+                       goto again;
+               }
+               spin_unlock_bh(&e->lock);
+
+               /*
+                * Only the first packet added to the arpq should kick off
+                * resolution.  However, because the alloc_skb below can fail,
+                * we allow each packet added to the arpq to retry resolution
+                * as a way of recovering from transient memory exhaustion.
+                * A better way would be to use a work request to retry L2T
+                * entries when there's no memory.
+                */
+               neigh_event_send(e->neigh, NULL);
+       }
+       return;
+}
+
+EXPORT_SYMBOL(t3_l2t_send_event);
+
+/*
+ * Allocate a free L2T entry.  Must be called with l2t_data.lock held.
+ */
+static struct l2t_entry *alloc_l2e(struct l2t_data *d)
+{
+       struct l2t_entry *end, *e, **p;
+
+       if (!atomic_read(&d->nfree))
+               return NULL;
+
+       /* there's definitely a free entry */
+       for (e = d->rover, end = &d->l2tab[d->nentries]; e != end; ++e)
+               if (atomic_read(&e->refcnt) == 0)
+                       goto found;
+
+       for (e = &d->l2tab[1]; atomic_read(&e->refcnt); ++e) ;
+found:
+       d->rover = e + 1;
+       atomic_dec(&d->nfree);
+
+       /*
+        * The entry we found may be an inactive entry that is
+        * presently in the hash table.  We need to remove it.
+        */
+       if (e->state != L2T_STATE_UNUSED) {
+               int hash = arp_hash(e->addr, e->ifindex, d);
+
+               for (p = &d->l2tab[hash].first; *p; p = &(*p)->next)
+                       if (*p == e) {
+                               *p = e->next;
+                               break;
+                       }
+               e->state = L2T_STATE_UNUSED;
+       }
+       return e;
+}
+
+/*
+ * Called when an L2T entry has no more users.  The entry is left in the hash
+ * table since it is likely to be reused but we also bump nfree to indicate
+ * that the entry can be reallocated for a different neighbor.  We also drop
+ * the existing neighbor reference in case the neighbor is going away and is
+ * waiting on our reference.
+ *
+ * Because entries can be reallocated to other neighbors once their ref count
+ * drops to 0 we need to take the entry's lock to avoid races with a new
+ * incarnation.
+ */
+void t3_l2e_free(struct l2t_data *d, struct l2t_entry *e)
+{
+       spin_lock_bh(&e->lock);
+       if (atomic_read(&e->refcnt) == 0) {     /* hasn't been recycled */
+               if (e->neigh) {
+                       neigh_release(e->neigh);
+                       e->neigh = NULL;
+               }
+       }
+       spin_unlock_bh(&e->lock);
+       atomic_inc(&d->nfree);
+}
+
+EXPORT_SYMBOL(t3_l2e_free);
+
+/*
+ * Update an L2T entry that was previously used for the same next hop as neigh.
+ * Must be called with softirqs disabled.
+ */
+static inline void reuse_entry(struct l2t_entry *e, struct neighbour *neigh)
+{
+       unsigned int nud_state;
+
+       spin_lock(&e->lock);    /* avoid race with t3_l2t_free */
+
+       if (neigh != e->neigh)
+               neigh_replace(e, neigh);
+       nud_state = neigh->nud_state;
+       if (memcmp(e->dmac, neigh->ha, sizeof(e->dmac)) ||
+           !(nud_state & NUD_VALID))
+               e->state = L2T_STATE_RESOLVING;
+       else if (nud_state & NUD_CONNECTED)
+               e->state = L2T_STATE_VALID;
+       else
+               e->state = L2T_STATE_STALE;
+       spin_unlock(&e->lock);
+}
+
+struct l2t_entry *t3_l2t_get(struct t3cdev *cdev, struct neighbour *neigh,
+                            struct net_device *dev)
+{
+       struct l2t_entry *e;
+       struct l2t_data *d = L2DATA(cdev);
+       u32 addr = *(u32 *) neigh->primary_key;
+       int ifidx = neigh->dev->ifindex;
+       int hash = arp_hash(addr, ifidx, d);
+       struct port_info *p = netdev_priv(dev);
+       int smt_idx = p->port_id;
+
+       write_lock_bh(&d->lock);
+       for (e = d->l2tab[hash].first; e; e = e->next)
+               if (e->addr == addr && e->ifindex == ifidx &&
+                   e->smt_idx == smt_idx) {
+                       l2t_hold(d, e);
+                       if (atomic_read(&e->refcnt) == 1)
+                               reuse_entry(e, neigh);
+                       goto done;
+               }
+
+       /* Need to allocate a new entry */
+       e = alloc_l2e(d);
+       if (e) {
+               spin_lock(&e->lock);    /* avoid race with t3_l2t_free */
+               e->next = d->l2tab[hash].first;
+               d->l2tab[hash].first = e;
+               e->state = L2T_STATE_RESOLVING;
+               e->addr = addr;
+               e->ifindex = ifidx;
+               e->smt_idx = smt_idx;
+               atomic_set(&e->refcnt, 1);
+               neigh_replace(e, neigh);
+               if (neigh->dev->priv_flags & IFF_802_1Q_VLAN)
+                       e->vlan = VLAN_DEV_INFO(neigh->dev)->vlan_id;
+               else
+                       e->vlan = VLAN_NONE;
+               spin_unlock(&e->lock);
+       }
+done:
+       write_unlock_bh(&d->lock);
+       return e;
+}
+
+EXPORT_SYMBOL(t3_l2t_get);
+
+/*
+ * Called when address resolution fails for an L2T entry to handle packets
+ * on the arpq head.  If a packet specifies a failure handler it is invoked,
+ * otherwise the packets is sent to the offload device.
+ *
+ * XXX: maybe we should abandon the latter behavior and just require a failure
+ * handler.
+ */
+static void handle_failed_resolution(struct t3cdev *dev, struct sk_buff *arpq)
+{
+       while (arpq) {
+               struct sk_buff *skb = arpq;
+               struct l2t_skb_cb *cb = L2T_SKB_CB(skb);
+
+               arpq = skb->next;
+               skb->next = NULL;
+               if (cb->arp_failure_handler)
+                       cb->arp_failure_handler(dev, skb);
+               else
+                       cxgb3_ofld_send(dev, skb);
+       }
+}
+
+/*
+ * Called when the host's ARP layer makes a change to some entry that is
+ * loaded into the HW L2 table.
+ */
+void t3_l2t_update(struct t3cdev *dev, struct neighbour *neigh)
+{
+       struct l2t_entry *e;
+       struct sk_buff *arpq = NULL;
+       struct l2t_data *d = L2DATA(dev);
+       u32 addr = *(u32 *) neigh->primary_key;
+       int ifidx = neigh->dev->ifindex;
+       int hash = arp_hash(addr, ifidx, d);
+
+       read_lock_bh(&d->lock);
+       for (e = d->l2tab[hash].first; e; e = e->next)
+               if (e->addr == addr && e->ifindex == ifidx) {
+                       spin_lock(&e->lock);
+                       goto found;
+               }
+       read_unlock_bh(&d->lock);
+       return;
+
+found:
+       read_unlock(&d->lock);
+       if (atomic_read(&e->refcnt)) {
+               if (neigh != e->neigh)
+                       neigh_replace(e, neigh);
+
+               if (e->state == L2T_STATE_RESOLVING) {
+                       if (neigh->nud_state & NUD_FAILED) {
+                               arpq = e->arpq_head;
+                               e->arpq_head = e->arpq_tail = NULL;
+                       } else if (neigh_is_connected(neigh))
+                               setup_l2e_send_pending(dev, NULL, e);
+               } else {
+                       e->state = neigh_is_connected(neigh) ?
+                           L2T_STATE_VALID : L2T_STATE_STALE;
+                       if (memcmp(e->dmac, neigh->ha, 6))
+                               setup_l2e_send_pending(dev, NULL, e);
+               }
+       }
+       spin_unlock_bh(&e->lock);
+
+       if (arpq)
+               handle_failed_resolution(dev, arpq);
+}
+
+struct l2t_data *t3_init_l2t(unsigned int l2t_capacity)
+{
+       struct l2t_data *d;
+       int i, size = sizeof(*d) + l2t_capacity * sizeof(struct l2t_entry);
+
+       d = cxgb_alloc_mem(size);
+       if (!d)
+               return NULL;
+
+       d->nentries = l2t_capacity;
+       d->rover = &d->l2tab[1];        /* entry 0 is not used */
+       atomic_set(&d->nfree, l2t_capacity - 1);
+       rwlock_init(&d->lock);
+
+       for (i = 0; i < l2t_capacity; ++i) {
+               d->l2tab[i].idx = i;
+               d->l2tab[i].state = L2T_STATE_UNUSED;
+               spin_lock_init(&d->l2tab[i].lock);
+               atomic_set(&d->l2tab[i].refcnt, 0);
+       }
+       return d;
+}
+
+void t3_free_l2t(struct l2t_data *d)
+{
+       cxgb_free_mem(d);
+}
+
diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
new file mode 100644 (file)
index 0000000..ba5d2cb
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef _CHELSIO_L2T_H
+#define _CHELSIO_L2T_H
+
+#include <linux/spinlock.h>
+#include "t3cdev.h"
+#include <asm/atomic.h>
+
+enum {
+       L2T_STATE_VALID,        /* entry is up to date */
+       L2T_STATE_STALE,        /* entry may be used but needs revalidation */
+       L2T_STATE_RESOLVING,    /* entry needs address resolution */
+       L2T_STATE_UNUSED        /* entry not in use */
+};
+
+struct neighbour;
+struct sk_buff;
+
+/*
+ * Each L2T entry plays multiple roles.  First of all, it keeps state for the
+ * corresponding entry of the HW L2 table and maintains a queue of offload
+ * packets awaiting address resolution.  Second, it is a node of a hash table
+ * chain, where the nodes of the chain are linked together through their next
+ * pointer.  Finally, each node is a bucket of a hash table, pointing to the
+ * first element in its chain through its first pointer.
+ */
+struct l2t_entry {
+       u16 state;              /* entry state */
+       u16 idx;                /* entry index */
+       u32 addr;               /* dest IP address */
+       int ifindex;            /* neighbor's net_device's ifindex */
+       u16 smt_idx;            /* SMT index */
+       u16 vlan;               /* VLAN TCI (id: bits 0-11, prio: 13-15 */
+       struct neighbour *neigh;        /* associated neighbour */
+       struct l2t_entry *first;        /* start of hash chain */
+       struct l2t_entry *next; /* next l2t_entry on chain */
+       struct sk_buff *arpq_head;      /* queue of packets awaiting resolution */
+       struct sk_buff *arpq_tail;
+       spinlock_t lock;
+       atomic_t refcnt;        /* entry reference count */
+       u8 dmac[6];             /* neighbour's MAC address */
+};
+
+struct l2t_data {
+       unsigned int nentries;  /* number of entries */
+       struct l2t_entry *rover;        /* starting point for next allocation */
+       atomic_t nfree;         /* number of free entries */
+       rwlock_t lock;
+       struct l2t_entry l2tab[0];
+};
+
+typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
+                                        struct sk_buff * skb);
+
+/*
+ * Callback stored in an skb to handle address resolution failure.
+ */
+struct l2t_skb_cb {
+       arp_failure_handler_func arp_failure_handler;
+};
+
+#define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
+
+static inline void set_arp_failure_handler(struct sk_buff *skb,
+                                          arp_failure_handler_func hnd)
+{
+       L2T_SKB_CB(skb)->arp_failure_handler = hnd;
+}
+
+/*
+ * Getting to the L2 data from an offload device.
+ */
+#define L2DATA(dev) ((dev)->l2opt)
+
+#define W_TCB_L2T_IX    0
+#define S_TCB_L2T_IX    7
+#define M_TCB_L2T_IX    0x7ffULL
+#define V_TCB_L2T_IX(x) ((x) << S_TCB_L2T_IX)
+
+void t3_l2e_free(struct l2t_data *d, struct l2t_entry *e);
+void t3_l2t_update(struct t3cdev *dev, struct neighbour *neigh);
+struct l2t_entry *t3_l2t_get(struct t3cdev *cdev, struct neighbour *neigh,
+                            struct net_device *dev);
+int t3_l2t_send_slow(struct t3cdev *dev, struct sk_buff *skb,
+                    struct l2t_entry *e);
+void t3_l2t_send_event(struct t3cdev *dev, struct l2t_entry *e);
+struct l2t_data *t3_init_l2t(unsigned int l2t_capacity);
+void t3_free_l2t(struct l2t_data *d);
+
+int cxgb3_ofld_send(struct t3cdev *dev, struct sk_buff *skb);
+
+static inline int l2t_send(struct t3cdev *dev, struct sk_buff *skb,
+                          struct l2t_entry *e)
+{
+       if (likely(e->state == L2T_STATE_VALID))
+               return cxgb3_ofld_send(dev, skb);
+       return t3_l2t_send_slow(dev, skb, e);
+}
+
+static inline void l2t_release(struct l2t_data *d, struct l2t_entry *e)
+{
+       if (atomic_dec_and_test(&e->refcnt))
+               t3_l2e_free(d, e);
+}
+
+static inline void l2t_hold(struct l2t_data *d, struct l2t_entry *e)
+{
+       if (atomic_add_return(1, &e->refcnt) == 1)      /* 0 -> 1 transition */
+               atomic_dec(&d->nfree);
+}
+
+#endif
diff --git a/drivers/net/cxgb3/mc5.c b/drivers/net/cxgb3/mc5.c
new file mode 100644 (file)
index 0000000..644d62e
--- /dev/null
@@ -0,0 +1,473 @@
+/*
+ * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "common.h"
+#include "regs.h"
+
+enum {
+       IDT75P52100 = 4,
+       IDT75N43102 = 5
+};
+
+/* DBGI command mode */
+enum {
+       DBGI_MODE_MBUS = 0,
+       DBGI_MODE_IDT52100 = 5
+};
+
+/* IDT 75P52100 commands */
+#define IDT_CMD_READ   0
+#define IDT_CMD_WRITE  1
+#define IDT_CMD_SEARCH 2
+#define IDT_CMD_LEARN  3
+
+/* IDT LAR register address and value for 144-bit mode (low 32 bits) */
+#define IDT_LAR_ADR0           0x180006
+#define IDT_LAR_MODE144        0xffff0000
+
+/* IDT SCR and SSR addresses (low 32 bits) */
+#define IDT_SCR_ADR0  0x180000
+#define IDT_SSR0_ADR0 0x180002
+#define IDT_SSR1_ADR0 0x180004
+
+/* IDT GMR base address (low 32 bits) */
+#define IDT_GMR_BASE_ADR0 0x180020
+
+/* IDT data and mask array base addresses (low 32 bits) */
+#define IDT_DATARY_BASE_ADR0 0
+#define IDT_MSKARY_BASE_ADR0 0x80000
+
+/* IDT 75N43102 commands */
+#define IDT4_CMD_SEARCH144 3
+#define IDT4_CMD_WRITE     4
+#define IDT4_CMD_READ      5
+
+/* IDT 75N43102 SCR address (low 32 bits) */
+#define IDT4_SCR_ADR0  0x3
+
+/* IDT 75N43102 GMR base addresses (low 32 bits) */
+#define IDT4_GMR_BASE0 0x10
+#define IDT4_GMR_BASE1 0x20
+#define IDT4_GMR_BASE2 0x30
+
+/* IDT 75N43102 data and mask array base addresses (low 32 bits) */
+#define IDT4_DATARY_BASE_ADR0 0x1000000
+#define IDT4_MSKARY_BASE_ADR0 0x2000000
+
+#define MAX_WRITE_ATTEMPTS 5
+
+#define MAX_ROUTES 2048
+
+/*
+ * Issue a command to the TCAM and wait for its completion.  The address and
+ * any data required by the command must have been setup by the caller.
+ */
+static int mc5_cmd_write(struct adapter *adapter, u32 cmd)
+{
+       t3_write_reg(adapter, A_MC5_DB_DBGI_REQ_CMD, cmd);
+       return t3_wait_op_done(adapter, A_MC5_DB_DBGI_RSP_STATUS,
+                              F_DBGIRSPVALID, 1, MAX_WRITE_ATTEMPTS, 1);
+}
+
+static inline void dbgi_wr_addr3(struct adapter *adapter, u32 v1, u32 v2,
+                                u32 v3)
+{
+       t3_write_reg(adapter, A_MC5_DB_DBGI_REQ_ADDR0, v1);
+       t3_write_reg(adapter, A_MC5_DB_DBGI_REQ_ADDR1, v2);
+       t3_write_reg(adapter, A_MC5_DB_DBGI_REQ_ADDR2, v3);
+}
+
+static inline void dbgi_wr_data3(struct adapter *adapter, u32 v1, u32 v2,
+                                u32 v3)
+{
+       t3_write_reg(adapter, A_MC5_DB_DBGI_REQ_DATA0, v1);
+       t3_write_reg(adapter, A_MC5_DB_DBGI_REQ_DATA1, v2);
+       t3_write_reg(adapter, A_MC5_DB_DBGI_REQ_DATA2, v3);
+}
+
+static inline void dbgi_rd_rsp3(struct adapter *adapter, u32 *v1, u32 *v2,
+                               u32 *v3)
+{
+       *v1 = t3_read_reg(adapter, A_MC5_DB_DBGI_RSP_DATA0);
+       *v2 = t3_read_reg(adapter, A_MC5_DB_DBGI_RSP_DATA1);
+       *v3 = t3_read_reg(adapter, A_MC5_DB_DBGI_RSP_DATA2);
+}
+
+/*
+ * Write data to the TCAM register at address (0, 0, addr_lo) using the TCAM
+ * command cmd.  The data to be written must have been set up by the caller.
+ * Returns -1 on failure, 0 on success.
+ */
+static int mc5_write(struct adapter *adapter, u32 addr_lo, u32 cmd)
+{
+       t3_write_reg(adapter, A_MC5_DB_DBGI_REQ_ADDR0, addr_lo);
+       if (mc5_cmd_write(adapter, cmd) == 0)
+               return 0;
+       CH_ERR(adapter, "MC5 timeout writing to TCAM address 0x%x\n",
+              addr_lo);
+       return -1;
+}
+
+static int init_mask_data_array(struct mc5 *mc5, u32 mask_array_base,
+                               u32 data_array_base, u32 write_cmd,
+                               int addr_shift)
+{
+       unsigned int i;
+       struct adapter *adap = mc5->adapter;
+
+       /*
+        * We need the size of the TCAM data and mask arrays in terms of
+        * 72-bit entries.
+        */
+       unsigned int size72 = mc5->tcam_size;
+       unsigned int server_base = t3_read_reg(adap, A_MC5_DB_SERVER_INDEX);
+
+       if (mc5->mode == MC5_MODE_144_BIT) {
+               size72 *= 2;    /* 1 144-bit entry is 2 72-bit entries */
+               server_base *= 2;
+       }
+
+       /* Clear the data array */
+       dbgi_wr_data3(adap, 0, 0, 0);
+       for (i = 0; i < size72; i++)
+               if (mc5_write(adap, data_array_base + (i << addr_shift),
+                             write_cmd))
+                       return -1;
+
+       /* Initialize the mask array. */
+       dbgi_wr_data3(adap, 0xffffffff, 0xffffffff, 0xff);
+       for (i = 0; i < size72; i++) {
+               if (i == server_base)   /* entering server or routing region */
+                       t3_write_reg(adap, A_MC5_DB_DBGI_REQ_DATA0,
+                                    mc5->mode == MC5_MODE_144_BIT ?
+                                    0xfffffff9 : 0xfffffffd);
+               if (mc5_write(adap, mask_array_base + (i << addr_shift),
+                             write_cmd))
+                       return -1;
+       }
+       return 0;
+}
+
+static int init_idt52100(struct mc5 *mc5)
+{
+       int i;
+       struct adapter *adap = mc5->adapter;
+
+       t3_write_reg(adap, A_MC5_DB_RSP_LATENCY,
+                    V_RDLAT(0x15) | V_LRNLAT(0x15) | V_SRCHLAT(0x15));
+       t3_write_reg(adap, A_MC5_DB_PART_ID_INDEX, 2);
+
+       /*
+        * Use GMRs 14-15 for ELOOKUP, GMRs 12-13 for SYN lookups, and
+        * GMRs 8-9 for ACK- and AOPEN searches.
+        */
+       t3_write_reg(adap, A_MC5_DB_POPEN_DATA_WR_CMD, IDT_CMD_WRITE);
+       t3_write_reg(adap, A_MC5_DB_POPEN_MASK_WR_CMD, IDT_CMD_WRITE);
+       t3_write_reg(adap, A_MC5_DB_AOPEN_SRCH_CMD, IDT_CMD_SEARCH);
+       t3_write_reg(adap, A_MC5_DB_AOPEN_LRN_CMD, IDT_CMD_LEARN);
+       t3_write_reg(adap, A_MC5_DB_SYN_SRCH_CMD, IDT_CMD_SEARCH | 0x6000);
+       t3_write_reg(adap, A_MC5_DB_SYN_LRN_CMD, IDT_CMD_LEARN);
+       t3_write_reg(adap, A_MC5_DB_ACK_SRCH_CMD, IDT_CMD_SEARCH);
+       t3_write_reg(adap, A_MC5_DB_ACK_LRN_CMD, IDT_CMD_LEARN);
+       t3_write_reg(adap, A_MC5_DB_ILOOKUP_CMD, IDT_CMD_SEARCH);
+       t3_write_reg(adap, A_MC5_DB_ELOOKUP_CMD, IDT_CMD_SEARCH | 0x7000);
+       t3_write_reg(adap, A_MC5_DB_DATA_WRITE_CMD, IDT_CMD_WRITE);
+       t3_write_reg(adap, A_MC5_DB_DATA_READ_CMD, IDT_CMD_READ);
+
+       /* Set DBGI command mode for IDT TCAM. */
+       t3_write_reg(adap, A_MC5_DB_DBGI_CONFIG, DBGI_MODE_IDT52100);
+
+       /* Set up LAR */
+       dbgi_wr_data3(adap, IDT_LAR_MODE144, 0, 0);
+       if (mc5_write(adap, IDT_LAR_ADR0, IDT_CMD_WRITE))
+               goto err;
+
+       /* Set up SSRs */
+       dbgi_wr_data3(adap, 0xffffffff, 0xffffffff, 0);
+       if (mc5_write(adap, IDT_SSR0_ADR0, IDT_CMD_WRITE) ||
+           mc5_write(adap, IDT_SSR1_ADR0, IDT_CMD_WRITE))
+               goto err;
+
+       /* Set up GMRs */
+       for (i = 0; i < 32; ++i) {
+               if (i >= 12 && i < 15)
+                       dbgi_wr_data3(adap, 0xfffffff9, 0xffffffff, 0xff);
+               else if (i == 15)
+                       dbgi_wr_data3(adap, 0xfffffff9, 0xffff8007, 0xff);
+               else
+                       dbgi_wr_data3(adap, 0xffffffff, 0xffffffff, 0xff);
+
+               if (mc5_write(adap, IDT_GMR_BASE_ADR0 + i, IDT_CMD_WRITE))
+                       goto err;
+       }
+
+       /* Set up SCR */
+       dbgi_wr_data3(adap, 1, 0, 0);
+       if (mc5_write(adap, IDT_SCR_ADR0, IDT_CMD_WRITE))
+               goto err;
+
+       return init_mask_data_array(mc5, IDT_MSKARY_BASE_ADR0,
+                                   IDT_DATARY_BASE_ADR0, IDT_CMD_WRITE, 0);
+err:
+       return -EIO;
+}
+
+static int init_idt43102(struct mc5 *mc5)
+{
+       int i;
+       struct adapter *adap = mc5->adapter;
+
+       t3_write_reg(adap, A_MC5_DB_RSP_LATENCY,
+                    adap->params.rev == 0 ? V_RDLAT(0xd) | V_SRCHLAT(0x11) :
+                    V_RDLAT(0xd) | V_SRCHLAT(0x12));
+
+       /*
+        * Use GMRs 24-25 for ELOOKUP, GMRs 20-21 for SYN lookups, and no mask
+        * for ACK- and AOPEN searches.
+        */
+       t3_write_reg(adap, A_MC5_DB_POPEN_DATA_WR_CMD, IDT4_CMD_WRITE);
+       t3_write_reg(adap, A_MC5_DB_POPEN_MASK_WR_CMD, IDT4_CMD_WRITE);
+       t3_write_reg(adap, A_MC5_DB_AOPEN_SRCH_CMD,
+                    IDT4_CMD_SEARCH144 | 0x3800);
+       t3_write_reg(adap, A_MC5_DB_SYN_SRCH_CMD, IDT4_CMD_SEARCH144);
+       t3_write_reg(adap, A_MC5_DB_ACK_SRCH_CMD, IDT4_CMD_SEARCH144 | 0x3800);
+       t3_write_reg(adap, A_MC5_DB_ILOOKUP_CMD, IDT4_CMD_SEARCH144 | 0x3800);
+       t3_write_reg(adap, A_MC5_DB_ELOOKUP_CMD, IDT4_CMD_SEARCH144 | 0x800);
+       t3_write_reg(adap, A_MC5_DB_DATA_WRITE_CMD, IDT4_CMD_WRITE);
+       t3_write_reg(adap, A_MC5_DB_DATA_READ_CMD, IDT4_CMD_READ);
+
+       t3_write_reg(adap, A_MC5_DB_PART_ID_INDEX, 3);
+
+       /* Set DBGI command mode for IDT TCAM. */
+       t3_write_reg(adap, A_MC5_DB_DBGI_CONFIG, DBGI_MODE_IDT52100);
+
+       /* Set up GMRs */
+       dbgi_wr_data3(adap, 0xffffffff, 0xffffffff, 0xff);
+       for (i = 0; i < 7; ++i)
+               if (mc5_write(adap, IDT4_GMR_BASE0 + i, IDT4_CMD_WRITE))
+                       goto err;
+
+       for (i = 0; i < 4; ++i)
+               if (mc5_write(adap, IDT4_GMR_BASE2 + i, IDT4_CMD_WRITE))
+                       goto err;
+
+       dbgi_wr_data3(adap, 0xfffffff9, 0xffffffff, 0xff);
+       if (mc5_write(adap, IDT4_GMR_BASE1, IDT4_CMD_WRITE) ||
+           mc5_write(adap, IDT4_GMR_BASE1 + 1, IDT4_CMD_WRITE) ||
+           mc5_write(adap, IDT4_GMR_BASE1 + 4, IDT4_CMD_WRITE))
+               goto err;
+
+       dbgi_wr_data3(adap, 0xfffffff9, 0xffff8007, 0xff);
+       if (mc5_write(adap, IDT4_GMR_BASE1 + 5, IDT4_CMD_WRITE))
+               goto err;
+
+       /* Set up SCR */
+       dbgi_wr_data3(adap, 0xf0000000, 0, 0);
+       if (mc5_write(adap, IDT4_SCR_ADR0, IDT4_CMD_WRITE))
+               goto err;
+
+       return init_mask_data_array(mc5, IDT4_MSKARY_BASE_ADR0,
+                                   IDT4_DATARY_BASE_ADR0, IDT4_CMD_WRITE, 1);
+err:
+       return -EIO;
+}
+
+/* Put MC5 in DBGI mode. */
+static inline void mc5_dbgi_mode_enable(const struct mc5 *mc5)
+{
+       t3_write_reg(mc5->adapter, A_MC5_DB_CONFIG,
+                    V_TMMODE(mc5->mode == MC5_MODE_72_BIT) | F_DBGIEN);
+}
+
+/* Put MC5 in M-Bus mode. */
+static void mc5_dbgi_mode_disable(const struct mc5 *mc5)
+{
+       t3_write_reg(mc5->adapter, A_MC5_DB_CONFIG,
+                    V_TMMODE(mc5->mode == MC5_MODE_72_BIT) |
+                    V_COMPEN(mc5->mode == MC5_MODE_72_BIT) |
+                    V_PRTYEN(mc5->parity_enabled) | F_MBUSEN);
+}
+
+/*
+ * Initialization that requires the OS and protocol layers to already
+ * be intialized goes here.
+ */
+int t3_mc5_init(struct mc5 *mc5, unsigned int nservers, unsigned int nfilters,
+               unsigned int nroutes)
+{
+       u32 cfg;
+       int err;
+       unsigned int tcam_size = mc5->tcam_size;
+       struct adapter *adap = mc5->adapter;
+
+       if (nroutes > MAX_ROUTES || nroutes + nservers + nfilters > tcam_size)
+               return -EINVAL;
+
+       /* Reset the TCAM */
+       cfg = t3_read_reg(adap, A_MC5_DB_CONFIG) & ~F_TMMODE;
+       cfg |= V_TMMODE(mc5->mode == MC5_MODE_72_BIT) | F_TMRST;
+       t3_write_reg(adap, A_MC5_DB_CONFIG, cfg);
+       if (t3_wait_op_done(adap, A_MC5_DB_CONFIG, F_TMRDY, 1, 500, 0)) {
+               CH_ERR(adap, "TCAM reset timed out\n");
+               return -1;
+       }
+
+       t3_write_reg(adap, A_MC5_DB_ROUTING_TABLE_INDEX, tcam_size - nroutes);
+       t3_write_reg(adap, A_MC5_DB_FILTER_TABLE,
+                    tcam_size - nroutes - nfilters);
+       t3_write_reg(adap, A_MC5_DB_SERVER_INDEX,
+                    tcam_size - nroutes - nfilters - nservers);
+
+       mc5->parity_enabled = 1;
+
+       /* All the TCAM addresses we access have only the low 32 bits non 0 */
+       t3_write_reg(adap, A_MC5_DB_DBGI_REQ_ADDR1, 0);
+       t3_write_reg(adap, A_MC5_DB_DBGI_REQ_ADDR2, 0);
+
+       mc5_dbgi_mode_enable(mc5);
+
+       switch (mc5->part_type) {
+       case IDT75P52100:
+               err = init_idt52100(mc5);
+               break;
+       case IDT75N43102:
+               err = init_idt43102(mc5);
+               break;
+       default:
+               CH_ERR(adap, "Unsupported TCAM type %d\n", mc5->part_type);
+               err = -EINVAL;
+               break;
+       }
+
+       mc5_dbgi_mode_disable(mc5);
+       return err;
+}
+
+/*
+ *     read_mc5_range - dump a part of the memory managed by MC5
+ *     @mc5: the MC5 handle
+ *     @start: the start address for the dump
+ *     @n: number of 72-bit words to read
+ *     @buf: result buffer
+ *
+ *     Read n 72-bit words from MC5 memory from the given start location.
+ */
+int t3_read_mc5_range(const struct mc5 *mc5, unsigned int start,
+                     unsigned int n, u32 *buf)
+{
+       u32 read_cmd;
+       int err = 0;
+       struct adapter *adap = mc5->adapter;
+
+       if (mc5->part_type == IDT75P52100)
+               read_cmd = IDT_CMD_READ;
+       else if (mc5->part_type == IDT75N43102)
+               read_cmd = IDT4_CMD_READ;
+       else
+               return -EINVAL;
+
+       mc5_dbgi_mode_enable(mc5);
+
+       while (n--) {
+               t3_write_reg(adap, A_MC5_DB_DBGI_REQ_ADDR0, start++);
+               if (mc5_cmd_write(adap, read_cmd)) {
+                       err = -EIO;
+                       break;
+               }
+               dbgi_rd_rsp3(adap, buf + 2, buf + 1, buf);
+               buf += 3;
+       }
+
+       mc5_dbgi_mode_disable(mc5);
+       return 0;
+}
+
+#define MC5_INT_FATAL (F_PARITYERR | F_REQQPARERR | F_DISPQPARERR)
+
+/*
+ * MC5 interrupt handler
+ */
+void t3_mc5_intr_handler(struct mc5 *mc5)
+{
+       struct adapter *adap = mc5->adapter;
+       u32 cause = t3_read_reg(adap, A_MC5_DB_INT_CAUSE);
+
+       if ((cause & F_PARITYERR) && mc5->parity_enabled) {
+               CH_ALERT(adap, "MC5 parity error\n");
+               mc5->stats.parity_err++;
+       }
+
+       if (cause & F_REQQPARERR) {
+               CH_ALERT(adap, "MC5 request queue parity error\n");
+               mc5->stats.reqq_parity_err++;
+       }
+
+       if (cause & F_DISPQPARERR) {
+               CH_ALERT(adap, "MC5 dispatch queue parity error\n");
+               mc5->stats.dispq_parity_err++;
+       }
+
+       if (cause & F_ACTRGNFULL)
+               mc5->stats.active_rgn_full++;
+       if (cause & F_NFASRCHFAIL)
+               mc5->stats.nfa_srch_err++;
+       if (cause & F_UNKNOWNCMD)
+               mc5->stats.unknown_cmd++;
+       if (cause & F_DELACTEMPTY)
+               mc5->stats.del_act_empty++;
+       if (cause & MC5_INT_FATAL)
+               t3_fatal_err(adap);
+
+       t3_write_reg(adap, A_MC5_DB_INT_CAUSE, cause);
+}
+
+void __devinit t3_mc5_prep(struct adapter *adapter, struct mc5 *mc5, int mode)
+{
+#define K * 1024
+
+       static unsigned int tcam_part_size[] = {        /* in K 72-bit entries */
+               64 K, 128 K, 256 K, 32 K
+       };
+
+#undef K
+
+       u32 cfg = t3_read_reg(adapter, A_MC5_DB_CONFIG);
+
+       mc5->adapter = adapter;
+       mc5->mode = (unsigned char)mode;
+       mc5->part_type = (unsigned char)G_TMTYPE(cfg);
+       if (cfg & F_TMTYPEHI)
+               mc5->part_type |= 4;
+
+       mc5->tcam_size = tcam_part_size[G_TMPARTSIZE(cfg)];
+       if (mode == MC5_MODE_144_BIT)
+               mc5->tcam_size /= 2;
+}
diff --git a/drivers/net/cxgb3/regs.h b/drivers/net/cxgb3/regs.h
new file mode 100644 (file)
index 0000000..b56c5f5
--- /dev/null
@@ -0,0 +1,2195 @@
+#define A_SG_CONTROL 0x0
+
+#define S_DROPPKT    20
+#define V_DROPPKT(x) ((x) << S_DROPPKT)
+#define F_DROPPKT    V_DROPPKT(1U)
+
+#define S_EGRGENCTRL    19
+#define V_EGRGENCTRL(x) ((x) << S_EGRGENCTRL)
+#define F_EGRGENCTRL    V_EGRGENCTRL(1U)
+
+#define S_USERSPACESIZE    14
+#define M_USERSPACESIZE    0x1f
+#define V_USERSPACESIZE(x) ((x) << S_USERSPACESIZE)
+
+#define S_HOSTPAGESIZE    11
+#define M_HOSTPAGESIZE    0x7
+#define V_HOSTPAGESIZE(x) ((x) << S_HOSTPAGESIZE)
+
+#define S_FLMODE    9
+#define V_FLMODE(x) ((x) << S_FLMODE)
+#define F_FLMODE    V_FLMODE(1U)
+
+#define S_PKTSHIFT    6
+#define M_PKTSHIFT    0x7
+#define V_PKTSHIFT(x) ((x) << S_PKTSHIFT)
+
+#define S_ONEINTMULTQ    5
+#define V_ONEINTMULTQ(x) ((x) << S_ONEINTMULTQ)
+#define F_ONEINTMULTQ    V_ONEINTMULTQ(1U)
+
+#define S_BIGENDIANINGRESS    2
+#define V_BIGENDIANINGRESS(x) ((x) << S_BIGENDIANINGRESS)
+#define F_BIGENDIANINGRESS    V_BIGENDIANINGRESS(1U)
+
+#define S_ISCSICOALESCING    1
+#define V_ISCSICOALESCING(x) ((x) << S_ISCSICOALESCING)
+#define F_ISCSICOALESCING    V_ISCSICOALESCING(1U)
+
+#define S_GLOBALENABLE    0
+#define V_GLOBALENABLE(x) ((x) << S_GLOBALENABLE)
+#define F_GLOBALENABLE    V_GLOBALENABLE(1U)
+
+#define S_AVOIDCQOVFL    24
+#define V_AVOIDCQOVFL(x) ((x) << S_AVOIDCQOVFL)
+#define F_AVOIDCQOVFL    V_AVOIDCQOVFL(1U)
+
+#define S_OPTONEINTMULTQ    23
+#define V_OPTONEINTMULTQ(x) ((x) << S_OPTONEINTMULTQ)
+#define F_OPTONEINTMULTQ    V_OPTONEINTMULTQ(1U)
+
+#define S_CQCRDTCTRL    22
+#define V_CQCRDTCTRL(x) ((x) << S_CQCRDTCTRL)
+#define F_CQCRDTCTRL    V_CQCRDTCTRL(1U)
+
+#define A_SG_KDOORBELL 0x4
+
+#define S_SELEGRCNTX    31
+#define V_SELEGRCNTX(x) ((x) << S_SELEGRCNTX)
+#define F_SELEGRCNTX    V_SELEGRCNTX(1U)
+
+#define S_EGRCNTX    0
+#define M_EGRCNTX    0xffff
+#define V_EGRCNTX(x) ((x) << S_EGRCNTX)
+
+#define A_SG_GTS 0x8
+
+#define S_RSPQ    29
+#define M_RSPQ    0x7
+#define V_RSPQ(x) ((x) << S_RSPQ)
+#define G_RSPQ(x) (((x) >> S_RSPQ) & M_RSPQ)
+
+#define S_NEWTIMER    16
+#define M_NEWTIMER    0x1fff
+#define V_NEWTIMER(x) ((x) << S_NEWTIMER)
+
+#define S_NEWINDEX    0
+#define M_NEWINDEX    0xffff
+#define V_NEWINDEX(x) ((x) << S_NEWINDEX)
+
+#define A_SG_CONTEXT_CMD 0xc
+
+#define S_CONTEXT_CMD_OPCODE    28
+#define M_CONTEXT_CMD_OPCODE    0xf
+#define V_CONTEXT_CMD_OPCODE(x) ((x) << S_CONTEXT_CMD_OPCODE)
+
+#define S_CONTEXT_CMD_BUSY    27
+#define V_CONTEXT_CMD_BUSY(x) ((x) << S_CONTEXT_CMD_BUSY)
+#define F_CONTEXT_CMD_BUSY    V_CONTEXT_CMD_BUSY(1U)
+
+#define S_CQ_CREDIT    20
+
+#define M_CQ_CREDIT    0x7f
+
+#define V_CQ_CREDIT(x) ((x) << S_CQ_CREDIT)
+
+#define G_CQ_CREDIT(x) (((x) >> S_CQ_CREDIT) & M_CQ_CREDIT)
+
+#define S_CQ    19
+
+#define V_CQ(x) ((x) << S_CQ)
+#define F_CQ    V_CQ(1U)
+
+#define S_RESPONSEQ    18
+#define V_RESPONSEQ(x) ((x) << S_RESPONSEQ)
+#define F_RESPONSEQ    V_RESPONSEQ(1U)
+
+#define S_EGRESS    17
+#define V_EGRESS(x) ((x) << S_EGRESS)
+#define F_EGRESS    V_EGRESS(1U)
+
+#define S_FREELIST    16
+#define V_FREELIST(x) ((x) << S_FREELIST)
+#define F_FREELIST    V_FREELIST(1U)
+
+#define S_CONTEXT    0
+#define M_CONTEXT    0xffff
+#define V_CONTEXT(x) ((x) << S_CONTEXT)
+
+#define G_CONTEXT(x) (((x) >> S_CONTEXT) & M_CONTEXT)
+
+#define A_SG_CONTEXT_DATA0 0x10
+
+#define A_SG_CONTEXT_DATA1 0x14
+
+#define A_SG_CONTEXT_DATA2 0x18
+
+#define A_SG_CONTEXT_DATA3 0x1c
+
+#define A_SG_CONTEXT_MASK0 0x20
+
+#define A_SG_CONTEXT_MASK1 0x24
+
+#define A_SG_CONTEXT_MASK2 0x28
+
+#define A_SG_CONTEXT_MASK3 0x2c
+
+#define A_SG_RSPQ_CREDIT_RETURN 0x30
+
+#define S_CREDITS    0
+#define M_CREDITS    0xffff
+#define V_CREDITS(x) ((x) << S_CREDITS)
+
+#define A_SG_DATA_INTR 0x34
+
+#define S_ERRINTR    31
+#define V_ERRINTR(x) ((x) << S_ERRINTR)
+#define F_ERRINTR    V_ERRINTR(1U)
+
+#define A_SG_HI_DRB_HI_THRSH 0x38
+
+#define A_SG_HI_DRB_LO_THRSH 0x3c
+
+#define A_SG_LO_DRB_HI_THRSH 0x40
+
+#define A_SG_LO_DRB_LO_THRSH 0x44
+
+#define A_SG_RSPQ_FL_STATUS 0x4c
+
+#define S_RSPQ0DISABLED    8
+
+#define A_SG_EGR_RCQ_DRB_THRSH 0x54
+
+#define S_HIRCQDRBTHRSH    16
+#define M_HIRCQDRBTHRSH    0x7ff
+#define V_HIRCQDRBTHRSH(x) ((x) << S_HIRCQDRBTHRSH)
+
+#define S_LORCQDRBTHRSH    0
+#define M_LORCQDRBTHRSH    0x7ff
+#define V_LORCQDRBTHRSH(x) ((x) << S_LORCQDRBTHRSH)
+
+#define A_SG_EGR_CNTX_BADDR 0x58
+
+#define A_SG_INT_CAUSE 0x5c
+
+#define S_RSPQDISABLED    3
+#define V_RSPQDISABLED(x) ((x) << S_RSPQDISABLED)
+#define F_RSPQDISABLED    V_RSPQDISABLED(1U)
+
+#define S_RSPQCREDITOVERFOW    2
+#define V_RSPQCREDITOVERFOW(x) ((x) << S_RSPQCREDITOVERFOW)
+#define F_RSPQCREDITOVERFOW    V_RSPQCREDITOVERFOW(1U)
+
+#define A_SG_INT_ENABLE 0x60
+
+#define A_SG_CMDQ_CREDIT_TH 0x64
+
+#define S_TIMEOUT    8
+#define M_TIMEOUT    0xffffff
+#define V_TIMEOUT(x) ((x) << S_TIMEOUT)
+
+#define S_THRESHOLD    0
+#define M_THRESHOLD    0xff
+#define V_THRESHOLD(x) ((x) << S_THRESHOLD)
+
+#define A_SG_TIMER_TICK 0x68
+
+#define A_SG_CQ_CONTEXT_BADDR 0x6c
+
+#define A_SG_OCO_BASE 0x70
+
+#define S_BASE1    16
+#define M_BASE1    0xffff
+#define V_BASE1(x) ((x) << S_BASE1)
+
+#define A_SG_DRB_PRI_THRESH 0x74
+
+#define A_PCIX_INT_ENABLE 0x80
+
+#define S_MSIXPARERR    22
+#define M_MSIXPARERR    0x7
+
+#define V_MSIXPARERR(x) ((x) << S_MSIXPARERR)
+
+#define S_CFPARERR    18
+#define M_CFPARERR    0xf
+
+#define V_CFPARERR(x) ((x) << S_CFPARERR)
+
+#define S_RFPARERR    14
+#define M_RFPARERR    0xf
+
+#define V_RFPARERR(x) ((x) << S_RFPARERR)
+
+#define S_WFPARERR    12
+#define M_WFPARERR    0x3
+
+#define V_WFPARERR(x) ((x) << S_WFPARERR)
+
+#define S_PIOPARERR    11
+#define V_PIOPARERR(x) ((x) << S_PIOPARERR)
+#define F_PIOPARERR    V_PIOPARERR(1U)
+
+#define S_DETUNCECCERR    10
+#define V_DETUNCECCERR(x) ((x) << S_DETUNCECCERR)
+#define F_DETUNCECCERR    V_DETUNCECCERR(1U)
+
+#define S_DETCORECCERR    9
+#define V_DETCORECCERR(x) ((x) << S_DETCORECCERR)
+#define F_DETCORECCERR    V_DETCORECCERR(1U)
+
+#define S_RCVSPLCMPERR    8
+#define V_RCVSPLCMPERR(x) ((x) << S_RCVSPLCMPERR)
+#define F_RCVSPLCMPERR    V_RCVSPLCMPERR(1U)
+
+#define S_UNXSPLCMP    7
+#define V_UNXSPLCMP(x) ((x) << S_UNXSPLCMP)
+#define F_UNXSPLCMP    V_UNXSPLCMP(1U)
+
+#define S_SPLCMPDIS    6
+#define V_SPLCMPDIS(x) ((x) << S_SPLCMPDIS)
+#define F_SPLCMPDIS    V_SPLCMPDIS(1U)
+
+#define S_DETPARERR    5
+#define V_DETPARERR(x) ((x) << S_DETPARERR)
+#define F_DETPARERR    V_DETPARERR(1U)
+
+#define S_SIGSYSERR    4
+#define V_SIGSYSERR(x) ((x) << S_SIGSYSERR)
+#define F_SIGSYSERR    V_SIGSYSERR(1U)
+
+#define S_RCVMSTABT    3
+#define V_RCVMSTABT(x) ((x) << S_RCVMSTABT)
+#define F_RCVMSTABT    V_RCVMSTABT(1U)
+
+#define S_RCVTARABT    2
+#define V_RCVTARABT(x) ((x) << S_RCVTARABT)
+#define F_RCVTARABT    V_RCVTARABT(1U)
+
+#define S_SIGTARABT    1
+#define V_SIGTARABT(x) ((x) << S_SIGTARABT)
+#define F_SIGTARABT    V_SIGTARABT(1U)
+
+#define S_MSTDETPARERR    0
+#define V_MSTDETPARERR(x) ((x) << S_MSTDETPARERR)
+#define F_MSTDETPARERR    V_MSTDETPARERR(1U)
+
+#define A_PCIX_INT_CAUSE 0x84
+
+#define A_PCIX_CFG 0x88
+
+#define S_CLIDECEN    18
+#define V_CLIDECEN(x) ((x) << S_CLIDECEN)
+#define F_CLIDECEN    V_CLIDECEN(1U)
+
+#define A_PCIX_MODE 0x8c
+
+#define S_PCLKRANGE    6
+#define M_PCLKRANGE    0x3
+#define V_PCLKRANGE(x) ((x) << S_PCLKRANGE)
+#define G_PCLKRANGE(x) (((x) >> S_PCLKRANGE) & M_PCLKRANGE)
+
+#define S_PCIXINITPAT    2
+#define M_PCIXINITPAT    0xf
+#define V_PCIXINITPAT(x) ((x) << S_PCIXINITPAT)
+#define G_PCIXINITPAT(x) (((x) >> S_PCIXINITPAT) & M_PCIXINITPAT)
+
+#define S_64BIT    0
+#define V_64BIT(x) ((x) << S_64BIT)
+#define F_64BIT    V_64BIT(1U)
+
+#define A_PCIE_INT_ENABLE 0x80
+
+#define S_BISTERR    15
+#define M_BISTERR    0xff
+
+#define V_BISTERR(x) ((x) << S_BISTERR)
+
+#define S_PCIE_MSIXPARERR    12
+#define M_PCIE_MSIXPARERR    0x7
+
+#define V_PCIE_MSIXPARERR(x) ((x) << S_PCIE_MSIXPARERR)
+
+#define S_PCIE_CFPARERR    11
+#define V_PCIE_CFPARERR(x) ((x) << S_PCIE_CFPARERR)
+#define F_PCIE_CFPARERR    V_PCIE_CFPARERR(1U)
+
+#define S_PCIE_RFPARERR    10
+#define V_PCIE_RFPARERR(x) ((x) << S_PCIE_RFPARERR)
+#define F_PCIE_RFPARERR    V_PCIE_RFPARERR(1U)
+
+#define S_PCIE_WFPARERR    9
+#define V_PCIE_WFPARERR(x) ((x) << S_PCIE_WFPARERR)
+#define F_PCIE_WFPARERR    V_PCIE_WFPARERR(1U)
+
+#define S_PCIE_PIOPARERR    8
+#define V_PCIE_PIOPARERR(x) ((x) << S_PCIE_PIOPARERR)
+#define F_PCIE_PIOPARERR    V_PCIE_PIOPARERR(1U)
+
+#define S_UNXSPLCPLERRC    7
+#define V_UNXSPLCPLERRC(x) ((x) << S_UNXSPLCPLERRC)
+#define F_UNXSPLCPLERRC    V_UNXSPLCPLERRC(1U)
+
+#define S_UNXSPLCPLERRR    6
+#define V_UNXSPLCPLERRR(x) ((x) << S_UNXSPLCPLERRR)
+#define F_UNXSPLCPLERRR    V_UNXSPLCPLERRR(1U)
+
+#define S_PEXERR    0
+#define V_PEXERR(x) ((x) << S_PEXERR)
+#define F_PEXERR    V_PEXERR(1U)
+
+#define A_PCIE_INT_CAUSE 0x84
+
+#define A_PCIE_CFG 0x88
+
+#define S_PCIE_CLIDECEN    16
+#define V_PCIE_CLIDECEN(x) ((x) << S_PCIE_CLIDECEN)
+#define F_PCIE_CLIDECEN    V_PCIE_CLIDECEN(1U)
+
+#define S_CRSTWRMMODE    0
+#define V_CRSTWRMMODE(x) ((x) << S_CRSTWRMMODE)
+#define F_CRSTWRMMODE    V_CRSTWRMMODE(1U)
+
+#define A_PCIE_MODE 0x8c
+
+#define S_NUMFSTTRNSEQRX    10
+#define M_NUMFSTTRNSEQRX    0xff
+#define V_NUMFSTTRNSEQRX(x) ((x) << S_NUMFSTTRNSEQRX)
+#define G_NUMFSTTRNSEQRX(x) (((x) >> S_NUMFSTTRNSEQRX) & M_NUMFSTTRNSEQRX)
+
+#define A_PCIE_PEX_CTRL0 0x98
+
+#define S_NUMFSTTRNSEQ    22
+#define M_NUMFSTTRNSEQ    0xff
+#define V_NUMFSTTRNSEQ(x) ((x) << S_NUMFSTTRNSEQ)
+#define G_NUMFSTTRNSEQ(x) (((x) >> S_NUMFSTTRNSEQ) & M_NUMFSTTRNSEQ)
+
+#define S_REPLAYLMT    2
+#define M_REPLAYLMT    0xfffff
+
+#define V_REPLAYLMT(x) ((x) << S_REPLAYLMT)
+
+#define A_PCIE_PEX_CTRL1 0x9c
+
+#define S_T3A_ACKLAT    0
+#define M_T3A_ACKLAT    0x7ff
+
+#define V_T3A_ACKLAT(x) ((x) << S_T3A_ACKLAT)
+
+#define S_ACKLAT    0
+#define M_ACKLAT    0x1fff
+
+#define V_ACKLAT(x) ((x) << S_ACKLAT)
+
+#define A_PCIE_PEX_ERR 0xa4
+
+#define A_T3DBG_GPIO_EN 0xd0
+
+#define S_GPIO11_OEN    27
+#define V_GPIO11_OEN(x) ((x) << S_GPIO11_OEN)
+#define F_GPIO11_OEN    V_GPIO11_OEN(1U)
+
+#define S_GPIO10_OEN    26
+#define V_GPIO10_OEN(x) ((x) << S_GPIO10_OEN)
+#define F_GPIO10_OEN    V_GPIO10_OEN(1U)
+
+#define S_GPIO7_OEN    23
+#define V_GPIO7_OEN(x) ((x) << S_GPIO7_OEN)
+#define F_GPIO7_OEN    V_GPIO7_OEN(1U)
+
+#define S_GPIO6_OEN    22
+#define V_GPIO6_OEN(x) ((x) << S_GPIO6_OEN)
+#define F_GPIO6_OEN    V_GPIO6_OEN(1U)
+
+#define S_GPIO5_OEN    21
+#define V_GPIO5_OEN(x) ((x) << S_GPIO5_OEN)
+#define F_GPIO5_OEN    V_GPIO5_OEN(1U)
+
+#define S_GPIO4_OEN    20
+#define V_GPIO4_OEN(x) ((x) << S_GPIO4_OEN)
+#define F_GPIO4_OEN    V_GPIO4_OEN(1U)
+
+#define S_GPIO2_OEN    18
+#define V_GPIO2_OEN(x) ((x) << S_GPIO2_OEN)
+#define F_GPIO2_OEN    V_GPIO2_OEN(1U)
+
+#define S_GPIO1_OEN    17
+#define V_GPIO1_OEN(x) ((x) << S_GPIO1_OEN)
+#define F_GPIO1_OEN    V_GPIO1_OEN(1U)
+
+#define S_GPIO0_OEN    16
+#define V_GPIO0_OEN(x) ((x) << S_GPIO0_OEN)
+#define F_GPIO0_OEN    V_GPIO0_OEN(1U)
+
+#define S_GPIO10_OUT_VAL    10
+#define V_GPIO10_OUT_VAL(x) ((x) << S_GPIO10_OUT_VAL)
+#define F_GPIO10_OUT_VAL    V_GPIO10_OUT_VAL(1U)
+
+#define S_GPIO7_OUT_VAL    7
+#define V_GPIO7_OUT_VAL(x) ((x) << S_GPIO7_OUT_VAL)
+#define F_GPIO7_OUT_VAL    V_GPIO7_OUT_VAL(1U)
+
+#define S_GPIO6_OUT_VAL    6
+#define V_GPIO6_OUT_VAL(x) ((x) << S_GPIO6_OUT_VAL)
+#define F_GPIO6_OUT_VAL    V_GPIO6_OUT_VAL(1U)
+
+#define S_GPIO5_OUT_VAL    5
+#define V_GPIO5_OUT_VAL(x) ((x) << S_GPIO5_OUT_VAL)
+#define F_GPIO5_OUT_VAL    V_GPIO5_OUT_VAL(1U)
+
+#define S_GPIO4_OUT_VAL    4
+#define V_GPIO4_OUT_VAL(x) ((x) << S_GPIO4_OUT_VAL)
+#define F_GPIO4_OUT_VAL    V_GPIO4_OUT_VAL(1U)
+
+#define S_GPIO2_OUT_VAL    2
+#define V_GPIO2_OUT_VAL(x) ((x) << S_GPIO2_OUT_VAL)
+#define F_GPIO2_OUT_VAL    V_GPIO2_OUT_VAL(1U)
+
+#define S_GPIO1_OUT_VAL    1
+#define V_GPIO1_OUT_VAL(x) ((x) << S_GPIO1_OUT_VAL)
+#define F_GPIO1_OUT_VAL    V_GPIO1_OUT_VAL(1U)
+
+#define S_GPIO0_OUT_VAL    0
+#define V_GPIO0_OUT_VAL(x) ((x) << S_GPIO0_OUT_VAL)
+#define F_GPIO0_OUT_VAL    V_GPIO0_OUT_VAL(1U)
+
+#define A_T3DBG_INT_ENABLE 0xd8
+
+#define S_GPIO11    11
+#define V_GPIO11(x) ((x) << S_GPIO11)
+#define F_GPIO11    V_GPIO11(1U)
+
+#define S_GPIO10    10
+#define V_GPIO10(x) ((x) << S_GPIO10)
+#define F_GPIO10    V_GPIO10(1U)
+
+#define S_GPIO7    7
+#define V_GPIO7(x) ((x) << S_GPIO7)
+#define F_GPIO7    V_GPIO7(1U)
+
+#define S_GPIO6    6
+#define V_GPIO6(x) ((x) << S_GPIO6)
+#define F_GPIO6    V_GPIO6(1U)
+
+#define S_GPIO5    5
+#define V_GPIO5(x) ((x) << S_GPIO5)
+#define F_GPIO5    V_GPIO5(1U)
+
+#define S_GPIO4    4
+#define V_GPIO4(x) ((x) << S_GPIO4)
+#define F_GPIO4    V_GPIO4(1U)
+
+#define S_GPIO3    3
+#define V_GPIO3(x) ((x) << S_GPIO3)
+#define F_GPIO3    V_GPIO3(1U)
+
+#define S_GPIO2    2
+#define V_GPIO2(x) ((x) << S_GPIO2)
+#define F_GPIO2    V_GPIO2(1U)
+
+#define S_GPIO1    1
+#define V_GPIO1(x) ((x) << S_GPIO1)
+#define F_GPIO1    V_GPIO1(1U)
+
+#define S_GPIO0    0
+#define V_GPIO0(x) ((x) << S_GPIO0)
+#define F_GPIO0    V_GPIO0(1U)
+
+#define A_T3DBG_INT_CAUSE 0xdc
+
+#define A_T3DBG_GPIO_ACT_LOW 0xf0
+
+#define MC7_PMRX_BASE_ADDR 0x100
+
+#define A_MC7_CFG 0x100
+
+#define S_IFEN    13
+#define V_IFEN(x) ((x) << S_IFEN)
+#define F_IFEN    V_IFEN(1U)
+
+#define S_TERM150    11
+#define V_TERM150(x) ((x) << S_TERM150)
+#define F_TERM150    V_TERM150(1U)
+
+#define S_SLOW    10
+#define V_SLOW(x) ((x) << S_SLOW)
+#define F_SLOW    V_SLOW(1U)
+
+#define S_WIDTH    8
+#define M_WIDTH    0x3
+#define V_WIDTH(x) ((x) << S_WIDTH)
+#define G_WIDTH(x) (((x) >> S_WIDTH) & M_WIDTH)
+
+#define S_BKS    6
+#define V_BKS(x) ((x) << S_BKS)
+#define F_BKS    V_BKS(1U)
+
+#define S_ORG    5
+#define V_ORG(x) ((x) << S_ORG)
+#define F_ORG    V_ORG(1U)
+
+#define S_DEN    2
+#define M_DEN    0x7
+#define V_DEN(x) ((x) << S_DEN)
+#define G_DEN(x) (((x) >> S_DEN) & M_DEN)
+
+#define S_RDY    1
+#define V_RDY(x) ((x) << S_RDY)
+#define F_RDY    V_RDY(1U)
+
+#define S_CLKEN    0
+#define V_CLKEN(x) ((x) << S_CLKEN)
+#define F_CLKEN    V_CLKEN(1U)
+
+#define A_MC7_MODE 0x104
+
+#define S_BUSY    31
+#define V_BUSY(x) ((x) << S_BUSY)
+#define F_BUSY    V_BUSY(1U)
+
+#define S_BUSY    31
+#define V_BUSY(x) ((x) << S_BUSY)
+#define F_BUSY    V_BUSY(1U)
+
+#define A_MC7_EXT_MODE1 0x108
+
+#define A_MC7_EXT_MODE2 0x10c
+
+#define A_MC7_EXT_MODE3 0x110
+
+#define A_MC7_PRE 0x114
+
+#define A_MC7_REF 0x118
+
+#define S_PREREFDIV    1
+#define M_PREREFDIV    0x3fff
+#define V_PREREFDIV(x) ((x) << S_PREREFDIV)
+
+#define S_PERREFEN    0
+#define V_PERREFEN(x) ((x) << S_PERREFEN)
+#define F_PERREFEN    V_PERREFEN(1U)
+
+#define A_MC7_DLL 0x11c
+
+#define S_DLLENB    1
+#define V_DLLENB(x) ((x) << S_DLLENB)
+#define F_DLLENB    V_DLLENB(1U)
+
+#define S_DLLRST    0
+#define V_DLLRST(x) ((x) << S_DLLRST)
+#define F_DLLRST    V_DLLRST(1U)
+
+#define A_MC7_PARM 0x120
+
+#define S_ACTTOPREDLY    26
+#define M_ACTTOPREDLY    0xf
+#define V_ACTTOPREDLY(x) ((x) << S_ACTTOPREDLY)
+
+#define S_ACTTORDWRDLY    23
+#define M_ACTTORDWRDLY    0x7
+#define V_ACTTORDWRDLY(x) ((x) << S_ACTTORDWRDLY)
+
+#define S_PRECYC    20
+#define M_PRECYC    0x7
+#define V_PRECYC(x) ((x) << S_PRECYC)
+
+#define S_REFCYC    13
+#define M_REFCYC    0x7f
+#define V_REFCYC(x) ((x) << S_REFCYC)
+
+#define S_BKCYC    8
+#define M_BKCYC    0x1f
+#define V_BKCYC(x) ((x) << S_BKCYC)
+
+#define S_WRTORDDLY    4
+#define M_WRTORDDLY    0xf
+#define V_WRTORDDLY(x) ((x) << S_WRTORDDLY)
+
+#define S_RDTOWRDLY    0
+#define M_RDTOWRDLY    0xf
+#define V_RDTOWRDLY(x) ((x) << S_RDTOWRDLY)
+
+#define A_MC7_CAL 0x128
+
+#define S_BUSY    31
+#define V_BUSY(x) ((x) << S_BUSY)
+#define F_BUSY    V_BUSY(1U)
+
+#define S_BUSY    31
+#define V_BUSY(x) ((x) << S_BUSY)
+#define F_BUSY    V_BUSY(1U)
+
+#define S_CAL_FAULT    30
+#define V_CAL_FAULT(x) ((x) << S_CAL_FAULT)
+#define F_CAL_FAULT    V_CAL_FAULT(1U)
+
+#define S_SGL_CAL_EN    20
+#define V_SGL_CAL_EN(x) ((x) << S_SGL_CAL_EN)
+#define F_SGL_CAL_EN    V_SGL_CAL_EN(1U)
+
+#define A_MC7_ERR_ADDR 0x12c
+
+#define A_MC7_ECC 0x130
+
+#define S_ECCCHKEN    1
+#define V_ECCCHKEN(x) ((x) << S_ECCCHKEN)
+#define F_ECCCHKEN    V_ECCCHKEN(1U)
+
+#define S_ECCGENEN    0
+#define V_ECCGENEN(x) ((x) << S_ECCGENEN)
+#define F_ECCGENEN    V_ECCGENEN(1U)
+
+#define A_MC7_CE_ADDR 0x134
+
+#define A_MC7_CE_DATA0 0x138
+
+#define A_MC7_CE_DATA1 0x13c
+
+#define A_MC7_CE_DATA2 0x140
+
+#define S_DATA    0
+#define M_DATA    0xff
+
+#define G_DATA(x) (((x) >> S_DATA) & M_DATA)
+
+#define A_MC7_UE_ADDR 0x144
+
+#define A_MC7_UE_DATA0 0x148
+
+#define A_MC7_UE_DATA1 0x14c
+
+#define A_MC7_UE_DATA2 0x150
+
+#define A_MC7_BD_ADDR 0x154
+
+#define S_ADDR    3
+
+#define M_ADDR    0x1fffffff
+
+#define A_MC7_BD_DATA0 0x158
+
+#define A_MC7_BD_DATA1 0x15c
+
+#define A_MC7_BD_OP 0x164
+
+#define S_OP    0
+
+#define V_OP(x) ((x) << S_OP)
+#define F_OP    V_OP(1U)
+
+#define F_OP    V_OP(1U)
+#define A_SF_OP 0x6dc
+
+#define A_MC7_BIST_ADDR_BEG 0x168
+
+#define A_MC7_BIST_ADDR_END 0x16c
+
+#define A_MC7_BIST_DATA 0x170
+
+#define A_MC7_BIST_OP 0x174
+
+#define S_CONT    3
+#define V_CONT(x) ((x) << S_CONT)
+#define F_CONT    V_CONT(1U)
+
+#define F_CONT    V_CONT(1U)
+
+#define A_MC7_INT_ENABLE 0x178
+
+#define S_AE    17
+#define V_AE(x) ((x) << S_AE)
+#define F_AE    V_AE(1U)
+
+#define S_PE    2
+#define M_PE    0x7fff
+
+#define V_PE(x) ((x) << S_PE)
+
+#define G_PE(x) (((x) >> S_PE) & M_PE)
+
+#define S_UE    1
+#define V_UE(x) ((x) << S_UE)
+#define F_UE    V_UE(1U)
+
+#define S_CE    0
+#define V_CE(x) ((x) << S_CE)
+#define F_CE    V_CE(1U)
+
+#define A_MC7_INT_CAUSE 0x17c
+
+#define MC7_PMTX_BASE_ADDR 0x180
+
+#define MC7_CM_BASE_ADDR 0x200
+
+#define A_CIM_BOOT_CFG 0x280
+
+#define S_BOOTADDR    2
+#define M_BOOTADDR    0x3fffffff
+#define V_BOOTADDR(x) ((x) << S_BOOTADDR)
+
+#define A_CIM_SDRAM_BASE_ADDR 0x28c
+
+#define A_CIM_SDRAM_ADDR_SIZE 0x290
+
+#define A_CIM_HOST_INT_ENABLE 0x298
+
+#define A_CIM_HOST_INT_CAUSE 0x29c
+
+#define S_BLKWRPLINT    12
+#define V_BLKWRPLINT(x) ((x) << S_BLKWRPLINT)
+#define F_BLKWRPLINT    V_BLKWRPLINT(1U)
+
+#define S_BLKRDPLINT    11
+#define V_BLKRDPLINT(x) ((x) << S_BLKRDPLINT)
+#define F_BLKRDPLINT    V_BLKRDPLINT(1U)
+
+#define S_BLKWRCTLINT    10
+#define V_BLKWRCTLINT(x) ((x) << S_BLKWRCTLINT)
+#define F_BLKWRCTLINT    V_BLKWRCTLINT(1U)
+
+#define S_BLKRDCTLINT    9
+#define V_BLKRDCTLINT(x) ((x) << S_BLKRDCTLINT)
+#define F_BLKRDCTLINT    V_BLKRDCTLINT(1U)
+
+#define S_BLKWRFLASHINT    8
+#define V_BLKWRFLASHINT(x) ((x) << S_BLKWRFLASHINT)
+#define F_BLKWRFLASHINT    V_BLKWRFLASHINT(1U)
+
+#define S_BLKRDFLASHINT    7
+#define V_BLKRDFLASHINT(x) ((x) << S_BLKRDFLASHINT)
+#define F_BLKRDFLASHINT    V_BLKRDFLASHINT(1U)
+
+#define S_SGLWRFLASHINT    6
+#define V_SGLWRFLASHINT(x) ((x) << S_SGLWRFLASHINT)
+#define F_SGLWRFLASHINT    V_SGLWRFLASHINT(1U)
+
+#define S_WRBLKFLASHINT    5
+#define V_WRBLKFLASHINT(x) ((x) << S_WRBLKFLASHINT)
+#define F_WRBLKFLASHINT    V_WRBLKFLASHINT(1U)
+
+#define S_BLKWRBOOTINT    4
+#define V_BLKWRBOOTINT(x) ((x) << S_BLKWRBOOTINT)
+#define F_BLKWRBOOTINT    V_BLKWRBOOTINT(1U)
+
+#define S_FLASHRANGEINT    2
+#define V_FLASHRANGEINT(x) ((x) << S_FLASHRANGEINT)
+#define F_FLASHRANGEINT    V_FLASHRANGEINT(1U)
+
+#define S_SDRAMRANGEINT    1
+#define V_SDRAMRANGEINT(x) ((x) << S_SDRAMRANGEINT)
+#define F_SDRAMRANGEINT    V_SDRAMRANGEINT(1U)
+
+#define S_RSVDSPACEINT    0
+#define V_RSVDSPACEINT(x) ((x) << S_RSVDSPACEINT)
+#define F_RSVDSPACEINT    V_RSVDSPACEINT(1U)
+
+#define A_CIM_HOST_ACC_CTRL 0x2b0
+
+#define S_HOSTBUSY    17
+#define V_HOSTBUSY(x) ((x) << S_HOSTBUSY)
+#define F_HOSTBUSY    V_HOSTBUSY(1U)
+
+#define A_CIM_HOST_ACC_DATA 0x2b4
+
+#define A_TP_IN_CONFIG 0x300
+
+#define S_NICMODE    14
+#define V_NICMODE(x) ((x) << S_NICMODE)
+#define F_NICMODE    V_NICMODE(1U)
+
+#define F_NICMODE    V_NICMODE(1U)
+
+#define S_IPV6ENABLE    15
+#define V_IPV6ENABLE(x) ((x) << S_IPV6ENABLE)
+#define F_IPV6ENABLE    V_IPV6ENABLE(1U)
+
+#define A_TP_OUT_CONFIG 0x304
+
+#define S_VLANEXTRACTIONENABLE    12
+
+#define A_TP_GLOBAL_CONFIG 0x308
+
+#define S_TXPACINGENABLE    24
+#define V_TXPACINGENABLE(x) ((x) << S_TXPACINGENABLE)
+#define F_TXPACINGENABLE    V_TXPACINGENABLE(1U)
+
+#define S_PATHMTU    15
+#define V_PATHMTU(x) ((x) << S_PATHMTU)
+#define F_PATHMTU    V_PATHMTU(1U)
+
+#define S_IPCHECKSUMOFFLOAD    13
+#define V_IPCHECKSUMOFFLOAD(x) ((x) << S_IPCHECKSUMOFFLOAD)
+#define F_IPCHECKSUMOFFLOAD    V_IPCHECKSUMOFFLOAD(1U)
+
+#define S_UDPCHECKSUMOFFLOAD    12
+#define V_UDPCHECKSUMOFFLOAD(x) ((x) << S_UDPCHECKSUMOFFLOAD)
+#define F_UDPCHECKSUMOFFLOAD    V_UDPCHECKSUMOFFLOAD(1U)
+
+#define S_TCPCHECKSUMOFFLOAD    11
+#define V_TCPCHECKSUMOFFLOAD(x) ((x) << S_TCPCHECKSUMOFFLOAD)
+#define F_TCPCHECKSUMOFFLOAD    V_TCPCHECKSUMOFFLOAD(1U)
+
+#define S_IPTTL    0
+#define M_IPTTL    0xff
+#define V_IPTTL(x) ((x) << S_IPTTL)
+
+#define A_TP_CMM_MM_BASE 0x314
+
+#define A_TP_CMM_TIMER_BASE 0x318
+
+#define S_CMTIMERMAXNUM    28
+#define M_CMTIMERMAXNUM    0x3
+#define V_CMTIMERMAXNUM(x) ((x) << S_CMTIMERMAXNUM)
+
+#define A_TP_PMM_SIZE 0x31c
+
+#define A_TP_PMM_TX_BASE 0x320
+
+#define A_TP_PMM_RX_BASE 0x328
+
+#define A_TP_PMM_RX_PAGE_SIZE 0x32c
+
+#define A_TP_PMM_RX_MAX_PAGE 0x330
+
+#define A_TP_PMM_TX_PAGE_SIZE 0x334
+
+#define A_TP_PMM_TX_MAX_PAGE 0x338
+
+#define A_TP_TCP_OPTIONS 0x340
+
+#define S_MTUDEFAULT    16
+#define M_MTUDEFAULT    0xffff
+#define V_MTUDEFAULT(x) ((x) << S_MTUDEFAULT)
+
+#define S_MTUENABLE    10
+#define V_MTUENABLE(x) ((x) << S_MTUENABLE)
+#define F_MTUENABLE    V_MTUENABLE(1U)
+
+#define S_SACKRX    8
+#define V_SACKRX(x) ((x) << S_SACKRX)
+#define F_SACKRX    V_SACKRX(1U)
+
+#define S_SACKMODE    4
+
+#define M_SACKMODE    0x3
+
+#define V_SACKMODE(x) ((x) << S_SACKMODE)
+
+#define S_WINDOWSCALEMODE    2
+#define M_WINDOWSCALEMODE    0x3
+#define V_WINDOWSCALEMODE(x) ((x) << S_WINDOWSCALEMODE)
+
+#define S_TIMESTAMPSMODE    0
+
+#define M_TIMESTAMPSMODE    0x3
+
+#define V_TIMESTAMPSMODE(x) ((x) << S_TIMESTAMPSMODE)
+
+#define A_TP_DACK_CONFIG 0x344
+
+#define S_AUTOSTATE3    30
+#define M_AUTOSTATE3    0x3
+#define V_AUTOSTATE3(x) ((x) << S_AUTOSTATE3)
+
+#define S_AUTOSTATE2    28
+#define M_AUTOSTATE2    0x3
+#define V_AUTOSTATE2(x) ((x) << S_AUTOSTATE2)
+
+#define S_AUTOSTATE1    26
+#define M_AUTOSTATE1    0x3
+#define V_AUTOSTATE1(x) ((x) << S_AUTOSTATE1)
+
+#define S_BYTETHRESHOLD    5
+#define M_BYTETHRESHOLD    0xfffff
+#define V_BYTETHRESHOLD(x) ((x) << S_BYTETHRESHOLD)
+
+#define S_MSSTHRESHOLD    3
+#define M_MSSTHRESHOLD    0x3
+#define V_MSSTHRESHOLD(x) ((x) << S_MSSTHRESHOLD)
+
+#define S_AUTOCAREFUL    2
+#define V_AUTOCAREFUL(x) ((x) << S_AUTOCAREFUL)
+#define F_AUTOCAREFUL    V_AUTOCAREFUL(1U)
+
+#define S_AUTOENABLE    1
+#define V_AUTOENABLE(x) ((x) << S_AUTOENABLE)
+#define F_AUTOENABLE    V_AUTOENABLE(1U)
+
+#define S_DACK_MODE    0
+#define V_DACK_MODE(x) ((x) << S_DACK_MODE)
+#define F_DACK_MODE    V_DACK_MODE(1U)
+
+#define A_TP_PC_CONFIG 0x348
+
+#define S_TXTOSQUEUEMAPMODE    26
+#define V_TXTOSQUEUEMAPMODE(x) ((x) << S_TXTOSQUEUEMAPMODE)
+#define F_TXTOSQUEUEMAPMODE    V_TXTOSQUEUEMAPMODE(1U)
+
+#define S_ENABLEEPCMDAFULL    23
+#define V_ENABLEEPCMDAFULL(x) ((x) << S_ENABLEEPCMDAFULL)
+#define F_ENABLEEPCMDAFULL    V_ENABLEEPCMDAFULL(1U)
+
+#define S_MODULATEUNIONMODE    22
+#define V_MODULATEUNIONMODE(x) ((x) << S_MODULATEUNIONMODE)
+#define F_MODULATEUNIONMODE    V_MODULATEUNIONMODE(1U)
+
+#define S_TXDEFERENABLE    20
+#define V_TXDEFERENABLE(x) ((x) << S_TXDEFERENABLE)
+#define F_TXDEFERENABLE    V_TXDEFERENABLE(1U)
+
+#define S_RXCONGESTIONMODE    19
+#define V_RXCONGESTIONMODE(x) ((x) << S_RXCONGESTIONMODE)
+#define F_RXCONGESTIONMODE    V_RXCONGESTIONMODE(1U)
+
+#define S_HEARBEATDACK    16
+#define V_HEARBEATDACK(x) ((x) << S_HEARBEATDACK)
+#define F_HEARBEATDACK    V_HEARBEATDACK(1U)
+
+#define S_TXCONGESTIONMODE    15
+#define V_TXCONGESTIONMODE(x) ((x) << S_TXCONGESTIONMODE)
+#define F_TXCONGESTIONMODE    V_TXCONGESTIONMODE(1U)
+
+#define S_ENABLEOCSPIFULL    30
+#define V_ENABLEOCSPIFULL(x) ((x) << S_ENABLEOCSPIFULL)
+#define F_ENABLEOCSPIFULL    V_ENABLEOCSPIFULL(1U)
+
+#define S_LOCKTID    28
+#define V_LOCKTID(x) ((x) << S_LOCKTID)
+#define F_LOCKTID    V_LOCKTID(1U)
+
+#define A_TP_PC_CONFIG2 0x34c
+
+#define S_CHDRAFULL    4
+#define V_CHDRAFULL(x) ((x) << S_CHDRAFULL)
+#define F_CHDRAFULL    V_CHDRAFULL(1U)
+
+#define A_TP_TCP_BACKOFF_REG0 0x350
+
+#define A_TP_TCP_BACKOFF_REG1 0x354
+
+#define A_TP_TCP_BACKOFF_REG2 0x358
+
+#define A_TP_TCP_BACKOFF_REG3 0x35c
+
+#define A_TP_PARA_REG2 0x368
+
+#define S_MAXRXDATA    16
+#define M_MAXRXDATA    0xffff
+#define V_MAXRXDATA(x) ((x) << S_MAXRXDATA)
+
+#define S_RXCOALESCESIZE    0
+#define M_RXCOALESCESIZE    0xffff
+#define V_RXCOALESCESIZE(x) ((x) << S_RXCOALESCESIZE)
+
+#define A_TP_PARA_REG3 0x36c
+
+#define S_TXDATAACKIDX    16
+#define M_TXDATAACKIDX    0xf
+
+#define V_TXDATAACKIDX(x) ((x) << S_TXDATAACKIDX)
+
+#define S_TXPACEAUTOSTRICT    10
+#define V_TXPACEAUTOSTRICT(x) ((x) << S_TXPACEAUTOSTRICT)
+#define F_TXPACEAUTOSTRICT    V_TXPACEAUTOSTRICT(1U)
+
+#define S_TXPACEFIXED    9
+#define V_TXPACEFIXED(x) ((x) << S_TXPACEFIXED)
+#define F_TXPACEFIXED    V_TXPACEFIXED(1U)
+
+#define S_TXPACEAUTO    8
+#define V_TXPACEAUTO(x) ((x) << S_TXPACEAUTO)
+#define F_TXPACEAUTO    V_TXPACEAUTO(1U)
+
+#define S_RXCOALESCEENABLE    1
+#define V_RXCOALESCEENABLE(x) ((x) << S_RXCOALESCEENABLE)
+#define F_RXCOALESCEENABLE    V_RXCOALESCEENABLE(1U)
+
+#define S_RXCOALESCEPSHEN    0
+#define V_RXCOALESCEPSHEN(x) ((x) << S_RXCOALESCEPSHEN)
+#define F_RXCOALESCEPSHEN    V_RXCOALESCEPSHEN(1U)
+
+#define A_TP_PARA_REG4 0x370
+
+#define A_TP_PARA_REG6 0x378
+
+#define S_T3A_ENABLEESND    13
+#define V_T3A_ENABLEESND(x) ((x) << S_T3A_ENABLEESND)
+#define F_T3A_ENABLEESND    V_T3A_ENABLEESND(1U)
+
+#define S_ENABLEESND    11
+#define V_ENABLEESND(x) ((x) << S_ENABLEESND)
+#define F_ENABLEESND    V_ENABLEESND(1U)
+
+#define A_TP_PARA_REG7 0x37c
+
+#define S_PMMAXXFERLEN1    16
+#define M_PMMAXXFERLEN1    0xffff
+#define V_PMMAXXFERLEN1(x) ((x) << S_PMMAXXFERLEN1)
+
+#define S_PMMAXXFERLEN0    0
+#define M_PMMAXXFERLEN0    0xffff
+#define V_PMMAXXFERLEN0(x) ((x) << S_PMMAXXFERLEN0)
+
+#define A_TP_TIMER_RESOLUTION 0x390
+
+#define S_TIMERRESOLUTION    16
+#define M_TIMERRESOLUTION    0xff
+#define V_TIMERRESOLUTION(x) ((x) << S_TIMERRESOLUTION)
+
+#define S_TIMESTAMPRESOLUTION    8
+#define M_TIMESTAMPRESOLUTION    0xff
+#define V_TIMESTAMPRESOLUTION(x) ((x) << S_TIMESTAMPRESOLUTION)
+
+#define S_DELAYEDACKRESOLUTION    0
+#define M_DELAYEDACKRESOLUTION    0xff
+#define V_DELAYEDACKRESOLUTION(x) ((x) << S_DELAYEDACKRESOLUTION)
+
+#define A_TP_MSL 0x394
+
+#define A_TP_RXT_MIN 0x398
+
+#define A_TP_RXT_MAX 0x39c
+
+#define A_TP_PERS_MIN 0x3a0
+
+#define A_TP_PERS_MAX 0x3a4
+
+#define A_TP_KEEP_IDLE 0x3a8
+
+#define A_TP_KEEP_INTVL 0x3ac
+
+#define A_TP_INIT_SRTT 0x3b0
+
+#define A_TP_DACK_TIMER 0x3b4
+
+#define A_TP_FINWAIT2_TIMER 0x3b8
+
+#define A_TP_SHIFT_CNT 0x3c0
+
+#define S_SYNSHIFTMAX    24
+
+#define M_SYNSHIFTMAX    0xff
+
+#define V_SYNSHIFTMAX(x) ((x) << S_SYNSHIFTMAX)
+
+#define S_RXTSHIFTMAXR1    20
+
+#define M_RXTSHIFTMAXR1    0xf
+
+#define V_RXTSHIFTMAXR1(x) ((x) << S_RXTSHIFTMAXR1)
+
+#define S_RXTSHIFTMAXR2    16
+
+#define M_RXTSHIFTMAXR2    0xf
+
+#define V_RXTSHIFTMAXR2(x) ((x) << S_RXTSHIFTMAXR2)
+
+#define S_PERSHIFTBACKOFFMAX    12
+#define M_PERSHIFTBACKOFFMAX    0xf
+#define V_PERSHIFTBACKOFFMAX(x) ((x) << S_PERSHIFTBACKOFFMAX)
+
+#define S_PERSHIFTMAX    8
+#define M_PERSHIFTMAX    0xf
+#define V_PERSHIFTMAX(x) ((x) << S_PERSHIFTMAX)
+
+#define S_KEEPALIVEMAX    0
+
+#define M_KEEPALIVEMAX    0xff
+
+#define V_KEEPALIVEMAX(x) ((x) << S_KEEPALIVEMAX)
+
+#define A_TP_MTU_PORT_TABLE 0x3d0
+
+#define A_TP_CCTRL_TABLE 0x3dc
+
+#define A_TP_MTU_TABLE 0x3e4
+
+#define A_TP_RSS_MAP_TABLE 0x3e8
+
+#define A_TP_RSS_LKP_TABLE 0x3ec
+
+#define A_TP_RSS_CONFIG 0x3f0
+
+#define S_TNL4TUPEN    29
+#define V_TNL4TUPEN(x) ((x) << S_TNL4TUPEN)
+#define F_TNL4TUPEN    V_TNL4TUPEN(1U)
+
+#define S_TNL2TUPEN    28
+#define V_TNL2TUPEN(x) ((x) << S_TNL2TUPEN)
+#define F_TNL2TUPEN    V_TNL2TUPEN(1U)
+
+#define S_TNLPRTEN    26
+#define V_TNLPRTEN(x) ((x) << S_TNLPRTEN)
+#define F_TNLPRTEN    V_TNLPRTEN(1U)
+
+#define S_TNLMAPEN    25
+#define V_TNLMAPEN(x) ((x) << S_TNLMAPEN)
+#define F_TNLMAPEN    V_TNLMAPEN(1U)
+
+#define S_TNLLKPEN    24
+#define V_TNLLKPEN(x) ((x) << S_TNLLKPEN)
+#define F_TNLLKPEN    V_TNLLKPEN(1U)
+
+#define S_RRCPLCPUSIZE    4
+#define M_RRCPLCPUSIZE    0x7
+#define V_RRCPLCPUSIZE(x) ((x) << S_RRCPLCPUSIZE)
+
+#define S_RQFEEDBACKENABLE    3
+#define V_RQFEEDBACKENABLE(x) ((x) << S_RQFEEDBACKENABLE)
+#define F_RQFEEDBACKENABLE    V_RQFEEDBACKENABLE(1U)
+
+#define S_DISABLE    0
+
+#define A_TP_TM_PIO_ADDR 0x418
+
+#define A_TP_TM_PIO_DATA 0x41c
+
+#define A_TP_TX_MOD_QUE_TABLE 0x420
+
+#define A_TP_TX_RESOURCE_LIMIT 0x424
+
+#define A_TP_TX_MOD_QUEUE_REQ_MAP 0x428
+
+#define S_TX_MOD_QUEUE_REQ_MAP    0
+#define M_TX_MOD_QUEUE_REQ_MAP    0xff
+#define V_TX_MOD_QUEUE_REQ_MAP(x) ((x) << S_TX_MOD_QUEUE_REQ_MAP)
+
+#define A_TP_TX_MOD_QUEUE_WEIGHT1 0x42c
+
+#define A_TP_TX_MOD_QUEUE_WEIGHT0 0x430
+
+#define A_TP_MOD_CHANNEL_WEIGHT 0x434
+
+#define A_TP_PIO_ADDR 0x440
+
+#define A_TP_PIO_DATA 0x444
+
+#define A_TP_RESET 0x44c
+
+#define S_FLSTINITENABLE    1
+#define V_FLSTINITENABLE(x) ((x) << S_FLSTINITENABLE)
+#define F_FLSTINITENABLE    V_FLSTINITENABLE(1U)
+
+#define S_TPRESET    0
+#define V_TPRESET(x) ((x) << S_TPRESET)
+#define F_TPRESET    V_TPRESET(1U)
+
+#define A_TP_CMM_MM_RX_FLST_BASE 0x460
+
+#define A_TP_CMM_MM_TX_FLST_BASE 0x464
+
+#define A_TP_CMM_MM_PS_FLST_BASE 0x468
+
+#define A_TP_MIB_INDEX 0x450
+
+#define A_TP_MIB_RDATA 0x454
+
+#define A_TP_CMM_MM_MAX_PSTRUCT 0x46c
+
+#define A_TP_INT_ENABLE 0x470
+
+#define A_TP_INT_CAUSE 0x474
+
+#define A_TP_TX_MOD_Q1_Q0_RATE_LIMIT 0x8
+
+#define A_TP_TX_DROP_CFG_CH0 0x12b
+
+#define A_TP_TX_DROP_MODE 0x12f
+
+#define A_TP_EGRESS_CONFIG 0x145
+
+#define S_REWRITEFORCETOSIZE    0
+#define V_REWRITEFORCETOSIZE(x) ((x) << S_REWRITEFORCETOSIZE)
+#define F_REWRITEFORCETOSIZE    V_REWRITEFORCETOSIZE(1U)
+
+#define A_TP_TX_TRC_KEY0 0x20
+
+#define A_TP_RX_TRC_KEY0 0x120
+
+#define A_ULPRX_CTL 0x500
+
+#define S_ROUND_ROBIN    4
+#define V_ROUND_ROBIN(x) ((x) << S_ROUND_ROBIN)
+#define F_ROUND_ROBIN    V_ROUND_ROBIN(1U)
+
+#define A_ULPRX_INT_ENABLE 0x504
+
+#define S_PARERR    0
+#define V_PARERR(x) ((x) << S_PARERR)
+#define F_PARERR    V_PARERR(1U)
+
+#define A_ULPRX_INT_CAUSE 0x508
+
+#define A_ULPRX_ISCSI_LLIMIT 0x50c
+
+#define A_ULPRX_ISCSI_ULIMIT 0x510
+
+#define A_ULPRX_ISCSI_TAGMASK 0x514
+
+#define A_ULPRX_TDDP_LLIMIT 0x51c
+
+#define A_ULPRX_TDDP_ULIMIT 0x520
+
+#define A_ULPRX_STAG_LLIMIT 0x52c
+
+#define A_ULPRX_STAG_ULIMIT 0x530
+
+#define A_ULPRX_RQ_LLIMIT 0x534
+#define A_ULPRX_RQ_LLIMIT 0x534
+
+#define A_ULPRX_RQ_ULIMIT 0x538
+#define A_ULPRX_RQ_ULIMIT 0x538
+
+#define A_ULPRX_PBL_LLIMIT 0x53c
+
+#define A_ULPRX_PBL_ULIMIT 0x540
+#define A_ULPRX_PBL_ULIMIT 0x540
+
+#define A_ULPRX_TDDP_TAGMASK 0x524
+
+#define A_ULPRX_RQ_LLIMIT 0x534
+#define A_ULPRX_RQ_LLIMIT 0x534
+
+#define A_ULPRX_RQ_ULIMIT 0x538
+#define A_ULPRX_RQ_ULIMIT 0x538
+
+#define A_ULPRX_PBL_ULIMIT 0x540
+#define A_ULPRX_PBL_ULIMIT 0x540
+
+#define A_ULPTX_CONFIG 0x580
+
+#define S_CFG_RR_ARB    0
+#define V_CFG_RR_ARB(x) ((x) << S_CFG_RR_ARB)
+#define F_CFG_RR_ARB    V_CFG_RR_ARB(1U)
+
+#define A_ULPTX_INT_ENABLE 0x584
+
+#define S_PBL_BOUND_ERR_CH1    1
+#define V_PBL_BOUND_ERR_CH1(x) ((x) << S_PBL_BOUND_ERR_CH1)
+#define F_PBL_BOUND_ERR_CH1    V_PBL_BOUND_ERR_CH1(1U)
+
+#define S_PBL_BOUND_ERR_CH0    0
+#define V_PBL_BOUND_ERR_CH0(x) ((x) << S_PBL_BOUND_ERR_CH0)
+#define F_PBL_BOUND_ERR_CH0    V_PBL_BOUND_ERR_CH0(1U)
+
+#define A_ULPTX_INT_CAUSE 0x588
+
+#define A_ULPTX_TPT_LLIMIT 0x58c
+
+#define A_ULPTX_TPT_ULIMIT 0x590
+
+#define A_ULPTX_PBL_LLIMIT 0x594
+
+#define A_ULPTX_PBL_ULIMIT 0x598
+
+#define A_ULPTX_DMA_WEIGHT 0x5ac
+
+#define S_D1_WEIGHT    16
+#define M_D1_WEIGHT    0xffff
+#define V_D1_WEIGHT(x) ((x) << S_D1_WEIGHT)
+
+#define S_D0_WEIGHT    0
+#define M_D0_WEIGHT    0xffff
+#define V_D0_WEIGHT(x) ((x) << S_D0_WEIGHT)
+
+#define A_PM1_RX_CFG 0x5c0
+
+#define A_PM1_RX_INT_ENABLE 0x5d8
+
+#define S_ZERO_E_CMD_ERROR    18
+#define V_ZERO_E_CMD_ERROR(x) ((x) << S_ZERO_E_CMD_ERROR)
+#define F_ZERO_E_CMD_ERROR    V_ZERO_E_CMD_ERROR(1U)
+
+#define S_IESPI0_FIFO2X_RX_FRAMING_ERROR    17
+#define V_IESPI0_FIFO2X_RX_FRAMING_ERROR(x) ((x) << S_IESPI0_FIFO2X_RX_FRAMING_ERROR)
+#define F_IESPI0_FIFO2X_RX_FRAMING_ERROR    V_IESPI0_FIFO2X_RX_FRAMING_ERROR(1U)
+
+#define S_IESPI1_FIFO2X_RX_FRAMING_ERROR    16
+#define V_IESPI1_FIFO2X_RX_FRAMING_ERROR(x) ((x) << S_IESPI1_FIFO2X_RX_FRAMING_ERROR)
+#define F_IESPI1_FIFO2X_RX_FRAMING_ERROR    V_IESPI1_FIFO2X_RX_FRAMING_ERROR(1U)
+
+#define S_IESPI0_RX_FRAMING_ERROR    15
+#define V_IESPI0_RX_FRAMING_ERROR(x) ((x) << S_IESPI0_RX_FRAMING_ERROR)
+#define F_IESPI0_RX_FRAMING_ERROR    V_IESPI0_RX_FRAMING_ERROR(1U)
+
+#define S_IESPI1_RX_FRAMING_ERROR    14
+#define V_IESPI1_RX_FRAMING_ERROR(x) ((x) << S_IESPI1_RX_FRAMING_ERROR)
+#define F_IESPI1_RX_FRAMING_ERROR    V_IESPI1_RX_FRAMING_ERROR(1U)
+
+#define S_IESPI0_TX_FRAMING_ERROR    13
+#define V_IESPI0_TX_FRAMING_ERROR(x) ((x) << S_IESPI0_TX_FRAMING_ERROR)
+#define F_IESPI0_TX_FRAMING_ERROR    V_IESPI0_TX_FRAMING_ERROR(1U)
+
+#define S_IESPI1_TX_FRAMING_ERROR    12
+#define V_IESPI1_TX_FRAMING_ERROR(x) ((x) << S_IESPI1_TX_FRAMING_ERROR)
+#define F_IESPI1_TX_FRAMING_ERROR    V_IESPI1_TX_FRAMING_ERROR(1U)
+
+#define S_OCSPI0_RX_FRAMING_ERROR    11
+#define V_OCSPI0_RX_FRAMING_ERROR(x) ((x) << S_OCSPI0_RX_FRAMING_ERROR)
+#define F_OCSPI0_RX_FRAMING_ERROR    V_OCSPI0_RX_FRAMING_ERROR(1U)
+
+#define S_OCSPI1_RX_FRAMING_ERROR    10
+#define V_OCSPI1_RX_FRAMING_ERROR(x) ((x) << S_OCSPI1_RX_FRAMING_ERROR)
+#define F_OCSPI1_RX_FRAMING_ERROR    V_OCSPI1_RX_FRAMING_ERROR(1U)
+
+#define S_OCSPI0_TX_FRAMING_ERROR    9
+#define V_OCSPI0_TX_FRAMING_ERROR(x) ((x) << S_OCSPI0_TX_FRAMING_ERROR)
+#define F_OCSPI0_TX_FRAMING_ERROR    V_OCSPI0_TX_FRAMING_ERROR(1U)
+
+#define S_OCSPI1_TX_FRAMING_ERROR    8
+#define V_OCSPI1_TX_FRAMING_ERROR(x) ((x) << S_OCSPI1_TX_FRAMING_ERROR)
+#define F_OCSPI1_TX_FRAMING_ERROR    V_OCSPI1_TX_FRAMING_ERROR(1U)
+
+#define S_OCSPI0_OFIFO2X_TX_FRAMING_ERROR    7
+#define V_OCSPI0_OFIFO2X_TX_FRAMING_ERROR(x) ((x) << S_OCSPI0_OFIFO2X_TX_FRAMING_ERROR)
+#define F_OCSPI0_OFIFO2X_TX_FRAMING_ERROR    V_OCSPI0_OFIFO2X_TX_FRAMING_ERROR(1U)
+
+#define S_OCSPI1_OFIFO2X_TX_FRAMING_ERROR    6
+#define V_OCSPI1_OFIFO2X_TX_FRAMING_ERROR(x) ((x) << S_OCSPI1_OFIFO2X_TX_FRAMING_ERROR)
+#define F_OCSPI1_OFIFO2X_TX_FRAMING_ERROR    V_OCSPI1_OFIFO2X_TX_FRAMING_ERROR(1U)
+
+#define S_IESPI_PAR_ERROR    3
+#define M_IESPI_PAR_ERROR    0x7
+
+#define V_IESPI_PAR_ERROR(x) ((x) << S_IESPI_PAR_ERROR)
+
+#define S_OCSPI_PAR_ERROR    0
+#define M_OCSPI_PAR_ERROR    0x7
+
+#define V_OCSPI_PAR_ERROR(x) ((x) << S_OCSPI_PAR_ERROR)
+
+#define A_PM1_RX_INT_CAUSE 0x5dc
+
+#define A_PM1_TX_CFG 0x5e0
+
+#define A_PM1_TX_INT_ENABLE 0x5f8
+
+#define S_ZERO_C_CMD_ERROR    18
+#define V_ZERO_C_CMD_ERROR(x) ((x) << S_ZERO_C_CMD_ERROR)
+#define F_ZERO_C_CMD_ERROR    V_ZERO_C_CMD_ERROR(1U)
+
+#define S_ICSPI0_FIFO2X_RX_FRAMING_ERROR    17
+#define V_ICSPI0_FIFO2X_RX_FRAMING_ERROR(x) ((x) << S_ICSPI0_FIFO2X_RX_FRAMING_ERROR)
+#define F_ICSPI0_FIFO2X_RX_FRAMING_ERROR    V_ICSPI0_FIFO2X_RX_FRAMING_ERROR(1U)
+
+#define S_ICSPI1_FIFO2X_RX_FRAMING_ERROR    16
+#define V_ICSPI1_FIFO2X_RX_FRAMING_ERROR(x) ((x) << S_ICSPI1_FIFO2X_RX_FRAMING_ERROR)
+#define F_ICSPI1_FIFO2X_RX_FRAMING_ERROR    V_ICSPI1_FIFO2X_RX_FRAMING_ERROR(1U)
+
+#define S_ICSPI0_RX_FRAMING_ERROR    15
+#define V_ICSPI0_RX_FRAMING_ERROR(x) ((x) << S_ICSPI0_RX_FRAMING_ERROR)
+#define F_ICSPI0_RX_FRAMING_ERROR    V_ICSPI0_RX_FRAMING_ERROR(1U)
+
+#define S_ICSPI1_RX_FRAMING_ERROR    14
+#define V_ICSPI1_RX_FRAMING_ERROR(x) ((x) << S_ICSPI1_RX_FRAMING_ERROR)
+#define F_ICSPI1_RX_FRAMING_ERROR    V_ICSPI1_RX_FRAMING_ERROR(1U)
+
+#define S_ICSPI0_TX_FRAMING_ERROR    13
+#define V_ICSPI0_TX_FRAMING_ERROR(x) ((x) << S_ICSPI0_TX_FRAMING_ERROR)
+#define F_ICSPI0_TX_FRAMING_ERROR    V_ICSPI0_TX_FRAMING_ERROR(1U)
+
+#define S_ICSPI1_TX_FRAMING_ERROR    12
+#define V_ICSPI1_TX_FRAMING_ERROR(x) ((x) << S_ICSPI1_TX_FRAMING_ERROR)
+#define F_ICSPI1_TX_FRAMING_ERROR    V_ICSPI1_TX_FRAMING_ERROR(1U)
+
+#define S_OESPI0_RX_FRAMING_ERROR    11
+#define V_OESPI0_RX_FRAMING_ERROR(x) ((x) << S_OESPI0_RX_FRAMING_ERROR)
+#define F_OESPI0_RX_FRAMING_ERROR    V_OESPI0_RX_FRAMING_ERROR(1U)
+
+#define S_OESPI1_RX_FRAMING_ERROR    10
+#define V_OESPI1_RX_FRAMING_ERROR(x) ((x) << S_OESPI1_RX_FRAMING_ERROR)
+#define F_OESPI1_RX_FRAMING_ERROR    V_OESPI1_RX_FRAMING_ERROR(1U)
+
+#define S_OESPI0_TX_FRAMING_ERROR    9
+#define V_OESPI0_TX_FRAMING_ERROR(x) ((x) << S_OESPI0_TX_FRAMING_ERROR)
+#define F_OESPI0_TX_FRAMING_ERROR    V_OESPI0_TX_FRAMING_ERROR(1U)
+
+#define S_OESPI1_TX_FRAMING_ERROR    8
+#define V_OESPI1_TX_FRAMING_ERROR(x) ((x) << S_OESPI1_TX_FRAMING_ERROR)
+#define F_OESPI1_TX_FRAMING_ERROR    V_OESPI1_TX_FRAMING_ERROR(1U)
+
+#define S_OESPI0_OFIFO2X_TX_FRAMING_ERROR    7
+#define V_OESPI0_OFIFO2X_TX_FRAMING_ERROR(x) ((x) << S_OESPI0_OFIFO2X_TX_FRAMING_ERROR)
+#define F_OESPI0_OFIFO2X_TX_FRAMING_ERROR    V_OESPI0_OFIFO2X_TX_FRAMING_ERROR(1U)
+
+#define S_OESPI1_OFIFO2X_TX_FRAMING_ERROR    6
+#define V_OESPI1_OFIFO2X_TX_FRAMING_ERROR(x) ((x) << S_OESPI1_OFIFO2X_TX_FRAMING_ERROR)
+#define F_OESPI1_OFIFO2X_TX_FRAMING_ERROR    V_OESPI1_OFIFO2X_TX_FRAMING_ERROR(1U)
+
+#define S_ICSPI_PAR_ERROR    3
+#define M_ICSPI_PAR_ERROR    0x7
+
+#define V_ICSPI_PAR_ERROR(x) ((x) << S_ICSPI_PAR_ERROR)
+
+#define S_OESPI_PAR_ERROR    0
+#define M_OESPI_PAR_ERROR    0x7
+
+#define V_OESPI_PAR_ERROR(x) ((x) << S_OESPI_PAR_ERROR)
+
+#define A_PM1_TX_INT_CAUSE 0x5fc
+
+#define A_MPS_CFG 0x600
+
+#define S_TPRXPORTEN    4
+#define V_TPRXPORTEN(x) ((x) << S_TPRXPORTEN)
+#define F_TPRXPORTEN    V_TPRXPORTEN(1U)
+
+#define S_TPTXPORT1EN    3
+#define V_TPTXPORT1EN(x) ((x) << S_TPTXPORT1EN)
+#define F_TPTXPORT1EN    V_TPTXPORT1EN(1U)
+
+#define S_TPTXPORT0EN    2
+#define V_TPTXPORT0EN(x) ((x) << S_TPTXPORT0EN)
+#define F_TPTXPORT0EN    V_TPTXPORT0EN(1U)
+
+#define S_PORT1ACTIVE    1
+#define V_PORT1ACTIVE(x) ((x) << S_PORT1ACTIVE)
+#define F_PORT1ACTIVE    V_PORT1ACTIVE(1U)
+
+#define S_PORT0ACTIVE    0
+#define V_PORT0ACTIVE(x) ((x) << S_PORT0ACTIVE)
+#define F_PORT0ACTIVE    V_PORT0ACTIVE(1U)
+
+#define S_ENFORCEPKT    11
+#define V_ENFORCEPKT(x) ((x) << S_ENFORCEPKT)
+#define F_ENFORCEPKT    V_ENFORCEPKT(1U)
+
+#define A_MPS_INT_ENABLE 0x61c
+
+#define S_MCAPARERRENB    6
+#define M_MCAPARERRENB    0x7
+
+#define V_MCAPARERRENB(x) ((x) << S_MCAPARERRENB)
+
+#define S_RXTPPARERRENB    4
+#define M_RXTPPARERRENB    0x3
+
+#define V_RXTPPARERRENB(x) ((x) << S_RXTPPARERRENB)
+
+#define S_TX1TPPARERRENB    2
+#define M_TX1TPPARERRENB    0x3
+
+#define V_TX1TPPARERRENB(x) ((x) << S_TX1TPPARERRENB)
+
+#define S_TX0TPPARERRENB    0
+#define M_TX0TPPARERRENB    0x3
+
+#define V_TX0TPPARERRENB(x) ((x) << S_TX0TPPARERRENB)
+
+#define A_MPS_INT_CAUSE 0x620
+
+#define S_MCAPARERR    6
+#define M_MCAPARERR    0x7
+
+#define V_MCAPARERR(x) ((x) << S_MCAPARERR)
+
+#define S_RXTPPARERR    4
+#define M_RXTPPARERR    0x3
+
+#define V_RXTPPARERR(x) ((x) << S_RXTPPARERR)
+
+#define S_TX1TPPARERR    2
+#define M_TX1TPPARERR    0x3
+
+#define V_TX1TPPARERR(x) ((x) << S_TX1TPPARERR)
+
+#define S_TX0TPPARERR    0
+#define M_TX0TPPARERR    0x3
+
+#define V_TX0TPPARERR(x) ((x) << S_TX0TPPARERR)
+
+#define A_CPL_SWITCH_CNTRL 0x640
+
+#define A_CPL_INTR_ENABLE 0x650
+
+#define S_CIM_OVFL_ERROR    4
+#define V_CIM_OVFL_ERROR(x) ((x) << S_CIM_OVFL_ERROR)
+#define F_CIM_OVFL_ERROR    V_CIM_OVFL_ERROR(1U)
+
+#define S_TP_FRAMING_ERROR    3
+#define V_TP_FRAMING_ERROR(x) ((x) << S_TP_FRAMING_ERROR)
+#define F_TP_FRAMING_ERROR    V_TP_FRAMING_ERROR(1U)
+
+#define S_SGE_FRAMING_ERROR    2
+#define V_SGE_FRAMING_ERROR(x) ((x) << S_SGE_FRAMING_ERROR)
+#define F_SGE_FRAMING_ERROR    V_SGE_FRAMING_ERROR(1U)
+
+#define S_CIM_FRAMING_ERROR    1
+#define V_CIM_FRAMING_ERROR(x) ((x) << S_CIM_FRAMING_ERROR)
+#define F_CIM_FRAMING_ERROR    V_CIM_FRAMING_ERROR(1U)
+
+#define S_ZERO_SWITCH_ERROR    0
+#define V_ZERO_SWITCH_ERROR(x) ((x) << S_ZERO_SWITCH_ERROR)
+#define F_ZERO_SWITCH_ERROR    V_ZERO_SWITCH_ERROR(1U)
+
+#define A_CPL_INTR_CAUSE 0x654
+
+#define A_CPL_MAP_TBL_DATA 0x65c
+
+#define A_SMB_GLOBAL_TIME_CFG 0x660
+
+#define A_I2C_CFG 0x6a0
+
+#define S_I2C_CLKDIV    0
+#define M_I2C_CLKDIV    0xfff
+#define V_I2C_CLKDIV(x) ((x) << S_I2C_CLKDIV)
+
+#define A_MI1_CFG 0x6b0
+
+#define S_CLKDIV    5
+#define M_CLKDIV    0xff
+#define V_CLKDIV(x) ((x) << S_CLKDIV)
+
+#define S_ST    3
+
+#define M_ST    0x3
+
+#define V_ST(x) ((x) << S_ST)
+
+#define G_ST(x) (((x) >> S_ST) & M_ST)
+
+#define S_PREEN    2
+#define V_PREEN(x) ((x) << S_PREEN)
+#define F_PREEN    V_PREEN(1U)
+
+#define S_MDIINV    1
+#define V_MDIINV(x) ((x) << S_MDIINV)
+#define F_MDIINV    V_MDIINV(1U)
+
+#define S_MDIEN    0
+#define V_MDIEN(x) ((x) << S_MDIEN)
+#define F_MDIEN    V_MDIEN(1U)
+
+#define A_MI1_ADDR 0x6b4
+
+#define S_PHYADDR    5
+#define M_PHYADDR    0x1f
+#define V_PHYADDR(x) ((x) << S_PHYADDR)
+
+#define S_REGADDR    0
+#define M_REGADDR    0x1f
+#define V_REGADDR(x) ((x) << S_REGADDR)
+
+#define A_MI1_DATA 0x6b8
+
+#define A_MI1_OP 0x6bc
+
+#define S_MDI_OP    0
+#define M_MDI_OP    0x3
+#define V_MDI_OP(x) ((x) << S_MDI_OP)
+
+#define A_SF_DATA 0x6d8
+
+#define A_SF_OP 0x6dc
+
+#define S_BYTECNT    1
+#define M_BYTECNT    0x3
+#define V_BYTECNT(x) ((x) << S_BYTECNT)
+
+#define A_PL_INT_ENABLE0 0x6e0
+
+#define S_T3DBG    23
+#define V_T3DBG(x) ((x) << S_T3DBG)
+#define F_T3DBG    V_T3DBG(1U)
+
+#define S_XGMAC0_1    20
+#define V_XGMAC0_1(x) ((x) << S_XGMAC0_1)
+#define F_XGMAC0_1    V_XGMAC0_1(1U)
+
+#define S_XGMAC0_0    19
+#define V_XGMAC0_0(x) ((x) << S_XGMAC0_0)
+#define F_XGMAC0_0    V_XGMAC0_0(1U)
+
+#define S_MC5A    18
+#define V_MC5A(x) ((x) << S_MC5A)
+#define F_MC5A    V_MC5A(1U)
+
+#define S_CPL_SWITCH    12
+#define V_CPL_SWITCH(x) ((x) << S_CPL_SWITCH)
+#define F_CPL_SWITCH    V_CPL_SWITCH(1U)
+
+#define S_MPS0    11
+#define V_MPS0(x) ((x) << S_MPS0)
+#define F_MPS0    V_MPS0(1U)
+
+#define S_PM1_TX    10
+#define V_PM1_TX(x) ((x) << S_PM1_TX)
+#define F_PM1_TX    V_PM1_TX(1U)
+
+#define S_PM1_RX    9
+#define V_PM1_RX(x) ((x) << S_PM1_RX)
+#define F_PM1_RX    V_PM1_RX(1U)
+
+#define S_ULP2_TX    8
+#define V_ULP2_TX(x) ((x) << S_ULP2_TX)
+#define F_ULP2_TX    V_ULP2_TX(1U)
+
+#define S_ULP2_RX    7
+#define V_ULP2_RX(x) ((x) << S_ULP2_RX)
+#define F_ULP2_RX    V_ULP2_RX(1U)
+
+#define S_TP1    6
+#define V_TP1(x) ((x) << S_TP1)
+#define F_TP1    V_TP1(1U)
+
+#define S_CIM    5
+#define V_CIM(x) ((x) << S_CIM)
+#define F_CIM    V_CIM(1U)
+
+#define S_MC7_CM    4
+#define V_MC7_CM(x) ((x) << S_MC7_CM)
+#define F_MC7_CM    V_MC7_CM(1U)
+
+#define S_MC7_PMTX    3
+#define V_MC7_PMTX(x) ((x) << S_MC7_PMTX)
+#define F_MC7_PMTX    V_MC7_PMTX(1U)
+
+#define S_MC7_PMRX    2
+#define V_MC7_PMRX(x) ((x) << S_MC7_PMRX)
+#define F_MC7_PMRX    V_MC7_PMRX(1U)
+
+#define S_PCIM0    1
+#define V_PCIM0(x) ((x) << S_PCIM0)
+#define F_PCIM0    V_PCIM0(1U)
+
+#define S_SGE3    0
+#define V_SGE3(x) ((x) << S_SGE3)
+#define F_SGE3    V_SGE3(1U)
+
+#define A_PL_INT_CAUSE0 0x6e4
+
+#define A_PL_RST 0x6f0
+
+#define S_CRSTWRM    1
+#define V_CRSTWRM(x) ((x) << S_CRSTWRM)
+#define F_CRSTWRM    V_CRSTWRM(1U)
+
+#define A_PL_REV 0x6f4
+
+#define A_PL_CLI 0x6f8
+
+#define A_MC5_DB_CONFIG 0x704
+
+#define S_TMTYPEHI    30
+#define V_TMTYPEHI(x) ((x) << S_TMTYPEHI)
+#define F_TMTYPEHI    V_TMTYPEHI(1U)
+
+#define S_TMPARTSIZE    28
+#define M_TMPARTSIZE    0x3
+#define V_TMPARTSIZE(x) ((x) << S_TMPARTSIZE)
+#define G_TMPARTSIZE(x) (((x) >> S_TMPARTSIZE) & M_TMPARTSIZE)
+
+#define S_TMTYPE    26
+#define M_TMTYPE    0x3
+#define V_TMTYPE(x) ((x) << S_TMTYPE)
+#define G_TMTYPE(x) (((x) >> S_TMTYPE) & M_TMTYPE)
+
+#define S_COMPEN    17
+#define V_COMPEN(x) ((x) << S_COMPEN)
+#define F_COMPEN    V_COMPEN(1U)
+
+#define S_PRTYEN    6
+#define V_PRTYEN(x) ((x) << S_PRTYEN)
+#define F_PRTYEN    V_PRTYEN(1U)
+
+#define S_MBUSEN    5
+#define V_MBUSEN(x) ((x) << S_MBUSEN)
+#define F_MBUSEN    V_MBUSEN(1U)
+
+#define S_DBGIEN    4
+#define V_DBGIEN(x) ((x) << S_DBGIEN)
+#define F_DBGIEN    V_DBGIEN(1U)
+
+#define S_TMRDY    2
+#define V_TMRDY(x) ((x) << S_TMRDY)
+#define F_TMRDY    V_TMRDY(1U)
+
+#define S_TMRST    1
+#define V_TMRST(x) ((x) << S_TMRST)
+#define F_TMRST    V_TMRST(1U)
+
+#define S_TMMODE    0
+#define V_TMMODE(x) ((x) << S_TMMODE)
+#define F_TMMODE    V_TMMODE(1U)
+
+#define F_TMMODE    V_TMMODE(1U)
+
+#define A_MC5_DB_ROUTING_TABLE_INDEX 0x70c
+
+#define A_MC5_DB_FILTER_TABLE 0x710
+
+#define A_MC5_DB_SERVER_INDEX 0x714
+
+#define A_MC5_DB_RSP_LATENCY 0x720
+
+#define S_RDLAT    16
+#define M_RDLAT    0x1f
+#define V_RDLAT(x) ((x) << S_RDLAT)
+
+#define S_LRNLAT    8
+#define M_LRNLAT    0x1f
+#define V_LRNLAT(x) ((x) << S_LRNLAT)
+
+#define S_SRCHLAT    0
+#define M_SRCHLAT    0x1f
+#define V_SRCHLAT(x) ((x) << S_SRCHLAT)
+
+#define A_MC5_DB_PART_ID_INDEX 0x72c
+
+#define A_MC5_DB_INT_ENABLE 0x740
+
+#define S_DELACTEMPTY    18
+#define V_DELACTEMPTY(x) ((x) << S_DELACTEMPTY)
+#define F_DELACTEMPTY    V_DELACTEMPTY(1U)
+
+#define S_DISPQPARERR    17
+#define V_DISPQPARERR(x) ((x) << S_DISPQPARERR)
+#define F_DISPQPARERR    V_DISPQPARERR(1U)
+
+#define S_REQQPARERR    16
+#define V_REQQPARERR(x) ((x) << S_REQQPARERR)
+#define F_REQQPARERR    V_REQQPARERR(1U)
+
+#define S_UNKNOWNCMD    15
+#define V_UNKNOWNCMD(x) ((x) << S_UNKNOWNCMD)
+#define F_UNKNOWNCMD    V_UNKNOWNCMD(1U)
+
+#define S_NFASRCHFAIL    8
+#define V_NFASRCHFAIL(x) ((x) << S_NFASRCHFAIL)
+#define F_NFASRCHFAIL    V_NFASRCHFAIL(1U)
+
+#define S_ACTRGNFULL    7
+#define V_ACTRGNFULL(x) ((x) << S_ACTRGNFULL)
+#define F_ACTRGNFULL    V_ACTRGNFULL(1U)
+
+#define S_PARITYERR    6
+#define V_PARITYERR(x) ((x) << S_PARITYERR)
+#define F_PARITYERR    V_PARITYERR(1U)
+
+#define A_MC5_DB_INT_CAUSE 0x744
+
+#define A_MC5_DB_DBGI_CONFIG 0x774
+
+#define A_MC5_DB_DBGI_REQ_CMD 0x778
+
+#define A_MC5_DB_DBGI_REQ_ADDR0 0x77c
+
+#define A_MC5_DB_DBGI_REQ_ADDR1 0x780
+
+#define A_MC5_DB_DBGI_REQ_ADDR2 0x784
+
+#define A_MC5_DB_DBGI_REQ_DATA0 0x788
+
+#define A_MC5_DB_DBGI_REQ_DATA1 0x78c
+
+#define A_MC5_DB_DBGI_REQ_DATA2 0x790
+
+#define A_MC5_DB_DBGI_RSP_STATUS 0x7b0
+
+#define S_DBGIRSPVALID    0
+#define V_DBGIRSPVALID(x) ((x) << S_DBGIRSPVALID)
+#define F_DBGIRSPVALID    V_DBGIRSPVALID(1U)
+
+#define A_MC5_DB_DBGI_RSP_DATA0 0x7b4
+
+#define A_MC5_DB_DBGI_RSP_DATA1 0x7b8
+
+#define A_MC5_DB_DBGI_RSP_DATA2 0x7bc
+
+#define A_MC5_DB_POPEN_DATA_WR_CMD 0x7cc
+
+#define A_MC5_DB_POPEN_MASK_WR_CMD 0x7d0
+
+#define A_MC5_DB_AOPEN_SRCH_CMD 0x7d4
+
+#define A_MC5_DB_AOPEN_LRN_CMD 0x7d8
+
+#define A_MC5_DB_SYN_SRCH_CMD 0x7dc
+
+#define A_MC5_DB_SYN_LRN_CMD 0x7e0
+
+#define A_MC5_DB_ACK_SRCH_CMD 0x7e4
+
+#define A_MC5_DB_ACK_LRN_CMD 0x7e8
+
+#define A_MC5_DB_ILOOKUP_CMD 0x7ec
+
+#define A_MC5_DB_ELOOKUP_CMD 0x7f0
+
+#define A_MC5_DB_DATA_WRITE_CMD 0x7f4
+
+#define A_MC5_DB_DATA_READ_CMD 0x7f8
+
+#define XGMAC0_0_BASE_ADDR 0x800
+
+#define A_XGM_TX_CTRL 0x800
+
+#define S_TXEN    0
+#define V_TXEN(x) ((x) << S_TXEN)
+#define F_TXEN    V_TXEN(1U)
+
+#define A_XGM_TX_CFG 0x804
+
+#define S_TXPAUSEEN    0
+#define V_TXPAUSEEN(x) ((x) << S_TXPAUSEEN)
+#define F_TXPAUSEEN    V_TXPAUSEEN(1U)
+
+#define A_XGM_RX_CTRL 0x80c
+
+#define S_RXEN    0
+#define V_RXEN(x) ((x) << S_RXEN)
+#define F_RXEN    V_RXEN(1U)
+
+#define A_XGM_RX_CFG 0x810
+
+#define S_DISPAUSEFRAMES    9
+#define V_DISPAUSEFRAMES(x) ((x) << S_DISPAUSEFRAMES)
+#define F_DISPAUSEFRAMES    V_DISPAUSEFRAMES(1U)
+
+#define S_EN1536BFRAMES    8
+#define V_EN1536BFRAMES(x) ((x) << S_EN1536BFRAMES)
+#define F_EN1536BFRAMES    V_EN1536BFRAMES(1U)
+
+#define S_ENJUMBO    7
+#define V_ENJUMBO(x) ((x) << S_ENJUMBO)
+#define F_ENJUMBO    V_ENJUMBO(1U)
+
+#define S_RMFCS    6
+#define V_RMFCS(x) ((x) << S_RMFCS)
+#define F_RMFCS    V_RMFCS(1U)
+
+#define S_ENHASHMCAST    2
+#define V_ENHASHMCAST(x) ((x) << S_ENHASHMCAST)
+#define F_ENHASHMCAST    V_ENHASHMCAST(1U)
+
+#define S_COPYALLFRAMES    0
+#define V_COPYALLFRAMES(x) ((x) << S_COPYALLFRAMES)
+#define F_COPYALLFRAMES    V_COPYALLFRAMES(1U)
+
+#define A_XGM_RX_HASH_LOW 0x814
+
+#define A_XGM_RX_HASH_HIGH 0x818
+
+#define A_XGM_RX_EXACT_MATCH_LOW_1 0x81c
+
+#define A_XGM_RX_EXACT_MATCH_HIGH_1 0x820
+
+#define A_XGM_RX_EXACT_MATCH_LOW_2 0x824
+
+#define A_XGM_RX_EXACT_MATCH_LOW_3 0x82c
+
+#define A_XGM_RX_EXACT_MATCH_LOW_4 0x834
+
+#define A_XGM_RX_EXACT_MATCH_LOW_5 0x83c
+
+#define A_XGM_RX_EXACT_MATCH_LOW_6 0x844
+
+#define A_XGM_RX_EXACT_MATCH_LOW_7 0x84c
+
+#define A_XGM_RX_EXACT_MATCH_LOW_8 0x854
+
+#define A_XGM_STAT_CTRL 0x880
+
+#define S_CLRSTATS    2
+#define V_CLRSTATS(x) ((x) << S_CLRSTATS)
+#define F_CLRSTATS    V_CLRSTATS(1U)
+
+#define A_XGM_RXFIFO_CFG 0x884
+
+#define S_RXFIFOPAUSEHWM    17
+#define M_RXFIFOPAUSEHWM    0xfff
+
+#define V_RXFIFOPAUSEHWM(x) ((x) << S_RXFIFOPAUSEHWM)
+
+#define G_RXFIFOPAUSEHWM(x) (((x) >> S_RXFIFOPAUSEHWM) & M_RXFIFOPAUSEHWM)
+
+#define S_RXFIFOPAUSELWM    5
+#define M_RXFIFOPAUSELWM    0xfff
+
+#define V_RXFIFOPAUSELWM(x) ((x) << S_RXFIFOPAUSELWM)
+
+#define G_RXFIFOPAUSELWM(x) (((x) >> S_RXFIFOPAUSELWM) & M_RXFIFOPAUSELWM)
+
+#define S_RXSTRFRWRD    1
+#define V_RXSTRFRWRD(x) ((x) << S_RXSTRFRWRD)
+#define F_RXSTRFRWRD    V_RXSTRFRWRD(1U)
+
+#define S_DISERRFRAMES    0
+#define V_DISERRFRAMES(x) ((x) << S_DISERRFRAMES)
+#define F_DISERRFRAMES    V_DISERRFRAMES(1U)
+
+#define A_XGM_TXFIFO_CFG 0x888
+
+#define S_TXFIFOTHRESH    4
+#define M_TXFIFOTHRESH    0x1ff
+
+#define V_TXFIFOTHRESH(x) ((x) << S_TXFIFOTHRESH)
+
+#define A_XGM_SERDES_CTRL 0x890
+#define A_XGM_SERDES_CTRL0 0x8e0
+
+#define S_SERDESRESET_    24
+#define V_SERDESRESET_(x) ((x) << S_SERDESRESET_)
+#define F_SERDESRESET_    V_SERDESRESET_(1U)
+
+#define S_RXENABLE    4
+#define V_RXENABLE(x) ((x) << S_RXENABLE)
+#define F_RXENABLE    V_RXENABLE(1U)
+
+#define S_TXENABLE    3
+#define V_TXENABLE(x) ((x) << S_TXENABLE)
+#define F_TXENABLE    V_TXENABLE(1U)
+
+#define A_XGM_PAUSE_TIMER 0x890
+
+#define A_XGM_RGMII_IMP 0x89c
+
+#define S_XGM_IMPSETUPDATE    6
+#define V_XGM_IMPSETUPDATE(x) ((x) << S_XGM_IMPSETUPDATE)
+#define F_XGM_IMPSETUPDATE    V_XGM_IMPSETUPDATE(1U)
+
+#define S_RGMIIIMPPD    3
+#define M_RGMIIIMPPD    0x7
+#define V_RGMIIIMPPD(x) ((x) << S_RGMIIIMPPD)
+
+#define S_RGMIIIMPPU    0
+#define M_RGMIIIMPPU    0x7
+#define V_RGMIIIMPPU(x) ((x) << S_RGMIIIMPPU)
+
+#define S_CALRESET    8
+#define V_CALRESET(x) ((x) << S_CALRESET)
+#define F_CALRESET    V_CALRESET(1U)
+
+#define S_CALUPDATE    7
+#define V_CALUPDATE(x) ((x) << S_CALUPDATE)
+#define F_CALUPDATE    V_CALUPDATE(1U)
+
+#define A_XGM_XAUI_IMP 0x8a0
+
+#define S_CALBUSY    31
+#define V_CALBUSY(x) ((x) << S_CALBUSY)
+#define F_CALBUSY    V_CALBUSY(1U)
+
+#define S_XGM_CALFAULT    29
+#define V_XGM_CALFAULT(x) ((x) << S_XGM_CALFAULT)
+#define F_XGM_CALFAULT    V_XGM_CALFAULT(1U)
+
+#define S_CALIMP    24
+#define M_CALIMP    0x1f
+#define V_CALIMP(x) ((x) << S_CALIMP)
+#define G_CALIMP(x) (((x) >> S_CALIMP) & M_CALIMP)
+
+#define S_XAUIIMP    0
+#define M_XAUIIMP    0x7
+#define V_XAUIIMP(x) ((x) << S_XAUIIMP)
+
+#define A_XGM_RX_MAX_PKT_SIZE 0x8a8
+#define A_XGM_RX_MAX_PKT_SIZE_ERR_CNT 0x9a4
+
+#define A_XGM_RESET_CTRL 0x8ac
+
+#define S_XG2G_RESET_    3
+#define V_XG2G_RESET_(x) ((x) << S_XG2G_RESET_)
+#define F_XG2G_RESET_    V_XG2G_RESET_(1U)
+
+#define S_RGMII_RESET_    2
+#define V_RGMII_RESET_(x) ((x) << S_RGMII_RESET_)
+#define F_RGMII_RESET_    V_RGMII_RESET_(1U)
+
+#define S_PCS_RESET_    1
+#define V_PCS_RESET_(x) ((x) << S_PCS_RESET_)
+#define F_PCS_RESET_    V_PCS_RESET_(1U)
+
+#define S_MAC_RESET_    0
+#define V_MAC_RESET_(x) ((x) << S_MAC_RESET_)
+#define F_MAC_RESET_    V_MAC_RESET_(1U)
+
+#define A_XGM_PORT_CFG 0x8b8
+
+#define S_CLKDIVRESET_    3
+#define V_CLKDIVRESET_(x) ((x) << S_CLKDIVRESET_)
+#define F_CLKDIVRESET_    V_CLKDIVRESET_(1U)
+
+#define S_PORTSPEED    1
+#define M_PORTSPEED    0x3
+
+#define V_PORTSPEED(x) ((x) << S_PORTSPEED)
+
+#define S_ENRGMII    0
+#define V_ENRGMII(x) ((x) << S_ENRGMII)
+#define F_ENRGMII    V_ENRGMII(1U)
+
+#define A_XGM_INT_ENABLE 0x8d4
+
+#define S_TXFIFO_PRTY_ERR    17
+#define M_TXFIFO_PRTY_ERR    0x7
+
+#define V_TXFIFO_PRTY_ERR(x) ((x) << S_TXFIFO_PRTY_ERR)
+
+#define S_RXFIFO_PRTY_ERR    14
+#define M_RXFIFO_PRTY_ERR    0x7
+
+#define V_RXFIFO_PRTY_ERR(x) ((x) << S_RXFIFO_PRTY_ERR)
+
+#define S_TXFIFO_UNDERRUN    13
+#define V_TXFIFO_UNDERRUN(x) ((x) << S_TXFIFO_UNDERRUN)
+#define F_TXFIFO_UNDERRUN    V_TXFIFO_UNDERRUN(1U)
+
+#define S_RXFIFO_OVERFLOW    12
+#define V_RXFIFO_OVERFLOW(x) ((x) << S_RXFIFO_OVERFLOW)
+#define F_RXFIFO_OVERFLOW    V_RXFIFO_OVERFLOW(1U)
+
+#define S_SERDES_LOS    4
+#define M_SERDES_LOS    0xf
+
+#define V_SERDES_LOS(x) ((x) << S_SERDES_LOS)
+
+#define S_XAUIPCSCTCERR    3
+#define V_XAUIPCSCTCERR(x) ((x) << S_XAUIPCSCTCERR)
+#define F_XAUIPCSCTCERR    V_XAUIPCSCTCERR(1U)
+
+#define S_XAUIPCSALIGNCHANGE    2
+#define V_XAUIPCSALIGNCHANGE(x) ((x) << S_XAUIPCSALIGNCHANGE)
+#define F_XAUIPCSALIGNCHANGE    V_XAUIPCSALIGNCHANGE(1U)
+
+#define A_XGM_INT_CAUSE 0x8d8
+
+#define A_XGM_XAUI_ACT_CTRL 0x8dc
+
+#define S_TXACTENABLE    1
+#define V_TXACTENABLE(x) ((x) << S_TXACTENABLE)
+#define F_TXACTENABLE    V_TXACTENABLE(1U)
+
+#define A_XGM_SERDES_CTRL0 0x8e0
+
+#define S_RESET3    23
+#define V_RESET3(x) ((x) << S_RESET3)
+#define F_RESET3    V_RESET3(1U)
+
+#define S_RESET2    22
+#define V_RESET2(x) ((x) << S_RESET2)
+#define F_RESET2    V_RESET2(1U)
+
+#define S_RESET1    21
+#define V_RESET1(x) ((x) << S_RESET1)
+#define F_RESET1    V_RESET1(1U)
+
+#define S_RESET0    20
+#define V_RESET0(x) ((x) << S_RESET0)
+#define F_RESET0    V_RESET0(1U)
+
+#define S_PWRDN3    19
+#define V_PWRDN3(x) ((x) << S_PWRDN3)
+#define F_PWRDN3    V_PWRDN3(1U)
+
+#define S_PWRDN2    18
+#define V_PWRDN2(x) ((x) << S_PWRDN2)
+#define F_PWRDN2    V_PWRDN2(1U)
+
+#define S_PWRDN1    17
+#define V_PWRDN1(x) ((x) << S_PWRDN1)
+#define F_PWRDN1    V_PWRDN1(1U)
+
+#define S_PWRDN0    16
+#define V_PWRDN0(x) ((x) << S_PWRDN0)
+#define F_PWRDN0    V_PWRDN0(1U)
+
+#define S_RESETPLL23    15
+#define V_RESETPLL23(x) ((x) << S_RESETPLL23)
+#define F_RESETPLL23    V_RESETPLL23(1U)
+
+#define S_RESETPLL01    14
+#define V_RESETPLL01(x) ((x) << S_RESETPLL01)
+#define F_RESETPLL01    V_RESETPLL01(1U)
+
+#define A_XGM_SERDES_STAT0 0x8f0
+
+#define S_LOWSIG0    0
+#define V_LOWSIG0(x) ((x) << S_LOWSIG0)
+#define F_LOWSIG0    V_LOWSIG0(1U)
+
+#define A_XGM_SERDES_STAT3 0x8fc
+
+#define A_XGM_STAT_TX_BYTE_LOW 0x900
+
+#define A_XGM_STAT_TX_BYTE_HIGH 0x904
+
+#define A_XGM_STAT_TX_FRAME_LOW 0x908
+
+#define A_XGM_STAT_TX_FRAME_HIGH 0x90c
+
+#define A_XGM_STAT_TX_BCAST 0x910
+
+#define A_XGM_STAT_TX_MCAST 0x914
+
+#define A_XGM_STAT_TX_PAUSE 0x918
+
+#define A_XGM_STAT_TX_64B_FRAMES 0x91c
+
+#define A_XGM_STAT_TX_65_127B_FRAMES 0x920
+
+#define A_XGM_STAT_TX_128_255B_FRAMES 0x924
+
+#define A_XGM_STAT_TX_256_511B_FRAMES 0x928
+
+#define A_XGM_STAT_TX_512_1023B_FRAMES 0x92c
+
+#define A_XGM_STAT_TX_1024_1518B_FRAMES 0x930
+
+#define A_XGM_STAT_TX_1519_MAXB_FRAMES 0x934
+
+#define A_XGM_STAT_TX_ERR_FRAMES 0x938
+
+#define A_XGM_STAT_RX_BYTES_LOW 0x93c
+
+#define A_XGM_STAT_RX_BYTES_HIGH 0x940
+
+#define A_XGM_STAT_RX_FRAMES_LOW 0x944
+
+#define A_XGM_STAT_RX_FRAMES_HIGH 0x948
+
+#define A_XGM_STAT_RX_BCAST_FRAMES 0x94c
+
+#define A_XGM_STAT_RX_MCAST_FRAMES 0x950
+
+#define A_XGM_STAT_RX_PAUSE_FRAMES 0x954
+
+#define A_XGM_STAT_RX_64B_FRAMES 0x958
+
+#define A_XGM_STAT_RX_65_127B_FRAMES 0x95c
+
+#define A_XGM_STAT_RX_128_255B_FRAMES 0x960
+
+#define A_XGM_STAT_RX_256_511B_FRAMES 0x964
+
+#define A_XGM_STAT_RX_512_1023B_FRAMES 0x968
+
+#define A_XGM_STAT_RX_1024_1518B_FRAMES 0x96c
+
+#define A_XGM_STAT_RX_1519_MAXB_FRAMES 0x970
+
+#define A_XGM_STAT_RX_SHORT_FRAMES 0x974
+
+#define A_XGM_STAT_RX_OVERSIZE_FRAMES 0x978
+
+#define A_XGM_STAT_RX_JABBER_FRAMES 0x97c
+
+#define A_XGM_STAT_RX_CRC_ERR_FRAMES 0x980
+
+#define A_XGM_STAT_RX_LENGTH_ERR_FRAMES 0x984
+
+#define A_XGM_STAT_RX_SYM_CODE_ERR_FRAMES 0x988
+
+#define A_XGM_SERDES_STATUS0 0x98c
+
+#define A_XGM_SERDES_STATUS1 0x990
+
+#define S_CMULOCK    31
+#define V_CMULOCK(x) ((x) << S_CMULOCK)
+#define F_CMULOCK    V_CMULOCK(1U)
+
+#define A_XGM_RX_MAX_PKT_SIZE_ERR_CNT 0x9a4
+
+#define A_XGM_RX_SPI4_SOP_EOP_CNT 0x9ac
+
+#define XGMAC0_1_BASE_ADDR 0xa00
diff --git a/drivers/net/cxgb3/sge.c b/drivers/net/cxgb3/sge.c
new file mode 100644 (file)
index 0000000..3f2cf8a
--- /dev/null
@@ -0,0 +1,2681 @@
+/*
+ * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include <linux/skbuff.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/if_vlan.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/dma-mapping.h>
+#include "common.h"
+#include "regs.h"
+#include "sge_defs.h"
+#include "t3_cpl.h"
+#include "firmware_exports.h"
+
+#define USE_GTS 0
+
+#define SGE_RX_SM_BUF_SIZE 1536
+#define SGE_RX_COPY_THRES  256
+
+# define SGE_RX_DROP_THRES 16
+
+/*
+ * Period of the Tx buffer reclaim timer.  This timer does not need to run
+ * frequently as Tx buffers are usually reclaimed by new Tx packets.
+ */
+#define TX_RECLAIM_PERIOD (HZ / 4)
+
+/* WR size in bytes */
+#define WR_LEN (WR_FLITS * 8)
+
+/*
+ * Types of Tx queues in each queue set.  Order here matters, do not change.
+ */
+enum { TXQ_ETH, TXQ_OFLD, TXQ_CTRL };
+
+/* Values for sge_txq.flags */
+enum {
+       TXQ_RUNNING = 1 << 0,   /* fetch engine is running */
+       TXQ_LAST_PKT_DB = 1 << 1,       /* last packet rang the doorbell */
+};
+
+struct tx_desc {
+       u64 flit[TX_DESC_FLITS];
+};
+
+struct rx_desc {
+       __be32 addr_lo;
+       __be32 len_gen;
+       __be32 gen2;
+       __be32 addr_hi;
+};
+
+struct tx_sw_desc {            /* SW state per Tx descriptor */
+       struct sk_buff *skb;
+};
+
+struct rx_sw_desc {            /* SW state per Rx descriptor */
+       struct sk_buff *skb;
+        DECLARE_PCI_UNMAP_ADDR(dma_addr);
+};
+
+struct rsp_desc {              /* response queue descriptor */
+       struct rss_header rss_hdr;
+       __be32 flags;
+       __be32 len_cq;
+       u8 imm_data[47];
+       u8 intr_gen;
+};
+
+struct unmap_info {            /* packet unmapping info, overlays skb->cb */
+       int sflit;              /* start flit of first SGL entry in Tx descriptor */
+       u16 fragidx;            /* first page fragment in current Tx descriptor */
+       u16 addr_idx;           /* buffer index of first SGL entry in descriptor */
+       u32 len;                /* mapped length of skb main body */
+};
+
+/*
+ * Maps a number of flits to the number of Tx descriptors that can hold them.
+ * The formula is
+ *
+ * desc = 1 + (flits - 2) / (WR_FLITS - 1).
+ *
+ * HW allows up to 4 descriptors to be combined into a WR.
+ */
+static u8 flit_desc_map[] = {
+       0,
+#if SGE_NUM_GENBITS == 1
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+       4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
+#elif SGE_NUM_GENBITS == 2
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+       4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+#else
+# error "SGE_NUM_GENBITS must be 1 or 2"
+#endif
+};
+
+static inline struct sge_qset *fl_to_qset(const struct sge_fl *q, int qidx)
+{
+       return container_of(q, struct sge_qset, fl[qidx]);
+}
+
+static inline struct sge_qset *rspq_to_qset(const struct sge_rspq *q)
+{
+       return container_of(q, struct sge_qset, rspq);
+}
+
+static inline struct sge_qset *txq_to_qset(const struct sge_txq *q, int qidx)
+{
+       return container_of(q, struct sge_qset, txq[qidx]);
+}
+
+/**
+ *     refill_rspq - replenish an SGE response queue
+ *     @adapter: the adapter
+ *     @q: the response queue to replenish
+ *     @credits: how many new responses to make available
+ *
+ *     Replenishes a response queue by making the supplied number of responses
+ *     available to HW.
+ */
+static inline void refill_rspq(struct adapter *adapter,
+                              const struct sge_rspq *q, unsigned int credits)
+{
+       t3_write_reg(adapter, A_SG_RSPQ_CREDIT_RETURN,
+                    V_RSPQ(q->cntxt_id) | V_CREDITS(credits));
+}
+
+/**
+ *     need_skb_unmap - does the platform need unmapping of sk_buffs?
+ *
+ *     Returns true if the platfrom needs sk_buff unmapping.  The compiler
+ *     optimizes away unecessary code if this returns true.
+ */
+static inline int need_skb_unmap(void)
+{
+       /*
+        * This structure is used to tell if the platfrom needs buffer
+        * unmapping by checking if DECLARE_PCI_UNMAP_ADDR defines anything.
+        */
+       struct dummy {
+               DECLARE_PCI_UNMAP_ADDR(addr);
+       };
+
+       return sizeof(struct dummy) != 0;
+}
+
+/**
+ *     unmap_skb - unmap a packet main body and its page fragments
+ *     @skb: the packet
+ *     @q: the Tx queue containing Tx descriptors for the packet
+ *     @cidx: index of Tx descriptor
+ *     @pdev: the PCI device
+ *
+ *     Unmap the main body of an sk_buff and its page fragments, if any.
+ *     Because of the fairly complicated structure of our SGLs and the desire
+ *     to conserve space for metadata, we keep the information necessary to
+ *     unmap an sk_buff partly in the sk_buff itself (in its cb), and partly
+ *     in the Tx descriptors (the physical addresses of the various data
+ *     buffers).  The send functions initialize the state in skb->cb so we
+ *     can unmap the buffers held in the first Tx descriptor here, and we
+ *     have enough information at this point to update the state for the next
+ *     Tx descriptor.
+ */
+static inline void unmap_skb(struct sk_buff *skb, struct sge_txq *q,
+                            unsigned int cidx, struct pci_dev *pdev)
+{
+       const struct sg_ent *sgp;
+       struct unmap_info *ui = (struct unmap_info *)skb->cb;
+       int nfrags, frag_idx, curflit, j = ui->addr_idx;
+
+       sgp = (struct sg_ent *)&q->desc[cidx].flit[ui->sflit];
+
+       if (ui->len) {
+               pci_unmap_single(pdev, be64_to_cpu(sgp->addr[0]), ui->len,
+                                PCI_DMA_TODEVICE);
+               ui->len = 0;    /* so we know for next descriptor for this skb */
+               j = 1;
+       }
+
+       frag_idx = ui->fragidx;
+       curflit = ui->sflit + 1 + j;
+       nfrags = skb_shinfo(skb)->nr_frags;
+
+       while (frag_idx < nfrags && curflit < WR_FLITS) {
+               pci_unmap_page(pdev, be64_to_cpu(sgp->addr[j]),
+                              skb_shinfo(skb)->frags[frag_idx].size,
+                              PCI_DMA_TODEVICE);
+               j ^= 1;
+               if (j == 0) {
+                       sgp++;
+                       curflit++;
+               }
+               curflit++;
+               frag_idx++;
+       }
+
+       if (frag_idx < nfrags) {        /* SGL continues into next Tx descriptor */
+               ui->fragidx = frag_idx;
+               ui->addr_idx = j;
+               ui->sflit = curflit - WR_FLITS - j;     /* sflit can be -1 */
+       }
+}
+
+/**
+ *     free_tx_desc - reclaims Tx descriptors and their buffers
+ *     @adapter: the adapter
+ *     @q: the Tx queue to reclaim descriptors from
+ *     @n: the number of descriptors to reclaim
+ *
+ *     Reclaims Tx descriptors from an SGE Tx queue and frees the associated
+ *     Tx buffers.  Called with the Tx queue lock held.
+ */
+static void free_tx_desc(struct adapter *adapter, struct sge_txq *q,
+                        unsigned int n)
+{
+       struct tx_sw_desc *d;
+       struct pci_dev *pdev = adapter->pdev;
+       unsigned int cidx = q->cidx;
+
+       d = &q->sdesc[cidx];
+       while (n--) {
+               if (d->skb) {   /* an SGL is present */
+                       if (need_skb_unmap())
+                               unmap_skb(d->skb, q, cidx, pdev);
+                       if (d->skb->priority == cidx)
+                               kfree_skb(d->skb);
+               }
+               ++d;
+               if (++cidx == q->size) {
+                       cidx = 0;
+                       d = q->sdesc;
+               }
+       }
+       q->cidx = cidx;
+}
+
+/**
+ *     reclaim_completed_tx - reclaims completed Tx descriptors
+ *     @adapter: the adapter
+ *     @q: the Tx queue to reclaim completed descriptors from
+ *
+ *     Reclaims Tx descriptors that the SGE has indicated it has processed,
+ *     and frees the associated buffers if possible.  Called with the Tx
+ *     queue's lock held.
+ */
+static inline void reclaim_completed_tx(struct adapter *adapter,
+                                       struct sge_txq *q)
+{
+       unsigned int reclaim = q->processed - q->cleaned;
+
+       if (reclaim) {
+               free_tx_desc(adapter, q, reclaim);
+               q->cleaned += reclaim;
+               q->in_use -= reclaim;
+       }
+}
+
+/**
+ *     should_restart_tx - are there enough resources to restart a Tx queue?
+ *     @q: the Tx queue
+ *
+ *     Checks if there are enough descriptors to restart a suspended Tx queue.
+ */
+static inline int should_restart_tx(const struct sge_txq *q)
+{
+       unsigned int r = q->processed - q->cleaned;
+
+       return q->in_use - r < (q->size >> 1);
+}
+
+/**
+ *     free_rx_bufs - free the Rx buffers on an SGE free list
+ *     @pdev: the PCI device associated with the adapter
+ *     @rxq: the SGE free list to clean up
+ *
+ *     Release the buffers on an SGE free-buffer Rx queue.  HW fetching from
+ *     this queue should be stopped before calling this function.
+ */
+static void free_rx_bufs(struct pci_dev *pdev, struct sge_fl *q)
+{
+       unsigned int cidx = q->cidx;
+
+       while (q->credits--) {
+               struct rx_sw_desc *d = &q->sdesc[cidx];
+
+               pci_unmap_single(pdev, pci_unmap_addr(d, dma_addr),
+                                q->buf_size, PCI_DMA_FROMDEVICE);
+               kfree_skb(d->skb);
+               d->skb = NULL;
+               if (++cidx == q->size)
+                       cidx = 0;
+       }
+}
+
+/**
+ *     add_one_rx_buf - add a packet buffer to a free-buffer list
+ *     @skb: the buffer to add
+ *     @len: the buffer length
+ *     @d: the HW Rx descriptor to write
+ *     @sd: the SW Rx descriptor to write
+ *     @gen: the generation bit value
+ *     @pdev: the PCI device associated with the adapter
+ *
+ *     Add a buffer of the given length to the supplied HW and SW Rx
+ *     descriptors.
+ */
+static inline void add_one_rx_buf(struct sk_buff *skb, unsigned int len,
+                                 struct rx_desc *d, struct rx_sw_desc *sd,
+                                 unsigned int gen, struct pci_dev *pdev)
+{
+       dma_addr_t mapping;
+
+       sd->skb = skb;
+       mapping = pci_map_single(pdev, skb->data, len, PCI_DMA_FROMDEVICE);
+       pci_unmap_addr_set(sd, dma_addr, mapping);
+
+       d->addr_lo = cpu_to_be32(mapping);
+       d->addr_hi = cpu_to_be32((u64) mapping >> 32);
+       wmb();
+       d->len_gen = cpu_to_be32(V_FLD_GEN1(gen));
+       d->gen2 = cpu_to_be32(V_FLD_GEN2(gen));
+}
+
+/**
+ *     refill_fl - refill an SGE free-buffer list
+ *     @adapter: the adapter
+ *     @q: the free-list to refill
+ *     @n: the number of new buffers to allocate
+ *     @gfp: the gfp flags for allocating new buffers
+ *
+ *     (Re)populate an SGE free-buffer list with up to @n new packet buffers,
+ *     allocated with the supplied gfp flags.  The caller must assure that
+ *     @n does not exceed the queue's capacity.
+ */
+static void refill_fl(struct adapter *adap, struct sge_fl *q, int n, gfp_t gfp)
+{
+       struct rx_sw_desc *sd = &q->sdesc[q->pidx];
+       struct rx_desc *d = &q->desc[q->pidx];
+
+       while (n--) {
+               struct sk_buff *skb = alloc_skb(q->buf_size, gfp);
+
+               if (!skb)
+                       break;
+
+               add_one_rx_buf(skb, q->buf_size, d, sd, q->gen, adap->pdev);
+               d++;
+               sd++;
+               if (++q->pidx == q->size) {
+                       q->pidx = 0;
+                       q->gen ^= 1;
+                       sd = q->sdesc;
+                       d = q->desc;
+               }
+               q->credits++;
+       }
+
+       t3_write_reg(adap, A_SG_KDOORBELL, V_EGRCNTX(q->cntxt_id));
+}
+
+static inline void __refill_fl(struct adapter *adap, struct sge_fl *fl)
+{
+       refill_fl(adap, fl, min(16U, fl->size - fl->credits), GFP_ATOMIC);
+}
+
+/**
+ *     recycle_rx_buf - recycle a receive buffer
+ *     @adapter: the adapter
+ *     @q: the SGE free list
+ *     @idx: index of buffer to recycle
+ *
+ *     Recycles the specified buffer on the given free list by adding it at
+ *     the next available slot on the list.
+ */
+static void recycle_rx_buf(struct adapter *adap, struct sge_fl *q,
+                          unsigned int idx)
+{
+       struct rx_desc *from = &q->desc[idx];
+       struct rx_desc *to = &q->desc[q->pidx];
+
+       q->sdesc[q->pidx] = q->sdesc[idx];
+       to->addr_lo = from->addr_lo;    /* already big endian */
+       to->addr_hi = from->addr_hi;    /* likewise */
+       wmb();
+       to->len_gen = cpu_to_be32(V_FLD_GEN1(q->gen));
+       to->gen2 = cpu_to_be32(V_FLD_GEN2(q->gen));
+       q->credits++;
+
+       if (++q->pidx == q->size) {
+               q->pidx = 0;
+               q->gen ^= 1;
+       }
+       t3_write_reg(adap, A_SG_KDOORBELL, V_EGRCNTX(q->cntxt_id));
+}
+
+/**
+ *     alloc_ring - allocate resources for an SGE descriptor ring
+ *     @pdev: the PCI device
+ *     @nelem: the number of descriptors
+ *     @elem_size: the size of each descriptor
+ *     @sw_size: the size of the SW state associated with each ring element
+ *     @phys: the physical address of the allocated ring
+ *     @metadata: address of the array holding the SW state for the ring
+ *
+ *     Allocates resources for an SGE descriptor ring, such as Tx queues,
+ *     free buffer lists, or response queues.  Each SGE ring requires
+ *     space for its HW descriptors plus, optionally, space for the SW state
+ *     associated with each HW entry (the metadata).  The function returns
+ *     three values: the virtual address for the HW ring (the return value
+ *     of the function), the physical address of the HW ring, and the address
+ *     of the SW ring.
+ */
+static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
+                       size_t sw_size, dma_addr_t *phys, void *metadata)
+{
+       size_t len = nelem * elem_size;
+       void *s = NULL;
+       void *p = dma_alloc_coherent(&pdev->dev, len, phys, GFP_KERNEL);
+
+       if (!p)
+               return NULL;
+       if (sw_size) {
+               s = kcalloc(nelem, sw_size, GFP_KERNEL);
+
+               if (!s) {
+                       dma_free_coherent(&pdev->dev, len, p, *phys);
+                       return NULL;
+               }
+       }
+       if (metadata)
+               *(void **)metadata = s;
+       memset(p, 0, len);
+       return p;
+}
+
+/**
+ *     free_qset - free the resources of an SGE queue set
+ *     @adapter: the adapter owning the queue set
+ *     @q: the queue set
+ *
+ *     Release the HW and SW resources associated with an SGE queue set, such
+ *     as HW contexts, packet buffers, and descriptor rings.  Traffic to the
+ *     queue set must be quiesced prior to calling this.
+ */
+void t3_free_qset(struct adapter *adapter, struct sge_qset *q)
+{
+       int i;
+       struct pci_dev *pdev = adapter->pdev;
+
+       if (q->tx_reclaim_timer.function)
+               del_timer_sync(&q->tx_reclaim_timer);
+
+       for (i = 0; i < SGE_RXQ_PER_SET; ++i)
+               if (q->fl[i].desc) {
+                       spin_lock(&adapter->sge.reg_lock);
+                       t3_sge_disable_fl(adapter, q->fl[i].cntxt_id);
+                       spin_unlock(&adapter->sge.reg_lock);
+                       free_rx_bufs(pdev, &q->fl[i]);
+                       kfree(q->fl[i].sdesc);
+                       dma_free_coherent(&pdev->dev,
+                                         q->fl[i].size *
+                                         sizeof(struct rx_desc), q->fl[i].desc,
+                                         q->fl[i].phys_addr);
+               }
+
+       for (i = 0; i < SGE_TXQ_PER_SET; ++i)
+               if (q->txq[i].desc) {
+                       spin_lock(&adapter->sge.reg_lock);
+                       t3_sge_enable_ecntxt(adapter, q->txq[i].cntxt_id, 0);
+                       spin_unlock(&adapter->sge.reg_lock);
+                       if (q->txq[i].sdesc) {
+                               free_tx_desc(adapter, &q->txq[i],
+                                            q->txq[i].in_use);
+                               kfree(q->txq[i].sdesc);
+                       }
+                       dma_free_coherent(&pdev->dev,
+                                         q->txq[i].size *
+                                         sizeof(struct tx_desc),
+                                         q->txq[i].desc, q->txq[i].phys_addr);
+                       __skb_queue_purge(&q->txq[i].sendq);
+               }
+
+       if (q->rspq.desc) {
+               spin_lock(&adapter->sge.reg_lock);
+               t3_sge_disable_rspcntxt(adapter, q->rspq.cntxt_id);
+               spin_unlock(&adapter->sge.reg_lock);
+               dma_free_coherent(&pdev->dev,
+                                 q->rspq.size * sizeof(struct rsp_desc),
+                                 q->rspq.desc, q->rspq.phys_addr);
+       }
+
+       if (q->netdev)
+               q->netdev->atalk_ptr = NULL;
+
+       memset(q, 0, sizeof(*q));
+}
+
+/**
+ *     init_qset_cntxt - initialize an SGE queue set context info
+ *     @qs: the queue set
+ *     @id: the queue set id
+ *
+ *     Initializes the TIDs and context ids for the queues of a queue set.
+ */
+static void init_qset_cntxt(struct sge_qset *qs, unsigned int id)
+{
+       qs->rspq.cntxt_id = id;
+       qs->fl[0].cntxt_id = 2 * id;
+       qs->fl[1].cntxt_id = 2 * id + 1;
+       qs->txq[TXQ_ETH].cntxt_id = FW_TUNNEL_SGEEC_START + id;
+       qs->txq[TXQ_ETH].token = FW_TUNNEL_TID_START + id;
+       qs->txq[TXQ_OFLD].cntxt_id = FW_OFLD_SGEEC_START + id;
+       qs->txq[TXQ_CTRL].cntxt_id = FW_CTRL_SGEEC_START + id;
+       qs->txq[TXQ_CTRL].token = FW_CTRL_TID_START + id;
+}
+
+/**
+ *     sgl_len - calculates the size of an SGL of the given capacity
+ *     @n: the number of SGL entries
+ *
+ *     Calculates the number of flits needed for a scatter/gather list that
+ *     can hold the given number of entries.
+ */
+static inline unsigned int sgl_len(unsigned int n)
+{
+       /* alternatively: 3 * (n / 2) + 2 * (n & 1) */
+       return (3 * n) / 2 + (n & 1);
+}
+
+/**
+ *     flits_to_desc - returns the num of Tx descriptors for the given flits
+ *     @n: the number of flits
+ *
+ *     Calculates the number of Tx descriptors needed for the supplied number
+ *     of flits.
+ */
+static inline unsigned int flits_to_desc(unsigned int n)
+{
+       BUG_ON(n >= ARRAY_SIZE(flit_desc_map));
+       return flit_desc_map[n];
+}
+
+/**
+ *     get_packet - return the next ingress packet buffer from a free list
+ *     @adap: the adapter that received the packet
+ *     @fl: the SGE free list holding the packet
+ *     @len: the packet length including any SGE padding
+ *     @drop_thres: # of remaining buffers before we start dropping packets
+ *
+ *     Get the next packet from a free list and complete setup of the
+ *     sk_buff.  If the packet is small we make a copy and recycle the
+ *     original buffer, otherwise we use the original buffer itself.  If a
+ *     positive drop threshold is supplied packets are dropped and their
+ *     buffers recycled if (a) the number of remaining buffers is under the
+ *     threshold and the packet is too big to copy, or (b) the packet should
+ *     be copied but there is no memory for the copy.
+ */
+static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
+                                 unsigned int len, unsigned int drop_thres)
+{
+       struct sk_buff *skb = NULL;
+       struct rx_sw_desc *sd = &fl->sdesc[fl->cidx];
+
+       prefetch(sd->skb->data);
+
+       if (len <= SGE_RX_COPY_THRES) {
+               skb = alloc_skb(len, GFP_ATOMIC);
+               if (likely(skb != NULL)) {
+                       __skb_put(skb, len);
+                       pci_dma_sync_single_for_cpu(adap->pdev,
+                                                   pci_unmap_addr(sd,
+                                                                  dma_addr),
+                                                   len, PCI_DMA_FROMDEVICE);
+                       memcpy(skb->data, sd->skb->data, len);
+                       pci_dma_sync_single_for_device(adap->pdev,
+                                                      pci_unmap_addr(sd,
+                                                                     dma_addr),
+                                                      len, PCI_DMA_FROMDEVICE);
+               } else if (!drop_thres)
+                       goto use_orig_buf;
+             recycle:
+               recycle_rx_buf(adap, fl, fl->cidx);
+               return skb;
+       }
+
+       if (unlikely(fl->credits < drop_thres))
+               goto recycle;
+
+      use_orig_buf:
+       pci_unmap_single(adap->pdev, pci_unmap_addr(sd, dma_addr),
+                        fl->buf_size, PCI_DMA_FROMDEVICE);
+       skb = sd->skb;
+       skb_put(skb, len);
+       __refill_fl(adap, fl);
+       return skb;
+}
+
+/**
+ *     get_imm_packet - return the next ingress packet buffer from a response
+ *     @resp: the response descriptor containing the packet data
+ *
+ *     Return a packet containing the immediate data of the given response.
+ */
+static inline struct sk_buff *get_imm_packet(const struct rsp_desc *resp)
+{
+       struct sk_buff *skb = alloc_skb(IMMED_PKT_SIZE, GFP_ATOMIC);
+
+       if (skb) {
+               __skb_put(skb, IMMED_PKT_SIZE);
+               memcpy(skb->data, resp->imm_data, IMMED_PKT_SIZE);
+       }
+       return skb;
+}
+
+/**
+ *     calc_tx_descs - calculate the number of Tx descriptors for a packet
+ *     @skb: the packet
+ *
+ *     Returns the number of Tx descriptors needed for the given Ethernet
+ *     packet.  Ethernet packets require addition of WR and CPL headers.
+ */
+static inline unsigned int calc_tx_descs(const struct sk_buff *skb)
+{
+       unsigned int flits;
+
+       if (skb->len <= WR_LEN - sizeof(struct cpl_tx_pkt))
+               return 1;
+
+       flits = sgl_len(skb_shinfo(skb)->nr_frags + 1) + 2;
+       if (skb_shinfo(skb)->gso_size)
+               flits++;
+       return flits_to_desc(flits);
+}
+
+/**
+ *     make_sgl - populate a scatter/gather list for a packet
+ *     @skb: the packet
+ *     @sgp: the SGL to populate
+ *     @start: start address of skb main body data to include in the SGL
+ *     @len: length of skb main body data to include in the SGL
+ *     @pdev: the PCI device
+ *
+ *     Generates a scatter/gather list for the buffers that make up a packet
+ *     and returns the SGL size in 8-byte words.  The caller must size the SGL
+ *     appropriately.
+ */
+static inline unsigned int make_sgl(const struct sk_buff *skb,
+                                   struct sg_ent *sgp, unsigned char *start,
+                                   unsigned int len, struct pci_dev *pdev)
+{
+       dma_addr_t mapping;
+       unsigned int i, j = 0, nfrags;
+
+       if (len) {
+               mapping = pci_map_single(pdev, start, len, PCI_DMA_TODEVICE);
+               sgp->len[0] = cpu_to_be32(len);
+               sgp->addr[0] = cpu_to_be64(mapping);
+               j = 1;
+       }
+
+       nfrags = skb_shinfo(skb)->nr_frags;
+       for (i = 0; i < nfrags; i++) {
+               skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
+
+               mapping = pci_map_page(pdev, frag->page, frag->page_offset,
+                                      frag->size, PCI_DMA_TODEVICE);
+               sgp->len[j] = cpu_to_be32(frag->size);
+               sgp->addr[j] = cpu_to_be64(mapping);
+               j ^= 1;
+               if (j == 0)
+                       ++sgp;
+       }
+       if (j)
+               sgp->len[j] = 0;
+       return ((nfrags + (len != 0)) * 3) / 2 + j;
+}
+
+/**
+ *     check_ring_tx_db - check and potentially ring a Tx queue's doorbell
+ *     @adap: the adapter
+ *     @q: the Tx queue
+ *
+ *     Ring the doorbel if a Tx queue is asleep.  There is a natural race,
+ *     where the HW is going to sleep just after we checked, however,
+ *     then the interrupt handler will detect the outstanding TX packet
+ *     and ring the doorbell for us.
+ *
+ *     When GTS is disabled we unconditionally ring the doorbell.
+ */
+static inline void check_ring_tx_db(struct adapter *adap, struct sge_txq *q)
+{
+#if USE_GTS
+       clear_bit(TXQ_LAST_PKT_DB, &q->flags);
+       if (test_and_set_bit(TXQ_RUNNING, &q->flags) == 0) {
+               set_bit(TXQ_LAST_PKT_DB, &q->flags);
+               t3_write_reg(adap, A_SG_KDOORBELL,
+                            F_SELEGRCNTX | V_EGRCNTX(q->cntxt_id));
+       }
+#else
+       wmb();                  /* write descriptors before telling HW */
+       t3_write_reg(adap, A_SG_KDOORBELL,
+                    F_SELEGRCNTX | V_EGRCNTX(q->cntxt_id));
+#endif
+}
+
+static inline void wr_gen2(struct tx_desc *d, unsigned int gen)
+{
+#if SGE_NUM_GENBITS == 2
+       d->flit[TX_DESC_FLITS - 1] = cpu_to_be64(gen);
+#endif
+}
+
+/**
+ *     write_wr_hdr_sgl - write a WR header and, optionally, SGL
+ *     @ndesc: number of Tx descriptors spanned by the SGL
+ *     @skb: the packet corresponding to the WR
+ *     @d: first Tx descriptor to be written
+ *     @pidx: index of above descriptors
+ *     @q: the SGE Tx queue
+ *     @sgl: the SGL
+ *     @flits: number of flits to the start of the SGL in the first descriptor
+ *     @sgl_flits: the SGL size in flits
+ *     @gen: the Tx descriptor generation
+ *     @wr_hi: top 32 bits of WR header based on WR type (big endian)
+ *     @wr_lo: low 32 bits of WR header based on WR type (big endian)
+ *
+ *     Write a work request header and an associated SGL.  If the SGL is
+ *     small enough to fit into one Tx descriptor it has already been written
+ *     and we just need to write the WR header.  Otherwise we distribute the
+ *     SGL across the number of descriptors it spans.
+ */
+static void write_wr_hdr_sgl(unsigned int ndesc, struct sk_buff *skb,
+                            struct tx_desc *d, unsigned int pidx,
+                            const struct sge_txq *q,
+                            const struct sg_ent *sgl,
+                            unsigned int flits, unsigned int sgl_flits,
+                            unsigned int gen, unsigned int wr_hi,
+                            unsigned int wr_lo)
+{
+       struct work_request_hdr *wrp = (struct work_request_hdr *)d;
+       struct tx_sw_desc *sd = &q->sdesc[pidx];
+
+       sd->skb = skb;
+       if (need_skb_unmap()) {
+               struct unmap_info *ui = (struct unmap_info *)skb->cb;
+
+               ui->fragidx = 0;
+               ui->addr_idx = 0;
+               ui->sflit = flits;
+       }
+
+       if (likely(ndesc == 1)) {
+               skb->priority = pidx;
+               wrp->wr_hi = htonl(F_WR_SOP | F_WR_EOP | V_WR_DATATYPE(1) |
+                                  V_WR_SGLSFLT(flits)) | wr_hi;
+               wmb();
+               wrp->wr_lo = htonl(V_WR_LEN(flits + sgl_flits) |
+                                  V_WR_GEN(gen)) | wr_lo;
+               wr_gen2(d, gen);
+       } else {
+               unsigned int ogen = gen;
+               const u64 *fp = (const u64 *)sgl;
+               struct work_request_hdr *wp = wrp;
+
+               wrp->wr_hi = htonl(F_WR_SOP | V_WR_DATATYPE(1) |
+                                  V_WR_SGLSFLT(flits)) | wr_hi;
+
+               while (sgl_flits) {
+                       unsigned int avail = WR_FLITS - flits;
+
+                       if (avail > sgl_flits)
+                               avail = sgl_flits;
+                       memcpy(&d->flit[flits], fp, avail * sizeof(*fp));
+                       sgl_flits -= avail;
+                       ndesc--;
+                       if (!sgl_flits)
+                               break;
+
+                       fp += avail;
+                       d++;
+                       sd++;
+                       if (++pidx == q->size) {
+                               pidx = 0;
+                               gen ^= 1;
+                               d = q->desc;
+                               sd = q->sdesc;
+                       }
+
+                       sd->skb = skb;
+                       wrp = (struct work_request_hdr *)d;
+                       wrp->wr_hi = htonl(V_WR_DATATYPE(1) |
+                                          V_WR_SGLSFLT(1)) | wr_hi;
+                       wrp->wr_lo = htonl(V_WR_LEN(min(WR_FLITS,
+                                                       sgl_flits + 1)) |
+                                          V_WR_GEN(gen)) | wr_lo;
+                       wr_gen2(d, gen);
+                       flits = 1;
+               }
+               skb->priority = pidx;
+               wrp->wr_hi |= htonl(F_WR_EOP);
+               wmb();
+               wp->wr_lo = htonl(V_WR_LEN(WR_FLITS) | V_WR_GEN(ogen)) | wr_lo;
+               wr_gen2((struct tx_desc *)wp, ogen);
+               WARN_ON(ndesc != 0);
+       }
+}
+
+/**
+ *     write_tx_pkt_wr - write a TX_PKT work request
+ *     @adap: the adapter
+ *     @skb: the packet to send
+ *     @pi: the egress interface
+ *     @pidx: index of the first Tx descriptor to write
+ *     @gen: the generation value to use
+ *     @q: the Tx queue
+ *     @ndesc: number of descriptors the packet will occupy
+ *     @compl: the value of the COMPL bit to use
+ *
+ *     Generate a TX_PKT work request to send the supplied packet.
+ */
+static void write_tx_pkt_wr(struct adapter *adap, struct sk_buff *skb,
+                           const struct port_info *pi,
+                           unsigned int pidx, unsigned int gen,
+                           struct sge_txq *q, unsigned int ndesc,
+                           unsigned int compl)
+{
+       unsigned int flits, sgl_flits, cntrl, tso_info;
+       struct sg_ent *sgp, sgl[MAX_SKB_FRAGS / 2 + 1];
+       struct tx_desc *d = &q->desc[pidx];
+       struct cpl_tx_pkt *cpl = (struct cpl_tx_pkt *)d;
+
+       cpl->len = htonl(skb->len | 0x80000000);
+       cntrl = V_TXPKT_INTF(pi->port_id);
+
+       if (vlan_tx_tag_present(skb) && pi->vlan_grp)
+               cntrl |= F_TXPKT_VLAN_VLD | V_TXPKT_VLAN(vlan_tx_tag_get(skb));
+
+       tso_info = V_LSO_MSS(skb_shinfo(skb)->gso_size);
+       if (tso_info) {
+               int eth_type;
+               struct cpl_tx_pkt_lso *hdr = (struct cpl_tx_pkt_lso *)cpl;
+
+               d->flit[2] = 0;
+               cntrl |= V_TXPKT_OPCODE(CPL_TX_PKT_LSO);
+               hdr->cntrl = htonl(cntrl);
+               eth_type = skb->nh.raw - skb->data == ETH_HLEN ?
+                   CPL_ETH_II : CPL_ETH_II_VLAN;
+               tso_info |= V_LSO_ETH_TYPE(eth_type) |
+                   V_LSO_IPHDR_WORDS(skb->nh.iph->ihl) |
+                   V_LSO_TCPHDR_WORDS(skb->h.th->doff);
+               hdr->lso_info = htonl(tso_info);
+               flits = 3;
+       } else {
+               cntrl |= V_TXPKT_OPCODE(CPL_TX_PKT);
+               cntrl |= F_TXPKT_IPCSUM_DIS;    /* SW calculates IP csum */
+               cntrl |= V_TXPKT_L4CSUM_DIS(skb->ip_summed != CHECKSUM_PARTIAL);
+               cpl->cntrl = htonl(cntrl);
+
+               if (skb->len <= WR_LEN - sizeof(*cpl)) {
+                       q->sdesc[pidx].skb = NULL;
+                       if (!skb->data_len)
+                               memcpy(&d->flit[2], skb->data, skb->len);
+                       else
+                               skb_copy_bits(skb, 0, &d->flit[2], skb->len);
+
+                       flits = (skb->len + 7) / 8 + 2;
+                       cpl->wr.wr_hi = htonl(V_WR_BCNTLFLT(skb->len & 7) |
+                                             V_WR_OP(FW_WROPCODE_TUNNEL_TX_PKT)
+                                             | F_WR_SOP | F_WR_EOP | compl);
+                       wmb();
+                       cpl->wr.wr_lo = htonl(V_WR_LEN(flits) | V_WR_GEN(gen) |
+                                             V_WR_TID(q->token));
+                       wr_gen2(d, gen);
+                       kfree_skb(skb);
+                       return;
+               }
+
+               flits = 2;
+       }
+
+       sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
+       sgl_flits = make_sgl(skb, sgp, skb->data, skb_headlen(skb), adap->pdev);
+       if (need_skb_unmap())
+               ((struct unmap_info *)skb->cb)->len = skb_headlen(skb);
+
+       write_wr_hdr_sgl(ndesc, skb, d, pidx, q, sgl, flits, sgl_flits, gen,
+                        htonl(V_WR_OP(FW_WROPCODE_TUNNEL_TX_PKT) | compl),
+                        htonl(V_WR_TID(q->token)));
+}
+
+/**
+ *     eth_xmit - add a packet to the Ethernet Tx queue
+ *     @skb: the packet
+ *     @dev: the egress net device
+ *
+ *     Add a packet to an SGE Tx queue.  Runs with softirqs disabled.
+ */
+int t3_eth_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+       unsigned int ndesc, pidx, credits, gen, compl;
+       const struct port_info *pi = netdev_priv(dev);
+       struct adapter *adap = dev->priv;
+       struct sge_qset *qs = dev2qset(dev);
+       struct sge_txq *q = &qs->txq[TXQ_ETH];
+
+       /*
+        * The chip min packet length is 9 octets but play safe and reject
+        * anything shorter than an Ethernet header.
+        */
+       if (unlikely(skb->len < ETH_HLEN)) {
+               dev_kfree_skb(skb);
+               return NETDEV_TX_OK;
+       }
+
+       spin_lock(&q->lock);
+       reclaim_completed_tx(adap, q);
+
+       credits = q->size - q->in_use;
+       ndesc = calc_tx_descs(skb);
+
+       if (unlikely(credits < ndesc)) {
+               if (!netif_queue_stopped(dev)) {
+                       netif_stop_queue(dev);
+                       set_bit(TXQ_ETH, &qs->txq_stopped);
+                       q->stops++;
+                       dev_err(&adap->pdev->dev,
+                               "%s: Tx ring %u full while queue awake!\n",
+                               dev->name, q->cntxt_id & 7);
+               }
+               spin_unlock(&q->lock);
+               return NETDEV_TX_BUSY;
+       }
+
+       q->in_use += ndesc;
+       if (unlikely(credits - ndesc < q->stop_thres)) {
+               q->stops++;
+               netif_stop_queue(dev);
+               set_bit(TXQ_ETH, &qs->txq_stopped);
+#if !USE_GTS
+               if (should_restart_tx(q) &&
+                   test_and_clear_bit(TXQ_ETH, &qs->txq_stopped)) {
+                       q->restarts++;
+                       netif_wake_queue(dev);
+               }
+#endif
+       }
+
+       gen = q->gen;
+       q->unacked += ndesc;
+       compl = (q->unacked & 8) << (S_WR_COMPL - 3);
+       q->unacked &= 7;
+       pidx = q->pidx;
+       q->pidx += ndesc;
+       if (q->pidx >= q->size) {
+               q->pidx -= q->size;
+               q->gen ^= 1;
+       }
+
+       /* update port statistics */
+       if (skb->ip_summed == CHECKSUM_COMPLETE)
+               qs->port_stats[SGE_PSTAT_TX_CSUM]++;
+       if (skb_shinfo(skb)->gso_size)
+               qs->port_stats[SGE_PSTAT_TSO]++;
+       if (vlan_tx_tag_present(skb) && pi->vlan_grp)
+               qs->port_stats[SGE_PSTAT_VLANINS]++;
+
+       dev->trans_start = jiffies;
+       spin_unlock(&q->lock);
+
+       /*
+        * We do not use Tx completion interrupts to free DMAd Tx packets.
+        * This is good for performamce but means that we rely on new Tx
+        * packets arriving to run the destructors of completed packets,
+        * which open up space in their sockets' send queues.  Sometimes
+        * we do not get such new packets causing Tx to stall.  A single
+        * UDP transmitter is a good example of this situation.  We have
+        * a clean up timer that periodically reclaims completed packets
+        * but it doesn't run often enough (nor do we want it to) to prevent
+        * lengthy stalls.  A solution to this problem is to run the
+        * destructor early, after the packet is queued but before it's DMAd.
+        * A cons is that we lie to socket memory accounting, but the amount
+        * of extra memory is reasonable (limited by the number of Tx
+        * descriptors), the packets do actually get freed quickly by new
+        * packets almost always, and for protocols like TCP that wait for
+        * acks to really free up the data the extra memory is even less.
+        * On the positive side we run the destructors on the sending CPU
+        * rather than on a potentially different completing CPU, usually a
+        * good thing.  We also run them without holding our Tx queue lock,
+        * unlike what reclaim_completed_tx() would otherwise do.
+        *
+        * Run the destructor before telling the DMA engine about the packet
+        * to make sure it doesn't complete and get freed prematurely.
+        */
+       if (likely(!skb_shared(skb)))
+               skb_orphan(skb);
+
+       write_tx_pkt_wr(adap, skb, pi, pidx, gen, q, ndesc, compl);
+       check_ring_tx_db(adap, q);
+       return NETDEV_TX_OK;
+}
+
+/**
+ *     write_imm - write a packet into a Tx descriptor as immediate data
+ *     @d: the Tx descriptor to write
+ *     @skb: the packet
+ *     @len: the length of packet data to write as immediate data
+ *     @gen: the generation bit value to write
+ *
+ *     Writes a packet as immediate data into a Tx descriptor.  The packet
+ *     contains a work request at its beginning.  We must write the packet
+ *     carefully so the SGE doesn't read accidentally before it's written in
+ *     its entirety.
+ */
+static inline void write_imm(struct tx_desc *d, struct sk_buff *skb,
+                            unsigned int len, unsigned int gen)
+{
+       struct work_request_hdr *from = (struct work_request_hdr *)skb->data;
+       struct work_request_hdr *to = (struct work_request_hdr *)d;
+
+       memcpy(&to[1], &from[1], len - sizeof(*from));
+       to->wr_hi = from->wr_hi | htonl(F_WR_SOP | F_WR_EOP |
+                                       V_WR_BCNTLFLT(len & 7));
+       wmb();
+       to->wr_lo = from->wr_lo | htonl(V_WR_GEN(gen) |
+                                       V_WR_LEN((len + 7) / 8));
+       wr_gen2(d, gen);
+       kfree_skb(skb);
+}
+
+/**
+ *     check_desc_avail - check descriptor availability on a send queue
+ *     @adap: the adapter
+ *     @q: the send queue
+ *     @skb: the packet needing the descriptors
+ *     @ndesc: the number of Tx descriptors needed
+ *     @qid: the Tx queue number in its queue set (TXQ_OFLD or TXQ_CTRL)
+ *
+ *     Checks if the requested number of Tx descriptors is available on an
+ *     SGE send queue.  If the queue is already suspended or not enough
+ *     descriptors are available the packet is queued for later transmission.
+ *     Must be called with the Tx queue locked.
+ *
+ *     Returns 0 if enough descriptors are available, 1 if there aren't
+ *     enough descriptors and the packet has been queued, and 2 if the caller
+ *     needs to retry because there weren't enough descriptors at the
+ *     beginning of the call but some freed up in the mean time.
+ */
+static inline int check_desc_avail(struct adapter *adap, struct sge_txq *q,
+                                  struct sk_buff *skb, unsigned int ndesc,
+                                  unsigned int qid)
+{
+       if (unlikely(!skb_queue_empty(&q->sendq))) {
+             addq_exit:__skb_queue_tail(&q->sendq, skb);
+               return 1;
+       }
+       if (unlikely(q->size - q->in_use < ndesc)) {
+               struct sge_qset *qs = txq_to_qset(q, qid);
+
+               set_bit(qid, &qs->txq_stopped);
+               smp_mb__after_clear_bit();
+
+               if (should_restart_tx(q) &&
+                   test_and_clear_bit(qid, &qs->txq_stopped))
+                       return 2;
+
+               q->stops++;
+               goto addq_exit;
+       }
+       return 0;
+}
+
+/**
+ *     reclaim_completed_tx_imm - reclaim completed control-queue Tx descs
+ *     @q: the SGE control Tx queue
+ *
+ *     This is a variant of reclaim_completed_tx() that is used for Tx queues
+ *     that send only immediate data (presently just the control queues) and
+ *     thus do not have any sk_buffs to release.
+ */
+static inline void reclaim_completed_tx_imm(struct sge_txq *q)
+{
+       unsigned int reclaim = q->processed - q->cleaned;
+
+       q->in_use -= reclaim;
+       q->cleaned += reclaim;
+}
+
+static inline int immediate(const struct sk_buff *skb)
+{
+       return skb->len <= WR_LEN && !skb->data_len;
+}
+
+/**
+ *     ctrl_xmit - send a packet through an SGE control Tx queue
+ *     @adap: the adapter
+ *     @q: the control queue
+ *     @skb: the packet
+ *
+ *     Send a packet through an SGE control Tx queue.  Packets sent through
+ *     a control queue must fit entirely as immediate data in a single Tx
+ *     descriptor and have no page fragments.
+ */
+static int ctrl_xmit(struct adapter *adap, struct sge_txq *q,
+                    struct sk_buff *skb)
+{
+       int ret;
+       struct work_request_hdr *wrp = (struct work_request_hdr *)skb->data;
+
+       if (unlikely(!immediate(skb))) {
+               WARN_ON(1);
+               dev_kfree_skb(skb);
+               return NET_XMIT_SUCCESS;
+       }
+
+       wrp->wr_hi |= htonl(F_WR_SOP | F_WR_EOP);
+       wrp->wr_lo = htonl(V_WR_TID(q->token));
+
+       spin_lock(&q->lock);
+      again:reclaim_completed_tx_imm(q);
+
+       ret = check_desc_avail(adap, q, skb, 1, TXQ_CTRL);
+       if (unlikely(ret)) {
+               if (ret == 1) {
+                       spin_unlock(&q->lock);
+                       return NET_XMIT_CN;
+               }
+               goto again;
+       }
+
+       write_imm(&q->desc[q->pidx], skb, skb->len, q->gen);
+
+       q->in_use++;
+       if (++q->pidx >= q->size) {
+               q->pidx = 0;
+               q->gen ^= 1;
+       }
+       spin_unlock(&q->lock);
+       wmb();
+       t3_write_reg(adap, A_SG_KDOORBELL,
+                    F_SELEGRCNTX | V_EGRCNTX(q->cntxt_id));
+       return NET_XMIT_SUCCESS;
+}
+
+/**
+ *     restart_ctrlq - restart a suspended control queue
+ *     @qs: the queue set cotaining the control queue
+ *
+ *     Resumes transmission on a suspended Tx control queue.
+ */
+static void restart_ctrlq(unsigned long data)
+{
+       struct sk_buff *skb;
+       struct sge_qset *qs = (struct sge_qset *)data;
+       struct sge_txq *q = &qs->txq[TXQ_CTRL];
+       struct adapter *adap = qs->netdev->priv;
+
+       spin_lock(&q->lock);
+      again:reclaim_completed_tx_imm(q);
+
+       while (q->in_use < q->size && (skb = __skb_dequeue(&q->sendq)) != NULL) {
+
+               write_imm(&q->desc[q->pidx], skb, skb->len, q->gen);
+
+               if (++q->pidx >= q->size) {
+                       q->pidx = 0;
+                       q->gen ^= 1;
+               }
+               q->in_use++;
+       }
+
+       if (!skb_queue_empty(&q->sendq)) {
+               set_bit(TXQ_CTRL, &qs->txq_stopped);
+               smp_mb__after_clear_bit();
+
+               if (should_restart_tx(q) &&
+                   test_and_clear_bit(TXQ_CTRL, &qs->txq_stopped))
+                       goto again;
+               q->stops++;
+       }
+
+       spin_unlock(&q->lock);
+       t3_write_reg(adap, A_SG_KDOORBELL,
+                    F_SELEGRCNTX | V_EGRCNTX(q->cntxt_id));
+}
+
+/*
+ * Send a management message through control queue 0
+ */
+int t3_mgmt_tx(struct adapter *adap, struct sk_buff *skb)
+{
+       return ctrl_xmit(adap, &adap->sge.qs[0].txq[TXQ_CTRL], skb);
+}
+
+/**
+ *     write_ofld_wr - write an offload work request
+ *     @adap: the adapter
+ *     @skb: the packet to send
+ *     @q: the Tx queue
+ *     @pidx: index of the first Tx descriptor to write
+ *     @gen: the generation value to use
+ *     @ndesc: number of descriptors the packet will occupy
+ *
+ *     Write an offload work request to send the supplied packet.  The packet
+ *     data already carry the work request with most fields populated.
+ */
+static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
+                         struct sge_txq *q, unsigned int pidx,
+                         unsigned int gen, unsigned int ndesc)
+{
+       unsigned int sgl_flits, flits;
+       struct work_request_hdr *from;
+       struct sg_ent *sgp, sgl[MAX_SKB_FRAGS / 2 + 1];
+       struct tx_desc *d = &q->desc[pidx];
+
+       if (immediate(skb)) {
+               q->sdesc[pidx].skb = NULL;
+               write_imm(d, skb, skb->len, gen);
+               return;
+       }
+
+       /* Only TX_DATA builds SGLs */
+
+       from = (struct work_request_hdr *)skb->data;
+       memcpy(&d->flit[1], &from[1], skb->h.raw - skb->data - sizeof(*from));
+
+       flits = (skb->h.raw - skb->data) / 8;
+       sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
+       sgl_flits = make_sgl(skb, sgp, skb->h.raw, skb->tail - skb->h.raw,
+                            adap->pdev);
+       if (need_skb_unmap())
+               ((struct unmap_info *)skb->cb)->len = skb->tail - skb->h.raw;
+
+       write_wr_hdr_sgl(ndesc, skb, d, pidx, q, sgl, flits, sgl_flits,
+                        gen, from->wr_hi, from->wr_lo);
+}
+
+/**
+ *     calc_tx_descs_ofld - calculate # of Tx descriptors for an offload packet
+ *     @skb: the packet
+ *
+ *     Returns the number of Tx descriptors needed for the given offload
+ *     packet.  These packets are already fully constructed.
+ */
+static inline unsigned int calc_tx_descs_ofld(const struct sk_buff *skb)
+{
+       unsigned int flits, cnt = skb_shinfo(skb)->nr_frags;
+
+       if (skb->len <= WR_LEN && cnt == 0)
+               return 1;       /* packet fits as immediate data */
+
+       flits = (skb->h.raw - skb->data) / 8;   /* headers */
+       if (skb->tail != skb->h.raw)
+               cnt++;
+       return flits_to_desc(flits + sgl_len(cnt));
+}
+
+/**
+ *     ofld_xmit - send a packet through an offload queue
+ *     @adap: the adapter
+ *     @q: the Tx offload queue
+ *     @skb: the packet
+ *
+ *     Send an offload packet through an SGE offload queue.
+ */
+static int ofld_xmit(struct adapter *adap, struct sge_txq *q,
+                    struct sk_buff *skb)
+{
+       int ret;
+       unsigned int ndesc = calc_tx_descs_ofld(skb), pidx, gen;
+
+       spin_lock(&q->lock);
+      again:reclaim_completed_tx(adap, q);
+
+       ret = check_desc_avail(adap, q, skb, ndesc, TXQ_OFLD);
+       if (unlikely(ret)) {
+               if (ret == 1) {
+                       skb->priority = ndesc;  /* save for restart */
+                       spin_unlock(&q->lock);
+                       return NET_XMIT_CN;
+               }
+               goto again;
+       }
+
+       gen = q->gen;
+       q->in_use += ndesc;
+       pidx = q->pidx;
+       q->pidx += ndesc;
+       if (q->pidx >= q->size) {
+               q->pidx -= q->size;
+               q->gen ^= 1;
+       }
+       spin_unlock(&q->lock);
+
+       write_ofld_wr(adap, skb, q, pidx, gen, ndesc);
+       check_ring_tx_db(adap, q);
+       return NET_XMIT_SUCCESS;
+}
+
+/**
+ *     restart_offloadq - restart a suspended offload queue
+ *     @qs: the queue set cotaining the offload queue
+ *
+ *     Resumes transmission on a suspended Tx offload queue.
+ */
+static void restart_offloadq(unsigned long data)
+{
+       struct sk_buff *skb;
+       struct sge_qset *qs = (struct sge_qset *)data;
+       struct sge_txq *q = &qs->txq[TXQ_OFLD];
+       struct adapter *adap = qs->netdev->priv;
+
+       spin_lock(&q->lock);
+      again:reclaim_completed_tx(adap, q);
+
+       while ((skb = skb_peek(&q->sendq)) != NULL) {
+               unsigned int gen, pidx;
+               unsigned int ndesc = skb->priority;
+
+               if (unlikely(q->size - q->in_use < ndesc)) {
+                       set_bit(TXQ_OFLD, &qs->txq_stopped);
+                       smp_mb__after_clear_bit();
+
+                       if (should_restart_tx(q) &&
+                           test_and_clear_bit(TXQ_OFLD, &qs->txq_stopped))
+                               goto again;
+                       q->stops++;
+                       break;
+               }
+
+               gen = q->gen;
+               q->in_use += ndesc;
+               pidx = q->pidx;
+               q->pidx += ndesc;
+               if (q->pidx >= q->size) {
+                       q->pidx -= q->size;
+                       q->gen ^= 1;
+               }
+               __skb_unlink(skb, &q->sendq);
+               spin_unlock(&q->lock);
+
+               write_ofld_wr(adap, skb, q, pidx, gen, ndesc);
+               spin_lock(&q->lock);
+       }
+       spin_unlock(&q->lock);
+
+#if USE_GTS
+       set_bit(TXQ_RUNNING, &q->flags);
+       set_bit(TXQ_LAST_PKT_DB, &q->flags);
+#endif
+       t3_write_reg(adap, A_SG_KDOORBELL,
+                    F_SELEGRCNTX | V_EGRCNTX(q->cntxt_id));
+}
+
+/**
+ *     queue_set - return the queue set a packet should use
+ *     @skb: the packet
+ *
+ *     Maps a packet to the SGE queue set it should use.  The desired queue
+ *     set is carried in bits 1-3 in the packet's priority.
+ */
+static inline int queue_set(const struct sk_buff *skb)
+{
+       return skb->priority >> 1;
+}
+
+/**
+ *     is_ctrl_pkt - return whether an offload packet is a control packet
+ *     @skb: the packet
+ *
+ *     Determines whether an offload packet should use an OFLD or a CTRL
+ *     Tx queue.  This is indicated by bit 0 in the packet's priority.
+ */
+static inline int is_ctrl_pkt(const struct sk_buff *skb)
+{
+       return skb->priority & 1;
+}
+
+/**
+ *     t3_offload_tx - send an offload packet
+ *     @tdev: the offload device to send to
+ *     @skb: the packet
+ *
+ *     Sends an offload packet.  We use the packet priority to select the
+ *     appropriate Tx queue as follows: bit 0 indicates whether the packet
+ *     should be sent as regular or control, bits 1-3 select the queue set.
+ */
+int t3_offload_tx(struct t3cdev *tdev, struct sk_buff *skb)
+{
+       struct adapter *adap = tdev2adap(tdev);
+       struct sge_qset *qs = &adap->sge.qs[queue_set(skb)];
+
+       if (unlikely(is_ctrl_pkt(skb)))
+               return ctrl_xmit(adap, &qs->txq[TXQ_CTRL], skb);
+
+       return ofld_xmit(adap, &qs->txq[TXQ_OFLD], skb);
+}
+
+/**
+ *     offload_enqueue - add an offload packet to an SGE offload receive queue
+ *     @q: the SGE response queue
+ *     @skb: the packet
+ *
+ *     Add a new offload packet to an SGE response queue's offload packet
+ *     queue.  If the packet is the first on the queue it schedules the RX
+ *     softirq to process the queue.
+ */
+static inline void offload_enqueue(struct sge_rspq *q, struct sk_buff *skb)
+{
+       skb->next = skb->prev = NULL;
+       if (q->rx_tail)
+               q->rx_tail->next = skb;
+       else {
+               struct sge_qset *qs = rspq_to_qset(q);
+
+               if (__netif_rx_schedule_prep(qs->netdev))
+                       __netif_rx_schedule(qs->netdev);
+               q->rx_head = skb;
+       }
+       q->rx_tail = skb;
+}
+
+/**
+ *     deliver_partial_bundle - deliver a (partial) bundle of Rx offload pkts
+ *     @tdev: the offload device that will be receiving the packets
+ *     @q: the SGE response queue that assembled the bundle
+ *     @skbs: the partial bundle
+ *     @n: the number of packets in the bundle
+ *
+ *     Delivers a (partial) bundle of Rx offload packets to an offload device.
+ */
+static inline void deliver_partial_bundle(struct t3cdev *tdev,
+                                         struct sge_rspq *q,
+                                         struct sk_buff *skbs[], int n)
+{
+       if (n) {
+               q->offload_bundles++;
+               tdev->recv(tdev, skbs, n);
+       }
+}
+
+/**
+ *     ofld_poll - NAPI handler for offload packets in interrupt mode
+ *     @dev: the network device doing the polling
+ *     @budget: polling budget
+ *
+ *     The NAPI handler for offload packets when a response queue is serviced
+ *     by the hard interrupt handler, i.e., when it's operating in non-polling
+ *     mode.  Creates small packet batches and sends them through the offload
+ *     receive handler.  Batches need to be of modest size as we do prefetches
+ *     on the packets in each.
+ */
+static int ofld_poll(struct net_device *dev, int *budget)
+{
+       struct adapter *adapter = dev->priv;
+       struct sge_qset *qs = dev2qset(dev);
+       struct sge_rspq *q = &qs->rspq;
+       int work_done, limit = min(*budget, dev->quota), avail = limit;
+
+       while (avail) {
+               struct sk_buff *head, *tail, *skbs[RX_BUNDLE_SIZE];
+               int ngathered;
+
+               spin_lock_irq(&q->lock);
+               head = q->rx_head;
+               if (!head) {
+                       work_done = limit - avail;
+                       *budget -= work_done;
+                       dev->quota -= work_done;
+                       __netif_rx_complete(dev);
+                       spin_unlock_irq(&q->lock);
+                       return 0;
+               }
+
+               tail = q->rx_tail;
+               q->rx_head = q->rx_tail = NULL;
+               spin_unlock_irq(&q->lock);
+
+               for (ngathered = 0; avail && head; avail--) {
+                       prefetch(head->data);
+                       skbs[ngathered] = head;
+                       head = head->next;
+                       skbs[ngathered]->next = NULL;
+                       if (++ngathered == RX_BUNDLE_SIZE) {
+                               q->offload_bundles++;
+                               adapter->tdev.recv(&adapter->tdev, skbs,
+                                                  ngathered);
+                               ngathered = 0;
+                       }
+               }
+               if (head) {     /* splice remaining packets back onto Rx queue */
+                       spin_lock_irq(&q->lock);
+                       tail->next = q->rx_head;
+                       if (!q->rx_head)
+                               q->rx_tail = tail;
+                       q->rx_head = head;
+                       spin_unlock_irq(&q->lock);
+               }
+               deliver_partial_bundle(&adapter->tdev, q, skbs, ngathered);
+       }
+       work_done = limit - avail;
+       *budget -= work_done;
+       dev->quota -= work_done;
+       return 1;
+}
+
+/**
+ *     rx_offload - process a received offload packet
+ *     @tdev: the offload device receiving the packet
+ *     @rq: the response queue that received the packet
+ *     @skb: the packet
+ *     @rx_gather: a gather list of packets if we are building a bundle
+ *     @gather_idx: index of the next available slot in the bundle
+ *
+ *     Process an ingress offload pakcet and add it to the offload ingress
+ *     queue.  Returns the index of the next available slot in the bundle.
+ */
+static inline int rx_offload(struct t3cdev *tdev, struct sge_rspq *rq,
+                            struct sk_buff *skb, struct sk_buff *rx_gather[],
+                            unsigned int gather_idx)
+{
+       rq->offload_pkts++;
+       skb->mac.raw = skb->nh.raw = skb->h.raw = skb->data;
+
+       if (rq->polling) {
+               rx_gather[gather_idx++] = skb;
+               if (gather_idx == RX_BUNDLE_SIZE) {
+                       tdev->recv(tdev, rx_gather, RX_BUNDLE_SIZE);
+                       gather_idx = 0;
+                       rq->offload_bundles++;
+               }
+       } else
+               offload_enqueue(rq, skb);
+
+       return gather_idx;
+}
+
+/**
+ *     restart_tx - check whether to restart suspended Tx queues
+ *     @qs: the queue set to resume
+ *
+ *     Restarts suspended Tx queues of an SGE queue set if they have enough
+ *     free resources to resume operation.
+ */
+static void restart_tx(struct sge_qset *qs)
+{
+       if (test_bit(TXQ_ETH, &qs->txq_stopped) &&
+           should_restart_tx(&qs->txq[TXQ_ETH]) &&
+           test_and_clear_bit(TXQ_ETH, &qs->txq_stopped)) {
+               qs->txq[TXQ_ETH].restarts++;
+               if (netif_running(qs->netdev))
+                       netif_wake_queue(qs->netdev);
+       }
+
+       if (test_bit(TXQ_OFLD, &qs->txq_stopped) &&
+           should_restart_tx(&qs->txq[TXQ_OFLD]) &&
+           test_and_clear_bit(TXQ_OFLD, &qs->txq_stopped)) {
+               qs->txq[TXQ_OFLD].restarts++;
+               tasklet_schedule(&qs->txq[TXQ_OFLD].qresume_tsk);
+       }
+       if (test_bit(TXQ_CTRL, &qs->txq_stopped) &&
+           should_restart_tx(&qs->txq[TXQ_CTRL]) &&
+           test_and_clear_bit(TXQ_CTRL, &qs->txq_stopped)) {
+               qs->txq[TXQ_CTRL].restarts++;
+               tasklet_schedule(&qs->txq[TXQ_CTRL].qresume_tsk);
+       }
+}
+
+/**
+ *     rx_eth - process an ingress ethernet packet
+ *     @adap: the adapter
+ *     @rq: the response queue that received the packet
+ *     @skb: the packet
+ *     @pad: amount of padding at the start of the buffer
+ *
+ *     Process an ingress ethernet pakcet and deliver it to the stack.
+ *     The padding is 2 if the packet was delivered in an Rx buffer and 0
+ *     if it was immediate data in a response.
+ */
+static void rx_eth(struct adapter *adap, struct sge_rspq *rq,
+                  struct sk_buff *skb, int pad)
+{
+       struct cpl_rx_pkt *p = (struct cpl_rx_pkt *)(skb->data + pad);
+       struct port_info *pi;
+
+       rq->eth_pkts++;
+       skb_pull(skb, sizeof(*p) + pad);
+       skb->dev = adap->port[p->iff];
+       skb->dev->last_rx = jiffies;
+       skb->protocol = eth_type_trans(skb, skb->dev);
+       pi = netdev_priv(skb->dev);
+       if (pi->rx_csum_offload && p->csum_valid && p->csum == 0xffff &&
+           !p->fragment) {
+               rspq_to_qset(rq)->port_stats[SGE_PSTAT_RX_CSUM_GOOD]++;
+               skb->ip_summed = CHECKSUM_UNNECESSARY;
+       } else
+               skb->ip_summed = CHECKSUM_NONE;
+
+       if (unlikely(p->vlan_valid)) {
+               struct vlan_group *grp = pi->vlan_grp;
+
+               rspq_to_qset(rq)->port_stats[SGE_PSTAT_VLANEX]++;
+               if (likely(grp))
+                       __vlan_hwaccel_rx(skb, grp, ntohs(p->vlan),
+                                         rq->polling);
+               else
+                       dev_kfree_skb_any(skb);
+       } else if (rq->polling)
+               netif_receive_skb(skb);
+       else
+               netif_rx(skb);
+}
+
+/**
+ *     handle_rsp_cntrl_info - handles control information in a response
+ *     @qs: the queue set corresponding to the response
+ *     @flags: the response control flags
+ *
+ *     Handles the control information of an SGE response, such as GTS
+ *     indications and completion credits for the queue set's Tx queues.
+ *     HW coalesces credits, we don't do any extra SW coalescing.
+ */
+static inline void handle_rsp_cntrl_info(struct sge_qset *qs, u32 flags)
+{
+       unsigned int credits;
+
+#if USE_GTS
+       if (flags & F_RSPD_TXQ0_GTS)
+               clear_bit(TXQ_RUNNING, &qs->txq[TXQ_ETH].flags);
+#endif
+
+       credits = G_RSPD_TXQ0_CR(flags);
+       if (credits)
+               qs->txq[TXQ_ETH].processed += credits;
+
+       credits = G_RSPD_TXQ2_CR(flags);
+       if (credits)
+               qs->txq[TXQ_CTRL].processed += credits;
+
+# if USE_GTS
+       if (flags & F_RSPD_TXQ1_GTS)
+               clear_bit(TXQ_RUNNING, &qs->txq[TXQ_OFLD].flags);
+# endif
+       credits = G_RSPD_TXQ1_CR(flags);
+       if (credits)
+               qs->txq[TXQ_OFLD].processed += credits;
+}
+
+/**
+ *     check_ring_db - check if we need to ring any doorbells
+ *     @adapter: the adapter
+ *     @qs: the queue set whose Tx queues are to be examined
+ *     @sleeping: indicates which Tx queue sent GTS
+ *
+ *     Checks if some of a queue set's Tx queues need to ring their doorbells
+ *     to resume transmission after idling while they still have unprocessed
+ *     descriptors.
+ */
+static void check_ring_db(struct adapter *adap, struct sge_qset *qs,
+                         unsigned int sleeping)
+{
+       if (sleeping & F_RSPD_TXQ0_GTS) {
+               struct sge_txq *txq = &qs->txq[TXQ_ETH];
+
+               if (txq->cleaned + txq->in_use != txq->processed &&
+                   !test_and_set_bit(TXQ_LAST_PKT_DB, &txq->flags)) {
+                       set_bit(TXQ_RUNNING, &txq->flags);
+                       t3_write_reg(adap, A_SG_KDOORBELL, F_SELEGRCNTX |
+                                    V_EGRCNTX(txq->cntxt_id));
+               }
+       }
+
+       if (sleeping & F_RSPD_TXQ1_GTS) {
+               struct sge_txq *txq = &qs->txq[TXQ_OFLD];
+
+               if (txq->cleaned + txq->in_use != txq->processed &&
+                   !test_and_set_bit(TXQ_LAST_PKT_DB, &txq->flags)) {
+                       set_bit(TXQ_RUNNING, &txq->flags);
+                       t3_write_reg(adap, A_SG_KDOORBELL, F_SELEGRCNTX |
+                                    V_EGRCNTX(txq->cntxt_id));
+               }
+       }
+}
+
+/**
+ *     is_new_response - check if a response is newly written
+ *     @r: the response descriptor
+ *     @q: the response queue
+ *
+ *     Returns true if a response descriptor contains a yet unprocessed
+ *     response.
+ */
+static inline int is_new_response(const struct rsp_desc *r,
+                                 const struct sge_rspq *q)
+{
+       return (r->intr_gen & F_RSPD_GEN2) == q->gen;
+}
+
+#define RSPD_GTS_MASK  (F_RSPD_TXQ0_GTS | F_RSPD_TXQ1_GTS)
+#define RSPD_CTRL_MASK (RSPD_GTS_MASK | \
+                       V_RSPD_TXQ0_CR(M_RSPD_TXQ0_CR) | \
+                       V_RSPD_TXQ1_CR(M_RSPD_TXQ1_CR) | \
+                       V_RSPD_TXQ2_CR(M_RSPD_TXQ2_CR))
+
+/* How long to delay the next interrupt in case of memory shortage, in 0.1us. */
+#define NOMEM_INTR_DELAY 2500
+
+/**
+ *     process_responses - process responses from an SGE response queue
+ *     @adap: the adapter
+ *     @qs: the queue set to which the response queue belongs
+ *     @budget: how many responses can be processed in this round
+ *
+ *     Process responses from an SGE response queue up to the supplied budget.
+ *     Responses include received packets as well as credits and other events
+ *     for the queues that belong to the response queue's queue set.
+ *     A negative budget is effectively unlimited.
+ *
+ *     Additionally choose the interrupt holdoff time for the next interrupt
+ *     on this queue.  If the system is under memory shortage use a fairly
+ *     long delay to help recovery.
+ */
+static int process_responses(struct adapter *adap, struct sge_qset *qs,
+                            int budget)
+{
+       struct sge_rspq *q = &qs->rspq;
+       struct rsp_desc *r = &q->desc[q->cidx];
+       int budget_left = budget;
+       unsigned int sleeping = 0;
+       struct sk_buff *offload_skbs[RX_BUNDLE_SIZE];
+       int ngathered = 0;
+
+       q->next_holdoff = q->holdoff_tmr;
+
+       while (likely(budget_left && is_new_response(r, q))) {
+               int eth, ethpad = 0;
+               struct sk_buff *skb = NULL;
+               u32 len, flags = ntohl(r->flags);
+               u32 rss_hi = *(const u32 *)r, rss_lo = r->rss_hdr.rss_hash_val;
+
+               eth = r->rss_hdr.opcode == CPL_RX_PKT;
+
+               if (unlikely(flags & F_RSPD_ASYNC_NOTIF)) {
+                       skb = alloc_skb(AN_PKT_SIZE, GFP_ATOMIC);
+                       if (!skb)
+                               goto no_mem;
+
+                       memcpy(__skb_put(skb, AN_PKT_SIZE), r, AN_PKT_SIZE);
+                       skb->data[0] = CPL_ASYNC_NOTIF;
+                       rss_hi = htonl(CPL_ASYNC_NOTIF << 24);
+                       q->async_notif++;
+               } else if (flags & F_RSPD_IMM_DATA_VALID) {
+                       skb = get_imm_packet(r);
+                       if (unlikely(!skb)) {
+                             no_mem:
+                               q->next_holdoff = NOMEM_INTR_DELAY;
+                               q->nomem++;
+                               /* consume one credit since we tried */
+                               budget_left--;
+                               break;
+                       }
+                       q->imm_data++;
+               } else if ((len = ntohl(r->len_cq)) != 0) {
+                       struct sge_fl *fl;
+
+                       fl = (len & F_RSPD_FLQ) ? &qs->fl[1] : &qs->fl[0];
+                       fl->credits--;
+                       skb = get_packet(adap, fl, G_RSPD_LEN(len),
+                                        eth ? SGE_RX_DROP_THRES : 0);
+                       if (!skb)
+                               q->rx_drops++;
+                       else if (r->rss_hdr.opcode == CPL_TRACE_PKT)
+                               __skb_pull(skb, 2);
+                       ethpad = 2;
+                       if (++fl->cidx == fl->size)
+                               fl->cidx = 0;
+               } else
+                       q->pure_rsps++;
+
+               if (flags & RSPD_CTRL_MASK) {
+                       sleeping |= flags & RSPD_GTS_MASK;
+                       handle_rsp_cntrl_info(qs, flags);
+               }
+
+               r++;
+               if (unlikely(++q->cidx == q->size)) {
+                       q->cidx = 0;
+                       q->gen ^= 1;
+                       r = q->desc;
+               }
+               prefetch(r);
+
+               if (++q->credits >= (q->size / 4)) {
+                       refill_rspq(adap, q, q->credits);
+                       q->credits = 0;
+               }
+
+               if (likely(skb != NULL)) {
+                       if (eth)
+                               rx_eth(adap, q, skb, ethpad);
+                       else {
+                               /* Preserve the RSS info in csum & priority */
+                               skb->csum = rss_hi;
+                               skb->priority = rss_lo;
+                               ngathered = rx_offload(&adap->tdev, q, skb,
+                                                      offload_skbs, ngathered);
+                       }
+               }
+
+               --budget_left;
+       }
+
+       deliver_partial_bundle(&adap->tdev, q, offload_skbs, ngathered);
+       if (sleeping)
+               check_ring_db(adap, qs, sleeping);
+
+       smp_mb();               /* commit Tx queue .processed updates */
+       if (unlikely(qs->txq_stopped != 0))
+               restart_tx(qs);
+
+       budget -= budget_left;
+       return budget;
+}
+
+static inline int is_pure_response(const struct rsp_desc *r)
+{
+       u32 n = ntohl(r->flags) & (F_RSPD_ASYNC_NOTIF | F_RSPD_IMM_DATA_VALID);
+
+       return (n | r->len_cq) == 0;
+}
+
+/**
+ *     napi_rx_handler - the NAPI handler for Rx processing
+ *     @dev: the net device
+ *     @budget: how many packets we can process in this round
+ *
+ *     Handler for new data events when using NAPI.
+ */
+static int napi_rx_handler(struct net_device *dev, int *budget)
+{
+       struct adapter *adap = dev->priv;
+       struct sge_qset *qs = dev2qset(dev);
+       int effective_budget = min(*budget, dev->quota);
+
+       int work_done = process_responses(adap, qs, effective_budget);
+       *budget -= work_done;
+       dev->quota -= work_done;
+
+       if (work_done >= effective_budget)
+               return 1;
+
+       netif_rx_complete(dev);
+
+       /*
+        * Because we don't atomically flush the following write it is
+        * possible that in very rare cases it can reach the device in a way
+        * that races with a new response being written plus an error interrupt
+        * causing the NAPI interrupt handler below to return unhandled status
+        * to the OS.  To protect against this would require flushing the write
+        * and doing both the write and the flush with interrupts off.  Way too
+        * expensive and unjustifiable given the rarity of the race.
+        *
+        * The race cannot happen at all with MSI-X.
+        */
+       t3_write_reg(adap, A_SG_GTS, V_RSPQ(qs->rspq.cntxt_id) |
+                    V_NEWTIMER(qs->rspq.next_holdoff) |
+                    V_NEWINDEX(qs->rspq.cidx));
+       return 0;
+}
+
+/*
+ * Returns true if the device is already scheduled for polling.
+ */
+static inline int napi_is_scheduled(struct net_device *dev)
+{
+       return test_bit(__LINK_STATE_RX_SCHED, &dev->state);
+}
+
+/**
+ *     process_pure_responses - process pure responses from a response queue
+ *     @adap: the adapter
+ *     @qs: the queue set owning the response queue
+ *     @r: the first pure response to process
+ *
+ *     A simpler version of process_responses() that handles only pure (i.e.,
+ *     non data-carrying) responses.  Such respones are too light-weight to
+ *     justify calling a softirq under NAPI, so we handle them specially in
+ *     the interrupt handler.  The function is called with a pointer to a
+ *     response, which the caller must ensure is a valid pure response.
+ *
+ *     Returns 1 if it encounters a valid data-carrying response, 0 otherwise.
+ */
+static int process_pure_responses(struct adapter *adap, struct sge_qset *qs,
+                                 struct rsp_desc *r)
+{
+       struct sge_rspq *q = &qs->rspq;
+       unsigned int sleeping = 0;
+
+       do {
+               u32 flags = ntohl(r->flags);
+
+               r++;
+               if (unlikely(++q->cidx == q->size)) {
+                       q->cidx = 0;
+                       q->gen ^= 1;
+                       r = q->desc;
+               }
+               prefetch(r);
+
+               if (flags & RSPD_CTRL_MASK) {
+                       sleeping |= flags & RSPD_GTS_MASK;
+                       handle_rsp_cntrl_info(qs, flags);
+               }
+
+               q->pure_rsps++;
+               if (++q->credits >= (q->size / 4)) {
+                       refill_rspq(adap, q, q->credits);
+                       q->credits = 0;
+               }
+       } while (is_new_response(r, q) && is_pure_response(r));
+
+       if (sleeping)
+               check_ring_db(adap, qs, sleeping);
+
+       smp_mb();               /* commit Tx queue .processed updates */
+       if (unlikely(qs->txq_stopped != 0))
+               restart_tx(qs);
+
+       return is_new_response(r, q);
+}
+
+/**
+ *     handle_responses - decide what to do with new responses in NAPI mode
+ *     @adap: the adapter
+ *     @q: the response queue
+ *
+ *     This is used by the NAPI interrupt handlers to decide what to do with
+ *     new SGE responses.  If there are no new responses it returns -1.  If
+ *     there are new responses and they are pure (i.e., non-data carrying)
+ *     it handles them straight in hard interrupt context as they are very
+ *     cheap and don't deliver any packets.  Finally, if there are any data
+ *     signaling responses it schedules the NAPI handler.  Returns 1 if it
+ *     schedules NAPI, 0 if all new responses were pure.
+ *
+ *     The caller must ascertain NAPI is not already running.
+ */
+static inline int handle_responses(struct adapter *adap, struct sge_rspq *q)
+{
+       struct sge_qset *qs = rspq_to_qset(q);
+       struct rsp_desc *r = &q->desc[q->cidx];
+
+       if (!is_new_response(r, q))
+               return -1;
+       if (is_pure_response(r) && process_pure_responses(adap, qs, r) == 0) {
+               t3_write_reg(adap, A_SG_GTS, V_RSPQ(q->cntxt_id) |
+                            V_NEWTIMER(q->holdoff_tmr) | V_NEWINDEX(q->cidx));
+               return 0;
+       }
+       if (likely(__netif_rx_schedule_prep(qs->netdev)))
+               __netif_rx_schedule(qs->netdev);
+       return 1;
+}
+
+/*
+ * The MSI-X interrupt handler for an SGE response queue for the non-NAPI case
+ * (i.e., response queue serviced in hard interrupt).
+ */
+irqreturn_t t3_sge_intr_msix(int irq, void *cookie)
+{
+       struct sge_qset *qs = cookie;
+       struct adapter *adap = qs->netdev->priv;
+       struct sge_rspq *q = &qs->rspq;
+
+       spin_lock(&q->lock);
+       if (process_responses(adap, qs, -1) == 0)
+               q->unhandled_irqs++;
+       t3_write_reg(adap, A_SG_GTS, V_RSPQ(q->cntxt_id) |
+                    V_NEWTIMER(q->next_holdoff) | V_NEWINDEX(q->cidx));
+       spin_unlock(&q->lock);
+       return IRQ_HANDLED;
+}
+
+/*
+ * The MSI-X interrupt handler for an SGE response queue for the NAPI case
+ * (i.e., response queue serviced by NAPI polling).
+ */
+irqreturn_t t3_sge_intr_msix_napi(int irq, void *cookie)
+{
+       struct sge_qset *qs = cookie;
+       struct adapter *adap = qs->netdev->priv;
+       struct sge_rspq *q = &qs->rspq;
+
+       spin_lock(&q->lock);
+       BUG_ON(napi_is_scheduled(qs->netdev));
+
+       if (handle_responses(adap, q) < 0)
+               q->unhandled_irqs++;
+       spin_unlock(&q->lock);
+       return IRQ_HANDLED;
+}
+
+/*
+ * The non-NAPI MSI interrupt handler.  This needs to handle data events from
+ * SGE response queues as well as error and other async events as they all use
+ * the same MSI vector.  We use one SGE response queue per port in this mode
+ * and protect all response queues with queue 0's lock.
+ */
+static irqreturn_t t3_intr_msi(int irq, void *cookie)
+{
+       int new_packets = 0;
+       struct adapter *adap = cookie;
+       struct sge_rspq *q = &adap->sge.qs[0].rspq;
+
+       spin_lock(&q->lock);
+
+       if (process_responses(adap, &adap->sge.qs[0], -1)) {
+               t3_write_reg(adap, A_SG_GTS, V_RSPQ(q->cntxt_id) |
+                            V_NEWTIMER(q->next_holdoff) | V_NEWINDEX(q->cidx));
+               new_packets = 1;
+       }
+
+       if (adap->params.nports == 2 &&
+           process_responses(adap, &adap->sge.qs[1], -1)) {
+               struct sge_rspq *q1 = &adap->sge.qs[1].rspq;
+
+               t3_write_reg(adap, A_SG_GTS, V_RSPQ(q1->cntxt_id) |
+                            V_NEWTIMER(q1->next_holdoff) |
+                            V_NEWINDEX(q1->cidx));
+               new_packets = 1;
+       }
+
+       if (!new_packets && t3_slow_intr_handler(adap) == 0)
+               q->unhandled_irqs++;
+
+       spin_unlock(&q->lock);
+       return IRQ_HANDLED;
+}
+
+static int rspq_check_napi(struct net_device *dev, struct sge_rspq *q)
+{
+       if (!napi_is_scheduled(dev) && is_new_response(&q->desc[q->cidx], q)) {
+               if (likely(__netif_rx_schedule_prep(dev)))
+                       __netif_rx_schedule(dev);
+               return 1;
+       }
+       return 0;
+}
+
+/*
+ * The MSI interrupt handler for the NAPI case (i.e., response queues serviced
+ * by NAPI polling).  Handles data events from SGE response queues as well as
+ * error and other async events as they all use the same MSI vector.  We use
+ * one SGE response queue per port in this mode and protect all response
+ * queues with queue 0's lock.
+ */
+irqreturn_t t3_intr_msi_napi(int irq, void *cookie)
+{
+       int new_packets;
+       struct adapter *adap = cookie;
+       struct sge_rspq *q = &adap->sge.qs[0].rspq;
+
+       spin_lock(&q->lock);
+
+       new_packets = rspq_check_napi(adap->sge.qs[0].netdev, q);
+       if (adap->params.nports == 2)
+               new_packets += rspq_check_napi(adap->sge.qs[1].netdev,
+                                              &adap->sge.qs[1].rspq);
+       if (!new_packets && t3_slow_intr_handler(adap) == 0)
+               q->unhandled_irqs++;
+
+       spin_unlock(&q->lock);
+       return IRQ_HANDLED;
+}
+
+/*
+ * A helper function that processes responses and issues GTS.
+ */
+static inline int process_responses_gts(struct adapter *adap,
+                                       struct sge_rspq *rq)
+{
+       int work;
+
+       work = process_responses(adap, rspq_to_qset(rq), -1);
+       t3_write_reg(adap, A_SG_GTS, V_RSPQ(rq->cntxt_id) |
+                    V_NEWTIMER(rq->next_holdoff) | V_NEWINDEX(rq->cidx));
+       return work;
+}
+
+/*
+ * The legacy INTx interrupt handler.  This needs to handle data events from
+ * SGE response queues as well as error and other async events as they all use
+ * the same interrupt pin.  We use one SGE response queue per port in this mode
+ * and protect all response queues with queue 0's lock.
+ */
+static irqreturn_t t3_intr(int irq, void *cookie)
+{
+       int work_done, w0, w1;
+       struct adapter *adap = cookie;
+       struct sge_rspq *q0 = &adap->sge.qs[0].rspq;
+       struct sge_rspq *q1 = &adap->sge.qs[1].rspq;
+
+       spin_lock(&q0->lock);
+
+       w0 = is_new_response(&q0->desc[q0->cidx], q0);
+       w1 = adap->params.nports == 2 &&
+           is_new_response(&q1->desc[q1->cidx], q1);
+
+       if (likely(w0 | w1)) {
+               t3_write_reg(adap, A_PL_CLI, 0);
+               t3_read_reg(adap, A_PL_CLI);    /* flush */
+
+               if (likely(w0))
+                       process_responses_gts(adap, q0);
+
+               if (w1)
+                       process_responses_gts(adap, q1);
+
+               work_done = w0 | w1;
+       } else
+               work_done = t3_slow_intr_handler(adap);
+
+       spin_unlock(&q0->lock);
+       return IRQ_RETVAL(work_done != 0);
+}
+
+/*
+ * Interrupt handler for legacy INTx interrupts for T3B-based cards.
+ * Handles data events from SGE response queues as well as error and other
+ * async events as they all use the same interrupt pin.  We use one SGE
+ * response queue per port in this mode and protect all response queues with
+ * queue 0's lock.
+ */
+static irqreturn_t t3b_intr(int irq, void *cookie)
+{
+       u32 map;
+       struct adapter *adap = cookie;
+       struct sge_rspq *q0 = &adap->sge.qs[0].rspq;
+
+       t3_write_reg(adap, A_PL_CLI, 0);
+       map = t3_read_reg(adap, A_SG_DATA_INTR);
+
+       if (unlikely(!map))     /* shared interrupt, most likely */
+               return IRQ_NONE;
+
+       spin_lock(&q0->lock);
+
+       if (unlikely(map & F_ERRINTR))
+               t3_slow_intr_handler(adap);
+
+       if (likely(map & 1))
+               process_responses_gts(adap, q0);
+
+       if (map & 2)
+               process_responses_gts(adap, &adap->sge.qs[1].rspq);
+
+       spin_unlock(&q0->lock);
+       return IRQ_HANDLED;
+}
+
+/*
+ * NAPI interrupt handler for legacy INTx interrupts for T3B-based cards.
+ * Handles data events from SGE response queues as well as error and other
+ * async events as they all use the same interrupt pin.  We use one SGE
+ * response queue per port in this mode and protect all response queues with
+ * queue 0's lock.
+ */
+static irqreturn_t t3b_intr_napi(int irq, void *cookie)
+{
+       u32 map;
+       struct net_device *dev;
+       struct adapter *adap = cookie;
+       struct sge_rspq *q0 = &adap->sge.qs[0].rspq;
+
+       t3_write_reg(adap, A_PL_CLI, 0);
+       map = t3_read_reg(adap, A_SG_DATA_INTR);
+
+       if (unlikely(!map))     /* shared interrupt, most likely */
+               return IRQ_NONE;
+
+       spin_lock(&q0->lock);
+
+       if (unlikely(map & F_ERRINTR))
+               t3_slow_intr_handler(adap);
+
+       if (likely(map & 1)) {
+               dev = adap->sge.qs[0].netdev;
+
+               if (likely(__netif_rx_schedule_prep(dev)))
+                       __netif_rx_schedule(dev);
+       }
+       if (map & 2) {
+               dev = adap->sge.qs[1].netdev;
+
+               if (likely(__netif_rx_schedule_prep(dev)))
+                       __netif_rx_schedule(dev);
+       }
+
+       spin_unlock(&q0->lock);
+       return IRQ_HANDLED;
+}
+
+/**
+ *     t3_intr_handler - select the top-level interrupt handler
+ *     @adap: the adapter
+ *     @polling: whether using NAPI to service response queues
+ *
+ *     Selects the top-level interrupt handler based on the type of interrupts
+ *     (MSI-X, MSI, or legacy) and whether NAPI will be used to service the
+ *     response queues.
+ */
+intr_handler_t t3_intr_handler(struct adapter *adap, int polling)
+{
+       if (adap->flags & USING_MSIX)
+               return polling ? t3_sge_intr_msix_napi : t3_sge_intr_msix;
+       if (adap->flags & USING_MSI)
+               return polling ? t3_intr_msi_napi : t3_intr_msi;
+       if (adap->params.rev > 0)
+               return polling ? t3b_intr_napi : t3b_intr;
+       return t3_intr;
+}
+
+/**
+ *     t3_sge_err_intr_handler - SGE async event interrupt handler
+ *     @adapter: the adapter
+ *
+ *     Interrupt handler for SGE asynchronous (non-data) events.
+ */
+void t3_sge_err_intr_handler(struct adapter *adapter)
+{
+       unsigned int v, status = t3_read_reg(adapter, A_SG_INT_CAUSE);
+
+       if (status & F_RSPQCREDITOVERFOW)
+               CH_ALERT(adapter, "SGE response queue credit overflow\n");
+
+       if (status & F_RSPQDISABLED) {
+               v = t3_read_reg(adapter, A_SG_RSPQ_FL_STATUS);
+
+               CH_ALERT(adapter,
+                        "packet delivered to disabled response queue "
+                        "(0x%x)\n", (v >> S_RSPQ0DISABLED) & 0xff);
+       }
+
+       t3_write_reg(adapter, A_SG_INT_CAUSE, status);
+       if (status & (F_RSPQCREDITOVERFOW | F_RSPQDISABLED))
+               t3_fatal_err(adapter);
+}
+
+/**
+ *     sge_timer_cb - perform periodic maintenance of an SGE qset
+ *     @data: the SGE queue set to maintain
+ *
+ *     Runs periodically from a timer to perform maintenance of an SGE queue
+ *     set.  It performs two tasks:
+ *
+ *     a) Cleans up any completed Tx descriptors that may still be pending.
+ *     Normal descriptor cleanup happens when new packets are added to a Tx
+ *     queue so this timer is relatively infrequent and does any cleanup only
+ *     if the Tx queue has not seen any new packets in a while.  We make a
+ *     best effort attempt to reclaim descriptors, in that we don't wait
+ *     around if we cannot get a queue's lock (which most likely is because
+ *     someone else is queueing new packets and so will also handle the clean
+ *     up).  Since control queues use immediate data exclusively we don't
+ *     bother cleaning them up here.
+ *
+ *     b) Replenishes Rx queues that have run out due to memory shortage.
+ *     Normally new Rx buffers are added when existing ones are consumed but
+ *     when out of memory a queue can become empty.  We try to add only a few
+ *     buffers here, the queue will be replenished fully as these new buffers
+ *     are used up if memory shortage has subsided.
+ */
+static void sge_timer_cb(unsigned long data)
+{
+       spinlock_t *lock;
+       struct sge_qset *qs = (struct sge_qset *)data;
+       struct adapter *adap = qs->netdev->priv;
+
+       if (spin_trylock(&qs->txq[TXQ_ETH].lock)) {
+               reclaim_completed_tx(adap, &qs->txq[TXQ_ETH]);
+               spin_unlock(&qs->txq[TXQ_ETH].lock);
+       }
+       if (spin_trylock(&qs->txq[TXQ_OFLD].lock)) {
+               reclaim_completed_tx(adap, &qs->txq[TXQ_OFLD]);
+               spin_unlock(&qs->txq[TXQ_OFLD].lock);
+       }
+       lock = (adap->flags & USING_MSIX) ? &qs->rspq.lock :
+           &adap->sge.qs[0].rspq.lock;
+       if (spin_trylock_irq(lock)) {
+               if (!napi_is_scheduled(qs->netdev)) {
+                       if (qs->fl[0].credits < qs->fl[0].size)
+                               __refill_fl(adap, &qs->fl[0]);
+                       if (qs->fl[1].credits < qs->fl[1].size)
+                               __refill_fl(adap, &qs->fl[1]);
+               }
+               spin_unlock_irq(lock);
+       }
+       mod_timer(&qs->tx_reclaim_timer, jiffies + TX_RECLAIM_PERIOD);
+}
+
+/**
+ *     t3_update_qset_coalesce - update coalescing settings for a queue set
+ *     @qs: the SGE queue set
+ *     @p: new queue set parameters
+ *
+ *     Update the coalescing settings for an SGE queue set.  Nothing is done
+ *     if the queue set is not initialized yet.
+ */
+void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p)
+{
+       if (!qs->netdev)
+               return;
+
+       qs->rspq.holdoff_tmr = max(p->coalesce_usecs * 10, 1U);/* can't be 0 */
+       qs->rspq.polling = p->polling;
+       qs->netdev->poll = p->polling ? napi_rx_handler : ofld_poll;
+}
+
+/**
+ *     t3_sge_alloc_qset - initialize an SGE queue set
+ *     @adapter: the adapter
+ *     @id: the queue set id
+ *     @nports: how many Ethernet ports will be using this queue set
+ *     @irq_vec_idx: the IRQ vector index for response queue interrupts
+ *     @p: configuration parameters for this queue set
+ *     @ntxq: number of Tx queues for the queue set
+ *     @netdev: net device associated with this queue set
+ *
+ *     Allocate resources and initialize an SGE queue set.  A queue set
+ *     comprises a response queue, two Rx free-buffer queues, and up to 3
+ *     Tx queues.  The Tx queues are assigned roles in the order Ethernet
+ *     queue, offload queue, and control queue.
+ */
+int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
+                     int irq_vec_idx, const struct qset_params *p,
+                     int ntxq, struct net_device *netdev)
+{
+       int i, ret = -ENOMEM;
+       struct sge_qset *q = &adapter->sge.qs[id];
+
+       init_qset_cntxt(q, id);
+       init_timer(&q->tx_reclaim_timer);
+       q->tx_reclaim_timer.data = (unsigned long)q;
+       q->tx_reclaim_timer.function = sge_timer_cb;
+
+       q->fl[0].desc = alloc_ring(adapter->pdev, p->fl_size,
+                                  sizeof(struct rx_desc),
+                                  sizeof(struct rx_sw_desc),
+                                  &q->fl[0].phys_addr, &q->fl[0].sdesc);
+       if (!q->fl[0].desc)
+               goto err;
+
+       q->fl[1].desc = alloc_ring(adapter->pdev, p->jumbo_size,
+                                  sizeof(struct rx_desc),
+                                  sizeof(struct rx_sw_desc),
+                                  &q->fl[1].phys_addr, &q->fl[1].sdesc);
+       if (!q->fl[1].desc)
+               goto err;
+
+       q->rspq.desc = alloc_ring(adapter->pdev, p->rspq_size,
+                                 sizeof(struct rsp_desc), 0,
+                                 &q->rspq.phys_addr, NULL);
+       if (!q->rspq.desc)
+               goto err;
+
+       for (i = 0; i < ntxq; ++i) {
+               /*
+                * The control queue always uses immediate data so does not
+                * need to keep track of any sk_buffs.
+                */
+               size_t sz = i == TXQ_CTRL ? 0 : sizeof(struct tx_sw_desc);
+
+               q->txq[i].desc = alloc_ring(adapter->pdev, p->txq_size[i],
+                                           sizeof(struct tx_desc), sz,
+                                           &q->txq[i].phys_addr,
+                                           &q->txq[i].sdesc);
+               if (!q->txq[i].desc)
+                       goto err;
+
+               q->txq[i].gen = 1;
+               q->txq[i].size = p->txq_size[i];
+               spin_lock_init(&q->txq[i].lock);
+               skb_queue_head_init(&q->txq[i].sendq);
+       }
+
+       tasklet_init(&q->txq[TXQ_OFLD].qresume_tsk, restart_offloadq,
+                    (unsigned long)q);
+       tasklet_init(&q->txq[TXQ_CTRL].qresume_tsk, restart_ctrlq,
+                    (unsigned long)q);
+
+       q->fl[0].gen = q->fl[1].gen = 1;
+       q->fl[0].size = p->fl_size;
+       q->fl[1].size = p->jumbo_size;
+
+       q->rspq.gen = 1;
+       q->rspq.size = p->rspq_size;
+       spin_lock_init(&q->rspq.lock);
+
+       q->txq[TXQ_ETH].stop_thres = nports *
+           flits_to_desc(sgl_len(MAX_SKB_FRAGS + 1) + 3);
+
+       if (ntxq == 1) {
+               q->fl[0].buf_size = SGE_RX_SM_BUF_SIZE + 2 +
+                   sizeof(struct cpl_rx_pkt);
+               q->fl[1].buf_size = MAX_FRAME_SIZE + 2 +
+                   sizeof(struct cpl_rx_pkt);
+       } else {
+               q->fl[0].buf_size = SGE_RX_SM_BUF_SIZE +
+                   sizeof(struct cpl_rx_data);
+               q->fl[1].buf_size = (16 * 1024) -
+                   SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+       }
+
+       spin_lock(&adapter->sge.reg_lock);
+
+       /* FL threshold comparison uses < */
+       ret = t3_sge_init_rspcntxt(adapter, q->rspq.cntxt_id, irq_vec_idx,
+                                  q->rspq.phys_addr, q->rspq.size,
+                                  q->fl[0].buf_size, 1, 0);
+       if (ret)
+               goto err_unlock;
+
+       for (i = 0; i < SGE_RXQ_PER_SET; ++i) {
+               ret = t3_sge_init_flcntxt(adapter, q->fl[i].cntxt_id, 0,
+                                         q->fl[i].phys_addr, q->fl[i].size,
+                                         q->fl[i].buf_size, p->cong_thres, 1,
+                                         0);
+               if (ret)
+                       goto err_unlock;
+       }
+
+       ret = t3_sge_init_ecntxt(adapter, q->txq[TXQ_ETH].cntxt_id, USE_GTS,
+                                SGE_CNTXT_ETH, id, q->txq[TXQ_ETH].phys_addr,
+                                q->txq[TXQ_ETH].size, q->txq[TXQ_ETH].token,
+                                1, 0);
+       if (ret)
+               goto err_unlock;
+
+       if (ntxq > 1) {
+               ret = t3_sge_init_ecntxt(adapter, q->txq[TXQ_OFLD].cntxt_id,
+                                        USE_GTS, SGE_CNTXT_OFLD, id,
+                                        q->txq[TXQ_OFLD].phys_addr,
+                                        q->txq[TXQ_OFLD].size, 0, 1, 0);
+               if (ret)
+                       goto err_unlock;
+       }
+
+       if (ntxq > 2) {
+               ret = t3_sge_init_ecntxt(adapter, q->txq[TXQ_CTRL].cntxt_id, 0,
+                                        SGE_CNTXT_CTRL, id,
+                                        q->txq[TXQ_CTRL].phys_addr,
+                                        q->txq[TXQ_CTRL].size,
+                                        q->txq[TXQ_CTRL].token, 1, 0);
+               if (ret)
+                       goto err_unlock;
+       }
+
+       spin_unlock(&adapter->sge.reg_lock);
+       q->netdev = netdev;
+       t3_update_qset_coalesce(q, p);
+
+       /*
+        * We use atalk_ptr as a backpointer to a qset.  In case a device is
+        * associated with multiple queue sets only the first one sets
+        * atalk_ptr.
+        */
+       if (netdev->atalk_ptr == NULL)
+               netdev->atalk_ptr = q;
+
+       refill_fl(adapter, &q->fl[0], q->fl[0].size, GFP_KERNEL);
+       refill_fl(adapter, &q->fl[1], q->fl[1].size, GFP_KERNEL);
+       refill_rspq(adapter, &q->rspq, q->rspq.size - 1);
+
+       t3_write_reg(adapter, A_SG_GTS, V_RSPQ(q->rspq.cntxt_id) |
+                    V_NEWTIMER(q->rspq.holdoff_tmr));
+
+       mod_timer(&q->tx_reclaim_timer, jiffies + TX_RECLAIM_PERIOD);
+       return 0;
+
+      err_unlock:
+       spin_unlock(&adapter->sge.reg_lock);
+      err:
+       t3_free_qset(adapter, q);
+       return ret;
+}
+
+/**
+ *     t3_free_sge_resources - free SGE resources
+ *     @adap: the adapter
+ *
+ *     Frees resources used by the SGE queue sets.
+ */
+void t3_free_sge_resources(struct adapter *adap)
+{
+       int i;
+
+       for (i = 0; i < SGE_QSETS; ++i)
+               t3_free_qset(adap, &adap->sge.qs[i]);
+}
+
+/**
+ *     t3_sge_start - enable SGE
+ *     @adap: the adapter
+ *
+ *     Enables the SGE for DMAs.  This is the last step in starting packet
+ *     transfers.
+ */
+void t3_sge_start(struct adapter *adap)
+{
+       t3_set_reg_field(adap, A_SG_CONTROL, F_GLOBALENABLE, F_GLOBALENABLE);
+}
+
+/**
+ *     t3_sge_stop - disable SGE operation
+ *     @adap: the adapter
+ *
+ *     Disables the DMA engine.  This can be called in emeregencies (e.g.,
+ *     from error interrupts) or from normal process context.  In the latter
+ *     case it also disables any pending queue restart tasklets.  Note that
+ *     if it is called in interrupt context it cannot disable the restart
+ *     tasklets as it cannot wait, however the tasklets will have no effect
+ *     since the doorbells are disabled and the driver will call this again
+ *     later from process context, at which time the tasklets will be stopped
+ *     if they are still running.
+ */
+void t3_sge_stop(struct adapter *adap)
+{
+       t3_set_reg_field(adap, A_SG_CONTROL, F_GLOBALENABLE, 0);
+       if (!in_interrupt()) {
+               int i;
+
+               for (i = 0; i < SGE_QSETS; ++i) {
+                       struct sge_qset *qs = &adap->sge.qs[i];
+
+                       tasklet_kill(&qs->txq[TXQ_OFLD].qresume_tsk);
+                       tasklet_kill(&qs->txq[TXQ_CTRL].qresume_tsk);
+               }
+       }
+}
+
+/**
+ *     t3_sge_init - initialize SGE
+ *     @adap: the adapter
+ *     @p: the SGE parameters
+ *
+ *     Performs SGE initialization needed every time after a chip reset.
+ *     We do not initialize any of the queue sets here, instead the driver
+ *     top-level must request those individually.  We also do not enable DMA
+ *     here, that should be done after the queues have been set up.
+ */
+void t3_sge_init(struct adapter *adap, struct sge_params *p)
+{
+       unsigned int ctrl, ups = ffs(pci_resource_len(adap->pdev, 2) >> 12);
+
+       ctrl = F_DROPPKT | V_PKTSHIFT(2) | F_FLMODE | F_AVOIDCQOVFL |
+           F_CQCRDTCTRL |
+           V_HOSTPAGESIZE(PAGE_SHIFT - 11) | F_BIGENDIANINGRESS |
+           V_USERSPACESIZE(ups ? ups - 1 : 0) | F_ISCSICOALESCING;
+#if SGE_NUM_GENBITS == 1
+       ctrl |= F_EGRGENCTRL;
+#endif
+       if (adap->params.rev > 0) {
+               if (!(adap->flags & (USING_MSIX | USING_MSI)))
+                       ctrl |= F_ONEINTMULTQ | F_OPTONEINTMULTQ;
+               ctrl |= F_CQCRDTCTRL | F_AVOIDCQOVFL;
+       }
+       t3_write_reg(adap, A_SG_CONTROL, ctrl);
+       t3_write_reg(adap, A_SG_EGR_RCQ_DRB_THRSH, V_HIRCQDRBTHRSH(512) |
+                    V_LORCQDRBTHRSH(512));
+       t3_write_reg(adap, A_SG_TIMER_TICK, core_ticks_per_usec(adap) / 10);
+       t3_write_reg(adap, A_SG_CMDQ_CREDIT_TH, V_THRESHOLD(32) |
+                    V_TIMEOUT(200 * core_ticks_per_usec(adap)));
+       t3_write_reg(adap, A_SG_HI_DRB_HI_THRSH, 1000);
+       t3_write_reg(adap, A_SG_HI_DRB_LO_THRSH, 256);
+       t3_write_reg(adap, A_SG_LO_DRB_HI_THRSH, 1000);
+       t3_write_reg(adap, A_SG_LO_DRB_LO_THRSH, 256);
+       t3_write_reg(adap, A_SG_OCO_BASE, V_BASE1(0xfff));
+       t3_write_reg(adap, A_SG_DRB_PRI_THRESH, 63 * 1024);
+}
+
+/**
+ *     t3_sge_prep - one-time SGE initialization
+ *     @adap: the associated adapter
+ *     @p: SGE parameters
+ *
+ *     Performs one-time initialization of SGE SW state.  Includes determining
+ *     defaults for the assorted SGE parameters, which admins can change until
+ *     they are used to initialize the SGE.
+ */
+void __devinit t3_sge_prep(struct adapter *adap, struct sge_params *p)
+{
+       int i;
+
+       p->max_pkt_size = (16 * 1024) - sizeof(struct cpl_rx_data) -
+           SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+
+       for (i = 0; i < SGE_QSETS; ++i) {
+               struct qset_params *q = p->qset + i;
+
+               q->polling = adap->params.rev > 0;
+               q->coalesce_usecs = 5;
+               q->rspq_size = 1024;
+               q->fl_size = 4096;
+               q->jumbo_size = 512;
+               q->txq_size[TXQ_ETH] = 1024;
+               q->txq_size[TXQ_OFLD] = 1024;
+               q->txq_size[TXQ_CTRL] = 256;
+               q->cong_thres = 0;
+       }
+
+       spin_lock_init(&adap->sge.reg_lock);
+}
+
+/**
+ *     t3_get_desc - dump an SGE descriptor for debugging purposes
+ *     @qs: the queue set
+ *     @qnum: identifies the specific queue (0..2: Tx, 3:response, 4..5: Rx)
+ *     @idx: the descriptor index in the queue
+ *     @data: where to dump the descriptor contents
+ *
+ *     Dumps the contents of a HW descriptor of an SGE queue.  Returns the
+ *     size of the descriptor.
+ */
+int t3_get_desc(const struct sge_qset *qs, unsigned int qnum, unsigned int idx,
+               unsigned char *data)
+{
+       if (qnum >= 6)
+               return -EINVAL;
+
+       if (qnum < 3) {
+               if (!qs->txq[qnum].desc || idx >= qs->txq[qnum].size)
+                       return -EINVAL;
+               memcpy(data, &qs->txq[qnum].desc[idx], sizeof(struct tx_desc));
+               return sizeof(struct tx_desc);
+       }
+
+       if (qnum == 3) {
+               if (!qs->rspq.desc || idx >= qs->rspq.size)
+                       return -EINVAL;
+               memcpy(data, &qs->rspq.desc[idx], sizeof(struct rsp_desc));
+               return sizeof(struct rsp_desc);
+       }
+
+       qnum -= 4;
+       if (!qs->fl[qnum].desc || idx >= qs->fl[qnum].size)
+               return -EINVAL;
+       memcpy(data, &qs->fl[qnum].desc[idx], sizeof(struct rx_desc));
+       return sizeof(struct rx_desc);
+}
diff --git a/drivers/net/cxgb3/sge_defs.h b/drivers/net/cxgb3/sge_defs.h
new file mode 100644 (file)
index 0000000..514869e
--- /dev/null
@@ -0,0 +1,251 @@
+/*
+ * This file is automatically generated --- any changes will be lost.
+ */
+
+#ifndef _SGE_DEFS_H
+#define _SGE_DEFS_H
+
+#define S_EC_CREDITS    0
+#define M_EC_CREDITS    0x7FFF
+#define V_EC_CREDITS(x) ((x) << S_EC_CREDITS)
+#define G_EC_CREDITS(x) (((x) >> S_EC_CREDITS) & M_EC_CREDITS)
+
+#define S_EC_GTS    15
+#define V_EC_GTS(x) ((x) << S_EC_GTS)
+#define F_EC_GTS    V_EC_GTS(1U)
+
+#define S_EC_INDEX    16
+#define M_EC_INDEX    0xFFFF
+#define V_EC_INDEX(x) ((x) << S_EC_INDEX)
+#define G_EC_INDEX(x) (((x) >> S_EC_INDEX) & M_EC_INDEX)
+
+#define S_EC_SIZE    0
+#define M_EC_SIZE    0xFFFF
+#define V_EC_SIZE(x) ((x) << S_EC_SIZE)
+#define G_EC_SIZE(x) (((x) >> S_EC_SIZE) & M_EC_SIZE)
+
+#define S_EC_BASE_LO    16
+#define M_EC_BASE_LO    0xFFFF
+#define V_EC_BASE_LO(x) ((x) << S_EC_BASE_LO)
+#define G_EC_BASE_LO(x) (((x) >> S_EC_BASE_LO) & M_EC_BASE_LO)
+
+#define S_EC_BASE_HI    0
+#define M_EC_BASE_HI    0xF
+#define V_EC_BASE_HI(x) ((x) << S_EC_BASE_HI)
+#define G_EC_BASE_HI(x) (((x) >> S_EC_BASE_HI) & M_EC_BASE_HI)
+
+#define S_EC_RESPQ    4
+#define M_EC_RESPQ    0x7
+#define V_EC_RESPQ(x) ((x) << S_EC_RESPQ)
+#define G_EC_RESPQ(x) (((x) >> S_EC_RESPQ) & M_EC_RESPQ)
+
+#define S_EC_TYPE    7
+#define M_EC_TYPE    0x7
+#define V_EC_TYPE(x) ((x) << S_EC_TYPE)
+#define G_EC_TYPE(x) (((x) >> S_EC_TYPE) & M_EC_TYPE)
+
+#define S_EC_GEN    10
+#define V_EC_GEN(x) ((x) << S_EC_GEN)
+#define F_EC_GEN    V_EC_GEN(1U)
+
+#define S_EC_UP_TOKEN    11
+#define M_EC_UP_TOKEN    0xFFFFF
+#define V_EC_UP_TOKEN(x) ((x) << S_EC_UP_TOKEN)
+#define G_EC_UP_TOKEN(x) (((x) >> S_EC_UP_TOKEN) & M_EC_UP_TOKEN)
+
+#define S_EC_VALID    31
+#define V_EC_VALID(x) ((x) << S_EC_VALID)
+#define F_EC_VALID    V_EC_VALID(1U)
+
+#define S_RQ_MSI_VEC    20
+#define M_RQ_MSI_VEC    0x3F
+#define V_RQ_MSI_VEC(x) ((x) << S_RQ_MSI_VEC)
+#define G_RQ_MSI_VEC(x) (((x) >> S_RQ_MSI_VEC) & M_RQ_MSI_VEC)
+
+#define S_RQ_INTR_EN    26
+#define V_RQ_INTR_EN(x) ((x) << S_RQ_INTR_EN)
+#define F_RQ_INTR_EN    V_RQ_INTR_EN(1U)
+
+#define S_RQ_GEN    28
+#define V_RQ_GEN(x) ((x) << S_RQ_GEN)
+#define F_RQ_GEN    V_RQ_GEN(1U)
+
+#define S_CQ_INDEX    0
+#define M_CQ_INDEX    0xFFFF
+#define V_CQ_INDEX(x) ((x) << S_CQ_INDEX)
+#define G_CQ_INDEX(x) (((x) >> S_CQ_INDEX) & M_CQ_INDEX)
+
+#define S_CQ_SIZE    16
+#define M_CQ_SIZE    0xFFFF
+#define V_CQ_SIZE(x) ((x) << S_CQ_SIZE)
+#define G_CQ_SIZE(x) (((x) >> S_CQ_SIZE) & M_CQ_SIZE)
+
+#define S_CQ_BASE_HI    0
+#define M_CQ_BASE_HI    0xFFFFF
+#define V_CQ_BASE_HI(x) ((x) << S_CQ_BASE_HI)
+#define G_CQ_BASE_HI(x) (((x) >> S_CQ_BASE_HI) & M_CQ_BASE_HI)
+
+#define S_CQ_RSPQ    20
+#define M_CQ_RSPQ    0x3F
+#define V_CQ_RSPQ(x) ((x) << S_CQ_RSPQ)
+#define G_CQ_RSPQ(x) (((x) >> S_CQ_RSPQ) & M_CQ_RSPQ)
+
+#define S_CQ_ASYNC_NOTIF    26
+#define V_CQ_ASYNC_NOTIF(x) ((x) << S_CQ_ASYNC_NOTIF)
+#define F_CQ_ASYNC_NOTIF    V_CQ_ASYNC_NOTIF(1U)
+
+#define S_CQ_ARMED    27
+#define V_CQ_ARMED(x) ((x) << S_CQ_ARMED)
+#define F_CQ_ARMED    V_CQ_ARMED(1U)
+
+#define S_CQ_ASYNC_NOTIF_SOL    28
+#define V_CQ_ASYNC_NOTIF_SOL(x) ((x) << S_CQ_ASYNC_NOTIF_SOL)
+#define F_CQ_ASYNC_NOTIF_SOL    V_CQ_ASYNC_NOTIF_SOL(1U)
+
+#define S_CQ_GEN    29
+#define V_CQ_GEN(x) ((x) << S_CQ_GEN)
+#define F_CQ_GEN    V_CQ_GEN(1U)
+
+#define S_CQ_OVERFLOW_MODE    31
+#define V_CQ_OVERFLOW_MODE(x) ((x) << S_CQ_OVERFLOW_MODE)
+#define F_CQ_OVERFLOW_MODE    V_CQ_OVERFLOW_MODE(1U)
+
+#define S_CQ_CREDITS    0
+#define M_CQ_CREDITS    0xFFFF
+#define V_CQ_CREDITS(x) ((x) << S_CQ_CREDITS)
+#define G_CQ_CREDITS(x) (((x) >> S_CQ_CREDITS) & M_CQ_CREDITS)
+
+#define S_CQ_CREDIT_THRES    16
+#define M_CQ_CREDIT_THRES    0x1FFF
+#define V_CQ_CREDIT_THRES(x) ((x) << S_CQ_CREDIT_THRES)
+#define G_CQ_CREDIT_THRES(x) (((x) >> S_CQ_CREDIT_THRES) & M_CQ_CREDIT_THRES)
+
+#define S_FL_BASE_HI    0
+#define M_FL_BASE_HI    0xFFFFF
+#define V_FL_BASE_HI(x) ((x) << S_FL_BASE_HI)
+#define G_FL_BASE_HI(x) (((x) >> S_FL_BASE_HI) & M_FL_BASE_HI)
+
+#define S_FL_INDEX_LO    20
+#define M_FL_INDEX_LO    0xFFF
+#define V_FL_INDEX_LO(x) ((x) << S_FL_INDEX_LO)
+#define G_FL_INDEX_LO(x) (((x) >> S_FL_INDEX_LO) & M_FL_INDEX_LO)
+
+#define S_FL_INDEX_HI    0
+#define M_FL_INDEX_HI    0xF
+#define V_FL_INDEX_HI(x) ((x) << S_FL_INDEX_HI)
+#define G_FL_INDEX_HI(x) (((x) >> S_FL_INDEX_HI) & M_FL_INDEX_HI)
+
+#define S_FL_SIZE    4
+#define M_FL_SIZE    0xFFFF
+#define V_FL_SIZE(x) ((x) << S_FL_SIZE)
+#define G_FL_SIZE(x) (((x) >> S_FL_SIZE) & M_FL_SIZE)
+
+#define S_FL_GEN    20
+#define V_FL_GEN(x) ((x) << S_FL_GEN)
+#define F_FL_GEN    V_FL_GEN(1U)
+
+#define S_FL_ENTRY_SIZE_LO    21
+#define M_FL_ENTRY_SIZE_LO    0x7FF
+#define V_FL_ENTRY_SIZE_LO(x) ((x) << S_FL_ENTRY_SIZE_LO)
+#define G_FL_ENTRY_SIZE_LO(x) (((x) >> S_FL_ENTRY_SIZE_LO) & M_FL_ENTRY_SIZE_LO)
+
+#define S_FL_ENTRY_SIZE_HI    0
+#define M_FL_ENTRY_SIZE_HI    0x1FFFFF
+#define V_FL_ENTRY_SIZE_HI(x) ((x) << S_FL_ENTRY_SIZE_HI)
+#define G_FL_ENTRY_SIZE_HI(x) (((x) >> S_FL_ENTRY_SIZE_HI) & M_FL_ENTRY_SIZE_HI)
+
+#define S_FL_CONG_THRES    21
+#define M_FL_CONG_THRES    0x3FF
+#define V_FL_CONG_THRES(x) ((x) << S_FL_CONG_THRES)
+#define G_FL_CONG_THRES(x) (((x) >> S_FL_CONG_THRES) & M_FL_CONG_THRES)
+
+#define S_FL_GTS    31
+#define V_FL_GTS(x) ((x) << S_FL_GTS)
+#define F_FL_GTS    V_FL_GTS(1U)
+
+#define S_FLD_GEN1    31
+#define V_FLD_GEN1(x) ((x) << S_FLD_GEN1)
+#define F_FLD_GEN1    V_FLD_GEN1(1U)
+
+#define S_FLD_GEN2    0
+#define V_FLD_GEN2(x) ((x) << S_FLD_GEN2)
+#define F_FLD_GEN2    V_FLD_GEN2(1U)
+
+#define S_RSPD_TXQ1_CR    0
+#define M_RSPD_TXQ1_CR    0x7F
+#define V_RSPD_TXQ1_CR(x) ((x) << S_RSPD_TXQ1_CR)
+#define G_RSPD_TXQ1_CR(x) (((x) >> S_RSPD_TXQ1_CR) & M_RSPD_TXQ1_CR)
+
+#define S_RSPD_TXQ1_GTS    7
+#define V_RSPD_TXQ1_GTS(x) ((x) << S_RSPD_TXQ1_GTS)
+#define F_RSPD_TXQ1_GTS    V_RSPD_TXQ1_GTS(1U)
+
+#define S_RSPD_TXQ2_CR    8
+#define M_RSPD_TXQ2_CR    0x7F
+#define V_RSPD_TXQ2_CR(x) ((x) << S_RSPD_TXQ2_CR)
+#define G_RSPD_TXQ2_CR(x) (((x) >> S_RSPD_TXQ2_CR) & M_RSPD_TXQ2_CR)
+
+#define S_RSPD_TXQ2_GTS    15
+#define V_RSPD_TXQ2_GTS(x) ((x) << S_RSPD_TXQ2_GTS)
+#define F_RSPD_TXQ2_GTS    V_RSPD_TXQ2_GTS(1U)
+
+#define S_RSPD_TXQ0_CR    16
+#define M_RSPD_TXQ0_CR    0x7F
+#define V_RSPD_TXQ0_CR(x) ((x) << S_RSPD_TXQ0_CR)
+#define G_RSPD_TXQ0_CR(x) (((x) >> S_RSPD_TXQ0_CR) & M_RSPD_TXQ0_CR)
+
+#define S_RSPD_TXQ0_GTS    23
+#define V_RSPD_TXQ0_GTS(x) ((x) << S_RSPD_TXQ0_GTS)
+#define F_RSPD_TXQ0_GTS    V_RSPD_TXQ0_GTS(1U)
+
+#define S_RSPD_EOP    24
+#define V_RSPD_EOP(x) ((x) << S_RSPD_EOP)
+#define F_RSPD_EOP    V_RSPD_EOP(1U)
+
+#define S_RSPD_SOP    25
+#define V_RSPD_SOP(x) ((x) << S_RSPD_SOP)
+#define F_RSPD_SOP    V_RSPD_SOP(1U)
+
+#define S_RSPD_ASYNC_NOTIF    26
+#define V_RSPD_ASYNC_NOTIF(x) ((x) << S_RSPD_ASYNC_NOTIF)
+#define F_RSPD_ASYNC_NOTIF    V_RSPD_ASYNC_NOTIF(1U)
+
+#define S_RSPD_FL0_GTS    27
+#define V_RSPD_FL0_GTS(x) ((x) << S_RSPD_FL0_GTS)
+#define F_RSPD_FL0_GTS    V_RSPD_FL0_GTS(1U)
+
+#define S_RSPD_FL1_GTS    28
+#define V_RSPD_FL1_GTS(x) ((x) << S_RSPD_FL1_GTS)
+#define F_RSPD_FL1_GTS    V_RSPD_FL1_GTS(1U)
+
+#define S_RSPD_IMM_DATA_VALID    29
+#define V_RSPD_IMM_DATA_VALID(x) ((x) << S_RSPD_IMM_DATA_VALID)
+#define F_RSPD_IMM_DATA_VALID    V_RSPD_IMM_DATA_VALID(1U)
+
+#define S_RSPD_OFFLOAD    30
+#define V_RSPD_OFFLOAD(x) ((x) << S_RSPD_OFFLOAD)
+#define F_RSPD_OFFLOAD    V_RSPD_OFFLOAD(1U)
+
+#define S_RSPD_GEN1    31
+#define V_RSPD_GEN1(x) ((x) << S_RSPD_GEN1)
+#define F_RSPD_GEN1    V_RSPD_GEN1(1U)
+
+#define S_RSPD_LEN    0
+#define M_RSPD_LEN    0x7FFFFFFF
+#define V_RSPD_LEN(x) ((x) << S_RSPD_LEN)
+#define G_RSPD_LEN(x) (((x) >> S_RSPD_LEN) & M_RSPD_LEN)
+
+#define S_RSPD_FLQ    31
+#define V_RSPD_FLQ(x) ((x) << S_RSPD_FLQ)
+#define F_RSPD_FLQ    V_RSPD_FLQ(1U)
+
+#define S_RSPD_GEN2    0
+#define V_RSPD_GEN2(x) ((x) << S_RSPD_GEN2)
+#define F_RSPD_GEN2    V_RSPD_GEN2(1U)
+
+#define S_RSPD_INR_VEC    1
+#define M_RSPD_INR_VEC    0x7F
+#define V_RSPD_INR_VEC(x) ((x) << S_RSPD_INR_VEC)
+#define G_RSPD_INR_VEC(x) (((x) >> S_RSPD_INR_VEC) & M_RSPD_INR_VEC)
+
+#endif                         /* _SGE_DEFS_H */
diff --git a/drivers/net/cxgb3/t3_cpl.h b/drivers/net/cxgb3/t3_cpl.h
new file mode 100644 (file)
index 0000000..b7a1a31
--- /dev/null
@@ -0,0 +1,1444 @@
+/*
+ * Copyright (c) 2004-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef T3_CPL_H
+#define T3_CPL_H
+
+#if !defined(__LITTLE_ENDIAN_BITFIELD) && !defined(__BIG_ENDIAN_BITFIELD)
+# include <asm/byteorder.h>
+#endif
+
+enum CPL_opcode {
+       CPL_PASS_OPEN_REQ = 0x1,
+       CPL_PASS_ACCEPT_RPL = 0x2,
+       CPL_ACT_OPEN_REQ = 0x3,
+       CPL_SET_TCB = 0x4,
+       CPL_SET_TCB_FIELD = 0x5,
+       CPL_GET_TCB = 0x6,
+       CPL_PCMD = 0x7,
+       CPL_CLOSE_CON_REQ = 0x8,
+       CPL_CLOSE_LISTSRV_REQ = 0x9,
+       CPL_ABORT_REQ = 0xA,
+       CPL_ABORT_RPL = 0xB,
+       CPL_TX_DATA = 0xC,
+       CPL_RX_DATA_ACK = 0xD,
+       CPL_TX_PKT = 0xE,
+       CPL_RTE_DELETE_REQ = 0xF,
+       CPL_RTE_WRITE_REQ = 0x10,
+       CPL_RTE_READ_REQ = 0x11,
+       CPL_L2T_WRITE_REQ = 0x12,
+       CPL_L2T_READ_REQ = 0x13,
+       CPL_SMT_WRITE_REQ = 0x14,
+       CPL_SMT_READ_REQ = 0x15,
+       CPL_TX_PKT_LSO = 0x16,
+       CPL_PCMD_READ = 0x17,
+       CPL_BARRIER = 0x18,
+       CPL_TID_RELEASE = 0x1A,
+
+       CPL_CLOSE_LISTSRV_RPL = 0x20,
+       CPL_ERROR = 0x21,
+       CPL_GET_TCB_RPL = 0x22,
+       CPL_L2T_WRITE_RPL = 0x23,
+       CPL_PCMD_READ_RPL = 0x24,
+       CPL_PCMD_RPL = 0x25,
+       CPL_PEER_CLOSE = 0x26,
+       CPL_RTE_DELETE_RPL = 0x27,
+       CPL_RTE_WRITE_RPL = 0x28,
+       CPL_RX_DDP_COMPLETE = 0x29,
+       CPL_RX_PHYS_ADDR = 0x2A,
+       CPL_RX_PKT = 0x2B,
+       CPL_RX_URG_NOTIFY = 0x2C,
+       CPL_SET_TCB_RPL = 0x2D,
+       CPL_SMT_WRITE_RPL = 0x2E,
+       CPL_TX_DATA_ACK = 0x2F,
+
+       CPL_ABORT_REQ_RSS = 0x30,
+       CPL_ABORT_RPL_RSS = 0x31,
+       CPL_CLOSE_CON_RPL = 0x32,
+       CPL_ISCSI_HDR = 0x33,
+       CPL_L2T_READ_RPL = 0x34,
+       CPL_RDMA_CQE = 0x35,
+       CPL_RDMA_CQE_READ_RSP = 0x36,
+       CPL_RDMA_CQE_ERR = 0x37,
+       CPL_RTE_READ_RPL = 0x38,
+       CPL_RX_DATA = 0x39,
+
+       CPL_ACT_OPEN_RPL = 0x40,
+       CPL_PASS_OPEN_RPL = 0x41,
+       CPL_RX_DATA_DDP = 0x42,
+       CPL_SMT_READ_RPL = 0x43,
+
+       CPL_ACT_ESTABLISH = 0x50,
+       CPL_PASS_ESTABLISH = 0x51,
+
+       CPL_PASS_ACCEPT_REQ = 0x70,
+
+       CPL_ASYNC_NOTIF = 0x80, /* fake opcode for async notifications */
+
+       CPL_TX_DMA_ACK = 0xA0,
+       CPL_RDMA_READ_REQ = 0xA1,
+       CPL_RDMA_TERMINATE = 0xA2,
+       CPL_TRACE_PKT = 0xA3,
+       CPL_RDMA_EC_STATUS = 0xA5,
+
+       NUM_CPL_CMDS            /* must be last and previous entries must be sorted */
+};
+
+enum CPL_error {
+       CPL_ERR_NONE = 0,
+       CPL_ERR_TCAM_PARITY = 1,
+       CPL_ERR_TCAM_FULL = 3,
+       CPL_ERR_CONN_RESET = 20,
+       CPL_ERR_CONN_EXIST = 22,
+       CPL_ERR_ARP_MISS = 23,
+       CPL_ERR_BAD_SYN = 24,
+       CPL_ERR_CONN_TIMEDOUT = 30,
+       CPL_ERR_XMIT_TIMEDOUT = 31,
+       CPL_ERR_PERSIST_TIMEDOUT = 32,
+       CPL_ERR_FINWAIT2_TIMEDOUT = 33,
+       CPL_ERR_KEEPALIVE_TIMEDOUT = 34,
+       CPL_ERR_RTX_NEG_ADVICE = 35,
+       CPL_ERR_PERSIST_NEG_ADVICE = 36,
+       CPL_ERR_ABORT_FAILED = 42,
+       CPL_ERR_GENERAL = 99
+};
+
+enum {
+       CPL_CONN_POLICY_AUTO = 0,
+       CPL_CONN_POLICY_ASK = 1,
+       CPL_CONN_POLICY_DENY = 3
+};
+
+enum {
+       ULP_MODE_NONE = 0,
+       ULP_MODE_ISCSI = 2,
+       ULP_MODE_RDMA = 4,
+       ULP_MODE_TCPDDP = 5
+};
+
+enum {
+       ULP_CRC_HEADER = 1 << 0,
+       ULP_CRC_DATA = 1 << 1
+};
+
+enum {
+       CPL_PASS_OPEN_ACCEPT,
+       CPL_PASS_OPEN_REJECT
+};
+
+enum {
+       CPL_ABORT_SEND_RST = 0,
+       CPL_ABORT_NO_RST,
+       CPL_ABORT_POST_CLOSE_REQ = 2
+};
+
+enum {                         /* TX_PKT_LSO ethernet types */
+       CPL_ETH_II,
+       CPL_ETH_II_VLAN,
+       CPL_ETH_802_3,
+       CPL_ETH_802_3_VLAN
+};
+
+enum {                         /* TCP congestion control algorithms */
+       CONG_ALG_RENO,
+       CONG_ALG_TAHOE,
+       CONG_ALG_NEWRENO,
+       CONG_ALG_HIGHSPEED
+};
+
+union opcode_tid {
+       __be32 opcode_tid;
+       __u8 opcode;
+};
+
+#define S_OPCODE 24
+#define V_OPCODE(x) ((x) << S_OPCODE)
+#define G_OPCODE(x) (((x) >> S_OPCODE) & 0xFF)
+#define G_TID(x)    ((x) & 0xFFFFFF)
+
+/* tid is assumed to be 24-bits */
+#define MK_OPCODE_TID(opcode, tid) (V_OPCODE(opcode) | (tid))
+
+#define OPCODE_TID(cmd) ((cmd)->ot.opcode_tid)
+
+/* extract the TID from a CPL command */
+#define GET_TID(cmd) (G_TID(ntohl(OPCODE_TID(cmd))))
+
+struct tcp_options {
+       __be16 mss;
+       __u8 wsf;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+        __u8:5;
+       __u8 ecn:1;
+       __u8 sack:1;
+       __u8 tstamp:1;
+#else
+       __u8 tstamp:1;
+       __u8 sack:1;
+       __u8 ecn:1;
+        __u8:5;
+#endif
+};
+
+struct rss_header {
+       __u8 opcode;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8 cpu_idx:6;
+       __u8 hash_type:2;
+#else
+       __u8 hash_type:2;
+       __u8 cpu_idx:6;
+#endif
+       __be16 cq_idx;
+       __be32 rss_hash_val;
+};
+
+#ifndef CHELSIO_FW
+struct work_request_hdr {
+       __be32 wr_hi;
+       __be32 wr_lo;
+};
+
+/* wr_hi fields */
+#define S_WR_SGE_CREDITS    0
+#define M_WR_SGE_CREDITS    0xFF
+#define V_WR_SGE_CREDITS(x) ((x) << S_WR_SGE_CREDITS)
+#define G_WR_SGE_CREDITS(x) (((x) >> S_WR_SGE_CREDITS) & M_WR_SGE_CREDITS)
+
+#define S_WR_SGLSFLT    8
+#define M_WR_SGLSFLT    0xFF
+#define V_WR_SGLSFLT(x) ((x) << S_WR_SGLSFLT)
+#define G_WR_SGLSFLT(x) (((x) >> S_WR_SGLSFLT) & M_WR_SGLSFLT)
+
+#define S_WR_BCNTLFLT    16
+#define M_WR_BCNTLFLT    0xF
+#define V_WR_BCNTLFLT(x) ((x) << S_WR_BCNTLFLT)
+#define G_WR_BCNTLFLT(x) (((x) >> S_WR_BCNTLFLT) & M_WR_BCNTLFLT)
+
+#define S_WR_DATATYPE    20
+#define V_WR_DATATYPE(x) ((x) << S_WR_DATATYPE)
+#define F_WR_DATATYPE    V_WR_DATATYPE(1U)
+
+#define S_WR_COMPL    21
+#define V_WR_COMPL(x) ((x) << S_WR_COMPL)
+#define F_WR_COMPL    V_WR_COMPL(1U)
+
+#define S_WR_EOP    22
+#define V_WR_EOP(x) ((x) << S_WR_EOP)
+#define F_WR_EOP    V_WR_EOP(1U)
+
+#define S_WR_SOP    23
+#define V_WR_SOP(x) ((x) << S_WR_SOP)
+#define F_WR_SOP    V_WR_SOP(1U)
+
+#define S_WR_OP    24
+#define M_WR_OP    0xFF
+#define V_WR_OP(x) ((x) << S_WR_OP)
+#define G_WR_OP(x) (((x) >> S_WR_OP) & M_WR_OP)
+
+/* wr_lo fields */
+#define S_WR_LEN    0
+#define M_WR_LEN    0xFF
+#define V_WR_LEN(x) ((x) << S_WR_LEN)
+#define G_WR_LEN(x) (((x) >> S_WR_LEN) & M_WR_LEN)
+
+#define S_WR_TID    8
+#define M_WR_TID    0xFFFFF
+#define V_WR_TID(x) ((x) << S_WR_TID)
+#define G_WR_TID(x) (((x) >> S_WR_TID) & M_WR_TID)
+
+#define S_WR_CR_FLUSH    30
+#define V_WR_CR_FLUSH(x) ((x) << S_WR_CR_FLUSH)
+#define F_WR_CR_FLUSH    V_WR_CR_FLUSH(1U)
+
+#define S_WR_GEN    31
+#define V_WR_GEN(x) ((x) << S_WR_GEN)
+#define F_WR_GEN    V_WR_GEN(1U)
+
+# define WR_HDR struct work_request_hdr wr
+# define RSS_HDR
+#else
+# define WR_HDR
+# define RSS_HDR struct rss_header rss_hdr;
+#endif
+
+/* option 0 lower-half fields */
+#define S_CPL_STATUS    0
+#define M_CPL_STATUS    0xFF
+#define V_CPL_STATUS(x) ((x) << S_CPL_STATUS)
+#define G_CPL_STATUS(x) (((x) >> S_CPL_STATUS) & M_CPL_STATUS)
+
+#define S_INJECT_TIMER    6
+#define V_INJECT_TIMER(x) ((x) << S_INJECT_TIMER)
+#define F_INJECT_TIMER    V_INJECT_TIMER(1U)
+
+#define S_NO_OFFLOAD    7
+#define V_NO_OFFLOAD(x) ((x) << S_NO_OFFLOAD)
+#define F_NO_OFFLOAD    V_NO_OFFLOAD(1U)
+
+#define S_ULP_MODE    8
+#define M_ULP_MODE    0xF
+#define V_ULP_MODE(x) ((x) << S_ULP_MODE)
+#define G_ULP_MODE(x) (((x) >> S_ULP_MODE) & M_ULP_MODE)
+
+#define S_RCV_BUFSIZ    12
+#define M_RCV_BUFSIZ    0x3FFF
+#define V_RCV_BUFSIZ(x) ((x) << S_RCV_BUFSIZ)
+#define G_RCV_BUFSIZ(x) (((x) >> S_RCV_BUFSIZ) & M_RCV_BUFSIZ)
+
+#define S_TOS    26
+#define M_TOS    0x3F
+#define V_TOS(x) ((x) << S_TOS)
+#define G_TOS(x) (((x) >> S_TOS) & M_TOS)
+
+/* option 0 upper-half fields */
+#define S_DELACK    0
+#define V_DELACK(x) ((x) << S_DELACK)
+#define F_DELACK    V_DELACK(1U)
+
+#define S_NO_CONG    1
+#define V_NO_CONG(x) ((x) << S_NO_CONG)
+#define F_NO_CONG    V_NO_CONG(1U)
+
+#define S_SRC_MAC_SEL    2
+#define M_SRC_MAC_SEL    0x3
+#define V_SRC_MAC_SEL(x) ((x) << S_SRC_MAC_SEL)
+#define G_SRC_MAC_SEL(x) (((x) >> S_SRC_MAC_SEL) & M_SRC_MAC_SEL)
+
+#define S_L2T_IDX    4
+#define M_L2T_IDX    0x7FF
+#define V_L2T_IDX(x) ((x) << S_L2T_IDX)
+#define G_L2T_IDX(x) (((x) >> S_L2T_IDX) & M_L2T_IDX)
+
+#define S_TX_CHANNEL    15
+#define V_TX_CHANNEL(x) ((x) << S_TX_CHANNEL)
+#define F_TX_CHANNEL    V_TX_CHANNEL(1U)
+
+#define S_TCAM_BYPASS    16
+#define V_TCAM_BYPASS(x) ((x) << S_TCAM_BYPASS)
+#define F_TCAM_BYPASS    V_TCAM_BYPASS(1U)
+
+#define S_NAGLE    17
+#define V_NAGLE(x) ((x) << S_NAGLE)
+#define F_NAGLE    V_NAGLE(1U)
+
+#define S_WND_SCALE    18
+#define M_WND_SCALE    0xF
+#define V_WND_SCALE(x) ((x) << S_WND_SCALE)
+#define G_WND_SCALE(x) (((x) >> S_WND_SCALE) & M_WND_SCALE)
+
+#define S_KEEP_ALIVE    22
+#define V_KEEP_ALIVE(x) ((x) << S_KEEP_ALIVE)
+#define F_KEEP_ALIVE    V_KEEP_ALIVE(1U)
+
+#define S_MAX_RETRANS    23
+#define M_MAX_RETRANS    0xF
+#define V_MAX_RETRANS(x) ((x) << S_MAX_RETRANS)
+#define G_MAX_RETRANS(x) (((x) >> S_MAX_RETRANS) & M_MAX_RETRANS)
+
+#define S_MAX_RETRANS_OVERRIDE    27
+#define V_MAX_RETRANS_OVERRIDE(x) ((x) << S_MAX_RETRANS_OVERRIDE)
+#define F_MAX_RETRANS_OVERRIDE    V_MAX_RETRANS_OVERRIDE(1U)
+
+#define S_MSS_IDX    28
+#define M_MSS_IDX    0xF
+#define V_MSS_IDX(x) ((x) << S_MSS_IDX)
+#define G_MSS_IDX(x) (((x) >> S_MSS_IDX) & M_MSS_IDX)
+
+/* option 1 fields */
+#define S_RSS_ENABLE    0
+#define V_RSS_ENABLE(x) ((x) << S_RSS_ENABLE)
+#define F_RSS_ENABLE    V_RSS_ENABLE(1U)
+
+#define S_RSS_MASK_LEN    1
+#define M_RSS_MASK_LEN    0x7
+#define V_RSS_MASK_LEN(x) ((x) << S_RSS_MASK_LEN)
+#define G_RSS_MASK_LEN(x) (((x) >> S_RSS_MASK_LEN) & M_RSS_MASK_LEN)
+
+#define S_CPU_IDX    4
+#define M_CPU_IDX    0x3F
+#define V_CPU_IDX(x) ((x) << S_CPU_IDX)
+#define G_CPU_IDX(x) (((x) >> S_CPU_IDX) & M_CPU_IDX)
+
+#define S_MAC_MATCH_VALID    18
+#define V_MAC_MATCH_VALID(x) ((x) << S_MAC_MATCH_VALID)
+#define F_MAC_MATCH_VALID    V_MAC_MATCH_VALID(1U)
+
+#define S_CONN_POLICY    19
+#define M_CONN_POLICY    0x3
+#define V_CONN_POLICY(x) ((x) << S_CONN_POLICY)
+#define G_CONN_POLICY(x) (((x) >> S_CONN_POLICY) & M_CONN_POLICY)
+
+#define S_SYN_DEFENSE    21
+#define V_SYN_DEFENSE(x) ((x) << S_SYN_DEFENSE)
+#define F_SYN_DEFENSE    V_SYN_DEFENSE(1U)
+
+#define S_VLAN_PRI    22
+#define M_VLAN_PRI    0x3
+#define V_VLAN_PRI(x) ((x) << S_VLAN_PRI)
+#define G_VLAN_PRI(x) (((x) >> S_VLAN_PRI) & M_VLAN_PRI)
+
+#define S_VLAN_PRI_VALID    24
+#define V_VLAN_PRI_VALID(x) ((x) << S_VLAN_PRI_VALID)
+#define F_VLAN_PRI_VALID    V_VLAN_PRI_VALID(1U)
+
+#define S_PKT_TYPE    25
+#define M_PKT_TYPE    0x3
+#define V_PKT_TYPE(x) ((x) << S_PKT_TYPE)
+#define G_PKT_TYPE(x) (((x) >> S_PKT_TYPE) & M_PKT_TYPE)
+
+#define S_MAC_MATCH    27
+#define M_MAC_MATCH    0x1F
+#define V_MAC_MATCH(x) ((x) << S_MAC_MATCH)
+#define G_MAC_MATCH(x) (((x) >> S_MAC_MATCH) & M_MAC_MATCH)
+
+/* option 2 fields */
+#define S_CPU_INDEX    0
+#define M_CPU_INDEX    0x7F
+#define V_CPU_INDEX(x) ((x) << S_CPU_INDEX)
+#define G_CPU_INDEX(x) (((x) >> S_CPU_INDEX) & M_CPU_INDEX)
+
+#define S_CPU_INDEX_VALID    7
+#define V_CPU_INDEX_VALID(x) ((x) << S_CPU_INDEX_VALID)
+#define F_CPU_INDEX_VALID    V_CPU_INDEX_VALID(1U)
+
+#define S_RX_COALESCE    8
+#define M_RX_COALESCE    0x3
+#define V_RX_COALESCE(x) ((x) << S_RX_COALESCE)
+#define G_RX_COALESCE(x) (((x) >> S_RX_COALESCE) & M_RX_COALESCE)
+
+#define S_RX_COALESCE_VALID    10
+#define V_RX_COALESCE_VALID(x) ((x) << S_RX_COALESCE_VALID)
+#define F_RX_COALESCE_VALID    V_RX_COALESCE_VALID(1U)
+
+#define S_CONG_CONTROL_FLAVOR    11
+#define M_CONG_CONTROL_FLAVOR    0x3
+#define V_CONG_CONTROL_FLAVOR(x) ((x) << S_CONG_CONTROL_FLAVOR)
+#define G_CONG_CONTROL_FLAVOR(x) (((x) >> S_CONG_CONTROL_FLAVOR) & M_CONG_CONTROL_FLAVOR)
+
+#define S_PACING_FLAVOR    13
+#define M_PACING_FLAVOR    0x3
+#define V_PACING_FLAVOR(x) ((x) << S_PACING_FLAVOR)
+#define G_PACING_FLAVOR(x) (((x) >> S_PACING_FLAVOR) & M_PACING_FLAVOR)
+
+#define S_FLAVORS_VALID    15
+#define V_FLAVORS_VALID(x) ((x) << S_FLAVORS_VALID)
+#define F_FLAVORS_VALID    V_FLAVORS_VALID(1U)
+
+#define S_RX_FC_DISABLE    16
+#define V_RX_FC_DISABLE(x) ((x) << S_RX_FC_DISABLE)
+#define F_RX_FC_DISABLE    V_RX_FC_DISABLE(1U)
+
+#define S_RX_FC_VALID    17
+#define V_RX_FC_VALID(x) ((x) << S_RX_FC_VALID)
+#define F_RX_FC_VALID    V_RX_FC_VALID(1U)
+
+struct cpl_pass_open_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __be16 local_port;
+       __be16 peer_port;
+       __be32 local_ip;
+       __be32 peer_ip;
+       __be32 opt0h;
+       __be32 opt0l;
+       __be32 peer_netmask;
+       __be32 opt1;
+};
+
+struct cpl_pass_open_rpl {
+       RSS_HDR union opcode_tid ot;
+       __be16 local_port;
+       __be16 peer_port;
+       __be32 local_ip;
+       __be32 peer_ip;
+       __u8 resvd[7];
+       __u8 status;
+};
+
+struct cpl_pass_establish {
+       RSS_HDR union opcode_tid ot;
+       __be16 local_port;
+       __be16 peer_port;
+       __be32 local_ip;
+       __be32 peer_ip;
+       __be32 tos_tid;
+       __be16 l2t_idx;
+       __be16 tcp_opt;
+       __be32 snd_isn;
+       __be32 rcv_isn;
+};
+
+/* cpl_pass_establish.tos_tid fields */
+#define S_PASS_OPEN_TID    0
+#define M_PASS_OPEN_TID    0xFFFFFF
+#define V_PASS_OPEN_TID(x) ((x) << S_PASS_OPEN_TID)
+#define G_PASS_OPEN_TID(x) (((x) >> S_PASS_OPEN_TID) & M_PASS_OPEN_TID)
+
+#define S_PASS_OPEN_TOS    24
+#define M_PASS_OPEN_TOS    0xFF
+#define V_PASS_OPEN_TOS(x) ((x) << S_PASS_OPEN_TOS)
+#define G_PASS_OPEN_TOS(x) (((x) >> S_PASS_OPEN_TOS) & M_PASS_OPEN_TOS)
+
+/* cpl_pass_establish.l2t_idx fields */
+#define S_L2T_IDX16    5
+#define M_L2T_IDX16    0x7FF
+#define V_L2T_IDX16(x) ((x) << S_L2T_IDX16)
+#define G_L2T_IDX16(x) (((x) >> S_L2T_IDX16) & M_L2T_IDX16)
+
+/* cpl_pass_establish.tcp_opt fields (also applies act_open_establish) */
+#define G_TCPOPT_WSCALE_OK(x)  (((x) >> 5) & 1)
+#define G_TCPOPT_SACK(x)       (((x) >> 6) & 1)
+#define G_TCPOPT_TSTAMP(x)     (((x) >> 7) & 1)
+#define G_TCPOPT_SND_WSCALE(x) (((x) >> 8) & 0xf)
+#define G_TCPOPT_MSS(x)        (((x) >> 12) & 0xf)
+
+struct cpl_pass_accept_req {
+       RSS_HDR union opcode_tid ot;
+       __be16 local_port;
+       __be16 peer_port;
+       __be32 local_ip;
+       __be32 peer_ip;
+       __be32 tos_tid;
+       struct tcp_options tcp_options;
+       __u8 dst_mac[6];
+       __be16 vlan_tag;
+       __u8 src_mac[6];
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+        __u8:3;
+       __u8 addr_idx:3;
+       __u8 port_idx:1;
+       __u8 exact_match:1;
+#else
+       __u8 exact_match:1;
+       __u8 port_idx:1;
+       __u8 addr_idx:3;
+        __u8:3;
+#endif
+       __u8 rsvd;
+       __be32 rcv_isn;
+       __be32 rsvd2;
+};
+
+struct cpl_pass_accept_rpl {
+       WR_HDR;
+       union opcode_tid ot;
+       __be32 opt2;
+       __be32 rsvd;
+       __be32 peer_ip;
+       __be32 opt0h;
+       __be32 opt0l_status;
+};
+
+struct cpl_act_open_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __be16 local_port;
+       __be16 peer_port;
+       __be32 local_ip;
+       __be32 peer_ip;
+       __be32 opt0h;
+       __be32 opt0l;
+       __be32 params;
+       __be32 opt2;
+};
+
+/* cpl_act_open_req.params fields */
+#define S_AOPEN_VLAN_PRI    9
+#define M_AOPEN_VLAN_PRI    0x3
+#define V_AOPEN_VLAN_PRI(x) ((x) << S_AOPEN_VLAN_PRI)
+#define G_AOPEN_VLAN_PRI(x) (((x) >> S_AOPEN_VLAN_PRI) & M_AOPEN_VLAN_PRI)
+
+#define S_AOPEN_VLAN_PRI_VALID    11
+#define V_AOPEN_VLAN_PRI_VALID(x) ((x) << S_AOPEN_VLAN_PRI_VALID)
+#define F_AOPEN_VLAN_PRI_VALID    V_AOPEN_VLAN_PRI_VALID(1U)
+
+#define S_AOPEN_PKT_TYPE    12
+#define M_AOPEN_PKT_TYPE    0x3
+#define V_AOPEN_PKT_TYPE(x) ((x) << S_AOPEN_PKT_TYPE)
+#define G_AOPEN_PKT_TYPE(x) (((x) >> S_AOPEN_PKT_TYPE) & M_AOPEN_PKT_TYPE)
+
+#define S_AOPEN_MAC_MATCH    14
+#define M_AOPEN_MAC_MATCH    0x1F
+#define V_AOPEN_MAC_MATCH(x) ((x) << S_AOPEN_MAC_MATCH)
+#define G_AOPEN_MAC_MATCH(x) (((x) >> S_AOPEN_MAC_MATCH) & M_AOPEN_MAC_MATCH)
+
+#define S_AOPEN_MAC_MATCH_VALID    19
+#define V_AOPEN_MAC_MATCH_VALID(x) ((x) << S_AOPEN_MAC_MATCH_VALID)
+#define F_AOPEN_MAC_MATCH_VALID    V_AOPEN_MAC_MATCH_VALID(1U)
+
+#define S_AOPEN_IFF_VLAN    20
+#define M_AOPEN_IFF_VLAN    0xFFF
+#define V_AOPEN_IFF_VLAN(x) ((x) << S_AOPEN_IFF_VLAN)
+#define G_AOPEN_IFF_VLAN(x) (((x) >> S_AOPEN_IFF_VLAN) & M_AOPEN_IFF_VLAN)
+
+struct cpl_act_open_rpl {
+       RSS_HDR union opcode_tid ot;
+       __be16 local_port;
+       __be16 peer_port;
+       __be32 local_ip;
+       __be32 peer_ip;
+       __be32 atid;
+       __u8 rsvd[3];
+       __u8 status;
+};
+
+struct cpl_act_establish {
+       RSS_HDR union opcode_tid ot;
+       __be16 local_port;
+       __be16 peer_port;
+       __be32 local_ip;
+       __be32 peer_ip;
+       __be32 tos_tid;
+       __be16 l2t_idx;
+       __be16 tcp_opt;
+       __be32 snd_isn;
+       __be32 rcv_isn;
+};
+
+struct cpl_get_tcb {
+       WR_HDR;
+       union opcode_tid ot;
+       __be16 cpuno;
+       __be16 rsvd;
+};
+
+struct cpl_get_tcb_rpl {
+       RSS_HDR union opcode_tid ot;
+       __u8 rsvd;
+       __u8 status;
+       __be16 len;
+};
+
+struct cpl_set_tcb {
+       WR_HDR;
+       union opcode_tid ot;
+       __u8 reply;
+       __u8 cpu_idx;
+       __be16 len;
+};
+
+/* cpl_set_tcb.reply fields */
+#define S_NO_REPLY    7
+#define V_NO_REPLY(x) ((x) << S_NO_REPLY)
+#define F_NO_REPLY    V_NO_REPLY(1U)
+
+struct cpl_set_tcb_field {
+       WR_HDR;
+       union opcode_tid ot;
+       __u8 reply;
+       __u8 cpu_idx;
+       __be16 word;
+       __be64 mask;
+       __be64 val;
+};
+
+struct cpl_set_tcb_rpl {
+       RSS_HDR union opcode_tid ot;
+       __u8 rsvd[3];
+       __u8 status;
+};
+
+struct cpl_pcmd {
+       WR_HDR;
+       union opcode_tid ot;
+       __u8 rsvd[3];
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8 src:1;
+       __u8 bundle:1;
+       __u8 channel:1;
+        __u8:5;
+#else
+        __u8:5;
+       __u8 channel:1;
+       __u8 bundle:1;
+       __u8 src:1;
+#endif
+       __be32 pcmd_parm[2];
+};
+
+struct cpl_pcmd_reply {
+       RSS_HDR union opcode_tid ot;
+       __u8 status;
+       __u8 rsvd;
+       __be16 len;
+};
+
+struct cpl_close_con_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __be32 rsvd;
+};
+
+struct cpl_close_con_rpl {
+       RSS_HDR union opcode_tid ot;
+       __u8 rsvd[3];
+       __u8 status;
+       __be32 snd_nxt;
+       __be32 rcv_nxt;
+};
+
+struct cpl_close_listserv_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __u8 rsvd0;
+       __u8 cpu_idx;
+       __be16 rsvd1;
+};
+
+struct cpl_close_listserv_rpl {
+       RSS_HDR union opcode_tid ot;
+       __u8 rsvd[3];
+       __u8 status;
+};
+
+struct cpl_abort_req_rss {
+       RSS_HDR union opcode_tid ot;
+       __be32 rsvd0;
+       __u8 rsvd1;
+       __u8 status;
+       __u8 rsvd2[6];
+};
+
+struct cpl_abort_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __be32 rsvd0;
+       __u8 rsvd1;
+       __u8 cmd;
+       __u8 rsvd2[6];
+};
+
+struct cpl_abort_rpl_rss {
+       RSS_HDR union opcode_tid ot;
+       __be32 rsvd0;
+       __u8 rsvd1;
+       __u8 status;
+       __u8 rsvd2[6];
+};
+
+struct cpl_abort_rpl {
+       WR_HDR;
+       union opcode_tid ot;
+       __be32 rsvd0;
+       __u8 rsvd1;
+       __u8 cmd;
+       __u8 rsvd2[6];
+};
+
+struct cpl_peer_close {
+       RSS_HDR union opcode_tid ot;
+       __be32 rcv_nxt;
+};
+
+struct tx_data_wr {
+       __be32 wr_hi;
+       __be32 wr_lo;
+       __be32 len;
+       __be32 flags;
+       __be32 sndseq;
+       __be32 param;
+};
+
+/* tx_data_wr.param fields */
+#define S_TX_PORT    0
+#define M_TX_PORT    0x7
+#define V_TX_PORT(x) ((x) << S_TX_PORT)
+#define G_TX_PORT(x) (((x) >> S_TX_PORT) & M_TX_PORT)
+
+#define S_TX_MSS    4
+#define M_TX_MSS    0xF
+#define V_TX_MSS(x) ((x) << S_TX_MSS)
+#define G_TX_MSS(x) (((x) >> S_TX_MSS) & M_TX_MSS)
+
+#define S_TX_QOS    8
+#define M_TX_QOS    0xFF
+#define V_TX_QOS(x) ((x) << S_TX_QOS)
+#define G_TX_QOS(x) (((x) >> S_TX_QOS) & M_TX_QOS)
+
+#define S_TX_SNDBUF 16
+#define M_TX_SNDBUF 0xFFFF
+#define V_TX_SNDBUF(x) ((x) << S_TX_SNDBUF)
+#define G_TX_SNDBUF(x) (((x) >> S_TX_SNDBUF) & M_TX_SNDBUF)
+
+struct cpl_tx_data {
+       union opcode_tid ot;
+       __be32 len;
+       __be32 rsvd;
+       __be16 urg;
+       __be16 flags;
+};
+
+/* cpl_tx_data.flags fields */
+#define S_TX_ULP_SUBMODE    6
+#define M_TX_ULP_SUBMODE    0xF
+#define V_TX_ULP_SUBMODE(x) ((x) << S_TX_ULP_SUBMODE)
+#define G_TX_ULP_SUBMODE(x) (((x) >> S_TX_ULP_SUBMODE) & M_TX_ULP_SUBMODE)
+
+#define S_TX_ULP_MODE    10
+#define M_TX_ULP_MODE    0xF
+#define V_TX_ULP_MODE(x) ((x) << S_TX_ULP_MODE)
+#define G_TX_ULP_MODE(x) (((x) >> S_TX_ULP_MODE) & M_TX_ULP_MODE)
+
+#define S_TX_SHOVE    14
+#define V_TX_SHOVE(x) ((x) << S_TX_SHOVE)
+#define F_TX_SHOVE    V_TX_SHOVE(1U)
+
+#define S_TX_MORE    15
+#define V_TX_MORE(x) ((x) << S_TX_MORE)
+#define F_TX_MORE    V_TX_MORE(1U)
+
+/* additional tx_data_wr.flags fields */
+#define S_TX_CPU_IDX    0
+#define M_TX_CPU_IDX    0x3F
+#define V_TX_CPU_IDX(x) ((x) << S_TX_CPU_IDX)
+#define G_TX_CPU_IDX(x) (((x) >> S_TX_CPU_IDX) & M_TX_CPU_IDX)
+
+#define S_TX_URG    16
+#define V_TX_URG(x) ((x) << S_TX_URG)
+#define F_TX_URG    V_TX_URG(1U)
+
+#define S_TX_CLOSE    17
+#define V_TX_CLOSE(x) ((x) << S_TX_CLOSE)
+#define F_TX_CLOSE    V_TX_CLOSE(1U)
+
+#define S_TX_INIT    18
+#define V_TX_INIT(x) ((x) << S_TX_INIT)
+#define F_TX_INIT    V_TX_INIT(1U)
+
+#define S_TX_IMM_ACK    19
+#define V_TX_IMM_ACK(x) ((x) << S_TX_IMM_ACK)
+#define F_TX_IMM_ACK    V_TX_IMM_ACK(1U)
+
+#define S_TX_IMM_DMA    20
+#define V_TX_IMM_DMA(x) ((x) << S_TX_IMM_DMA)
+#define F_TX_IMM_DMA    V_TX_IMM_DMA(1U)
+
+struct cpl_tx_data_ack {
+       RSS_HDR union opcode_tid ot;
+       __be32 ack_seq;
+};
+
+struct cpl_wr_ack {
+       RSS_HDR union opcode_tid ot;
+       __be16 credits;
+       __be16 rsvd;
+       __be32 snd_nxt;
+       __be32 snd_una;
+};
+
+struct cpl_rdma_ec_status {
+       RSS_HDR union opcode_tid ot;
+       __u8 rsvd[3];
+       __u8 status;
+};
+
+struct mngt_pktsched_wr {
+       __be32 wr_hi;
+       __be32 wr_lo;
+       __u8 mngt_opcode;
+       __u8 rsvd[7];
+       __u8 sched;
+       __u8 idx;
+       __u8 min;
+       __u8 max;
+       __u8 binding;
+       __u8 rsvd1[3];
+};
+
+struct cpl_iscsi_hdr {
+       RSS_HDR union opcode_tid ot;
+       __be16 pdu_len_ddp;
+       __be16 len;
+       __be32 seq;
+       __be16 urg;
+       __u8 rsvd;
+       __u8 status;
+};
+
+/* cpl_iscsi_hdr.pdu_len_ddp fields */
+#define S_ISCSI_PDU_LEN    0
+#define M_ISCSI_PDU_LEN    0x7FFF
+#define V_ISCSI_PDU_LEN(x) ((x) << S_ISCSI_PDU_LEN)
+#define G_ISCSI_PDU_LEN(x) (((x) >> S_ISCSI_PDU_LEN) & M_ISCSI_PDU_LEN)
+
+#define S_ISCSI_DDP    15
+#define V_ISCSI_DDP(x) ((x) << S_ISCSI_DDP)
+#define F_ISCSI_DDP    V_ISCSI_DDP(1U)
+
+struct cpl_rx_data {
+       RSS_HDR union opcode_tid ot;
+       __be16 rsvd;
+       __be16 len;
+       __be32 seq;
+       __be16 urg;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8 dack_mode:2;
+       __u8 psh:1;
+       __u8 heartbeat:1;
+        __u8:4;
+#else
+        __u8:4;
+       __u8 heartbeat:1;
+       __u8 psh:1;
+       __u8 dack_mode:2;
+#endif
+       __u8 status;
+};
+
+struct cpl_rx_data_ack {
+       WR_HDR;
+       union opcode_tid ot;
+       __be32 credit_dack;
+};
+
+/* cpl_rx_data_ack.ack_seq fields */
+#define S_RX_CREDITS    0
+#define M_RX_CREDITS    0x7FFFFFF
+#define V_RX_CREDITS(x) ((x) << S_RX_CREDITS)
+#define G_RX_CREDITS(x) (((x) >> S_RX_CREDITS) & M_RX_CREDITS)
+
+#define S_RX_MODULATE    27
+#define V_RX_MODULATE(x) ((x) << S_RX_MODULATE)
+#define F_RX_MODULATE    V_RX_MODULATE(1U)
+
+#define S_RX_FORCE_ACK    28
+#define V_RX_FORCE_ACK(x) ((x) << S_RX_FORCE_ACK)
+#define F_RX_FORCE_ACK    V_RX_FORCE_ACK(1U)
+
+#define S_RX_DACK_MODE    29
+#define M_RX_DACK_MODE    0x3
+#define V_RX_DACK_MODE(x) ((x) << S_RX_DACK_MODE)
+#define G_RX_DACK_MODE(x) (((x) >> S_RX_DACK_MODE) & M_RX_DACK_MODE)
+
+#define S_RX_DACK_CHANGE    31
+#define V_RX_DACK_CHANGE(x) ((x) << S_RX_DACK_CHANGE)
+#define F_RX_DACK_CHANGE    V_RX_DACK_CHANGE(1U)
+
+struct cpl_rx_urg_notify {
+       RSS_HDR union opcode_tid ot;
+       __be32 seq;
+};
+
+struct cpl_rx_ddp_complete {
+       RSS_HDR union opcode_tid ot;
+       __be32 ddp_report;
+};
+
+struct cpl_rx_data_ddp {
+       RSS_HDR union opcode_tid ot;
+       __be16 urg;
+       __be16 len;
+       __be32 seq;
+       union {
+               __be32 nxt_seq;
+               __be32 ddp_report;
+       };
+       __be32 ulp_crc;
+       __be32 ddpvld_status;
+};
+
+/* cpl_rx_data_ddp.ddpvld_status fields */
+#define S_DDP_STATUS    0
+#define M_DDP_STATUS    0xFF
+#define V_DDP_STATUS(x) ((x) << S_DDP_STATUS)
+#define G_DDP_STATUS(x) (((x) >> S_DDP_STATUS) & M_DDP_STATUS)
+
+#define S_DDP_VALID    15
+#define M_DDP_VALID    0x1FFFF
+#define V_DDP_VALID(x) ((x) << S_DDP_VALID)
+#define G_DDP_VALID(x) (((x) >> S_DDP_VALID) & M_DDP_VALID)
+
+#define S_DDP_PPOD_MISMATCH    15
+#define V_DDP_PPOD_MISMATCH(x) ((x) << S_DDP_PPOD_MISMATCH)
+#define F_DDP_PPOD_MISMATCH    V_DDP_PPOD_MISMATCH(1U)
+
+#define S_DDP_PDU    16
+#define V_DDP_PDU(x) ((x) << S_DDP_PDU)
+#define F_DDP_PDU    V_DDP_PDU(1U)
+
+#define S_DDP_LLIMIT_ERR    17
+#define V_DDP_LLIMIT_ERR(x) ((x) << S_DDP_LLIMIT_ERR)
+#define F_DDP_LLIMIT_ERR    V_DDP_LLIMIT_ERR(1U)
+
+#define S_DDP_PPOD_PARITY_ERR    18
+#define V_DDP_PPOD_PARITY_ERR(x) ((x) << S_DDP_PPOD_PARITY_ERR)
+#define F_DDP_PPOD_PARITY_ERR    V_DDP_PPOD_PARITY_ERR(1U)
+
+#define S_DDP_PADDING_ERR    19
+#define V_DDP_PADDING_ERR(x) ((x) << S_DDP_PADDING_ERR)
+#define F_DDP_PADDING_ERR    V_DDP_PADDING_ERR(1U)
+
+#define S_DDP_HDRCRC_ERR    20
+#define V_DDP_HDRCRC_ERR(x) ((x) << S_DDP_HDRCRC_ERR)
+#define F_DDP_HDRCRC_ERR    V_DDP_HDRCRC_ERR(1U)
+
+#define S_DDP_DATACRC_ERR    21
+#define V_DDP_DATACRC_ERR(x) ((x) << S_DDP_DATACRC_ERR)
+#define F_DDP_DATACRC_ERR    V_DDP_DATACRC_ERR(1U)
+
+#define S_DDP_INVALID_TAG    22
+#define V_DDP_INVALID_TAG(x) ((x) << S_DDP_INVALID_TAG)
+#define F_DDP_INVALID_TAG    V_DDP_INVALID_TAG(1U)
+
+#define S_DDP_ULIMIT_ERR    23
+#define V_DDP_ULIMIT_ERR(x) ((x) << S_DDP_ULIMIT_ERR)
+#define F_DDP_ULIMIT_ERR    V_DDP_ULIMIT_ERR(1U)
+
+#define S_DDP_OFFSET_ERR    24
+#define V_DDP_OFFSET_ERR(x) ((x) << S_DDP_OFFSET_ERR)
+#define F_DDP_OFFSET_ERR    V_DDP_OFFSET_ERR(1U)
+
+#define S_DDP_COLOR_ERR    25
+#define V_DDP_COLOR_ERR(x) ((x) << S_DDP_COLOR_ERR)
+#define F_DDP_COLOR_ERR    V_DDP_COLOR_ERR(1U)
+
+#define S_DDP_TID_MISMATCH    26
+#define V_DDP_TID_MISMATCH(x) ((x) << S_DDP_TID_MISMATCH)
+#define F_DDP_TID_MISMATCH    V_DDP_TID_MISMATCH(1U)
+
+#define S_DDP_INVALID_PPOD    27
+#define V_DDP_INVALID_PPOD(x) ((x) << S_DDP_INVALID_PPOD)
+#define F_DDP_INVALID_PPOD    V_DDP_INVALID_PPOD(1U)
+
+#define S_DDP_ULP_MODE    28
+#define M_DDP_ULP_MODE    0xF
+#define V_DDP_ULP_MODE(x) ((x) << S_DDP_ULP_MODE)
+#define G_DDP_ULP_MODE(x) (((x) >> S_DDP_ULP_MODE) & M_DDP_ULP_MODE)
+
+/* cpl_rx_data_ddp.ddp_report fields */
+#define S_DDP_OFFSET    0
+#define M_DDP_OFFSET    0x3FFFFF
+#define V_DDP_OFFSET(x) ((x) << S_DDP_OFFSET)
+#define G_DDP_OFFSET(x) (((x) >> S_DDP_OFFSET) & M_DDP_OFFSET)
+
+#define S_DDP_URG    24
+#define V_DDP_URG(x) ((x) << S_DDP_URG)
+#define F_DDP_URG    V_DDP_URG(1U)
+
+#define S_DDP_PSH    25
+#define V_DDP_PSH(x) ((x) << S_DDP_PSH)
+#define F_DDP_PSH    V_DDP_PSH(1U)
+
+#define S_DDP_BUF_COMPLETE    26
+#define V_DDP_BUF_COMPLETE(x) ((x) << S_DDP_BUF_COMPLETE)
+#define F_DDP_BUF_COMPLETE    V_DDP_BUF_COMPLETE(1U)
+
+#define S_DDP_BUF_TIMED_OUT    27
+#define V_DDP_BUF_TIMED_OUT(x) ((x) << S_DDP_BUF_TIMED_OUT)
+#define F_DDP_BUF_TIMED_OUT    V_DDP_BUF_TIMED_OUT(1U)
+
+#define S_DDP_BUF_IDX    28
+#define V_DDP_BUF_IDX(x) ((x) << S_DDP_BUF_IDX)
+#define F_DDP_BUF_IDX    V_DDP_BUF_IDX(1U)
+
+struct cpl_tx_pkt {
+       WR_HDR;
+       __be32 cntrl;
+       __be32 len;
+};
+
+struct cpl_tx_pkt_lso {
+       WR_HDR;
+       __be32 cntrl;
+       __be32 len;
+
+       __be32 rsvd;
+       __be32 lso_info;
+};
+
+/* cpl_tx_pkt*.cntrl fields */
+#define S_TXPKT_VLAN    0
+#define M_TXPKT_VLAN    0xFFFF
+#define V_TXPKT_VLAN(x) ((x) << S_TXPKT_VLAN)
+#define G_TXPKT_VLAN(x) (((x) >> S_TXPKT_VLAN) & M_TXPKT_VLAN)
+
+#define S_TXPKT_INTF    16
+#define M_TXPKT_INTF    0xF
+#define V_TXPKT_INTF(x) ((x) << S_TXPKT_INTF)
+#define G_TXPKT_INTF(x) (((x) >> S_TXPKT_INTF) & M_TXPKT_INTF)
+
+#define S_TXPKT_IPCSUM_DIS    20
+#define V_TXPKT_IPCSUM_DIS(x) ((x) << S_TXPKT_IPCSUM_DIS)
+#define F_TXPKT_IPCSUM_DIS    V_TXPKT_IPCSUM_DIS(1U)
+
+#define S_TXPKT_L4CSUM_DIS    21
+#define V_TXPKT_L4CSUM_DIS(x) ((x) << S_TXPKT_L4CSUM_DIS)
+#define F_TXPKT_L4CSUM_DIS    V_TXPKT_L4CSUM_DIS(1U)
+
+#define S_TXPKT_VLAN_VLD    22
+#define V_TXPKT_VLAN_VLD(x) ((x) << S_TXPKT_VLAN_VLD)
+#define F_TXPKT_VLAN_VLD    V_TXPKT_VLAN_VLD(1U)
+
+#define S_TXPKT_LOOPBACK    23
+#define V_TXPKT_LOOPBACK(x) ((x) << S_TXPKT_LOOPBACK)
+#define F_TXPKT_LOOPBACK    V_TXPKT_LOOPBACK(1U)
+
+#define S_TXPKT_OPCODE    24
+#define M_TXPKT_OPCODE    0xFF
+#define V_TXPKT_OPCODE(x) ((x) << S_TXPKT_OPCODE)
+#define G_TXPKT_OPCODE(x) (((x) >> S_TXPKT_OPCODE) & M_TXPKT_OPCODE)
+
+/* cpl_tx_pkt_lso.lso_info fields */
+#define S_LSO_MSS    0
+#define M_LSO_MSS    0x3FFF
+#define V_LSO_MSS(x) ((x) << S_LSO_MSS)
+#define G_LSO_MSS(x) (((x) >> S_LSO_MSS) & M_LSO_MSS)
+
+#define S_LSO_ETH_TYPE    14
+#define M_LSO_ETH_TYPE    0x3
+#define V_LSO_ETH_TYPE(x) ((x) << S_LSO_ETH_TYPE)
+#define G_LSO_ETH_TYPE(x) (((x) >> S_LSO_ETH_TYPE) & M_LSO_ETH_TYPE)
+
+#define S_LSO_TCPHDR_WORDS    16
+#define M_LSO_TCPHDR_WORDS    0xF
+#define V_LSO_TCPHDR_WORDS(x) ((x) << S_LSO_TCPHDR_WORDS)
+#define G_LSO_TCPHDR_WORDS(x) (((x) >> S_LSO_TCPHDR_WORDS) & M_LSO_TCPHDR_WORDS)
+
+#define S_LSO_IPHDR_WORDS    20
+#define M_LSO_IPHDR_WORDS    0xF
+#define V_LSO_IPHDR_WORDS(x) ((x) << S_LSO_IPHDR_WORDS)
+#define G_LSO_IPHDR_WORDS(x) (((x) >> S_LSO_IPHDR_WORDS) & M_LSO_IPHDR_WORDS)
+
+#define S_LSO_IPV6    24
+#define V_LSO_IPV6(x) ((x) << S_LSO_IPV6)
+#define F_LSO_IPV6    V_LSO_IPV6(1U)
+
+struct cpl_trace_pkt {
+#ifdef CHELSIO_FW
+       __u8 rss_opcode;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8 err:1;
+        __u8:7;
+#else
+        __u8:7;
+       __u8 err:1;
+#endif
+       __u8 rsvd0;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8 qid:4;
+        __u8:4;
+#else
+        __u8:4;
+       __u8 qid:4;
+#endif
+       __be32 tstamp;
+#endif                         /* CHELSIO_FW */
+
+       __u8 opcode;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8 iff:4;
+        __u8:4;
+#else
+        __u8:4;
+       __u8 iff:4;
+#endif
+       __u8 rsvd[4];
+       __be16 len;
+};
+
+struct cpl_rx_pkt {
+       RSS_HDR __u8 opcode;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8 iff:4;
+       __u8 csum_valid:1;
+       __u8 ipmi_pkt:1;
+       __u8 vlan_valid:1;
+       __u8 fragment:1;
+#else
+       __u8 fragment:1;
+       __u8 vlan_valid:1;
+       __u8 ipmi_pkt:1;
+       __u8 csum_valid:1;
+       __u8 iff:4;
+#endif
+       __be16 csum;
+       __be16 vlan;
+       __be16 len;
+};
+
+struct cpl_l2t_write_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __be32 params;
+       __u8 rsvd[2];
+       __u8 dst_mac[6];
+};
+
+/* cpl_l2t_write_req.params fields */
+#define S_L2T_W_IDX    0
+#define M_L2T_W_IDX    0x7FF
+#define V_L2T_W_IDX(x) ((x) << S_L2T_W_IDX)
+#define G_L2T_W_IDX(x) (((x) >> S_L2T_W_IDX) & M_L2T_W_IDX)
+
+#define S_L2T_W_VLAN    11
+#define M_L2T_W_VLAN    0xFFF
+#define V_L2T_W_VLAN(x) ((x) << S_L2T_W_VLAN)
+#define G_L2T_W_VLAN(x) (((x) >> S_L2T_W_VLAN) & M_L2T_W_VLAN)
+
+#define S_L2T_W_IFF    23
+#define M_L2T_W_IFF    0xF
+#define V_L2T_W_IFF(x) ((x) << S_L2T_W_IFF)
+#define G_L2T_W_IFF(x) (((x) >> S_L2T_W_IFF) & M_L2T_W_IFF)
+
+#define S_L2T_W_PRIO    27
+#define M_L2T_W_PRIO    0x7
+#define V_L2T_W_PRIO(x) ((x) << S_L2T_W_PRIO)
+#define G_L2T_W_PRIO(x) (((x) >> S_L2T_W_PRIO) & M_L2T_W_PRIO)
+
+struct cpl_l2t_write_rpl {
+       RSS_HDR union opcode_tid ot;
+       __u8 status;
+       __u8 rsvd[3];
+};
+
+struct cpl_l2t_read_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __be16 rsvd;
+       __be16 l2t_idx;
+};
+
+struct cpl_l2t_read_rpl {
+       RSS_HDR union opcode_tid ot;
+       __be32 params;
+       __u8 rsvd[2];
+       __u8 dst_mac[6];
+};
+
+/* cpl_l2t_read_rpl.params fields */
+#define S_L2T_R_PRIO    0
+#define M_L2T_R_PRIO    0x7
+#define V_L2T_R_PRIO(x) ((x) << S_L2T_R_PRIO)
+#define G_L2T_R_PRIO(x) (((x) >> S_L2T_R_PRIO) & M_L2T_R_PRIO)
+
+#define S_L2T_R_VLAN    8
+#define M_L2T_R_VLAN    0xFFF
+#define V_L2T_R_VLAN(x) ((x) << S_L2T_R_VLAN)
+#define G_L2T_R_VLAN(x) (((x) >> S_L2T_R_VLAN) & M_L2T_R_VLAN)
+
+#define S_L2T_R_IFF    20
+#define M_L2T_R_IFF    0xF
+#define V_L2T_R_IFF(x) ((x) << S_L2T_R_IFF)
+#define G_L2T_R_IFF(x) (((x) >> S_L2T_R_IFF) & M_L2T_R_IFF)
+
+#define S_L2T_STATUS    24
+#define M_L2T_STATUS    0xFF
+#define V_L2T_STATUS(x) ((x) << S_L2T_STATUS)
+#define G_L2T_STATUS(x) (((x) >> S_L2T_STATUS) & M_L2T_STATUS)
+
+struct cpl_smt_write_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __u8 rsvd0;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8 mtu_idx:4;
+       __u8 iff:4;
+#else
+       __u8 iff:4;
+       __u8 mtu_idx:4;
+#endif
+       __be16 rsvd2;
+       __be16 rsvd3;
+       __u8 src_mac1[6];
+       __be16 rsvd4;
+       __u8 src_mac0[6];
+};
+
+struct cpl_smt_write_rpl {
+       RSS_HDR union opcode_tid ot;
+       __u8 status;
+       __u8 rsvd[3];
+};
+
+struct cpl_smt_read_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __u8 rsvd0;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+        __u8:4;
+       __u8 iff:4;
+#else
+       __u8 iff:4;
+        __u8:4;
+#endif
+       __be16 rsvd2;
+};
+
+struct cpl_smt_read_rpl {
+       RSS_HDR union opcode_tid ot;
+       __u8 status;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8 mtu_idx:4;
+        __u8:4;
+#else
+        __u8:4;
+       __u8 mtu_idx:4;
+#endif
+       __be16 rsvd2;
+       __be16 rsvd3;
+       __u8 src_mac1[6];
+       __be16 rsvd4;
+       __u8 src_mac0[6];
+};
+
+struct cpl_rte_delete_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __be32 params;
+};
+
+/* { cpl_rte_delete_req, cpl_rte_read_req }.params fields */
+#define S_RTE_REQ_LUT_IX    8
+#define M_RTE_REQ_LUT_IX    0x7FF
+#define V_RTE_REQ_LUT_IX(x) ((x) << S_RTE_REQ_LUT_IX)
+#define G_RTE_REQ_LUT_IX(x) (((x) >> S_RTE_REQ_LUT_IX) & M_RTE_REQ_LUT_IX)
+
+#define S_RTE_REQ_LUT_BASE    19
+#define M_RTE_REQ_LUT_BASE    0x7FF
+#define V_RTE_REQ_LUT_BASE(x) ((x) << S_RTE_REQ_LUT_BASE)
+#define G_RTE_REQ_LUT_BASE(x) (((x) >> S_RTE_REQ_LUT_BASE) & M_RTE_REQ_LUT_BASE)
+
+#define S_RTE_READ_REQ_SELECT    31
+#define V_RTE_READ_REQ_SELECT(x) ((x) << S_RTE_READ_REQ_SELECT)
+#define F_RTE_READ_REQ_SELECT    V_RTE_READ_REQ_SELECT(1U)
+
+struct cpl_rte_delete_rpl {
+       RSS_HDR union opcode_tid ot;
+       __u8 status;
+       __u8 rsvd[3];
+};
+
+struct cpl_rte_write_req {
+       WR_HDR;
+       union opcode_tid ot;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+        __u8:6;
+       __u8 write_tcam:1;
+       __u8 write_l2t_lut:1;
+#else
+       __u8 write_l2t_lut:1;
+       __u8 write_tcam:1;
+        __u8:6;
+#endif
+       __u8 rsvd[3];
+       __be32 lut_params;
+       __be16 rsvd2;
+       __be16 l2t_idx;
+       __be32 netmask;
+       __be32 faddr;
+};
+
+/* cpl_rte_write_req.lut_params fields */
+#define S_RTE_WRITE_REQ_LUT_IX    10
+#define M_RTE_WRITE_REQ_LUT_IX    0x7FF
+#define V_RTE_WRITE_REQ_LUT_IX(x) ((x) << S_RTE_WRITE_REQ_LUT_IX)
+#define G_RTE_WRITE_REQ_LUT_IX(x) (((x) >> S_RTE_WRITE_REQ_LUT_IX) & M_RTE_WRITE_REQ_LUT_IX)
+
+#define S_RTE_WRITE_REQ_LUT_BASE    21
+#define M_RTE_WRITE_REQ_LUT_BASE    0x7FF
+#define V_RTE_WRITE_REQ_LUT_BASE(x) ((x) << S_RTE_WRITE_REQ_LUT_BASE)
+#define G_RTE_WRITE_REQ_LUT_BASE(x) (((x) >> S_RTE_WRITE_REQ_LUT_BASE) & M_RTE_WRITE_REQ_LUT_BASE)
+
+struct cpl_rte_write_rpl {
+       RSS_HDR union opcode_tid ot;
+       __u8 status;
+       __u8 rsvd[3];
+};
+
+struct cpl_rte_read_req {
+       WR_HDR;
+       union opcode_tid ot;
+       __be32 params;
+};
+
+struct cpl_rte_read_rpl {
+       RSS_HDR union opcode_tid ot;
+       __u8 status;
+       __u8 rsvd0;
+       __be16 l2t_idx;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+        __u8:7;
+       __u8 select:1;
+#else
+       __u8 select:1;
+        __u8:7;
+#endif
+       __u8 rsvd2[3];
+       __be32 addr;
+};
+
+struct cpl_tid_release {
+       WR_HDR;
+       union opcode_tid ot;
+       __be32 rsvd;
+};
+
+struct cpl_barrier {
+       WR_HDR;
+       __u8 opcode;
+       __u8 rsvd[7];
+};
+
+struct cpl_rdma_read_req {
+       __u8 opcode;
+       __u8 rsvd[15];
+};
+
+struct cpl_rdma_terminate {
+#ifdef CHELSIO_FW
+       __u8 opcode;
+       __u8 rsvd[2];
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8 rspq:3;
+        __u8:5;
+#else
+        __u8:5;
+       __u8 rspq:3;
+#endif
+       __be32 tid_len;
+#endif
+       __be32 msn;
+       __be32 mo;
+       __u8 data[0];
+};
+
+/* cpl_rdma_terminate.tid_len fields */
+#define S_FLIT_CNT    0
+#define M_FLIT_CNT    0xFF
+#define V_FLIT_CNT(x) ((x) << S_FLIT_CNT)
+#define G_FLIT_CNT(x) (((x) >> S_FLIT_CNT) & M_FLIT_CNT)
+
+#define S_TERM_TID    8
+#define M_TERM_TID    0xFFFFF
+#define V_TERM_TID(x) ((x) << S_TERM_TID)
+#define G_TERM_TID(x) (((x) >> S_TERM_TID) & M_TERM_TID)
+#endif                         /* T3_CPL_H */
diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
new file mode 100644 (file)
index 0000000..365a7f5
--- /dev/null
@@ -0,0 +1,3375 @@
+/*
+ * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "common.h"
+#include "regs.h"
+#include "sge_defs.h"
+#include "firmware_exports.h"
+
+/**
+ *     t3_wait_op_done_val - wait until an operation is completed
+ *     @adapter: the adapter performing the operation
+ *     @reg: the register to check for completion
+ *     @mask: a single-bit field within @reg that indicates completion
+ *     @polarity: the value of the field when the operation is completed
+ *     @attempts: number of check iterations
+ *     @delay: delay in usecs between iterations
+ *     @valp: where to store the value of the register at completion time
+ *
+ *     Wait until an operation is completed by checking a bit in a register
+ *     up to @attempts times.  If @valp is not NULL the value of the register
+ *     at the time it indicated completion is stored there.  Returns 0 if the
+ *     operation completes and -EAGAIN otherwise.
+ */
+
+int t3_wait_op_done_val(struct adapter *adapter, int reg, u32 mask,
+                       int polarity, int attempts, int delay, u32 *valp)
+{
+       while (1) {
+               u32 val = t3_read_reg(adapter, reg);
+
+               if (!!(val & mask) == polarity) {
+                       if (valp)
+                               *valp = val;
+                       return 0;
+               }
+               if (--attempts == 0)
+                       return -EAGAIN;
+               if (delay)
+                       udelay(delay);
+       }
+}
+
+/**
+ *     t3_write_regs - write a bunch of registers
+ *     @adapter: the adapter to program
+ *     @p: an array of register address/register value pairs
+ *     @n: the number of address/value pairs
+ *     @offset: register address offset
+ *
+ *     Takes an array of register address/register value pairs and writes each
+ *     value to the corresponding register.  Register addresses are adjusted
+ *     by the supplied offset.
+ */
+void t3_write_regs(struct adapter *adapter, const struct addr_val_pair *p,
+                  int n, unsigned int offset)
+{
+       while (n--) {
+               t3_write_reg(adapter, p->reg_addr + offset, p->val);
+               p++;
+       }
+}
+
+/**
+ *     t3_set_reg_field - set a register field to a value
+ *     @adapter: the adapter to program
+ *     @addr: the register address
+ *     @mask: specifies the portion of the register to modify
+ *     @val: the new value for the register field
+ *
+ *     Sets a register field specified by the supplied mask to the
+ *     given value.
+ */
+void t3_set_reg_field(struct adapter *adapter, unsigned int addr, u32 mask,
+                     u32 val)
+{
+       u32 v = t3_read_reg(adapter, addr) & ~mask;
+
+       t3_write_reg(adapter, addr, v | val);
+       t3_read_reg(adapter, addr);     /* flush */
+}
+
+/**
+ *     t3_read_indirect - read indirectly addressed registers
+ *     @adap: the adapter
+ *     @addr_reg: register holding the indirect address
+ *     @data_reg: register holding the value of the indirect register
+ *     @vals: where the read register values are stored
+ *     @start_idx: index of first indirect register to read
+ *     @nregs: how many indirect registers to read
+ *
+ *     Reads registers that are accessed indirectly through an address/data
+ *     register pair.
+ */
+void t3_read_indirect(struct adapter *adap, unsigned int addr_reg,
+                     unsigned int data_reg, u32 *vals, unsigned int nregs,
+                     unsigned int start_idx)
+{
+       while (nregs--) {
+               t3_write_reg(adap, addr_reg, start_idx);
+               *vals++ = t3_read_reg(adap, data_reg);
+               start_idx++;
+       }
+}
+
+/**
+ *     t3_mc7_bd_read - read from MC7 through backdoor accesses
+ *     @mc7: identifies MC7 to read from
+ *     @start: index of first 64-bit word to read
+ *     @n: number of 64-bit words to read
+ *     @buf: where to store the read result
+ *
+ *     Read n 64-bit words from MC7 starting at word start, using backdoor
+ *     accesses.
+ */
+int t3_mc7_bd_read(struct mc7 *mc7, unsigned int start, unsigned int n,
+                  u64 *buf)
+{
+       static const int shift[] = { 0, 0, 16, 24 };
+       static const int step[] = { 0, 32, 16, 8 };
+
+       unsigned int size64 = mc7->size / 8;    /* # of 64-bit words */
+       struct adapter *adap = mc7->adapter;
+
+       if (start >= size64 || start + n > size64)
+               return -EINVAL;
+
+       start *= (8 << mc7->width);
+       while (n--) {
+               int i;
+               u64 val64 = 0;
+
+               for (i = (1 << mc7->width) - 1; i >= 0; --i) {
+                       int attempts = 10;
+                       u32 val;
+
+                       t3_write_reg(adap, mc7->offset + A_MC7_BD_ADDR, start);
+                       t3_write_reg(adap, mc7->offset + A_MC7_BD_OP, 0);
+                       val = t3_read_reg(adap, mc7->offset + A_MC7_BD_OP);
+                       while ((val & F_BUSY) && attempts--)
+                               val = t3_read_reg(adap,
+                                                 mc7->offset + A_MC7_BD_OP);
+                       if (val & F_BUSY)
+                               return -EIO;
+
+                       val = t3_read_reg(adap, mc7->offset + A_MC7_BD_DATA1);
+                       if (mc7->width == 0) {
+                               val64 = t3_read_reg(adap,
+                                                   mc7->offset +
+                                                   A_MC7_BD_DATA0);
+                               val64 |= (u64) val << 32;
+                       } else {
+                               if (mc7->width > 1)
+                                       val >>= shift[mc7->width];
+                               val64 |= (u64) val << (step[mc7->width] * i);
+                       }
+                       start += 8;
+               }
+               *buf++ = val64;
+       }
+       return 0;
+}
+
+/*
+ * Initialize MI1.
+ */
+static void mi1_init(struct adapter *adap, const struct adapter_info *ai)
+{
+       u32 clkdiv = adap->params.vpd.cclk / (2 * adap->params.vpd.mdc) - 1;
+       u32 val = F_PREEN | V_MDIINV(ai->mdiinv) | V_MDIEN(ai->mdien) |
+           V_CLKDIV(clkdiv);
+
+       if (!(ai->caps & SUPPORTED_10000baseT_Full))
+               val |= V_ST(1);
+       t3_write_reg(adap, A_MI1_CFG, val);
+}
+
+#define MDIO_ATTEMPTS 10
+
+/*
+ * MI1 read/write operations for direct-addressed PHYs.
+ */
+static int mi1_read(struct adapter *adapter, int phy_addr, int mmd_addr,
+                   int reg_addr, unsigned int *valp)
+{
+       int ret;
+       u32 addr = V_REGADDR(reg_addr) | V_PHYADDR(phy_addr);
+
+       if (mmd_addr)
+               return -EINVAL;
+
+       mutex_lock(&adapter->mdio_lock);
+       t3_write_reg(adapter, A_MI1_ADDR, addr);
+       t3_write_reg(adapter, A_MI1_OP, V_MDI_OP(2));
+       ret = t3_wait_op_done(adapter, A_MI1_OP, F_BUSY, 0, MDIO_ATTEMPTS, 20);
+       if (!ret)
+               *valp = t3_read_reg(adapter, A_MI1_DATA);
+       mutex_unlock(&adapter->mdio_lock);
+       return ret;
+}
+
+static int mi1_write(struct adapter *adapter, int phy_addr, int mmd_addr,
+                    int reg_addr, unsigned int val)
+{
+       int ret;
+       u32 addr = V_REGADDR(reg_addr) | V_PHYADDR(phy_addr);
+
+       if (mmd_addr)
+               return -EINVAL;
+
+       mutex_lock(&adapter->mdio_lock);
+       t3_write_reg(adapter, A_MI1_ADDR, addr);
+       t3_write_reg(adapter, A_MI1_DATA, val);
+       t3_write_reg(adapter, A_MI1_OP, V_MDI_OP(1));
+       ret = t3_wait_op_done(adapter, A_MI1_OP, F_BUSY, 0, MDIO_ATTEMPTS, 20);
+       mutex_unlock(&adapter->mdio_lock);
+       return ret;
+}
+
+static const struct mdio_ops mi1_mdio_ops = {
+       mi1_read,
+       mi1_write
+};
+
+/*
+ * MI1 read/write operations for indirect-addressed PHYs.
+ */
+static int mi1_ext_read(struct adapter *adapter, int phy_addr, int mmd_addr,
+                       int reg_addr, unsigned int *valp)
+{
+       int ret;
+       u32 addr = V_REGADDR(mmd_addr) | V_PHYADDR(phy_addr);
+
+       mutex_lock(&adapter->mdio_lock);
+       t3_write_reg(adapter, A_MI1_ADDR, addr);
+       t3_write_reg(adapter, A_MI1_DATA, reg_addr);
+       t3_write_reg(adapter, A_MI1_OP, V_MDI_OP(0));
+       ret = t3_wait_op_done(adapter, A_MI1_OP, F_BUSY, 0, MDIO_ATTEMPTS, 20);
+       if (!ret) {
+               t3_write_reg(adapter, A_MI1_OP, V_MDI_OP(3));
+               ret = t3_wait_op_done(adapter, A_MI1_OP, F_BUSY, 0,
+                                     MDIO_ATTEMPTS, 20);
+               if (!ret)
+                       *valp = t3_read_reg(adapter, A_MI1_DATA);
+       }
+       mutex_unlock(&adapter->mdio_lock);
+       return ret;
+}
+
+static int mi1_ext_write(struct adapter *adapter, int phy_addr, int mmd_addr,
+                        int reg_addr, unsigned int val)
+{
+       int ret;
+       u32 addr = V_REGADDR(mmd_addr) | V_PHYADDR(phy_addr);
+
+       mutex_lock(&adapter->mdio_lock);
+       t3_write_reg(adapter, A_MI1_ADDR, addr);
+       t3_write_reg(adapter, A_MI1_DATA, reg_addr);
+       t3_write_reg(adapter, A_MI1_OP, V_MDI_OP(0));
+       ret = t3_wait_op_done(adapter, A_MI1_OP, F_BUSY, 0, MDIO_ATTEMPTS, 20);
+       if (!ret) {
+               t3_write_reg(adapter, A_MI1_DATA, val);
+               t3_write_reg(adapter, A_MI1_OP, V_MDI_OP(1));
+               ret = t3_wait_op_done(adapter, A_MI1_OP, F_BUSY, 0,
+                                     MDIO_ATTEMPTS, 20);
+       }
+       mutex_unlock(&adapter->mdio_lock);
+       return ret;
+}
+
+static const struct mdio_ops mi1_mdio_ext_ops = {
+       mi1_ext_read,
+       mi1_ext_write
+};
+
+/**
+ *     t3_mdio_change_bits - modify the value of a PHY register
+ *     @phy: the PHY to operate on
+ *     @mmd: the device address
+ *     @reg: the register address
+ *     @clear: what part of the register value to mask off
+ *     @set: what part of the register value to set
+ *
+ *     Changes the value of a PHY register by applying a mask to its current
+ *     value and ORing the result with a new value.
+ */
+int t3_mdio_change_bits(struct cphy *phy, int mmd, int reg, unsigned int clear,
+                       unsigned int set)
+{
+       int ret;
+       unsigned int val;
+
+       ret = mdio_read(phy, mmd, reg, &val);
+       if (!ret) {
+               val &= ~clear;
+               ret = mdio_write(phy, mmd, reg, val | set);
+       }
+       return ret;
+}
+
+/**
+ *     t3_phy_reset - reset a PHY block
+ *     @phy: the PHY to operate on
+ *     @mmd: the device address of the PHY block to reset
+ *     @wait: how long to wait for the reset to complete in 1ms increments
+ *
+ *     Resets a PHY block and optionally waits for the reset to complete.
+ *     @mmd should be 0 for 10/100/1000 PHYs and the device address to reset
+ *     for 10G PHYs.
+ */
+int t3_phy_reset(struct cphy *phy, int mmd, int wait)
+{
+       int err;
+       unsigned int ctl;
+
+       err = t3_mdio_change_bits(phy, mmd, MII_BMCR, BMCR_PDOWN, BMCR_RESET);
+       if (err || !wait)
+               return err;
+
+       do {
+               err = mdio_read(phy, mmd, MII_BMCR, &ctl);
+               if (err)
+                       return err;
+               ctl &= BMCR_RESET;
+               if (ctl)
+                       msleep(1);
+       } while (ctl && --wait);
+
+       return ctl ? -1 : 0;
+}
+
+/**
+ *     t3_phy_advertise - set the PHY advertisement registers for autoneg
+ *     @phy: the PHY to operate on
+ *     @advert: bitmap of capabilities the PHY should advertise
+ *
+ *     Sets a 10/100/1000 PHY's advertisement registers to advertise the
+ *     requested capabilities.
+ */
+int t3_phy_advertise(struct cphy *phy, unsigned int advert)
+{
+       int err;
+       unsigned int val = 0;
+
+       err = mdio_read(phy, 0, MII_CTRL1000, &val);
+       if (err)
+               return err;
+
+       val &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
+       if (advert & ADVERTISED_1000baseT_Half)
+               val |= ADVERTISE_1000HALF;
+       if (advert & ADVERTISED_1000baseT_Full)
+               val |= ADVERTISE_1000FULL;
+
+       err = mdio_write(phy, 0, MII_CTRL1000, val);
+       if (err)
+               return err;
+
+       val = 1;
+       if (advert & ADVERTISED_10baseT_Half)
+               val |= ADVERTISE_10HALF;
+       if (advert & ADVERTISED_10baseT_Full)
+               val |= ADVERTISE_10FULL;
+       if (advert & ADVERTISED_100baseT_Half)
+               val |= ADVERTISE_100HALF;
+       if (advert & ADVERTISED_100baseT_Full)
+               val |= ADVERTISE_100FULL;
+       if (advert & ADVERTISED_Pause)
+               val |= ADVERTISE_PAUSE_CAP;
+       if (advert & ADVERTISED_Asym_Pause)
+               val |= ADVERTISE_PAUSE_ASYM;
+       return mdio_write(phy, 0, MII_ADVERTISE, val);
+}
+
+/**
+ *     t3_set_phy_speed_duplex - force PHY speed and duplex
+ *     @phy: the PHY to operate on
+ *     @speed: requested PHY speed
+ *     @duplex: requested PHY duplex
+ *
+ *     Force a 10/100/1000 PHY's speed and duplex.  This also disables
+ *     auto-negotiation except for GigE, where auto-negotiation is mandatory.
+ */
+int t3_set_phy_speed_duplex(struct cphy *phy, int speed, int duplex)
+{
+       int err;
+       unsigned int ctl;
+
+       err = mdio_read(phy, 0, MII_BMCR, &ctl);
+       if (err)
+               return err;
+
+       if (speed >= 0) {
+               ctl &= ~(BMCR_SPEED100 | BMCR_SPEED1000 | BMCR_ANENABLE);
+               if (speed == SPEED_100)
+                       ctl |= BMCR_SPEED100;
+               else if (speed == SPEED_1000)
+                       ctl |= BMCR_SPEED1000;
+       }
+       if (duplex >= 0) {
+               ctl &= ~(BMCR_FULLDPLX | BMCR_ANENABLE);
+               if (duplex == DUPLEX_FULL)
+                       ctl |= BMCR_FULLDPLX;
+       }
+       if (ctl & BMCR_SPEED1000) /* auto-negotiation required for GigE */
+               ctl |= BMCR_ANENABLE;
+       return mdio_write(phy, 0, MII_BMCR, ctl);
+}
+
+static const struct adapter_info t3_adap_info[] = {
+       {2, 0, 0, 0,
+        F_GPIO2_OEN | F_GPIO4_OEN |
+        F_GPIO2_OUT_VAL | F_GPIO4_OUT_VAL, F_GPIO3 | F_GPIO5,
+        SUPPORTED_OFFLOAD,
+        &mi1_mdio_ops, "Chelsio PE9000"},
+       {2, 0, 0, 0,
+        F_GPIO2_OEN | F_GPIO4_OEN |
+        F_GPIO2_OUT_VAL | F_GPIO4_OUT_VAL, F_GPIO3 | F_GPIO5,
+        SUPPORTED_OFFLOAD,
+        &mi1_mdio_ops, "Chelsio T302"},
+       {1, 0, 0, 0,
+        F_GPIO1_OEN | F_GPIO6_OEN | F_GPIO7_OEN | F_GPIO10_OEN |
+        F_GPIO1_OUT_VAL | F_GPIO6_OUT_VAL | F_GPIO10_OUT_VAL, 0,
+        SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_OFFLOAD,
+        &mi1_mdio_ext_ops, "Chelsio T310"},
+       {2, 0, 0, 0,
+        F_GPIO1_OEN | F_GPIO2_OEN | F_GPIO4_OEN | F_GPIO5_OEN | F_GPIO6_OEN |
+        F_GPIO7_OEN | F_GPIO10_OEN | F_GPIO11_OEN | F_GPIO1_OUT_VAL |
+        F_GPIO5_OUT_VAL | F_GPIO6_OUT_VAL | F_GPIO10_OUT_VAL, 0,
+        SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_OFFLOAD,
+        &mi1_mdio_ext_ops, "Chelsio T320"},
+};
+
+/*
+ * Return the adapter_info structure with a given index.  Out-of-range indices
+ * return NULL.
+ */
+const struct adapter_info *t3_get_adapter_info(unsigned int id)
+{
+       return id < ARRAY_SIZE(t3_adap_info) ? &t3_adap_info[id] : NULL;
+}
+
+#define CAPS_1G (SUPPORTED_10baseT_Full | SUPPORTED_100baseT_Full | \
+                SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_MII)
+#define CAPS_10G (SUPPORTED_10000baseT_Full | SUPPORTED_AUI)
+
+static const struct port_type_info port_types[] = {
+       {NULL},
+       {t3_ael1002_phy_prep, CAPS_10G | SUPPORTED_FIBRE,
+        "10GBASE-XR"},
+       {t3_vsc8211_phy_prep, CAPS_1G | SUPPORTED_TP | SUPPORTED_IRQ,
+        "10/100/1000BASE-T"},
+       {NULL, CAPS_1G | SUPPORTED_TP | SUPPORTED_IRQ,
+        "10/100/1000BASE-T"},
+       {t3_xaui_direct_phy_prep, CAPS_10G | SUPPORTED_TP, "10GBASE-CX4"},
+       {NULL, CAPS_10G, "10GBASE-KX4"},
+       {t3_qt2045_phy_prep, CAPS_10G | SUPPORTED_TP, "10GBASE-CX4"},
+       {t3_ael1006_phy_prep, CAPS_10G | SUPPORTED_FIBRE,
+        "10GBASE-SR"},
+       {NULL, CAPS_10G | SUPPORTED_TP, "10GBASE-CX4"},
+};
+
+#undef CAPS_1G
+#undef CAPS_10G
+
+#define VPD_ENTRY(name, len) \
+       u8 name##_kword[2]; u8 name##_len; u8 name##_data[len]
+
+/*
+ * Partial EEPROM Vital Product Data structure.  Includes only the ID and
+ * VPD-R sections.
+ */
+struct t3_vpd {
+       u8 id_tag;
+       u8 id_len[2];
+       u8 id_data[16];
+       u8 vpdr_tag;
+       u8 vpdr_len[2];
+       VPD_ENTRY(pn, 16);      /* part number */
+       VPD_ENTRY(ec, 16);      /* EC level */
+       VPD_ENTRY(sn, 16);      /* serial number */
+       VPD_ENTRY(na, 12);      /* MAC address base */
+       VPD_ENTRY(cclk, 6);     /* core clock */
+       VPD_ENTRY(mclk, 6);     /* mem clock */
+       VPD_ENTRY(uclk, 6);     /* uP clk */
+       VPD_ENTRY(mdc, 6);      /* MDIO clk */
+       VPD_ENTRY(mt, 2);       /* mem timing */
+       VPD_ENTRY(xaui0cfg, 6); /* XAUI0 config */
+       VPD_ENTRY(xaui1cfg, 6); /* XAUI1 config */
+       VPD_ENTRY(port0, 2);    /* PHY0 complex */
+       VPD_ENTRY(port1, 2);    /* PHY1 complex */
+       VPD_ENTRY(port2, 2);    /* PHY2 complex */
+       VPD_ENTRY(port3, 2);    /* PHY3 complex */
+       VPD_ENTRY(rv, 1);       /* csum */
+       u32 pad;                /* for multiple-of-4 sizing and alignment */
+};
+
+#define EEPROM_MAX_POLL   4
+#define EEPROM_STAT_ADDR  0x4000
+#define VPD_BASE          0xc00
+
+/**
+ *     t3_seeprom_read - read a VPD EEPROM location
+ *     @adapter: adapter to read
+ *     @addr: EEPROM address
+ *     @data: where to store the read data
+ *
+ *     Read a 32-bit word from a location in VPD EEPROM using the card's PCI
+ *     VPD ROM capability.  A zero is written to the flag bit when the
+ *     addres is written to the control register.  The hardware device will
+ *     set the flag to 1 when 4 bytes have been read into the data register.
+ */
+int t3_seeprom_read(struct adapter *adapter, u32 addr, u32 *data)
+{
+       u16 val;
+       int attempts = EEPROM_MAX_POLL;
+       unsigned int base = adapter->params.pci.vpd_cap_addr;
+
+       if ((addr >= EEPROMSIZE && addr != EEPROM_STAT_ADDR) || (addr & 3))
+               return -EINVAL;
+
+       pci_write_config_word(adapter->pdev, base + PCI_VPD_ADDR, addr);
+       do {
+               udelay(10);
+               pci_read_config_word(adapter->pdev, base + PCI_VPD_ADDR, &val);
+       } while (!(val & PCI_VPD_ADDR_F) && --attempts);
+
+       if (!(val & PCI_VPD_ADDR_F)) {
+               CH_ERR(adapter, "reading EEPROM address 0x%x failed\n", addr);
+               return -EIO;
+       }
+       pci_read_config_dword(adapter->pdev, base + PCI_VPD_DATA, data);
+       *data = le32_to_cpu(*data);
+       return 0;
+}
+
+/**
+ *     t3_seeprom_write - write a VPD EEPROM location
+ *     @adapter: adapter to write
+ *     @addr: EEPROM address
+ *     @data: value to write
+ *
+ *     Write a 32-bit word to a location in VPD EEPROM using the card's PCI
+ *     VPD ROM capability.
+ */
+int t3_seeprom_write(struct adapter *adapter, u32 addr, u32 data)
+{
+       u16 val;
+       int attempts = EEPROM_MAX_POLL;
+       unsigned int base = adapter->params.pci.vpd_cap_addr;
+
+       if ((addr >= EEPROMSIZE && addr != EEPROM_STAT_ADDR) || (addr & 3))
+               return -EINVAL;
+
+       pci_write_config_dword(adapter->pdev, base + PCI_VPD_DATA,
+                              cpu_to_le32(data));
+       pci_write_config_word(adapter->pdev,base + PCI_VPD_ADDR,
+                             addr | PCI_VPD_ADDR_F);
+       do {
+               msleep(1);
+               pci_read_config_word(adapter->pdev, base + PCI_VPD_ADDR, &val);
+       } while ((val & PCI_VPD_ADDR_F) && --attempts);
+
+       if (val & PCI_VPD_ADDR_F) {
+               CH_ERR(adapter, "write to EEPROM address 0x%x failed\n", addr);
+               return -EIO;
+       }
+       return 0;
+}
+
+/**
+ *     t3_seeprom_wp - enable/disable EEPROM write protection
+ *     @adapter: the adapter
+ *     @enable: 1 to enable write protection, 0 to disable it
+ *
+ *     Enables or disables write protection on the serial EEPROM.
+ */
+int t3_seeprom_wp(struct adapter *adapter, int enable)
+{
+       return t3_seeprom_write(adapter, EEPROM_STAT_ADDR, enable ? 0xc : 0);
+}
+
+/*
+ * Convert a character holding a hex digit to a number.
+ */
+static unsigned int hex2int(unsigned char c)
+{
+       return isdigit(c) ? c - '0' : toupper(c) - 'A' + 10;
+}
+
+/**
+ *     get_vpd_params - read VPD parameters from VPD EEPROM
+ *     @adapter: adapter to read
+ *     @p: where to store the parameters
+ *
+ *     Reads card parameters stored in VPD EEPROM.
+ */
+static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
+{
+       int i, addr, ret;
+       struct t3_vpd vpd;
+
+       /*
+        * Card information is normally at VPD_BASE but some early cards had
+        * it at 0.
+        */
+       ret = t3_seeprom_read(adapter, VPD_BASE, (u32 *)&vpd);
+       if (ret)
+               return ret;
+       addr = vpd.id_tag == 0x82 ? VPD_BASE : 0;
+
+       for (i = 0; i < sizeof(vpd); i += 4) {
+               ret = t3_seeprom_read(adapter, addr + i,
+                                     (u32 *)((u8 *)&vpd + i));
+               if (ret)
+                       return ret;
+       }
+
+       p->cclk = simple_strtoul(vpd.cclk_data, NULL, 10);
+       p->mclk = simple_strtoul(vpd.mclk_data, NULL, 10);
+       p->uclk = simple_strtoul(vpd.uclk_data, NULL, 10);
+       p->mdc = simple_strtoul(vpd.mdc_data, NULL, 10);
+       p->mem_timing = simple_strtoul(vpd.mt_data, NULL, 10);
+
+       /* Old eeproms didn't have port information */
+       if (adapter->params.rev == 0 && !vpd.port0_data[0]) {
+               p->port_type[0] = uses_xaui(adapter) ? 1 : 2;
+               p->port_type[1] = uses_xaui(adapter) ? 6 : 2;
+       } else {
+               p->port_type[0] = hex2int(vpd.port0_data[0]);
+               p->port_type[1] = hex2int(vpd.port1_data[0]);
+               p->xauicfg[0] = simple_strtoul(vpd.xaui0cfg_data, NULL, 16);
+               p->xauicfg[1] = simple_strtoul(vpd.xaui1cfg_data, NULL, 16);
+       }
+
+       for (i = 0; i < 6; i++)
+               p->eth_base[i] = hex2int(vpd.na_data[2 * i]) * 16 +
+                                hex2int(vpd.na_data[2 * i + 1]);
+       return 0;
+}
+
+/* serial flash and firmware constants */
+enum {
+       SF_ATTEMPTS = 5,        /* max retries for SF1 operations */
+       SF_SEC_SIZE = 64 * 1024,        /* serial flash sector size */
+       SF_SIZE = SF_SEC_SIZE * 8,      /* serial flash size */
+
+       /* flash command opcodes */
+       SF_PROG_PAGE = 2,       /* program page */
+       SF_WR_DISABLE = 4,      /* disable writes */
+       SF_RD_STATUS = 5,       /* read status register */
+       SF_WR_ENABLE = 6,       /* enable writes */
+       SF_RD_DATA_FAST = 0xb,  /* read flash */
+       SF_ERASE_SECTOR = 0xd8, /* erase sector */
+
+       FW_FLASH_BOOT_ADDR = 0x70000,   /* start address of FW in flash */
+       FW_VERS_ADDR = 0x77ffc  /* flash address holding FW version */
+};
+
+/**
+ *     sf1_read - read data from the serial flash
+ *     @adapter: the adapter
+ *     @byte_cnt: number of bytes to read
+ *     @cont: whether another operation will be chained
+ *     @valp: where to store the read data
+ *
+ *     Reads up to 4 bytes of data from the serial flash.  The location of
+ *     the read needs to be specified prior to calling this by issuing the
+ *     appropriate commands to the serial flash.
+ */
+static int sf1_read(struct adapter *adapter, unsigned int byte_cnt, int cont,
+                   u32 *valp)
+{
+       int ret;
+
+       if (!byte_cnt || byte_cnt > 4)
+               return -EINVAL;
+       if (t3_read_reg(adapter, A_SF_OP) & F_BUSY)
+               return -EBUSY;
+       t3_write_reg(adapter, A_SF_OP, V_CONT(cont) | V_BYTECNT(byte_cnt - 1));
+       ret = t3_wait_op_done(adapter, A_SF_OP, F_BUSY, 0, SF_ATTEMPTS, 10);
+       if (!ret)
+               *valp = t3_read_reg(adapter, A_SF_DATA);
+       return ret;
+}
+
+/**
+ *     sf1_write - write data to the serial flash
+ *     @adapter: the adapter
+ *     @byte_cnt: number of bytes to write
+ *     @cont: whether another operation will be chained
+ *     @val: value to write
+ *
+ *     Writes up to 4 bytes of data to the serial flash.  The location of
+ *     the write needs to be specified prior to calling this by issuing the
+ *     appropriate commands to the serial flash.
+ */
+static int sf1_write(struct adapter *adapter, unsigned int byte_cnt, int cont,
+                    u32 val)
+{
+       if (!byte_cnt || byte_cnt > 4)
+               return -EINVAL;
+       if (t3_read_reg(adapter, A_SF_OP) & F_BUSY)
+               return -EBUSY;
+       t3_write_reg(adapter, A_SF_DATA, val);
+       t3_write_reg(adapter, A_SF_OP,
+                    V_CONT(cont) | V_BYTECNT(byte_cnt - 1) | V_OP(1));
+       return t3_wait_op_done(adapter, A_SF_OP, F_BUSY, 0, SF_ATTEMPTS, 10);
+}
+
+/**
+ *     flash_wait_op - wait for a flash operation to complete
+ *     @adapter: the adapter
+ *     @attempts: max number of polls of the status register
+ *     @delay: delay between polls in ms
+ *
+ *     Wait for a flash operation to complete by polling the status register.
+ */
+static int flash_wait_op(struct adapter *adapter, int attempts, int delay)
+{
+       int ret;
+       u32 status;
+
+       while (1) {
+               if ((ret = sf1_write(adapter, 1, 1, SF_RD_STATUS)) != 0 ||
+                   (ret = sf1_read(adapter, 1, 0, &status)) != 0)
+                       return ret;
+               if (!(status & 1))
+                       return 0;
+               if (--attempts == 0)
+                       return -EAGAIN;
+               if (delay)
+                       msleep(delay);
+       }
+}
+
+/**
+ *     t3_read_flash - read words from serial flash
+ *     @adapter: the adapter
+ *     @addr: the start address for the read
+ *     @nwords: how many 32-bit words to read
+ *     @data: where to store the read data
+ *     @byte_oriented: whether to store data as bytes or as words
+ *
+ *     Read the specified number of 32-bit words from the serial flash.
+ *     If @byte_oriented is set the read data is stored as a byte array
+ *     (i.e., big-endian), otherwise as 32-bit words in the platform's
+ *     natural endianess.
+ */
+int t3_read_flash(struct adapter *adapter, unsigned int addr,
+                 unsigned int nwords, u32 *data, int byte_oriented)
+{
+       int ret;
+
+       if (addr + nwords * sizeof(u32) > SF_SIZE || (addr & 3))
+               return -EINVAL;
+
+       addr = swab32(addr) | SF_RD_DATA_FAST;
+
+       if ((ret = sf1_write(adapter, 4, 1, addr)) != 0 ||
+           (ret = sf1_read(adapter, 1, 1, data)) != 0)
+               return ret;
+
+       for (; nwords; nwords--, data++) {
+               ret = sf1_read(adapter, 4, nwords > 1, data);
+               if (ret)
+                       return ret;
+               if (byte_oriented)
+                       *data = htonl(*data);
+       }
+       return 0;
+}
+
+/**
+ *     t3_write_flash - write up to a page of data to the serial flash
+ *     @adapter: the adapter
+ *     @addr: the start address to write
+ *     @n: length of data to write
+ *     @data: the data to write
+ *
+ *     Writes up to a page of data (256 bytes) to the serial flash starting
+ *     at the given address.
+ */
+static int t3_write_flash(struct adapter *adapter, unsigned int addr,
+                         unsigned int n, const u8 *data)
+{
+       int ret;
+       u32 buf[64];
+       unsigned int i, c, left, val, offset = addr & 0xff;
+
+       if (addr + n > SF_SIZE || offset + n > 256)
+               return -EINVAL;
+
+       val = swab32(addr) | SF_PROG_PAGE;
+
+       if ((ret = sf1_write(adapter, 1, 0, SF_WR_ENABLE)) != 0 ||
+           (ret = sf1_write(adapter, 4, 1, val)) != 0)
+               return ret;
+
+       for (left = n; left; left -= c) {
+               c = min(left, 4U);
+               for (val = 0, i = 0; i < c; ++i)
+                       val = (val << 8) + *data++;
+
+               ret = sf1_write(adapter, c, c != left, val);
+               if (ret)
+                       return ret;
+       }
+       if ((ret = flash_wait_op(adapter, 5, 1)) != 0)
+               return ret;
+
+       /* Read the page to verify the write succeeded */
+       ret = t3_read_flash(adapter, addr & ~0xff, ARRAY_SIZE(buf), buf, 1);
+       if (ret)
+               return ret;
+
+       if (memcmp(data - n, (u8 *) buf + offset, n))
+               return -EIO;
+       return 0;
+}
+
+enum fw_version_type {
+       FW_VERSION_N3,
+       FW_VERSION_T3
+};
+
+/**
+ *     t3_get_fw_version - read the firmware version
+ *     @adapter: the adapter
+ *     @vers: where to place the version
+ *
+ *     Reads the FW version from flash.
+ */
+int t3_get_fw_version(struct adapter *adapter, u32 *vers)
+{
+       return t3_read_flash(adapter, FW_VERS_ADDR, 1, vers, 0);
+}
+
+/**
+ *     t3_check_fw_version - check if the FW is compatible with this driver
+ *     @adapter: the adapter
+ *
+ *     Checks if an adapter's FW is compatible with the driver.  Returns 0
+ *     if the versions are compatible, a negative error otherwise.
+ */
+int t3_check_fw_version(struct adapter *adapter)
+{
+       int ret;
+       u32 vers;
+       unsigned int type, major, minor;
+
+       ret = t3_get_fw_version(adapter, &vers);
+       if (ret)
+               return ret;
+
+       type = G_FW_VERSION_TYPE(vers);
+       major = G_FW_VERSION_MAJOR(vers);
+       minor = G_FW_VERSION_MINOR(vers);
+
+       if (type == FW_VERSION_T3 && major == 3 && minor == 1)
+               return 0;
+
+       CH_ERR(adapter, "found wrong FW version(%u.%u), "
+              "driver needs version 3.1\n", major, minor);
+       return -EINVAL;
+}
+
+/**
+ *     t3_flash_erase_sectors - erase a range of flash sectors
+ *     @adapter: the adapter
+ *     @start: the first sector to erase
+ *     @end: the last sector to erase
+ *
+ *     Erases the sectors in the given range.
+ */
+static int t3_flash_erase_sectors(struct adapter *adapter, int start, int end)
+{
+       while (start <= end) {
+               int ret;
+
+               if ((ret = sf1_write(adapter, 1, 0, SF_WR_ENABLE)) != 0 ||
+                   (ret = sf1_write(adapter, 4, 0,
+                                    SF_ERASE_SECTOR | (start << 8))) != 0 ||
+                   (ret = flash_wait_op(adapter, 5, 500)) != 0)
+                       return ret;
+               start++;
+       }
+       return 0;
+}
+
+/*
+ *     t3_load_fw - download firmware
+ *     @adapter: the adapter
+ *     @fw_data: the firrware image to write
+ *     @size: image size
+ *
+ *     Write the supplied firmware image to the card's serial flash.
+ *     The FW image has the following sections: @size - 8 bytes of code and
+ *     data, followed by 4 bytes of FW version, followed by the 32-bit
+ *     1's complement checksum of the whole image.
+ */
+int t3_load_fw(struct adapter *adapter, const u8 *fw_data, unsigned int size)
+{
+       u32 csum;
+       unsigned int i;
+       const u32 *p = (const u32 *)fw_data;
+       int ret, addr, fw_sector = FW_FLASH_BOOT_ADDR >> 16;
+
+       if (size & 3)
+               return -EINVAL;
+       if (size > FW_VERS_ADDR + 8 - FW_FLASH_BOOT_ADDR)
+               return -EFBIG;
+
+       for (csum = 0, i = 0; i < size / sizeof(csum); i++)
+               csum += ntohl(p[i]);
+       if (csum != 0xffffffff) {
+               CH_ERR(adapter, "corrupted firmware image, checksum %u\n",
+                      csum);
+               return -EINVAL;
+       }
+
+       ret = t3_flash_erase_sectors(adapter, fw_sector, fw_sector);
+       if (ret)
+               goto out;
+
+       size -= 8;              /* trim off version and checksum */
+       for (addr = FW_FLASH_BOOT_ADDR; size;) {
+               unsigned int chunk_size = min(size, 256U);
+
+               ret = t3_write_flash(adapter, addr, chunk_size, fw_data);
+               if (ret)
+                       goto out;
+
+               addr += chunk_size;
+               fw_data += chunk_size;
+               size -= chunk_size;
+       }
+
+       ret = t3_write_flash(adapter, FW_VERS_ADDR, 4, fw_data);
+out:
+       if (ret)
+               CH_ERR(adapter, "firmware download failed, error %d\n", ret);
+       return ret;
+}
+
+#define CIM_CTL_BASE 0x2000
+
+/**
+ *      t3_cim_ctl_blk_read - read a block from CIM control region
+ *
+ *      @adap: the adapter
+ *      @addr: the start address within the CIM control region
+ *      @n: number of words to read
+ *      @valp: where to store the result
+ *
+ *      Reads a block of 4-byte words from the CIM control region.
+ */
+int t3_cim_ctl_blk_read(struct adapter *adap, unsigned int addr,
+                       unsigned int n, unsigned int *valp)
+{
+       int ret = 0;
+
+       if (t3_read_reg(adap, A_CIM_HOST_ACC_CTRL) & F_HOSTBUSY)
+               return -EBUSY;
+
+       for ( ; !ret && n--; addr += 4) {
+               t3_write_reg(adap, A_CIM_HOST_ACC_CTRL, CIM_CTL_BASE + addr);
+               ret = t3_wait_op_done(adap, A_CIM_HOST_ACC_CTRL, F_HOSTBUSY,
+                                     0, 5, 2);
+               if (!ret)
+                       *valp++ = t3_read_reg(adap, A_CIM_HOST_ACC_DATA);
+       }
+       return ret;
+}
+
+
+/**
+ *     t3_link_changed - handle interface link changes
+ *     @adapter: the adapter
+ *     @port_id: the port index that changed link state
+ *
+ *     Called when a port's link settings change to propagate the new values
+ *     to the associated PHY and MAC.  After performing the common tasks it
+ *     invokes an OS-specific handler.
+ */
+void t3_link_changed(struct adapter *adapter, int port_id)
+{
+       int link_ok, speed, duplex, fc;
+       struct port_info *pi = adap2pinfo(adapter, port_id);
+       struct cphy *phy = &pi->phy;
+       struct cmac *mac = &pi->mac;
+       struct link_config *lc = &pi->link_config;
+
+       phy->ops->get_link_status(phy, &link_ok, &speed, &duplex, &fc);
+
+       if (link_ok != lc->link_ok && adapter->params.rev > 0 &&
+           uses_xaui(adapter)) {
+               if (link_ok)
+                       t3b_pcs_reset(mac);
+               t3_write_reg(adapter, A_XGM_XAUI_ACT_CTRL + mac->offset,
+                            link_ok ? F_TXACTENABLE | F_RXEN : 0);
+       }
+       lc->link_ok = link_ok;
+       lc->speed = speed < 0 ? SPEED_INVALID : speed;
+       lc->duplex = duplex < 0 ? DUPLEX_INVALID : duplex;
+       if (lc->requested_fc & PAUSE_AUTONEG)
+               fc &= lc->requested_fc;
+       else
+               fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
+
+       if (link_ok && speed >= 0 && lc->autoneg == AUTONEG_ENABLE) {
+               /* Set MAC speed, duplex, and flow control to match PHY. */
+               t3_mac_set_speed_duplex_fc(mac, speed, duplex, fc);
+               lc->fc = fc;
+       }
+
+       t3_os_link_changed(adapter, port_id, link_ok, speed, duplex, fc);
+}
+
+/**
+ *     t3_link_start - apply link configuration to MAC/PHY
+ *     @phy: the PHY to setup
+ *     @mac: the MAC to setup
+ *     @lc: the requested link configuration
+ *
+ *     Set up a port's MAC and PHY according to a desired link configuration.
+ *     - If the PHY can auto-negotiate first decide what to advertise, then
+ *       enable/disable auto-negotiation as desired, and reset.
+ *     - If the PHY does not auto-negotiate just reset it.
+ *     - If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
+ *       otherwise do it later based on the outcome of auto-negotiation.
+ */
+int t3_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc)
+{
+       unsigned int fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
+
+       lc->link_ok = 0;
+       if (lc->supported & SUPPORTED_Autoneg) {
+               lc->advertising &= ~(ADVERTISED_Asym_Pause | ADVERTISED_Pause);
+               if (fc) {
+                       lc->advertising |= ADVERTISED_Asym_Pause;
+                       if (fc & PAUSE_RX)
+                               lc->advertising |= ADVERTISED_Pause;
+               }
+               phy->ops->advertise(phy, lc->advertising);
+
+               if (lc->autoneg == AUTONEG_DISABLE) {
+                       lc->speed = lc->requested_speed;
+                       lc->duplex = lc->requested_duplex;
+                       lc->fc = (unsigned char)fc;
+                       t3_mac_set_speed_duplex_fc(mac, lc->speed, lc->duplex,
+                                                  fc);
+                       /* Also disables autoneg */
+                       phy->ops->set_speed_duplex(phy, lc->speed, lc->duplex);
+                       phy->ops->reset(phy, 0);
+               } else
+                       phy->ops->autoneg_enable(phy);
+       } else {
+               t3_mac_set_speed_duplex_fc(mac, -1, -1, fc);
+               lc->fc = (unsigned char)fc;
+               phy->ops->reset(phy, 0);
+       }
+       return 0;
+}
+
+/**
+ *     t3_set_vlan_accel - control HW VLAN extraction
+ *     @adapter: the adapter
+ *     @ports: bitmap of adapter ports to operate on
+ *     @on: enable (1) or disable (0) HW VLAN extraction
+ *
+ *     Enables or disables HW extraction of VLAN tags for the given port.
+ */
+void t3_set_vlan_accel(struct adapter *adapter, unsigned int ports, int on)
+{
+       t3_set_reg_field(adapter, A_TP_OUT_CONFIG,
+                        ports << S_VLANEXTRACTIONENABLE,
+                        on ? (ports << S_VLANEXTRACTIONENABLE) : 0);
+}
+
+struct intr_info {
+       unsigned int mask;      /* bits to check in interrupt status */
+       const char *msg;        /* message to print or NULL */
+       short stat_idx;         /* stat counter to increment or -1 */
+       unsigned short fatal:1; /* whether the condition reported is fatal */
+};
+
+/**
+ *     t3_handle_intr_status - table driven interrupt handler
+ *     @adapter: the adapter that generated the interrupt
+ *     @reg: the interrupt status register to process
+ *     @mask: a mask to apply to the interrupt status
+ *     @acts: table of interrupt actions
+ *     @stats: statistics counters tracking interrupt occurences
+ *
+ *     A table driven interrupt handler that applies a set of masks to an
+ *     interrupt status word and performs the corresponding actions if the
+ *     interrupts described by the mask have occured.  The actions include
+ *     optionally printing a warning or alert message, and optionally
+ *     incrementing a stat counter.  The table is terminated by an entry
+ *     specifying mask 0.  Returns the number of fatal interrupt conditions.
+ */
+static int t3_handle_intr_status(struct adapter *adapter, unsigned int reg,
+                                unsigned int mask,
+                                const struct intr_info *acts,
+                                unsigned long *stats)
+{
+       int fatal = 0;
+       unsigned int status = t3_read_reg(adapter, reg) & mask;
+
+       for (; acts->mask; ++acts) {
+               if (!(status & acts->mask))
+                       continue;
+               if (acts->fatal) {
+                       fatal++;
+                       CH_ALERT(adapter, "%s (0x%x)\n",
+                                acts->msg, status & acts->mask);
+               } else if (acts->msg)
+                       CH_WARN(adapter, "%s (0x%x)\n",
+                               acts->msg, status & acts->mask);
+               if (acts->stat_idx >= 0)
+                       stats[acts->stat_idx]++;
+       }
+       if (status)             /* clear processed interrupts */
+               t3_write_reg(adapter, reg, status);
+       return fatal;
+}
+
+#define SGE_INTR_MASK (F_RSPQDISABLED)
+#define MC5_INTR_MASK (F_PARITYERR | F_ACTRGNFULL | F_UNKNOWNCMD | \
+                      F_REQQPARERR | F_DISPQPARERR | F_DELACTEMPTY | \
+                      F_NFASRCHFAIL)
+#define MC7_INTR_MASK (F_AE | F_UE | F_CE | V_PE(M_PE))
+#define XGM_INTR_MASK (V_TXFIFO_PRTY_ERR(M_TXFIFO_PRTY_ERR) | \
+                      V_RXFIFO_PRTY_ERR(M_RXFIFO_PRTY_ERR) | \
+                      F_TXFIFO_UNDERRUN | F_RXFIFO_OVERFLOW)
+#define PCIX_INTR_MASK (F_MSTDETPARERR | F_SIGTARABT | F_RCVTARABT | \
+                       F_RCVMSTABT | F_SIGSYSERR | F_DETPARERR | \
+                       F_SPLCMPDIS | F_UNXSPLCMP | F_RCVSPLCMPERR | \
+                       F_DETCORECCERR | F_DETUNCECCERR | F_PIOPARERR | \
+                       V_WFPARERR(M_WFPARERR) | V_RFPARERR(M_RFPARERR) | \
+                       V_CFPARERR(M_CFPARERR) /* | V_MSIXPARERR(M_MSIXPARERR) */)
+#define PCIE_INTR_MASK (F_UNXSPLCPLERRR | F_UNXSPLCPLERRC | F_PCIE_PIOPARERR |\
+                       F_PCIE_WFPARERR | F_PCIE_RFPARERR | F_PCIE_CFPARERR | \
+                       /* V_PCIE_MSIXPARERR(M_PCIE_MSIXPARERR) | */ \
+                       V_BISTERR(M_BISTERR) | F_PEXERR)
+#define ULPRX_INTR_MASK F_PARERR
+#define ULPTX_INTR_MASK 0
+#define CPLSW_INTR_MASK (F_TP_FRAMING_ERROR | \
+                        F_SGE_FRAMING_ERROR | F_CIM_FRAMING_ERROR | \
+                        F_ZERO_SWITCH_ERROR)
+#define CIM_INTR_MASK (F_BLKWRPLINT | F_BLKRDPLINT | F_BLKWRCTLINT | \
+                      F_BLKRDCTLINT | F_BLKWRFLASHINT | F_BLKRDFLASHINT | \
+                      F_SGLWRFLASHINT | F_WRBLKFLASHINT | F_BLKWRBOOTINT | \
+                      F_FLASHRANGEINT | F_SDRAMRANGEINT | F_RSVDSPACEINT)
+#define PMTX_INTR_MASK (F_ZERO_C_CMD_ERROR | ICSPI_FRM_ERR | OESPI_FRM_ERR | \
+                       V_ICSPI_PAR_ERROR(M_ICSPI_PAR_ERROR) | \
+                       V_OESPI_PAR_ERROR(M_OESPI_PAR_ERROR))
+#define PMRX_INTR_MASK (F_ZERO_E_CMD_ERROR | IESPI_FRM_ERR | OCSPI_FRM_ERR | \
+                       V_IESPI_PAR_ERROR(M_IESPI_PAR_ERROR) | \
+                       V_OCSPI_PAR_ERROR(M_OCSPI_PAR_ERROR))
+#define MPS_INTR_MASK (V_TX0TPPARERRENB(M_TX0TPPARERRENB) | \
+                      V_TX1TPPARERRENB(M_TX1TPPARERRENB) | \
+                      V_RXTPPARERRENB(M_RXTPPARERRENB) | \
+                      V_MCAPARERRENB(M_MCAPARERRENB))
+#define PL_INTR_MASK (F_T3DBG | F_XGMAC0_0 | F_XGMAC0_1 | F_MC5A | F_PM1_TX | \
+                     F_PM1_RX | F_ULP2_TX | F_ULP2_RX | F_TP1 | F_CIM | \
+                     F_MC7_CM | F_MC7_PMTX | F_MC7_PMRX | F_SGE3 | F_PCIM0 | \
+                     F_MPS0 | F_CPL_SWITCH)
+
+/*
+ * Interrupt handler for the PCIX1 module.
+ */
+static void pci_intr_handler(struct adapter *adapter)
+{
+       static const struct intr_info pcix1_intr_info[] = {
+               {F_MSTDETPARERR, "PCI master detected parity error", -1, 1},
+               {F_SIGTARABT, "PCI signaled target abort", -1, 1},
+               {F_RCVTARABT, "PCI received target abort", -1, 1},
+               {F_RCVMSTABT, "PCI received master abort", -1, 1},
+               {F_SIGSYSERR, "PCI signaled system error", -1, 1},
+               {F_DETPARERR, "PCI detected parity error", -1, 1},
+               {F_SPLCMPDIS, "PCI split completion discarded", -1, 1},
+               {F_UNXSPLCMP, "PCI unexpected split completion error", -1, 1},
+               {F_RCVSPLCMPERR, "PCI received split completion error", -1,
+                1},
+               {F_DETCORECCERR, "PCI correctable ECC error",
+                STAT_PCI_CORR_ECC, 0},
+               {F_DETUNCECCERR, "PCI uncorrectable ECC error", -1, 1},
+               {F_PIOPARERR, "PCI PIO FIFO parity error", -1, 1},
+               {V_WFPARERR(M_WFPARERR), "PCI write FIFO parity error", -1,
+                1},
+               {V_RFPARERR(M_RFPARERR), "PCI read FIFO parity error", -1,
+                1},
+               {V_CFPARERR(M_CFPARERR), "PCI command FIFO parity error", -1,
+                1},
+               {V_MSIXPARERR(M_MSIXPARERR), "PCI MSI-X table/PBA parity "
+                "error", -1, 1},
+               {0}
+       };
+
+       if (t3_handle_intr_status(adapter, A_PCIX_INT_CAUSE, PCIX_INTR_MASK,
+                                 pcix1_intr_info, adapter->irq_stats))
+               t3_fatal_err(adapter);
+}
+
+/*
+ * Interrupt handler for the PCIE module.
+ */
+static void pcie_intr_handler(struct adapter *adapter)
+{
+       static const struct intr_info pcie_intr_info[] = {
+               {F_PEXERR, "PCI PEX error", -1, 1},
+               {F_UNXSPLCPLERRR,
+                "PCI unexpected split completion DMA read error", -1, 1},
+               {F_UNXSPLCPLERRC,
+                "PCI unexpected split completion DMA command error", -1, 1},
+               {F_PCIE_PIOPARERR, "PCI PIO FIFO parity error", -1, 1},
+               {F_PCIE_WFPARERR, "PCI write FIFO parity error", -1, 1},
+               {F_PCIE_RFPARERR, "PCI read FIFO parity error", -1, 1},
+               {F_PCIE_CFPARERR, "PCI command FIFO parity error", -1, 1},
+               {V_PCIE_MSIXPARERR(M_PCIE_MSIXPARERR),
+                "PCI MSI-X table/PBA parity error", -1, 1},
+               {V_BISTERR(M_BISTERR), "PCI BIST error", -1, 1},
+               {0}
+       };
+
+       if (t3_handle_intr_status(adapter, A_PCIE_INT_CAUSE, PCIE_INTR_MASK,
+                                 pcie_intr_info, adapter->irq_stats))
+               t3_fatal_err(adapter);
+}
+
+/*
+ * TP interrupt handler.
+ */
+static void tp_intr_handler(struct adapter *adapter)
+{
+       static const struct intr_info tp_intr_info[] = {
+               {0xffffff, "TP parity error", -1, 1},
+               {0x1000000, "TP out of Rx pages", -1, 1},
+               {0x2000000, "TP out of Tx pages", -1, 1},
+               {0}
+       };
+
+       if (t3_handle_intr_status(adapter, A_TP_INT_CAUSE, 0xffffffff,
+                                 tp_intr_info, NULL))
+               t3_fatal_err(adapter);
+}
+
+/*
+ * CIM interrupt handler.
+ */
+static void cim_intr_handler(struct adapter *adapter)
+{
+       static const struct intr_info cim_intr_info[] = {
+               {F_RSVDSPACEINT, "CIM reserved space write", -1, 1},
+               {F_SDRAMRANGEINT, "CIM SDRAM address out of range", -1, 1},
+               {F_FLASHRANGEINT, "CIM flash address out of range", -1, 1},
+               {F_BLKWRBOOTINT, "CIM block write to boot space", -1, 1},
+               {F_WRBLKFLASHINT, "CIM write to cached flash space", -1, 1},
+               {F_SGLWRFLASHINT, "CIM single write to flash space", -1, 1},
+               {F_BLKRDFLASHINT, "CIM block read from flash space", -1, 1},
+               {F_BLKWRFLASHINT, "CIM block write to flash space", -1, 1},
+               {F_BLKRDCTLINT, "CIM block read from CTL space", -1, 1},
+               {F_BLKWRCTLINT, "CIM block write to CTL space", -1, 1},
+               {F_BLKRDPLINT, "CIM block read from PL space", -1, 1},
+               {F_BLKWRPLINT, "CIM block write to PL space", -1, 1},
+               {0}
+       };
+
+       if (t3_handle_intr_status(adapter, A_CIM_HOST_INT_CAUSE, 0xffffffff,
+                                 cim_intr_info, NULL))
+               t3_fatal_err(adapter);
+}
+
+/*
+ * ULP RX interrupt handler.
+ */
+static void ulprx_intr_handler(struct adapter *adapter)
+{
+       static const struct intr_info ulprx_intr_info[] = {
+               {F_PARERR, "ULP RX parity error", -1, 1},
+               {0}
+       };
+
+       if (t3_handle_intr_status(adapter, A_ULPRX_INT_CAUSE, 0xffffffff,
+                                 ulprx_intr_info, NULL))
+               t3_fatal_err(adapter);
+}
+
+/*
+ * ULP TX interrupt handler.
+ */
+static void ulptx_intr_handler(struct adapter *adapter)
+{
+       static const struct intr_info ulptx_intr_info[] = {
+               {F_PBL_BOUND_ERR_CH0, "ULP TX channel 0 PBL out of bounds",
+                STAT_ULP_CH0_PBL_OOB, 0},
+               {F_PBL_BOUND_ERR_CH1, "ULP TX channel 1 PBL out of bounds",
+                STAT_ULP_CH1_PBL_OOB, 0},
+               {0}
+       };
+
+       if (t3_handle_intr_status(adapter, A_ULPTX_INT_CAUSE, 0xffffffff,
+                                 ulptx_intr_info, adapter->irq_stats))
+               t3_fatal_err(adapter);
+}
+
+#define ICSPI_FRM_ERR (F_ICSPI0_FIFO2X_RX_FRAMING_ERROR | \
+       F_ICSPI1_FIFO2X_RX_FRAMING_ERROR | F_ICSPI0_RX_FRAMING_ERROR | \
+       F_ICSPI1_RX_FRAMING_ERROR | F_ICSPI0_TX_FRAMING_ERROR | \
+       F_ICSPI1_TX_FRAMING_ERROR)
+#define OESPI_FRM_ERR (F_OESPI0_RX_FRAMING_ERROR | \
+       F_OESPI1_RX_FRAMING_ERROR | F_OESPI0_TX_FRAMING_ERROR | \
+       F_OESPI1_TX_FRAMING_ERROR | F_OESPI0_OFIFO2X_TX_FRAMING_ERROR | \
+       F_OESPI1_OFIFO2X_TX_FRAMING_ERROR)
+
+/*
+ * PM TX interrupt handler.
+ */
+static void pmtx_intr_handler(struct adapter *adapter)
+{
+       static const struct intr_info pmtx_intr_info[] = {
+               {F_ZERO_C_CMD_ERROR, "PMTX 0-length pcmd", -1, 1},
+               {ICSPI_FRM_ERR, "PMTX ispi framing error", -1, 1},
+               {OESPI_FRM_ERR, "PMTX ospi framing error", -1, 1},
+               {V_ICSPI_PAR_ERROR(M_ICSPI_PAR_ERROR),
+                "PMTX ispi parity error", -1, 1},
+               {V_OESPI_PAR_ERROR(M_OESPI_PAR_ERROR),
+                "PMTX ospi parity error", -1, 1},
+               {0}
+       };
+
+       if (t3_handle_intr_status(adapter, A_PM1_TX_INT_CAUSE, 0xffffffff,
+                                 pmtx_intr_info, NULL))
+               t3_fatal_err(adapter);
+}
+
+#define IESPI_FRM_ERR (F_IESPI0_FIFO2X_RX_FRAMING_ERROR | \
+       F_IESPI1_FIFO2X_RX_FRAMING_ERROR | F_IESPI0_RX_FRAMING_ERROR | \
+       F_IESPI1_RX_FRAMING_ERROR | F_IESPI0_TX_FRAMING_ERROR | \
+       F_IESPI1_TX_FRAMING_ERROR)
+#define OCSPI_FRM_ERR (F_OCSPI0_RX_FRAMING_ERROR | \
+       F_OCSPI1_RX_FRAMING_ERROR | F_OCSPI0_TX_FRAMING_ERROR | \
+       F_OCSPI1_TX_FRAMING_ERROR | F_OCSPI0_OFIFO2X_TX_FRAMING_ERROR | \
+       F_OCSPI1_OFIFO2X_TX_FRAMING_ERROR)
+
+/*
+ * PM RX interrupt handler.
+ */
+static void pmrx_intr_handler(struct adapter *adapter)
+{
+       static const struct intr_info pmrx_intr_info[] = {
+               {F_ZERO_E_CMD_ERROR, "PMRX 0-length pcmd", -1, 1},
+               {IESPI_FRM_ERR, "PMRX ispi framing error", -1, 1},
+               {OCSPI_FRM_ERR, "PMRX ospi framing error", -1, 1},
+               {V_IESPI_PAR_ERROR(M_IESPI_PAR_ERROR),
+                "PMRX ispi parity error", -1, 1},
+               {V_OCSPI_PAR_ERROR(M_OCSPI_PAR_ERROR),
+                "PMRX ospi parity error", -1, 1},
+               {0}
+       };
+
+       if (t3_handle_intr_status(adapter, A_PM1_RX_INT_CAUSE, 0xffffffff,
+                                 pmrx_intr_info, NULL))
+               t3_fatal_err(adapter);
+}
+
+/*
+ * CPL switch interrupt handler.
+ */
+static void cplsw_intr_handler(struct adapter *adapter)
+{
+       static const struct intr_info cplsw_intr_info[] = {
+/*             { F_CIM_OVFL_ERROR, "CPL switch CIM overflow", -1, 1 }, */
+               {F_TP_FRAMING_ERROR, "CPL switch TP framing error", -1, 1},
+               {F_SGE_FRAMING_ERROR, "CPL switch SGE framing error", -1, 1},
+               {F_CIM_FRAMING_ERROR, "CPL switch CIM framing error", -1, 1},
+               {F_ZERO_SWITCH_ERROR, "CPL switch no-switch error", -1, 1},
+               {0}
+       };
+
+       if (t3_handle_intr_status(adapter, A_CPL_INTR_CAUSE, 0xffffffff,
+                                 cplsw_intr_info, NULL))
+               t3_fatal_err(adapter);
+}
+
+/*
+ * MPS interrupt handler.
+ */
+static void mps_intr_handler(struct adapter *adapter)
+{
+       static const struct intr_info mps_intr_info[] = {
+               {0x1ff, "MPS parity error", -1, 1},
+               {0}
+       };
+
+       if (t3_handle_intr_status(adapter, A_MPS_INT_CAUSE, 0xffffffff,
+                                 mps_intr_info, NULL))
+               t3_fatal_err(adapter);
+}
+
+#define MC7_INTR_FATAL (F_UE | V_PE(M_PE) | F_AE)
+
+/*
+ * MC7 interrupt handler.
+ */
+static void mc7_intr_handler(struct mc7 *mc7)
+{
+       struct adapter *adapter = mc7->adapter;
+       u32 cause = t3_read_reg(adapter, mc7->offset + A_MC7_INT_CAUSE);
+
+       if (cause & F_CE) {
+               mc7->stats.corr_err++;
+               CH_WARN(adapter, "%s MC7 correctable error at addr 0x%x, "
+                       "data 0x%x 0x%x 0x%x\n", mc7->name,
+                       t3_read_reg(adapter, mc7->offset + A_MC7_CE_ADDR),
+                       t3_read_reg(adapter, mc7->offset + A_MC7_CE_DATA0),
+                       t3_read_reg(adapter, mc7->offset + A_MC7_CE_DATA1),
+                       t3_read_reg(adapter, mc7->offset + A_MC7_CE_DATA2));
+       }
+
+       if (cause & F_UE) {
+               mc7->stats.uncorr_err++;
+               CH_ALERT(adapter, "%s MC7 uncorrectable error at addr 0x%x, "
+                        "data 0x%x 0x%x 0x%x\n", mc7->name,
+                        t3_read_reg(adapter, mc7->offset + A_MC7_UE_ADDR),
+                        t3_read_reg(adapter, mc7->offset + A_MC7_UE_DATA0),
+                        t3_read_reg(adapter, mc7->offset + A_MC7_UE_DATA1),
+                        t3_read_reg(adapter, mc7->offset + A_MC7_UE_DATA2));
+       }
+
+       if (G_PE(cause)) {
+               mc7->stats.parity_err++;
+               CH_ALERT(adapter, "%s MC7 parity error 0x%x\n",
+                        mc7->name, G_PE(cause));
+       }
+
+       if (cause & F_AE) {
+               u32 addr = 0;
+
+               if (adapter->params.rev > 0)
+                       addr = t3_read_reg(adapter,
+                                          mc7->offset + A_MC7_ERR_ADDR);
+               mc7->stats.addr_err++;
+               CH_ALERT(adapter, "%s MC7 address error: 0x%x\n",
+                        mc7->name, addr);
+       }
+
+       if (cause & MC7_INTR_FATAL)
+               t3_fatal_err(adapter);
+
+       t3_write_reg(adapter, mc7->offset + A_MC7_INT_CAUSE, cause);
+}
+
+#define XGM_INTR_FATAL (V_TXFIFO_PRTY_ERR(M_TXFIFO_PRTY_ERR) | \
+                       V_RXFIFO_PRTY_ERR(M_RXFIFO_PRTY_ERR))
+/*
+ * XGMAC interrupt handler.
+ */
+static int mac_intr_handler(struct adapter *adap, unsigned int idx)
+{
+       struct cmac *mac = &adap2pinfo(adap, idx)->mac;
+       u32 cause = t3_read_reg(adap, A_XGM_INT_CAUSE + mac->offset);
+
+       if (cause & V_TXFIFO_PRTY_ERR(M_TXFIFO_PRTY_ERR)) {
+               mac->stats.tx_fifo_parity_err++;
+               CH_ALERT(adap, "port%d: MAC TX FIFO parity error\n", idx);
+       }
+       if (cause & V_RXFIFO_PRTY_ERR(M_RXFIFO_PRTY_ERR)) {
+               mac->stats.rx_fifo_parity_err++;
+               CH_ALERT(adap, "port%d: MAC RX FIFO parity error\n", idx);
+       }
+       if (cause & F_TXFIFO_UNDERRUN)
+               mac->stats.tx_fifo_urun++;
+       if (cause & F_RXFIFO_OVERFLOW)
+               mac->stats.rx_fifo_ovfl++;
+       if (cause & V_SERDES_LOS(M_SERDES_LOS))
+               mac->stats.serdes_signal_loss++;
+       if (cause & F_XAUIPCSCTCERR)
+               mac->stats.xaui_pcs_ctc_err++;
+       if (cause & F_XAUIPCSALIGNCHANGE)
+               mac->stats.xaui_pcs_align_change++;
+
+       t3_write_reg(adap, A_XGM_INT_CAUSE + mac->offset, cause);
+       if (cause & XGM_INTR_FATAL)
+               t3_fatal_err(adap);
+       return cause != 0;
+}
+
+/*
+ * Interrupt handler for PHY events.
+ */
+int t3_phy_intr_handler(struct adapter *adapter)
+{
+       static const int intr_gpio_bits[] = { 8, 0x20 };
+
+       u32 i, cause = t3_read_reg(adapter, A_T3DBG_INT_CAUSE);
+
+       for_each_port(adapter, i) {
+               if (cause & intr_gpio_bits[i]) {
+                       struct cphy *phy = &adap2pinfo(adapter, i)->phy;
+                       int phy_cause = phy->ops->intr_handler(phy);
+
+                       if (phy_cause & cphy_cause_link_change)
+                               t3_link_changed(adapter, i);
+                       if (phy_cause & cphy_cause_fifo_error)
+                               phy->fifo_errors++;
+               }
+       }
+
+       t3_write_reg(adapter, A_T3DBG_INT_CAUSE, cause);
+       return 0;
+}
+
+/*
+ * T3 slow path (non-data) interrupt handler.
+ */
+int t3_slow_intr_handler(struct adapter *adapter)
+{
+       u32 cause = t3_read_reg(adapter, A_PL_INT_CAUSE0);
+
+       cause &= adapter->slow_intr_mask;
+       if (!cause)
+               return 0;
+       if (cause & F_PCIM0) {
+               if (is_pcie(adapter))
+                       pcie_intr_handler(adapter);
+               else
+                       pci_intr_handler(adapter);
+       }
+       if (cause & F_SGE3)
+               t3_sge_err_intr_handler(adapter);
+       if (cause & F_MC7_PMRX)
+               mc7_intr_handler(&adapter->pmrx);
+       if (cause & F_MC7_PMTX)
+               mc7_intr_handler(&adapter->pmtx);
+       if (cause & F_MC7_CM)
+               mc7_intr_handler(&adapter->cm);
+       if (cause & F_CIM)
+               cim_intr_handler(adapter);
+       if (cause & F_TP1)
+               tp_intr_handler(adapter);
+       if (cause & F_ULP2_RX)
+               ulprx_intr_handler(adapter);
+       if (cause & F_ULP2_TX)
+               ulptx_intr_handler(adapter);
+       if (cause & F_PM1_RX)
+               pmrx_intr_handler(adapter);
+       if (cause & F_PM1_TX)
+               pmtx_intr_handler(adapter);
+       if (cause & F_CPL_SWITCH)
+               cplsw_intr_handler(adapter);
+       if (cause & F_MPS0)
+               mps_intr_handler(adapter);
+       if (cause & F_MC5A)
+               t3_mc5_intr_handler(&adapter->mc5);
+       if (cause & F_XGMAC0_0)
+               mac_intr_handler(adapter, 0);
+       if (cause & F_XGMAC0_1)
+               mac_intr_handler(adapter, 1);
+       if (cause & F_T3DBG)
+               t3_os_ext_intr_handler(adapter);
+
+       /* Clear the interrupts just processed. */
+       t3_write_reg(adapter, A_PL_INT_CAUSE0, cause);
+       t3_read_reg(adapter, A_PL_INT_CAUSE0);  /* flush */
+       return 1;
+}
+
+/**
+ *     t3_intr_enable - enable interrupts
+ *     @adapter: the adapter whose interrupts should be enabled
+ *
+ *     Enable interrupts by setting the interrupt enable registers of the
+ *     various HW modules and then enabling the top-level interrupt
+ *     concentrator.
+ */
+void t3_intr_enable(struct adapter *adapter)
+{
+       static const struct addr_val_pair intr_en_avp[] = {
+               {A_SG_INT_ENABLE, SGE_INTR_MASK},
+               {A_MC7_INT_ENABLE, MC7_INTR_MASK},
+               {A_MC7_INT_ENABLE - MC7_PMRX_BASE_ADDR + MC7_PMTX_BASE_ADDR,
+                MC7_INTR_MASK},
+               {A_MC7_INT_ENABLE - MC7_PMRX_BASE_ADDR + MC7_CM_BASE_ADDR,
+                MC7_INTR_MASK},
+               {A_MC5_DB_INT_ENABLE, MC5_INTR_MASK},
+               {A_ULPRX_INT_ENABLE, ULPRX_INTR_MASK},
+               {A_TP_INT_ENABLE, 0x3bfffff},
+               {A_PM1_TX_INT_ENABLE, PMTX_INTR_MASK},
+               {A_PM1_RX_INT_ENABLE, PMRX_INTR_MASK},
+               {A_CIM_HOST_INT_ENABLE, CIM_INTR_MASK},
+               {A_MPS_INT_ENABLE, MPS_INTR_MASK},
+       };
+
+       adapter->slow_intr_mask = PL_INTR_MASK;
+
+       t3_write_regs(adapter, intr_en_avp, ARRAY_SIZE(intr_en_avp), 0);
+
+       if (adapter->params.rev > 0) {
+               t3_write_reg(adapter, A_CPL_INTR_ENABLE,
+                            CPLSW_INTR_MASK | F_CIM_OVFL_ERROR);
+               t3_write_reg(adapter, A_ULPTX_INT_ENABLE,
+                            ULPTX_INTR_MASK | F_PBL_BOUND_ERR_CH0 |
+                            F_PBL_BOUND_ERR_CH1);
+       } else {
+               t3_write_reg(adapter, A_CPL_INTR_ENABLE, CPLSW_INTR_MASK);
+               t3_write_reg(adapter, A_ULPTX_INT_ENABLE, ULPTX_INTR_MASK);
+       }
+
+       t3_write_reg(adapter, A_T3DBG_GPIO_ACT_LOW,
+                    adapter_info(adapter)->gpio_intr);
+       t3_write_reg(adapter, A_T3DBG_INT_ENABLE,
+                    adapter_info(adapter)->gpio_intr);
+       if (is_pcie(adapter))
+               t3_write_reg(adapter, A_PCIE_INT_ENABLE, PCIE_INTR_MASK);
+       else
+               t3_write_reg(adapter, A_PCIX_INT_ENABLE, PCIX_INTR_MASK);
+       t3_write_reg(adapter, A_PL_INT_ENABLE0, adapter->slow_intr_mask);
+       t3_read_reg(adapter, A_PL_INT_ENABLE0); /* flush */
+}
+
+/**
+ *     t3_intr_disable - disable a card's interrupts
+ *     @adapter: the adapter whose interrupts should be disabled
+ *
+ *     Disable interrupts.  We only disable the top-level interrupt
+ *     concentrator and the SGE data interrupts.
+ */
+void t3_intr_disable(struct adapter *adapter)
+{
+       t3_write_reg(adapter, A_PL_INT_ENABLE0, 0);
+       t3_read_reg(adapter, A_PL_INT_ENABLE0); /* flush */
+       adapter->slow_intr_mask = 0;
+}
+
+/**
+ *     t3_intr_clear - clear all interrupts
+ *     @adapter: the adapter whose interrupts should be cleared
+ *
+ *     Clears all interrupts.
+ */
+void t3_intr_clear(struct adapter *adapter)
+{
+       static const unsigned int cause_reg_addr[] = {
+               A_SG_INT_CAUSE,
+               A_SG_RSPQ_FL_STATUS,
+               A_PCIX_INT_CAUSE,
+               A_MC7_INT_CAUSE,
+               A_MC7_INT_CAUSE - MC7_PMRX_BASE_ADDR + MC7_PMTX_BASE_ADDR,
+               A_MC7_INT_CAUSE - MC7_PMRX_BASE_ADDR + MC7_CM_BASE_ADDR,
+               A_CIM_HOST_INT_CAUSE,
+               A_TP_INT_CAUSE,
+               A_MC5_DB_INT_CAUSE,
+               A_ULPRX_INT_CAUSE,
+               A_ULPTX_INT_CAUSE,
+               A_CPL_INTR_CAUSE,
+               A_PM1_TX_INT_CAUSE,
+               A_PM1_RX_INT_CAUSE,
+               A_MPS_INT_CAUSE,
+               A_T3DBG_INT_CAUSE,
+       };
+       unsigned int i;
+
+       /* Clear PHY and MAC interrupts for each port. */
+       for_each_port(adapter, i)
+           t3_port_intr_clear(adapter, i);
+
+       for (i = 0; i < ARRAY_SIZE(cause_reg_addr); ++i)
+               t3_write_reg(adapter, cause_reg_addr[i], 0xffffffff);
+
+       t3_write_reg(adapter, A_PL_INT_CAUSE0, 0xffffffff);
+       t3_read_reg(adapter, A_PL_INT_CAUSE0);  /* flush */
+}
+
+/**
+ *     t3_port_intr_enable - enable port-specific interrupts
+ *     @adapter: associated adapter
+ *     @idx: index of port whose interrupts should be enabled
+ *
+ *     Enable port-specific (i.e., MAC and PHY) interrupts for the given
+ *     adapter port.
+ */
+void t3_port_intr_enable(struct adapter *adapter, int idx)
+{
+       struct cphy *phy = &adap2pinfo(adapter, idx)->phy;
+
+       t3_write_reg(adapter, XGM_REG(A_XGM_INT_ENABLE, idx), XGM_INTR_MASK);
+       t3_read_reg(adapter, XGM_REG(A_XGM_INT_ENABLE, idx)); /* flush */
+       phy->ops->intr_enable(phy);
+}
+
+/**
+ *     t3_port_intr_disable - disable port-specific interrupts
+ *     @adapter: associated adapter
+ *     @idx: index of port whose interrupts should be disabled
+ *
+ *     Disable port-specific (i.e., MAC and PHY) interrupts for the given
+ *     adapter port.
+ */
+void t3_port_intr_disable(struct adapter *adapter, int idx)
+{
+       struct cphy *phy = &adap2pinfo(adapter, idx)->phy;
+
+       t3_write_reg(adapter, XGM_REG(A_XGM_INT_ENABLE, idx), 0);
+       t3_read_reg(adapter, XGM_REG(A_XGM_INT_ENABLE, idx)); /* flush */
+       phy->ops->intr_disable(phy);
+}
+
+/**
+ *     t3_port_intr_clear - clear port-specific interrupts
+ *     @adapter: associated adapter
+ *     @idx: index of port whose interrupts to clear
+ *
+ *     Clear port-specific (i.e., MAC and PHY) interrupts for the given
+ *     adapter port.
+ */
+void t3_port_intr_clear(struct adapter *adapter, int idx)
+{
+       struct cphy *phy = &adap2pinfo(adapter, idx)->phy;
+
+       t3_write_reg(adapter, XGM_REG(A_XGM_INT_CAUSE, idx), 0xffffffff);
+       t3_read_reg(adapter, XGM_REG(A_XGM_INT_CAUSE, idx)); /* flush */
+       phy->ops->intr_clear(phy);
+}
+
+/**
+ *     t3_sge_write_context - write an SGE context
+ *     @adapter: the adapter
+ *     @id: the context id
+ *     @type: the context type
+ *
+ *     Program an SGE context with the values already loaded in the
+ *     CONTEXT_DATA? registers.
+ */
+static int t3_sge_write_context(struct adapter *adapter, unsigned int id,
+                               unsigned int type)
+{
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK0, 0xffffffff);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK1, 0xffffffff);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK2, 0xffffffff);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK3, 0xffffffff);
+       t3_write_reg(adapter, A_SG_CONTEXT_CMD,
+                    V_CONTEXT_CMD_OPCODE(1) | type | V_CONTEXT(id));
+       return t3_wait_op_done(adapter, A_SG_CONTEXT_CMD, F_CONTEXT_CMD_BUSY,
+                              0, 5, 1);
+}
+
+/**
+ *     t3_sge_init_ecntxt - initialize an SGE egress context
+ *     @adapter: the adapter to configure
+ *     @id: the context id
+ *     @gts_enable: whether to enable GTS for the context
+ *     @type: the egress context type
+ *     @respq: associated response queue
+ *     @base_addr: base address of queue
+ *     @size: number of queue entries
+ *     @token: uP token
+ *     @gen: initial generation value for the context
+ *     @cidx: consumer pointer
+ *
+ *     Initialize an SGE egress context and make it ready for use.  If the
+ *     platform allows concurrent context operations, the caller is
+ *     responsible for appropriate locking.
+ */
+int t3_sge_init_ecntxt(struct adapter *adapter, unsigned int id, int gts_enable,
+                      enum sge_context_type type, int respq, u64 base_addr,
+                      unsigned int size, unsigned int token, int gen,
+                      unsigned int cidx)
+{
+       unsigned int credits = type == SGE_CNTXT_OFLD ? 0 : FW_WR_NUM;
+
+       if (base_addr & 0xfff)  /* must be 4K aligned */
+               return -EINVAL;
+       if (t3_read_reg(adapter, A_SG_CONTEXT_CMD) & F_CONTEXT_CMD_BUSY)
+               return -EBUSY;
+
+       base_addr >>= 12;
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA0, V_EC_INDEX(cidx) |
+                    V_EC_CREDITS(credits) | V_EC_GTS(gts_enable));
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA1, V_EC_SIZE(size) |
+                    V_EC_BASE_LO(base_addr & 0xffff));
+       base_addr >>= 16;
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA2, base_addr);
+       base_addr >>= 32;
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA3,
+                    V_EC_BASE_HI(base_addr & 0xf) | V_EC_RESPQ(respq) |
+                    V_EC_TYPE(type) | V_EC_GEN(gen) | V_EC_UP_TOKEN(token) |
+                    F_EC_VALID);
+       return t3_sge_write_context(adapter, id, F_EGRESS);
+}
+
+/**
+ *     t3_sge_init_flcntxt - initialize an SGE free-buffer list context
+ *     @adapter: the adapter to configure
+ *     @id: the context id
+ *     @gts_enable: whether to enable GTS for the context
+ *     @base_addr: base address of queue
+ *     @size: number of queue entries
+ *     @bsize: size of each buffer for this queue
+ *     @cong_thres: threshold to signal congestion to upstream producers
+ *     @gen: initial generation value for the context
+ *     @cidx: consumer pointer
+ *
+ *     Initialize an SGE free list context and make it ready for use.  The
+ *     caller is responsible for ensuring only one context operation occurs
+ *     at a time.
+ */
+int t3_sge_init_flcntxt(struct adapter *adapter, unsigned int id,
+                       int gts_enable, u64 base_addr, unsigned int size,
+                       unsigned int bsize, unsigned int cong_thres, int gen,
+                       unsigned int cidx)
+{
+       if (base_addr & 0xfff)  /* must be 4K aligned */
+               return -EINVAL;
+       if (t3_read_reg(adapter, A_SG_CONTEXT_CMD) & F_CONTEXT_CMD_BUSY)
+               return -EBUSY;
+
+       base_addr >>= 12;
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA0, base_addr);
+       base_addr >>= 32;
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA1,
+                    V_FL_BASE_HI((u32) base_addr) |
+                    V_FL_INDEX_LO(cidx & M_FL_INDEX_LO));
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA2, V_FL_SIZE(size) |
+                    V_FL_GEN(gen) | V_FL_INDEX_HI(cidx >> 12) |
+                    V_FL_ENTRY_SIZE_LO(bsize & M_FL_ENTRY_SIZE_LO));
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA3,
+                    V_FL_ENTRY_SIZE_HI(bsize >> (32 - S_FL_ENTRY_SIZE_LO)) |
+                    V_FL_CONG_THRES(cong_thres) | V_FL_GTS(gts_enable));
+       return t3_sge_write_context(adapter, id, F_FREELIST);
+}
+
+/**
+ *     t3_sge_init_rspcntxt - initialize an SGE response queue context
+ *     @adapter: the adapter to configure
+ *     @id: the context id
+ *     @irq_vec_idx: MSI-X interrupt vector index, 0 if no MSI-X, -1 if no IRQ
+ *     @base_addr: base address of queue
+ *     @size: number of queue entries
+ *     @fl_thres: threshold for selecting the normal or jumbo free list
+ *     @gen: initial generation value for the context
+ *     @cidx: consumer pointer
+ *
+ *     Initialize an SGE response queue context and make it ready for use.
+ *     The caller is responsible for ensuring only one context operation
+ *     occurs at a time.
+ */
+int t3_sge_init_rspcntxt(struct adapter *adapter, unsigned int id,
+                        int irq_vec_idx, u64 base_addr, unsigned int size,
+                        unsigned int fl_thres, int gen, unsigned int cidx)
+{
+       unsigned int intr = 0;
+
+       if (base_addr & 0xfff)  /* must be 4K aligned */
+               return -EINVAL;
+       if (t3_read_reg(adapter, A_SG_CONTEXT_CMD) & F_CONTEXT_CMD_BUSY)
+               return -EBUSY;
+
+       base_addr >>= 12;
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA0, V_CQ_SIZE(size) |
+                    V_CQ_INDEX(cidx));
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA1, base_addr);
+       base_addr >>= 32;
+       if (irq_vec_idx >= 0)
+               intr = V_RQ_MSI_VEC(irq_vec_idx) | F_RQ_INTR_EN;
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA2,
+                    V_CQ_BASE_HI((u32) base_addr) | intr | V_RQ_GEN(gen));
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA3, fl_thres);
+       return t3_sge_write_context(adapter, id, F_RESPONSEQ);
+}
+
+/**
+ *     t3_sge_init_cqcntxt - initialize an SGE completion queue context
+ *     @adapter: the adapter to configure
+ *     @id: the context id
+ *     @base_addr: base address of queue
+ *     @size: number of queue entries
+ *     @rspq: response queue for async notifications
+ *     @ovfl_mode: CQ overflow mode
+ *     @credits: completion queue credits
+ *     @credit_thres: the credit threshold
+ *
+ *     Initialize an SGE completion queue context and make it ready for use.
+ *     The caller is responsible for ensuring only one context operation
+ *     occurs at a time.
+ */
+int t3_sge_init_cqcntxt(struct adapter *adapter, unsigned int id, u64 base_addr,
+                       unsigned int size, int rspq, int ovfl_mode,
+                       unsigned int credits, unsigned int credit_thres)
+{
+       if (base_addr & 0xfff)  /* must be 4K aligned */
+               return -EINVAL;
+       if (t3_read_reg(adapter, A_SG_CONTEXT_CMD) & F_CONTEXT_CMD_BUSY)
+               return -EBUSY;
+
+       base_addr >>= 12;
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA0, V_CQ_SIZE(size));
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA1, base_addr);
+       base_addr >>= 32;
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA2,
+                    V_CQ_BASE_HI((u32) base_addr) | V_CQ_RSPQ(rspq) |
+                    V_CQ_GEN(1) | V_CQ_OVERFLOW_MODE(ovfl_mode));
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA3, V_CQ_CREDITS(credits) |
+                    V_CQ_CREDIT_THRES(credit_thres));
+       return t3_sge_write_context(adapter, id, F_CQ);
+}
+
+/**
+ *     t3_sge_enable_ecntxt - enable/disable an SGE egress context
+ *     @adapter: the adapter
+ *     @id: the egress context id
+ *     @enable: enable (1) or disable (0) the context
+ *
+ *     Enable or disable an SGE egress context.  The caller is responsible for
+ *     ensuring only one context operation occurs at a time.
+ */
+int t3_sge_enable_ecntxt(struct adapter *adapter, unsigned int id, int enable)
+{
+       if (t3_read_reg(adapter, A_SG_CONTEXT_CMD) & F_CONTEXT_CMD_BUSY)
+               return -EBUSY;
+
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK0, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK1, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK2, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK3, F_EC_VALID);
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA3, V_EC_VALID(enable));
+       t3_write_reg(adapter, A_SG_CONTEXT_CMD,
+                    V_CONTEXT_CMD_OPCODE(1) | F_EGRESS | V_CONTEXT(id));
+       return t3_wait_op_done(adapter, A_SG_CONTEXT_CMD, F_CONTEXT_CMD_BUSY,
+                              0, 5, 1);
+}
+
+/**
+ *     t3_sge_disable_fl - disable an SGE free-buffer list
+ *     @adapter: the adapter
+ *     @id: the free list context id
+ *
+ *     Disable an SGE free-buffer list.  The caller is responsible for
+ *     ensuring only one context operation occurs at a time.
+ */
+int t3_sge_disable_fl(struct adapter *adapter, unsigned int id)
+{
+       if (t3_read_reg(adapter, A_SG_CONTEXT_CMD) & F_CONTEXT_CMD_BUSY)
+               return -EBUSY;
+
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK0, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK1, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK2, V_FL_SIZE(M_FL_SIZE));
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK3, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA2, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_CMD,
+                    V_CONTEXT_CMD_OPCODE(1) | F_FREELIST | V_CONTEXT(id));
+       return t3_wait_op_done(adapter, A_SG_CONTEXT_CMD, F_CONTEXT_CMD_BUSY,
+                              0, 5, 1);
+}
+
+/**
+ *     t3_sge_disable_rspcntxt - disable an SGE response queue
+ *     @adapter: the adapter
+ *     @id: the response queue context id
+ *
+ *     Disable an SGE response queue.  The caller is responsible for
+ *     ensuring only one context operation occurs at a time.
+ */
+int t3_sge_disable_rspcntxt(struct adapter *adapter, unsigned int id)
+{
+       if (t3_read_reg(adapter, A_SG_CONTEXT_CMD) & F_CONTEXT_CMD_BUSY)
+               return -EBUSY;
+
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK0, V_CQ_SIZE(M_CQ_SIZE));
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK1, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK2, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK3, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA0, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_CMD,
+                    V_CONTEXT_CMD_OPCODE(1) | F_RESPONSEQ | V_CONTEXT(id));
+       return t3_wait_op_done(adapter, A_SG_CONTEXT_CMD, F_CONTEXT_CMD_BUSY,
+                              0, 5, 1);
+}
+
+/**
+ *     t3_sge_disable_cqcntxt - disable an SGE completion queue
+ *     @adapter: the adapter
+ *     @id: the completion queue context id
+ *
+ *     Disable an SGE completion queue.  The caller is responsible for
+ *     ensuring only one context operation occurs at a time.
+ */
+int t3_sge_disable_cqcntxt(struct adapter *adapter, unsigned int id)
+{
+       if (t3_read_reg(adapter, A_SG_CONTEXT_CMD) & F_CONTEXT_CMD_BUSY)
+               return -EBUSY;
+
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK0, V_CQ_SIZE(M_CQ_SIZE));
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK1, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK2, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_MASK3, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA0, 0);
+       t3_write_reg(adapter, A_SG_CONTEXT_CMD,
+                    V_CONTEXT_CMD_OPCODE(1) | F_CQ | V_CONTEXT(id));
+       return t3_wait_op_done(adapter, A_SG_CONTEXT_CMD, F_CONTEXT_CMD_BUSY,
+                              0, 5, 1);
+}
+
+/**
+ *     t3_sge_cqcntxt_op - perform an operation on a completion queue context
+ *     @adapter: the adapter
+ *     @id: the context id
+ *     @op: the operation to perform
+ *
+ *     Perform the selected operation on an SGE completion queue context.
+ *     The caller is responsible for ensuring only one context operation
+ *     occurs at a time.
+ */
+int t3_sge_cqcntxt_op(struct adapter *adapter, unsigned int id, unsigned int op,
+                     unsigned int credits)
+{
+       u32 val;
+
+       if (t3_read_reg(adapter, A_SG_CONTEXT_CMD) & F_CONTEXT_CMD_BUSY)
+               return -EBUSY;
+
+       t3_write_reg(adapter, A_SG_CONTEXT_DATA0, credits << 16);
+       t3_write_reg(adapter, A_SG_CONTEXT_CMD, V_CONTEXT_CMD_OPCODE(op) |
+                    V_CONTEXT(id) | F_CQ);
+       if (t3_wait_op_done_val(adapter, A_SG_CONTEXT_CMD, F_CONTEXT_CMD_BUSY,
+                               0, 5, 1, &val))
+               return -EIO;
+
+       if (op >= 2 && op < 7) {
+               if (adapter->params.rev > 0)
+                       return G_CQ_INDEX(val);
+
+               t3_write_reg(adapter, A_SG_CONTEXT_CMD,
+                            V_CONTEXT_CMD_OPCODE(0) | F_CQ | V_CONTEXT(id));
+               if (t3_wait_op_done(adapter, A_SG_CONTEXT_CMD,
+                                   F_CONTEXT_CMD_BUSY, 0, 5, 1))
+                       return -EIO;
+               return G_CQ_INDEX(t3_read_reg(adapter, A_SG_CONTEXT_DATA0));
+       }
+       return 0;
+}
+
+/**
+ *     t3_sge_read_context - read an SGE context
+ *     @type: the context type
+ *     @adapter: the adapter
+ *     @id: the context id
+ *     @data: holds the retrieved context
+ *
+ *     Read an SGE egress context.  The caller is responsible for ensuring
+ *     only one context operation occurs at a time.
+ */
+static int t3_sge_read_context(unsigned int type, struct adapter *adapter,
+                              unsigned int id, u32 data[4])
+{
+       if (t3_read_reg(adapter, A_SG_CONTEXT_CMD) & F_CONTEXT_CMD_BUSY)
+               return -EBUSY;
+
+       t3_write_reg(adapter, A_SG_CONTEXT_CMD,
+                    V_CONTEXT_CMD_OPCODE(0) | type | V_CONTEXT(id));
+       if (t3_wait_op_done(adapter, A_SG_CONTEXT_CMD, F_CONTEXT_CMD_BUSY, 0,
+                           5, 1))
+               return -EIO;
+       data[0] = t3_read_reg(adapter, A_SG_CONTEXT_DATA0);
+       data[1] = t3_read_reg(adapter, A_SG_CONTEXT_DATA1);
+       data[2] = t3_read_reg(adapter, A_SG_CONTEXT_DATA2);
+       data[3] = t3_read_reg(adapter, A_SG_CONTEXT_DATA3);
+       return 0;
+}
+
+/**
+ *     t3_sge_read_ecntxt - read an SGE egress context
+ *     @adapter: the adapter
+ *     @id: the context id
+ *     @data: holds the retrieved context
+ *
+ *     Read an SGE egress context.  The caller is responsible for ensuring
+ *     only one context operation occurs at a time.
+ */
+int t3_sge_read_ecntxt(struct adapter *adapter, unsigned int id, u32 data[4])
+{
+       if (id >= 65536)
+               return -EINVAL;
+       return t3_sge_read_context(F_EGRESS, adapter, id, data);
+}
+
+/**
+ *     t3_sge_read_cq - read an SGE CQ context
+ *     @adapter: the adapter
+ *     @id: the context id
+ *     @data: holds the retrieved context
+ *
+ *     Read an SGE CQ context.  The caller is responsible for ensuring
+ *     only one context operation occurs at a time.
+ */
+int t3_sge_read_cq(struct adapter *adapter, unsigned int id, u32 data[4])
+{
+       if (id >= 65536)
+               return -EINVAL;
+       return t3_sge_read_context(F_CQ, adapter, id, data);
+}
+
+/**
+ *     t3_sge_read_fl - read an SGE free-list context
+ *     @adapter: the adapter
+ *     @id: the context id
+ *     @data: holds the retrieved context
+ *
+ *     Read an SGE free-list context.  The caller is responsible for ensuring
+ *     only one context operation occurs at a time.
+ */
+int t3_sge_read_fl(struct adapter *adapter, unsigned int id, u32 data[4])
+{
+       if (id >= SGE_QSETS * 2)
+               return -EINVAL;
+       return t3_sge_read_context(F_FREELIST, adapter, id, data);
+}
+
+/**
+ *     t3_sge_read_rspq - read an SGE response queue context
+ *     @adapter: the adapter
+ *     @id: the context id
+ *     @data: holds the retrieved context
+ *
+ *     Read an SGE response queue context.  The caller is responsible for
+ *     ensuring only one context operation occurs at a time.
+ */
+int t3_sge_read_rspq(struct adapter *adapter, unsigned int id, u32 data[4])
+{
+       if (id >= SGE_QSETS)
+               return -EINVAL;
+       return t3_sge_read_context(F_RESPONSEQ, adapter, id, data);
+}
+
+/**
+ *     t3_config_rss - configure Rx packet steering
+ *     @adapter: the adapter
+ *     @rss_config: RSS settings (written to TP_RSS_CONFIG)
+ *     @cpus: values for the CPU lookup table (0xff terminated)
+ *     @rspq: values for the response queue lookup table (0xffff terminated)
+ *
+ *     Programs the receive packet steering logic.  @cpus and @rspq provide
+ *     the values for the CPU and response queue lookup tables.  If they
+ *     provide fewer values than the size of the tables the supplied values
+ *     are used repeatedly until the tables are fully populated.
+ */
+void t3_config_rss(struct adapter *adapter, unsigned int rss_config,
+                  const u8 * cpus, const u16 *rspq)
+{
+       int i, j, cpu_idx = 0, q_idx = 0;
+
+       if (cpus)
+               for (i = 0; i < RSS_TABLE_SIZE; ++i) {
+                       u32 val = i << 16;
+
+                       for (j = 0; j < 2; ++j) {
+                               val |= (cpus[cpu_idx++] & 0x3f) << (8 * j);
+                               if (cpus[cpu_idx] == 0xff)
+                                       cpu_idx = 0;
+                       }
+                       t3_write_reg(adapter, A_TP_RSS_LKP_TABLE, val);
+               }
+
+       if (rspq)
+               for (i = 0; i < RSS_TABLE_SIZE; ++i) {
+                       t3_write_reg(adapter, A_TP_RSS_MAP_TABLE,
+                                    (i << 16) | rspq[q_idx++]);
+                       if (rspq[q_idx] == 0xffff)
+                               q_idx = 0;
+               }
+
+       t3_write_reg(adapter, A_TP_RSS_CONFIG, rss_config);
+}
+
+/**
+ *     t3_read_rss - read the contents of the RSS tables
+ *     @adapter: the adapter
+ *     @lkup: holds the contents of the RSS lookup table
+ *     @map: holds the contents of the RSS map table
+ *
+ *     Reads the contents of the receive packet steering tables.
+ */
+int t3_read_rss(struct adapter *adapter, u8 * lkup, u16 *map)
+{
+       int i;
+       u32 val;
+
+       if (lkup)
+               for (i = 0; i < RSS_TABLE_SIZE; ++i) {
+                       t3_write_reg(adapter, A_TP_RSS_LKP_TABLE,
+                                    0xffff0000 | i);
+                       val = t3_read_reg(adapter, A_TP_RSS_LKP_TABLE);
+                       if (!(val & 0x80000000))
+                               return -EAGAIN;
+                       *lkup++ = val;
+                       *lkup++ = (val >> 8);
+               }
+
+       if (map)
+               for (i = 0; i < RSS_TABLE_SIZE; ++i) {
+                       t3_write_reg(adapter, A_TP_RSS_MAP_TABLE,
+                                    0xffff0000 | i);
+                       val = t3_read_reg(adapter, A_TP_RSS_MAP_TABLE);
+                       if (!(val & 0x80000000))
+                               return -EAGAIN;
+                       *map++ = val;
+               }
+       return 0;
+}
+
+/**
+ *     t3_tp_set_offload_mode - put TP in NIC/offload mode
+ *     @adap: the adapter
+ *     @enable: 1 to select offload mode, 0 for regular NIC
+ *
+ *     Switches TP to NIC/offload mode.
+ */
+void t3_tp_set_offload_mode(struct adapter *adap, int enable)
+{
+       if (is_offload(adap) || !enable)
+               t3_set_reg_field(adap, A_TP_IN_CONFIG, F_NICMODE,
+                                V_NICMODE(!enable));
+}
+
+/**
+ *     pm_num_pages - calculate the number of pages of the payload memory
+ *     @mem_size: the size of the payload memory
+ *     @pg_size: the size of each payload memory page
+ *
+ *     Calculate the number of pages, each of the given size, that fit in a
+ *     memory of the specified size, respecting the HW requirement that the
+ *     number of pages must be a multiple of 24.
+ */
+static inline unsigned int pm_num_pages(unsigned int mem_size,
+                                       unsigned int pg_size)
+{
+       unsigned int n = mem_size / pg_size;
+
+       return n - n % 24;
+}
+
+#define mem_region(adap, start, size, reg) \
+       t3_write_reg((adap), A_ ## reg, (start)); \
+       start += size
+
+/*
+ *     partition_mem - partition memory and configure TP memory settings
+ *     @adap: the adapter
+ *     @p: the TP parameters
+ *
+ *     Partitions context and payload memory and configures TP's memory
+ *     registers.
+ */
+static void partition_mem(struct adapter *adap, const struct tp_params *p)
+{
+       unsigned int m, pstructs, tids = t3_mc5_size(&adap->mc5);
+       unsigned int timers = 0, timers_shift = 22;
+
+       if (adap->params.rev > 0) {
+               if (tids <= 16 * 1024) {
+                       timers = 1;
+                       timers_shift = 16;
+               } else if (tids <= 64 * 1024) {
+                       timers = 2;
+                       timers_shift = 18;
+               } else if (tids <= 256 * 1024) {
+                       timers = 3;
+                       timers_shift = 20;
+               }
+       }
+
+       t3_write_reg(adap, A_TP_PMM_SIZE,
+                    p->chan_rx_size | (p->chan_tx_size >> 16));
+
+       t3_write_reg(adap, A_TP_PMM_TX_BASE, 0);
+       t3_write_reg(adap, A_TP_PMM_TX_PAGE_SIZE, p->tx_pg_size);
+       t3_write_reg(adap, A_TP_PMM_TX_MAX_PAGE, p->tx_num_pgs);
+       t3_set_reg_field(adap, A_TP_PARA_REG3, V_TXDATAACKIDX(M_TXDATAACKIDX),
+                        V_TXDATAACKIDX(fls(p->tx_pg_size) - 12));
+
+       t3_write_reg(adap, A_TP_PMM_RX_BASE, 0);
+       t3_write_reg(adap, A_TP_PMM_RX_PAGE_SIZE, p->rx_pg_size);
+       t3_write_reg(adap, A_TP_PMM_RX_MAX_PAGE, p->rx_num_pgs);
+
+       pstructs = p->rx_num_pgs + p->tx_num_pgs;
+       /* Add a bit of headroom and make multiple of 24 */
+       pstructs += 48;
+       pstructs -= pstructs % 24;
+       t3_write_reg(adap, A_TP_CMM_MM_MAX_PSTRUCT, pstructs);
+
+       m = tids * TCB_SIZE;
+       mem_region(adap, m, (64 << 10) * 64, SG_EGR_CNTX_BADDR);
+       mem_region(adap, m, (64 << 10) * 64, SG_CQ_CONTEXT_BADDR);
+       t3_write_reg(adap, A_TP_CMM_TIMER_BASE, V_CMTIMERMAXNUM(timers) | m);
+       m += ((p->ntimer_qs - 1) << timers_shift) + (1 << 22);
+       mem_region(adap, m, pstructs * 64, TP_CMM_MM_BASE);
+       mem_region(adap, m, 64 * (pstructs / 24), TP_CMM_MM_PS_FLST_BASE);
+       mem_region(adap, m, 64 * (p->rx_num_pgs / 24), TP_CMM_MM_RX_FLST_BASE);
+       mem_region(adap, m, 64 * (p->tx_num_pgs / 24), TP_CMM_MM_TX_FLST_BASE);
+
+       m = (m + 4095) & ~0xfff;
+       t3_write_reg(adap, A_CIM_SDRAM_BASE_ADDR, m);
+       t3_write_reg(adap, A_CIM_SDRAM_ADDR_SIZE, p->cm_size - m);
+
+       tids = (p->cm_size - m - (3 << 20)) / 3072 - 32;
+       m = t3_mc5_size(&adap->mc5) - adap->params.mc5.nservers -
+           adap->params.mc5.nfilters - adap->params.mc5.nroutes;
+       if (tids < m)
+               adap->params.mc5.nservers += m - tids;
+}
+
+static inline void tp_wr_indirect(struct adapter *adap, unsigned int addr,
+                                 u32 val)
+{
+       t3_write_reg(adap, A_TP_PIO_ADDR, addr);
+       t3_write_reg(adap, A_TP_PIO_DATA, val);
+}
+
+static void tp_config(struct adapter *adap, const struct tp_params *p)
+{
+       t3_write_reg(adap, A_TP_GLOBAL_CONFIG, F_TXPACINGENABLE | F_PATHMTU |
+                    F_IPCHECKSUMOFFLOAD | F_UDPCHECKSUMOFFLOAD |
+                    F_TCPCHECKSUMOFFLOAD | V_IPTTL(64));
+       t3_write_reg(adap, A_TP_TCP_OPTIONS, V_MTUDEFAULT(576) |
+                    F_MTUENABLE | V_WINDOWSCALEMODE(1) |
+                    V_TIMESTAMPSMODE(1) | V_SACKMODE(1) | V_SACKRX(1));
+       t3_write_reg(adap, A_TP_DACK_CONFIG, V_AUTOSTATE3(1) |
+                    V_AUTOSTATE2(1) | V_AUTOSTATE1(0) |
+                    V_BYTETHRESHOLD(16384) | V_MSSTHRESHOLD(2) |
+                    F_AUTOCAREFUL | F_AUTOENABLE | V_DACK_MODE(1));
+       t3_set_reg_field(adap, A_TP_IN_CONFIG, F_IPV6ENABLE | F_NICMODE,
+                        F_IPV6ENABLE | F_NICMODE);
+       t3_write_reg(adap, A_TP_TX_RESOURCE_LIMIT, 0x18141814);
+       t3_write_reg(adap, A_TP_PARA_REG4, 0x5050105);
+       t3_set_reg_field(adap, A_TP_PARA_REG6,
+                        adap->params.rev > 0 ? F_ENABLEESND : F_T3A_ENABLEESND,
+                        0);
+
+       t3_set_reg_field(adap, A_TP_PC_CONFIG,
+                        F_ENABLEEPCMDAFULL | F_ENABLEOCSPIFULL,
+                        F_TXDEFERENABLE | F_HEARBEATDACK | F_TXCONGESTIONMODE |
+                        F_RXCONGESTIONMODE);
+       t3_set_reg_field(adap, A_TP_PC_CONFIG2, F_CHDRAFULL, 0);
+
+       if (adap->params.rev > 0) {
+               tp_wr_indirect(adap, A_TP_EGRESS_CONFIG, F_REWRITEFORCETOSIZE);
+               t3_set_reg_field(adap, A_TP_PARA_REG3, F_TXPACEAUTO,
+                                F_TXPACEAUTO);
+               t3_set_reg_field(adap, A_TP_PC_CONFIG, F_LOCKTID, F_LOCKTID);
+               t3_set_reg_field(adap, A_TP_PARA_REG3, 0, F_TXPACEAUTOSTRICT);
+       } else
+               t3_set_reg_field(adap, A_TP_PARA_REG3, 0, F_TXPACEFIXED);
+
+       t3_write_reg(adap, A_TP_TX_MOD_QUEUE_WEIGHT1, 0x12121212);
+       t3_write_reg(adap, A_TP_TX_MOD_QUEUE_WEIGHT0, 0x12121212);
+       t3_write_reg(adap, A_TP_MOD_CHANNEL_WEIGHT, 0x1212);
+}
+
+/* Desired TP timer resolution in usec */
+#define TP_TMR_RES 50
+
+/* TCP timer values in ms */
+#define TP_DACK_TIMER 50
+#define TP_RTO_MIN    250
+
+/**
+ *     tp_set_timers - set TP timing parameters
+ *     @adap: the adapter to set
+ *     @core_clk: the core clock frequency in Hz
+ *
+ *     Set TP's timing parameters, such as the various timer resolutions and
+ *     the TCP timer values.
+ */
+static void tp_set_timers(struct adapter *adap, unsigned int core_clk)
+{
+       unsigned int tre = fls(core_clk / (1000000 / TP_TMR_RES)) - 1;
+       unsigned int dack_re = fls(core_clk / 5000) - 1;        /* 200us */
+       unsigned int tstamp_re = fls(core_clk / 1000);  /* 1ms, at least */
+       unsigned int tps = core_clk >> tre;
+
+       t3_write_reg(adap, A_TP_TIMER_RESOLUTION, V_TIMERRESOLUTION(tre) |
+                    V_DELAYEDACKRESOLUTION(dack_re) |
+                    V_TIMESTAMPRESOLUTION(tstamp_re));
+       t3_write_reg(adap, A_TP_DACK_TIMER,
+                    (core_clk >> dack_re) / (1000 / TP_DACK_TIMER));
+       t3_write_reg(adap, A_TP_TCP_BACKOFF_REG0, 0x3020100);
+       t3_write_reg(adap, A_TP_TCP_BACKOFF_REG1, 0x7060504);
+       t3_write_reg(adap, A_TP_TCP_BACKOFF_REG2, 0xb0a0908);
+       t3_write_reg(adap, A_TP_TCP_BACKOFF_REG3, 0xf0e0d0c);
+       t3_write_reg(adap, A_TP_SHIFT_CNT, V_SYNSHIFTMAX(6) |
+                    V_RXTSHIFTMAXR1(4) | V_RXTSHIFTMAXR2(15) |
+                    V_PERSHIFTBACKOFFMAX(8) | V_PERSHIFTMAX(8) |
+                    V_KEEPALIVEMAX(9));
+
+#define SECONDS * tps
+
+       t3_write_reg(adap, A_TP_MSL, adap->params.rev > 0 ? 0 : 2 SECONDS);
+       t3_write_reg(adap, A_TP_RXT_MIN, tps / (1000 / TP_RTO_MIN));
+       t3_write_reg(adap, A_TP_RXT_MAX, 64 SECONDS);
+       t3_write_reg(adap, A_TP_PERS_MIN, 5 SECONDS);
+       t3_write_reg(adap, A_TP_PERS_MAX, 64 SECONDS);
+       t3_write_reg(adap, A_TP_KEEP_IDLE, 7200 SECONDS);
+       t3_write_reg(adap, A_TP_KEEP_INTVL, 75 SECONDS);
+       t3_write_reg(adap, A_TP_INIT_SRTT, 3 SECONDS);
+       t3_write_reg(adap, A_TP_FINWAIT2_TIMER, 600 SECONDS);
+
+#undef SECONDS
+}
+
+/**
+ *     t3_tp_set_coalescing_size - set receive coalescing size
+ *     @adap: the adapter
+ *     @size: the receive coalescing size
+ *     @psh: whether a set PSH bit should deliver coalesced data
+ *
+ *     Set the receive coalescing size and PSH bit handling.
+ */
+int t3_tp_set_coalescing_size(struct adapter *adap, unsigned int size, int psh)
+{
+       u32 val;
+
+       if (size > MAX_RX_COALESCING_LEN)
+               return -EINVAL;
+
+       val = t3_read_reg(adap, A_TP_PARA_REG3);
+       val &= ~(F_RXCOALESCEENABLE | F_RXCOALESCEPSHEN);
+
+       if (size) {
+               val |= F_RXCOALESCEENABLE;
+               if (psh)
+                       val |= F_RXCOALESCEPSHEN;
+               t3_write_reg(adap, A_TP_PARA_REG2, V_RXCOALESCESIZE(size) |
+                            V_MAXRXDATA(MAX_RX_COALESCING_LEN));
+       }
+       t3_write_reg(adap, A_TP_PARA_REG3, val);
+       return 0;
+}
+
+/**
+ *     t3_tp_set_max_rxsize - set the max receive size
+ *     @adap: the adapter
+ *     @size: the max receive size
+ *
+ *     Set TP's max receive size.  This is the limit that applies when
+ *     receive coalescing is disabled.
+ */
+void t3_tp_set_max_rxsize(struct adapter *adap, unsigned int size)
+{
+       t3_write_reg(adap, A_TP_PARA_REG7,
+                    V_PMMAXXFERLEN0(size) | V_PMMAXXFERLEN1(size));
+}
+
+static void __devinit init_mtus(unsigned short mtus[])
+{
+       /*
+        * See draft-mathis-plpmtud-00.txt for the values.  The min is 88 so
+        * it can accomodate max size TCP/IP headers when SACK and timestamps
+        * are enabled and still have at least 8 bytes of payload.
+        */
+       mtus[0] = 88;
+       mtus[1] = 256;
+       mtus[2] = 512;
+       mtus[3] = 576;
+       mtus[4] = 808;
+       mtus[5] = 1024;
+       mtus[6] = 1280;
+       mtus[7] = 1492;
+       mtus[8] = 1500;
+       mtus[9] = 2002;
+       mtus[10] = 2048;
+       mtus[11] = 4096;
+       mtus[12] = 4352;
+       mtus[13] = 8192;
+       mtus[14] = 9000;
+       mtus[15] = 9600;
+}
+
+/*
+ * Initial congestion control parameters.
+ */
+static void __devinit init_cong_ctrl(unsigned short *a, unsigned short *b)
+{
+       a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = a[8] = 1;
+       a[9] = 2;
+       a[10] = 3;
+       a[11] = 4;
+       a[12] = 5;
+       a[13] = 6;
+       a[14] = 7;
+       a[15] = 8;
+       a[16] = 9;
+       a[17] = 10;
+       a[18] = 14;
+       a[19] = 17;
+       a[20] = 21;
+       a[21] = 25;
+       a[22] = 30;
+       a[23] = 35;
+       a[24] = 45;
+       a[25] = 60;
+       a[26] = 80;
+       a[27] = 100;
+       a[28] = 200;
+       a[29] = 300;
+       a[30] = 400;
+       a[31] = 500;
+
+       b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = b[6] = b[7] = b[8] = 0;
+       b[9] = b[10] = 1;
+       b[11] = b[12] = 2;
+       b[13] = b[14] = b[15] = b[16] = 3;
+       b[17] = b[18] = b[19] = b[20] = b[21] = 4;
+       b[22] = b[23] = b[24] = b[25] = b[26] = b[27] = 5;
+       b[28] = b[29] = 6;
+       b[30] = b[31] = 7;
+}
+
+/* The minimum additive increment value for the congestion control table */
+#define CC_MIN_INCR 2U
+
+/**
+ *     t3_load_mtus - write the MTU and congestion control HW tables
+ *     @adap: the adapter
+ *     @mtus: the unrestricted values for the MTU table
+ *     @alphs: the values for the congestion control alpha parameter
+ *     @beta: the values for the congestion control beta parameter
+ *     @mtu_cap: the maximum permitted effective MTU
+ *
+ *     Write the MTU table with the supplied MTUs capping each at &mtu_cap.
+ *     Update the high-speed congestion control table with the supplied alpha,
+ *     beta, and MTUs.
+ */
+void t3_load_mtus(struct adapter *adap, unsigned short mtus[NMTUS],
+                 unsigned short alpha[NCCTRL_WIN],
+                 unsigned short beta[NCCTRL_WIN], unsigned short mtu_cap)
+{
+       static const unsigned int avg_pkts[NCCTRL_WIN] = {
+               2, 6, 10, 14, 20, 28, 40, 56, 80, 112, 160, 224, 320, 448, 640,
+               896, 1281, 1792, 2560, 3584, 5120, 7168, 10240, 14336, 20480,
+               28672, 40960, 57344, 81920, 114688, 163840, 229376
+       };
+
+       unsigned int i, w;
+
+       for (i = 0; i < NMTUS; ++i) {
+               unsigned int mtu = min(mtus[i], mtu_cap);
+               unsigned int log2 = fls(mtu);
+
+               if (!(mtu & ((1 << log2) >> 2)))        /* round */
+                       log2--;
+               t3_write_reg(adap, A_TP_MTU_TABLE,
+                            (i << 24) | (log2 << 16) | mtu);
+
+               for (w = 0; w < NCCTRL_WIN; ++w) {
+                       unsigned int inc;
+
+                       inc = max(((mtu - 40) * alpha[w]) / avg_pkts[w],
+                                 CC_MIN_INCR);
+
+                       t3_write_reg(adap, A_TP_CCTRL_TABLE, (i << 21) |
+                                    (w << 16) | (beta[w] << 13) | inc);
+               }
+       }
+}
+
+/**
+ *     t3_read_hw_mtus - returns the values in the HW MTU table
+ *     @adap: the adapter
+ *     @mtus: where to store the HW MTU values
+ *
+ *     Reads the HW MTU table.
+ */
+void t3_read_hw_mtus(struct adapter *adap, unsigned short mtus[NMTUS])
+{
+       int i;
+
+       for (i = 0; i < NMTUS; ++i) {
+               unsigned int val;
+
+               t3_write_reg(adap, A_TP_MTU_TABLE, 0xff000000 | i);
+               val = t3_read_reg(adap, A_TP_MTU_TABLE);
+               mtus[i] = val & 0x3fff;
+       }
+}
+
+/**
+ *     t3_get_cong_cntl_tab - reads the congestion control table
+ *     @adap: the adapter
+ *     @incr: where to store the alpha values
+ *
+ *     Reads the additive increments programmed into the HW congestion
+ *     control table.
+ */
+void t3_get_cong_cntl_tab(struct adapter *adap,
+                         unsigned short incr[NMTUS][NCCTRL_WIN])
+{
+       unsigned int mtu, w;
+
+       for (mtu = 0; mtu < NMTUS; ++mtu)
+               for (w = 0; w < NCCTRL_WIN; ++w) {
+                       t3_write_reg(adap, A_TP_CCTRL_TABLE,
+                                    0xffff0000 | (mtu << 5) | w);
+                       incr[mtu][w] = t3_read_reg(adap, A_TP_CCTRL_TABLE) &
+                                      0x1fff;
+               }
+}
+
+/**
+ *     t3_tp_get_mib_stats - read TP's MIB counters
+ *     @adap: the adapter
+ *     @tps: holds the returned counter values
+ *
+ *     Returns the values of TP's MIB counters.
+ */
+void t3_tp_get_mib_stats(struct adapter *adap, struct tp_mib_stats *tps)
+{
+       t3_read_indirect(adap, A_TP_MIB_INDEX, A_TP_MIB_RDATA, (u32 *) tps,
+                        sizeof(*tps) / sizeof(u32), 0);
+}
+
+#define ulp_region(adap, name, start, len) \
+       t3_write_reg((adap), A_ULPRX_ ## name ## _LLIMIT, (start)); \
+       t3_write_reg((adap), A_ULPRX_ ## name ## _ULIMIT, \
+                    (start) + (len) - 1); \
+       start += len
+
+#define ulptx_region(adap, name, start, len) \
+       t3_write_reg((adap), A_ULPTX_ ## name ## _LLIMIT, (start)); \
+       t3_write_reg((adap), A_ULPTX_ ## name ## _ULIMIT, \
+                    (start) + (len) - 1)
+
+static void ulp_config(struct adapter *adap, const struct tp_params *p)
+{
+       unsigned int m = p->chan_rx_size;
+
+       ulp_region(adap, ISCSI, m, p->chan_rx_size / 8);
+       ulp_region(adap, TDDP, m, p->chan_rx_size / 8);
+       ulptx_region(adap, TPT, m, p->chan_rx_size / 4);
+       ulp_region(adap, STAG, m, p->chan_rx_size / 4);
+       ulp_region(adap, RQ, m, p->chan_rx_size / 4);
+       ulptx_region(adap, PBL, m, p->chan_rx_size / 4);
+       ulp_region(adap, PBL, m, p->chan_rx_size / 4);
+       t3_write_reg(adap, A_ULPRX_TDDP_TAGMASK, 0xffffffff);
+}
+
+void t3_config_trace_filter(struct adapter *adapter,
+                           const struct trace_params *tp, int filter_index,
+                           int invert, int enable)
+{
+       u32 addr, key[4], mask[4];
+
+       key[0] = tp->sport | (tp->sip << 16);
+       key[1] = (tp->sip >> 16) | (tp->dport << 16);
+       key[2] = tp->dip;
+       key[3] = tp->proto | (tp->vlan << 8) | (tp->intf << 20);
+
+       mask[0] = tp->sport_mask | (tp->sip_mask << 16);
+       mask[1] = (tp->sip_mask >> 16) | (tp->dport_mask << 16);
+       mask[2] = tp->dip_mask;
+       mask[3] = tp->proto_mask | (tp->vlan_mask << 8) | (tp->intf_mask << 20);
+
+       if (invert)
+               key[3] |= (1 << 29);
+       if (enable)
+               key[3] |= (1 << 28);
+
+       addr = filter_index ? A_TP_RX_TRC_KEY0 : A_TP_TX_TRC_KEY0;
+       tp_wr_indirect(adapter, addr++, key[0]);
+       tp_wr_indirect(adapter, addr++, mask[0]);
+       tp_wr_indirect(adapter, addr++, key[1]);
+       tp_wr_indirect(adapter, addr++, mask[1]);
+       tp_wr_indirect(adapter, addr++, key[2]);
+       tp_wr_indirect(adapter, addr++, mask[2]);
+       tp_wr_indirect(adapter, addr++, key[3]);
+       tp_wr_indirect(adapter, addr, mask[3]);
+       t3_read_reg(adapter, A_TP_PIO_DATA);
+}
+
+/**
+ *     t3_config_sched - configure a HW traffic scheduler
+ *     @adap: the adapter
+ *     @kbps: target rate in Kbps
+ *     @sched: the scheduler index
+ *
+ *     Configure a HW scheduler for the target rate
+ */
+int t3_config_sched(struct adapter *adap, unsigned int kbps, int sched)
+{
+       unsigned int v, tps, cpt, bpt, delta, mindelta = ~0;
+       unsigned int clk = adap->params.vpd.cclk * 1000;
+       unsigned int selected_cpt = 0, selected_bpt = 0;
+
+       if (kbps > 0) {
+               kbps *= 125;    /* -> bytes */
+               for (cpt = 1; cpt <= 255; cpt++) {
+                       tps = clk / cpt;
+                       bpt = (kbps + tps / 2) / tps;
+                       if (bpt > 0 && bpt <= 255) {
+                               v = bpt * tps;
+                               delta = v >= kbps ? v - kbps : kbps - v;
+                               if (delta <= mindelta) {
+                                       mindelta = delta;
+                                       selected_cpt = cpt;
+                                       selected_bpt = bpt;
+                               }
+                       } else if (selected_cpt)
+                               break;
+               }
+               if (!selected_cpt)
+                       return -EINVAL;
+       }
+       t3_write_reg(adap, A_TP_TM_PIO_ADDR,
+                    A_TP_TX_MOD_Q1_Q0_RATE_LIMIT - sched / 2);
+       v = t3_read_reg(adap, A_TP_TM_PIO_DATA);
+       if (sched & 1)
+               v = (v & 0xffff) | (selected_cpt << 16) | (selected_bpt << 24);
+       else
+               v = (v & 0xffff0000) | selected_cpt | (selected_bpt << 8);
+       t3_write_reg(adap, A_TP_TM_PIO_DATA, v);
+       return 0;
+}
+
+static int tp_init(struct adapter *adap, const struct tp_params *p)
+{
+       int busy = 0;
+
+       tp_config(adap, p);
+       t3_set_vlan_accel(adap, 3, 0);
+
+       if (is_offload(adap)) {
+               tp_set_timers(adap, adap->params.vpd.cclk * 1000);
+               t3_write_reg(adap, A_TP_RESET, F_FLSTINITENABLE);
+               busy = t3_wait_op_done(adap, A_TP_RESET, F_FLSTINITENABLE,
+                                      0, 1000, 5);
+               if (busy)
+                       CH_ERR(adap, "TP initialization timed out\n");
+       }
+
+       if (!busy)
+               t3_write_reg(adap, A_TP_RESET, F_TPRESET);
+       return busy;
+}
+
+int t3_mps_set_active_ports(struct adapter *adap, unsigned int port_mask)
+{
+       if (port_mask & ~((1 << adap->params.nports) - 1))
+               return -EINVAL;
+       t3_set_reg_field(adap, A_MPS_CFG, F_PORT1ACTIVE | F_PORT0ACTIVE,
+                        port_mask << S_PORT0ACTIVE);
+       return 0;
+}
+
+/*
+ * Perform the bits of HW initialization that are dependent on the number
+ * of available ports.
+ */
+static void init_hw_for_avail_ports(struct adapter *adap, int nports)
+{
+       int i;
+
+       if (nports == 1) {
+               t3_set_reg_field(adap, A_ULPRX_CTL, F_ROUND_ROBIN, 0);
+               t3_set_reg_field(adap, A_ULPTX_CONFIG, F_CFG_RR_ARB, 0);
+               t3_write_reg(adap, A_MPS_CFG, F_TPRXPORTEN | F_TPTXPORT0EN |
+                            F_PORT0ACTIVE | F_ENFORCEPKT);
+               t3_write_reg(adap, A_PM1_TX_CFG, 0xc000c000);
+       } else {
+               t3_set_reg_field(adap, A_ULPRX_CTL, 0, F_ROUND_ROBIN);
+               t3_set_reg_field(adap, A_ULPTX_CONFIG, 0, F_CFG_RR_ARB);
+               t3_write_reg(adap, A_ULPTX_DMA_WEIGHT,
+                            V_D1_WEIGHT(16) | V_D0_WEIGHT(16));
+               t3_write_reg(adap, A_MPS_CFG, F_TPTXPORT0EN | F_TPTXPORT1EN |
+                            F_TPRXPORTEN | F_PORT0ACTIVE | F_PORT1ACTIVE |
+                            F_ENFORCEPKT);
+               t3_write_reg(adap, A_PM1_TX_CFG, 0x80008000);
+               t3_set_reg_field(adap, A_TP_PC_CONFIG, 0, F_TXTOSQUEUEMAPMODE);
+               t3_write_reg(adap, A_TP_TX_MOD_QUEUE_REQ_MAP,
+                            V_TX_MOD_QUEUE_REQ_MAP(0xaa));
+               for (i = 0; i < 16; i++)
+                       t3_write_reg(adap, A_TP_TX_MOD_QUE_TABLE,
+                                    (i << 16) | 0x1010);
+       }
+}
+
+static int calibrate_xgm(struct adapter *adapter)
+{
+       if (uses_xaui(adapter)) {
+               unsigned int v, i;
+
+               for (i = 0; i < 5; ++i) {
+                       t3_write_reg(adapter, A_XGM_XAUI_IMP, 0);
+                       t3_read_reg(adapter, A_XGM_XAUI_IMP);
+                       msleep(1);
+                       v = t3_read_reg(adapter, A_XGM_XAUI_IMP);
+                       if (!(v & (F_XGM_CALFAULT | F_CALBUSY))) {
+                               t3_write_reg(adapter, A_XGM_XAUI_IMP,
+                                            V_XAUIIMP(G_CALIMP(v) >> 2));
+                               return 0;
+                       }
+               }
+               CH_ERR(adapter, "MAC calibration failed\n");
+               return -1;
+       } else {
+               t3_write_reg(adapter, A_XGM_RGMII_IMP,
+                            V_RGMIIIMPPD(2) | V_RGMIIIMPPU(3));
+               t3_set_reg_field(adapter, A_XGM_RGMII_IMP, F_XGM_IMPSETUPDATE,
+                                F_XGM_IMPSETUPDATE);
+       }
+       return 0;
+}
+
+static void calibrate_xgm_t3b(struct adapter *adapter)
+{
+       if (!uses_xaui(adapter)) {
+               t3_write_reg(adapter, A_XGM_RGMII_IMP, F_CALRESET |
+                            F_CALUPDATE | V_RGMIIIMPPD(2) | V_RGMIIIMPPU(3));
+               t3_set_reg_field(adapter, A_XGM_RGMII_IMP, F_CALRESET, 0);
+               t3_set_reg_field(adapter, A_XGM_RGMII_IMP, 0,
+                                F_XGM_IMPSETUPDATE);
+               t3_set_reg_field(adapter, A_XGM_RGMII_IMP, F_XGM_IMPSETUPDATE,
+                                0);
+               t3_set_reg_field(adapter, A_XGM_RGMII_IMP, F_CALUPDATE, 0);
+               t3_set_reg_field(adapter, A_XGM_RGMII_IMP, 0, F_CALUPDATE);
+       }
+}
+
+struct mc7_timing_params {
+       unsigned char ActToPreDly;
+       unsigned char ActToRdWrDly;
+       unsigned char PreCyc;
+       unsigned char RefCyc[5];
+       unsigned char BkCyc;
+       unsigned char WrToRdDly;
+       unsigned char RdToWrDly;
+};
+
+/*
+ * Write a value to a register and check that the write completed.  These
+ * writes normally complete in a cycle or two, so one read should suffice.
+ * The very first read exists to flush the posted write to the device.
+ */
+static int wrreg_wait(struct adapter *adapter, unsigned int addr, u32 val)
+{
+       t3_write_reg(adapter, addr, val);
+       t3_read_reg(adapter, addr);     /* flush */
+       if (!(t3_read_reg(adapter, addr) & F_BUSY))
+               return 0;
+       CH_ERR(adapter, "write to MC7 register 0x%x timed out\n", addr);
+       return -EIO;
+}
+
+static int mc7_init(struct mc7 *mc7, unsigned int mc7_clock, int mem_type)
+{
+       static const unsigned int mc7_mode[] = {
+               0x632, 0x642, 0x652, 0x432, 0x442
+       };
+       static const struct mc7_timing_params mc7_timings[] = {
+               {12, 3, 4, {20, 28, 34, 52, 0}, 15, 6, 4},
+               {12, 4, 5, {20, 28, 34, 52, 0}, 16, 7, 4},
+               {12, 5, 6, {20, 28, 34, 52, 0}, 17, 8, 4},
+               {9, 3, 4, {15, 21, 26, 39, 0}, 12, 6, 4},
+               {9, 4, 5, {15, 21, 26, 39, 0}, 13, 7, 4}
+       };
+
+       u32 val;
+       unsigned int width, density, slow, attempts;
+       struct adapter *adapter = mc7->adapter;
+       const struct mc7_timing_params *p = &mc7_timings[mem_type];
+
+       val = t3_read_reg(adapter, mc7->offset + A_MC7_CFG);
+       slow = val & F_SLOW;
+       width = G_WIDTH(val);
+       density = G_DEN(val);
+
+       t3_write_reg(adapter, mc7->offset + A_MC7_CFG, val | F_IFEN);
+       val = t3_read_reg(adapter, mc7->offset + A_MC7_CFG);    /* flush */
+       msleep(1);
+
+       if (!slow) {
+               t3_write_reg(adapter, mc7->offset + A_MC7_CAL, F_SGL_CAL_EN);
+               t3_read_reg(adapter, mc7->offset + A_MC7_CAL);
+               msleep(1);
+               if (t3_read_reg(adapter, mc7->offset + A_MC7_CAL) &
+                   (F_BUSY | F_SGL_CAL_EN | F_CAL_FAULT)) {
+                       CH_ERR(adapter, "%s MC7 calibration timed out\n",
+                              mc7->name);
+                       goto out_fail;
+               }
+       }
+
+       t3_write_reg(adapter, mc7->offset + A_MC7_PARM,
+                    V_ACTTOPREDLY(p->ActToPreDly) |
+                    V_ACTTORDWRDLY(p->ActToRdWrDly) | V_PRECYC(p->PreCyc) |
+                    V_REFCYC(p->RefCyc[density]) | V_BKCYC(p->BkCyc) |
+                    V_WRTORDDLY(p->WrToRdDly) | V_RDTOWRDLY(p->RdToWrDly));
+
+       t3_write_reg(adapter, mc7->offset + A_MC7_CFG,
+                    val | F_CLKEN | F_TERM150);
+       t3_read_reg(adapter, mc7->offset + A_MC7_CFG);  /* flush */
+
+       if (!slow)
+               t3_set_reg_field(adapter, mc7->offset + A_MC7_DLL, F_DLLENB,
+                                F_DLLENB);
+       udelay(1);
+
+       val = slow ? 3 : 6;
+       if (wrreg_wait(adapter, mc7->offset + A_MC7_PRE, 0) ||
+           wrreg_wait(adapter, mc7->offset + A_MC7_EXT_MODE2, 0) ||
+           wrreg_wait(adapter, mc7->offset + A_MC7_EXT_MODE3, 0) ||
+           wrreg_wait(adapter, mc7->offset + A_MC7_EXT_MODE1, val))
+               goto out_fail;
+
+       if (!slow) {
+               t3_write_reg(adapter, mc7->offset + A_MC7_MODE, 0x100);
+               t3_set_reg_field(adapter, mc7->offset + A_MC7_DLL, F_DLLRST, 0);
+               udelay(5);
+       }
+
+       if (wrreg_wait(adapter, mc7->offset + A_MC7_PRE, 0) ||
+           wrreg_wait(adapter, mc7->offset + A_MC7_REF, 0) ||
+           wrreg_wait(adapter, mc7->offset + A_MC7_REF, 0) ||
+           wrreg_wait(adapter, mc7->offset + A_MC7_MODE,
+                      mc7_mode[mem_type]) ||
+           wrreg_wait(adapter, mc7->offset + A_MC7_EXT_MODE1, val | 0x380) ||
+           wrreg_wait(adapter, mc7->offset + A_MC7_EXT_MODE1, val))
+               goto out_fail;
+
+       /* clock value is in KHz */
+       mc7_clock = mc7_clock * 7812 + mc7_clock / 2;   /* ns */
+       mc7_clock /= 1000000;   /* KHz->MHz, ns->us */
+
+       t3_write_reg(adapter, mc7->offset + A_MC7_REF,
+                    F_PERREFEN | V_PREREFDIV(mc7_clock));
+       t3_read_reg(adapter, mc7->offset + A_MC7_REF);  /* flush */
+
+       t3_write_reg(adapter, mc7->offset + A_MC7_ECC, F_ECCGENEN | F_ECCCHKEN);
+       t3_write_reg(adapter, mc7->offset + A_MC7_BIST_DATA, 0);
+       t3_write_reg(adapter, mc7->offset + A_MC7_BIST_ADDR_BEG, 0);
+       t3_write_reg(adapter, mc7->offset + A_MC7_BIST_ADDR_END,
+                    (mc7->size << width) - 1);
+       t3_write_reg(adapter, mc7->offset + A_MC7_BIST_OP, V_OP(1));
+       t3_read_reg(adapter, mc7->offset + A_MC7_BIST_OP);      /* flush */
+
+       attempts = 50;
+       do {
+               msleep(250);
+               val = t3_read_reg(adapter, mc7->offset + A_MC7_BIST_OP);
+       } while ((val & F_BUSY) && --attempts);
+       if (val & F_BUSY) {
+               CH_ERR(adapter, "%s MC7 BIST timed out\n", mc7->name);
+               goto out_fail;
+       }
+
+       /* Enable normal memory accesses. */
+       t3_set_reg_field(adapter, mc7->offset + A_MC7_CFG, 0, F_RDY);
+       return 0;
+
+out_fail:
+       return -1;
+}
+
+static void config_pcie(struct adapter *adap)
+{
+       static const u16 ack_lat[4][6] = {
+               {237, 416, 559, 1071, 2095, 4143},
+               {128, 217, 289, 545, 1057, 2081},
+               {73, 118, 154, 282, 538, 1050},
+               {67, 107, 86, 150, 278, 534}
+       };
+       static const u16 rpl_tmr[4][6] = {
+               {711, 1248, 1677, 3213, 6285, 12429},
+               {384, 651, 867, 1635, 3171, 6243},
+               {219, 354, 462, 846, 1614, 3150},
+               {201, 321, 258, 450, 834, 1602}
+       };
+
+       u16 val;
+       unsigned int log2_width, pldsize;
+       unsigned int fst_trn_rx, fst_trn_tx, acklat, rpllmt;
+
+       pci_read_config_word(adap->pdev,
+                            adap->params.pci.pcie_cap_addr + PCI_EXP_DEVCTL,
+                            &val);
+       pldsize = (val & PCI_EXP_DEVCTL_PAYLOAD) >> 5;
+       pci_read_config_word(adap->pdev,
+                            adap->params.pci.pcie_cap_addr + PCI_EXP_LNKCTL,
+                            &val);
+
+       fst_trn_tx = G_NUMFSTTRNSEQ(t3_read_reg(adap, A_PCIE_PEX_CTRL0));
+       fst_trn_rx = adap->params.rev == 0 ? fst_trn_tx :
+           G_NUMFSTTRNSEQRX(t3_read_reg(adap, A_PCIE_MODE));
+       log2_width = fls(adap->params.pci.width) - 1;
+       acklat = ack_lat[log2_width][pldsize];
+       if (val & 1)            /* check LOsEnable */
+               acklat += fst_trn_tx * 4;
+       rpllmt = rpl_tmr[log2_width][pldsize] + fst_trn_rx * 4;
+
+       if (adap->params.rev == 0)
+               t3_set_reg_field(adap, A_PCIE_PEX_CTRL1,
+                                V_T3A_ACKLAT(M_T3A_ACKLAT),
+                                V_T3A_ACKLAT(acklat));
+       else
+               t3_set_reg_field(adap, A_PCIE_PEX_CTRL1, V_ACKLAT(M_ACKLAT),
+                                V_ACKLAT(acklat));
+
+       t3_set_reg_field(adap, A_PCIE_PEX_CTRL0, V_REPLAYLMT(M_REPLAYLMT),
+                        V_REPLAYLMT(rpllmt));
+
+       t3_write_reg(adap, A_PCIE_PEX_ERR, 0xffffffff);
+       t3_set_reg_field(adap, A_PCIE_CFG, F_PCIE_CLIDECEN, F_PCIE_CLIDECEN);
+}
+
+/*
+ * Initialize and configure T3 HW modules.  This performs the
+ * initialization steps that need to be done once after a card is reset.
+ * MAC and PHY initialization is handled separarely whenever a port is enabled.
+ *
+ * fw_params are passed to FW and their value is platform dependent.  Only the
+ * top 8 bits are available for use, the rest must be 0.
+ */
+int t3_init_hw(struct adapter *adapter, u32 fw_params)
+{
+       int err = -EIO, attempts = 100;
+       const struct vpd_params *vpd = &adapter->params.vpd;
+
+       if (adapter->params.rev > 0)
+               calibrate_xgm_t3b(adapter);
+       else if (calibrate_xgm(adapter))
+               goto out_err;
+
+       if (vpd->mclk) {
+               partition_mem(adapter, &adapter->params.tp);
+
+               if (mc7_init(&adapter->pmrx, vpd->mclk, vpd->mem_timing) ||
+                   mc7_init(&adapter->pmtx, vpd->mclk, vpd->mem_timing) ||
+                   mc7_init(&adapter->cm, vpd->mclk, vpd->mem_timing) ||
+                   t3_mc5_init(&adapter->mc5, adapter->params.mc5.nservers,
+                               adapter->params.mc5.nfilters,
+                               adapter->params.mc5.nroutes))
+                       goto out_err;
+       }
+
+       if (tp_init(adapter, &adapter->params.tp))
+               goto out_err;
+
+       t3_tp_set_coalescing_size(adapter,
+                                 min(adapter->params.sge.max_pkt_size,
+                                     MAX_RX_COALESCING_LEN), 1);
+       t3_tp_set_max_rxsize(adapter,
+                            min(adapter->params.sge.max_pkt_size, 16384U));
+       ulp_config(adapter, &adapter->params.tp);
+
+       if (is_pcie(adapter))
+               config_pcie(adapter);
+       else
+               t3_set_reg_field(adapter, A_PCIX_CFG, 0, F_CLIDECEN);
+
+       t3_write_reg(adapter, A_PM1_RX_CFG, 0xf000f000);
+       init_hw_for_avail_ports(adapter, adapter->params.nports);
+       t3_sge_init(adapter, &adapter->params.sge);
+
+       t3_write_reg(adapter, A_CIM_HOST_ACC_DATA, vpd->uclk | fw_params);
+       t3_write_reg(adapter, A_CIM_BOOT_CFG,
+                    V_BOOTADDR(FW_FLASH_BOOT_ADDR >> 2));
+       t3_read_reg(adapter, A_CIM_BOOT_CFG);   /* flush */
+
+       do {                    /* wait for uP to initialize */
+               msleep(20);
+       } while (t3_read_reg(adapter, A_CIM_HOST_ACC_DATA) && --attempts);
+       if (!attempts)
+               goto out_err;
+
+       err = 0;
+out_err:
+       return err;
+}
+
+/**
+ *     get_pci_mode - determine a card's PCI mode
+ *     @adapter: the adapter
+ *     @p: where to store the PCI settings
+ *
+ *     Determines a card's PCI mode and associated parameters, such as speed
+ *     and width.
+ */
+static void __devinit get_pci_mode(struct adapter *adapter,
+                                  struct pci_params *p)
+{
+       static unsigned short speed_map[] = { 33, 66, 100, 133 };
+       u32 pci_mode, pcie_cap;
+
+       pcie_cap = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
+       if (pcie_cap) {
+               u16 val;
+
+               p->variant = PCI_VARIANT_PCIE;
+               p->pcie_cap_addr = pcie_cap;
+               pci_read_config_word(adapter->pdev, pcie_cap + PCI_EXP_LNKSTA,
+                                       &val);
+               p->width = (val >> 4) & 0x3f;
+               return;
+       }
+
+       pci_mode = t3_read_reg(adapter, A_PCIX_MODE);
+       p->speed = speed_map[G_PCLKRANGE(pci_mode)];
+       p->width = (pci_mode & F_64BIT) ? 64 : 32;
+       pci_mode = G_PCIXINITPAT(pci_mode);
+       if (pci_mode == 0)
+               p->variant = PCI_VARIANT_PCI;
+       else if (pci_mode < 4)
+               p->variant = PCI_VARIANT_PCIX_MODE1_PARITY;
+       else if (pci_mode < 8)
+               p->variant = PCI_VARIANT_PCIX_MODE1_ECC;
+       else
+               p->variant = PCI_VARIANT_PCIX_266_MODE2;
+}
+
+/**
+ *     init_link_config - initialize a link's SW state
+ *     @lc: structure holding the link state
+ *     @ai: information about the current card
+ *
+ *     Initializes the SW state maintained for each link, including the link's
+ *     capabilities and default speed/duplex/flow-control/autonegotiation
+ *     settings.
+ */
+static void __devinit init_link_config(struct link_config *lc,
+                                      unsigned int caps)
+{
+       lc->supported = caps;
+       lc->requested_speed = lc->speed = SPEED_INVALID;
+       lc->requested_duplex = lc->duplex = DUPLEX_INVALID;
+       lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
+       if (lc->supported & SUPPORTED_Autoneg) {
+               lc->advertising = lc->supported;
+               lc->autoneg = AUTONEG_ENABLE;
+               lc->requested_fc |= PAUSE_AUTONEG;
+       } else {
+               lc->advertising = 0;
+               lc->autoneg = AUTONEG_DISABLE;
+       }
+}
+
+/**
+ *     mc7_calc_size - calculate MC7 memory size
+ *     @cfg: the MC7 configuration
+ *
+ *     Calculates the size of an MC7 memory in bytes from the value of its
+ *     configuration register.
+ */
+static unsigned int __devinit mc7_calc_size(u32 cfg)
+{
+       unsigned int width = G_WIDTH(cfg);
+       unsigned int banks = !!(cfg & F_BKS) + 1;
+       unsigned int org = !!(cfg & F_ORG) + 1;
+       unsigned int density = G_DEN(cfg);
+       unsigned int MBs = ((256 << density) * banks) / (org << width);
+
+       return MBs << 20;
+}
+
+static void __devinit mc7_prep(struct adapter *adapter, struct mc7 *mc7,
+                              unsigned int base_addr, const char *name)
+{
+       u32 cfg;
+
+       mc7->adapter = adapter;
+       mc7->name = name;
+       mc7->offset = base_addr - MC7_PMRX_BASE_ADDR;
+       cfg = t3_read_reg(adapter, mc7->offset + A_MC7_CFG);
+       mc7->size = mc7_calc_size(cfg);
+       mc7->width = G_WIDTH(cfg);
+}
+
+void mac_prep(struct cmac *mac, struct adapter *adapter, int index)
+{
+       mac->adapter = adapter;
+       mac->offset = (XGMAC0_1_BASE_ADDR - XGMAC0_0_BASE_ADDR) * index;
+       mac->nucast = 1;
+
+       if (adapter->params.rev == 0 && uses_xaui(adapter)) {
+               t3_write_reg(adapter, A_XGM_SERDES_CTRL + mac->offset,
+                            is_10G(adapter) ? 0x2901c04 : 0x2301c04);
+               t3_set_reg_field(adapter, A_XGM_PORT_CFG + mac->offset,
+                                F_ENRGMII, 0);
+       }
+}
+
+void early_hw_init(struct adapter *adapter, const struct adapter_info *ai)
+{
+       u32 val = V_PORTSPEED(is_10G(adapter) ? 3 : 2);
+
+       mi1_init(adapter, ai);
+       t3_write_reg(adapter, A_I2C_CFG,        /* set for 80KHz */
+                    V_I2C_CLKDIV(adapter->params.vpd.cclk / 80 - 1));
+       t3_write_reg(adapter, A_T3DBG_GPIO_EN,
+                    ai->gpio_out | F_GPIO0_OEN | F_GPIO0_OUT_VAL);
+
+       if (adapter->params.rev == 0 || !uses_xaui(adapter))
+               val |= F_ENRGMII;
+
+       /* Enable MAC clocks so we can access the registers */
+       t3_write_reg(adapter, A_XGM_PORT_CFG, val);
+       t3_read_reg(adapter, A_XGM_PORT_CFG);
+
+       val |= F_CLKDIVRESET_;
+       t3_write_reg(adapter, A_XGM_PORT_CFG, val);
+       t3_read_reg(adapter, A_XGM_PORT_CFG);
+       t3_write_reg(adapter, XGM_REG(A_XGM_PORT_CFG, 1), val);
+       t3_read_reg(adapter, A_XGM_PORT_CFG);
+}
+
+/*
+ * Reset the adapter.  PCIe cards lose their config space during reset, PCI-X
+ * ones don't.
+ */
+int t3_reset_adapter(struct adapter *adapter)
+{
+       int i;
+       uint16_t devid = 0;
+
+       if (is_pcie(adapter))
+               pci_save_state(adapter->pdev);
+       t3_write_reg(adapter, A_PL_RST, F_CRSTWRM | F_CRSTWRMMODE);
+
+       /*
+        * Delay. Give Some time to device to reset fully.
+        * XXX The delay time should be modified.
+        */
+       for (i = 0; i < 10; i++) {
+               msleep(50);
+               pci_read_config_word(adapter->pdev, 0x00, &devid);
+               if (devid == 0x1425)
+                       break;
+       }
+
+       if (devid != 0x1425)
+               return -1;
+
+       if (is_pcie(adapter))
+               pci_restore_state(adapter->pdev);
+       return 0;
+}
+
+/*
+ * Initialize adapter SW state for the various HW modules, set initial values
+ * for some adapter tunables, take PHYs out of reset, and initialize the MDIO
+ * interface.
+ */
+int __devinit t3_prep_adapter(struct adapter *adapter,
+                             const struct adapter_info *ai, int reset)
+{
+       int ret;
+       unsigned int i, j = 0;
+
+       get_pci_mode(adapter, &adapter->params.pci);
+
+       adapter->params.info = ai;
+       adapter->params.nports = ai->nports;
+       adapter->params.rev = t3_read_reg(adapter, A_PL_REV);
+       adapter->params.linkpoll_period = 0;
+       adapter->params.stats_update_period = is_10G(adapter) ?
+           MAC_STATS_ACCUM_SECS : (MAC_STATS_ACCUM_SECS * 10);
+       adapter->params.pci.vpd_cap_addr =
+           pci_find_capability(adapter->pdev, PCI_CAP_ID_VPD);
+       ret = get_vpd_params(adapter, &adapter->params.vpd);
+       if (ret < 0)
+               return ret;
+
+       if (reset && t3_reset_adapter(adapter))
+               return -1;
+
+       t3_sge_prep(adapter, &adapter->params.sge);
+
+       if (adapter->params.vpd.mclk) {
+               struct tp_params *p = &adapter->params.tp;
+
+               mc7_prep(adapter, &adapter->pmrx, MC7_PMRX_BASE_ADDR, "PMRX");
+               mc7_prep(adapter, &adapter->pmtx, MC7_PMTX_BASE_ADDR, "PMTX");
+               mc7_prep(adapter, &adapter->cm, MC7_CM_BASE_ADDR, "CM");
+
+               p->nchan = ai->nports;
+               p->pmrx_size = t3_mc7_size(&adapter->pmrx);
+               p->pmtx_size = t3_mc7_size(&adapter->pmtx);
+               p->cm_size = t3_mc7_size(&adapter->cm);
+               p->chan_rx_size = p->pmrx_size / 2;     /* only 1 Rx channel */
+               p->chan_tx_size = p->pmtx_size / p->nchan;
+               p->rx_pg_size = 64 * 1024;
+               p->tx_pg_size = is_10G(adapter) ? 64 * 1024 : 16 * 1024;
+               p->rx_num_pgs = pm_num_pages(p->chan_rx_size, p->rx_pg_size);
+               p->tx_num_pgs = pm_num_pages(p->chan_tx_size, p->tx_pg_size);
+               p->ntimer_qs = p->cm_size >= (128 << 20) ||
+                   adapter->params.rev > 0 ? 12 : 6;
+
+               adapter->params.mc5.nservers = DEFAULT_NSERVERS;
+               adapter->params.mc5.nfilters = adapter->params.rev > 0 ?
+                   DEFAULT_NFILTERS : 0;
+               adapter->params.mc5.nroutes = 0;
+               t3_mc5_prep(adapter, &adapter->mc5, MC5_MODE_144_BIT);
+
+               init_mtus(adapter->params.mtus);
+               init_cong_ctrl(adapter->params.a_wnd, adapter->params.b_wnd);
+       }
+
+       early_hw_init(adapter, ai);
+
+       for_each_port(adapter, i) {
+               u8 hw_addr[6];
+               struct port_info *p = adap2pinfo(adapter, i);
+
+               while (!adapter->params.vpd.port_type[j])
+                       ++j;
+
+               p->port_type = &port_types[adapter->params.vpd.port_type[j]];
+               p->port_type->phy_prep(&p->phy, adapter, ai->phy_base_addr + j,
+                                      ai->mdio_ops);
+               mac_prep(&p->mac, adapter, j);
+               ++j;
+
+               /*
+                * The VPD EEPROM stores the base Ethernet address for the
+                * card.  A port's address is derived from the base by adding
+                * the port's index to the base's low octet.
+                */
+               memcpy(hw_addr, adapter->params.vpd.eth_base, 5);
+               hw_addr[5] = adapter->params.vpd.eth_base[5] + i;
+
+               memcpy(adapter->port[i]->dev_addr, hw_addr,
+                      ETH_ALEN);
+               memcpy(adapter->port[i]->perm_addr, hw_addr,
+                      ETH_ALEN);
+               init_link_config(&p->link_config, p->port_type->caps);
+               p->phy.ops->power_down(&p->phy, 1);
+               if (!(p->port_type->caps & SUPPORTED_IRQ))
+                       adapter->params.linkpoll_period = 10;
+       }
+
+       return 0;
+}
+
+void t3_led_ready(struct adapter *adapter)
+{
+       t3_set_reg_field(adapter, A_T3DBG_GPIO_EN, F_GPIO0_OUT_VAL,
+                        F_GPIO0_OUT_VAL);
+}
diff --git a/drivers/net/cxgb3/t3cdev.h b/drivers/net/cxgb3/t3cdev.h
new file mode 100644 (file)
index 0000000..9af3bcd
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2006-2007 Chelsio Communications.  All rights reserved.
+ * Copyright (C) 2006-2007 Open Grid Computing, Inc.  All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef _T3CDEV_H_
+#define _T3CDEV_H_
+
+#include <linux/list.h>
+#include <asm/atomic.h>
+#include <asm/semaphore.h>
+#include <linux/netdevice.h>
+#include <linux/proc_fs.h>
+#include <linux/skbuff.h>
+#include <net/neighbour.h>
+
+#define T3CNAMSIZ 16
+
+/* Get the t3cdev associated with a net_device */
+#define T3CDEV(netdev) (struct t3cdev *)(netdev->priv)
+
+struct cxgb3_client;
+
+enum t3ctype {
+       T3A = 0,
+       T3B
+};
+
+struct t3cdev {
+       char name[T3CNAMSIZ];   /* T3C device name */
+       enum t3ctype type;
+       struct list_head ofld_dev_list; /* for list linking */
+       struct net_device *lldev;       /* LL dev associated with T3C messages */
+       struct proc_dir_entry *proc_dir;        /* root of proc dir for this T3C */
+       int (*send)(struct t3cdev *dev, struct sk_buff *skb);
+       int (*recv)(struct t3cdev *dev, struct sk_buff **skb, int n);
+       int (*ctl)(struct t3cdev *dev, unsigned int req, void *data);
+       void (*neigh_update)(struct t3cdev *dev, struct neighbour *neigh);
+       void *priv;             /* driver private data */
+       void *l2opt;            /* optional layer 2 data */
+       void *l3opt;            /* optional layer 3 data */
+       void *l4opt;            /* optional layer 4 data */
+       void *ulp;              /* ulp stuff */
+};
+
+#endif                         /* _T3CDEV_H_ */
diff --git a/drivers/net/cxgb3/version.h b/drivers/net/cxgb3/version.h
new file mode 100644 (file)
index 0000000..2b67dd5
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+/* $Date: 2006/10/31 18:57:51 $ $RCSfile: version.h,v $ $Revision: 1.3 $ */
+#ifndef __CHELSIO_VERSION_H
+#define __CHELSIO_VERSION_H
+#define DRV_DESC "Chelsio T3 Network Driver"
+#define DRV_NAME "cxgb3"
+/* Driver version */
+#define DRV_VERSION "1.0"
+#endif                         /* __CHELSIO_VERSION_H */
diff --git a/drivers/net/cxgb3/vsc8211.c b/drivers/net/cxgb3/vsc8211.c
new file mode 100644 (file)
index 0000000..eee4285
--- /dev/null
@@ -0,0 +1,228 @@
+/*
+ * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "common.h"
+
+/* VSC8211 PHY specific registers. */
+enum {
+       VSC8211_INTR_ENABLE = 25,
+       VSC8211_INTR_STATUS = 26,
+       VSC8211_AUX_CTRL_STAT = 28,
+};
+
+enum {
+       VSC_INTR_RX_ERR = 1 << 0,
+       VSC_INTR_MS_ERR = 1 << 1,       /* master/slave resolution error */
+       VSC_INTR_CABLE = 1 << 2,        /* cable impairment */
+       VSC_INTR_FALSE_CARR = 1 << 3,   /* false carrier */
+       VSC_INTR_MEDIA_CHG = 1 << 4,    /* AMS media change */
+       VSC_INTR_RX_FIFO = 1 << 5,      /* Rx FIFO over/underflow */
+       VSC_INTR_TX_FIFO = 1 << 6,      /* Tx FIFO over/underflow */
+       VSC_INTR_DESCRAMBL = 1 << 7,    /* descrambler lock-lost */
+       VSC_INTR_SYMBOL_ERR = 1 << 8,   /* symbol error */
+       VSC_INTR_NEG_DONE = 1 << 10,    /* autoneg done */
+       VSC_INTR_NEG_ERR = 1 << 11,     /* autoneg error */
+       VSC_INTR_LINK_CHG = 1 << 13,    /* link change */
+       VSC_INTR_ENABLE = 1 << 15,      /* interrupt enable */
+};
+
+#define CFG_CHG_INTR_MASK (VSC_INTR_LINK_CHG | VSC_INTR_NEG_ERR | \
+                          VSC_INTR_NEG_DONE)
+#define INTR_MASK (CFG_CHG_INTR_MASK | VSC_INTR_TX_FIFO | VSC_INTR_RX_FIFO | \
+                  VSC_INTR_ENABLE)
+
+/* PHY specific auxiliary control & status register fields */
+#define S_ACSR_ACTIPHY_TMR    0
+#define M_ACSR_ACTIPHY_TMR    0x3
+#define V_ACSR_ACTIPHY_TMR(x) ((x) << S_ACSR_ACTIPHY_TMR)
+
+#define S_ACSR_SPEED    3
+#define M_ACSR_SPEED    0x3
+#define G_ACSR_SPEED(x) (((x) >> S_ACSR_SPEED) & M_ACSR_SPEED)
+
+#define S_ACSR_DUPLEX 5
+#define F_ACSR_DUPLEX (1 << S_ACSR_DUPLEX)
+
+#define S_ACSR_ACTIPHY 6
+#define F_ACSR_ACTIPHY (1 << S_ACSR_ACTIPHY)
+
+/*
+ * Reset the PHY.  This PHY completes reset immediately so we never wait.
+ */
+static int vsc8211_reset(struct cphy *cphy, int wait)
+{
+       return t3_phy_reset(cphy, 0, 0);
+}
+
+static int vsc8211_intr_enable(struct cphy *cphy)
+{
+       return mdio_write(cphy, 0, VSC8211_INTR_ENABLE, INTR_MASK);
+}
+
+static int vsc8211_intr_disable(struct cphy *cphy)
+{
+       return mdio_write(cphy, 0, VSC8211_INTR_ENABLE, 0);
+}
+
+static int vsc8211_intr_clear(struct cphy *cphy)
+{
+       u32 val;
+
+       /* Clear PHY interrupts by reading the register. */
+       return mdio_read(cphy, 0, VSC8211_INTR_STATUS, &val);
+}
+
+static int vsc8211_autoneg_enable(struct cphy *cphy)
+{
+       return t3_mdio_change_bits(cphy, 0, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE,
+                                  BMCR_ANENABLE | BMCR_ANRESTART);
+}
+
+static int vsc8211_autoneg_restart(struct cphy *cphy)
+{
+       return t3_mdio_change_bits(cphy, 0, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE,
+                                  BMCR_ANRESTART);
+}
+
+static int vsc8211_get_link_status(struct cphy *cphy, int *link_ok,
+                                  int *speed, int *duplex, int *fc)
+{
+       unsigned int bmcr, status, lpa, adv;
+       int err, sp = -1, dplx = -1, pause = 0;
+
+       err = mdio_read(cphy, 0, MII_BMCR, &bmcr);
+       if (!err)
+               err = mdio_read(cphy, 0, MII_BMSR, &status);
+       if (err)
+               return err;
+
+       if (link_ok) {
+               /*
+                * BMSR_LSTATUS is latch-low, so if it is 0 we need to read it
+                * once more to get the current link state.
+                */
+               if (!(status & BMSR_LSTATUS))
+                       err = mdio_read(cphy, 0, MII_BMSR, &status);
+               if (err)
+                       return err;
+               *link_ok = (status & BMSR_LSTATUS) != 0;
+       }
+       if (!(bmcr & BMCR_ANENABLE)) {
+               dplx = (bmcr & BMCR_FULLDPLX) ? DUPLEX_FULL : DUPLEX_HALF;
+               if (bmcr & BMCR_SPEED1000)
+                       sp = SPEED_1000;
+               else if (bmcr & BMCR_SPEED100)
+                       sp = SPEED_100;
+               else
+                       sp = SPEED_10;
+       } else if (status & BMSR_ANEGCOMPLETE) {
+               err = mdio_read(cphy, 0, VSC8211_AUX_CTRL_STAT, &status);
+               if (err)
+                       return err;
+
+               dplx = (status & F_ACSR_DUPLEX) ? DUPLEX_FULL : DUPLEX_HALF;
+               sp = G_ACSR_SPEED(status);
+               if (sp == 0)
+                       sp = SPEED_10;
+               else if (sp == 1)
+                       sp = SPEED_100;
+               else
+                       sp = SPEED_1000;
+
+               if (fc && dplx == DUPLEX_FULL) {
+                       err = mdio_read(cphy, 0, MII_LPA, &lpa);
+                       if (!err)
+                               err = mdio_read(cphy, 0, MII_ADVERTISE, &adv);
+                       if (err)
+                               return err;
+
+                       if (lpa & adv & ADVERTISE_PAUSE_CAP)
+                               pause = PAUSE_RX | PAUSE_TX;
+                       else if ((lpa & ADVERTISE_PAUSE_CAP) &&
+                                (lpa & ADVERTISE_PAUSE_ASYM) &&
+                                (adv & ADVERTISE_PAUSE_ASYM))
+                               pause = PAUSE_TX;
+                       else if ((lpa & ADVERTISE_PAUSE_ASYM) &&
+                                (adv & ADVERTISE_PAUSE_CAP))
+                               pause = PAUSE_RX;
+               }
+       }
+       if (speed)
+               *speed = sp;
+       if (duplex)
+               *duplex = dplx;
+       if (fc)
+               *fc = pause;
+       return 0;
+}
+
+static int vsc8211_power_down(struct cphy *cphy, int enable)
+{
+       return t3_mdio_change_bits(cphy, 0, MII_BMCR, BMCR_PDOWN,
+                                  enable ? BMCR_PDOWN : 0);
+}
+
+static int vsc8211_intr_handler(struct cphy *cphy)
+{
+       unsigned int cause;
+       int err, cphy_cause = 0;
+
+       err = mdio_read(cphy, 0, VSC8211_INTR_STATUS, &cause);
+       if (err)
+               return err;
+
+       cause &= INTR_MASK;
+       if (cause & CFG_CHG_INTR_MASK)
+               cphy_cause |= cphy_cause_link_change;
+       if (cause & (VSC_INTR_RX_FIFO | VSC_INTR_TX_FIFO))
+               cphy_cause |= cphy_cause_fifo_error;
+       return cphy_cause;
+}
+
+static struct cphy_ops vsc8211_ops = {
+       .reset = vsc8211_reset,
+       .intr_enable = vsc8211_intr_enable,
+       .intr_disable = vsc8211_intr_disable,
+       .intr_clear = vsc8211_intr_clear,
+       .intr_handler = vsc8211_intr_handler,
+       .autoneg_enable = vsc8211_autoneg_enable,
+       .autoneg_restart = vsc8211_autoneg_restart,
+       .advertise = t3_phy_advertise,
+       .set_speed_duplex = t3_set_phy_speed_duplex,
+       .get_link_status = vsc8211_get_link_status,
+       .power_down = vsc8211_power_down,
+};
+
+void t3_vsc8211_phy_prep(struct cphy *phy, struct adapter *adapter,
+                        int phy_addr, const struct mdio_ops *mdio_ops)
+{
+       cphy_init(phy, adapter, phy_addr, &vsc8211_ops, mdio_ops);
+}
diff --git a/drivers/net/cxgb3/xgmac.c b/drivers/net/cxgb3/xgmac.c
new file mode 100644 (file)
index 0000000..907a272
--- /dev/null
@@ -0,0 +1,409 @@
+/*
+ * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "common.h"
+#include "regs.h"
+
+/*
+ * # of exact address filters.  The first one is used for the station address,
+ * the rest are available for multicast addresses.
+ */
+#define EXACT_ADDR_FILTERS 8
+
+static inline int macidx(const struct cmac *mac)
+{
+       return mac->offset / (XGMAC0_1_BASE_ADDR - XGMAC0_0_BASE_ADDR);
+}
+
+static void xaui_serdes_reset(struct cmac *mac)
+{
+       static const unsigned int clear[] = {
+               F_PWRDN0 | F_PWRDN1, F_RESETPLL01, F_RESET0 | F_RESET1,
+               F_PWRDN2 | F_PWRDN3, F_RESETPLL23, F_RESET2 | F_RESET3
+       };
+
+       int i;
+       struct adapter *adap = mac->adapter;
+       u32 ctrl = A_XGM_SERDES_CTRL0 + mac->offset;
+
+       t3_write_reg(adap, ctrl, adap->params.vpd.xauicfg[macidx(mac)] |
+                    F_RESET3 | F_RESET2 | F_RESET1 | F_RESET0 |
+                    F_PWRDN3 | F_PWRDN2 | F_PWRDN1 | F_PWRDN0 |
+                    F_RESETPLL23 | F_RESETPLL01);
+       t3_read_reg(adap, ctrl);
+       udelay(15);
+
+       for (i = 0; i < ARRAY_SIZE(clear); i++) {
+               t3_set_reg_field(adap, ctrl, clear[i], 0);
+               udelay(15);
+       }
+}
+
+void t3b_pcs_reset(struct cmac *mac)
+{
+       t3_set_reg_field(mac->adapter, A_XGM_RESET_CTRL + mac->offset,
+                        F_PCS_RESET_, 0);
+       udelay(20);
+       t3_set_reg_field(mac->adapter, A_XGM_RESET_CTRL + mac->offset, 0,
+                        F_PCS_RESET_);
+}
+
+int t3_mac_reset(struct cmac *mac)
+{
+       static const struct addr_val_pair mac_reset_avp[] = {
+               {A_XGM_TX_CTRL, 0},
+               {A_XGM_RX_CTRL, 0},
+               {A_XGM_RX_CFG, F_DISPAUSEFRAMES | F_EN1536BFRAMES |
+                F_RMFCS | F_ENJUMBO | F_ENHASHMCAST},
+               {A_XGM_RX_HASH_LOW, 0},
+               {A_XGM_RX_HASH_HIGH, 0},
+               {A_XGM_RX_EXACT_MATCH_LOW_1, 0},
+               {A_XGM_RX_EXACT_MATCH_LOW_2, 0},
+               {A_XGM_RX_EXACT_MATCH_LOW_3, 0},
+               {A_XGM_RX_EXACT_MATCH_LOW_4, 0},
+               {A_XGM_RX_EXACT_MATCH_LOW_5, 0},
+               {A_XGM_RX_EXACT_MATCH_LOW_6, 0},
+               {A_XGM_RX_EXACT_MATCH_LOW_7, 0},
+               {A_XGM_RX_EXACT_MATCH_LOW_8, 0},
+               {A_XGM_STAT_CTRL, F_CLRSTATS}
+       };
+       u32 val;
+       struct adapter *adap = mac->adapter;
+       unsigned int oft = mac->offset;
+
+       t3_write_reg(adap, A_XGM_RESET_CTRL + oft, F_MAC_RESET_);
+       t3_read_reg(adap, A_XGM_RESET_CTRL + oft);      /* flush */
+
+       t3_write_regs(adap, mac_reset_avp, ARRAY_SIZE(mac_reset_avp), oft);
+       t3_set_reg_field(adap, A_XGM_RXFIFO_CFG + oft,
+                        F_RXSTRFRWRD | F_DISERRFRAMES,
+                        uses_xaui(adap) ? 0 : F_RXSTRFRWRD);
+
+       if (uses_xaui(adap)) {
+               if (adap->params.rev == 0) {
+                       t3_set_reg_field(adap, A_XGM_SERDES_CTRL + oft, 0,
+                                        F_RXENABLE | F_TXENABLE);
+                       if (t3_wait_op_done(adap, A_XGM_SERDES_STATUS1 + oft,
+                                           F_CMULOCK, 1, 5, 2)) {
+                               CH_ERR(adap,
+                                      "MAC %d XAUI SERDES CMU lock failed\n",
+                                      macidx(mac));
+                               return -1;
+                       }
+                       t3_set_reg_field(adap, A_XGM_SERDES_CTRL + oft, 0,
+                                        F_SERDESRESET_);
+               } else
+                       xaui_serdes_reset(mac);
+       }
+
+       if (adap->params.rev > 0)
+               t3_write_reg(adap, A_XGM_PAUSE_TIMER + oft, 0xf000);
+
+       val = F_MAC_RESET_;
+       if (is_10G(adap))
+               val |= F_PCS_RESET_;
+       else if (uses_xaui(adap))
+               val |= F_PCS_RESET_ | F_XG2G_RESET_;
+       else
+               val |= F_RGMII_RESET_ | F_XG2G_RESET_;
+       t3_write_reg(adap, A_XGM_RESET_CTRL + oft, val);
+       t3_read_reg(adap, A_XGM_RESET_CTRL + oft);      /* flush */
+       if ((val & F_PCS_RESET_) && adap->params.rev) {
+               msleep(1);
+               t3b_pcs_reset(mac);
+       }
+
+       memset(&mac->stats, 0, sizeof(mac->stats));
+       return 0;
+}
+
+/*
+ * Set the exact match register 'idx' to recognize the given Ethernet address.
+ */
+static void set_addr_filter(struct cmac *mac, int idx, const u8 * addr)
+{
+       u32 addr_lo, addr_hi;
+       unsigned int oft = mac->offset + idx * 8;
+
+       addr_lo = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0];
+       addr_hi = (addr[5] << 8) | addr[4];
+
+       t3_write_reg(mac->adapter, A_XGM_RX_EXACT_MATCH_LOW_1 + oft, addr_lo);
+       t3_write_reg(mac->adapter, A_XGM_RX_EXACT_MATCH_HIGH_1 + oft, addr_hi);
+}
+
+/* Set one of the station's unicast MAC addresses. */
+int t3_mac_set_address(struct cmac *mac, unsigned int idx, u8 addr[6])
+{
+       if (idx >= mac->nucast)
+               return -EINVAL;
+       set_addr_filter(mac, idx, addr);
+       return 0;
+}
+
+/*
+ * Specify the number of exact address filters that should be reserved for
+ * unicast addresses.  Caller should reload the unicast and multicast addresses
+ * after calling this.
+ */
+int t3_mac_set_num_ucast(struct cmac *mac, int n)
+{
+       if (n > EXACT_ADDR_FILTERS)
+               return -EINVAL;
+       mac->nucast = n;
+       return 0;
+}
+
+/* Calculate the RX hash filter index of an Ethernet address */
+static int hash_hw_addr(const u8 * addr)
+{
+       int hash = 0, octet, bit, i = 0, c;
+
+       for (octet = 0; octet < 6; ++octet)
+               for (c = addr[octet], bit = 0; bit < 8; c >>= 1, ++bit) {
+                       hash ^= (c & 1) << i;
+                       if (++i == 6)
+                               i = 0;
+               }
+       return hash;
+}
+
+int t3_mac_set_rx_mode(struct cmac *mac, struct t3_rx_mode *rm)
+{
+       u32 val, hash_lo, hash_hi;
+       struct adapter *adap = mac->adapter;
+       unsigned int oft = mac->offset;
+
+       val = t3_read_reg(adap, A_XGM_RX_CFG + oft) & ~F_COPYALLFRAMES;
+       if (rm->dev->flags & IFF_PROMISC)
+               val |= F_COPYALLFRAMES;
+       t3_write_reg(adap, A_XGM_RX_CFG + oft, val);
+
+       if (rm->dev->flags & IFF_ALLMULTI)
+               hash_lo = hash_hi = 0xffffffff;
+       else {
+               u8 *addr;
+               int exact_addr_idx = mac->nucast;
+
+               hash_lo = hash_hi = 0;
+               while ((addr = t3_get_next_mcaddr(rm)))
+                       if (exact_addr_idx < EXACT_ADDR_FILTERS)
+                               set_addr_filter(mac, exact_addr_idx++, addr);
+                       else {
+                               int hash = hash_hw_addr(addr);
+
+                               if (hash < 32)
+                                       hash_lo |= (1 << hash);
+                               else
+                                       hash_hi |= (1 << (hash - 32));
+                       }
+       }
+
+       t3_write_reg(adap, A_XGM_RX_HASH_LOW + oft, hash_lo);
+       t3_write_reg(adap, A_XGM_RX_HASH_HIGH + oft, hash_hi);
+       return 0;
+}
+
+int t3_mac_set_mtu(struct cmac *mac, unsigned int mtu)
+{
+       int hwm, lwm;
+       unsigned int thres, v;
+       struct adapter *adap = mac->adapter;
+
+       /*
+        * MAX_FRAME_SIZE inludes header + FCS, mtu doesn't.  The HW max
+        * packet size register includes header, but not FCS.
+        */
+       mtu += 14;
+       if (mtu > MAX_FRAME_SIZE - 4)
+               return -EINVAL;
+       t3_write_reg(adap, A_XGM_RX_MAX_PKT_SIZE + mac->offset, mtu);
+
+       /*
+        * Adjust the PAUSE frame watermarks.  We always set the LWM, and the
+        * HWM only if flow-control is enabled.
+        */
+       hwm = max(MAC_RXFIFO_SIZE - 3 * mtu, MAC_RXFIFO_SIZE / 2U);
+       hwm = min(hwm, 3 * MAC_RXFIFO_SIZE / 4 + 1024);
+       lwm = hwm - 1024;
+       v = t3_read_reg(adap, A_XGM_RXFIFO_CFG + mac->offset);
+       v &= ~V_RXFIFOPAUSELWM(M_RXFIFOPAUSELWM);
+       v |= V_RXFIFOPAUSELWM(lwm / 8);
+       if (G_RXFIFOPAUSEHWM(v))
+               v = (v & ~V_RXFIFOPAUSEHWM(M_RXFIFOPAUSEHWM)) |
+                   V_RXFIFOPAUSEHWM(hwm / 8);
+       t3_write_reg(adap, A_XGM_RXFIFO_CFG + mac->offset, v);
+
+       /* Adjust the TX FIFO threshold based on the MTU */
+       thres = (adap->params.vpd.cclk * 1000) / 15625;
+       thres = (thres * mtu) / 1000;
+       if (is_10G(adap))
+               thres /= 10;
+       thres = mtu > thres ? (mtu - thres + 7) / 8 : 0;
+       thres = max(thres, 8U); /* need at least 8 */
+       t3_set_reg_field(adap, A_XGM_TXFIFO_CFG + mac->offset,
+                        V_TXFIFOTHRESH(M_TXFIFOTHRESH), V_TXFIFOTHRESH(thres));
+       return 0;
+}
+
+int t3_mac_set_speed_duplex_fc(struct cmac *mac, int speed, int duplex, int fc)
+{
+       u32 val;
+       struct adapter *adap = mac->adapter;
+       unsigned int oft = mac->offset;
+
+       if (duplex >= 0 && duplex != DUPLEX_FULL)
+               return -EINVAL;
+       if (speed >= 0) {
+               if (speed == SPEED_10)
+                       val = V_PORTSPEED(0);
+               else if (speed == SPEED_100)
+                       val = V_PORTSPEED(1);
+               else if (speed == SPEED_1000)
+                       val = V_PORTSPEED(2);
+               else if (speed == SPEED_10000)
+                       val = V_PORTSPEED(3);
+               else
+                       return -EINVAL;
+
+               t3_set_reg_field(adap, A_XGM_PORT_CFG + oft,
+                                V_PORTSPEED(M_PORTSPEED), val);
+       }
+
+       val = t3_read_reg(adap, A_XGM_RXFIFO_CFG + oft);
+       val &= ~V_RXFIFOPAUSEHWM(M_RXFIFOPAUSEHWM);
+       if (fc & PAUSE_TX)
+               val |= V_RXFIFOPAUSEHWM(G_RXFIFOPAUSELWM(val) + 128);   /* +1KB */
+       t3_write_reg(adap, A_XGM_RXFIFO_CFG + oft, val);
+
+       t3_set_reg_field(adap, A_XGM_TX_CFG + oft, F_TXPAUSEEN,
+                        (fc & PAUSE_RX) ? F_TXPAUSEEN : 0);
+       return 0;
+}
+
+int t3_mac_enable(struct cmac *mac, int which)
+{
+       int idx = macidx(mac);
+       struct adapter *adap = mac->adapter;
+       unsigned int oft = mac->offset;
+
+       if (which & MAC_DIRECTION_TX) {
+               t3_write_reg(adap, A_XGM_TX_CTRL + oft, F_TXEN);
+               t3_write_reg(adap, A_TP_PIO_ADDR, A_TP_TX_DROP_CFG_CH0 + idx);
+               t3_write_reg(adap, A_TP_PIO_DATA, 0xbf000001);
+               t3_write_reg(adap, A_TP_PIO_ADDR, A_TP_TX_DROP_MODE);
+               t3_set_reg_field(adap, A_TP_PIO_DATA, 1 << idx, 1 << idx);
+       }
+       if (which & MAC_DIRECTION_RX)
+               t3_write_reg(adap, A_XGM_RX_CTRL + oft, F_RXEN);
+       return 0;
+}
+
+int t3_mac_disable(struct cmac *mac, int which)
+{
+       int idx = macidx(mac);
+       struct adapter *adap = mac->adapter;
+
+       if (which & MAC_DIRECTION_TX) {
+               t3_write_reg(adap, A_XGM_TX_CTRL + mac->offset, 0);
+               t3_write_reg(adap, A_TP_PIO_ADDR, A_TP_TX_DROP_CFG_CH0 + idx);
+               t3_write_reg(adap, A_TP_PIO_DATA, 0xc000001f);
+               t3_write_reg(adap, A_TP_PIO_ADDR, A_TP_TX_DROP_MODE);
+               t3_set_reg_field(adap, A_TP_PIO_DATA, 1 << idx, 0);
+       }
+       if (which & MAC_DIRECTION_RX)
+               t3_write_reg(adap, A_XGM_RX_CTRL + mac->offset, 0);
+       return 0;
+}
+
+/*
+ * This function is called periodically to accumulate the current values of the
+ * RMON counters into the port statistics.  Since the packet counters are only
+ * 32 bits they can overflow in ~286 secs at 10G, so the function should be
+ * called more frequently than that.  The byte counters are 45-bit wide, they
+ * would overflow in ~7.8 hours.
+ */
+const struct mac_stats *t3_mac_update_stats(struct cmac *mac)
+{
+#define RMON_READ(mac, addr) t3_read_reg(mac->adapter, addr + mac->offset)
+#define RMON_UPDATE(mac, name, reg) \
+       (mac)->stats.name += (u64)RMON_READ(mac, A_XGM_STAT_##reg)
+#define RMON_UPDATE64(mac, name, reg_lo, reg_hi) \
+       (mac)->stats.name += RMON_READ(mac, A_XGM_STAT_##reg_lo) + \
+                            ((u64)RMON_READ(mac, A_XGM_STAT_##reg_hi) << 32)
+
+       u32 v, lo;
+
+       RMON_UPDATE64(mac, rx_octets, RX_BYTES_LOW, RX_BYTES_HIGH);
+       RMON_UPDATE64(mac, rx_frames, RX_FRAMES_LOW, RX_FRAMES_HIGH);
+       RMON_UPDATE(mac, rx_mcast_frames, RX_MCAST_FRAMES);
+       RMON_UPDATE(mac, rx_bcast_frames, RX_BCAST_FRAMES);
+       RMON_UPDATE(mac, rx_fcs_errs, RX_CRC_ERR_FRAMES);
+       RMON_UPDATE(mac, rx_pause, RX_PAUSE_FRAMES);
+       RMON_UPDATE(mac, rx_jabber, RX_JABBER_FRAMES);
+       RMON_UPDATE(mac, rx_short, RX_SHORT_FRAMES);
+       RMON_UPDATE(mac, rx_symbol_errs, RX_SYM_CODE_ERR_FRAMES);
+
+       RMON_UPDATE(mac, rx_too_long, RX_OVERSIZE_FRAMES);
+       mac->stats.rx_too_long += RMON_READ(mac, A_XGM_RX_MAX_PKT_SIZE_ERR_CNT);
+
+       RMON_UPDATE(mac, rx_frames_64, RX_64B_FRAMES);
+       RMON_UPDATE(mac, rx_frames_65_127, RX_65_127B_FRAMES);
+       RMON_UPDATE(mac, rx_frames_128_255, RX_128_255B_FRAMES);
+       RMON_UPDATE(mac, rx_frames_256_511, RX_256_511B_FRAMES);
+       RMON_UPDATE(mac, rx_frames_512_1023, RX_512_1023B_FRAMES);
+       RMON_UPDATE(mac, rx_frames_1024_1518, RX_1024_1518B_FRAMES);
+       RMON_UPDATE(mac, rx_frames_1519_max, RX_1519_MAXB_FRAMES);
+
+       RMON_UPDATE64(mac, tx_octets, TX_BYTE_LOW, TX_BYTE_HIGH);
+       RMON_UPDATE64(mac, tx_frames, TX_FRAME_LOW, TX_FRAME_HIGH);
+       RMON_UPDATE(mac, tx_mcast_frames, TX_MCAST);
+       RMON_UPDATE(mac, tx_bcast_frames, TX_BCAST);
+       RMON_UPDATE(mac, tx_pause, TX_PAUSE);
+       /* This counts error frames in general (bad FCS, underrun, etc). */
+       RMON_UPDATE(mac, tx_underrun, TX_ERR_FRAMES);
+
+       RMON_UPDATE(mac, tx_frames_64, TX_64B_FRAMES);
+       RMON_UPDATE(mac, tx_frames_65_127, TX_65_127B_FRAMES);
+       RMON_UPDATE(mac, tx_frames_128_255, TX_128_255B_FRAMES);
+       RMON_UPDATE(mac, tx_frames_256_511, TX_256_511B_FRAMES);
+       RMON_UPDATE(mac, tx_frames_512_1023, TX_512_1023B_FRAMES);
+       RMON_UPDATE(mac, tx_frames_1024_1518, TX_1024_1518B_FRAMES);
+       RMON_UPDATE(mac, tx_frames_1519_max, TX_1519_MAXB_FRAMES);
+
+       /* The next stat isn't clear-on-read. */
+       t3_write_reg(mac->adapter, A_TP_MIB_INDEX, mac->offset ? 51 : 50);
+       v = t3_read_reg(mac->adapter, A_TP_MIB_RDATA);
+       lo = (u32) mac->stats.rx_cong_drops;
+       mac->stats.rx_cong_drops += (u64) (v - lo);
+
+       return &mac->stats;
+}
index 4ae0fed7122e7abbf5498137d26f799cb5976f16..9f7e1db8ce62a12b1fe054844deb6ca5445406b1 100644 (file)
@@ -5,7 +5,7 @@
  *
  *      adopted from sunlance.c by Richard van den Berg
  *
- *      Copyright (C) 2002, 2003, 2005  Maciej W. Rozycki
+ *      Copyright (C) 2002, 2003, 2005, 2006  Maciej W. Rozycki
  *
  *      additional sources:
  *      - PMAD-AA TURBOchannel Ethernet Module Functional Specification,
@@ -44,6 +44,8 @@
  *      v0.010: Fixes for the PMAD mapping of the LANCE buffer and for the
  *              PMAX requirement to only use halfword accesses to the
  *              buffer. macro
+ *
+ *      v0.011: Converted the PMAD to the driver model. macro
  */
 
 #include <linux/crc32.h>
@@ -58,6 +60,7 @@
 #include <linux/spinlock.h>
 #include <linux/stddef.h>
 #include <linux/string.h>
+#include <linux/tc.h>
 #include <linux/types.h>
 
 #include <asm/addrspace.h>
 #include <asm/dec/kn01.h>
 #include <asm/dec/machtype.h>
 #include <asm/dec/system.h>
-#include <asm/dec/tc.h>
 
 static char version[] __devinitdata =
-"declance.c: v0.010 by Linux MIPS DECstation task force\n";
+"declance.c: v0.011 by Linux MIPS DECstation task force\n";
 
 MODULE_AUTHOR("Linux MIPS DECstation task force");
 MODULE_DESCRIPTION("DEC LANCE (DECstation onboard, PMAD-xx) driver");
 MODULE_LICENSE("GPL");
 
+#define __unused __attribute__ ((unused))
+
 /*
  * card types
  */
@@ -246,7 +250,6 @@ struct lance_init_block {
 struct lance_private {
        struct net_device *next;
        int type;
-       int slot;
        int dma_irq;
        volatile struct lance_regs *ll;
 
@@ -288,6 +291,7 @@ struct lance_regs {
 
 int dec_lance_debug = 2;
 
+static struct tc_driver dec_lance_tc_driver;
 static struct net_device *root_lance_dev;
 
 static inline void writereg(volatile unsigned short *regptr, short value)
@@ -1023,7 +1027,7 @@ static void lance_set_multicast_retry(unsigned long _opaque)
        lance_set_multicast(dev);
 }
 
-static int __init dec_lance_init(const int type, const int slot)
+static int __init dec_lance_probe(struct device *bdev, const int type)
 {
        static unsigned version_printed;
        static const char fmt[] = "declance%d";
@@ -1031,6 +1035,7 @@ static int __init dec_lance_init(const int type, const int slot)
        struct net_device *dev;
        struct lance_private *lp;
        volatile struct lance_regs *ll;
+       resource_size_t start = 0, len = 0;
        int i, ret;
        unsigned long esar_base;
        unsigned char *esar;
@@ -1038,14 +1043,18 @@ static int __init dec_lance_init(const int type, const int slot)
        if (dec_lance_debug && version_printed++ == 0)
                printk(version);
 
-       i = 0;
-       dev = root_lance_dev;
-       while (dev) {
-               i++;
-               lp = (struct lance_private *)dev->priv;
-               dev = lp->next;
+       if (bdev)
+               snprintf(name, sizeof(name), "%s", bdev->bus_id);
+       else {
+               i = 0;
+               dev = root_lance_dev;
+               while (dev) {
+                       i++;
+                       lp = (struct lance_private *)dev->priv;
+                       dev = lp->next;
+               }
+               snprintf(name, sizeof(name), fmt, i);
        }
-       snprintf(name, sizeof(name), fmt, i);
 
        dev = alloc_etherdev(sizeof(struct lance_private));
        if (!dev) {
@@ -1063,7 +1072,6 @@ static int __init dec_lance_init(const int type, const int slot)
        spin_lock_init(&lp->lock);
 
        lp->type = type;
-       lp->slot = slot;
        switch (type) {
        case ASIC_LANCE:
                dev->base_addr = CKSEG1ADDR(dec_kn_slot_base + IOASIC_LANCE);
@@ -1110,12 +1118,22 @@ static int __init dec_lance_init(const int type, const int slot)
                break;
 #ifdef CONFIG_TC
        case PMAD_LANCE:
-               claim_tc_card(slot);
+               dev_set_drvdata(bdev, dev);
+
+               start = to_tc_dev(bdev)->resource.start;
+               len = to_tc_dev(bdev)->resource.end - start + 1;
+               if (!request_mem_region(start, len, bdev->bus_id)) {
+                       printk(KERN_ERR
+                              "%s: Unable to reserve MMIO resource\n",
+                              bdev->bus_id);
+                       ret = -EBUSY;
+                       goto err_out_dev;
+               }
 
-               dev->mem_start = CKSEG1ADDR(get_tc_base_addr(slot));
+               dev->mem_start = CKSEG1ADDR(start);
                dev->mem_end = dev->mem_start + 0x100000;
                dev->base_addr = dev->mem_start + 0x100000;
-               dev->irq = get_tc_irq_nr(slot);
+               dev->irq = to_tc_dev(bdev)->interrupt;
                esar_base = dev->mem_start + 0x1c0002;
                lp->dma_irq = -1;
 
@@ -1174,7 +1192,7 @@ static int __init dec_lance_init(const int type, const int slot)
                printk(KERN_ERR "%s: declance_init called with unknown type\n",
                        name);
                ret = -ENODEV;
-               goto err_out_free_dev;
+               goto err_out_dev;
        }
 
        ll = (struct lance_regs *) dev->base_addr;
@@ -1188,7 +1206,7 @@ static int __init dec_lance_init(const int type, const int slot)
                        "%s: Ethernet station address prom not found!\n",
                        name);
                ret = -ENODEV;
-               goto err_out_free_dev;
+               goto err_out_resource;
        }
        /* Check the prom contents */
        for (i = 0; i < 8; i++) {
@@ -1198,7 +1216,7 @@ static int __init dec_lance_init(const int type, const int slot)
                        printk(KERN_ERR "%s: Something is wrong with the "
                                "ethernet station address prom!\n", name);
                        ret = -ENODEV;
-                       goto err_out_free_dev;
+                       goto err_out_resource;
                }
        }
 
@@ -1255,48 +1273,51 @@ static int __init dec_lance_init(const int type, const int slot)
        if (ret) {
                printk(KERN_ERR
                        "%s: Unable to register netdev, aborting.\n", name);
-               goto err_out_free_dev;
+               goto err_out_resource;
        }
 
-       lp->next = root_lance_dev;
-       root_lance_dev = dev;
+       if (!bdev) {
+               lp->next = root_lance_dev;
+               root_lance_dev = dev;
+       }
 
        printk("%s: registered as %s.\n", name, dev->name);
        return 0;
 
-err_out_free_dev:
+err_out_resource:
+       if (bdev)
+               release_mem_region(start, len);
+
+err_out_dev:
        free_netdev(dev);
 
 err_out:
        return ret;
 }
 
+static void __exit dec_lance_remove(struct device *bdev)
+{
+       struct net_device *dev = dev_get_drvdata(bdev);
+       resource_size_t start, len;
+
+       unregister_netdev(dev);
+       start = to_tc_dev(bdev)->resource.start;
+       len = to_tc_dev(bdev)->resource.end - start + 1;
+       release_mem_region(start, len);
+       free_netdev(dev);
+}
 
 /* Find all the lance cards on the system and initialize them */
-static int __init dec_lance_probe(void)
+static int __init dec_lance_platform_probe(void)
 {
        int count = 0;
 
-       /* Scan slots for PMAD-AA cards first. */
-#ifdef CONFIG_TC
-       if (TURBOCHANNEL) {
-               int slot;
-
-               while ((slot = search_tc_card("PMAD-AA")) >= 0) {
-                       if (dec_lance_init(PMAD_LANCE, slot) < 0)
-                               break;
-                       count++;
-               }
-       }
-#endif
-
-       /* Then handle onboard devices. */
        if (dec_interrupt[DEC_IRQ_LANCE] >= 0) {
                if (dec_interrupt[DEC_IRQ_LANCE_MERR] >= 0) {
-                       if (dec_lance_init(ASIC_LANCE, -1) >= 0)
+                       if (dec_lance_probe(NULL, ASIC_LANCE) >= 0)
                                count++;
                } else if (!TURBOCHANNEL) {
-                       if (dec_lance_init(PMAX_LANCE, -1) >= 0)
+                       if (dec_lance_probe(NULL, PMAX_LANCE) >= 0)
                                count++;
                }
        }
@@ -1304,21 +1325,70 @@ static int __init dec_lance_probe(void)
        return (count > 0) ? 0 : -ENODEV;
 }
 
-static void __exit dec_lance_cleanup(void)
+static void __exit dec_lance_platform_remove(void)
 {
        while (root_lance_dev) {
                struct net_device *dev = root_lance_dev;
                struct lance_private *lp = netdev_priv(dev);
 
                unregister_netdev(dev);
-#ifdef CONFIG_TC
-               if (lp->slot >= 0)
-                       release_tc_card(lp->slot);
-#endif
                root_lance_dev = lp->next;
                free_netdev(dev);
        }
 }
 
-module_init(dec_lance_probe);
-module_exit(dec_lance_cleanup);
+#ifdef CONFIG_TC
+static int __init dec_lance_tc_probe(struct device *dev);
+static int __exit dec_lance_tc_remove(struct device *dev);
+
+static const struct tc_device_id dec_lance_tc_table[] = {
+       { "DEC     ", "PMAD-AA " },
+       { }
+};
+MODULE_DEVICE_TABLE(tc, dec_lance_tc_table);
+
+static struct tc_driver dec_lance_tc_driver = {
+       .id_table       = dec_lance_tc_table,
+       .driver         = {
+               .name   = "declance",
+               .bus    = &tc_bus_type,
+               .probe  = dec_lance_tc_probe,
+               .remove = __exit_p(dec_lance_tc_remove),
+       },
+};
+
+static int __init dec_lance_tc_probe(struct device *dev)
+{
+        int status = dec_lance_probe(dev, PMAD_LANCE);
+        if (!status)
+                get_device(dev);
+        return status;
+}
+
+static int __exit dec_lance_tc_remove(struct device *dev)
+{
+        put_device(dev);
+        dec_lance_remove(dev);
+        return 0;
+}
+#endif
+
+static int __init dec_lance_init(void)
+{
+       int status;
+
+       status = tc_register_driver(&dec_lance_tc_driver);
+       if (!status)
+               dec_lance_platform_probe();
+       return status;
+}
+
+static void __exit dec_lance_exit(void)
+{
+       dec_lance_platform_remove();
+       tc_unregister_driver(&dec_lance_tc_driver);
+}
+
+
+module_init(dec_lance_init);
+module_exit(dec_lance_exit);
index f091042b146eaed8d4de0641010cd7a3a3b77e73..689f158a469eb78d6146f98231e0f36b69680f5d 100644 (file)
 #include <linux/capability.h>
 #include <linux/in.h>
 #include <linux/ip.h>
-#ifdef NETIF_F_TSO6
 #include <linux/ipv6.h>
-#endif
 #include <linux/tcp.h>
 #include <linux/udp.h>
 #include <net/pkt_sched.h>
 #include <linux/list.h>
 #include <linux/reboot.h>
-#ifdef NETIF_F_TSO
 #include <net/checksum.h>
-#endif
 #include <linux/mii.h>
 #include <linux/ethtool.h>
 #include <linux/if_vlan.h>
@@ -257,7 +253,6 @@ struct e1000_adapter {
        spinlock_t tx_queue_lock;
 #endif
        atomic_t irq_sem;
-       unsigned int detect_link;
        unsigned int total_tx_bytes;
        unsigned int total_tx_packets;
        unsigned int total_rx_bytes;
@@ -348,9 +343,7 @@ struct e1000_adapter {
        boolean_t have_msi;
 #endif
        /* to not mess up cache alignment, always add to the bottom */
-#ifdef NETIF_F_TSO
        boolean_t tso_force;
-#endif
        boolean_t smart_power_down;     /* phy smart power down */
        boolean_t quad_port_a;
        unsigned long flags;
index fb96c87f9e56c9fe90223dd2902d0b15dc1c99b3..44ebc72962dc47d6e434f8153b21f4932985cac1 100644 (file)
@@ -338,7 +338,6 @@ e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
        return 0;
 }
 
-#ifdef NETIF_F_TSO
 static int
 e1000_set_tso(struct net_device *netdev, uint32_t data)
 {
@@ -352,18 +351,15 @@ e1000_set_tso(struct net_device *netdev, uint32_t data)
        else
                netdev->features &= ~NETIF_F_TSO;
 
-#ifdef NETIF_F_TSO6
        if (data)
                netdev->features |= NETIF_F_TSO6;
        else
                netdev->features &= ~NETIF_F_TSO6;
-#endif
 
        DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
        adapter->tso_force = TRUE;
        return 0;
 }
-#endif /* NETIF_F_TSO */
 
 static uint32_t
 e1000_get_msglevel(struct net_device *netdev)
@@ -1971,10 +1967,8 @@ static const struct ethtool_ops e1000_ethtool_ops = {
        .set_tx_csum            = e1000_set_tx_csum,
        .get_sg                 = ethtool_op_get_sg,
        .set_sg                 = ethtool_op_set_sg,
-#ifdef NETIF_F_TSO
        .get_tso                = ethtool_op_get_tso,
        .set_tso                = e1000_set_tso,
-#endif
        .self_test_count        = e1000_diag_test_count,
        .self_test              = e1000_diag_test,
        .get_strings            = e1000_get_strings,
index c6259c7127f6bb9aaa4dbda53ee783ed428c1e0e..222fcd2d10dee8a1231d22da091a3bacd0dd8aee 100644 (file)
@@ -36,7 +36,7 @@ static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
 #else
 #define DRIVERNAPI "-NAPI"
 #endif
-#define DRV_VERSION "7.3.15-k2"DRIVERNAPI
+#define DRV_VERSION "7.3.20-k2"DRIVERNAPI
 char e1000_driver_version[] = DRV_VERSION;
 static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
 
@@ -990,16 +990,12 @@ e1000_probe(struct pci_dev *pdev,
                        netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
        }
 
-#ifdef NETIF_F_TSO
        if ((adapter->hw.mac_type >= e1000_82544) &&
           (adapter->hw.mac_type != e1000_82547))
                netdev->features |= NETIF_F_TSO;
 
-#ifdef NETIF_F_TSO6
        if (adapter->hw.mac_type > e1000_82547_rev_2)
                netdev->features |= NETIF_F_TSO6;
-#endif
-#endif
        if (pci_using_dac)
                netdev->features |= NETIF_F_HIGHDMA;
 
@@ -2583,15 +2579,22 @@ e1000_watchdog(unsigned long data)
 
        if (link) {
                if (!netif_carrier_ok(netdev)) {
+                       uint32_t ctrl;
                        boolean_t txb2b = 1;
                        e1000_get_speed_and_duplex(&adapter->hw,
                                                   &adapter->link_speed,
                                                   &adapter->link_duplex);
 
-                       DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
-                              adapter->link_speed,
-                              adapter->link_duplex == FULL_DUPLEX ?
-                              "Full Duplex" : "Half Duplex");
+                       ctrl = E1000_READ_REG(&adapter->hw, CTRL);
+                       DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
+                               "Flow Control: %s\n",
+                               adapter->link_speed,
+                               adapter->link_duplex == FULL_DUPLEX ?
+                               "Full Duplex" : "Half Duplex",
+                               ((ctrl & E1000_CTRL_TFCE) && (ctrl &
+                               E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
+                               E1000_CTRL_RFCE) ? "RX" : ((ctrl &
+                               E1000_CTRL_TFCE) ? "TX" : "None" )));
 
                        /* tweak tx_queue_len according to speed/duplex
                         * and adjust the timeout factor */
@@ -2619,7 +2622,6 @@ e1000_watchdog(unsigned long data)
                                E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
                        }
 
-#ifdef NETIF_F_TSO
                        /* disable TSO for pcie and 10/100 speeds, to avoid
                         * some hardware issues */
                        if (!adapter->tso_force &&
@@ -2630,22 +2632,17 @@ e1000_watchdog(unsigned long data)
                                        DPRINTK(PROBE,INFO,
                                        "10/100 speed: disabling TSO\n");
                                        netdev->features &= ~NETIF_F_TSO;
-#ifdef NETIF_F_TSO6
                                        netdev->features &= ~NETIF_F_TSO6;
-#endif
                                        break;
                                case SPEED_1000:
                                        netdev->features |= NETIF_F_TSO;
-#ifdef NETIF_F_TSO6
                                        netdev->features |= NETIF_F_TSO6;
-#endif
                                        break;
                                default:
                                        /* oops */
                                        break;
                                }
                        }
-#endif
 
                        /* enable transmits in the hardware, need to do this
                         * after setting TARC0 */
@@ -2875,7 +2872,6 @@ static int
 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
           struct sk_buff *skb)
 {
-#ifdef NETIF_F_TSO
        struct e1000_context_desc *context_desc;
        struct e1000_buffer *buffer_info;
        unsigned int i;
@@ -2904,7 +2900,6 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                                                   0);
                        cmd_length = E1000_TXD_CMD_IP;
                        ipcse = skb->h.raw - skb->data - 1;
-#ifdef NETIF_F_TSO6
                } else if (skb->protocol == htons(ETH_P_IPV6)) {
                        skb->nh.ipv6h->payload_len = 0;
                        skb->h.th->check =
@@ -2914,7 +2909,6 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                                                 IPPROTO_TCP,
                                                 0);
                        ipcse = 0;
-#endif
                }
                ipcss = skb->nh.raw - skb->data;
                ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
@@ -2947,8 +2941,6 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
 
                return TRUE;
        }
-#endif
-
        return FALSE;
 }
 
@@ -2968,8 +2960,9 @@ e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                buffer_info = &tx_ring->buffer_info[i];
                context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
 
+               context_desc->lower_setup.ip_config = 0;
                context_desc->upper_setup.tcp_fields.tucss = css;
-               context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
+               context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
                context_desc->upper_setup.tcp_fields.tucse = 0;
                context_desc->tcp_seg_setup.data = 0;
                context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
@@ -3005,7 +2998,6 @@ e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
        while (len) {
                buffer_info = &tx_ring->buffer_info[i];
                size = min(len, max_per_txd);
-#ifdef NETIF_F_TSO
                /* Workaround for Controller erratum --
                 * descriptor for non-tso packet in a linear SKB that follows a
                 * tso gets written back prematurely before the data is fully
@@ -3020,7 +3012,6 @@ e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                 * in TSO mode.  Append 4-byte sentinel desc */
                if (unlikely(mss && !nr_frags && size == len && size > 8))
                        size -= 4;
-#endif
                /* work-around for errata 10 and it applies
                 * to all controllers in PCI-X mode
                 * The fix is to make sure that the first descriptor of a
@@ -3062,12 +3053,10 @@ e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                while (len) {
                        buffer_info = &tx_ring->buffer_info[i];
                        size = min(len, max_per_txd);
-#ifdef NETIF_F_TSO
                        /* Workaround for premature desc write-backs
                         * in TSO mode.  Append 4-byte sentinel desc */
                        if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
                                size -= 4;
-#endif
                        /* Workaround for potential 82544 hang in PCI-X.
                         * Avoid terminating buffers within evenly-aligned
                         * dwords. */
@@ -3292,7 +3281,6 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
        if (adapter->hw.mac_type >= e1000_82571)
                max_per_txd = 8192;
 
-#ifdef NETIF_F_TSO
        mss = skb_shinfo(skb)->gso_size;
        /* The controller does a simple calculation to
         * make sure there is enough room in the FIFO before
@@ -3346,16 +3334,10 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
        if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
                count++;
        count++;
-#else
-       if (skb->ip_summed == CHECKSUM_PARTIAL)
-               count++;
-#endif
 
-#ifdef NETIF_F_TSO
        /* Controller Erratum workaround */
        if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
                count++;
-#endif
 
        count += TXD_USE_COUNT(len, max_txd_pwr);
 
@@ -3765,8 +3747,8 @@ e1000_update_stats(struct e1000_adapter *adapter)
  * @data: pointer to a network interface device structure
  **/
 
-static
-irqreturn_t e1000_intr_msi(int irq, void *data)
+static irqreturn_t
+e1000_intr_msi(int irq, void *data)
 {
        struct net_device *netdev = data;
        struct e1000_adapter *adapter = netdev_priv(netdev);
@@ -3774,49 +3756,27 @@ irqreturn_t e1000_intr_msi(int irq, void *data)
 #ifndef CONFIG_E1000_NAPI
        int i;
 #endif
+       uint32_t icr = E1000_READ_REG(hw, ICR);
 
-       /* this code avoids the read of ICR but has to get 1000 interrupts
-        * at every link change event before it will notice the change */
-       if (++adapter->detect_link >= 1000) {
-               uint32_t icr = E1000_READ_REG(hw, ICR);
 #ifdef CONFIG_E1000_NAPI
-               /* read ICR disables interrupts using IAM, so keep up with our
-                * enable/disable accounting */
-               atomic_inc(&adapter->irq_sem);
+       /* read ICR disables interrupts using IAM, so keep up with our
+        * enable/disable accounting */
+       atomic_inc(&adapter->irq_sem);
 #endif
-               adapter->detect_link = 0;
-               if ((icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) &&
-                   (icr & E1000_ICR_INT_ASSERTED)) {
-                       hw->get_link_status = 1;
-                       /* 80003ES2LAN workaround--
-                       * For packet buffer work-around on link down event;
-                       * disable receives here in the ISR and
-                       * reset adapter in watchdog
-                       */
-                       if (netif_carrier_ok(netdev) &&
-                           (adapter->hw.mac_type == e1000_80003es2lan)) {
-                               /* disable receives */
-                               uint32_t rctl = E1000_READ_REG(hw, RCTL);
-                               E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
-                       }
-                       /* guard against interrupt when we're going down */
-                       if (!test_bit(__E1000_DOWN, &adapter->flags))
-                               mod_timer(&adapter->watchdog_timer,
-                                         jiffies + 1);
+       if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
+               hw->get_link_status = 1;
+               /* 80003ES2LAN workaround-- For packet buffer work-around on
+                * link down event; disable receives here in the ISR and reset
+                * adapter in watchdog */
+               if (netif_carrier_ok(netdev) &&
+                   (adapter->hw.mac_type == e1000_80003es2lan)) {
+                       /* disable receives */
+                       uint32_t rctl = E1000_READ_REG(hw, RCTL);
+                       E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
                }
-       } else {
-               E1000_WRITE_REG(hw, ICR, (0xffffffff & ~(E1000_ICR_RXSEQ |
-                                                        E1000_ICR_LSC)));
-               /* bummer we have to flush here, but things break otherwise as
-                * some event appears to be lost or delayed and throughput
-                * drops.  In almost all tests this flush is un-necessary */
-               E1000_WRITE_FLUSH(hw);
-#ifdef CONFIG_E1000_NAPI
-               /* Interrupt Auto-Mask (IAM)...upon writing ICR, interrupts are
-                * masked.  No need for the IMC write, but it does mean we
-                * should account for it ASAP. */
-               atomic_inc(&adapter->irq_sem);
-#endif
+               /* guard against interrupt when we're going down */
+               if (!test_bit(__E1000_DOWN, &adapter->flags))
+                       mod_timer(&adapter->watchdog_timer, jiffies + 1);
        }
 
 #ifdef CONFIG_E1000_NAPI
@@ -3836,7 +3796,7 @@ irqreturn_t e1000_intr_msi(int irq, void *data)
 
        for (i = 0; i < E1000_MAX_INTR; i++)
                if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
-                  !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
+                  e1000_clean_tx_irq(adapter, adapter->tx_ring)))
                        break;
 
        if (likely(adapter->itr_setting & 3))
@@ -3939,7 +3899,7 @@ e1000_intr(int irq, void *data)
 
        for (i = 0; i < E1000_MAX_INTR; i++)
                if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
-                  !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
+                  e1000_clean_tx_irq(adapter, adapter->tx_ring)))
                        break;
 
        if (likely(adapter->itr_setting & 3))
@@ -3989,7 +3949,7 @@ e1000_clean(struct net_device *poll_dev, int *budget)
        poll_dev->quota -= work_done;
 
        /* If no Tx and not enough Rx work done, exit the polling mode */
-       if ((!tx_cleaned && (work_done == 0)) ||
+       if ((tx_cleaned && (work_done < work_to_do)) ||
           !netif_running(poll_dev)) {
 quit_polling:
                if (likely(adapter->itr_setting & 3))
@@ -4019,7 +3979,7 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
 #ifdef CONFIG_E1000_NAPI
        unsigned int count = 0;
 #endif
-       boolean_t cleaned = FALSE;
+       boolean_t cleaned = TRUE;
        unsigned int total_tx_bytes=0, total_tx_packets=0;
 
        i = tx_ring->next_to_clean;
@@ -4034,10 +3994,13 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
 
                        if (cleaned) {
                                struct sk_buff *skb = buffer_info->skb;
-                               unsigned int segs = skb_shinfo(skb)->gso_segs;
+                               unsigned int segs, bytecount;
+                               segs = skb_shinfo(skb)->gso_segs ?: 1;
+                               /* multiply data chunks by size of headers */
+                               bytecount = ((segs - 1) * skb_headlen(skb)) +
+                                           skb->len;
                                total_tx_packets += segs;
-                               total_tx_packets++;
-                               total_tx_bytes += skb->len;
+                               total_tx_bytes += bytecount;
                        }
                        e1000_unmap_and_free_tx_resource(adapter, buffer_info);
                        tx_desc->upper.data = 0;
@@ -4050,7 +4013,10 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
 #ifdef CONFIG_E1000_NAPI
 #define E1000_TX_WEIGHT 64
                /* weight of a sort for tx, to avoid endless transmit cleanup */
-               if (count++ == E1000_TX_WEIGHT) break;
+               if (count++ == E1000_TX_WEIGHT) {
+                       cleaned = FALSE;
+                       break;
+               }
 #endif
        }
 
index 18afc0c25dac5d42b2c0c366f2f7ab22f8d54153..10af742d8a2080c16676b59dc6ac7081b34f5880 100644 (file)
@@ -48,8 +48,6 @@ typedef enum {
     TRUE = 1
 } boolean_t;
 
-#define MSGOUT(S, A, B)        printk(KERN_DEBUG S "\n", A, B)
-
 #ifdef DBG
 #define DEBUGOUT(S)            printk(KERN_DEBUG S "\n")
 #define DEBUGOUT1(S, A...)     printk(KERN_DEBUG S "\n", A)
@@ -58,7 +56,7 @@ typedef enum {
 #define DEBUGOUT1(S, A...)
 #endif
 
-#define DEBUGFUNC(F) DEBUGOUT(F)
+#define DEBUGFUNC(F) DEBUGOUT(F "\n")
 #define DEBUGOUT2 DEBUGOUT1
 #define DEBUGOUT3 DEBUGOUT2
 #define DEBUGOUT7 DEBUGOUT3
index cf2a279307e1ce0a547c0a4f7e6ea7a04ff0b603..f8862e203ac9f9f4d76ba4ef026040cbf308d15b 100644 (file)
@@ -760,22 +760,13 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
        case SPEED_1000:
                DPRINTK(PROBE, INFO, "1000 Mbps Speed specified without "
                        "Duplex\n");
-               DPRINTK(PROBE, INFO,
-                       "Using Autonegotiation at 1000 Mbps "
-                       "Full Duplex only\n");
-               adapter->hw.autoneg = adapter->fc_autoneg = 1;
-               adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
-               break;
+               goto full_duplex_only;
        case SPEED_1000 + HALF_DUPLEX:
                DPRINTK(PROBE, INFO,
                        "Half Duplex is not supported at 1000 Mbps\n");
-               DPRINTK(PROBE, INFO,
-                       "Using Autonegotiation at 1000 Mbps "
-                       "Full Duplex only\n");
-               adapter->hw.autoneg = adapter->fc_autoneg = 1;
-               adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
-               break;
+               /* fall through */
        case SPEED_1000 + FULL_DUPLEX:
+full_duplex_only:
                DPRINTK(PROBE, INFO,
                       "Using Autonegotiation at 1000 Mbps Full Duplex only\n");
                adapter->hw.autoneg = adapter->fc_autoneg = 1;
index 93f2b7a2216096dfb5be8462da913df2b3417bef..a363148d019850d16b843a1a0cb0f4743f25f32a 100644 (file)
  *     0.57: 14 May 2006: Mac address set in probe/remove and order corrections.
  *     0.58: 30 Oct 2006: Added support for sideband management unit.
  *     0.59: 30 Oct 2006: Added support for recoverable error.
+ *     0.60: 20 Jan 2007: Code optimizations for rings, rx & tx data paths, and stats.
  *
  * Known bugs:
  * We suspect that on some hardware no TX done interrupts are generated.
 #else
 #define DRIVERNAPI
 #endif
-#define FORCEDETH_VERSION              "0.59"
+#define FORCEDETH_VERSION              "0.60"
 #define DRV_NAME                       "forcedeth"
 
 #include <linux/module.h>
 #define DEV_HAS_MSI_X           0x0080  /* device supports MSI-X */
 #define DEV_HAS_POWER_CNTRL     0x0100  /* device supports power savings */
 #define DEV_HAS_PAUSEFRAME_TX   0x0200  /* device supports tx pause frames */
-#define DEV_HAS_STATISTICS      0x0400  /* device supports hw statistics */
-#define DEV_HAS_TEST_EXTENDED   0x0800  /* device supports extended diagnostic test */
-#define DEV_HAS_MGMT_UNIT       0x1000  /* device supports management unit */
+#define DEV_HAS_STATISTICS_V1   0x0400  /* device supports hw statistics version 1 */
+#define DEV_HAS_STATISTICS_V2   0x0800  /* device supports hw statistics version 2 */
+#define DEV_HAS_TEST_EXTENDED   0x1000  /* device supports extended diagnostic test */
+#define DEV_HAS_MGMT_UNIT       0x2000  /* device supports management unit */
 
 enum {
        NvRegIrqStatus = 0x000,
@@ -210,7 +212,7 @@ enum {
  * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
  */
        NvRegPollingInterval = 0x00c,
-#define NVREG_POLL_DEFAULT_THROUGHPUT  970
+#define NVREG_POLL_DEFAULT_THROUGHPUT  970 /* backup tx cleanup if loop max reached */
 #define NVREG_POLL_DEFAULT_CPU 13
        NvRegMSIMap0 = 0x020,
        NvRegMSIMap1 = 0x024,
@@ -304,8 +306,8 @@ enum {
 #define NVREG_TXRXCTL_RESET    0x0010
 #define NVREG_TXRXCTL_RXCHECK  0x0400
 #define NVREG_TXRXCTL_DESC_1   0
-#define NVREG_TXRXCTL_DESC_2   0x02100
-#define NVREG_TXRXCTL_DESC_3   0x02200
+#define NVREG_TXRXCTL_DESC_2   0x002100
+#define NVREG_TXRXCTL_DESC_3   0xc02200
 #define NVREG_TXRXCTL_VLANSTRIP 0x00040
 #define NVREG_TXRXCTL_VLANINS  0x00080
        NvRegTxRingPhysAddrHigh = 0x148,
@@ -487,7 +489,8 @@ union ring_type {
 
 /* Miscelaneous hardware related defines: */
 #define NV_PCI_REGSZ_VER1              0x270
-#define NV_PCI_REGSZ_VER2              0x604
+#define NV_PCI_REGSZ_VER2              0x2d4
+#define NV_PCI_REGSZ_VER3              0x604
 
 /* various timeout delays: all in usec */
 #define NV_TXRX_RESET_DELAY    4
@@ -518,12 +521,6 @@ union ring_type {
 #define TX_RING_MIN            64
 #define RING_MAX_DESC_VER_1    1024
 #define RING_MAX_DESC_VER_2_3  16384
-/*
- * Difference between the get and put pointers for the tx ring.
- * This is used to throttle the amount of data outstanding in the
- * tx ring.
- */
-#define TX_LIMIT_DIFFERENCE    1
 
 /* rx/tx mac addr + type + vlan + align + slack*/
 #define NV_RX_HEADERS          (64)
@@ -611,9 +608,6 @@ static const struct nv_ethtool_str nv_estats_str[] = {
        { "tx_carrier_errors" },
        { "tx_excess_deferral" },
        { "tx_retry_error" },
-       { "tx_deferral" },
-       { "tx_packets" },
-       { "tx_pause" },
        { "rx_frame_error" },
        { "rx_extra_byte" },
        { "rx_late_collision" },
@@ -626,11 +620,17 @@ static const struct nv_ethtool_str nv_estats_str[] = {
        { "rx_unicast" },
        { "rx_multicast" },
        { "rx_broadcast" },
+       { "rx_packets" },
+       { "rx_errors_total" },
+       { "tx_errors_total" },
+
+       /* version 2 stats */
+       { "tx_deferral" },
+       { "tx_packets" },
        { "rx_bytes" },
+       { "tx_pause" },
        { "rx_pause" },
-       { "rx_drop_frame" },
-       { "rx_packets" },
-       { "rx_errors_total" }
+       { "rx_drop_frame" }
 };
 
 struct nv_ethtool_stats {
@@ -643,9 +643,6 @@ struct nv_ethtool_stats {
        u64 tx_carrier_errors;
        u64 tx_excess_deferral;
        u64 tx_retry_error;
-       u64 tx_deferral;
-       u64 tx_packets;
-       u64 tx_pause;
        u64 rx_frame_error;
        u64 rx_extra_byte;
        u64 rx_late_collision;
@@ -658,13 +655,22 @@ struct nv_ethtool_stats {
        u64 rx_unicast;
        u64 rx_multicast;
        u64 rx_broadcast;
+       u64 rx_packets;
+       u64 rx_errors_total;
+       u64 tx_errors_total;
+
+       /* version 2 stats */
+       u64 tx_deferral;
+       u64 tx_packets;
        u64 rx_bytes;
+       u64 tx_pause;
        u64 rx_pause;
        u64 rx_drop_frame;
-       u64 rx_packets;
-       u64 rx_errors_total;
 };
 
+#define NV_DEV_STATISTICS_V2_COUNT (sizeof(struct nv_ethtool_stats)/sizeof(u64))
+#define NV_DEV_STATISTICS_V1_COUNT (NV_DEV_STATISTICS_V2_COUNT - 6)
+
 /* diagnostics */
 #define NV_TEST_COUNT_BASE 3
 #define NV_TEST_COUNT_EXTENDED 4
@@ -691,6 +697,12 @@ static const struct register_test nv_registers_test[] = {
        { 0,0 }
 };
 
+struct nv_skb_map {
+       struct sk_buff *skb;
+       dma_addr_t dma;
+       unsigned int dma_len;
+};
+
 /*
  * SMP locking:
  * All hardware access under dev->priv->lock, except the performance
@@ -741,10 +753,12 @@ struct fe_priv {
        /* rx specific fields.
         * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
         */
+       union ring_type get_rx, put_rx, first_rx, last_rx;
+       struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
+       struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
+       struct nv_skb_map *rx_skb;
+
        union ring_type rx_ring;
-       unsigned int cur_rx, refill_rx;
-       struct sk_buff **rx_skbuff;
-       dma_addr_t *rx_dma;
        unsigned int rx_buf_sz;
        unsigned int pkt_limit;
        struct timer_list oom_kick;
@@ -761,15 +775,15 @@ struct fe_priv {
        /*
         * tx specific fields.
         */
+       union ring_type get_tx, put_tx, first_tx, last_tx;
+       struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
+       struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
+       struct nv_skb_map *tx_skb;
+
        union ring_type tx_ring;
-       unsigned int next_tx, nic_tx;
-       struct sk_buff **tx_skbuff;
-       dma_addr_t *tx_dma;
-       unsigned int *tx_dma_len;
        u32 tx_flags;
        int tx_ring_size;
-       int tx_limit_start;
-       int tx_limit_stop;
+       int tx_stop;
 
        /* vlan fields */
        struct vlan_group *vlangrp;
@@ -921,16 +935,10 @@ static void free_rings(struct net_device *dev)
                        pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
                                            np->rx_ring.ex, np->ring_addr);
        }
-       if (np->rx_skbuff)
-               kfree(np->rx_skbuff);
-       if (np->rx_dma)
-               kfree(np->rx_dma);
-       if (np->tx_skbuff)
-               kfree(np->tx_skbuff);
-       if (np->tx_dma)
-               kfree(np->tx_dma);
-       if (np->tx_dma_len)
-               kfree(np->tx_dma_len);
+       if (np->rx_skb)
+               kfree(np->rx_skb);
+       if (np->tx_skb)
+               kfree(np->tx_skb);
 }
 
 static int using_multi_irqs(struct net_device *dev)
@@ -1279,6 +1287,61 @@ static void nv_mac_reset(struct net_device *dev)
        pci_push(base);
 }
 
+static void nv_get_hw_stats(struct net_device *dev)
+{
+       struct fe_priv *np = netdev_priv(dev);
+       u8 __iomem *base = get_hwbase(dev);
+
+       np->estats.tx_bytes += readl(base + NvRegTxCnt);
+       np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
+       np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
+       np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
+       np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
+       np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
+       np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
+       np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
+       np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
+       np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
+       np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
+       np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
+       np->estats.rx_runt += readl(base + NvRegRxRunt);
+       np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
+       np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
+       np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
+       np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
+       np->estats.rx_length_error += readl(base + NvRegRxLenErr);
+       np->estats.rx_unicast += readl(base + NvRegRxUnicast);
+       np->estats.rx_multicast += readl(base + NvRegRxMulticast);
+       np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
+       np->estats.rx_packets =
+               np->estats.rx_unicast +
+               np->estats.rx_multicast +
+               np->estats.rx_broadcast;
+       np->estats.rx_errors_total =
+               np->estats.rx_crc_errors +
+               np->estats.rx_over_errors +
+               np->estats.rx_frame_error +
+               (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
+               np->estats.rx_late_collision +
+               np->estats.rx_runt +
+               np->estats.rx_frame_too_long;
+       np->estats.tx_errors_total =
+               np->estats.tx_late_collision +
+               np->estats.tx_fifo_errors +
+               np->estats.tx_carrier_errors +
+               np->estats.tx_excess_deferral +
+               np->estats.tx_retry_error;
+
+       if (np->driver_data & DEV_HAS_STATISTICS_V2) {
+               np->estats.tx_deferral += readl(base + NvRegTxDef);
+               np->estats.tx_packets += readl(base + NvRegTxFrame);
+               np->estats.rx_bytes += readl(base + NvRegRxCnt);
+               np->estats.tx_pause += readl(base + NvRegTxPause);
+               np->estats.rx_pause += readl(base + NvRegRxPause);
+               np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
+       }
+}
+
 /*
  * nv_get_stats: dev->get_stats function
  * Get latest stats value from the nic.
@@ -1289,10 +1352,19 @@ static struct net_device_stats *nv_get_stats(struct net_device *dev)
 {
        struct fe_priv *np = netdev_priv(dev);
 
-       /* It seems that the nic always generates interrupts and doesn't
-        * accumulate errors internally. Thus the current values in np->stats
-        * are already up to date.
-        */
+       /* If the nic supports hw counters then retrieve latest values */
+       if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2)) {
+               nv_get_hw_stats(dev);
+
+               /* copy to net_device stats */
+               np->stats.tx_bytes = np->estats.tx_bytes;
+               np->stats.tx_fifo_errors = np->estats.tx_fifo_errors;
+               np->stats.tx_carrier_errors = np->estats.tx_carrier_errors;
+               np->stats.rx_crc_errors = np->estats.rx_crc_errors;
+               np->stats.rx_over_errors = np->estats.rx_over_errors;
+               np->stats.rx_errors = np->estats.rx_errors_total;
+               np->stats.tx_errors = np->estats.tx_errors_total;
+       }
        return &np->stats;
 }
 
@@ -1304,43 +1376,63 @@ static struct net_device_stats *nv_get_stats(struct net_device *dev)
 static int nv_alloc_rx(struct net_device *dev)
 {
        struct fe_priv *np = netdev_priv(dev);
-       unsigned int refill_rx = np->refill_rx;
-       int nr;
-
-       while (np->cur_rx != refill_rx) {
-               struct sk_buff *skb;
-
-               nr = refill_rx % np->rx_ring_size;
-               if (np->rx_skbuff[nr] == NULL) {
+       struct ring_desc* less_rx;
 
-                       skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
-                       if (!skb)
-                               break;
+       less_rx = np->get_rx.orig;
+       if (less_rx-- == np->first_rx.orig)
+               less_rx = np->last_rx.orig;
 
+       while (np->put_rx.orig != less_rx) {
+               struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
+               if (skb) {
                        skb->dev = dev;
-                       np->rx_skbuff[nr] = skb;
+                       np->put_rx_ctx->skb = skb;
+                       np->put_rx_ctx->dma = pci_map_single(np->pci_dev, skb->data,
+                                                            skb->end-skb->data, PCI_DMA_FROMDEVICE);
+                       np->put_rx_ctx->dma_len = skb->end-skb->data;
+                       np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
+                       wmb();
+                       np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
+                       if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
+                               np->put_rx.orig = np->first_rx.orig;
+                       if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
+                               np->put_rx_ctx = np->first_rx_ctx;
                } else {
-                       skb = np->rx_skbuff[nr];
+                       return 1;
                }
-               np->rx_dma[nr] = pci_map_single(np->pci_dev, skb->data,
-                                       skb->end-skb->data, PCI_DMA_FROMDEVICE);
-               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
-                       np->rx_ring.orig[nr].buf = cpu_to_le32(np->rx_dma[nr]);
+       }
+       return 0;
+}
+
+static int nv_alloc_rx_optimized(struct net_device *dev)
+{
+       struct fe_priv *np = netdev_priv(dev);
+       struct ring_desc_ex* less_rx;
+
+       less_rx = np->get_rx.ex;
+       if (less_rx-- == np->first_rx.ex)
+               less_rx = np->last_rx.ex;
+
+       while (np->put_rx.ex != less_rx) {
+               struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
+               if (skb) {
+                       skb->dev = dev;
+                       np->put_rx_ctx->skb = skb;
+                       np->put_rx_ctx->dma = pci_map_single(np->pci_dev, skb->data,
+                                                            skb->end-skb->data, PCI_DMA_FROMDEVICE);
+                       np->put_rx_ctx->dma_len = skb->end-skb->data;
+                       np->put_rx.ex->bufhigh = cpu_to_le64(np->put_rx_ctx->dma) >> 32;
+                       np->put_rx.ex->buflow = cpu_to_le64(np->put_rx_ctx->dma) & 0x0FFFFFFFF;
                        wmb();
-                       np->rx_ring.orig[nr].flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
+                       np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
+                       if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
+                               np->put_rx.ex = np->first_rx.ex;
+                       if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
+                               np->put_rx_ctx = np->first_rx_ctx;
                } else {
-                       np->rx_ring.ex[nr].bufhigh = cpu_to_le64(np->rx_dma[nr]) >> 32;
-                       np->rx_ring.ex[nr].buflow = cpu_to_le64(np->rx_dma[nr]) & 0x0FFFFFFFF;
-                       wmb();
-                       np->rx_ring.ex[nr].flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
+                       return 1;
                }
-               dprintk(KERN_DEBUG "%s: nv_alloc_rx: Packet %d marked as Available\n",
-                                       dev->name, refill_rx);
-               refill_rx++;
        }
-       np->refill_rx = refill_rx;
-       if (np->cur_rx - refill_rx == np->rx_ring_size)
-               return 1;
        return 0;
 }
 
@@ -1358,6 +1450,7 @@ static void nv_do_rx_refill(unsigned long data)
 {
        struct net_device *dev = (struct net_device *) data;
        struct fe_priv *np = netdev_priv(dev);
+       int retcode;
 
        if (!using_multi_irqs(dev)) {
                if (np->msi_flags & NV_MSI_X_ENABLED)
@@ -1367,7 +1460,11 @@ static void nv_do_rx_refill(unsigned long data)
        } else {
                disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
        }
-       if (nv_alloc_rx(dev)) {
+       if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+               retcode = nv_alloc_rx(dev);
+       else
+               retcode = nv_alloc_rx_optimized(dev);
+       if (retcode) {
                spin_lock_irq(&np->lock);
                if (!np->in_shutdown)
                        mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
@@ -1388,56 +1485,81 @@ static void nv_init_rx(struct net_device *dev)
 {
        struct fe_priv *np = netdev_priv(dev);
        int i;
+       np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
+       if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+               np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1];
+       else
+               np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1];
+       np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
+       np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1];
 
-       np->cur_rx = np->rx_ring_size;
-       np->refill_rx = 0;
-       for (i = 0; i < np->rx_ring_size; i++)
-               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+       for (i = 0; i < np->rx_ring_size; i++) {
+               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
                        np->rx_ring.orig[i].flaglen = 0;
-               else
+                       np->rx_ring.orig[i].buf = 0;
+               } else {
                        np->rx_ring.ex[i].flaglen = 0;
+                       np->rx_ring.ex[i].txvlan = 0;
+                       np->rx_ring.ex[i].bufhigh = 0;
+                       np->rx_ring.ex[i].buflow = 0;
+               }
+               np->rx_skb[i].skb = NULL;
+               np->rx_skb[i].dma = 0;
+       }
 }
 
 static void nv_init_tx(struct net_device *dev)
 {
        struct fe_priv *np = netdev_priv(dev);
        int i;
+       np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
+       if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+               np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1];
+       else
+               np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1];
+       np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
+       np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1];
 
-       np->next_tx = np->nic_tx = 0;
        for (i = 0; i < np->tx_ring_size; i++) {
-               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
                        np->tx_ring.orig[i].flaglen = 0;
-               else
+                       np->tx_ring.orig[i].buf = 0;
+               } else {
                        np->tx_ring.ex[i].flaglen = 0;
-               np->tx_skbuff[i] = NULL;
-               np->tx_dma[i] = 0;
+                       np->tx_ring.ex[i].txvlan = 0;
+                       np->tx_ring.ex[i].bufhigh = 0;
+                       np->tx_ring.ex[i].buflow = 0;
+               }
+               np->tx_skb[i].skb = NULL;
+               np->tx_skb[i].dma = 0;
        }
 }
 
 static int nv_init_ring(struct net_device *dev)
 {
+       struct fe_priv *np = netdev_priv(dev);
+
        nv_init_tx(dev);
        nv_init_rx(dev);
-       return nv_alloc_rx(dev);
+       if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+               return nv_alloc_rx(dev);
+       else
+               return nv_alloc_rx_optimized(dev);
 }
 
-static int nv_release_txskb(struct net_device *dev, unsigned int skbnr)
+static int nv_release_txskb(struct net_device *dev, struct nv_skb_map* tx_skb)
 {
        struct fe_priv *np = netdev_priv(dev);
 
-       dprintk(KERN_INFO "%s: nv_release_txskb for skbnr %d\n",
-               dev->name, skbnr);
-
-       if (np->tx_dma[skbnr]) {
-               pci_unmap_page(np->pci_dev, np->tx_dma[skbnr],
-                              np->tx_dma_len[skbnr],
+       if (tx_skb->dma) {
+               pci_unmap_page(np->pci_dev, tx_skb->dma,
+                              tx_skb->dma_len,
                               PCI_DMA_TODEVICE);
-               np->tx_dma[skbnr] = 0;
+               tx_skb->dma = 0;
        }
-
-       if (np->tx_skbuff[skbnr]) {
-               dev_kfree_skb_any(np->tx_skbuff[skbnr]);
-               np->tx_skbuff[skbnr] = NULL;
+       if (tx_skb->skb) {
+               dev_kfree_skb_any(tx_skb->skb);
+               tx_skb->skb = NULL;
                return 1;
        } else {
                return 0;
@@ -1450,11 +1572,16 @@ static void nv_drain_tx(struct net_device *dev)
        unsigned int i;
 
        for (i = 0; i < np->tx_ring_size; i++) {
-               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
                        np->tx_ring.orig[i].flaglen = 0;
-               else
+                       np->tx_ring.orig[i].buf = 0;
+               } else {
                        np->tx_ring.ex[i].flaglen = 0;
-               if (nv_release_txskb(dev, i))
+                       np->tx_ring.ex[i].txvlan = 0;
+                       np->tx_ring.ex[i].bufhigh = 0;
+                       np->tx_ring.ex[i].buflow = 0;
+               }
+               if (nv_release_txskb(dev, &np->tx_skb[i]))
                        np->stats.tx_dropped++;
        }
 }
@@ -1463,18 +1590,24 @@ static void nv_drain_rx(struct net_device *dev)
 {
        struct fe_priv *np = netdev_priv(dev);
        int i;
+
        for (i = 0; i < np->rx_ring_size; i++) {
-               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
                        np->rx_ring.orig[i].flaglen = 0;
-               else
+                       np->rx_ring.orig[i].buf = 0;
+               } else {
                        np->rx_ring.ex[i].flaglen = 0;
+                       np->rx_ring.ex[i].txvlan = 0;
+                       np->rx_ring.ex[i].bufhigh = 0;
+                       np->rx_ring.ex[i].buflow = 0;
+               }
                wmb();
-               if (np->rx_skbuff[i]) {
-                       pci_unmap_single(np->pci_dev, np->rx_dma[i],
-                                               np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
+               if (np->rx_skb[i].skb) {
+                       pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
+                                               np->rx_skb[i].skb->end-np->rx_skb[i].skb->data,
                                                PCI_DMA_FROMDEVICE);
-                       dev_kfree_skb(np->rx_skbuff[i]);
-                       np->rx_skbuff[i] = NULL;
+                       dev_kfree_skb(np->rx_skb[i].skb);
+                       np->rx_skb[i].skb = NULL;
                }
        }
 }
@@ -1485,6 +1618,11 @@ static void drain_ring(struct net_device *dev)
        nv_drain_rx(dev);
 }
 
+static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
+{
+       return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
+}
+
 /*
  * nv_start_xmit: dev->hard_start_xmit function
  * Called with netif_tx_lock held.
@@ -1495,14 +1633,16 @@ static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
        u32 tx_flags = 0;
        u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
        unsigned int fragments = skb_shinfo(skb)->nr_frags;
-       unsigned int nr = (np->next_tx - 1) % np->tx_ring_size;
-       unsigned int start_nr = np->next_tx % np->tx_ring_size;
        unsigned int i;
        u32 offset = 0;
        u32 bcnt;
        u32 size = skb->len-skb->data_len;
        u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
-       u32 tx_flags_vlan = 0;
+       u32 empty_slots;
+       struct ring_desc* put_tx;
+       struct ring_desc* start_tx;
+       struct ring_desc* prev_tx;
+       struct nv_skb_map* prev_tx_ctx;
 
        /* add fragments to entries count */
        for (i = 0; i < fragments; i++) {
@@ -1510,34 +1650,35 @@ static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
                           ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
        }
 
-       spin_lock_irq(&np->lock);
-
-       if ((np->next_tx - np->nic_tx + entries - 1) > np->tx_limit_stop) {
-               spin_unlock_irq(&np->lock);
+       empty_slots = nv_get_empty_tx_slots(np);
+       if (unlikely(empty_slots <= entries)) {
+               spin_lock_irq(&np->lock);
                netif_stop_queue(dev);
+               np->tx_stop = 1;
+               spin_unlock_irq(&np->lock);
                return NETDEV_TX_BUSY;
        }
 
+       start_tx = put_tx = np->put_tx.orig;
+
        /* setup the header buffer */
        do {
+               prev_tx = put_tx;
+               prev_tx_ctx = np->put_tx_ctx;
                bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
-               nr = (nr + 1) % np->tx_ring_size;
-
-               np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
+               np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
                                                PCI_DMA_TODEVICE);
-               np->tx_dma_len[nr] = bcnt;
+               np->put_tx_ctx->dma_len = bcnt;
+               put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
+               put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
 
-               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
-                       np->tx_ring.orig[nr].buf = cpu_to_le32(np->tx_dma[nr]);
-                       np->tx_ring.orig[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
-               } else {
-                       np->tx_ring.ex[nr].bufhigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
-                       np->tx_ring.ex[nr].buflow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
-                       np->tx_ring.ex[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
-               }
                tx_flags = np->tx_flags;
                offset += bcnt;
                size -= bcnt;
+               if (unlikely(put_tx++ == np->last_tx.orig))
+                       put_tx = np->first_tx.orig;
+               if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
+                       np->put_tx_ctx = np->first_tx_ctx;
        } while (size);
 
        /* setup the fragments */
@@ -1547,58 +1688,174 @@ static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
                offset = 0;
 
                do {
+                       prev_tx = put_tx;
+                       prev_tx_ctx = np->put_tx_ctx;
                        bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
-                       nr = (nr + 1) % np->tx_ring_size;
+                       np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
+                                                          PCI_DMA_TODEVICE);
+                       np->put_tx_ctx->dma_len = bcnt;
+                       put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
+                       put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
 
-                       np->tx_dma[nr] = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
-                                                     PCI_DMA_TODEVICE);
-                       np->tx_dma_len[nr] = bcnt;
-
-                       if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
-                               np->tx_ring.orig[nr].buf = cpu_to_le32(np->tx_dma[nr]);
-                               np->tx_ring.orig[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
-                       } else {
-                               np->tx_ring.ex[nr].bufhigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
-                               np->tx_ring.ex[nr].buflow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
-                               np->tx_ring.ex[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
-                       }
                        offset += bcnt;
                        size -= bcnt;
+                       if (unlikely(put_tx++ == np->last_tx.orig))
+                               put_tx = np->first_tx.orig;
+                       if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
+                               np->put_tx_ctx = np->first_tx_ctx;
                } while (size);
        }
 
        /* set last fragment flag  */
-       if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
-               np->tx_ring.orig[nr].flaglen |= cpu_to_le32(tx_flags_extra);
-       } else {
-               np->tx_ring.ex[nr].flaglen |= cpu_to_le32(tx_flags_extra);
+       prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
+
+       /* save skb in this slot's context area */
+       prev_tx_ctx->skb = skb;
+
+       if (skb_is_gso(skb))
+               tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
+       else
+               tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
+                        NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
+
+       spin_lock_irq(&np->lock);
+
+       /* set tx flags */
+       start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
+       np->put_tx.orig = put_tx;
+
+       spin_unlock_irq(&np->lock);
+
+       dprintk(KERN_DEBUG "%s: nv_start_xmit: entries %d queued for transmission. tx_flags_extra: %x\n",
+               dev->name, entries, tx_flags_extra);
+       {
+               int j;
+               for (j=0; j<64; j++) {
+                       if ((j%16) == 0)
+                               dprintk("\n%03x:", j);
+                       dprintk(" %02x", ((unsigned char*)skb->data)[j]);
+               }
+               dprintk("\n");
        }
 
-       np->tx_skbuff[nr] = skb;
+       dev->trans_start = jiffies;
+       writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
+       return NETDEV_TX_OK;
+}
+
+static int nv_start_xmit_optimized(struct sk_buff *skb, struct net_device *dev)
+{
+       struct fe_priv *np = netdev_priv(dev);
+       u32 tx_flags = 0;
+       u32 tx_flags_extra;
+       unsigned int fragments = skb_shinfo(skb)->nr_frags;
+       unsigned int i;
+       u32 offset = 0;
+       u32 bcnt;
+       u32 size = skb->len-skb->data_len;
+       u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
+       u32 empty_slots;
+       struct ring_desc_ex* put_tx;
+       struct ring_desc_ex* start_tx;
+       struct ring_desc_ex* prev_tx;
+       struct nv_skb_map* prev_tx_ctx;
+
+       /* add fragments to entries count */
+       for (i = 0; i < fragments; i++) {
+               entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
+                          ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
+       }
+
+       empty_slots = nv_get_empty_tx_slots(np);
+       if (unlikely(empty_slots <= entries)) {
+               spin_lock_irq(&np->lock);
+               netif_stop_queue(dev);
+               np->tx_stop = 1;
+               spin_unlock_irq(&np->lock);
+               return NETDEV_TX_BUSY;
+       }
+
+       start_tx = put_tx = np->put_tx.ex;
+
+       /* setup the header buffer */
+       do {
+               prev_tx = put_tx;
+               prev_tx_ctx = np->put_tx_ctx;
+               bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
+               np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
+                                               PCI_DMA_TODEVICE);
+               np->put_tx_ctx->dma_len = bcnt;
+               put_tx->bufhigh = cpu_to_le64(np->put_tx_ctx->dma) >> 32;
+               put_tx->buflow = cpu_to_le64(np->put_tx_ctx->dma) & 0x0FFFFFFFF;
+               put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
+
+               tx_flags = NV_TX2_VALID;
+               offset += bcnt;
+               size -= bcnt;
+               if (unlikely(put_tx++ == np->last_tx.ex))
+                       put_tx = np->first_tx.ex;
+               if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
+                       np->put_tx_ctx = np->first_tx_ctx;
+       } while (size);
+
+       /* setup the fragments */
+       for (i = 0; i < fragments; i++) {
+               skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
+               u32 size = frag->size;
+               offset = 0;
+
+               do {
+                       prev_tx = put_tx;
+                       prev_tx_ctx = np->put_tx_ctx;
+                       bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
+                       np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
+                                                          PCI_DMA_TODEVICE);
+                       np->put_tx_ctx->dma_len = bcnt;
+                       put_tx->bufhigh = cpu_to_le64(np->put_tx_ctx->dma) >> 32;
+                       put_tx->buflow = cpu_to_le64(np->put_tx_ctx->dma) & 0x0FFFFFFFF;
+                       put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
+
+                       offset += bcnt;
+                       size -= bcnt;
+                       if (unlikely(put_tx++ == np->last_tx.ex))
+                               put_tx = np->first_tx.ex;
+                       if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
+                               np->put_tx_ctx = np->first_tx_ctx;
+               } while (size);
+       }
+
+       /* set last fragment flag  */
+       prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
+
+       /* save skb in this slot's context area */
+       prev_tx_ctx->skb = skb;
 
-#ifdef NETIF_F_TSO
        if (skb_is_gso(skb))
                tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
        else
-#endif
-       tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
+               tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
                         NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
 
        /* vlan tag */
-       if (np->vlangrp && vlan_tx_tag_present(skb)) {
-               tx_flags_vlan = NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb);
+       if (likely(!np->vlangrp)) {
+               start_tx->txvlan = 0;
+       } else {
+               if (vlan_tx_tag_present(skb))
+                       start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb));
+               else
+                       start_tx->txvlan = 0;
        }
 
+       spin_lock_irq(&np->lock);
+
        /* set tx flags */
-       if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
-               np->tx_ring.orig[start_nr].flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
-       } else {
-               np->tx_ring.ex[start_nr].txvlan = cpu_to_le32(tx_flags_vlan);
-               np->tx_ring.ex[start_nr].flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
-       }
+       start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
+       np->put_tx.ex = put_tx;
+
+       spin_unlock_irq(&np->lock);
 
-       dprintk(KERN_DEBUG "%s: nv_start_xmit: packet %d (entries %d) queued for transmission. tx_flags_extra: %x\n",
-               dev->name, np->next_tx, entries, tx_flags_extra);
+       dprintk(KERN_DEBUG "%s: nv_start_xmit_optimized: entries %d queued for transmission. tx_flags_extra: %x\n",
+               dev->name, entries, tx_flags_extra);
        {
                int j;
                for (j=0; j<64; j++) {
@@ -1609,12 +1866,8 @@ static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
                dprintk("\n");
        }
 
-       np->next_tx += entries;
-
        dev->trans_start = jiffies;
-       spin_unlock_irq(&np->lock);
        writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
-       pci_push(get_hwbase(dev));
        return NETDEV_TX_OK;
 }
 
@@ -1627,26 +1880,22 @@ static void nv_tx_done(struct net_device *dev)
 {
        struct fe_priv *np = netdev_priv(dev);
        u32 flags;
-       unsigned int i;
-       struct sk_buff *skb;
+       struct ring_desc* orig_get_tx = np->get_tx.orig;
 
-       while (np->nic_tx != np->next_tx) {
-               i = np->nic_tx % np->tx_ring_size;
+       while ((np->get_tx.orig != np->put_tx.orig) &&
+              !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID)) {
 
-               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
-                       flags = le32_to_cpu(np->tx_ring.orig[i].flaglen);
-               else
-                       flags = le32_to_cpu(np->tx_ring.ex[i].flaglen);
+               dprintk(KERN_DEBUG "%s: nv_tx_done: flags 0x%x.\n",
+                                       dev->name, flags);
+
+               pci_unmap_page(np->pci_dev, np->get_tx_ctx->dma,
+                              np->get_tx_ctx->dma_len,
+                              PCI_DMA_TODEVICE);
+               np->get_tx_ctx->dma = 0;
 
-               dprintk(KERN_DEBUG "%s: nv_tx_done: looking at packet %d, flags 0x%x.\n",
-                                       dev->name, np->nic_tx, flags);
-               if (flags & NV_TX_VALID)
-                       break;
                if (np->desc_ver == DESC_VER_1) {
                        if (flags & NV_TX_LASTPACKET) {
-                               skb = np->tx_skbuff[i];
-                               if (flags & (NV_TX_RETRYERROR|NV_TX_CARRIERLOST|NV_TX_LATECOLLISION|
-                                            NV_TX_UNDERFLOW|NV_TX_ERROR)) {
+                               if (flags & NV_TX_ERROR) {
                                        if (flags & NV_TX_UNDERFLOW)
                                                np->stats.tx_fifo_errors++;
                                        if (flags & NV_TX_CARRIERLOST)
@@ -1654,14 +1903,14 @@ static void nv_tx_done(struct net_device *dev)
                                        np->stats.tx_errors++;
                                } else {
                                        np->stats.tx_packets++;
-                                       np->stats.tx_bytes += skb->len;
+                                       np->stats.tx_bytes += np->get_tx_ctx->skb->len;
                                }
+                               dev_kfree_skb_any(np->get_tx_ctx->skb);
+                               np->get_tx_ctx->skb = NULL;
                        }
                } else {
                        if (flags & NV_TX2_LASTPACKET) {
-                               skb = np->tx_skbuff[i];
-                               if (flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION|
-                                            NV_TX2_UNDERFLOW|NV_TX2_ERROR)) {
+                               if (flags & NV_TX2_ERROR) {
                                        if (flags & NV_TX2_UNDERFLOW)
                                                np->stats.tx_fifo_errors++;
                                        if (flags & NV_TX2_CARRIERLOST)
@@ -1669,15 +1918,56 @@ static void nv_tx_done(struct net_device *dev)
                                        np->stats.tx_errors++;
                                } else {
                                        np->stats.tx_packets++;
-                                       np->stats.tx_bytes += skb->len;
+                                       np->stats.tx_bytes += np->get_tx_ctx->skb->len;
                                }
+                               dev_kfree_skb_any(np->get_tx_ctx->skb);
+                               np->get_tx_ctx->skb = NULL;
                        }
                }
-               nv_release_txskb(dev, i);
-               np->nic_tx++;
+               if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
+                       np->get_tx.orig = np->first_tx.orig;
+               if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
+                       np->get_tx_ctx = np->first_tx_ctx;
+       }
+       if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
+               np->tx_stop = 0;
+               netif_wake_queue(dev);
+       }
+}
+
+static void nv_tx_done_optimized(struct net_device *dev, int limit)
+{
+       struct fe_priv *np = netdev_priv(dev);
+       u32 flags;
+       struct ring_desc_ex* orig_get_tx = np->get_tx.ex;
+
+       while ((np->get_tx.ex != np->put_tx.ex) &&
+              !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX_VALID) &&
+              (limit-- > 0)) {
+
+               dprintk(KERN_DEBUG "%s: nv_tx_done_optimized: flags 0x%x.\n",
+                                       dev->name, flags);
+
+               pci_unmap_page(np->pci_dev, np->get_tx_ctx->dma,
+                              np->get_tx_ctx->dma_len,
+                              PCI_DMA_TODEVICE);
+               np->get_tx_ctx->dma = 0;
+
+               if (flags & NV_TX2_LASTPACKET) {
+                       if (!(flags & NV_TX2_ERROR))
+                               np->stats.tx_packets++;
+                       dev_kfree_skb_any(np->get_tx_ctx->skb);
+                       np->get_tx_ctx->skb = NULL;
+               }
+               if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
+                       np->get_tx.ex = np->first_tx.ex;
+               if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
+                       np->get_tx_ctx = np->first_tx_ctx;
        }
-       if (np->next_tx - np->nic_tx < np->tx_limit_start)
+       if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
+               np->tx_stop = 0;
                netif_wake_queue(dev);
+       }
 }
 
 /*
@@ -1700,9 +1990,8 @@ static void nv_tx_timeout(struct net_device *dev)
        {
                int i;
 
-               printk(KERN_INFO "%s: Ring at %lx: next %d nic %d\n",
-                               dev->name, (unsigned long)np->ring_addr,
-                               np->next_tx, np->nic_tx);
+               printk(KERN_INFO "%s: Ring at %lx\n",
+                      dev->name, (unsigned long)np->ring_addr);
                printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
                for (i=0;i<=np->register_size;i+= 32) {
                        printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
@@ -1750,13 +2039,16 @@ static void nv_tx_timeout(struct net_device *dev)
        nv_stop_tx(dev);
 
        /* 2) check that the packets were not sent already: */
-       nv_tx_done(dev);
+       if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+               nv_tx_done(dev);
+       else
+               nv_tx_done_optimized(dev, np->tx_ring_size);
 
        /* 3) if there are dead entries: clear everything */
-       if (np->next_tx != np->nic_tx) {
+       if (np->get_tx_ctx != np->put_tx_ctx) {
                printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name);
                nv_drain_tx(dev);
-               np->next_tx = np->nic_tx = 0;
+               nv_init_tx(dev);
                setup_hw_rings(dev, NV_SETUP_TX_RING);
                netif_wake_queue(dev);
        }
@@ -1813,50 +2105,175 @@ static int nv_getlen(struct net_device *dev, void *packet, int datalen)
                                        dev->name);
                        return -1;
                }
-               dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
-                               dev->name, datalen);
-               return datalen;
+               dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
+                               dev->name, datalen);
+               return datalen;
+       }
+}
+
+static int nv_rx_process(struct net_device *dev, int limit)
+{
+       struct fe_priv *np = netdev_priv(dev);
+       u32 flags;
+       u32 rx_processed_cnt = 0;
+       struct sk_buff *skb;
+       int len;
+
+       while((np->get_rx.orig != np->put_rx.orig) &&
+             !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) &&
+               (rx_processed_cnt++ < limit)) {
+
+               dprintk(KERN_DEBUG "%s: nv_rx_process: flags 0x%x.\n",
+                                       dev->name, flags);
+
+               /*
+                * the packet is for us - immediately tear down the pci mapping.
+                * TODO: check if a prefetch of the first cacheline improves
+                * the performance.
+                */
+               pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
+                               np->get_rx_ctx->dma_len,
+                               PCI_DMA_FROMDEVICE);
+               skb = np->get_rx_ctx->skb;
+               np->get_rx_ctx->skb = NULL;
+
+               {
+                       int j;
+                       dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
+                       for (j=0; j<64; j++) {
+                               if ((j%16) == 0)
+                                       dprintk("\n%03x:", j);
+                               dprintk(" %02x", ((unsigned char*)skb->data)[j]);
+                       }
+                       dprintk("\n");
+               }
+               /* look at what we actually got: */
+               if (np->desc_ver == DESC_VER_1) {
+                       if (likely(flags & NV_RX_DESCRIPTORVALID)) {
+                               len = flags & LEN_MASK_V1;
+                               if (unlikely(flags & NV_RX_ERROR)) {
+                                       if (flags & NV_RX_ERROR4) {
+                                               len = nv_getlen(dev, skb->data, len);
+                                               if (len < 0) {
+                                                       np->stats.rx_errors++;
+                                                       dev_kfree_skb(skb);
+                                                       goto next_pkt;
+                                               }
+                                       }
+                                       /* framing errors are soft errors */
+                                       else if (flags & NV_RX_FRAMINGERR) {
+                                               if (flags & NV_RX_SUBSTRACT1) {
+                                                       len--;
+                                               }
+                                       }
+                                       /* the rest are hard errors */
+                                       else {
+                                               if (flags & NV_RX_MISSEDFRAME)
+                                                       np->stats.rx_missed_errors++;
+                                               if (flags & NV_RX_CRCERR)
+                                                       np->stats.rx_crc_errors++;
+                                               if (flags & NV_RX_OVERFLOW)
+                                                       np->stats.rx_over_errors++;
+                                               np->stats.rx_errors++;
+                                               dev_kfree_skb(skb);
+                                               goto next_pkt;
+                                       }
+                               }
+                       } else {
+                               dev_kfree_skb(skb);
+                               goto next_pkt;
+                       }
+               } else {
+                       if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
+                               len = flags & LEN_MASK_V2;
+                               if (unlikely(flags & NV_RX2_ERROR)) {
+                                       if (flags & NV_RX2_ERROR4) {
+                                               len = nv_getlen(dev, skb->data, len);
+                                               if (len < 0) {
+                                                       np->stats.rx_errors++;
+                                                       dev_kfree_skb(skb);
+                                                       goto next_pkt;
+                                               }
+                                       }
+                                       /* framing errors are soft errors */
+                                       else if (flags & NV_RX2_FRAMINGERR) {
+                                               if (flags & NV_RX2_SUBSTRACT1) {
+                                                       len--;
+                                               }
+                                       }
+                                       /* the rest are hard errors */
+                                       else {
+                                               if (flags & NV_RX2_CRCERR)
+                                                       np->stats.rx_crc_errors++;
+                                               if (flags & NV_RX2_OVERFLOW)
+                                                       np->stats.rx_over_errors++;
+                                               np->stats.rx_errors++;
+                                               dev_kfree_skb(skb);
+                                               goto next_pkt;
+                                       }
+                               }
+                               if ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK2)/*ip and tcp */ {
+                                       skb->ip_summed = CHECKSUM_UNNECESSARY;
+                               } else {
+                                       if ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK1 ||
+                                           (flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK3) {
+                                               skb->ip_summed = CHECKSUM_UNNECESSARY;
+                                       }
+                               }
+                       } else {
+                               dev_kfree_skb(skb);
+                               goto next_pkt;
+                       }
+               }
+               /* got a valid packet - forward it to the network core */
+               skb_put(skb, len);
+               skb->protocol = eth_type_trans(skb, dev);
+               dprintk(KERN_DEBUG "%s: nv_rx_process: %d bytes, proto %d accepted.\n",
+                                       dev->name, len, skb->protocol);
+#ifdef CONFIG_FORCEDETH_NAPI
+               netif_receive_skb(skb);
+#else
+               netif_rx(skb);
+#endif
+               dev->last_rx = jiffies;
+               np->stats.rx_packets++;
+               np->stats.rx_bytes += len;
+next_pkt:
+               if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
+                       np->get_rx.orig = np->first_rx.orig;
+               if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
+                       np->get_rx_ctx = np->first_rx_ctx;
        }
+
+       return rx_processed_cnt;
 }
 
-static int nv_rx_process(struct net_device *dev, int limit)
+static int nv_rx_process_optimized(struct net_device *dev, int limit)
 {
        struct fe_priv *np = netdev_priv(dev);
        u32 flags;
        u32 vlanflags = 0;
-       int count;
-
-       for (count = 0; count < limit; ++count) {
-               struct sk_buff *skb;
-               int len;
-               int i;
-               if (np->cur_rx - np->refill_rx >= np->rx_ring_size)
-                       break;  /* we scanned the whole ring - do not continue */
-
-               i = np->cur_rx % np->rx_ring_size;
-               if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
-                       flags = le32_to_cpu(np->rx_ring.orig[i].flaglen);
-                       len = nv_descr_getlength(&np->rx_ring.orig[i], np->desc_ver);
-               } else {
-                       flags = le32_to_cpu(np->rx_ring.ex[i].flaglen);
-                       len = nv_descr_getlength_ex(&np->rx_ring.ex[i], np->desc_ver);
-                       vlanflags = le32_to_cpu(np->rx_ring.ex[i].buflow);
-               }
+       u32 rx_processed_cnt = 0;
+       struct sk_buff *skb;
+       int len;
 
-               dprintk(KERN_DEBUG "%s: nv_rx_process: looking at packet %d, flags 0x%x.\n",
-                                       dev->name, np->cur_rx, flags);
+       while((np->get_rx.ex != np->put_rx.ex) &&
+             !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) &&
+             (rx_processed_cnt++ < limit)) {
 
-               if (flags & NV_RX_AVAIL)
-                       break;  /* still owned by hardware, */
+               dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: flags 0x%x.\n",
+                                       dev->name, flags);
 
                /*
                 * the packet is for us - immediately tear down the pci mapping.
                 * TODO: check if a prefetch of the first cacheline improves
                 * the performance.
                 */
-               pci_unmap_single(np->pci_dev, np->rx_dma[i],
-                               np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
+               pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
+                               np->get_rx_ctx->dma_len,
                                PCI_DMA_FROMDEVICE);
+               skb = np->get_rx_ctx->skb;
+               np->get_rx_ctx->skb = NULL;
 
                {
                        int j;
@@ -1864,123 +2281,90 @@ static int nv_rx_process(struct net_device *dev, int limit)
                        for (j=0; j<64; j++) {
                                if ((j%16) == 0)
                                        dprintk("\n%03x:", j);
-                               dprintk(" %02x", ((unsigned char*)np->rx_skbuff[i]->data)[j]);
+                               dprintk(" %02x", ((unsigned char*)skb->data)[j]);
                        }
                        dprintk("\n");
                }
                /* look at what we actually got: */
-               if (np->desc_ver == DESC_VER_1) {
-                       if (!(flags & NV_RX_DESCRIPTORVALID))
-                               goto next_pkt;
-
-                       if (flags & NV_RX_ERROR) {
-                               if (flags & NV_RX_MISSEDFRAME) {
-                                       np->stats.rx_missed_errors++;
-                                       np->stats.rx_errors++;
-                                       goto next_pkt;
-                               }
-                               if (flags & (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3)) {
-                                       np->stats.rx_errors++;
-                                       goto next_pkt;
-                               }
-                               if (flags & NV_RX_CRCERR) {
-                                       np->stats.rx_crc_errors++;
-                                       np->stats.rx_errors++;
-                                       goto next_pkt;
-                               }
-                               if (flags & NV_RX_OVERFLOW) {
-                                       np->stats.rx_over_errors++;
-                                       np->stats.rx_errors++;
-                                       goto next_pkt;
-                               }
-                               if (flags & NV_RX_ERROR4) {
-                                       len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
-                                       if (len < 0) {
-                                               np->stats.rx_errors++;
-                                               goto next_pkt;
-                                       }
-                               }
-                               /* framing errors are soft errors. */
-                               if (flags & NV_RX_FRAMINGERR) {
-                                       if (flags & NV_RX_SUBSTRACT1) {
-                                               len--;
-                                       }
-                               }
-                       }
-               } else {
-                       if (!(flags & NV_RX2_DESCRIPTORVALID))
-                               goto next_pkt;
-
-                       if (flags & NV_RX2_ERROR) {
-                               if (flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) {
-                                       np->stats.rx_errors++;
-                                       goto next_pkt;
-                               }
-                               if (flags & NV_RX2_CRCERR) {
-                                       np->stats.rx_crc_errors++;
-                                       np->stats.rx_errors++;
-                                       goto next_pkt;
-                               }
-                               if (flags & NV_RX2_OVERFLOW) {
-                                       np->stats.rx_over_errors++;
-                                       np->stats.rx_errors++;
-                                       goto next_pkt;
-                               }
+               if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
+                       len = flags & LEN_MASK_V2;
+                       if (unlikely(flags & NV_RX2_ERROR)) {
                                if (flags & NV_RX2_ERROR4) {
-                                       len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
+                                       len = nv_getlen(dev, skb->data, len);
                                        if (len < 0) {
-                                               np->stats.rx_errors++;
+                                               dev_kfree_skb(skb);
                                                goto next_pkt;
                                        }
                                }
                                /* framing errors are soft errors */
-                               if (flags & NV_RX2_FRAMINGERR) {
+                               else if (flags & NV_RX2_FRAMINGERR) {
                                        if (flags & NV_RX2_SUBSTRACT1) {
                                                len--;
                                        }
                                }
+                               /* the rest are hard errors */
+                               else {
+                                       dev_kfree_skb(skb);
+                                       goto next_pkt;
+                               }
                        }
-                       if (np->rx_csum) {
-                               flags &= NV_RX2_CHECKSUMMASK;
-                               if (flags == NV_RX2_CHECKSUMOK1 ||
-                                   flags == NV_RX2_CHECKSUMOK2 ||
-                                   flags == NV_RX2_CHECKSUMOK3) {
-                                       dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name);
-                                       np->rx_skbuff[i]->ip_summed = CHECKSUM_UNNECESSARY;
-                               } else {
-                                       dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name);
+
+                       if ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK2)/*ip and tcp */ {
+                               skb->ip_summed = CHECKSUM_UNNECESSARY;
+                       } else {
+                               if ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK1 ||
+                                   (flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUMOK3) {
+                                       skb->ip_summed = CHECKSUM_UNNECESSARY;
                                }
                        }
-               }
-               /* got a valid packet - forward it to the network core */
-               skb = np->rx_skbuff[i];
-               np->rx_skbuff[i] = NULL;
 
-               skb_put(skb, len);
-               skb->protocol = eth_type_trans(skb, dev);
-               dprintk(KERN_DEBUG "%s: nv_rx_process: packet %d with %d bytes, proto %d accepted.\n",
-                                       dev->name, np->cur_rx, len, skb->protocol);
+                       /* got a valid packet - forward it to the network core */
+                       skb_put(skb, len);
+                       skb->protocol = eth_type_trans(skb, dev);
+                       prefetch(skb->data);
+
+                       dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: %d bytes, proto %d accepted.\n",
+                               dev->name, len, skb->protocol);
+
+                       if (likely(!np->vlangrp)) {
 #ifdef CONFIG_FORCEDETH_NAPI
-               if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
-                       vlan_hwaccel_receive_skb(skb, np->vlangrp,
-                                                vlanflags & NV_RX3_VLAN_TAG_MASK);
-               else
-                       netif_receive_skb(skb);
+                               netif_receive_skb(skb);
 #else
-               if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
-                       vlan_hwaccel_rx(skb, np->vlangrp,
-                                       vlanflags & NV_RX3_VLAN_TAG_MASK);
-               else
-                       netif_rx(skb);
+                               netif_rx(skb);
 #endif
-               dev->last_rx = jiffies;
-               np->stats.rx_packets++;
-               np->stats.rx_bytes += len;
+                       } else {
+                               vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
+                               if (vlanflags & NV_RX3_VLAN_TAG_PRESENT) {
+#ifdef CONFIG_FORCEDETH_NAPI
+                                       vlan_hwaccel_receive_skb(skb, np->vlangrp,
+                                                                vlanflags & NV_RX3_VLAN_TAG_MASK);
+#else
+                                       vlan_hwaccel_rx(skb, np->vlangrp,
+                                                       vlanflags & NV_RX3_VLAN_TAG_MASK);
+#endif
+                               } else {
+#ifdef CONFIG_FORCEDETH_NAPI
+                                       netif_receive_skb(skb);
+#else
+                                       netif_rx(skb);
+#endif
+                               }
+                       }
+
+                       dev->last_rx = jiffies;
+                       np->stats.rx_packets++;
+                       np->stats.rx_bytes += len;
+               } else {
+                       dev_kfree_skb(skb);
+               }
 next_pkt:
-               np->cur_rx++;
+               if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
+                       np->get_rx.ex = np->first_rx.ex;
+               if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
+                       np->get_rx_ctx = np->first_rx_ctx;
        }
 
-       return count;
+       return rx_processed_cnt;
 }
 
 static void set_bufsize(struct net_device *dev)
@@ -2456,7 +2840,6 @@ static irqreturn_t nv_nic_irq(int foo, void *data)
                        events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
                        writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
                }
-               pci_push(base);
                dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
                if (!(events & np->irqmask))
                        break;
@@ -2465,22 +2848,46 @@ static irqreturn_t nv_nic_irq(int foo, void *data)
                nv_tx_done(dev);
                spin_unlock(&np->lock);
 
-               if (events & NVREG_IRQ_LINK) {
+#ifdef CONFIG_FORCEDETH_NAPI
+               if (events & NVREG_IRQ_RX_ALL) {
+                       netif_rx_schedule(dev);
+
+                       /* Disable furthur receive irq's */
+                       spin_lock(&np->lock);
+                       np->irqmask &= ~NVREG_IRQ_RX_ALL;
+
+                       if (np->msi_flags & NV_MSI_X_ENABLED)
+                               writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
+                       else
+                               writel(np->irqmask, base + NvRegIrqMask);
+                       spin_unlock(&np->lock);
+               }
+#else
+               if (nv_rx_process(dev, dev->weight)) {
+                       if (unlikely(nv_alloc_rx(dev))) {
+                               spin_lock(&np->lock);
+                               if (!np->in_shutdown)
+                                       mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
+                               spin_unlock(&np->lock);
+                       }
+               }
+#endif
+               if (unlikely(events & NVREG_IRQ_LINK)) {
                        spin_lock(&np->lock);
                        nv_link_irq(dev);
                        spin_unlock(&np->lock);
                }
-               if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
+               if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
                        spin_lock(&np->lock);
                        nv_linkchange(dev);
                        spin_unlock(&np->lock);
                        np->link_timeout = jiffies + LINK_TIMEOUT;
                }
-               if (events & (NVREG_IRQ_TX_ERR)) {
+               if (unlikely(events & (NVREG_IRQ_TX_ERR))) {
                        dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
                                                dev->name, events);
                }
-               if (events & (NVREG_IRQ_UNKNOWN)) {
+               if (unlikely(events & (NVREG_IRQ_UNKNOWN))) {
                        printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
                                                dev->name, events);
                }
@@ -2501,6 +2908,63 @@ static irqreturn_t nv_nic_irq(int foo, void *data)
                        spin_unlock(&np->lock);
                        break;
                }
+               if (unlikely(i > max_interrupt_work)) {
+                       spin_lock(&np->lock);
+                       /* disable interrupts on the nic */
+                       if (!(np->msi_flags & NV_MSI_X_ENABLED))
+                               writel(0, base + NvRegIrqMask);
+                       else
+                               writel(np->irqmask, base + NvRegIrqMask);
+                       pci_push(base);
+
+                       if (!np->in_shutdown) {
+                               np->nic_poll_irq = np->irqmask;
+                               mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
+                       }
+                       printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
+                       spin_unlock(&np->lock);
+                       break;
+               }
+
+       }
+       dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
+
+       return IRQ_RETVAL(i);
+}
+
+#define TX_WORK_PER_LOOP  64
+#define RX_WORK_PER_LOOP  64
+/**
+ * All _optimized functions are used to help increase performance
+ * (reduce CPU and increase throughput). They use descripter version 3,
+ * compiler directives, and reduce memory accesses.
+ */
+static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
+{
+       struct net_device *dev = (struct net_device *) data;
+       struct fe_priv *np = netdev_priv(dev);
+       u8 __iomem *base = get_hwbase(dev);
+       u32 events;
+       int i;
+
+       dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized\n", dev->name);
+
+       for (i=0; ; i++) {
+               if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
+                       events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
+                       writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
+               } else {
+                       events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
+                       writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
+               }
+               dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
+               if (!(events & np->irqmask))
+                       break;
+
+               spin_lock(&np->lock);
+               nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
+               spin_unlock(&np->lock);
+
 #ifdef CONFIG_FORCEDETH_NAPI
                if (events & NVREG_IRQ_RX_ALL) {
                        netif_rx_schedule(dev);
@@ -2516,15 +2980,53 @@ static irqreturn_t nv_nic_irq(int foo, void *data)
                        spin_unlock(&np->lock);
                }
 #else
-               nv_rx_process(dev, dev->weight);
-               if (nv_alloc_rx(dev)) {
+               if (nv_rx_process_optimized(dev, dev->weight)) {
+                       if (unlikely(nv_alloc_rx_optimized(dev))) {
+                               spin_lock(&np->lock);
+                               if (!np->in_shutdown)
+                                       mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
+                               spin_unlock(&np->lock);
+                       }
+               }
+#endif
+               if (unlikely(events & NVREG_IRQ_LINK)) {
                        spin_lock(&np->lock);
-                       if (!np->in_shutdown)
-                               mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
+                       nv_link_irq(dev);
                        spin_unlock(&np->lock);
                }
-#endif
-               if (i > max_interrupt_work) {
+               if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
+                       spin_lock(&np->lock);
+                       nv_linkchange(dev);
+                       spin_unlock(&np->lock);
+                       np->link_timeout = jiffies + LINK_TIMEOUT;
+               }
+               if (unlikely(events & (NVREG_IRQ_TX_ERR))) {
+                       dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
+                                               dev->name, events);
+               }
+               if (unlikely(events & (NVREG_IRQ_UNKNOWN))) {
+                       printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
+                                               dev->name, events);
+               }
+               if (unlikely(events & NVREG_IRQ_RECOVER_ERROR)) {
+                       spin_lock(&np->lock);
+                       /* disable interrupts on the nic */
+                       if (!(np->msi_flags & NV_MSI_X_ENABLED))
+                               writel(0, base + NvRegIrqMask);
+                       else
+                               writel(np->irqmask, base + NvRegIrqMask);
+                       pci_push(base);
+
+                       if (!np->in_shutdown) {
+                               np->nic_poll_irq = np->irqmask;
+                               np->recover_error = 1;
+                               mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
+                       }
+                       spin_unlock(&np->lock);
+                       break;
+               }
+
+               if (unlikely(i > max_interrupt_work)) {
                        spin_lock(&np->lock);
                        /* disable interrupts on the nic */
                        if (!(np->msi_flags & NV_MSI_X_ENABLED))
@@ -2543,7 +3045,7 @@ static irqreturn_t nv_nic_irq(int foo, void *data)
                }
 
        }
-       dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
+       dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized completed\n", dev->name);
 
        return IRQ_RETVAL(i);
 }
@@ -2562,20 +3064,19 @@ static irqreturn_t nv_nic_irq_tx(int foo, void *data)
        for (i=0; ; i++) {
                events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
                writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus);
-               pci_push(base);
                dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
                if (!(events & np->irqmask))
                        break;
 
                spin_lock_irqsave(&np->lock, flags);
-               nv_tx_done(dev);
+               nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
                spin_unlock_irqrestore(&np->lock, flags);
 
-               if (events & (NVREG_IRQ_TX_ERR)) {
+               if (unlikely(events & (NVREG_IRQ_TX_ERR))) {
                        dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
                                                dev->name, events);
                }
-               if (i > max_interrupt_work) {
+               if (unlikely(i > max_interrupt_work)) {
                        spin_lock_irqsave(&np->lock, flags);
                        /* disable interrupts on the nic */
                        writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
@@ -2604,7 +3105,10 @@ static int nv_napi_poll(struct net_device *dev, int *budget)
        u8 __iomem *base = get_hwbase(dev);
        unsigned long flags;
 
-       pkts = nv_rx_process(dev, limit);
+       if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+               pkts = nv_rx_process(dev, limit);
+       else
+               pkts = nv_rx_process_optimized(dev, limit);
 
        if (nv_alloc_rx(dev)) {
                spin_lock_irqsave(&np->lock, flags);
@@ -2670,20 +3174,20 @@ static irqreturn_t nv_nic_irq_rx(int foo, void *data)
        for (i=0; ; i++) {
                events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
                writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
-               pci_push(base);
                dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
                if (!(events & np->irqmask))
                        break;
 
-               nv_rx_process(dev, dev->weight);
-               if (nv_alloc_rx(dev)) {
-                       spin_lock_irqsave(&np->lock, flags);
-                       if (!np->in_shutdown)
-                               mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
-                       spin_unlock_irqrestore(&np->lock, flags);
+               if (nv_rx_process_optimized(dev, dev->weight)) {
+                       if (unlikely(nv_alloc_rx_optimized(dev))) {
+                               spin_lock_irqsave(&np->lock, flags);
+                               if (!np->in_shutdown)
+                                       mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
+                               spin_unlock_irqrestore(&np->lock, flags);
+                       }
                }
 
-               if (i > max_interrupt_work) {
+               if (unlikely(i > max_interrupt_work)) {
                        spin_lock_irqsave(&np->lock, flags);
                        /* disable interrupts on the nic */
                        writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
@@ -2718,11 +3222,15 @@ static irqreturn_t nv_nic_irq_other(int foo, void *data)
        for (i=0; ; i++) {
                events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
                writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus);
-               pci_push(base);
                dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
                if (!(events & np->irqmask))
                        break;
 
+               /* check tx in case we reached max loop limit in tx isr */
+               spin_lock_irqsave(&np->lock, flags);
+               nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
+               spin_unlock_irqrestore(&np->lock, flags);
+
                if (events & NVREG_IRQ_LINK) {
                        spin_lock_irqsave(&np->lock, flags);
                        nv_link_irq(dev);
@@ -2752,7 +3260,7 @@ static irqreturn_t nv_nic_irq_other(int foo, void *data)
                        printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
                                                dev->name, events);
                }
-               if (i > max_interrupt_work) {
+               if (unlikely(i > max_interrupt_work)) {
                        spin_lock_irqsave(&np->lock, flags);
                        /* disable interrupts on the nic */
                        writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
@@ -2835,6 +3343,16 @@ static int nv_request_irq(struct net_device *dev, int intr_test)
        u8 __iomem *base = get_hwbase(dev);
        int ret = 1;
        int i;
+       irqreturn_t (*handler)(int foo, void *data);
+
+       if (intr_test) {
+               handler = nv_nic_irq_test;
+       } else {
+               if (np->desc_ver == DESC_VER_3)
+                       handler = nv_nic_irq_optimized;
+               else
+                       handler = nv_nic_irq;
+       }
 
        if (np->msi_flags & NV_MSI_X_CAPABLE) {
                for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
@@ -2872,10 +3390,7 @@ static int nv_request_irq(struct net_device *dev, int intr_test)
                                set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
                        } else {
                                /* Request irq for all interrupts */
-                               if ((!intr_test &&
-                                    request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
-                                   (intr_test &&
-                                    request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, &nv_nic_irq_test, IRQF_SHARED, dev->name, dev) != 0)) {
+                               if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, handler, IRQF_SHARED, dev->name, dev) != 0) {
                                        printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
                                        pci_disable_msix(np->pci_dev);
                                        np->msi_flags &= ~NV_MSI_X_ENABLED;
@@ -2891,8 +3406,7 @@ static int nv_request_irq(struct net_device *dev, int intr_test)
        if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
                if ((ret = pci_enable_msi(np->pci_dev)) == 0) {
                        np->msi_flags |= NV_MSI_ENABLED;
-                       if ((!intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
-                           (intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq_test, IRQF_SHARED, dev->name, dev) != 0)) {
+                       if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
                                printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
                                pci_disable_msi(np->pci_dev);
                                np->msi_flags &= ~NV_MSI_ENABLED;
@@ -2907,8 +3421,7 @@ static int nv_request_irq(struct net_device *dev, int intr_test)
                }
        }
        if (ret != 0) {
-               if ((!intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
-                   (intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq_test, IRQF_SHARED, dev->name, dev) != 0))
+               if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
                        goto out_err;
 
        }
@@ -3051,47 +3564,8 @@ static void nv_do_stats_poll(unsigned long data)
 {
        struct net_device *dev = (struct net_device *) data;
        struct fe_priv *np = netdev_priv(dev);
-       u8 __iomem *base = get_hwbase(dev);
 
-       np->estats.tx_bytes += readl(base + NvRegTxCnt);
-       np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
-       np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
-       np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
-       np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
-       np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
-       np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
-       np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
-       np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
-       np->estats.tx_deferral += readl(base + NvRegTxDef);
-       np->estats.tx_packets += readl(base + NvRegTxFrame);
-       np->estats.tx_pause += readl(base + NvRegTxPause);
-       np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
-       np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
-       np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
-       np->estats.rx_runt += readl(base + NvRegRxRunt);
-       np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
-       np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
-       np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
-       np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
-       np->estats.rx_length_error += readl(base + NvRegRxLenErr);
-       np->estats.rx_unicast += readl(base + NvRegRxUnicast);
-       np->estats.rx_multicast += readl(base + NvRegRxMulticast);
-       np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
-       np->estats.rx_bytes += readl(base + NvRegRxCnt);
-       np->estats.rx_pause += readl(base + NvRegRxPause);
-       np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
-       np->estats.rx_packets =
-               np->estats.rx_unicast +
-               np->estats.rx_multicast +
-               np->estats.rx_broadcast;
-       np->estats.rx_errors_total =
-               np->estats.rx_crc_errors +
-               np->estats.rx_over_errors +
-               np->estats.rx_frame_error +
-               (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
-               np->estats.rx_late_collision +
-               np->estats.rx_runt +
-               np->estats.rx_frame_too_long;
+       nv_get_hw_stats(dev);
 
        if (!np->in_shutdown)
                mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
@@ -3465,7 +3939,7 @@ static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ri
 {
        struct fe_priv *np = netdev_priv(dev);
        u8 __iomem *base = get_hwbase(dev);
-       u8 *rxtx_ring, *rx_skbuff, *tx_skbuff, *rx_dma, *tx_dma, *tx_dma_len;
+       u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
        dma_addr_t ring_addr;
 
        if (ring->rx_pending < RX_RING_MIN ||
@@ -3491,12 +3965,9 @@ static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ri
                                            sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
                                            &ring_addr);
        }
-       rx_skbuff = kmalloc(sizeof(struct sk_buff*) * ring->rx_pending, GFP_KERNEL);
-       rx_dma = kmalloc(sizeof(dma_addr_t) * ring->rx_pending, GFP_KERNEL);
-       tx_skbuff = kmalloc(sizeof(struct sk_buff*) * ring->tx_pending, GFP_KERNEL);
-       tx_dma = kmalloc(sizeof(dma_addr_t) * ring->tx_pending, GFP_KERNEL);
-       tx_dma_len = kmalloc(sizeof(unsigned int) * ring->tx_pending, GFP_KERNEL);
-       if (!rxtx_ring || !rx_skbuff || !rx_dma || !tx_skbuff || !tx_dma || !tx_dma_len) {
+       rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
+       tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
+       if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
                /* fall back to old rings */
                if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
                        if (rxtx_ring)
@@ -3509,14 +3980,8 @@ static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ri
                }
                if (rx_skbuff)
                        kfree(rx_skbuff);
-               if (rx_dma)
-                       kfree(rx_dma);
                if (tx_skbuff)
                        kfree(tx_skbuff);
-               if (tx_dma)
-                       kfree(tx_dma);
-               if (tx_dma_len)
-                       kfree(tx_dma_len);
                goto exit;
        }
 
@@ -3538,8 +4003,6 @@ static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ri
        /* set new values */
        np->rx_ring_size = ring->rx_pending;
        np->tx_ring_size = ring->tx_pending;
-       np->tx_limit_stop = ring->tx_pending - TX_LIMIT_DIFFERENCE;
-       np->tx_limit_start = ring->tx_pending - TX_LIMIT_DIFFERENCE - 1;
        if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
                np->rx_ring.orig = (struct ring_desc*)rxtx_ring;
                np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
@@ -3547,18 +4010,12 @@ static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ri
                np->rx_ring.ex = (struct ring_desc_ex*)rxtx_ring;
                np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
        }
-       np->rx_skbuff = (struct sk_buff**)rx_skbuff;
-       np->rx_dma = (dma_addr_t*)rx_dma;
-       np->tx_skbuff = (struct sk_buff**)tx_skbuff;
-       np->tx_dma = (dma_addr_t*)tx_dma;
-       np->tx_dma_len = (unsigned int*)tx_dma_len;
+       np->rx_skb = (struct nv_skb_map*)rx_skbuff;
+       np->tx_skb = (struct nv_skb_map*)tx_skbuff;
        np->ring_addr = ring_addr;
 
-       memset(np->rx_skbuff, 0, sizeof(struct sk_buff*) * np->rx_ring_size);
-       memset(np->rx_dma, 0, sizeof(dma_addr_t) * np->rx_ring_size);
-       memset(np->tx_skbuff, 0, sizeof(struct sk_buff*) * np->tx_ring_size);
-       memset(np->tx_dma, 0, sizeof(dma_addr_t) * np->tx_ring_size);
-       memset(np->tx_dma_len, 0, sizeof(unsigned int) * np->tx_ring_size);
+       memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
+       memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
 
        if (netif_running(dev)) {
                /* reinit driver view of the queues */
@@ -3727,8 +4184,10 @@ static int nv_get_stats_count(struct net_device *dev)
 {
        struct fe_priv *np = netdev_priv(dev);
 
-       if (np->driver_data & DEV_HAS_STATISTICS)
-               return sizeof(struct nv_ethtool_stats)/sizeof(u64);
+       if (np->driver_data & DEV_HAS_STATISTICS_V1)
+               return NV_DEV_STATISTICS_V1_COUNT;
+       else if (np->driver_data & DEV_HAS_STATISTICS_V2)
+               return NV_DEV_STATISTICS_V2_COUNT;
        else
                return 0;
 }
@@ -3955,7 +4414,7 @@ static int nv_loopback_test(struct net_device *dev)
                        dprintk(KERN_DEBUG "%s: loopback len mismatch %d vs %d\n",
                                dev->name, len, pkt_len);
                } else {
-                       rx_skb = np->rx_skbuff[0];
+                       rx_skb = np->rx_skb[0].skb;
                        for (i = 0; i < pkt_len; i++) {
                                if (rx_skb->data[i] != (u8)(i & 0xff)) {
                                        ret = 0;
@@ -4315,7 +4774,7 @@ static int nv_open(struct net_device *dev)
                mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
 
        /* start statistics timer */
-       if (np->driver_data & DEV_HAS_STATISTICS)
+       if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2))
                mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
 
        spin_unlock_irq(&np->lock);
@@ -4412,7 +4871,9 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
        if (err < 0)
                goto out_disable;
 
-       if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS))
+       if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V2))
+               np->register_size = NV_PCI_REGSZ_VER3;
+       else if (id->driver_data & DEV_HAS_STATISTICS_V1)
                np->register_size = NV_PCI_REGSZ_VER2;
        else
                np->register_size = NV_PCI_REGSZ_VER1;
@@ -4475,10 +4936,8 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
                np->rx_csum = 1;
                np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
                dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
-#ifdef NETIF_F_TSO
                dev->features |= NETIF_F_TSO;
-#endif
-       }
+       }
 
        np->vlanctl_bits = 0;
        if (id->driver_data & DEV_HAS_VLAN) {
@@ -4512,8 +4971,6 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
 
        np->rx_ring_size = RX_RING_DEFAULT;
        np->tx_ring_size = TX_RING_DEFAULT;
-       np->tx_limit_stop = np->tx_ring_size - TX_LIMIT_DIFFERENCE;
-       np->tx_limit_start = np->tx_ring_size - TX_LIMIT_DIFFERENCE - 1;
 
        if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
                np->rx_ring.orig = pci_alloc_consistent(pci_dev,
@@ -4530,22 +4987,19 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
                        goto out_unmap;
                np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
        }
-       np->rx_skbuff = kmalloc(sizeof(struct sk_buff*) * np->rx_ring_size, GFP_KERNEL);
-       np->rx_dma = kmalloc(sizeof(dma_addr_t) * np->rx_ring_size, GFP_KERNEL);
-       np->tx_skbuff = kmalloc(sizeof(struct sk_buff*) * np->tx_ring_size, GFP_KERNEL);
-       np->tx_dma = kmalloc(sizeof(dma_addr_t) * np->tx_ring_size, GFP_KERNEL);
-       np->tx_dma_len = kmalloc(sizeof(unsigned int) * np->tx_ring_size, GFP_KERNEL);
-       if (!np->rx_skbuff || !np->rx_dma || !np->tx_skbuff || !np->tx_dma || !np->tx_dma_len)
+       np->rx_skb = kmalloc(sizeof(struct nv_skb_map) * np->rx_ring_size, GFP_KERNEL);
+       np->tx_skb = kmalloc(sizeof(struct nv_skb_map) * np->tx_ring_size, GFP_KERNEL);
+       if (!np->rx_skb || !np->tx_skb)
                goto out_freering;
-       memset(np->rx_skbuff, 0, sizeof(struct sk_buff*) * np->rx_ring_size);
-       memset(np->rx_dma, 0, sizeof(dma_addr_t) * np->rx_ring_size);
-       memset(np->tx_skbuff, 0, sizeof(struct sk_buff*) * np->tx_ring_size);
-       memset(np->tx_dma, 0, sizeof(dma_addr_t) * np->tx_ring_size);
-       memset(np->tx_dma_len, 0, sizeof(unsigned int) * np->tx_ring_size);
+       memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
+       memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
 
        dev->open = nv_open;
        dev->stop = nv_close;
-       dev->hard_start_xmit = nv_start_xmit;
+       if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
+               dev->hard_start_xmit = nv_start_xmit;
+       else
+               dev->hard_start_xmit = nv_start_xmit_optimized;
        dev->get_stats = nv_get_stats;
        dev->change_mtu = nv_change_mtu;
        dev->set_mac_address = nv_set_mac_address;
@@ -4553,7 +5007,7 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
 #ifdef CONFIG_NET_POLL_CONTROLLER
        dev->poll_controller = nv_poll_controller;
 #endif
-       dev->weight = 64;
+       dev->weight = RX_WORK_PER_LOOP;
 #ifdef CONFIG_FORCEDETH_NAPI
        dev->poll = nv_napi_poll;
 #endif
@@ -4868,83 +5322,83 @@ static struct pci_device_id pci_tbl[] = {
        },
        {       /* CK804 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1,
        },
        {       /* CK804 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1,
        },
        {       /* MCP04 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1,
        },
        {       /* MCP04 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1,
        },
        {       /* MCP51 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1,
        },
        {       /* MCP51 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1,
        },
        {       /* MCP55 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP55 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP61 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_16),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP61 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_17),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP61 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_18),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP61 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_19),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP65 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP65 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP65 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP65 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP67 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_24),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP67 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_25),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP67 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_26),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {       /* MCP67 Ethernet Controller */
                PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_27),
-               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
+               .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
        },
        {0,},
 };
index 844c136e9920cc92c98d5abbb60c7a8a7767a14c..7dc5185aa2c09969a8cffab4faf1dd08dbb2c5fc 100644 (file)
@@ -3034,7 +3034,7 @@ static int __init hp100_module_init(void)
                goto out2;
 #endif
 #ifdef CONFIG_PCI
-       err = pci_module_init(&hp100_pci_driver);
+       err = pci_register_driver(&hp100_pci_driver);
        if (err && err != -ENODEV)
                goto out3;
 #endif
index f4aba4355b19fc2e5deddbba263823b774ad5af2..cf30a1059ce02f1808b4cd8251366df938958b35 100644 (file)
@@ -61,9 +61,7 @@
 #include <net/pkt_sched.h>
 #include <linux/list.h>
 #include <linux/reboot.h>
-#ifdef NETIF_F_TSO
 #include <net/checksum.h>
-#endif
 
 #include <linux/ethtool.h>
 #include <linux/if_vlan.h>
index 82c044d6e08af339a01c047bf4e60279cc455b8e..d6628bd9590a0773a423e8f9389e42a83d57f44f 100644 (file)
@@ -82,10 +82,8 @@ static struct ixgb_stats ixgb_gstrings_stats[] = {
        {"tx_restart_queue", IXGB_STAT(restart_queue) },
        {"rx_long_length_errors", IXGB_STAT(stats.roc)},
        {"rx_short_length_errors", IXGB_STAT(stats.ruc)},
-#ifdef NETIF_F_TSO
        {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)},
        {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)},
-#endif
        {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)},
        {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)},
        {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)},
@@ -240,7 +238,6 @@ ixgb_set_tx_csum(struct net_device *netdev, uint32_t data)
        return 0;
 }
 
-#ifdef NETIF_F_TSO
 static int
 ixgb_set_tso(struct net_device *netdev, uint32_t data)
 {
@@ -250,7 +247,6 @@ ixgb_set_tso(struct net_device *netdev, uint32_t data)
                netdev->features &= ~NETIF_F_TSO;
        return 0;
 } 
-#endif /* NETIF_F_TSO */
 
 static uint32_t
 ixgb_get_msglevel(struct net_device *netdev)
@@ -722,10 +718,8 @@ static const struct ethtool_ops ixgb_ethtool_ops = {
        .set_sg = ethtool_op_set_sg,
        .get_msglevel = ixgb_get_msglevel,
        .set_msglevel = ixgb_set_msglevel,
-#ifdef NETIF_F_TSO
        .get_tso = ethtool_op_get_tso,
        .set_tso = ixgb_set_tso,
-#endif
        .get_strings = ixgb_get_strings,
        .phys_id = ixgb_phys_id,
        .get_stats_count = ixgb_get_stats_count,
index a083a9189230d8f0a3dda97f7b3eba485862f1d1..51bd7e8ff0d622a8825869288ea86bac0fb2bcc5 100644 (file)
@@ -456,9 +456,7 @@ ixgb_probe(struct pci_dev *pdev,
                           NETIF_F_HW_VLAN_TX |
                           NETIF_F_HW_VLAN_RX |
                           NETIF_F_HW_VLAN_FILTER;
-#ifdef NETIF_F_TSO
        netdev->features |= NETIF_F_TSO;
-#endif
 #ifdef NETIF_F_LLTX
        netdev->features |= NETIF_F_LLTX;
 #endif
@@ -1176,7 +1174,6 @@ ixgb_watchdog(unsigned long data)
 static int
 ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
 {
-#ifdef NETIF_F_TSO
        struct ixgb_context_desc *context_desc;
        unsigned int i;
        uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
@@ -1233,7 +1230,6 @@ ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
 
                return 1;
        }
-#endif
 
        return 0;
 }
index 2af20459814424736c589bbc64a90973c53e3e41..e67361e2bf5dc9f29ca7bbbd182c416cbc33bc85 100644 (file)
@@ -1046,6 +1046,14 @@ static int __devinit macb_probe(struct platform_device *pdev)
 
        spin_lock_init(&bp->lock);
 
+#if defined(CONFIG_ARCH_AT91)
+       bp->pclk = clk_get(&pdev->dev, "macb_clk");
+       if (IS_ERR(bp->pclk)) {
+               dev_err(&pdev->dev, "failed to get macb_clk\n");
+               goto err_out_free_dev;
+       }
+       clk_enable(bp->pclk);
+#else
        bp->pclk = clk_get(&pdev->dev, "pclk");
        if (IS_ERR(bp->pclk)) {
                dev_err(&pdev->dev, "failed to get pclk\n");
@@ -1059,6 +1067,7 @@ static int __devinit macb_probe(struct platform_device *pdev)
 
        clk_enable(bp->pclk);
        clk_enable(bp->hclk);
+#endif
 
        bp->regs = ioremap(regs->start, regs->end - regs->start + 1);
        if (!bp->regs) {
@@ -1119,9 +1128,17 @@ static int __devinit macb_probe(struct platform_device *pdev)
 
        pdata = pdev->dev.platform_data;
        if (pdata && pdata->is_rmii)
+#if defined(CONFIG_ARCH_AT91)
+               macb_writel(bp, USRIO, (MACB_BIT(RMII) | MACB_BIT(CLKEN)) );
+#else
                macb_writel(bp, USRIO, 0);
+#endif
        else
+#if defined(CONFIG_ARCH_AT91)
+               macb_writel(bp, USRIO, MACB_BIT(CLKEN));
+#else
                macb_writel(bp, USRIO, MACB_BIT(MII));
+#endif
 
        bp->tx_pending = DEF_TX_RING_PENDING;
 
@@ -1148,9 +1165,11 @@ err_out_free_irq:
 err_out_iounmap:
        iounmap(bp->regs);
 err_out_disable_clocks:
+#ifndef CONFIG_ARCH_AT91
        clk_disable(bp->hclk);
-       clk_disable(bp->pclk);
        clk_put(bp->hclk);
+#endif
+       clk_disable(bp->pclk);
 err_out_put_pclk:
        clk_put(bp->pclk);
 err_out_free_dev:
@@ -1173,9 +1192,11 @@ static int __devexit macb_remove(struct platform_device *pdev)
                unregister_netdev(dev);
                free_irq(dev->irq, dev);
                iounmap(bp->regs);
+#ifndef CONFIG_ARCH_AT91
                clk_disable(bp->hclk);
-               clk_disable(bp->pclk);
                clk_put(bp->hclk);
+#endif
+               clk_disable(bp->pclk);
                clk_put(bp->pclk);
                free_netdev(dev);
                platform_set_drvdata(pdev, NULL);
index 27bf0ae0f0bb8310136e749fa94d8d495d92d09d..b3bb2182edd1ce3f9cf1178f18169a51fba926cd 100644 (file)
 #define MACB_SOF_OFFSET                                30
 #define MACB_SOF_SIZE                          2
 
-/* Bitfields in USRIO */
+/* Bitfields in USRIO (AVR32) */
 #define MACB_MII_OFFSET                                0
 #define MACB_MII_SIZE                          1
 #define MACB_EAM_OFFSET                                1
 #define MACB_TX_PAUSE_ZERO_OFFSET              3
 #define MACB_TX_PAUSE_ZERO_SIZE                        1
 
+/* Bitfields in USRIO (AT91) */
+#define MACB_RMII_OFFSET                       0
+#define MACB_RMII_SIZE                         1
+#define MACB_CLKEN_OFFSET                      1
+#define MACB_CLKEN_SIZE                                1
+
 /* Bitfields in WOL */
 #define MACB_IP_OFFSET                         0
 #define MACB_IP_SIZE                           16
index 2907cfb12ada0adff1422c9ef70b3651b58f56fc..9ec24f0d5d6834e280fbe245d116d77c01277f02 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/crc32.h>
 #include <linux/spinlock.h>
+#include <linux/bitrev.h>
 #include <asm/prom.h>
 #include <asm/dbdma.h>
 #include <asm/io.h>
@@ -74,7 +75,6 @@ struct mace_data {
 #define PRIV_BYTES     (sizeof(struct mace_data) \
        + (N_RX_RING + NCMDS_TX * N_TX_RING + 3) * sizeof(struct dbdma_cmd))
 
-static int bitrev(int);
 static int mace_open(struct net_device *dev);
 static int mace_close(struct net_device *dev);
 static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev);
@@ -96,18 +96,6 @@ static void __mace_set_address(struct net_device *dev, void *addr);
  */
 static unsigned char *dummy_buf;
 
-/* Bit-reverse one byte of an ethernet hardware address. */
-static inline int
-bitrev(int b)
-{
-    int d = 0, i;
-
-    for (i = 0; i < 8; ++i, b >>= 1)
-       d = (d << 1) | (b & 1);
-    return d;
-}
-
-
 static int __devinit mace_probe(struct macio_dev *mdev, const struct of_device_id *match)
 {
        struct device_node *mace = macio_get_of_node(mdev);
@@ -173,7 +161,7 @@ static int __devinit mace_probe(struct macio_dev *mdev, const struct of_device_i
 
        rev = addr[0] == 0 && addr[1] == 0xA0;
        for (j = 0; j < 6; ++j) {
-               dev->dev_addr[j] = rev? bitrev(addr[j]): addr[j];
+               dev->dev_addr[j] = rev ? bitrev8(addr[j]): addr[j];
        }
        mp->chipid = (in_8(&mp->mace->chipid_hi) << 8) |
                        in_8(&mp->mace->chipid_lo);
index 464e4a6f3d5f45e3bca9101452f123a1b935a02a..5d541e8730415a952d70db69f8461e1abb6d352b 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/delay.h>
 #include <linux/string.h>
 #include <linux/crc32.h>
+#include <linux/bitrev.h>
 #include <asm/io.h>
 #include <asm/pgtable.h>
 #include <asm/irq.h>
@@ -81,19 +82,6 @@ static irqreturn_t mace_interrupt(int irq, void *dev_id);
 static irqreturn_t mace_dma_intr(int irq, void *dev_id);
 static void mace_tx_timeout(struct net_device *dev);
 
-/* Bit-reverse one byte of an ethernet hardware address. */
-
-static int bitrev(int b)
-{
-       int d = 0, i;
-
-       for (i = 0; i < 8; ++i, b >>= 1) {
-               d = (d << 1) | (b & 1);
-       }
-
-       return d;
-}
-
 /*
  * Load a receive DMA channel with a base address and ring length
  */
@@ -219,12 +207,12 @@ struct net_device *mace_probe(int unit)
        addr = (void *)MACE_PROM;
 
        for (j = 0; j < 6; ++j) {
-               u8 v=bitrev(addr[j<<4]);
+               u8 v = bitrev8(addr[j<<4]);
                checksum ^= v;
                dev->dev_addr[j] = v;
        }
        for (; j < 8; ++j) {
-               checksum ^= bitrev(addr[j<<4]);
+               checksum ^= bitrev8(addr[j<<4]);
        }
 
        if (checksum != 0xFF) {
index 393d995f19199cb573b53854e604c62e2c082350..24f6050fbf33ab71106224320e51da2a35758031 100644 (file)
@@ -121,16 +121,12 @@ enum macsonic_type {
  * For reversing the PROM address
  */
 
-static unsigned char nibbletab[] = {0, 8, 4, 12, 2, 10, 6, 14,
-                                   1, 9, 5, 13, 3, 11, 7, 15};
-
 static inline void bit_reverse_addr(unsigned char addr[6])
 {
        int i;
 
        for(i = 0; i < 6; i++)
-               addr[i] = ((nibbletab[addr[i] & 0xf] << 4) |
-                          nibbletab[(addr[i] >> 4) &0xf]);
+               addr[i] = bitrev8(addr[i]);
 }
 
 int __init macsonic_init(struct net_device* dev)
index 61cbd4a604460448bd699664500f1803fb0794e7..030924fb1ab3544545ea5770c9d265010bd9f315 100644 (file)
@@ -1412,10 +1412,8 @@ static const struct ethtool_ops myri10ge_ethtool_ops = {
        .set_tx_csum = ethtool_op_set_tx_hw_csum,
        .get_sg = ethtool_op_get_sg,
        .set_sg = ethtool_op_set_sg,
-#ifdef NETIF_F_TSO
        .get_tso = ethtool_op_get_tso,
        .set_tso = ethtool_op_set_tso,
-#endif
        .get_strings = myri10ge_get_strings,
        .get_stats_count = myri10ge_get_stats_count,
        .get_ethtool_stats = myri10ge_get_ethtool_stats,
@@ -1975,13 +1973,11 @@ again:
        mss = 0;
        max_segments = MXGEFW_MAX_SEND_DESC;
 
-#ifdef NETIF_F_TSO
        if (skb->len > (dev->mtu + ETH_HLEN)) {
                mss = skb_shinfo(skb)->gso_size;
                if (mss != 0)
                        max_segments = MYRI10GE_MAX_SEND_DESC_TSO;
        }
-#endif                         /*NETIF_F_TSO */
 
        if ((unlikely(avail < max_segments))) {
                /* we are out of transmit resources */
@@ -2013,7 +2009,6 @@ again:
 
        cum_len = 0;
 
-#ifdef NETIF_F_TSO
        if (mss) {              /* TSO */
                /* this removes any CKSUM flag from before */
                flags = (MXGEFW_FLAGS_TSO_HDR | MXGEFW_FLAGS_FIRST);
@@ -2029,7 +2024,6 @@ again:
                 * the checksum by parsing the header. */
                pseudo_hdr_offset = mss;
        } else
-#endif                         /*NETIF_F_TSO */
                /* Mark small packets, and pad out tiny packets */
        if (skb->len <= MXGEFW_SEND_SMALL_SIZE) {
                flags |= MXGEFW_FLAGS_SMALL;
@@ -2097,7 +2091,6 @@ again:
                                seglen = len;
                        flags_next = flags & ~MXGEFW_FLAGS_FIRST;
                        cum_len_next = cum_len + seglen;
-#ifdef NETIF_F_TSO
                        if (mss) {      /* TSO */
                                (req - rdma_count)->rdma_count = rdma_count + 1;
 
@@ -2124,7 +2117,6 @@ again:
                                            (small * MXGEFW_FLAGS_SMALL);
                                }
                        }
-#endif                         /* NETIF_F_TSO */
                        req->addr_high = high_swapped;
                        req->addr_low = htonl(low);
                        req->pseudo_hdr_offset = htons(pseudo_hdr_offset);
@@ -2161,14 +2153,12 @@ again:
        }
 
        (req - rdma_count)->rdma_count = rdma_count;
-#ifdef NETIF_F_TSO
        if (mss)
                do {
                        req--;
                        req->flags |= MXGEFW_FLAGS_TSO_LAST;
                } while (!(req->flags & (MXGEFW_FLAGS_TSO_CHOP |
                                         MXGEFW_FLAGS_FIRST)));
-#endif
        idx = ((count - 1) + tx->req) & tx->mask;
        tx->info[idx].last = 1;
        if (tx->wc_fifo == NULL)
index e8598b809228a422d3359068098f27722feb014f..3f3896e988790ab9a5484c6f267902bc56f03612 100644 (file)
 
 #include "netxen_nic_hw.h"
 
-#define NETXEN_NIC_BUILD_NO     "2"
 #define _NETXEN_NIC_LINUX_MAJOR 3
 #define _NETXEN_NIC_LINUX_MINOR 3
 #define _NETXEN_NIC_LINUX_SUBVERSION 3
-#define NETXEN_NIC_LINUX_VERSIONID  "3.3.3" "-" NETXEN_NIC_BUILD_NO
+#define NETXEN_NIC_LINUX_VERSIONID  "3.3.3"
+
+#define NUM_FLASH_SECTORS (64)
+#define FLASH_SECTOR_SIZE (64 * 1024)
+#define FLASH_TOTAL_SIZE  (NUM_FLASH_SECTORS * FLASH_SECTOR_SIZE)
 
 #define RCV_DESC_RINGSIZE      \
        (sizeof(struct rcv_desc) * adapter->max_rx_desc_count)
@@ -85,6 +88,7 @@
 #define NETXEN_RCV_PRODUCER_OFFSET     0
 #define NETXEN_RCV_PEG_DB_ID           2
 #define NETXEN_HOST_DUMMY_DMA_SIZE 1024
+#define FLASH_SUCCESS 0
 
 #define ADDR_IN_WINDOW1(off)   \
        ((off > NETXEN_CRB_PCIX_HOST2) && (off < NETXEN_CRB_MAX)) ? 1 : 0
@@ -1028,6 +1032,15 @@ void netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val);
 void netxen_load_firmware(struct netxen_adapter *adapter);
 int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose);
 int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp);
+int netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr, 
+                               u8 *bytes, size_t size);
+int netxen_rom_fast_write_words(struct netxen_adapter *adapter, int addr, 
+                               u8 *bytes, size_t size);
+int netxen_flash_unlock(struct netxen_adapter *adapter);
+int netxen_backup_crbinit(struct netxen_adapter *adapter);
+int netxen_flash_erase_secondary(struct netxen_adapter *adapter);
+int netxen_flash_erase_primary(struct netxen_adapter *adapter);
+
 int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data);
 int netxen_rom_se(struct netxen_adapter *adapter, int addr);
 int netxen_do_rom_se(struct netxen_adapter *adapter, int addr);
index c381d77a7336a1acb6536f2bbb956b7228bf6e4c..cc0efe213e01f84b95af13e4bbf81dceb3c02a47 100644 (file)
@@ -32,6 +32,7 @@
  */
 
 #include <linux/types.h>
+#include <linux/delay.h>
 #include <asm/uaccess.h>
 #include <linux/pci.h>
 #include <asm/io.h>
@@ -94,17 +95,7 @@ static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
 
 static int netxen_nic_get_eeprom_len(struct net_device *dev)
 {
-       struct netxen_port *port = netdev_priv(dev);
-       struct netxen_adapter *adapter = port->adapter;
-       int n;
-
-       if ((netxen_rom_fast_read(adapter, 0, &n) == 0)
-           && (n & NETXEN_ROM_ROUNDUP)) {
-               n &= ~NETXEN_ROM_ROUNDUP;
-               if (n < NETXEN_MAX_EEPROM_LEN)
-                       return n;
-       }
-       return 0;
+       return FLASH_TOTAL_SIZE;
 }
 
 static void
@@ -440,18 +431,92 @@ netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
        struct netxen_port *port = netdev_priv(dev);
        struct netxen_adapter *adapter = port->adapter;
        int offset;
+       int ret;
 
        if (eeprom->len == 0)
                return -EINVAL;
 
        eeprom->magic = (port->pdev)->vendor | ((port->pdev)->device << 16);
-       for (offset = 0; offset < eeprom->len; offset++)
-               if (netxen_rom_fast_read
-                   (adapter, (8 * offset) + 8, (int *)eeprom->data) == -1)
-                       return -EIO;
+       offset = eeprom->offset;
+
+       ret = netxen_rom_fast_read_words(adapter, offset, bytes, 
+                                               eeprom->len);
+       if (ret < 0)
+               return ret;
+
        return 0;
 }
 
+static int
+netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
+                       u8 * bytes)
+{
+       struct netxen_port *port = netdev_priv(dev);
+       struct netxen_adapter *adapter = port->adapter;
+       int offset = eeprom->offset;
+       static int flash_start;
+       static int ready_to_flash;
+       int ret;
+
+       if (flash_start == 0) {
+               ret = netxen_flash_unlock(adapter);
+               if (ret < 0) {
+                       printk(KERN_ERR "%s: Flash unlock failed.\n",
+                               netxen_nic_driver_name);
+                       return ret;
+               }
+               printk(KERN_INFO "%s: flash unlocked. \n", 
+                       netxen_nic_driver_name);
+               ret = netxen_flash_erase_secondary(adapter);
+               if (ret != FLASH_SUCCESS) {
+                       printk(KERN_ERR "%s: Flash erase failed.\n", 
+                               netxen_nic_driver_name);
+                       return ret;
+               }
+               printk(KERN_INFO "%s: secondary flash erased successfully.\n", 
+                       netxen_nic_driver_name);
+               flash_start = 1;
+               return 0;
+       }
+
+       if (offset == BOOTLD_START) {
+               ret = netxen_flash_erase_primary(adapter);
+               if (ret != FLASH_SUCCESS) {
+                       printk(KERN_ERR "%s: Flash erase failed.\n", 
+                               netxen_nic_driver_name);
+                       return ret;
+               }
+
+               ret = netxen_rom_se(adapter, USER_START);
+               if (ret != FLASH_SUCCESS)
+                       return ret;
+               ret = netxen_rom_se(adapter, FIXED_START);
+               if (ret != FLASH_SUCCESS)
+                       return ret;
+
+               printk(KERN_INFO "%s: primary flash erased successfully\n", 
+                       netxen_nic_driver_name);
+
+               ret = netxen_backup_crbinit(adapter);
+               if (ret != FLASH_SUCCESS) {
+                       printk(KERN_ERR "%s: CRBinit backup failed.\n", 
+                               netxen_nic_driver_name);
+                       return ret;
+               }
+               printk(KERN_INFO "%s: CRBinit backup done.\n", 
+                       netxen_nic_driver_name);
+               ready_to_flash = 1;
+       }
+
+       if (!ready_to_flash) {
+               printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
+                       netxen_nic_driver_name);
+               return -EINVAL;
+       }
+
+       return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
+}
+
 static void
 netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
 {
@@ -721,6 +786,7 @@ struct ethtool_ops netxen_nic_ethtool_ops = {
        .get_link = netxen_nic_get_link,
        .get_eeprom_len = netxen_nic_get_eeprom_len,
        .get_eeprom = netxen_nic_get_eeprom,
+       .set_eeprom = netxen_nic_set_eeprom,
        .get_ringparam = netxen_nic_get_ringparam,
        .get_pauseparam = netxen_nic_get_pauseparam,
        .set_pauseparam = netxen_nic_set_pauseparam,
index 973af96337a922dc150d38639ebdfeef63b6ae75..f7bb8c90537cd9880603b0abd41ae24907fb2c1c 100644 (file)
@@ -110,6 +110,7 @@ static void crb_addr_transform_setup(void)
        crb_addr_transform(CAM);
        crb_addr_transform(C2C1);
        crb_addr_transform(C2C0);
+       crb_addr_transform(SMB);
 }
 
 int netxen_init_firmware(struct netxen_adapter *adapter)
@@ -276,6 +277,7 @@ unsigned long netxen_decode_crb_addr(unsigned long addr)
 
 static long rom_max_timeout = 10000;
 static long rom_lock_timeout = 1000000;
+static long rom_write_timeout = 700;
 
 static inline int rom_lock(struct netxen_adapter *adapter)
 {
@@ -404,7 +406,7 @@ do_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp)
 {
        netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr);
        netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3);
-       udelay(100);            /* prevent bursting on CRB */
+       udelay(70);             /* prevent bursting on CRB */
        netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
        netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb);
        if (netxen_wait_rom_done(adapter)) {
@@ -413,13 +415,46 @@ do_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp)
        }
        /* reset abyte_cnt and dummy_byte_cnt */
        netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0);
-       udelay(100);            /* prevent bursting on CRB */
+       udelay(70);             /* prevent bursting on CRB */
        netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
 
        *valp = netxen_nic_reg_read(adapter, NETXEN_ROMUSB_ROM_RDATA);
        return 0;
 }
 
+static inline int 
+do_rom_fast_read_words(struct netxen_adapter *adapter, int addr,
+                       u8 *bytes, size_t size)
+{
+       int addridx;
+       int ret = 0;
+
+       for (addridx = addr; addridx < (addr + size); addridx += 4) {
+               ret = do_rom_fast_read(adapter, addridx, (int *)bytes);
+               if (ret != 0)
+                       break;
+               bytes += 4;
+       }
+
+       return ret;
+}
+
+int
+netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr, 
+                               u8 *bytes, size_t size)
+{
+       int ret;
+
+       ret = rom_lock(adapter);
+       if (ret < 0)
+               return ret;
+
+       ret = do_rom_fast_read_words(adapter, addr, bytes, size);
+
+       netxen_rom_unlock(adapter);
+       return ret;
+}
+
 int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp)
 {
        int ret;
@@ -443,6 +478,152 @@ int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data)
        netxen_rom_unlock(adapter);
        return ret;
 }
+
+static inline int do_rom_fast_write_words(struct netxen_adapter *adapter, 
+                                               int addr, u8 *bytes, size_t size)
+{
+       int addridx = addr;
+       int ret = 0;
+
+       while (addridx < (addr + size)) {
+               int last_attempt = 0;
+               int timeout = 0;
+               int data;
+
+               data = *(u32*)bytes;
+
+               ret = do_rom_fast_write(adapter, addridx, data);
+               if (ret < 0)
+                       return ret;
+                       
+               while(1) {
+                       int data1;
+
+                       do_rom_fast_read(adapter, addridx, &data1);
+                       if (data1 == data)
+                               break;
+
+                       if (timeout++ >= rom_write_timeout) {
+                               if (last_attempt++ < 4) {
+                                       ret = do_rom_fast_write(adapter, 
+                                                               addridx, data);
+                                       if (ret < 0)
+                                               return ret;
+                               }
+                               else {
+                                       printk(KERN_INFO "Data write did not "
+                                          "succeed at address 0x%x\n", addridx);
+                                       break;
+                               }
+                       }
+               }
+
+               bytes += 4;
+               addridx += 4;
+       }
+
+       return ret;
+}
+
+int netxen_rom_fast_write_words(struct netxen_adapter *adapter, int addr, 
+                                       u8 *bytes, size_t size)
+{
+       int ret = 0;
+
+       ret = rom_lock(adapter);
+       if (ret < 0)
+               return ret;
+
+       ret = do_rom_fast_write_words(adapter, addr, bytes, size);
+       netxen_rom_unlock(adapter);
+
+       return ret;
+}
+
+int netxen_rom_wrsr(struct netxen_adapter *adapter, int data)
+{
+       int ret;
+
+       ret = netxen_rom_wren(adapter);
+       if (ret < 0)
+               return ret;
+
+       netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_ROM_WDATA, data);
+       netxen_crb_writelit_adapter(adapter, 
+                                       NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0x1);
+
+       ret = netxen_wait_rom_done(adapter);
+       if (ret < 0)
+               return ret;
+
+       return netxen_rom_wip_poll(adapter);
+}
+
+int netxen_rom_rdsr(struct netxen_adapter *adapter)
+{
+       int ret;
+
+       ret = rom_lock(adapter);
+       if (ret < 0)
+               return ret;
+
+       ret = netxen_do_rom_rdsr(adapter);
+       netxen_rom_unlock(adapter);
+       return ret;
+}
+
+int netxen_backup_crbinit(struct netxen_adapter *adapter)
+{
+       int ret = FLASH_SUCCESS;
+       int val;
+       char *buffer = kmalloc(FLASH_SECTOR_SIZE, GFP_KERNEL);
+
+       if (!buffer)
+               return -ENOMEM; 
+       /* unlock sector 63 */
+       val = netxen_rom_rdsr(adapter);
+       val = val & 0xe3;
+       ret = netxen_rom_wrsr(adapter, val);
+       if (ret != FLASH_SUCCESS)
+               goto out_kfree;
+
+       ret = netxen_rom_wip_poll(adapter);
+       if (ret != FLASH_SUCCESS)
+               goto out_kfree;
+
+       /* copy  sector 0 to sector 63 */
+       ret = netxen_rom_fast_read_words(adapter, CRBINIT_START, 
+                                               buffer, FLASH_SECTOR_SIZE);
+       if (ret != FLASH_SUCCESS)
+               goto out_kfree;
+
+       ret = netxen_rom_fast_write_words(adapter, FIXED_START, 
+                                               buffer, FLASH_SECTOR_SIZE);
+       if (ret != FLASH_SUCCESS)
+               goto out_kfree;
+
+       /* lock sector 63 */
+       val = netxen_rom_rdsr(adapter);
+       if (!(val & 0x8)) {
+               val |= (0x1 << 2);
+               /* lock sector 63 */
+               if (netxen_rom_wrsr(adapter, val) == 0) {
+                       ret = netxen_rom_wip_poll(adapter);
+                       if (ret != FLASH_SUCCESS)
+                               goto out_kfree;
+
+                       /* lock SR writes */
+                       ret = netxen_rom_wip_poll(adapter);
+                       if (ret != FLASH_SUCCESS)
+                               goto out_kfree;
+               }
+       }
+
+out_kfree:
+       kfree(buffer);
+       return ret;
+}
+
 int netxen_do_rom_se(struct netxen_adapter *adapter, int addr)
 {
        netxen_rom_wren(adapter);
@@ -457,6 +638,27 @@ int netxen_do_rom_se(struct netxen_adapter *adapter, int addr)
        return netxen_rom_wip_poll(adapter);
 }
 
+void check_erased_flash(struct netxen_adapter *adapter, int addr)
+{
+       int i;
+       int val;
+       int count = 0, erased_errors = 0;
+       int range;
+
+       range = (addr == USER_START) ? FIXED_START : addr + FLASH_SECTOR_SIZE;
+       
+       for (i = addr; i < range; i += 4) {
+               netxen_rom_fast_read(adapter, i, &val);
+               if (val != 0xffffffff)
+                       erased_errors++;
+               count++;
+       }
+
+       if (erased_errors)
+               printk(KERN_INFO "0x%x out of 0x%x words fail to be erased "
+                       "for sector address: %x\n", erased_errors, count, addr);
+}
+
 int netxen_rom_se(struct netxen_adapter *adapter, int addr)
 {
        int ret = 0;
@@ -465,6 +667,68 @@ int netxen_rom_se(struct netxen_adapter *adapter, int addr)
        }
        ret = netxen_do_rom_se(adapter, addr);
        netxen_rom_unlock(adapter);
+       msleep(30);
+       check_erased_flash(adapter, addr);
+
+       return ret;
+}
+
+int
+netxen_flash_erase_sections(struct netxen_adapter *adapter, int start, int end)
+{
+       int ret = FLASH_SUCCESS;
+       int i;
+
+       for (i = start; i < end; i++) {
+               ret = netxen_rom_se(adapter, i * FLASH_SECTOR_SIZE);
+               if (ret)
+                       break;
+               ret = netxen_rom_wip_poll(adapter);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return ret;
+}
+
+int
+netxen_flash_erase_secondary(struct netxen_adapter *adapter)
+{
+       int ret = FLASH_SUCCESS;
+       int start, end;
+
+       start = SECONDARY_START / FLASH_SECTOR_SIZE;
+       end   = USER_START / FLASH_SECTOR_SIZE;
+       ret = netxen_flash_erase_sections(adapter, start, end);
+
+       return ret;
+}
+
+int
+netxen_flash_erase_primary(struct netxen_adapter *adapter)
+{
+       int ret = FLASH_SUCCESS;
+       int start, end;
+
+       start = PRIMARY_START / FLASH_SECTOR_SIZE;
+       end   = SECONDARY_START / FLASH_SECTOR_SIZE;
+       ret = netxen_flash_erase_sections(adapter, start, end);
+
+       return ret;
+}
+
+int netxen_flash_unlock(struct netxen_adapter *adapter)
+{
+       int ret = 0;
+
+       ret = netxen_rom_wrsr(adapter, 0);
+       if (ret < 0)
+               return ret;
+
+       ret = netxen_rom_wren(adapter);
+       if (ret < 0)
+               return ret;
+
        return ret;
 }
 
@@ -543,9 +807,13 @@ int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose)
                }
                for (i = 0; i < n; i++) {
 
-                       off =
-                           netxen_decode_crb_addr((unsigned long)buf[i].addr) +
-                           NETXEN_PCI_CRBSPACE;
+                       off = netxen_decode_crb_addr((unsigned long)buf[i].addr);
+                       if (off == NETXEN_ADDR_ERROR) {
+                               printk(KERN_ERR"CRB init value out of range %lx\n",
+                                       buf[i].addr);
+                               continue;
+                       }
+                       off += NETXEN_PCI_CRBSPACE;
                        /* skipping cold reboot MAGIC */
                        if (off == NETXEN_CAM_RAM(0x1fc))
                                continue;
@@ -662,6 +930,7 @@ void netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val)
        int loops = 0;
 
        if (!pegtune_val) {
+               val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
                while (val != PHAN_INITIALIZE_COMPLETE && loops < 200000) {
                        udelay(100);
                        schedule();
diff --git a/drivers/net/oaknet.c b/drivers/net/oaknet.c
deleted file mode 100644 (file)
index 702e3e9..0000000
+++ /dev/null
@@ -1,666 +0,0 @@
-/*
- *
- *    Copyright (c) 1999-2000 Grant Erickson <grant@lcse.umn.edu>
- *
- *    Module name: oaknet.c
- *
- *    Description:
- *      Driver for the National Semiconductor DP83902AV Ethernet controller
- *      on-board the IBM PowerPC "Oak" evaluation board. Adapted from the
- *      various other 8390 drivers written by Donald Becker and Paul Gortmaker.
- *
- *      Additional inspiration from the "tcd8390.c" driver from TiVo, Inc.
- *      and "enetLib.c" from IBM.
- *
- */
-
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/delay.h>
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
-#include <linux/init.h>
-#include <linux/jiffies.h>
-
-#include <asm/board.h>
-#include <asm/io.h>
-
-#include "8390.h"
-
-
-/* Preprocessor Defines */
-
-#if !defined(TRUE) || TRUE != 1
-#define        TRUE    1
-#endif
-
-#if !defined(FALSE) || FALSE != 0
-#define        FALSE   0
-#endif
-
-#define        OAKNET_START_PG         0x20    /* First page of TX buffer */
-#define        OAKNET_STOP_PG          0x40    /* Last pagge +1 of RX ring */
-
-#define        OAKNET_WAIT             (2 * HZ / 100)  /* 20 ms */
-
-/* Experimenting with some fixes for a broken driver... */
-
-#define        OAKNET_DISINT
-#define        OAKNET_HEADCHECK
-#define        OAKNET_RWFIX
-
-
-/* Global Variables */
-
-static const char *name = "National DP83902AV";
-
-static struct net_device *oaknet_devs;
-
-
-/* Function Prototypes */
-
-static int      oaknet_open(struct net_device *dev);
-static int      oaknet_close(struct net_device *dev);
-
-static void     oaknet_reset_8390(struct net_device *dev);
-static void     oaknet_get_8390_hdr(struct net_device *dev,
-                                    struct e8390_pkt_hdr *hdr, int ring_page);
-static void     oaknet_block_input(struct net_device *dev, int count,
-                                   struct sk_buff *skb, int ring_offset);
-static void     oaknet_block_output(struct net_device *dev, int count,
-                                    const unsigned char *buf, int start_page);
-
-static void     oaknet_dma_error(struct net_device *dev, const char *name);
-
-
-/*
- * int oaknet_init()
- *
- * Description:
- *   This routine performs all the necessary platform-specific initiali-
- *   zation and set-up for the IBM "Oak" evaluation board's National
- *   Semiconductor DP83902AV "ST-NIC" Ethernet controller.
- *
- * Input(s):
- *   N/A
- *
- * Output(s):
- *   N/A
- *
- * Returns:
- *   0 if OK, otherwise system error number on error.
- *
- */
-static int __init oaknet_init(void)
-{
-       register int i;
-       int reg0, regd;
-       int ret = -ENOMEM;
-       struct net_device *dev;
-#if 0
-       unsigned long ioaddr = OAKNET_IO_BASE;
-#else
-       unsigned long ioaddr = ioremap(OAKNET_IO_BASE, OAKNET_IO_SIZE);
-#endif
-       bd_t *bip = (bd_t *)__res;
-
-       if (!ioaddr)
-               return -ENOMEM;
-
-       dev = alloc_ei_netdev();
-       if (!dev)
-               goto out_unmap;
-
-       ret = -EBUSY;
-       if (!request_region(OAKNET_IO_BASE, OAKNET_IO_SIZE, name))
-               goto out_dev;
-
-       /* Quick register check to see if the device is really there. */
-
-       ret = -ENODEV;
-       if ((reg0 = ei_ibp(ioaddr)) == 0xFF)
-               goto out_region;
-
-       /*
-        * That worked. Now a more thorough check, using the multicast
-        * address registers, that the device is definitely out there
-        * and semi-functional.
-        */
-
-       ei_obp(E8390_NODMA + E8390_PAGE1 + E8390_STOP, ioaddr + E8390_CMD);
-       regd = ei_ibp(ioaddr + 0x0D);
-       ei_obp(0xFF, ioaddr + 0x0D);
-       ei_obp(E8390_NODMA + E8390_PAGE0, ioaddr + E8390_CMD);
-       ei_ibp(ioaddr + EN0_COUNTER0);
-
-       /* It's no good. Fix things back up and leave. */
-
-       ret = -ENODEV;
-       if (ei_ibp(ioaddr + EN0_COUNTER0) != 0) {
-               ei_obp(reg0, ioaddr);
-               ei_obp(regd, ioaddr + 0x0D);
-               goto out_region;
-       }
-
-       SET_MODULE_OWNER(dev);
-
-       /*
-        * This controller is on an embedded board, so the base address
-        * and interrupt assignments are pre-assigned and unchageable.
-        */
-
-       dev->base_addr = ioaddr;
-       dev->irq = OAKNET_INT;
-
-       /*
-        * Disable all chip interrupts for now and ACK all pending
-        * interrupts.
-        */
-
-       ei_obp(0x0, ioaddr + EN0_IMR);
-       ei_obp(0xFF, ioaddr + EN0_ISR);
-
-       /* Attempt to get the interrupt line */
-
-       ret = -EAGAIN;
-       if (request_irq(dev->irq, ei_interrupt, 0, name, dev)) {
-               printk("%s: unable to request interrupt %d.\n",
-                      name, dev->irq);
-               goto out_region;
-       }
-
-       /* Tell the world about what and where we've found. */
-
-       printk("%s: %s at", dev->name, name);
-       for (i = 0; i < ETHER_ADDR_LEN; ++i) {
-               dev->dev_addr[i] = bip->bi_enetaddr[i];
-               printk("%c%.2x", (i ? ':' : ' '), dev->dev_addr[i]);
-       }
-       printk(", found at %#lx, using IRQ %d.\n", dev->base_addr, dev->irq);
-
-       /* Set up some required driver fields and then we're done. */
-
-       ei_status.name          = name;
-       ei_status.word16        = FALSE;
-       ei_status.tx_start_page = OAKNET_START_PG;
-       ei_status.rx_start_page = OAKNET_START_PG + TX_PAGES;
-       ei_status.stop_page     = OAKNET_STOP_PG;
-
-       ei_status.reset_8390    = &oaknet_reset_8390;
-       ei_status.block_input   = &oaknet_block_input;
-       ei_status.block_output  = &oaknet_block_output;
-       ei_status.get_8390_hdr  = &oaknet_get_8390_hdr;
-
-       dev->open = oaknet_open;
-       dev->stop = oaknet_close;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = ei_poll;
-#endif
-
-       NS8390_init(dev, FALSE);
-       ret = register_netdev(dev);
-       if (ret)
-               goto out_irq;
-
-       oaknet_devs = dev;
-       return 0;
-
-out_irq;
-       free_irq(dev->irq, dev);
-out_region:
-       release_region(OAKNET_IO_BASE, OAKNET_IO_SIZE);
-out_dev:
-       free_netdev(dev);
-out_unmap:
-       iounmap(ioaddr);
-       return ret;
-}
-
-/*
- * static int oaknet_open()
- *
- * Description:
- *   This routine is a modest wrapper around ei_open, the 8390-generic,
- *   driver open routine. This just increments the module usage count
- *   and passes along the status from ei_open.
- *
- * Input(s):
- *  *dev - Pointer to the device structure for this driver.
- *
- * Output(s):
- *  *dev - Pointer to the device structure for this driver, potentially
- *         modified by ei_open.
- *
- * Returns:
- *   0 if OK, otherwise < 0 on error.
- *
- */
-static int
-oaknet_open(struct net_device *dev)
-{
-       int status = ei_open(dev);
-       return (status);
-}
-
-/*
- * static int oaknet_close()
- *
- * Description:
- *   This routine is a modest wrapper around ei_close, the 8390-generic,
- *   driver close routine. This just decrements the module usage count
- *   and passes along the status from ei_close.
- *
- * Input(s):
- *  *dev - Pointer to the device structure for this driver.
- *
- * Output(s):
- *  *dev - Pointer to the device structure for this driver, potentially
- *         modified by ei_close.
- *
- * Returns:
- *   0 if OK, otherwise < 0 on error.
- *
- */
-static int
-oaknet_close(struct net_device *dev)
-{
-       int status = ei_close(dev);
-       return (status);
-}
-
-/*
- * static void oaknet_reset_8390()
- *
- * Description:
- *   This routine resets the DP83902 chip.
- *
- * Input(s):
- *  *dev - Pointer to the device structure for this driver.
- *
- * Output(s):
- *   N/A
- *
- * Returns:
- *   N/A
- *
- */
-static void
-oaknet_reset_8390(struct net_device *dev)
-{
-       int base = E8390_BASE;
-
-       /*
-        * We have no provision of reseting the controller as is done
-        * in other drivers, such as "ne.c". However, the following
-        * seems to work well enough in the TiVo driver.
-        */
-
-       printk("Resetting %s...\n", dev->name);
-       ei_obp(E8390_STOP | E8390_NODMA | E8390_PAGE0, base + E8390_CMD);
-       ei_status.txing = 0;
-       ei_status.dmaing = 0;
-}
-
-/*
- * static void oaknet_get_8390_hdr()
- *
- * Description:
- *   This routine grabs the 8390-specific header. It's similar to the
- *   block input routine, but we don't need to be concerned with ring wrap
- *   as the header will be at the start of a page, so we optimize accordingly.
- *
- * Input(s):
- *  *dev       - Pointer to the device structure for this driver.
- *  *hdr       - Pointer to storage for the 8390-specific packet header.
- *   ring_page - ?
- *
- * Output(s):
- *  *hdr       - Pointer to the 8390-specific packet header for the just-
- *               received frame.
- *
- * Returns:
- *   N/A
- *
- */
-static void
-oaknet_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
-                   int ring_page)
-{
-       int base = dev->base_addr;
-
-       /*
-        * This should NOT happen. If it does, it is the LAST thing you'll
-        * see.
-        */
-
-       if (ei_status.dmaing) {
-               oaknet_dma_error(dev, "oaknet_get_8390_hdr");
-               return;
-       }
-
-       ei_status.dmaing |= 0x01;
-       outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, base + OAKNET_CMD);
-       outb_p(sizeof(struct e8390_pkt_hdr), base + EN0_RCNTLO);
-       outb_p(0, base + EN0_RCNTHI);
-       outb_p(0, base + EN0_RSARLO);           /* On page boundary */
-       outb_p(ring_page, base + EN0_RSARHI);
-       outb_p(E8390_RREAD + E8390_START, base + OAKNET_CMD);
-
-       if (ei_status.word16)
-               insw(base + OAKNET_DATA, hdr,
-                    sizeof(struct e8390_pkt_hdr) >> 1);
-       else
-               insb(base + OAKNET_DATA, hdr,
-                    sizeof(struct e8390_pkt_hdr));
-
-       /* Byte-swap the packet byte count */
-
-       hdr->count = le16_to_cpu(hdr->count);
-
-       outb_p(ENISR_RDC, base + EN0_ISR);      /* ACK Remote DMA interrupt */
-       ei_status.dmaing &= ~0x01;
-}
-
-/*
- * XXX - Document me.
- */
-static void
-oaknet_block_input(struct net_device *dev, int count, struct sk_buff *skb,
-                  int ring_offset)
-{
-       int base = OAKNET_BASE;
-       char *buf = skb->data;
-
-       /*
-        * This should NOT happen. If it does, it is the LAST thing you'll
-        * see.
-        */
-
-       if (ei_status.dmaing) {
-               oaknet_dma_error(dev, "oaknet_block_input");
-               return;
-       }
-
-#ifdef OAKNET_DISINT
-       save_flags(flags);
-       cli();
-#endif
-
-       ei_status.dmaing |= 0x01;
-       ei_obp(E8390_NODMA + E8390_PAGE0 + E8390_START, base + E8390_CMD);
-       ei_obp(count & 0xff, base + EN0_RCNTLO);
-       ei_obp(count >> 8, base + EN0_RCNTHI);
-       ei_obp(ring_offset & 0xff, base + EN0_RSARLO);
-       ei_obp(ring_offset >> 8, base + EN0_RSARHI);
-       ei_obp(E8390_RREAD + E8390_START, base + E8390_CMD);
-       if (ei_status.word16) {
-               ei_isw(base + E8390_DATA, buf, count >> 1);
-               if (count & 0x01) {
-                       buf[count - 1] = ei_ib(base + E8390_DATA);
-#ifdef OAKNET_HEADCHECK
-                       bytes++;
-#endif
-               }
-       } else {
-               ei_isb(base + E8390_DATA, buf, count);
-       }
-#ifdef OAKNET_HEADCHECK
-       /*
-        * This was for the ALPHA version only, but enough people have
-        * been encountering problems so it is still here.  If you see
-        * this message you either 1) have a slightly incompatible clone
-        * or 2) have noise/speed problems with your bus.
-        */
-
-       /* DMA termination address check... */
-       {
-               int addr, tries = 20;
-               do {
-                       /* DON'T check for 'ei_ibp(EN0_ISR) & ENISR_RDC' here
-                          -- it's broken for Rx on some cards! */
-                       int high = ei_ibp(base + EN0_RSARHI);
-                       int low = ei_ibp(base + EN0_RSARLO);
-                       addr = (high << 8) + low;
-                       if (((ring_offset + bytes) & 0xff) == low)
-                               break;
-               } while (--tries > 0);
-               if (tries <= 0)
-                       printk("%s: RX transfer address mismatch,"
-                              "%#4.4x (expected) vs. %#4.4x (actual).\n",
-                              dev->name, ring_offset + bytes, addr);
-       }
-#endif
-       ei_obp(ENISR_RDC, base + EN0_ISR);      /* ACK Remote DMA interrupt */
-       ei_status.dmaing &= ~0x01;
-
-#ifdef OAKNET_DISINT
-       restore_flags(flags);
-#endif
-}
-
-/*
- * static void oaknet_block_output()
- *
- * Description:
- *   This routine...
- *
- * Input(s):
- *  *dev        - Pointer to the device structure for this driver.
- *   count      - Number of bytes to be transferred.
- *  *buf        -
- *   start_page -
- *
- * Output(s):
- *   N/A
- *
- * Returns:
- *   N/A
- *
- */
-static void
-oaknet_block_output(struct net_device *dev, int count,
-                   const unsigned char *buf, int start_page)
-{
-       int base = E8390_BASE;
-#if 0
-       int bug;
-#endif
-       unsigned long start;
-#ifdef OAKNET_DISINT
-       unsigned long flags;
-#endif
-#ifdef OAKNET_HEADCHECK
-       int retries = 0;
-#endif
-
-       /* Round the count up for word writes. */
-
-       if (ei_status.word16 && (count & 0x1))
-               count++;
-
-       /*
-        * This should NOT happen. If it does, it is the LAST thing you'll
-        * see.
-        */
-
-       if (ei_status.dmaing) {
-               oaknet_dma_error(dev, "oaknet_block_output");
-               return;
-       }
-
-#ifdef OAKNET_DISINT
-       save_flags(flags);
-       cli();
-#endif
-
-       ei_status.dmaing |= 0x01;
-
-       /* Make sure we are in page 0. */
-
-       ei_obp(E8390_PAGE0 + E8390_START + E8390_NODMA, base + E8390_CMD);
-
-#ifdef OAKNET_HEADCHECK
-retry:
-#endif
-
-#if 0
-       /*
-        * The 83902 documentation states that the processor needs to
-        * do a "dummy read" before doing the remote write to work
-        * around a chip bug they don't feel like fixing.
-        */
-
-       bug = 0;
-       while (1) {
-               unsigned int rdhi;
-               unsigned int rdlo;
-
-               /* Now the normal output. */
-               ei_obp(ENISR_RDC, base + EN0_ISR);
-               ei_obp(count & 0xff, base + EN0_RCNTLO);
-               ei_obp(count >> 8,   base + EN0_RCNTHI);
-               ei_obp(0x00, base + EN0_RSARLO);
-               ei_obp(start_page, base + EN0_RSARHI);
-
-               if (bug++)
-                       break;
-
-               /* Perform the dummy read */
-               rdhi = ei_ibp(base + EN0_CRDAHI);
-               rdlo = ei_ibp(base + EN0_CRDALO);
-               ei_obp(E8390_RREAD + E8390_START, base + E8390_CMD);
-
-               while (1) {
-                       unsigned int nrdhi;
-                       unsigned int nrdlo;
-                       nrdhi = ei_ibp(base + EN0_CRDAHI);
-                       nrdlo = ei_ibp(base + EN0_CRDALO);
-                       if ((rdhi != nrdhi) || (rdlo != nrdlo))
-                               break;
-               }
-       }
-#else
-#ifdef OAKNET_RWFIX
-       /*
-        * Handle the read-before-write bug the same way as the
-        * Crynwr packet driver -- the Nat'l Semi. method doesn't work.
-        * Actually this doesn't always work either, but if you have
-        * problems with your 83902 this is better than nothing!
-        */
-
-       ei_obp(0x42, base + EN0_RCNTLO);
-       ei_obp(0x00, base + EN0_RCNTHI);
-       ei_obp(0x42, base + EN0_RSARLO);
-       ei_obp(0x00, base + EN0_RSARHI);
-       ei_obp(E8390_RREAD + E8390_START, base + E8390_CMD);
-       /* Make certain that the dummy read has occurred. */
-       udelay(6);
-#endif
-
-       ei_obp(ENISR_RDC, base + EN0_ISR);
-
-       /* Now the normal output. */
-       ei_obp(count & 0xff, base + EN0_RCNTLO);
-       ei_obp(count >> 8,   base + EN0_RCNTHI);
-       ei_obp(0x00, base + EN0_RSARLO);
-       ei_obp(start_page, base + EN0_RSARHI);
-#endif /* 0/1 */
-
-       ei_obp(E8390_RWRITE + E8390_START, base + E8390_CMD);
-       if (ei_status.word16) {
-               ei_osw(E8390_BASE + E8390_DATA, buf, count >> 1);
-       } else {
-               ei_osb(E8390_BASE + E8390_DATA, buf, count);
-       }
-
-#ifdef OAKNET_DISINT
-       restore_flags(flags);
-#endif
-
-       start = jiffies;
-
-#ifdef OAKNET_HEADCHECK
-       /*
-        * This was for the ALPHA version only, but enough people have
-        * been encountering problems so it is still here.
-        */
-
-       {
-               /* DMA termination address check... */
-               int addr, tries = 20;
-               do {
-                       int high = ei_ibp(base + EN0_RSARHI);
-                       int low = ei_ibp(base + EN0_RSARLO);
-                       addr = (high << 8) + low;
-                       if ((start_page << 8) + count == addr)
-                               break;
-               } while (--tries > 0);
-
-               if (tries <= 0) {
-                       printk("%s: Tx packet transfer address mismatch,"
-                              "%#4.4x (expected) vs. %#4.4x (actual).\n",
-                              dev->name, (start_page << 8) + count, addr);
-                       if (retries++ == 0)
-                               goto retry;
-               }
-       }
-#endif
-
-       while ((ei_ibp(base + EN0_ISR) & ENISR_RDC) == 0) {
-               if (time_after(jiffies, start + OAKNET_WAIT)) {
-                       printk("%s: timeout waiting for Tx RDC.\n", dev->name);
-                       oaknet_reset_8390(dev);
-                       NS8390_init(dev, TRUE);
-                       break;
-               }
-       }
-
-       ei_obp(ENISR_RDC, base + EN0_ISR);      /* Ack intr. */
-       ei_status.dmaing &= ~0x01;
-}
-
-/*
- * static void oaknet_dma_error()
- *
- * Description:
- *   This routine prints out a last-ditch informative message to the console
- *   indicating that a DMA error occurred. If you see this, it's the last
- *   thing you'll see.
- *
- * Input(s):
- *  *dev  - Pointer to the device structure for this driver.
- *  *name - Informative text (e.g. function name) indicating where the
- *          DMA error occurred.
- *
- * Output(s):
- *   N/A
- *
- * Returns:
- *   N/A
- *
- */
-static void
-oaknet_dma_error(struct net_device *dev, const char *name)
-{
-       printk(KERN_EMERG "%s: DMAing conflict in %s."
-              "[DMAstat:%d][irqlock:%d][intr:%ld]\n",
-              dev->name, name, ei_status.dmaing, ei_status.irqlock,
-              dev->interrupt);
-}
-
-/*
- * Oak Ethernet module unload interface.
- */
-static void __exit oaknet_cleanup_module (void)
-{
-       /* Convert to loop once driver supports multiple devices. */
-       unregister_netdev(oaknet_dev);
-       free_irq(oaknet_devs->irq, oaknet_devs);
-       release_region(oaknet_devs->base_addr, OAKNET_IO_SIZE);
-       iounmap(ioaddr);
-       free_netdev(oaknet_devs);
-}
-
-module_init(oaknet_init);
-module_exit(oaknet_cleanup_module);
-MODULE_LICENSE("GPL");
diff --git a/drivers/net/pasemi_mac.c b/drivers/net/pasemi_mac.c
new file mode 100644 (file)
index 0000000..d670ac7
--- /dev/null
@@ -0,0 +1,1019 @@
+/*
+ * Copyright (C) 2006-2007 PA Semi, Inc
+ *
+ * Driver for the PA Semi PWRficient onchip 1G/10G Ethernet MACs
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/interrupt.h>
+#include <linux/dmaengine.h>
+#include <linux/delay.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <asm/dma-mapping.h>
+#include <linux/in.h>
+#include <linux/skbuff.h>
+
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <net/checksum.h>
+
+#include "pasemi_mac.h"
+
+
+/* TODO list
+ *
+ * - Get rid of pci_{read,write}_config(), map registers with ioremap
+ *   for performance
+ * - PHY support
+ * - Multicast support
+ * - Large MTU support
+ * - Other performance improvements
+ */
+
+
+/* Must be a power of two */
+#define RX_RING_SIZE 512
+#define TX_RING_SIZE 512
+
+#define TX_DESC(mac, num)      ((mac)->tx->desc[(num) & (TX_RING_SIZE-1)])
+#define TX_DESC_INFO(mac, num) ((mac)->tx->desc_info[(num) & (TX_RING_SIZE-1)])
+#define RX_DESC(mac, num)      ((mac)->rx->desc[(num) & (RX_RING_SIZE-1)])
+#define RX_DESC_INFO(mac, num) ((mac)->rx->desc_info[(num) & (RX_RING_SIZE-1)])
+#define RX_BUFF(mac, num)      ((mac)->rx->buffers[(num) & (RX_RING_SIZE-1)])
+
+#define BUF_SIZE 1646 /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
+
+/* XXXOJN these should come out of the device tree some day */
+#define PAS_DMA_CAP_BASE   0xe00d0040
+#define PAS_DMA_CAP_SIZE   0x100
+#define PAS_DMA_COM_BASE   0xe00d0100
+#define PAS_DMA_COM_SIZE   0x100
+
+static struct pasdma_status *dma_status;
+
+static int pasemi_get_mac_addr(struct pasemi_mac *mac)
+{
+       struct pci_dev *pdev = mac->pdev;
+       struct device_node *dn = pci_device_to_OF_node(pdev);
+       const u8 *maddr;
+       u8 addr[6];
+
+       if (!dn) {
+               dev_dbg(&pdev->dev,
+                         "No device node for mac, not configuring\n");
+               return -ENOENT;
+       }
+
+       maddr = get_property(dn, "mac-address", NULL);
+       if (maddr == NULL) {
+               dev_warn(&pdev->dev,
+                        "no mac address in device tree, not configuring\n");
+               return -ENOENT;
+       }
+
+       if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[0],
+                  &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) {
+               dev_warn(&pdev->dev,
+                        "can't parse mac address, not configuring\n");
+               return -EINVAL;
+       }
+
+       memcpy(mac->mac_addr, addr, sizeof(addr));
+       return 0;
+}
+
+static int pasemi_mac_setup_rx_resources(struct net_device *dev)
+{
+       struct pasemi_mac_rxring *ring;
+       struct pasemi_mac *mac = netdev_priv(dev);
+       int chan_id = mac->dma_rxch;
+
+       ring = kzalloc(sizeof(*ring), GFP_KERNEL);
+
+       if (!ring)
+               goto out_ring;
+
+       spin_lock_init(&ring->lock);
+
+       ring->desc_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
+                                 RX_RING_SIZE, GFP_KERNEL);
+
+       if (!ring->desc_info)
+               goto out_desc_info;
+
+       /* Allocate descriptors */
+       ring->desc = dma_alloc_coherent(&mac->dma_pdev->dev,
+                                       RX_RING_SIZE *
+                                       sizeof(struct pas_dma_xct_descr),
+                                       &ring->dma, GFP_KERNEL);
+
+       if (!ring->desc)
+               goto out_desc;
+
+       memset(ring->desc, 0, RX_RING_SIZE * sizeof(struct pas_dma_xct_descr));
+
+       ring->buffers = dma_alloc_coherent(&mac->dma_pdev->dev,
+                                          RX_RING_SIZE * sizeof(u64),
+                                          &ring->buf_dma, GFP_KERNEL);
+       if (!ring->buffers)
+               goto out_buffers;
+
+       memset(ring->buffers, 0, RX_RING_SIZE * sizeof(u64));
+
+       pci_write_config_dword(mac->dma_pdev, PAS_DMA_RXCHAN_BASEL(chan_id),
+                              PAS_DMA_RXCHAN_BASEL_BRBL(ring->dma));
+
+       pci_write_config_dword(mac->dma_pdev, PAS_DMA_RXCHAN_BASEU(chan_id),
+                              PAS_DMA_RXCHAN_BASEU_BRBH(ring->dma >> 32) |
+                              PAS_DMA_RXCHAN_BASEU_SIZ(RX_RING_SIZE >> 2));
+
+       pci_write_config_dword(mac->dma_pdev, PAS_DMA_RXCHAN_CFG(chan_id),
+                              PAS_DMA_RXCHAN_CFG_HBU(1));
+
+       pci_write_config_dword(mac->dma_pdev, PAS_DMA_RXINT_BASEL(mac->dma_if),
+                              PAS_DMA_RXINT_BASEL_BRBL(__pa(ring->buffers)));
+
+       pci_write_config_dword(mac->dma_pdev, PAS_DMA_RXINT_BASEU(mac->dma_if),
+                              PAS_DMA_RXINT_BASEU_BRBH(__pa(ring->buffers) >> 32) |
+                              PAS_DMA_RXINT_BASEU_SIZ(RX_RING_SIZE >> 3));
+
+       ring->next_to_fill = 0;
+       ring->next_to_clean = 0;
+
+       snprintf(ring->irq_name, sizeof(ring->irq_name),
+                "%s rx", dev->name);
+       mac->rx = ring;
+
+       return 0;
+
+out_buffers:
+       dma_free_coherent(&mac->dma_pdev->dev,
+                         RX_RING_SIZE * sizeof(struct pas_dma_xct_descr),
+                         mac->rx->desc, mac->rx->dma);
+out_desc:
+       kfree(ring->desc_info);
+out_desc_info:
+       kfree(ring);
+out_ring:
+       return -ENOMEM;
+}
+
+
+static int pasemi_mac_setup_tx_resources(struct net_device *dev)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+       u32 val;
+       int chan_id = mac->dma_txch;
+       struct pasemi_mac_txring *ring;
+
+       ring = kzalloc(sizeof(*ring), GFP_KERNEL);
+       if (!ring)
+               goto out_ring;
+
+       spin_lock_init(&ring->lock);
+
+       ring->desc_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
+                                 TX_RING_SIZE, GFP_KERNEL);
+       if (!ring->desc_info)
+               goto out_desc_info;
+
+       /* Allocate descriptors */
+       ring->desc = dma_alloc_coherent(&mac->dma_pdev->dev,
+                                       TX_RING_SIZE *
+                                       sizeof(struct pas_dma_xct_descr),
+                                       &ring->dma, GFP_KERNEL);
+       if (!ring->desc)
+               goto out_desc;
+
+       memset(ring->desc, 0, TX_RING_SIZE * sizeof(struct pas_dma_xct_descr));
+
+       pci_write_config_dword(mac->dma_pdev, PAS_DMA_TXCHAN_BASEL(chan_id),
+                              PAS_DMA_TXCHAN_BASEL_BRBL(ring->dma));
+       val = PAS_DMA_TXCHAN_BASEU_BRBH(ring->dma >> 32);
+       val |= PAS_DMA_TXCHAN_BASEU_SIZ(TX_RING_SIZE >> 2);
+
+       pci_write_config_dword(mac->dma_pdev, PAS_DMA_TXCHAN_BASEU(chan_id), val);
+
+       pci_write_config_dword(mac->dma_pdev, PAS_DMA_TXCHAN_CFG(chan_id),
+                              PAS_DMA_TXCHAN_CFG_TY_IFACE |
+                              PAS_DMA_TXCHAN_CFG_TATTR(mac->dma_if) |
+                              PAS_DMA_TXCHAN_CFG_UP |
+                              PAS_DMA_TXCHAN_CFG_WT(2));
+
+       ring->next_to_use = 0;
+       ring->next_to_clean = 0;
+
+       snprintf(ring->irq_name, sizeof(ring->irq_name),
+                "%s tx", dev->name);
+       mac->tx = ring;
+
+       return 0;
+
+out_desc:
+       kfree(ring->desc_info);
+out_desc_info:
+       kfree(ring);
+out_ring:
+       return -ENOMEM;
+}
+
+static void pasemi_mac_free_tx_resources(struct net_device *dev)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+       unsigned int i;
+       struct pasemi_mac_buffer *info;
+       struct pas_dma_xct_descr *dp;
+
+       for (i = 0; i < TX_RING_SIZE; i++) {
+               info = &TX_DESC_INFO(mac, i);
+               dp = &TX_DESC(mac, i);
+               if (info->dma) {
+                       if (info->skb) {
+                               pci_unmap_single(mac->dma_pdev,
+                                                info->dma,
+                                                info->skb->len,
+                                                PCI_DMA_TODEVICE);
+                               dev_kfree_skb_any(info->skb);
+                       }
+                       info->dma = 0;
+                       info->skb = NULL;
+                       dp->mactx = 0;
+                       dp->ptr = 0;
+               }
+       }
+
+       dma_free_coherent(&mac->dma_pdev->dev,
+                         TX_RING_SIZE * sizeof(struct pas_dma_xct_descr),
+                         mac->tx->desc, mac->tx->dma);
+
+       kfree(mac->tx->desc_info);
+       kfree(mac->tx);
+       mac->tx = NULL;
+}
+
+static void pasemi_mac_free_rx_resources(struct net_device *dev)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+       unsigned int i;
+       struct pasemi_mac_buffer *info;
+       struct pas_dma_xct_descr *dp;
+
+       for (i = 0; i < RX_RING_SIZE; i++) {
+               info = &RX_DESC_INFO(mac, i);
+               dp = &RX_DESC(mac, i);
+               if (info->dma) {
+                       if (info->skb) {
+                               pci_unmap_single(mac->dma_pdev,
+                                                info->dma,
+                                                info->skb->len,
+                                                PCI_DMA_FROMDEVICE);
+                               dev_kfree_skb_any(info->skb);
+                       }
+                       info->dma = 0;
+                       info->skb = NULL;
+                       dp->macrx = 0;
+                       dp->ptr = 0;
+               }
+       }
+
+       dma_free_coherent(&mac->dma_pdev->dev,
+                         RX_RING_SIZE * sizeof(struct pas_dma_xct_descr),
+                         mac->rx->desc, mac->rx->dma);
+
+       dma_free_coherent(&mac->dma_pdev->dev, RX_RING_SIZE * sizeof(u64),
+                         mac->rx->buffers, mac->rx->buf_dma);
+
+       kfree(mac->rx->desc_info);
+       kfree(mac->rx);
+       mac->rx = NULL;
+}
+
+static void pasemi_mac_replenish_rx_ring(struct net_device *dev)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+       unsigned int i;
+       int start = mac->rx->next_to_fill;
+       unsigned int count;
+
+       count = (mac->rx->next_to_clean + RX_RING_SIZE -
+                mac->rx->next_to_fill) & (RX_RING_SIZE - 1);
+
+       /* Check to see if we're doing first-time setup */
+       if (unlikely(mac->rx->next_to_clean == 0 && mac->rx->next_to_fill == 0))
+               count = RX_RING_SIZE;
+
+       if (count <= 0)
+               return;
+
+       for (i = start; i < start + count; i++) {
+               struct pasemi_mac_buffer *info = &RX_DESC_INFO(mac, i);
+               u64 *buff = &RX_BUFF(mac, i);
+               struct sk_buff *skb;
+               dma_addr_t dma;
+
+               skb = dev_alloc_skb(BUF_SIZE);
+
+               if (!skb) {
+                       count = i - start;
+                       break;
+               }
+
+               skb->dev = dev;
+
+               dma = pci_map_single(mac->dma_pdev, skb->data, skb->len,
+                                    PCI_DMA_FROMDEVICE);
+
+               if (dma_mapping_error(dma)) {
+                       dev_kfree_skb_irq(info->skb);
+                       count = i - start;
+                       break;
+               }
+
+               info->skb = skb;
+               info->dma = dma;
+               *buff = XCT_RXB_LEN(BUF_SIZE) | XCT_RXB_ADDR(dma);
+       }
+
+       wmb();
+
+       pci_write_config_dword(mac->dma_pdev,
+                              PAS_DMA_RXCHAN_INCR(mac->dma_rxch),
+                              count);
+       pci_write_config_dword(mac->dma_pdev,
+                              PAS_DMA_RXINT_INCR(mac->dma_if),
+                              count);
+
+       mac->rx->next_to_fill += count;
+}
+
+static int pasemi_mac_clean_rx(struct pasemi_mac *mac, int limit)
+{
+       unsigned int i;
+       int start, count;
+
+       spin_lock(&mac->rx->lock);
+
+       start = mac->rx->next_to_clean;
+       count = 0;
+
+       for (i = start; i < (start + RX_RING_SIZE) && count < limit; i++) {
+               struct pas_dma_xct_descr *dp;
+               struct pasemi_mac_buffer *info;
+               struct sk_buff *skb;
+               unsigned int j, len;
+               dma_addr_t dma;
+
+               rmb();
+
+               dp = &RX_DESC(mac, i);
+
+               if (!(dp->macrx & XCT_MACRX_O))
+                       break;
+
+               count++;
+
+               info = NULL;
+
+               /* We have to scan for our skb since there's no way
+                * to back-map them from the descriptor, and if we
+                * have several receive channels then they might not
+                * show up in the same order as they were put on the
+                * interface ring.
+                */
+
+               dma = (dp->ptr & XCT_PTR_ADDR_M);
+               for (j = start; j < (start + RX_RING_SIZE); j++) {
+                       info = &RX_DESC_INFO(mac, j);
+                       if (info->dma == dma)
+                               break;
+               }
+
+               BUG_ON(!info);
+               BUG_ON(info->dma != dma);
+
+               pci_unmap_single(mac->dma_pdev, info->dma, info->skb->len,
+                                PCI_DMA_FROMDEVICE);
+
+               skb = info->skb;
+
+               len = (dp->macrx & XCT_MACRX_LLEN_M) >> XCT_MACRX_LLEN_S;
+
+               skb_put(skb, len);
+
+               skb->protocol = eth_type_trans(skb, mac->netdev);
+
+               if ((dp->macrx & XCT_MACRX_HTY_M) == XCT_MACRX_HTY_IPV4_OK) {
+                       skb->ip_summed = CHECKSUM_COMPLETE;
+                       skb->csum = (dp->macrx & XCT_MACRX_CSUM_M) >>
+                                          XCT_MACRX_CSUM_S;
+               } else
+                       skb->ip_summed = CHECKSUM_NONE;
+
+               mac->stats.rx_bytes += len;
+               mac->stats.rx_packets++;
+
+               netif_receive_skb(skb);
+
+               info->dma = 0;
+               info->skb = NULL;
+               dp->ptr = 0;
+               dp->macrx = 0;
+       }
+
+       mac->rx->next_to_clean += count;
+       pasemi_mac_replenish_rx_ring(mac->netdev);
+
+       spin_unlock(&mac->rx->lock);
+
+       return count;
+}
+
+static int pasemi_mac_clean_tx(struct pasemi_mac *mac)
+{
+       int i;
+       struct pasemi_mac_buffer *info;
+       struct pas_dma_xct_descr *dp;
+       int start, count;
+       int flags;
+
+       spin_lock_irqsave(&mac->tx->lock, flags);
+
+       start = mac->tx->next_to_clean;
+       count = 0;
+
+       for (i = start; i < mac->tx->next_to_use; i++) {
+               dp = &TX_DESC(mac, i);
+               if (!dp || (dp->mactx & XCT_MACTX_O))
+                       break;
+
+               count++;
+
+               info = &TX_DESC_INFO(mac, i);
+
+               pci_unmap_single(mac->dma_pdev, info->dma,
+                                info->skb->len, PCI_DMA_TODEVICE);
+               dev_kfree_skb_irq(info->skb);
+
+               info->skb = NULL;
+               info->dma = 0;
+               dp->mactx = 0;
+               dp->ptr = 0;
+       }
+       mac->tx->next_to_clean += count;
+       spin_unlock_irqrestore(&mac->tx->lock, flags);
+
+       return count;
+}
+
+
+static irqreturn_t pasemi_mac_rx_intr(int irq, void *data)
+{
+       struct net_device *dev = data;
+       struct pasemi_mac *mac = netdev_priv(dev);
+       unsigned int reg;
+
+       if (!(*mac->rx_status & PAS_STATUS_INT))
+               return IRQ_NONE;
+
+       netif_rx_schedule(dev);
+       pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_COM_TIMEOUTCFG,
+                              PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(0));
+
+       reg = PAS_IOB_DMA_RXCH_RESET_PINTC | PAS_IOB_DMA_RXCH_RESET_SINTC |
+             PAS_IOB_DMA_RXCH_RESET_DINTC;
+       if (*mac->rx_status & PAS_STATUS_TIMER)
+               reg |= PAS_IOB_DMA_RXCH_RESET_TINTC;
+
+       pci_write_config_dword(mac->iob_pdev,
+                              PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg);
+
+
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t pasemi_mac_tx_intr(int irq, void *data)
+{
+       struct net_device *dev = data;
+       struct pasemi_mac *mac = netdev_priv(dev);
+       unsigned int reg;
+       int was_full;
+
+       was_full = mac->tx->next_to_clean - mac->tx->next_to_use == TX_RING_SIZE;
+
+       if (!(*mac->tx_status & PAS_STATUS_INT))
+               return IRQ_NONE;
+
+       pasemi_mac_clean_tx(mac);
+
+       reg = PAS_IOB_DMA_TXCH_RESET_PINTC | PAS_IOB_DMA_TXCH_RESET_SINTC;
+       if (*mac->tx_status & PAS_STATUS_TIMER)
+               reg |= PAS_IOB_DMA_TXCH_RESET_TINTC;
+
+       pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_TXCH_RESET(mac->dma_txch),
+                              reg);
+
+       if (was_full)
+               netif_wake_queue(dev);
+
+       return IRQ_HANDLED;
+}
+
+static int pasemi_mac_open(struct net_device *dev)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+       unsigned int flags;
+       int ret;
+
+       /* enable rx section */
+       pci_write_config_dword(mac->dma_pdev, PAS_DMA_COM_RXCMD,
+                              PAS_DMA_COM_RXCMD_EN);
+
+       /* enable tx section */
+       pci_write_config_dword(mac->dma_pdev, PAS_DMA_COM_TXCMD,
+                              PAS_DMA_COM_TXCMD_EN);
+
+       flags = PAS_MAC_CFG_TXP_FCE | PAS_MAC_CFG_TXP_FPC(3) |
+               PAS_MAC_CFG_TXP_SL(3) | PAS_MAC_CFG_TXP_COB(0xf) |
+               PAS_MAC_CFG_TXP_TIFT(8) | PAS_MAC_CFG_TXP_TIFG(12);
+
+       pci_write_config_dword(mac->pdev, PAS_MAC_CFG_TXP, flags);
+
+       flags = PAS_MAC_CFG_PCFG_S1 | PAS_MAC_CFG_PCFG_PE |
+               PAS_MAC_CFG_PCFG_PR | PAS_MAC_CFG_PCFG_CE;
+
+       flags |= PAS_MAC_CFG_PCFG_TSR_1G | PAS_MAC_CFG_PCFG_SPD_1G;
+
+       pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_RXCH_CFG(mac->dma_rxch),
+                              PAS_IOB_DMA_RXCH_CFG_CNTTH(30));
+
+       pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_COM_TIMEOUTCFG,
+                              PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(1000000));
+
+       pci_write_config_dword(mac->pdev, PAS_MAC_CFG_PCFG, flags);
+
+       ret = pasemi_mac_setup_rx_resources(dev);
+       if (ret)
+               goto out_rx_resources;
+
+       ret = pasemi_mac_setup_tx_resources(dev);
+       if (ret)
+               goto out_tx_resources;
+
+       pci_write_config_dword(mac->pdev, PAS_MAC_IPC_CHNL,
+                              PAS_MAC_IPC_CHNL_DCHNO(mac->dma_rxch) |
+                              PAS_MAC_IPC_CHNL_BCH(mac->dma_rxch));
+
+       /* enable rx if */
+       pci_write_config_dword(mac->dma_pdev,
+                              PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
+                              PAS_DMA_RXINT_RCMDSTA_EN);
+
+       /* enable rx channel */
+       pci_write_config_dword(mac->dma_pdev,
+                              PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch),
+                              PAS_DMA_RXCHAN_CCMDSTA_EN |
+                              PAS_DMA_RXCHAN_CCMDSTA_DU);
+
+       /* enable tx channel */
+       pci_write_config_dword(mac->dma_pdev,
+                              PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch),
+                              PAS_DMA_TXCHAN_TCMDSTA_EN);
+
+       pasemi_mac_replenish_rx_ring(dev);
+
+       netif_start_queue(dev);
+       netif_poll_enable(dev);
+
+       ret = request_irq(mac->dma_pdev->irq + mac->dma_txch,
+                         &pasemi_mac_tx_intr, IRQF_DISABLED,
+                         mac->tx->irq_name, dev);
+       if (ret) {
+               dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
+                      mac->dma_pdev->irq + mac->dma_txch, ret);
+               goto out_tx_int;
+       }
+
+       ret = request_irq(mac->dma_pdev->irq + 20 + mac->dma_rxch,
+                         &pasemi_mac_rx_intr, IRQF_DISABLED,
+                         mac->rx->irq_name, dev);
+       if (ret) {
+               dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
+                      mac->dma_pdev->irq + 20 + mac->dma_rxch, ret);
+               goto out_rx_int;
+       }
+
+       return 0;
+
+out_rx_int:
+       free_irq(mac->dma_pdev->irq + mac->dma_txch, dev);
+out_tx_int:
+       netif_poll_disable(dev);
+       netif_stop_queue(dev);
+       pasemi_mac_free_tx_resources(dev);
+out_tx_resources:
+       pasemi_mac_free_rx_resources(dev);
+out_rx_resources:
+
+       return ret;
+}
+
+#define MAX_RETRIES 5000
+
+static int pasemi_mac_close(struct net_device *dev)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+       unsigned int stat;
+       int retries;
+
+       netif_stop_queue(dev);
+
+       /* Clean out any pending buffers */
+       pasemi_mac_clean_tx(mac);
+       pasemi_mac_clean_rx(mac, RX_RING_SIZE);
+
+       /* Disable interface */
+       pci_write_config_dword(mac->dma_pdev,
+                              PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch),
+                              PAS_DMA_TXCHAN_TCMDSTA_ST);
+       pci_write_config_dword(mac->dma_pdev,
+                     PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
+                     PAS_DMA_RXINT_RCMDSTA_ST);
+       pci_write_config_dword(mac->dma_pdev,
+                     PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch),
+                     PAS_DMA_RXCHAN_CCMDSTA_ST);
+
+       for (retries = 0; retries < MAX_RETRIES; retries++) {
+               pci_read_config_dword(mac->dma_pdev,
+                                     PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch),
+                                     &stat);
+               if (stat & PAS_DMA_TXCHAN_TCMDSTA_ACT)
+                       break;
+               cond_resched();
+       }
+
+       if (!(stat & PAS_DMA_TXCHAN_TCMDSTA_ACT)) {
+               dev_err(&mac->dma_pdev->dev, "Failed to stop tx channel\n");
+       }
+
+       for (retries = 0; retries < MAX_RETRIES; retries++) {
+               pci_read_config_dword(mac->dma_pdev,
+                                     PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch),
+                                     &stat);
+               if (stat & PAS_DMA_RXCHAN_CCMDSTA_ACT)
+                       break;
+               cond_resched();
+       }
+
+       if (!(stat & PAS_DMA_RXCHAN_CCMDSTA_ACT)) {
+               dev_err(&mac->dma_pdev->dev, "Failed to stop rx channel\n");
+       }
+
+       for (retries = 0; retries < MAX_RETRIES; retries++) {
+               pci_read_config_dword(mac->dma_pdev,
+                                     PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
+                                     &stat);
+               if (stat & PAS_DMA_RXINT_RCMDSTA_ACT)
+                       break;
+               cond_resched();
+       }
+
+       if (!(stat & PAS_DMA_RXINT_RCMDSTA_ACT)) {
+               dev_err(&mac->dma_pdev->dev, "Failed to stop rx interface\n");
+       }
+
+       /* Then, disable the channel. This must be done separately from
+        * stopping, since you can't disable when active.
+        */
+
+       pci_write_config_dword(mac->dma_pdev,
+                              PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch), 0);
+       pci_write_config_dword(mac->dma_pdev,
+                              PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch), 0);
+       pci_write_config_dword(mac->dma_pdev,
+                              PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0);
+
+       free_irq(mac->dma_pdev->irq + mac->dma_txch, dev);
+       free_irq(mac->dma_pdev->irq + 20 + mac->dma_rxch, dev);
+
+       /* Free resources */
+       pasemi_mac_free_rx_resources(dev);
+       pasemi_mac_free_tx_resources(dev);
+
+       return 0;
+}
+
+static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+       struct pasemi_mac_txring *txring;
+       struct pasemi_mac_buffer *info;
+       struct pas_dma_xct_descr *dp;
+       u64 dflags;
+       dma_addr_t map;
+       int flags;
+
+       dflags = XCT_MACTX_O | XCT_MACTX_ST | XCT_MACTX_SS | XCT_MACTX_CRC_PAD;
+
+       if (skb->ip_summed == CHECKSUM_PARTIAL) {
+               switch (skb->nh.iph->protocol) {
+               case IPPROTO_TCP:
+                       dflags |= XCT_MACTX_CSUM_TCP;
+                       dflags |= XCT_MACTX_IPH((skb->h.raw - skb->nh.raw) >> 2);
+                       dflags |= XCT_MACTX_IPO(skb->nh.raw - skb->data);
+                       break;
+               case IPPROTO_UDP:
+                       dflags |= XCT_MACTX_CSUM_UDP;
+                       dflags |= XCT_MACTX_IPH((skb->h.raw - skb->nh.raw) >> 2);
+                       dflags |= XCT_MACTX_IPO(skb->nh.raw - skb->data);
+                       break;
+               }
+       }
+
+       map = pci_map_single(mac->dma_pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
+
+       if (dma_mapping_error(map))
+               return NETDEV_TX_BUSY;
+
+       txring = mac->tx;
+
+       spin_lock_irqsave(&txring->lock, flags);
+
+       if (txring->next_to_clean - txring->next_to_use == TX_RING_SIZE) {
+               spin_unlock_irqrestore(&txring->lock, flags);
+               pasemi_mac_clean_tx(mac);
+               spin_lock_irqsave(&txring->lock, flags);
+
+               if (txring->next_to_clean - txring->next_to_use ==
+                   TX_RING_SIZE) {
+                       /* Still no room -- stop the queue and wait for tx
+                        * intr when there's room.
+                        */
+                       netif_stop_queue(dev);
+                       goto out_err;
+               }
+       }
+
+
+       dp = &TX_DESC(mac, txring->next_to_use);
+       info = &TX_DESC_INFO(mac, txring->next_to_use);
+
+       dp->mactx = dflags | XCT_MACTX_LLEN(skb->len);
+       dp->ptr   = XCT_PTR_LEN(skb->len) | XCT_PTR_ADDR(map);
+       info->dma = map;
+       info->skb = skb;
+
+       txring->next_to_use++;
+       mac->stats.tx_packets++;
+       mac->stats.tx_bytes += skb->len;
+
+       spin_unlock_irqrestore(&txring->lock, flags);
+
+       pci_write_config_dword(mac->dma_pdev,
+                              PAS_DMA_TXCHAN_INCR(mac->dma_txch), 1);
+
+       return NETDEV_TX_OK;
+
+out_err:
+       spin_unlock_irqrestore(&txring->lock, flags);
+       pci_unmap_single(mac->dma_pdev, map, skb->len, PCI_DMA_TODEVICE);
+       return NETDEV_TX_BUSY;
+}
+
+static struct net_device_stats *pasemi_mac_get_stats(struct net_device *dev)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+
+       return &mac->stats;
+}
+
+static void pasemi_mac_set_rx_mode(struct net_device *dev)
+{
+       struct pasemi_mac *mac = netdev_priv(dev);
+       unsigned int flags;
+
+       pci_read_config_dword(mac->pdev, PAS_MAC_CFG_PCFG, &flags);
+
+       /* Set promiscuous */
+       if (dev->flags & IFF_PROMISC)
+               flags |= PAS_MAC_CFG_PCFG_PR;
+       else
+               flags &= ~PAS_MAC_CFG_PCFG_PR;
+
+       pci_write_config_dword(mac->pdev, PAS_MAC_CFG_PCFG, flags);
+}
+
+
+static int pasemi_mac_poll(struct net_device *dev, int *budget)
+{
+       int pkts, limit = min(*budget, dev->quota);
+       struct pasemi_mac *mac = netdev_priv(dev);
+
+       pkts = pasemi_mac_clean_rx(mac, limit);
+
+       if (pkts < limit) {
+               /* all done, no more packets present */
+               netif_rx_complete(dev);
+
+               /* re-enable receive interrupts */
+               pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_COM_TIMEOUTCFG,
+                                      PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(1000000));
+               return 0;
+       } else {
+               /* used up our quantum, so reschedule */
+               dev->quota -= pkts;
+               *budget -= pkts;
+               return 1;
+       }
+}
+
+static int __devinit
+pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+{
+       static int index = 0;
+       struct net_device *dev;
+       struct pasemi_mac *mac;
+       int err;
+
+       err = pci_enable_device(pdev);
+       if (err)
+               return err;
+
+       dev = alloc_etherdev(sizeof(struct pasemi_mac));
+       if (dev == NULL) {
+               dev_err(&pdev->dev,
+                       "pasemi_mac: Could not allocate ethernet device.\n");
+               err = -ENOMEM;
+               goto out_disable_device;
+       }
+
+       SET_MODULE_OWNER(dev);
+       pci_set_drvdata(pdev, dev);
+       SET_NETDEV_DEV(dev, &pdev->dev);
+
+       mac = netdev_priv(dev);
+
+       mac->pdev = pdev;
+       mac->netdev = dev;
+       mac->dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL);
+
+       if (!mac->dma_pdev) {
+               dev_err(&pdev->dev, "Can't find DMA Controller\n");
+               err = -ENODEV;
+               goto out_free_netdev;
+       }
+
+       mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
+
+       if (!mac->iob_pdev) {
+               dev_err(&pdev->dev, "Can't find I/O Bridge\n");
+               err = -ENODEV;
+               goto out_put_dma_pdev;
+       }
+
+       /* These should come out of the device tree eventually */
+       mac->dma_txch = index;
+       mac->dma_rxch = index;
+
+       /* We probe GMAC before XAUI, but the DMA interfaces are
+        * in XAUI, GMAC order.
+        */
+       if (index < 4)
+               mac->dma_if = index + 2;
+       else
+               mac->dma_if = index - 4;
+       index++;
+
+       switch (pdev->device) {
+       case 0xa005:
+               mac->type = MAC_TYPE_GMAC;
+               break;
+       case 0xa006:
+               mac->type = MAC_TYPE_XAUI;
+               break;
+       default:
+               err = -ENODEV;
+               goto out;
+       }
+
+       /* get mac addr from device tree */
+       if (pasemi_get_mac_addr(mac) || !is_valid_ether_addr(mac->mac_addr)) {
+               err = -ENODEV;
+               goto out;
+       }
+       memcpy(dev->dev_addr, mac->mac_addr, sizeof(mac->mac_addr));
+
+       dev->open = pasemi_mac_open;
+       dev->stop = pasemi_mac_close;
+       dev->hard_start_xmit = pasemi_mac_start_tx;
+       dev->get_stats = pasemi_mac_get_stats;
+       dev->set_multicast_list = pasemi_mac_set_rx_mode;
+       dev->weight = 64;
+       dev->poll = pasemi_mac_poll;
+       dev->features = NETIF_F_HW_CSUM;
+
+       /* The dma status structure is located in the I/O bridge, and
+        * is cache coherent.
+        */
+       if (!dma_status)
+               /* XXXOJN This should come from the device tree */
+               dma_status = __ioremap(0xfd800000, 0x1000, 0);
+
+       mac->rx_status = &dma_status->rx_sta[mac->dma_rxch];
+       mac->tx_status = &dma_status->tx_sta[mac->dma_txch];
+
+       err = register_netdev(dev);
+
+       if (err) {
+               dev_err(&mac->pdev->dev, "register_netdev failed with error %d\n",
+                       err);
+               goto out;
+       } else
+               printk(KERN_INFO "%s: PA Semi %s: intf %d, txch %d, rxch %d, "
+                      "hw addr %02x:%02x:%02x:%02x:%02x:%02x\n",
+                      dev->name, mac->type == MAC_TYPE_GMAC ? "GMAC" : "XAUI",
+                      mac->dma_if, mac->dma_txch, mac->dma_rxch,
+                      dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
+                      dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
+
+       return err;
+
+out:
+       pci_dev_put(mac->iob_pdev);
+out_put_dma_pdev:
+       pci_dev_put(mac->dma_pdev);
+out_free_netdev:
+       free_netdev(dev);
+out_disable_device:
+       pci_disable_device(pdev);
+       return err;
+
+}
+
+static void __devexit pasemi_mac_remove(struct pci_dev *pdev)
+{
+       struct net_device *netdev = pci_get_drvdata(pdev);
+       struct pasemi_mac *mac;
+
+       if (!netdev)
+               return;
+
+       mac = netdev_priv(netdev);
+
+       unregister_netdev(netdev);
+
+       pci_disable_device(pdev);
+       pci_dev_put(mac->dma_pdev);
+       pci_dev_put(mac->iob_pdev);
+
+       pci_set_drvdata(pdev, NULL);
+       free_netdev(netdev);
+}
+
+static struct pci_device_id pasemi_mac_pci_tbl[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) },
+       { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) },
+};
+
+MODULE_DEVICE_TABLE(pci, pasemi_mac_pci_tbl);
+
+static struct pci_driver pasemi_mac_driver = {
+       .name           = "pasemi_mac",
+       .id_table       = pasemi_mac_pci_tbl,
+       .probe          = pasemi_mac_probe,
+       .remove         = __devexit_p(pasemi_mac_remove),
+};
+
+static void __exit pasemi_mac_cleanup_module(void)
+{
+       pci_unregister_driver(&pasemi_mac_driver);
+       __iounmap(dma_status);
+       dma_status = NULL;
+}
+
+int pasemi_mac_init_module(void)
+{
+       return pci_register_driver(&pasemi_mac_driver);
+}
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
+MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver");
+
+module_init(pasemi_mac_init_module);
+module_exit(pasemi_mac_cleanup_module);
diff --git a/drivers/net/pasemi_mac.h b/drivers/net/pasemi_mac.h
new file mode 100644 (file)
index 0000000..c3e37e4
--- /dev/null
@@ -0,0 +1,460 @@
+/*
+ * Copyright (C) 2006 PA Semi, Inc
+ *
+ * Driver for the PA6T-1682M onchip 1G/10G Ethernet MACs, soft state and
+ * hardware register layouts.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#ifndef PASEMI_MAC_H
+#define PASEMI_MAC_H
+
+#include <linux/ethtool.h>
+#include <linux/netdevice.h>
+#include <linux/spinlock.h>
+
+struct pasemi_mac_txring {
+       spinlock_t       lock;
+       struct pas_dma_xct_descr        *desc;
+       dma_addr_t       dma;
+       unsigned int     size;
+       unsigned int     next_to_use;
+       unsigned int     next_to_clean;
+       struct pasemi_mac_buffer *desc_info;
+       char             irq_name[10];  /* "eth%d tx" */
+};
+
+struct pasemi_mac_rxring {
+       spinlock_t       lock;
+       struct pas_dma_xct_descr        *desc;  /* RX channel descriptor ring */
+       dma_addr_t       dma;
+       u64             *buffers;       /* RX interface buffer ring */
+       dma_addr_t       buf_dma;
+       unsigned int     size;
+       unsigned int     next_to_fill;
+       unsigned int     next_to_clean;
+       struct pasemi_mac_buffer *desc_info;
+       char             irq_name[10];  /* "eth%d rx" */
+};
+
+struct pasemi_mac {
+       struct net_device *netdev;
+       struct pci_dev *pdev;
+       struct pci_dev *dma_pdev;
+       struct pci_dev *iob_pdev;
+       struct net_device_stats stats;
+
+       /* Pointer to the cacheable per-channel status registers */
+       u64     *rx_status;
+       u64     *tx_status;
+
+       u8              type;
+#define MAC_TYPE_GMAC  1
+#define MAC_TYPE_XAUI  2
+       u32     dma_txch;
+       u32     dma_if;
+       u32     dma_rxch;
+
+       u8              mac_addr[6];
+
+       struct timer_list       rxtimer;
+
+       struct pasemi_mac_txring *tx;
+       struct pasemi_mac_rxring *rx;
+};
+
+/* Software status descriptor (desc_info) */
+struct pasemi_mac_buffer {
+       struct sk_buff *skb;
+       dma_addr_t      dma;
+};
+
+
+/* status register layout in IOB region, at 0xfb800000 */
+struct pasdma_status {
+       u64 rx_sta[64];
+       u64 tx_sta[20];
+};
+
+/* descriptor structure */
+struct pas_dma_xct_descr {
+       union {
+               u64     mactx;
+               u64     macrx;
+       };
+       union {
+               u64     ptr;
+               u64     rxb;
+       };
+};
+
+/* MAC CFG register offsets */
+
+enum {
+       PAS_MAC_CFG_PCFG = 0x80,
+       PAS_MAC_CFG_TXP = 0x98,
+       PAS_MAC_IPC_CHNL = 0x208,
+};
+
+/* MAC CFG register fields */
+#define PAS_MAC_CFG_PCFG_PE            0x80000000
+#define PAS_MAC_CFG_PCFG_CE            0x40000000
+#define PAS_MAC_CFG_PCFG_BU            0x20000000
+#define PAS_MAC_CFG_PCFG_TT            0x10000000
+#define PAS_MAC_CFG_PCFG_TSR_M         0x0c000000
+#define PAS_MAC_CFG_PCFG_TSR_10M       0x00000000
+#define PAS_MAC_CFG_PCFG_TSR_100M      0x04000000
+#define PAS_MAC_CFG_PCFG_TSR_1G                0x08000000
+#define PAS_MAC_CFG_PCFG_TSR_10G       0x0c000000
+#define PAS_MAC_CFG_PCFG_T24           0x02000000
+#define PAS_MAC_CFG_PCFG_PR            0x01000000
+#define PAS_MAC_CFG_PCFG_CRO_M         0x00ff0000
+#define PAS_MAC_CFG_PCFG_CRO_S 16
+#define PAS_MAC_CFG_PCFG_IPO_M         0x0000ff00
+#define PAS_MAC_CFG_PCFG_IPO_S 8
+#define PAS_MAC_CFG_PCFG_S1            0x00000080
+#define PAS_MAC_CFG_PCFG_IO_M          0x00000060
+#define PAS_MAC_CFG_PCFG_IO_MAC                0x00000000
+#define PAS_MAC_CFG_PCFG_IO_OFF                0x00000020
+#define PAS_MAC_CFG_PCFG_IO_IND_ETH    0x00000040
+#define PAS_MAC_CFG_PCFG_IO_IND_IP     0x00000060
+#define PAS_MAC_CFG_PCFG_LP            0x00000010
+#define PAS_MAC_CFG_PCFG_TS            0x00000008
+#define PAS_MAC_CFG_PCFG_HD            0x00000004
+#define PAS_MAC_CFG_PCFG_SPD_M         0x00000003
+#define PAS_MAC_CFG_PCFG_SPD_10M       0x00000000
+#define PAS_MAC_CFG_PCFG_SPD_100M      0x00000001
+#define PAS_MAC_CFG_PCFG_SPD_1G                0x00000002
+#define PAS_MAC_CFG_PCFG_SPD_10G       0x00000003
+#define PAS_MAC_CFG_TXP_FCF            0x01000000
+#define PAS_MAC_CFG_TXP_FCE            0x00800000
+#define PAS_MAC_CFG_TXP_FC             0x00400000
+#define PAS_MAC_CFG_TXP_FPC_M          0x00300000
+#define PAS_MAC_CFG_TXP_FPC_S          20
+#define PAS_MAC_CFG_TXP_FPC(x)         (((x) << PAS_MAC_CFG_TXP_FPC_S) & \
+                                        PAS_MAC_CFG_TXP_FPC_M)
+#define PAS_MAC_CFG_TXP_RT             0x00080000
+#define PAS_MAC_CFG_TXP_BL             0x00040000
+#define PAS_MAC_CFG_TXP_SL_M           0x00030000
+#define PAS_MAC_CFG_TXP_SL_S           16
+#define PAS_MAC_CFG_TXP_SL(x)          (((x) << PAS_MAC_CFG_TXP_SL_S) & \
+                                        PAS_MAC_CFG_TXP_SL_M)
+#define PAS_MAC_CFG_TXP_COB_M          0x0000f000
+#define PAS_MAC_CFG_TXP_COB_S          12
+#define PAS_MAC_CFG_TXP_COB(x)         (((x) << PAS_MAC_CFG_TXP_COB_S) & \
+                                        PAS_MAC_CFG_TXP_COB_M)
+#define PAS_MAC_CFG_TXP_TIFT_M         0x00000f00
+#define PAS_MAC_CFG_TXP_TIFT_S         8
+#define PAS_MAC_CFG_TXP_TIFT(x)                (((x) << PAS_MAC_CFG_TXP_TIFT_S) & \
+                                        PAS_MAC_CFG_TXP_TIFT_M)
+#define PAS_MAC_CFG_TXP_TIFG_M         0x000000ff
+#define PAS_MAC_CFG_TXP_TIFG_S         0
+#define PAS_MAC_CFG_TXP_TIFG(x)                (((x) << PAS_MAC_CFG_TXP_TIFG_S) & \
+                                        PAS_MAC_CFG_TXP_TIFG_M)
+
+#define PAS_MAC_IPC_CHNL_DCHNO_M       0x003f0000
+#define PAS_MAC_IPC_CHNL_DCHNO_S       16
+#define PAS_MAC_IPC_CHNL_DCHNO(x)      (((x) << PAS_MAC_IPC_CHNL_DCHNO_S) & \
+                                        PAS_MAC_IPC_CHNL_DCHNO_M)
+#define PAS_MAC_IPC_CHNL_BCH_M         0x0000003f
+#define PAS_MAC_IPC_CHNL_BCH_S         0
+#define PAS_MAC_IPC_CHNL_BCH(x)                (((x) << PAS_MAC_IPC_CHNL_BCH_S) & \
+                                        PAS_MAC_IPC_CHNL_BCH_M)
+
+/* All these registers live in the PCI configuration space for the DMA PCI
+ * device. Use the normal PCI config access functions for them.
+ */
+enum {
+       PAS_DMA_COM_TXCMD = 0x100,      /* Transmit Command Register  */
+       PAS_DMA_COM_TXSTA = 0x104,      /* Transmit Status Register   */
+       PAS_DMA_COM_RXCMD = 0x108,      /* Receive Command Register   */
+       PAS_DMA_COM_RXSTA = 0x10c,      /* Receive Status Register    */
+};
+#define PAS_DMA_COM_TXCMD_EN   0x00000001 /* enable */
+#define PAS_DMA_COM_TXSTA_ACT  0x00000001 /* active */
+#define PAS_DMA_COM_RXCMD_EN   0x00000001 /* enable */
+#define PAS_DMA_COM_RXSTA_ACT  0x00000001 /* active */
+
+
+/* Per-interface and per-channel registers */
+#define _PAS_DMA_RXINT_STRIDE          0x20
+#define PAS_DMA_RXINT_RCMDSTA(i)       (0x200+(i)*_PAS_DMA_RXINT_STRIDE)
+#define    PAS_DMA_RXINT_RCMDSTA_EN    0x00000001
+#define    PAS_DMA_RXINT_RCMDSTA_ST    0x00000002
+#define    PAS_DMA_RXINT_RCMDSTA_OO    0x00000100
+#define    PAS_DMA_RXINT_RCMDSTA_BP    0x00000200
+#define    PAS_DMA_RXINT_RCMDSTA_DR    0x00000400
+#define    PAS_DMA_RXINT_RCMDSTA_BT    0x00000800
+#define    PAS_DMA_RXINT_RCMDSTA_TB    0x00001000
+#define    PAS_DMA_RXINT_RCMDSTA_ACT   0x00010000
+#define    PAS_DMA_RXINT_RCMDSTA_DROPS_M       0xfffe0000
+#define    PAS_DMA_RXINT_RCMDSTA_DROPS_S       17
+#define PAS_DMA_RXINT_INCR(i)          (0x210+(i)*_PAS_DMA_RXINT_STRIDE)
+#define    PAS_DMA_RXINT_INCR_INCR_M   0x0000ffff
+#define    PAS_DMA_RXINT_INCR_INCR_S   0
+#define    PAS_DMA_RXINT_INCR_INCR(x)  ((x) & 0x0000ffff)
+#define PAS_DMA_RXINT_BASEL(i)         (0x218+(i)*_PAS_DMA_RXINT_STRIDE)
+#define    PAS_DMA_RXINT_BASEL_BRBL(x) ((x) & ~0x3f)
+#define PAS_DMA_RXINT_BASEU(i)         (0x21c+(i)*_PAS_DMA_RXINT_STRIDE)
+#define    PAS_DMA_RXINT_BASEU_BRBH(x) ((x) & 0xfff)
+#define    PAS_DMA_RXINT_BASEU_SIZ_M   0x3fff0000      /* # of cache lines worth of buffer ring */
+#define    PAS_DMA_RXINT_BASEU_SIZ_S   16              /* 0 = 16K */
+#define    PAS_DMA_RXINT_BASEU_SIZ(x)  (((x) << PAS_DMA_RXINT_BASEU_SIZ_S) & \
+                                        PAS_DMA_RXINT_BASEU_SIZ_M)
+
+
+#define _PAS_DMA_TXCHAN_STRIDE 0x20    /* Size per channel             */
+#define _PAS_DMA_TXCHAN_TCMDSTA        0x300   /* Command / Status             */
+#define _PAS_DMA_TXCHAN_CFG    0x304   /* Configuration                */
+#define _PAS_DMA_TXCHAN_DSCRBU 0x308   /* Descriptor BU Allocation     */
+#define _PAS_DMA_TXCHAN_INCR   0x310   /* Descriptor increment         */
+#define _PAS_DMA_TXCHAN_CNT    0x314   /* Descriptor count/offset      */
+#define _PAS_DMA_TXCHAN_BASEL  0x318   /* Descriptor ring base (low)   */
+#define _PAS_DMA_TXCHAN_BASEU  0x31c   /*                      (high)  */
+#define PAS_DMA_TXCHAN_TCMDSTA(c) (0x300+(c)*_PAS_DMA_TXCHAN_STRIDE)
+#define    PAS_DMA_TXCHAN_TCMDSTA_EN   0x00000001      /* Enabled */
+#define    PAS_DMA_TXCHAN_TCMDSTA_ST   0x00000002      /* Stop interface */
+#define    PAS_DMA_TXCHAN_TCMDSTA_ACT  0x00010000      /* Active */
+#define PAS_DMA_TXCHAN_CFG(c)     (0x304+(c)*_PAS_DMA_TXCHAN_STRIDE)
+#define    PAS_DMA_TXCHAN_CFG_TY_IFACE 0x00000000      /* Type = interface */
+#define    PAS_DMA_TXCHAN_CFG_TATTR_M  0x0000003c
+#define    PAS_DMA_TXCHAN_CFG_TATTR_S  2
+#define    PAS_DMA_TXCHAN_CFG_TATTR(x) (((x) << PAS_DMA_TXCHAN_CFG_TATTR_S) & \
+                                        PAS_DMA_TXCHAN_CFG_TATTR_M)
+#define    PAS_DMA_TXCHAN_CFG_WT_M     0x000001c0
+#define    PAS_DMA_TXCHAN_CFG_WT_S     6
+#define    PAS_DMA_TXCHAN_CFG_WT(x)    (((x) << PAS_DMA_TXCHAN_CFG_WT_S) & \
+                                        PAS_DMA_TXCHAN_CFG_WT_M)
+#define    PAS_DMA_TXCHAN_CFG_CF       0x00001000      /* Clean first line */
+#define    PAS_DMA_TXCHAN_CFG_CL       0x00002000      /* Clean last line */
+#define    PAS_DMA_TXCHAN_CFG_UP       0x00004000      /* update tx descr when sent */
+#define PAS_DMA_TXCHAN_INCR(c)    (0x310+(c)*_PAS_DMA_TXCHAN_STRIDE)
+#define PAS_DMA_TXCHAN_BASEL(c)   (0x318+(c)*_PAS_DMA_TXCHAN_STRIDE)
+#define    PAS_DMA_TXCHAN_BASEL_BRBL_M 0xffffffc0
+#define    PAS_DMA_TXCHAN_BASEL_BRBL_S 0
+#define    PAS_DMA_TXCHAN_BASEL_BRBL(x)        (((x) << PAS_DMA_TXCHAN_BASEL_BRBL_S) & \
+                                        PAS_DMA_TXCHAN_BASEL_BRBL_M)
+#define PAS_DMA_TXCHAN_BASEU(c)   (0x31c+(c)*_PAS_DMA_TXCHAN_STRIDE)
+#define    PAS_DMA_TXCHAN_BASEU_BRBH_M 0x00000fff
+#define    PAS_DMA_TXCHAN_BASEU_BRBH_S 0
+#define    PAS_DMA_TXCHAN_BASEU_BRBH(x)        (((x) << PAS_DMA_TXCHAN_BASEU_BRBH_S) & \
+                                        PAS_DMA_TXCHAN_BASEU_BRBH_M)
+/* # of cache lines worth of buffer ring */
+#define    PAS_DMA_TXCHAN_BASEU_SIZ_M  0x3fff0000
+#define    PAS_DMA_TXCHAN_BASEU_SIZ_S  16              /* 0 = 16K */
+#define    PAS_DMA_TXCHAN_BASEU_SIZ(x) (((x) << PAS_DMA_TXCHAN_BASEU_SIZ_S) & \
+                                        PAS_DMA_TXCHAN_BASEU_SIZ_M)
+
+#define _PAS_DMA_RXCHAN_STRIDE 0x20    /* Size per channel             */
+#define _PAS_DMA_RXCHAN_CCMDSTA        0x800   /* Command / Status             */
+#define _PAS_DMA_RXCHAN_CFG    0x804   /* Configuration                */
+#define _PAS_DMA_RXCHAN_INCR   0x810   /* Descriptor increment         */
+#define _PAS_DMA_RXCHAN_CNT    0x814   /* Descriptor count/offset      */
+#define _PAS_DMA_RXCHAN_BASEL  0x818   /* Descriptor ring base (low)   */
+#define _PAS_DMA_RXCHAN_BASEU  0x81c   /*                      (high)  */
+#define PAS_DMA_RXCHAN_CCMDSTA(c) (0x800+(c)*_PAS_DMA_RXCHAN_STRIDE)
+#define    PAS_DMA_RXCHAN_CCMDSTA_EN   0x00000001      /* Enabled */
+#define    PAS_DMA_RXCHAN_CCMDSTA_ST   0x00000002      /* Stop interface */
+#define    PAS_DMA_RXCHAN_CCMDSTA_ACT  0x00010000      /* Active */
+#define    PAS_DMA_RXCHAN_CCMDSTA_DU   0x00020000
+#define PAS_DMA_RXCHAN_CFG(c)     (0x804+(c)*_PAS_DMA_RXCHAN_STRIDE)
+#define    PAS_DMA_RXCHAN_CFG_HBU_M    0x00000380
+#define    PAS_DMA_RXCHAN_CFG_HBU_S    7
+#define    PAS_DMA_RXCHAN_CFG_HBU(x)   (((x) << PAS_DMA_RXCHAN_CFG_HBU_S) & \
+                                        PAS_DMA_RXCHAN_CFG_HBU_M)
+#define PAS_DMA_RXCHAN_INCR(c)    (0x810+(c)*_PAS_DMA_RXCHAN_STRIDE)
+#define PAS_DMA_RXCHAN_BASEL(c)   (0x818+(c)*_PAS_DMA_RXCHAN_STRIDE)
+#define    PAS_DMA_RXCHAN_BASEL_BRBL_M 0xffffffc0
+#define    PAS_DMA_RXCHAN_BASEL_BRBL_S 0
+#define    PAS_DMA_RXCHAN_BASEL_BRBL(x)        (((x) << PAS_DMA_RXCHAN_BASEL_BRBL_S) & \
+                                        PAS_DMA_RXCHAN_BASEL_BRBL_M)
+#define PAS_DMA_RXCHAN_BASEU(c)   (0x81c+(c)*_PAS_DMA_RXCHAN_STRIDE)
+#define    PAS_DMA_RXCHAN_BASEU_BRBH_M 0x00000fff
+#define    PAS_DMA_RXCHAN_BASEU_BRBH_S 0
+#define    PAS_DMA_RXCHAN_BASEU_BRBH(x)        (((x) << PAS_DMA_RXCHAN_BASEU_BRBH_S) & \
+                                        PAS_DMA_RXCHAN_BASEU_BRBH_M)
+/* # of cache lines worth of buffer ring */
+#define    PAS_DMA_RXCHAN_BASEU_SIZ_M  0x3fff0000
+#define    PAS_DMA_RXCHAN_BASEU_SIZ_S  16              /* 0 = 16K */
+#define    PAS_DMA_RXCHAN_BASEU_SIZ(x) (((x) << PAS_DMA_RXCHAN_BASEU_SIZ_S) & \
+                                        PAS_DMA_RXCHAN_BASEU_SIZ_M)
+
+#define    PAS_STATUS_PCNT_M           0x000000000000ffffull
+#define    PAS_STATUS_PCNT_S           0
+#define    PAS_STATUS_DCNT_M           0x00000000ffff0000ull
+#define    PAS_STATUS_DCNT_S           16
+#define    PAS_STATUS_BPCNT_M          0x0000ffff00000000ull
+#define    PAS_STATUS_BPCNT_S          32
+#define    PAS_STATUS_TIMER            0x1000000000000000ull
+#define    PAS_STATUS_ERROR            0x2000000000000000ull
+#define    PAS_STATUS_SOFT             0x4000000000000000ull
+#define    PAS_STATUS_INT              0x8000000000000000ull
+
+#define PAS_IOB_DMA_RXCH_CFG(i)                (0x1100 + (i)*4)
+#define    PAS_IOB_DMA_RXCH_CFG_CNTTH_M                0x00000fff
+#define    PAS_IOB_DMA_RXCH_CFG_CNTTH_S                0
+#define    PAS_IOB_DMA_RXCH_CFG_CNTTH(x)       (((x) << PAS_IOB_DMA_RXCH_CFG_CNTTH_S) & \
+                                                PAS_IOB_DMA_RXCH_CFG_CNTTH_M)
+#define PAS_IOB_DMA_TXCH_CFG(i)                (0x1200 + (i)*4)
+#define    PAS_IOB_DMA_TXCH_CFG_CNTTH_M                0x00000fff
+#define    PAS_IOB_DMA_TXCH_CFG_CNTTH_S                0
+#define    PAS_IOB_DMA_TXCH_CFG_CNTTH(x)       (((x) << PAS_IOB_DMA_TXCH_CFG_CNTTH_S) & \
+                                                PAS_IOB_DMA_TXCH_CFG_CNTTH_M)
+#define PAS_IOB_DMA_RXCH_STAT(i)       (0x1300 + (i)*4)
+#define    PAS_IOB_DMA_RXCH_STAT_INTGEN        0x00001000
+#define    PAS_IOB_DMA_RXCH_STAT_CNTDEL_M      0x00000fff
+#define    PAS_IOB_DMA_RXCH_STAT_CNTDEL_S      0
+#define    PAS_IOB_DMA_RXCH_STAT_CNTDEL(x)     (((x) << PAS_IOB_DMA_RXCH_STAT_CNTDEL_S) &\
+                                                PAS_IOB_DMA_RXCH_STAT_CNTDEL_M)
+#define PAS_IOB_DMA_TXCH_STAT(i)       (0x1400 + (i)*4)
+#define    PAS_IOB_DMA_TXCH_STAT_INTGEN        0x00001000
+#define    PAS_IOB_DMA_TXCH_STAT_CNTDEL_M      0x00000fff
+#define    PAS_IOB_DMA_TXCH_STAT_CNTDEL_S      0
+#define    PAS_IOB_DMA_TXCH_STAT_CNTDEL(x)     (((x) << PAS_IOB_DMA_TXCH_STAT_CNTDEL_S) &\
+                                                PAS_IOB_DMA_TXCH_STAT_CNTDEL_M)
+#define PAS_IOB_DMA_RXCH_RESET(i)      (0x1500 + (i)*4)
+#define    PAS_IOB_DMA_RXCH_RESET_PCNT_M       0xffff0000
+#define    PAS_IOB_DMA_RXCH_RESET_PCNT_S       0
+#define    PAS_IOB_DMA_RXCH_RESET_PCNT(x)      (((x) << PAS_IOB_DMA_RXCH_RESET_PCNT_S) & \
+                                                PAS_IOB_DMA_RXCH_RESET_PCNT_M)
+#define    PAS_IOB_DMA_RXCH_RESET_PCNTRST      0x00000020
+#define    PAS_IOB_DMA_RXCH_RESET_DCNTRST      0x00000010
+#define    PAS_IOB_DMA_RXCH_RESET_TINTC                0x00000008
+#define    PAS_IOB_DMA_RXCH_RESET_DINTC                0x00000004
+#define    PAS_IOB_DMA_RXCH_RESET_SINTC                0x00000002
+#define    PAS_IOB_DMA_RXCH_RESET_PINTC                0x00000001
+#define PAS_IOB_DMA_TXCH_RESET(i)      (0x1600 + (i)*4)
+#define    PAS_IOB_DMA_TXCH_RESET_PCNT_M       0xffff0000
+#define    PAS_IOB_DMA_TXCH_RESET_PCNT_S       0
+#define    PAS_IOB_DMA_TXCH_RESET_PCNT(x)      (((x) << PAS_IOB_DMA_TXCH_RESET_PCNT_S) & \
+                                                PAS_IOB_DMA_TXCH_RESET_PCNT_M)
+#define    PAS_IOB_DMA_TXCH_RESET_PCNTRST      0x00000020
+#define    PAS_IOB_DMA_TXCH_RESET_DCNTRST      0x00000010
+#define    PAS_IOB_DMA_TXCH_RESET_TINTC                0x00000008
+#define    PAS_IOB_DMA_TXCH_RESET_DINTC                0x00000004
+#define    PAS_IOB_DMA_TXCH_RESET_SINTC                0x00000002
+#define    PAS_IOB_DMA_TXCH_RESET_PINTC                0x00000001
+
+#define PAS_IOB_DMA_COM_TIMEOUTCFG             0x1700
+#define    PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT_M   0x00ffffff
+#define    PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT_S   0
+#define    PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(x)  (((x) << PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT_S) & \
+                                                PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT_M)
+
+/* Transmit descriptor fields */
+#define        XCT_MACTX_T             0x8000000000000000ull
+#define        XCT_MACTX_ST            0x4000000000000000ull
+#define XCT_MACTX_NORES                0x0000000000000000ull
+#define XCT_MACTX_8BRES                0x1000000000000000ull
+#define XCT_MACTX_24BRES       0x2000000000000000ull
+#define XCT_MACTX_40BRES       0x3000000000000000ull
+#define XCT_MACTX_I            0x0800000000000000ull
+#define XCT_MACTX_O            0x0400000000000000ull
+#define XCT_MACTX_E            0x0200000000000000ull
+#define XCT_MACTX_VLAN_M       0x0180000000000000ull
+#define XCT_MACTX_VLAN_NOP     0x0000000000000000ull
+#define XCT_MACTX_VLAN_REMOVE  0x0080000000000000ull
+#define XCT_MACTX_VLAN_INSERT   0x0100000000000000ull
+#define XCT_MACTX_VLAN_REPLACE  0x0180000000000000ull
+#define XCT_MACTX_CRC_M                0x0060000000000000ull
+#define XCT_MACTX_CRC_NOP      0x0000000000000000ull
+#define XCT_MACTX_CRC_INSERT   0x0020000000000000ull
+#define XCT_MACTX_CRC_PAD      0x0040000000000000ull
+#define XCT_MACTX_CRC_REPLACE  0x0060000000000000ull
+#define XCT_MACTX_SS           0x0010000000000000ull
+#define XCT_MACTX_LLEN_M       0x00007fff00000000ull
+#define XCT_MACTX_LLEN_S       32ull
+#define XCT_MACTX_LLEN(x)      ((((long)(x)) << XCT_MACTX_LLEN_S) & \
+                                XCT_MACTX_LLEN_M)
+#define XCT_MACTX_IPH_M                0x00000000f8000000ull
+#define XCT_MACTX_IPH_S                27ull
+#define XCT_MACTX_IPH(x)       ((((long)(x)) << XCT_MACTX_IPH_S) & \
+                                XCT_MACTX_IPH_M)
+#define XCT_MACTX_IPO_M                0x0000000007c00000ull
+#define XCT_MACTX_IPO_S                22ull
+#define XCT_MACTX_IPO(x)       ((((long)(x)) << XCT_MACTX_IPO_S) & \
+                                XCT_MACTX_IPO_M)
+#define XCT_MACTX_CSUM_M       0x0000000000000060ull
+#define XCT_MACTX_CSUM_NOP     0x0000000000000000ull
+#define XCT_MACTX_CSUM_TCP     0x0000000000000040ull
+#define XCT_MACTX_CSUM_UDP     0x0000000000000060ull
+#define XCT_MACTX_V6           0x0000000000000010ull
+#define XCT_MACTX_C            0x0000000000000004ull
+#define XCT_MACTX_AL2          0x0000000000000002ull
+
+/* Receive descriptor fields */
+#define        XCT_MACRX_T             0x8000000000000000ull
+#define        XCT_MACRX_ST            0x4000000000000000ull
+#define XCT_MACRX_NORES                0x0000000000000000ull
+#define XCT_MACRX_8BRES                0x1000000000000000ull
+#define XCT_MACRX_24BRES       0x2000000000000000ull
+#define XCT_MACRX_40BRES       0x3000000000000000ull
+#define XCT_MACRX_O            0x0400000000000000ull
+#define XCT_MACRX_E            0x0200000000000000ull
+#define XCT_MACRX_FF           0x0100000000000000ull
+#define XCT_MACRX_PF           0x0080000000000000ull
+#define XCT_MACRX_OB           0x0040000000000000ull
+#define XCT_MACRX_OD           0x0020000000000000ull
+#define XCT_MACRX_FS           0x0010000000000000ull
+#define XCT_MACRX_NB_M         0x000fc00000000000ull
+#define XCT_MACRX_NB_S         46ULL
+#define XCT_MACRX_NB(x)                ((((long)(x)) << XCT_MACRX_NB_S) & \
+                                XCT_MACRX_NB_M)
+#define XCT_MACRX_LLEN_M       0x00003fff00000000ull
+#define XCT_MACRX_LLEN_S       32ULL
+#define XCT_MACRX_LLEN(x)      ((((long)(x)) << XCT_MACRX_LLEN_S) & \
+                                XCT_MACRX_LLEN_M)
+#define XCT_MACRX_CRC          0x0000000080000000ull
+#define XCT_MACRX_LEN_M                0x0000000060000000ull
+#define XCT_MACRX_LEN_TOOSHORT 0x0000000020000000ull
+#define XCT_MACRX_LEN_BELOWMIN 0x0000000040000000ull
+#define XCT_MACRX_LEN_TRUNC    0x0000000060000000ull
+#define XCT_MACRX_CAST_M       0x0000000018000000ull
+#define XCT_MACRX_CAST_UNI     0x0000000000000000ull
+#define XCT_MACRX_CAST_MULTI   0x0000000008000000ull
+#define XCT_MACRX_CAST_BROAD   0x0000000010000000ull
+#define XCT_MACRX_CAST_PAUSE   0x0000000018000000ull
+#define XCT_MACRX_VLC_M                0x0000000006000000ull
+#define XCT_MACRX_FM           0x0000000001000000ull
+#define XCT_MACRX_HTY_M                0x0000000000c00000ull
+#define XCT_MACRX_HTY_IPV4_OK  0x0000000000000000ull
+#define XCT_MACRX_HTY_IPV6     0x0000000000400000ull
+#define XCT_MACRX_HTY_IPV4_BAD 0x0000000000800000ull
+#define XCT_MACRX_HTY_NONIP    0x0000000000c00000ull
+#define XCT_MACRX_IPP_M                0x00000000003f0000ull
+#define XCT_MACRX_IPP_S                16
+#define XCT_MACRX_CSUM_M       0x000000000000ffffull
+#define XCT_MACRX_CSUM_S       0
+
+#define XCT_PTR_T              0x8000000000000000ull
+#define XCT_PTR_LEN_M          0x7ffff00000000000ull
+#define XCT_PTR_LEN_S          44
+#define XCT_PTR_LEN(x)         ((((long)(x)) << XCT_PTR_LEN_S) & \
+                                XCT_PTR_LEN_M)
+#define XCT_PTR_ADDR_M         0x00000fffffffffffull
+#define XCT_PTR_ADDR_S         0
+#define XCT_PTR_ADDR(x)                ((((long)(x)) << XCT_PTR_ADDR_S) & \
+                                XCT_PTR_ADDR_M)
+
+/* Receive interface buffer fields */
+#define XCT_RXB_LEN_M          0x0ffff00000000000ull
+#define XCT_RXB_LEN_S          44
+#define XCT_RXB_LEN(x)         ((((long)(x)) << XCT_PTR_LEN_S) & XCT_PTR_LEN_M)
+#define XCT_RXB_ADDR_M         0x00000fffffffffffull
+#define XCT_RXB_ADDR_S         0
+#define XCT_RXB_ADDR(x)                ((((long)(x)) << XCT_PTR_ADDR_S) & XCT_PTR_ADDR_M)
+
+
+#endif /* PASEMI_MAC_H */
old mode 100644 (file)
new mode 100755 (executable)
index 8844c20..2429b27
@@ -22,6 +22,7 @@
 #include <linux/errno.h>
 #include <linux/ioport.h>
 #include <linux/ip.h>
+#include <linux/in.h>
 #include <linux/if_arp.h>
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
@@ -63,6 +64,7 @@ MODULE_PARM_DESC(msi, "Turn on Message Signaled Interrupts.");
 
 static struct pci_device_id ql3xxx_pci_tbl[] __devinitdata = {
        {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, QL3022_DEVICE_ID)},
+       {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, QL3032_DEVICE_ID)},
        /* required last entry */
        {0,}
 };
@@ -1475,6 +1477,10 @@ static int ql_mii_setup(struct ql3_adapter *qdev)
                         2) << 7))
                return -1;
 
+       if (qdev->device_id == QL3032_DEVICE_ID)
+               ql_write_page0_reg(qdev, 
+                       &port_regs->macMIIMgmtControlReg, 0x0f00000);
+
        /* Divide 125MHz clock by 28 to meet PHY timing requirements */
        reg = MAC_MII_CONTROL_CLK_SEL_DIV28;
 
@@ -1706,18 +1712,42 @@ static void ql_process_mac_tx_intr(struct ql3_adapter *qdev,
                                   struct ob_mac_iocb_rsp *mac_rsp)
 {
        struct ql_tx_buf_cb *tx_cb;
+       int i;
 
        tx_cb = &qdev->tx_buf[mac_rsp->transaction_id];
        pci_unmap_single(qdev->pdev,
-                        pci_unmap_addr(tx_cb, mapaddr),
-                        pci_unmap_len(tx_cb, maplen), PCI_DMA_TODEVICE);
-       dev_kfree_skb_irq(tx_cb->skb);
+                        pci_unmap_addr(&tx_cb->map[0], mapaddr),
+                        pci_unmap_len(&tx_cb->map[0], maplen),
+                        PCI_DMA_TODEVICE);
+       tx_cb->seg_count--;
+       if (tx_cb->seg_count) {
+               for (i = 1; i < tx_cb->seg_count; i++) {
+                       pci_unmap_page(qdev->pdev,
+                                      pci_unmap_addr(&tx_cb->map[i],
+                                                     mapaddr),
+                                      pci_unmap_len(&tx_cb->map[i], maplen),
+                                      PCI_DMA_TODEVICE);
+               }
+       }
        qdev->stats.tx_packets++;
        qdev->stats.tx_bytes += tx_cb->skb->len;
+       dev_kfree_skb_irq(tx_cb->skb);
        tx_cb->skb = NULL;
        atomic_inc(&qdev->tx_count);
 }
 
+/*
+ * The difference between 3022 and 3032 for inbound completions:
+ * 3022 uses two buffers per completion.  The first buffer contains 
+ * (some) header info, the second the remainder of the headers plus 
+ * the data.  For this chip we reserve some space at the top of the 
+ * receive buffer so that the header info in buffer one can be 
+ * prepended to the buffer two.  Buffer two is the sent up while 
+ * buffer one is returned to the hardware to be reused.
+ * 3032 receives all of it's data and headers in one buffer for a 
+ * simpler process.  3032 also supports checksum verification as
+ * can be seen in ql_process_macip_rx_intr().
+ */
 static void ql_process_mac_rx_intr(struct ql3_adapter *qdev,
                                   struct ib_mac_iocb_rsp *ib_mac_rsp_ptr)
 {
@@ -1740,14 +1770,17 @@ static void ql_process_mac_rx_intr(struct ql3_adapter *qdev,
        qdev->last_rsp_offset = qdev->small_buf_phy_addr_low + offset;
        qdev->small_buf_release_cnt++;
 
-       /* start of first buffer */
-       lrg_buf_phy_addr_low = le32_to_cpu(*curr_ial_ptr);
-       lrg_buf_cb1 = &qdev->lrg_buf[qdev->lrg_buf_index];
-       qdev->lrg_buf_release_cnt++;
-       if (++qdev->lrg_buf_index == NUM_LARGE_BUFFERS)
-               qdev->lrg_buf_index = 0;
-       curr_ial_ptr++;         /* 64-bit pointers require two incs. */
-       curr_ial_ptr++;
+       if (qdev->device_id == QL3022_DEVICE_ID) {
+               /* start of first buffer (3022 only) */
+               lrg_buf_phy_addr_low = le32_to_cpu(*curr_ial_ptr);
+               lrg_buf_cb1 = &qdev->lrg_buf[qdev->lrg_buf_index];
+               qdev->lrg_buf_release_cnt++;
+               if (++qdev->lrg_buf_index == NUM_LARGE_BUFFERS) {
+                       qdev->lrg_buf_index = 0;
+               }
+               curr_ial_ptr++; /* 64-bit pointers require two incs. */
+               curr_ial_ptr++;
+       }
 
        /* start of second buffer */
        lrg_buf_phy_addr_low = le32_to_cpu(*curr_ial_ptr);
@@ -1778,7 +1811,8 @@ static void ql_process_mac_rx_intr(struct ql3_adapter *qdev,
        qdev->ndev->last_rx = jiffies;
        lrg_buf_cb2->skb = NULL;
 
-       ql_release_to_lrg_buf_free_list(qdev, lrg_buf_cb1);
+       if (qdev->device_id == QL3022_DEVICE_ID)
+               ql_release_to_lrg_buf_free_list(qdev, lrg_buf_cb1);
        ql_release_to_lrg_buf_free_list(qdev, lrg_buf_cb2);
 }
 
@@ -1790,7 +1824,7 @@ static void ql_process_macip_rx_intr(struct ql3_adapter *qdev,
        struct ql_rcv_buf_cb *lrg_buf_cb1 = NULL;
        struct ql_rcv_buf_cb *lrg_buf_cb2 = NULL;
        u32 *curr_ial_ptr;
-       struct sk_buff *skb1, *skb2;
+       struct sk_buff *skb1 = NULL, *skb2;
        struct net_device *ndev = qdev->ndev;
        u16 length = le16_to_cpu(ib_ip_rsp_ptr->length);
        u16 size = 0;
@@ -1806,16 +1840,20 @@ static void ql_process_macip_rx_intr(struct ql3_adapter *qdev,
        qdev->last_rsp_offset = qdev->small_buf_phy_addr_low + offset;
        qdev->small_buf_release_cnt++;
 
-       /* start of first buffer */
-       lrg_buf_phy_addr_low = le32_to_cpu(*curr_ial_ptr);
-       lrg_buf_cb1 = &qdev->lrg_buf[qdev->lrg_buf_index];
-
-       qdev->lrg_buf_release_cnt++;
-       if (++qdev->lrg_buf_index == NUM_LARGE_BUFFERS)
-               qdev->lrg_buf_index = 0;
-       skb1 = lrg_buf_cb1->skb;
-       curr_ial_ptr++;         /* 64-bit pointers require two incs. */
-       curr_ial_ptr++;
+       if (qdev->device_id == QL3022_DEVICE_ID) {
+               /* start of first buffer on 3022 */
+               lrg_buf_phy_addr_low = le32_to_cpu(*curr_ial_ptr);
+               lrg_buf_cb1 = &qdev->lrg_buf[qdev->lrg_buf_index];
+               qdev->lrg_buf_release_cnt++;
+               if (++qdev->lrg_buf_index == NUM_LARGE_BUFFERS)
+                       qdev->lrg_buf_index = 0;
+               skb1 = lrg_buf_cb1->skb;
+               curr_ial_ptr++; /* 64-bit pointers require two incs. */
+               curr_ial_ptr++;
+               size = ETH_HLEN;
+               if (*((u16 *) skb1->data) != 0xFFFF)
+                       size += VLAN_ETH_HLEN - ETH_HLEN;
+       }
 
        /* start of second buffer */
        lrg_buf_phy_addr_low = le32_to_cpu(*curr_ial_ptr);
@@ -1825,18 +1863,6 @@ static void ql_process_macip_rx_intr(struct ql3_adapter *qdev,
        if (++qdev->lrg_buf_index == NUM_LARGE_BUFFERS)
                qdev->lrg_buf_index = 0;
 
-       qdev->stats.rx_packets++;
-       qdev->stats.rx_bytes += length;
-
-       /*
-        * Copy the ethhdr from first buffer to second. This
-        * is necessary for IP completions.
-        */
-       if (*((u16 *) skb1->data) != 0xFFFF)
-               size = VLAN_ETH_HLEN;
-       else
-               size = ETH_HLEN;
-
        skb_put(skb2, length);  /* Just the second buffer length here. */
        pci_unmap_single(qdev->pdev,
                         pci_unmap_addr(lrg_buf_cb2, mapaddr),
@@ -1844,16 +1870,40 @@ static void ql_process_macip_rx_intr(struct ql3_adapter *qdev,
                         PCI_DMA_FROMDEVICE);
        prefetch(skb2->data);
 
-       memcpy(skb_push(skb2, size), skb1->data + VLAN_ID_LEN, size);
-       skb2->dev = qdev->ndev;
        skb2->ip_summed = CHECKSUM_NONE;
+       if (qdev->device_id == QL3022_DEVICE_ID) {
+               /*
+                * Copy the ethhdr from first buffer to second. This
+                * is necessary for 3022 IP completions.
+                */
+               memcpy(skb_push(skb2, size), skb1->data + VLAN_ID_LEN, size);
+       } else {
+               u16 checksum = le16_to_cpu(ib_ip_rsp_ptr->checksum);
+               if (checksum & 
+                       (IB_IP_IOCB_RSP_3032_ICE | 
+                        IB_IP_IOCB_RSP_3032_CE | 
+                        IB_IP_IOCB_RSP_3032_NUC)) {
+                       printk(KERN_ERR
+                              "%s: Bad checksum for this %s packet, checksum = %x.\n",
+                              __func__,
+                              ((checksum & 
+                               IB_IP_IOCB_RSP_3032_TCP) ? "TCP" :
+                               "UDP"),checksum);
+               } else if (checksum & IB_IP_IOCB_RSP_3032_TCP) {
+                       skb2->ip_summed = CHECKSUM_UNNECESSARY;
+               } 
+       }
+       skb2->dev = qdev->ndev;
        skb2->protocol = eth_type_trans(skb2, qdev->ndev);
 
        netif_receive_skb(skb2);
+       qdev->stats.rx_packets++;
+       qdev->stats.rx_bytes += length;
        ndev->last_rx = jiffies;
        lrg_buf_cb2->skb = NULL;
 
-       ql_release_to_lrg_buf_free_list(qdev, lrg_buf_cb1);
+       if (qdev->device_id == QL3022_DEVICE_ID)
+               ql_release_to_lrg_buf_free_list(qdev, lrg_buf_cb1);
        ql_release_to_lrg_buf_free_list(qdev, lrg_buf_cb2);
 }
 
@@ -1880,12 +1930,14 @@ static int ql_tx_rx_clean(struct ql3_adapter *qdev,
                        break;
 
                case OPCODE_IB_MAC_IOCB:
+               case OPCODE_IB_3032_MAC_IOCB:
                        ql_process_mac_rx_intr(qdev, (struct ib_mac_iocb_rsp *)
                                               net_rsp);
                        (*rx_cleaned)++;
                        break;
 
                case OPCODE_IB_IP_IOCB:
+               case OPCODE_IB_3032_IP_IOCB:
                        ql_process_macip_rx_intr(qdev, (struct ib_ip_iocb_rsp *)
                                                 net_rsp);
                        (*rx_cleaned)++;
@@ -2032,13 +2084,96 @@ static irqreturn_t ql3xxx_isr(int irq, void *dev_id)
        return IRQ_RETVAL(handled);
 }
 
+/*
+ * Get the total number of segments needed for the 
+ * given number of fragments.  This is necessary because
+ * outbound address lists (OAL) will be used when more than
+ * two frags are given.  Each address list has 5 addr/len 
+ * pairs.  The 5th pair in each AOL is used to  point to
+ * the next AOL if more frags are coming.  
+ * That is why the frags:segment count  ratio is not linear.
+ */
+static int ql_get_seg_count(unsigned short frags)
+{
+       switch(frags) {
+       case 0: return 1;       /* just the skb->data seg */
+       case 1: return 2;       /* skb->data + 1 frag */
+       case 2: return 3;       /* skb->data + 2 frags */
+       case 3: return 5;       /* skb->data + 1 frag + 1 AOL containting 2 frags */
+       case 4: return 6;
+       case 5: return 7;
+       case 6: return 8;
+       case 7: return 10;
+       case 8: return 11;
+       case 9: return 12;
+       case 10: return 13;
+       case 11: return 15;
+       case 12: return 16;
+       case 13: return 17;
+       case 14: return 18;
+       case 15: return 20;
+       case 16: return 21;
+       case 17: return 22;
+       case 18: return 23;
+       }
+       return -1;
+}
+
+static void ql_hw_csum_setup(struct sk_buff *skb,
+                            struct ob_mac_iocb_req *mac_iocb_ptr)
+{
+       struct ethhdr *eth;
+       struct iphdr *ip = NULL;
+       u8 offset = ETH_HLEN;
+
+       eth = (struct ethhdr *)(skb->data);
+
+       if (eth->h_proto == __constant_htons(ETH_P_IP)) {
+               ip = (struct iphdr *)&skb->data[ETH_HLEN];
+       } else if (eth->h_proto == htons(ETH_P_8021Q) &&
+                  ((struct vlan_ethhdr *)skb->data)->
+                  h_vlan_encapsulated_proto == __constant_htons(ETH_P_IP)) {
+               ip = (struct iphdr *)&skb->data[VLAN_ETH_HLEN];
+               offset = VLAN_ETH_HLEN;
+       }
+
+       if (ip) {
+               if (ip->protocol == IPPROTO_TCP) {
+                       mac_iocb_ptr->flags1 |= OB_3032MAC_IOCB_REQ_TC;
+                       mac_iocb_ptr->ip_hdr_off = offset;
+                       mac_iocb_ptr->ip_hdr_len = ip->ihl;
+               } else if (ip->protocol == IPPROTO_UDP) {
+                       mac_iocb_ptr->flags1 |= OB_3032MAC_IOCB_REQ_UC;
+                       mac_iocb_ptr->ip_hdr_off = offset;
+                       mac_iocb_ptr->ip_hdr_len = ip->ihl;
+               }
+       }
+}
+
+/*
+ * The difference between 3022 and 3032 sends:
+ * 3022 only supports a simple single segment transmission.
+ * 3032 supports checksumming and scatter/gather lists (fragments).
+ * The 3032 supports sglists by using the 3 addr/len pairs (ALP) 
+ * in the IOCB plus a chain of outbound address lists (OAL) that 
+ * each contain 5 ALPs.  The last ALP of the IOCB (3rd) or OAL (5th) 
+ * will used to point to an OAL when more ALP entries are required.  
+ * The IOCB is always the top of the chain followed by one or more 
+ * OALs (when necessary).
+ */
 static int ql3xxx_send(struct sk_buff *skb, struct net_device *ndev)
 {
        struct ql3_adapter *qdev = (struct ql3_adapter *)netdev_priv(ndev);
        struct ql3xxx_port_registers __iomem *port_regs = qdev->mem_map_registers;
        struct ql_tx_buf_cb *tx_cb;
+       u32 tot_len = skb->len;
+       struct oal *oal;
+       struct oal_entry *oal_entry;
+       int len;
        struct ob_mac_iocb_req *mac_iocb_ptr;
        u64 map;
+       int seg_cnt, seg = 0;
+       int frag_cnt = (int)skb_shinfo(skb)->nr_frags;
 
        if (unlikely(atomic_read(&qdev->tx_count) < 2)) {
                if (!netif_queue_stopped(ndev))
@@ -2046,21 +2181,79 @@ static int ql3xxx_send(struct sk_buff *skb, struct net_device *ndev)
                return NETDEV_TX_BUSY;
        }
        tx_cb = &qdev->tx_buf[qdev->req_producer_index] ;
+       seg_cnt = tx_cb->seg_count = ql_get_seg_count((skb_shinfo(skb)->nr_frags));
+       if(seg_cnt == -1) {
+               printk(KERN_ERR PFX"%s: invalid segment count!\n",__func__);
+               return NETDEV_TX_OK;
+
+       }
        mac_iocb_ptr = tx_cb->queue_entry;
        memset((void *)mac_iocb_ptr, 0, sizeof(struct ob_mac_iocb_req));
        mac_iocb_ptr->opcode = qdev->mac_ob_opcode;
        mac_iocb_ptr->flags |= qdev->mb_bit_mask;
        mac_iocb_ptr->transaction_id = qdev->req_producer_index;
-       mac_iocb_ptr->data_len = cpu_to_le16((u16) skb->len);
+       mac_iocb_ptr->data_len = cpu_to_le16((u16) tot_len);
        tx_cb->skb = skb;
-       map = pci_map_single(qdev->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
-       mac_iocb_ptr->buf_addr0_low = cpu_to_le32(LS_64BITS(map));
-       mac_iocb_ptr->buf_addr0_high = cpu_to_le32(MS_64BITS(map));
-       mac_iocb_ptr->buf_0_len = cpu_to_le32(skb->len | OB_MAC_IOCB_REQ_E);
-       pci_unmap_addr_set(tx_cb, mapaddr, map);
-       pci_unmap_len_set(tx_cb, maplen, skb->len);
-       atomic_dec(&qdev->tx_count);
+       if (skb->ip_summed == CHECKSUM_PARTIAL)
+               ql_hw_csum_setup(skb, mac_iocb_ptr);
+       len = skb_headlen(skb);
+       map = pci_map_single(qdev->pdev, skb->data, len, PCI_DMA_TODEVICE);
+       oal_entry = (struct oal_entry *)&mac_iocb_ptr->buf_addr0_low;
+       oal_entry->dma_lo = cpu_to_le32(LS_64BITS(map));
+       oal_entry->dma_hi = cpu_to_le32(MS_64BITS(map));
+       oal_entry->len = cpu_to_le32(len);
+       pci_unmap_addr_set(&tx_cb->map[seg], mapaddr, map);
+       pci_unmap_len_set(&tx_cb->map[seg], maplen, len);
+       seg++;
+
+       if (!skb_shinfo(skb)->nr_frags) {
+               /* Terminate the last segment. */
+               oal_entry->len =
+                   cpu_to_le32(le32_to_cpu(oal_entry->len) | OAL_LAST_ENTRY);
+       } else {
+               int i;
+               oal = tx_cb->oal;
+               for (i=0; i<frag_cnt; i++,seg++) {
+                       skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
+                       oal_entry++;
+                       if ((seg == 2 && seg_cnt > 3) ||        /* Check for continuation */
+                           (seg == 7 && seg_cnt > 8) ||        /* requirements. It's strange */
+                           (seg == 12 && seg_cnt > 13) ||      /* but necessary. */
+                           (seg == 17 && seg_cnt > 18)) {
+                               /* Continuation entry points to outbound address list. */
+                               map = pci_map_single(qdev->pdev, oal,
+                                                    sizeof(struct oal),
+                                                    PCI_DMA_TODEVICE);
+                               oal_entry->dma_lo = cpu_to_le32(LS_64BITS(map));
+                               oal_entry->dma_hi = cpu_to_le32(MS_64BITS(map));
+                               oal_entry->len =
+                                   cpu_to_le32(sizeof(struct oal) |
+                                               OAL_CONT_ENTRY);
+                               pci_unmap_addr_set(&tx_cb->map[seg], mapaddr,
+                                                  map);
+                               pci_unmap_len_set(&tx_cb->map[seg], maplen,
+                                                 len);
+                               oal_entry = (struct oal_entry *)oal;
+                               oal++;
+                               seg++;
+                       }
 
+                       map =
+                           pci_map_page(qdev->pdev, frag->page,
+                                        frag->page_offset, frag->size,
+                                        PCI_DMA_TODEVICE);
+                       oal_entry->dma_lo = cpu_to_le32(LS_64BITS(map));
+                       oal_entry->dma_hi = cpu_to_le32(MS_64BITS(map));
+                       oal_entry->len = cpu_to_le32(frag->size);
+                       pci_unmap_addr_set(&tx_cb->map[seg], mapaddr, map);
+                       pci_unmap_len_set(&tx_cb->map[seg], maplen,
+                                         frag->size);
+               }
+               /* Terminate the last segment. */
+               oal_entry->len =
+                   cpu_to_le32(le32_to_cpu(oal_entry->len) | OAL_LAST_ENTRY);
+       }
+       wmb();
        qdev->req_producer_index++;
        if (qdev->req_producer_index == NUM_REQ_Q_ENTRIES)
                qdev->req_producer_index = 0;
@@ -2074,8 +2267,10 @@ static int ql3xxx_send(struct sk_buff *skb, struct net_device *ndev)
                printk(KERN_DEBUG PFX "%s: tx queued, slot %d, len %d\n",
                       ndev->name, qdev->req_producer_index, skb->len);
 
+       atomic_dec(&qdev->tx_count);
        return NETDEV_TX_OK;
 }
+
 static int ql_alloc_net_req_rsp_queues(struct ql3_adapter *qdev)
 {
        qdev->req_q_size =
@@ -2359,7 +2554,22 @@ static int ql_alloc_large_buffers(struct ql3_adapter *qdev)
        return 0;
 }
 
-static void ql_create_send_free_list(struct ql3_adapter *qdev)
+static void ql_free_send_free_list(struct ql3_adapter *qdev)
+{
+       struct ql_tx_buf_cb *tx_cb;
+       int i;
+
+       tx_cb = &qdev->tx_buf[0];
+       for (i = 0; i < NUM_REQ_Q_ENTRIES; i++) {
+               if (tx_cb->oal) {
+                       kfree(tx_cb->oal);
+                       tx_cb->oal = NULL;
+               }
+               tx_cb++;
+       }
+}
+
+static int ql_create_send_free_list(struct ql3_adapter *qdev)
 {
        struct ql_tx_buf_cb *tx_cb;
        int i;
@@ -2368,11 +2578,16 @@ static void ql_create_send_free_list(struct ql3_adapter *qdev)
 
        /* Create free list of transmit buffers */
        for (i = 0; i < NUM_REQ_Q_ENTRIES; i++) {
+
                tx_cb = &qdev->tx_buf[i];
                tx_cb->skb = NULL;
                tx_cb->queue_entry = req_q_curr;
                req_q_curr++;
+               tx_cb->oal = kmalloc(512, GFP_KERNEL);
+               if (tx_cb->oal == NULL)
+                       return -1;
        }
+       return 0;
 }
 
 static int ql_alloc_mem_resources(struct ql3_adapter *qdev)
@@ -2447,12 +2662,14 @@ static int ql_alloc_mem_resources(struct ql3_adapter *qdev)
 
        /* Initialize the large buffer queue. */
        ql_init_large_buffers(qdev);
-       ql_create_send_free_list(qdev);
+       if (ql_create_send_free_list(qdev))
+               goto err_free_list;
 
        qdev->rsp_current = qdev->rsp_q_virt_addr;
 
        return 0;
-
+err_free_list:
+       ql_free_send_free_list(qdev);
 err_small_buffers:
        ql_free_buffer_queues(qdev);
 err_buffer_queues:
@@ -2468,6 +2685,7 @@ err_req_rsp:
 
 static void ql_free_mem_resources(struct ql3_adapter *qdev)
 {
+       ql_free_send_free_list(qdev);
        ql_free_large_buffers(qdev);
        ql_free_small_buffers(qdev);
        ql_free_buffer_queues(qdev);
@@ -2766,11 +2984,20 @@ static int ql_adapter_initialize(struct ql3_adapter *qdev)
        }
 
        /* Enable Ethernet Function */
-       value =
-           (PORT_CONTROL_EF | PORT_CONTROL_ET | PORT_CONTROL_EI |
-            PORT_CONTROL_HH);
-       ql_write_page0_reg(qdev, &port_regs->portControl,
-                          ((value << 16) | value));
+       if (qdev->device_id == QL3032_DEVICE_ID) {
+               value =
+                   (QL3032_PORT_CONTROL_EF | QL3032_PORT_CONTROL_KIE |
+                    QL3032_PORT_CONTROL_EIv6 | QL3032_PORT_CONTROL_EIv4);
+               ql_write_page0_reg(qdev, &port_regs->functionControl,
+                                  ((value << 16) | value));
+       } else {
+               value =
+                   (PORT_CONTROL_EF | PORT_CONTROL_ET | PORT_CONTROL_EI |
+                    PORT_CONTROL_HH);
+               ql_write_page0_reg(qdev, &port_regs->portControl,
+                                  ((value << 16) | value));
+       }
+
 
 out:
        return status;
@@ -2917,8 +3144,10 @@ static void ql_display_dev_info(struct net_device *ndev)
        struct pci_dev *pdev = qdev->pdev;
 
        printk(KERN_INFO PFX
-              "\n%s Adapter %d RevisionID %d found on PCI slot %d.\n",
-              DRV_NAME, qdev->index, qdev->chip_rev_id, qdev->pci_slot);
+              "\n%s Adapter %d RevisionID %d found %s on PCI slot %d.\n",
+              DRV_NAME, qdev->index, qdev->chip_rev_id,
+              (qdev->device_id == QL3032_DEVICE_ID) ? "QLA3032" : "QLA3022",
+              qdev->pci_slot);
        printk(KERN_INFO PFX
               "%s Interface.\n",
               test_bit(QL_LINK_OPTICAL,&qdev->flags) ? "OPTICAL" : "COPPER");
@@ -3212,15 +3441,22 @@ static void ql_reset_work(struct work_struct *work)
                 * Loop through the active list and return the skb.
                 */
                for (i = 0; i < NUM_REQ_Q_ENTRIES; i++) {
+                       int j;
                        tx_cb = &qdev->tx_buf[i];
                        if (tx_cb->skb) {
-
                                printk(KERN_DEBUG PFX
                                       "%s: Freeing lost SKB.\n",
                                       qdev->ndev->name);
                                pci_unmap_single(qdev->pdev,
-                                       pci_unmap_addr(tx_cb, mapaddr),
-                                       pci_unmap_len(tx_cb, maplen), PCI_DMA_TODEVICE);
+                                        pci_unmap_addr(&tx_cb->map[0], mapaddr),
+                                        pci_unmap_len(&tx_cb->map[0], maplen),
+                                        PCI_DMA_TODEVICE);
+                               for(j=1;j<tx_cb->seg_count;j++) {
+                                       pci_unmap_page(qdev->pdev,
+                                              pci_unmap_addr(&tx_cb->map[j],mapaddr),
+                                              pci_unmap_len(&tx_cb->map[j],maplen),
+                                              PCI_DMA_TODEVICE);
+                               }
                                dev_kfree_skb(tx_cb->skb);
                                tx_cb->skb = NULL;
                        }
@@ -3379,21 +3615,24 @@ static int __devinit ql3xxx_probe(struct pci_dev *pdev,
        SET_MODULE_OWNER(ndev);
        SET_NETDEV_DEV(ndev, &pdev->dev);
 
-       if (pci_using_dac)
-               ndev->features |= NETIF_F_HIGHDMA;
-
        pci_set_drvdata(pdev, ndev);
 
        qdev = netdev_priv(ndev);
        qdev->index = cards_found;
        qdev->ndev = ndev;
        qdev->pdev = pdev;
+       qdev->device_id = pci_entry->device;
        qdev->port_link_state = LS_DOWN;
        if (msi)
                qdev->msi = 1;
 
        qdev->msg_enable = netif_msg_init(debug, default_msg);
 
+       if (pci_using_dac)
+               ndev->features |= NETIF_F_HIGHDMA;
+       if (qdev->device_id == QL3032_DEVICE_ID)
+               ndev->features |= (NETIF_F_HW_CSUM | NETIF_F_SG);
+
        qdev->mem_map_registers =
            ioremap_nocache(pci_resource_start(pdev, 1),
                            pci_resource_len(qdev->pdev, 1));
old mode 100644 (file)
new mode 100755 (executable)
index ea94de7..b2d76ea
@@ -21,7 +21,9 @@
 
 #define OPCODE_UPDATE_NCB_IOCB      0xF0
 #define OPCODE_IB_MAC_IOCB          0xF9
+#define OPCODE_IB_3032_MAC_IOCB     0x09
 #define OPCODE_IB_IP_IOCB           0xFA
+#define OPCODE_IB_3032_IP_IOCB      0x0A
 #define OPCODE_IB_TCP_IOCB          0xFB
 #define OPCODE_DUMP_PROTO_IOCB      0xFE
 #define OPCODE_BUFFER_ALERT_IOCB    0xFB
 struct ob_mac_iocb_req {
        u8 opcode;
        u8 flags;
-#define OB_MAC_IOCB_REQ_MA  0xC0
-#define OB_MAC_IOCB_REQ_F   0x20
-#define OB_MAC_IOCB_REQ_X   0x10
+#define OB_MAC_IOCB_REQ_MA  0xe0
+#define OB_MAC_IOCB_REQ_F   0x10
+#define OB_MAC_IOCB_REQ_X   0x08
 #define OB_MAC_IOCB_REQ_D   0x02
 #define OB_MAC_IOCB_REQ_I   0x01
-       __le16 reserved0;
+       u8 flags1;
+#define OB_3032MAC_IOCB_REQ_IC 0x04
+#define OB_3032MAC_IOCB_REQ_TC 0x02
+#define OB_3032MAC_IOCB_REQ_UC 0x01
+       u8 reserved0;
 
        __le32 transaction_id;
        __le16 data_len;
-       __le16 reserved1;
+       u8 ip_hdr_off;
+       u8 ip_hdr_len;
+       __le32 reserved1;
        __le32 reserved2;
-       __le32 reserved3;
        __le32 buf_addr0_low;
        __le32 buf_addr0_high;
        __le32 buf_0_len;
@@ -58,8 +65,8 @@ struct ob_mac_iocb_req {
        __le32 buf_addr2_low;
        __le32 buf_addr2_high;
        __le32 buf_2_len;
+       __le32 reserved3;
        __le32 reserved4;
-       __le32 reserved5;
 };
 /*
  * The following constants define control bits for buffer
@@ -74,6 +81,7 @@ struct ob_mac_iocb_rsp {
        u8 opcode;
        u8 flags;
 #define OB_MAC_IOCB_RSP_P   0x08
+#define OB_MAC_IOCB_RSP_L   0x04
 #define OB_MAC_IOCB_RSP_S   0x02
 #define OB_MAC_IOCB_RSP_I   0x01
 
@@ -85,6 +93,7 @@ struct ob_mac_iocb_rsp {
 
 struct ib_mac_iocb_rsp {
        u8 opcode;
+#define IB_MAC_IOCB_RSP_V   0x80
        u8 flags;
 #define IB_MAC_IOCB_RSP_S   0x80
 #define IB_MAC_IOCB_RSP_H1  0x40
@@ -138,6 +147,7 @@ struct ob_ip_iocb_req {
 struct ob_ip_iocb_rsp {
        u8 opcode;
        u8 flags;
+#define OB_MAC_IOCB_RSP_H       0x10
 #define OB_MAC_IOCB_RSP_E       0x08
 #define OB_MAC_IOCB_RSP_L       0x04
 #define OB_MAC_IOCB_RSP_S       0x02
@@ -220,6 +230,10 @@ struct ob_tcp_iocb_rsp {
 
 struct ib_ip_iocb_rsp {
        u8 opcode;
+#define IB_IP_IOCB_RSP_3032_V   0x80
+#define IB_IP_IOCB_RSP_3032_O   0x40
+#define IB_IP_IOCB_RSP_3032_I   0x20
+#define IB_IP_IOCB_RSP_3032_R   0x10
        u8 flags;
 #define IB_IP_IOCB_RSP_S        0x80
 #define IB_IP_IOCB_RSP_H1       0x40
@@ -230,6 +244,12 @@ struct ib_ip_iocb_rsp {
 
        __le16 length;
        __le16 checksum;
+#define IB_IP_IOCB_RSP_3032_ICE                0x01
+#define IB_IP_IOCB_RSP_3032_CE         0x02
+#define IB_IP_IOCB_RSP_3032_NUC                0x04
+#define IB_IP_IOCB_RSP_3032_UDP                0x08
+#define IB_IP_IOCB_RSP_3032_TCP                0x10
+#define IB_IP_IOCB_RSP_3032_IPE                0x20
        __le16 reserved;
 #define IB_IP_IOCB_RSP_R        0x01
        __le32 ial_low;
@@ -524,6 +544,21 @@ enum {
        IP_ADDR_INDEX_REG_FUNC_2_SEC = 0x0005,
        IP_ADDR_INDEX_REG_FUNC_3_PRI = 0x0006,
        IP_ADDR_INDEX_REG_FUNC_3_SEC = 0x0007,
+       IP_ADDR_INDEX_REG_6 = 0x0008,
+       IP_ADDR_INDEX_REG_OFFSET_MASK = 0x0030,
+       IP_ADDR_INDEX_REG_E = 0x0040, 
+};
+enum {
+       QL3032_PORT_CONTROL_DS = 0x0001,
+       QL3032_PORT_CONTROL_HH = 0x0002,
+       QL3032_PORT_CONTROL_EIv6 = 0x0004,
+       QL3032_PORT_CONTROL_EIv4 = 0x0008,
+       QL3032_PORT_CONTROL_ET = 0x0010,
+       QL3032_PORT_CONTROL_EF = 0x0020,
+       QL3032_PORT_CONTROL_DRM = 0x0040,
+       QL3032_PORT_CONTROL_RLB = 0x0080,
+       QL3032_PORT_CONTROL_RCB = 0x0100,
+       QL3032_PORT_CONTROL_KIE = 0x0200,
 };
 
 enum {
@@ -657,7 +692,8 @@ struct ql3xxx_port_registers {
        u32 internalRamWDataReg;
        u32 reclaimedBufferAddrRegLow;
        u32 reclaimedBufferAddrRegHigh;
-       u32 reserved[2];
+       u32 tcpConfiguration;
+       u32 functionControl;
        u32 fpgaRevID;
        u32 localRamAddr;
        u32 localRamDataAutoIncr;
@@ -963,6 +999,7 @@ struct eeprom_data {
 
 #define QL3XXX_VENDOR_ID    0x1077
 #define QL3022_DEVICE_ID    0x3022
+#define QL3032_DEVICE_ID    0x3032
 
 /* MTU & Frame Size stuff */
 #define NORMAL_MTU_SIZE                ETH_DATA_LEN
@@ -1038,11 +1075,41 @@ struct ql_rcv_buf_cb {
        int index;
 };
 
+/*
+ * Original IOCB has 3 sg entries:
+ * first points to skb-data area
+ * second points to first frag
+ * third points to next oal.
+ * OAL has 5 entries:
+ * 1 thru 4 point to frags
+ * fifth points to next oal.
+ */ 
+#define MAX_OAL_CNT ((MAX_SKB_FRAGS-1)/4 + 1)
+
+struct oal_entry {
+       u32 dma_lo;
+       u32 dma_hi;
+       u32 len;
+#define OAL_LAST_ENTRY   0x80000000    /* Last valid buffer in list. */
+#define OAL_CONT_ENTRY   0x40000000    /* points to an OAL. (continuation) */
+       u32 reserved;
+};
+
+struct oal {
+       struct oal_entry oal_entry[5];
+};
+
+struct map_list {
+        DECLARE_PCI_UNMAP_ADDR(mapaddr);
+        DECLARE_PCI_UNMAP_LEN(maplen);
+};
+
 struct ql_tx_buf_cb {
        struct sk_buff *skb;
        struct ob_mac_iocb_req *queue_entry ;
-        DECLARE_PCI_UNMAP_ADDR(mapaddr);
-        DECLARE_PCI_UNMAP_LEN(maplen);
+       int seg_count;
+       struct oal *oal;
+       struct map_list map[MAX_SKB_FRAGS+1]; 
 };
 
 /* definitions for type field */
@@ -1189,6 +1256,7 @@ struct ql3_adapter {
        struct delayed_work reset_work;
        struct delayed_work tx_timeout_work;
        u32 max_frame_size;
+       u32 device_id;
 };
 
 #endif                         /* _QLA3XXX_H_ */
index a914fef44309bd7a3cec59fe896696951f17907c..0e345cbc2bf918a2f0a55fd0c360ae36905f07e8 100644 (file)
@@ -15,7 +15,7 @@
 
 #define TBD 0
 
-typedef struct _XENA_dev_config {
+struct XENA_dev_config {
 /* Convention: mHAL_XXX is mask, vHAL_XXX is value */
 
 /* General Control-Status Registers */
@@ -300,6 +300,7 @@ typedef struct _XENA_dev_config {
        u64 gpio_control;
 #define GPIO_CTRL_GPIO_0               BIT(8)
        u64 misc_control;
+#define FAULT_BEHAVIOUR                        BIT(0)
 #define EXT_REQ_EN                     BIT(1)
 #define MISC_LINK_STABILITY_PRD(val)   vBIT(val,29,3)
 
@@ -851,9 +852,9 @@ typedef struct _XENA_dev_config {
 #define SPI_CONTROL_DONE               BIT(6)
        u64 spi_data;
 #define SPI_DATA_WRITE(data,len)       vBIT(data,0,len)
-} XENA_dev_config_t;
+};
 
-#define XENA_REG_SPACE sizeof(XENA_dev_config_t)
+#define XENA_REG_SPACE sizeof(struct XENA_dev_config)
 #define        XENA_EEPROM_SPACE (0x01 << 11)
 
 #endif                         /* _REGS_H */
index 1dd66b8ea0fae545e12b70da9e45a7b01c16d79b..639fbc0f16f3f8d8d1832d3bfca7ce436433e784 100644 (file)
@@ -77,7 +77,7 @@
 #include "s2io.h"
 #include "s2io-regs.h"
 
-#define DRV_VERSION "2.0.15.2"
+#define DRV_VERSION "2.0.16.1"
 
 /* S2io Driver name & version. */
 static char s2io_driver_name[] = "Neterion";
@@ -86,7 +86,7 @@ static char s2io_driver_version[] = DRV_VERSION;
 static int rxd_size[4] = {32,48,48,64};
 static int rxd_count[4] = {127,85,85,63};
 
-static inline int RXD_IS_UP2DT(RxD_t *rxdp)
+static inline int RXD_IS_UP2DT(struct RxD_t *rxdp)
 {
        int ret;
 
@@ -111,9 +111,9 @@ static inline int RXD_IS_UP2DT(RxD_t *rxdp)
 #define TASKLET_IN_USE test_and_set_bit(0, (&sp->tasklet_status))
 #define PANIC  1
 #define LOW    2
-static inline int rx_buffer_level(nic_t * sp, int rxb_size, int ring)
+static inline int rx_buffer_level(struct s2io_nic * sp, int rxb_size, int ring)
 {
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
 
        mac_control = &sp->mac_control;
        if (rxb_size <= rxd_count[sp->rxd_mode])
@@ -286,7 +286,7 @@ static char ethtool_stats_keys[][ETH_GSTRING_LEN] = {
 static void s2io_vlan_rx_register(struct net_device *dev,
                                        struct vlan_group *grp)
 {
-       nic_t *nic = dev->priv;
+       struct s2io_nic *nic = dev->priv;
        unsigned long flags;
 
        spin_lock_irqsave(&nic->tx_lock, flags);
@@ -297,7 +297,7 @@ static void s2io_vlan_rx_register(struct net_device *dev,
 /* Unregister the vlan */
 static void s2io_vlan_rx_kill_vid(struct net_device *dev, unsigned long vid)
 {
-       nic_t *nic = dev->priv;
+       struct s2io_nic *nic = dev->priv;
        unsigned long flags;
 
        spin_lock_irqsave(&nic->tx_lock, flags);
@@ -401,9 +401,10 @@ S2IO_PARM_INT(lro, 0);
  * aggregation happens until we hit max IP pkt size(64K)
  */
 S2IO_PARM_INT(lro_max_pkts, 0xFFFF);
-#ifndef CONFIG_S2IO_NAPI
 S2IO_PARM_INT(indicate_max_pkts, 0);
-#endif
+
+S2IO_PARM_INT(napi, 1);
+S2IO_PARM_INT(ufo, 0);
 
 static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
     {DEFAULT_FIFO_0_LEN, [1 ...(MAX_TX_FIFOS - 1)] = DEFAULT_FIFO_1_7_LEN};
@@ -457,14 +458,14 @@ static int init_shared_mem(struct s2io_nic *nic)
        u32 size;
        void *tmp_v_addr, *tmp_v_addr_next;
        dma_addr_t tmp_p_addr, tmp_p_addr_next;
-       RxD_block_t *pre_rxd_blk = NULL;
-       int i, j, blk_cnt, rx_sz, tx_sz;
+       struct RxD_block *pre_rxd_blk = NULL;
+       int i, j, blk_cnt;
        int lst_size, lst_per_page;
        struct net_device *dev = nic->dev;
        unsigned long tmp;
-       buffAdd_t *ba;
+       struct buffAdd *ba;
 
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
 
        mac_control = &nic->mac_control;
@@ -482,13 +483,12 @@ static int init_shared_mem(struct s2io_nic *nic)
                return -EINVAL;
        }
 
-       lst_size = (sizeof(TxD_t) * config->max_txds);
-       tx_sz = lst_size * size;
+       lst_size = (sizeof(struct TxD) * config->max_txds);
        lst_per_page = PAGE_SIZE / lst_size;
 
        for (i = 0; i < config->tx_fifo_num; i++) {
                int fifo_len = config->tx_cfg[i].fifo_len;
-               int list_holder_size = fifo_len * sizeof(list_info_hold_t);
+               int list_holder_size = fifo_len * sizeof(struct list_info_hold);
                mac_control->fifos[i].list_info = kmalloc(list_holder_size,
                                                          GFP_KERNEL);
                if (!mac_control->fifos[i].list_info) {
@@ -579,10 +579,9 @@ static int init_shared_mem(struct s2io_nic *nic)
                        mac_control->rings[i].block_count;
        }
        if (nic->rxd_mode == RXD_MODE_1)
-               size = (size * (sizeof(RxD1_t)));
+               size = (size * (sizeof(struct RxD1)));
        else
-               size = (size * (sizeof(RxD3_t)));
-       rx_sz = size;
+               size = (size * (sizeof(struct RxD3)));
 
        for (i = 0; i < config->rx_ring_num; i++) {
                mac_control->rings[i].rx_curr_get_info.block_index = 0;
@@ -600,7 +599,7 @@ static int init_shared_mem(struct s2io_nic *nic)
                                (rxd_count[nic->rxd_mode] + 1);
                /*  Allocating all the Rx blocks */
                for (j = 0; j < blk_cnt; j++) {
-                       rx_block_info_t *rx_blocks;
+                       struct rx_block_info *rx_blocks;
                        int l;
 
                        rx_blocks = &mac_control->rings[i].rx_blocks[j];
@@ -620,9 +619,11 @@ static int init_shared_mem(struct s2io_nic *nic)
                        memset(tmp_v_addr, 0, size);
                        rx_blocks->block_virt_addr = tmp_v_addr;
                        rx_blocks->block_dma_addr = tmp_p_addr;
-                       rx_blocks->rxds = kmalloc(sizeof(rxd_info_t)*
+                       rx_blocks->rxds = kmalloc(sizeof(struct rxd_info)*
                                                  rxd_count[nic->rxd_mode],
                                                  GFP_KERNEL);
+                       if (!rx_blocks->rxds)
+                               return -ENOMEM;
                        for (l=0; l<rxd_count[nic->rxd_mode];l++) {
                                rx_blocks->rxds[l].virt_addr =
                                        rx_blocks->block_virt_addr +
@@ -645,7 +646,7 @@ static int init_shared_mem(struct s2io_nic *nic)
                                mac_control->rings[i].rx_blocks[(j + 1) %
                                              blk_cnt].block_dma_addr;
 
-                       pre_rxd_blk = (RxD_block_t *) tmp_v_addr;
+                       pre_rxd_blk = (struct RxD_block *) tmp_v_addr;
                        pre_rxd_blk->reserved_2_pNext_RxD_block =
                            (unsigned long) tmp_v_addr_next;
                        pre_rxd_blk->pNext_RxD_Blk_physical =
@@ -661,14 +662,14 @@ static int init_shared_mem(struct s2io_nic *nic)
                        blk_cnt = config->rx_cfg[i].num_rxd /
                           (rxd_count[nic->rxd_mode]+ 1);
                        mac_control->rings[i].ba =
-                               kmalloc((sizeof(buffAdd_t *) * blk_cnt),
+                               kmalloc((sizeof(struct buffAdd *) * blk_cnt),
                                     GFP_KERNEL);
                        if (!mac_control->rings[i].ba)
                                return -ENOMEM;
                        for (j = 0; j < blk_cnt; j++) {
                                int k = 0;
                                mac_control->rings[i].ba[j] =
-                                       kmalloc((sizeof(buffAdd_t) *
+                                       kmalloc((sizeof(struct buffAdd) *
                                                (rxd_count[nic->rxd_mode] + 1)),
                                                GFP_KERNEL);
                                if (!mac_control->rings[i].ba[j])
@@ -700,7 +701,7 @@ static int init_shared_mem(struct s2io_nic *nic)
        }
 
        /* Allocation and initialization of Statistics block */
-       size = sizeof(StatInfo_t);
+       size = sizeof(struct stat_block);
        mac_control->stats_mem = pci_alloc_consistent
            (nic->pdev, size, &mac_control->stats_mem_phy);
 
@@ -715,7 +716,7 @@ static int init_shared_mem(struct s2io_nic *nic)
        mac_control->stats_mem_sz = size;
 
        tmp_v_addr = mac_control->stats_mem;
-       mac_control->stats_info = (StatInfo_t *) tmp_v_addr;
+       mac_control->stats_info = (struct stat_block *) tmp_v_addr;
        memset(tmp_v_addr, 0, size);
        DBG_PRINT(INIT_DBG, "%s:Ring Mem PHY: 0x%llx\n", dev->name,
                  (unsigned long long) tmp_p_addr);
@@ -735,7 +736,7 @@ static void free_shared_mem(struct s2io_nic *nic)
        int i, j, blk_cnt, size;
        void *tmp_v_addr;
        dma_addr_t tmp_p_addr;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
        int lst_size, lst_per_page;
        struct net_device *dev = nic->dev;
@@ -746,7 +747,7 @@ static void free_shared_mem(struct s2io_nic *nic)
        mac_control = &nic->mac_control;
        config = &nic->config;
 
-       lst_size = (sizeof(TxD_t) * config->max_txds);
+       lst_size = (sizeof(struct TxD) * config->max_txds);
        lst_per_page = PAGE_SIZE / lst_size;
 
        for (i = 0; i < config->tx_fifo_num; i++) {
@@ -809,7 +810,7 @@ static void free_shared_mem(struct s2io_nic *nic)
                                if (!mac_control->rings[i].ba[j])
                                        continue;
                                while (k != rxd_count[nic->rxd_mode]) {
-                                       buffAdd_t *ba =
+                                       struct buffAdd *ba =
                                                &mac_control->rings[i].ba[j][k];
                                        kfree(ba->ba_0_org);
                                        kfree(ba->ba_1_org);
@@ -835,9 +836,9 @@ static void free_shared_mem(struct s2io_nic *nic)
  * s2io_verify_pci_mode -
  */
 
-static int s2io_verify_pci_mode(nic_t *nic)
+static int s2io_verify_pci_mode(struct s2io_nic *nic)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        register u64 val64 = 0;
        int     mode;
 
@@ -868,9 +869,9 @@ static int bus_speed[8] = {33, 133, 133, 200, 266, 133, 200, 266};
 /**
  * s2io_print_pci_mode -
  */
-static int s2io_print_pci_mode(nic_t *nic)
+static int s2io_print_pci_mode(struct s2io_nic *nic)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        register u64 val64 = 0;
        int     mode;
        struct config_param *config = &nic->config;
@@ -938,13 +939,13 @@ static int s2io_print_pci_mode(nic_t *nic)
 
 static int init_nic(struct s2io_nic *nic)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        struct net_device *dev = nic->dev;
        register u64 val64 = 0;
        void __iomem *add;
        u32 time;
        int i, j;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
        int dtx_cnt = 0;
        unsigned long long mem_share;
@@ -1414,7 +1415,7 @@ static int init_nic(struct s2io_nic *nic)
 
        val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
            TTI_DATA2_MEM_TX_UFC_B(0x20) |
-           TTI_DATA2_MEM_TX_UFC_C(0x70) | TTI_DATA2_MEM_TX_UFC_D(0x80);
+           TTI_DATA2_MEM_TX_UFC_C(0x40) | TTI_DATA2_MEM_TX_UFC_D(0x80);
        writeq(val64, &bar0->tti_data2_mem);
 
        val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD;
@@ -1610,7 +1611,8 @@ static int init_nic(struct s2io_nic *nic)
         * that does not start on an ADB to reduce disconnects.
         */
        if (nic->device_type == XFRAME_II_DEVICE) {
-               val64 = EXT_REQ_EN | MISC_LINK_STABILITY_PRD(3);
+               val64 = FAULT_BEHAVIOUR | EXT_REQ_EN |
+                       MISC_LINK_STABILITY_PRD(3);
                writeq(val64, &bar0->misc_control);
                val64 = readq(&bar0->pic_control2);
                val64 &= ~(BIT(13)|BIT(14)|BIT(15));
@@ -1626,7 +1628,7 @@ static int init_nic(struct s2io_nic *nic)
 #define LINK_UP_DOWN_INTERRUPT         1
 #define MAC_RMAC_ERR_TIMER             2
 
-static int s2io_link_fault_indication(nic_t *nic)
+static int s2io_link_fault_indication(struct s2io_nic *nic)
 {
        if (nic->intr_type != INTA)
                return MAC_RMAC_ERR_TIMER;
@@ -1649,14 +1651,14 @@ static int s2io_link_fault_indication(nic_t *nic)
 
 static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        register u64 val64 = 0, temp64 = 0;
 
        /*  Top level interrupt classification */
        /*  PIC Interrupts */
        if ((mask & (TX_PIC_INTR | RX_PIC_INTR))) {
                /*  Enable PIC Intrs in the general intr mask register */
-               val64 = TXPIC_INT_M | PIC_RX_INT_M;
+               val64 = TXPIC_INT_M;
                if (flag == ENABLE_INTRS) {
                        temp64 = readq(&bar0->general_int_mask);
                        temp64 &= ~((u64) val64);
@@ -1694,70 +1696,6 @@ static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
                }
        }
 
-       /*  DMA Interrupts */
-       /*  Enabling/Disabling Tx DMA interrupts */
-       if (mask & TX_DMA_INTR) {
-               /* Enable TxDMA Intrs in the general intr mask register */
-               val64 = TXDMA_INT_M;
-               if (flag == ENABLE_INTRS) {
-                       temp64 = readq(&bar0->general_int_mask);
-                       temp64 &= ~((u64) val64);
-                       writeq(temp64, &bar0->general_int_mask);
-                       /*
-                        * Keep all interrupts other than PFC interrupt
-                        * and PCC interrupt disabled in DMA level.
-                        */
-                       val64 = DISABLE_ALL_INTRS & ~(TXDMA_PFC_INT_M |
-                                                     TXDMA_PCC_INT_M);
-                       writeq(val64, &bar0->txdma_int_mask);
-                       /*
-                        * Enable only the MISC error 1 interrupt in PFC block
-                        */
-                       val64 = DISABLE_ALL_INTRS & (~PFC_MISC_ERR_1);
-                       writeq(val64, &bar0->pfc_err_mask);
-                       /*
-                        * Enable only the FB_ECC error interrupt in PCC block
-                        */
-                       val64 = DISABLE_ALL_INTRS & (~PCC_FB_ECC_ERR);
-                       writeq(val64, &bar0->pcc_err_mask);
-               } else if (flag == DISABLE_INTRS) {
-                       /*
-                        * Disable TxDMA Intrs in the general intr mask
-                        * register
-                        */
-                       writeq(DISABLE_ALL_INTRS, &bar0->txdma_int_mask);
-                       writeq(DISABLE_ALL_INTRS, &bar0->pfc_err_mask);
-                       temp64 = readq(&bar0->general_int_mask);
-                       val64 |= temp64;
-                       writeq(val64, &bar0->general_int_mask);
-               }
-       }
-
-       /*  Enabling/Disabling Rx DMA interrupts */
-       if (mask & RX_DMA_INTR) {
-               /*  Enable RxDMA Intrs in the general intr mask register */
-               val64 = RXDMA_INT_M;
-               if (flag == ENABLE_INTRS) {
-                       temp64 = readq(&bar0->general_int_mask);
-                       temp64 &= ~((u64) val64);
-                       writeq(temp64, &bar0->general_int_mask);
-                       /*
-                        * All RxDMA block interrupts are disabled for now
-                        * TODO
-                        */
-                       writeq(DISABLE_ALL_INTRS, &bar0->rxdma_int_mask);
-               } else if (flag == DISABLE_INTRS) {
-                       /*
-                        * Disable RxDMA Intrs in the general intr mask
-                        * register
-                        */
-                       writeq(DISABLE_ALL_INTRS, &bar0->rxdma_int_mask);
-                       temp64 = readq(&bar0->general_int_mask);
-                       val64 |= temp64;
-                       writeq(val64, &bar0->general_int_mask);
-               }
-       }
-
        /*  MAC Interrupts */
        /*  Enabling/Disabling MAC interrupts */
        if (mask & (TX_MAC_INTR | RX_MAC_INTR)) {
@@ -1784,53 +1722,6 @@ static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
                }
        }
 
-       /*  XGXS Interrupts */
-       if (mask & (TX_XGXS_INTR | RX_XGXS_INTR)) {
-               val64 = TXXGXS_INT_M | RXXGXS_INT_M;
-               if (flag == ENABLE_INTRS) {
-                       temp64 = readq(&bar0->general_int_mask);
-                       temp64 &= ~((u64) val64);
-                       writeq(temp64, &bar0->general_int_mask);
-                       /*
-                        * All XGXS block error interrupts are disabled for now
-                        * TODO
-                        */
-                       writeq(DISABLE_ALL_INTRS, &bar0->xgxs_int_mask);
-               } else if (flag == DISABLE_INTRS) {
-                       /*
-                        * Disable MC Intrs in the general intr mask register
-                        */
-                       writeq(DISABLE_ALL_INTRS, &bar0->xgxs_int_mask);
-                       temp64 = readq(&bar0->general_int_mask);
-                       val64 |= temp64;
-                       writeq(val64, &bar0->general_int_mask);
-               }
-       }
-
-       /*  Memory Controller(MC) interrupts */
-       if (mask & MC_INTR) {
-               val64 = MC_INT_M;
-               if (flag == ENABLE_INTRS) {
-                       temp64 = readq(&bar0->general_int_mask);
-                       temp64 &= ~((u64) val64);
-                       writeq(temp64, &bar0->general_int_mask);
-                       /*
-                        * Enable all MC Intrs.
-                        */
-                       writeq(0x0, &bar0->mc_int_mask);
-                       writeq(0x0, &bar0->mc_err_mask);
-               } else if (flag == DISABLE_INTRS) {
-                       /*
-                        * Disable MC Intrs in the general intr mask register
-                        */
-                       writeq(DISABLE_ALL_INTRS, &bar0->mc_int_mask);
-                       temp64 = readq(&bar0->general_int_mask);
-                       val64 |= temp64;
-                       writeq(val64, &bar0->general_int_mask);
-               }
-       }
-
-
        /*  Tx traffic interrupts */
        if (mask & TX_TRAFFIC_INTR) {
                val64 = TXTRAFFIC_INT_M;
@@ -1877,41 +1768,36 @@ static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
        }
 }
 
-static int check_prc_pcc_state(u64 val64, int flag, int rev_id, int herc)
+/**
+ *  verify_pcc_quiescent- Checks for PCC quiescent state
+ *  Return: 1 If PCC is quiescence
+ *          0 If PCC is not quiescence
+ */
+static int verify_pcc_quiescent(struct s2io_nic *sp, int flag)
 {
-       int ret = 0;
+       int ret = 0, herc;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
+       u64 val64 = readq(&bar0->adapter_status);
+       
+       herc = (sp->device_type == XFRAME_II_DEVICE);
 
        if (flag == FALSE) {
-               if ((!herc && (rev_id >= 4)) || herc) {
-                       if (!(val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) &&
-                           ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
-                            ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
+               if ((!herc && (get_xena_rev_id(sp->pdev) >= 4)) || herc) {
+                       if (!(val64 & ADAPTER_STATUS_RMAC_PCC_IDLE))
                                ret = 1;
-                       }
-               }else {
-                       if (!(val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) &&
-                           ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
-                            ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
+               } else {
+                       if (!(val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE))
                                ret = 1;
-                       }
                }
        } else {
-               if ((!herc && (rev_id >= 4)) || herc) {
+               if ((!herc && (get_xena_rev_id(sp->pdev) >= 4)) || herc) {
                        if (((val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) ==
-                            ADAPTER_STATUS_RMAC_PCC_IDLE) &&
-                           (!(val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ||
-                            ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
-                             ADAPTER_STATUS_RC_PRC_QUIESCENT))) {
+                            ADAPTER_STATUS_RMAC_PCC_IDLE))
                                ret = 1;
-                       }
                } else {
                        if (((val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) ==
-                            ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) &&
-                           (!(val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ||
-                            ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
-                             ADAPTER_STATUS_RC_PRC_QUIESCENT))) {
+                            ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE))
                                ret = 1;
-                       }
                }
        }
 
@@ -1919,9 +1805,6 @@ static int check_prc_pcc_state(u64 val64, int flag, int rev_id, int herc)
 }
 /**
  *  verify_xena_quiescence - Checks whether the H/W is ready
- *  @val64 :  Value read from adapter status register.
- *  @flag : indicates if the adapter enable bit was ever written once
- *  before.
  *  Description: Returns whether the H/W is ready to go or not. Depending
  *  on whether adapter enable bit was written or not the comparison
  *  differs and the calling function passes the input argument flag to
@@ -1930,24 +1813,63 @@ static int check_prc_pcc_state(u64 val64, int flag, int rev_id, int herc)
  *          0 If Xena is not quiescence
  */
 
-static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag)
+static int verify_xena_quiescence(struct s2io_nic *sp)
 {
-       int ret = 0, herc;
-       u64 tmp64 = ~((u64) val64);
-       int rev_id = get_xena_rev_id(sp->pdev);
+       int  mode;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
+       u64 val64 = readq(&bar0->adapter_status);
+       mode = s2io_verify_pci_mode(sp);
 
-       herc = (sp->device_type == XFRAME_II_DEVICE);
-       if (!
-           (tmp64 &
-            (ADAPTER_STATUS_TDMA_READY | ADAPTER_STATUS_RDMA_READY |
-             ADAPTER_STATUS_PFC_READY | ADAPTER_STATUS_TMAC_BUF_EMPTY |
-             ADAPTER_STATUS_PIC_QUIESCENT | ADAPTER_STATUS_MC_DRAM_READY |
-             ADAPTER_STATUS_MC_QUEUES_READY | ADAPTER_STATUS_M_PLL_LOCK |
-             ADAPTER_STATUS_P_PLL_LOCK))) {
-               ret = check_prc_pcc_state(val64, flag, rev_id, herc);
+       if (!(val64 & ADAPTER_STATUS_TDMA_READY)) {
+               DBG_PRINT(ERR_DBG, "%s", "TDMA is not ready!");
+               return 0;
+       }
+       if (!(val64 & ADAPTER_STATUS_RDMA_READY)) {
+       DBG_PRINT(ERR_DBG, "%s", "RDMA is not ready!");
+               return 0;
+       }
+       if (!(val64 & ADAPTER_STATUS_PFC_READY)) {
+               DBG_PRINT(ERR_DBG, "%s", "PFC is not ready!");
+               return 0;
+       }
+       if (!(val64 & ADAPTER_STATUS_TMAC_BUF_EMPTY)) {
+               DBG_PRINT(ERR_DBG, "%s", "TMAC BUF is not empty!");
+               return 0;
+       }
+       if (!(val64 & ADAPTER_STATUS_PIC_QUIESCENT)) {
+               DBG_PRINT(ERR_DBG, "%s", "PIC is not QUIESCENT!");
+               return 0;
+       }
+       if (!(val64 & ADAPTER_STATUS_MC_DRAM_READY)) {
+               DBG_PRINT(ERR_DBG, "%s", "MC_DRAM is not ready!");
+               return 0;
+       }
+       if (!(val64 & ADAPTER_STATUS_MC_QUEUES_READY)) {
+               DBG_PRINT(ERR_DBG, "%s", "MC_QUEUES is not ready!");
+               return 0;
+       }
+       if (!(val64 & ADAPTER_STATUS_M_PLL_LOCK)) {
+               DBG_PRINT(ERR_DBG, "%s", "M_PLL is not locked!");
+               return 0;
        }
 
-       return ret;
+       /*
+        * In PCI 33 mode, the P_PLL is not used, and therefore,
+        * the the P_PLL_LOCK bit in the adapter_status register will
+        * not be asserted.
+        */
+       if (!(val64 & ADAPTER_STATUS_P_PLL_LOCK) &&
+               sp->device_type == XFRAME_II_DEVICE && mode !=
+               PCI_MODE_PCI_33) {
+               DBG_PRINT(ERR_DBG, "%s", "P_PLL is not locked!");
+               return 0;
+       }
+       if (!((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
+                       ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
+               DBG_PRINT(ERR_DBG, "%s", "RC_PRC is not QUIESCENT!");
+               return 0;
+       }
+       return 1;
 }
 
 /**
@@ -1958,9 +1880,9 @@ static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag)
  *
  */
 
-static void fix_mac_address(nic_t * sp)
+static void fix_mac_address(struct s2io_nic * sp)
 {
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u64 val64;
        int i = 0;
 
@@ -1986,11 +1908,11 @@ static void fix_mac_address(nic_t * sp)
 
 static int start_nic(struct s2io_nic *nic)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        struct net_device *dev = nic->dev;
        register u64 val64 = 0;
        u16 subid, i;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
 
        mac_control = &nic->mac_control;
@@ -2052,7 +1974,7 @@ static int start_nic(struct s2io_nic *nic)
         * it.
         */
        val64 = readq(&bar0->adapter_status);
-       if (!verify_xena_quiescence(nic, val64, nic->device_enabled_once)) {
+       if (!verify_xena_quiescence(nic)) {
                DBG_PRINT(ERR_DBG, "%s: device is not ready, ", dev->name);
                DBG_PRINT(ERR_DBG, "Adapter status reads: 0x%llx\n",
                          (unsigned long long) val64);
@@ -2095,11 +2017,12 @@ static int start_nic(struct s2io_nic *nic)
 /**
  * s2io_txdl_getskb - Get the skb from txdl, unmap and return skb
  */
-static struct sk_buff *s2io_txdl_getskb(fifo_info_t *fifo_data, TxD_t *txdlp, int get_off)
+static struct sk_buff *s2io_txdl_getskb(struct fifo_info *fifo_data, struct \
+                                       TxD *txdlp, int get_off)
 {
-       nic_t *nic = fifo_data->nic;
+       struct s2io_nic *nic = fifo_data->nic;
        struct sk_buff *skb;
-       TxD_t *txds;
+       struct TxD *txds;
        u16 j, frg_cnt;
 
        txds = txdlp;
@@ -2113,7 +2036,7 @@ static struct sk_buff *s2io_txdl_getskb(fifo_info_t *fifo_data, TxD_t *txdlp, in
        skb = (struct sk_buff *) ((unsigned long)
                        txds->Host_Control);
        if (!skb) {
-               memset(txdlp, 0, (sizeof(TxD_t) * fifo_data->max_txds));
+               memset(txdlp, 0, (sizeof(struct TxD) * fifo_data->max_txds));
                return NULL;
        }
        pci_unmap_single(nic->pdev, (dma_addr_t)
@@ -2132,7 +2055,7 @@ static struct sk_buff *s2io_txdl_getskb(fifo_info_t *fifo_data, TxD_t *txdlp, in
                                       frag->size, PCI_DMA_TODEVICE);
                }
        }
-       memset(txdlp,0, (sizeof(TxD_t) * fifo_data->max_txds));
+       memset(txdlp,0, (sizeof(struct TxD) * fifo_data->max_txds));
        return(skb);
 }
 
@@ -2148,9 +2071,9 @@ static void free_tx_buffers(struct s2io_nic *nic)
 {
        struct net_device *dev = nic->dev;
        struct sk_buff *skb;
-       TxD_t *txdp;
+       struct TxD *txdp;
        int i, j;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
        int cnt = 0;
 
@@ -2159,7 +2082,7 @@ static void free_tx_buffers(struct s2io_nic *nic)
 
        for (i = 0; i < config->tx_fifo_num; i++) {
                for (j = 0; j < config->tx_cfg[i].fifo_len - 1; j++) {
-                       txdp = (TxD_t *) mac_control->fifos[i].list_info[j].
+                       txdp = (struct TxD *) mac_control->fifos[i].list_info[j].
                            list_virt_addr;
                        skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j);
                        if (skb) {
@@ -2187,10 +2110,10 @@ static void free_tx_buffers(struct s2io_nic *nic)
 
 static void stop_nic(struct s2io_nic *nic)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        register u64 val64 = 0;
        u16 interruptible;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
 
        mac_control = &nic->mac_control;
@@ -2208,14 +2131,15 @@ static void stop_nic(struct s2io_nic *nic)
        writeq(val64, &bar0->adapter_control);
 }
 
-static int fill_rxd_3buf(nic_t *nic, RxD_t *rxdp, struct sk_buff *skb)
+static int fill_rxd_3buf(struct s2io_nic *nic, struct RxD_t *rxdp, struct \
+                               sk_buff *skb)
 {
        struct net_device *dev = nic->dev;
        struct sk_buff *frag_list;
        void *tmp;
 
        /* Buffer-1 receives L3/L4 headers */
-       ((RxD3_t*)rxdp)->Buffer1_ptr = pci_map_single
+       ((struct RxD3*)rxdp)->Buffer1_ptr = pci_map_single
                        (nic->pdev, skb->data, l3l4hdr_size + 4,
                        PCI_DMA_FROMDEVICE);
 
@@ -2226,13 +2150,14 @@ static int fill_rxd_3buf(nic_t *nic, RxD_t *rxdp, struct sk_buff *skb)
                return -ENOMEM ;
        }
        frag_list = skb_shinfo(skb)->frag_list;
+       skb->truesize += frag_list->truesize;
        frag_list->next = NULL;
        tmp = (void *)ALIGN((long)frag_list->data, ALIGN_SIZE + 1);
        frag_list->data = tmp;
        frag_list->tail = tmp;
 
        /* Buffer-2 receives L4 data payload */
-       ((RxD3_t*)rxdp)->Buffer2_ptr = pci_map_single(nic->pdev,
+       ((struct RxD3*)rxdp)->Buffer2_ptr = pci_map_single(nic->pdev,
                                frag_list->data, dev->mtu,
                                PCI_DMA_FROMDEVICE);
        rxdp->Control_2 |= SET_BUFFER1_SIZE_3(l3l4hdr_size + 4);
@@ -2266,18 +2191,16 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
 {
        struct net_device *dev = nic->dev;
        struct sk_buff *skb;
-       RxD_t *rxdp;
+       struct RxD_t *rxdp;
        int off, off1, size, block_no, block_no1;
        u32 alloc_tab = 0;
        u32 alloc_cnt;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
        u64 tmp;
-       buffAdd_t *ba;
-#ifndef CONFIG_S2IO_NAPI
+       struct buffAdd *ba;
        unsigned long flags;
-#endif
-       RxD_t *first_rxdp = NULL;
+       struct RxD_t *first_rxdp = NULL;
 
        mac_control = &nic->mac_control;
        config = &nic->config;
@@ -2320,12 +2243,15 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
                        DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
                                  dev->name, rxdp);
                }
-#ifndef CONFIG_S2IO_NAPI
-               spin_lock_irqsave(&nic->put_lock, flags);
-               mac_control->rings[ring_no].put_pos =
-                   (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
-               spin_unlock_irqrestore(&nic->put_lock, flags);
-#endif
+               if(!napi) {
+                       spin_lock_irqsave(&nic->put_lock, flags);
+                       mac_control->rings[ring_no].put_pos =
+                       (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
+                       spin_unlock_irqrestore(&nic->put_lock, flags);
+               } else {
+                       mac_control->rings[ring_no].put_pos =
+                       (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
+               }
                if ((rxdp->Control_1 & RXD_OWN_XENA) &&
                        ((nic->rxd_mode >= RXD_MODE_3A) &&
                                (rxdp->Control_2 & BIT(0)))) {
@@ -2356,9 +2282,9 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
                }
                if (nic->rxd_mode == RXD_MODE_1) {
                        /* 1 buffer mode - normal operation mode */
-                       memset(rxdp, 0, sizeof(RxD1_t));
+                       memset(rxdp, 0, sizeof(struct RxD1));
                        skb_reserve(skb, NET_IP_ALIGN);
-                       ((RxD1_t*)rxdp)->Buffer0_ptr = pci_map_single
+                       ((struct RxD1*)rxdp)->Buffer0_ptr = pci_map_single
                            (nic->pdev, skb->data, size - NET_IP_ALIGN,
                                PCI_DMA_FROMDEVICE);
                        rxdp->Control_2 = SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN);
@@ -2375,7 +2301,7 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
                         * payload
                         */
 
-                       memset(rxdp, 0, sizeof(RxD3_t));
+                       memset(rxdp, 0, sizeof(struct RxD3));
                        ba = &mac_control->rings[ring_no].ba[block_no][off];
                        skb_reserve(skb, BUF0_LEN);
                        tmp = (u64)(unsigned long) skb->data;
@@ -2384,13 +2310,13 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
                        skb->data = (void *) (unsigned long)tmp;
                        skb->tail = (void *) (unsigned long)tmp;
 
-                       if (!(((RxD3_t*)rxdp)->Buffer0_ptr))
-                               ((RxD3_t*)rxdp)->Buffer0_ptr =
+                       if (!(((struct RxD3*)rxdp)->Buffer0_ptr))
+                               ((struct RxD3*)rxdp)->Buffer0_ptr =
                                   pci_map_single(nic->pdev, ba->ba_0, BUF0_LEN,
                                           PCI_DMA_FROMDEVICE);
                        else
                                pci_dma_sync_single_for_device(nic->pdev,
-                                   (dma_addr_t) ((RxD3_t*)rxdp)->Buffer0_ptr,
+                                   (dma_addr_t) ((struct RxD3*)rxdp)->Buffer0_ptr,
                                    BUF0_LEN, PCI_DMA_FROMDEVICE);
                        rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
                        if (nic->rxd_mode == RXD_MODE_3B) {
@@ -2400,13 +2326,13 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
                                 * Buffer2 will have L3/L4 header plus
                                 * L4 payload
                                 */
-                               ((RxD3_t*)rxdp)->Buffer2_ptr = pci_map_single
+                               ((struct RxD3*)rxdp)->Buffer2_ptr = pci_map_single
                                (nic->pdev, skb->data, dev->mtu + 4,
                                                PCI_DMA_FROMDEVICE);
 
                                /* Buffer-1 will be dummy buffer. Not used */
-                               if (!(((RxD3_t*)rxdp)->Buffer1_ptr)) {
-                                       ((RxD3_t*)rxdp)->Buffer1_ptr =
+                               if (!(((struct RxD3*)rxdp)->Buffer1_ptr)) {
+                                       ((struct RxD3*)rxdp)->Buffer1_ptr =
                                                pci_map_single(nic->pdev,
                                                ba->ba_1, BUF1_LEN,
                                                PCI_DMA_FROMDEVICE);
@@ -2466,9 +2392,9 @@ static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
        struct net_device *dev = sp->dev;
        int j;
        struct sk_buff *skb;
-       RxD_t *rxdp;
-       mac_info_t *mac_control;
-       buffAdd_t *ba;
+       struct RxD_t *rxdp;
+       struct mac_info *mac_control;
+       struct buffAdd *ba;
 
        mac_control = &sp->mac_control;
        for (j = 0 ; j < rxd_count[sp->rxd_mode]; j++) {
@@ -2481,41 +2407,41 @@ static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
                }
                if (sp->rxd_mode == RXD_MODE_1) {
                        pci_unmap_single(sp->pdev, (dma_addr_t)
-                                ((RxD1_t*)rxdp)->Buffer0_ptr,
+                                ((struct RxD1*)rxdp)->Buffer0_ptr,
                                 dev->mtu +
                                 HEADER_ETHERNET_II_802_3_SIZE
                                 + HEADER_802_2_SIZE +
                                 HEADER_SNAP_SIZE,
                                 PCI_DMA_FROMDEVICE);
-                       memset(rxdp, 0, sizeof(RxD1_t));
+                       memset(rxdp, 0, sizeof(struct RxD1));
                } else if(sp->rxd_mode == RXD_MODE_3B) {
                        ba = &mac_control->rings[ring_no].
                                ba[blk][j];
                        pci_unmap_single(sp->pdev, (dma_addr_t)
-                                ((RxD3_t*)rxdp)->Buffer0_ptr,
+                                ((struct RxD3*)rxdp)->Buffer0_ptr,
                                 BUF0_LEN,
                                 PCI_DMA_FROMDEVICE);
                        pci_unmap_single(sp->pdev, (dma_addr_t)
-                                ((RxD3_t*)rxdp)->Buffer1_ptr,
+                                ((struct RxD3*)rxdp)->Buffer1_ptr,
                                 BUF1_LEN,
                                 PCI_DMA_FROMDEVICE);
                        pci_unmap_single(sp->pdev, (dma_addr_t)
-                                ((RxD3_t*)rxdp)->Buffer2_ptr,
+                                ((struct RxD3*)rxdp)->Buffer2_ptr,
                                 dev->mtu + 4,
                                 PCI_DMA_FROMDEVICE);
-                       memset(rxdp, 0, sizeof(RxD3_t));
+                       memset(rxdp, 0, sizeof(struct RxD3));
                } else {
                        pci_unmap_single(sp->pdev, (dma_addr_t)
-                               ((RxD3_t*)rxdp)->Buffer0_ptr, BUF0_LEN,
+                               ((struct RxD3*)rxdp)->Buffer0_ptr, BUF0_LEN,
                                PCI_DMA_FROMDEVICE);
                        pci_unmap_single(sp->pdev, (dma_addr_t)
-                               ((RxD3_t*)rxdp)->Buffer1_ptr,
+                               ((struct RxD3*)rxdp)->Buffer1_ptr,
                                l3l4hdr_size + 4,
                                PCI_DMA_FROMDEVICE);
                        pci_unmap_single(sp->pdev, (dma_addr_t)
-                               ((RxD3_t*)rxdp)->Buffer2_ptr, dev->mtu,
+                               ((struct RxD3*)rxdp)->Buffer2_ptr, dev->mtu,
                                PCI_DMA_FROMDEVICE);
-                       memset(rxdp, 0, sizeof(RxD3_t));
+                       memset(rxdp, 0, sizeof(struct RxD3));
                }
                dev_kfree_skb(skb);
                atomic_dec(&sp->rx_bufs_left[ring_no]);
@@ -2535,7 +2461,7 @@ static void free_rx_buffers(struct s2io_nic *sp)
 {
        struct net_device *dev = sp->dev;
        int i, blk = 0, buf_cnt = 0;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
 
        mac_control = &sp->mac_control;
@@ -2568,15 +2494,13 @@ static void free_rx_buffers(struct s2io_nic *sp)
  * 0 on success and 1 if there are No Rx packets to be processed.
  */
 
-#if defined(CONFIG_S2IO_NAPI)
 static int s2io_poll(struct net_device *dev, int *budget)
 {
-       nic_t *nic = dev->priv;
+       struct s2io_nic *nic = dev->priv;
        int pkt_cnt = 0, org_pkts_to_process;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
-       u64 val64 = 0xFFFFFFFFFFFFFFFFULL;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        int i;
 
        atomic_inc(&nic->isr_cnt);
@@ -2588,8 +2512,8 @@ static int s2io_poll(struct net_device *dev, int *budget)
                nic->pkts_to_process = dev->quota;
        org_pkts_to_process = nic->pkts_to_process;
 
-       writeq(val64, &bar0->rx_traffic_int);
-       val64 = readl(&bar0->rx_traffic_int);
+       writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
+       readl(&bar0->rx_traffic_int);
 
        for (i = 0; i < config->rx_ring_num; i++) {
                rx_intr_handler(&mac_control->rings[i]);
@@ -2615,7 +2539,7 @@ static int s2io_poll(struct net_device *dev, int *budget)
        }
        /* Re enable the Rx interrupts. */
        writeq(0x0, &bar0->rx_traffic_mask);
-       val64 = readl(&bar0->rx_traffic_mask);
+       readl(&bar0->rx_traffic_mask);
        atomic_dec(&nic->isr_cnt);
        return 0;
 
@@ -2633,7 +2557,6 @@ no_rx:
        atomic_dec(&nic->isr_cnt);
        return 1;
 }
-#endif
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
 /**
@@ -2647,10 +2570,10 @@ no_rx:
  */
 static void s2io_netpoll(struct net_device *dev)
 {
-       nic_t *nic = dev->priv;
-       mac_info_t *mac_control;
+       struct s2io_nic *nic = dev->priv;
+       struct mac_info *mac_control;
        struct config_param *config;
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        u64 val64 = 0xFFFFFFFFFFFFFFFFULL;
        int i;
 
@@ -2699,17 +2622,15 @@ static void s2io_netpoll(struct net_device *dev)
  *  Return Value:
  *  NONE.
  */
-static void rx_intr_handler(ring_info_t *ring_data)
+static void rx_intr_handler(struct ring_info *ring_data)
 {
-       nic_t *nic = ring_data->nic;
+       struct s2io_nic *nic = ring_data->nic;
        struct net_device *dev = (struct net_device *) nic->dev;
        int get_block, put_block, put_offset;
-       rx_curr_get_info_t get_info, put_info;
-       RxD_t *rxdp;
+       struct rx_curr_get_info get_info, put_info;
+       struct RxD_t *rxdp;
        struct sk_buff *skb;
-#ifndef CONFIG_S2IO_NAPI
        int pkt_cnt = 0;
-#endif
        int i;
 
        spin_lock(&nic->rx_lock);
@@ -2722,19 +2643,21 @@ static void rx_intr_handler(ring_info_t *ring_data)
 
        get_info = ring_data->rx_curr_get_info;
        get_block = get_info.block_index;
-       put_info = ring_data->rx_curr_put_info;
+       memcpy(&put_info, &ring_data->rx_curr_put_info, sizeof(put_info));
        put_block = put_info.block_index;
        rxdp = ring_data->rx_blocks[get_block].rxds[get_info.offset].virt_addr;
-#ifndef CONFIG_S2IO_NAPI
-       spin_lock(&nic->put_lock);
-       put_offset = ring_data->put_pos;
-       spin_unlock(&nic->put_lock);
-#else
-       put_offset = (put_block * (rxd_count[nic->rxd_mode] + 1)) +
-               put_info.offset;
-#endif
+       if (!napi) {
+               spin_lock(&nic->put_lock);
+               put_offset = ring_data->put_pos;
+               spin_unlock(&nic->put_lock);
+       } else
+               put_offset = ring_data->put_pos;
+
        while (RXD_IS_UP2DT(rxdp)) {
-               /* If your are next to put index then it's FIFO full condition */
+               /*
+                * If your are next to put index then it's
+                * FIFO full condition
+                */
                if ((get_block == put_block) &&
                    (get_info.offset + 1) == put_info.offset) {
                        DBG_PRINT(INTR_DBG, "%s: Ring Full\n",dev->name);
@@ -2750,7 +2673,7 @@ static void rx_intr_handler(ring_info_t *ring_data)
                }
                if (nic->rxd_mode == RXD_MODE_1) {
                        pci_unmap_single(nic->pdev, (dma_addr_t)
-                                ((RxD1_t*)rxdp)->Buffer0_ptr,
+                                ((struct RxD1*)rxdp)->Buffer0_ptr,
                                 dev->mtu +
                                 HEADER_ETHERNET_II_802_3_SIZE +
                                 HEADER_802_2_SIZE +
@@ -2758,22 +2681,22 @@ static void rx_intr_handler(ring_info_t *ring_data)
                                 PCI_DMA_FROMDEVICE);
                } else if (nic->rxd_mode == RXD_MODE_3B) {
                        pci_dma_sync_single_for_cpu(nic->pdev, (dma_addr_t)
-                                ((RxD3_t*)rxdp)->Buffer0_ptr,
+                                ((struct RxD3*)rxdp)->Buffer0_ptr,
                                 BUF0_LEN, PCI_DMA_FROMDEVICE);
                        pci_unmap_single(nic->pdev, (dma_addr_t)
-                                ((RxD3_t*)rxdp)->Buffer2_ptr,
+                                ((struct RxD3*)rxdp)->Buffer2_ptr,
                                 dev->mtu + 4,
                                 PCI_DMA_FROMDEVICE);
                } else {
                        pci_dma_sync_single_for_cpu(nic->pdev, (dma_addr_t)
-                                        ((RxD3_t*)rxdp)->Buffer0_ptr, BUF0_LEN,
+                                        ((struct RxD3*)rxdp)->Buffer0_ptr, BUF0_LEN,
                                         PCI_DMA_FROMDEVICE);
                        pci_unmap_single(nic->pdev, (dma_addr_t)
-                                        ((RxD3_t*)rxdp)->Buffer1_ptr,
+                                        ((struct RxD3*)rxdp)->Buffer1_ptr,
                                         l3l4hdr_size + 4,
                                         PCI_DMA_FROMDEVICE);
                        pci_unmap_single(nic->pdev, (dma_addr_t)
-                                        ((RxD3_t*)rxdp)->Buffer2_ptr,
+                                        ((struct RxD3*)rxdp)->Buffer2_ptr,
                                         dev->mtu, PCI_DMA_FROMDEVICE);
                }
                prefetch(skb->data);
@@ -2792,20 +2715,17 @@ static void rx_intr_handler(ring_info_t *ring_data)
                        rxdp = ring_data->rx_blocks[get_block].block_virt_addr;
                }
 
-#ifdef CONFIG_S2IO_NAPI
                nic->pkts_to_process -= 1;
-               if (!nic->pkts_to_process)
+               if ((napi) && (!nic->pkts_to_process))
                        break;
-#else
                pkt_cnt++;
                if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts))
                        break;
-#endif
        }
        if (nic->lro) {
                /* Clear all LRO sessions before exiting */
                for (i=0; i<MAX_LRO_SESSIONS; i++) {
-                       lro_t *lro = &nic->lro0_n[i];
+                       struct lro *lro = &nic->lro0_n[i];
                        if (lro->in_use) {
                                update_L3L4_header(nic, lro);
                                queue_rx_frame(lro->parent);
@@ -2829,17 +2749,17 @@ static void rx_intr_handler(ring_info_t *ring_data)
  *  NONE
  */
 
-static void tx_intr_handler(fifo_info_t *fifo_data)
+static void tx_intr_handler(struct fifo_info *fifo_data)
 {
-       nic_t *nic = fifo_data->nic;
+       struct s2io_nic *nic = fifo_data->nic;
        struct net_device *dev = (struct net_device *) nic->dev;
-       tx_curr_get_info_t get_info, put_info;
+       struct tx_curr_get_info get_info, put_info;
        struct sk_buff *skb;
-       TxD_t *txdlp;
+       struct TxD *txdlp;
 
        get_info = fifo_data->tx_curr_get_info;
-       put_info = fifo_data->tx_curr_put_info;
-       txdlp = (TxD_t *) fifo_data->list_info[get_info.offset].
+       memcpy(&put_info, &fifo_data->tx_curr_put_info, sizeof(put_info));
+       txdlp = (struct TxD *) fifo_data->list_info[get_info.offset].
            list_virt_addr;
        while ((!(txdlp->Control_1 & TXD_LIST_OWN_XENA)) &&
               (get_info.offset != put_info.offset) &&
@@ -2854,11 +2774,10 @@ static void tx_intr_handler(fifo_info_t *fifo_data)
                        }
                        if ((err >> 48) == 0xA) {
                                DBG_PRINT(TX_DBG, "TxD returned due \
-to loss of link\n");
+                                               to loss of link\n");
                        }
                        else {
-                               DBG_PRINT(ERR_DBG, "***TxD error \
-%llx\n", err);
+                               DBG_PRINT(ERR_DBG, "***TxD error %llx\n", err);
                        }
                }
 
@@ -2877,7 +2796,7 @@ to loss of link\n");
                get_info.offset++;
                if (get_info.offset == get_info.fifo_len + 1)
                        get_info.offset = 0;
-               txdlp = (TxD_t *) fifo_data->list_info
+               txdlp = (struct TxD *) fifo_data->list_info
                    [get_info.offset].list_virt_addr;
                fifo_data->tx_curr_get_info.offset =
                    get_info.offset;
@@ -2902,8 +2821,8 @@ to loss of link\n");
 static void s2io_mdio_write(u32 mmd_type, u64 addr, u16 value, struct net_device *dev)
 {
        u64 val64 = 0x0;
-       nic_t *sp = dev->priv;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct s2io_nic *sp = dev->priv;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
 
        //address transaction
        val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
@@ -2951,8 +2870,8 @@ static u64 s2io_mdio_read(u32 mmd_type, u64 addr, struct net_device *dev)
 {
        u64 val64 = 0x0;
        u64 rval64 = 0x0;
-       nic_t *sp = dev->priv;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct s2io_nic *sp = dev->priv;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
 
        /* address transaction */
        val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
@@ -3055,8 +2974,8 @@ static void s2io_updt_xpak_counter(struct net_device *dev)
        u64 val64 = 0x0;
        u64 addr  = 0x0;
 
-       nic_t *sp = dev->priv;
-       StatInfo_t *stat_info = sp->mac_control.stats_info;
+       struct s2io_nic *sp = dev->priv;
+       struct stat_block *stat_info = sp->mac_control.stats_info;
 
        /* Check the communication with the MDIO slave */
        addr = 0x0000;
@@ -3154,10 +3073,12 @@ static void s2io_updt_xpak_counter(struct net_device *dev)
 static void alarm_intr_handler(struct s2io_nic *nic)
 {
        struct net_device *dev = (struct net_device *) nic->dev;
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        register u64 val64 = 0, err_reg = 0;
        u64 cnt;
        int i;
+       if (atomic_read(&nic->card_state) == CARD_DOWN)
+               return;
        nic->mac_control.stats_info->sw_stat.ring_full_cnt = 0;
        /* Handling the XPAK counters update */
        if(nic->mac_control.stats_info->xpak_stat.xpak_timer_count < 72000) {
@@ -3297,6 +3218,25 @@ static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit)
        }
        return ret;
 }
+/*
+ * check_pci_device_id - Checks if the device id is supported
+ * @id : device id
+ * Description: Function to check if the pci device id is supported by driver.
+ * Return value: Actual device id if supported else PCI_ANY_ID
+ */
+static u16 check_pci_device_id(u16 id)
+{
+       switch (id) {
+       case PCI_DEVICE_ID_HERC_WIN:
+       case PCI_DEVICE_ID_HERC_UNI:
+               return XFRAME_II_DEVICE;
+       case PCI_DEVICE_ID_S2IO_UNI:
+       case PCI_DEVICE_ID_S2IO_WIN:
+               return XFRAME_I_DEVICE;
+       default:
+               return PCI_ANY_ID;
+       }
+}
 
 /**
  *  s2io_reset - Resets the card.
@@ -3308,42 +3248,57 @@ static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit)
  *  void.
  */
 
-static void s2io_reset(nic_t * sp)
+static void s2io_reset(struct s2io_nic * sp)
 {
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u64 val64;
        u16 subid, pci_cmd;
+       int i;
+       u16 val16;
+       DBG_PRINT(INIT_DBG,"%s - Resetting XFrame card %s\n",
+                       __FUNCTION__, sp->dev->name);
 
        /* Back up  the PCI-X CMD reg, dont want to lose MMRBC, OST settings */
        pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER, &(pci_cmd));
 
+       if (sp->device_type == XFRAME_II_DEVICE) {
+               int ret;
+               ret = pci_set_power_state(sp->pdev, 3);
+               if (!ret)
+                       ret = pci_set_power_state(sp->pdev, 0);
+               else {
+                       DBG_PRINT(ERR_DBG,"%s PME based SW_Reset failed!\n",
+                                       __FUNCTION__);
+                       goto old_way;
+               }
+               msleep(20);
+               goto new_way;
+       }
+old_way:
        val64 = SW_RESET_ALL;
        writeq(val64, &bar0->sw_reset);
-
-       /*
-        * At this stage, if the PCI write is indeed completed, the
-        * card is reset and so is the PCI Config space of the device.
-        * So a read cannot be issued at this stage on any of the
-        * registers to ensure the write into "sw_reset" register
-        * has gone through.
-        * Question: Is there any system call that will explicitly force
-        * all the write commands still pending on the bus to be pushed
-        * through?
-        * As of now I'am just giving a 250ms delay and hoping that the
-        * PCI write to sw_reset register is done by this time.
-        */
-       msleep(250);
+new_way:
        if (strstr(sp->product_name, "CX4")) {
                msleep(750);
        }
+       msleep(250);
+       for (i = 0; i < S2IO_MAX_PCI_CONFIG_SPACE_REINIT; i++) {
 
-       /* Restore the PCI state saved during initialization. */
-       pci_restore_state(sp->pdev);
-       pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
-                                    pci_cmd);
-       s2io_init_pci(sp);
+               /* Restore the PCI state saved during initialization. */
+               pci_restore_state(sp->pdev);
+               pci_read_config_word(sp->pdev, 0x2, &val16);
+               if (check_pci_device_id(val16) != (u16)PCI_ANY_ID)
+                       break;
+               msleep(200);
+       }
 
-       msleep(250);
+       if (check_pci_device_id(val16) == (u16)PCI_ANY_ID) {
+               DBG_PRINT(ERR_DBG,"%s SW_Reset failed!\n", __FUNCTION__);
+       }
+
+       pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER, pci_cmd);
+
+       s2io_init_pci(sp);
 
        /* Set swapper to enable I/O register access */
        s2io_set_swapper(sp);
@@ -3399,10 +3354,10 @@ static void s2io_reset(nic_t * sp)
  *  SUCCESS on success and FAILURE on failure.
  */
 
-static int s2io_set_swapper(nic_t * sp)
+static int s2io_set_swapper(struct s2io_nic * sp)
 {
        struct net_device *dev = sp->dev;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u64 val64, valt, valr;
 
        /*
@@ -3527,9 +3482,9 @@ static int s2io_set_swapper(nic_t * sp)
        return SUCCESS;
 }
 
-static int wait_for_msix_trans(nic_t *nic, int i)
+static int wait_for_msix_trans(struct s2io_nic *nic, int i)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        u64 val64;
        int ret = 0, cnt = 0;
 
@@ -3548,9 +3503,9 @@ static int wait_for_msix_trans(nic_t *nic, int i)
        return ret;
 }
 
-static void restore_xmsi_data(nic_t *nic)
+static void restore_xmsi_data(struct s2io_nic *nic)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        u64 val64;
        int i;
 
@@ -3566,9 +3521,9 @@ static void restore_xmsi_data(nic_t *nic)
        }
 }
 
-static void store_xmsi_data(nic_t *nic)
+static void store_xmsi_data(struct s2io_nic *nic)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        u64 val64, addr, data;
        int i;
 
@@ -3589,9 +3544,9 @@ static void store_xmsi_data(nic_t *nic)
        }
 }
 
-int s2io_enable_msi(nic_t *nic)
+int s2io_enable_msi(struct s2io_nic *nic)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        u16 msi_ctrl, msg_val;
        struct config_param *config = &nic->config;
        struct net_device *dev = nic->dev;
@@ -3639,9 +3594,9 @@ int s2io_enable_msi(nic_t *nic)
        return 0;
 }
 
-static int s2io_enable_msi_x(nic_t *nic)
+static int s2io_enable_msi_x(struct s2io_nic *nic)
 {
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        u64 tx_mat, rx_mat;
        u16 msi_control; /* Temp variable */
        int ret, i, j, msix_indx = 1;
@@ -3749,7 +3704,7 @@ static int s2io_enable_msi_x(nic_t *nic)
 
 static int s2io_open(struct net_device *dev)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
        int err = 0;
 
        /*
@@ -3802,7 +3757,7 @@ hw_init_failed:
 
 static int s2io_close(struct net_device *dev)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
 
        flush_scheduled_work();
        netif_stop_queue(dev);
@@ -3828,15 +3783,15 @@ static int s2io_close(struct net_device *dev)
 
 static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
        u16 frg_cnt, frg_len, i, queue, queue_len, put_off, get_off;
        register u64 val64;
-       TxD_t *txdp;
-       TxFIFO_element_t __iomem *tx_fifo;
+       struct TxD *txdp;
+       struct TxFIFO_element __iomem *tx_fifo;
        unsigned long flags;
        u16 vlan_tag = 0;
        int vlan_priority = 0;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
        int offload_type;
 
@@ -3864,7 +3819,7 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
 
        put_off = (u16) mac_control->fifos[queue].tx_curr_put_info.offset;
        get_off = (u16) mac_control->fifos[queue].tx_curr_get_info.offset;
-       txdp = (TxD_t *) mac_control->fifos[queue].list_info[put_off].
+       txdp = (struct TxD *) mac_control->fifos[queue].list_info[put_off].
                list_virt_addr;
 
        queue_len = mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1;
@@ -3887,12 +3842,10 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
        }
 
        offload_type = s2io_offload_type(skb);
-#ifdef NETIF_F_TSO
        if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
                txdp->Control_1 |= TXD_TCP_LSO_EN;
                txdp->Control_1 |= TXD_TCP_LSO_MSS(s2io_tcp_mss(skb));
        }
-#endif
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
                txdp->Control_2 |=
                    (TXD_TX_CKO_IPV4_EN | TXD_TX_CKO_TCP_EN |
@@ -3993,13 +3946,13 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
 static void
 s2io_alarm_handle(unsigned long data)
 {
-       nic_t *sp = (nic_t *)data;
+       struct s2io_nic *sp = (struct s2io_nic *)data;
 
        alarm_intr_handler(sp);
        mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
 }
 
-static int s2io_chk_rx_buffers(nic_t *sp, int rng_n)
+static int s2io_chk_rx_buffers(struct s2io_nic *sp, int rng_n)
 {
        int rxb_size, level;
 
@@ -4031,9 +3984,9 @@ static int s2io_chk_rx_buffers(nic_t *sp, int rng_n)
 static irqreturn_t s2io_msi_handle(int irq, void *dev_id)
 {
        struct net_device *dev = (struct net_device *) dev_id;
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
        int i;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
 
        atomic_inc(&sp->isr_cnt);
@@ -4063,8 +4016,8 @@ static irqreturn_t s2io_msi_handle(int irq, void *dev_id)
 
 static irqreturn_t s2io_msix_ring_handle(int irq, void *dev_id)
 {
-       ring_info_t *ring = (ring_info_t *)dev_id;
-       nic_t *sp = ring->nic;
+       struct ring_info *ring = (struct ring_info *)dev_id;
+       struct s2io_nic *sp = ring->nic;
 
        atomic_inc(&sp->isr_cnt);
 
@@ -4077,17 +4030,17 @@ static irqreturn_t s2io_msix_ring_handle(int irq, void *dev_id)
 
 static irqreturn_t s2io_msix_fifo_handle(int irq, void *dev_id)
 {
-       fifo_info_t *fifo = (fifo_info_t *)dev_id;
-       nic_t *sp = fifo->nic;
+       struct fifo_info *fifo = (struct fifo_info *)dev_id;
+       struct s2io_nic *sp = fifo->nic;
 
        atomic_inc(&sp->isr_cnt);
        tx_intr_handler(fifo);
        atomic_dec(&sp->isr_cnt);
        return IRQ_HANDLED;
 }
-static void s2io_txpic_intr_handle(nic_t *sp)
+static void s2io_txpic_intr_handle(struct s2io_nic *sp)
 {
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u64 val64;
 
        val64 = readq(&bar0->pic_int_status);
@@ -4109,39 +4062,33 @@ static void s2io_txpic_intr_handle(nic_t *sp)
                }
                else if (val64 & GPIO_INT_REG_LINK_UP) {
                        val64 = readq(&bar0->adapter_status);
-                       if (verify_xena_quiescence(sp, val64,
-                                                  sp->device_enabled_once)) {
                                /* Enable Adapter */
-                               val64 = readq(&bar0->adapter_control);
-                               val64 |= ADAPTER_CNTL_EN;
-                               writeq(val64, &bar0->adapter_control);
-                               val64 |= ADAPTER_LED_ON;
-                               writeq(val64, &bar0->adapter_control);
-                               if (!sp->device_enabled_once)
-                                       sp->device_enabled_once = 1;
+                       val64 = readq(&bar0->adapter_control);
+                       val64 |= ADAPTER_CNTL_EN;
+                       writeq(val64, &bar0->adapter_control);
+                       val64 |= ADAPTER_LED_ON;
+                       writeq(val64, &bar0->adapter_control);
+                       if (!sp->device_enabled_once)
+                               sp->device_enabled_once = 1;
 
-                               s2io_link(sp, LINK_UP);
-                               /*
-                                * unmask link down interrupt and mask link-up
-                                * intr
-                                */
-                               val64 = readq(&bar0->gpio_int_mask);
-                               val64 &= ~GPIO_INT_MASK_LINK_DOWN;
-                               val64 |= GPIO_INT_MASK_LINK_UP;
-                               writeq(val64, &bar0->gpio_int_mask);
+                       s2io_link(sp, LINK_UP);
+                       /*
+                        * unmask link down interrupt and mask link-up
+                        * intr
+                        */
+                       val64 = readq(&bar0->gpio_int_mask);
+                       val64 &= ~GPIO_INT_MASK_LINK_DOWN;
+                       val64 |= GPIO_INT_MASK_LINK_UP;
+                       writeq(val64, &bar0->gpio_int_mask);
 
-                       }
                }else if (val64 & GPIO_INT_REG_LINK_DOWN) {
                        val64 = readq(&bar0->adapter_status);
-                       if (verify_xena_quiescence(sp, val64,
-                                                  sp->device_enabled_once)) {
-                               s2io_link(sp, LINK_DOWN);
-                               /* Link is down so unmaks link up interrupt */
-                               val64 = readq(&bar0->gpio_int_mask);
-                               val64 &= ~GPIO_INT_MASK_LINK_UP;
-                               val64 |= GPIO_INT_MASK_LINK_DOWN;
-                               writeq(val64, &bar0->gpio_int_mask);
-                       }
+                       s2io_link(sp, LINK_DOWN);
+                       /* Link is down so unmaks link up interrupt */
+                       val64 = readq(&bar0->gpio_int_mask);
+                       val64 &= ~GPIO_INT_MASK_LINK_UP;
+                       val64 |= GPIO_INT_MASK_LINK_DOWN;
+                       writeq(val64, &bar0->gpio_int_mask);
                }
        }
        val64 = readq(&bar0->gpio_int_mask);
@@ -4163,11 +4110,11 @@ static void s2io_txpic_intr_handle(nic_t *sp)
 static irqreturn_t s2io_isr(int irq, void *dev_id)
 {
        struct net_device *dev = (struct net_device *) dev_id;
-       nic_t *sp = dev->priv;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct s2io_nic *sp = dev->priv;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        int i;
-       u64 reason = 0, val64, org_mask;
-       mac_info_t *mac_control;
+       u64 reason = 0;
+       struct mac_info *mac_control;
        struct config_param *config;
 
        atomic_inc(&sp->isr_cnt);
@@ -4185,43 +4132,48 @@ static irqreturn_t s2io_isr(int irq, void *dev_id)
        reason = readq(&bar0->general_int_status);
 
        if (!reason) {
-               /* The interrupt was not raised by Xena. */
+               /* The interrupt was not raised by us. */
+               atomic_dec(&sp->isr_cnt);
+               return IRQ_NONE;
+       }
+       else if (unlikely(reason == S2IO_MINUS_ONE) ) {
+               /* Disable device and get out */
                atomic_dec(&sp->isr_cnt);
                return IRQ_NONE;
        }
 
-       val64 = 0xFFFFFFFFFFFFFFFFULL;
-       /* Store current mask before masking all interrupts */
-       org_mask = readq(&bar0->general_int_mask);
-       writeq(val64, &bar0->general_int_mask);
+       if (napi) {
+               if (reason & GEN_INTR_RXTRAFFIC) {
+                       if ( likely ( netif_rx_schedule_prep(dev)) ) {
+                               __netif_rx_schedule(dev);
+                               writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_mask);
+                       }
+                       else
+                               writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
+               }
+       } else {
+               /*
+                * Rx handler is called by default, without checking for the
+                * cause of interrupt.
+                * rx_traffic_int reg is an R1 register, writing all 1's
+                * will ensure that the actual interrupt causing bit get's
+                * cleared and hence a read can be avoided.
+                */
+               if (reason & GEN_INTR_RXTRAFFIC)
+                       writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
 
-#ifdef CONFIG_S2IO_NAPI
-       if (reason & GEN_INTR_RXTRAFFIC) {
-               if (netif_rx_schedule_prep(dev)) {
-                       writeq(val64, &bar0->rx_traffic_mask);
-                       __netif_rx_schedule(dev);
+               for (i = 0; i < config->rx_ring_num; i++) {
+                       rx_intr_handler(&mac_control->rings[i]);
                }
        }
-#else
-       /*
-        * Rx handler is called by default, without checking for the
-        * cause of interrupt.
-        * rx_traffic_int reg is an R1 register, writing all 1's
-        * will ensure that the actual interrupt causing bit get's
-        * cleared and hence a read can be avoided.
-        */
-       writeq(val64, &bar0->rx_traffic_int);
-       for (i = 0; i < config->rx_ring_num; i++) {
-               rx_intr_handler(&mac_control->rings[i]);
-       }
-#endif
 
        /*
         * tx_traffic_int reg is an R1 register, writing all 1's
         * will ensure that the actual interrupt causing bit get's
         * cleared and hence a read can be avoided.
         */
-       writeq(val64, &bar0->tx_traffic_int);
+       if (reason & GEN_INTR_TXTRAFFIC)
+               writeq(S2IO_MINUS_ONE, &bar0->tx_traffic_int);
 
        for (i = 0; i < config->tx_fifo_num; i++)
                tx_intr_handler(&mac_control->fifos[i]);
@@ -4233,11 +4185,14 @@ static irqreturn_t s2io_isr(int irq, void *dev_id)
         * reallocate the buffers from the interrupt handler itself,
         * else schedule a tasklet to reallocate the buffers.
         */
-#ifndef CONFIG_S2IO_NAPI
-       for (i = 0; i < config->rx_ring_num; i++)
-               s2io_chk_rx_buffers(sp, i);
-#endif
-       writeq(org_mask, &bar0->general_int_mask);
+       if (!napi) {
+               for (i = 0; i < config->rx_ring_num; i++)
+                       s2io_chk_rx_buffers(sp, i);
+       }
+
+       writeq(0, &bar0->general_int_mask);
+       readl(&bar0->general_int_status);
+
        atomic_dec(&sp->isr_cnt);
        return IRQ_HANDLED;
 }
@@ -4245,9 +4200,9 @@ static irqreturn_t s2io_isr(int irq, void *dev_id)
 /**
  * s2io_updt_stats -
  */
-static void s2io_updt_stats(nic_t *sp)
+static void s2io_updt_stats(struct s2io_nic *sp)
 {
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u64 val64;
        int cnt = 0;
 
@@ -4266,7 +4221,7 @@ static void s2io_updt_stats(nic_t *sp)
                                break; /* Updt failed */
                } while(1);
        } else {
-               memset(sp->mac_control.stats_info, 0, sizeof(StatInfo_t));
+               memset(sp->mac_control.stats_info, 0, sizeof(struct stat_block));
        }
 }
 
@@ -4282,8 +4237,8 @@ static void s2io_updt_stats(nic_t *sp)
 
 static struct net_device_stats *s2io_get_stats(struct net_device *dev)
 {
-       nic_t *sp = dev->priv;
-       mac_info_t *mac_control;
+       struct s2io_nic *sp = dev->priv;
+       struct mac_info *mac_control;
        struct config_param *config;
 
 
@@ -4324,8 +4279,8 @@ static void s2io_set_multicast(struct net_device *dev)
 {
        int i, j, prev_cnt;
        struct dev_mc_list *mclist;
-       nic_t *sp = dev->priv;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct s2io_nic *sp = dev->priv;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u64 val64 = 0, multi_mac = 0x010203040506ULL, mask =
            0xfeffffffffffULL;
        u64 dis_addr = 0xffffffffffffULL, mac_addr = 0;
@@ -4478,8 +4433,8 @@ static void s2io_set_multicast(struct net_device *dev)
 
 static int s2io_set_mac_addr(struct net_device *dev, u8 * addr)
 {
-       nic_t *sp = dev->priv;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct s2io_nic *sp = dev->priv;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        register u64 val64, mac_addr = 0;
        int i;
 
@@ -4525,7 +4480,7 @@ static int s2io_set_mac_addr(struct net_device *dev, u8 * addr)
 static int s2io_ethtool_sset(struct net_device *dev,
                             struct ethtool_cmd *info)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
        if ((info->autoneg == AUTONEG_ENABLE) ||
            (info->speed != SPEED_10000) || (info->duplex != DUPLEX_FULL))
                return -EINVAL;
@@ -4551,7 +4506,7 @@ static int s2io_ethtool_sset(struct net_device *dev,
 
 static int s2io_ethtool_gset(struct net_device *dev, struct ethtool_cmd *info)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
        info->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
        info->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
        info->port = PORT_FIBRE;
@@ -4584,7 +4539,7 @@ static int s2io_ethtool_gset(struct net_device *dev, struct ethtool_cmd *info)
 static void s2io_ethtool_gdrvinfo(struct net_device *dev,
                                  struct ethtool_drvinfo *info)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
 
        strncpy(info->driver, s2io_driver_name, sizeof(info->driver));
        strncpy(info->version, s2io_driver_version, sizeof(info->version));
@@ -4616,7 +4571,7 @@ static void s2io_ethtool_gregs(struct net_device *dev,
        int i;
        u64 reg;
        u8 *reg_space = (u8 *) space;
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
 
        regs->len = XENA_REG_SPACE;
        regs->version = sp->pdev->subsystem_device;
@@ -4638,8 +4593,8 @@ static void s2io_ethtool_gregs(struct net_device *dev,
 */
 static void s2io_phy_id(unsigned long data)
 {
-       nic_t *sp = (nic_t *) data;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct s2io_nic *sp = (struct s2io_nic *) data;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u64 val64 = 0;
        u16 subid;
 
@@ -4676,8 +4631,8 @@ static void s2io_phy_id(unsigned long data)
 static int s2io_ethtool_idnic(struct net_device *dev, u32 data)
 {
        u64 val64 = 0, last_gpio_ctrl_val;
-       nic_t *sp = dev->priv;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct s2io_nic *sp = dev->priv;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u16 subid;
 
        subid = sp->pdev->subsystem_device;
@@ -4725,8 +4680,8 @@ static void s2io_ethtool_getpause_data(struct net_device *dev,
                                       struct ethtool_pauseparam *ep)
 {
        u64 val64;
-       nic_t *sp = dev->priv;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct s2io_nic *sp = dev->priv;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
 
        val64 = readq(&bar0->rmac_pause_cfg);
        if (val64 & RMAC_PAUSE_GEN_ENABLE)
@@ -4752,8 +4707,8 @@ static int s2io_ethtool_setpause_data(struct net_device *dev,
                               struct ethtool_pauseparam *ep)
 {
        u64 val64;
-       nic_t *sp = dev->priv;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct s2io_nic *sp = dev->priv;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
 
        val64 = readq(&bar0->rmac_pause_cfg);
        if (ep->tx_pause)
@@ -4785,12 +4740,12 @@ static int s2io_ethtool_setpause_data(struct net_device *dev,
  */
 
 #define S2IO_DEV_ID            5
-static int read_eeprom(nic_t * sp, int off, u64 * data)
+static int read_eeprom(struct s2io_nic * sp, int off, u64 * data)
 {
        int ret = -1;
        u32 exit_cnt = 0;
        u64 val64;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
 
        if (sp->device_type == XFRAME_I_DEVICE) {
                val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
@@ -4850,11 +4805,11 @@ static int read_eeprom(nic_t * sp, int off, u64 * data)
  *  0 on success, -1 on failure.
  */
 
-static int write_eeprom(nic_t * sp, int off, u64 data, int cnt)
+static int write_eeprom(struct s2io_nic * sp, int off, u64 data, int cnt)
 {
        int exit_cnt = 0, ret = -1;
        u64 val64;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
 
        if (sp->device_type == XFRAME_I_DEVICE) {
                val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
@@ -4899,7 +4854,7 @@ static int write_eeprom(nic_t * sp, int off, u64 data, int cnt)
        }
        return ret;
 }
-static void s2io_vpd_read(nic_t *nic)
+static void s2io_vpd_read(struct s2io_nic *nic)
 {
        u8 *vpd_data;
        u8 data;
@@ -4914,6 +4869,7 @@ static void s2io_vpd_read(nic_t *nic)
                strcpy(nic->product_name, "Xframe I 10GbE network adapter");
                vpd_addr = 0x50;
        }
+       strcpy(nic->serial_num, "NOT AVAILABLE");
 
        vpd_data = kmalloc(256, GFP_KERNEL);
        if (!vpd_data)
@@ -4937,7 +4893,22 @@ static void s2io_vpd_read(nic_t *nic)
                pci_read_config_dword(nic->pdev,  (vpd_addr + 4),
                                      (u32 *)&vpd_data[i]);
        }
-       if ((!fail) && (vpd_data[1] < VPD_PRODUCT_NAME_LEN)) {
+
+       if(!fail) {
+               /* read serial number of adapter */
+               for (cnt = 0; cnt < 256; cnt++) {
+               if ((vpd_data[cnt] == 'S') &&
+                       (vpd_data[cnt+1] == 'N') &&
+                       (vpd_data[cnt+2] < VPD_STRING_LEN)) {
+                               memset(nic->serial_num, 0, VPD_STRING_LEN);
+                               memcpy(nic->serial_num, &vpd_data[cnt + 3],
+                                       vpd_data[cnt+2]);
+                               break;
+                       }
+               }
+       }
+
+       if ((!fail) && (vpd_data[1] < VPD_STRING_LEN)) {
                memset(nic->product_name, 0, vpd_data[1]);
                memcpy(nic->product_name, &vpd_data[3], vpd_data[1]);
        }
@@ -4962,7 +4933,7 @@ static int s2io_ethtool_geeprom(struct net_device *dev,
 {
        u32 i, valid;
        u64 data;
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
 
        eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16);
 
@@ -5000,7 +4971,7 @@ static int s2io_ethtool_seeprom(struct net_device *dev,
 {
        int len = eeprom->len, cnt = 0;
        u64 valid = 0, data;
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
 
        if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) {
                DBG_PRINT(ERR_DBG,
@@ -5044,9 +5015,9 @@ static int s2io_ethtool_seeprom(struct net_device *dev,
  * 0 on success.
  */
 
-static int s2io_register_test(nic_t * sp, uint64_t * data)
+static int s2io_register_test(struct s2io_nic * sp, uint64_t * data)
 {
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u64 val64 = 0, exp_val;
        int fail = 0;
 
@@ -5111,7 +5082,7 @@ static int s2io_register_test(nic_t * sp, uint64_t * data)
  * 0 on success.
  */
 
-static int s2io_eeprom_test(nic_t * sp, uint64_t * data)
+static int s2io_eeprom_test(struct s2io_nic * sp, uint64_t * data)
 {
        int fail = 0;
        u64 ret_data, org_4F0, org_7F0;
@@ -5213,7 +5184,7 @@ static int s2io_eeprom_test(nic_t * sp, uint64_t * data)
  * 0 on success and -1 on failure.
  */
 
-static int s2io_bist_test(nic_t * sp, uint64_t * data)
+static int s2io_bist_test(struct s2io_nic * sp, uint64_t * data)
 {
        u8 bist = 0;
        int cnt = 0, ret = -1;
@@ -5249,9 +5220,9 @@ static int s2io_bist_test(nic_t * sp, uint64_t * data)
  * 0 on success.
  */
 
-static int s2io_link_test(nic_t * sp, uint64_t * data)
+static int s2io_link_test(struct s2io_nic * sp, uint64_t * data)
 {
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u64 val64;
 
        val64 = readq(&bar0->adapter_status);
@@ -5276,9 +5247,9 @@ static int s2io_link_test(nic_t * sp, uint64_t * data)
  *  0 on success.
  */
 
-static int s2io_rldram_test(nic_t * sp, uint64_t * data)
+static int s2io_rldram_test(struct s2io_nic * sp, uint64_t * data)
 {
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        u64 val64;
        int cnt, iteration = 0, test_fail = 0;
 
@@ -5380,7 +5351,7 @@ static void s2io_ethtool_test(struct net_device *dev,
                              struct ethtool_test *ethtest,
                              uint64_t * data)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
        int orig_state = netif_running(sp->dev);
 
        if (ethtest->flags == ETH_TEST_FL_OFFLINE) {
@@ -5436,8 +5407,8 @@ static void s2io_get_ethtool_stats(struct net_device *dev,
                                   u64 * tmp_stats)
 {
        int i = 0;
-       nic_t *sp = dev->priv;
-       StatInfo_t *stat_info = sp->mac_control.stats_info;
+       struct s2io_nic *sp = dev->priv;
+       struct stat_block *stat_info = sp->mac_control.stats_info;
 
        s2io_updt_stats(sp);
        tmp_stats[i++] =
@@ -5664,14 +5635,14 @@ static int s2io_ethtool_get_regs_len(struct net_device *dev)
 
 static u32 s2io_ethtool_get_rx_csum(struct net_device * dev)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
 
        return (sp->rx_csum);
 }
 
 static int s2io_ethtool_set_rx_csum(struct net_device *dev, u32 data)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
 
        if (data)
                sp->rx_csum = 1;
@@ -5750,10 +5721,8 @@ static const struct ethtool_ops netdev_ethtool_ops = {
        .set_tx_csum = s2io_ethtool_op_set_tx_csum,
        .get_sg = ethtool_op_get_sg,
        .set_sg = ethtool_op_set_sg,
-#ifdef NETIF_F_TSO
        .get_tso = s2io_ethtool_op_get_tso,
        .set_tso = s2io_ethtool_op_set_tso,
-#endif
        .get_ufo = ethtool_op_get_ufo,
        .set_ufo = ethtool_op_set_ufo,
        .self_test_count = s2io_ethtool_self_test_count,
@@ -5794,7 +5763,7 @@ static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 
 static int s2io_change_mtu(struct net_device *dev, int new_mtu)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
 
        if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) {
                DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n",
@@ -5813,7 +5782,7 @@ static int s2io_change_mtu(struct net_device *dev, int new_mtu)
                if (netif_queue_stopped(dev))
                        netif_wake_queue(dev);
        } else { /* Device is down */
-               XENA_dev_config_t __iomem *bar0 = sp->bar0;
+               struct XENA_dev_config __iomem *bar0 = sp->bar0;
                u64 val64 = new_mtu;
 
                writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
@@ -5838,9 +5807,9 @@ static int s2io_change_mtu(struct net_device *dev, int new_mtu)
 static void s2io_tasklet(unsigned long dev_addr)
 {
        struct net_device *dev = (struct net_device *) dev_addr;
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
        int i, ret;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
 
        mac_control = &sp->mac_control;
@@ -5873,9 +5842,9 @@ static void s2io_tasklet(unsigned long dev_addr)
 
 static void s2io_set_link(struct work_struct *work)
 {
-       nic_t *nic = container_of(work, nic_t, set_link_task);
+       struct s2io_nic *nic = container_of(work, struct s2io_nic, set_link_task);
        struct net_device *dev = nic->dev;
-       XENA_dev_config_t __iomem *bar0 = nic->bar0;
+       struct XENA_dev_config __iomem *bar0 = nic->bar0;
        register u64 val64;
        u16 subid;
 
@@ -5894,57 +5863,53 @@ static void s2io_set_link(struct work_struct *work)
        }
 
        val64 = readq(&bar0->adapter_status);
-       if (verify_xena_quiescence(nic, val64, nic->device_enabled_once)) {
-               if (LINK_IS_UP(val64)) {
-                       val64 = readq(&bar0->adapter_control);
-                       val64 |= ADAPTER_CNTL_EN;
-                       writeq(val64, &bar0->adapter_control);
-                       if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
-                                                            subid)) {
-                               val64 = readq(&bar0->gpio_control);
-                               val64 |= GPIO_CTRL_GPIO_0;
-                               writeq(val64, &bar0->gpio_control);
-                               val64 = readq(&bar0->gpio_control);
-                       } else {
-                               val64 |= ADAPTER_LED_ON;
+       if (LINK_IS_UP(val64)) {
+               if (!(readq(&bar0->adapter_control) & ADAPTER_CNTL_EN)) {
+                       if (verify_xena_quiescence(nic)) {
+                               val64 = readq(&bar0->adapter_control);
+                               val64 |= ADAPTER_CNTL_EN;
                                writeq(val64, &bar0->adapter_control);
-                       }
-                       if (s2io_link_fault_indication(nic) ==
-                                               MAC_RMAC_ERR_TIMER) {
-                               val64 = readq(&bar0->adapter_status);
-                               if (!LINK_IS_UP(val64)) {
-                                       DBG_PRINT(ERR_DBG, "%s:", dev->name);
-                                       DBG_PRINT(ERR_DBG, " Link down");
-                                       DBG_PRINT(ERR_DBG, "after ");
-                                       DBG_PRINT(ERR_DBG, "enabling ");
-                                       DBG_PRINT(ERR_DBG, "device \n");
+                               if (CARDS_WITH_FAULTY_LINK_INDICATORS(
+                                       nic->device_type, subid)) {
+                                       val64 = readq(&bar0->gpio_control);
+                                       val64 |= GPIO_CTRL_GPIO_0;
+                                       writeq(val64, &bar0->gpio_control);
+                                       val64 = readq(&bar0->gpio_control);
+                               } else {
+                                       val64 |= ADAPTER_LED_ON;
+                                       writeq(val64, &bar0->adapter_control);
                                }
-                       }
-                       if (nic->device_enabled_once == FALSE) {
                                nic->device_enabled_once = TRUE;
+                       } else {
+                               DBG_PRINT(ERR_DBG, "%s: Error: ", dev->name);
+                               DBG_PRINT(ERR_DBG, "device is not Quiescent\n");
+                               netif_stop_queue(dev);
                        }
+               }
+               val64 = readq(&bar0->adapter_status);
+               if (!LINK_IS_UP(val64)) {
+                       DBG_PRINT(ERR_DBG, "%s:", dev->name);
+                       DBG_PRINT(ERR_DBG, " Link down after enabling ");
+                       DBG_PRINT(ERR_DBG, "device \n");
+               } else
                        s2io_link(nic, LINK_UP);
-               } else {
-                       if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
-                                                             subid)) {
-                               val64 = readq(&bar0->gpio_control);
-                               val64 &= ~GPIO_CTRL_GPIO_0;
-                               writeq(val64, &bar0->gpio_control);
-                               val64 = readq(&bar0->gpio_control);
-                       }
-                       s2io_link(nic, LINK_DOWN);
+       } else {
+               if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
+                                                     subid)) {
+                       val64 = readq(&bar0->gpio_control);
+                       val64 &= ~GPIO_CTRL_GPIO_0;
+                       writeq(val64, &bar0->gpio_control);
+                       val64 = readq(&bar0->gpio_control);
                }
-       } else {                /* NIC is not Quiescent. */
-               DBG_PRINT(ERR_DBG, "%s: Error: ", dev->name);
-               DBG_PRINT(ERR_DBG, "device is not Quiescent\n");
-               netif_stop_queue(dev);
+               s2io_link(nic, LINK_DOWN);
        }
        clear_bit(0, &(nic->link_state));
 }
 
-static int set_rxd_buffer_pointer(nic_t *sp, RxD_t *rxdp, buffAdd_t *ba,
-                          struct sk_buff **skb, u64 *temp0, u64 *temp1,
-                          u64 *temp2, int size)
+static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
+                               struct buffAdd *ba,
+                               struct sk_buff **skb, u64 *temp0, u64 *temp1,
+                               u64 *temp2, int size)
 {
        struct net_device *dev = sp->dev;
        struct sk_buff *frag_list;
@@ -5958,7 +5923,7 @@ static int set_rxd_buffer_pointer(nic_t *sp, RxD_t *rxdp, buffAdd_t *ba,
                         * using same mapped address for the Rxd
                         * buffer pointer
                         */
-                       ((RxD1_t*)rxdp)->Buffer0_ptr = *temp0;
+                       ((struct RxD1*)rxdp)->Buffer0_ptr = *temp0;
                } else {
                        *skb = dev_alloc_skb(size);
                        if (!(*skb)) {
@@ -5970,7 +5935,7 @@ static int set_rxd_buffer_pointer(nic_t *sp, RxD_t *rxdp, buffAdd_t *ba,
                         * such it will be used for next rxd whose
                         * Host Control is NULL
                         */
-                       ((RxD1_t*)rxdp)->Buffer0_ptr = *temp0 =
+                       ((struct RxD1*)rxdp)->Buffer0_ptr = *temp0 =
                                pci_map_single( sp->pdev, (*skb)->data,
                                        size - NET_IP_ALIGN,
                                        PCI_DMA_FROMDEVICE);
@@ -5979,36 +5944,36 @@ static int set_rxd_buffer_pointer(nic_t *sp, RxD_t *rxdp, buffAdd_t *ba,
        } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) {
                /* Two buffer Mode */
                if (*skb) {
-                       ((RxD3_t*)rxdp)->Buffer2_ptr = *temp2;
-                       ((RxD3_t*)rxdp)->Buffer0_ptr = *temp0;
-                       ((RxD3_t*)rxdp)->Buffer1_ptr = *temp1;
+                       ((struct RxD3*)rxdp)->Buffer2_ptr = *temp2;
+                       ((struct RxD3*)rxdp)->Buffer0_ptr = *temp0;
+                       ((struct RxD3*)rxdp)->Buffer1_ptr = *temp1;
                } else {
                        *skb = dev_alloc_skb(size);
                        if (!(*skb)) {
                                DBG_PRINT(ERR_DBG, "%s: dev_alloc_skb failed\n",
-                                         dev->name);
+                                       dev->name);
                                return -ENOMEM;
                        }
-                       ((RxD3_t*)rxdp)->Buffer2_ptr = *temp2 =
+                       ((struct RxD3*)rxdp)->Buffer2_ptr = *temp2 =
                                pci_map_single(sp->pdev, (*skb)->data,
                                               dev->mtu + 4,
                                               PCI_DMA_FROMDEVICE);
-                       ((RxD3_t*)rxdp)->Buffer0_ptr = *temp0 =
+                       ((struct RxD3*)rxdp)->Buffer0_ptr = *temp0 =
                                pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN,
                                                PCI_DMA_FROMDEVICE);
                        rxdp->Host_Control = (unsigned long) (*skb);
 
                        /* Buffer-1 will be dummy buffer not used */
-                       ((RxD3_t*)rxdp)->Buffer1_ptr = *temp1 =
+                       ((struct RxD3*)rxdp)->Buffer1_ptr = *temp1 =
                                pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN,
                                               PCI_DMA_FROMDEVICE);
                }
        } else if ((rxdp->Host_Control == 0)) {
                /* Three buffer mode */
                if (*skb) {
-                       ((RxD3_t*)rxdp)->Buffer0_ptr = *temp0;
-                       ((RxD3_t*)rxdp)->Buffer1_ptr = *temp1;
-                       ((RxD3_t*)rxdp)->Buffer2_ptr = *temp2;
+                       ((struct RxD3*)rxdp)->Buffer0_ptr = *temp0;
+                       ((struct RxD3*)rxdp)->Buffer1_ptr = *temp1;
+                       ((struct RxD3*)rxdp)->Buffer2_ptr = *temp2;
                } else {
                        *skb = dev_alloc_skb(size);
                        if (!(*skb)) {
@@ -6016,11 +5981,11 @@ static int set_rxd_buffer_pointer(nic_t *sp, RxD_t *rxdp, buffAdd_t *ba,
                                          dev->name);
                                return -ENOMEM;
                        }
-                       ((RxD3_t*)rxdp)->Buffer0_ptr = *temp0 =
+                       ((struct RxD3*)rxdp)->Buffer0_ptr = *temp0 =
                                pci_map_single(sp->pdev, ba->ba_0, BUF0_LEN,
                                               PCI_DMA_FROMDEVICE);
                        /* Buffer-1 receives L3/L4 headers */
-                       ((RxD3_t*)rxdp)->Buffer1_ptr = *temp1 =
+                       ((struct RxD3*)rxdp)->Buffer1_ptr = *temp1 =
                                pci_map_single( sp->pdev, (*skb)->data,
                                                l3l4hdr_size + 4,
                                                PCI_DMA_FROMDEVICE);
@@ -6040,14 +6005,15 @@ static int set_rxd_buffer_pointer(nic_t *sp, RxD_t *rxdp, buffAdd_t *ba,
                        /*
                         * Buffer-2 receives L4 data payload
                         */
-                       ((RxD3_t*)rxdp)->Buffer2_ptr = *temp2 =
+                       ((struct RxD3*)rxdp)->Buffer2_ptr = *temp2 =
                                pci_map_single( sp->pdev, frag_list->data,
                                                dev->mtu, PCI_DMA_FROMDEVICE);
                }
        }
        return 0;
 }
-static void set_rxd_buffer_size(nic_t *sp, RxD_t *rxdp, int size)
+static void set_rxd_buffer_size(struct s2io_nic *sp, struct RxD_t *rxdp,
+                               int size)
 {
        struct net_device *dev = sp->dev;
        if (sp->rxd_mode == RXD_MODE_1) {
@@ -6063,15 +6029,15 @@ static void set_rxd_buffer_size(nic_t *sp, RxD_t *rxdp, int size)
        }
 }
 
-static  int rxd_owner_bit_reset(nic_t *sp)
+static  int rxd_owner_bit_reset(struct s2io_nic *sp)
 {
        int i, j, k, blk_cnt = 0, size;
-       mac_info_t * mac_control = &sp->mac_control;
+       struct mac_info * mac_control = &sp->mac_control;
        struct config_param *config = &sp->config;
        struct net_device *dev = sp->dev;
-       RxD_t *rxdp = NULL;
+       struct RxD_t *rxdp = NULL;
        struct sk_buff *skb = NULL;
-       buffAdd_t *ba = NULL;
+       struct buffAdd *ba = NULL;
        u64 temp0_64 = 0, temp1_64 = 0, temp2_64 = 0;
 
        /* Calculate the size based on ring mode */
@@ -6110,7 +6076,7 @@ static  int rxd_owner_bit_reset(nic_t *sp)
 
 }
 
-static int s2io_add_isr(nic_t * sp)
+static int s2io_add_isr(struct s2io_nic * sp)
 {
        int ret = 0;
        struct net_device *dev = sp->dev;
@@ -6125,7 +6091,7 @@ static int s2io_add_isr(nic_t * sp)
                sp->intr_type = INTA;
        }
 
-       /* Store the values of the MSIX table in the nic_t structure */
+       /* Store the values of the MSIX table in the struct s2io_nic structure */
        store_xmsi_data(sp);
 
        /* After proper initialization of H/W, register ISR */
@@ -6180,7 +6146,7 @@ static int s2io_add_isr(nic_t * sp)
        }
        return 0;
 }
-static void s2io_rem_isr(nic_t * sp)
+static void s2io_rem_isr(struct s2io_nic * sp)
 {
        int cnt = 0;
        struct net_device *dev = sp->dev;
@@ -6222,10 +6188,10 @@ static void s2io_rem_isr(nic_t * sp)
        } while(cnt < 5);
 }
 
-static void s2io_card_down(nic_t * sp)
+static void s2io_card_down(struct s2io_nic * sp)
 {
        int cnt = 0;
-       XENA_dev_config_t __iomem *bar0 = sp->bar0;
+       struct XENA_dev_config __iomem *bar0 = sp->bar0;
        unsigned long flags;
        register u64 val64 = 0;
 
@@ -6256,7 +6222,8 @@ static void s2io_card_down(nic_t * sp)
                rxd_owner_bit_reset(sp);
 
                val64 = readq(&bar0->adapter_status);
-               if (verify_xena_quiescence(sp, val64, sp->device_enabled_once)) {
+               if (verify_xena_quiescence(sp)) {
+                       if(verify_pcc_quiescent(sp, sp->device_enabled_once))
                        break;
                }
 
@@ -6285,10 +6252,10 @@ static void s2io_card_down(nic_t * sp)
        clear_bit(0, &(sp->link_state));
 }
 
-static int s2io_card_up(nic_t * sp)
+static int s2io_card_up(struct s2io_nic * sp)
 {
        int i, ret = 0;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
        struct net_device *dev = (struct net_device *) sp->dev;
        u16 interruptible;
@@ -6319,6 +6286,13 @@ static int s2io_card_up(nic_t * sp)
                DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
                          atomic_read(&sp->rx_bufs_left[i]));
        }
+       /* Maintain the state prior to the open */
+       if (sp->promisc_flg)
+               sp->promisc_flg = 0;
+       if (sp->m_cast_flg) {
+               sp->m_cast_flg = 0;
+               sp->all_multi_pos= 0;
+       }
 
        /* Setting its receive mode */
        s2io_set_multicast(dev);
@@ -6380,7 +6354,7 @@ static int s2io_card_up(nic_t * sp)
 
 static void s2io_restart_nic(struct work_struct *work)
 {
-       nic_t *sp = container_of(work, nic_t, rst_timer_task);
+       struct s2io_nic *sp = container_of(work, struct s2io_nic, rst_timer_task);
        struct net_device *dev = sp->dev;
 
        s2io_card_down(sp);
@@ -6409,7 +6383,7 @@ static void s2io_restart_nic(struct work_struct *work)
 
 static void s2io_tx_watchdog(struct net_device *dev)
 {
-       nic_t *sp = dev->priv;
+       struct s2io_nic *sp = dev->priv;
 
        if (netif_carrier_ok(dev)) {
                schedule_work(&sp->rst_timer_task);
@@ -6434,16 +6408,16 @@ static void s2io_tx_watchdog(struct net_device *dev)
  *   Return value:
  *   SUCCESS on success and -1 on failure.
  */
-static int rx_osm_handler(ring_info_t *ring_data, RxD_t * rxdp)
+static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
 {
-       nic_t *sp = ring_data->nic;
+       struct s2io_nic *sp = ring_data->nic;
        struct net_device *dev = (struct net_device *) sp->dev;
        struct sk_buff *skb = (struct sk_buff *)
                ((unsigned long) rxdp->Host_Control);
        int ring_no = ring_data->ring_no;
        u16 l3_csum, l4_csum;
        unsigned long long err = rxdp->Control_1 & RXD_T_CODE;
-       lro_t *lro;
+       struct lro *lro;
 
        skb->dev = dev;
 
@@ -6488,7 +6462,7 @@ static int rx_osm_handler(ring_info_t *ring_data, RxD_t * rxdp)
                int buf2_len = RXD_GET_BUFFER2_SIZE_3(rxdp->Control_2);
                unsigned char *buff = skb_push(skb, buf0_len);
 
-               buffAdd_t *ba = &ring_data->ba[get_block][get_off];
+               struct buffAdd *ba = &ring_data->ba[get_block][get_off];
                sp->stats.rx_bytes += buf0_len + buf2_len;
                memcpy(buff, ba->ba_0, buf0_len);
 
@@ -6498,7 +6472,6 @@ static int rx_osm_handler(ring_info_t *ring_data, RxD_t * rxdp)
                        skb_put(skb, buf1_len);
                        skb->len += buf2_len;
                        skb->data_len += buf2_len;
-                       skb->truesize += buf2_len;
                        skb_put(skb_shinfo(skb)->frag_list, buf2_len);
                        sp->stats.rx_bytes += buf1_len;
 
@@ -6582,23 +6555,20 @@ static int rx_osm_handler(ring_info_t *ring_data, RxD_t * rxdp)
 
        if (!sp->lro) {
                skb->protocol = eth_type_trans(skb, dev);
-#ifdef CONFIG_S2IO_NAPI
-               if (sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2)) {
-                       /* Queueing the vlan frame to the upper layer */
-                       vlan_hwaccel_receive_skb(skb, sp->vlgrp,
-                               RXD_GET_VLAN_TAG(rxdp->Control_2));
-               } else {
-                       netif_receive_skb(skb);
-               }
-#else
                if (sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2)) {
                        /* Queueing the vlan frame to the upper layer */
-                       vlan_hwaccel_rx(skb, sp->vlgrp,
-                               RXD_GET_VLAN_TAG(rxdp->Control_2));
+                       if (napi)
+                               vlan_hwaccel_receive_skb(skb, sp->vlgrp,
+                                       RXD_GET_VLAN_TAG(rxdp->Control_2));
+                       else
+                               vlan_hwaccel_rx(skb, sp->vlgrp,
+                                       RXD_GET_VLAN_TAG(rxdp->Control_2));
                } else {
-                       netif_rx(skb);
+                       if (napi)
+                               netif_receive_skb(skb);
+                       else
+                               netif_rx(skb);
                }
-#endif
        } else {
 send_up:
                queue_rx_frame(skb);
@@ -6622,7 +6592,7 @@ aggregate:
  *  void.
  */
 
-static void s2io_link(nic_t * sp, int link)
+static void s2io_link(struct s2io_nic * sp, int link)
 {
        struct net_device *dev = (struct net_device *) sp->dev;
 
@@ -6666,7 +6636,7 @@ static int get_xena_rev_id(struct pci_dev *pdev)
  *  void
  */
 
-static void s2io_init_pci(nic_t * sp)
+static void s2io_init_pci(struct s2io_nic * sp)
 {
        u16 pci_cmd = 0, pcix_cmd = 0;
 
@@ -6699,13 +6669,9 @@ static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type)
                DBG_PRINT(ERR_DBG, "s2io: Default to 8 Rx rings\n");
                rx_ring_num = 8;
        }
-#ifdef CONFIG_S2IO_NAPI
-       if (*dev_intr_type != INTA) {
-               DBG_PRINT(ERR_DBG, "s2io: NAPI cannot be enabled when "
-                         "MSI/MSI-X is enabled. Defaulting to INTA\n");
-               *dev_intr_type = INTA;
-       }
-#endif
+       if (*dev_intr_type != INTA)
+               napi = 0;
+
 #ifndef CONFIG_PCI_MSI
        if (*dev_intr_type != INTA) {
                DBG_PRINT(ERR_DBG, "s2io: This kernel does not support"
@@ -6726,6 +6692,8 @@ static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type)
                                        "Defaulting to INTA\n");
                *dev_intr_type = INTA;
        }
+       if ( (rx_ring_num > 1) && (*dev_intr_type != INTA) )
+               napi = 0;
        if (rx_ring_mode > 3) {
                DBG_PRINT(ERR_DBG, "s2io: Requested ring mode not supported\n");
                DBG_PRINT(ERR_DBG, "s2io: Defaulting to 3-buffer mode\n");
@@ -6751,15 +6719,15 @@ static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type)
 static int __devinit
 s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
 {
-       nic_t *sp;
+       struct s2io_nic *sp;
        struct net_device *dev;
        int i, j, ret;
        int dma_flag = FALSE;
        u32 mac_up, mac_down;
        u64 val64 = 0, tmp64 = 0;
-       XENA_dev_config_t __iomem *bar0 = NULL;
+       struct XENA_dev_config __iomem *bar0 = NULL;
        u16 subid;
-       mac_info_t *mac_control;
+       struct mac_info *mac_control;
        struct config_param *config;
        int mode;
        u8 dev_intr_type = intr_type;
@@ -6814,7 +6782,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
                }
        }
 
-       dev = alloc_etherdev(sizeof(nic_t));
+       dev = alloc_etherdev(sizeof(struct s2io_nic));
        if (dev == NULL) {
                DBG_PRINT(ERR_DBG, "Device allocation failed\n");
                pci_disable_device(pdev);
@@ -6829,7 +6797,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
 
        /*  Private member variable initialized to s2io NIC structure */
        sp = dev->priv;
-       memset(sp, 0, sizeof(nic_t));
+       memset(sp, 0, sizeof(struct s2io_nic));
        sp->dev = dev;
        sp->pdev = pdev;
        sp->high_dma_flag = dma_flag;
@@ -6925,7 +6893,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
        sp->bar0 = ioremap(pci_resource_start(pdev, 0),
                                     pci_resource_len(pdev, 0));
        if (!sp->bar0) {
-               DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem1\n",
+               DBG_PRINT(ERR_DBG, "%s: Neterion: cannot remap io mem1\n",
                          dev->name);
                ret = -ENOMEM;
                goto bar0_remap_failed;
@@ -6934,7 +6902,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
        sp->bar1 = ioremap(pci_resource_start(pdev, 2),
                                     pci_resource_len(pdev, 2));
        if (!sp->bar1) {
-               DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem2\n",
+               DBG_PRINT(ERR_DBG, "%s: Neterion: cannot remap io mem2\n",
                          dev->name);
                ret = -ENOMEM;
                goto bar1_remap_failed;
@@ -6945,7 +6913,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
 
        /* Initializing the BAR1 address as the start of the FIFO pointer. */
        for (j = 0; j < MAX_TX_FIFOS; j++) {
-               mac_control->tx_FIFO_start[j] = (TxFIFO_element_t __iomem *)
+               mac_control->tx_FIFO_start[j] = (struct TxFIFO_element __iomem *)
                    (sp->bar1 + (j * 0x00020000));
        }
 
@@ -6966,10 +6934,8 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
         * will use eth_mac_addr() for  dev->set_mac_address
         * mac address will be set every time dev->open() is called
         */
-#if defined(CONFIG_S2IO_NAPI)
        dev->poll = s2io_poll;
        dev->weight = 32;
-#endif
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
        dev->poll_controller = s2io_netpoll;
@@ -6978,13 +6944,9 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
        dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
        if (sp->high_dma_flag == TRUE)
                dev->features |= NETIF_F_HIGHDMA;
-#ifdef NETIF_F_TSO
        dev->features |= NETIF_F_TSO;
-#endif
-#ifdef NETIF_F_TSO6
        dev->features |= NETIF_F_TSO6;
-#endif
-       if (sp->device_type & XFRAME_II_DEVICE) {
+       if ((sp->device_type & XFRAME_II_DEVICE) && (ufo))  {
                dev->features |= NETIF_F_UFO;
                dev->features |= NETIF_F_HW_CSUM;
        }
@@ -7065,9 +7027,9 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
 
        /* Initialize spinlocks */
        spin_lock_init(&sp->tx_lock);
-#ifndef CONFIG_S2IO_NAPI
-       spin_lock_init(&sp->put_lock);
-#endif
+
+       if (!napi)
+               spin_lock_init(&sp->put_lock);
        spin_lock_init(&sp->rx_lock);
 
        /*
@@ -7098,13 +7060,14 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
        DBG_PRINT(ERR_DBG, "%s: Driver version %s\n", dev->name,
                  s2io_driver_version);
        DBG_PRINT(ERR_DBG, "%s: MAC ADDR: "
-                         "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name,
+                         "%02x:%02x:%02x:%02x:%02x:%02x", dev->name,
                          sp->def_mac_addr[0].mac_addr[0],
                          sp->def_mac_addr[0].mac_addr[1],
                          sp->def_mac_addr[0].mac_addr[2],
                          sp->def_mac_addr[0].mac_addr[3],
                          sp->def_mac_addr[0].mac_addr[4],
                          sp->def_mac_addr[0].mac_addr[5]);
+       DBG_PRINT(ERR_DBG, "SERIAL NUMBER: %s\n", sp->serial_num);
        if (sp->device_type & XFRAME_II_DEVICE) {
                mode = s2io_print_pci_mode(sp);
                if (mode < 0) {
@@ -7128,9 +7091,9 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
                                                dev->name);
                    break;
        }
-#ifdef CONFIG_S2IO_NAPI
-       DBG_PRINT(ERR_DBG, "%s: NAPI enabled\n", dev->name);
-#endif
+
+       if (napi)
+               DBG_PRINT(ERR_DBG, "%s: NAPI enabled\n", dev->name);
        switch(sp->intr_type) {
                case INTA:
                    DBG_PRINT(ERR_DBG, "%s: Interrupt type INTA\n", dev->name);
@@ -7145,7 +7108,9 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
        if (sp->lro)
                DBG_PRINT(ERR_DBG, "%s: Large receive offload enabled\n",
                          dev->name);
-
+       if (ufo)
+               DBG_PRINT(ERR_DBG, "%s: UDP Fragmentation Offload(UFO)"
+                                       " enabled\n", dev->name);
        /* Initialize device name */
        sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
 
@@ -7202,7 +7167,7 @@ static void __devexit s2io_rem_nic(struct pci_dev *pdev)
 {
        struct net_device *dev =
            (struct net_device *) pci_get_drvdata(pdev);
-       nic_t *sp;
+       struct s2io_nic *sp;
 
        if (dev == NULL) {
                DBG_PRINT(ERR_DBG, "Driver Data is NULL!!\n");
@@ -7215,7 +7180,6 @@ static void __devexit s2io_rem_nic(struct pci_dev *pdev)
        free_shared_mem(sp);
        iounmap(sp->bar0);
        iounmap(sp->bar1);
-       pci_disable_device(pdev);
        if (sp->intr_type != MSI_X)
                pci_release_regions(pdev);
        else {
@@ -7226,6 +7190,7 @@ static void __devexit s2io_rem_nic(struct pci_dev *pdev)
        }
        pci_set_drvdata(pdev, NULL);
        free_netdev(dev);
+       pci_disable_device(pdev);
 }
 
 /**
@@ -7244,7 +7209,7 @@ int __init s2io_starter(void)
  * Description: This function is the cleanup routine for the driver. It unregist * ers the driver.
  */
 
-static void s2io_closer(void)
+static __exit void s2io_closer(void)
 {
        pci_unregister_driver(&s2io_driver);
        DBG_PRINT(INIT_DBG, "cleanup done\n");
@@ -7254,7 +7219,7 @@ module_init(s2io_starter);
 module_exit(s2io_closer);
 
 static int check_L2_lro_capable(u8 *buffer, struct iphdr **ip,
-               struct tcphdr **tcp, RxD_t *rxdp)
+               struct tcphdr **tcp, struct RxD_t *rxdp)
 {
        int ip_off;
        u8 l2_type = (u8)((rxdp->Control_1 >> 37) & 0x7), ip_len;
@@ -7288,7 +7253,7 @@ static int check_L2_lro_capable(u8 *buffer, struct iphdr **ip,
        return 0;
 }
 
-static int check_for_socket_match(lro_t *lro, struct iphdr *ip,
+static int check_for_socket_match(struct lro *lro, struct iphdr *ip,
                                  struct tcphdr *tcp)
 {
        DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
@@ -7303,7 +7268,7 @@ static inline int get_l4_pyld_length(struct iphdr *ip, struct tcphdr *tcp)
        return(ntohs(ip->tot_len) - (ip->ihl << 2) - (tcp->doff << 2));
 }
 
-static void initiate_new_session(lro_t *lro, u8 *l2h,
+static void initiate_new_session(struct lro *lro, u8 *l2h,
                     struct iphdr *ip, struct tcphdr *tcp, u32 tcp_pyld_len)
 {
        DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
@@ -7329,12 +7294,12 @@ static void initiate_new_session(lro_t *lro, u8 *l2h,
        lro->in_use = 1;
 }
 
-static void update_L3L4_header(nic_t *sp, lro_t *lro)
+static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro)
 {
        struct iphdr *ip = lro->iph;
        struct tcphdr *tcp = lro->tcph;
        u16 nchk;
-       StatInfo_t *statinfo = sp->mac_control.stats_info;
+       struct stat_block *statinfo = sp->mac_control.stats_info;
        DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
 
        /* Update L3 header */
@@ -7360,7 +7325,7 @@ static void update_L3L4_header(nic_t *sp, lro_t *lro)
        statinfo->sw_stat.num_aggregations++;
 }
 
-static void aggregate_new_rx(lro_t *lro, struct iphdr *ip,
+static void aggregate_new_rx(struct lro *lro, struct iphdr *ip,
                struct tcphdr *tcp, u32 l4_pyld)
 {
        DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
@@ -7382,7 +7347,7 @@ static void aggregate_new_rx(lro_t *lro, struct iphdr *ip,
        }
 }
 
-static int verify_l3_l4_lro_capable(lro_t *l_lro, struct iphdr *ip,
+static int verify_l3_l4_lro_capable(struct lro *l_lro, struct iphdr *ip,
                                    struct tcphdr *tcp, u32 tcp_pyld_len)
 {
        u8 *ptr;
@@ -7440,8 +7405,8 @@ static int verify_l3_l4_lro_capable(lro_t *l_lro, struct iphdr *ip,
 }
 
 static int
-s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, lro_t **lro,
-                     RxD_t *rxdp, nic_t *sp)
+s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, struct lro **lro,
+                     struct RxD_t *rxdp, struct s2io_nic *sp)
 {
        struct iphdr *ip;
        struct tcphdr *tcph;
@@ -7458,7 +7423,7 @@ s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, lro_t **lro,
        tcph = (struct tcphdr *)*tcp;
        *tcp_len = get_l4_pyld_length(ip, tcph);
        for (i=0; i<MAX_LRO_SESSIONS; i++) {
-               lro_t *l_lro = &sp->lro0_n[i];
+               struct lro *l_lro = &sp->lro0_n[i];
                if (l_lro->in_use) {
                        if (check_for_socket_match(l_lro, ip, tcph))
                                continue;
@@ -7496,7 +7461,7 @@ s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, lro_t **lro,
                }
 
                for (i=0; i<MAX_LRO_SESSIONS; i++) {
-                       lro_t *l_lro = &sp->lro0_n[i];
+                       struct lro *l_lro = &sp->lro0_n[i];
                        if (!(l_lro->in_use)) {
                                *lro = l_lro;
                                ret = 3; /* Begin anew */
@@ -7535,9 +7500,9 @@ s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, lro_t **lro,
        return ret;
 }
 
-static void clear_lro_session(lro_t *lro)
+static void clear_lro_session(struct lro *lro)
 {
-       static u16 lro_struct_size = sizeof(lro_t);
+       static u16 lro_struct_size = sizeof(struct lro);
 
        memset(lro, 0, lro_struct_size);
 }
@@ -7547,14 +7512,14 @@ static void queue_rx_frame(struct sk_buff *skb)
        struct net_device *dev = skb->dev;
 
        skb->protocol = eth_type_trans(skb, dev);
-#ifdef CONFIG_S2IO_NAPI
-       netif_receive_skb(skb);
-#else
-       netif_rx(skb);
-#endif
+       if (napi)
+               netif_receive_skb(skb);
+       else
+               netif_rx(skb);
 }
 
-static void lro_append_pkt(nic_t *sp, lro_t *lro, struct sk_buff *skb,
+static void lro_append_pkt(struct s2io_nic *sp, struct lro *lro,
+                          struct sk_buff *skb,
                           u32 tcp_len)
 {
        struct sk_buff *first = lro->parent;
@@ -7566,6 +7531,7 @@ static void lro_append_pkt(nic_t *sp, lro_t *lro, struct sk_buff *skb,
                lro->last_frag->next = skb;
        else
                skb_shinfo(first)->frag_list = skb;
+       first->truesize += skb->truesize;
        lro->last_frag = skb;
        sp->mac_control.stats_info->sw_stat.clubbed_frms_cnt++;
        return;
index 3b0bafd273c8c74fdd95b5120d5c9f0c7a9aad42..a5e1a513deb53039d1ac97e0514d3fe940bd382d 100644 (file)
@@ -30,6 +30,8 @@
 #undef SUCCESS
 #define SUCCESS 0
 #define FAILURE -1
+#define S2IO_MINUS_ONE 0xFFFFFFFFFFFFFFFFULL
+#define S2IO_MAX_PCI_CONFIG_SPACE_REINIT 100
 
 #define CHECKBIT(value, nbit) (value & (1 << nbit))
 
@@ -37,7 +39,7 @@
 #define MAX_FLICKER_TIME       60000 /* 60 Secs */
 
 /* Maximum outstanding splits to be configured into xena. */
-typedef enum xena_max_outstanding_splits {
+enum {
        XENA_ONE_SPLIT_TRANSACTION = 0,
        XENA_TWO_SPLIT_TRANSACTION = 1,
        XENA_THREE_SPLIT_TRANSACTION = 2,
@@ -46,7 +48,7 @@ typedef enum xena_max_outstanding_splits {
        XENA_TWELVE_SPLIT_TRANSACTION = 5,
        XENA_SIXTEEN_SPLIT_TRANSACTION = 6,
        XENA_THIRTYTWO_SPLIT_TRANSACTION = 7
-} xena_max_outstanding_splits;
+};
 #define XENA_MAX_OUTSTANDING_SPLITS(n) (n << 4)
 
 /*  OS concerned variables and constants */
@@ -77,7 +79,7 @@ static int debug_level = ERR_DBG;
 #define S2IO_JUMBO_SIZE 9600
 
 /* Driver statistics maintained by driver */
-typedef struct {
+struct swStat {
        unsigned long long single_ecc_errs;
        unsigned long long double_ecc_errs;
        unsigned long long parity_err_cnt;
@@ -92,10 +94,10 @@ typedef struct {
        unsigned long long flush_max_pkts;
        unsigned long long sum_avg_pkts_aggregated;
        unsigned long long num_aggregations;
-} swStat_t;
+};
 
 /* Xpak releated alarm and warnings */
-typedef struct {
+struct xpakStat {
        u64 alarm_transceiver_temp_high;
        u64 alarm_transceiver_temp_low;
        u64 alarm_laser_bias_current_high;
@@ -110,11 +112,11 @@ typedef struct {
        u64 warn_laser_output_power_low;
        u64 xpak_regs_stat;
        u32 xpak_timer_count;
-} xpakStat_t;
+};
 
 
 /* The statistics block of Xena */
-typedef struct stat_block {
+struct stat_block {
 /* Tx MAC statistics counters. */
        __le32 tmac_data_octets;
        __le32 tmac_frms;
@@ -290,9 +292,9 @@ typedef struct stat_block {
        __le32 reserved_14;
        __le32 link_fault_cnt;
        u8  buffer[20];
-       swStat_t sw_stat;
-       xpakStat_t xpak_stat;
-} StatInfo_t;
+       struct swStat sw_stat;
+       struct xpakStat xpak_stat;
+};
 
 /*
  * Structures representing different init time configuration
@@ -315,7 +317,7 @@ static int fifo_map[][MAX_TX_FIFOS] = {
 };
 
 /* Maintains Per FIFO related information. */
-typedef struct tx_fifo_config {
+struct tx_fifo_config {
 #define        MAX_AVAILABLE_TXDS      8192
        u32 fifo_len;           /* specifies len of FIFO upto 8192, ie no of TxDLs */
 /* Priority definition */
@@ -332,11 +334,11 @@ typedef struct tx_fifo_config {
        u8 f_no_snoop;
 #define NO_SNOOP_TXD                0x01
 #define NO_SNOOP_TXD_BUFFER          0x02
-} tx_fifo_config_t;
+};
 
 
 /* Maintains per Ring related information */
-typedef struct rx_ring_config {
+struct rx_ring_config {
        u32 num_rxd;            /*No of RxDs per Rx Ring */
 #define RX_RING_PRI_0               0  /* highest */
 #define RX_RING_PRI_1               1
@@ -357,7 +359,7 @@ typedef struct rx_ring_config {
        u8 f_no_snoop;
 #define NO_SNOOP_RXD                0x01
 #define NO_SNOOP_RXD_BUFFER         0x02
-} rx_ring_config_t;
+};
 
 /* This structure provides contains values of the tunable parameters
  * of the H/W
@@ -367,7 +369,7 @@ struct config_param {
        u32 tx_fifo_num;        /*Number of Tx FIFOs */
 
        u8 fifo_mapping[MAX_TX_FIFOS];
-       tx_fifo_config_t tx_cfg[MAX_TX_FIFOS];  /*Per-Tx FIFO config */
+       struct tx_fifo_config tx_cfg[MAX_TX_FIFOS];     /*Per-Tx FIFO config */
        u32 max_txds;           /*Max no. of Tx buffer descriptor per TxDL */
        u64 tx_intr_type;
        /* Specifies if Tx Intr is UTILZ or PER_LIST type. */
@@ -376,7 +378,7 @@ struct config_param {
        u32 rx_ring_num;        /*Number of receive rings */
 #define MAX_RX_BLOCKS_PER_RING  150
 
-       rx_ring_config_t rx_cfg[MAX_RX_RINGS];  /*Per-Rx Ring config */
+       struct rx_ring_config rx_cfg[MAX_RX_RINGS];     /*Per-Rx Ring config */
        u8 bimodal;             /*Flag for setting bimodal interrupts*/
 
 #define HEADER_ETHERNET_II_802_3_SIZE 14
@@ -395,14 +397,14 @@ struct config_param {
 };
 
 /* Structure representing MAC Addrs */
-typedef struct mac_addr {
+struct mac_addr {
        u8 mac_addr[ETH_ALEN];
-} macaddr_t;
+};
 
 /* Structure that represent every FIFO element in the BAR1
  * Address location.
  */
-typedef struct _TxFIFO_element {
+struct TxFIFO_element {
        u64 TxDL_Pointer;
 
        u64 List_Control;
@@ -413,10 +415,10 @@ typedef struct _TxFIFO_element {
 #define TX_FIFO_SPECIAL_FUNC           BIT(23)
 #define TX_FIFO_DS_NO_SNOOP            BIT(31)
 #define TX_FIFO_BUFF_NO_SNOOP          BIT(30)
-} TxFIFO_element_t;
+};
 
 /* Tx descriptor structure */
-typedef struct _TxD {
+struct TxD {
        u64 Control_1;
 /* bit mask */
 #define TXD_LIST_OWN_XENA       BIT(7)
@@ -447,16 +449,16 @@ typedef struct _TxD {
 
        u64 Buffer_Pointer;
        u64 Host_Control;       /* reserved for host */
-} TxD_t;
+};
 
 /* Structure to hold the phy and virt addr of every TxDL. */
-typedef struct list_info_hold {
+struct list_info_hold {
        dma_addr_t list_phy_addr;
        void *list_virt_addr;
-} list_info_hold_t;
+};
 
 /* Rx descriptor structure for 1 buffer mode */
-typedef struct _RxD_t {
+struct RxD_t {
        u64 Host_Control;       /* reserved for host */
        u64 Control_1;
 #define RXD_OWN_XENA            BIT(7)
@@ -481,21 +483,21 @@ typedef struct _RxD_t {
 #define SET_NUM_TAG(val)       vBIT(val,16,32)
 
 
-} RxD_t;
+};
 /* Rx descriptor structure for 1 buffer mode */
-typedef struct _RxD1_t {
-       struct _RxD_t h;
+struct RxD1 {
+       struct RxD_t h;
 
 #define MASK_BUFFER0_SIZE_1       vBIT(0x3FFF,2,14)
 #define SET_BUFFER0_SIZE_1(val)   vBIT(val,2,14)
 #define RXD_GET_BUFFER0_SIZE_1(_Control_2) \
        (u16)((_Control_2 & MASK_BUFFER0_SIZE_1) >> 48)
        u64 Buffer0_ptr;
-} RxD1_t;
+};
 /* Rx descriptor structure for 3 or 2 buffer mode */
 
-typedef struct _RxD3_t {
-       struct _RxD_t h;
+struct RxD3 {
+       struct RxD_t h;
 
 #define MASK_BUFFER0_SIZE_3       vBIT(0xFF,2,14)
 #define MASK_BUFFER1_SIZE_3       vBIT(0xFFFF,16,16)
@@ -515,15 +517,15 @@ typedef struct _RxD3_t {
        u64 Buffer0_ptr;
        u64 Buffer1_ptr;
        u64 Buffer2_ptr;
-} RxD3_t;
+};
 
 
 /* Structure that represents the Rx descriptor block which contains
  * 128 Rx descriptors.
  */
-typedef struct _RxD_block {
+struct RxD_block {
 #define MAX_RXDS_PER_BLOCK_1            127
-       RxD1_t rxd[MAX_RXDS_PER_BLOCK_1];
+       struct RxD1 rxd[MAX_RXDS_PER_BLOCK_1];
 
        u64 reserved_0;
 #define END_OF_BLOCK    0xFEFFFFFFFFFFFFFFULL
@@ -533,22 +535,22 @@ typedef struct _RxD_block {
        u64 pNext_RxD_Blk_physical;     /* Buff0_ptr.In a 32 bit arch
                                         * the upper 32 bits should
                                         * be 0 */
-} RxD_block_t;
+};
 
 #define SIZE_OF_BLOCK  4096
 
-#define RXD_MODE_1     0
-#define RXD_MODE_3A    1
-#define RXD_MODE_3B    2
+#define RXD_MODE_1     0 /* One Buffer mode */
+#define RXD_MODE_3A    1 /* Three Buffer mode */
+#define RXD_MODE_3B    2 /* Two Buffer mode */
 
 /* Structure to hold virtual addresses of Buf0 and Buf1 in
  * 2buf mode. */
-typedef struct bufAdd {
+struct buffAdd {
        void *ba_0_org;
        void *ba_1_org;
        void *ba_0;
        void *ba_1;
-} buffAdd_t;
+};
 
 /* Structure which stores all the MAC control parameters */
 
@@ -556,43 +558,46 @@ typedef struct bufAdd {
  * from which the Rx Interrupt processor can start picking
  * up the RxDs for processing.
  */
-typedef struct _rx_curr_get_info_t {
+struct rx_curr_get_info {
        u32 block_index;
        u32 offset;
        u32 ring_len;
-} rx_curr_get_info_t;
+};
 
-typedef rx_curr_get_info_t rx_curr_put_info_t;
+struct rx_curr_put_info {
+       u32 block_index;
+       u32 offset;
+       u32 ring_len;
+};
 
 /* This structure stores the offset of the TxDl in the FIFO
  * from which the Tx Interrupt processor can start picking
  * up the TxDLs for send complete interrupt processing.
  */
-typedef struct {
+struct tx_curr_get_info {
        u32 offset;
        u32 fifo_len;
-} tx_curr_get_info_t;
-
-typedef tx_curr_get_info_t tx_curr_put_info_t;
+};
 
+struct tx_curr_put_info {
+       u32 offset;
+       u32 fifo_len;
+};
 
-typedef struct rxd_info {
+struct rxd_info {
        void *virt_addr;
        dma_addr_t dma_addr;
-}rxd_info_t;
+};
 
 /* Structure that holds the Phy and virt addresses of the Blocks */
-typedef struct rx_block_info {
+struct rx_block_info {
        void *block_virt_addr;
        dma_addr_t block_dma_addr;
-       rxd_info_t *rxds;
-} rx_block_info_t;
-
-/* pre declaration of the nic structure */
-typedef struct s2io_nic nic_t;
+       struct rxd_info *rxds;
+};
 
 /* Ring specific structure */
-typedef struct ring_info {
+struct ring_info {
        /* The ring number */
        int ring_no;
 
@@ -600,7 +605,7 @@ typedef struct ring_info {
         *  Place holders for the virtual and physical addresses of
         *  all the Rx Blocks
         */
-       rx_block_info_t rx_blocks[MAX_RX_BLOCKS_PER_RING];
+       struct rx_block_info rx_blocks[MAX_RX_BLOCKS_PER_RING];
        int block_count;
        int pkt_cnt;
 
@@ -608,26 +613,24 @@ typedef struct ring_info {
         * Put pointer info which indictes which RxD has to be replenished
         * with a new buffer.
         */
-       rx_curr_put_info_t rx_curr_put_info;
+       struct rx_curr_put_info rx_curr_put_info;
 
        /*
         * Get pointer info which indictes which is the last RxD that was
         * processed by the driver.
         */
-       rx_curr_get_info_t rx_curr_get_info;
+       struct rx_curr_get_info rx_curr_get_info;
 
-#ifndef CONFIG_S2IO_NAPI
        /* Index to the absolute position of the put pointer of Rx ring */
        int put_pos;
-#endif
 
        /* Buffer Address store. */
-       buffAdd_t **ba;
-       nic_t *nic;
-} ring_info_t;
+       struct buffAdd **ba;
+       struct s2io_nic *nic;
+};
 
 /* Fifo specific structure */
-typedef struct fifo_info {
+struct fifo_info {
        /* FIFO number */
        int fifo_no;
 
@@ -635,40 +638,40 @@ typedef struct fifo_info {
        int max_txds;
 
        /* Place holder of all the TX List's Phy and Virt addresses. */
-       list_info_hold_t *list_info;
+       struct list_info_hold *list_info;
 
        /*
         * Current offset within the tx FIFO where driver would write
         * new Tx frame
         */
-       tx_curr_put_info_t tx_curr_put_info;
+       struct tx_curr_put_info tx_curr_put_info;
 
        /*
         * Current offset within tx FIFO from where the driver would start freeing
         * the buffers
         */
-       tx_curr_get_info_t tx_curr_get_info;
+       struct tx_curr_get_info tx_curr_get_info;
 
-       nic_t *nic;
-}fifo_info_t;
+       struct s2io_nic *nic;
+};
 
 /* Information related to the Tx and Rx FIFOs and Rings of Xena
  * is maintained in this structure.
  */
-typedef struct mac_info {
+struct mac_info {
 /* tx side stuff */
        /* logical pointer of start of each Tx FIFO */
-       TxFIFO_element_t __iomem *tx_FIFO_start[MAX_TX_FIFOS];
+       struct TxFIFO_element __iomem *tx_FIFO_start[MAX_TX_FIFOS];
 
        /* Fifo specific structure */
-       fifo_info_t fifos[MAX_TX_FIFOS];
+       struct fifo_info fifos[MAX_TX_FIFOS];
 
        /* Save virtual address of TxD page with zero DMA addr(if any) */
        void *zerodma_virt_addr;
 
 /* rx side stuff */
        /* Ring specific structure */
-       ring_info_t rings[MAX_RX_RINGS];
+       struct ring_info rings[MAX_RX_RINGS];
 
        u16 rmac_pause_time;
        u16 mc_pause_threshold_q0q3;
@@ -677,14 +680,14 @@ typedef struct mac_info {
        void *stats_mem;        /* orignal pointer to allocated mem */
        dma_addr_t stats_mem_phy;       /* Physical address of the stat block */
        u32 stats_mem_sz;
-       StatInfo_t *stats_info; /* Logical address of the stat block */
-} mac_info_t;
+       struct stat_block *stats_info;  /* Logical address of the stat block */
+};
 
 /* structure representing the user defined MAC addresses */
-typedef struct {
+struct usr_addr {
        char addr[ETH_ALEN];
        int usage_cnt;
-} usr_addr_t;
+};
 
 /* Default Tunable parameters of the NIC. */
 #define DEFAULT_FIFO_0_LEN 4096
@@ -717,7 +720,7 @@ struct msix_info_st {
 };
 
 /* Data structure to represent a LRO session */
-typedef struct lro {
+struct lro {
        struct sk_buff  *parent;
        struct sk_buff  *last_frag;
        u8              *l2h;
@@ -733,20 +736,18 @@ typedef struct lro {
        u32             cur_tsval;
        u32             cur_tsecr;
        u8              saw_ts;
-}lro_t;
+};
 
 /* Structure representing one instance of the NIC */
 struct s2io_nic {
        int rxd_mode;
-#ifdef CONFIG_S2IO_NAPI
        /*
         * Count of packets to be processed in a given iteration, it will be indicated
         * by the quota field of the device structure when NAPI is enabled.
         */
        int pkts_to_process;
-#endif
        struct net_device *dev;
-       mac_info_t mac_control;
+       struct mac_info mac_control;
        struct config_param config;
        struct pci_dev *pdev;
        void __iomem *bar0;
@@ -754,8 +755,8 @@ struct s2io_nic {
 #define MAX_MAC_SUPPORTED   16
 #define MAX_SUPPORTED_MULTICASTS MAX_MAC_SUPPORTED
 
-       macaddr_t def_mac_addr[MAX_MAC_SUPPORTED];
-       macaddr_t pre_mac_addr[MAX_MAC_SUPPORTED];
+       struct mac_addr def_mac_addr[MAX_MAC_SUPPORTED];
+       struct mac_addr pre_mac_addr[MAX_MAC_SUPPORTED];
 
        struct net_device_stats stats;
        int high_dma_flag;
@@ -775,9 +776,7 @@ struct s2io_nic {
        atomic_t rx_bufs_left[MAX_RX_RINGS];
 
        spinlock_t tx_lock;
-#ifndef CONFIG_S2IO_NAPI
        spinlock_t put_lock;
-#endif
 
 #define PROMISC     1
 #define ALL_MULTI   2
@@ -785,7 +784,7 @@ struct s2io_nic {
 #define MAX_ADDRS_SUPPORTED 64
        u16 usr_addr_count;
        u16 mc_addr_count;
-       usr_addr_t usr_addrs[MAX_ADDRS_SUPPORTED];
+       struct usr_addr usr_addrs[MAX_ADDRS_SUPPORTED];
 
        u16 m_cast_flg;
        u16 all_multi_pos;
@@ -841,7 +840,7 @@ struct s2io_nic {
        u8 device_type;
 
 #define MAX_LRO_SESSIONS       32
-       lro_t lro0_n[MAX_LRO_SESSIONS];
+       struct lro lro0_n[MAX_LRO_SESSIONS];
        unsigned long   clubbed_frms_cnt;
        unsigned long   sending_both;
        u8              lro;
@@ -855,8 +854,9 @@ struct s2io_nic {
        spinlock_t      rx_lock;
        atomic_t        isr_cnt;
        u64 *ufo_in_band_v;
-#define VPD_PRODUCT_NAME_LEN 50
-       u8  product_name[VPD_PRODUCT_NAME_LEN];
+#define VPD_STRING_LEN 80
+       u8  product_name[VPD_STRING_LEN];
+       u8  serial_num[VPD_STRING_LEN];
 };
 
 #define RESET_ERROR 1;
@@ -975,43 +975,50 @@ static void __devexit s2io_rem_nic(struct pci_dev *pdev);
 static int init_shared_mem(struct s2io_nic *sp);
 static void free_shared_mem(struct s2io_nic *sp);
 static int init_nic(struct s2io_nic *nic);
-static void rx_intr_handler(ring_info_t *ring_data);
-static void tx_intr_handler(fifo_info_t *fifo_data);
+static void rx_intr_handler(struct ring_info *ring_data);
+static void tx_intr_handler(struct fifo_info *fifo_data);
 static void alarm_intr_handler(struct s2io_nic *sp);
 
 static int s2io_starter(void);
+static void s2io_closer(void);
 static void s2io_tx_watchdog(struct net_device *dev);
 static void s2io_tasklet(unsigned long dev_addr);
 static void s2io_set_multicast(struct net_device *dev);
-static int rx_osm_handler(ring_info_t *ring_data, RxD_t * rxdp);
-static void s2io_link(nic_t * sp, int link);
-#if defined(CONFIG_S2IO_NAPI)
+static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp);
+static void s2io_link(struct s2io_nic * sp, int link);
+static void s2io_reset(struct s2io_nic * sp);
 static int s2io_poll(struct net_device *dev, int *budget);
-#endif
-static void s2io_init_pci(nic_t * sp);
+static void s2io_init_pci(struct s2io_nic * sp);
 static int s2io_set_mac_addr(struct net_device *dev, u8 * addr);
 static void s2io_alarm_handle(unsigned long data);
-static int s2io_enable_msi(nic_t *nic);
+static int s2io_enable_msi(struct s2io_nic *nic);
 static irqreturn_t s2io_msi_handle(int irq, void *dev_id);
 static irqreturn_t
 s2io_msix_ring_handle(int irq, void *dev_id);
 static irqreturn_t
 s2io_msix_fifo_handle(int irq, void *dev_id);
 static irqreturn_t s2io_isr(int irq, void *dev_id);
-static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag);
+static int verify_xena_quiescence(struct s2io_nic *sp);
 static const struct ethtool_ops netdev_ethtool_ops;
 static void s2io_set_link(struct work_struct *work);
-static int s2io_set_swapper(nic_t * sp);
-static void s2io_card_down(nic_t *nic);
-static int s2io_card_up(nic_t *nic);
+static int s2io_set_swapper(struct s2io_nic * sp);
+static void s2io_card_down(struct s2io_nic *nic);
+static int s2io_card_up(struct s2io_nic *nic);
 static int get_xena_rev_id(struct pci_dev *pdev);
-static void restore_xmsi_data(nic_t *nic);
+static int wait_for_cmd_complete(void *addr, u64 busy_bit);
+static int s2io_add_isr(struct s2io_nic * sp);
+static void s2io_rem_isr(struct s2io_nic * sp);
+
+static void restore_xmsi_data(struct s2io_nic *nic);
 
-static int s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, lro_t **lro, RxD_t *rxdp, nic_t *sp);
-static void clear_lro_session(lro_t *lro);
+static int
+s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, struct lro **lro,
+                     struct RxD_t *rxdp, struct s2io_nic *sp);
+static void clear_lro_session(struct lro *lro);
 static void queue_rx_frame(struct sk_buff *skb);
-static void update_L3L4_header(nic_t *sp, lro_t *lro);
-static void lro_append_pkt(nic_t *sp, lro_t *lro, struct sk_buff *skb, u32 tcp_len);
+static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro);
+static void lro_append_pkt(struct s2io_nic *sp, struct lro *lro,
+                          struct sk_buff *skb, u32 tcp_len);
 
 #define s2io_tcp_mss(skb) skb_shinfo(skb)->gso_size
 #define s2io_udp_mss(skb) skb_shinfo(skb)->gso_size
diff --git a/drivers/net/sc92031.c b/drivers/net/sc92031.c
new file mode 100644 (file)
index 0000000..7f800fe
--- /dev/null
@@ -0,0 +1,1620 @@
+/*  Silan SC92031 PCI Fast Ethernet Adapter driver
+ *
+ *  Based on vendor drivers:
+ *  Silan Fast Ethernet Netcard Driver:
+ *    MODULE_AUTHOR ("gaoyonghong");
+ *    MODULE_DESCRIPTION ("SILAN Fast Ethernet driver");
+ *    MODULE_LICENSE("GPL");
+ *  8139D Fast Ethernet driver:
+ *    (C) 2002 by gaoyonghong
+ *    MODULE_AUTHOR ("gaoyonghong");
+ *    MODULE_DESCRIPTION ("Rsltek 8139D PCI Fast Ethernet Adapter driver");
+ *    MODULE_LICENSE("GPL");
+ *  Both are almost identical and seem to be based on pci-skeleton.c
+ *
+ *  Rewritten for 2.6 by Cesar Eduardo Barros
+ */
+
+/* Note about set_mac_address: I don't know how to change the hardware
+ * matching, so you need to enable IFF_PROMISC when using it.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/dma-mapping.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/crc32.h>
+
+#include <asm/irq.h>
+
+#define PCI_VENDOR_ID_SILAN            0x1904
+#define PCI_DEVICE_ID_SILAN_SC92031    0x2031
+#define PCI_DEVICE_ID_SILAN_8139D      0x8139
+
+#define SC92031_NAME "sc92031"
+#define SC92031_DESCRIPTION "Silan SC92031 PCI Fast Ethernet Adapter driver"
+#define SC92031_VERSION "2.0c"
+
+/* BAR 0 is MMIO, BAR 1 is PIO */
+#ifndef SC92031_USE_BAR
+#define SC92031_USE_BAR 0
+#endif
+
+/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). */
+static int multicast_filter_limit = 64;
+module_param(multicast_filter_limit, int, 0);
+MODULE_PARM_DESC(multicast_filter_limit,
+       "Maximum number of filtered multicast addresses");
+
+static int media;
+module_param(media, int, 0);
+MODULE_PARM_DESC(media, "Media type (0x00 = autodetect,"
+       " 0x01 = 10M half, 0x02 = 10M full,"
+       " 0x04 = 100M half, 0x08 = 100M full)");
+
+/* Size of the in-memory receive ring. */
+#define  RX_BUF_LEN_IDX  3 /* 0==8K, 1==16K, 2==32K, 3==64K ,4==128K*/
+#define  RX_BUF_LEN    (8192 << RX_BUF_LEN_IDX)
+
+/* Number of Tx descriptor registers. */
+#define  NUM_TX_DESC      4
+
+/* max supported ethernet frame size -- must be at least (dev->mtu+14+4).*/
+#define  MAX_ETH_FRAME_SIZE      1536
+
+/* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */
+#define  TX_BUF_SIZE       MAX_ETH_FRAME_SIZE
+#define  TX_BUF_TOT_LEN    (TX_BUF_SIZE * NUM_TX_DESC)
+
+/* The following settings are log_2(bytes)-4:  0 == 16 bytes .. 6==1024, 7==end of packet. */
+#define  RX_FIFO_THRESH    7     /* Rx buffer level before first PCI xfer.  */
+
+/* Time in jiffies before concluding the transmitter is hung. */
+#define  TX_TIMEOUT     (4*HZ)
+
+#define  SILAN_STATS_NUM    2    /* number of ETHTOOL_GSTATS */
+
+/* media options */
+#define  AUTOSELECT    0x00
+#define  M10_HALF      0x01
+#define  M10_FULL      0x02
+#define  M100_HALF     0x04
+#define  M100_FULL     0x08
+
+ /* Symbolic offsets to registers. */
+enum  silan_registers {
+   Config0    = 0x00,         // Config0
+   Config1    = 0x04,         // Config1
+   RxBufWPtr  = 0x08,         // Rx buffer writer poiter
+   IntrStatus = 0x0C,         // Interrupt status
+   IntrMask   = 0x10,         // Interrupt mask
+   RxbufAddr  = 0x14,         // Rx buffer start address
+   RxBufRPtr  = 0x18,         // Rx buffer read pointer
+   Txstatusall = 0x1C,        // Transmit status of all descriptors
+   TxStatus0  = 0x20,        // Transmit status (Four 32bit registers).
+   TxAddr0    = 0x30,         // Tx descriptors (also four 32bit).
+   RxConfig   = 0x40,         // Rx configuration
+   MAC0              = 0x44,         // Ethernet hardware address.
+   MAR0              = 0x4C,         // Multicast filter.
+   RxStatus0  = 0x54,         // Rx status
+   TxConfig   = 0x5C,         // Tx configuration
+   PhyCtrl    = 0x60,         // physical control
+   FlowCtrlConfig = 0x64,     // flow control
+   Miicmd0    = 0x68,         // Mii command0 register
+   Miicmd1    = 0x6C,         // Mii command1 register
+   Miistatus  = 0x70,         // Mii status register
+   Timercnt   = 0x74,         // Timer counter register
+   TimerIntr  = 0x78,         // Timer interrupt register
+   PMConfig   = 0x7C,         // Power Manager configuration
+   CRC0       = 0x80,         // Power Manager CRC ( Two 32bit regisers)
+   Wakeup0    = 0x88,         // power Manager wakeup( Eight 64bit regiser)
+   LSBCRC0    = 0xC8,         // power Manager LSBCRC(Two 32bit regiser)
+   TestD0     = 0xD0,
+   TestD4     = 0xD4,
+   TestD8     = 0xD8,
+};
+
+#define MII_BMCR            0        // Basic mode control register
+#define MII_BMSR            1        // Basic mode status register
+#define MII_JAB             16
+#define MII_OutputStatus    24
+
+#define BMCR_FULLDPLX       0x0100    // Full duplex
+#define BMCR_ANRESTART      0x0200    // Auto negotiation restart
+#define BMCR_ANENABLE       0x1000    // Enable auto negotiation
+#define BMCR_SPEED100       0x2000    // Select 100Mbps
+#define BMSR_LSTATUS        0x0004    // Link status
+#define PHY_16_JAB_ENB      0x1000
+#define PHY_16_PORT_ENB     0x1
+
+enum IntrStatusBits {
+   LinkFail       = 0x80000000,
+   LinkOK         = 0x40000000,
+   TimeOut        = 0x20000000,
+   RxOverflow     = 0x0040,
+   RxOK           = 0x0020,
+   TxOK           = 0x0001,
+   IntrBits = LinkFail|LinkOK|TimeOut|RxOverflow|RxOK|TxOK,
+};
+
+enum TxStatusBits {
+   TxCarrierLost = 0x20000000,
+   TxAborted     = 0x10000000,
+   TxOutOfWindow = 0x08000000,
+   TxNccShift    = 22,
+   EarlyTxThresShift = 16,
+   TxStatOK      = 0x8000,
+   TxUnderrun    = 0x4000,
+   TxOwn         = 0x2000,
+};
+
+enum RxStatusBits {
+   RxStatesOK   = 0x80000,
+   RxBadAlign   = 0x40000,
+   RxHugeFrame  = 0x20000,
+   RxSmallFrame = 0x10000,
+   RxCRCOK      = 0x8000,
+   RxCrlFrame   = 0x4000,
+   Rx_Broadcast = 0x2000,
+   Rx_Multicast = 0x1000,
+   RxAddrMatch  = 0x0800,
+   MiiErr       = 0x0400,
+};
+
+enum RxConfigBits {
+   RxFullDx    = 0x80000000,
+   RxEnb       = 0x40000000,
+   RxSmall     = 0x20000000,
+   RxHuge      = 0x10000000,
+   RxErr       = 0x08000000,
+   RxAllphys   = 0x04000000,
+   RxMulticast = 0x02000000,
+   RxBroadcast = 0x01000000,
+   RxLoopBack  = (1 << 23) | (1 << 22),
+   LowThresholdShift  = 12,
+   HighThresholdShift = 2,
+};
+
+enum TxConfigBits {
+   TxFullDx       = 0x80000000,
+   TxEnb          = 0x40000000,
+   TxEnbPad       = 0x20000000,
+   TxEnbHuge      = 0x10000000,
+   TxEnbFCS       = 0x08000000,
+   TxNoBackOff    = 0x04000000,
+   TxEnbPrem      = 0x02000000,
+   TxCareLostCrs  = 0x1000000,
+   TxExdCollNum   = 0xf00000,
+   TxDataRate     = 0x80000,
+};
+
+enum PhyCtrlconfigbits {
+   PhyCtrlAne         = 0x80000000,
+   PhyCtrlSpd100      = 0x40000000,
+   PhyCtrlSpd10       = 0x20000000,
+   PhyCtrlPhyBaseAddr = 0x1f000000,
+   PhyCtrlDux         = 0x800000,
+   PhyCtrlReset       = 0x400000,
+};
+
+enum FlowCtrlConfigBits {
+   FlowCtrlFullDX = 0x80000000,
+   FlowCtrlEnb    = 0x40000000,
+};
+
+enum Config0Bits {
+   Cfg0_Reset  = 0x80000000,
+   Cfg0_Anaoff = 0x40000000,
+   Cfg0_LDPS   = 0x20000000,
+};
+
+enum Config1Bits {
+   Cfg1_EarlyRx = 1 << 31,
+   Cfg1_EarlyTx = 1 << 30,
+
+   //rx buffer size
+   Cfg1_Rcv8K   = 0x0,
+   Cfg1_Rcv16K  = 0x1,
+   Cfg1_Rcv32K  = 0x3,
+   Cfg1_Rcv64K  = 0x7,
+   Cfg1_Rcv128K = 0xf,
+};
+
+enum MiiCmd0Bits {
+   Mii_Divider = 0x20000000,
+   Mii_WRITE   = 0x400000,
+   Mii_READ    = 0x200000,
+   Mii_SCAN    = 0x100000,
+   Mii_Tamod   = 0x80000,
+   Mii_Drvmod  = 0x40000,
+   Mii_mdc     = 0x20000,
+   Mii_mdoen   = 0x10000,
+   Mii_mdo     = 0x8000,
+   Mii_mdi     = 0x4000,
+};
+
+enum MiiStatusBits {
+    Mii_StatusBusy = 0x80000000,
+};
+
+enum PMConfigBits {
+   PM_Enable  = 1 << 31,
+   PM_LongWF  = 1 << 30,
+   PM_Magic   = 1 << 29,
+   PM_LANWake = 1 << 28,
+   PM_LWPTN   = (1 << 27 | 1<< 26),
+   PM_LinkUp  = 1 << 25,
+   PM_WakeUp  = 1 << 24,
+};
+
+/* Locking rules:
+ * priv->lock protects most of the fields of priv and most of the
+ * hardware registers. It does not have to protect against softirqs
+ * between sc92031_disable_interrupts and sc92031_enable_interrupts;
+ * it also does not need to be used in ->open and ->stop while the
+ * device interrupts are off.
+ * Not having to protect against softirqs is very useful due to heavy
+ * use of mdelay() at _sc92031_reset.
+ * Functions prefixed with _sc92031_ must be called with the lock held;
+ * functions prefixed with sc92031_ must be called without the lock held.
+ * Use mmiowb() before unlocking if the hardware was written to.
+ */
+
+/* Locking rules for the interrupt:
+ * - the interrupt and the tasklet never run at the same time
+ * - neither run between sc92031_disable_interrupts and
+ *   sc92031_enable_interrupt
+ */
+
+struct sc92031_priv {
+       spinlock_t              lock;
+       /* iomap.h cookie */
+       void __iomem            *port_base;
+       /* pci device structure */
+       struct pci_dev          *pdev;
+       /* tasklet */
+       struct tasklet_struct   tasklet;
+
+       /* CPU address of rx ring */
+       void                    *rx_ring;
+       /* PCI address of rx ring */
+       dma_addr_t              rx_ring_dma_addr;
+       /* PCI address of rx ring read pointer */
+       dma_addr_t              rx_ring_tail;
+
+       /* tx ring write index */
+       unsigned                tx_head;
+       /* tx ring read index */
+       unsigned                tx_tail;
+       /* CPU address of tx bounce buffer */
+       void                    *tx_bufs;
+       /* PCI address of tx bounce buffer */
+       dma_addr_t              tx_bufs_dma_addr;
+
+       /* copies of some hardware registers */
+       u32                     intr_status;
+       atomic_t                intr_mask;
+       u32                     rx_config;
+       u32                     tx_config;
+       u32                     pm_config;
+
+       /* copy of some flags from dev->flags */
+       unsigned int            mc_flags;
+
+       /* for ETHTOOL_GSTATS */
+       u64                     tx_timeouts;
+       u64                     rx_loss;
+
+       /* for dev->get_stats */
+       long                    rx_value;
+       struct net_device_stats stats;
+};
+
+/* I don't know which registers can be safely read; however, I can guess
+ * MAC0 is one of them. */
+static inline void _sc92031_dummy_read(void __iomem *port_base)
+{
+       ioread32(port_base + MAC0);
+}
+
+static u32 _sc92031_mii_wait(void __iomem *port_base)
+{
+       u32 mii_status;
+
+       do {
+               udelay(10);
+               mii_status = ioread32(port_base + Miistatus);
+       } while (mii_status & Mii_StatusBusy);
+
+       return mii_status;
+}
+
+static u32 _sc92031_mii_cmd(void __iomem *port_base, u32 cmd0, u32 cmd1)
+{
+       iowrite32(Mii_Divider, port_base + Miicmd0);
+
+       _sc92031_mii_wait(port_base);
+
+       iowrite32(cmd1, port_base + Miicmd1);
+       iowrite32(Mii_Divider | cmd0, port_base + Miicmd0);
+
+       return _sc92031_mii_wait(port_base);
+}
+
+static void _sc92031_mii_scan(void __iomem *port_base)
+{
+       _sc92031_mii_cmd(port_base, Mii_SCAN, 0x1 << 6);
+}
+
+static u16 _sc92031_mii_read(void __iomem *port_base, unsigned reg)
+{
+       return _sc92031_mii_cmd(port_base, Mii_READ, reg << 6) >> 13;
+}
+
+static void _sc92031_mii_write(void __iomem *port_base, unsigned reg, u16 val)
+{
+       _sc92031_mii_cmd(port_base, Mii_WRITE, (reg << 6) | ((u32)val << 11));
+}
+
+static void sc92031_disable_interrupts(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+
+       /* tell the tasklet/interrupt not to enable interrupts */
+       atomic_set(&priv->intr_mask, 0);
+       wmb();
+
+       /* stop interrupts */
+       iowrite32(0, port_base + IntrMask);
+       _sc92031_dummy_read(port_base);
+       mmiowb();
+
+       /* wait for any concurrent interrupt/tasklet to finish */
+       synchronize_irq(dev->irq);
+       tasklet_disable(&priv->tasklet);
+}
+
+static void sc92031_enable_interrupts(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+
+       tasklet_enable(&priv->tasklet);
+
+       atomic_set(&priv->intr_mask, IntrBits);
+       wmb();
+
+       iowrite32(IntrBits, port_base + IntrMask);
+       mmiowb();
+}
+
+static void _sc92031_disable_tx_rx(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+
+       priv->rx_config &= ~RxEnb;
+       priv->tx_config &= ~TxEnb;
+       iowrite32(priv->rx_config, port_base + RxConfig);
+       iowrite32(priv->tx_config, port_base + TxConfig);
+}
+
+static void _sc92031_enable_tx_rx(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+
+       priv->rx_config |= RxEnb;
+       priv->tx_config |= TxEnb;
+       iowrite32(priv->rx_config, port_base + RxConfig);
+       iowrite32(priv->tx_config, port_base + TxConfig);
+}
+
+static void _sc92031_tx_clear(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+
+       while (priv->tx_head - priv->tx_tail > 0) {
+               priv->tx_tail++;
+               priv->stats.tx_dropped++;
+       }
+       priv->tx_head = priv->tx_tail = 0;
+}
+
+static void _sc92031_set_mar(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       u32 mar0 = 0, mar1 = 0;
+
+       if ((dev->flags & IFF_PROMISC)
+                       || dev->mc_count > multicast_filter_limit
+                       || (dev->flags & IFF_ALLMULTI))
+               mar0 = mar1 = 0xffffffff;
+       else if (dev->flags & IFF_MULTICAST) {
+               struct dev_mc_list *mc_list;
+
+               for (mc_list = dev->mc_list; mc_list; mc_list = mc_list->next) {
+                       u32 crc;
+                       unsigned bit = 0;
+
+                       crc = ~ether_crc(ETH_ALEN, mc_list->dmi_addr);
+                       crc >>= 24;
+
+                       if (crc & 0x01) bit |= 0x02;
+                       if (crc & 0x02) bit |= 0x01;
+                       if (crc & 0x10) bit |= 0x20;
+                       if (crc & 0x20) bit |= 0x10;
+                       if (crc & 0x40) bit |= 0x08;
+                       if (crc & 0x80) bit |= 0x04;
+
+                       if (bit > 31)
+                               mar0 |= 0x1 << (bit - 32);
+                       else
+                               mar1 |= 0x1 << bit;
+               }
+       }
+
+       iowrite32(mar0, port_base + MAR0);
+       iowrite32(mar1, port_base + MAR0 + 4);
+}
+
+static void _sc92031_set_rx_config(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       unsigned int old_mc_flags;
+       u32 rx_config_bits = 0;
+
+       old_mc_flags = priv->mc_flags;
+
+       if (dev->flags & IFF_PROMISC)
+               rx_config_bits |= RxSmall | RxHuge | RxErr | RxBroadcast
+                               | RxMulticast | RxAllphys;
+
+       if (dev->flags & (IFF_ALLMULTI | IFF_MULTICAST))
+               rx_config_bits |= RxMulticast;
+
+       if (dev->flags & IFF_BROADCAST)
+               rx_config_bits |= RxBroadcast;
+
+       priv->rx_config &= ~(RxSmall | RxHuge | RxErr | RxBroadcast
+                       | RxMulticast | RxAllphys);
+       priv->rx_config |= rx_config_bits;
+
+       priv->mc_flags = dev->flags & (IFF_PROMISC | IFF_ALLMULTI
+                       | IFF_MULTICAST | IFF_BROADCAST);
+
+       if (netif_carrier_ok(dev) && priv->mc_flags != old_mc_flags)
+               iowrite32(priv->rx_config, port_base + RxConfig);
+}
+
+static bool _sc92031_check_media(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       u16 bmsr;
+
+       bmsr = _sc92031_mii_read(port_base, MII_BMSR);
+       rmb();
+       if (bmsr & BMSR_LSTATUS) {
+               bool speed_100, duplex_full;
+               u32 flow_ctrl_config = 0;
+               u16 output_status = _sc92031_mii_read(port_base,
+                               MII_OutputStatus);
+               _sc92031_mii_scan(port_base);
+
+               speed_100 = output_status & 0x2;
+               duplex_full = output_status & 0x4;
+
+               /* Initial Tx/Rx configuration */
+               priv->rx_config = (0x40 << LowThresholdShift) | (0x1c0 << HighThresholdShift);
+               priv->tx_config = 0x48800000;
+
+               /* NOTE: vendor driver had dead code here to enable tx padding */
+
+               if (!speed_100)
+                       priv->tx_config |= 0x80000;
+
+               // configure rx mode
+               _sc92031_set_rx_config(dev);
+
+               if (duplex_full) {
+                       priv->rx_config |= RxFullDx;
+                       priv->tx_config |= TxFullDx;
+                       flow_ctrl_config = FlowCtrlFullDX | FlowCtrlEnb;
+               } else {
+                       priv->rx_config &= ~RxFullDx;
+                       priv->tx_config &= ~TxFullDx;
+               }
+
+               _sc92031_set_mar(dev);
+               _sc92031_set_rx_config(dev);
+               _sc92031_enable_tx_rx(dev);
+               iowrite32(flow_ctrl_config, port_base + FlowCtrlConfig);
+
+               netif_carrier_on(dev);
+
+               if (printk_ratelimit())
+                       printk(KERN_INFO "%s: link up, %sMbps, %s-duplex\n",
+                               dev->name,
+                               speed_100 ? "100" : "10",
+                               duplex_full ? "full" : "half");
+               return true;
+       } else {
+               _sc92031_mii_scan(port_base);
+
+               netif_carrier_off(dev);
+
+               _sc92031_disable_tx_rx(dev);
+
+               if (printk_ratelimit())
+                       printk(KERN_INFO "%s: link down\n", dev->name);
+               return false;
+       }
+}
+
+static void _sc92031_phy_reset(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       u32 phy_ctrl;
+
+       phy_ctrl = ioread32(port_base + PhyCtrl);
+       phy_ctrl &= ~(PhyCtrlDux | PhyCtrlSpd100 | PhyCtrlSpd10);
+       phy_ctrl |= PhyCtrlAne | PhyCtrlReset;
+
+       switch (media) {
+       default:
+       case AUTOSELECT:
+               phy_ctrl |= PhyCtrlDux | PhyCtrlSpd100 | PhyCtrlSpd10;
+               break;
+       case M10_HALF:
+               phy_ctrl |= PhyCtrlSpd10;
+               break;
+       case M10_FULL:
+               phy_ctrl |= PhyCtrlDux | PhyCtrlSpd10;
+               break;
+       case M100_HALF:
+               phy_ctrl |= PhyCtrlSpd100;
+               break;
+       case M100_FULL:
+               phy_ctrl |= PhyCtrlDux | PhyCtrlSpd100;
+               break;
+       }
+
+       iowrite32(phy_ctrl, port_base + PhyCtrl);
+       mdelay(10);
+
+       phy_ctrl &= ~PhyCtrlReset;
+       iowrite32(phy_ctrl, port_base + PhyCtrl);
+       mdelay(1);
+
+       _sc92031_mii_write(port_base, MII_JAB,
+                       PHY_16_JAB_ENB | PHY_16_PORT_ENB);
+       _sc92031_mii_scan(port_base);
+
+       netif_carrier_off(dev);
+       netif_stop_queue(dev);
+}
+
+static void _sc92031_reset(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+
+       /* disable PM */
+       iowrite32(0, port_base + PMConfig);
+
+       /* soft reset the chip */
+       iowrite32(Cfg0_Reset, port_base + Config0);
+       mdelay(200);
+
+       iowrite32(0, port_base + Config0);
+       mdelay(10);
+
+       /* disable interrupts */
+       iowrite32(0, port_base + IntrMask);
+
+       /* clear multicast address */
+       iowrite32(0, port_base + MAR0);
+       iowrite32(0, port_base + MAR0 + 4);
+
+       /* init rx ring */
+       iowrite32(priv->rx_ring_dma_addr, port_base + RxbufAddr);
+       priv->rx_ring_tail = priv->rx_ring_dma_addr;
+
+       /* init tx ring */
+       _sc92031_tx_clear(dev);
+
+       /* clear old register values */
+       priv->intr_status = 0;
+       atomic_set(&priv->intr_mask, 0);
+       priv->rx_config = 0;
+       priv->tx_config = 0;
+       priv->mc_flags = 0;
+
+       /* configure rx buffer size */
+       /* NOTE: vendor driver had dead code here to enable early tx/rx */
+       iowrite32(Cfg1_Rcv64K, port_base + Config1);
+
+       _sc92031_phy_reset(dev);
+       _sc92031_check_media(dev);
+
+       /* calculate rx fifo overflow */
+       priv->rx_value = 0;
+
+       /* enable PM */
+       iowrite32(priv->pm_config, port_base + PMConfig);
+
+       /* clear intr register */
+       ioread32(port_base + IntrStatus);
+}
+
+static void _sc92031_tx_tasklet(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+
+       unsigned old_tx_tail;
+       unsigned entry;
+       u32 tx_status;
+
+       old_tx_tail = priv->tx_tail;
+       while (priv->tx_head - priv->tx_tail > 0) {
+               entry = priv->tx_tail % NUM_TX_DESC;
+               tx_status = ioread32(port_base + TxStatus0 + entry * 4);
+
+               if (!(tx_status & (TxStatOK | TxUnderrun | TxAborted)))
+                       break;
+
+               priv->tx_tail++;
+
+               if (tx_status & TxStatOK) {
+                       priv->stats.tx_bytes += tx_status & 0x1fff;
+                       priv->stats.tx_packets++;
+                       /* Note: TxCarrierLost is always asserted at 100mbps. */
+                       priv->stats.collisions += (tx_status >> 22) & 0xf;
+               }
+
+               if (tx_status & (TxOutOfWindow | TxAborted)) {
+                       priv->stats.tx_errors++;
+
+                       if (tx_status & TxAborted)
+                               priv->stats.tx_aborted_errors++;
+
+                       if (tx_status & TxCarrierLost)
+                               priv->stats.tx_carrier_errors++;
+
+                       if (tx_status & TxOutOfWindow)
+                               priv->stats.tx_window_errors++;
+               }
+
+               if (tx_status & TxUnderrun)
+                       priv->stats.tx_fifo_errors++;
+       }
+
+       if (priv->tx_tail != old_tx_tail)
+               if (netif_queue_stopped(dev))
+                       netif_wake_queue(dev);
+}
+
+static void _sc92031_rx_tasklet_error(u32 rx_status,
+               struct sc92031_priv *priv, unsigned rx_size)
+{
+       if(rx_size > (MAX_ETH_FRAME_SIZE + 4) || rx_size < 16) {
+               priv->stats.rx_errors++;
+               priv->stats.rx_length_errors++;
+       }
+
+       if (!(rx_status & RxStatesOK)) {
+               priv->stats.rx_errors++;
+
+               if (rx_status & (RxHugeFrame | RxSmallFrame))
+                       priv->stats.rx_length_errors++;
+
+               if (rx_status & RxBadAlign)
+                       priv->stats.rx_frame_errors++;
+
+               if (!(rx_status & RxCRCOK))
+                       priv->stats.rx_crc_errors++;
+       } else
+               priv->rx_loss++;
+}
+
+static void _sc92031_rx_tasklet(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+
+       dma_addr_t rx_ring_head;
+       unsigned rx_len;
+       unsigned rx_ring_offset;
+       void *rx_ring = priv->rx_ring;
+
+       rx_ring_head = ioread32(port_base + RxBufWPtr);
+       rmb();
+
+       /* rx_ring_head is only 17 bits in the RxBufWPtr register.
+        * we need to change it to 32 bits physical address
+        */
+       rx_ring_head &= (dma_addr_t)(RX_BUF_LEN - 1);
+       rx_ring_head |= priv->rx_ring_dma_addr & ~(dma_addr_t)(RX_BUF_LEN - 1);
+       if (rx_ring_head < priv->rx_ring_dma_addr)
+               rx_ring_head += RX_BUF_LEN;
+
+       if (rx_ring_head >= priv->rx_ring_tail)
+               rx_len = rx_ring_head - priv->rx_ring_tail;
+       else
+               rx_len = RX_BUF_LEN - (priv->rx_ring_tail - rx_ring_head);
+
+       if (!rx_len)
+               return;
+
+       if (unlikely(rx_len > RX_BUF_LEN)) {
+               if (printk_ratelimit())
+                       printk(KERN_ERR "%s: rx packets length > rx buffer\n",
+                                       dev->name);
+               return;
+       }
+
+       rx_ring_offset = (priv->rx_ring_tail - priv->rx_ring_dma_addr) % RX_BUF_LEN;
+
+       while (rx_len) {
+               u32 rx_status;
+               unsigned rx_size, rx_size_align, pkt_size;
+               struct sk_buff *skb;
+
+               rx_status = le32_to_cpup((__le32 *)(rx_ring + rx_ring_offset));
+               rmb();
+
+               rx_size = rx_status >> 20;
+               rx_size_align = (rx_size + 3) & ~3;     // for 4 bytes aligned
+               pkt_size = rx_size - 4; // Omit the four octet CRC from the length.
+
+               rx_ring_offset = (rx_ring_offset + 4) % RX_BUF_LEN;
+
+               if (unlikely(rx_status == 0
+                               || rx_size > (MAX_ETH_FRAME_SIZE + 4)
+                               || rx_size < 16
+                               || !(rx_status & RxStatesOK))) {
+                       _sc92031_rx_tasklet_error(rx_status, priv, rx_size);
+                       break;
+               }
+
+               if (unlikely(rx_size_align + 4 > rx_len)) {
+                       if (printk_ratelimit())
+                               printk(KERN_ERR "%s: rx_len is too small\n", dev->name);
+                       break;
+               }
+
+               rx_len -= rx_size_align + 4;
+
+               skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN);
+               if (unlikely(!skb)) {
+                       if (printk_ratelimit())
+                               printk(KERN_ERR "%s: Couldn't allocate a skb_buff for a packet of size %u\n",
+                                               dev->name, pkt_size);
+                       goto next;
+               }
+
+               skb_reserve(skb, NET_IP_ALIGN);
+
+               if ((rx_ring_offset + pkt_size) > RX_BUF_LEN) {
+                       memcpy(skb_put(skb, RX_BUF_LEN - rx_ring_offset),
+                               rx_ring + rx_ring_offset, RX_BUF_LEN - rx_ring_offset);
+                       memcpy(skb_put(skb, pkt_size - (RX_BUF_LEN - rx_ring_offset)),
+                               rx_ring, pkt_size - (RX_BUF_LEN - rx_ring_offset));
+               } else {
+                       memcpy(skb_put(skb, pkt_size), rx_ring + rx_ring_offset, pkt_size);
+               }
+
+               skb->dev = dev;
+               skb->protocol = eth_type_trans(skb, dev);
+               dev->last_rx = jiffies;
+               netif_rx(skb);
+
+               priv->stats.rx_bytes += pkt_size;
+               priv->stats.rx_packets++;
+
+               if (rx_status & Rx_Multicast)
+                       priv->stats.multicast++;
+
+       next:
+               rx_ring_offset = (rx_ring_offset + rx_size_align) % RX_BUF_LEN;
+       }
+       mb();
+
+       priv->rx_ring_tail = rx_ring_head;
+       iowrite32(priv->rx_ring_tail, port_base + RxBufRPtr);
+}
+
+static void _sc92031_link_tasklet(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+
+       if (_sc92031_check_media(dev))
+               netif_wake_queue(dev);
+       else {
+               netif_stop_queue(dev);
+               priv->stats.tx_carrier_errors++;
+       }
+}
+
+static void sc92031_tasklet(unsigned long data)
+{
+       struct net_device *dev = (struct net_device *)data;
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       u32 intr_status, intr_mask;
+
+       intr_status = priv->intr_status;
+
+       spin_lock(&priv->lock);
+
+       if (unlikely(!netif_running(dev)))
+               goto out;
+
+       if (intr_status & TxOK)
+               _sc92031_tx_tasklet(dev);
+
+       if (intr_status & RxOK)
+               _sc92031_rx_tasklet(dev);
+
+       if (intr_status & RxOverflow)
+               priv->stats.rx_errors++;
+
+       if (intr_status & TimeOut) {
+               priv->stats.rx_errors++;
+               priv->stats.rx_length_errors++;
+       }
+
+       if (intr_status & (LinkFail | LinkOK))
+               _sc92031_link_tasklet(dev);
+
+out:
+       intr_mask = atomic_read(&priv->intr_mask);
+       rmb();
+
+       iowrite32(intr_mask, port_base + IntrMask);
+       mmiowb();
+
+       spin_unlock(&priv->lock);
+}
+
+static irqreturn_t sc92031_interrupt(int irq, void *dev_id)
+{
+       struct net_device *dev = dev_id;
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       u32 intr_status, intr_mask;
+
+       /* mask interrupts before clearing IntrStatus */
+       iowrite32(0, port_base + IntrMask);
+       _sc92031_dummy_read(port_base);
+
+       intr_status = ioread32(port_base + IntrStatus);
+       if (unlikely(intr_status == 0xffffffff))
+               return IRQ_NONE;        // hardware has gone missing
+
+       intr_status &= IntrBits;
+       if (!intr_status)
+               goto out_none;
+
+       priv->intr_status = intr_status;
+       tasklet_schedule(&priv->tasklet);
+
+       return IRQ_HANDLED;
+
+out_none:
+       intr_mask = atomic_read(&priv->intr_mask);
+       rmb();
+
+       iowrite32(intr_mask, port_base + IntrMask);
+       mmiowb();
+
+       return IRQ_NONE;
+}
+
+static struct net_device_stats *sc92031_get_stats(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+
+       // FIXME I do not understand what is this trying to do.
+       if (netif_running(dev)) {
+               int temp;
+
+               spin_lock_bh(&priv->lock);
+
+               /* Update the error count. */
+               temp = (ioread32(port_base + RxStatus0) >> 16) & 0xffff;
+
+               if (temp == 0xffff) {
+                       priv->rx_value += temp;
+                       priv->stats.rx_fifo_errors = priv->rx_value;
+               } else {
+                       priv->stats.rx_fifo_errors = temp + priv->rx_value;
+               }
+
+               spin_unlock_bh(&priv->lock);
+       }
+
+       return &priv->stats;
+}
+
+static int sc92031_start_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+       int err = 0;
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+
+       unsigned len;
+       unsigned entry;
+       u32 tx_status;
+
+       if (unlikely(skb->len > TX_BUF_SIZE)) {
+               err = -EMSGSIZE;
+               priv->stats.tx_dropped++;
+               goto out;
+       }
+
+       spin_lock_bh(&priv->lock);
+
+       if (unlikely(!netif_carrier_ok(dev))) {
+               err = -ENOLINK;
+               priv->stats.tx_dropped++;
+               goto out_unlock;
+       }
+
+       BUG_ON(priv->tx_head - priv->tx_tail >= NUM_TX_DESC);
+
+       entry = priv->tx_head++ % NUM_TX_DESC;
+
+       skb_copy_and_csum_dev(skb, priv->tx_bufs + entry * TX_BUF_SIZE);
+
+       len = skb->len;
+       if (unlikely(len < ETH_ZLEN)) {
+               memset(priv->tx_bufs + entry * TX_BUF_SIZE + len,
+                               0, ETH_ZLEN - len);
+               len = ETH_ZLEN;
+       }
+
+       wmb();
+
+       if (len < 100)
+               tx_status = len;
+       else if (len < 300)
+               tx_status = 0x30000 | len;
+       else
+               tx_status = 0x50000 | len;
+
+       iowrite32(priv->tx_bufs_dma_addr + entry * TX_BUF_SIZE,
+                       port_base + TxAddr0 + entry * 4);
+       iowrite32(tx_status, port_base + TxStatus0 + entry * 4);
+       mmiowb();
+
+       dev->trans_start = jiffies;
+
+       if (priv->tx_head - priv->tx_tail >= NUM_TX_DESC)
+               netif_stop_queue(dev);
+
+out_unlock:
+       spin_unlock_bh(&priv->lock);
+
+out:
+       dev_kfree_skb(skb);
+
+       return err;
+}
+
+static int sc92031_open(struct net_device *dev)
+{
+       int err;
+       struct sc92031_priv *priv = netdev_priv(dev);
+       struct pci_dev *pdev = priv->pdev;
+
+       priv->rx_ring = pci_alloc_consistent(pdev, RX_BUF_LEN,
+                       &priv->rx_ring_dma_addr);
+       if (unlikely(!priv->rx_ring)) {
+               err = -ENOMEM;
+               goto out_alloc_rx_ring;
+       }
+
+       priv->tx_bufs = pci_alloc_consistent(pdev, TX_BUF_TOT_LEN,
+                       &priv->tx_bufs_dma_addr);
+       if (unlikely(!priv->tx_bufs)) {
+               err = -ENOMEM;
+               goto out_alloc_tx_bufs;
+       }
+       priv->tx_head = priv->tx_tail = 0;
+
+       err = request_irq(pdev->irq, sc92031_interrupt,
+                       SA_SHIRQ, dev->name, dev);
+       if (unlikely(err < 0))
+               goto out_request_irq;
+
+       priv->pm_config = 0;
+
+       /* Interrupts already disabled by sc92031_stop or sc92031_probe */
+       spin_lock(&priv->lock);
+
+       _sc92031_reset(dev);
+       mmiowb();
+
+       spin_unlock(&priv->lock);
+       sc92031_enable_interrupts(dev);
+
+       if (netif_carrier_ok(dev))
+               netif_start_queue(dev);
+       else
+               netif_tx_disable(dev);
+
+       return 0;
+
+out_request_irq:
+       pci_free_consistent(pdev, TX_BUF_TOT_LEN, priv->tx_bufs,
+                       priv->tx_bufs_dma_addr);
+out_alloc_tx_bufs:
+       pci_free_consistent(pdev, RX_BUF_LEN, priv->rx_ring,
+                       priv->rx_ring_dma_addr);
+out_alloc_rx_ring:
+       return err;
+}
+
+static int sc92031_stop(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       struct pci_dev *pdev = priv->pdev;
+
+       netif_tx_disable(dev);
+
+       /* Disable interrupts, stop Tx and Rx. */
+       sc92031_disable_interrupts(dev);
+
+       spin_lock(&priv->lock);
+
+       _sc92031_disable_tx_rx(dev);
+       _sc92031_tx_clear(dev);
+       mmiowb();
+
+       spin_unlock(&priv->lock);
+
+       free_irq(pdev->irq, dev);
+       pci_free_consistent(pdev, TX_BUF_TOT_LEN, priv->tx_bufs,
+                       priv->tx_bufs_dma_addr);
+       pci_free_consistent(pdev, RX_BUF_LEN, priv->rx_ring,
+                       priv->rx_ring_dma_addr);
+
+       return 0;
+}
+
+static void sc92031_set_multicast_list(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+
+       spin_lock_bh(&priv->lock);
+
+       _sc92031_set_mar(dev);
+       _sc92031_set_rx_config(dev);
+       mmiowb();
+
+       spin_unlock_bh(&priv->lock);
+}
+
+static void sc92031_tx_timeout(struct net_device *dev)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+
+       /* Disable interrupts by clearing the interrupt mask.*/
+       sc92031_disable_interrupts(dev);
+
+       spin_lock(&priv->lock);
+
+       priv->tx_timeouts++;
+
+       _sc92031_reset(dev);
+       mmiowb();
+
+       spin_unlock(&priv->lock);
+
+       /* enable interrupts */
+       sc92031_enable_interrupts(dev);
+
+       if (netif_carrier_ok(dev))
+               netif_wake_queue(dev);
+}
+
+#ifdef CONFIG_NET_POLL_CONTROLLER
+static void sc92031_poll_controller(struct net_device *dev)
+{
+       disable_irq(dev->irq);
+       if (sc92031_interrupt(dev->irq, dev) != IRQ_NONE)
+               sc92031_tasklet((unsigned long)dev);
+       enable_irq(dev->irq);
+}
+#endif
+
+static int sc92031_ethtool_get_settings(struct net_device *dev,
+               struct ethtool_cmd *cmd)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       u8 phy_address;
+       u32 phy_ctrl;
+       u16 output_status;
+
+       spin_lock_bh(&priv->lock);
+
+       phy_address = ioread32(port_base + Miicmd1) >> 27;
+       phy_ctrl = ioread32(port_base + PhyCtrl);
+
+       output_status = _sc92031_mii_read(port_base, MII_OutputStatus);
+       _sc92031_mii_scan(port_base);
+       mmiowb();
+
+       spin_unlock_bh(&priv->lock);
+
+       cmd->supported = SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full
+                       | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full
+                       | SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII;
+
+       cmd->advertising = ADVERTISED_TP | ADVERTISED_MII;
+
+       if ((phy_ctrl & (PhyCtrlDux | PhyCtrlSpd100 | PhyCtrlSpd10))
+                       == (PhyCtrlDux | PhyCtrlSpd100 | PhyCtrlSpd10))
+               cmd->advertising |= ADVERTISED_Autoneg;
+
+       if ((phy_ctrl & PhyCtrlSpd10) == PhyCtrlSpd10)
+               cmd->advertising |= ADVERTISED_10baseT_Half;
+
+       if ((phy_ctrl & (PhyCtrlSpd10 | PhyCtrlDux))
+                       == (PhyCtrlSpd10 | PhyCtrlDux))
+               cmd->advertising |= ADVERTISED_10baseT_Full;
+
+       if ((phy_ctrl & PhyCtrlSpd100) == PhyCtrlSpd100)
+               cmd->advertising |= ADVERTISED_100baseT_Half;
+
+       if ((phy_ctrl & (PhyCtrlSpd100 | PhyCtrlDux))
+                       == (PhyCtrlSpd100 | PhyCtrlDux))
+               cmd->advertising |= ADVERTISED_100baseT_Full;
+
+       if (phy_ctrl & PhyCtrlAne)
+               cmd->advertising |= ADVERTISED_Autoneg;
+
+       cmd->speed = (output_status & 0x2) ? SPEED_100 : SPEED_10;
+       cmd->duplex = (output_status & 0x4) ? DUPLEX_FULL : DUPLEX_HALF;
+       cmd->port = PORT_MII;
+       cmd->phy_address = phy_address;
+       cmd->transceiver = XCVR_INTERNAL;
+       cmd->autoneg = (phy_ctrl & PhyCtrlAne) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
+
+       return 0;
+}
+
+static int sc92031_ethtool_set_settings(struct net_device *dev,
+               struct ethtool_cmd *cmd)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       u32 phy_ctrl;
+       u32 old_phy_ctrl;
+
+       if (!(cmd->speed == SPEED_10 || cmd->speed == SPEED_100))
+               return -EINVAL;
+       if (!(cmd->duplex == DUPLEX_HALF || cmd->duplex == DUPLEX_FULL))
+               return -EINVAL;
+       if (!(cmd->port == PORT_MII))
+               return -EINVAL;
+       if (!(cmd->phy_address == 0x1f))
+               return -EINVAL;
+       if (!(cmd->transceiver == XCVR_INTERNAL))
+               return -EINVAL;
+       if (!(cmd->autoneg == AUTONEG_DISABLE || cmd->autoneg == AUTONEG_ENABLE))
+               return -EINVAL;
+
+       if (cmd->autoneg == AUTONEG_ENABLE) {
+               if (!(cmd->advertising & (ADVERTISED_Autoneg
+                               | ADVERTISED_100baseT_Full
+                               | ADVERTISED_100baseT_Half
+                               | ADVERTISED_10baseT_Full
+                               | ADVERTISED_10baseT_Half)))
+                       return -EINVAL;
+
+               phy_ctrl = PhyCtrlAne;
+
+               // FIXME: I'm not sure what the original code was trying to do
+               if (cmd->advertising & ADVERTISED_Autoneg)
+                       phy_ctrl |= PhyCtrlDux | PhyCtrlSpd100 | PhyCtrlSpd10;
+               if (cmd->advertising & ADVERTISED_100baseT_Full)
+                       phy_ctrl |= PhyCtrlDux | PhyCtrlSpd100;
+               if (cmd->advertising & ADVERTISED_100baseT_Half)
+                       phy_ctrl |= PhyCtrlSpd100;
+               if (cmd->advertising & ADVERTISED_10baseT_Full)
+                       phy_ctrl |= PhyCtrlSpd10 | PhyCtrlDux;
+               if (cmd->advertising & ADVERTISED_10baseT_Half)
+                       phy_ctrl |= PhyCtrlSpd10;
+       } else {
+               // FIXME: Whole branch guessed
+               phy_ctrl = 0;
+
+               if (cmd->speed == SPEED_10)
+                       phy_ctrl |= PhyCtrlSpd10;
+               else /* cmd->speed == SPEED_100 */
+                       phy_ctrl |= PhyCtrlSpd100;
+
+               if (cmd->duplex == DUPLEX_FULL)
+                       phy_ctrl |= PhyCtrlDux;
+       }
+
+       spin_lock_bh(&priv->lock);
+
+       old_phy_ctrl = ioread32(port_base + PhyCtrl);
+       phy_ctrl |= old_phy_ctrl & ~(PhyCtrlAne | PhyCtrlDux
+                       | PhyCtrlSpd100 | PhyCtrlSpd10);
+       if (phy_ctrl != old_phy_ctrl)
+               iowrite32(phy_ctrl, port_base + PhyCtrl);
+
+       spin_unlock_bh(&priv->lock);
+
+       return 0;
+}
+
+static void sc92031_ethtool_get_drvinfo(struct net_device *dev,
+               struct ethtool_drvinfo *drvinfo)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       struct pci_dev *pdev = priv->pdev;
+
+       strcpy(drvinfo->driver, SC92031_NAME);
+       strcpy(drvinfo->version, SC92031_VERSION);
+       strcpy(drvinfo->bus_info, pci_name(pdev));
+}
+
+static void sc92031_ethtool_get_wol(struct net_device *dev,
+               struct ethtool_wolinfo *wolinfo)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       u32 pm_config;
+
+       spin_lock_bh(&priv->lock);
+       pm_config = ioread32(port_base + PMConfig);
+       spin_unlock_bh(&priv->lock);
+
+       // FIXME: Guessed
+       wolinfo->supported = WAKE_PHY | WAKE_MAGIC
+                       | WAKE_UCAST | WAKE_MCAST | WAKE_BCAST;
+       wolinfo->wolopts = 0;
+
+       if (pm_config & PM_LinkUp)
+               wolinfo->wolopts |= WAKE_PHY;
+
+       if (pm_config & PM_Magic)
+               wolinfo->wolopts |= WAKE_MAGIC;
+
+       if (pm_config & PM_WakeUp)
+               // FIXME: Guessed
+               wolinfo->wolopts |= WAKE_UCAST | WAKE_MCAST | WAKE_BCAST;
+}
+
+static int sc92031_ethtool_set_wol(struct net_device *dev,
+               struct ethtool_wolinfo *wolinfo)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       u32 pm_config;
+
+       spin_lock_bh(&priv->lock);
+
+       pm_config = ioread32(port_base + PMConfig)
+                       & ~(PM_LinkUp | PM_Magic | PM_WakeUp);
+
+       if (wolinfo->wolopts & WAKE_PHY)
+               pm_config |= PM_LinkUp;
+
+       if (wolinfo->wolopts & WAKE_MAGIC)
+               pm_config |= PM_Magic;
+
+       // FIXME: Guessed
+       if (wolinfo->wolopts & (WAKE_UCAST | WAKE_MCAST | WAKE_BCAST))
+               pm_config |= PM_WakeUp;
+
+       priv->pm_config = pm_config;
+       iowrite32(pm_config, port_base + PMConfig);
+       mmiowb();
+
+       spin_unlock_bh(&priv->lock);
+
+       return 0;
+}
+
+static int sc92031_ethtool_nway_reset(struct net_device *dev)
+{
+       int err = 0;
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem *port_base = priv->port_base;
+       u16 bmcr;
+
+       spin_lock_bh(&priv->lock);
+
+       bmcr = _sc92031_mii_read(port_base, MII_BMCR);
+       if (!(bmcr & BMCR_ANENABLE)) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       _sc92031_mii_write(port_base, MII_BMCR, bmcr | BMCR_ANRESTART);
+
+out:
+       _sc92031_mii_scan(port_base);
+       mmiowb();
+
+       spin_unlock_bh(&priv->lock);
+
+       return err;
+}
+
+static const char sc92031_ethtool_stats_strings[SILAN_STATS_NUM][ETH_GSTRING_LEN] = {
+       "tx_timeout",
+       "rx_loss",
+};
+
+static void sc92031_ethtool_get_strings(struct net_device *dev,
+               u32 stringset, u8 *data)
+{
+       if (stringset == ETH_SS_STATS)
+               memcpy(data, sc92031_ethtool_stats_strings,
+                               SILAN_STATS_NUM * ETH_GSTRING_LEN);
+}
+
+static int sc92031_ethtool_get_stats_count(struct net_device *dev)
+{
+       return SILAN_STATS_NUM;
+}
+
+static void sc92031_ethtool_get_ethtool_stats(struct net_device *dev,
+               struct ethtool_stats *stats, u64 *data)
+{
+       struct sc92031_priv *priv = netdev_priv(dev);
+
+       spin_lock_bh(&priv->lock);
+       data[0] = priv->tx_timeouts;
+       data[1] = priv->rx_loss;
+       spin_unlock_bh(&priv->lock);
+}
+
+static struct ethtool_ops sc92031_ethtool_ops = {
+       .get_settings           = sc92031_ethtool_get_settings,
+       .set_settings           = sc92031_ethtool_set_settings,
+       .get_drvinfo            = sc92031_ethtool_get_drvinfo,
+       .get_wol                = sc92031_ethtool_get_wol,
+       .set_wol                = sc92031_ethtool_set_wol,
+       .nway_reset             = sc92031_ethtool_nway_reset,
+       .get_link               = ethtool_op_get_link,
+       .get_tx_csum            = ethtool_op_get_tx_csum,
+       .get_sg                 = ethtool_op_get_sg,
+       .get_tso                = ethtool_op_get_tso,
+       .get_strings            = sc92031_ethtool_get_strings,
+       .get_stats_count        = sc92031_ethtool_get_stats_count,
+       .get_ethtool_stats      = sc92031_ethtool_get_ethtool_stats,
+       .get_perm_addr          = ethtool_op_get_perm_addr,
+       .get_ufo                = ethtool_op_get_ufo,
+};
+
+static int __devinit sc92031_probe(struct pci_dev *pdev,
+               const struct pci_device_id *id)
+{
+       int err;
+       void __iomem* port_base;
+       struct net_device *dev;
+       struct sc92031_priv *priv;
+       u32 mac0, mac1;
+
+       err = pci_enable_device(pdev);
+       if (unlikely(err < 0))
+               goto out_enable_device;
+
+       pci_set_master(pdev);
+
+       err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
+       if (unlikely(err < 0))
+               goto out_set_dma_mask;
+
+       err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
+       if (unlikely(err < 0))
+               goto out_set_dma_mask;
+
+       err = pci_request_regions(pdev, SC92031_NAME);
+       if (unlikely(err < 0))
+               goto out_request_regions;
+
+       port_base = pci_iomap(pdev, SC92031_USE_BAR, 0);
+       if (unlikely(!port_base)) {
+               err = -EIO;
+               goto out_iomap;
+       }
+
+       dev = alloc_etherdev(sizeof(struct sc92031_priv));
+       if (unlikely(!dev)) {
+               err = -ENOMEM;
+               goto out_alloc_etherdev;
+       }
+
+       pci_set_drvdata(pdev, dev);
+
+#if SC92031_USE_BAR == 0
+       dev->mem_start = pci_resource_start(pdev, SC92031_USE_BAR);
+       dev->mem_end = pci_resource_end(pdev, SC92031_USE_BAR);
+#elif SC92031_USE_BAR == 1
+       dev->base_addr = pci_resource_start(pdev, SC92031_USE_BAR);
+#endif
+       dev->irq = pdev->irq;
+
+       /* faked with skb_copy_and_csum_dev */
+       dev->features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HIGHDMA;
+
+       dev->get_stats          = sc92031_get_stats;
+       dev->ethtool_ops        = &sc92031_ethtool_ops;
+       dev->hard_start_xmit    = sc92031_start_xmit;
+       dev->watchdog_timeo     = TX_TIMEOUT;
+       dev->open               = sc92031_open;
+       dev->stop               = sc92031_stop;
+       dev->set_multicast_list = sc92031_set_multicast_list;
+       dev->tx_timeout         = sc92031_tx_timeout;
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       dev->poll_controller    = sc92031_poll_controller;
+#endif
+
+       priv = netdev_priv(dev);
+       spin_lock_init(&priv->lock);
+       priv->port_base = port_base;
+       priv->pdev = pdev;
+       tasklet_init(&priv->tasklet, sc92031_tasklet, (unsigned long)dev);
+       /* Fudge tasklet count so the call to sc92031_enable_interrupts at
+        * sc92031_open will work correctly */
+       tasklet_disable_nosync(&priv->tasklet);
+
+       /* PCI PM Wakeup */
+       iowrite32((~PM_LongWF & ~PM_LWPTN) | PM_Enable, port_base + PMConfig);
+
+       mac0 = ioread32(port_base + MAC0);
+       mac1 = ioread32(port_base + MAC0 + 4);
+       dev->dev_addr[0] = dev->perm_addr[0] = mac0 >> 24;
+       dev->dev_addr[1] = dev->perm_addr[1] = mac0 >> 16;
+       dev->dev_addr[2] = dev->perm_addr[2] = mac0 >> 8;
+       dev->dev_addr[3] = dev->perm_addr[3] = mac0;
+       dev->dev_addr[4] = dev->perm_addr[4] = mac1 >> 8;
+       dev->dev_addr[5] = dev->perm_addr[5] = mac1;
+
+       err = register_netdev(dev);
+       if (err < 0)
+               goto out_register_netdev;
+
+       return 0;
+
+out_register_netdev:
+       free_netdev(dev);
+out_alloc_etherdev:
+       pci_iounmap(pdev, port_base);
+out_iomap:
+       pci_release_regions(pdev);
+out_request_regions:
+out_set_dma_mask:
+       pci_disable_device(pdev);
+out_enable_device:
+       return err;
+}
+
+static void __devexit sc92031_remove(struct pci_dev *pdev)
+{
+       struct net_device *dev = pci_get_drvdata(pdev);
+       struct sc92031_priv *priv = netdev_priv(dev);
+       void __iomem* port_base = priv->port_base;
+
+       unregister_netdev(dev);
+       free_netdev(dev);
+       pci_iounmap(pdev, port_base);
+       pci_release_regions(pdev);
+       pci_disable_device(pdev);
+}
+
+static int sc92031_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+       struct net_device *dev = pci_get_drvdata(pdev);
+       struct sc92031_priv *priv = netdev_priv(dev);
+
+       pci_save_state(pdev);
+
+       if (!netif_running(dev))
+               goto out;
+
+       netif_device_detach(dev);
+
+       /* Disable interrupts, stop Tx and Rx. */
+       sc92031_disable_interrupts(dev);
+
+       spin_lock(&priv->lock);
+
+       _sc92031_disable_tx_rx(dev);
+       _sc92031_tx_clear(dev);
+       mmiowb();
+
+       spin_unlock(&priv->lock);
+
+out:
+       pci_set_power_state(pdev, pci_choose_state(pdev, state));
+
+       return 0;
+}
+
+static int sc92031_resume(struct pci_dev *pdev)
+{
+       struct net_device *dev = pci_get_drvdata(pdev);
+       struct sc92031_priv *priv = netdev_priv(dev);
+
+       pci_restore_state(pdev);
+       pci_set_power_state(pdev, PCI_D0);
+
+       if (!netif_running(dev))
+               goto out;
+
+       /* Interrupts already disabled by sc92031_suspend */
+       spin_lock(&priv->lock);
+
+       _sc92031_reset(dev);
+       mmiowb();
+
+       spin_unlock(&priv->lock);
+       sc92031_enable_interrupts(dev);
+
+       netif_device_attach(dev);
+
+       if (netif_carrier_ok(dev))
+               netif_wake_queue(dev);
+       else
+               netif_tx_disable(dev);
+
+out:
+       return 0;
+}
+
+static struct pci_device_id sc92031_pci_device_id_table[] __devinitdata = {
+       { PCI_DEVICE(PCI_VENDOR_ID_SILAN, PCI_DEVICE_ID_SILAN_SC92031) },
+       { PCI_DEVICE(PCI_VENDOR_ID_SILAN, PCI_DEVICE_ID_SILAN_8139D) },
+       { 0, }
+};
+MODULE_DEVICE_TABLE(pci, sc92031_pci_device_id_table);
+
+static struct pci_driver sc92031_pci_driver = {
+       .name           = SC92031_NAME,
+       .id_table       = sc92031_pci_device_id_table,
+       .probe          = sc92031_probe,
+       .remove         = __devexit_p(sc92031_remove),
+       .suspend        = sc92031_suspend,
+       .resume         = sc92031_resume,
+};
+
+static int __init sc92031_init(void)
+{
+       printk(KERN_INFO SC92031_DESCRIPTION " " SC92031_VERSION "\n");
+       return pci_register_driver(&sc92031_pci_driver);
+}
+
+static void __exit sc92031_exit(void)
+{
+       pci_unregister_driver(&sc92031_pci_driver);
+}
+
+module_init(sc92031_init);
+module_exit(sc92031_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Cesar Eduardo Barros <cesarb@cesarb.net>");
+MODULE_DESCRIPTION(SC92031_DESCRIPTION);
+MODULE_VERSION(SC92031_VERSION);
diff --git a/drivers/net/sk_mca.c b/drivers/net/sk_mca.c
deleted file mode 100644 (file)
index 96e06c5..0000000
+++ /dev/null
@@ -1,1216 +0,0 @@
-/*
-net-3-driver for the SKNET MCA-based cards
-
-This is an extension to the Linux operating system, and is covered by the
-same GNU General Public License that covers that work.
-
-Copyright 1999 by Alfred Arnold (alfred@ccac.rwth-aachen.de,
-                                 alfred.arnold@lancom.de)
-
-This driver is based both on the 3C523 driver and the SK_G16 driver.
-
-paper sources:
-  'PC Hardware: Aufbau, Funktionsweise, Programmierung' by
-  Hans-Peter Messmer for the basic Microchannel stuff
-
-  'Linux Geraetetreiber' by Allesandro Rubini, Kalle Dalheimer
-  for help on Ethernet driver programming
-
-  'Ethernet/IEEE 802.3 Family 1992 World Network Data Book/Handbook' by AMD
-  for documentation on the AM7990 LANCE
-
-  'SKNET Personal Technisches Manual', Version 1.2 by Schneider&Koch
-  for documentation on the Junior board
-
-  'SK-NET MC2+ Technical Manual", Version 1.1 by Schneider&Koch for
-  documentation on the MC2 bord
-
-  A big thank you to the S&K support for providing me so quickly with
-  documentation!
-
-  Also see http://www.syskonnect.com/
-
-  Missing things:
-
-  -> set debug level via ioctl instead of compile-time switches
-  -> I didn't follow the development of the 2.1.x kernels, so my
-     assumptions about which things changed with which kernel version
-     are probably nonsense
-
-History:
-  May 16th, 1999
-       startup
-  May 22st, 1999
-       added private structure, methods
-        begun building data structures in RAM
-  May 23nd, 1999
-       can receive frames, send frames
-  May 24th, 1999
-        modularized initialization of LANCE
-        loadable as module
-       still Tx problem :-(
-  May 26th, 1999
-       MC2 works
-       support for multiple devices
-       display media type for MC2+
-  May 28th, 1999
-       fixed problem in GetLANCE leaving interrupts turned off
-        increase TX queue to 4 packets to improve send performance
-  May 29th, 1999
-       a few corrections in statistics, caught rcvr overruns
-        reinitialization of LANCE/board in critical situations
-        MCA info implemented
-       implemented LANCE multicast filter
-  Jun 6th, 1999
-       additions for Linux 2.2
-  Dec 25th, 1999
-       unfortunately there seem to be newer MC2+ boards that react
-       on IRQ 3/5/9/10 instead of 3/5/10/11, so we have to autoprobe
-       in questionable cases...
-  Dec 28th, 1999
-       integrated patches from David Weinehall & Bill Wendling for 2.3
-       kernels (isa_...functions).  Things are defined in a way that
-        it still works with 2.0.x 8-)
-  Dec 30th, 1999
-       added handling of the remaining interrupt conditions.  That
-        should cure the spurious hangs.
-  Jan 30th, 2000
-       newer kernels automatically probe more than one board, so the
-       'startslot' as a variable is also needed here
-  June 1st, 2000
-       added changes for recent 2.3 kernels
-
- *************************************************************************/
-
-#include <linux/kernel.h>
-#include <linux/string.h>
-#include <linux/errno.h>
-#include <linux/ioport.h>
-#include <linux/slab.h>
-#include <linux/interrupt.h>
-#include <linux/delay.h>
-#include <linux/time.h>
-#include <linux/mca-legacy.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
-#include <linux/skbuff.h>
-#include <linux/bitops.h>
-
-#include <asm/processor.h>
-#include <asm/io.h>
-
-#define _SK_MCA_DRIVER_
-#include "sk_mca.h"
-
-/* ------------------------------------------------------------------------
- * global static data - not more since we can handle multiple boards and
- * have to pack all state info into the device struct!
- * ------------------------------------------------------------------------ */
-
-static char *MediaNames[Media_Count] =
-    { "10Base2", "10BaseT", "10Base5", "Unknown" };
-
-static unsigned char poly[] =
-    { 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0,
-       1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0
-};
-
-/* ------------------------------------------------------------------------
- * private subfunctions
- * ------------------------------------------------------------------------ */
-
-/* dump parts of shared memory - only needed during debugging */
-
-#ifdef DEBUG
-static void dumpmem(struct net_device *dev, u32 start, u32 len)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       int z;
-
-       for (z = 0; z < len; z++) {
-               if ((z & 15) == 0)
-                       printk("%04x:", z);
-               printk(" %02x", readb(priv->base + start + z));
-               if ((z & 15) == 15)
-                       printk("\n");
-       }
-}
-
-/* print exact time - ditto */
-
-static void PrTime(void)
-{
-       struct timeval tv;
-
-       do_gettimeofday(&tv);
-       printk("%9d:%06d: ", tv.tv_sec, tv.tv_usec);
-}
-#endif
-
-/* deduce resources out of POS registers */
-
-static void __init getaddrs(int slot, int junior, int *base, int *irq,
-                    skmca_medium * medium)
-{
-       u_char pos0, pos1, pos2;
-
-       if (junior) {
-               pos0 = mca_read_stored_pos(slot, 2);
-               *base = ((pos0 & 0x0e) << 13) + 0xc0000;
-               *irq = ((pos0 & 0x10) >> 4) + 10;
-               *medium = Media_Unknown;
-       } else {
-               /* reset POS 104 Bits 0+1 so the shared memory region goes to the
-                  configured area between 640K and 1M.  Afterwards, enable the MC2.
-                  I really don't know what rode SK to do this... */
-
-               mca_write_pos(slot, 4,
-                             mca_read_stored_pos(slot, 4) & 0xfc);
-               mca_write_pos(slot, 2,
-                             mca_read_stored_pos(slot, 2) | 0x01);
-
-               pos1 = mca_read_stored_pos(slot, 3);
-               pos2 = mca_read_stored_pos(slot, 4);
-               *base = ((pos1 & 0x07) << 14) + 0xc0000;
-               switch (pos2 & 0x0c) {
-               case 0:
-                       *irq = 3;
-                       break;
-               case 4:
-                       *irq = 5;
-                       break;
-               case 8:
-                       *irq = -10;
-                       break;
-               case 12:
-                       *irq = -11;
-                       break;
-               }
-               *medium = (pos2 >> 6) & 3;
-       }
-}
-
-/* check for both cards:
-   When the MC2 is turned off, it was configured for more than 15MB RAM,
-   is disabled and won't get detected using the standard probe.  We
-   therefore have to scan the slots manually :-( */
-
-static int __init dofind(int *junior, int firstslot)
-{
-       int slot;
-       unsigned int id;
-
-       for (slot = firstslot; slot < MCA_MAX_SLOT_NR; slot++) {
-               id = mca_read_stored_pos(slot, 0)
-                   + (((unsigned int) mca_read_stored_pos(slot, 1)) << 8);
-
-               *junior = 0;
-               if (id == SKNET_MCA_ID)
-                       return slot;
-               *junior = 1;
-               if (id == SKNET_JUNIOR_MCA_ID)
-                       return slot;
-       }
-       return MCA_NOTFOUND;
-}
-
-/* reset the whole board */
-
-static void ResetBoard(struct net_device *dev)
-{
-       skmca_priv *priv = netdev_priv(dev);
-
-       writeb(CTRL_RESET_ON, priv->ctrladdr);
-       udelay(10);
-       writeb(CTRL_RESET_OFF, priv->ctrladdr);
-}
-
-/* wait for LANCE interface to become not busy */
-
-static int WaitLANCE(struct net_device *dev)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       int t = 0;
-
-       while ((readb(priv->ctrladdr) & STAT_IO_BUSY) ==
-              STAT_IO_BUSY) {
-               udelay(1);
-               if (++t > 1000) {
-                       printk("%s: LANCE access timeout", dev->name);
-                       return 0;
-               }
-       }
-
-       return 1;
-}
-
-/* set LANCE register - must be atomic */
-
-static void SetLANCE(struct net_device *dev, u16 addr, u16 value)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       unsigned long flags;
-
-       /* disable interrupts */
-
-       spin_lock_irqsave(&priv->lock, flags);
-
-       /* wait until no transfer is pending */
-
-       WaitLANCE(dev);
-
-       /* transfer register address to RAP */
-
-       writeb(CTRL_RESET_OFF | CTRL_RW_WRITE | CTRL_ADR_RAP, priv->ctrladdr);
-       writew(addr, priv->ioregaddr);
-       writeb(IOCMD_GO, priv->cmdaddr);
-       udelay(1);
-       WaitLANCE(dev);
-
-       /* transfer data to register */
-
-       writeb(CTRL_RESET_OFF | CTRL_RW_WRITE | CTRL_ADR_DATA, priv->ctrladdr);
-       writew(value, priv->ioregaddr);
-       writeb(IOCMD_GO, priv->cmdaddr);
-       udelay(1);
-       WaitLANCE(dev);
-
-       /* reenable interrupts */
-
-       spin_unlock_irqrestore(&priv->lock, flags);
-}
-
-/* get LANCE register */
-
-static u16 GetLANCE(struct net_device *dev, u16 addr)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       unsigned long flags;
-       unsigned int res;
-
-       /* disable interrupts */
-
-       spin_lock_irqsave(&priv->lock, flags);
-
-       /* wait until no transfer is pending */
-
-       WaitLANCE(dev);
-
-       /* transfer register address to RAP */
-
-       writeb(CTRL_RESET_OFF | CTRL_RW_WRITE | CTRL_ADR_RAP, priv->ctrladdr);
-       writew(addr, priv->ioregaddr);
-       writeb(IOCMD_GO, priv->cmdaddr);
-       udelay(1);
-       WaitLANCE(dev);
-
-       /* transfer data from register */
-
-       writeb(CTRL_RESET_OFF | CTRL_RW_READ | CTRL_ADR_DATA, priv->ctrladdr);
-       writeb(IOCMD_GO, priv->cmdaddr);
-       udelay(1);
-       WaitLANCE(dev);
-       res = readw(priv->ioregaddr);
-
-       /* reenable interrupts */
-
-       spin_unlock_irqrestore(&priv->lock, flags);
-
-       return res;
-}
-
-/* build up descriptors in shared RAM */
-
-static void InitDscrs(struct net_device *dev)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       u32 bufaddr;
-
-       /* Set up Tx descriptors. The board has only 16K RAM so bits 16..23
-          are always 0. */
-
-       bufaddr = RAM_DATABASE;
-       {
-               LANCE_TxDescr descr;
-               int z;
-
-               for (z = 0; z < TXCOUNT; z++) {
-                       descr.LowAddr = bufaddr;
-                       descr.Flags = 0;
-                       descr.Len = 0xf000;
-                       descr.Status = 0;
-                       memcpy_toio(priv->base + RAM_TXBASE +
-                                  (z * sizeof(LANCE_TxDescr)), &descr,
-                                  sizeof(LANCE_TxDescr));
-                       memset_io(priv->base + bufaddr, 0, RAM_BUFSIZE);
-                       bufaddr += RAM_BUFSIZE;
-               }
-       }
-
-       /* do the same for the Rx descriptors */
-
-       {
-               LANCE_RxDescr descr;
-               int z;
-
-               for (z = 0; z < RXCOUNT; z++) {
-                       descr.LowAddr = bufaddr;
-                       descr.Flags = RXDSCR_FLAGS_OWN;
-                       descr.MaxLen = -RAM_BUFSIZE;
-                       descr.Len = 0;
-                       memcpy_toio(priv->base + RAM_RXBASE +
-                                  (z * sizeof(LANCE_RxDescr)), &descr,
-                                  sizeof(LANCE_RxDescr));
-                       memset_io(priv->base + bufaddr, 0, RAM_BUFSIZE);
-                       bufaddr += RAM_BUFSIZE;
-               }
-       }
-}
-
-/* calculate the hash bit position for a given multicast address
-   taken more or less directly from the AMD datasheet... */
-
-static void UpdateCRC(unsigned char *CRC, int bit)
-{
-       int j;
-
-       /* shift CRC one bit */
-
-       memmove(CRC + 1, CRC, 32 * sizeof(unsigned char));
-       CRC[0] = 0;
-
-       /* if bit XOR controlbit = 1, set CRC = CRC XOR polynomial */
-
-       if (bit ^ CRC[32])
-               for (j = 0; j < 32; j++)
-                       CRC[j] ^= poly[j];
-}
-
-static unsigned int GetHash(char *address)
-{
-       unsigned char CRC[33];
-       int i, byte, hashcode;
-
-       /* a multicast address has bit 0 in the first byte set */
-
-       if ((address[0] & 1) == 0)
-               return -1;
-
-       /* initialize CRC */
-
-       memset(CRC, 1, sizeof(CRC));
-
-       /* loop through address bits */
-
-       for (byte = 0; byte < 6; byte++)
-               for (i = 0; i < 8; i++)
-                       UpdateCRC(CRC, (address[byte] >> i) & 1);
-
-       /* hashcode is the 6 least significant bits of the CRC */
-
-       hashcode = 0;
-       for (i = 0; i < 6; i++)
-               hashcode = (hashcode << 1) + CRC[i];
-       return hashcode;
-}
-
-/* feed ready-built initialization block into LANCE */
-
-static void InitLANCE(struct net_device *dev)
-{
-       skmca_priv *priv = netdev_priv(dev);
-
-       /* build up descriptors. */
-
-       InitDscrs(dev);
-
-       /* next RX descriptor to be read is the first one.  Since the LANCE
-          will start from the beginning after initialization, we have to
-          reset out pointers too. */
-
-       priv->nextrx = 0;
-
-       /* no TX descriptors active */
-
-       priv->nexttxput = priv->nexttxdone = priv->txbusy = 0;
-
-       /* set up the LANCE bus control register - constant for SKnet boards */
-
-       SetLANCE(dev, LANCE_CSR3,
-                CSR3_BSWAP_OFF | CSR3_ALE_LOW | CSR3_BCON_HOLD);
-
-       /* write address of initialization block into LANCE */
-
-       SetLANCE(dev, LANCE_CSR1, RAM_INITBASE & 0xffff);
-       SetLANCE(dev, LANCE_CSR2, (RAM_INITBASE >> 16) & 0xff);
-
-       /* we don't get ready until the LANCE has read the init block */
-
-       netif_stop_queue(dev);
-
-       /* let LANCE read the initialization block.  LANCE is ready
-          when we receive the corresponding interrupt. */
-
-       SetLANCE(dev, LANCE_CSR0, CSR0_INEA | CSR0_INIT);
-}
-
-/* stop the LANCE so we can reinitialize it */
-
-static void StopLANCE(struct net_device *dev)
-{
-       /* can't take frames any more */
-
-       netif_stop_queue(dev);
-
-       /* disable interrupts, stop it */
-
-       SetLANCE(dev, LANCE_CSR0, CSR0_STOP);
-}
-
-/* initialize card and LANCE for proper operation */
-
-static void InitBoard(struct net_device *dev)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       LANCE_InitBlock block;
-
-       /* Lay out the shared RAM - first we create the init block for the LANCE.
-          We do not overwrite it later because we need it again when we switch
-          promiscous mode on/off. */
-
-       block.Mode = 0;
-       if (dev->flags & IFF_PROMISC)
-               block.Mode |= LANCE_INIT_PROM;
-       memcpy(block.PAdr, dev->dev_addr, 6);
-       memset(block.LAdrF, 0, sizeof(block.LAdrF));
-       block.RdrP = (RAM_RXBASE & 0xffffff) | (LRXCOUNT << 29);
-       block.TdrP = (RAM_TXBASE & 0xffffff) | (LTXCOUNT << 29);
-
-       memcpy_toio(priv->base + RAM_INITBASE, &block, sizeof(block));
-
-       /* initialize LANCE. Implicitly sets up other structures in RAM. */
-
-       InitLANCE(dev);
-}
-
-/* deinitialize card and LANCE */
-
-static void DeinitBoard(struct net_device *dev)
-{
-       /* stop LANCE */
-
-       StopLANCE(dev);
-
-       /* reset board */
-
-       ResetBoard(dev);
-}
-
-/* probe for device's irq */
-
-static int __init ProbeIRQ(struct net_device *dev)
-{
-       unsigned long imaskval, njiffies, irq;
-       u16 csr0val;
-
-       /* enable all interrupts */
-
-       imaskval = probe_irq_on();
-
-       /* initialize the board. Wait for interrupt 'Initialization done'. */
-
-       ResetBoard(dev);
-       InitBoard(dev);
-
-       njiffies = jiffies + HZ;
-       do {
-               csr0val = GetLANCE(dev, LANCE_CSR0);
-       }
-       while (((csr0val & CSR0_IDON) == 0) && (jiffies != njiffies));
-
-       /* turn of interrupts again */
-
-       irq = probe_irq_off(imaskval);
-
-       /* if we found something, ack the interrupt */
-
-       if (irq)
-               SetLANCE(dev, LANCE_CSR0, csr0val | CSR0_IDON);
-
-       /* back to idle state */
-
-       DeinitBoard(dev);
-
-       return irq;
-}
-
-/* ------------------------------------------------------------------------
- * interrupt handler(s)
- * ------------------------------------------------------------------------ */
-
-/* LANCE has read initialization block -> start it */
-
-static u16 irqstart_handler(struct net_device *dev, u16 oldcsr0)
-{
-       /* now we're ready to transmit */
-
-       netif_wake_queue(dev);
-
-       /* reset IDON bit, start LANCE */
-
-       SetLANCE(dev, LANCE_CSR0, oldcsr0 | CSR0_IDON | CSR0_STRT);
-       return GetLANCE(dev, LANCE_CSR0);
-}
-
-/* did we lose blocks due to a FIFO overrun ? */
-
-static u16 irqmiss_handler(struct net_device *dev, u16 oldcsr0)
-{
-       skmca_priv *priv = netdev_priv(dev);
-
-       /* update statistics */
-
-       priv->stat.rx_fifo_errors++;
-
-       /* reset MISS bit */
-
-       SetLANCE(dev, LANCE_CSR0, oldcsr0 | CSR0_MISS);
-       return GetLANCE(dev, LANCE_CSR0);
-}
-
-/* receive interrupt */
-
-static u16 irqrx_handler(struct net_device *dev, u16 oldcsr0)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       LANCE_RxDescr descr;
-       unsigned int descraddr;
-
-       /* run through queue until we reach a descriptor we do not own */
-
-       descraddr = RAM_RXBASE + (priv->nextrx * sizeof(LANCE_RxDescr));
-       while (1) {
-               /* read descriptor */
-               memcpy_fromio(&descr, priv->base + descraddr,
-                            sizeof(LANCE_RxDescr));
-
-               /* if we reach a descriptor we do not own, we're done */
-               if ((descr.Flags & RXDSCR_FLAGS_OWN) != 0)
-                       break;
-
-#ifdef DEBUG
-               PrTime();
-               printk("Receive packet on descr %d len %d\n", priv->nextrx,
-                      descr.Len);
-#endif
-
-               /* erroneous packet ? */
-               if ((descr.Flags & RXDSCR_FLAGS_ERR) != 0) {
-                       priv->stat.rx_errors++;
-                       if ((descr.Flags & RXDSCR_FLAGS_CRC) != 0)
-                               priv->stat.rx_crc_errors++;
-                       else if ((descr.Flags & RXDSCR_FLAGS_CRC) != 0)
-                               priv->stat.rx_frame_errors++;
-                       else if ((descr.Flags & RXDSCR_FLAGS_OFLO) != 0)
-                               priv->stat.rx_fifo_errors++;
-               }
-
-               /* good packet ? */
-               else {
-                       struct sk_buff *skb;
-
-                       skb = dev_alloc_skb(descr.Len + 2);
-                       if (skb == NULL)
-                               priv->stat.rx_dropped++;
-                       else {
-                               memcpy_fromio(skb_put(skb, descr.Len),
-                                            priv->base +
-                                            descr.LowAddr, descr.Len);
-                               skb->dev = dev;
-                               skb->protocol = eth_type_trans(skb, dev);
-                               skb->ip_summed = CHECKSUM_NONE;
-                               priv->stat.rx_packets++;
-                               priv->stat.rx_bytes += descr.Len;
-                               netif_rx(skb);
-                               dev->last_rx = jiffies;
-                       }
-               }
-
-               /* give descriptor back to LANCE */
-               descr.Len = 0;
-               descr.Flags |= RXDSCR_FLAGS_OWN;
-
-               /* update descriptor in shared RAM */
-               memcpy_toio(priv->base + descraddr, &descr,
-                          sizeof(LANCE_RxDescr));
-
-               /* go to next descriptor */
-               priv->nextrx++;
-               descraddr += sizeof(LANCE_RxDescr);
-               if (priv->nextrx >= RXCOUNT) {
-                       priv->nextrx = 0;
-                       descraddr = RAM_RXBASE;
-               }
-       }
-
-       /* reset RINT bit */
-
-       SetLANCE(dev, LANCE_CSR0, oldcsr0 | CSR0_RINT);
-       return GetLANCE(dev, LANCE_CSR0);
-}
-
-/* transmit interrupt */
-
-static u16 irqtx_handler(struct net_device *dev, u16 oldcsr0)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       LANCE_TxDescr descr;
-       unsigned int descraddr;
-
-       /* check descriptors at most until no busy one is left */
-
-       descraddr =
-           RAM_TXBASE + (priv->nexttxdone * sizeof(LANCE_TxDescr));
-       while (priv->txbusy > 0) {
-               /* read descriptor */
-               memcpy_fromio(&descr, priv->base + descraddr,
-                            sizeof(LANCE_TxDescr));
-
-               /* if the LANCE still owns this one, we've worked out all sent packets */
-               if ((descr.Flags & TXDSCR_FLAGS_OWN) != 0)
-                       break;
-
-#ifdef DEBUG
-               PrTime();
-               printk("Send packet done on descr %d\n", priv->nexttxdone);
-#endif
-
-               /* update statistics */
-               if ((descr.Flags & TXDSCR_FLAGS_ERR) == 0) {
-                       priv->stat.tx_packets++;
-                       priv->stat.tx_bytes++;
-               } else {
-                       priv->stat.tx_errors++;
-                       if ((descr.Status & TXDSCR_STATUS_UFLO) != 0) {
-                               priv->stat.tx_fifo_errors++;
-                               InitLANCE(dev);
-                       }
-                               else
-                           if ((descr.Status & TXDSCR_STATUS_LCOL) !=
-                               0) priv->stat.tx_window_errors++;
-                       else if ((descr.Status & TXDSCR_STATUS_LCAR) != 0)
-                               priv->stat.tx_carrier_errors++;
-                       else if ((descr.Status & TXDSCR_STATUS_RTRY) != 0)
-                               priv->stat.tx_aborted_errors++;
-               }
-
-               /* go to next descriptor */
-               priv->nexttxdone++;
-               descraddr += sizeof(LANCE_TxDescr);
-               if (priv->nexttxdone >= TXCOUNT) {
-                       priv->nexttxdone = 0;
-                       descraddr = RAM_TXBASE;
-               }
-               priv->txbusy--;
-       }
-
-       /* reset TX interrupt bit */
-
-       SetLANCE(dev, LANCE_CSR0, oldcsr0 | CSR0_TINT);
-       oldcsr0 = GetLANCE(dev, LANCE_CSR0);
-
-       /* at least one descriptor is freed.  Therefore we can accept
-          a new one */
-       /* inform upper layers we're in business again */
-
-       netif_wake_queue(dev);
-
-       return oldcsr0;
-}
-
-/* general interrupt entry */
-
-static irqreturn_t irq_handler(int irq, void *device)
-{
-       struct net_device *dev = (struct net_device *) device;
-       u16 csr0val;
-
-       /* read CSR0 to get interrupt cause */
-
-       csr0val = GetLANCE(dev, LANCE_CSR0);
-
-       /* in case we're not meant... */
-
-       if ((csr0val & CSR0_INTR) == 0)
-               return IRQ_NONE;
-
-#if 0
-       set_bit(LINK_STATE_RXSEM, &dev->state);
-#endif
-
-       /* loop through the interrupt bits until everything is clear */
-
-       do {
-               if ((csr0val & CSR0_IDON) != 0)
-                       csr0val = irqstart_handler(dev, csr0val);
-               if ((csr0val & CSR0_RINT) != 0)
-                       csr0val = irqrx_handler(dev, csr0val);
-               if ((csr0val & CSR0_MISS) != 0)
-                       csr0val = irqmiss_handler(dev, csr0val);
-               if ((csr0val & CSR0_TINT) != 0)
-                       csr0val = irqtx_handler(dev, csr0val);
-               if ((csr0val & CSR0_MERR) != 0) {
-                       SetLANCE(dev, LANCE_CSR0, csr0val | CSR0_MERR);
-                       csr0val = GetLANCE(dev, LANCE_CSR0);
-               }
-               if ((csr0val & CSR0_BABL) != 0) {
-                       SetLANCE(dev, LANCE_CSR0, csr0val | CSR0_BABL);
-                       csr0val = GetLANCE(dev, LANCE_CSR0);
-               }
-       }
-       while ((csr0val & CSR0_INTR) != 0);
-
-#if 0
-       clear_bit(LINK_STATE_RXSEM, &dev->state);
-#endif
-       return IRQ_HANDLED;
-}
-
-/* ------------------------------------------------------------------------
- * driver methods
- * ------------------------------------------------------------------------ */
-
-/* MCA info */
-
-static int skmca_getinfo(char *buf, int slot, void *d)
-{
-       int len = 0, i;
-       struct net_device *dev = (struct net_device *) d;
-       skmca_priv *priv;
-
-       /* can't say anything about an uninitialized device... */
-
-       if (dev == NULL)
-               return len;
-       priv = netdev_priv(dev);
-
-       /* print info */
-
-       len += sprintf(buf + len, "IRQ: %d\n", priv->realirq);
-       len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start,
-                      dev->mem_end - 1);
-       len +=
-           sprintf(buf + len, "Transceiver: %s\n",
-                   MediaNames[priv->medium]);
-       len += sprintf(buf + len, "Device: %s\n", dev->name);
-       len += sprintf(buf + len, "MAC address:");
-       for (i = 0; i < 6; i++)
-               len += sprintf(buf + len, " %02x", dev->dev_addr[i]);
-       buf[len++] = '\n';
-       buf[len] = 0;
-
-       return len;
-}
-
-/* open driver.  Means also initialization and start of LANCE */
-
-static int skmca_open(struct net_device *dev)
-{
-       int result;
-       skmca_priv *priv = netdev_priv(dev);
-
-       /* register resources - only necessary for IRQ */
-       result =
-           request_irq(priv->realirq, irq_handler,
-                       IRQF_SHARED | IRQF_SAMPLE_RANDOM, "sk_mca", dev);
-       if (result != 0) {
-               printk("%s: failed to register irq %d\n", dev->name,
-                      dev->irq);
-               return result;
-       }
-       dev->irq = priv->realirq;
-
-       /* set up the card and LANCE */
-
-       InitBoard(dev);
-
-       /* set up flags */
-
-       netif_start_queue(dev);
-
-       return 0;
-}
-
-/* close driver.  Shut down board and free allocated resources */
-
-static int skmca_close(struct net_device *dev)
-{
-       /* turn off board */
-       DeinitBoard(dev);
-
-       /* release resources */
-       if (dev->irq != 0)
-               free_irq(dev->irq, dev);
-       dev->irq = 0;
-
-       return 0;
-}
-
-/* transmit a block. */
-
-static int skmca_tx(struct sk_buff *skb, struct net_device *dev)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       LANCE_TxDescr descr;
-       unsigned int address;
-       int tmplen, retval = 0;
-       unsigned long flags;
-
-       /* if we get called with a NULL descriptor, the Ethernet layer thinks
-          our card is stuck an we should reset it.  We'll do this completely: */
-
-       if (skb == NULL) {
-               DeinitBoard(dev);
-               InitBoard(dev);
-               return 0;       /* don't try to free the block here ;-) */
-       }
-
-       /* is there space in the Tx queue ? If no, the upper layer gave us a
-          packet in spite of us not being ready and is really in trouble.
-          We'll do the dropping for him: */
-       if (priv->txbusy >= TXCOUNT) {
-               priv->stat.tx_dropped++;
-               retval = -EIO;
-               goto tx_done;
-       }
-
-       /* get TX descriptor */
-       address = RAM_TXBASE + (priv->nexttxput * sizeof(LANCE_TxDescr));
-       memcpy_fromio(&descr, priv->base + address, sizeof(LANCE_TxDescr));
-
-       /* enter packet length as 2s complement - assure minimum length */
-       tmplen = skb->len;
-       if (tmplen < 60)
-               tmplen = 60;
-       descr.Len = 65536 - tmplen;
-
-       /* copy filler into RAM - in case we're filling up...
-          we're filling a bit more than necessary, but that doesn't harm
-          since the buffer is far larger... */
-       if (tmplen > skb->len) {
-               char *fill = "NetBSD is a nice OS too! ";
-               unsigned int destoffs = 0, l = strlen(fill);
-
-               while (destoffs < tmplen) {
-                       memcpy_toio(priv->base + descr.LowAddr +
-                                  destoffs, fill, l);
-                       destoffs += l;
-               }
-       }
-
-       /* do the real data copying */
-       memcpy_toio(priv->base + descr.LowAddr, skb->data, skb->len);
-
-       /* hand descriptor over to LANCE - this is the first and last chunk */
-       descr.Flags =
-           TXDSCR_FLAGS_OWN | TXDSCR_FLAGS_STP | TXDSCR_FLAGS_ENP;
-
-#ifdef DEBUG
-       PrTime();
-       printk("Send packet on descr %d len %d\n", priv->nexttxput,
-              skb->len);
-#endif
-
-       /* one more descriptor busy */
-
-       spin_lock_irqsave(&priv->lock, flags);
-
-       priv->nexttxput++;
-       if (priv->nexttxput >= TXCOUNT)
-               priv->nexttxput = 0;
-       priv->txbusy++;
-
-       /* are we saturated ? */
-
-       if (priv->txbusy >= TXCOUNT)
-               netif_stop_queue(dev);
-
-       /* write descriptor back to RAM */
-       memcpy_toio(priv->base + address, &descr, sizeof(LANCE_TxDescr));
-
-       /* if no descriptors were active, give the LANCE a hint to read it
-          immediately */
-
-       if (priv->txbusy == 0)
-               SetLANCE(dev, LANCE_CSR0, CSR0_INEA | CSR0_TDMD);
-
-       spin_unlock_irqrestore(&priv->lock, flags);
-
-      tx_done:
-
-       dev_kfree_skb(skb);
-
-       return retval;
-}
-
-/* return pointer to Ethernet statistics */
-
-static struct net_device_stats *skmca_stats(struct net_device *dev)
-{
-       skmca_priv *priv = netdev_priv(dev);
-
-       return &(priv->stat);
-}
-
-/* switch receiver mode.  We use the LANCE's multicast filter to prefilter
-   multicast addresses. */
-
-static void skmca_set_multicast_list(struct net_device *dev)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       LANCE_InitBlock block;
-
-       /* first stop the LANCE... */
-       StopLANCE(dev);
-
-       /* ...then modify the initialization block... */
-       memcpy_fromio(&block, priv->base + RAM_INITBASE, sizeof(block));
-       if (dev->flags & IFF_PROMISC)
-               block.Mode |= LANCE_INIT_PROM;
-       else
-               block.Mode &= ~LANCE_INIT_PROM;
-
-       if (dev->flags & IFF_ALLMULTI) {        /* get all multicasts */
-               memset(block.LAdrF, 0xff, sizeof(block.LAdrF));
-       } else {                /* get selected/no multicasts */
-
-               struct dev_mc_list *mptr;
-               int code;
-
-               memset(block.LAdrF, 0, sizeof(block.LAdrF));
-               for (mptr = dev->mc_list; mptr != NULL; mptr = mptr->next) {
-                       code = GetHash(mptr->dmi_addr);
-                       block.LAdrF[(code >> 3) & 7] |= 1 << (code & 7);
-               }
-       }
-
-       memcpy_toio(priv->base + RAM_INITBASE, &block, sizeof(block));
-
-       /* ...then reinit LANCE with the correct flags */
-       InitLANCE(dev);
-}
-
-/* ------------------------------------------------------------------------
- * hardware check
- * ------------------------------------------------------------------------ */
-
-static int startslot;          /* counts through slots when probing multiple devices */
-
-static void cleanup_card(struct net_device *dev)
-{
-       skmca_priv *priv = netdev_priv(dev);
-       DeinitBoard(dev);
-       if (dev->irq != 0)
-               free_irq(dev->irq, dev);
-       iounmap(priv->base);
-       mca_mark_as_unused(priv->slot);
-       mca_set_adapter_procfn(priv->slot, NULL, NULL);
-}
-
-struct net_device * __init skmca_probe(int unit)
-{
-       struct net_device *dev;
-       int force_detect = 0;
-       int junior, slot, i;
-       int base = 0, irq = 0;
-       skmca_priv *priv;
-       skmca_medium medium;
-       int err;
-
-       /* can't work without an MCA bus ;-) */
-
-       if (MCA_bus == 0)
-               return ERR_PTR(-ENODEV);
-
-       dev = alloc_etherdev(sizeof(skmca_priv));
-       if (!dev)
-               return ERR_PTR(-ENOMEM);
-
-       if (unit >= 0) {
-               sprintf(dev->name, "eth%d", unit);
-               netdev_boot_setup_check(dev);
-       }
-
-       SET_MODULE_OWNER(dev);
-
-       /* start address of 1 --> forced detection */
-
-       if (dev->mem_start == 1)
-               force_detect = 1;
-
-       /* search through slots */
-
-       base = dev->mem_start;
-       irq = dev->base_addr;
-       for (slot = startslot; (slot = dofind(&junior, slot)) != -1; slot++) {
-               /* deduce card addresses */
-
-               getaddrs(slot, junior, &base, &irq, &medium);
-
-               /* slot already in use ? */
-
-               if (mca_is_adapter_used(slot))
-                       continue;
-
-               /* were we looking for something different ? */
-
-               if (dev->irq && dev->irq != irq)
-                       continue;
-               if (dev->mem_start && dev->mem_start != base)
-                       continue;
-
-               /* found something that matches */
-
-               break;
-       }
-
-       /* nothing found ? */
-
-       if (slot == -1) {
-               free_netdev(dev);
-               return (base || irq) ? ERR_PTR(-ENXIO) : ERR_PTR(-ENODEV);
-       }
-
-       /* make procfs entries */
-
-       if (junior)
-               mca_set_adapter_name(slot,
-                                    "SKNET junior MC2 Ethernet Adapter");
-       else
-               mca_set_adapter_name(slot, "SKNET MC2+ Ethernet Adapter");
-       mca_set_adapter_procfn(slot, (MCA_ProcFn) skmca_getinfo, dev);
-
-       mca_mark_as_used(slot);
-
-       /* announce success */
-       printk("%s: SKNet %s adapter found in slot %d\n", dev->name,
-              junior ? "Junior MC2" : "MC2+", slot + 1);
-
-       priv = netdev_priv(dev);
-       priv->base = ioremap(base, 0x4000);
-       if (!priv->base) {
-               mca_set_adapter_procfn(slot, NULL, NULL);
-               mca_mark_as_unused(slot);
-               free_netdev(dev);
-               return ERR_PTR(-ENOMEM);
-       }
-
-       priv->slot = slot;
-       priv->macbase = priv->base + 0x3fc0;
-       priv->ioregaddr = priv->base + 0x3ff0;
-       priv->ctrladdr = priv->base + 0x3ff2;
-       priv->cmdaddr = priv->base + 0x3ff3;
-       priv->medium = medium;
-       memset(&priv->stat, 0, sizeof(struct net_device_stats));
-       spin_lock_init(&priv->lock);
-
-       /* set base + irq for this device (irq not allocated so far) */
-       dev->irq = 0;
-       dev->mem_start = base;
-       dev->mem_end = base + 0x4000;
-
-       /* autoprobe ? */
-       if (irq < 0) {
-               int nirq;
-
-               printk
-                   ("%s: ambigous POS bit combination, must probe for IRQ...\n",
-                    dev->name);
-               nirq = ProbeIRQ(dev);
-               if (nirq <= 0)
-                       printk("%s: IRQ probe failed, assuming IRQ %d",
-                              dev->name, priv->realirq = -irq);
-               else
-                       priv->realirq = nirq;
-       } else
-               priv->realirq = irq;
-
-       /* set methods */
-       dev->open = skmca_open;
-       dev->stop = skmca_close;
-       dev->hard_start_xmit = skmca_tx;
-       dev->do_ioctl = NULL;
-       dev->get_stats = skmca_stats;
-       dev->set_multicast_list = skmca_set_multicast_list;
-       dev->flags |= IFF_MULTICAST;
-
-       /* copy out MAC address */
-       for (i = 0; i < 6; i++)
-               dev->dev_addr[i] = readb(priv->macbase + (i << 1));
-
-       /* print config */
-       printk("%s: IRQ %d, memory %#lx-%#lx, "
-              "MAC address %02x:%02x:%02x:%02x:%02x:%02x.\n",
-              dev->name, priv->realirq, dev->mem_start, dev->mem_end - 1,
-              dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
-              dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
-       printk("%s: %s medium\n", dev->name, MediaNames[priv->medium]);
-
-       /* reset board */
-
-       ResetBoard(dev);
-
-       startslot = slot + 1;
-
-       err = register_netdev(dev);
-       if (err) {
-               cleanup_card(dev);
-               free_netdev(dev);
-               dev = ERR_PTR(err);
-       }
-       return dev;
-}
-
-/* ------------------------------------------------------------------------
- * modularization support
- * ------------------------------------------------------------------------ */
-
-#ifdef MODULE
-MODULE_LICENSE("GPL");
-
-#define DEVMAX 5
-
-static struct net_device *moddevs[DEVMAX];
-
-int init_module(void)
-{
-       int z;
-
-       startslot = 0;
-       for (z = 0; z < DEVMAX; z++) {
-               struct net_device *dev = skmca_probe(-1);
-               if (IS_ERR(dev))
-                       break;
-               moddevs[z] = dev;
-       }
-       if (!z)
-               return -EIO;
-       return 0;
-}
-
-void cleanup_module(void)
-{
-       int z;
-
-       for (z = 0; z < DEVMAX; z++) {
-               struct net_device *dev = moddevs[z];
-               if (dev) {
-                       unregister_netdev(dev);
-                       cleanup_card(dev);
-                       free_netdev(dev);
-               }
-       }
-}
-#endif                         /* MODULE */
diff --git a/drivers/net/sk_mca.h b/drivers/net/sk_mca.h
deleted file mode 100644 (file)
index 0dae056..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-#ifndef _SK_MCA_INCLUDE_
-#define _SK_MCA_INCLUDE_
-
-#ifdef _SK_MCA_DRIVER_
-
-/* Adapter ID's */
-#define SKNET_MCA_ID 0x6afd
-#define SKNET_JUNIOR_MCA_ID 0x6be9
-
-/* media enumeration - defined in a way that it fits onto the MC2+'s
-   POS registers... */
-
-typedef enum { Media_10Base2, Media_10BaseT,
-       Media_10Base5, Media_Unknown, Media_Count
-} skmca_medium;
-
-/* private structure */
-typedef struct {
-       unsigned int slot;      /* MCA-Slot-#                       */
-       void __iomem *base;
-       void __iomem *macbase;  /* base address of MAC address PROM */
-       void __iomem *ioregaddr;/* address of I/O-register (Lo)     */
-       void __iomem *ctrladdr; /* address of control/stat register */
-       void __iomem *cmdaddr;  /* address of I/O-command register  */
-       int nextrx;             /* index of next RX descriptor to
-                                  be read                          */
-       int nexttxput;          /* index of next free TX descriptor */
-       int nexttxdone;         /* index of next TX descriptor to
-                                  be finished                      */
-       int txbusy;             /* # of busy TX descriptors         */
-       struct net_device_stats stat;   /* packet statistics            */
-       int realirq;            /* memorizes actual IRQ, even when
-                                  currently not allocated          */
-       skmca_medium medium;    /* physical cannector               */
-       spinlock_t lock;
-} skmca_priv;
-
-/* card registers: control/status register bits */
-
-#define CTRL_ADR_DATA      0   /* Bit 0 = 0 ->access data register  */
-#define CTRL_ADR_RAP       1   /* Bit 0 = 1 ->access RAP register   */
-#define CTRL_RW_WRITE      0   /* Bit 1 = 0 ->write register        */
-#define CTRL_RW_READ       2   /* Bit 1 = 1 ->read register         */
-#define CTRL_RESET_ON      0   /* Bit 3 = 0 ->reset board           */
-#define CTRL_RESET_OFF     8   /* Bit 3 = 1 ->no reset of board     */
-
-#define STAT_ADR_DATA      0   /* Bit 0 of ctrl register read back  */
-#define STAT_ADR_RAP       1
-#define STAT_RW_WRITE      0   /* Bit 1 of ctrl register read back  */
-#define STAT_RW_READ       2
-#define STAT_RESET_ON      0   /* Bit 3 of ctrl register read back  */
-#define STAT_RESET_OFF     8
-#define STAT_IRQ_ACT       0   /* interrupt pending                 */
-#define STAT_IRQ_NOACT     16  /* no interrupt pending              */
-#define STAT_IO_NOBUSY     0   /* no transfer busy                  */
-#define STAT_IO_BUSY       32  /* transfer busy                     */
-
-/* I/O command register bits */
-
-#define IOCMD_GO           128 /* Bit 7 = 1 -> start register xfer  */
-
-/* LANCE registers */
-
-#define LANCE_CSR0         0   /* Status/Control                    */
-
-#define CSR0_ERR           0x8000      /* general error flag                */
-#define CSR0_BABL          0x4000      /* transmitter timeout               */
-#define CSR0_CERR          0x2000      /* collision error                   */
-#define CSR0_MISS          0x1000      /* lost Rx block                     */
-#define CSR0_MERR          0x0800      /* memory access error               */
-#define CSR0_RINT          0x0400      /* receiver interrupt                */
-#define CSR0_TINT          0x0200      /* transmitter interrupt             */
-#define CSR0_IDON          0x0100      /* initialization done               */
-#define CSR0_INTR          0x0080      /* general interrupt flag            */
-#define CSR0_INEA          0x0040      /* interrupt enable                  */
-#define CSR0_RXON          0x0020      /* receiver enabled                  */
-#define CSR0_TXON          0x0010      /* transmitter enabled               */
-#define CSR0_TDMD          0x0008      /* force transmission now            */
-#define CSR0_STOP          0x0004      /* stop LANCE                        */
-#define CSR0_STRT          0x0002      /* start LANCE                       */
-#define CSR0_INIT          0x0001      /* read initialization block         */
-
-#define LANCE_CSR1         1   /* addr bit 0..15 of initialization  */
-#define LANCE_CSR2         2   /*          16..23 block             */
-
-#define LANCE_CSR3         3   /* Bus control                       */
-#define CSR3_BCON_HOLD     0   /* Bit 0 = 0 -> BM1,BM0,HOLD         */
-#define CSR3_BCON_BUSRQ    1   /* Bit 0 = 1 -> BUSAK0,BYTE,BUSRQ    */
-#define CSR3_ALE_HIGH      0   /* Bit 1 = 0 -> ALE asserted high    */
-#define CSR3_ALE_LOW       2   /* Bit 1 = 1 -> ALE asserted low     */
-#define CSR3_BSWAP_OFF     0   /* Bit 2 = 0 -> no byte swap         */
-#define CSR3_BSWAP_ON      4   /* Bit 2 = 1 -> byte swap            */
-
-/* LANCE structures */
-
-typedef struct {               /* LANCE initialization block        */
-       u16 Mode;               /* mode flags                        */
-       u8 PAdr[6];             /* MAC address                       */
-       u8 LAdrF[8];            /* Multicast filter                  */
-       u32 RdrP;               /* Receive descriptor                */
-       u32 TdrP;               /* Transmit descriptor               */
-} LANCE_InitBlock;
-
-/* Mode flags init block */
-
-#define LANCE_INIT_PROM    0x8000      /* enable promiscous mode            */
-#define LANCE_INIT_INTL    0x0040      /* internal loopback                 */
-#define LANCE_INIT_DRTY    0x0020      /* disable retry                     */
-#define LANCE_INIT_COLL    0x0010      /* force collision                   */
-#define LANCE_INIT_DTCR    0x0008      /* disable transmit CRC              */
-#define LANCE_INIT_LOOP    0x0004      /* loopback                          */
-#define LANCE_INIT_DTX     0x0002      /* disable transmitter               */
-#define LANCE_INIT_DRX     0x0001      /* disable receiver                  */
-
-typedef struct {               /* LANCE Tx descriptor               */
-       u16 LowAddr;            /* bit 0..15 of address              */
-       u16 Flags;              /* bit 16..23 of address + Flags     */
-       u16 Len;                /* 2s complement of packet length    */
-       u16 Status;             /* Result of transmission            */
-} LANCE_TxDescr;
-
-#define TXDSCR_FLAGS_OWN   0x8000      /* LANCE owns descriptor             */
-#define TXDSCR_FLAGS_ERR   0x4000      /* summary error flag                */
-#define TXDSCR_FLAGS_MORE  0x1000      /* more than one retry needed?       */
-#define TXDSCR_FLAGS_ONE   0x0800      /* one retry?                        */
-#define TXDSCR_FLAGS_DEF   0x0400      /* transmission deferred?            */
-#define TXDSCR_FLAGS_STP   0x0200      /* first packet in chain?            */
-#define TXDSCR_FLAGS_ENP   0x0100      /* last packet in chain?             */
-
-#define TXDSCR_STATUS_BUFF 0x8000      /* buffer error?                     */
-#define TXDSCR_STATUS_UFLO 0x4000      /* silo underflow during transmit?   */
-#define TXDSCR_STATUS_LCOL 0x1000      /* late collision?                   */
-#define TXDSCR_STATUS_LCAR 0x0800      /* loss of carrier?                  */
-#define TXDSCR_STATUS_RTRY 0x0400      /* retry error?                      */
-
-typedef struct {               /* LANCE Rx descriptor               */
-       u16 LowAddr;            /* bit 0..15 of address              */
-       u16 Flags;              /* bit 16..23 of address + Flags     */
-       u16 MaxLen;             /* 2s complement of buffer length    */
-       u16 Len;                /* packet length                     */
-} LANCE_RxDescr;
-
-#define RXDSCR_FLAGS_OWN   0x8000      /* LANCE owns descriptor             */
-#define RXDSCR_FLAGS_ERR   0x4000      /* summary error flag                */
-#define RXDSCR_FLAGS_FRAM  0x2000      /* framing error flag                */
-#define RXDSCR_FLAGS_OFLO  0x1000      /* FIFO overflow?                    */
-#define RXDSCR_FLAGS_CRC   0x0800      /* CRC error?                        */
-#define RXDSCR_FLAGS_BUFF  0x0400      /* buffer error?                     */
-#define RXDSCR_FLAGS_STP   0x0200      /* first packet in chain?            */
-#define RXDCSR_FLAGS_ENP   0x0100      /* last packet in chain?             */
-
-/* RAM layout */
-
-#define TXCOUNT            4   /* length of TX descriptor queue     */
-#define LTXCOUNT           2   /* log2 of it                        */
-#define RXCOUNT            4   /* length of RX descriptor queue     */
-#define LRXCOUNT           2   /* log2 of it                        */
-
-#define RAM_INITBASE       0   /* LANCE init block                  */
-#define RAM_TXBASE         24  /* Start of TX descriptor queue      */
-#define RAM_RXBASE         \
-(RAM_TXBASE + (TXCOUNT * 8))   /* Start of RX descriptor queue      */
-#define RAM_DATABASE       \
-(RAM_RXBASE + (RXCOUNT * 8))   /* Start of data area for frames     */
-#define RAM_BUFSIZE        1580        /* max. frame size - should never be
-                                  reached                           */
-
-#endif                         /* _SK_MCA_DRIVER_ */
-
-#endif /* _SK_MCA_INCLUDE_ */
diff --git a/drivers/net/skfp/can.c b/drivers/net/skfp/can.c
deleted file mode 100644 (file)
index 8a49abc..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/******************************************************************************
- *
- *     (C)Copyright 1998,1999 SysKonnect,
- *     a business unit of Schneider & Koch & Co. Datensysteme GmbH.
- *
- *     See the file "skfddi.c" for further information.
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     The information in this file is provided "AS IS" without warranty.
- *
- ******************************************************************************/
-
-#ifndef        lint
-static const char xID_sccs[] = "@(#)can.c      1.5 97/04/07 (C) SK " ;
-#endif
-
-/*
- * canonical bit order
- */
-const u_char canonical[256] = {
-       0x00,0x80,0x40,0xc0,0x20,0xa0,0x60,0xe0,
-       0x10,0x90,0x50,0xd0,0x30,0xb0,0x70,0xf0,
-       0x08,0x88,0x48,0xc8,0x28,0xa8,0x68,0xe8,
-       0x18,0x98,0x58,0xd8,0x38,0xb8,0x78,0xf8,
-       0x04,0x84,0x44,0xc4,0x24,0xa4,0x64,0xe4,
-       0x14,0x94,0x54,0xd4,0x34,0xb4,0x74,0xf4,
-       0x0c,0x8c,0x4c,0xcc,0x2c,0xac,0x6c,0xec,
-       0x1c,0x9c,0x5c,0xdc,0x3c,0xbc,0x7c,0xfc,
-       0x02,0x82,0x42,0xc2,0x22,0xa2,0x62,0xe2,
-       0x12,0x92,0x52,0xd2,0x32,0xb2,0x72,0xf2,
-       0x0a,0x8a,0x4a,0xca,0x2a,0xaa,0x6a,0xea,
-       0x1a,0x9a,0x5a,0xda,0x3a,0xba,0x7a,0xfa,
-       0x06,0x86,0x46,0xc6,0x26,0xa6,0x66,0xe6,
-       0x16,0x96,0x56,0xd6,0x36,0xb6,0x76,0xf6,
-       0x0e,0x8e,0x4e,0xce,0x2e,0xae,0x6e,0xee,
-       0x1e,0x9e,0x5e,0xde,0x3e,0xbe,0x7e,0xfe,
-       0x01,0x81,0x41,0xc1,0x21,0xa1,0x61,0xe1,
-       0x11,0x91,0x51,0xd1,0x31,0xb1,0x71,0xf1,
-       0x09,0x89,0x49,0xc9,0x29,0xa9,0x69,0xe9,
-       0x19,0x99,0x59,0xd9,0x39,0xb9,0x79,0xf9,
-       0x05,0x85,0x45,0xc5,0x25,0xa5,0x65,0xe5,
-       0x15,0x95,0x55,0xd5,0x35,0xb5,0x75,0xf5,
-       0x0d,0x8d,0x4d,0xcd,0x2d,0xad,0x6d,0xed,
-       0x1d,0x9d,0x5d,0xdd,0x3d,0xbd,0x7d,0xfd,
-       0x03,0x83,0x43,0xc3,0x23,0xa3,0x63,0xe3,
-       0x13,0x93,0x53,0xd3,0x33,0xb3,0x73,0xf3,
-       0x0b,0x8b,0x4b,0xcb,0x2b,0xab,0x6b,0xeb,
-       0x1b,0x9b,0x5b,0xdb,0x3b,0xbb,0x7b,0xfb,
-       0x07,0x87,0x47,0xc7,0x27,0xa7,0x67,0xe7,
-       0x17,0x97,0x57,0xd7,0x37,0xb7,0x77,0xf7,
-       0x0f,0x8f,0x4f,0xcf,0x2f,0xaf,0x6f,0xef,
-       0x1f,0x9f,0x5f,0xdf,0x3f,0xbf,0x7f,0xff
-} ;
-
-#ifdef MAKE_TABLE
-int byte_reverse(x)
-int x ;
-{
-       int     y = 0 ;
-
-       if (x & 0x01)
-               y |= 0x80 ;
-       if (x & 0x02)
-               y |= 0x40 ;
-       if (x & 0x04)
-               y |= 0x20 ;
-       if (x & 0x08)
-               y |= 0x10 ;
-       if (x & 0x10)
-               y |= 0x08 ;
-       if (x & 0x20)
-               y |= 0x04 ;
-       if (x & 0x40)
-               y |= 0x02 ;
-       if (x & 0x80)
-               y |= 0x01 ;
-       return(y) ;
-}
-#endif
index 5b475833f64562d23177c5f2393a9a94c6327956..4fe624b0dd251907522f74d9aecd97554f3f3040 100644 (file)
@@ -23,6 +23,7 @@
 #include "h/smc.h"
 #include "h/supern_2.h"
 #include "h/skfbiinc.h"
+#include <linux/bitrev.h>
 
 #ifndef        lint
 static const char ID_sccs[] = "@(#)drvfbi.c    1.63 99/02/11 (C) SK " ;
@@ -445,16 +446,14 @@ void read_address(struct s_smc *smc, u_char *mac_addr)
        char PmdType ;
        int     i ;
 
-       extern const u_char canonical[256] ;
-
 #if    (defined(ISA) || defined(MCA))
        for (i = 0; i < 4 ;i++) {       /* read mac address from board */
                smc->hw.fddi_phys_addr.a[i] =
-                       canonical[(inpw(PR_A(i+SA_MAC))&0xff)] ;
+                       bitrev8(inpw(PR_A(i+SA_MAC)));
        }
        for (i = 4; i < 6; i++) {
                smc->hw.fddi_phys_addr.a[i] =
-                       canonical[(inpw(PR_A(i+SA_MAC+PRA_OFF))&0xff)] ;
+                       bitrev8(inpw(PR_A(i+SA_MAC+PRA_OFF)));
        }
 #endif
 #ifdef EISA
@@ -464,17 +463,17 @@ void read_address(struct s_smc *smc, u_char *mac_addr)
         */
        for (i = 0; i < 4 ;i++) {       /* read mac address from board */
                smc->hw.fddi_phys_addr.a[i] =
-                       canonical[inp(PR_A(i+SA_MAC))] ;
+                       bitrev8(inp(PR_A(i+SA_MAC)));
        }
        for (i = 4; i < 6; i++) {
                smc->hw.fddi_phys_addr.a[i] =
-                       canonical[inp(PR_A(i+SA_MAC+PRA_OFF))] ;
+                       bitrev8(inp(PR_A(i+SA_MAC+PRA_OFF)));
        }
 #endif
 #ifdef PCI
        for (i = 0; i < 6; i++) {       /* read mac address from board */
                smc->hw.fddi_phys_addr.a[i] =
-                       canonical[inp(ADDR(B2_MAC_0+i))] ;
+                       bitrev8(inp(ADDR(B2_MAC_0+i)));
        }
 #endif
 #ifndef        PCI
@@ -493,7 +492,7 @@ void read_address(struct s_smc *smc, u_char *mac_addr)
        if (mac_addr) {
                for (i = 0; i < 6 ;i++) {
                        smc->hw.fddi_canon_addr.a[i] = mac_addr[i] ;
-                       smc->hw.fddi_home_addr.a[i] = canonical[mac_addr[i]] ;
+                       smc->hw.fddi_home_addr.a[i] = bitrev8(mac_addr[i]);
                }
                return ;
        }
@@ -501,7 +500,7 @@ void read_address(struct s_smc *smc, u_char *mac_addr)
 
        for (i = 0; i < 6 ;i++) {
                smc->hw.fddi_canon_addr.a[i] =
-                       canonical[smc->hw.fddi_phys_addr.a[i]] ;
+                       bitrev8(smc->hw.fddi_phys_addr.a[i]);
        }
 }
 
@@ -1269,11 +1268,8 @@ void driver_get_bia(struct s_smc *smc, struct fddi_addr *bia_addr)
 {
        int i ;
 
-       extern const u_char canonical[256] ;
-
-       for (i = 0 ; i < 6 ; i++) {
-               bia_addr->a[i] = canonical[smc->hw.fddi_phys_addr.a[i]] ;
-       }
+       for (i = 0 ; i < 6 ; i++)
+               bia_addr->a[i] = bitrev8(smc->hw.fddi_phys_addr.a[i]);
 }
 
 void smt_start_watchdog(struct s_smc *smc)
index 0784f558ca9a395e2f36b22fa5e802b16376e9ae..a45205da8033d6eb8aea4d56df39fe4375ffb99b 100644 (file)
@@ -22,7 +22,7 @@
 #include "h/fddi.h"
 #include "h/smc.h"
 #include "h/supern_2.h"
-#include "can.c"
+#include <linux/bitrev.h>
 
 #ifndef        lint
 static const char ID_sccs[] = "@(#)fplustm.c   1.32 99/02/23 (C) SK " ;
@@ -1073,7 +1073,7 @@ static struct s_fpmc* mac_get_mc_table(struct s_smc *smc,
        if (can) {
                p = own->a ;
                for (i = 0 ; i < 6 ; i++, p++)
-                       *p = canonical[*p] ;
+                       *p = bitrev8(*p);
        }
        slot = NULL;
        for (i = 0, tb = smc->hw.fp.mc.table ; i < FPMAX_MULTICAST ; i++, tb++){
index 99a776a51fb5764872d2d5a4ee7f44e373556b3f..fe847800acdcd85ac2a962668d6a0b19eadd7415 100644 (file)
@@ -18,6 +18,7 @@
 #include "h/fddi.h"
 #include "h/smc.h"
 #include "h/smt_p.h"
+#include <linux/bitrev.h>
 
 #define KERNEL
 #include "h/smtstate.h"
@@ -26,8 +27,6 @@
 static const char ID_sccs[] = "@(#)smt.c       2.43 98/11/23 (C) SK " ;
 #endif
 
-extern const u_char canonical[256] ;
-
 /*
  * FC in SMbuf
  */
@@ -180,7 +179,7 @@ void smt_agent_init(struct s_smc *smc)
        driver_get_bia(smc,&smc->mib.fddiSMTStationId.sid_node) ;
        for (i = 0 ; i < 6 ; i ++) {
                smc->mib.fddiSMTStationId.sid_node.a[i] =
-                       canonical[smc->mib.fddiSMTStationId.sid_node.a[i]] ;
+                       bitrev8(smc->mib.fddiSMTStationId.sid_node.a[i]);
        }
        smc->mib.fddiSMTManufacturerData[0] =
                smc->mib.fddiSMTStationId.sid_node.a[0] ;
@@ -2049,9 +2048,8 @@ static void hwm_conv_can(struct s_smc *smc, char *data, int len)
 
        SK_UNUSED(smc) ;
 
-       for (i = len; i ; i--, data++) {
-               *data = canonical[*(u_char *)data] ;
-       }
+       for (i = len; i ; i--, data++)
+               *data = bitrev8(*data);
 }
 #endif
 
index 45283f3f95e4a345e4c769d2181432c0deba0082..e482e7fcbb2be36117ee646d4699fb87d49c141d 100644 (file)
@@ -42,7 +42,7 @@
 #include "skge.h"
 
 #define DRV_NAME               "skge"
-#define DRV_VERSION            "1.9"
+#define DRV_VERSION            "1.10"
 #define PFX                    DRV_NAME " "
 
 #define DEFAULT_TX_RING_SIZE   128
@@ -132,18 +132,93 @@ static void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs,
 }
 
 /* Wake on Lan only supported on Yukon chips with rev 1 or above */
-static int wol_supported(const struct skge_hw *hw)
+static u32 wol_supported(const struct skge_hw *hw)
 {
-       return !((hw->chip_id == CHIP_ID_GENESIS ||
-                 (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)));
+       if (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev != 0)
+               return WAKE_MAGIC | WAKE_PHY;
+       else
+               return 0;
+}
+
+static u32 pci_wake_enabled(struct pci_dev *dev)
+{
+       int pm = pci_find_capability(dev, PCI_CAP_ID_PM);
+       u16 value;
+
+       /* If device doesn't support PM Capabilities, but request is to disable
+        * wake events, it's a nop; otherwise fail */
+       if (!pm)
+               return 0;
+
+       pci_read_config_word(dev, pm + PCI_PM_PMC, &value);
+
+       value &= PCI_PM_CAP_PME_MASK;
+       value >>= ffs(PCI_PM_CAP_PME_MASK) - 1;   /* First bit of mask */
+
+       return value != 0;
+}
+
+static void skge_wol_init(struct skge_port *skge)
+{
+       struct skge_hw *hw = skge->hw;
+       int port = skge->port;
+       enum pause_control save_mode;
+       u32 ctrl;
+
+       /* Bring hardware out of reset */
+       skge_write16(hw, B0_CTST, CS_RST_CLR);
+       skge_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR);
+
+       skge_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
+       skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
+
+       /* Force to 10/100 skge_reset will re-enable on resume   */
+       save_mode = skge->flow_control;
+       skge->flow_control = FLOW_MODE_SYMMETRIC;
+
+       ctrl = skge->advertising;
+       skge->advertising &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full);
+
+       skge_phy_reset(skge);
+
+       skge->flow_control = save_mode;
+       skge->advertising = ctrl;
+
+       /* Set GMAC to no flow control and auto update for speed/duplex */
+       gma_write16(hw, port, GM_GP_CTRL,
+                   GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA|
+                   GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS);
+
+       /* Set WOL address */
+       memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR),
+                   skge->netdev->dev_addr, ETH_ALEN);
+
+       /* Turn on appropriate WOL control bits */
+       skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT);
+       ctrl = 0;
+       if (skge->wol & WAKE_PHY)
+               ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT;
+       else
+               ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT;
+
+       if (skge->wol & WAKE_MAGIC)
+               ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
+       else
+               ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;;
+
+       ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
+       skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
+
+       /* block receiver */
+       skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
 }
 
 static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
 {
        struct skge_port *skge = netdev_priv(dev);
 
-       wol->supported = wol_supported(skge->hw) ? WAKE_MAGIC : 0;
-       wol->wolopts = skge->wol ? WAKE_MAGIC : 0;
+       wol->supported = wol_supported(skge->hw);
+       wol->wolopts = skge->wol;
 }
 
 static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
@@ -151,23 +226,12 @@ static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
        struct skge_port *skge = netdev_priv(dev);
        struct skge_hw *hw = skge->hw;
 
-       if (wol->wolopts != WAKE_MAGIC && wol->wolopts != 0)
+       if (wol->wolopts & wol_supported(hw))
                return -EOPNOTSUPP;
 
-       if (wol->wolopts == WAKE_MAGIC && !wol_supported(hw))
-               return -EOPNOTSUPP;
-
-       skge->wol = wol->wolopts == WAKE_MAGIC;
-
-       if (skge->wol) {
-               memcpy_toio(hw->regs + WOL_MAC_ADDR, dev->dev_addr, ETH_ALEN);
-
-               skge_write16(hw, WOL_CTRL_STAT,
-                            WOL_CTL_ENA_PME_ON_MAGIC_PKT |
-                            WOL_CTL_ENA_MAGIC_PKT_UNIT);
-       } else
-               skge_write16(hw, WOL_CTRL_STAT, WOL_CTL_DEFAULT);
-
+       skge->wol = wol->wolopts;
+       if (!netif_running(dev))
+               skge_wol_init(skge);
        return 0;
 }
 
@@ -2373,6 +2437,9 @@ static int skge_up(struct net_device *dev)
        size_t rx_size, tx_size;
        int err;
 
+       if (!is_valid_ether_addr(dev->dev_addr))
+               return -EINVAL;
+
        if (netif_msg_ifup(skge))
                printk(KERN_INFO PFX "%s: enabling interface\n", dev->name);
 
@@ -2392,7 +2459,7 @@ static int skge_up(struct net_device *dev)
        BUG_ON(skge->dma & 7);
 
        if ((u64)skge->dma >> 32 != ((u64) skge->dma + skge->mem_size) >> 32) {
-               printk(KERN_ERR PFX "pci_alloc_consistent region crosses 4G boundary\n");
+               dev_err(&hw->pdev->dev, "pci_alloc_consistent region crosses 4G boundary\n");
                err = -EINVAL;
                goto free_pci_mem;
        }
@@ -3001,6 +3068,7 @@ static void skge_mac_intr(struct skge_hw *hw, int port)
 /* Handle device specific framing and timeout interrupts */
 static void skge_error_irq(struct skge_hw *hw)
 {
+       struct pci_dev *pdev = hw->pdev;
        u32 hwstatus = skge_read32(hw, B0_HWE_ISRC);
 
        if (hw->chip_id == CHIP_ID_GENESIS) {
@@ -3016,12 +3084,12 @@ static void skge_error_irq(struct skge_hw *hw)
        }
 
        if (hwstatus & IS_RAM_RD_PAR) {
-               printk(KERN_ERR PFX "Ram read data parity error\n");
+               dev_err(&pdev->dev, "Ram read data parity error\n");
                skge_write16(hw, B3_RI_CTRL, RI_CLR_RD_PERR);
        }
 
        if (hwstatus & IS_RAM_WR_PAR) {
-               printk(KERN_ERR PFX "Ram write data parity error\n");
+               dev_err(&pdev->dev, "Ram write data parity error\n");
                skge_write16(hw, B3_RI_CTRL, RI_CLR_WR_PERR);
        }
 
@@ -3032,38 +3100,38 @@ static void skge_error_irq(struct skge_hw *hw)
                skge_mac_parity(hw, 1);
 
        if (hwstatus & IS_R1_PAR_ERR) {
-               printk(KERN_ERR PFX "%s: receive queue parity error\n",
-                      hw->dev[0]->name);
+               dev_err(&pdev->dev, "%s: receive queue parity error\n",
+                       hw->dev[0]->name);
                skge_write32(hw, B0_R1_CSR, CSR_IRQ_CL_P);
        }
 
        if (hwstatus & IS_R2_PAR_ERR) {
-               printk(KERN_ERR PFX "%s: receive queue parity error\n",
-                      hw->dev[1]->name);
+               dev_err(&pdev->dev, "%s: receive queue parity error\n",
+                       hw->dev[1]->name);
                skge_write32(hw, B0_R2_CSR, CSR_IRQ_CL_P);
        }
 
        if (hwstatus & (IS_IRQ_MST_ERR|IS_IRQ_STAT)) {
                u16 pci_status, pci_cmd;
 
-               pci_read_config_word(hw->pdev, PCI_COMMAND, &pci_cmd);
-               pci_read_config_word(hw->pdev, PCI_STATUS, &pci_status);
+               pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
+               pci_read_config_word(pdev, PCI_STATUS, &pci_status);
 
-               printk(KERN_ERR PFX "%s: PCI error cmd=%#x status=%#x\n",
-                              pci_name(hw->pdev), pci_cmd, pci_status);
+               dev_err(&pdev->dev, "PCI error cmd=%#x status=%#x\n",
+                       pci_cmd, pci_status);
 
                /* Write the error bits back to clear them. */
                pci_status &= PCI_STATUS_ERROR_BITS;
                skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
-               pci_write_config_word(hw->pdev, PCI_COMMAND,
+               pci_write_config_word(pdev, PCI_COMMAND,
                                      pci_cmd | PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
-               pci_write_config_word(hw->pdev, PCI_STATUS, pci_status);
+               pci_write_config_word(pdev, PCI_STATUS, pci_status);
                skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
 
                /* if error still set then just ignore it */
                hwstatus = skge_read32(hw, B0_HWE_ISRC);
                if (hwstatus & IS_IRQ_STAT) {
-                       printk(KERN_INFO PFX "unable to clear error (so ignoring them)\n");
+                       dev_warn(&hw->pdev->dev, "unable to clear error (so ignoring them)\n");
                        hw->intr_mask &= ~IS_HW_ERR;
                }
        }
@@ -3277,8 +3345,8 @@ static int skge_reset(struct skge_hw *hw)
                        hw->phy_addr = PHY_ADDR_BCOM;
                        break;
                default:
-                       printk(KERN_ERR PFX "%s: unsupported phy type 0x%x\n",
-                              pci_name(hw->pdev), hw->phy_type);
+                       dev_err(&hw->pdev->dev, "unsupported phy type 0x%x\n",
+                              hw->phy_type);
                        return -EOPNOTSUPP;
                }
                break;
@@ -3293,8 +3361,8 @@ static int skge_reset(struct skge_hw *hw)
                break;
 
        default:
-               printk(KERN_ERR PFX "%s: unsupported chip type 0x%x\n",
-                      pci_name(hw->pdev), hw->chip_id);
+               dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
+                      hw->chip_id);
                return -EOPNOTSUPP;
        }
 
@@ -3334,7 +3402,7 @@ static int skge_reset(struct skge_hw *hw)
                /* avoid boards with stuck Hardware error bits */
                if ((skge_read32(hw, B0_ISRC) & IS_HW_ERR) &&
                    (skge_read32(hw, B0_HWE_ISRC) & IS_IRQ_SENSOR)) {
-                       printk(KERN_WARNING PFX "stuck hardware sensor bit\n");
+                       dev_warn(&hw->pdev->dev, "stuck hardware sensor bit\n");
                        hw->intr_mask &= ~IS_HW_ERR;
                }
 
@@ -3408,7 +3476,7 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port,
        struct net_device *dev = alloc_etherdev(sizeof(*skge));
 
        if (!dev) {
-               printk(KERN_ERR "skge etherdev alloc failed");
+               dev_err(&hw->pdev->dev, "etherdev alloc failed\n");
                return NULL;
        }
 
@@ -3452,6 +3520,7 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port,
        skge->duplex = -1;
        skge->speed = -1;
        skge->advertising = skge_supported_modes(hw);
+       skge->wol = pci_wake_enabled(hw->pdev) ? wol_supported(hw) : 0;
 
        hw->dev[port] = dev;
 
@@ -3496,15 +3565,13 @@ static int __devinit skge_probe(struct pci_dev *pdev,
 
        err = pci_enable_device(pdev);
        if (err) {
-               printk(KERN_ERR PFX "%s cannot enable PCI device\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot enable PCI device\n");
                goto err_out;
        }
 
        err = pci_request_regions(pdev, DRV_NAME);
        if (err) {
-               printk(KERN_ERR PFX "%s cannot obtain PCI resources\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot obtain PCI resources\n");
                goto err_out_disable_pdev;
        }
 
@@ -3519,8 +3586,7 @@ static int __devinit skge_probe(struct pci_dev *pdev,
        }
 
        if (err) {
-               printk(KERN_ERR PFX "%s no usable DMA configuration\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "no usable DMA configuration\n");
                goto err_out_free_regions;
        }
 
@@ -3538,8 +3604,7 @@ static int __devinit skge_probe(struct pci_dev *pdev,
        err = -ENOMEM;
        hw = kzalloc(sizeof(*hw), GFP_KERNEL);
        if (!hw) {
-               printk(KERN_ERR PFX "%s: cannot allocate hardware struct\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot allocate hardware struct\n");
                goto err_out_free_regions;
        }
 
@@ -3550,8 +3615,7 @@ static int __devinit skge_probe(struct pci_dev *pdev,
 
        hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
        if (!hw->regs) {
-               printk(KERN_ERR PFX "%s: cannot map device registers\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot map device registers\n");
                goto err_out_free_hw;
        }
 
@@ -3567,23 +3631,19 @@ static int __devinit skge_probe(struct pci_dev *pdev,
        if (!dev)
                goto err_out_led_off;
 
-       if (!is_valid_ether_addr(dev->dev_addr)) {
-               printk(KERN_ERR PFX "%s: bad (zero?) ethernet address in rom\n",
-                      pci_name(pdev));
-               err = -EIO;
-               goto err_out_free_netdev;
-       }
+       /* Some motherboards are broken and has zero in ROM. */
+       if (!is_valid_ether_addr(dev->dev_addr))
+               dev_warn(&pdev->dev, "bad (zero?) ethernet address in rom\n");
 
        err = register_netdev(dev);
        if (err) {
-               printk(KERN_ERR PFX "%s: cannot register net device\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot register net device\n");
                goto err_out_free_netdev;
        }
 
        err = request_irq(pdev->irq, skge_intr, IRQF_SHARED, dev->name, hw);
        if (err) {
-               printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
+               dev_err(&pdev->dev, "%s: cannot assign irq %d\n",
                       dev->name, pdev->irq);
                goto err_out_unregister;
        }
@@ -3594,7 +3654,7 @@ static int __devinit skge_probe(struct pci_dev *pdev,
                        skge_show_addr(dev1);
                else {
                        /* Failure to register second port need not be fatal */
-                       printk(KERN_WARNING PFX "register of second port failed\n");
+                       dev_warn(&pdev->dev, "register of second port failed\n");
                        hw->dev[1] = NULL;
                        free_netdev(dev1);
                }
@@ -3659,28 +3719,46 @@ static void __devexit skge_remove(struct pci_dev *pdev)
 }
 
 #ifdef CONFIG_PM
+static int vaux_avail(struct pci_dev *pdev)
+{
+       int pm_cap;
+
+       pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
+       if (pm_cap) {
+               u16 ctl;
+               pci_read_config_word(pdev, pm_cap + PCI_PM_PMC, &ctl);
+               if (ctl & PCI_PM_CAP_AUX_POWER)
+                       return 1;
+       }
+       return 0;
+}
+
+
 static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        struct skge_hw *hw  = pci_get_drvdata(pdev);
-       int i, wol = 0;
+       int i, err, wol = 0;
+
+       err = pci_save_state(pdev);
+       if (err)
+               return err;
 
-       pci_save_state(pdev);
        for (i = 0; i < hw->ports; i++) {
                struct net_device *dev = hw->dev[i];
+               struct skge_port *skge = netdev_priv(dev);
 
-               if (netif_running(dev)) {
-                       struct skge_port *skge = netdev_priv(dev);
+               if (netif_running(dev))
+                       skge_down(dev);
+               if (skge->wol)
+                       skge_wol_init(skge);
 
-                       netif_carrier_off(dev);
-                       if (skge->wol)
-                               netif_stop_queue(dev);
-                       else
-                               skge_down(dev);
-                       wol |= skge->wol;
-               }
-               netif_device_detach(dev);
+               wol |= skge->wol;
        }
 
+       if (wol && vaux_avail(pdev))
+               skge_write8(hw, B0_POWER_CTRL,
+                           PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_ON | PC_VCC_OFF);
+
        skge_write32(hw, B0_IMSK, 0);
        pci_enable_wake(pdev, pci_choose_state(pdev, state), wol);
        pci_set_power_state(pdev, pci_choose_state(pdev, state));
@@ -3693,8 +3771,14 @@ static int skge_resume(struct pci_dev *pdev)
        struct skge_hw *hw  = pci_get_drvdata(pdev);
        int i, err;
 
-       pci_set_power_state(pdev, PCI_D0);
-       pci_restore_state(pdev);
+       err = pci_set_power_state(pdev, PCI_D0);
+       if (err)
+               goto out;
+
+       err = pci_restore_state(pdev);
+       if (err)
+               goto out;
+
        pci_enable_wake(pdev, PCI_D0, 0);
 
        err = skge_reset(hw);
@@ -3704,7 +3788,6 @@ static int skge_resume(struct pci_dev *pdev)
        for (i = 0; i < hw->ports; i++) {
                struct net_device *dev = hw->dev[i];
 
-               netif_device_attach(dev);
                if (netif_running(dev)) {
                        err = skge_up(dev);
 
index f6223c533c015bff50618d66bc8c3340c048e337..17b1b479dff575a03943b232e6d29849e0a78e51 100644 (file)
@@ -876,11 +876,13 @@ enum {
        WOL_PATT_CNT_0  = 0x0f38,/* 32 bit      WOL Pattern Counter 3..0 */
        WOL_PATT_CNT_4  = 0x0f3c,/* 24 bit      WOL Pattern Counter 6..4 */
 };
+#define WOL_REGS(port, x)      (x + (port)*0x80)
 
 enum {
        WOL_PATT_RAM_1  = 0x1000,/*  WOL Pattern RAM Link 1 */
        WOL_PATT_RAM_2  = 0x1400,/*  WOL Pattern RAM Link 2 */
 };
+#define WOL_PATT_RAM_BASE(port)        (WOL_PATT_RAM_1 + (port)*0x400)
 
 enum {
        BASE_XMAC_1     = 0x2000,/* XMAC 1 registers */
index 822dd0b1313389506d6a6c4df288ed25ed058fdf..f2ab3d56e5653663040190dd91dcdfbc3e38ed70 100644 (file)
@@ -49,7 +49,7 @@
 #include "sky2.h"
 
 #define DRV_NAME               "sky2"
-#define DRV_VERSION            "1.10"
+#define DRV_VERSION            "1.12"
 #define PFX                    DRV_NAME " "
 
 /*
@@ -105,6 +105,7 @@ static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) },    /* DGE-560T */
        { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4001) },    /* DGE-550SX */
        { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B02) },    /* DGE-560SX */
+       { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B03) },    /* DGE-550T */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) }, /* 88E8021 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) }, /* 88E8022 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) }, /* 88E8061 */
@@ -126,6 +127,9 @@ static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4366) }, /* 88EC036 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4367) }, /* 88EC032 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4368) }, /* 88EC034 */
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */
        { 0 }
 };
 
@@ -140,7 +144,7 @@ static const u32 portirq_msk[] = { Y2_IS_PORT_1, Y2_IS_PORT_2 };
 static const char *yukon2_name[] = {
        "XL",           /* 0xb3 */
        "EC Ultra",     /* 0xb4 */
-       "UNKNOWN",      /* 0xb5 */
+       "Extreme",      /* 0xb5 */
        "EC",           /* 0xb6 */
        "FE",           /* 0xb7 */
 };
@@ -192,76 +196,52 @@ static u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg)
        return v;
 }
 
-static void sky2_set_power_state(struct sky2_hw *hw, pci_power_t state)
-{
-       u16 power_control;
-       int vaux;
-
-       pr_debug("sky2_set_power_state %d\n", state);
-       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
-
-       power_control = sky2_pci_read16(hw, hw->pm_cap + PCI_PM_PMC);
-       vaux = (sky2_read16(hw, B0_CTST) & Y2_VAUX_AVAIL) &&
-               (power_control & PCI_PM_CAP_PME_D3cold);
-
-       power_control = sky2_pci_read16(hw, hw->pm_cap + PCI_PM_CTRL);
-
-       power_control |= PCI_PM_CTRL_PME_STATUS;
-       power_control &= ~(PCI_PM_CTRL_STATE_MASK);
 
-       switch (state) {
-       case PCI_D0:
-               /* switch power to VCC (WA for VAUX problem) */
-               sky2_write8(hw, B0_POWER_CTRL,
-                           PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
-
-               /* disable Core Clock Division, */
-               sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS);
-
-               if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
-                       /* enable bits are inverted */
-                       sky2_write8(hw, B2_Y2_CLK_GATE,
-                                   Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
-                                   Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
-                                   Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
-               else
-                       sky2_write8(hw, B2_Y2_CLK_GATE, 0);
+static void sky2_power_on(struct sky2_hw *hw)
+{
+       /* switch power to VCC (WA for VAUX problem) */
+       sky2_write8(hw, B0_POWER_CTRL,
+                   PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
 
-               if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
-                       u32 reg1;
+       /* disable Core Clock Division, */
+       sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS);
 
-                       sky2_pci_write32(hw, PCI_DEV_REG3, 0);
-                       reg1 = sky2_pci_read32(hw, PCI_DEV_REG4);
-                       reg1 &= P_ASPM_CONTROL_MSK;
-                       sky2_pci_write32(hw, PCI_DEV_REG4, reg1);
-                       sky2_pci_write32(hw, PCI_DEV_REG5, 0);
-               }
+       if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
+               /* enable bits are inverted */
+               sky2_write8(hw, B2_Y2_CLK_GATE,
+                           Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
+                           Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
+                           Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
+       else
+               sky2_write8(hw, B2_Y2_CLK_GATE, 0);
 
-               break;
+       if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX) {
+               u32 reg1;
 
-       case PCI_D3hot:
-       case PCI_D3cold:
-               if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
-                       sky2_write8(hw, B2_Y2_CLK_GATE, 0);
-               else
-                       /* enable bits are inverted */
-                       sky2_write8(hw, B2_Y2_CLK_GATE,
-                                   Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
-                                   Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
-                                   Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
-
-               /* switch power to VAUX */
-               if (vaux && state != PCI_D3cold)
-                       sky2_write8(hw, B0_POWER_CTRL,
-                                   (PC_VAUX_ENA | PC_VCC_ENA |
-                                    PC_VAUX_ON | PC_VCC_OFF));
-               break;
-       default:
-               printk(KERN_ERR PFX "Unknown power state %d\n", state);
+               sky2_pci_write32(hw, PCI_DEV_REG3, 0);
+               reg1 = sky2_pci_read32(hw, PCI_DEV_REG4);
+               reg1 &= P_ASPM_CONTROL_MSK;
+               sky2_pci_write32(hw, PCI_DEV_REG4, reg1);
+               sky2_pci_write32(hw, PCI_DEV_REG5, 0);
        }
+}
 
-       sky2_pci_write16(hw, hw->pm_cap + PCI_PM_CTRL, power_control);
-       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
+static void sky2_power_aux(struct sky2_hw *hw)
+{
+       if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
+               sky2_write8(hw, B2_Y2_CLK_GATE, 0);
+       else
+               /* enable bits are inverted */
+               sky2_write8(hw, B2_Y2_CLK_GATE,
+                           Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
+                           Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
+                           Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
+
+       /* switch power to VAUX */
+       if (sky2_read16(hw, B0_CTST) & Y2_VAUX_AVAIL)
+               sky2_write8(hw, B0_POWER_CTRL,
+                           (PC_VAUX_ENA | PC_VCC_ENA |
+                            PC_VAUX_ON | PC_VCC_OFF));
 }
 
 static void sky2_gmac_reset(struct sky2_hw *hw, unsigned port)
@@ -313,8 +293,10 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
        struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
        u16 ctrl, ct1000, adv, pg, ledctrl, ledover, reg;
 
-       if (sky2->autoneg == AUTONEG_ENABLE &&
-           !(hw->chip_id == CHIP_ID_YUKON_XL || hw->chip_id == CHIP_ID_YUKON_EC_U)) {
+       if (sky2->autoneg == AUTONEG_ENABLE
+           && !(hw->chip_id == CHIP_ID_YUKON_XL
+                || hw->chip_id == CHIP_ID_YUKON_EC_U
+                || hw->chip_id == CHIP_ID_YUKON_EX)) {
                u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
 
                ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
@@ -341,8 +323,10 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
                        /* enable automatic crossover */
                        ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO);
 
-                       if (sky2->autoneg == AUTONEG_ENABLE &&
-                           (hw->chip_id == CHIP_ID_YUKON_XL || hw->chip_id == CHIP_ID_YUKON_EC_U)) {
+                       if (sky2->autoneg == AUTONEG_ENABLE
+                           && (hw->chip_id == CHIP_ID_YUKON_XL
+                               || hw->chip_id == CHIP_ID_YUKON_EC_U
+                               || hw->chip_id == CHIP_ID_YUKON_EX)) {
                                ctrl &= ~PHY_M_PC_DSC_MSK;
                                ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA;
                        }
@@ -497,7 +481,9 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
                /* restore page register */
                gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
                break;
+
        case CHIP_ID_YUKON_EC_U:
+       case CHIP_ID_YUKON_EX:
                pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
 
                /* select page 3 to access LED control register */
@@ -539,7 +525,7 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
 
                /* set page register to 0 */
                gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
-       } else {
+       } else if (hw->chip_id != CHIP_ID_YUKON_EX) {
                gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
 
                if (sky2->autoneg == AUTONEG_DISABLE || sky2->speed == SPEED_100) {
@@ -591,6 +577,73 @@ static void sky2_phy_reinit(struct sky2_port *sky2)
        spin_unlock_bh(&sky2->phy_lock);
 }
 
+/* Put device in state to listen for Wake On Lan */
+static void sky2_wol_init(struct sky2_port *sky2)
+{
+       struct sky2_hw *hw = sky2->hw;
+       unsigned port = sky2->port;
+       enum flow_control save_mode;
+       u16 ctrl;
+       u32 reg1;
+
+       /* Bring hardware out of reset */
+       sky2_write16(hw, B0_CTST, CS_RST_CLR);
+       sky2_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR);
+
+       sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
+       sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
+
+       /* Force to 10/100
+        * sky2_reset will re-enable on resume
+        */
+       save_mode = sky2->flow_mode;
+       ctrl = sky2->advertising;
+
+       sky2->advertising &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full);
+       sky2->flow_mode = FC_NONE;
+       sky2_phy_power(hw, port, 1);
+       sky2_phy_reinit(sky2);
+
+       sky2->flow_mode = save_mode;
+       sky2->advertising = ctrl;
+
+       /* Set GMAC to no flow control and auto update for speed/duplex */
+       gma_write16(hw, port, GM_GP_CTRL,
+                   GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA|
+                   GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS);
+
+       /* Set WOL address */
+       memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR),
+                   sky2->netdev->dev_addr, ETH_ALEN);
+
+       /* Turn on appropriate WOL control bits */
+       sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT);
+       ctrl = 0;
+       if (sky2->wol & WAKE_PHY)
+               ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT;
+       else
+               ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT;
+
+       if (sky2->wol & WAKE_MAGIC)
+               ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
+       else
+               ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;;
+
+       ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
+       sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
+
+       /* Turn on legacy PCI-Express PME mode */
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
+       reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
+       reg1 |= PCI_Y2_PME_LEGACY;
+       sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
+
+       /* block receiver */
+       sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
+
+}
+
 static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
 {
        struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
@@ -684,7 +737,7 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
        sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
        sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
 
-       if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
+       if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX) {
                sky2_write8(hw, SK_REG(port, RX_GMF_LP_THR), 768/8);
                sky2_write8(hw, SK_REG(port, RX_GMF_UP_THR), 1024/8);
                if (hw->dev[port]->mtu > ETH_DATA_LEN) {
@@ -1467,6 +1520,9 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
                        if (unlikely(netif_msg_tx_done(sky2)))
                                printk(KERN_DEBUG "%s: tx done %u\n",
                                       dev->name, idx);
+                       sky2->net_stats.tx_packets++;
+                       sky2->net_stats.tx_bytes += re->skb->len;
+
                        dev_kfree_skb_any(re->skb);
                }
 
@@ -1641,7 +1697,9 @@ static void sky2_link_up(struct sky2_port *sky2)
        sky2_write8(hw, SK_REG(port, LNK_LED_REG),
                    LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF);
 
-       if (hw->chip_id == CHIP_ID_YUKON_XL || hw->chip_id == CHIP_ID_YUKON_EC_U) {
+       if (hw->chip_id == CHIP_ID_YUKON_XL
+           || hw->chip_id == CHIP_ID_YUKON_EC_U
+           || hw->chip_id == CHIP_ID_YUKON_EX) {
                u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
                u16 led = PHY_M_LEDC_LOS_CTRL(1);       /* link active */
 
@@ -1734,14 +1792,16 @@ static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
        sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
 
        /* Pause bits are offset (9..8) */
-       if (hw->chip_id == CHIP_ID_YUKON_XL || hw->chip_id == CHIP_ID_YUKON_EC_U)
+       if (hw->chip_id == CHIP_ID_YUKON_XL
+           || hw->chip_id == CHIP_ID_YUKON_EC_U
+           || hw->chip_id == CHIP_ID_YUKON_EX)
                aux >>= 6;
 
        sky2->flow_status = sky2_flow(aux & PHY_M_PS_RX_P_EN,
                                      aux & PHY_M_PS_TX_P_EN);
 
        if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000
-           && hw->chip_id != CHIP_ID_YUKON_EC_U)
+           && !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX))
                sky2->flow_status = FC_NONE;
 
        if (aux & PHY_M_PS_RX_P_EN)
@@ -1794,48 +1854,37 @@ out:
 }
 
 
-/* Transmit timeout is only called if we are running, carries is up
+/* Transmit timeout is only called if we are running, carrier is up
  * and tx queue is full (stopped).
+ * Called with netif_tx_lock held.
  */
 static void sky2_tx_timeout(struct net_device *dev)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
        struct sky2_hw *hw = sky2->hw;
-       unsigned txq = txqaddr[sky2->port];
-       u16 report, done;
+       u32 imask;
 
        if (netif_msg_timer(sky2))
                printk(KERN_ERR PFX "%s: tx timeout\n", dev->name);
 
-       report = sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX);
-       done = sky2_read16(hw, Q_ADDR(txq, Q_DONE));
-
        printk(KERN_DEBUG PFX "%s: transmit ring %u .. %u report=%u done=%u\n",
-              dev->name,
-              sky2->tx_cons, sky2->tx_prod, report, done);
+              dev->name, sky2->tx_cons, sky2->tx_prod,
+              sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX),
+              sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE)));
 
-       if (report != done) {
-               printk(KERN_INFO PFX "status burst pending (irq moderation?)\n");
-
-               sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
-               sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
-       } else if (report != sky2->tx_cons) {
-               printk(KERN_INFO PFX "status report lost?\n");
+       imask = sky2_read32(hw, B0_IMSK);       /* block IRQ in hw */
+       sky2_write32(hw, B0_IMSK, 0);
+       sky2_read32(hw, B0_IMSK);
 
-               netif_tx_lock_bh(dev);
-               sky2_tx_complete(sky2, report);
-               netif_tx_unlock_bh(dev);
-       } else {
-               printk(KERN_INFO PFX "hardware hung? flushing\n");
+       netif_poll_disable(hw->dev[0]);         /* stop NAPI poll */
+       synchronize_irq(hw->pdev->irq);
 
-               sky2_write32(hw, Q_ADDR(txq, Q_CSR), BMU_STOP);
-               sky2_write32(hw, Y2_QADDR(txq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
+       netif_start_queue(dev);                 /* don't wakeup during flush */
+       sky2_tx_complete(sky2, sky2->tx_prod);  /* Flush transmit queue */
 
-               sky2_tx_clean(dev);
+       sky2_write32(hw, B0_IMSK, imask);
 
-               sky2_qset(hw, txq);
-               sky2_prefetch_init(hw, txq, sky2->tx_le_map, TX_RING_SIZE - 1);
-       }
+       sky2_phy_reinit(sky2);                  /* this clears flow control etc */
 }
 
 static int sky2_change_mtu(struct net_device *dev, int new_mtu)
@@ -1849,8 +1898,9 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
        if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
                return -EINVAL;
 
+       /* TSO on Yukon Ultra and MTU > 1500 not supported */
        if (hw->chip_id == CHIP_ID_YUKON_EC_U && new_mtu > ETH_DATA_LEN)
-               return -EINVAL;
+               dev->features &= ~NETIF_F_TSO;
 
        if (!netif_running(dev)) {
                dev->mtu = new_mtu;
@@ -2089,6 +2139,8 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
                                goto force_update;
 
                        skb->protocol = eth_type_trans(skb, dev);
+                       sky2->net_stats.rx_packets++;
+                       sky2->net_stats.rx_bytes += skb->len;
                        dev->last_rx = jiffies;
 
 #ifdef SKY2_VLAN_TAG_USED
@@ -2218,8 +2270,8 @@ static void sky2_hw_intr(struct sky2_hw *hw)
 
                pci_err = sky2_pci_read16(hw, PCI_STATUS);
                if (net_ratelimit())
-                       printk(KERN_ERR PFX "%s: pci hw error (0x%x)\n",
-                              pci_name(hw->pdev), pci_err);
+                       dev_err(&hw->pdev->dev, "PCI hardware error (0x%x)\n",
+                               pci_err);
 
                sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
                sky2_pci_write16(hw, PCI_STATUS,
@@ -2234,8 +2286,8 @@ static void sky2_hw_intr(struct sky2_hw *hw)
                pex_err = sky2_pci_read32(hw, PEX_UNC_ERR_STAT);
 
                if (net_ratelimit())
-                       printk(KERN_ERR PFX "%s: pci express error (0x%x)\n",
-                              pci_name(hw->pdev), pex_err);
+                       dev_err(&hw->pdev->dev, "PCI Express error (0x%x)\n",
+                               pex_err);
 
                /* clear the interrupt */
                sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
@@ -2404,6 +2456,7 @@ static inline u32 sky2_mhz(const struct sky2_hw *hw)
        switch (hw->chip_id) {
        case CHIP_ID_YUKON_EC:
        case CHIP_ID_YUKON_EC_U:
+       case CHIP_ID_YUKON_EX:
                return 125;     /* 125 Mhz */
        case CHIP_ID_YUKON_FE:
                return 100;     /* 100 Mhz */
@@ -2423,34 +2476,62 @@ static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk)
 }
 
 
-static int sky2_reset(struct sky2_hw *hw)
+static int __devinit sky2_init(struct sky2_hw *hw)
 {
-       u16 status;
        u8 t8;
-       int i;
 
        sky2_write8(hw, B0_CTST, CS_RST_CLR);
 
        hw->chip_id = sky2_read8(hw, B2_CHIP_ID);
        if (hw->chip_id < CHIP_ID_YUKON_XL || hw->chip_id > CHIP_ID_YUKON_FE) {
-               printk(KERN_ERR PFX "%s: unsupported chip type 0x%x\n",
-                      pci_name(hw->pdev), hw->chip_id);
+               dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
+                       hw->chip_id);
                return -EOPNOTSUPP;
        }
 
+       if (hw->chip_id == CHIP_ID_YUKON_EX)
+               dev_warn(&hw->pdev->dev, "this driver not yet tested on this chip type\n"
+                        "Please report success or failure to <netdev@vger.kernel.org>\n");
+
+       /* Make sure and enable all clocks */
+       if (hw->chip_id == CHIP_ID_YUKON_EX || hw->chip_id == CHIP_ID_YUKON_EC_U)
+               sky2_pci_write32(hw, PCI_DEV_REG3, 0);
+
        hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4;
 
        /* This rev is really old, and requires untested workarounds */
        if (hw->chip_id == CHIP_ID_YUKON_EC && hw->chip_rev == CHIP_REV_YU_EC_A1) {
-               printk(KERN_ERR PFX "%s: unsupported revision Yukon-%s (0x%x) rev %d\n",
-                      pci_name(hw->pdev), yukon2_name[hw->chip_id - CHIP_ID_YUKON_XL],
-                      hw->chip_id, hw->chip_rev);
+               dev_err(&hw->pdev->dev, "unsupported revision Yukon-%s (0x%x) rev %d\n",
+                       yukon2_name[hw->chip_id - CHIP_ID_YUKON_XL],
+                       hw->chip_id, hw->chip_rev);
                return -EOPNOTSUPP;
        }
 
+       hw->pmd_type = sky2_read8(hw, B2_PMD_TYP);
+       hw->ports = 1;
+       t8 = sky2_read8(hw, B2_Y2_HW_RES);
+       if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) {
+               if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC))
+                       ++hw->ports;
+       }
+
+       return 0;
+}
+
+static void sky2_reset(struct sky2_hw *hw)
+{
+       u16 status;
+       int i;
+
        /* disable ASF */
        if (hw->chip_id <= CHIP_ID_YUKON_EC) {
-               sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET);
+               if (hw->chip_id == CHIP_ID_YUKON_EX) {
+                       status = sky2_read16(hw, HCU_CCSR);
+                       status &= ~(HCU_CCSR_AHB_RST | HCU_CCSR_CPU_RST_MODE |
+                                   HCU_CCSR_UC_STATE_MSK);
+                       sky2_write16(hw, HCU_CCSR, status);
+               } else
+                       sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET);
                sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE);
        }
 
@@ -2472,15 +2553,7 @@ static int sky2_reset(struct sky2_hw *hw)
                sky2_pci_write32(hw, PEX_UNC_ERR_STAT, 0xffffffffUL);
 
 
-       hw->pmd_type = sky2_read8(hw, B2_PMD_TYP);
-       hw->ports = 1;
-       t8 = sky2_read8(hw, B2_Y2_HW_RES);
-       if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) {
-               if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC))
-                       ++hw->ports;
-       }
-
-       sky2_set_power_state(hw, PCI_D0);
+       sky2_power_on(hw);
 
        for (i = 0; i < hw->ports; i++) {
                sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
@@ -2563,7 +2636,37 @@ static int sky2_reset(struct sky2_hw *hw)
        sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
        sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
        sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
+}
+
+static inline u8 sky2_wol_supported(const struct sky2_hw *hw)
+{
+       return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0;
+}
+
+static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+       const struct sky2_port *sky2 = netdev_priv(dev);
+
+       wol->supported = sky2_wol_supported(sky2->hw);
+       wol->wolopts = sky2->wol;
+}
+
+static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+       struct sky2_port *sky2 = netdev_priv(dev);
+       struct sky2_hw *hw = sky2->hw;
+
+       if (wol->wolopts & ~sky2_wol_supported(sky2->hw))
+               return -EOPNOTSUPP;
+
+       sky2->wol = wol->wolopts;
+
+       if (hw->chip_id == CHIP_ID_YUKON_EC_U)
+               sky2_write32(hw, B0_CTST, sky2->wol
+                            ? Y2_HW_WOL_ON : Y2_HW_WOL_OFF);
 
+       if (!netif_running(dev))
+               sky2_wol_init(sky2);
        return 0;
 }
 
@@ -2814,25 +2917,9 @@ static void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data)
        }
 }
 
-/* Use hardware MIB variables for critical path statistics and
- * transmit feedback not reported at interrupt.
- * Other errors are accounted for in interrupt handler.
- */
 static struct net_device_stats *sky2_get_stats(struct net_device *dev)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
-       u64 data[13];
-
-       sky2_phy_stats(sky2, data, ARRAY_SIZE(data));
-
-       sky2->net_stats.tx_bytes = data[0];
-       sky2->net_stats.rx_bytes = data[1];
-       sky2->net_stats.tx_packets = data[2] + data[4] + data[6];
-       sky2->net_stats.rx_packets = data[3] + data[5] + data[7];
-       sky2->net_stats.multicast = data[3] + data[5];
-       sky2->net_stats.collisions = data[10];
-       sky2->net_stats.tx_aborted_errors = data[12];
-
        return &sky2->net_stats;
 }
 
@@ -3191,7 +3278,9 @@ static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs,
 static const struct ethtool_ops sky2_ethtool_ops = {
        .get_settings = sky2_get_settings,
        .set_settings = sky2_set_settings,
-       .get_drvinfo = sky2_get_drvinfo,
+       .get_drvinfo  = sky2_get_drvinfo,
+       .get_wol      = sky2_get_wol,
+       .set_wol      = sky2_set_wol,
        .get_msglevel = sky2_get_msglevel,
        .set_msglevel = sky2_set_msglevel,
        .nway_reset   = sky2_nway_reset,
@@ -3221,13 +3310,14 @@ static const struct ethtool_ops sky2_ethtool_ops = {
 
 /* Initialize network device */
 static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
-                                                    unsigned port, int highmem)
+                                                    unsigned port,
+                                                    int highmem, int wol)
 {
        struct sky2_port *sky2;
        struct net_device *dev = alloc_etherdev(sizeof(*sky2));
 
        if (!dev) {
-               printk(KERN_ERR "sky2 etherdev alloc failed");
+               dev_err(&hw->pdev->dev, "etherdev alloc failed");
                return NULL;
        }
 
@@ -3269,6 +3359,7 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
        sky2->speed = -1;
        sky2->advertising = sky2_supported_modes(hw);
        sky2->rx_csum = 1;
+       sky2->wol = wol;
 
        spin_lock_init(&sky2->phy_lock);
        sky2->tx_pending = TX_DEF_PENDING;
@@ -3278,11 +3369,9 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
 
        sky2->port = port;
 
-       if (hw->chip_id != CHIP_ID_YUKON_EC_U)
-               dev->features |= NETIF_F_TSO;
+       dev->features |= NETIF_F_TSO | NETIF_F_IP_CSUM | NETIF_F_SG;
        if (highmem)
                dev->features |= NETIF_F_HIGHDMA;
-       dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
 
 #ifdef SKY2_VLAN_TAG_USED
        dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
@@ -3343,8 +3432,7 @@ static int __devinit sky2_test_msi(struct sky2_hw *hw)
 
        err = request_irq(pdev->irq, sky2_test_intr, 0, DRV_NAME, hw);
        if (err) {
-               printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
-                      pci_name(pdev), pdev->irq);
+               dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
                return err;
        }
 
@@ -3355,9 +3443,8 @@ static int __devinit sky2_test_msi(struct sky2_hw *hw)
 
        if (!hw->msi) {
                /* MSI test failed, go back to INTx mode */
-               printk(KERN_INFO PFX "%s: No interrupt generated using MSI, "
-                      "switching to INTx mode.\n",
-                      pci_name(pdev));
+               dev_info(&pdev->dev, "No interrupt generated using MSI, "
+                        "switching to INTx mode.\n");
 
                err = -EOPNOTSUPP;
                sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
@@ -3371,62 +3458,62 @@ static int __devinit sky2_test_msi(struct sky2_hw *hw)
        return err;
 }
 
+static int __devinit pci_wake_enabled(struct pci_dev *dev)
+{
+       int pm  = pci_find_capability(dev, PCI_CAP_ID_PM);
+       u16 value;
+
+       if (!pm)
+               return 0;
+       if (pci_read_config_word(dev, pm + PCI_PM_CTRL, &value))
+               return 0;
+       return value & PCI_PM_CTRL_PME_ENABLE;
+}
+
 static int __devinit sky2_probe(struct pci_dev *pdev,
                                const struct pci_device_id *ent)
 {
-       struct net_device *dev, *dev1 = NULL;
+       struct net_device *dev;
        struct sky2_hw *hw;
-       int err, pm_cap, using_dac = 0;
+       int err, using_dac = 0, wol_default;
 
        err = pci_enable_device(pdev);
        if (err) {
-               printk(KERN_ERR PFX "%s cannot enable PCI device\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot enable PCI device\n");
                goto err_out;
        }
 
        err = pci_request_regions(pdev, DRV_NAME);
        if (err) {
-               printk(KERN_ERR PFX "%s cannot obtain PCI resources\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot obtain PCI resources\n");
                goto err_out;
        }
 
        pci_set_master(pdev);
 
-       /* Find power-management capability. */
-       pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
-       if (pm_cap == 0) {
-               printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
-                      "aborting.\n");
-               err = -EIO;
-               goto err_out_free_regions;
-       }
-
        if (sizeof(dma_addr_t) > sizeof(u32) &&
            !(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
                using_dac = 1;
                err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
                if (err < 0) {
-                       printk(KERN_ERR PFX "%s unable to obtain 64 bit DMA "
-                              "for consistent allocations\n", pci_name(pdev));
+                       dev_err(&pdev->dev, "unable to obtain 64 bit DMA "
+                               "for consistent allocations\n");
                        goto err_out_free_regions;
                }
-
        } else {
                err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
                if (err) {
-                       printk(KERN_ERR PFX "%s no usable DMA configuration\n",
-                              pci_name(pdev));
+                       dev_err(&pdev->dev, "no usable DMA configuration\n");
                        goto err_out_free_regions;
                }
        }
 
+       wol_default = pci_wake_enabled(pdev) ? WAKE_MAGIC : 0;
+
        err = -ENOMEM;
        hw = kzalloc(sizeof(*hw), GFP_KERNEL);
        if (!hw) {
-               printk(KERN_ERR PFX "%s: cannot allocate hardware struct\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot allocate hardware struct\n");
                goto err_out_free_regions;
        }
 
@@ -3434,11 +3521,9 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
 
        hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
        if (!hw->regs) {
-               printk(KERN_ERR PFX "%s: cannot map device registers\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot map device registers\n");
                goto err_out_free_hw;
        }
-       hw->pm_cap = pm_cap;
 
 #ifdef __BIG_ENDIAN
        /* The sk98lin vendor driver uses hardware byte swapping but
@@ -3458,18 +3543,22 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
        if (!hw->st_le)
                goto err_out_iounmap;
 
-       err = sky2_reset(hw);
+       err = sky2_init(hw);
        if (err)
                goto err_out_iounmap;
 
-       printk(KERN_INFO PFX "v%s addr 0x%llx irq %d Yukon-%s (0x%x) rev %d\n",
+       dev_info(&pdev->dev, "v%s addr 0x%llx irq %d Yukon-%s (0x%x) rev %d\n",
               DRV_VERSION, (unsigned long long)pci_resource_start(pdev, 0),
               pdev->irq, yukon2_name[hw->chip_id - CHIP_ID_YUKON_XL],
               hw->chip_id, hw->chip_rev);
 
-       dev = sky2_init_netdev(hw, 0, using_dac);
-       if (!dev)
+       sky2_reset(hw);
+
+       dev = sky2_init_netdev(hw, 0, using_dac, wol_default);
+       if (!dev) {
+               err = -ENOMEM;
                goto err_out_free_pci;
+       }
 
        if (!disable_msi && pci_enable_msi(pdev) == 0) {
                err = sky2_test_msi(hw);
@@ -3481,32 +3570,33 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
 
        err = register_netdev(dev);
        if (err) {
-               printk(KERN_ERR PFX "%s: cannot register net device\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot register net device\n");
                goto err_out_free_netdev;
        }
 
        err = request_irq(pdev->irq,  sky2_intr, hw->msi ? 0 : IRQF_SHARED,
                          dev->name, hw);
        if (err) {
-               printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
-                      pci_name(pdev), pdev->irq);
+               dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
                goto err_out_unregister;
        }
        sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
 
        sky2_show_addr(dev);
 
-       if (hw->ports > 1 && (dev1 = sky2_init_netdev(hw, 1, using_dac))) {
-               if (register_netdev(dev1) == 0)
-                       sky2_show_addr(dev1);
-               else {
-                       /* Failure to register second port need not be fatal */
-                       printk(KERN_WARNING PFX
-                              "register of second port failed\n");
+       if (hw->ports > 1) {
+               struct net_device *dev1;
+
+               dev1 = sky2_init_netdev(hw, 1, using_dac, wol_default);
+               if (!dev1)
+                       dev_warn(&pdev->dev, "allocation for second device failed\n");
+               else if ((err = register_netdev(dev1))) {
+                       dev_warn(&pdev->dev,
+                                "register of second port failed (%d)\n", err);
                        hw->dev[1] = NULL;
                        free_netdev(dev1);
-               }
+               } else
+                       sky2_show_addr(dev1);
        }
 
        setup_timer(&hw->idle_timer, sky2_idle, (unsigned long) hw);
@@ -3555,7 +3645,8 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
                unregister_netdev(dev1);
        unregister_netdev(dev0);
 
-       sky2_set_power_state(hw, PCI_D3hot);
+       sky2_power_aux(hw);
+
        sky2_write16(hw, B0_Y2LED, LED_STAT_OFF);
        sky2_write8(hw, B0_CTST, CS_RST_SET);
        sky2_read8(hw, B0_CTST);
@@ -3580,27 +3671,31 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
 static int sky2_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        struct sky2_hw *hw = pci_get_drvdata(pdev);
-       int i;
-       pci_power_t pstate = pci_choose_state(pdev, state);
-
-       if (!(pstate == PCI_D3hot || pstate == PCI_D3cold))
-               return -EINVAL;
+       int i, wol = 0;
 
        del_timer_sync(&hw->idle_timer);
        netif_poll_disable(hw->dev[0]);
 
        for (i = 0; i < hw->ports; i++) {
                struct net_device *dev = hw->dev[i];
+               struct sky2_port *sky2 = netdev_priv(dev);
 
-               if (netif_running(dev)) {
+               if (netif_running(dev))
                        sky2_down(dev);
-                       netif_device_detach(dev);
-               }
+
+               if (sky2->wol)
+                       sky2_wol_init(sky2);
+
+               wol |= sky2->wol;
        }
 
        sky2_write32(hw, B0_IMSK, 0);
+       sky2_power_aux(hw);
+
        pci_save_state(pdev);
-       sky2_set_power_state(hw, pstate);
+       pci_enable_wake(pdev, pci_choose_state(pdev, state), wol);
+       pci_set_power_state(pdev, pci_choose_state(pdev, state));
+
        return 0;
 }
 
@@ -3609,21 +3704,22 @@ static int sky2_resume(struct pci_dev *pdev)
        struct sky2_hw *hw = pci_get_drvdata(pdev);
        int i, err;
 
-       pci_restore_state(pdev);
-       pci_enable_wake(pdev, PCI_D0, 0);
-       sky2_set_power_state(hw, PCI_D0);
+       err = pci_set_power_state(pdev, PCI_D0);
+       if (err)
+               goto out;
 
-       err = sky2_reset(hw);
+       err = pci_restore_state(pdev);
        if (err)
                goto out;
 
+       pci_enable_wake(pdev, PCI_D0, 0);
+       sky2_reset(hw);
+
        sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
 
        for (i = 0; i < hw->ports; i++) {
                struct net_device *dev = hw->dev[i];
                if (netif_running(dev)) {
-                       netif_device_attach(dev);
-
                        err = sky2_up(dev);
                        if (err) {
                                printk(KERN_ERR PFX "%s: could not up: %d\n",
@@ -3636,11 +3732,43 @@ static int sky2_resume(struct pci_dev *pdev)
 
        netif_poll_enable(hw->dev[0]);
        sky2_idle_start(hw);
+       return 0;
 out:
+       dev_err(&pdev->dev, "resume failed (%d)\n", err);
+       pci_disable_device(pdev);
        return err;
 }
 #endif
 
+static void sky2_shutdown(struct pci_dev *pdev)
+{
+       struct sky2_hw *hw = pci_get_drvdata(pdev);
+       int i, wol = 0;
+
+       del_timer_sync(&hw->idle_timer);
+       netif_poll_disable(hw->dev[0]);
+
+       for (i = 0; i < hw->ports; i++) {
+               struct net_device *dev = hw->dev[i];
+               struct sky2_port *sky2 = netdev_priv(dev);
+
+               if (sky2->wol) {
+                       wol = 1;
+                       sky2_wol_init(sky2);
+               }
+       }
+
+       if (wol)
+               sky2_power_aux(hw);
+
+       pci_enable_wake(pdev, PCI_D3hot, wol);
+       pci_enable_wake(pdev, PCI_D3cold, wol);
+
+       pci_disable_device(pdev);
+       pci_set_power_state(pdev, PCI_D3hot);
+
+}
+
 static struct pci_driver sky2_driver = {
        .name = DRV_NAME,
        .id_table = sky2_id_table,
@@ -3650,6 +3778,7 @@ static struct pci_driver sky2_driver = {
        .suspend = sky2_suspend,
        .resume = sky2_resume,
 #endif
+       .shutdown = sky2_shutdown,
 };
 
 static int __init sky2_init_module(void)
index 6ed1d47dbbd3452bfa0460fb6b92df67c8370f5f..3b0189569d525dce17eeac1d2cfdc826113713fc 100644 (file)
@@ -32,6 +32,7 @@ enum pci_dev_reg_1 {
        PCI_Y2_PHY1_COMA = 1<<28, /* Set PHY 1 to Coma Mode (YUKON-2) */
        PCI_Y2_PHY2_POWD = 1<<27, /* Set PHY 2 to Power Down (YUKON-2) */
        PCI_Y2_PHY1_POWD = 1<<26, /* Set PHY 1 to Power Down (YUKON-2) */
+       PCI_Y2_PME_LEGACY= 1<<15, /* PCI Express legacy power management mode */
 };
 
 enum pci_dev_reg_2 {
@@ -370,12 +371,9 @@ enum {
 
 /*     B2_CHIP_ID               8 bit  Chip Identification Number */
 enum {
-       CHIP_ID_GENESIS    = 0x0a, /* Chip ID for GENESIS */
-       CHIP_ID_YUKON      = 0xb0, /* Chip ID for YUKON */
-       CHIP_ID_YUKON_LITE = 0xb1, /* Chip ID for YUKON-Lite (Rev. A1-A3) */
-       CHIP_ID_YUKON_LP   = 0xb2, /* Chip ID for YUKON-LP */
        CHIP_ID_YUKON_XL   = 0xb3, /* Chip ID for YUKON-2 XL */
        CHIP_ID_YUKON_EC_U = 0xb4, /* Chip ID for YUKON-2 EC Ultra */
+       CHIP_ID_YUKON_EX   = 0xb5, /* Chip ID for YUKON-2 Extreme */
        CHIP_ID_YUKON_EC   = 0xb6, /* Chip ID for YUKON-2 EC */
        CHIP_ID_YUKON_FE   = 0xb7, /* Chip ID for YUKON-2 FE */
 
@@ -767,6 +765,24 @@ enum {
        POLL_LIST_ADDR_HI= 0x0e2c,/* 32 bit     Poll. List Start Addr (high) */
 };
 
+enum {
+       SMB_CFG          = 0x0e40, /* 32 bit    SMBus Config Register */
+       SMB_CSR          = 0x0e44, /* 32 bit    SMBus Control/Status Register */
+};
+
+enum {
+       CPU_WDOG         = 0x0e48, /* 32 bit    Watchdog Register  */
+       CPU_CNTR         = 0x0e4C, /* 32 bit    Counter Register  */
+       CPU_TIM          = 0x0e50,/* 32 bit     Timer Compare Register  */
+       CPU_AHB_ADDR     = 0x0e54, /* 32 bit    CPU AHB Debug  Register  */
+       CPU_AHB_WDATA    = 0x0e58, /* 32 bit    CPU AHB Debug  Register  */
+       CPU_AHB_RDATA    = 0x0e5C, /* 32 bit    CPU AHB Debug  Register  */
+       HCU_MAP_BASE     = 0x0e60, /* 32 bit    Reset Mapping Base */
+       CPU_AHB_CTRL     = 0x0e64, /* 32 bit    CPU AHB Debug  Register  */
+       HCU_CCSR         = 0x0e68, /* 32 bit    CPU Control and Status Register */
+       HCU_HCSR         = 0x0e6C, /* 32 bit    Host Control and Status Register */
+};
+
 /* ASF Subsystem Registers (Yukon-2 only) */
 enum {
        B28_Y2_SMB_CONFIG  = 0x0e40,/* 32 bit   ASF SMBus Config Register */
@@ -837,33 +853,27 @@ enum {
        GMAC_LINK_CTRL  = 0x0f10,/* 16 bit      Link Control Reg */
 
 /* Wake-up Frame Pattern Match Control Registers (YUKON only) */
-
-       WOL_REG_OFFS    = 0x20,/* HW-Bug: Address is + 0x20 against spec. */
-
        WOL_CTRL_STAT   = 0x0f20,/* 16 bit      WOL Control/Status Reg */
        WOL_MATCH_CTL   = 0x0f22,/*  8 bit      WOL Match Control Reg */
        WOL_MATCH_RES   = 0x0f23,/*  8 bit      WOL Match Result Reg */
        WOL_MAC_ADDR    = 0x0f24,/* 32 bit      WOL MAC Address */
-       WOL_PATT_PME    = 0x0f2a,/*  8 bit      WOL PME Match Enable (Yukon-2) */
-       WOL_PATT_ASFM   = 0x0f2b,/*  8 bit      WOL ASF Match Enable (Yukon-2) */
        WOL_PATT_RPTR   = 0x0f2c,/*  8 bit      WOL Pattern Read Pointer */
 
 /* WOL Pattern Length Registers (YUKON only) */
-
        WOL_PATT_LEN_LO = 0x0f30,/* 32 bit      WOL Pattern Length 3..0 */
        WOL_PATT_LEN_HI = 0x0f34,/* 24 bit      WOL Pattern Length 6..4 */
 
 /* WOL Pattern Counter Registers (YUKON only) */
-
-
        WOL_PATT_CNT_0  = 0x0f38,/* 32 bit      WOL Pattern Counter 3..0 */
        WOL_PATT_CNT_4  = 0x0f3c,/* 24 bit      WOL Pattern Counter 6..4 */
 };
+#define WOL_REGS(port, x)      (x + (port)*0x80)
 
 enum {
        WOL_PATT_RAM_1  = 0x1000,/*  WOL Pattern RAM Link 1 */
        WOL_PATT_RAM_2  = 0x1400,/*  WOL Pattern RAM Link 2 */
 };
+#define WOL_PATT_RAM_BASE(port)        (WOL_PATT_RAM_1 + (port)*0x400)
 
 enum {
        BASE_GMAC_1     = 0x2800,/* GMAC 1 registers */
@@ -1654,6 +1664,39 @@ enum {
        Y2_ASF_CLR_ASFI = 1<<1, /* Clear host IRQ */
        Y2_ASF_HOST_IRQ = 1<<0, /* Issue an IRQ to HOST system */
 };
+/*     HCU_CCSR        CPU Control and Status Register */
+enum {
+       HCU_CCSR_SMBALERT_MONITOR= 1<<27, /* SMBALERT pin monitor */
+       HCU_CCSR_CPU_SLEEP      = 1<<26, /* CPU sleep status */
+       /* Clock Stretching Timeout */
+       HCU_CCSR_CS_TO          = 1<<25,
+       HCU_CCSR_WDOG           = 1<<24, /* Watchdog Reset */
+
+       HCU_CCSR_CLR_IRQ_HOST   = 1<<17, /* Clear IRQ_HOST */
+       HCU_CCSR_SET_IRQ_HCU    = 1<<16, /* Set IRQ_HCU */
+
+       HCU_CCSR_AHB_RST        = 1<<9, /* Reset AHB bridge */
+       HCU_CCSR_CPU_RST_MODE   = 1<<8, /* CPU Reset Mode */
+
+       HCU_CCSR_SET_SYNC_CPU   = 1<<5,
+       HCU_CCSR_CPU_CLK_DIVIDE_MSK = 3<<3,/* CPU Clock Divide */
+       HCU_CCSR_CPU_CLK_DIVIDE_BASE= 1<<3,
+       HCU_CCSR_OS_PRSNT       = 1<<2, /* ASF OS Present */
+/* Microcontroller State */
+       HCU_CCSR_UC_STATE_MSK   = 3,
+       HCU_CCSR_UC_STATE_BASE  = 1<<0,
+       HCU_CCSR_ASF_RESET      = 0,
+       HCU_CCSR_ASF_HALTED     = 1<<1,
+       HCU_CCSR_ASF_RUNNING    = 1<<0,
+};
+
+/*     HCU_HCSR        Host Control and Status Register */
+enum {
+       HCU_HCSR_SET_IRQ_CPU    = 1<<16, /* Set IRQ_CPU */
+
+       HCU_HCSR_CLR_IRQ_HCU    = 1<<1, /* Clear IRQ_HCU */
+       HCU_HCSR_SET_IRQ_HOST   = 1<<0, /* Set IRQ_HOST */
+};
 
 /*     STAT_CTRL               32 bit  Status BMU control register (Yukon-2 only) */
 enum {
@@ -1715,14 +1758,17 @@ enum {
        GM_IS_RX_COMPL  = 1<<0, /* Frame Reception Complete */
 
 #define GMAC_DEF_MSK     GM_IS_TX_FF_UR
+};
 
 /*     GMAC_LINK_CTRL  16 bit  GMAC Link Control Reg (YUKON only) */
-                                               /* Bits 15.. 2: reserved */
+enum {                                         /* Bits 15.. 2: reserved */
        GMLC_RST_CLR    = 1<<1, /* Clear GMAC Link Reset */
        GMLC_RST_SET    = 1<<0, /* Set   GMAC Link Reset */
+};
 
 
 /*     WOL_CTRL_STAT   16 bit  WOL Control/Status Reg */
+enum {
        WOL_CTL_LINK_CHG_OCC            = 1<<15,
        WOL_CTL_MAGIC_PKT_OCC           = 1<<14,
        WOL_CTL_PATTERN_OCC             = 1<<13,
@@ -1741,17 +1787,6 @@ enum {
        WOL_CTL_DIS_PATTERN_UNIT        = 1<<0,
 };
 
-#define WOL_CTL_DEFAULT                                \
-       (WOL_CTL_DIS_PME_ON_LINK_CHG |  \
-       WOL_CTL_DIS_PME_ON_PATTERN |    \
-       WOL_CTL_DIS_PME_ON_MAGIC_PKT |  \
-       WOL_CTL_DIS_LINK_CHG_UNIT |             \
-       WOL_CTL_DIS_PATTERN_UNIT |              \
-       WOL_CTL_DIS_MAGIC_PKT_UNIT)
-
-/*     WOL_MATCH_CTL    8 bit  WOL Match Control Reg */
-#define WOL_CTL_PATT_ENA(x)    (1 << (x))
-
 
 /* Control flags */
 enum {
@@ -1875,6 +1910,7 @@ struct sky2_port {
        u8                   autoneg;   /* AUTONEG_ENABLE, AUTONEG_DISABLE */
        u8                   duplex;    /* DUPLEX_HALF, DUPLEX_FULL */
        u8                   rx_csum;
+       u8                   wol;
        enum flow_control    flow_mode;
        enum flow_control    flow_status;
 
@@ -1887,7 +1923,6 @@ struct sky2_hw {
        struct pci_dev       *pdev;
        struct net_device    *dev[2];
 
-       int                  pm_cap;
        u8                   chip_id;
        u8                   chip_rev;
        u8                   pmd_type;
index 8ea2fc1b96cb8d4f5c5125808dafd08849e2ccb7..bf6ff39e02bbc035e2da03992be4c3661d07fa1c 100644 (file)
@@ -280,72 +280,67 @@ spider_net_free_chain(struct spider_net_card *card,
 {
        struct spider_net_descr *descr;
 
-       for (descr = chain->tail; !descr->bus_addr; descr = descr->next) {
-               pci_unmap_single(card->pdev, descr->bus_addr,
-                                SPIDER_NET_DESCR_SIZE, PCI_DMA_BIDIRECTIONAL);
+       descr = chain->ring;
+       do {
                descr->bus_addr = 0;
-       }
+               descr->next_descr_addr = 0;
+               descr = descr->next;
+       } while (descr != chain->ring);
+
+       dma_free_coherent(&card->pdev->dev, chain->num_desc,
+           chain->ring, chain->dma_addr);
 }
 
 /**
- * spider_net_init_chain - links descriptor chain
+ * spider_net_init_chain - alloc and link descriptor chain
  * @card: card structure
  * @chain: address of chain
- * @start_descr: address of descriptor array
- * @no: number of descriptors
  *
- * we manage a circular list that mirrors the hardware structure,
+ * We manage a circular list that mirrors the hardware structure,
  * except that the hardware uses bus addresses.
  *
- * returns 0 on success, <0 on failure
+ * Returns 0 on success, <0 on failure
  */
 static int
 spider_net_init_chain(struct spider_net_card *card,
-                      struct spider_net_descr_chain *chain,
-                      struct spider_net_descr *start_descr,
-                      int no)
+                      struct spider_net_descr_chain *chain)
 {
        int i;
        struct spider_net_descr *descr;
        dma_addr_t buf;
+       size_t alloc_size;
 
-       descr = start_descr;
-       memset(descr, 0, sizeof(*descr) * no);
+       alloc_size = chain->num_desc * sizeof (struct spider_net_descr);
 
-       /* set up the hardware pointers in each descriptor */
-       for (i=0; i<no; i++, descr++) {
-               descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
+       chain->ring = dma_alloc_coherent(&card->pdev->dev, alloc_size,
+               &chain->dma_addr, GFP_KERNEL);
+
+       if (!chain->ring)
+               return -ENOMEM;
 
-               buf = pci_map_single(card->pdev, descr,
-                                    SPIDER_NET_DESCR_SIZE,
-                                    PCI_DMA_BIDIRECTIONAL);
+       descr = chain->ring;
+       memset(descr, 0, alloc_size);
 
-               if (pci_dma_mapping_error(buf))
-                       goto iommu_error;
+       /* Set up the hardware pointers in each descriptor */
+       buf = chain->dma_addr;
+       for (i=0; i < chain->num_desc; i++, descr++) {
+               descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
 
                descr->bus_addr = buf;
+               descr->next_descr_addr = 0;
                descr->next = descr + 1;
                descr->prev = descr - 1;
 
+               buf += sizeof(struct spider_net_descr);
        }
        /* do actual circular list */
-       (descr-1)->next = start_descr;
-       start_descr->prev = descr-1;
+       (descr-1)->next = chain->ring;
+       chain->ring->prev = descr-1;
 
        spin_lock_init(&chain->lock);
-       chain->head = start_descr;
-       chain->tail = start_descr;
-
+       chain->head = chain->ring;
+       chain->tail = chain->ring;
        return 0;
-
-iommu_error:
-       descr = start_descr;
-       for (i=0; i < no; i++, descr++)
-               if (descr->bus_addr)
-                       pci_unmap_single(card->pdev, descr->bus_addr,
-                                        SPIDER_NET_DESCR_SIZE,
-                                        PCI_DMA_BIDIRECTIONAL);
-       return -ENOMEM;
 }
 
 /**
@@ -372,21 +367,20 @@ spider_net_free_rx_chain_contents(struct spider_net_card *card)
 }
 
 /**
- * spider_net_prepare_rx_descr - reinitializes a rx descriptor
+ * spider_net_prepare_rx_descr - Reinitialize RX descriptor
  * @card: card structure
  * @descr: descriptor to re-init
  *
- * return 0 on succes, <0 on failure
+ * Return 0 on succes, <0 on failure.
  *
- * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
- * Activate the descriptor state-wise
+ * Allocates a new rx skb, iommu-maps it and attaches it to the
+ * descriptor. Mark the descriptor as activated, ready-to-use.
  */
 static int
 spider_net_prepare_rx_descr(struct spider_net_card *card,
                            struct spider_net_descr *descr)
 {
        dma_addr_t buf;
-       int error = 0;
        int offset;
        int bufsize;
 
@@ -414,7 +408,7 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
                (SPIDER_NET_RXBUF_ALIGN - 1);
        if (offset)
                skb_reserve(descr->skb, SPIDER_NET_RXBUF_ALIGN - offset);
-       /* io-mmu-map the skb */
+       /* iommu-map the skb */
        buf = pci_map_single(card->pdev, descr->skb->data,
                        SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
        descr->buf_addr = buf;
@@ -425,11 +419,16 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
                card->spider_stats.rx_iommu_map_error++;
                descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
        } else {
+               descr->next_descr_addr = 0;
+               wmb();
                descr->dmac_cmd_status = SPIDER_NET_DESCR_CARDOWNED |
                                         SPIDER_NET_DMAC_NOINTR_COMPLETE;
+
+               wmb();
+               descr->prev->next_descr_addr = descr->bus_addr;
        }
 
-       return error;
+       return 0;
 }
 
 /**
@@ -493,10 +492,10 @@ spider_net_refill_rx_chain(struct spider_net_card *card)
 }
 
 /**
- * spider_net_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
+ * spider_net_alloc_rx_skbs - Allocates rx skbs in rx descriptor chains
  * @card: card structure
  *
- * returns 0 on success, <0 on failure
+ * Returns 0 on success, <0 on failure.
  */
 static int
 spider_net_alloc_rx_skbs(struct spider_net_card *card)
@@ -507,16 +506,16 @@ spider_net_alloc_rx_skbs(struct spider_net_card *card)
        result = -ENOMEM;
 
        chain = &card->rx_chain;
-       /* put at least one buffer into the chain. if this fails,
-        * we've got a problem. if not, spider_net_refill_rx_chain
-        * will do the rest at the end of this function */
+       /* Put at least one buffer into the chain. if this fails,
+        * we've got a problem. If not, spider_net_refill_rx_chain
+        * will do the rest at the end of this function. */
        if (spider_net_prepare_rx_descr(card, chain->head))
                goto error;
        else
                chain->head = chain->head->next;
 
-       /* this will allocate the rest of the rx buffers; if not, it's
-        * business as usual later on */
+       /* This will allocate the rest of the rx buffers;
+        * if not, it's business as usual later on. */
        spider_net_refill_rx_chain(card);
        spider_net_enable_rxdmac(card);
        return 0;
@@ -707,7 +706,7 @@ spider_net_set_low_watermark(struct spider_net_card *card)
        }
 
        /* If TX queue is short, don't even bother with interrupts */
-       if (cnt < card->num_tx_desc/4)
+       if (cnt < card->tx_chain.num_desc/4)
                return cnt;
 
        /* Set low-watermark 3/4th's of the way into the queue. */
@@ -915,16 +914,13 @@ spider_net_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  * spider_net_pass_skb_up - takes an skb from a descriptor and passes it on
  * @descr: descriptor to process
  * @card: card structure
- * @napi: whether caller is in NAPI context
- *
- * returns 1 on success, 0 if no packet was passed to the stack
  *
- * iommu-unmaps the skb, fills out skb structure and passes the data to the
- * stack. The descriptor state is not changed.
+ * Fills out skb structure and passes the data to the stack.
+ * The descriptor state is not changed.
  */
-static int
+static void
 spider_net_pass_skb_up(struct spider_net_descr *descr,
-                      struct spider_net_card *card, int napi)
+                      struct spider_net_card *card)
 {
        struct sk_buff *skb;
        struct net_device *netdev;
@@ -932,23 +928,8 @@ spider_net_pass_skb_up(struct spider_net_descr *descr,
 
        data_status = descr->data_status;
        data_error = descr->data_error;
-
        netdev = card->netdev;
 
-       /* unmap descriptor */
-       pci_unmap_single(card->pdev, descr->buf_addr, SPIDER_NET_MAX_FRAME,
-                       PCI_DMA_FROMDEVICE);
-
-       /* the cases we'll throw away the packet immediately */
-       if (data_error & SPIDER_NET_DESTROY_RX_FLAGS) {
-               if (netif_msg_rx_err(card))
-                       pr_err("error in received descriptor found, "
-                              "data_status=x%08x, data_error=x%08x\n",
-                              data_status, data_error);
-               card->spider_stats.rx_desc_error++;
-               return 0;
-       }
-
        skb = descr->skb;
        skb->dev = netdev;
        skb_put(skb, descr->valid_size);
@@ -977,57 +958,72 @@ spider_net_pass_skb_up(struct spider_net_descr *descr,
        }
 
        /* pass skb up to stack */
-       if (napi)
-               netif_receive_skb(skb);
-       else
-               netif_rx_ni(skb);
+       netif_receive_skb(skb);
 
        /* update netdevice statistics */
        card->netdev_stats.rx_packets++;
        card->netdev_stats.rx_bytes += skb->len;
+}
 
-       return 1;
+#ifdef DEBUG
+static void show_rx_chain(struct spider_net_card *card)
+{
+       struct spider_net_descr_chain *chain = &card->rx_chain;
+       struct spider_net_descr *start= chain->tail;
+       struct spider_net_descr *descr= start;
+       int status;
+
+       int cnt = 0;
+       int cstat = spider_net_get_descr_status(descr);
+       printk(KERN_INFO "RX chain tail at descr=%ld\n",
+            (start - card->descr) - card->tx_chain.num_desc);
+       status = cstat;
+       do
+       {
+               status = spider_net_get_descr_status(descr);
+               if (cstat != status) {
+                       printk(KERN_INFO "Have %d descrs with stat=x%08x\n", cnt, cstat);
+                       cstat = status;
+                       cnt = 0;
+               }
+               cnt ++;
+               descr = descr->next;
+       } while (descr != start);
+       printk(KERN_INFO "Last %d descrs with stat=x%08x\n", cnt, cstat);
 }
+#endif
 
 /**
  * spider_net_decode_one_descr - processes an rx descriptor
  * @card: card structure
- * @napi: whether caller is in NAPI context
  *
- * returns 1 if a packet has been sent to the stack, otherwise 0
+ * Returns 1 if a packet has been sent to the stack, otherwise 0
  *
- * processes an rx descriptor by iommu-unmapping the data buffer and passing
+ * Processes an rx descriptor by iommu-unmapping the data buffer and passing
  * the packet up to the stack. This function is called in softirq
  * context, e.g. either bottom half from interrupt or NAPI polling context
  */
 static int
-spider_net_decode_one_descr(struct spider_net_card *card, int napi)
+spider_net_decode_one_descr(struct spider_net_card *card)
 {
        struct spider_net_descr_chain *chain = &card->rx_chain;
        struct spider_net_descr *descr = chain->tail;
        int status;
-       int result;
 
        status = spider_net_get_descr_status(descr);
 
-       if (status == SPIDER_NET_DESCR_CARDOWNED) {
-               /* nothing in the descriptor yet */
-               result=0;
-               goto out;
-       }
-
-       if (status == SPIDER_NET_DESCR_NOT_IN_USE) {
-               /* not initialized yet, the ring must be empty */
-               spider_net_refill_rx_chain(card);
-               spider_net_enable_rxdmac(card);
-               result=0;
-               goto out;
-       }
+       /* Nothing in the descriptor, or ring must be empty */
+       if ((status == SPIDER_NET_DESCR_CARDOWNED) ||
+           (status == SPIDER_NET_DESCR_NOT_IN_USE))
+               return 0;
 
        /* descriptor definitively used -- move on tail */
        chain->tail = descr->next;
 
-       result = 0;
+       /* unmap descriptor */
+       pci_unmap_single(card->pdev, descr->buf_addr,
+                       SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
+
        if ( (status == SPIDER_NET_DESCR_RESPONSE_ERROR) ||
             (status == SPIDER_NET_DESCR_PROTECTION_ERROR) ||
             (status == SPIDER_NET_DESCR_FORCE_END) ) {
@@ -1035,31 +1031,55 @@ spider_net_decode_one_descr(struct spider_net_card *card, int napi)
                        pr_err("%s: dropping RX descriptor with state %d\n",
                               card->netdev->name, status);
                card->netdev_stats.rx_dropped++;
-               pci_unmap_single(card->pdev, descr->buf_addr,
-                               SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
-               dev_kfree_skb_irq(descr->skb);
-               goto refill;
+               goto bad_desc;
        }
 
        if ( (status != SPIDER_NET_DESCR_COMPLETE) &&
             (status != SPIDER_NET_DESCR_FRAME_END) ) {
-               if (netif_msg_rx_err(card)) {
-                       pr_err("%s: RX descriptor with state %d\n",
+               if (netif_msg_rx_err(card))
+                       pr_err("%s: RX descriptor with unkown state %d\n",
                               card->netdev->name, status);
-                       card->spider_stats.rx_desc_unk_state++;
-               }
-               goto refill;
+               card->spider_stats.rx_desc_unk_state++;
+               goto bad_desc;
        }
 
-       /* ok, we've got a packet in descr */
-       result = spider_net_pass_skb_up(descr, card, napi);
-refill:
+       /* The cases we'll throw away the packet immediately */
+       if (descr->data_error & SPIDER_NET_DESTROY_RX_FLAGS) {
+               if (netif_msg_rx_err(card))
+                       pr_err("%s: error in received descriptor found, "
+                              "data_status=x%08x, data_error=x%08x\n",
+                              card->netdev->name,
+                              descr->data_status, descr->data_error);
+               goto bad_desc;
+       }
+
+       if (descr->dmac_cmd_status & 0xfefe) {
+               pr_err("%s: bad status, cmd_status=x%08x\n",
+                              card->netdev->name,
+                              descr->dmac_cmd_status);
+               pr_err("buf_addr=x%08x\n", descr->buf_addr);
+               pr_err("buf_size=x%08x\n", descr->buf_size);
+               pr_err("next_descr_addr=x%08x\n", descr->next_descr_addr);
+               pr_err("result_size=x%08x\n", descr->result_size);
+               pr_err("valid_size=x%08x\n", descr->valid_size);
+               pr_err("data_status=x%08x\n", descr->data_status);
+               pr_err("data_error=x%08x\n", descr->data_error);
+               pr_err("bus_addr=x%08x\n", descr->bus_addr);
+               pr_err("which=%ld\n", descr - card->rx_chain.ring);
+
+               card->spider_stats.rx_desc_error++;
+               goto bad_desc;
+       }
+
+       /* Ok, we've got a packet in descr */
+       spider_net_pass_skb_up(descr, card);
        descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
-       /* change the descriptor state: */
-       if (!napi)
-               spider_net_refill_rx_chain(card);
-out:
-       return result;
+       return 1;
+
+bad_desc:
+       dev_kfree_skb_irq(descr->skb);
+       descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
+       return 0;
 }
 
 /**
@@ -1085,7 +1105,7 @@ spider_net_poll(struct net_device *netdev, int *budget)
        packets_to_do = min(*budget, netdev->quota);
 
        while (packets_to_do) {
-               if (spider_net_decode_one_descr(card, 1)) {
+               if (spider_net_decode_one_descr(card)) {
                        packets_done++;
                        packets_to_do--;
                } else {
@@ -1098,6 +1118,7 @@ spider_net_poll(struct net_device *netdev, int *budget)
        netdev->quota -= packets_done;
        *budget -= packets_done;
        spider_net_refill_rx_chain(card);
+       spider_net_enable_rxdmac(card);
 
        /* if all packets are in the stack, enable interrupts and return 0 */
        /* if not, return 1 */
@@ -1226,24 +1247,6 @@ spider_net_set_mac(struct net_device *netdev, void *p)
        return 0;
 }
 
-/**
- * spider_net_handle_rxram_full - cleans up RX ring upon RX RAM full interrupt
- * @card: card structure
- *
- * spider_net_handle_rxram_full empties the RX ring so that spider can put
- * more packets in it and empty its RX RAM. This is called in bottom half
- * context
- */
-static void
-spider_net_handle_rxram_full(struct spider_net_card *card)
-{
-       while (spider_net_decode_one_descr(card, 0))
-               ;
-       spider_net_enable_rxchtails(card);
-       spider_net_enable_rxdmac(card);
-       netif_rx_schedule(card->netdev);
-}
-
 /**
  * spider_net_handle_error_irq - handles errors raised by an interrupt
  * @card: card structure
@@ -1366,10 +1369,10 @@ spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
        case SPIDER_NET_GRFAFLLINT: /* fallthrough */
        case SPIDER_NET_GRMFLLINT:
                if (netif_msg_intr(card) && net_ratelimit())
-                       pr_debug("Spider RX RAM full, incoming packets "
+                       pr_err("Spider RX RAM full, incoming packets "
                               "might be discarded!\n");
                spider_net_rx_irq_off(card);
-               tasklet_schedule(&card->rxram_full_tl);
+               netif_rx_schedule(card->netdev);
                show_error = 0;
                break;
 
@@ -1384,7 +1387,7 @@ spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
        case SPIDER_NET_GDCDCEINT: /* fallthrough */
        case SPIDER_NET_GDBDCEINT: /* fallthrough */
        case SPIDER_NET_GDADCEINT:
-               if (netif_msg_intr(card))
+               if (netif_msg_intr(card) && net_ratelimit())
                        pr_err("got descriptor chain end interrupt, "
                               "restarting DMAC %c.\n",
                               'D'-(i-SPIDER_NET_GDDDCEINT)/3);
@@ -1455,7 +1458,7 @@ spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
                        break;
        }
 
-       if ((show_error) && (netif_msg_intr(card)))
+       if ((show_error) && (netif_msg_intr(card)) && net_ratelimit())
                pr_err("Got error interrupt on %s, GHIINT0STS = 0x%08x, "
                       "GHIINT1STS = 0x%08x, GHIINT2STS = 0x%08x\n",
                       card->netdev->name,
@@ -1651,27 +1654,18 @@ int
 spider_net_open(struct net_device *netdev)
 {
        struct spider_net_card *card = netdev_priv(netdev);
-       struct spider_net_descr *descr;
-       int i, result;
+       int result;
 
-       result = -ENOMEM;
-       if (spider_net_init_chain(card, &card->tx_chain, card->descr,
-                                 card->num_tx_desc))
+       result = spider_net_init_chain(card, &card->tx_chain);
+       if (result)
                goto alloc_tx_failed;
-
        card->low_watermark = NULL;
 
-       /* rx_chain is after tx_chain, so offset is descr + tx_count */
-       if (spider_net_init_chain(card, &card->rx_chain,
-                                 card->descr + card->num_tx_desc,
-                                 card->num_rx_desc))
+       result = spider_net_init_chain(card, &card->rx_chain);
+       if (result)
                goto alloc_rx_failed;
 
-       descr = card->rx_chain.head;
-       for (i=0; i < card->num_rx_desc; i++, descr++)
-               descr->next_descr_addr = descr->next->bus_addr;
-
-       /* allocate rx skbs */
+       /* Allocate rx skbs */
        if (spider_net_alloc_rx_skbs(card))
                goto alloc_skbs_failed;
 
@@ -1902,7 +1896,6 @@ spider_net_stop(struct net_device *netdev)
 {
        struct spider_net_card *card = netdev_priv(netdev);
 
-       tasklet_kill(&card->rxram_full_tl);
        netif_poll_disable(netdev);
        netif_carrier_off(netdev);
        netif_stop_queue(netdev);
@@ -1924,6 +1917,7 @@ spider_net_stop(struct net_device *netdev)
 
        /* release chains */
        spider_net_release_tx_chain(card, 1);
+       spider_net_free_rx_chain_contents(card);
 
        spider_net_free_rx_chain_contents(card);
 
@@ -2046,9 +2040,6 @@ spider_net_setup_netdev(struct spider_net_card *card)
 
        pci_set_drvdata(card->pdev, netdev);
 
-       card->rxram_full_tl.data = (unsigned long) card;
-       card->rxram_full_tl.func =
-               (void (*)(unsigned long)) spider_net_handle_rxram_full;
        init_timer(&card->tx_timer);
        card->tx_timer.function =
                (void (*)(unsigned long)) spider_net_cleanup_tx_ring;
@@ -2057,8 +2048,8 @@ spider_net_setup_netdev(struct spider_net_card *card)
 
        card->options.rx_csum = SPIDER_NET_RX_CSUM_DEFAULT;
 
-       card->num_tx_desc = tx_descriptors;
-       card->num_rx_desc = rx_descriptors;
+       card->tx_chain.num_desc = tx_descriptors;
+       card->rx_chain.num_desc = rx_descriptors;
 
        spider_net_setup_netdev_ops(netdev);
 
@@ -2107,12 +2098,8 @@ spider_net_alloc_card(void)
 {
        struct net_device *netdev;
        struct spider_net_card *card;
-       size_t alloc_size;
 
-       alloc_size = sizeof (*card) +
-               sizeof (struct spider_net_descr) * rx_descriptors +
-               sizeof (struct spider_net_descr) * tx_descriptors;
-       netdev = alloc_etherdev(alloc_size);
+       netdev = alloc_etherdev(sizeof(struct spider_net_card));
        if (!netdev)
                return NULL;
 
index 3e196df29790dcd50795c6872bb64e5e7d08389d..2fec5cf76926d31d18bc8f1b278e47fdcc13e86b 100644 (file)
@@ -24,7 +24,7 @@
 #ifndef _SPIDER_NET_H
 #define _SPIDER_NET_H
 
-#define VERSION "1.6 A"
+#define VERSION "1.6 B"
 
 #include "sungem_phy.h"
 
@@ -378,6 +378,9 @@ struct spider_net_descr_chain {
        spinlock_t lock;
        struct spider_net_descr *head;
        struct spider_net_descr *tail;
+       struct spider_net_descr *ring;
+       int num_desc;
+       dma_addr_t dma_addr;
 };
 
 /* descriptor data_status bits */
@@ -397,8 +400,6 @@ struct spider_net_descr_chain {
  * 701b8000 would be correct, but every packets gets that flag */
 #define SPIDER_NET_DESTROY_RX_FLAGS    0x700b8000
 
-#define SPIDER_NET_DESCR_SIZE          32
-
 /* this will be bigger some time */
 struct spider_net_options {
        int rx_csum; /* for rx: if 0 ip_summed=NONE,
@@ -441,25 +442,16 @@ struct spider_net_card {
        struct spider_net_descr_chain rx_chain;
        struct spider_net_descr *low_watermark;
 
-       struct net_device_stats netdev_stats;
-
-       struct spider_net_options options;
-
-       spinlock_t intmask_lock;
-       struct tasklet_struct rxram_full_tl;
        struct timer_list tx_timer;
-
        struct work_struct tx_timeout_task;
        atomic_t tx_timeout_task_counter;
        wait_queue_head_t waitq;
 
        /* for ethtool */
        int msg_enable;
-       int num_rx_desc;
-       int num_tx_desc;
+       struct net_device_stats netdev_stats;
        struct spider_net_extra_stats spider_stats;
-
-       struct spider_net_descr descr[0];
+       struct spider_net_options options;
 };
 
 #define pr_err(fmt,arg...) \
index 91b99510291516d172701c2b7e9e9cff6f4f30ce..6bcf03fc89be75f1b1524e841b137d3861ddfef2 100644 (file)
@@ -158,9 +158,9 @@ spider_net_ethtool_get_ringparam(struct net_device *netdev,
        struct spider_net_card *card = netdev->priv;
 
        ering->tx_max_pending = SPIDER_NET_TX_DESCRIPTORS_MAX;
-       ering->tx_pending = card->num_tx_desc;
+       ering->tx_pending = card->tx_chain.num_desc;
        ering->rx_max_pending = SPIDER_NET_RX_DESCRIPTORS_MAX;
-       ering->rx_pending = card->num_rx_desc;
+       ering->rx_pending = card->rx_chain.num_desc;
 }
 
 static int spider_net_get_stats_count(struct net_device *netdev)
index f4bf62c2a7a5dea42a175509d4aff8ff84e5b596..135c0987deaeeb25a0793a4e0925b1bfb3f1fe89 100644 (file)
 #define TG3_VLAN_TAG_USED 0
 #endif
 
-#ifdef NETIF_F_TSO
 #define TG3_TSO_SUPPORT        1
-#else
-#define TG3_TSO_SUPPORT        0
-#endif
 
 #include "tg3.h"
 
@@ -3873,7 +3869,6 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        entry = tp->tx_prod;
        base_flags = 0;
-#if TG3_TSO_SUPPORT != 0
        mss = 0;
        if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
            (mss = skb_shinfo(skb)->gso_size) != 0) {
@@ -3906,11 +3901,6 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
        }
        else if (skb->ip_summed == CHECKSUM_PARTIAL)
                base_flags |= TXD_FLAG_TCPUDP_CSUM;
-#else
-       mss = 0;
-       if (skb->ip_summed == CHECKSUM_PARTIAL)
-               base_flags |= TXD_FLAG_TCPUDP_CSUM;
-#endif
 #if TG3_VLAN_TAG_USED
        if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
                base_flags |= (TXD_FLAG_VLAN |
@@ -3970,7 +3960,6 @@ out_unlock:
        return NETDEV_TX_OK;
 }
 
-#if TG3_TSO_SUPPORT != 0
 static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
 
 /* Use GSO to workaround a rare TSO bug that may be triggered when the
@@ -4002,7 +3991,6 @@ tg3_tso_bug_end:
 
        return NETDEV_TX_OK;
 }
-#endif
 
 /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
@@ -4036,7 +4024,6 @@ static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
        base_flags = 0;
        if (skb->ip_summed == CHECKSUM_PARTIAL)
                base_flags |= TXD_FLAG_TCPUDP_CSUM;
-#if TG3_TSO_SUPPORT != 0
        mss = 0;
        if (skb->len > (tp->dev->mtu + ETH_HLEN) &&
            (mss = skb_shinfo(skb)->gso_size) != 0) {
@@ -4091,9 +4078,6 @@ static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
                        }
                }
        }
-#else
-       mss = 0;
-#endif
 #if TG3_VLAN_TAG_USED
        if (tp->vlgrp != NULL && vlan_tx_tag_present(skb))
                base_flags |= (TXD_FLAG_VLAN |
@@ -5329,7 +5313,6 @@ static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp)
        return 0;
 }
 
-#if TG3_TSO_SUPPORT != 0
 
 #define TG3_TSO_FW_RELEASE_MAJOR       0x1
 #define TG3_TSO_FW_RELASE_MINOR                0x6
@@ -5906,7 +5889,6 @@ static int tg3_load_tso_firmware(struct tg3 *tp)
        return 0;
 }
 
-#endif /* TG3_TSO_SUPPORT != 0 */
 
 /* tp->lock is held. */
 static void __tg3_set_mac_addr(struct tg3 *tp)
@@ -6120,7 +6102,6 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
                tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE);
                tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE);
        }
-#if TG3_TSO_SUPPORT != 0
        else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
                int fw_len;
 
@@ -6135,7 +6116,6 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
                tw32(BUFMGR_MB_POOL_SIZE,
                     NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00);
        }
-#endif
 
        if (tp->dev->mtu <= ETH_DATA_LEN) {
                tw32(BUFMGR_MB_RDMA_LOW_WATER,
@@ -6337,10 +6317,8 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
        if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)
                rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST;
 
-#if TG3_TSO_SUPPORT != 0
        if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
                rdmac_mode |= (1 << 27);
-#endif
 
        /* Receive/send statistics. */
        if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
@@ -6511,10 +6489,8 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
        tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB);
        tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ);
        tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE);
-#if TG3_TSO_SUPPORT != 0
        if (tp->tg3_flags2 & TG3_FLG2_HW_TSO)
                tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8);
-#endif
        tw32(SNDBDI_MODE, SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE);
        tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE);
 
@@ -6524,13 +6500,11 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
                        return err;
        }
 
-#if TG3_TSO_SUPPORT != 0
        if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) {
                err = tg3_load_tso_firmware(tp);
                if (err)
                        return err;
        }
-#endif
 
        tp->tx_mode = TX_MODE_ENABLE;
        tw32_f(MAC_TX_MODE, tp->tx_mode);
@@ -8062,7 +8036,6 @@ static void tg3_set_msglevel(struct net_device *dev, u32 value)
        tp->msg_enable = value;
 }
 
-#if TG3_TSO_SUPPORT != 0
 static int tg3_set_tso(struct net_device *dev, u32 value)
 {
        struct tg3 *tp = netdev_priv(dev);
@@ -8081,7 +8054,6 @@ static int tg3_set_tso(struct net_device *dev, u32 value)
        }
        return ethtool_op_set_tso(dev, value);
 }
-#endif
 
 static int tg3_nway_reset(struct net_device *dev)
 {
@@ -9212,10 +9184,8 @@ static const struct ethtool_ops tg3_ethtool_ops = {
        .set_tx_csum            = tg3_set_tx_csum,
        .get_sg                 = ethtool_op_get_sg,
        .set_sg                 = ethtool_op_set_sg,
-#if TG3_TSO_SUPPORT != 0
        .get_tso                = ethtool_op_get_tso,
        .set_tso                = tg3_set_tso,
-#endif
        .self_test_count        = tg3_get_test_count,
        .self_test              = tg3_self_test,
        .get_strings            = tg3_get_strings,
@@ -11856,7 +11826,6 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
 
        tg3_init_bufmgr_config(tp);
 
-#if TG3_TSO_SUPPORT != 0
        if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
                tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
        }
@@ -11881,7 +11850,6 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
                        dev->features |= NETIF_F_TSO6;
        }
 
-#endif
 
        if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 &&
            !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) &&
index 7e4b23c7c1bab72dc73174c492ca9df70c326b6b..abb8611c5a916b7d3e12223cdfbfeeb30920e523 100644 (file)
@@ -2865,8 +2865,8 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
                                align = UCC_GETH_TX_BD_RING_ALIGNMENT;
                        ugeth->tx_bd_ring_offset[j] =
-                               (u32) (kmalloc((u32) (length + align),
-                               GFP_KERNEL));
+                               kmalloc((u32) (length + align), GFP_KERNEL);
+
                        if (ugeth->tx_bd_ring_offset[j] != 0)
                                ugeth->p_tx_bd_ring[j] =
                                        (void*)((ugeth->tx_bd_ring_offset[j] +
@@ -2901,7 +2901,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
                        if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
                                align = UCC_GETH_RX_BD_RING_ALIGNMENT;
                        ugeth->rx_bd_ring_offset[j] =
-                           (u32) (kmalloc((u32) (length + align), GFP_KERNEL));
+                               kmalloc((u32) (length + align), GFP_KERNEL);
                        if (ugeth->rx_bd_ring_offset[j] != 0)
                                ugeth->p_rx_bd_ring[j] =
                                        (void*)((ugeth->rx_bd_ring_offset[j] +
@@ -2927,10 +2927,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
        /* Init Tx bds */
        for (j = 0; j < ug_info->numQueuesTx; j++) {
                /* Setup the skbuff rings */
-               ugeth->tx_skbuff[j] =
-                   (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-                                              ugeth->ug_info->bdRingLenTx[j],
-                                              GFP_KERNEL);
+               ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+                                             ugeth->ug_info->bdRingLenTx[j],
+                                             GFP_KERNEL);
 
                if (ugeth->tx_skbuff[j] == NULL) {
                        ugeth_err("%s: Could not allocate tx_skbuff",
@@ -2959,10 +2958,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
        /* Init Rx bds */
        for (j = 0; j < ug_info->numQueuesRx; j++) {
                /* Setup the skbuff rings */
-               ugeth->rx_skbuff[j] =
-                   (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-                                              ugeth->ug_info->bdRingLenRx[j],
-                                              GFP_KERNEL);
+               ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+                                             ugeth->ug_info->bdRingLenRx[j],
+                                             GFP_KERNEL);
 
                if (ugeth->rx_skbuff[j] == NULL) {
                        ugeth_err("%s: Could not allocate rx_skbuff",
@@ -3453,8 +3451,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
         * allocated resources can be released when the channel is freed.
         */
        if (!(ugeth->p_init_enet_param_shadow =
-            (struct ucc_geth_init_pram *) kmalloc(sizeof(struct ucc_geth_init_pram),
-                                             GFP_KERNEL))) {
+             kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
                ugeth_err
                    ("%s: Can not allocate memory for"
                        " p_UccInitEnetParamShadows.", __FUNCTION__);
index 21f76f51c95e4efd26c4466330e74a63d322f42d..61708cf4c85df29fe27829d27483f69cd24ccfe5 100644 (file)
@@ -235,6 +235,19 @@ comment "Cyclades-PC300 MLPPP support is disabled."
 comment "Refer to the file README.mlppp, provided by PC300 package."
        depends on WAN && HDLC && PC300 && (PPP=n || !PPP_MULTILINK || PPP_SYNC_TTY=n || !HDLC_PPP)
 
+config PC300TOO
+       tristate "Cyclades PC300 RSV/X21 alternative support"
+       depends on HDLC && PCI
+       help
+         Alternative driver for PC300 RSV/X21 PCI cards made by
+         Cyclades, Inc. If you have such a card, say Y here and see
+         <http://www.kernel.org/pub/linux/utils/net/hdlc/>.
+
+         To compile this as a module, choose M here: the module
+         will be called pc300too.
+
+         If unsure, say N here.
+
 config N2
        tristate "SDL RISCom/N2 support"
        depends on HDLC && ISA
@@ -344,17 +357,6 @@ config DLCI
          To compile this driver as a module, choose M here: the
          module will be called dlci.
 
-config DLCI_COUNT
-       int "Max open DLCI"
-       depends on DLCI
-       default "24"
-       help
-         Maximal number of logical point-to-point frame relay connections
-         (the identifiers of which are called DCLIs) that the driver can
-         handle.
-
-         The default is probably fine.
-
 config DLCI_MAX
        int "Max DLCI per device"
        depends on DLCI
index 83ec2c87ba3f34fea00937247f9e4e64bce65c67..d61fef36afc96b88e722e321dbd6aab016ef1e9f 100644 (file)
@@ -41,6 +41,7 @@ obj-$(CONFIG_N2)              += n2.o
 obj-$(CONFIG_C101)             += c101.o
 obj-$(CONFIG_WANXL)            += wanxl.o
 obj-$(CONFIG_PCI200SYN)                += pci200syn.o
+obj-$(CONFIG_PC300TOO)         += pc300too.o
 
 clean-files := wanxlfw.inc
 $(obj)/wanxl.o:        $(obj)/wanxlfw.inc
index db354e0edbe57692185e1d6fecae60f7d5cfbbaa..9040d7cf651e585d6b3976b76159ddef7125c7ee 100644 (file)
@@ -222,7 +222,7 @@ int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        return -EINVAL;
 }
 
-void hdlc_setup(struct net_device *dev)
+static void hdlc_setup(struct net_device *dev)
 {
        hdlc_device *hdlc = dev_to_hdlc(dev);
 
@@ -325,7 +325,6 @@ MODULE_LICENSE("GPL v2");
 EXPORT_SYMBOL(hdlc_open);
 EXPORT_SYMBOL(hdlc_close);
 EXPORT_SYMBOL(hdlc_ioctl);
-EXPORT_SYMBOL(hdlc_setup);
 EXPORT_SYMBOL(alloc_hdlcdev);
 EXPORT_SYMBOL(unregister_hdlc_device);
 EXPORT_SYMBOL(register_hdlc_protocol);
diff --git a/drivers/net/wan/pc300too.c b/drivers/net/wan/pc300too.c
new file mode 100644 (file)
index 0000000..79b2d54
--- /dev/null
@@ -0,0 +1,565 @@
+/*
+ * Cyclades PC300 synchronous serial card driver for Linux
+ *
+ * Copyright (C) 2000-2007 Krzysztof Halasa <khc@pm.waw.pl>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ *
+ * For information see <http://www.kernel.org/pub/linux/utils/net/hdlc/>.
+ *
+ * Sources of information:
+ *    Hitachi HD64572 SCA-II User's Manual
+ *    Cyclades PC300 Linux driver
+ *
+ * This driver currently supports only PC300/RSV (V.24/V.35) and
+ * PC300/X21 cards.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/fcntl.h>
+#include <linux/in.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/moduleparam.h>
+#include <linux/netdevice.h>
+#include <linux/hdlc.h>
+#include <linux/pci.h>
+#include <linux/delay.h>
+#include <asm/io.h>
+
+#include "hd64572.h"
+
+static const char* version = "Cyclades PC300 driver version: 1.17";
+static const char* devname = "PC300";
+
+#undef DEBUG_PKT
+#define DEBUG_RINGS
+
+#define PC300_PLX_SIZE         0x80    /* PLX control window size (128 B) */
+#define PC300_SCA_SIZE         0x400   /* SCA window size (1 KB) */
+#define ALL_PAGES_ALWAYS_MAPPED
+#define NEED_DETECT_RAM
+#define NEED_SCA_MSCI_INTR
+#define MAX_TX_BUFFERS         10
+
+static int pci_clock_freq = 33000000;
+static int use_crystal_clock = 0;
+static unsigned int CLOCK_BASE;
+
+/* Masks to access the init_ctrl PLX register */
+#define PC300_CLKSEL_MASK       (0x00000004UL)
+#define PC300_CHMEDIA_MASK(port) (0x00000020UL << ((port) * 3))
+#define PC300_CTYPE_MASK        (0x00000800UL)
+
+
+enum { PC300_RSV = 1, PC300_X21, PC300_TE }; /* card types */
+
+/*
+ *      PLX PCI9050-1 local configuration and shared runtime registers.
+ *      This structure can be used to access 9050 registers (memory mapped).
+ */
+typedef struct {
+       u32 loc_addr_range[4];  /* 00-0Ch : Local Address Ranges */
+       u32 loc_rom_range;      /* 10h : Local ROM Range */
+       u32 loc_addr_base[4];   /* 14-20h : Local Address Base Addrs */
+       u32 loc_rom_base;       /* 24h : Local ROM Base */
+       u32 loc_bus_descr[4];   /* 28-34h : Local Bus Descriptors */
+       u32 rom_bus_descr;      /* 38h : ROM Bus Descriptor */
+       u32 cs_base[4];         /* 3C-48h : Chip Select Base Addrs */
+       u32 intr_ctrl_stat;     /* 4Ch : Interrupt Control/Status */
+       u32 init_ctrl;          /* 50h : EEPROM ctrl, Init Ctrl, etc */
+}plx9050;
+
+
+
+typedef struct port_s {
+       struct net_device *dev;
+       struct card_s *card;
+       spinlock_t lock;        /* TX lock */
+       sync_serial_settings settings;
+       int rxpart;             /* partial frame received, next frame invalid*/
+       unsigned short encoding;
+       unsigned short parity;
+       unsigned int iface;
+       u16 rxin;               /* rx ring buffer 'in' pointer */
+       u16 txin;               /* tx ring buffer 'in' and 'last' pointers */
+       u16 txlast;
+       u8 rxs, txs, tmc;       /* SCA registers */
+       u8 phy_node;            /* physical port # - 0 or 1 */
+}port_t;
+
+
+
+typedef struct card_s {
+       int type;               /* RSV, X21, etc. */
+       int n_ports;            /* 1 or 2 ports */
+       u8* __iomem rambase;    /* buffer memory base (virtual) */
+       u8* __iomem scabase;    /* SCA memory base (virtual) */
+       plx9050 __iomem *plxbase; /* PLX registers memory base (virtual) */
+       u32 init_ctrl_value;    /* Saved value - 9050 bug workaround */
+       u16 rx_ring_buffers;    /* number of buffers in a ring */
+       u16 tx_ring_buffers;
+       u16 buff_offset;        /* offset of first buffer of first channel */
+       u8 irq;                 /* interrupt request level */
+
+       port_t ports[2];
+}card_t;
+
+
+#define sca_in(reg, card)           readb(card->scabase + (reg))
+#define sca_out(value, reg, card)    writeb(value, card->scabase + (reg))
+#define sca_inw(reg, card)          readw(card->scabase + (reg))
+#define sca_outw(value, reg, card)   writew(value, card->scabase + (reg))
+#define sca_inl(reg, card)          readl(card->scabase + (reg))
+#define sca_outl(value, reg, card)   writel(value, card->scabase + (reg))
+
+#define port_to_card(port)          (port->card)
+#define log_node(port)              (port->phy_node)
+#define phy_node(port)              (port->phy_node)
+#define winbase(card)               (card->rambase)
+#define get_port(card, port)        ((port) < (card)->n_ports ? \
+                                        (&(card)->ports[port]) : (NULL))
+
+#include "hd6457x.c"
+
+
+static void pc300_set_iface(port_t *port)
+{
+       card_t *card = port->card;
+       u32* init_ctrl = &card->plxbase->init_ctrl;
+       u16 msci = get_msci(port);
+       u8 rxs = port->rxs & CLK_BRG_MASK;
+       u8 txs = port->txs & CLK_BRG_MASK;
+
+       sca_out(EXS_TES1, (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS,
+               port_to_card(port));
+       switch(port->settings.clock_type) {
+       case CLOCK_INT:
+               rxs |= CLK_BRG; /* BRG output */
+               txs |= CLK_PIN_OUT | CLK_TX_RXCLK; /* RX clock */
+               break;
+
+       case CLOCK_TXINT:
+               rxs |= CLK_LINE; /* RXC input */
+               txs |= CLK_PIN_OUT | CLK_BRG; /* BRG output */
+               break;
+
+       case CLOCK_TXFROMRX:
+               rxs |= CLK_LINE; /* RXC input */
+               txs |= CLK_PIN_OUT | CLK_TX_RXCLK; /* RX clock */
+               break;
+
+       default:                /* EXTernal clock */
+               rxs |= CLK_LINE; /* RXC input */
+               txs |= CLK_PIN_OUT | CLK_LINE; /* TXC input */
+               break;
+       }
+
+       port->rxs = rxs;
+       port->txs = txs;
+       sca_out(rxs, msci + RXS, card);
+       sca_out(txs, msci + TXS, card);
+       sca_set_port(port);
+
+       if (port->card->type == PC300_RSV) {
+               if (port->iface == IF_IFACE_V35)
+                       writel(card->init_ctrl_value |
+                              PC300_CHMEDIA_MASK(port->phy_node), init_ctrl);
+               else
+                       writel(card->init_ctrl_value &
+                              ~PC300_CHMEDIA_MASK(port->phy_node), init_ctrl);
+       }
+}
+
+
+
+static int pc300_open(struct net_device *dev)
+{
+       port_t *port = dev_to_port(dev);
+
+       int result = hdlc_open(dev);
+       if (result)
+               return result;
+
+       sca_open(dev);
+       pc300_set_iface(port);
+       return 0;
+}
+
+
+
+static int pc300_close(struct net_device *dev)
+{
+       sca_close(dev);
+       hdlc_close(dev);
+       return 0;
+}
+
+
+
+static int pc300_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
+{
+       const size_t size = sizeof(sync_serial_settings);
+       sync_serial_settings new_line;
+       sync_serial_settings __user *line = ifr->ifr_settings.ifs_ifsu.sync;
+       int new_type;
+       port_t *port = dev_to_port(dev);
+
+#ifdef DEBUG_RINGS
+       if (cmd == SIOCDEVPRIVATE) {
+               sca_dump_rings(dev);
+               return 0;
+       }
+#endif
+       if (cmd != SIOCWANDEV)
+               return hdlc_ioctl(dev, ifr, cmd);
+
+       if (ifr->ifr_settings.type == IF_GET_IFACE) {
+               ifr->ifr_settings.type = port->iface;
+               if (ifr->ifr_settings.size < size) {
+                       ifr->ifr_settings.size = size; /* data size wanted */
+                       return -ENOBUFS;
+               }
+               if (copy_to_user(line, &port->settings, size))
+                       return -EFAULT;
+               return 0;
+
+       }
+
+       if (port->card->type == PC300_X21 &&
+           (ifr->ifr_settings.type == IF_IFACE_SYNC_SERIAL ||
+            ifr->ifr_settings.type == IF_IFACE_X21))
+               new_type = IF_IFACE_X21;
+
+       else if (port->card->type == PC300_RSV &&
+                (ifr->ifr_settings.type == IF_IFACE_SYNC_SERIAL ||
+                 ifr->ifr_settings.type == IF_IFACE_V35))
+               new_type = IF_IFACE_V35;
+
+       else if (port->card->type == PC300_RSV &&
+                ifr->ifr_settings.type == IF_IFACE_V24)
+               new_type = IF_IFACE_V24;
+
+       else
+               return hdlc_ioctl(dev, ifr, cmd);
+
+       if (!capable(CAP_NET_ADMIN))
+               return -EPERM;
+
+       if (copy_from_user(&new_line, line, size))
+               return -EFAULT;
+
+       if (new_line.clock_type != CLOCK_EXT &&
+           new_line.clock_type != CLOCK_TXFROMRX &&
+           new_line.clock_type != CLOCK_INT &&
+           new_line.clock_type != CLOCK_TXINT)
+               return -EINVAL; /* No such clock setting */
+
+       if (new_line.loopback != 0 && new_line.loopback != 1)
+               return -EINVAL;
+
+       memcpy(&port->settings, &new_line, size); /* Update settings */
+       port->iface = new_type;
+       pc300_set_iface(port);
+       return 0;
+}
+
+
+
+static void pc300_pci_remove_one(struct pci_dev *pdev)
+{
+       int i;
+       card_t *card = pci_get_drvdata(pdev);
+
+       for (i = 0; i < 2; i++)
+               if (card->ports[i].card) {
+                       struct net_device *dev = port_to_dev(&card->ports[i]);
+                       unregister_hdlc_device(dev);
+               }
+
+       if (card->irq)
+               free_irq(card->irq, card);
+
+       if (card->rambase)
+               iounmap(card->rambase);
+       if (card->scabase)
+               iounmap(card->scabase);
+       if (card->plxbase)
+               iounmap(card->plxbase);
+
+       pci_release_regions(pdev);
+       pci_disable_device(pdev);
+       pci_set_drvdata(pdev, NULL);
+       if (card->ports[0].dev)
+               free_netdev(card->ports[0].dev);
+       if (card->ports[1].dev)
+               free_netdev(card->ports[1].dev);
+       kfree(card);
+}
+
+
+
+static int __devinit pc300_pci_init_one(struct pci_dev *pdev,
+                                       const struct pci_device_id *ent)
+{
+       card_t *card;
+       u8 rev_id;
+       u32 __iomem *p;
+       int i;
+       u32 ramsize;
+       u32 ramphys;            /* buffer memory base */
+       u32 scaphys;            /* SCA memory base */
+       u32 plxphys;            /* PLX registers memory base */
+
+#ifndef MODULE
+       static int printed_version;
+       if (!printed_version++)
+               printk(KERN_INFO "%s\n", version);
+#endif
+
+       i = pci_enable_device(pdev);
+       if (i)
+               return i;
+
+       i = pci_request_regions(pdev, "PC300");
+       if (i) {
+               pci_disable_device(pdev);
+               return i;
+       }
+
+       card = kmalloc(sizeof(card_t), GFP_KERNEL);
+       if (card == NULL) {
+               printk(KERN_ERR "pc300: unable to allocate memory\n");
+               pci_release_regions(pdev);
+               pci_disable_device(pdev);
+               return -ENOBUFS;
+       }
+       memset(card, 0, sizeof(card_t));
+       pci_set_drvdata(pdev, card);
+
+       if (pdev->device == PCI_DEVICE_ID_PC300_TE_1 ||
+           pdev->device == PCI_DEVICE_ID_PC300_TE_2)
+               card->type = PC300_TE; /* not fully supported */
+       else if (card->init_ctrl_value & PC300_CTYPE_MASK)
+               card->type = PC300_X21;
+       else
+               card->type = PC300_RSV;
+
+       if (pdev->device == PCI_DEVICE_ID_PC300_RX_1 ||
+           pdev->device == PCI_DEVICE_ID_PC300_TE_1)
+               card->n_ports = 1;
+       else
+               card->n_ports = 2;
+
+       for (i = 0; i < card->n_ports; i++)
+               if (!(card->ports[i].dev = alloc_hdlcdev(&card->ports[i]))) {
+                       printk(KERN_ERR "pc300: unable to allocate memory\n");
+                       pc300_pci_remove_one(pdev);
+                       return -ENOMEM;
+               }
+
+       pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
+       if (pci_resource_len(pdev, 0) != PC300_PLX_SIZE ||
+           pci_resource_len(pdev, 2) != PC300_SCA_SIZE ||
+           pci_resource_len(pdev, 3) < 16384) {
+               printk(KERN_ERR "pc300: invalid card EEPROM parameters\n");
+               pc300_pci_remove_one(pdev);
+               return -EFAULT;
+       }
+
+       plxphys = pci_resource_start(pdev,0) & PCI_BASE_ADDRESS_MEM_MASK;
+       card->plxbase = ioremap(plxphys, PC300_PLX_SIZE);
+
+       scaphys = pci_resource_start(pdev,2) & PCI_BASE_ADDRESS_MEM_MASK;
+       card->scabase = ioremap(scaphys, PC300_SCA_SIZE);
+
+       ramphys = pci_resource_start(pdev,3) & PCI_BASE_ADDRESS_MEM_MASK;
+       card->rambase = ioremap(ramphys, pci_resource_len(pdev,3));
+
+       if (card->plxbase == NULL ||
+           card->scabase == NULL ||
+           card->rambase == NULL) {
+               printk(KERN_ERR "pc300: ioremap() failed\n");
+               pc300_pci_remove_one(pdev);
+       }
+
+       /* PLX PCI 9050 workaround for local configuration register read bug */
+       pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, scaphys);
+       card->init_ctrl_value = readl(&((plx9050*)card->scabase)->init_ctrl);
+       pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, plxphys);
+
+       /* Reset PLX */
+       p = &card->plxbase->init_ctrl;
+       writel(card->init_ctrl_value | 0x40000000, p);
+       readl(p);               /* Flush the write - do not use sca_flush */
+       udelay(1);
+
+       writel(card->init_ctrl_value, p);
+       readl(p);               /* Flush the write - do not use sca_flush */
+       udelay(1);
+
+       /* Reload Config. Registers from EEPROM */
+       writel(card->init_ctrl_value | 0x20000000, p);
+       readl(p);               /* Flush the write - do not use sca_flush */
+       udelay(1);
+
+       writel(card->init_ctrl_value, p);
+       readl(p);               /* Flush the write - do not use sca_flush */
+       udelay(1);
+
+       ramsize = sca_detect_ram(card, card->rambase,
+                                pci_resource_len(pdev, 3));
+
+       if (use_crystal_clock)
+               card->init_ctrl_value &= ~PC300_CLKSEL_MASK;
+       else
+               card->init_ctrl_value |= PC300_CLKSEL_MASK;
+
+       writel(card->init_ctrl_value, &card->plxbase->init_ctrl);
+       /* number of TX + RX buffers for one port */
+       i = ramsize / (card->n_ports * (sizeof(pkt_desc) + HDLC_MAX_MRU));
+       card->tx_ring_buffers = min(i / 2, MAX_TX_BUFFERS);
+       card->rx_ring_buffers = i - card->tx_ring_buffers;
+
+       card->buff_offset = card->n_ports * sizeof(pkt_desc) *
+               (card->tx_ring_buffers + card->rx_ring_buffers);
+
+       printk(KERN_INFO "pc300: PC300/%s, %u KB RAM at 0x%x, IRQ%u, "
+              "using %u TX + %u RX packets rings\n",
+              card->type == PC300_X21 ? "X21" :
+              card->type == PC300_TE ? "TE" : "RSV",
+              ramsize / 1024, ramphys, pdev->irq,
+              card->tx_ring_buffers, card->rx_ring_buffers);
+
+       if (card->tx_ring_buffers < 1) {
+               printk(KERN_ERR "pc300: RAM test failed\n");
+               pc300_pci_remove_one(pdev);
+               return -EFAULT;
+       }
+
+       /* Enable interrupts on the PCI bridge, LINTi1 active low */
+       writew(0x0041, &card->plxbase->intr_ctrl_stat);
+
+       /* Allocate IRQ */
+       if (request_irq(pdev->irq, sca_intr, IRQF_SHARED, devname, card)) {
+               printk(KERN_WARNING "pc300: could not allocate IRQ%d.\n",
+                      pdev->irq);
+               pc300_pci_remove_one(pdev);
+               return -EBUSY;
+       }
+       card->irq = pdev->irq;
+
+       sca_init(card, 0);
+
+       // COTE not set - allows better TX DMA settings
+       // sca_out(sca_in(PCR, card) | PCR_COTE, PCR, card);
+
+       sca_out(0x10, BTCR, card);
+
+       for (i = 0; i < card->n_ports; i++) {
+               port_t *port = &card->ports[i];
+               struct net_device *dev = port_to_dev(port);
+               hdlc_device *hdlc = dev_to_hdlc(dev);
+               port->phy_node = i;
+
+               spin_lock_init(&port->lock);
+               SET_MODULE_OWNER(dev);
+               dev->irq = card->irq;
+               dev->mem_start = ramphys;
+               dev->mem_end = ramphys + ramsize - 1;
+               dev->tx_queue_len = 50;
+               dev->do_ioctl = pc300_ioctl;
+               dev->open = pc300_open;
+               dev->stop = pc300_close;
+               hdlc->attach = sca_attach;
+               hdlc->xmit = sca_xmit;
+               port->settings.clock_type = CLOCK_EXT;
+               port->card = card;
+               if (card->type == PC300_X21)
+                       port->iface = IF_IFACE_X21;
+               else
+                       port->iface = IF_IFACE_V35;
+
+               if (register_hdlc_device(dev)) {
+                       printk(KERN_ERR "pc300: unable to register hdlc "
+                              "device\n");
+                       port->card = NULL;
+                       pc300_pci_remove_one(pdev);
+                       return -ENOBUFS;
+               }
+               sca_init_sync_port(port);       /* Set up SCA memory */
+
+               printk(KERN_INFO "%s: PC300 node %d\n",
+                      dev->name, port->phy_node);
+       }
+       return 0;
+}
+
+
+
+static struct pci_device_id pc300_pci_tbl[] __devinitdata = {
+       { PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_PC300_RX_1, PCI_ANY_ID,
+         PCI_ANY_ID, 0, 0, 0 },
+       { PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_PC300_RX_2, PCI_ANY_ID,
+         PCI_ANY_ID, 0, 0, 0 },
+       { PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_PC300_TE_1, PCI_ANY_ID,
+         PCI_ANY_ID, 0, 0, 0 },
+       { PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_PC300_TE_2, PCI_ANY_ID,
+         PCI_ANY_ID, 0, 0, 0 },
+       { 0, }
+};
+
+
+static struct pci_driver pc300_pci_driver = {
+       name:           "PC300",
+       id_table:       pc300_pci_tbl,
+       probe:          pc300_pci_init_one,
+       remove:         pc300_pci_remove_one,
+};
+
+
+static int __init pc300_init_module(void)
+{
+#ifdef MODULE
+       printk(KERN_INFO "%s\n", version);
+#endif
+       if (pci_clock_freq < 1000000 || pci_clock_freq > 80000000) {
+               printk(KERN_ERR "pc300: Invalid PCI clock frequency\n");
+               return -EINVAL;
+       }
+       if (use_crystal_clock != 0 && use_crystal_clock != 1) {
+               printk(KERN_ERR "pc300: Invalid 'use_crystal_clock' value\n");
+               return -EINVAL;
+       }
+
+       CLOCK_BASE = use_crystal_clock ? 24576000 : pci_clock_freq;
+
+       return pci_module_init(&pc300_pci_driver);
+}
+
+
+
+static void __exit pc300_cleanup_module(void)
+{
+       pci_unregister_driver(&pc300_pci_driver);
+}
+
+MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
+MODULE_DESCRIPTION("Cyclades PC300 serial port driver");
+MODULE_LICENSE("GPL v2");
+MODULE_DEVICE_TABLE(pci, pc300_pci_tbl);
+module_param(pci_clock_freq, int, 0444);
+MODULE_PARM_DESC(pci_clock_freq, "System PCI clock frequency in Hz");
+module_param(use_crystal_clock, int, 0444);
+MODULE_PARM_DESC(use_crystal_clock,
+                "Use 24.576 MHz clock instead of PCI clock");
+module_init(pc300_init_module);
+module_exit(pc300_cleanup_module);
index 59ddd21c3958ae3ab9942b8f9272f13a176467b6..8dbcf83bb5f360a96d4b2b1320489e7af78eb5e7 100644 (file)
@@ -331,8 +331,7 @@ static void z8530_rtsdtr(struct z8530_channel *c, int set)
 static void z8530_rx(struct z8530_channel *c)
 {
        u8 ch,stat;
-       spin_lock(c->lock);
+
        while(1)
        {
                /* FIFO empty ? */
@@ -390,7 +389,6 @@ static void z8530_rx(struct z8530_channel *c)
         */
        write_zsctrl(c, ERR_RES);
        write_zsctrl(c, RES_H_IUS);
-       spin_unlock(c->lock);
 }
 
 
@@ -406,7 +404,6 @@ static void z8530_rx(struct z8530_channel *c)
  
 static void z8530_tx(struct z8530_channel *c)
 {
-       spin_lock(c->lock);
        while(c->txcount) {
                /* FIFO full ? */
                if(!(read_zsreg(c, R0)&4))
@@ -434,7 +431,6 @@ static void z8530_tx(struct z8530_channel *c)
 
        z8530_tx_done(c);        
        write_zsctrl(c, RES_H_IUS);
-       spin_unlock(c->lock);
 }
 
 /**
@@ -452,7 +448,6 @@ static void z8530_status(struct z8530_channel *chan)
 {
        u8 status, altered;
 
-       spin_lock(chan->lock);
        status=read_zsreg(chan, R0);
        altered=chan->status^status;
        
@@ -487,7 +482,6 @@ static void z8530_status(struct z8530_channel *chan)
        }       
        write_zsctrl(chan, RES_EXT_INT);
        write_zsctrl(chan, RES_H_IUS);
-       spin_unlock(chan->lock);
 }
 
 struct z8530_irqhandler z8530_sync=
@@ -511,7 +505,6 @@ EXPORT_SYMBOL(z8530_sync);
  
 static void z8530_dma_rx(struct z8530_channel *chan)
 {
-       spin_lock(chan->lock);
        if(chan->rxdma_on)
        {
                /* Special condition check only */
@@ -534,7 +527,6 @@ static void z8530_dma_rx(struct z8530_channel *chan)
                /* DMA is off right now, drain the slow way */
                z8530_rx(chan);
        }       
-       spin_unlock(chan->lock);
 }
 
 /**
@@ -547,7 +539,6 @@ static void z8530_dma_rx(struct z8530_channel *chan)
  
 static void z8530_dma_tx(struct z8530_channel *chan)
 {
-       spin_lock(chan->lock);
        if(!chan->dma_tx)
        {
                printk(KERN_WARNING "Hey who turned the DMA off?\n");
@@ -557,7 +548,6 @@ static void z8530_dma_tx(struct z8530_channel *chan)
        /* This shouldnt occur in DMA mode */
        printk(KERN_ERR "DMA tx - bogus event!\n");
        z8530_tx(chan);
-       spin_unlock(chan->lock);
 }
 
 /**
@@ -596,7 +586,6 @@ static void z8530_dma_status(struct z8530_channel *chan)
                }
        }
 
-       spin_lock(chan->lock);
        if(altered&chan->dcdcheck)
        {
                if(status&chan->dcdcheck)
@@ -618,7 +607,6 @@ static void z8530_dma_status(struct z8530_channel *chan)
 
        write_zsctrl(chan, RES_EXT_INT);
        write_zsctrl(chan, RES_H_IUS);
-       spin_unlock(chan->lock);
 }
 
 struct z8530_irqhandler z8530_dma_sync=
index 8286678513b937db84bbfebff057191a62a0bdab..3a064def162e70d7e37547b1e3c97a9b6bc74b33 100644 (file)
 #define BCM43xx_UCODEFLAG_UNKPACTRL    0x0040
 #define BCM43xx_UCODEFLAG_JAPAN                0x0080
 
+/* Hardware Radio Enable masks */
+#define BCM43xx_MMIO_RADIO_HWENABLED_HI_MASK (1 << 16)
+#define BCM43xx_MMIO_RADIO_HWENABLED_LO_MASK (1 << 4)
+
 /* Generic-Interrupt reasons. */
 #define BCM43xx_IRQ_READY              (1 << 0)
 #define BCM43xx_IRQ_BEACON             (1 << 1)
@@ -758,7 +762,8 @@ struct bcm43xx_private {
            bad_frames_preempt:1,       /* Use "Bad Frames Preemption" (default off) */
            reg124_set_0x4:1,           /* Some variable to keep track of IRQ stuff. */
            short_preamble:1,           /* TRUE, if short preamble is enabled. */
-           firmware_norelease:1;       /* Do not release the firmware. Used on suspend. */
+           firmware_norelease:1,       /* Do not release the firmware. Used on suspend. */
+           radio_hw_enable:1;          /* TRUE if radio is hardware enabled */
 
        struct bcm43xx_stats stats;
 
index 7d383a27b9274d71027fb92c4f5d207f40833aa8..8f198befba390e1f325ee03f77bdc04b5896bc44 100644 (file)
@@ -26,6 +26,7 @@
 */
 
 #include "bcm43xx_leds.h"
+#include "bcm43xx_radio.h"
 #include "bcm43xx.h"
 
 #include <asm/bitops.h>
@@ -108,6 +109,7 @@ static void bcm43xx_led_init_hardcoded(struct bcm43xx_private *bcm,
        switch (led_index) {
        case 0:
                led->behaviour = BCM43xx_LED_ACTIVITY;
+               led->activelow = 1;
                if (bcm->board_vendor == PCI_VENDOR_ID_COMPAQ)
                        led->behaviour = BCM43xx_LED_RADIO_ALL;
                break;
@@ -199,20 +201,21 @@ void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity)
                        turn_on = activity;
                        break;
                case BCM43xx_LED_RADIO_ALL:
-                       turn_on = radio->enabled;
+                       turn_on = radio->enabled && bcm43xx_is_hw_radio_enabled(bcm);
                        break;
                case BCM43xx_LED_RADIO_A:
                case BCM43xx_LED_BCM4303_2:
-                       turn_on = (radio->enabled && phy->type == BCM43xx_PHYTYPE_A);
+                       turn_on = (radio->enabled && bcm43xx_is_hw_radio_enabled(bcm) &&
+                                  phy->type == BCM43xx_PHYTYPE_A);
                        break;
                case BCM43xx_LED_RADIO_B:
                case BCM43xx_LED_BCM4303_1:
-                       turn_on = (radio->enabled &&
+                       turn_on = (radio->enabled && bcm43xx_is_hw_radio_enabled(bcm) &&
                                   (phy->type == BCM43xx_PHYTYPE_B ||
                                    phy->type == BCM43xx_PHYTYPE_G));
                        break;
                case BCM43xx_LED_MODE_BG:
-                       if (phy->type == BCM43xx_PHYTYPE_G &&
+                       if (phy->type == BCM43xx_PHYTYPE_G && bcm43xx_is_hw_radio_enabled(bcm) &&
                            1/*FIXME: using G rates.*/)
                                turn_on = 1;
                        break;
index 91b752e3d07e104f10673f35fc8aee2aa5199df8..23aaf1ed8541d925bf1d453a43536b7766fc843d 100644 (file)
@@ -2441,6 +2441,9 @@ static int bcm43xx_chip_init(struct bcm43xx_private *bcm)
        if (err)
                goto err_gpio_cleanup;
        bcm43xx_radio_turn_on(bcm);
+       bcm->radio_hw_enable = bcm43xx_is_hw_radio_enabled(bcm);
+       dprintk(KERN_INFO PFX "Radio %s by hardware\n",
+               (bcm->radio_hw_enable == 0) ? "disabled" : "enabled");
 
        bcm43xx_write16(bcm, 0x03E6, 0x0000);
        err = bcm43xx_phy_init(bcm);
@@ -3174,10 +3177,25 @@ static void bcm43xx_periodic_every30sec(struct bcm43xx_private *bcm)
 }
 
 static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm)
+{
+       bcm43xx_phy_xmitpower(bcm); //FIXME: unless scanning?
+       //TODO for APHY (temperature?)
+}
+
+static void bcm43xx_periodic_every1sec(struct bcm43xx_private *bcm)
 {
        struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
        struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
+       int radio_hw_enable;
 
+       /* check if radio hardware enabled status changed */
+       radio_hw_enable = bcm43xx_is_hw_radio_enabled(bcm);
+       if (unlikely(bcm->radio_hw_enable != radio_hw_enable)) {
+               bcm->radio_hw_enable = radio_hw_enable;
+               dprintk(KERN_INFO PFX "Radio hardware status changed to %s\n",
+                      (radio_hw_enable == 0) ? "disabled" : "enabled");
+               bcm43xx_leds_update(bcm, 0);
+       }
        if (phy->type == BCM43xx_PHYTYPE_G) {
                //TODO: update_aci_moving_average
                if (radio->aci_enable && radio->aci_wlan_automatic) {
@@ -3201,21 +3219,21 @@ static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm)
                        //TODO: implement rev1 workaround
                }
        }
-       bcm43xx_phy_xmitpower(bcm); //FIXME: unless scanning?
-       //TODO for APHY (temperature?)
 }
 
 static void do_periodic_work(struct bcm43xx_private *bcm)
 {
-       if (bcm->periodic_state % 8 == 0)
+       if (bcm->periodic_state % 120 == 0)
                bcm43xx_periodic_every120sec(bcm);
-       if (bcm->periodic_state % 4 == 0)
+       if (bcm->periodic_state % 60 == 0)
                bcm43xx_periodic_every60sec(bcm);
-       if (bcm->periodic_state % 2 == 0)
+       if (bcm->periodic_state % 30 == 0)
                bcm43xx_periodic_every30sec(bcm);
-       bcm43xx_periodic_every15sec(bcm);
+       if (bcm->periodic_state % 15 == 0)
+               bcm43xx_periodic_every15sec(bcm);
+       bcm43xx_periodic_every1sec(bcm);
 
-       schedule_delayed_work(&bcm->periodic_work, HZ * 15);
+       schedule_delayed_work(&bcm->periodic_work, HZ);
 }
 
 static void bcm43xx_periodic_work_handler(struct work_struct *work)
@@ -3228,7 +3246,7 @@ static void bcm43xx_periodic_work_handler(struct work_struct *work)
        unsigned long orig_trans_start = 0;
 
        mutex_lock(&bcm->mutex);
-       if (unlikely(bcm->periodic_state % 4 == 0)) {
+       if (unlikely(bcm->periodic_state % 60 == 0)) {
                /* Periodic work will take a long time, so we want it to
                 * be preemtible.
                 */
@@ -3260,7 +3278,7 @@ static void bcm43xx_periodic_work_handler(struct work_struct *work)
 
        do_periodic_work(bcm);
 
-       if (unlikely(bcm->periodic_state % 4 == 0)) {
+       if (unlikely(bcm->periodic_state % 60 == 0)) {
                spin_lock_irqsave(&bcm->irq_lock, flags);
                tasklet_enable(&bcm->isr_tasklet);
                bcm43xx_interrupt_enable(bcm, savedirqs);
index bb9c484d7e195303414eba2df621cd55e503977a..af19a07032a3ed8ba59a6ff031b97f9dbae1b3d4 100644 (file)
@@ -1981,6 +1981,7 @@ void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm)
        }
        radio->enabled = 1;
        dprintk(KERN_INFO PFX "Radio turned on\n");
+       bcm43xx_leds_update(bcm, 0);
 }
        
 void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm)
@@ -2001,6 +2002,7 @@ void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm)
                bcm43xx_phy_write(bcm, 0x0015, 0xAA00);
        radio->enabled = 0;
        dprintk(KERN_INFO PFX "Radio turned off\n");
+       bcm43xx_leds_update(bcm, 0);
 }
 
 void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm)
index 9ed18039fa3e2f6ff0cc20157d609a72df769d3e..77a98a53a2e2f4e7c85a952135a0783cfd581205 100644 (file)
@@ -65,6 +65,22 @@ void bcm43xx_radio_init2060(struct bcm43xx_private *bcm);
 void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm);
 void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm);
 
+static inline
+int bcm43xx_is_hw_radio_enabled(struct bcm43xx_private *bcm)
+{
+       /* function to return state of hardware enable of radio
+        * returns 0 if radio disabled, 1 if radio enabled
+        */
+       if (bcm->current_core->rev >= 3)
+               return ((bcm43xx_read32(bcm, BCM43xx_MMIO_RADIO_HWENABLED_HI)
+                                       & BCM43xx_MMIO_RADIO_HWENABLED_HI_MASK)
+                                       == 0) ? 1 : 0;
+       else
+               return ((bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_HWENABLED_LO)
+                                       & BCM43xx_MMIO_RADIO_HWENABLED_LO_MASK)
+                                       == 0) ? 0 : 1;
+}
+
 int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm, u8 channel,
                                int synthetic_pu_workaround);
 
index 22cb3fb7502e280a16a4d5e73f95bb42482ead3a..c878a2f3239c1295a3b37e498c5ad5541f36da86 100644 (file)
@@ -9166,7 +9166,7 @@ static int ipw_wx_set_rts(struct net_device *dev,
 {
        struct ipw_priv *priv = ieee80211_priv(dev);
        mutex_lock(&priv->mutex);
-       if (wrqu->rts.disabled)
+       if (wrqu->rts.disabled || !wrqu->rts.fixed)
                priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
        else {
                if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
@@ -9255,7 +9255,7 @@ static int ipw_wx_set_frag(struct net_device *dev,
 {
        struct ipw_priv *priv = ieee80211_priv(dev);
        mutex_lock(&priv->mutex);
-       if (wrqu->frag.disabled)
+       if (wrqu->frag.disabled || !wrqu->frag.fixed)
                priv->ieee->fts = DEFAULT_FTS;
        else {
                if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
index 656f216b857f1149b4d1c5d11b81b60ce6c2bba7..4e7f6cf5143611d296ff1d9e6cfdf265d360f035 100644 (file)
@@ -2059,7 +2059,7 @@ static int determine_firmware(struct net_device *dev)
        int err;
        struct comp_id nic_id, sta_id;
        unsigned int firmver;
-       char tmp[SYMBOL_MAX_VER_LEN+1];
+       char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
 
        /* Get the hardware version */
        err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
index f057fd9fcd79edcf2288451ec21c51aa09ad3f6b..a037b11dac9da840645624cb5e28d165ecc76bcb 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/module.h>
 
 #include <linux/netdevice.h>
+#include <linux/ethtool.h>
 #include <linux/pci.h>
 #include <linux/etherdevice.h>
 #include <linux/delay.h>
@@ -787,6 +788,17 @@ islpci_set_multicast_list(struct net_device *dev)
 }
 #endif
 
+static void islpci_ethtool_get_drvinfo(struct net_device *dev,
+                                       struct ethtool_drvinfo *info)
+{
+       strcpy(info->driver, DRV_NAME);
+       strcpy(info->version, DRV_VERSION);
+}
+
+static struct ethtool_ops islpci_ethtool_ops = {
+       .get_drvinfo = islpci_ethtool_get_drvinfo,
+};
+
 struct net_device *
 islpci_setup(struct pci_dev *pdev)
 {
@@ -813,6 +825,7 @@ islpci_setup(struct pci_dev *pdev)
        ndev->do_ioctl = &prism54_ioctl;
        ndev->wireless_handlers =
            (struct iw_handler_def *) &prism54_handler_def;
+       ndev->ethtool_ops = &islpci_ethtool_ops;
 
        ndev->hard_start_xmit = &islpci_eth_transmit;
        /* ndev->set_multicast_list = &islpci_set_multicast_list; */
index a9aa1662eaa4c3be3cbd6c35a232f6d1fd490c45..736666da6c24344580c547ea708e3c24a65727f7 100644 (file)
@@ -211,4 +211,8 @@ islpci_trigger(islpci_private *priv)
 
 int islpci_free_memory(islpci_private *);
 struct net_device *islpci_setup(struct pci_dev *);
+
+#define DRV_NAME       "prism54"
+#define DRV_VERSION    "1.2"
+
 #endif                         /* _ISLPCI_DEV_H */
index 58257b40c043f5eb37eab5c110859af15a86d80e..3dcb13bb7d5782c089da59442a15e24cf3c49ba7 100644 (file)
@@ -28,9 +28,6 @@
 #include "islpci_mgt.h"                /* for pc_debug */
 #include "isl_oid.h"
 
-#define DRV_NAME       "prism54"
-#define DRV_VERSION    "1.2"
-
 MODULE_AUTHOR("[Intersil] R.Bastings and W.Termorshuizen, The prism54.org Development Team <prism54-devel@prism54.org>");
 MODULE_DESCRIPTION("The Prism54 802.11 Wireless LAN adapter");
 MODULE_LICENSE("GPL");
index 78ea72fb8f0ce9a3de74d6fd594442d90527ee4d..12dfc0b6efe6796b2f371b53a357e23dc1a558f6 100644 (file)
@@ -84,6 +84,18 @@ static void print_id(struct zd_chip *chip)
        dev_info(zd_chip_dev(chip), "%s\n", buffer);
 }
 
+static zd_addr_t inc_addr(zd_addr_t addr)
+{
+       u16 a = (u16)addr;
+       /* Control registers use byte addressing, but everything else uses word
+        * addressing. */
+       if ((a & 0xf000) == CR_START)
+               a += 2;
+       else
+               a += 1;
+       return (zd_addr_t)a;
+}
+
 /* Read a variable number of 32-bit values. Parameter count is not allowed to
  * exceed USB_MAX_IOREAD32_COUNT.
  */
@@ -114,7 +126,7 @@ int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr
        for (i = 0; i < count; i++) {
                int j = 2*i;
                /* We read the high word always first. */
-               a16[j] = zd_inc_word(addr[i]);
+               a16[j] = inc_addr(addr[i]);
                a16[j+1] = addr[i];
        }
 
@@ -163,7 +175,7 @@ int _zd_iowrite32v_locked(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs,
                j = 2*i;
                /* We write the high word always first. */
                ioreqs16[j].value   = ioreqs[i].value >> 16;
-               ioreqs16[j].addr    = zd_inc_word(ioreqs[i].addr);
+               ioreqs16[j].addr    = inc_addr(ioreqs[i].addr);
                ioreqs16[j+1].value = ioreqs[i].value;
                ioreqs16[j+1].addr  = ioreqs[i].addr;
        }
@@ -466,7 +478,8 @@ static int read_values(struct zd_chip *chip, u8 *values, size_t count,
 
        ZD_ASSERT(mutex_is_locked(&chip->mutex));
        for (i = 0;;) {
-               r = zd_ioread32_locked(chip, &v, e2p_addr+i/2);
+               r = zd_ioread32_locked(chip, &v,
+                                      (zd_addr_t)((u16)e2p_addr+i/2));
                if (r)
                        return r;
                v -= guard;
@@ -798,47 +811,18 @@ static int hw_reset_phy(struct zd_chip *chip)
 static int zd1211_hw_init_hmac(struct zd_chip *chip)
 {
        static const struct zd_ioreq32 ioreqs[] = {
-               { CR_ACK_TIMEOUT_EXT,           0x20 },
-               { CR_ADDA_MBIAS_WARMTIME,       0x30000808 },
                { CR_ZD1211_RETRY_MAX,          0x2 },
-               { CR_SNIFFER_ON,                0 },
-               { CR_RX_FILTER,                 STA_RX_FILTER },
-               { CR_GROUP_HASH_P1,             0x00 },
-               { CR_GROUP_HASH_P2,             0x80000000 },
-               { CR_REG1,                      0xa4 },
-               { CR_ADDA_PWR_DWN,              0x7f },
-               { CR_BCN_PLCP_CFG,              0x00f00401 },
-               { CR_PHY_DELAY,                 0x00 },
-               { CR_ACK_TIMEOUT_EXT,           0x80 },
-               { CR_ADDA_PWR_DWN,              0x00 },
-               { CR_ACK_TIME_80211,            0x100 },
-               { CR_RX_PE_DELAY,               0x70 },
-               { CR_PS_CTRL,                   0x10000000 },
-               { CR_RTS_CTS_RATE,              0x02030203 },
                { CR_RX_THRESHOLD,              0x000c0640 },
-               { CR_AFTER_PNP,                 0x1 },
-               { CR_WEP_PROTECT,               0x114 },
        };
 
-       int r;
-
        dev_dbg_f(zd_chip_dev(chip), "\n");
        ZD_ASSERT(mutex_is_locked(&chip->mutex));
-       r = zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
-#ifdef DEBUG
-       if (r) {
-               dev_err(zd_chip_dev(chip),
-                       "error in zd_iowrite32a_locked. Error number %d\n", r);
-       }
-#endif /* DEBUG */
-       return r;
+       return zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
 }
 
 static int zd1211b_hw_init_hmac(struct zd_chip *chip)
 {
        static const struct zd_ioreq32 ioreqs[] = {
-               { CR_ACK_TIMEOUT_EXT,           0x20 },
-               { CR_ADDA_MBIAS_WARMTIME,       0x30000808 },
                { CR_ZD1211B_RETRY_MAX,         0x02020202 },
                { CR_ZD1211B_TX_PWR_CTL4,       0x007f003f },
                { CR_ZD1211B_TX_PWR_CTL3,       0x007f003f },
@@ -847,6 +831,20 @@ static int zd1211b_hw_init_hmac(struct zd_chip *chip)
                { CR_ZD1211B_AIFS_CTL1,         0x00280028 },
                { CR_ZD1211B_AIFS_CTL2,         0x008C003C },
                { CR_ZD1211B_TXOP,              0x01800824 },
+               { CR_RX_THRESHOLD,              0x000c0eff, },
+       };
+
+       dev_dbg_f(zd_chip_dev(chip), "\n");
+       ZD_ASSERT(mutex_is_locked(&chip->mutex));
+       return zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
+}
+
+static int hw_init_hmac(struct zd_chip *chip)
+{
+       int r;
+       static const struct zd_ioreq32 ioreqs[] = {
+               { CR_ACK_TIMEOUT_EXT,           0x20 },
+               { CR_ADDA_MBIAS_WARMTIME,       0x30000808 },
                { CR_SNIFFER_ON,                0 },
                { CR_RX_FILTER,                 STA_RX_FILTER },
                { CR_GROUP_HASH_P1,             0x00 },
@@ -861,25 +859,16 @@ static int zd1211b_hw_init_hmac(struct zd_chip *chip)
                { CR_RX_PE_DELAY,               0x70 },
                { CR_PS_CTRL,                   0x10000000 },
                { CR_RTS_CTS_RATE,              0x02030203 },
-               { CR_RX_THRESHOLD,              0x000c0eff, },
                { CR_AFTER_PNP,                 0x1 },
                { CR_WEP_PROTECT,               0x114 },
+               { CR_IFS_VALUE,                 IFS_VALUE_DEFAULT },
        };
 
-       int r;
-
-       dev_dbg_f(zd_chip_dev(chip), "\n");
        ZD_ASSERT(mutex_is_locked(&chip->mutex));
        r = zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
-       if (r) {
-               dev_dbg_f(zd_chip_dev(chip),
-                       "error in zd_iowrite32a_locked. Error number %d\n", r);
-       }
-       return r;
-}
+       if (r)
+               return r;
 
-static int hw_init_hmac(struct zd_chip *chip)
-{
        return chip->is_zd1211b ?
                zd1211b_hw_init_hmac(chip) : zd1211_hw_init_hmac(chip);
 }
@@ -974,16 +963,14 @@ static int hw_init(struct zd_chip *chip)
        if (r)
                return r;
 
-       /* Although the vendor driver defaults to a different value during
-        * init, it overwrites the IFS value with the following every time
-        * the channel changes. We should aim to be more intelligent... */
-       r = zd_iowrite32_locked(chip, IFS_VALUE_DEFAULT, CR_IFS_VALUE);
-       if (r)
-               return r;
-
        return set_beacon_interval(chip, 100);
 }
 
+static zd_addr_t fw_reg_addr(struct zd_chip *chip, u16 offset)
+{
+       return (zd_addr_t)((u16)chip->fw_regs_base + offset);
+}
+
 #ifdef DEBUG
 static int dump_cr(struct zd_chip *chip, const zd_addr_t addr,
                   const char *addr_string)
@@ -1018,9 +1005,11 @@ static int test_init(struct zd_chip *chip)
 
 static void dump_fw_registers(struct zd_chip *chip)
 {
-       static const zd_addr_t addr[4] = {
-               FW_FIRMWARE_VER, FW_USB_SPEED, FW_FIX_TX_RATE,
-               FW_LINK_STATUS
+       const zd_addr_t addr[4] = {
+               fw_reg_addr(chip, FW_REG_FIRMWARE_VER),
+               fw_reg_addr(chip, FW_REG_USB_SPEED),
+               fw_reg_addr(chip, FW_REG_FIX_TX_RATE),
+               fw_reg_addr(chip, FW_REG_LED_LINK_STATUS),
        };
 
        int r;
@@ -1046,7 +1035,8 @@ static int print_fw_version(struct zd_chip *chip)
        int r;
        u16 version;
 
-       r = zd_ioread16_locked(chip, &version, FW_FIRMWARE_VER);
+       r = zd_ioread16_locked(chip, &version,
+               fw_reg_addr(chip, FW_REG_FIRMWARE_VER));
        if (r)
                return r;
 
@@ -1126,6 +1116,22 @@ int zd_chip_disable_hwint(struct zd_chip *chip)
        return r;
 }
 
+static int read_fw_regs_offset(struct zd_chip *chip)
+{
+       int r;
+
+       ZD_ASSERT(mutex_is_locked(&chip->mutex));
+       r = zd_ioread16_locked(chip, (u16*)&chip->fw_regs_base,
+                              FWRAW_REGS_ADDR);
+       if (r)
+               return r;
+       dev_dbg_f(zd_chip_dev(chip), "fw_regs_base: %#06hx\n",
+                 (u16)chip->fw_regs_base);
+
+       return 0;
+}
+
+
 int zd_chip_init_hw(struct zd_chip *chip, u8 device_type)
 {
        int r;
@@ -1145,7 +1151,7 @@ int zd_chip_init_hw(struct zd_chip *chip, u8 device_type)
        if (r)
                goto out;
 
-       r = zd_usb_init_hw(&chip->usb);
+       r = read_fw_regs_offset(chip);
        if (r)
                goto out;
 
@@ -1325,15 +1331,15 @@ u8 zd_chip_get_channel(struct zd_chip *chip)
 
 int zd_chip_control_leds(struct zd_chip *chip, enum led_status status)
 {
-       static const zd_addr_t a[] = {
-               FW_LINK_STATUS,
+       const zd_addr_t a[] = {
+               fw_reg_addr(chip, FW_REG_LED_LINK_STATUS),
                CR_LED,
        };
 
        int r;
        u16 v[ARRAY_SIZE(a)];
        struct zd_ioreq16 ioreqs[ARRAY_SIZE(a)] = {
-               [0] = { FW_LINK_STATUS },
+               [0] = { fw_reg_addr(chip, FW_REG_LED_LINK_STATUS) },
                [1] = { CR_LED },
        };
        u16 other_led;
index a4e3cee9b59d2f94b604f358535cc54dcb8ebe15..b07569e391ee2e4d16ccbd7f2434fa1a2e6dd491 100644 (file)
@@ -18,7 +18,6 @@
 #ifndef _ZD_CHIP_H
 #define _ZD_CHIP_H
 
-#include "zd_types.h"
 #include "zd_rf.h"
 #include "zd_usb.h"
 
  * adds a processor for handling the USB protocol.
  */
 
+/* Address space */
+enum {
+       /* CONTROL REGISTERS */
+       CR_START                        = 0x9000,
+
+
+       /* FIRMWARE */
+       FW_START                        = 0xee00,
+
+
+       /* EEPROM */
+       E2P_START                       = 0xf800,
+       E2P_LEN                         = 0x800,
+
+       /* EEPROM layout */
+       E2P_LOAD_CODE_LEN               = 0xe,          /* base 0xf800 */
+       E2P_LOAD_VECT_LEN               = 0x9,          /* base 0xf80e */
+       /* E2P_DATA indexes into this */
+       E2P_DATA_LEN                    = 0x7e,         /* base 0xf817 */
+       E2P_BOOT_CODE_LEN               = 0x760,        /* base 0xf895 */
+       E2P_INTR_VECT_LEN               = 0xb,          /* base 0xfff5 */
+
+       /* Some precomputed offsets into the EEPROM */
+       E2P_DATA_OFFSET                 = E2P_LOAD_CODE_LEN + E2P_LOAD_VECT_LEN,
+       E2P_BOOT_CODE_OFFSET            = E2P_DATA_OFFSET + E2P_DATA_LEN,
+};
+
+#define CTL_REG(offset) ((zd_addr_t)(CR_START + (offset)))
+#define E2P_DATA(offset) ((zd_addr_t)(E2P_START + E2P_DATA_OFFSET + (offset)))
+#define FWRAW_DATA(offset) ((zd_addr_t)(FW_START + (offset)))
+
 /* 8-bit hardware registers */
 #define CR0   CTL_REG(0x0000)
 #define CR1   CTL_REG(0x0004)
 
 #define CR_MAX_PHY_REG 255
 
-/* Taken from the ZYDAS driver, not all of them are relevant for the ZSD1211
+/* Taken from the ZYDAS driver, not all of them are relevant for the ZD1211
  * driver.
  */
 
 /*
  * Upper 16 bit contains the regulatory domain.
  */
-#define E2P_SUBID              E2P_REG(0x00)
-#define E2P_POD                        E2P_REG(0x02)
-#define E2P_MAC_ADDR_P1                E2P_REG(0x04)
-#define E2P_MAC_ADDR_P2                E2P_REG(0x06)
-#define E2P_PWR_CAL_VALUE1     E2P_REG(0x08)
-#define E2P_PWR_CAL_VALUE2     E2P_REG(0x0a)
-#define E2P_PWR_CAL_VALUE3     E2P_REG(0x0c)
-#define E2P_PWR_CAL_VALUE4      E2P_REG(0x0e)
-#define E2P_PWR_INT_VALUE1     E2P_REG(0x10)
-#define E2P_PWR_INT_VALUE2     E2P_REG(0x12)
-#define E2P_PWR_INT_VALUE3     E2P_REG(0x14)
-#define E2P_PWR_INT_VALUE4     E2P_REG(0x16)
+#define E2P_SUBID              E2P_DATA(0x00)
+#define E2P_POD                        E2P_DATA(0x02)
+#define E2P_MAC_ADDR_P1                E2P_DATA(0x04)
+#define E2P_MAC_ADDR_P2                E2P_DATA(0x06)
+#define E2P_PWR_CAL_VALUE1     E2P_DATA(0x08)
+#define E2P_PWR_CAL_VALUE2     E2P_DATA(0x0a)
+#define E2P_PWR_CAL_VALUE3     E2P_DATA(0x0c)
+#define E2P_PWR_CAL_VALUE4      E2P_DATA(0x0e)
+#define E2P_PWR_INT_VALUE1     E2P_DATA(0x10)
+#define E2P_PWR_INT_VALUE2     E2P_DATA(0x12)
+#define E2P_PWR_INT_VALUE3     E2P_DATA(0x14)
+#define E2P_PWR_INT_VALUE4     E2P_DATA(0x16)
 
 /* Contains a bit for each allowed channel. It gives for Europe (ETSI 0x30)
  * also only 11 channels. */
-#define E2P_ALLOWED_CHANNEL    E2P_REG(0x18)
-
-#define E2P_PHY_REG            E2P_REG(0x1a)
-#define E2P_DEVICE_VER         E2P_REG(0x20)
-#define E2P_36M_CAL_VALUE1     E2P_REG(0x28)
-#define E2P_36M_CAL_VALUE2      E2P_REG(0x2a)
-#define E2P_36M_CAL_VALUE3      E2P_REG(0x2c)
-#define E2P_36M_CAL_VALUE4     E2P_REG(0x2e)
-#define E2P_11A_INT_VALUE1     E2P_REG(0x30)
-#define E2P_11A_INT_VALUE2     E2P_REG(0x32)
-#define E2P_11A_INT_VALUE3     E2P_REG(0x34)
-#define E2P_11A_INT_VALUE4     E2P_REG(0x36)
-#define E2P_48M_CAL_VALUE1     E2P_REG(0x38)
-#define E2P_48M_CAL_VALUE2     E2P_REG(0x3a)
-#define E2P_48M_CAL_VALUE3     E2P_REG(0x3c)
-#define E2P_48M_CAL_VALUE4     E2P_REG(0x3e)
-#define E2P_48M_INT_VALUE1     E2P_REG(0x40)
-#define E2P_48M_INT_VALUE2     E2P_REG(0x42)
-#define E2P_48M_INT_VALUE3     E2P_REG(0x44)
-#define E2P_48M_INT_VALUE4     E2P_REG(0x46)
-#define E2P_54M_CAL_VALUE1     E2P_REG(0x48)   /* ??? */
-#define E2P_54M_CAL_VALUE2     E2P_REG(0x4a)
-#define E2P_54M_CAL_VALUE3     E2P_REG(0x4c)
-#define E2P_54M_CAL_VALUE4     E2P_REG(0x4e)
-#define E2P_54M_INT_VALUE1     E2P_REG(0x50)
-#define E2P_54M_INT_VALUE2     E2P_REG(0x52)
-#define E2P_54M_INT_VALUE3     E2P_REG(0x54)
-#define E2P_54M_INT_VALUE4     E2P_REG(0x56)
-
-/* All 16 bit values */
-#define FW_FIRMWARE_VER         FW_REG(0)
-/* non-zero if USB high speed connection */
-#define FW_USB_SPEED            FW_REG(1)
-#define FW_FIX_TX_RATE          FW_REG(2)
-/* Seems to be able to control LEDs over the firmware */
-#define FW_LINK_STATUS          FW_REG(3)
-#define FW_SOFT_RESET           FW_REG(4)
-#define FW_FLASH_CHK            FW_REG(5)
+#define E2P_ALLOWED_CHANNEL    E2P_DATA(0x18)
+
+#define E2P_PHY_REG            E2P_DATA(0x1a)
+#define E2P_DEVICE_VER         E2P_DATA(0x20)
+#define E2P_36M_CAL_VALUE1     E2P_DATA(0x28)
+#define E2P_36M_CAL_VALUE2      E2P_DATA(0x2a)
+#define E2P_36M_CAL_VALUE3      E2P_DATA(0x2c)
+#define E2P_36M_CAL_VALUE4     E2P_DATA(0x2e)
+#define E2P_11A_INT_VALUE1     E2P_DATA(0x30)
+#define E2P_11A_INT_VALUE2     E2P_DATA(0x32)
+#define E2P_11A_INT_VALUE3     E2P_DATA(0x34)
+#define E2P_11A_INT_VALUE4     E2P_DATA(0x36)
+#define E2P_48M_CAL_VALUE1     E2P_DATA(0x38)
+#define E2P_48M_CAL_VALUE2     E2P_DATA(0x3a)
+#define E2P_48M_CAL_VALUE3     E2P_DATA(0x3c)
+#define E2P_48M_CAL_VALUE4     E2P_DATA(0x3e)
+#define E2P_48M_INT_VALUE1     E2P_DATA(0x40)
+#define E2P_48M_INT_VALUE2     E2P_DATA(0x42)
+#define E2P_48M_INT_VALUE3     E2P_DATA(0x44)
+#define E2P_48M_INT_VALUE4     E2P_DATA(0x46)
+#define E2P_54M_CAL_VALUE1     E2P_DATA(0x48)  /* ??? */
+#define E2P_54M_CAL_VALUE2     E2P_DATA(0x4a)
+#define E2P_54M_CAL_VALUE3     E2P_DATA(0x4c)
+#define E2P_54M_CAL_VALUE4     E2P_DATA(0x4e)
+#define E2P_54M_INT_VALUE1     E2P_DATA(0x50)
+#define E2P_54M_INT_VALUE2     E2P_DATA(0x52)
+#define E2P_54M_INT_VALUE3     E2P_DATA(0x54)
+#define E2P_54M_INT_VALUE4     E2P_DATA(0x56)
+
+/* This word contains the base address of the FW_REG_ registers below */
+#define FWRAW_REGS_ADDR                FWRAW_DATA(0x1d)
+
+/* All 16 bit values, offset from the address in FWRAW_REGS_ADDR */
+enum {
+       FW_REG_FIRMWARE_VER     = 0,
+       /* non-zero if USB high speed connection */
+       FW_REG_USB_SPEED        = 1,
+       FW_REG_FIX_TX_RATE      = 2,
+       /* Seems to be able to control LEDs over the firmware */
+       FW_REG_LED_LINK_STATUS  = 3,
+       FW_REG_SOFT_RESET       = 4,
+       FW_REG_FLASH_CHK        = 5,
+};
 
+/* Values for FW_LINK_STATUS */
 #define FW_LINK_OFF            0x0
 #define FW_LINK_TX             0x1
 /* 0x2 - link led on? */
 
-enum {
-       CR_BASE_OFFSET                  = 0x9000,
-       FW_START_OFFSET                 = 0xee00,
-       FW_BASE_ADDR_OFFSET             = FW_START_OFFSET + 0x1d,
-       EEPROM_START_OFFSET             = 0xf800,
-       EEPROM_SIZE                     = 0x800, /* words */
-       LOAD_CODE_SIZE                  = 0xe, /* words */
-       LOAD_VECT_SIZE                  = 0x10000 - 0xfff7, /* words */
-       EEPROM_REGS_OFFSET              = LOAD_CODE_SIZE + LOAD_VECT_SIZE,
-       EEPROM_REGS_SIZE                = 0x7e, /* words */
-       E2P_BASE_OFFSET                 = EEPROM_START_OFFSET +
-                                         EEPROM_REGS_OFFSET,
-};
-
-#define FW_REG_TABLE_ADDR      USB_ADDR(FW_START_OFFSET + 0x1d)
-
 enum {
        /* indices for ofdm_cal_values */
        OFDM_36M_INDEX = 0,
@@ -679,6 +699,8 @@ struct zd_chip {
        struct zd_usb usb;
        struct zd_rf rf;
        struct mutex mutex;
+       /* Base address of FW_REG_ registers */
+       zd_addr_t fw_regs_base;
        u8 e2p_mac[ETH_ALEN];
        /* EepSetPoint in the vendor driver */
        u8 pwr_cal_values[E2P_CHANNEL_COUNT];
index fb22f62cf1f3d5238e3a0526fd355c1de01a17fb..deb99d1eaa77941fb5594635fde5fdb4b5976663 100644 (file)
@@ -23,6 +23,8 @@
 #include <linux/device.h>
 #include <linux/kernel.h>
 
+typedef u16 __nocast zd_addr_t;
+
 #define dev_printk_f(level, dev, fmt, args...) \
        dev_printk(level, dev, "%s() " fmt, __func__, ##args)
 
index 26b8298dff8cf685290cc727edd12684e2c2ef33..c4f36d39642b1bdeccf8106415da7a337448acf9 100644 (file)
@@ -2,7 +2,6 @@
 #define _ZD_IEEE80211_H
 
 #include <net/ieee80211.h>
-#include "zd_types.h"
 
 /* Additional definitions from the standards.
  */
index 676b3734f1edd96e673a4aa7efbbd9269d0c78e5..a57732eb69e1ca136f2974685f5e56d3e6903734 100644 (file)
@@ -18,8 +18,6 @@
 #ifndef _ZD_RF_H
 #define _ZD_RF_H
 
-#include "zd_types.h"
-
 #define UW2451_RF                      0x2
 #define UCHIP_RF                       0x3
 #define AL2230_RF                      0x4
diff --git a/drivers/net/wireless/zd1211rw/zd_types.h b/drivers/net/wireless/zd1211rw/zd_types.h
deleted file mode 100644 (file)
index 0155a15..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/* zd_types.h
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef _ZD_TYPES_H
-#define _ZD_TYPES_H
-
-#include <linux/types.h>
-
-/* We have three register spaces mapped into the overall USB address space of
- * 64K words (16-bit values). There is the control register space of
- * double-word registers, the eeprom register space and the firmware register
- * space. The control register space is byte mapped, the others are word
- * mapped.
- *
- * For that reason, we are using byte offsets for control registers and word
- * offsets for everything else.
- */
-
-typedef u32 __nocast zd_addr_t;
-
-enum {
-       ADDR_BASE_MASK          = 0xff000000,
-       ADDR_OFFSET_MASK        = 0x0000ffff,
-       ADDR_ZERO_MASK          = 0x00ff0000,
-       NULL_BASE               = 0x00000000,
-       USB_BASE                = 0x01000000,
-       CR_BASE                 = 0x02000000,
-       CR_MAX_OFFSET           = 0x0b30,
-       E2P_BASE                = 0x03000000,
-       E2P_MAX_OFFSET          = 0x007e,
-       FW_BASE                 = 0x04000000,
-       FW_MAX_OFFSET           = 0x0005,
-};
-
-#define ZD_ADDR_BASE(addr) ((u32)(addr) & ADDR_BASE_MASK)
-#define ZD_OFFSET(addr) ((u32)(addr) & ADDR_OFFSET_MASK)
-
-#define ZD_ADDR(base, offset) \
-       ((zd_addr_t)(((base) & ADDR_BASE_MASK) | ((offset) & ADDR_OFFSET_MASK)))
-
-#define ZD_NULL_ADDR    ((zd_addr_t)0)
-#define USB_REG(offset)  ZD_ADDR(USB_BASE, offset)     /* word addressing */
-#define CTL_REG(offset)  ZD_ADDR(CR_BASE, offset)      /* byte addressing */
-#define E2P_REG(offset)  ZD_ADDR(E2P_BASE, offset)     /* word addressing */
-#define FW_REG(offset)   ZD_ADDR(FW_BASE, offset)      /* word addressing */
-
-static inline zd_addr_t zd_inc_word(zd_addr_t addr)
-{
-       u32 base = ZD_ADDR_BASE(addr);
-       u32 offset = ZD_OFFSET(addr);
-
-       offset += base == CR_BASE ? 2 : 1;
-
-       return base | offset;
-}
-
-#endif /* _ZD_TYPES_H */
index 605e96e740576cf0d871181460dfc405efcc0835..75ef55624d7fd2cf15820e79127beff3e6e393dd 100644 (file)
@@ -58,6 +58,10 @@ static struct usb_device_id usb_ids[] = {
        { USB_DEVICE(0x079b, 0x0062), .driver_info = DEVICE_ZD1211B },
        { USB_DEVICE(0x1582, 0x6003), .driver_info = DEVICE_ZD1211B },
        { USB_DEVICE(0x050d, 0x705c), .driver_info = DEVICE_ZD1211B },
+       { USB_DEVICE(0x083a, 0x4505), .driver_info = DEVICE_ZD1211B },
+       { USB_DEVICE(0x0471, 0x1236), .driver_info = DEVICE_ZD1211B },
+       { USB_DEVICE(0x13b1, 0x0024), .driver_info = DEVICE_ZD1211B },
+       { USB_DEVICE(0x0586, 0x340f), .driver_info = DEVICE_ZD1211B },
        /* "Driverless" devices that need ejecting */
        { USB_DEVICE(0x0ace, 0x2011), .driver_info = DEVICE_INSTALLER },
        {}
@@ -73,96 +77,6 @@ MODULE_DEVICE_TABLE(usb, usb_ids);
 #define FW_ZD1211_PREFIX       "zd1211/zd1211_"
 #define FW_ZD1211B_PREFIX      "zd1211/zd1211b_"
 
-/* register address handling */
-
-#ifdef DEBUG
-static int check_addr(struct zd_usb *usb, zd_addr_t addr)
-{
-       u32 base = ZD_ADDR_BASE(addr);
-       u32 offset = ZD_OFFSET(addr);
-
-       if ((u32)addr & ADDR_ZERO_MASK)
-               goto invalid_address;
-       switch (base) {
-       case USB_BASE:
-               break;
-       case CR_BASE:
-               if (offset > CR_MAX_OFFSET) {
-                       dev_dbg(zd_usb_dev(usb),
-                               "CR offset %#010x larger than"
-                               " CR_MAX_OFFSET %#10x\n",
-                               offset, CR_MAX_OFFSET);
-                       goto invalid_address;
-               }
-               if (offset & 1) {
-                       dev_dbg(zd_usb_dev(usb),
-                               "CR offset %#010x is not a multiple of 2\n",
-                               offset);
-                       goto invalid_address;
-               }
-               break;
-       case E2P_BASE:
-               if (offset > E2P_MAX_OFFSET) {
-                       dev_dbg(zd_usb_dev(usb),
-                               "E2P offset %#010x larger than"
-                               " E2P_MAX_OFFSET %#010x\n",
-                               offset, E2P_MAX_OFFSET);
-                       goto invalid_address;
-               }
-               break;
-       case FW_BASE:
-               if (!usb->fw_base_offset) {
-                       dev_dbg(zd_usb_dev(usb),
-                              "ERROR: fw base offset has not been set\n");
-                       return -EAGAIN;
-               }
-               if (offset > FW_MAX_OFFSET) {
-                       dev_dbg(zd_usb_dev(usb),
-                               "FW offset %#10x is larger than"
-                               " FW_MAX_OFFSET %#010x\n",
-                               offset, FW_MAX_OFFSET);
-                       goto invalid_address;
-               }
-               break;
-       default:
-               dev_dbg(zd_usb_dev(usb),
-                       "address has unsupported base %#010x\n", addr);
-               goto invalid_address;
-       }
-
-       return 0;
-invalid_address:
-       dev_dbg(zd_usb_dev(usb),
-               "ERROR: invalid address: %#010x\n", addr);
-       return -EINVAL;
-}
-#endif /* DEBUG */
-
-static u16 usb_addr(struct zd_usb *usb, zd_addr_t addr)
-{
-       u32 base;
-       u16 offset;
-
-       base = ZD_ADDR_BASE(addr);
-       offset = ZD_OFFSET(addr);
-
-       ZD_ASSERT(check_addr(usb, addr) == 0);
-
-       switch (base) {
-       case CR_BASE:
-               offset += CR_BASE_OFFSET;
-               break;
-       case E2P_BASE:
-               offset += E2P_BASE_OFFSET;
-               break;
-       case FW_BASE:
-               offset += usb->fw_base_offset;
-               break;
-       }
-
-       return offset;
-}
-
 /* USB device initialization */
 
 static int request_fw_file(
@@ -295,14 +209,13 @@ static int handle_version_mismatch(struct usb_device *udev, u8 device_type,
        if (r)
                goto error;
 
-       r = upload_code(udev, ur_fw->data, ur_fw->size, FW_START_OFFSET,
-               REBOOT);
+       r = upload_code(udev, ur_fw->data, ur_fw->size, FW_START, REBOOT);
        if (r)
                goto error;
 
-       offset = ((EEPROM_REGS_OFFSET + EEPROM_REGS_SIZE) * sizeof(u16));
+       offset = (E2P_BOOT_CODE_OFFSET * sizeof(u16));
        r = upload_code(udev, ub_fw->data + offset, ub_fw->size - offset,
-               E2P_BASE_OFFSET + EEPROM_REGS_SIZE, REBOOT);
+               E2P_START + E2P_BOOT_CODE_OFFSET, REBOOT);
 
        /* At this point, the vendor driver downloads the whole firmware
         * image, hacks around with version IDs, and uploads it again,
@@ -331,7 +244,7 @@ static int upload_firmware(struct usb_device *udev, u8 device_type)
        if (r)
                goto error;
 
-       fw_bcdDevice = get_word(ub_fw->data, EEPROM_REGS_OFFSET);
+       fw_bcdDevice = get_word(ub_fw->data, E2P_DATA_OFFSET);
 
        if (fw_bcdDevice != bcdDevice) {
                dev_info(&udev->dev,
@@ -357,8 +270,7 @@ static int upload_firmware(struct usb_device *udev, u8 device_type)
        if (r)
                goto error;
 
-       r = upload_code(udev, uph_fw->data, uph_fw->size, FW_START_OFFSET,
-                       REBOOT);
+       r = upload_code(udev, uph_fw->data, uph_fw->size, FW_START, REBOOT);
        if (r) {
                dev_err(&udev->dev,
                        "Could not upload firmware code uph. Error number %d\n",
@@ -858,7 +770,7 @@ static inline void init_usb_interrupt(struct zd_usb *usb)
        spin_lock_init(&intr->lock);
        intr->interval = int_urb_interval(zd_usb_to_usbdev(usb));
        init_completion(&intr->read_regs.completion);
-       intr->read_regs.cr_int_addr = cpu_to_le16(usb_addr(usb, CR_INTERRUPT));
+       intr->read_regs.cr_int_addr = cpu_to_le16((u16)CR_INTERRUPT);
 }
 
 static inline void init_usb_rx(struct zd_usb *usb)
@@ -890,22 +802,6 @@ void zd_usb_init(struct zd_usb *usb, struct net_device *netdev,
        init_usb_rx(usb);
 }
 
-int zd_usb_init_hw(struct zd_usb *usb)
-{
-       int r;
-       struct zd_chip *chip = zd_usb_to_chip(usb);
-
-       ZD_ASSERT(mutex_is_locked(&chip->mutex));
-       r = zd_ioread16_locked(chip, &usb->fw_base_offset,
-                       USB_REG((u16)FW_BASE_ADDR_OFFSET));
-       if (r)
-               return r;
-       dev_dbg_f(zd_usb_dev(usb), "fw_base_offset: %#06hx\n",
-                usb->fw_base_offset);
-
-       return 0;
-}
-
 void zd_usb_clear(struct zd_usb *usb)
 {
        usb_set_intfdata(usb->intf, NULL);
@@ -1253,7 +1149,7 @@ int zd_usb_ioread16v(struct zd_usb *usb, u16 *values,
                return -ENOMEM;
        req->id = cpu_to_le16(USB_REQ_READ_REGS);
        for (i = 0; i < count; i++)
-               req->addr[i] = cpu_to_le16(usb_addr(usb, addresses[i]));
+               req->addr[i] = cpu_to_le16((u16)addresses[i]);
 
        udev = zd_usb_to_usbdev(usb);
        prepare_read_regs_int(usb);
@@ -1318,7 +1214,7 @@ int zd_usb_iowrite16v(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs,
        req->id = cpu_to_le16(USB_REQ_WRITE_REGS);
        for (i = 0; i < count; i++) {
                struct reg_data *rw  = &req->reg_writes[i];
-               rw->addr = cpu_to_le16(usb_addr(usb, ioreqs[i].addr));
+               rw->addr = cpu_to_le16((u16)ioreqs[i].addr);
                rw->value = cpu_to_le16(ioreqs[i].value);
        }
 
index 317d37c36679052b16609f9e8f2972e4ff8ac810..506ea6a74393958f6ef874fe205fbcea60b01f1a 100644 (file)
@@ -25,7 +25,6 @@
 #include <linux/usb.h>
 
 #include "zd_def.h"
-#include "zd_types.h"
 
 enum devicetype {
        DEVICE_ZD1211  = 0,
@@ -181,15 +180,14 @@ struct zd_usb_tx {
        spinlock_t lock;
 };
 
-/* Contains the usb parts. The structure doesn't require a lock, because intf
- * and fw_base_offset, will not be changed after initialization.
+/* Contains the usb parts. The structure doesn't require a lock because intf
+ * will not be changed after initialization.
  */
 struct zd_usb {
        struct zd_usb_interrupt intr;
        struct zd_usb_rx rx;
        struct zd_usb_tx tx;
        struct usb_interface *intf;
-       u16 fw_base_offset;
 };
 
 #define zd_usb_dev(usb) (&usb->intf->dev)
index bd1faebf61a05fd10bfe1b299e152467ba959db6..fca978fb158e22e5313ebf8564faf09ee6bae160 100644 (file)
@@ -773,13 +773,13 @@ static int get_gsi_base(acpi_handle handle, u32 *gsi_base)
                goto out;
 
        table = obj->buffer.pointer;
-       switch (((acpi_table_entry_header *)table)->type) {
-       case ACPI_MADT_IOSAPIC:
-               *gsi_base = ((struct acpi_table_iosapic *)table)->global_irq_base;
+       switch (((struct acpi_subtable_header *)table)->type) {
+       case ACPI_MADT_TYPE_IO_SAPIC:
+               *gsi_base = ((struct acpi_madt_io_sapic *)table)->global_irq_base;
                result = 0;
                break;
-       case ACPI_MADT_IOAPIC:
-               *gsi_base = ((struct acpi_table_ioapic *)table)->global_irq_base;
+       case ACPI_MADT_TYPE_IO_APIC:
+               *gsi_base = ((struct acpi_madt_io_apic *)table)->global_irq_base;
                result = 0;
                break;
        default:
index 5d188c558386b73aadd714c21cc9e305483c0d44..78cf0711d1fadd5bd670425a4e7ce732748795c2 100644 (file)
@@ -28,6 +28,8 @@
 #include <asm/sn/sn_feature_sets.h>
 #include <asm/sn/sn_sal.h>
 #include <asm/sn/types.h>
+#include <linux/acpi.h>
+#include <asm/sn/acpi.h>
 
 #include "../pci.h"
 
@@ -35,14 +37,17 @@ MODULE_LICENSE("GPL");
 MODULE_AUTHOR("SGI (prarit@sgi.com, dickie@sgi.com, habeck@sgi.com)");
 MODULE_DESCRIPTION("SGI Altix Hot Plug PCI Controller Driver");
 
-#define PCIIO_ASIC_TYPE_TIOCA          4
+
+/* SAL call error codes. Keep in sync with prom header io/include/pcibr.h */
 #define PCI_SLOT_ALREADY_UP            2       /* slot already up */
 #define PCI_SLOT_ALREADY_DOWN          3       /* slot already down */
 #define PCI_L1_ERR                     7       /* L1 console command error */
 #define PCI_EMPTY_33MHZ                        15      /* empty 33 MHz bus */
+
+
+#define PCIIO_ASIC_TYPE_TIOCA          4
 #define PCI_L1_QSIZE                   128     /* our L1 message buffer size */
 #define SN_MAX_HP_SLOTS                        32      /* max hotplug slots */
-#define SGI_HOTPLUG_PROM_REV           0x0430  /* Min. required PROM version */
 #define SN_SLOT_NAME_SIZE              33      /* size of name string */
 
 /* internal list head */
@@ -227,7 +232,7 @@ static void sn_bus_free_data(struct pci_dev *dev)
 }
 
 static int sn_slot_enable(struct hotplug_slot *bss_hotplug_slot,
-                         int device_num)
+                         int device_num, char **ssdt)
 {
        struct slot *slot = bss_hotplug_slot->private;
        struct pcibus_info *pcibus_info;
@@ -240,7 +245,8 @@ static int sn_slot_enable(struct hotplug_slot *bss_hotplug_slot,
         * Power-on and initialize the slot in the SN
         * PCI infrastructure.
         */
-       rc = sal_pcibr_slot_enable(pcibus_info, device_num, &resp);
+       rc = sal_pcibr_slot_enable(pcibus_info, device_num, &resp, ssdt);
+
 
        if (rc == PCI_SLOT_ALREADY_UP) {
                dev_dbg(slot->pci_bus->self, "is already active\n");
@@ -335,6 +341,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
        int func, num_funcs;
        int new_ppb = 0;
        int rc;
+       char *ssdt = NULL;
        void pcibios_fixup_device_resources(struct pci_dev *);
 
        /* Serialize the Linux PCI infrastructure */
@@ -342,14 +349,29 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
 
        /*
         * Power-on and initialize the slot in the SN
-        * PCI infrastructure.
+        * PCI infrastructure. Also, retrieve the ACPI SSDT
+        * table for the slot (if ACPI capable PROM).
         */
-       rc = sn_slot_enable(bss_hotplug_slot, slot->device_num);
+       rc = sn_slot_enable(bss_hotplug_slot, slot->device_num, &ssdt);
        if (rc) {
                mutex_unlock(&sn_hotplug_mutex);
                return rc;
        }
 
+       if (ssdt)
+               ssdt = __va(ssdt);
+       /* Add the new SSDT for the slot to the ACPI namespace */
+       if (SN_ACPI_BASE_SUPPORT() && ssdt) {
+               acpi_status ret;
+
+               ret = acpi_load_table((struct acpi_table_header *)ssdt);
+               if (ACPI_FAILURE(ret)) {
+                       printk(KERN_ERR "%s: acpi_load_table failed (0x%x)\n",
+                              __FUNCTION__, ret);
+                       /* try to continue on */
+               }
+       }
+
        num_funcs = pci_scan_slot(slot->pci_bus,
                                  PCI_DEVFN(slot->device_num + 1, 0));
        if (!num_funcs) {
@@ -374,7 +396,10 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
                         * pdi_host_pcidev_info).
                         */
                        pcibios_fixup_device_resources(dev);
-                       sn_pci_fixup_slot(dev);
+                       if (SN_ACPI_BASE_SUPPORT())
+                               sn_acpi_slot_fixup(dev);
+                       else
+                               sn_io_slot_fixup(dev);
                        if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
                                unsigned char sec_bus;
                                pci_read_config_byte(dev, PCI_SECONDARY_BUS,
@@ -388,6 +413,63 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
                }
        }
 
+       /*
+        * Add the slot's devices to the ACPI infrastructure */
+       if (SN_ACPI_BASE_SUPPORT() && ssdt) {
+               unsigned long adr;
+               struct acpi_device *pdevice;
+               struct acpi_device *device;
+               acpi_handle phandle;
+               acpi_handle chandle = NULL;
+               acpi_handle rethandle;
+               acpi_status ret;
+
+               phandle = PCI_CONTROLLER(slot->pci_bus)->acpi_handle;
+
+               if (acpi_bus_get_device(phandle, &pdevice)) {
+                       dev_dbg(slot->pci_bus->self,
+                               "no parent device, assuming NULL\n");
+                       pdevice = NULL;
+               }
+
+               /*
+                * Walk the rootbus node's immediate children looking for
+                * the slot's device node(s). There can be more than
+                * one for multifunction devices.
+                */
+               for (;;) {
+                       rethandle = NULL;
+                       ret = acpi_get_next_object(ACPI_TYPE_DEVICE,
+                                                  phandle, chandle,
+                                                  &rethandle);
+
+                       if (ret == AE_NOT_FOUND || rethandle == NULL)
+                               break;
+
+                       chandle = rethandle;
+
+                       ret = acpi_evaluate_integer(chandle, METHOD_NAME__ADR,
+                                                   NULL, &adr);
+
+                       if (ACPI_SUCCESS(ret) &&
+                           (adr>>16) == (slot->device_num + 1)) {
+
+                               ret = acpi_bus_add(&device, pdevice, chandle,
+                                                  ACPI_BUS_TYPE_DEVICE);
+                               if (ACPI_FAILURE(ret)) {
+                                       printk(KERN_ERR "%s: acpi_bus_add "
+                                              "failed (0x%x) for slot %d "
+                                              "func %d\n", __FUNCTION__,
+                                              ret, (int)(adr>>16),
+                                              (int)(adr&0xffff));
+                                       /* try to continue on */
+                               } else {
+                                       acpi_bus_start(device);
+                               }
+                       }
+               }
+       }
+
        /* Call the driver for the new device */
        pci_bus_add_devices(slot->pci_bus);
        /* Call the drivers for the new devices subordinate to PPB */
@@ -412,6 +494,7 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
        struct pci_dev *dev;
        int func;
        int rc;
+       acpi_owner_id ssdt_id = 0;
 
        /* Acquire update access to the bus */
        mutex_lock(&sn_hotplug_mutex);
@@ -422,6 +505,52 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
        if (rc)
                goto leaving;
 
+       /* free the ACPI resources for the slot */
+       if (SN_ACPI_BASE_SUPPORT() &&
+            PCI_CONTROLLER(slot->pci_bus)->acpi_handle) {
+               unsigned long adr;
+               struct acpi_device *device;
+               acpi_handle phandle;
+               acpi_handle chandle = NULL;
+               acpi_handle rethandle;
+               acpi_status ret;
+
+               /* Get the rootbus node pointer */
+               phandle = PCI_CONTROLLER(slot->pci_bus)->acpi_handle;
+
+               /*
+                * Walk the rootbus node's immediate children looking for
+                * the slot's device node(s). There can be more than
+                * one for multifunction devices.
+                */
+               for (;;) {
+                       rethandle = NULL;
+                       ret = acpi_get_next_object(ACPI_TYPE_DEVICE,
+                                                  phandle, chandle,
+                                                  &rethandle);
+
+                       if (ret == AE_NOT_FOUND || rethandle == NULL)
+                               break;
+
+                       chandle = rethandle;
+
+                       ret = acpi_evaluate_integer(chandle,
+                                                   METHOD_NAME__ADR,
+                                                   NULL, &adr);
+                       if (ACPI_SUCCESS(ret) &&
+                           (adr>>16) == (slot->device_num + 1)) {
+                               /* retain the owner id */
+                               acpi_get_id(chandle, &ssdt_id);
+
+                               ret = acpi_bus_get_device(chandle,
+                                                         &device);
+                               if (ACPI_SUCCESS(ret))
+                                       acpi_bus_trim(device, 1);
+                       }
+               }
+
+       }
+
        /* Free the SN resources assigned to the Linux device.*/
        for (func = 0; func < 8;  func++) {
                dev = pci_get_slot(slot->pci_bus,
@@ -434,6 +563,18 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
                }
        }
 
+       /* Remove the SSDT for the slot from the ACPI namespace */
+       if (SN_ACPI_BASE_SUPPORT() && ssdt_id) {
+               acpi_status ret;
+               ret = acpi_unload_table_id(ssdt_id);
+               if (ACPI_FAILURE(ret)) {
+                       printk(KERN_ERR "%s: acpi_unload_table_id "
+                              "failed (0x%x) for id %d\n",
+                              __FUNCTION__, ret, ssdt_id);
+                       /* try to continue on */
+               }
+       }
+
        /* free the collected sysdata pointers */
        sn_bus_free_sysdata();
 
index b1854171b9632b8ef260cf34ab6f0d0641a0f487..ad27e5e0101fd178bc9dbeeb84a94e855f0fc89e 100644 (file)
@@ -2,8 +2,8 @@
 # Plug and Play ACPI configuration
 #
 config PNPACPI
-       bool "Plug and Play ACPI support (EXPERIMENTAL)"
-       depends on PNP && ACPI && EXPERIMENTAL
+       bool "Plug and Play ACPI support"
+       depends on PNP && ACPI
        default y
        ---help---
          Linux uses the PNPACPI to autodetect built-in
index d42015c382af5aa7fd106081403c490ad3673317..2065e74bb63f530d6fae0b99279d24058d1493b1 100644 (file)
@@ -3,7 +3,8 @@
  *
  * Some code is based on pnpbios_core.c
  * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
- *
+ * (c) Copyright 2007 Hewlett-Packard Development Company, L.P.
+ *     Bjorn Helgaas <bjorn.helgaas@hp.com>
  */
 
 #include <linux/pnp.h>
@@ -21,18 +22,21 @@ static const struct pnp_device_id pnp_dev_table[] = {
        {       "",                     0       }
 };
 
-static void reserve_ioport_range(char *pnpid, int start, int end)
+static void reserve_range(char *pnpid, int start, int end, int port)
 {
        struct resource *res;
        char *regionid;
 
        regionid = kmalloc(16, GFP_KERNEL);
-       if ( regionid == NULL )
+       if (regionid == NULL)
                return;
        snprintf(regionid, 16, "pnp %s", pnpid);
-       res = request_region(start,end-start+1,regionid);
-       if ( res == NULL )
-               kfree( regionid );
+       if (port)
+               res = request_region(start,end-start+1,regionid);
+       else
+               res = request_mem_region(start,end-start+1,regionid);
+       if (res == NULL)
+               kfree(regionid);
        else
                res->flags &= ~IORESOURCE_BUSY;
        /*
@@ -41,26 +45,20 @@ static void reserve_ioport_range(char *pnpid, int start, int end)
         * have double reservations.
         */
        printk(KERN_INFO
-               "pnp: %s: ioport range 0x%x-0x%x %s reserved\n",
-               pnpid, start, end,
-               NULL != res ? "has been" : "could not be"
-       );
-
-       return;
+               "pnp: %s: %s range 0x%x-0x%x %s reserved\n",
+               pnpid, port ? "ioport" : "iomem", start, end,
+               NULL != res ? "has been" : "could not be");
 }
 
-static void reserve_resources_of_dev( struct pnp_dev *dev )
+static void reserve_resources_of_dev(struct pnp_dev *dev)
 {
        int i;
 
-       for (i=0;i<PNP_MAX_PORT;i++) {
+       for (i = 0; i < PNP_MAX_PORT; i++) {
                if (!pnp_port_valid(dev, i))
-                       /* end of resources */
                        continue;
                if (pnp_port_start(dev, i) == 0)
-                       /* disabled */
-                       /* Do nothing */
-                       continue;
+                       continue;       /* disabled */
                if (pnp_port_start(dev, i) < 0x100)
                        /*
                         * Below 0x100 is only standard PC hardware
@@ -72,14 +70,18 @@ static void reserve_resources_of_dev( struct pnp_dev *dev )
                         */
                        continue;
                if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
-                       /* invalid endpoint */
-                       /* Do nothing */
+                       continue;       /* invalid */
+
+               reserve_range(dev->dev.bus_id, pnp_port_start(dev, i),
+                       pnp_port_end(dev, i), 1);
+       }
+
+       for (i = 0; i < PNP_MAX_MEM; i++) {
+               if (!pnp_mem_valid(dev, i))
                        continue;
-               reserve_ioport_range(
-                       dev->dev.bus_id,
-                       pnp_port_start(dev, i),
-                       pnp_port_end(dev, i)
-               );
+
+               reserve_range(dev->dev.bus_id, pnp_mem_start(dev, i),
+                       pnp_mem_end(dev, i), 0);
        }
 
        return;
index 896449f0cf85b7a2f15b7ec1ece5df065319a447..4206df2d61b70f673d50bf86d6f56647826a80e7 100644 (file)
@@ -1449,6 +1449,10 @@ static const struct usb_device_id        products [] = {
        // Linksys USB1000
        USB_DEVICE (0x1737, 0x0039),
        .driver_info = (unsigned long) &ax88178_info,
+}, {
+       // IO-DATA ETG-US2
+       USB_DEVICE (0x04bb, 0x0930),
+       .driver_info = (unsigned long) &ax88178_info,
 },
        { },            // END
 };
index 98f6898cae1f48350162686f1f33894d63e0fad7..c7467823cd1ca975349ec5ddfdac2ed293d7beac 100644 (file)
@@ -214,9 +214,9 @@ PEGASUS_DEV( "Billionton USBEL-100", VENDOR_BILLIONTON, 0x0988,
                DEFAULT_GPIO_RESET )
 PEGASUS_DEV( "Billionton USBE-100", VENDOR_BILLIONTON, 0x8511,
                DEFAULT_GPIO_RESET | PEGASUS_II )
-PEGASUS_DEV( "Corega FEter USB-TX", VENDOR_COREGA, 0x0004,
+PEGASUS_DEV( "Corega FEther USB-TX", VENDOR_COREGA, 0x0004,
                DEFAULT_GPIO_RESET )
-PEGASUS_DEV( "Corega FEter USB-TXS", VENDOR_COREGA, 0x000d,
+PEGASUS_DEV( "Corega FEther USB-TXS", VENDOR_COREGA, 0x000d,
                DEFAULT_GPIO_RESET | PEGASUS_II )
 PEGASUS_DEV( "D-Link DSB-650TX", VENDOR_DLINK, 0x4001,
                DEFAULT_GPIO_RESET )
diff --git a/drivers/video/output.c b/drivers/video/output.c
new file mode 100644 (file)
index 0000000..1473f2c
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ *  output.c - Display Output Switch driver
+ *
+ *  Copyright (C) 2006 Luming Yu <luming.yu@intel.com>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or (at
+ *  your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#include <linux/module.h>
+#include <linux/video_output.h>
+#include <linux/err.h>
+#include <linux/ctype.h>
+
+
+MODULE_DESCRIPTION("Display Output Switcher Lowlevel Control Abstraction");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Luming Yu <luming.yu@intel.com>");
+
+static ssize_t video_output_show_state(struct class_device *dev,char *buf)
+{
+       ssize_t ret_size = 0;
+       struct output_device *od = to_output_device(dev);
+       if (od->props)
+               ret_size = sprintf(buf,"%.8x\n",od->props->get_status(od));
+       return ret_size;
+}
+
+static ssize_t video_output_store_state(struct class_device *dev,
+       const char *buf,size_t count)
+{
+       char *endp;
+       struct output_device *od = to_output_device(dev);
+       int request_state = simple_strtoul(buf,&endp,0);
+       size_t size = endp - buf;
+
+       if (*endp && isspace(*endp))
+               size++;
+       if (size != count)
+               return -EINVAL;
+
+       if (od->props) {
+               od->request_state = request_state;
+               od->props->set_state(od);
+       }
+       return count;
+}
+
+static void video_output_class_release(struct class_device *dev)
+{
+       struct output_device *od = to_output_device(dev);
+       kfree(od);
+}
+
+static struct class_device_attribute video_output_attributes[] = {
+       __ATTR(state, 0644, video_output_show_state, video_output_store_state),
+       __ATTR_NULL,
+};
+
+static struct class video_output_class = {
+       .name = "video_output",
+       .release = video_output_class_release,
+       .class_dev_attrs = video_output_attributes,
+};
+
+struct output_device *video_output_register(const char *name,
+       struct device *dev,
+       void *devdata,
+       struct output_properties *op)
+{
+       struct output_device *new_dev;
+       int ret_code = 0;
+
+       new_dev = kzalloc(sizeof(struct output_device),GFP_KERNEL);
+       if (!new_dev) {
+               ret_code = -ENOMEM;
+               goto error_return;
+       }
+       new_dev->props = op;
+       new_dev->class_dev.class = &video_output_class;
+       new_dev->class_dev.dev = dev;
+       strlcpy(new_dev->class_dev.class_id,name,KOBJ_NAME_LEN);
+       class_set_devdata(&new_dev->class_dev,devdata);
+       ret_code = class_device_register(&new_dev->class_dev);
+       if (ret_code) {
+               kfree(new_dev);
+               goto error_return;
+       }
+       return new_dev;
+
+error_return:
+       return ERR_PTR(ret_code);
+}
+EXPORT_SYMBOL(video_output_register);
+
+void video_output_unregister(struct output_device *dev)
+{
+       if (!dev)
+               return;
+       class_device_unregister(&dev->class_dev);
+}
+EXPORT_SYMBOL(video_output_unregister);
+
+static void __exit video_output_class_exit(void)
+{
+       class_unregister(&video_output_class);
+}
+
+static int __init video_output_class_init(void)
+{
+       return class_register(&video_output_class);
+}
+
+postcore_initcall(video_output_class_init);
+module_exit(video_output_class_exit);
index ebc1f697615a15a79cfdba299299668aacd1ad45..422f29c06c77d10e17a10c434300fda383502768 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -63,7 +63,7 @@
 
 /* Current ACPICA subsystem version in YYYYMMDD format */
 
-#define ACPI_CA_VERSION                 0x20060707
+#define ACPI_CA_VERSION                 0x20070126
 
 /*
  * OS name, used for the _OS object.  The _OS object is essentially obsolete,
 
 #define ACPI_NUM_OWNERID_MASKS          8
 
+/* Size of the root table array is increased by this increment */
+
+#define ACPI_ROOT_TABLE_SIZE_INCREMENT  4
+
 /******************************************************************************
  *
  * ACPI Specification constants (Do not change unless the specification changes)
 #define ACPI_PATH_SEGMENT_LENGTH        5      /* 4 chars for name + 1 char for separator */
 #define ACPI_PATH_SEPARATOR             '.'
 
+/* Sizes for ACPI table headers */
+
+#define ACPI_OEM_ID_SIZE                6
+#define ACPI_OEM_TABLE_ID_SIZE          8
+
 /* Constants used in searching for the RSDP in low memory */
 
 #define ACPI_EBDA_PTR_LOCATION          0x0000040E     /* Physical Address */
index d8167095caf3cf5ea5706f747fa335b471dae35e..d626bb1d297318065cebf546dc184fe1152e1a52 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -159,6 +159,10 @@ void
 acpi_db_create_execution_threads(char *num_threads_arg,
                                 char *num_loops_arg, char *method_name_arg);
 
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+u32 acpi_db_get_cache_info(struct acpi_memory_list *cache);
+#endif
+
 /*
  * dbfileio - Debugger file I/O commands
  */
@@ -214,4 +218,6 @@ void acpi_db_prep_namestring(char *name);
 
 struct acpi_namespace_node *acpi_db_local_ns_lookup(char *name);
 
+void acpi_db_uint32_to_hex_string(u32 value, char *buffer);
+
 #endif                         /* __ACDEBUG_H__ */
index 9a7d6921f53424098322b2df79d6ba9b468f90bf..389d772c7d5b5ee2bdc996d3d0acae60f17c2801 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -97,9 +97,11 @@ typedef const struct acpi_dmtable_info {
 #define ACPI_DMT_CHKSUM                 20
 #define ACPI_DMT_SPACEID                21
 #define ACPI_DMT_GAS                    22
-#define ACPI_DMT_MADT                   23
-#define ACPI_DMT_SRAT                   24
-#define ACPI_DMT_EXIT                   25
+#define ACPI_DMT_DMAR                   23
+#define ACPI_DMT_MADT                   24
+#define ACPI_DMT_SRAT                   25
+#define ACPI_DMT_EXIT                   26
+#define ACPI_DMT_SIG                    27
 
 typedef
 void (*ACPI_TABLE_HANDLER) (struct acpi_table_header * table);
@@ -108,6 +110,7 @@ struct acpi_dmtable_data {
        char *signature;
        struct acpi_dmtable_info *table_info;
        ACPI_TABLE_HANDLER table_handler;
+       char *name;
 };
 
 struct acpi_op_walk_info {
@@ -139,7 +142,9 @@ extern const char *acpi_gbl_match_ops[];
 
 extern struct acpi_dmtable_info acpi_dm_table_info_asf0[];
 extern struct acpi_dmtable_info acpi_dm_table_info_asf1[];
+extern struct acpi_dmtable_info acpi_dm_table_info_asf1a[];
 extern struct acpi_dmtable_info acpi_dm_table_info_asf2[];
+extern struct acpi_dmtable_info acpi_dm_table_info_asf2a[];
 extern struct acpi_dmtable_info acpi_dm_table_info_asf3[];
 extern struct acpi_dmtable_info acpi_dm_table_info_asf4[];
 extern struct acpi_dmtable_info acpi_dm_table_info_asf_hdr[];
@@ -147,6 +152,11 @@ extern struct acpi_dmtable_info acpi_dm_table_info_boot[];
 extern struct acpi_dmtable_info acpi_dm_table_info_cpep[];
 extern struct acpi_dmtable_info acpi_dm_table_info_cpep0[];
 extern struct acpi_dmtable_info acpi_dm_table_info_dbgp[];
+extern struct acpi_dmtable_info acpi_dm_table_info_dmar[];
+extern struct acpi_dmtable_info acpi_dm_table_info_dmar_hdr[];
+extern struct acpi_dmtable_info acpi_dm_table_info_dmar_scope[];
+extern struct acpi_dmtable_info acpi_dm_table_info_dmar0[];
+extern struct acpi_dmtable_info acpi_dm_table_info_dmar1[];
 extern struct acpi_dmtable_info acpi_dm_table_info_ecdt[];
 extern struct acpi_dmtable_info acpi_dm_table_info_facs[];
 extern struct acpi_dmtable_info acpi_dm_table_info_fadt1[];
@@ -201,6 +211,8 @@ void acpi_dm_dump_asf(struct acpi_table_header *table);
 
 void acpi_dm_dump_cpep(struct acpi_table_header *table);
 
+void acpi_dm_dump_dmar(struct acpi_table_header *table);
+
 void acpi_dm_dump_fadt(struct acpi_table_header *table);
 
 void acpi_dm_dump_srat(struct acpi_table_header *table);
@@ -314,7 +326,7 @@ acpi_dm_resource_template(struct acpi_op_walk_info *info,
                          union acpi_parse_object *op,
                          u8 * byte_data, u32 byte_count);
 
-u8 acpi_dm_is_resource_template(union acpi_parse_object *op);
+acpi_status acpi_dm_is_resource_template(union acpi_parse_object *op);
 
 void acpi_dm_indent(u32 level);
 
index a22fe9cf8493dc3fb9ed5003fa53b48e0a824c9d..cb8d2868c8ac3520ba07a12cbf9c93101c53c634 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -210,7 +210,7 @@ acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state);
  * dsinit
  */
 acpi_status
-acpi_ds_initialize_objects(struct acpi_table_desc *table_desc,
+acpi_ds_initialize_objects(acpi_native_uint table_index,
                           struct acpi_namespace_node *start_node);
 
 /*
index 234142828e1a7fb44dcdea286dda62f162292a16..d23cdf326808f68f971e3d70e9a484f52a2bb6e5 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 797ca1ea5214612ab8bb2c593f11441eac7b38f3..b73f18a48785685d46bee2702178f4eaf2eec1ec 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define AE_CTRL_BREAK                   (acpi_status) (0x0009 | AE_CODE_CONTROL)
 #define AE_CTRL_CONTINUE                (acpi_status) (0x000A | AE_CODE_CONTROL)
 #define AE_CTRL_SKIP                    (acpi_status) (0x000B | AE_CODE_CONTROL)
+#define AE_CTRL_PARSE_CONTINUE          (acpi_status) (0x000C | AE_CODE_CONTROL)
+#define AE_CTRL_PARSE_PENDING           (acpi_status) (0x000D | AE_CODE_CONTROL)
 
-#define AE_CODE_CTRL_MAX                0x000B
+#define AE_CODE_CTRL_MAX                0x000D
 
 #ifdef DEFINE_ACPI_GLOBALS
 
@@ -291,7 +293,9 @@ char const *acpi_gbl_exception_names_ctrl[] = {
        "AE_CTRL_TRANSFER",
        "AE_CTRL_BREAK",
        "AE_CTRL_CONTINUE",
-       "AE_CTRL_SKIP"
+       "AE_CTRL_SKIP",
+       "AE_CTRL_PARSE_CONTINUE",
+       "AE_CTRL_PARSE_PENDING"
 };
 
 #endif                         /* ACPI GLOBALS */
index 06972e6637de50d8b8be1dafdab911801ce08490..24c3f05ab367ce92adf664a369c780550d2e5315 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define ACPI_INIT_GLOBAL(a,b) a
 #endif
 
-/*
- * Keep local copies of these FADT-based registers.  NOTE: These globals
- * are first in this file for alignment reasons on 64-bit systems.
- */
-ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1a_enable;
-ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1b_enable;
-
-/*****************************************************************************
- *
- * Debug support
- *
- ****************************************************************************/
-
-/* Runtime configuration of debug print levels */
-
-extern u32 acpi_dbg_level;
-extern u32 acpi_dbg_layer;
-
-/* Procedure nesting level for debug output */
-
-extern u32 acpi_gbl_nesting_level;
-
-/* Support for dynamic control method tracing mechanism */
-
-ACPI_EXTERN u32 acpi_gbl_original_dbg_level;
-ACPI_EXTERN u32 acpi_gbl_original_dbg_layer;
-ACPI_EXTERN acpi_name acpi_gbl_trace_method_name;
-ACPI_EXTERN u32 acpi_gbl_trace_dbg_level;
-ACPI_EXTERN u32 acpi_gbl_trace_dbg_layer;
-ACPI_EXTERN u32 acpi_gbl_trace_flags;
-
 /*****************************************************************************
  *
  * Runtime configuration (static defaults that can be overriden at runtime)
@@ -133,6 +102,34 @@ ACPI_EXTERN u8 ACPI_INIT_GLOBAL(acpi_gbl_create_osi_method, TRUE);
  */
 ACPI_EXTERN u8 ACPI_INIT_GLOBAL(acpi_gbl_leave_wake_gpes_disabled, TRUE);
 
+/*****************************************************************************
+ *
+ * Debug support
+ *
+ ****************************************************************************/
+
+/* Runtime configuration of debug print levels */
+
+extern u32 acpi_dbg_level;
+extern u32 acpi_dbg_layer;
+
+/* Procedure nesting level for debug output */
+
+extern u32 acpi_gbl_nesting_level;
+
+/* Event counters */
+
+ACPI_EXTERN u32 acpi_gpe_count;
+
+/* Support for dynamic control method tracing mechanism */
+
+ACPI_EXTERN u32 acpi_gbl_original_dbg_level;
+ACPI_EXTERN u32 acpi_gbl_original_dbg_layer;
+ACPI_EXTERN acpi_name acpi_gbl_trace_method_name;
+ACPI_EXTERN u32 acpi_gbl_trace_dbg_level;
+ACPI_EXTERN u32 acpi_gbl_trace_dbg_layer;
+ACPI_EXTERN u32 acpi_gbl_trace_flags;
+
 /*****************************************************************************
  *
  * ACPI Table globals
@@ -140,47 +137,29 @@ ACPI_EXTERN u8 ACPI_INIT_GLOBAL(acpi_gbl_leave_wake_gpes_disabled, TRUE);
  ****************************************************************************/
 
 /*
- * Table pointers.
- * Although these pointers are somewhat redundant with the global acpi_table,
- * they are convenient because they are typed pointers.
+ * acpi_gbl_root_table_list is the master list of ACPI tables found in the
+ * RSDT/XSDT.
  *
- * These tables are single-table only; meaning that there can be at most one
- * of each in the system.  Each global points to the actual table.
- */
-ACPI_EXTERN u32 acpi_gbl_table_flags;
-ACPI_EXTERN u32 acpi_gbl_rsdt_table_count;
-ACPI_EXTERN struct rsdp_descriptor *acpi_gbl_RSDP;
-ACPI_EXTERN struct xsdt_descriptor *acpi_gbl_XSDT;
-ACPI_EXTERN struct fadt_descriptor *acpi_gbl_FADT;
-ACPI_EXTERN struct acpi_table_header *acpi_gbl_DSDT;
-ACPI_EXTERN struct facs_descriptor *acpi_gbl_FACS;
-ACPI_EXTERN struct acpi_common_facs acpi_gbl_common_fACS;
-/*
- * Since there may be multiple SSDTs and PSDTs, a single pointer is not
- * sufficient; Therefore, there isn't one!
+ * acpi_gbl_FADT is a local copy of the FADT, converted to a common format.
  */
+ACPI_EXTERN struct acpi_internal_rsdt acpi_gbl_root_table_list;
+ACPI_EXTERN struct acpi_table_fadt acpi_gbl_FADT;
+extern acpi_native_uint acpi_gbl_permanent_mmap;
 
-/* The root table can be either an RSDT or an XSDT */
+/* These addresses are calculated from FADT address values */
 
-ACPI_EXTERN u8 acpi_gbl_root_table_type;
-#define     ACPI_TABLE_TYPE_RSDT        'R'
-#define     ACPI_TABLE_TYPE_XSDT        'X'
+ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1a_enable;
+ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1b_enable;
 
 /*
- * Handle both ACPI 1.0 and ACPI 2.0 Integer widths:
- * If we are executing a method that exists in a 32-bit ACPI table,
- * use only the lower 32 bits of the (internal) 64-bit Integer.
+ * Handle both ACPI 1.0 and ACPI 2.0 Integer widths. The integer width is
+ * determined by the revision of the DSDT: If the DSDT revision is less than
+ * 2, use only the lower 32 bits of the internal 64-bit Integer.
  */
 ACPI_EXTERN u8 acpi_gbl_integer_bit_width;
 ACPI_EXTERN u8 acpi_gbl_integer_byte_width;
 ACPI_EXTERN u8 acpi_gbl_integer_nybble_width;
 
-/*
- * ACPI Table info arrays
- */
-extern struct acpi_table_list acpi_gbl_table_lists[ACPI_TABLE_ID_MAX + 1];
-extern struct acpi_table_support acpi_gbl_table_data[ACPI_TABLE_ID_MAX + 1];
-
 /*****************************************************************************
  *
  * Mutual exlusion within ACPICA subsystem
@@ -188,7 +167,7 @@ extern struct acpi_table_support acpi_gbl_table_data[ACPI_TABLE_ID_MAX + 1];
  ****************************************************************************/
 
 /*
- * Predefined mutex objects.  This array contains the
+ * Predefined mutex objects. This array contains the
  * actual OS mutex handles, indexed by the local ACPI_MUTEX_HANDLEs.
  * (The table maps local handles to the real OS handles)
  */
@@ -197,6 +176,7 @@ ACPI_EXTERN struct acpi_mutex_info acpi_gbl_mutex_info[ACPI_NUM_MUTEX];
 /*
  * Global lock semaphore works in conjunction with the actual HW global lock
  */
+ACPI_EXTERN acpi_mutex acpi_gbl_global_lock_mutex;
 ACPI_EXTERN acpi_semaphore acpi_gbl_global_lock_semaphore;
 
 /*
@@ -220,6 +200,7 @@ ACPI_EXTERN spinlock_t _acpi_gbl_hardware_lock;     /* For ACPI H/W except GPE regis
 
 ACPI_EXTERN struct acpi_memory_list *acpi_gbl_global_list;
 ACPI_EXTERN struct acpi_memory_list *acpi_gbl_ns_node_list;
+ACPI_EXTERN u8 acpi_gbl_display_final_mem_stats;
 #endif
 
 /* Object caches */
@@ -240,7 +221,6 @@ ACPI_EXTERN struct acpi_walk_state *acpi_gbl_breakpoint_walk;
 
 /* Misc */
 
-ACPI_EXTERN u32 acpi_gbl_global_lock_thread_count;
 ACPI_EXTERN u32 acpi_gbl_original_mode;
 ACPI_EXTERN u32 acpi_gbl_rsdp_original_location;
 ACPI_EXTERN u32 acpi_gbl_ns_lookup_count;
@@ -260,12 +240,19 @@ ACPI_EXTERN u8 acpi_gbl_system_awake_and_running;
 
 extern u8 acpi_gbl_shutdown;
 extern u32 acpi_gbl_startup_flags;
-extern const u8 acpi_gbl_decode_to8bit[8];
 extern const char *acpi_gbl_sleep_state_names[ACPI_S_STATE_COUNT];
 extern const char *acpi_gbl_highest_dstate_names[4];
 extern const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES];
 extern const char *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS];
 
+/* Exception codes */
+
+extern char const *acpi_gbl_exception_names_env[];
+extern char const *acpi_gbl_exception_names_pgm[];
+extern char const *acpi_gbl_exception_names_tbl[];
+extern char const *acpi_gbl_exception_names_aml[];
+extern char const *acpi_gbl_exception_names_ctrl[];
+
 /*****************************************************************************
  *
  * Namespace globals
index 29b60a8c0593bc3cd57c3122637c6f64d62e8605..9df275cf7bc1a795e9b8aeff4555f07de249c35c 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -61,8 +61,6 @@
 /*
  * hwacpi - high level functions
  */
-acpi_status acpi_hw_initialize(void);
-
 acpi_status acpi_hw_set_mode(u32 mode);
 
 u32 acpi_hw_get_mode(void);
@@ -84,7 +82,7 @@ acpi_hw_low_level_read(u32 width,
 acpi_status
 acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address *reg);
 
-acpi_status acpi_hw_clear_acpi_status(u32 flags);
+acpi_status acpi_hw_clear_acpi_status(void);
 
 /*
  * hwgpe - GPE support
index 91586d0d5bb57f8d4ea26602bcd31aafbce391e3..ce7c9d653910598c29cce2baa2dcbb28b8cbb83b 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -277,12 +277,6 @@ acpi_status acpi_ex_system_do_suspend(acpi_integer time);
 
 acpi_status acpi_ex_system_do_stall(u32 time);
 
-acpi_status
-acpi_ex_system_acquire_mutex(union acpi_operand_object *time,
-                            union acpi_operand_object *obj_desc);
-
-acpi_status acpi_ex_system_release_mutex(union acpi_operand_object *obj_desc);
-
 acpi_status acpi_ex_system_signal_event(union acpi_operand_object *obj_desc);
 
 acpi_status
@@ -451,10 +445,14 @@ acpi_ex_copy_integer_to_buffer_field(union acpi_operand_object *source_desc,
 /*
  * exutils - interpreter/scanner utilities
  */
-acpi_status acpi_ex_enter_interpreter(void);
+void acpi_ex_enter_interpreter(void);
 
 void acpi_ex_exit_interpreter(void);
 
+void acpi_ex_reacquire_interpreter(void);
+
+void acpi_ex_relinquish_interpreter(void);
+
 void acpi_ex_truncate_for32bit_table(union acpi_operand_object *obj_desc);
 
 u8 acpi_ex_acquire_global_lock(u32 rule);
index 063c4b54290f254d7ba22ec933be53ca03fcb561..6f83ddbed3af75117c84c741548556344462e389 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -80,8 +80,8 @@ union acpi_parse_object;
  * table below also!
  */
 #define ACPI_MTX_INTERPRETER            0      /* AML Interpreter, main lock */
-#define ACPI_MTX_TABLES                 1      /* Data for ACPI tables */
-#define ACPI_MTX_NAMESPACE              2      /* ACPI Namespace */
+#define ACPI_MTX_NAMESPACE              1      /* ACPI Namespace */
+#define ACPI_MTX_TABLES                 2      /* Data for ACPI tables */
 #define ACPI_MTX_EVENTS                 3      /* Data for ACPI events */
 #define ACPI_MTX_CACHES                 4      /* Internal caches, general purposes */
 #define ACPI_MTX_MEMORY                 5      /* Debug memory tracking lists */
@@ -162,7 +162,7 @@ struct acpi_mutex_info {
 typedef enum {
        ACPI_IMODE_LOAD_PASS1 = 0x01,
        ACPI_IMODE_LOAD_PASS2 = 0x02,
-       ACPI_IMODE_EXECUTE = 0x0E
+       ACPI_IMODE_EXECUTE = 0x03
 } acpi_interpreter_mode;
 
 union acpi_name_union {
@@ -204,7 +204,7 @@ struct acpi_namespace_node {
 /* Namespace Node flags */
 
 #define ANOBJ_END_OF_PEER_LIST          0x01   /* End-of-list, Peer field points to parent */
-#define ANOBJ_RESERVED                  0x02   /* Available for future use */
+#define ANOBJ_TEMPORARY                 0x02   /* Node is create by a method and is temporary */
 #define ANOBJ_METHOD_ARG                0x04   /* Node is a method argument */
 #define ANOBJ_METHOD_LOCAL              0x08   /* Node is a method local */
 #define ANOBJ_SUBTREE_HAS_INI           0x10   /* Used to optimize device initialization */
@@ -219,25 +219,42 @@ struct acpi_namespace_node {
  * ACPI Table Descriptor.  One per ACPI table
  */
 struct acpi_table_desc {
-       struct acpi_table_desc *prev;
-       struct acpi_table_desc *next;
-       struct acpi_table_desc *installed_desc;
+       acpi_physical_address address;
        struct acpi_table_header *pointer;
-       u8 *aml_start;
-       u64 physical_address;
-       acpi_size length;
-       u32 aml_length;
+       u32 length;             /* Length fixed at 32 bits */
+       union acpi_name_union signature;
        acpi_owner_id owner_id;
-       u8 type;
-       u8 allocation;
-       u8 loaded_into_namespace;
+       u8 flags;
 };
 
-struct acpi_table_list {
-       struct acpi_table_desc *next;
+/* Flags for above */
+
+#define ACPI_TABLE_ORIGIN_UNKNOWN       (0)
+#define ACPI_TABLE_ORIGIN_MAPPED        (1)
+#define ACPI_TABLE_ORIGIN_ALLOCATED     (2)
+#define ACPI_TABLE_ORIGIN_MASK          (3)
+#define ACPI_TABLE_IS_LOADED            (4)
+
+/* One internal RSDT for table management */
+
+struct acpi_internal_rsdt {
+       struct acpi_table_desc *tables;
        u32 count;
+       u32 size;
+       u8 flags;
 };
 
+/* Flags for above */
+
+#define ACPI_ROOT_ORIGIN_UNKNOWN        (0)    /* ~ORIGIN_ALLOCATED */
+#define ACPI_ROOT_ORIGIN_ALLOCATED      (1)
+#define ACPI_ROOT_ALLOW_RESIZE          (2)
+
+/* Predefined (fixed) table indexes */
+
+#define ACPI_TABLE_INDEX_DSDT           (0)
+#define ACPI_TABLE_INDEX_FACS           (1)
+
 struct acpi_find_context {
        char *search_for;
        acpi_handle *list;
@@ -350,7 +367,7 @@ struct acpi_gpe_event_info {
        union acpi_gpe_dispatch_info dispatch;  /* Either Method or Handler */
        struct acpi_gpe_register_info *register_info;   /* Backpointer to register info */
        u8 flags;               /* Misc info about this GPE */
-       u8 register_bit;        /* This GPE bit within the register */
+       u8 gpe_number;          /* This GPE */
 };
 
 /* Information about a GPE register pair, one per each status/enable pair in an array */
@@ -855,12 +872,30 @@ struct acpi_bit_register_info {
  ****************************************************************************/
 
 struct acpi_db_method_info {
-       acpi_handle thread_gate;
+       acpi_handle main_thread_gate;
+       acpi_handle thread_complete_gate;
+       u32 *threads;
+       u32 num_threads;
+       u32 num_created;
+       u32 num_completed;
+
        char *name;
-       char **args;
        u32 flags;
        u32 num_loops;
        char pathname[128];
+       char **args;
+
+       /*
+        * Arguments to be passed to method for the command
+        * Threads -
+        *   the Number of threads, ID of current thread and
+        *   Index of current thread inside all them created.
+        */
+       char init_args;
+       char *arguments[4];
+       char num_threads_str[11];
+       char id_of_thread_str[11];
+       char index_of_thread_str[11];
 };
 
 struct acpi_integrity_info {
@@ -919,6 +954,8 @@ struct acpi_memory_list {
 
        u32 total_allocated;
        u32 total_freed;
+       u32 max_occupied;
+       u32 total_size;
        u32 current_total_size;
        u32 requests;
        u32 hits;
index 192fa095a51583ab6df2bff319ed842c0597ace1..8948a6461834d1d8fa2eb5cd3a3239d48a8a4483 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define ACPI_SET_BIT(target,bit)        ((target) |= (bit))
 #define ACPI_CLEAR_BIT(target,bit)      ((target) &= ~(bit))
 #define ACPI_MIN(a,b)                   (((a)<(b))?(a):(b))
+#define ACPI_MAX(a,b)                   (((a)>(b))?(a):(b))
 
 /* Size calculation */
 
 #define ACPI_ARRAY_LENGTH(x)            (sizeof(x) / sizeof((x)[0]))
 
-#if ACPI_MACHINE_WIDTH == 16
-
-/*
- * For 16-bit addresses, we have to assume that the upper 32 bits
- * (out of 64) are zero.
- */
-#define ACPI_LODWORD(l)                 ((u32)(l))
-#define ACPI_HIDWORD(l)                 ((u32)(0))
-
-#define ACPI_GET_ADDRESS(a)             ((a).lo)
-#define ACPI_STORE_ADDRESS(a,b)         {(a).hi=0;(a).lo=(u32)(b);}
-#define ACPI_VALID_ADDRESS(a)           ((a).hi | (a).lo)
-
-#else
 #ifdef ACPI_NO_INTEGER64_SUPPORT
 /*
  * acpi_integer is 32-bits, no 64-bit support on this platform
 #define ACPI_LODWORD(l)                 ((u32)(l))
 #define ACPI_HIDWORD(l)                 ((u32)(0))
 
-#define ACPI_GET_ADDRESS(a)             (a)
-#define ACPI_STORE_ADDRESS(a,b)         ((a)=(b))
-#define ACPI_VALID_ADDRESS(a)           (a)
-
 #else
 
 /*
  */
 #define ACPI_LODWORD(l)                 ((u32)(u64)(l))
 #define ACPI_HIDWORD(l)                 ((u32)(((*(struct uint64_struct *)(void *)(&l))).hi))
-
-#define ACPI_GET_ADDRESS(a)             (a)
-#define ACPI_STORE_ADDRESS(a,b)         ((a)=(acpi_physical_address)(b))
-#define ACPI_VALID_ADDRESS(a)           (a)
-#endif
 #endif
 
 /*
 #define ACPI_TO_POINTER(i)              ACPI_ADD_PTR (void,(void *) NULL,(acpi_native_uint) i)
 #define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p,(void *) NULL)
 #define ACPI_OFFSET(d,f)                (acpi_size) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL)
-
-#if ACPI_MACHINE_WIDTH == 16
-#define ACPI_STORE_POINTER(d,s)         ACPI_MOVE_32_TO_32(d,s)
-#define ACPI_PHYSADDR_TO_PTR(i)         (void *)(i)
-#define ACPI_PTR_TO_PHYSADDR(i)         (u32) ACPI_CAST_PTR (u8,(i))
-#else
 #define ACPI_PHYSADDR_TO_PTR(i)         ACPI_TO_POINTER(i)
 #define ACPI_PTR_TO_PHYSADDR(i)         ACPI_TO_INTEGER(i)
-#endif
 
 #ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
 #define ACPI_COMPARE_NAME(a,b)          (*ACPI_CAST_PTR (u32,(a)) == *ACPI_CAST_PTR (u32,(b)))
 
 /* The hardware supports unaligned transfers, just do the little-endian move */
 
-#if ACPI_MACHINE_WIDTH == 16
-
-/* No 64-bit integers */
-/* 16-bit source, 16/32/64 destination */
-
-#define ACPI_MOVE_16_TO_16(d,s)         *(u16 *)(void *)(d) = *(u16 *)(void *)(s)
-#define ACPI_MOVE_16_TO_32(d,s)         *(u32 *)(void *)(d) = *(u16 *)(void *)(s)
-#define ACPI_MOVE_16_TO_64(d,s)         ACPI_MOVE_16_TO_32(d,s)
-
-/* 32-bit source, 16/32/64 destination */
-
-#define ACPI_MOVE_32_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)        /* Truncate to 16 */
-#define ACPI_MOVE_32_TO_32(d,s)         *(u32 *)(void *)(d) = *(u32 *)(void *)(s)
-#define ACPI_MOVE_32_TO_64(d,s)         ACPI_MOVE_32_TO_32(d,s)
-
-/* 64-bit source, 16/32/64 destination */
-
-#define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)        /* Truncate to 16 */
-#define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)        /* Truncate to 32 */
-#define ACPI_MOVE_64_TO_64(d,s)         ACPI_MOVE_32_TO_32(d,s)
-
-#else
 /* 16-bit source, 16/32/64 destination */
 
 #define ACPI_MOVE_16_TO_16(d,s)         *(u16 *)(void *)(d) = *(u16 *)(void *)(s)
 #define ACPI_MOVE_64_TO_16(d,s)         ACPI_MOVE_16_TO_16(d,s)        /* Truncate to 16 */
 #define ACPI_MOVE_64_TO_32(d,s)         ACPI_MOVE_32_TO_32(d,s)        /* Truncate to 32 */
 #define ACPI_MOVE_64_TO_64(d,s)         *(u64 *)(void *)(d) = *(u64 *)(void *)(s)
-#endif
 
 #else
 /*
 
 /* Macros based on machine integer width */
 
-#if ACPI_MACHINE_WIDTH == 16
-#define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_16_TO_16(d,s)
-
-#elif ACPI_MACHINE_WIDTH == 32
+#if ACPI_MACHINE_WIDTH == 32
 #define ACPI_MOVE_SIZE_TO_16(d,s)       ACPI_MOVE_32_TO_16(d,s)
 
 #elif ACPI_MACHINE_WIDTH == 64
 #define ACPI_DEBUGGER_EXEC(a)
 #endif
 
-/*
- * For 16-bit code, we want to shrink some things even though
- * we are using ACPI_DEBUG_OUTPUT to get the debug output
- */
-#if ACPI_MACHINE_WIDTH == 16
-#undef ACPI_DEBUG_ONLY_MEMBERS
-#undef _VERBOSE_STRUCTURES
-#define ACPI_DEBUG_ONLY_MEMBERS(a)
-#endif
-
 #ifdef ACPI_DEBUG_OUTPUT
 /*
  * 1) Set name to blanks
index b67da3636899f6a3b03805be169608e1392166a7..34bfae8a05f32458b82766356e0269a66454fae4 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 83b52f9f899a64f598c7f7ec4369f3e98eb9f460..535b7e1c41bcc12657d768136470901ca9184dd7 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define ACPI_NS_ERROR_IF_FOUND      0x08
 #define ACPI_NS_PREFIX_IS_SCOPE     0x10
 #define ACPI_NS_EXTERNAL            0x20
+#define ACPI_NS_TEMPORARY           0x40
 
-#define ACPI_NS_WALK_UNLOCK         TRUE
-#define ACPI_NS_WALK_NO_UNLOCK      FALSE
+/* Flags for acpi_ns_walk_namespace */
+
+#define ACPI_NS_WALK_NO_UNLOCK      0
+#define ACPI_NS_WALK_UNLOCK         0x01
+#define ACPI_NS_WALK_TEMP_NODES     0x02
 
 /*
  * nsinit - Namespace initialization
@@ -82,7 +86,7 @@ acpi_status acpi_ns_initialize_devices(void);
 acpi_status acpi_ns_load_namespace(void);
 
 acpi_status
-acpi_ns_load_table(struct acpi_table_desc *table_desc,
+acpi_ns_load_table(acpi_native_uint table_index,
                   struct acpi_namespace_node *node);
 
 /*
@@ -92,7 +96,7 @@ acpi_status
 acpi_ns_walk_namespace(acpi_object_type type,
                       acpi_handle start_object,
                       u32 max_depth,
-                      u8 unlock_before_callback,
+                      u32 flags,
                       acpi_walk_callback user_function,
                       void *context, void **return_value);
 
@@ -106,11 +110,12 @@ struct acpi_namespace_node *acpi_ns_get_next_node(acpi_object_type type,
  * nsparse - table parsing
  */
 acpi_status
-acpi_ns_parse_table(struct acpi_table_desc *table_desc,
-                   struct acpi_namespace_node *scope);
+acpi_ns_parse_table(acpi_native_uint table_index,
+                   struct acpi_namespace_node *start_node);
 
 acpi_status
-acpi_ns_one_complete_parse(u8 pass_number, struct acpi_table_desc *table_desc);
+acpi_ns_one_complete_parse(acpi_native_uint pass_number,
+                          acpi_native_uint table_index);
 
 /*
  * nsaccess - Top-level namespace access
index 8fdee31119f360c1f896dcda2645ad14a72f4237..04e9735a674214fb49aab10f3b75d273e3f44e0d 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * to the interpreter, and to keep track of the various handlers such as
  * address space handlers and notify handlers. The object is a constant
  * size in order to allow it to be cached and reused.
+ *
+ * Note: The object is optimized to be aligned and will not work if it is
+ * byte-packed.
  */
+#if ACPI_MACHINE_WIDTH == 64
+#pragma pack(8)
+#else
+#pragma pack(4)
+#endif
 
 /*******************************************************************************
  *
@@ -101,7 +109,8 @@ struct acpi_object_common {
 ACPI_OBJECT_COMMON_HEADER};
 
 struct acpi_object_integer {
-       ACPI_OBJECT_COMMON_HEADER acpi_integer value;
+       ACPI_OBJECT_COMMON_HEADER u8 fill[3];   /* Prevent warning on some compilers */
+       acpi_integer value;
 };
 
 /*
@@ -203,7 +212,9 @@ struct acpi_object_power_resource {
 };
 
 struct acpi_object_processor {
-       ACPI_OBJECT_COMMON_HEADER u8 proc_id;
+       ACPI_OBJECT_COMMON_HEADER
+           /* The next two fields take advantage of the 3-byte space before NOTIFY_INFO */
+       u8 proc_id;
        u8 length;
         ACPI_COMMON_NOTIFY_INFO acpi_io_address address;
 };
@@ -406,4 +417,6 @@ union acpi_descriptor {
        union acpi_parse_object op;
 };
 
+#pragma pack()
+
 #endif                         /* _ACOBJECT_H */
index 7659a46bc432e85f1742b708a0c817a21a890d48..e6f76a280a94d62cf2c082ec2425b74d8b1257fd 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define ARGI_LLESSEQUAL_OP              ARGI_INVALID_OPCODE
 #define ARGI_LNOT_OP                    ARGI_LIST1 (ARGI_INTEGER)
 #define ARGI_LNOTEQUAL_OP               ARGI_INVALID_OPCODE
-#define ARGI_LOAD_OP                    ARGI_LIST2 (ARGI_REGION_OR_FIELD,ARGI_TARGETREF)
+#define ARGI_LOAD_OP                    ARGI_LIST2 (ARGI_REGION_OR_BUFFER,ARGI_TARGETREF)
 #define ARGI_LOAD_TABLE_OP              ARGI_LIST6 (ARGI_STRING,     ARGI_STRING,        ARGI_STRING,       ARGI_STRING,    ARGI_STRING, ARGI_ANYTYPE)
 #define ARGI_LOCAL0                     ARG_NONE
 #define ARGI_LOCAL1                     ARG_NONE
index 8d5039d0b430187c403d13b862d8419580a99b2c..7812267b577f2d857827ed501faf66894829afcf 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 9d49d3c41cd924ed6c768cd3701e5da3a4d73232..85c358e21014fd594b4c03e6e4c0e117f09c63b0 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index b9a39d1009bd49d2177a13b1888ba907edd85a23..2e5f00d3ea0d101f5b8621cd2568dae7a03e06e4 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index fdd10953b2b6503760c91b8035b85d54243770bd..0d9f984a60a199498286b80074e2d348eacc0f24 100644 (file)
@@ -59,7 +59,6 @@ acpi_evaluate_reference(acpi_handle handle,
 
 #define ACPI_BUS_FILE_ROOT     "acpi"
 extern struct proc_dir_entry *acpi_root_dir;
-extern struct fadt_descriptor acpi_fadt;
 
 enum acpi_bus_removal_type {
        ACPI_BUS_REMOVAL_NORMAL = 0,
@@ -92,13 +91,12 @@ typedef int (*acpi_op_remove) (struct acpi_device * device, int type);
 typedef int (*acpi_op_lock) (struct acpi_device * device, int type);
 typedef int (*acpi_op_start) (struct acpi_device * device);
 typedef int (*acpi_op_stop) (struct acpi_device * device, int type);
-typedef int (*acpi_op_suspend) (struct acpi_device * device, int state);
-typedef int (*acpi_op_resume) (struct acpi_device * device, int state);
+typedef int (*acpi_op_suspend) (struct acpi_device * device, pm_message_t state);
+typedef int (*acpi_op_resume) (struct acpi_device * device);
 typedef int (*acpi_op_scan) (struct acpi_device * device);
 typedef int (*acpi_op_bind) (struct acpi_device * device);
 typedef int (*acpi_op_unbind) (struct acpi_device * device);
-typedef int (*acpi_op_match) (struct acpi_device * device,
-                             struct acpi_driver * driver);
+typedef int (*acpi_op_shutdown) (struct acpi_device * device);
 
 struct acpi_bus_ops {
        u32 acpi_op_add:1;
@@ -111,7 +109,7 @@ struct acpi_bus_ops {
        u32 acpi_op_scan:1;
        u32 acpi_op_bind:1;
        u32 acpi_op_unbind:1;
-       u32 acpi_op_match:1;
+       u32 acpi_op_shutdown:1;
        u32 reserved:21;
 };
 
@@ -126,16 +124,16 @@ struct acpi_device_ops {
        acpi_op_scan scan;
        acpi_op_bind bind;
        acpi_op_unbind unbind;
-       acpi_op_match match;
+       acpi_op_shutdown shutdown;
 };
 
 struct acpi_driver {
-       struct list_head node;
        char name[80];
        char class[80];
-       atomic_t references;
        char *ids;              /* Supported Hardware IDs */
        struct acpi_device_ops ops;
+       struct device_driver drv;
+       struct module *owner;
 };
 
 /*
@@ -185,7 +183,7 @@ struct acpi_device_dir {
 
 typedef char acpi_bus_id[5];
 typedef unsigned long acpi_bus_address;
-typedef char acpi_hardware_id[9];
+typedef char acpi_hardware_id[15];
 typedef char acpi_unique_id[9];
 typedef char acpi_device_name[40];
 typedef char acpi_device_class[20];
@@ -296,11 +294,14 @@ struct acpi_device {
        struct acpi_device_ops ops;
        struct acpi_driver *driver;
        void *driver_data;
-       struct kobject kobj;
        struct device dev;
+       struct acpi_bus_ops bus_ops;    /* workaround for different code path for hotplug */
+       enum acpi_bus_removal_type removal_type; /* indicate for different removal type */
 };
 
 #define acpi_driver_data(d)    ((d)->driver_data)
+#define to_acpi_device(d)      container_of(d, struct acpi_device, dev)
+#define to_acpi_driver(d)      container_of(d, struct acpi_driver, drv)
 
 /*
  * Events
index 6a5bdcefec6438ef81f6abcf5142cb843e035886..4dc8a5043ef033fd35042be6ad0999233c8db0ad 100644 (file)
 
 /* _HID definitions */
 
-#define ACPI_POWER_HID                 "ACPI_PWR"
-#define ACPI_PROCESSOR_HID             "ACPI_CPU"
-#define ACPI_SYSTEM_HID                        "ACPI_SYS"
-#define ACPI_THERMAL_HID               "ACPI_THM"
-#define ACPI_BUTTON_HID_POWERF         "ACPI_FPB"
-#define ACPI_BUTTON_HID_SLEEPF         "ACPI_FSB"
-
+#define ACPI_POWER_HID                 "power_resource"
+#define ACPI_PROCESSOR_HID             "ACPI0007"
+#define ACPI_SYSTEM_HID                        "acpi_system"
+#define ACPI_THERMAL_HID               "thermal"
+#define ACPI_BUTTON_HID_POWERF         "button_power"
+#define ACPI_BUTTON_HID_SLEEPF         "button_sleep"
+#define ACPI_VIDEO_HID                 "video"
+#define ACPI_BAY_HID                   "bay"
 /* --------------------------------------------------------------------------
                                        PCI
    -------------------------------------------------------------------------- */
index 0cd63bce0ae423d1905d37448879df7c802d79ac..781394b9efe0b630621e246450f4bc575f754b94 100644 (file)
@@ -8,7 +8,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -85,7 +85,7 @@ acpi_status acpi_os_terminate(void);
 /*
  * ACPI Table interfaces
  */
-acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *address);
+acpi_physical_address acpi_os_get_root_pointer(void);
 
 acpi_status
 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
@@ -143,9 +143,7 @@ void acpi_os_release_mutex(acpi_mutex handle);
  */
 void *acpi_os_allocate(acpi_size size);
 
-acpi_status
-acpi_os_map_memory(acpi_physical_address physical_address,
-                  acpi_size size, void __iomem ** logical_address);
+void __iomem *acpi_os_map_memory(acpi_physical_address where, acpi_native_uint length);
 
 void acpi_os_unmap_memory(void __iomem * logical_address, acpi_size size);
 
index 81458767a90e8815bc22b8b56d7389a3cb355a9d..e08f7df85a4fdc2974e2c7e8ff7ba777e032f4dc 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 /*
  * Global interfaces
  */
+acpi_status
+acpi_initialize_tables(struct acpi_table_desc *initial_storage,
+                      u32 initial_table_count, u8 allow_resize);
+
 acpi_status acpi_initialize_subsystem(void);
 
 acpi_status acpi_enable_subsystem(u32 flags);
@@ -92,30 +96,28 @@ void acpi_free(void *address);
 /*
  * ACPI table manipulation interfaces
  */
-acpi_status
-acpi_find_root_pointer(u32 flags, struct acpi_pointer *rsdp_address);
+acpi_status acpi_reallocate_root_table(void);
+
+acpi_status acpi_find_root_pointer(acpi_native_uint * rsdp_address);
 
 acpi_status acpi_load_tables(void);
 
 acpi_status acpi_load_table(struct acpi_table_header *table_ptr);
 
-acpi_status acpi_unload_table_id(acpi_table_type table_type, acpi_owner_id id);
+acpi_status acpi_unload_table_id(acpi_owner_id id);
 
-#ifdef ACPI_FUTURE_USAGE
-acpi_status acpi_unload_table(acpi_table_type table_type);
 acpi_status
-acpi_get_table_header(acpi_table_type table_type,
-                     u32 instance, struct acpi_table_header *out_table_header);
-#endif                         /*  ACPI_FUTURE_USAGE  */
+acpi_get_table_header(acpi_string signature,
+                     acpi_native_uint instance,
+                     struct acpi_table_header *out_table_header);
 
 acpi_status
-acpi_get_table(acpi_table_type table_type,
-              u32 instance, struct acpi_buffer *ret_buffer);
+acpi_get_table(acpi_string signature,
+              acpi_native_uint instance, struct acpi_table_header **out_table);
 
 acpi_status
-acpi_get_firmware_table(acpi_string signature,
-                       u32 instance,
-                       u32 flags, struct acpi_table_header **table_pointer);
+acpi_get_table_by_index(acpi_native_uint table_index,
+                       struct acpi_table_header **out_table);
 
 /*
  * Namespace and name interfaces
@@ -310,9 +312,9 @@ acpi_resource_to_address64(struct acpi_resource *resource,
 /*
  * Hardware (ACPI device) interfaces
  */
-acpi_status acpi_get_register(u32 register_id, u32 * return_value, u32 flags);
+acpi_status acpi_get_register(u32 register_id, u32 * return_value);
 
-acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags);
+acpi_status acpi_set_register(u32 register_id, u32 value);
 
 acpi_status
 acpi_set_firmware_waking_vector(acpi_physical_address physical_address);
index 80a3b33571b4c44df62457225e64d56f65a84fea..9486ab266a5e24b898e427d90f289b2988595b87 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 5e8095f0f78f882ff62df22e6c75d587cdeb6a2f..aeb4498e5e06047b52ea521e2a8ad69cb3428630 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -139,7 +139,8 @@ struct acpi_init_walk_info {
        u16 buffer_init;
        u16 package_init;
        u16 object_count;
-       struct acpi_table_desc *table_desc;
+       acpi_owner_id owner_id;
+       acpi_native_uint table_index;
 };
 
 struct acpi_get_devices_info {
index 4dbaf02fe526685d7def74b211db037c565674a1..2b9f46f9da4d8f9d1d71b6eec3b4723cab4c68ce 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #ifndef __ACTABLES_H__
 #define __ACTABLES_H__
 
-/* Used in acpi_tb_map_acpi_table for size parameter if table header is to be used */
-
-#define SIZE_IN_HEADER          0
+acpi_status acpi_allocate_root_table(u32 initial_table_count);
 
 /*
- * tbconvrt - Table conversion routines
+ * tbfadt - FADT parse/convert/validate
  */
-acpi_status acpi_tb_convert_to_xsdt(struct acpi_table_desc *table_info);
-
-acpi_status acpi_tb_convert_table_fadt(void);
+void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags);
 
-acpi_status acpi_tb_build_common_facs(struct acpi_table_desc *table_info);
-
-u32
-acpi_tb_get_table_count(struct rsdp_descriptor *RSDP,
-                       struct acpi_table_header *RSDT);
+void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length);
 
 /*
- * tbget - Table "get" routines
+ * tbfind - find ACPI table
  */
 acpi_status
-acpi_tb_get_table(struct acpi_pointer *address,
-                 struct acpi_table_desc *table_info);
-
-acpi_status
-acpi_tb_get_table_header(struct acpi_pointer *address,
-                        struct acpi_table_header *return_header);
-
-acpi_status
-acpi_tb_get_table_body(struct acpi_pointer *address,
-                      struct acpi_table_header *header,
-                      struct acpi_table_desc *table_info);
-
-acpi_status
-acpi_tb_get_table_ptr(acpi_table_type table_type,
-                     u32 instance, struct acpi_table_header **table_ptr_loc);
-
-acpi_status acpi_tb_verify_rsdp(struct acpi_pointer *address);
-
-void acpi_tb_get_rsdt_address(struct acpi_pointer *out_address);
-
-acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr);
+acpi_tb_find_table(char *signature,
+                  char *oem_id,
+                  char *oem_table_id, acpi_native_uint * table_index);
 
 /*
- * tbgetall - get multiple required tables
+ * tbinstal - Table removal and deletion
  */
-acpi_status acpi_tb_get_required_tables(void);
+acpi_status acpi_tb_resize_root_table_list(void);
 
-/*
- * tbinstall - Table installation
- */
-acpi_status acpi_tb_install_table(struct acpi_table_desc *table_info);
+acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc);
 
 acpi_status
-acpi_tb_recognize_table(struct acpi_table_desc *table_info, u8 search_type);
+acpi_tb_add_table(struct acpi_table_desc *table_desc,
+                 acpi_native_uint * table_index);
 
 acpi_status
-acpi_tb_init_table_descriptor(acpi_table_type table_type,
-                             struct acpi_table_desc *table_info);
+acpi_tb_store_table(acpi_physical_address address,
+                   struct acpi_table_header *table,
+                   u32 length, u8 flags, acpi_native_uint * table_index);
 
-/*
- * tbremove - Table removal and deletion
- */
-void acpi_tb_delete_all_tables(void);
+void acpi_tb_delete_table(struct acpi_table_desc *table_desc);
 
-void acpi_tb_delete_tables_by_type(acpi_table_type type);
+void acpi_tb_terminate(void);
 
-void acpi_tb_delete_single_table(struct acpi_table_desc *table_desc);
+void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index);
 
-struct acpi_table_desc *acpi_tb_uninstall_table(struct acpi_table_desc
-                                               *table_desc);
+acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index);
+
+acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index);
 
-/*
- * tbxfroot - RSDP, RSDT utilities
- */
 acpi_status
-acpi_tb_find_table(char *signature,
-                  char *oem_id,
-                  char *oem_table_id, struct acpi_table_header **table_ptr);
+acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id);
 
-acpi_status acpi_tb_get_table_rsdt(void);
+u8 acpi_tb_is_table_loaded(acpi_native_uint table_index);
 
-acpi_status acpi_tb_validate_rsdp(struct rsdp_descriptor *rsdp);
+void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded);
 
 /*
- * tbutils - common table utilities
+ * tbutils - table manager utilities
  */
-acpi_status acpi_tb_is_table_installed(struct acpi_table_desc *new_table_desc);
+u8 acpi_tb_tables_loaded(void);
 
-acpi_status
-acpi_tb_verify_table_checksum(struct acpi_table_header *table_header);
+void
+acpi_tb_print_table_header(acpi_physical_address address,
+                          struct acpi_table_header *header);
 
-u8 acpi_tb_sum_table(void *buffer, u32 length);
+u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length);
 
-u8 acpi_tb_generate_checksum(struct acpi_table_header *table);
+acpi_status
+acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length);
 
-void acpi_tb_set_checksum(struct acpi_table_header *table);
+void
+acpi_tb_install_table(acpi_physical_address address,
+                     u8 flags, char *signature, acpi_native_uint table_index);
 
 acpi_status
-acpi_tb_validate_table_header(struct acpi_table_header *table_header);
+acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags);
 
 #endif                         /* __ACTABLES_H__ */
index b125ceed9cb7696b20e9db6b5fb035f308f636d2..09469e7db6a542e6ae7ebbc8d1125b9d5e1c59e7 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * Values for description table header signatures. Useful because they make
  * it more difficult to inadvertently type in the wrong signature.
  */
-#define DSDT_SIG                "DSDT" /* Differentiated System Description Table */
-#define FADT_SIG                "FACP" /* Fixed ACPI Description Table */
-#define FACS_SIG                "FACS" /* Firmware ACPI Control Structure */
-#define PSDT_SIG                "PSDT" /* Persistent System Description Table */
-#define RSDP_SIG                "RSD PTR "     /* Root System Description Pointer */
-#define RSDT_SIG                "RSDT" /* Root System Description Table */
-#define XSDT_SIG                "XSDT" /* Extended  System Description Table */
-#define SSDT_SIG                "SSDT" /* Secondary System Description Table */
-#define RSDP_NAME               "RSDP"
+#define ACPI_SIG_DSDT           "DSDT" /* Differentiated System Description Table */
+#define ACPI_SIG_FADT           "FACP" /* Fixed ACPI Description Table */
+#define ACPI_SIG_FACS           "FACS" /* Firmware ACPI Control Structure */
+#define ACPI_SIG_PSDT           "PSDT" /* Persistent System Description Table */
+#define ACPI_SIG_RSDP           "RSD PTR "     /* Root System Description Pointer */
+#define ACPI_SIG_RSDT           "RSDT" /* Root System Description Table */
+#define ACPI_SIG_XSDT           "XSDT" /* Extended  System Description Table */
+#define ACPI_SIG_SSDT           "SSDT" /* Secondary System Description Table */
+#define ACPI_RSDP_NAME          "RSDP" /* Short name for RSDP, not signature */
 
 /*
  * All tables and structures must be byte-packed to match the ACPI
  *
  ******************************************************************************/
 
-#define ACPI_TABLE_HEADER_DEF \
-       char                            signature[4];           /* ASCII table signature */\
-       u32                             length;                 /* Length of table in bytes, including this header */\
-       u8                              revision;               /* ACPI Specification minor version # */\
-       u8                              checksum;               /* To make sum of entire table == 0 */\
-       char                            oem_id[6];              /* ASCII OEM identification */\
-       char                            oem_table_id[8];        /* ASCII OEM table identification */\
-       u32                             oem_revision;           /* OEM revision number */\
-       char                            asl_compiler_id[4];     /* ASCII ASL compiler vendor ID */\
-       u32                             asl_compiler_revision;  /* ASL compiler version */
-
 struct acpi_table_header {
-ACPI_TABLE_HEADER_DEF};
+       char signature[ACPI_NAME_SIZE]; /* ASCII table signature */
+       u32 length;             /* Length of table in bytes, including this header */
+       u8 revision;            /* ACPI Specification minor version # */
+       u8 checksum;            /* To make sum of entire table == 0 */
+       char oem_id[ACPI_OEM_ID_SIZE];  /* ASCII OEM identification */
+       char oem_table_id[ACPI_OEM_TABLE_ID_SIZE];      /* ASCII OEM table identification */
+       u32 oem_revision;       /* OEM revision number */
+       char asl_compiler_id[ACPI_NAME_SIZE];   /* ASCII ASL compiler vendor ID */
+       u32 asl_compiler_revision;      /* ASL compiler version */
+};
 
 /*
  * GAS - Generic Address Structure (ACPI 2.0+)
+ *
+ * Note: Since this structure is used in the ACPI tables, it is byte aligned.
+ * If misalignment is not supported, access to the Address field must be
+ * performed with care.
  */
 struct acpi_generic_address {
-       u8 address_space_id;    /* Address space where struct or register exists */
-       u8 register_bit_width;  /* Size in bits of given register */
-       u8 register_bit_offset; /* Bit offset within the register */
+       u8 space_id;            /* Address space where struct or register exists */
+       u8 bit_width;           /* Size in bits of given register */
+       u8 bit_offset;          /* Bit offset within the register */
        u8 access_width;        /* Minimum Access size (ACPI 3.0) */
        u64 address;            /* 64-bit address of struct or register */
 };
@@ -114,10 +116,10 @@ struct acpi_generic_address {
  *
  ******************************************************************************/
 
-struct rsdp_descriptor {
+struct acpi_table_rsdp {
        char signature[8];      /* ACPI signature, contains "RSD PTR " */
        u8 checksum;            /* ACPI 1.0 checksum */
-       char oem_id[6];         /* OEM identification */
+       char oem_id[ACPI_OEM_ID_SIZE];  /* OEM identification */
        u8 revision;            /* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */
        u32 rsdt_physical_address;      /* 32-bit physical address of the RSDT */
        u32 length;             /* Table length in bytes, including header (ACPI 2.0+) */
@@ -134,12 +136,14 @@ struct rsdp_descriptor {
  *
  ******************************************************************************/
 
-struct rsdt_descriptor {
-       ACPI_TABLE_HEADER_DEF u32 table_offset_entry[1];        /* Array of pointers to ACPI tables */
+struct acpi_table_rsdt {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u32 table_offset_entry[1];      /* Array of pointers to ACPI tables */
 };
 
-struct xsdt_descriptor {
-       ACPI_TABLE_HEADER_DEF u64 table_offset_entry[1];        /* Array of pointers to ACPI tables */
+struct acpi_table_xsdt {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u64 table_offset_entry[1];      /* Array of pointers to ACPI tables */
 };
 
 /*******************************************************************************
@@ -148,36 +152,27 @@ struct xsdt_descriptor {
  *
  ******************************************************************************/
 
-struct facs_descriptor {
+struct acpi_table_facs {
        char signature[4];      /* ASCII table signature */
        u32 length;             /* Length of structure, in bytes */
        u32 hardware_signature; /* Hardware configuration signature */
        u32 firmware_waking_vector;     /* 32-bit physical address of the Firmware Waking Vector */
        u32 global_lock;        /* Global Lock for shared hardware resources */
-
-       /* Flags (32 bits) */
-
-       u8 S4bios_f:1;          /* 00:    S4BIOS support is present */
-        u8:7;                  /* 01-07: Reserved, must be zero */
-       u8 reserved1[3];        /* 08-31: Reserved, must be zero */
-
+       u32 flags;
        u64 xfirmware_waking_vector;    /* 64-bit version of the Firmware Waking Vector (ACPI 2.0+) */
        u8 version;             /* Version of this table (ACPI 2.0+) */
        u8 reserved[31];        /* Reserved, must be zero */
 };
 
+/* Flag macros */
+
+#define ACPI_FACS_S4_BIOS_PRESENT (1)  /* 00: S4BIOS support is present */
+
+/* Global lock flags */
+
 #define ACPI_GLOCK_PENDING      0x01   /* 00: Pending global lock ownership */
 #define ACPI_GLOCK_OWNED        0x02   /* 01: Global lock is owned */
 
-/*
- * Common FACS - This is a version-independent FACS structure used for internal use only
- */
-struct acpi_common_facs {
-       u32 *global_lock;
-       u64 *firmware_waking_vector;
-       u8 vector_width;
-};
-
 /*******************************************************************************
  *
  * FADT - Fixed ACPI Description Table (Signature "FACP")
@@ -186,121 +181,98 @@ struct acpi_common_facs {
 
 /* Fields common to all versions of the FADT */
 
-#define ACPI_FADT_COMMON \
-       ACPI_TABLE_HEADER_DEF \
-       u32                             V1_firmware_ctrl;   /* 32-bit physical address of FACS */ \
-       u32                             V1_dsdt;            /* 32-bit physical address of DSDT */ \
-       u8                              reserved1;          /* System Interrupt Model isn't used in ACPI 2.0*/ \
-       u8                              prefer_PM_profile;  /* Conveys preferred power management profile to OSPM. */ \
-       u16                             sci_int;            /* System vector of SCI interrupt */ \
-       u32                             smi_cmd;            /* Port address of SMI command port */ \
-       u8                              acpi_enable;        /* Value to write to smi_cmd to enable ACPI */ \
-       u8                              acpi_disable;       /* Value to write to smi_cmd to disable ACPI */ \
-       u8                              S4bios_req;         /* Value to write to SMI CMD to enter S4BIOS state */ \
-       u8                              pstate_cnt;         /* Processor performance state control*/ \
-       u32                             V1_pm1a_evt_blk;    /* Port address of Power Mgt 1a Event Reg Blk */ \
-       u32                             V1_pm1b_evt_blk;    /* Port address of Power Mgt 1b Event Reg Blk */ \
-       u32                             V1_pm1a_cnt_blk;    /* Port address of Power Mgt 1a Control Reg Blk */ \
-       u32                             V1_pm1b_cnt_blk;    /* Port address of Power Mgt 1b Control Reg Blk */ \
-       u32                             V1_pm2_cnt_blk;     /* Port address of Power Mgt 2 Control Reg Blk */ \
-       u32                             V1_pm_tmr_blk;      /* Port address of Power Mgt Timer Ctrl Reg Blk */ \
-       u32                             V1_gpe0_blk;        /* Port addr of General Purpose acpi_event 0 Reg Blk */ \
-       u32                             V1_gpe1_blk;        /* Port addr of General Purpose acpi_event 1 Reg Blk */ \
-       u8                              pm1_evt_len;        /* Byte Length of ports at pm1_x_evt_blk */ \
-       u8                              pm1_cnt_len;        /* Byte Length of ports at pm1_x_cnt_blk */ \
-       u8                              pm2_cnt_len;        /* Byte Length of ports at pm2_cnt_blk */ \
-       u8                              pm_tm_len;          /* Byte Length of ports at pm_tm_blk */ \
-       u8                              gpe0_blk_len;       /* Byte Length of ports at gpe0_blk */ \
-       u8                              gpe1_blk_len;       /* Byte Length of ports at gpe1_blk */ \
-       u8                              gpe1_base;          /* Offset in gpe model where gpe1 events start */ \
-       u8                              cst_cnt;            /* Support for the _CST object and C States change notification.*/ \
-       u16                             plvl2_lat;          /* Worst case HW latency to enter/exit C2 state */ \
-       u16                             plvl3_lat;          /* Worst case HW latency to enter/exit C3 state */ \
-       u16                             flush_size;         /* Processor's memory cache line width, in bytes */ \
-       u16                             flush_stride;       /* Number of flush strides that need to be read */ \
-       u8                              duty_offset;        /* Processor's duty cycle index in processor's P_CNT reg*/ \
-       u8                              duty_width;         /* Processor's duty cycle value bit width in P_CNT register.*/ \
-       u8                              day_alrm;           /* Index to day-of-month alarm in RTC CMOS RAM */ \
-       u8                              mon_alrm;           /* Index to month-of-year alarm in RTC CMOS RAM */ \
-       u8                              century;            /* Index to century in RTC CMOS RAM */ \
-       u16                             iapc_boot_arch;     /* IA-PC Boot Architecture Flags. See Table 5-10 for description*/ \
-       u8                              reserved2;          /* Reserved, must be zero */
-
-/*
- * ACPI 2.0+ FADT
- */
-struct fadt_descriptor {
-       ACPI_FADT_COMMON
-           /* Flags (32 bits) */
-       u8 wb_invd:1;           /* 00:    The wbinvd instruction works properly */
-       u8 wb_invd_flush:1;     /* 01:    The wbinvd flushes but does not invalidate */
-       u8 proc_c1:1;           /* 02:    All processors support C1 state */
-       u8 plvl2_up:1;          /* 03:    C2 state works on MP system */
-       u8 pwr_button:1;        /* 04:    Power button is handled as a generic feature */
-       u8 sleep_button:1;      /* 05:    Sleep button is handled as a generic feature, or not present */
-       u8 fixed_rTC:1;         /* 06:    RTC wakeup stat not in fixed register space */
-       u8 rtcs4:1;             /* 07:    RTC wakeup stat not possible from S4 */
-       u8 tmr_val_ext:1;       /* 08:    tmr_val is 32 bits 0=24-bits */
-       u8 dock_cap:1;          /* 09:    Docking supported */
-       u8 reset_reg_sup:1;     /* 10:    System reset via the FADT RESET_REG supported */
-       u8 sealed_case:1;       /* 11:    No internal expansion capabilities and case is sealed */
-       u8 headless:1;          /* 12:    No local video capabilities or local input devices */
-       u8 cpu_sw_sleep:1;      /* 13:    Must execute native instruction after writing SLP_TYPx register */
-
-       u8 pci_exp_wak:1;       /* 14:    System supports PCIEXP_WAKE (STS/EN) bits (ACPI 3.0) */
-       u8 use_platform_clock:1;        /* 15:    OSPM should use platform-provided timer (ACPI 3.0) */
-       u8 S4rtc_sts_valid:1;   /* 16:    Contents of RTC_STS valid after S4 wake (ACPI 3.0) */
-       u8 remote_power_on_capable:1;   /* 17:    System is compatible with remote power on (ACPI 3.0) */
-       u8 force_apic_cluster_model:1;  /* 18:    All local APICs must use cluster model (ACPI 3.0) */
-       u8 force_apic_physical_destination_mode:1;      /* 19:   All local x_aPICs must use physical dest mode (ACPI 3.0) */
-        u8:4;                  /* 20-23: Reserved, must be zero */
-       u8 reserved3;           /* 24-31: Reserved, must be zero */
-
-       struct acpi_generic_address reset_register;     /* Reset register address in GAS format */
+struct acpi_table_fadt {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u32 facs;               /* 32-bit physical address of FACS */
+       u32 dsdt;               /* 32-bit physical address of DSDT */
+       u8 model;               /* System Interrupt Model (ACPI 1.0) - not used in ACPI 2.0+ */
+       u8 preferred_profile;   /* Conveys preferred power management profile to OSPM. */
+       u16 sci_interrupt;      /* System vector of SCI interrupt */
+       u32 smi_command;        /* 32-bit Port address of SMI command port */
+       u8 acpi_enable;         /* Value to write to smi_cmd to enable ACPI */
+       u8 acpi_disable;        /* Value to write to smi_cmd to disable ACPI */
+       u8 S4bios_request;      /* Value to write to SMI CMD to enter S4BIOS state */
+       u8 pstate_control;      /* Processor performance state control */
+       u32 pm1a_event_block;   /* 32-bit Port address of Power Mgt 1a Event Reg Blk */
+       u32 pm1b_event_block;   /* 32-bit Port address of Power Mgt 1b Event Reg Blk */
+       u32 pm1a_control_block; /* 32-bit Port address of Power Mgt 1a Control Reg Blk */
+       u32 pm1b_control_block; /* 32-bit Port address of Power Mgt 1b Control Reg Blk */
+       u32 pm2_control_block;  /* 32-bit Port address of Power Mgt 2 Control Reg Blk */
+       u32 pm_timer_block;     /* 32-bit Port address of Power Mgt Timer Ctrl Reg Blk */
+       u32 gpe0_block;         /* 32-bit Port address of General Purpose Event 0 Reg Blk */
+       u32 gpe1_block;         /* 32-bit Port address of General Purpose Event 1 Reg Blk */
+       u8 pm1_event_length;    /* Byte Length of ports at pm1x_event_block */
+       u8 pm1_control_length;  /* Byte Length of ports at pm1x_control_block */
+       u8 pm2_control_length;  /* Byte Length of ports at pm2_control_block */
+       u8 pm_timer_length;     /* Byte Length of ports at pm_timer_block */
+       u8 gpe0_block_length;   /* Byte Length of ports at gpe0_block */
+       u8 gpe1_block_length;   /* Byte Length of ports at gpe1_block */
+       u8 gpe1_base;           /* Offset in GPE number space where GPE1 events start */
+       u8 cst_control;         /* Support for the _CST object and C States change notification */
+       u16 C2latency;          /* Worst case HW latency to enter/exit C2 state */
+       u16 C3latency;          /* Worst case HW latency to enter/exit C3 state */
+       u16 flush_size;         /* Processor's memory cache line width, in bytes */
+       u16 flush_stride;       /* Number of flush strides that need to be read */
+       u8 duty_offset;         /* Processor duty cycle index in processor's P_CNT reg */
+       u8 duty_width;          /* Processor duty cycle value bit width in P_CNT register. */
+       u8 day_alarm;           /* Index to day-of-month alarm in RTC CMOS RAM */
+       u8 month_alarm;         /* Index to month-of-year alarm in RTC CMOS RAM */
+       u8 century;             /* Index to century in RTC CMOS RAM */
+       u16 boot_flags;         /* IA-PC Boot Architecture Flags. See Table 5-10 for description */
+       u8 reserved;            /* Reserved, must be zero */
+       u32 flags;              /* Miscellaneous flag bits (see below for individual flags) */
+       struct acpi_generic_address reset_register;     /* 64-bit address of the Reset register */
        u8 reset_value;         /* Value to write to the reset_register port to reset the system */
-       u8 reserved4[3];        /* These three bytes must be zero */
-       u64 xfirmware_ctrl;     /* 64-bit physical address of FACS */
+       u8 reserved4[3];        /* Reserved, must be zero */
+       u64 Xfacs;              /* 64-bit physical address of FACS */
        u64 Xdsdt;              /* 64-bit physical address of DSDT */
-       struct acpi_generic_address xpm1a_evt_blk;      /* Extended Power Mgt 1a acpi_event Reg Blk address */
-       struct acpi_generic_address xpm1b_evt_blk;      /* Extended Power Mgt 1b acpi_event Reg Blk address */
-       struct acpi_generic_address xpm1a_cnt_blk;      /* Extended Power Mgt 1a Control Reg Blk address */
-       struct acpi_generic_address xpm1b_cnt_blk;      /* Extended Power Mgt 1b Control Reg Blk address */
-       struct acpi_generic_address xpm2_cnt_blk;       /* Extended Power Mgt 2 Control Reg Blk address */
-       struct acpi_generic_address xpm_tmr_blk;        /* Extended Power Mgt Timer Ctrl Reg Blk address */
-       struct acpi_generic_address xgpe0_blk;  /* Extended General Purpose acpi_event 0 Reg Blk address */
-       struct acpi_generic_address xgpe1_blk;  /* Extended General Purpose acpi_event 1 Reg Blk address */
+       struct acpi_generic_address xpm1a_event_block;  /* 64-bit Extended Power Mgt 1a Event Reg Blk address */
+       struct acpi_generic_address xpm1b_event_block;  /* 64-bit Extended Power Mgt 1b Event Reg Blk address */
+       struct acpi_generic_address xpm1a_control_block;        /* 64-bit Extended Power Mgt 1a Control Reg Blk address */
+       struct acpi_generic_address xpm1b_control_block;        /* 64-bit Extended Power Mgt 1b Control Reg Blk address */
+       struct acpi_generic_address xpm2_control_block; /* 64-bit Extended Power Mgt 2 Control Reg Blk address */
+       struct acpi_generic_address xpm_timer_block;    /* 64-bit Extended Power Mgt Timer Ctrl Reg Blk address */
+       struct acpi_generic_address xgpe0_block;        /* 64-bit Extended General Purpose Event 0 Reg Blk address */
+       struct acpi_generic_address xgpe1_block;        /* 64-bit Extended General Purpose Event 1 Reg Blk address */
 };
 
-/*
- * "Down-revved" ACPI 2.0 FADT descriptor
- * Defined here to allow compiler to generate the length of the struct
- */
-struct fadt_descriptor_rev2_minus {
-       ACPI_FADT_COMMON u32 flags;
-       struct acpi_generic_address reset_register;     /* Reset register address in GAS format */
-       u8 reset_value;         /* Value to write to the reset_register port to reset the system. */
-       u8 reserved7[3];        /* Reserved, must be zero */
-};
+/* FADT flags */
+
+#define ACPI_FADT_WBINVD            (1)        /* 00: The wbinvd instruction works properly */
+#define ACPI_FADT_WBINVD_FLUSH      (1<<1)     /* 01: The wbinvd flushes but does not invalidate */
+#define ACPI_FADT_C1_SUPPORTED      (1<<2)     /* 02: All processors support C1 state */
+#define ACPI_FADT_C2_MP_SUPPORTED   (1<<3)     /* 03: C2 state works on MP system */
+#define ACPI_FADT_POWER_BUTTON      (1<<4)     /* 04: Power button is handled as a generic feature */
+#define ACPI_FADT_SLEEP_BUTTON      (1<<5)     /* 05: Sleep button is handled as a generic feature, or  not present */
+#define ACPI_FADT_FIXED_RTC         (1<<6)     /* 06: RTC wakeup stat not in fixed register space */
+#define ACPI_FADT_S4_RTC_WAKE       (1<<7)     /* 07: RTC wakeup stat not possible from S4 */
+#define ACPI_FADT_32BIT_TIMER       (1<<8)     /* 08: tmr_val is 32 bits 0=24-bits */
+#define ACPI_FADT_DOCKING_SUPPORTED (1<<9)     /* 09: Docking supported */
+#define ACPI_FADT_RESET_REGISTER    (1<<10)    /* 10: System reset via the FADT RESET_REG supported */
+#define ACPI_FADT_SEALED_CASE       (1<<11)    /* 11: No internal expansion capabilities and case is sealed */
+#define ACPI_FADT_HEADLESS          (1<<12)    /* 12: No local video capabilities or local input devices */
+#define ACPI_FADT_SLEEP_TYPE        (1<<13)    /* 13: Must execute native instruction after writing  SLP_TYPx register */
+#define ACPI_FADT_PCI_EXPRESS_WAKE  (1<<14)    /* 14: System supports PCIEXP_WAKE (STS/EN) bits (ACPI 3.0) */
+#define ACPI_FADT_PLATFORM_CLOCK    (1<<15)    /* 15: OSPM should use platform-provided timer (ACPI 3.0) */
+#define ACPI_FADT_S4_RTC_VALID      (1<<16)    /* 16: Contents of RTC_STS valid after S4 wake (ACPI 3.0) */
+#define ACPI_FADT_REMOTE_POWER_ON   (1<<17)    /* 17: System is compatible with remote power on (ACPI 3.0) */
+#define ACPI_FADT_APIC_CLUSTER      (1<<18)    /* 18: All local APICs must use cluster model (ACPI 3.0) */
+#define ACPI_FADT_APIC_PHYSICAL     (1<<19)    /* 19: All local x_aPICs must use physical dest mode (ACPI 3.0) */
 
 /*
- * ACPI 1.0 FADT
- * Defined here to allow compiler to generate the length of the struct
+ * FADT Prefered Power Management Profiles
  */
-struct fadt_descriptor_rev1 {
-       ACPI_FADT_COMMON u32 flags;
+enum acpi_prefered_pm_profiles {
+       PM_UNSPECIFIED = 0,
+       PM_DESKTOP = 1,
+       PM_MOBILE = 2,
+       PM_WORKSTATION = 3,
+       PM_ENTERPRISE_SERVER = 4,
+       PM_SOHO_SERVER = 5,
+       PM_APPLIANCE_PC = 6
 };
 
-/* FADT: Prefered Power Management Profiles */
-
-#define PM_UNSPECIFIED                  0
-#define PM_DESKTOP                      1
-#define PM_MOBILE                       2
-#define PM_WORKSTATION                  3
-#define PM_ENTERPRISE_SERVER            4
-#define PM_SOHO_SERVER                  5
-#define PM_APPLIANCE_PC                 6
-
-/* FADT: Boot Arch Flags */
+/* FADT Boot Arch Flags */
 
 #define BAF_LEGACY_DEVICES              0x0001
 #define BAF_8042_KEYBOARD_CONTROLLER    0x0002
@@ -312,59 +284,12 @@ struct fadt_descriptor_rev1 {
 
 #pragma pack()
 
-/*
- * This macro is temporary until the table bitfield flag definitions
- * are removed and replaced by a Flags field.
- */
-#define ACPI_FLAG_OFFSET(d,f,o)         (u8) (ACPI_OFFSET (d,f) + \
-                         sizeof(((d *)0)->f) + o)
-/*
- * Get the remaining ACPI tables
- */
-#include "actbl1.h"
+#define ACPI_FADT_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_table_fadt, f)
 
 /*
- * ACPI Table information.  We save the table address, length,
- * and type of memory allocation (mapped or allocated) for each
- * table for 1) when we exit, and 2) if a new table is installed
+ * Get the remaining ACPI tables
  */
-#define ACPI_MEM_NOT_ALLOCATED  0
-#define ACPI_MEM_ALLOCATED      1
-#define ACPI_MEM_MAPPED         2
-
-/* Definitions for the Flags bitfield member of struct acpi_table_support */
-
-#define ACPI_TABLE_SINGLE       0x00
-#define ACPI_TABLE_MULTIPLE     0x01
-#define ACPI_TABLE_EXECUTABLE   0x02
-
-#define ACPI_TABLE_ROOT         0x00
-#define ACPI_TABLE_PRIMARY      0x10
-#define ACPI_TABLE_SECONDARY    0x20
-#define ACPI_TABLE_ALL          0x30
-#define ACPI_TABLE_TYPE_MASK    0x30
-
-/* Data about each known table type */
-
-struct acpi_table_support {
-       char *name;
-       char *signature;
-       void **global_ptr;
-       u8 sig_length;
-       u8 flags;
-};
-
-extern u8 acpi_fadt_is_v1;     /* is set to 1 if FADT is revision 1,
-                                * needed for certain workarounds */
-/* Macros used to generate offsets to specific table fields */
-
-#define ACPI_FACS_OFFSET(f)             (u8) ACPI_OFFSET (struct facs_descriptor,f)
-#define ACPI_FADT_OFFSET(f)             (u8) ACPI_OFFSET (struct fadt_descriptor, f)
-#define ACPI_GAS_OFFSET(f)              (u8) ACPI_OFFSET (struct acpi_generic_address,f)
-#define ACPI_HDR_OFFSET(f)              (u8) ACPI_OFFSET (struct acpi_table_header,f)
-#define ACPI_RSDP_OFFSET(f)             (u8) ACPI_OFFSET (struct rsdp_descriptor,f)
 
-#define ACPI_FADT_FLAG_OFFSET(f,o)      ACPI_FLAG_OFFSET (struct fadt_descriptor,f,o)
-#define ACPI_FACS_FLAG_OFFSET(f,o)      ACPI_FLAG_OFFSET (struct facs_descriptor,f,o)
+#include <acpi/actbl1.h>
 
 #endif                         /* __ACTBL_H__ */
index 745a6445a4f919cb237a0b3e9761a121729966f9..4e5d3ca53a8eb15d6ae209d187f15404a7edf0bc 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -61,6 +61,7 @@
 #define ACPI_SIG_BOOT           "BOOT" /* Simple Boot Flag Table */
 #define ACPI_SIG_CPEP           "CPEP" /* Corrected Platform Error Polling table */
 #define ACPI_SIG_DBGP           "DBGP" /* Debug Port table */
+#define ACPI_SIG_DMAR           "DMAR" /* DMA Remapping table */
 #define ACPI_SIG_ECDT           "ECDT" /* Embedded Controller Boot Resources Table */
 #define ACPI_SIG_HPET           "HPET" /* High Precision Event Timer table */
 #define ACPI_SIG_MADT           "APIC" /* Multiple APIC Description Table */
 #define ACPI_SIG_TCPA           "TCPA" /* Trusted Computing Platform Alliance table */
 #define ACPI_SIG_WDRT           "WDRT" /* Watchdog Resource Table */
 
-/* Legacy names */
-
-#define APIC_SIG                "APIC" /* Multiple APIC Description Table */
-#define BOOT_SIG                "BOOT" /* Simple Boot Flag Table */
-#define SBST_SIG                "SBST" /* Smart Battery Specification Table */
-
 /*
  * All tables must be byte-packed to match the ACPI specification, since
  * the tables are provided by the system BIOS.
  * portable, so do not use any other bitfield types.
  */
 
+/* Common Sub-table header (used in MADT, SRAT, etc.) */
+
+struct acpi_subtable_header {
+       u8 type;
+       u8 length;
+};
+
 /*******************************************************************************
  *
  * ASF - Alert Standard Format table (Signature "ASF!")
  *
+ * Conforms to the Alert Standard Format Specification V2.0, 23 April 2003
+ *
  ******************************************************************************/
 
 struct acpi_table_asf {
-ACPI_TABLE_HEADER_DEF};
+       struct acpi_table_header header;        /* Common ACPI table header */
+};
 
-#define ACPI_ASF_HEADER_DEF \
-       u8                              type; \
-       u8                              reserved; \
-       u16                             length;
+/* ASF subtable header */
 
 struct acpi_asf_header {
-ACPI_ASF_HEADER_DEF};
+       u8 type;
+       u8 reserved;
+       u16 length;
+};
 
-/* Values for Type field */
+/* Values for Type field above */
 
-#define ASF_INFO                0
-#define ASF_ALERT               1
-#define ASF_CONTROL             2
-#define ASF_BOOT                3
-#define ASF_ADDRESS             4
-#define ASF_RESERVED            5
+enum acpi_asf_type {
+       ACPI_ASF_TYPE_INFO = 0,
+       ACPI_ASF_TYPE_ALERT = 1,
+       ACPI_ASF_TYPE_CONTROL = 2,
+       ACPI_ASF_TYPE_BOOT = 3,
+       ACPI_ASF_TYPE_ADDRESS = 4,
+       ACPI_ASF_TYPE_RESERVED = 5
+};
 
 /*
  * ASF subtables
@@ -124,7 +131,8 @@ ACPI_ASF_HEADER_DEF};
 /* 0: ASF Information */
 
 struct acpi_asf_info {
-       ACPI_ASF_HEADER_DEF u8 min_reset_value;
+       struct acpi_asf_header header;
+       u8 min_reset_value;
        u8 min_poll_interval;
        u16 system_id;
        u32 mfg_id;
@@ -135,26 +143,49 @@ struct acpi_asf_info {
 /* 1: ASF Alerts */
 
 struct acpi_asf_alert {
-       ACPI_ASF_HEADER_DEF u8 assert_mask;
+       struct acpi_asf_header header;
+       u8 assert_mask;
        u8 deassert_mask;
        u8 alerts;
        u8 data_length;
-       u8 array[1];
+};
+
+struct acpi_asf_alert_data {
+       u8 address;
+       u8 command;
+       u8 mask;
+       u8 value;
+       u8 sensor_type;
+       u8 type;
+       u8 offset;
+       u8 source_type;
+       u8 severity;
+       u8 sensor_number;
+       u8 entity;
+       u8 instance;
 };
 
 /* 2: ASF Remote Control */
 
 struct acpi_asf_remote {
-       ACPI_ASF_HEADER_DEF u8 controls;
+       struct acpi_asf_header header;
+       u8 controls;
        u8 data_length;
        u16 reserved2;
-       u8 array[1];
+};
+
+struct acpi_asf_control_data {
+       u8 function;
+       u8 address;
+       u8 command;
+       u8 value;
 };
 
 /* 3: ASF RMCP Boot Options */
 
 struct acpi_asf_rmcp {
-       ACPI_ASF_HEADER_DEF u8 capabilities[7];
+       struct acpi_asf_header header;
+       u8 capabilities[7];
        u8 completion_code;
        u32 enterprise_id;
        u8 command;
@@ -166,9 +197,9 @@ struct acpi_asf_rmcp {
 /* 4: ASF Address */
 
 struct acpi_asf_address {
-       ACPI_ASF_HEADER_DEF u8 eprom_address;
+       struct acpi_asf_header header;
+       u8 eprom_address;
        u8 devices;
-       u8 smbus_addresses[1];
 };
 
 /*******************************************************************************
@@ -178,7 +209,8 @@ struct acpi_asf_address {
  ******************************************************************************/
 
 struct acpi_table_boot {
-       ACPI_TABLE_HEADER_DEF u8 cmos_index;    /* Index in CMOS RAM for the boot register */
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u8 cmos_index;          /* Index in CMOS RAM for the boot register */
        u8 reserved[3];
 };
 
@@ -189,7 +221,8 @@ struct acpi_table_boot {
  ******************************************************************************/
 
 struct acpi_table_cpep {
-       ACPI_TABLE_HEADER_DEF u64 reserved;
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u64 reserved;
 };
 
 /* Subtable */
@@ -197,9 +230,9 @@ struct acpi_table_cpep {
 struct acpi_cpep_polling {
        u8 type;
        u8 length;
-       u8 processor_id;        /* Processor ID */
-       u8 processor_eid;       /* Processor EID */
-       u32 polling_interval;   /* Polling interval (msec) */
+       u8 id;                  /* Processor ID */
+       u8 eid;                 /* Processor EID */
+       u32 interval;           /* Polling interval (msec) */
 };
 
 /*******************************************************************************
@@ -209,196 +242,281 @@ struct acpi_cpep_polling {
  ******************************************************************************/
 
 struct acpi_table_dbgp {
-       ACPI_TABLE_HEADER_DEF u8 interface_type;        /* 0=full 16550, 1=subset of 16550 */
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u8 type;                /* 0=full 16550, 1=subset of 16550 */
        u8 reserved[3];
        struct acpi_generic_address debug_port;
 };
 
 /*******************************************************************************
  *
- * ECDT - Embedded Controller Boot Resources Table
+ * DMAR - DMA Remapping table
  *
  ******************************************************************************/
 
-struct ec_boot_resources {
-       ACPI_TABLE_HEADER_DEF struct acpi_generic_address ec_control;   /* Address of EC command/status register */
-       struct acpi_generic_address ec_data;    /* Address of EC data register */
-       u32 uid;                /* Unique ID - must be same as the EC _UID method */
-       u8 gpe_bit;             /* The GPE for the EC */
-       u8 ec_id[1];            /* Full namepath of the EC in the ACPI namespace */
+struct acpi_table_dmar {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u8 width;               /* Host Address Width */
+       u8 reserved[11];
+};
+
+/* DMAR subtable header */
+
+struct acpi_dmar_header {
+       u16 type;
+       u16 length;
+       u8 flags;
+       u8 reserved[3];
+};
+
+/* Values for subtable type in struct acpi_dmar_header */
+
+enum acpi_dmar_type {
+       ACPI_DMAR_TYPE_HARDWARE_UNIT = 0,
+       ACPI_DMAR_TYPE_RESERVED_MEMORY = 1,
+       ACPI_DMAR_TYPE_RESERVED = 2     /* 2 and greater are reserved */
+};
+
+struct acpi_dmar_device_scope {
+       u8 entry_type;
+       u8 length;
+       u8 segment;
+       u8 bus;
+};
+
+/* Values for entry_type in struct acpi_dmar_device_scope */
+
+enum acpi_dmar_scope_type {
+       ACPI_DMAR_SCOPE_TYPE_NOT_USED = 0,
+       ACPI_DMAR_SCOPE_TYPE_ENDPOINT = 1,
+       ACPI_DMAR_SCOPE_TYPE_BRIDGE = 2,
+       ACPI_DMAR_SCOPE_TYPE_RESERVED = 3       /* 3 and greater are reserved */
+};
+
+/*
+ * DMAR Sub-tables, correspond to Type in struct acpi_dmar_header
+ */
+
+/* 0: Hardware Unit Definition */
+
+struct acpi_dmar_hardware_unit {
+       struct acpi_dmar_header header;
+       u64 address;            /* Register Base Address */
+};
+
+/* Flags */
+
+#define ACPI_DMAR_INCLUDE_ALL       (1)
+
+/* 1: Reserved Memory Defininition */
+
+struct acpi_dmar_reserved_memory {
+       struct acpi_dmar_header header;
+       u64 address;            /* 4_k aligned base address */
+       u64 end_address;        /* 4_k aligned limit address */
 };
 
+/* Flags */
+
+#define ACPI_DMAR_ALLOW_ALL         (1)
+
 /*******************************************************************************
  *
- * HPET - High Precision Event Timer table
+ * ECDT - Embedded Controller Boot Resources Table
  *
  ******************************************************************************/
 
-struct acpi_hpet_table {
-       ACPI_TABLE_HEADER_DEF u32 hardware_id;  /* Hardware ID of event timer block */
-       struct acpi_generic_address base_address;       /* Address of event timer block */
-       u8 hpet_number;         /* HPET sequence number */
-       u16 clock_tick;         /* Main counter min tick, periodic mode */
-       u8 attributes;
+struct acpi_table_ecdt {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       struct acpi_generic_address control;    /* Address of EC command/status register */
+       struct acpi_generic_address data;       /* Address of EC data register */
+       u32 uid;                /* Unique ID - must be same as the EC _UID method */
+       u8 gpe;                 /* The GPE for the EC */
+       u8 id[1];               /* Full namepath of the EC in the ACPI namespace */
 };
 
-#if 0                          /* HPET flags to be converted to macros */
-struct {                       /* Flags (8 bits) */
-       u8 page_protect:1;      /* 00:    No page protection */
-       u8 page_protect4:1;     /* 01:    4_kB page protected */
-       u8 page_protect64:1;    /* 02:    64_kB page protected */
-        u8:5;                  /* 03-07: Reserved, must be zero */
-} flags;
-#endif
-
 /*******************************************************************************
  *
- * MADT - Multiple APIC Description Table
+ * HPET - High Precision Event Timer table
  *
  ******************************************************************************/
 
-struct multiple_apic_table {
-       ACPI_TABLE_HEADER_DEF u32 local_apic_address;   /* Physical address of local APIC */
-
-       /* Flags (32 bits) */
-
-       u8 PCATcompat:1;        /* 00:    System also has dual 8259s */
-        u8:7;                  /* 01-07: Reserved, must be zero */
-       u8 reserved1[3];        /* 08-31: Reserved, must be zero */
+struct acpi_table_hpet {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u32 id;                 /* Hardware ID of event timer block */
+       struct acpi_generic_address address;    /* Address of event timer block */
+       u8 sequence;            /* HPET sequence number */
+       u16 minimum_tick;       /* Main counter min tick, periodic mode */
+       u8 flags;
 };
 
-/* Values for MADT PCATCompat */
+/*! Flags */
 
-#define DUAL_PIC                0
-#define MULTIPLE_APIC           1
+#define ACPI_HPET_PAGE_PROTECT      (1)        /* 00: No page protection */
+#define ACPI_HPET_PAGE_PROTECT_4    (1<<1)     /* 01: 4KB page protected */
+#define ACPI_HPET_PAGE_PROTECT_64   (1<<2)     /* 02: 64KB page protected */
 
-/* Common MADT Sub-table header */
+/*! [End] no source code translation !*/
 
-#define APIC_HEADER_DEF \
-       u8                              type; \
-       u8                              length;
-
-struct apic_header {
-APIC_HEADER_DEF};
-
-/* Values for Type in struct apic_header */
+/*******************************************************************************
+ *
+ * MADT - Multiple APIC Description Table
+ *
+ ******************************************************************************/
 
-#define APIC_PROCESSOR          0
-#define APIC_IO                 1
-#define APIC_XRUPT_OVERRIDE     2
-#define APIC_NMI                3
-#define APIC_LOCAL_NMI          4
-#define APIC_ADDRESS_OVERRIDE   5
-#define APIC_IO_SAPIC           6
-#define APIC_LOCAL_SAPIC        7
-#define APIC_XRUPT_SOURCE       8
-#define APIC_RESERVED           9      /* 9 and greater are reserved */
+struct acpi_table_madt {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u32 address;            /* Physical address of local APIC */
+       u32 flags;
+};
 
-/* Flag definitions for MADT sub-tables */
+/* Flags */
 
-#define ACPI_MADT_IFLAGS /* INTI flags (16 bits) */ \
-       u8                              polarity        : 2;    /* 00-01: Polarity of APIC I/O input signals */\
-       u8                              trigger_mode    : 2;    /* 02-03: Trigger mode of APIC input signals */\
-       u8                                              : 4;    /* 04-07: Reserved, must be zero */\
-       u8                              reserved1;      /* 08-15: Reserved, must be zero */
+#define ACPI_MADT_PCAT_COMPAT       (1)        /* 00:    System also has dual 8259s */
 
-#define ACPI_MADT_LFLAGS /* Local Sapic flags (32 bits) */ \
-       u8                              processor_enabled: 1;   /* 00:    Processor is usable if set */\
-       u8                                              : 7;    /* 01-07: Reserved, must be zero */\
-       u8                              reserved2[3];   /* 08-31: Reserved, must be zero */
+/* Values for PCATCompat flag */
 
-/* Values for MPS INTI flags */
+#define ACPI_MADT_DUAL_PIC          0
+#define ACPI_MADT_MULTIPLE_APIC     1
 
-#define POLARITY_CONFORMS       0
-#define POLARITY_ACTIVE_HIGH    1
-#define POLARITY_RESERVED       2
-#define POLARITY_ACTIVE_LOW     3
+/* Values for subtable type in struct acpi_subtable_header */
 
-#define TRIGGER_CONFORMS        0
-#define TRIGGER_EDGE            1
-#define TRIGGER_RESERVED        2
-#define TRIGGER_LEVEL           3
+enum acpi_madt_type {
+       ACPI_MADT_TYPE_LOCAL_APIC = 0,
+       ACPI_MADT_TYPE_IO_APIC = 1,
+       ACPI_MADT_TYPE_INTERRUPT_OVERRIDE = 2,
+       ACPI_MADT_TYPE_NMI_SOURCE = 3,
+       ACPI_MADT_TYPE_LOCAL_APIC_NMI = 4,
+       ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE = 5,
+       ACPI_MADT_TYPE_IO_SAPIC = 6,
+       ACPI_MADT_TYPE_LOCAL_SAPIC = 7,
+       ACPI_MADT_TYPE_INTERRUPT_SOURCE = 8,
+       ACPI_MADT_TYPE_RESERVED = 9     /* 9 and greater are reserved */
+};
 
 /*
- * MADT Sub-tables, correspond to Type in struct apic_header
+ * MADT Sub-tables, correspond to Type in struct acpi_subtable_header
  */
 
-/* 0: processor APIC */
+/* 0: Processor Local APIC */
 
-struct madt_processor_apic {
-       APIC_HEADER_DEF u8 processor_id;        /* ACPI processor id */
-       u8 local_apic_id;       /* Processor's local APIC id */
- ACPI_MADT_LFLAGS};
+struct acpi_madt_local_apic {
+       struct acpi_subtable_header header;
+       u8 processor_id;        /* ACPI processor id */
+       u8 id;                  /* Processor's local APIC id */
+       u32 lapic_flags;
+};
 
 /* 1: IO APIC */
 
-struct madt_io_apic {
-       APIC_HEADER_DEF u8 io_apic_id;  /* I/O APIC ID */
+struct acpi_madt_io_apic {
+       struct acpi_subtable_header header;
+       u8 id;                  /* I/O APIC ID */
        u8 reserved;            /* Reserved - must be zero */
        u32 address;            /* APIC physical address */
-       u32 interrupt;          /* Global system interrupt where INTI lines start */
+       u32 global_irq_base;    /* Global system interrupt where INTI lines start */
 };
 
 /* 2: Interrupt Override */
 
-struct madt_interrupt_override {
-       APIC_HEADER_DEF u8 bus; /* 0 - ISA */
-       u8 source;              /* Interrupt source (IRQ) */
-       u32 interrupt;          /* Global system interrupt */
- ACPI_MADT_IFLAGS};
+struct acpi_madt_interrupt_override {
+       struct acpi_subtable_header header;
+       u8 bus;                 /* 0 - ISA */
+       u8 source_irq;          /* Interrupt source (IRQ) */
+       u32 global_irq;         /* Global system interrupt */
+       u16 inti_flags;
+};
 
-/* 3: NMI Sources */
+/* 3: NMI Source */
 
-struct madt_nmi_source {
-       APIC_HEADER_DEF ACPI_MADT_IFLAGS u32 interrupt; /* Global system interrupt */
+struct acpi_madt_nmi_source {
+       struct acpi_subtable_header header;
+       u16 inti_flags;
+       u32 global_irq;         /* Global system interrupt */
 };
 
 /* 4: Local APIC NMI */
 
-struct madt_local_apic_nmi {
-       APIC_HEADER_DEF u8 processor_id;        /* ACPI processor id */
-       ACPI_MADT_IFLAGS u8 lint;       /* LINTn to which NMI is connected */
+struct acpi_madt_local_apic_nmi {
+       struct acpi_subtable_header header;
+       u8 processor_id;        /* ACPI processor id */
+       u16 inti_flags;
+       u8 lint;                /* LINTn to which NMI is connected */
 };
 
 /* 5: Address Override */
 
-struct madt_address_override {
-       APIC_HEADER_DEF u16 reserved;   /* Reserved, must be zero */
+struct acpi_madt_local_apic_override {
+       struct acpi_subtable_header header;
+       u16 reserved;           /* Reserved, must be zero */
        u64 address;            /* APIC physical address */
 };
 
 /* 6: I/O Sapic */
 
-struct madt_io_sapic {
-       APIC_HEADER_DEF u8 io_sapic_id; /* I/O SAPIC ID */
+struct acpi_madt_io_sapic {
+       struct acpi_subtable_header header;
+       u8 id;                  /* I/O SAPIC ID */
        u8 reserved;            /* Reserved, must be zero */
-       u32 interrupt_base;     /* Glocal interrupt for SAPIC start */
+       u32 global_irq_base;    /* Global interrupt for SAPIC start */
        u64 address;            /* SAPIC physical address */
 };
 
 /* 7: Local Sapic */
 
-struct madt_local_sapic {
-       APIC_HEADER_DEF u8 processor_id;        /* ACPI processor id */
-       u8 local_sapic_id;      /* SAPIC ID */
-       u8 local_sapic_eid;     /* SAPIC EID */
+struct acpi_madt_local_sapic {
+       struct acpi_subtable_header header;
+       u8 processor_id;        /* ACPI processor id */
+       u8 id;                  /* SAPIC ID */
+       u8 eid;                 /* SAPIC EID */
        u8 reserved[3];         /* Reserved, must be zero */
-        ACPI_MADT_LFLAGS u32 processor_uID;    /* Numeric UID - ACPI 3.0 */
-       char processor_uIDstring[1];    /* String UID  - ACPI 3.0 */
+       u32 lapic_flags;
+       u32 uid;                /* Numeric UID - ACPI 3.0 */
+       char uid_string[1];     /* String UID  - ACPI 3.0 */
 };
 
 /* 8: Platform Interrupt Source */
 
-struct madt_interrupt_source {
-       APIC_HEADER_DEF ACPI_MADT_IFLAGS u8 interrupt_type;     /* 1=PMI, 2=INIT, 3=corrected */
-       u8 processor_id;        /* Processor ID */
-       u8 processor_eid;       /* Processor EID */
+struct acpi_madt_interrupt_source {
+       struct acpi_subtable_header header;
+       u16 inti_flags;
+       u8 type;                /* 1=PMI, 2=INIT, 3=corrected */
+       u8 id;                  /* Processor ID */
+       u8 eid;                 /* Processor EID */
        u8 io_sapic_vector;     /* Vector value for PMI interrupts */
-       u32 interrupt;          /* Global system interrupt */
+       u32 global_irq;         /* Global system interrupt */
        u32 flags;              /* Interrupt Source Flags */
 };
 
-#ifdef DUPLICATE_DEFINITION_WITH_LINUX_ACPI_H
+/* Flags field above */
+
+#define ACPI_MADT_CPEI_OVERRIDE     (1)
+
+/*
+ * Common flags fields for MADT subtables
+ */
+
+/* MADT Local APIC flags (lapic_flags) */
+
+#define ACPI_MADT_ENABLED           (1)        /* 00: Processor is usable if set */
+
+/* MADT MPS INTI flags (inti_flags) */
+
+#define ACPI_MADT_POLARITY_MASK     (3)        /* 00-01: Polarity of APIC I/O input signals */
+#define ACPI_MADT_TRIGGER_MASK      (3<<2)     /* 02-03: Trigger mode of APIC input signals */
+
+/* Values for MPS INTI flags */
+
+#define ACPI_MADT_POLARITY_CONFORMS       0
+#define ACPI_MADT_POLARITY_ACTIVE_HIGH    1
+#define ACPI_MADT_POLARITY_RESERVED       2
+#define ACPI_MADT_POLARITY_ACTIVE_LOW     3
+
+#define ACPI_MADT_TRIGGER_CONFORMS        (0)
+#define ACPI_MADT_TRIGGER_EDGE            (1<<2)
+#define ACPI_MADT_TRIGGER_RESERVED        (2<<2)
+#define ACPI_MADT_TRIGGER_LEVEL           (3<<2)
+
 /*******************************************************************************
  *
  * MCFG - PCI Memory Mapped Configuration table and sub-table
@@ -406,17 +524,19 @@ struct madt_interrupt_source {
  ******************************************************************************/
 
 struct acpi_table_mcfg {
-       ACPI_TABLE_HEADER_DEF u8 reserved[8];
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u8 reserved[8];
 };
 
+/* Subtable */
+
 struct acpi_mcfg_allocation {
-       u64 base_address;       /* Base address, processor-relative */
+       u64 address;            /* Base address, processor-relative */
        u16 pci_segment;        /* PCI segment group number */
        u8 start_bus_number;    /* Starting PCI Bus number */
        u8 end_bus_number;      /* Final PCI Bus number */
        u32 reserved;
 };
-#endif
 
 /*******************************************************************************
  *
@@ -424,8 +544,9 @@ struct acpi_mcfg_allocation {
  *
  ******************************************************************************/
 
-struct smart_battery_table {
-       ACPI_TABLE_HEADER_DEF u32 warning_level;
+struct acpi_table_sbst {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u32 warning_level;
        u32 low_level;
        u32 critical_level;
 };
@@ -436,9 +557,10 @@ struct smart_battery_table {
  *
  ******************************************************************************/
 
-struct system_locality_info {
-       ACPI_TABLE_HEADER_DEF u64 locality_count;
-       u8 entry[1][1];
+struct acpi_table_slit {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u64 locality_count;
+       u8 entry[1];            /* Real size = localities^2 */
 };
 
 /*******************************************************************************
@@ -448,7 +570,8 @@ struct system_locality_info {
  ******************************************************************************/
 
 struct acpi_table_spcr {
-       ACPI_TABLE_HEADER_DEF u8 interface_type;        /* 0=full 16550, 1=subset of 16550 */
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u8 interface_type;      /* 0=full 16550, 1=subset of 16550 */
        u8 reserved[3];
        struct acpi_generic_address serial_port;
        u8 interrupt_type;
@@ -459,7 +582,7 @@ struct acpi_table_spcr {
        u8 stop_bits;
        u8 flow_control;
        u8 terminal_type;
-       u8 reserved2;
+       u8 reserved1;
        u16 pci_device_id;
        u16 pci_vendor_id;
        u8 pci_bus;
@@ -467,7 +590,7 @@ struct acpi_table_spcr {
        u8 pci_function;
        u32 pci_flags;
        u8 pci_segment;
-       u32 reserved3;
+       u32 reserved2;
 };
 
 /*******************************************************************************
@@ -477,12 +600,13 @@ struct acpi_table_spcr {
  ******************************************************************************/
 
 struct acpi_table_spmi {
-       ACPI_TABLE_HEADER_DEF u8 reserved;
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u8 reserved;
        u8 interface_type;
        u16 spec_revision;      /* Version of IPMI */
        u8 interrupt_type;
        u8 gpe_number;          /* GPE assigned */
-       u8 reserved2;
+       u8 reserved1;
        u8 pci_device_flag;
        u32 interrupt;
        struct acpi_generic_address ipmi_register;
@@ -498,58 +622,53 @@ struct acpi_table_spmi {
  *
  ******************************************************************************/
 
-struct system_resource_affinity {
-       ACPI_TABLE_HEADER_DEF u32 reserved1;    /* Must be value '1' */
-       u64 reserved2;          /* Reserved, must be zero */
+struct acpi_table_srat {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u32 table_revision;     /* Must be value '1' */
+       u64 reserved;           /* Reserved, must be zero */
 };
 
-/* SRAT common sub-table header */
+/* Values for subtable type in struct acpi_subtable_header */
 
-#define SRAT_SUBTABLE_HEADER \
-       u8                              type; \
-       u8                              length;
-
-/* Values for Type above */
-
-#define SRAT_CPU_AFFINITY       0
-#define SRAT_MEMORY_AFFINITY    1
-#define SRAT_RESERVED           2
+enum acpi_srat_type {
+       ACPI_SRAT_TYPE_CPU_AFFINITY = 0,
+       ACPI_SRAT_TYPE_MEMORY_AFFINITY = 1,
+       ACPI_SRAT_TYPE_RESERVED = 2
+};
 
 /* SRAT sub-tables */
 
-struct static_resource_alloc {
-       SRAT_SUBTABLE_HEADER u8 proximity_domain_lo;
+struct acpi_srat_cpu_affinity {
+       struct acpi_subtable_header header;
+       u8 proximity_domain_lo;
        u8 apic_id;
-
-       /* Flags (32 bits) */
-
-       u8 enabled:1;           /* 00:    Use affinity structure */
-        u8:7;                  /* 01-07: Reserved, must be zero */
-       u8 reserved3[3];        /* 08-31: Reserved, must be zero */
-
+       u32 flags;
        u8 local_sapic_eid;
        u8 proximity_domain_hi[3];
-       u32 reserved4;          /* Reserved, must be zero */
+       u32 reserved          /* Reserved, must be zero */
 };
 
-struct memory_affinity {
-       SRAT_SUBTABLE_HEADER u32 proximity_domain;
-       u16 reserved3;
-       u64 base_address;
-       u64 address_length;
-       u32 reserved4;
-
-       /* Flags (32 bits) */
+/* Flags */
 
-       u8 enabled:1;           /* 00:    Use affinity structure */
-       u8 hot_pluggable:1;     /* 01:    Memory region is hot pluggable */
-       u8 non_volatile:1;      /* 02:    Memory is non-volatile */
-        u8:5;                  /* 03-07: Reserved, must be zero */
-       u8 reserved5[3];        /* 08-31: Reserved, must be zero */
+#define ACPI_SRAT_CPU_ENABLED       (1)        /* 00: Use affinity structure */
 
-       u64 reserved6;          /* Reserved, must be zero */
+struct acpi_srat_mem_affinity {
+       struct acpi_subtable_header header;
+       u32 proximity_domain;
+       u16 reserved;           /* Reserved, must be zero */
+       u64 base_address;
+       u64 length;
+       u32 memory_type;        /* See acpi_address_range_id */
+       u32 flags;
+       u64 reserved1;          /* Reserved, must be zero */
 };
 
+/* Flags */
+
+#define ACPI_SRAT_MEM_ENABLED       (1)        /* 00: Use affinity structure */
+#define ACPI_SRAT_MEM_HOT_PLUGGABLE (1<<1)     /* 01: Memory region is hot pluggable */
+#define ACPI_SRAT_MEM_NON_VOLATILE  (1<<2)     /* 02: Memory region is non-volatile */
+
 /*******************************************************************************
  *
  * TCPA - Trusted Computing Platform Alliance table
@@ -557,7 +676,8 @@ struct memory_affinity {
  ******************************************************************************/
 
 struct acpi_table_tcpa {
-       ACPI_TABLE_HEADER_DEF u16 reserved;
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u16 reserved;
        u32 max_log_length;     /* Maximum length for the event log area */
        u64 log_address;        /* Address of the event log area */
 };
@@ -569,7 +689,8 @@ struct acpi_table_tcpa {
  ******************************************************************************/
 
 struct acpi_table_wdrt {
-       ACPI_TABLE_HEADER_DEF u32 header_length;        /* Watchdog Header Length */
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u32 header_length;      /* Watchdog Header Length */
        u8 pci_segment;         /* PCI Segment number */
        u8 pci_bus;             /* PCI Bus number */
        u8 pci_device;          /* PCI Device number */
@@ -582,58 +703,9 @@ struct acpi_table_wdrt {
        u32 entries;            /* Number of watchdog entries that follow */
 };
 
-#if 0                          /* Flags, will be converted to macros */
-u8 enabled:1;                  /* 00:    Timer enabled */
-u8:6;                          /* 01-06: Reserved */
-u8 sleep_stop:1;               /* 07:    Timer stopped in sleep state */
-#endif
-
-/* Macros used to generate offsets to specific table fields */
-
-#define ACPI_ASF0_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_asf_info,f)
-#define ACPI_ASF1_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_asf_alert,f)
-#define ACPI_ASF2_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_asf_remote,f)
-#define ACPI_ASF3_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_asf_rmcp,f)
-#define ACPI_ASF4_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_asf_address,f)
-#define ACPI_BOOT_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_table_boot,f)
-#define ACPI_CPEP_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_table_cpep,f)
-#define ACPI_CPEP0_OFFSET(f)            (u8) ACPI_OFFSET (struct acpi_cpep_polling,f)
-#define ACPI_DBGP_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_table_dbgp,f)
-#define ACPI_ECDT_OFFSET(f)             (u8) ACPI_OFFSET (struct ec_boot_resources,f)
-#define ACPI_HPET_OFFSET(f)             (u8) ACPI_OFFSET (struct hpet_table,f)
-#define ACPI_MADT_OFFSET(f)             (u8) ACPI_OFFSET (struct multiple_apic_table,f)
-#define ACPI_MADT0_OFFSET(f)            (u8) ACPI_OFFSET (struct madt_processor_apic,f)
-#define ACPI_MADT1_OFFSET(f)            (u8) ACPI_OFFSET (struct madt_io_apic,f)
-#define ACPI_MADT2_OFFSET(f)            (u8) ACPI_OFFSET (struct madt_interrupt_override,f)
-#define ACPI_MADT3_OFFSET(f)            (u8) ACPI_OFFSET (struct madt_nmi_source,f)
-#define ACPI_MADT4_OFFSET(f)            (u8) ACPI_OFFSET (struct madt_local_apic_nmi,f)
-#define ACPI_MADT5_OFFSET(f)            (u8) ACPI_OFFSET (struct madt_address_override,f)
-#define ACPI_MADT6_OFFSET(f)            (u8) ACPI_OFFSET (struct madt_io_sapic,f)
-#define ACPI_MADT7_OFFSET(f)            (u8) ACPI_OFFSET (struct madt_local_sapic,f)
-#define ACPI_MADT8_OFFSET(f)            (u8) ACPI_OFFSET (struct madt_interrupt_source,f)
-#define ACPI_MADTH_OFFSET(f)            (u8) ACPI_OFFSET (struct apic_header,f)
-#define ACPI_MCFG_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_table_mcfg,f)
-#define ACPI_MCFG0_OFFSET(f)            (u8) ACPI_OFFSET (struct acpi_mcfg_allocation,f)
-#define ACPI_SBST_OFFSET(f)             (u8) ACPI_OFFSET (struct smart_battery_table,f)
-#define ACPI_SLIT_OFFSET(f)             (u8) ACPI_OFFSET (struct system_locality_info,f)
-#define ACPI_SPCR_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_table_spcr,f)
-#define ACPI_SPMI_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_table_spmi,f)
-#define ACPI_SRAT_OFFSET(f)             (u8) ACPI_OFFSET (struct system_resource_affinity,f)
-#define ACPI_SRAT0_OFFSET(f)            (u8) ACPI_OFFSET (struct static_resource_alloc,f)
-#define ACPI_SRAT1_OFFSET(f)            (u8) ACPI_OFFSET (struct memory_affinity,f)
-#define ACPI_TCPA_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_table_tcpa,f)
-#define ACPI_WDRT_OFFSET(f)             (u8) ACPI_OFFSET (struct acpi_table_wdrt,f)
-
-#define ACPI_HPET_FLAG_OFFSET(f,o)      ACPI_FLAG_OFFSET (struct hpet_table,f,o)
-#define ACPI_SRAT0_FLAG_OFFSET(f,o)     ACPI_FLAG_OFFSET (struct static_resource_alloc,f,o)
-#define ACPI_SRAT1_FLAG_OFFSET(f,o)     ACPI_FLAG_OFFSET (struct memory_affinity,f,o)
-#define ACPI_MADT_FLAG_OFFSET(f,o)      ACPI_FLAG_OFFSET (struct multiple_apic_table,f,o)
-#define ACPI_MADT0_FLAG_OFFSET(f,o)     ACPI_FLAG_OFFSET (struct madt_processor_apic,f,o)
-#define ACPI_MADT2_FLAG_OFFSET(f,o)     ACPI_FLAG_OFFSET (struct madt_interrupt_override,f,o)
-#define ACPI_MADT3_FLAG_OFFSET(f,o)     ACPI_FLAG_OFFSET (struct madt_nmi_source,f,o)
-#define ACPI_MADT4_FLAG_OFFSET(f,o)     ACPI_FLAG_OFFSET (struct madt_local_apic_nmi,f,o)
-#define ACPI_MADT7_FLAG_OFFSET(f,o)     ACPI_FLAG_OFFSET (struct madt_local_sapic,f,o)
-#define ACPI_MADT8_FLAG_OFFSET(f,o)     ACPI_FLAG_OFFSET (struct madt_interrupt_source,f,o)
+/* Flags */
+
+#define ACPI_WDRT_TIMER_ENABLED     (1)        /* 00: Timer enabled */
 
 /* Reset to default packing */
 
diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h
deleted file mode 100644 (file)
index 67efe6c..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/******************************************************************************
- *
- * Name: actbl2.h - ACPI Specification Revision 2.0 Tables
- *
- *****************************************************************************/
-
-/*
- * Copyright (C) 2000 - 2006, R. Byron Moore
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
-
-#ifndef __ACTBL2_H__
-#define __ACTBL2_H__
-
-/* Code moved to both actbl.h and actbl1.h */
-
-#endif                         /* __ACTBL2_H__ */
diff --git a/include/acpi/actbl71.h b/include/acpi/actbl71.h
deleted file mode 100644 (file)
index 10ac05b..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/******************************************************************************
- *
- * Name: actbl71.h - IA-64 Extensions to the ACPI Spec Rev. 0.71
- *                   This file includes tables specific to this
- *                   specification revision.
- *
- *****************************************************************************/
-
-/*
- *  Copyright (C) 2000 - 2003, R. Byron Moore
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#ifndef __ACTBL71_H__
-#define __ACTBL71_H__
-
-/* 0.71 FADT address_space data item bitmasks defines */
-/* If the associated bit is zero then it is in memory space else in io space */
-
-#define SMI_CMD_ADDRESS_SPACE       0x01
-#define PM1_BLK_ADDRESS_SPACE       0x02
-#define PM2_CNT_BLK_ADDRESS_SPACE   0x04
-#define PM_TMR_BLK_ADDRESS_SPACE    0x08
-#define GPE0_BLK_ADDRESS_SPACE      0x10
-#define GPE1_BLK_ADDRESS_SPACE      0x20
-
-/* Only for clarity in declarations */
-
-typedef u64 IO_ADDRESS;
-
-#pragma pack(1)
-struct {                       /* Root System Descriptor Pointer */
-       NATIVE_CHAR signature[8];       /* contains "RSD PTR " */
-       u8 checksum;            /* to make sum of struct == 0 */
-       NATIVE_CHAR oem_id[6];  /* OEM identification */
-       u8 reserved;            /* Must be 0 for 1.0, 2 for 2.0 */
-       u64 rsdt_physical_address;      /* 64-bit physical address of RSDT */
-};
-
-/*****************************************/
-/* IA64 Extensions to ACPI Spec Rev 0.71 */
-/* for the Root System Description Table */
-/*****************************************/
-struct {
-       struct acpi_table_header header;        /* Table header */
-       u32 reserved_pad;       /* IA64 alignment, must be 0 */
-       u64 table_offset_entry[1];      /* Array of pointers to other */
-       /* tables' headers */
-};
-
-/*******************************************/
-/* IA64 Extensions to ACPI Spec Rev 0.71   */
-/* for the Firmware ACPI Control Structure */
-/*******************************************/
-struct {
-       NATIVE_CHAR signature[4];       /* signature "FACS" */
-       u32 length;             /* length of structure, in bytes */
-       u32 hardware_signature; /* hardware configuration signature */
-       u32 reserved4;          /* must be 0 */
-       u64 firmware_waking_vector;     /* ACPI OS waking vector */
-       u64 global_lock;        /* Global Lock */
-       u32 S4bios_f:1;         /* Indicates if S4BIOS support is present */
-       u32 reserved1:31;       /* must be 0 */
-       u8 reserved3[28];       /* reserved - must be zero */
-};
-
-/******************************************/
-/* IA64 Extensions to ACPI Spec Rev 0.71  */
-/* for the Fixed ACPI Description Table   */
-/******************************************/
-struct {
-       struct acpi_table_header header;        /* table header */
-       u32 reserved_pad;       /* IA64 alignment, must be 0 */
-       u64 firmware_ctrl;      /* 64-bit Physical address of FACS */
-       u64 dsdt;               /* 64-bit Physical address of DSDT */
-       u8 model;               /* System Interrupt Model */
-       u8 address_space;       /* Address Space Bitmask */
-       u16 sci_int;            /* System vector of SCI interrupt */
-       u8 acpi_enable;         /* value to write to smi_cmd to enable ACPI */
-       u8 acpi_disable;        /* value to write to smi_cmd to disable ACPI */
-       u8 S4bios_req;          /* Value to write to SMI CMD to enter S4BIOS state */
-       u8 reserved2;           /* reserved - must be zero */
-       u64 smi_cmd;            /* Port address of SMI command port */
-       u64 pm1a_evt_blk;       /* Port address of Power Mgt 1a acpi_event Reg Blk */
-       u64 pm1b_evt_blk;       /* Port address of Power Mgt 1b acpi_event Reg Blk */
-       u64 pm1a_cnt_blk;       /* Port address of Power Mgt 1a Control Reg Blk */
-       u64 pm1b_cnt_blk;       /* Port address of Power Mgt 1b Control Reg Blk */
-       u64 pm2_cnt_blk;        /* Port address of Power Mgt 2 Control Reg Blk */
-       u64 pm_tmr_blk;         /* Port address of Power Mgt Timer Ctrl Reg Blk */
-       u64 gpe0_blk;           /* Port addr of General Purpose acpi_event 0 Reg Blk */
-       u64 gpe1_blk;           /* Port addr of General Purpose acpi_event 1 Reg Blk */
-       u8 pm1_evt_len;         /* Byte length of ports at pm1_x_evt_blk */
-       u8 pm1_cnt_len;         /* Byte length of ports at pm1_x_cnt_blk */
-       u8 pm2_cnt_len;         /* Byte Length of ports at pm2_cnt_blk */
-       u8 pm_tm_len;           /* Byte Length of ports at pm_tm_blk */
-       u8 gpe0_blk_len;        /* Byte Length of ports at gpe0_blk */
-       u8 gpe1_blk_len;        /* Byte Length of ports at gpe1_blk */
-       u8 gpe1_base;           /* offset in gpe model where gpe1 events start */
-       u8 reserved3;           /* reserved */
-       u16 plvl2_lat;          /* worst case HW latency to enter/exit C2 state */
-       u16 plvl3_lat;          /* worst case HW latency to enter/exit C3 state */
-       u8 day_alrm;            /* index to day-of-month alarm in RTC CMOS RAM */
-       u8 mon_alrm;            /* index to month-of-year alarm in RTC CMOS RAM */
-       u8 century;             /* index to century in RTC CMOS RAM */
-       u8 reserved4;           /* reserved */
-       u32 flush_cash:1;       /* PAL_FLUSH_CACHE is correctly supported */
-       u32 reserved5:1;        /* reserved - must be zero */
-       u32 proc_c1:1;          /* all processors support C1 state */
-       u32 plvl2_up:1;         /* C2 state works on MP system */
-       u32 pwr_button:1;       /* Power button is handled as a generic feature */
-       u32 sleep_button:1;     /* Sleep button is handled as a generic feature, or not present */
-       u32 fixed_rTC:1;        /* RTC wakeup stat not in fixed register space */
-       u32 rtcs4:1;            /* RTC wakeup stat not possible from S4 */
-       u32 tmr_val_ext:1;      /* tmr_val is 32 bits */
-       u32 dock_cap:1;         /* Supports Docking */
-       u32 reserved6:22;       /* reserved - must be zero */
-};
-
-#pragma pack()
-
-#endif                         /* __ACTBL71_H__ */
index 64b603cfe92e1df95227ddf9108d205644dd8520..72a6e2c3a5361fa3a1b5b5e0ef2548ec97569863 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -48,7 +48,8 @@
 
 /*
  * ACPI_MACHINE_WIDTH must be specified in an OS- or compiler-dependent header
- * and must be either 16, 32, or 64
+ * and must be either 32 or 64. 16-bit ACPICA is no longer supported, as of
+ * 12/2006.
  */
 #ifndef ACPI_MACHINE_WIDTH
 #error ACPI_MACHINE_WIDTH not defined
@@ -149,7 +150,6 @@ typedef int INT32;
 typedef u64 acpi_native_uint;
 typedef s64 acpi_native_int;
 
-typedef u64 acpi_table_ptr;
 typedef u64 acpi_io_address;
 typedef u64 acpi_physical_address;
 
@@ -189,48 +189,15 @@ typedef int INT32;
 typedef u32 acpi_native_uint;
 typedef s32 acpi_native_int;
 
-typedef u64 acpi_table_ptr;
 typedef u32 acpi_io_address;
-typedef u64 acpi_physical_address;
+typedef u32 acpi_physical_address;
 
 #define ACPI_MAX_PTR                    ACPI_UINT32_MAX
 #define ACPI_SIZE_MAX                   ACPI_UINT32_MAX
 
-/*******************************************************************************
- *
- * Types specific to 16-bit targets
- *
- ******************************************************************************/
-
-#elif ACPI_MACHINE_WIDTH == 16
-
-/*! [Begin] no source code translation (keep the typedefs as-is) */
-
-typedef unsigned long UINT32;
-typedef short INT16;
-typedef long INT32;
-
-/*! [End] no source code translation !*/
-
-typedef u16 acpi_native_uint;
-typedef s16 acpi_native_int;
-
-typedef u32 acpi_table_ptr;
-typedef u32 acpi_io_address;
-typedef char *acpi_physical_address;
-
-#define ACPI_MAX_PTR                    ACPI_UINT16_MAX
-#define ACPI_SIZE_MAX                   ACPI_UINT16_MAX
-
-#define ACPI_USE_NATIVE_DIVIDE /* No 64-bit integers, ok to use native divide */
-
-/* 64-bit integers cannot be supported */
-
-#define ACPI_NO_INTEGER64_SUPPORT
-
 #else
 
-/* ACPI_MACHINE_WIDTH must be either 64, 32, or 16 */
+/* ACPI_MACHINE_WIDTH must be either 64 or 32 */
 
 #error unknown ACPI_MACHINE_WIDTH
 #endif
@@ -311,36 +278,6 @@ typedef acpi_native_uint acpi_size;
  *
  ******************************************************************************/
 
-/*
- * Pointer overlays to avoid lots of typecasting for
- * code that accepts both physical and logical pointers.
- */
-union acpi_pointers {
-       acpi_physical_address physical;
-       void *logical;
-       acpi_table_ptr value;
-};
-
-struct acpi_pointer {
-       u32 pointer_type;
-       union acpi_pointers pointer;
-};
-
-/* pointer_types for above */
-
-#define ACPI_PHYSICAL_POINTER           0x01
-#define ACPI_LOGICAL_POINTER            0x02
-
-/* Processor mode */
-
-#define ACPI_PHYSICAL_ADDRESSING        0x04
-#define ACPI_LOGICAL_ADDRESSING         0x08
-#define ACPI_MEMORY_MODE                0x0C
-
-#define ACPI_PHYSMODE_PHYSPTR           ACPI_PHYSICAL_ADDRESSING | ACPI_PHYSICAL_POINTER
-#define ACPI_LOGMODE_PHYSPTR            ACPI_LOGICAL_ADDRESSING  | ACPI_PHYSICAL_POINTER
-#define ACPI_LOGMODE_LOGPTR             ACPI_LOGICAL_ADDRESSING  | ACPI_LOGICAL_POINTER
-
 /* Logical defines and NULL */
 
 #ifdef FALSE
@@ -442,7 +379,8 @@ typedef u64 acpi_integer;
 /*
  * Initialization state
  */
-#define ACPI_INITIALIZED_OK             0x01
+#define ACPI_SUBSYSTEM_INITIALIZE       0x01
+#define ACPI_INITIALIZED_OK             0x02
 
 /*
  * Power state values
@@ -490,21 +428,6 @@ typedef u64 acpi_integer;
 #define ACPI_NOTIFY_BUS_MODE_MISMATCH   (u8) 6
 #define ACPI_NOTIFY_POWER_FAULT         (u8) 7
 
-/*
- *  Table types.  These values are passed to the table related APIs
- */
-typedef u32 acpi_table_type;
-
-#define ACPI_TABLE_ID_RSDP              (acpi_table_type) 0
-#define ACPI_TABLE_ID_DSDT              (acpi_table_type) 1
-#define ACPI_TABLE_ID_FADT              (acpi_table_type) 2
-#define ACPI_TABLE_ID_FACS              (acpi_table_type) 3
-#define ACPI_TABLE_ID_PSDT              (acpi_table_type) 4
-#define ACPI_TABLE_ID_SSDT              (acpi_table_type) 5
-#define ACPI_TABLE_ID_XSDT              (acpi_table_type) 6
-#define ACPI_TABLE_ID_MAX               6
-#define ACPI_NUM_TABLE_TYPES            (ACPI_TABLE_ID_MAX+1)
-
 /*
  * Types associated with ACPI names and objects.  The first group of
  * values (up to ACPI_TYPE_EXTERNAL_MAX) correspond to the definition
@@ -637,7 +560,7 @@ typedef u32 acpi_event_status;
  *  | | |  +--- Type of dispatch -- to method, handler, or none
  *  | | +--- Enabled for runtime?
  *  | +--- Enabled for wake?
- *  +--- System state when GPE ocurred (running/waking)
+ *  +--- Unused
  */
 #define ACPI_GPE_XRUPT_TYPE_MASK        (u8) 0x01
 #define ACPI_GPE_LEVEL_TRIGGERED        (u8) 0x01
@@ -663,10 +586,6 @@ typedef u32 acpi_event_status;
 
 #define ACPI_GPE_ENABLE_MASK            (u8) 0x60      /* Both run/wake */
 
-#define ACPI_GPE_SYSTEM_MASK            (u8) 0x80
-#define ACPI_GPE_SYSTEM_RUNNING         (u8) 0x80
-#define ACPI_GPE_SYSTEM_WAKING          (u8) 0x00
-
 /*
  * Flags for GPE and Lock interfaces
  */
@@ -815,13 +734,6 @@ struct acpi_buffer {
 #define ACPI_SYS_MODE_LEGACY            0x0002
 #define ACPI_SYS_MODES_MASK             0x0003
 
-/*
- * ACPI Table Info.  One per ACPI table _type_
- */
-struct acpi_table_info {
-       u32 count;
-};
-
 /*
  * System info returned by acpi_get_system_info()
  */
@@ -833,8 +745,6 @@ struct acpi_system_info {
        u32 reserved2;
        u32 debug_level;
        u32 debug_layer;
-       u32 num_table_types;
-       struct acpi_table_info table_info[ACPI_TABLE_ID_MAX + 1];
 };
 
 /*
index ba039ea1a057ab8e39ab5844c34f75b31131d15d..883ffe92148ff1651f2b2e36aadc0628f76f57ec 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -141,8 +141,6 @@ acpi_status acpi_ut_hardware_initialize(void);
 
 void acpi_ut_subsystem_shutdown(void);
 
-acpi_status acpi_ut_validate_fadt(void);
-
 /*
  * utclib - Local implementations of C library functions
  */
@@ -453,6 +451,8 @@ acpi_ut_short_divide(acpi_integer in_dividend,
 /*
  * utmisc
  */
+const char *acpi_ut_validate_exception(acpi_status status);
+
 u8 acpi_ut_is_aml_table(struct acpi_table_header *table);
 
 acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id);
@@ -470,7 +470,7 @@ void acpi_ut_print_string(char *string, u8 max_length);
 
 u8 acpi_ut_valid_acpi_name(u32 name);
 
-acpi_name acpi_ut_repair_name(acpi_name name);
+acpi_name acpi_ut_repair_name(char *name);
 
 u8 acpi_ut_valid_acpi_char(char character, acpi_native_uint position);
 
index cf18426a87b113e22925f687b987987df55b3473..da53a4ef287ad3cbdc414d2b02d05bea005746fb 100644 (file)
@@ -7,7 +7,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define ARGI_DATAOBJECT             0x12       /* Buffer, String, package or reference to a Node - Used only by size_of operator */
 #define ARGI_COMPLEXOBJ             0x13       /* Buffer, String, or package (Used by INDEX op only) */
 #define ARGI_REF_OR_STRING          0x14       /* Reference or String (Used by DEREFOF op only) */
-#define ARGI_REGION_OR_FIELD        0x15       /* Used by LOAD op only */
+#define ARGI_REGION_OR_BUFFER       0x15       /* Used by LOAD op only */
 #define ARGI_DATAREFOBJ             0x16
 
 /* Note: types above can expand to 0x1F maximum */
index be03818af9d19731dec2aa280b8b38ace1526cb8..f7d541239da4f803da1a41dabc8b56916d7ac234 100644 (file)
@@ -6,7 +6,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 453a469fd397b9a8073037d25ddfd2761c218c29..dab2ec59a3b0b7a822d49c99cdec3f98b9834214 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index da80933963db32b4b2bcf3e2867ff42c0d9e3be4..3bb50494a38a03a590f43c25ff619b5fe6c8f29d 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 7f1e92930b6258b75e931daac2e25f657441dd27..5f532d2ac180518fdd3c9c579f43e70b5f2d73a2 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 7cfad93edf10085ae2b84e1a9700e1fcdba41ba1..5e657eb8946c953bc0b58846344653cc9d1eaa9c 100644 (file)
@@ -39,7 +39,7 @@
  * Calling conventions:
  *
  * ACPI_SYSTEM_XFACE        - Interfaces to host OS (handlers, threads)
- * ACPI_EXTERNAL_XFACE      - External ACPI interfaces 
+ * ACPI_EXTERNAL_XFACE      - External ACPI interfaces
  * ACPI_INTERNAL_XFACE      - Internal ACPI interfaces
  * ACPI_INTERNAL_VAR_XFACE  - Internal variable-parameter list interfaces
  */
 int __acpi_acquire_global_lock(unsigned int *lock);
 int __acpi_release_global_lock(unsigned int *lock);
 
-#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
-       ((Acq) = __acpi_acquire_global_lock((unsigned int *) GLptr))
+#define ACPI_ACQUIRE_GLOBAL_LOCK(facs, Acq) \
+       ((Acq) = __acpi_acquire_global_lock(&facs->global_lock))
 
-#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
-       ((Acq) = __acpi_release_global_lock((unsigned int *) GLptr))
+#define ACPI_RELEASE_GLOBAL_LOCK(facs, Acq) \
+       ((Acq) = __acpi_release_global_lock(&facs->global_lock))
 
 /*
  * Math helper asm macros
@@ -87,7 +87,7 @@ extern void check_acpi_pci(void);
 static inline void check_acpi_pci(void) { }
 #endif
 
-#ifdef CONFIG_ACPI 
+#ifdef CONFIG_ACPI
 extern int acpi_lapic;
 extern int acpi_ioapic;
 extern int acpi_noirq;
@@ -95,9 +95,9 @@ extern int acpi_strict;
 extern int acpi_disabled;
 extern int acpi_ht;
 extern int acpi_pci_disabled;
-static inline void disable_acpi(void) 
-{ 
-       acpi_disabled = 1; 
+static inline void disable_acpi(void)
+{
+       acpi_disabled = 1;
        acpi_ht = 0;
        acpi_pci_disabled = 1;
        acpi_noirq = 1;
@@ -114,9 +114,9 @@ extern int acpi_use_timer_override;
 #endif
 
 static inline void acpi_noirq_set(void) { acpi_noirq = 1; }
-static inline void acpi_disable_pci(void) 
+static inline void acpi_disable_pci(void)
 {
-       acpi_pci_disabled = 1; 
+       acpi_pci_disabled = 1;
        acpi_noirq_set();
 }
 extern int acpi_irq_balance_set(char *str);
@@ -144,8 +144,6 @@ extern void acpi_reserve_bootmem(void);
 
 #endif /*CONFIG_ACPI_SLEEP*/
 
-extern u8 x86_acpiid_to_apicid[];
-
 #define ARCH_HAS_POWER_INIT    1
 
 #endif /*__KERNEL__*/
index 99f66be240be66e517e93b14fe0b9fda52e65752..24990e546da3b60cc55bce0b297063b2fbc3e701 100644 (file)
@@ -3,13 +3,13 @@
 
 #include <linux/acpi.h>
 
-static inline void mpc_oem_bus_info(struct mpc_config_bus *m, char *name, 
+static inline void mpc_oem_bus_info(struct mpc_config_bus *m, char *name,
                                struct mpc_config_translation *translation)
 {
        Dprintk("Bus #%d is %s\n", m->mpc_busid, name);
 }
 
-static inline void mpc_oem_pci_bus(struct mpc_config_bus *m, 
+static inline void mpc_oem_pci_bus(struct mpc_config_bus *m,
                                struct mpc_config_translation *translation)
 {
 }
@@ -22,7 +22,7 @@ static inline int mps_oem_check(struct mp_config_table *mpc, char *oem,
                char *productid)
 {
        if (mpc->mpc_oemptr) {
-               struct mp_config_oemtable *oem_table = 
+               struct mp_config_oemtable *oem_table =
                        (struct mp_config_oemtable *)mpc->mpc_oemptr;
                if (!strncmp(oem, "UNISYS", 6))
                        return parse_unisys_oem((char *)oem_table);
@@ -31,12 +31,13 @@ static inline int mps_oem_check(struct mp_config_table *mpc, char *oem,
 }
 
 #ifdef CONFIG_ACPI
+
 static inline int es7000_check_dsdt(void)
 {
-       struct acpi_table_header *header = NULL;
-       if(!acpi_get_table_header_early(ACPI_DSDT, &header))
-               acpi_table_print(header, 0);
-       if (!strncmp(header->oem_id, "UNISYS", 6))
+       struct acpi_table_header header;
+       memcpy(&header, 0, sizeof(struct acpi_table_header));
+       acpi_get_table_header(ACPI_SIG_DSDT, 0, &header);
+       if (!strncmp(header.oem_id, "UNISYS", 6))
                return 1;
        return 0;
 }
@@ -44,7 +45,7 @@ static inline int es7000_check_dsdt(void)
 /* Hook from generic ACPI tables.c */
 static inline int acpi_madt_oem_check(char *oem_id, char *oem_table_id)
 {
-       unsigned long oem_addr; 
+       unsigned long oem_addr;
        if (!find_unisys_acpi_oem_table(&oem_addr)) {
                if (es7000_check_dsdt())
                        return parse_unisys_oem((char *)oem_addr);
index 09a5dd0e44a89f8c083bedce37f80d3d7e438f1a..5d03792d4f65f92f584f4e7477925e7be912c6b9 100644 (file)
@@ -82,11 +82,11 @@ ia64_acpi_release_global_lock (unsigned int *lock)
        return old & 0x1;
 }
 
-#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq)                           \
-       ((Acq) = ia64_acpi_acquire_global_lock((unsigned int *) GLptr))
+#define ACPI_ACQUIRE_GLOBAL_LOCK(facs, Acq)                            \
+       ((Acq) = ia64_acpi_acquire_global_lock(&facs->global_lock))
 
-#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq)                           \
-       ((Acq) = ia64_acpi_release_global_lock((unsigned int *) GLptr))
+#define ACPI_RELEASE_GLOBAL_LOCK(facs, Acq)                            \
+       ((Acq) = ia64_acpi_release_global_lock(&facs->global_lock))
 
 #define acpi_disabled 0        /* ACPI always enabled on IA64 */
 #define acpi_noirq 0   /* ACPI always enabled on IA64 */
@@ -119,8 +119,6 @@ extern int __devinitdata pxm_to_nid_map[MAX_PXM_DOMAINS];
 extern int __initdata nid_to_pxm_map[MAX_NUMNODES];
 #endif
 
-extern u16 ia64_acpiid_to_sapicid[];
-
 /*
  * Refer Intel ACPI _PDC support document for bit definitions
  */
index 2850a7ef5e71148bdcfb28f2f573ae5a8a55aa90..9ce2801cbd5725a87fa19953d3eed714889febe6 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "acpi/acglobal.h"
 
-#define SN_ACPI_BASE_SUPPORT()   (acpi_gbl_DSDT->oem_revision >= 0x20101)
+extern int sn_acpi_rev;
+#define SN_ACPI_BASE_SUPPORT()   (sn_acpi_rev >= 0x20101)
 
 #endif /* _ASM_IA64_SN_ACPI_H */
index da3eade0cae2cbbfdfca830403cf0889be10b58e..17cb6cc3f21a8dc8899b55aaaa115436a2d2fa9a 100644 (file)
@@ -142,7 +142,7 @@ extern int          pcibr_ate_alloc(struct pcibus_info *, int);
 extern void            pcibr_ate_free(struct pcibus_info *, int);
 extern void            ate_write(struct pcibus_info *, int, int, u64);
 extern int sal_pcibr_slot_enable(struct pcibus_info *soft, int device,
-                                void *resp);
+                                void *resp, char **ssdt);
 extern int sal_pcibr_slot_disable(struct pcibus_info *soft, int device,
                                  int action, void *resp);
 extern u16 sn_ioboard_to_pci_bus(struct pci_bus *pci_bus);
index 9fe89a93d880b1bfcfd06ea84b9b5d5c35862a93..1c2382cea807b5431d638b23451a1994bad7e50e 100644 (file)
@@ -70,10 +70,16 @@ extern void sn_irq_fixup(struct pci_dev *pci_dev,
                         struct sn_irq_info *sn_irq_info);
 extern void sn_irq_unfixup(struct pci_dev *pci_dev);
 extern struct pcidev_info * sn_pcidev_info_get(struct pci_dev *);
+extern void sn_bus_fixup(struct pci_bus *);
+extern void sn_acpi_bus_fixup(struct pci_bus *);
+extern void sn_common_bus_fixup(struct pci_bus *, struct pcibus_bussoft *);
 extern void sn_bus_store_sysdata(struct pci_dev *dev);
 extern void sn_bus_free_sysdata(void);
 extern void sn_generate_path(struct pci_bus *pci_bus, char *address);
-extern void sn_pci_fixup_slot(struct pci_dev *dev);
+extern void sn_io_slot_fixup(struct pci_dev *);
+extern void sn_acpi_slot_fixup(struct pci_dev *);
+extern void sn_pci_fixup_slot(struct pci_dev *dev, struct pcidev_info *,
+                             struct sn_irq_info *);
 extern void sn_pci_unfixup_slot(struct pci_dev *dev);
 extern void sn_irq_lh_init(void);
 #endif                         /* _ASM_IA64_SN_PCI_PCIDEV_H */
index 6b6fc6f8be7edb75e7f761bd43180a2a603eeadc..a29f05087a310abd56d6c938094a7921c5b7993a 100644 (file)
@@ -37,7 +37,7 @@
  * Calling conventions:
  *
  * ACPI_SYSTEM_XFACE        - Interfaces to host OS (handlers, threads)
- * ACPI_EXTERNAL_XFACE      - External ACPI interfaces 
+ * ACPI_EXTERNAL_XFACE      - External ACPI interfaces
  * ACPI_INTERNAL_XFACE      - Internal ACPI interfaces
  * ACPI_INTERNAL_VAR_XFACE  - Internal variable-parameter list interfaces
  */
 int __acpi_acquire_global_lock(unsigned int *lock);
 int __acpi_release_global_lock(unsigned int *lock);
 
-#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
-       ((Acq) = __acpi_acquire_global_lock((unsigned int *) GLptr))
+#define ACPI_ACQUIRE_GLOBAL_LOCK(facs, Acq) \
+       ((Acq) = __acpi_acquire_global_lock(&facs->global_lock))
 
-#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
-       ((Acq) = __acpi_release_global_lock((unsigned int *) GLptr))
+#define ACPI_RELEASE_GLOBAL_LOCK(facs, Acq) \
+       ((Acq) = __acpi_release_global_lock(&facs->global_lock))
 
 /*
  * Math helper asm macros
@@ -87,10 +87,10 @@ extern int acpi_strict;
 extern int acpi_disabled;
 extern int acpi_pci_disabled;
 extern int acpi_ht;
-static inline void disable_acpi(void) 
-{ 
-       acpi_disabled = 1; 
-       acpi_ht = 0; 
+static inline void disable_acpi(void)
+{
+       acpi_disabled = 1;
+       acpi_ht = 0;
        acpi_pci_disabled = 1;
        acpi_noirq = 1;
 }
@@ -100,9 +100,9 @@ static inline void disable_acpi(void)
 
 extern int acpi_gsi_to_irq(u32 gsi, unsigned int *irq);
 static inline void acpi_noirq_set(void) { acpi_noirq = 1; }
-static inline void acpi_disable_pci(void) 
+static inline void acpi_disable_pci(void)
 {
-       acpi_pci_disabled = 1; 
+       acpi_pci_disabled = 1;
        acpi_noirq_set();
 }
 extern int acpi_irq_balance_set(char *str);
@@ -136,8 +136,6 @@ extern void acpi_reserve_bootmem(void);
 extern int acpi_disabled;
 extern int acpi_pci_disabled;
 
-extern u8 x86_acpiid_to_apicid[];
-
 #define ARCH_HAS_POWER_INIT 1
 
 extern int acpi_skip_timer_override;
index 91f1f23638700b92ec687279ea2ced21cee974c5..815f1fb4ce211302a334d447ae61b72d4c25053a 100644 (file)
@@ -53,166 +53,6 @@ enum acpi_irq_model_id {
 
 extern enum acpi_irq_model_id  acpi_irq_model;
 
-
-/* Root System Description Pointer (RSDP) */
-
-struct acpi_table_rsdp {
-       char                    signature[8];
-       u8                      checksum;
-       char                    oem_id[6];
-       u8                      revision;
-       u32                     rsdt_address;
-} __attribute__ ((packed));
-
-struct acpi20_table_rsdp {
-       char                    signature[8];
-       u8                      checksum;
-       char                    oem_id[6];
-       u8                      revision;
-       u32                     rsdt_address;
-       u32                     length;
-       u64                     xsdt_address;
-       u8                      ext_checksum;
-       u8                      reserved[3];
-} __attribute__ ((packed));
-
-typedef struct {
-       u8                      type;
-       u8                      length;
-} __attribute__ ((packed)) acpi_table_entry_header;
-
-/* Root System Description Table (RSDT) */
-
-struct acpi_table_rsdt {
-       struct acpi_table_header header;
-       u32                     entry[8];
-} __attribute__ ((packed));
-
-/* Extended System Description Table (XSDT) */
-
-struct acpi_table_xsdt {
-       struct acpi_table_header header;
-       u64                     entry[1];
-} __attribute__ ((packed));
-
-/* Fixed ACPI Description Table (FADT) */
-
-struct acpi_table_fadt {
-       struct acpi_table_header header;
-       u32 facs_addr;
-       u32 dsdt_addr;
-       /* ... */
-} __attribute__ ((packed));
-
-/* Multiple APIC Description Table (MADT) */
-
-struct acpi_table_madt {
-       struct acpi_table_header header;
-       u32                     lapic_address;
-       struct {
-               u32                     pcat_compat:1;
-               u32                     reserved:31;
-       }                       flags;
-} __attribute__ ((packed));
-
-enum acpi_madt_entry_id {
-       ACPI_MADT_LAPIC = 0,
-       ACPI_MADT_IOAPIC,
-       ACPI_MADT_INT_SRC_OVR,
-       ACPI_MADT_NMI_SRC,
-       ACPI_MADT_LAPIC_NMI,
-       ACPI_MADT_LAPIC_ADDR_OVR,
-       ACPI_MADT_IOSAPIC,
-       ACPI_MADT_LSAPIC,
-       ACPI_MADT_PLAT_INT_SRC,
-       ACPI_MADT_ENTRY_COUNT
-};
-
-typedef struct {
-       u16                     polarity:2;
-       u16                     trigger:2;
-       u16                     reserved:12;
-} __attribute__ ((packed)) acpi_interrupt_flags;
-
-struct acpi_table_lapic {
-       acpi_table_entry_header header;
-       u8                      acpi_id;
-       u8                      id;
-       struct {
-               u32                     enabled:1;
-               u32                     reserved:31;
-       }                       flags;
-} __attribute__ ((packed));
-
-struct acpi_table_ioapic {
-       acpi_table_entry_header header;
-       u8                      id;
-       u8                      reserved;
-       u32                     address;
-       u32                     global_irq_base;
-} __attribute__ ((packed));
-
-struct acpi_table_int_src_ovr {
-       acpi_table_entry_header header;
-       u8                      bus;
-       u8                      bus_irq;
-       u32                     global_irq;
-       acpi_interrupt_flags    flags;
-} __attribute__ ((packed));
-
-struct acpi_table_nmi_src {
-       acpi_table_entry_header header;
-       acpi_interrupt_flags    flags;
-       u32                     global_irq;
-} __attribute__ ((packed));
-
-struct acpi_table_lapic_nmi {
-       acpi_table_entry_header header;
-       u8                      acpi_id;
-       acpi_interrupt_flags    flags;
-       u8                      lint;
-} __attribute__ ((packed));
-
-struct acpi_table_lapic_addr_ovr {
-       acpi_table_entry_header header;
-       u8                      reserved[2];
-       u64                     address;
-} __attribute__ ((packed));
-
-struct acpi_table_iosapic {
-       acpi_table_entry_header header;
-       u8                      id;
-       u8                      reserved;
-       u32                     global_irq_base;
-       u64                     address;
-} __attribute__ ((packed));
-
-struct acpi_table_lsapic {
-       acpi_table_entry_header header;
-       u8                      acpi_id;
-       u8                      id;
-       u8                      eid;
-       u8                      reserved[3];
-       struct {
-               u32                     enabled:1;
-               u32                     reserved:31;
-       }                       flags;
-} __attribute__ ((packed));
-
-struct acpi_table_plat_int_src {
-       acpi_table_entry_header header;
-       acpi_interrupt_flags    flags;
-       u8                      type;   /* See acpi_interrupt_type */
-       u8                      id;
-       u8                      eid;
-       u8                      iosapic_vector;
-       u32                     global_irq;
-       struct {
-               u32                     cpei_override_flag:1;
-               u32                     reserved:31;
-       }                       plint_flags;
-} __attribute__ ((packed));
-
 enum acpi_interrupt_id {
        ACPI_INTERRUPT_PMI      = 1,
        ACPI_INTERRUPT_INIT,
@@ -222,89 +62,6 @@ enum acpi_interrupt_id {
 
 #define        ACPI_SPACE_MEM          0
 
-struct acpi_gen_regaddr {
-       u8  space_id;
-       u8  bit_width;
-       u8  bit_offset;
-       u8  resv;
-       u32 addrl;
-       u32 addrh;
-} __attribute__ ((packed));
-
-struct acpi_table_hpet {
-       struct acpi_table_header header;
-       u32 id;
-       struct acpi_gen_regaddr addr;
-       u8 number;
-       u16 min_tick;
-       u8 page_protect;
-} __attribute__ ((packed));
-
-/*
- * Simple Boot Flags
- * http://www.microsoft.com/whdc/hwdev/resources/specs/simp_bios.mspx
- */
-struct acpi_table_sbf
-{
-       u8 sbf_signature[4];
-       u32 sbf_len;
-       u8 sbf_revision;
-       u8 sbf_csum;
-       u8 sbf_oemid[6];
-       u8 sbf_oemtable[8];
-       u8 sbf_revdata[4];
-       u8 sbf_creator[4];
-       u8 sbf_crearev[4];
-       u8 sbf_cmos;
-       u8 sbf_spare[3];
-} __attribute__ ((packed));
-
-/*
- * System Resource Affinity Table (SRAT)
- * http://www.microsoft.com/whdc/hwdev/platform/proc/SRAT.mspx
- */
-
-struct acpi_table_srat {
-       struct acpi_table_header header;
-       u32                     table_revision;
-       u64                     reserved;
-} __attribute__ ((packed));
-
-enum acpi_srat_entry_id {
-       ACPI_SRAT_PROCESSOR_AFFINITY = 0,
-       ACPI_SRAT_MEMORY_AFFINITY,
-       ACPI_SRAT_ENTRY_COUNT
-};
-
-struct acpi_table_processor_affinity {
-       acpi_table_entry_header header;
-       u8                      proximity_domain;
-       u8                      apic_id;
-       struct {
-               u32                     enabled:1;
-               u32                     reserved:31;
-       }                       flags;
-       u8                      lsapic_eid;
-       u8                      reserved[7];
-} __attribute__ ((packed));
-
-struct acpi_table_memory_affinity {
-       acpi_table_entry_header header;
-       u8                      proximity_domain;
-       u8                      reserved1[5];
-       u32                     base_addr_lo;
-       u32                     base_addr_hi;
-       u32                     length_lo;
-       u32                     length_hi;
-       u32                     memory_type;    /* See acpi_address_range_id */
-       struct {
-               u32                     enabled:1;
-               u32                     hot_pluggable:1;
-               u32                     reserved:30;
-       }                       flags;
-       u64                     reserved2;
-} __attribute__ ((packed));
-
 enum acpi_address_range_id {
        ACPI_ADDRESS_RANGE_MEMORY = 1,
        ACPI_ADDRESS_RANGE_RESERVED = 2,
@@ -313,84 +70,12 @@ enum acpi_address_range_id {
        ACPI_ADDRESS_RANGE_COUNT
 };
 
-/*
- * System Locality Information Table (SLIT)
- *   see http://devresource.hp.com/devresource/docs/techpapers/ia64/slit.pdf
- */
-
-struct acpi_table_slit {
-       struct acpi_table_header header;
-       u64                     localities;
-       u8                      entry[1];       /* real size = localities^2 */
-} __attribute__ ((packed));
-
-/* Smart Battery Description Table (SBST) */
-
-struct acpi_table_sbst {
-       struct acpi_table_header header;
-       u32                     warning;        /* Warn user */
-       u32                     low;            /* Critical sleep */
-       u32                     critical;       /* Critical shutdown */
-} __attribute__ ((packed));
-
-/* Embedded Controller Boot Resources Table (ECDT) */
-
-struct acpi_table_ecdt {
-       struct acpi_table_header        header;
-       struct acpi_generic_address     ec_control;
-       struct acpi_generic_address     ec_data;
-       u32                             uid;
-       u8                              gpe_bit;
-       char                            ec_id[0];
-} __attribute__ ((packed));
-
-/* PCI MMCONFIG */
-
-/* Defined in PCI Firmware Specification 3.0 */
-struct acpi_table_mcfg_config {
-       u32                             base_address;
-       u32                             base_reserved;
-       u16                             pci_segment_group_number;
-       u8                              start_bus_number;
-       u8                              end_bus_number;
-       u8                              reserved[4];
-} __attribute__ ((packed));
-struct acpi_table_mcfg {
-       struct acpi_table_header        header;
-       u8                              reserved[8];
-       struct acpi_table_mcfg_config   config[0];
-} __attribute__ ((packed));
 
 /* Table Handlers */
 
-enum acpi_table_id {
-       ACPI_TABLE_UNKNOWN = 0,
-       ACPI_APIC,
-       ACPI_BOOT,
-       ACPI_DBGP,
-       ACPI_DSDT,
-       ACPI_ECDT,
-       ACPI_ETDT,
-       ACPI_FADT,
-       ACPI_FACS,
-       ACPI_OEMX,
-       ACPI_PSDT,
-       ACPI_SBST,
-       ACPI_SLIT,
-       ACPI_SPCR,
-       ACPI_SRAT,
-       ACPI_SSDT,
-       ACPI_SPMI,
-       ACPI_HPET,
-       ACPI_MCFG,
-       ACPI_TABLE_COUNT
-};
-
-typedef int (*acpi_table_handler) (unsigned long phys_addr, unsigned long size);
-
-extern acpi_table_handler acpi_table_ops[ACPI_TABLE_COUNT];
+typedef int (*acpi_table_handler) (struct acpi_table_header *table);
 
-typedef int (*acpi_madt_entry_handler) (acpi_table_entry_header *header, const unsigned long end);
+typedef int (*acpi_madt_entry_handler) (struct acpi_subtable_header *header, const unsigned long end);
 
 char * __acpi_map_table (unsigned long phys_addr, unsigned long size);
 unsigned long acpi_find_rsdp (void);
@@ -399,14 +84,12 @@ int acpi_boot_table_init (void);
 int acpi_numa_init (void);
 
 int acpi_table_init (void);
-int acpi_table_parse (enum acpi_table_id id, acpi_table_handler handler);
-int acpi_get_table_header_early (enum acpi_table_id id, struct acpi_table_header **header);
-int acpi_table_parse_madt (enum acpi_madt_entry_id id, acpi_madt_entry_handler handler, unsigned int max_entries);
-int acpi_table_parse_srat (enum acpi_srat_entry_id id, acpi_madt_entry_handler handler, unsigned int max_entries);
-int acpi_parse_mcfg (unsigned long phys_addr, unsigned long size);
-void acpi_table_print (struct acpi_table_header *header, unsigned long phys_addr);
-void acpi_table_print_madt_entry (acpi_table_entry_header *madt);
-void acpi_table_print_srat_entry (acpi_table_entry_header *srat);
+int acpi_table_parse (char *id, acpi_table_handler handler);
+int acpi_table_parse_madt (enum acpi_madt_type id, acpi_madt_entry_handler handler, unsigned int max_entries);
+int acpi_table_parse_srat (enum acpi_srat_type id, acpi_madt_entry_handler handler, unsigned int max_entries);
+int acpi_parse_mcfg (struct acpi_table_header *header);
+void acpi_table_print_madt_entry (struct acpi_subtable_header *madt);
+void acpi_table_print_srat_entry (struct acpi_subtable_header *srat);
 
 /* the following four functions are architecture-dependent */
 #ifdef CONFIG_HAVE_ARCH_PARSE_SRAT
@@ -417,8 +100,8 @@ void acpi_table_print_srat_entry (acpi_table_entry_header *srat);
 #define acpi_numa_arch_fixup() do {} while (0)
 #else
 void acpi_numa_slit_init (struct acpi_table_slit *slit);
-void acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa);
-void acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma);
+void acpi_numa_processor_affinity_init (struct acpi_srat_cpu_affinity *pa);
+void acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
 void acpi_numa_arch_fixup(void);
 #endif
 
@@ -433,7 +116,7 @@ int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base);
 
 extern int acpi_mp_config;
 
-extern struct acpi_table_mcfg_config *pci_mmcfg_config;
+extern struct acpi_mcfg_allocation *pci_mmcfg_config;
 extern int pci_mmcfg_config_num;
 
 extern int sbf_port;
index ccd706f876ec118112e3591a6aa2d28ecb3893e8..5b4f1e3caf5d5a69b852e86f2189414241b8e298 100644 (file)
 #define PCI_VENDOR_ID_TDI               0x192E
 #define PCI_DEVICE_ID_TDI_EHCI          0x0101
 
+#define PCI_VENDOR_ID_PASEMI           0x1959
+
 #define PCI_VENDOR_ID_JMICRON          0x197B
 #define PCI_DEVICE_ID_JMICRON_JMB360   0x2360
 #define PCI_DEVICE_ID_JMICRON_JMB361   0x2361
diff --git a/include/linux/video_output.h b/include/linux/video_output.h
new file mode 100644 (file)
index 0000000..e63e0c0
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ *
+ *  Copyright (C) 2006 Luming Yu <luming.yu@intel.com>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or (at
+ *  your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#ifndef _LINUX_VIDEO_OUTPUT_H
+#define _LINUX_VIDEO_OUTPUT_H
+#include <linux/device.h>
+struct output_device;
+struct output_properties {
+       int (*set_state)(struct output_device *);
+       int (*get_status)(struct output_device *);
+};
+struct output_device {
+       int request_state;
+       struct output_properties *props;
+       struct class_device class_dev;
+};
+#define to_output_device(obj) container_of(obj, struct output_device, class_dev)
+struct output_device *video_output_register(const char *name,
+       struct device *dev,
+       void *devdata,
+       struct output_properties *op);
+void video_output_unregister(struct output_device *dev);
+#endif
index fa2f7da606a95488f5893b5cf4538c6083b770b9..fb58e03b3fbda3497245f3b484c01db14a343e4c 100644 (file)
@@ -265,6 +265,12 @@ ieee80211softmac_wx_get_rate(struct net_device *net_dev,
        int err = -EINVAL;
 
        spin_lock_irqsave(&mac->lock, flags);
+
+       if (unlikely(!mac->running)) {
+               err = -ENODEV;
+               goto out_unlock;
+       }
+
        switch (mac->txrates.default_rate) {
        case IEEE80211_CCK_RATE_1MB:
                data->bitrate.value = 1000000;
index 96926eb13b0a5f59edd14849e32c825143c2eb18..d65c40331e66193c731daaad592019569e4582af 100644 (file)
@@ -57,7 +57,7 @@ endef
 # See documentation in Documentation/kbuild/makefiles.txt
 
 # checker-shell
-# Usage: option = $(call checker-shell, $(CC)...-o $$OUT, option-ok, otherwise)
+# Usage: option = $(call checker-shell,$(CC)...-o $$OUT,option-ok,otherwise)
 # Exit code chooses option. $$OUT is safe location for needless output.
 define checker-shell
   $(shell set -e; \
@@ -74,23 +74,23 @@ define checker-shell
 endef
 
 # as-option
-# Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,)
-as-option = $(call checker-shell, \
-   $(CC) $(CFLAGS) $(1) -c -xassembler /dev/null -o $$OUT, $(1), $(2))
+# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
+as-option = $(call checker-shell,\
+   $(CC) $(CFLAGS) $(1) -c -xassembler /dev/null -o $$OUT,$(1),$(2))
 
 # as-instr
-# Usage: cflags-y += $(call as-instr, instr, option1, option2)
-as-instr = $(call checker-shell, \
-   printf "$(1)" | $(CC) $(AFLAGS) -c -xassembler -o $$OUT -, $(2), $(3))
+# Usage: cflags-y += $(call as-instr,instr,option1,option2)
+as-instr = $(call checker-shell,\
+   printf "$(1)" | $(CC) $(AFLAGS) -c -xassembler -o $$OUT -,$(2),$(3))
 
 # cc-option
-# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586)
-cc-option = $(call checker-shell, \
-   $(CC) $(CFLAGS) $(if $(3),$(3),$(1)) -S -xc /dev/null -o $$OUT, $(1), $(2))
+# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
+cc-option = $(call checker-shell,\
+   $(CC) $(CFLAGS) $(if $(3),$(3),$(1)) -S -xc /dev/null -o $$OUT,$(1),$(2))
 
 # cc-option-yn
-# Usage: flag := $(call cc-option-yn, -march=winchip-c6)
-cc-option-yn = $(call cc-option, "y", "n", $(1))
+# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
+cc-option-yn = $(call cc-option,"y","n",$(1))
 
 # cc-option-align
 # Prefix align with either -falign or -malign
@@ -98,7 +98,7 @@ cc-option-align = $(subst -functions=0,,\
    $(call cc-option,-falign-functions=0,-malign-functions=0))
 
 # cc-version
-# Usage gcc-ver := $(call cc-version, $(CC))
+# Usage gcc-ver := $(call cc-version,$(CC))
 cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
 
 # cc-ifversion
@@ -107,8 +107,8 @@ cc-ifversion = $(shell [ $(call cc-version, $(CC)) $(1) $(2) ] && echo $(3))
 
 # ld-option
 # Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=both)
-ld-option = $(call checker-shell, \
-   $(CC) $(1) -nostdlib -xc /dev/null -o $$OUT, $(1), $(2))
+ld-option = $(call checker-shell,\
+   $(CC) $(1) -nostdlib -xc /dev/null -o $$OUT,$(1),$(2))
 
 ######
 
@@ -120,22 +120,22 @@ build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
 # Prefix -I with $(srctree) if it is not an absolute path,
 # add original to the end
 addtree = $(if \
-       $(filter-out -I/%, $(1)), $(patsubst -I%,-I$(srctree)/%,$(1))) $(1)
+       $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1)
 
 # Find all -I options and call addtree
-flags = $(foreach o,$($(1)), \
-       $(if $(filter -I%,$(o)), $(call addtree, $(o)), $(o)))
+flags = $(foreach o,$($(1)),\
+       $(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o)))
 
 # echo command.
 # Short version is used, if $(quiet) equals `quiet_', otherwise full one.
-echo-cmd = $(if $($(quiet)cmd_$(1)), \
+echo-cmd = $(if $($(quiet)cmd_$(1)),\
        echo '  $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
 
 # printing commands
 cmd = @$(echo-cmd) $(cmd_$(1))
 
 # Add $(obj)/ for paths that are not absolute
-objectify = $(foreach o,$(1), $(if $(filter /%,$(o)), $(o), $(obj)/$(o)))
+objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
 
 ###
 # if_changed      - execute command if any prerequisite is newer than