diff -uNr vmnet-only-org/Makefile vmnet-only/Makefile
--- vmnet-only-org/Makefile	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/Makefile	2008-03-07 15:31:40.000000000 +0900
@@ -2,6 +2,7 @@
 #############################################################
 # Copyright 1998 VMware, Inc.  All rights reserved. -- VMware Confidential
 #############################################################
+
 ####
 ####  VMware kernel module Makefile to be distributed externally
 ####
@@ -20,20 +21,55 @@
 
 DRIVER := vmnet
 
+ifeq ($(DRIVER), vmnet)
+ifndef VMWARE_VER
+VMWARE_VER := $(shell $(SRCROOT)/getversion.pl)
+export VMWARE_VER
+endif
+endif
+
 # Grep program
 GREP = /bin/grep
 
 vm_check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
         > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)
+vm_check_gxx = $(shell if $(CC) $(1) -S -o /dev/null -xc++ /dev/null \
+        > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)
 vm_check_file = $(shell if test -f $(1); then echo "yes"; else echo "no"; fi)
 
 ifndef VM_KBUILD
 VM_KBUILD := no
+VM_KBUILD_OUTPUT := $(KBUILD_OUTPUT)
+ifdef O
+  ifeq ("$(origin O)", "command line")
+    VM_KBUILD_OUTPUT := $(O)
+  endif
+endif
+ifeq ($(VM_KBUILD_OUTPUT),)
+VM_KBUILD_OUTPUT := $(BUILD_DIR)
+endif
 ifeq ($(call vm_check_file,$(BUILD_DIR)/Makefile), yes)
-ifneq ($(call vm_check_file,$(BUILD_DIR)/Rules.make), yes)
+ifeq ($(call vm_check_file,$(VM_KBUILD_OUTPUT)/.config), no)
+VM_DUMMY := $(shell echo >&2 '*** Your sources installation is broken:')
+VM_DUMMY := $(shell echo >&2 '*** $(BUILD_DIR) does not contain .config file')
+VM_DUMMY := $(shell echo >&2 '*** vmmon/vmnet build may fail, or built vmmon/vmnet may crash.')
+ifeq ($(call vm_check_file,/boot/vmlinuz.config), yes)
+VM_DUMMY := $(shell echo >&2 '*** You are apparently use SuSE system. You should copy')
+VM_DUMMY := $(shell echo >&2 '*** /boot/vmlinuz.config to the $(BUILD_DIR)/.config.')
+endif
+VM_DUMMY := $(shell echo >&2)
+VM_DUMMY := $(shell echo >&2 '*** Hit ENTER to continue, or ^C to stop build.')
+VM_DUMMY := $(shell read dummy)
+else
+ifeq ($(call vm_check_file,$(BUILD_DIR)/Rules.make), yes)
+ifeq ($(shell if $(GREP) "^PATCHLEVEL = 4$$" $(BUILD_DIR)/Makefile > /dev/null 2>&1; then echo "yes"; fi), yes)
+VM_KBUILD := 24
+endif
+else
 VM_KBUILD := 26
 endif
 endif
+endif
 export VM_KBUILD
 endif
 
@@ -95,6 +131,30 @@
 
 endif
 
+VMWARE_DEBUG_REDIRECT := > /dev/null 2>&1
+ifeq ($(VMWARE_DEBUG_AUTOCONF),y)
+ifneq ($(VERSION),)
+VMWARE_DEBUG_REDIRECT := >&2
+endif
+endif
+vm_check_build = $(shell if $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
+	$(CPPFLAGS) $(CFLAGS) $(CFLAGS_KERNEL) \
+	$(EXTRA_CFLAGS) -Iinclude2/asm/mach-default \
+	-DKBUILD_BASENAME=\"$(DRIVER)\" \
+	-Werror -S -o /dev/null -xc $(1) \
+	$(VMWARE_DEBUG_REDIRECT); then echo "$(2)"; else echo "$(3)"; fi)
+
+CC_WARNINGS := -Wall -Wstrict-prototypes
+CC_OPTS := $(GLOBAL_DEFS) $(CC_WARNINGS) -DVMW_USING_KBUILD
+ifdef VMX86_DEVEL
+CC_OPTS += -DVMX86_DEVEL
+endif
+ifdef VMX86_DEBUG
+CC_OPTS += -DVMX86_DEBUG
+endif
+CC_OPTS += -DVME_DEFAULT=$(VMWARE_VER)
+
+
 include $(SRCROOT)/Makefile.kernel
 
 ifdef TOPDIR
diff -uNr vmnet-only-org/Makefile.kernel vmnet-only/Makefile.kernel
--- vmnet-only-org/Makefile.kernel	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/Makefile.kernel	2008-03-07 15:31:40.000000000 +0900
@@ -6,15 +6,8 @@
 ####  VMware vmnet Makefile to be distributed externally
 ####
 
-vm_check_build = $(shell if $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_KERNEL) \
-	$(EXTRA_CFLAGS) -Iinclude2/asm/mach-default -DKBUILD_BASENAME=\"$(DRIVER)\" \
-	-Werror -S -o /dev/null -xc $(1) \
-	> /dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi)
-
-CC_WARNINGS := -Wall -Wstrict-prototypes 
-CC_OPTS := $(GLOBAL_DEFS) $(CC_WARNINGS) 
-
-CC_OPTS += -DVMW_USING_KBUILD
+CC_OPTS += $(call vm_check_gcc,-Wno-unused-parameter,)
+CC_OPTS += $(call vm_check_gcc,-Wno-sign-compare,)
 
 INCLUDE := -I$(SRCROOT)
 
@@ -22,7 +15,10 @@
 EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/epoll.c,   -DVMW_HAVE_EPOLL, )
 EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/socket.c,  -DVMW_HAVE_SK_WMEM_ALLOC, )
 EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/sk_alloc.c,-DVMW_HAVE_SK_ALLOC_WITH_PROTO, )
+EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/netdev_has_net.c,-DVMW_NETDEV_HAS_NET, )
+EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/nfhook_uses_skb.c,-DVMW_NFHOOK_USES_SKB, )
 EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/setnice.c, -DVMW_HAVE_SET_USER_NICE, )
+EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/skblin.c,  -DVMW_SKB_LINEARIZE_2618, )
 
 obj-m += $(DRIVER).o
 
@@ -42,5 +38,6 @@
 ####
 
 clean:
-	rm -rf $(DRIVER).o $(DRIVER).mod.o $(DRIVER).mod.c $(DRIVER).ko .tmp_versions \
+	rm -rf $(DRIVER).o $(DRIVER).mod.o $(DRIVER).mod.c $(DRIVER).ko \
+	       .tmp_versions Module.symvers Modules.symvers \
 	       $($(DRIVER)-y) .*.cmd .*.o.flags
diff -uNr vmnet-only-org/Makefile.normal vmnet-only/Makefile.normal
--- vmnet-only-org/Makefile.normal	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/Makefile.normal	2008-03-07 15:31:40.000000000 +0900
@@ -36,10 +36,13 @@
 INCLUDE += $(shell $(CC) $(INCLUDE) -E geninclude.c \
 	   | sed -n -e 's!^APATH!-I$(HEADER_DIR)/asm!p')
 
+CC_OPTS += -DVME_DEFAULT=$(VMWARE_VER)
 CC_OPTS += $(call vm_check_build, $(SRCROOT)/epoll.c,   -DVMW_HAVE_EPOLL, )
 CC_OPTS += $(call vm_check_build, $(SRCROOT)/socket.c,  -DVMW_HAVE_SK_WMEM_ALLOC, )
 CC_OPTS += $(call vm_check_build, $(SRCROOT)/sk_alloc.c,-DVMW_HAVE_SK_ALLOC_WITH_PROTO, )
+CC_OPTS += $(call vm_check_build, $(SRCROOT)/netdev_has_net.c,-DVMW_NETDEV_HAS_NET, )
 CC_OPTS += $(call vm_check_build, $(SRCROOT)/setnice.c, -DVMW_HAVE_SET_USER_NICE, )
+CC_OPTS += $(call vm_check_build, $(SRCROOT)/skblin.c, -DVMW_SKB_LINEARIZE_2618, )
 
 CFLAGS := -O $(CC_WARNINGS) $(CC_OPTS) $(INCLUDE) $(GLOBAL_DEFS)
 
@@ -51,21 +54,18 @@
 
 default: all
 
-all: $(DRIVERNAME)
+all: $(DRIVER).o
 
 $(DRIVERNAME): $(OBJS) $(SMAC)
 	$(LD) -r -o $@ $^
 
-$(DRIVER): $(DRIVERNAME)
-	cp -f $< $@
-
-../$(DRIVER).o: $(DRIVERNAME)
+$(DRIVER) $(DRIVER).o ../$(DRIVER).o: $(DRIVERNAME)
 	cp -f $< $@
 
 auto-build: ../$(DRIVER).o
 
 clean:
-	rm -f $(DRIVERNAME) $(OBJS)
+	rm -f $(DRIVERNAME) $(DRIVER) $(DRIVER).o ../$(DRIVER).o $(OBJS)
 
 .PHONY: default all auto-build clean
 
diff -uNr vmnet-only-org/bridge.c vmnet-only/bridge.c
--- vmnet-only-org/bridge.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/bridge.c	2008-03-07 15:31:40.000000000 +0900
@@ -32,8 +32,9 @@
 #include <linux/tcp.h>
 #include <net/tcp.h>
 
-#ifdef CONFIG_NET_RADIO
+#if defined(CONFIG_NET_RADIO) || defined(CONFIG_WLAN_80211)
 #   include <linux/wireless.h>
+#   include <net/iw_handler.h>
 #endif
 #include "vmnetInt.h"
 #include "compat_spinlock.h"
@@ -72,12 +73,15 @@
    VNetPort                 port;           // connection to virtual hub
    Bool                     wirelessAdapter; // connected to wireless adapter?
    struct SMACState        *smac;           // device structure for wireless
+#ifdef VMW_NETDEV_HAS_NET
+   struct net_device       *internalDev;
+#endif
 };
 
 typedef PacketStatus (* SMACINT SMACFunc)(struct SMACState *, SMACPackets *);
 
-static int  VNetBridgeUp(VNetBridge *bridge);
-static void VNetBridgeDown(VNetBridge *bridge);
+static int  VNetBridgeUp(VNetBridge *bridge, Bool rtnlLock);
+static void VNetBridgeDown(VNetBridge *bridge, Bool rtnlLock);
 
 static int  VNetBridgeNotify(struct notifier_block *this, u_long msg,
 			     void *data);
@@ -110,8 +114,6 @@
  *
  *      Set IFF_PROMISC on the peer interface.
  *
- *      XXX need locking?
- *
  * Results:
  *      None.
  *
@@ -122,7 +124,8 @@
  */
 
 static void
-VNetBridgeStartPromisc(VNetBridge *bridge)
+VNetBridgeStartPromisc(VNetBridge *bridge,      // IN:
+                       Bool rtnlLock)           // IN: Acquire RTNL lock
 {
    struct net_device *dev = bridge->dev;
 
@@ -131,6 +134,9 @@
     * cards which do support RF monitoring would not be able to function
     * correctly i.e. they would not be able to send data packets.
     */
+   if (rtnlLock) {
+      rtnl_lock();
+   }
    if (!bridge->enabledPromisc && !bridge->wirelessAdapter) {
       dev_set_promiscuity(dev, 1);
       bridge->enabledPromisc = TRUE;
@@ -138,6 +144,9 @@
       LOG(0, (KERN_NOTICE "bridge-%s: enabled promiscuous mode\n",
 	      bridge->name));
    }
+   if (rtnlLock) {
+      rtnl_unlock();
+   }
 }
 
 
@@ -148,8 +157,6 @@
  *
  *      Restore saved IFF_PROMISC on the peer interface.
  *
- *      XXX need locking?
- *
  * Results:
  *      None.
  *
@@ -160,16 +167,23 @@
  */
 
 static void
-VNetBridgeStopPromisc(VNetBridge *bridge)
+VNetBridgeStopPromisc(VNetBridge *bridge,       // IN:
+                      Bool rtnlLock)            // IN: Acquire RTNL lock
 {
    struct net_device *dev = bridge->dev;
 
+   if (rtnlLock) {
+      rtnl_lock();
+   }
    if (bridge->enabledPromisc && !bridge->wirelessAdapter) {
       dev_set_promiscuity(dev, -1);
       bridge->enabledPromisc = FALSE;
       LOG(0, (KERN_NOTICE "bridge-%s: disabled promiscuous mode\n",
 	      bridge->name));
    }
+   if (rtnlLock) {
+      rtnl_unlock();
+   }
 }
 
 
@@ -182,8 +196,6 @@
  *
  *      This can be called periodically.
  *
- *      XXX need locking?
- *
  * Results:
  *      None.
  *
@@ -196,6 +208,7 @@
 static INLINE_SINGLE_CALLER void
 VNetBridgeCheckPromisc(VNetBridge *bridge)
 {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
    if (bridge->enabledPromisc && !bridge->wirelessAdapter) {
       struct net_device *dev = bridge->dev;
       Bool devPromisc = (dev->flags & IFF_PROMISC) != 0;
@@ -207,9 +220,67 @@
 	            "Your Ethernet driver is not compatible with VMware's bridged networking.\n",
                     bridge->name));
          }
+         rtnl_lock();
          dev_set_promiscuity(dev, 0);
+         rtnl_unlock();
       }
    }
+#endif
+}
+
+
+#ifdef VMW_NETDEV_HAS_NET
+/*
+ *----------------------------------------------------------------------
+ *
+ * VNetBridgeInternalSetup --
+ *
+ *      Setup callback for our bridge internal device.  Nothing to do,
+ *      generic code sets up everything we expect from device.
+ *
+ * Results:
+ *      None.
+ *
+ * Side effects:
+ *      None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void
+VNetBridgeInternalSetup(struct net_device *net)
+{
+   /* Do nothing. */
+}
+#endif
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * VNetBridgeDevCompatible --
+ *
+ *      Check whether bridge and network device are compatible.
+ *
+ * Results:
+ *      Non-zero if device is good enough for bridge.  Zero otherwise.
+ *
+ * Side effects:
+ *      None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static INLINE_SINGLE_CALLER int
+VNetBridgeDevCompatible(VNetBridge *bridge,      // IN: Bridge
+                        struct net_device *net)  // IN: Network device
+{
+#ifdef VMW_NETDEV_HAS_NET
+   if (net->nd_net != bridge->internalDev->nd_net) {
+      return 0;
+   }
+#endif
+   return strcmp(net->name, bridge->name) == 0;
 }
 
 
@@ -233,8 +304,8 @@
  */
 
 int
-VNetBridge_Create(char      *devName, // IN:  name of device (e.g., "eth0")
-                  VNetPort **ret)     // OUT: port to virtual hub
+VNetBridge_Create(const char *devName, // IN:  name of device (e.g., "eth0")
+                  VNetPort **ret)      // OUT: port to virtual hub
 {
    VNetBridge *bridge = NULL;
    static unsigned id = 0;
@@ -265,6 +336,14 @@
    memcpy(bridge->name, devName, sizeof bridge->name);
    NULL_TERMINATE_STRING(bridge->name);
 
+#ifdef VMW_NETDEV_HAS_NET
+   bridge->internalDev = compat_alloc_netdev(0, "vmnetX", VNetBridgeInternalSetup);
+   if (!bridge->internalDev) {
+      retval = -ENOMEM;
+      goto out;
+   }
+#endif
+
    /*
     * Set up notifier for network device state change
     */
@@ -277,7 +356,7 @@
     * Try to bring it up
     */
 
-   retval = VNetBridgeUp(bridge);
+   retval = VNetBridgeUp(bridge, TRUE);
    if (retval == -ENODEV) {
       LOG(1, (KERN_DEBUG "bridge-%s: peer interface %s not found, "
 	      "will wait for it to come up\n",
@@ -353,6 +432,11 @@
       if (bridge->notifier.notifier_call != NULL) {
          unregister_netdevice_notifier(&bridge->notifier);
       }
+#ifdef VMW_NETDEV_HAS_NET
+      if (bridge->internalDev) {
+         compat_free_netdev(bridge->internalDev);
+      }
+#endif
       kfree(bridge);
    }
    return retval;
@@ -382,11 +466,17 @@
    VNetBridge *bridge = (VNetBridge*)this->private;
 
    if (bridge->dev != NULL) {
-      VNetBridgeDown(bridge);
+      VNetBridgeDown(bridge, TRUE);
    }
 
    unregister_netdevice_notifier(&bridge->notifier);
 
+#ifdef VMW_NETDEV_HAS_NET
+   if (bridge->internalDev) {
+      compat_free_netdev(bridge->internalDev);
+   }
+#endif
+
    if (this->procEntry) {
       VNetProc_RemoveEntry(this->procEntry, NULL);
    }
@@ -537,7 +627,7 @@
 
    dev_lock_list();
    if (MAC_EQ(dest, dev->dev_addr) ||
-       skb->len > dev->mtu + dev->hard_header_len) {
+       skb->len > dev->mtu + dev->hard_header_len + 4) {
       dev_unlock_list();
    } else {
 #     if 0 // XXX we should do header translation
@@ -583,7 +673,7 @@
     * We save it so we can recognize it (and its clones) again.
     */
 
-   if (VNetPacketMatch(dest, dev->dev_addr, (uint8 *)&AllMultiFilter, dev->flags)) {
+   if (VNetPacketMatch(dest, dev->dev_addr, allMultiFilter, dev->flags)) {
       clone = skb_clone(skb, GFP_ATOMIC);
       if (clone) {
 	 unsigned long flags;
@@ -708,9 +798,9 @@
    VNetBridge *bridge = (VNetBridge*)this->private;
    if (bridge->dev) {
       if (VNetGetAttachedPorts(this)) {
-         VNetBridgeStartPromisc(bridge);
+         VNetBridgeStartPromisc(bridge, TRUE);
       } else {
-         VNetBridgeStopPromisc(bridge);
+         VNetBridgeStopPromisc(bridge, TRUE);
       }
    }
 }
@@ -764,14 +854,16 @@
 static Bool
 VNetBridgeIsDeviceWireless(struct net_device *dev) //IN: sock
 {
-#if !defined(CONFIG_NET_RADIO)
+#ifdef CONFIG_WIRELESS_EXT
+   return dev->wireless_handlers != NULL;
+#elif !defined CONFIG_NET_RADIO && !defined CONFIG_WLAN_80211
    return FALSE;
 #elif WIRELESS_EXT > 19
    return dev->wireless_handlers != NULL;
 #elif WIRELESS_EXT > 12
-   return dev->wireless_handlers != NULL || dev->get_wireless_stats != NULL;
+   return dev->wireless_handlers != NULL || dev->wireless_handlers->get_wireless_stats(dev) != NULL;
 #else
-   return dev->get_wireless_stats != NULL;
+   return dev->wireless_handlers->get_wireless_stats(dev) != NULL;
 #endif
 }
 
@@ -796,7 +888,8 @@
  */
 
 int
-VNetBridgeUp(VNetBridge *bridge) // IN: bridge struct
+VNetBridgeUp(VNetBridge *bridge, // IN: bridge struct
+             Bool rtnlLock)      // IN: acquire RTNL lock
 {
    int retval = 0;
 
@@ -810,7 +903,7 @@
     */
 
    dev_lock_list();
-   bridge->dev = DEV_GET(bridge->name);
+   bridge->dev = DEV_GET(bridge);
    LOG(2, (KERN_DEBUG "bridge-%s: got dev %p\n",
 	   bridge->name, bridge->dev));
    if (bridge->dev == NULL) {
@@ -833,8 +926,8 @@
     * is an Ethernet.
     */
 
-   if (bridge->dev->hard_header_len != ETH_HLEN) {
-      LOG(1, (KERN_DEBUG "bridge-%s: can't bridge with %s, bad header length %d\n",
+   if (bridge->dev->hard_header_len != ETH_HLEN && bridge->dev->hard_header_len != ETH_HLEN + 4) {
+      LOG(1, (KERN_DEBUG "bridge-%s: can't bridge with %s, bad header length %d\n", 
 	      bridge->name, bridge->dev->name, bridge->dev->hard_header_len));
       dev_unlock_list();
       retval = -EINVAL;
@@ -848,7 +941,7 @@
     * (The alternative is to support the callback.)
     */
 
-   bridge->sk = compat_sk_alloc(GFP_ATOMIC);
+   bridge->sk = compat_sk_alloc(bridge, GFP_ATOMIC);
    if (bridge->sk == NULL) {
       dev_unlock_list();
       retval = -ENOMEM;
@@ -905,7 +998,7 @@
 
    down(&vnetStructureSemaphore);
    if (VNetGetAttachedPorts(&bridge->port.jack)) {
-      VNetBridgeStartPromisc(bridge);
+      VNetBridgeStartPromisc(bridge, rtnlLock);
    }
    up(&vnetStructureSemaphore);
 
@@ -950,14 +1043,15 @@
  */
 
 void
-VNetBridgeDown(VNetBridge *bridge) // IN: bridge
+VNetBridgeDown(VNetBridge *bridge, // IN: bridge
+               Bool rtnlLock)      // IN: acquire RTNL lock
 {
    if (bridge->dev == NULL) {
       LOG(0, (KERN_NOTICE "bridge-%s: already down\n", bridge->name));
       return;
    }
 
-   VNetBridgeStopPromisc(bridge);
+   VNetBridgeStopPromisc(bridge, rtnlLock);
    if (bridge->smac){
       SMAC_SetMac(bridge->smac, NULL);
    }
@@ -1003,7 +1097,7 @@
          LOG(0, (KERN_WARNING "bridge-%s: interface %s unregistered without "
                  "going down! Disabling the bridge\n", bridge->name,
                  dev->name));
-         VNetBridgeDown(bridge);
+         VNetBridgeDown(bridge, FALSE);
       }
       break;
 
@@ -1013,18 +1107,18 @@
       if (dev == bridge->dev) {
          LOG(1, (KERN_DEBUG "bridge-%s: disabling the bridge\n",
                  bridge->name));
-         VNetBridgeDown(bridge);
+         VNetBridgeDown(bridge, FALSE);
       }
       break;
 
    case NETDEV_UP:
       LOG(2, (KERN_DEBUG "bridge-%s: interface %s is going up\n",
               bridge->name, dev->name));
-      if (bridge->dev == NULL && strcmp(dev->name, bridge->name) == 0) {
+      if (bridge->dev == NULL && VNetBridgeDevCompatible(bridge, dev)) {
          int errno;
 
          LOG(1, (KERN_DEBUG "bridge-%s: enabling the bridge\n", bridge->name));
-	 errno = VNetBridgeUp(bridge);
+	 errno = VNetBridgeUp(bridge, FALSE);
 	 switch (-errno) {
 	 case 0:
 	    break;
diff -uNr vmnet-only-org/compat_file.h vmnet-only/compat_file.h
--- vmnet-only-org/compat_file.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_file.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_FILE_H__
 #   define __COMPAT_FILE_H__
 
diff -uNr vmnet-only-org/compat_highmem.h vmnet-only/compat_highmem.h
--- vmnet-only-org/compat_highmem.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_highmem.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_HIGHMEM_H__
 #   define __COMPAT_HIGHMEM_H__
 
diff -uNr vmnet-only-org/compat_kdev_t.h vmnet-only/compat_kdev_t.h
--- vmnet-only-org/compat_kdev_t.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_kdev_t.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_KDEV_T_H__
 #   define __COMPAT_KDEV_T_H__
 
diff -uNr vmnet-only-org/compat_mm.h vmnet-only/compat_mm.h
--- vmnet-only-org/compat_mm.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_mm.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_MM_H__
 #   define __COMPAT_MM_H__
 
diff -uNr vmnet-only-org/compat_netdevice.h vmnet-only/compat_netdevice.h
--- vmnet-only-org/compat_netdevice.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_netdevice.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_NETDEVICE_H__
 #   define __COMPAT_NETDEVICE_H__
 
@@ -31,7 +35,8 @@
 /*
  * SET_MODULE_OWNER appeared sometime during 2.3.x. It was setting
  * dev->owner = THIS_MODULE until 2.5.70, where netdevice refcounting
- * was completely changed.
+ * was completely changed.  SET_MODULE_OWNER was nop for whole
+ * 2.6.x series, and finally disappeared in 2.6.24.
  *
  * MOD_xxx_USE_COUNT wrappers are here, as they must be mutually
  * exclusive with SET_MODULE_OWNER call.
@@ -41,11 +46,24 @@
 #   define COMPAT_NETDEV_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
 #   define COMPAT_NETDEV_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
 #else
-#   define COMPAT_SET_MODULE_OWNER(dev) SET_MODULE_OWNER(dev)
+#   if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
+#      define COMPAT_SET_MODULE_OWNER(dev) SET_MODULE_OWNER(dev)
+#   else
+#      define COMPAT_SET_MODULE_OWNER(dev) do {} while (0)
+#   endif
 #   define COMPAT_NETDEV_MOD_INC_USE_COUNT do {} while (0)
 #   define COMPAT_NETDEV_MOD_DEC_USE_COUNT do {} while (0)
 #endif
 
+/*
+ * SET_NETDEV_DEV appeared sometime during 2.5.x, and later was
+ * crossported to various 2.4.x kernels (as dummy macro).
+ */
+#ifdef SET_NETDEV_DEV
+#   define COMPAT_SET_NETDEV_DEV(dev, pdev) SET_NETDEV_DEV(dev, pdev)
+#else
+#   define COMPAT_SET_NETDEV_DEV(dev, pdev) do {} while (0)
+#endif
 
 /*
  * Build alloc_etherdev API on the top of init_etherdev.  For 2.0.x kernels
@@ -100,11 +118,41 @@
 #endif
 
 
-/* free_netdev() is available since 2.4.23.  Use kfree() on older kernels. */
+/*
+ * alloc_netdev and free_netdev are there since 2.4.23.  Their use is mandatory
+ * since 2.6.24.
+ */
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 23)
-#define compat_free_netdev(dev)     kfree(dev)
+static inline struct net_device *
+compat_alloc_netdev(int priv_size,
+                    const char *mask,
+                    void (*setup)(struct net_device *))
+{
+   struct net_device *dev;
+   int netdev_size = sizeof *dev;
+   int alloc_size;
+
+#   if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
+   netdev_size += IFNAMSIZ;
+#   endif
+
+   alloc_size = netdev_size + priv_size;
+   dev = kmalloc(alloc_size, GFP_KERNEL);
+   if (dev) {
+      memset(dev, 0, alloc_size);
+      dev->priv = (char*)dev + netdev_size;
+      setup(dev);
+#   if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
+      dev->name = (char*)(dev + 1);
+#   endif
+      strcpy(dev->name, mask);   
+   }
+   return dev;
+}
+#   define compat_free_netdev(dev)     kfree(dev)
 #else
-#define compat_free_netdev(dev)     free_netdev(dev)
+#   define compat_alloc_netdev(size, mask, setup) alloc_netdev(size, mask, setup)
+#   define compat_free_netdev(dev)                free_netdev(dev)
 #endif
 
 
diff -uNr vmnet-only-org/compat_page.h vmnet-only/compat_page.h
--- vmnet-only-org/compat_page.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_page.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_PAGE_H__
 #   define __COMPAT_PAGE_H__
 
@@ -39,5 +43,19 @@
    return order;
 }
 
+/* 
+ * BUG() was added to <asm/page.h> in 2.2.18, and was moved to <asm/bug.h>
+ * in 2.5.58.
+ * 
+ * XXX: Technically, this belongs in some sort of "compat_asm_page.h" file, but
+ * since our compatibility wrappers don't distinguish between <asm/xxx.h> and
+ * <linux/xxx.h>, putting it here is reasonable.
+ */
+#ifndef BUG
+#define BUG() do {                                                            \
+   printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__);                      \
+  __asm__ __volatile__(".byte 0x0f,0x0b");                                    \
+} while (0)
+#endif
 
 #endif /* __COMPAT_PAGE_H__ */
diff -uNr vmnet-only-org/compat_pgtable.h vmnet-only/compat_pgtable.h
--- vmnet-only-org/compat_pgtable.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_pgtable.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_PGTABLE_H__
 #   define __COMPAT_PGTABLE_H__
 
diff -uNr vmnet-only-org/compat_sched.h vmnet-only/compat_sched.h
--- vmnet-only-org/compat_sched.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_sched.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_SCHED_H__
 #   define __COMPAT_SCHED_H__
 
@@ -24,6 +28,34 @@
 #   define cond_resched() (need_resched() ? schedule() : (void) 0)
 #endif
 
+/* Oh well.  We need yield...  Happy us! */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 20)
+#   ifdef __x86_64__
+#      define compat_yield() there_is_nothing_like_yield()
+#   else
+#      include <linux/unistd.h>
+#      include <linux/kernel.h>
+
+/*
+ * Used by _syscallX macros. Note that this is global variable, so
+ * do not rely on its contents too much. As exit() is only function
+ * we use, and we never check return value from exit(), we have
+ * no problem...
+ */
+extern int errno;
+
+/*
+ * compat_exit() provides an access to the exit() function. It must 
+ * be named compat_exit(), as exit() (with different signature) is 
+ * provided by x86-64, arm and other (but not by i386).
+ */
+#      define __NR_compat_yield __NR_sched_yield
+static inline _syscall0(int, compat_yield);
+#   endif
+#else
+#   define compat_yield() yield()
+#endif
+
 
 /*
  * Since 2.5.34 there are two methods to enumerate tasks:
@@ -189,19 +221,35 @@
 #include <linux/freezer.h>
 #endif
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13) || defined(VMW_TL10S64_WORKAROUND)
-#define compat_try_to_freeze() do { try_to_freeze(); } while (0)
+#define compat_try_to_freeze() try_to_freeze()
 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
-#define compat_try_to_freeze() do { try_to_freeze(PF_FREEZE); } while (0)
+#define compat_try_to_freeze() try_to_freeze(PF_FREEZE)
 #elif defined(CONFIG_SOFTWARE_SUSPEND) || defined(CONFIG_SOFTWARE_SUSPEND2)
 #include "compat_mm.h"
 #include <linux/errno.h>
 #include <linux/suspend.h>
-#define compat_try_to_freeze() do { \
-                                  if (current->flags & PF_FREEZE) \
-                                     refrigerator(PF_FREEZE); \
-                               } while (0)
+static inline int compat_try_to_freeze(void)  { 
+   if (current->flags & PF_FREEZE) {
+      refrigerator(PF_FREEZE); 
+      return 1;
+   } else {
+      return 0;
+   }
+}
+#else
+static inline int compat_try_to_freeze(void) { return 0; }
+#endif
+
+/*
+ * As of 2.6.23-rc1, kernel threads are no longer freezable by
+ * default. Instead, kernel threads that need to be frozen must opt-in
+ * by calling set_freezable() as soon as the thread is created.
+ */
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22)
+#define compat_set_freezable() do { set_freezable(); } while (0)
 #else
-#define compat_try_to_freeze() do {} while (0)
+#define compat_set_freezable() do {} while (0)
 #endif
 
 #endif /* __COMPAT_SCHED_H__ */
diff -uNr vmnet-only-org/compat_semaphore.h vmnet-only/compat_semaphore.h
--- vmnet-only-org/compat_semaphore.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_semaphore.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_SEMAPHORE_H__
 #   define __COMPAT_SEMAPHORE_H__
 
diff -uNr vmnet-only-org/compat_skbuff.h vmnet-only/compat_skbuff.h
--- vmnet-only-org/compat_skbuff.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_skbuff.h	2008-03-07 15:31:40.000000000 +0900
@@ -42,6 +42,18 @@
 #define compat_skb_set_transport_header(skb, off) ((skb)->h.raw = (skb)->data + (off))
 #endif
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18) || defined(VMW_SKB_LINEARIZE_2618)
+#   define compat_skb_linearize(skb) skb_linearize((skb))
+#else
+
+#   if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 0)
+#      define compat_skb_linearize(skb) __skb_linearize((skb), GFP_ATOMIC)
+#   else
+#      define compat_skb_linearize(skb) skb_linearize((skb), GFP_ATOMIC)
+#   endif
+
+#endif
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
 #define compat_skb_csum_offset(skb)        (skb)->csum_offset
 #else
diff -uNr vmnet-only-org/compat_sock.h vmnet-only/compat_sock.h
--- vmnet-only-org/compat_sock.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_sock.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,9 +1,20 @@
+/* **********************************************************
+ * Copyright (C) 2003 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_SOCK_H__
 #   define __COMPAT_SOCK_H__
 
 
 #include <net/sock.h>
-
+/* http://forum.openvz.org/index.php?t=msg&goto=23299& */
+static inline void sock_valbool_flag(struct sock *sk, int bit, int valbool)
+{
+if (valbool)
+sock_set_flag(sk, bit);
+else
+sock_reset_flag(sk, bit);
+}
 
 /*
  * Between 2.5.70 and 2.5.71 all sock members were renamed from XXX to sk_XXX.
diff -uNr vmnet-only-org/compat_spinlock.h vmnet-only/compat_spinlock.h
--- vmnet-only-org/compat_spinlock.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_spinlock.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2005 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_SPINLOCK_H__
 #   define __COMPAT_SPINLOCK_H__
 
diff -uNr vmnet-only-org/compat_uaccess.h vmnet-only/compat_uaccess.h
--- vmnet-only-org/compat_uaccess.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_uaccess.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_UACCESS_H__
 #   define __COMPAT_UACCESS_H__
 
diff -uNr vmnet-only-org/compat_version.h vmnet-only/compat_version.h
--- vmnet-only-org/compat_version.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_version.h	2008-03-07 15:31:40.000000000 +0900
@@ -103,5 +103,6 @@
 #   define KERNEL_2_5_5
 #endif
 
+enum vmEmulations { VME_UNKNOWN, VME_V2, VME_GSX1, VME_V3, VME_V32, VME_GSX2, VME_GSX25, VME_V4, VME_V321, VME_GSX251, VME_V45, VME_V452, VME_GSX32, VME_V5, VME_V55, VME_S1B1, VME_V6, VME_TOT };
 
 #endif /* __COMPAT_VERSION_H__ */
diff -uNr vmnet-only-org/compat_wait.h vmnet-only/compat_wait.h
--- vmnet-only-org/compat_wait.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/compat_wait.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __COMPAT_WAIT_H__
 #   define __COMPAT_WAIT_H__
 
diff -uNr vmnet-only-org/driver-config.h vmnet-only/driver-config.h
--- vmnet-only-org/driver-config.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/driver-config.h	2008-03-07 15:31:40.000000000 +0900
@@ -12,6 +12,16 @@
 #ifndef __VMX_CONFIG_H__
 #define __VMX_CONFIG_H__
 
+#ifdef __cplusplus
+typedef bool _Bool;
+#   define new new_member
+#   define private private_member
+#   define namespace namespace_member
+#   define false false_value
+#   define true true_value
+#   define bool bool_type
+#endif
+
 #define INCLUDE_ALLOW_VMCORE
 #define INCLUDE_ALLOW_VMMON
 #define INCLUDE_ALLOW_MODULE
@@ -35,6 +45,7 @@
    #define __SMP__ 1
 #endif
 
+#ifndef VMW_USING_KBUILD
 #if defined(CONFIG_MODVERSIONS) && defined(KERNEL_2_1)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,60)
 /* MODVERSIONS might be already defined when using kernel's Makefiles */
@@ -44,9 +55,15 @@
 #include <linux/modversions.h>
 #endif
 #endif
+#endif
 
 #ifndef __KERNEL__
 #define __KERNEL__
 #endif
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
+/* Prevent uintptr_t from being declared in vm_basic_types.h. */
+#define _STDINT_H _fake_kernel_stdint
+#endif
+
 #endif
diff -uNr vmnet-only-org/driver.c vmnet-only/driver.c
--- vmnet-only-org/driver.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/driver.c	2008-03-07 15:31:40.000000000 +0900
@@ -77,8 +77,11 @@
 static VNetInterface *vnetInterfaces = NULL;
 
 /* this will let all multicast packets go through. */
-uint8 AllMultiFilter[VNET_LADRF_LEN] = { 0xff, 0xff, 0xff, 0xff,
-					 0xff, 0xff, 0xff, 0xff };
+const uint8 allMultiFilter[VNET_LADRF_LEN] = { 0xff, 0xff, 0xff, 0xff,
+					       0xff, 0xff, 0xff, 0xff };
+
+/* broadcast MAC */
+const uint8 broadcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
 /*
  * All jack->peer accesses are guarded by this lock.
@@ -407,7 +410,7 @@
  */
 
 static INLINE void
-VNetRemovePortFromList(VNetPort *port) // IN: port to remove from list
+VNetRemovePortFromList(const VNetPort *port) // IN: port to remove from list
 {
    VNetPort **p;
    
@@ -865,6 +868,7 @@
 #ifdef CONFIG_NETFILTER
    VNet_RuleHeader ruleHeader;
 #endif
+   uint32 ifflags;
 
    if (!port) {
       LOG(1, (KERN_DEBUG "/dev/vmnet: bad file pointer on ioctl\n"));
@@ -872,11 +876,29 @@
    }
    
    // sprintf(vnetHub[hubNum]->devName, "vmnet%d", hubNum);
+   switch (iocmd) {
+   case OLD_SIOCPORT:
+      iocmd = SIOCPORT;
+      break;
+   case OLD_SIOCBRIDGE:
+      iocmd = SIOCBRIDGE;
+      break;
+   case OLD_SIOCNETIF:
+      iocmd = SIOCNETIF;
+      break;
+   case OLD_SIOCSLADRF:
+      iocmd = SIOCSLADRF;
+      break;
+   case OLD_SIOCSETMACADDR:
+      iocmd = SIOCSETMACADDR;
+      break;
+   case OLD_SIOCGETAPIVERSION:
+      iocmd = SIOCGETAPIVERSION;
+      break;
+   }
 
    switch (iocmd) {
-#ifdef VNET_API_DEPRECATED
    case SIOCSIFBR:
-#endif
    case SIOCSPEER:
    case SIOCBRIDGE:
       if (copy_from_user(name, (void *)ioarg, 8)) {
@@ -1031,31 +1053,31 @@
       }
       break;
 
-#ifdef VNET_API_DEPRECATED
-   /* We can't think of a good reason to use this ioctl. --gustav,hpreg */
    case SIOCGIFFLAGS:
       if (copy_to_user((void *)ioarg, &port->flags, sizeof port->flags)) {
          return -EFAULT;
       }
       break;
       
-#endif
    case SIOCSIFFLAGS:
-      if (copy_from_user(&port->flags, (void *)ioarg, sizeof port->flags)) {
+      if (ioarg <= 0xFFFF) {
+         ifflags = ioarg; /* VMware <= 4.0.0 compat code */
+      } else if (copy_from_user(&ifflags, (void *)ioarg, sizeof port->flags)) {
          return -EFAULT;
       }
-      port->flags = ((port->flags
+      port->flags = ((ifflags
                       & (IFF_UP|IFF_BROADCAST|IFF_DEBUG
                          |IFF_PROMISC|IFF_MULTICAST|IFF_ALLMULTI))
                      | IFF_RUNNING);
       if (port->fileOpIoctl) {
 
          /*
-          * Userif ports have some postprocessing when the IFF_UP flags is 
+          * Userif ports have some postprocessing when the IFF_UP flags is
           * changed.
           */
          port->fileOpIoctl(port, filp, iocmd, ioarg);
       }
+      /* XXX process queued packets? */
       break;
 
    case SIOCSETMACADDR:
@@ -1080,16 +1102,28 @@
       break;
    case SIOCGETAPIVERSION2:
       {
-	 uint32 verFromUser;
-	 if (copy_from_user(&verFromUser, (void *)ioarg, sizeof verFromUser)) {
+	 uint32 ver;
+
+	 if (copy_from_user(&ver, (void *)ioarg, sizeof ver)) {
+	    return -EFAULT;
+	 }
+	 if (ver <= VNET_API_VERSION_WS45) {
+	    ver = VNET_API_VERSION_WS45;
+	 } else {
+	    ver = VNET_API_VERSION;
+	 }
+	 if (copy_to_user((void*)ioarg, &ver, sizeof ver)) {
 	    return -EFAULT;
 	 }
-	 /* Should we require verFromUser == VNET_API_VERSION? */
       }
-      /* fall thru */
+      break;
    case SIOCGETAPIVERSION: 
       {
-	 uint32 verToUser = VNET_API_VERSION;
+	 uint32 verToUser = VNET_API_VERSION_WS45;
+	 
+	 if (VME_DEFAULT >= VME_V5) {
+	    verToUser = VNET_API_VERSION;
+	 }
 	 if (copy_to_user((void*)ioarg, &verToUser, sizeof verToUser)) {
 	    return -EFAULT;
 	 }
@@ -1277,12 +1311,15 @@
 #define CRC_POLYNOMIAL_BE 0x04c11db7UL  /* Ethernet CRC, big endian */
 
 static INLINE_SINGLE_CALLER Bool
-VNetMulticastFilter(uint8 *destAddr, // IN: multicast MAC
-		    uint8 *ladrf)    // IN: multicast filter
+VNetMulticastFilter(const uint8 *destAddr, // IN: multicast MAC
+		    const uint8 *ladrf)    // IN: multicast filter
 {
    uint16 hashcode;
-   int32 crc, poly = CRC_POLYNOMIAL_BE;
-   int j, bit, byte;
+   int32 crc;
+   int32 poly = CRC_POLYNOMIAL_BE;
+   int j;
+   int bit;
+   int byte;
    
    crc = 0xffffffff;                  /* init CRC for each address */
    for (byte = 0; byte < ETH_ALEN; byte++) { /* for each address byte */
@@ -1325,13 +1362,11 @@
  */
 
 Bool
-VNetPacketMatch(uint8   *destAddr, // IN: destination MAC
-                uint8   *ifAddr,   // IN: MAC of interface
-		uint8   *ladrf,    // IN: multicast filter
-                uint32   flags)    // IN: filter flags
+VNetPacketMatch(const uint8   *destAddr, // IN: destination MAC
+                const uint8   *ifAddr,   // IN: MAC of interface
+		const uint8   *ladrf,    // IN: multicast filter
+                uint32   flags)          // IN: filter flags
 {
-   static const uint8 broadcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-
    /* 
     * Return TRUE if promiscuous requested, or unicast destined
     * for interface, or broadcast (and broadcast requested), or
@@ -1516,7 +1551,7 @@
  */
 
 Bool
-VNetCycleDetectIf(char *name,       // IN:
+VNetCycleDetectIf(const char *name, // IN:
                   int   generation) // IN:
 {
    VNetInterface *p;
@@ -1595,8 +1630,8 @@
  */
 
 void
-VNetSend(VNetJack        *jack, // IN: jack
-         struct sk_buff  *skb)  // IN: packet
+VNetSend(const VNetJack *jack, // IN: jack
+         struct sk_buff *skb)  // IN: packet
 {
    read_lock(&vnetPeerLock);
    if (jack && jack->peer && jack->peer->rcv) {
@@ -1664,8 +1699,8 @@
  */
 
 int
-VNetPrintJack(VNetJack  *jack, // IN: jack
-              char      *buf)  // OUT: info about jack
+VNetPrintJack(const VNetJack *jack, // IN: jack
+              char           *buf)  // OUT: info about jack
 {
    int len = 0;
    
@@ -1698,8 +1733,8 @@
  */
 
 int
-VNetPrintPort(VNetPort  *port, // IN: port
-              char      *buf)  // OUT: info about port
+VNetPrintPort(const VNetPort *port, // IN: port
+              char           *buf)  // OUT: info about port
 {
    int len = 0;
 
diff -uNr vmnet-only-org/epoll.c vmnet-only/epoll.c
--- vmnet-only-org/epoll.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/epoll.c	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2004 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 /*
  * Detect whether we have 'struct poll_wqueues'
  * 2.6.x kernels always had this struct.  Stock 2.4.x kernels
diff -uNr vmnet-only-org/filter.c vmnet-only/filter.c
--- vmnet-only-org/filter.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/filter.c	2008-03-07 15:31:40.000000000 +0900
@@ -12,6 +12,9 @@
 #include <linux/ip.h>
 #include "compat_skbuff.h"
 #include <linux/netdevice.h>
+#define NF_IP_LOCAL_OUT NF_INET_LOCAL_OUT
+#define NF_IP_LOCAL_IN NF_INET_LOCAL_IN
+#define NF_IP_POST_ROUTING NF_INET_POST_ROUTING
 /*
  * All this makes sense only if NETFILTER support is configured in our kernel.
  */
@@ -39,11 +42,8 @@
 #define VNET_FILTER_ACTION_FWD_DEFAULT (1<<8 | 7)
 
 /* netfilter hooks for filtering. */
-static unsigned int VNetFilterHookFn(unsigned int hooknum,
-                                     struct sk_buff **pskb,
-                                     const struct net_device *in,
-                                     const struct net_device *out,
-                                     int (*okfn)(struct sk_buff *));
+static nf_hookfn VNetFilterHookFn;
+
 static struct nf_hook_ops vmnet_nf_ops[] = {
    {  .hook = VNetFilterHookFn,
       compat_nf_hook_owner
@@ -185,13 +185,19 @@
 
 static unsigned int
 VNetFilterHookFn(unsigned int hooknum,                 // IN:
+#ifdef VMW_NFHOOK_USES_SKB
+                 struct sk_buff *skb,                  // IN:
+#else
                  struct sk_buff **pskb,                // IN:
+#endif
                  const struct net_device *in,          // IN:
                  const struct net_device *out,         // IN:
                  int (*okfn)(struct sk_buff *))        // IN:
 {
-   struct iphdr *ip;
+#ifndef VMW_NFHOOK_USES_SKB
    struct sk_buff *skb = *pskb;
+#endif
+   struct iphdr *ip;
    uint32 remoteAddr;
    uint16 localPort;
    uint16 remotePort;
diff -uNr vmnet-only-org/geninclude.c vmnet-only/geninclude.c
--- vmnet-only-org/geninclude.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/geninclude.c	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2003 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #include <linux/autoconf.h>
 
 #ifdef CONFIG_X86_VOYAGER
diff -uNr vmnet-only-org/getversion.pl vmnet-only/getversion.pl
--- vmnet-only-org/getversion.pl	1970-01-01 09:00:00.000000000 +0900
+++ vmnet-only/getversion.pl	2008-03-07 15:31:40.000000000 +0900
@@ -0,0 +1,206 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+
+sub GetVMwareVersion {
+	my ($path) = @_;
+	my $res = undef; # Pointer to array of TYPE, PROTOCOL, BUILD, PRODUCT
+	
+	if (open VMWARE, "$path -v < /dev/null 2>&1 |") {
+		my $line;
+		while (defined($line = <VMWARE>)) {
+			chomp $line;
+
+			if ($line =~ /VMware (.*) protocol=(.*) build=(.*) product='(.*)'/) {
+				$res = [ $1, $2, $3, $4 ];
+			} elsif (not defined($res) and $line =~ /VMware (.*) (\d+(?:\.\d+)*|e\.x\.p) build-(\d+)/) {
+				$res = [ $1, '6', $3, "$2 build $3" ];
+			}
+		}
+		close VMWARE;
+	}
+	return $res;
+}
+
+sub GetDBAnswer {
+	my ($path, $answer) = @_;
+	my $res = undef;
+	
+	if (open(CFG, '<', $path)) {
+		my $line;
+		while (defined($line = <CFG>)) {
+			chomp $line;
+			if ($line =~ /^answer $answer (.*)$/) {
+				$res = $1;
+			}
+		}
+		close CFG;
+	}
+	return $res;
+}
+
+my $path;
+my $res;
+
+$path = GetDBAnswer('/etc/vmware/locations', 'BINDIR');
+if (defined($path)) {
+	$res = GetVMwareVersion($path . '/vmware');
+}
+if (not defined($res)) {
+	$path = GetDBAnswer('/etc/vmware/locations', 'LIBDIR');
+	if (defined($path)) {
+		$res = GetVMwareVersion($path . '/bin/vmware');
+		$res = GetVMwareVersion($path . '/bin/vmware-vmx') unless defined($res);
+	}
+}
+$res = GetVMwareVersion('vmware') unless defined($res);
+
+my $type;
+my $protocol;
+my $build;
+my $product;
+
+if (not defined($res)) {
+	print STDERR "VMware 2 or VMware Express detected, building for VMware 2, VMware Express and VMware Workstation 4.0.x.\n";
+	print 'VME_V4';
+	exit 0;
+}
+($type, $protocol, $build, $product) = @$res;
+if ($type =~ /GSX/i) {
+	if ($product =~ /^1\./) {
+		print STDERR "Building for VMware GSX Server 1.x.x.\n";
+		print 'VME_GSX1';
+		exit 0;
+	}
+	if ($product =~ /^2\.0/) {
+		print STDERR "Building for VMware GSX Server 2.0.x.\n";
+		print 'VME_GSX2';
+		exit 0;
+	}
+	if ($product =~ /^2\.5\.[1-9]/) {
+		print STDERR "Building for VMware GSX Server 2.5.1.\n";
+		print 'VME_GSX251';
+		exit 0;
+	}
+	if ($product =~ /^2\.5/) {
+		print STDERR "Building for VMware GSX Server 2.5.0.\n";
+		print 'VME_GSX25';
+		exit 0;
+	}
+	if ($product =~ /^3\.0/) {
+		print STDERR "Building for VMware GSX Server 3.0.0 or VMware Workstation 4.5.1.\n";
+		print 'VME_V45';
+		exit 0;
+	}
+	if ($product =~ /^3\.1/) {
+		print STDERR "Building for VMware GSX Server 3.1.0 or VMware Workstation 4.5.[23].\n";
+		print 'VME_V452';
+		exit 0;
+	}
+	if ($product =~ /^3\.2/) {
+		print STDERR "Building for VMware GSX Server 3.2.x.\n";
+		print 'VME_GSX32';
+		exit 0;
+	}
+	print STDERR "Unknown VMware GSX Server $product detected. Building for GSX Server 3.2.x.\n";
+	print 'VME_GSX32';
+	exit 0;
+} elsif ($type =~ /Workstation/i) {
+	if ($product =~ /^3\.[01]\./) {
+		print STDERR "Building for VMware Workstation 3.0.x.\n";
+		print 'VME_V3';
+		exit 0;
+	}
+	if ($product =~ /^3\.2\.0/) {
+		print STDERR "Building for VMware Workstation 3.2.0.\n";
+		print 'VME_V32';
+		exit 0;
+	}
+	if ($product =~ /^3\.2\./) {
+		print STDERR "Building for VMware Workstation 3.2.1.\n";
+		print 'VME_V321';
+		exit 0;
+	}
+	if ($product =~ /^4\.0\./) {
+		print STDERR "Building for VMware Workstation 4.0.x.\n";
+		print 'VME_V4';
+		exit 0;
+	}
+	if ($product =~ /^4\.5\.[01]/) {
+		print STDERR "Building for VMware Workstation 4.5.1 or VMware GSX Server 3.0.0.\n";
+		print 'VME_V45';
+		exit 0;
+	}
+	if ($product =~ /^4\.5\.[2-9]/) {
+		print STDERR "Building for VMware Workstation 4.5.[23] or VMware GSX Server 3.1.0.\n";
+		print 'VME_V452';
+		exit 0;
+	}
+	if ($product =~ /^5\.0\.0/) {
+		print STDERR "Building for VMware Workstation 5.0.0.\n";
+		print 'VME_V5';
+		exit 0;
+	}
+	if ($product =~ /^5\.5\.[01]/) {
+		print STDERR "Building for VMware Workstation 5.5.0 or 5.5.1.\n";
+		print 'VME_V55';
+		exit 0;
+	}
+	if ($product =~ /^5\.5\.[2-9]/) {
+		print STDERR "Building for VMware Workstation 5.5.2 or 5.5.3.\n";
+		print 'VME_S1B1';
+		exit 0;
+	}
+	if ($product =~ /^6\.0\.[01]/) {
+		print STDERR "Building for VMware Workstation 6.0.0.\n";
+		print 'VME_V6';
+		exit 0;
+	}
+	if ($product =~ /^e\.x\.p/) {
+		if ($build eq '.....') {
+			;
+		}
+	}
+	print STDERR "Unknown VMware Workstation $product detected. Building for Workstation 6.0.0.\n";
+	print 'VME_V6';
+	exit 0;
+} elsif ($type =~ /Player/i) {
+	if ($product =~ /^1\.0\.[01]/) {
+		print STDERR "Building for VMware Player 1.0.0 or 1.0.1 or VMware Workstation 5.5.0 or 5.5.1.\n";
+		print 'VME_V55';
+		exit 0;
+	}
+	if ($product =~ /^1\.0\.[2-9]/) {
+		print STDERR "Building for VMware Player 1.0.2 or 1.0.3 or VMware Workstation 5.5.2 or 5.5.3.\n";
+		print 'VME_S1B1';
+		exit 0;
+	}
+	if ($product =~ /^2\.0\.[01]/) {
+		print STDERR "Building for VMware Player 2.0.0 or VMware Workstation 6.0.0.\n";
+		print 'VME_V6';
+		exit 0;
+	}
+	print STDERR "Unknown VMware Player $product detected. Building for VMware Player 2.0.0\n";
+	print 'VME_V6';
+	exit 0;
+} elsif ($type =~ /Server/i) {
+	if ($product =~ /^e\.x\.p/) {
+		if ($build eq '20925' or $build eq '22088' or $build eq '22874') {
+			print STDERR "Building for VMware Server 1 beta 1 or beta 2.\n";
+			print 'VME_S1B1';
+			exit 0;
+		}
+	}
+	if ($product =~ /^1\.0\.[0-9]/) {
+		print STDERR "Building for VMware Server 1.0.0.\n";
+		print 'VME_S1B1';
+		exit 0;
+	}
+	print STDERR "Unknown VMware Server $product detected. Building for Server 1.0.0.\n";
+	print 'VME_S1B1';
+	exit 0;
+}
+print STDERR "Unknown product ($type) detected. Building for TOT.\n";
+print 'VME_TOT';
+exit 0;
diff -uNr vmnet-only-org/hub.c vmnet-only/hub.c
--- vmnet-only-org/hub.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/hub.c	2008-03-07 15:31:40.000000000 +0900
@@ -440,8 +440,8 @@
  */
 
 void
-VNetHubReceive(VNetJack       *this,
-               struct sk_buff *skb)
+VNetHubReceive(VNetJack       *this, // IN:
+               struct sk_buff *skb)  // IN:
 {
    VNetHub *hub = (VNetHub*)this->private;
    VNetJack *jack;
@@ -450,11 +450,11 @@
 
    hub->stats[this->index].tx++;
    
-   for (i=0; i<NUM_JACKS_PER_HUB; i++) {
+   for (i = 0; i < NUM_JACKS_PER_HUB; i++) {
       jack = &hub->jack[i];
-      if (jack->private         /* allocated */
-          && jack->peer         /* and connected */
-          && (jack != this)) {  /* and not a loop */
+      if (jack->private &&   /* allocated */
+          jack->peer &&      /* and connected */
+          (jack != this)) {  /* and not a loop */
          clone = skb_clone(skb, GFP_ATOMIC);
          if (clone) {
             VNetSend(jack, clone);
@@ -486,7 +486,7 @@
 VNetHubCycleDetect(VNetJack *this,
                    int       generation)
 {
-   VNetHub *hub = (VNetHub*)this->private;
+   VNetHub *hub = (VNetHub *)this->private;
    Bool foundCycle;
    int i;
    
@@ -496,7 +496,7 @@
 
    hub->myGeneration = generation;
       
-   for (i=0; i<NUM_JACKS_PER_HUB; i++) {
+   for (i = 0; i < NUM_JACKS_PER_HUB; i++) {
       if (hub->jack[i].private && (i != this->index)) {
          foundCycle = VNetCycleDetect(hub->jack[i].peer, generation);
          if (foundCycle) {
@@ -530,7 +530,7 @@
 void
 VNetHubPortsChanged(VNetJack *this)
 {
-   VNetHub *hub = (VNetHub*)this->private;
+   VNetHub *hub = (VNetHub *)this->private;
    int num, new;
    int i;
    
diff -uNr vmnet-only-org/net.h vmnet-only/net.h
--- vmnet-only-org/net.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/net.h	2008-03-07 15:31:40.000000000 +0900
@@ -25,8 +25,9 @@
 #define ETHERNET_MTU         1518
 #define ETH_MIN_FRAME_LEN      60
 
-
+#ifndef ETHER_ADDR_LEN
 #define ETHER_ADDR_LEN          6  /* length of MAC address */
+#endif
 #define ETH_HEADER_LEN	       14  /* length of Ethernet header */
 #define IP_ADDR_LEN	        4  /* length of IPv4 address */
 #define IP_HEADER_LEN	       20  /* minimum length of IPv4 header */
diff -uNr vmnet-only-org/netdev_has_net.c vmnet-only/netdev_has_net.c
--- vmnet-only-org/netdev_has_net.c	1970-01-01 09:00:00.000000000 +0900
+++ vmnet-only/netdev_has_net.c	2008-03-07 15:31:40.000000000 +0900
@@ -0,0 +1,25 @@
+/* **********************************************************
+ * Copyright (C) 2007 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
+/*
+ * Detect whether there is separate net namespace.  It got introduced after
+ * 2.6.23.  If this builds, there are two arguments to __dev_get_by_name...
+ * For lower boundary use 2.6.23 - hopefully nobody crossports patch to
+ * older kernels.
+ */
+
+#include <linux/autoconf.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
+#   error This compile test intentionally fails.
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
+#   include <linux/netdevice.h>
+
+struct net_device * 
+vmware_get_by_name(void)
+{
+   return __dev_get_by_name(0, "dummy");
+}
+#endif
diff -uNr vmnet-only-org/netif.c vmnet-only/netif.c
--- vmnet-only-org/netif.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/netif.c	2008-03-07 15:31:40.000000000 +0900
@@ -36,7 +36,7 @@
 
 typedef struct VNetNetIF {
    VNetPort                port;
-   struct net_device       dev;
+   struct net_device      *dev;
    char                    devName[VNET_NAME_LEN];
    struct net_device_stats stats;
 } VNetNetIF;
@@ -167,6 +167,46 @@
 /*
  *----------------------------------------------------------------------
  *
+ * VNetNetIfSetup --
+ *
+ *      Sets initial netdevice state.
+ * 
+ * Results: 
+ *      None.
+ *
+ * Side effects:
+ *      None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void
+VNetNetIfSetup(struct net_device *dev)  // IN:
+{
+   ether_setup(dev); // turns on IFF_BROADCAST, IFF_MULTICAST
+   dev->init = VNetNetifProbe;
+   dev->open = VNetNetifOpen;
+   dev->hard_start_xmit = VNetNetifStartXmit;
+   dev->stop = VNetNetifClose;
+   dev->get_stats = VNetNetifGetStats;
+   dev->set_mac_address = VNetNetifSetMAC;
+   dev->set_multicast_list = VNetNetifSetMulticast;
+#ifdef KERNEL_2_3_43
+   /*
+    * We cannot stuck... If someone will report problems under
+    * low memory conditions or some such, we should enable it.
+    */
+#if 0
+   dev->tx_timeout = VNetNetifTxTimeout;
+   dev->watchdog_timeo = TX_TIMEOUT;
+#endif
+#endif   
+}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
  * VNetNetIf_Create --
  *
  *      Create a net level port to the wonderful world of virtual
@@ -188,7 +228,7 @@
                  int hubNum)     // IN: 
 {
    VNetNetIF *netIf;
-   struct net_device *dev = NULL;
+   struct net_device *dev;
    int retval = 0;
    static unsigned id = 0;
    
@@ -259,52 +299,33 @@
    netIf->port.fileOpIoctl = NULL;
    netIf->port.fileOpPoll = NULL;
    
-   dev = &netIf->dev;
-   
-   memset(dev, 0, sizeof *dev);
-   dev->priv = netIf;
-   dev->init = VNetNetifProbe;
+   memset(&netIf->stats, 0, sizeof netIf->stats);
    
    memcpy(netIf->devName, devName, sizeof netIf->devName);
    NULL_TERMINATE_STRING(netIf->devName);
 
-#ifdef KERNEL_2_3_99
-   strncpy(dev->name, netIf->devName, sizeof dev->name);
-   NULL_TERMINATE_STRING(dev->name);
-#else
-   dev->name = netIf->devName;
-#endif
-   memset(&netIf->stats, 0, sizeof netIf->stats);
+   dev = compat_alloc_netdev(0, netIf->devName, VNetNetIfSetup);
+   if (!dev) {
+      retval = -ENOMEM;
+      goto out;
+   }
+
+   dev->priv = netIf;
+   netIf->dev = dev;
    
-   ether_setup(dev); // turns on IFF_BROADCAST, IFF_MULTICAST
    memcpy(dev->dev_addr, netIf->port.paddr, sizeof netIf->port.paddr);
    
-   dev->open = &VNetNetifOpen;
-   dev->hard_start_xmit = &VNetNetifStartXmit;
-   dev->stop = &VNetNetifClose;
-   dev->get_stats = &VNetNetifGetStats;
-   dev->set_mac_address = &VNetNetifSetMAC;
-   dev->set_multicast_list = &VNetNetifSetMulticast;
-#ifdef KERNEL_2_3_43
-   /*
-    * We cannot stuck... If someone will report problems under
-    * low memory conditions or some such, we should enable it.
-    */
-#if 0
-   dev->tx_timeout = &VNetNetifTxTimeout;
-   dev->watchdog_timeo = TX_TIMEOUT;
-#endif
-#endif   
-   
    if (register_netdev(dev) != 0) {
       LOG(0, (KERN_NOTICE "%s: could not register network device\n", devName));
       retval = -ENODEV;
-      goto out;
+      goto outFreeDev;
    }
 
    *ret = (VNetPort*)netIf;
    return 0;
 
+outFreeDev:
+   compat_free_netdev(dev);
 out:
    if (netIf) {
       if (netIf->port.jack.procEntry) {
@@ -336,7 +357,9 @@
 VNetNetIfFree(VNetJack *this) // IN: jack
 {
    VNetNetIF *netIf = (VNetNetIF*)this;
-   unregister_netdev(&netIf->dev);
+
+   unregister_netdev(netIf->dev);
+   compat_free_netdev(netIf->dev);
    if (this->procEntry) {
       VNetProc_RemoveEntry(this->procEntry, NULL);
    }
@@ -367,20 +390,20 @@
    VNetNetIF *netIf = (VNetNetIF*)this->private;
    uint8 *dest = SKB_2_DESTMAC(skb);
    
-   if (!NETDEV_UP_AND_RUNNING(&netIf->dev)) {
+   if (!NETDEV_UP_AND_RUNNING(netIf->dev)) {
       goto drop_packet;
    }
 
    if (!VNetPacketMatch(dest,
-                        netIf->dev.dev_addr,
-                        (uint8 *)AllMultiFilter, 
-                        netIf->dev.flags)) {
+                        netIf->dev->dev_addr,
+                        allMultiFilter, 
+                        netIf->dev->flags)) {
       goto drop_packet;
    }
    
    /* send to the host interface */
-   skb->dev = &netIf->dev;
-   skb->protocol = eth_type_trans(skb, &netIf->dev);
+   skb->dev = netIf->dev;
+   skb->protocol = eth_type_trans(skb, netIf->dev);
    netif_rx_ni(skb);
    netIf->stats.rx_packets++;
 
diff -uNr vmnet-only-org/nfhook_uses_skb.c vmnet-only/nfhook_uses_skb.c
--- vmnet-only-org/nfhook_uses_skb.c	1970-01-01 09:00:00.000000000 +0900
+++ vmnet-only/nfhook_uses_skb.c	2008-03-07 15:31:40.000000000 +0900
@@ -0,0 +1,31 @@
+/* **********************************************************
+ * Copyright (C) 2007 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
+/*
+ * Detect whether nf_hookfn takes struct sk_buff* skb, or struct sk_buff** pskb.
+ * Kernels before 2.6.23 take pskb, kernels since 2.6.24 take skb, and we
+ * are not sure about 2.6.23 itself, as change occured between 2.6.23 and
+ * 2.6.24-rc1.
+ */
+
+#include <linux/autoconf.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
+#   error This compile test intentionally fails.
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
+#   include <linux/netfilter.h>
+
+nf_hookfn test_function;
+
+unsigned int
+test_function(unsigned int hooknum,
+              struct sk_buff *skb,
+	      const struct net_device *in,
+	      const struct net_device *out,
+	      int (*defn)(struct sk_buff*))
+{
+   return 1234;
+}
+#endif
diff -uNr vmnet-only-org/pgtbl.h vmnet-only/pgtbl.h
--- vmnet-only-org/pgtbl.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/pgtbl.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __PGTBL_H__
 #   define __PGTBL_H__
 
diff -uNr vmnet-only-org/setnice.c vmnet-only/setnice.c
--- vmnet-only-org/setnice.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/setnice.c	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2005 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 /*
  * set_user_nice appeared in 2.4.21.  But some distros
  * backported it to older kernels.
diff -uNr vmnet-only-org/sk_alloc.c vmnet-only/sk_alloc.c
--- vmnet-only-org/sk_alloc.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/sk_alloc.c	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2005 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 /*
  * Detect whether sk_alloc takes a struct proto * as third parameter.
  * This API change was introduced between 2.6.12-rc1 and 2.6.12-rc2.
diff -uNr vmnet-only-org/skblin.c vmnet-only/skblin.c
--- vmnet-only-org/skblin.c	1970-01-01 09:00:00.000000000 +0900
+++ vmnet-only/skblin.c	2008-03-07 15:31:40.000000000 +0900
@@ -0,0 +1,27 @@
+/* **********************************************************
+ * Copyright (C) 2006 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
+/*
+ * Detect whether skb_linearize takes one or two arguments.
+ */
+
+#include <linux/autoconf.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 17)
+/*
+ * Since 2.6.18 all kernels have single-argument skb_linearize.  For
+ * older kernels use autodetection.  Not using autodetection on newer
+ * kernels saves us from compile failure on some post 2.6.18 kernels
+ * which do not have selfcontained skbuff.h.
+ */
+
+#include <linux/skbuff.h>
+
+int test_skb_linearize(struct sk_buff *skb)
+{
+   return skb_linearize(skb);
+}
+
+#endif
diff -uNr vmnet-only-org/smac.h vmnet-only/smac.h
--- vmnet-only-org/smac.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/smac.h	2008-03-07 15:31:40.000000000 +0900
@@ -15,9 +15,9 @@
 #ifndef _SMAC_H_
 #define _SMAC_H_
 
-#ifdef WIN32
+#ifdef _WIN32
 #include "vnetInt.h"
-#else /* WIN32 */
+#else /* _WIN32 */
 
 #include "vm_basic_types.h"
 
@@ -30,7 +30,7 @@
 #define ETH_HLEN 14
 #endif /* ETH_HLEN */
 
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
 #if defined __linux__ && !defined __x86_64__
 #define SMACINT __attribute__((cdecl, regparm(3)))
@@ -58,10 +58,10 @@
  * between packets on different OSes.
  */
 
-#ifdef WIN32
+#ifdef _WIN32
 /* defines Windows versions of SMACPacket and SMACPackets */
 #include "smac_win.h"
-#else /* WIN32 */
+#else /* _WIN32 */
 /* non-WIN32 versions of these structs */
 typedef struct SMACPacket {
 #ifdef __linux__
@@ -76,7 +76,7 @@
    SMACPacket orig;  // IN: packet
    SMACPacket clone; // OUT: packet
 } SMACPackets;
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
 PacketStatus SMACINT
 SMAC_CheckPacketFromHost(struct SMACState *state,  // IN: pointer to smac state
diff -uNr vmnet-only-org/smac_compat.c vmnet-only/smac_compat.c
--- vmnet-only-org/smac_compat.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/smac_compat.c	2008-03-07 15:31:40.000000000 +0900
@@ -44,11 +44,11 @@
 #include "vmnetInt.h"
 #include "smac_compat.h"
 
-#ifdef VMX86_DEBUG
+#ifdef VMX86_DEVEL
 #define DBG 1
 #else
 #undef DBG
-#endif /* VMX86_DEBUG */
+#endif /* VMX86_DEVEL */
 
 
 
@@ -89,9 +89,9 @@
  */
 
 void SMACINT
-SMACL_Memcpy(void *d,  // IN: destination pointer
-	     void *s,  // IN: source pointer
-	     size_t l) // IN: length to copy
+SMACL_Memcpy(void *d,        // IN: destination pointer
+	     const void *s,  // IN: source pointer
+	     size_t l)       // IN: length to copy
 {
    memcpy(d, s, l);
 }
@@ -113,9 +113,9 @@
  */
 
 int SMACINT
-SMACL_Memcmp(void *p1, // IN: pointer to data
-	     void *p2, // IN: pointer to data
-	     size_t l) // IN: length to compare
+SMACL_Memcmp(const void *p1, // IN: pointer to data
+	     const void *p2, // IN: pointer to data
+	     size_t l)       // IN: length to compare
 {
    return memcmp(p1, p2, l);
 }
@@ -376,14 +376,13 @@
 
 /*
  *----------------------------------------------------------------------
- *  SMACL_IsSkbNonlinear --
+ *  SMACL_LinearizeSkb --
  *
- *      Wrapper function to check if the skb is nonlinear.
+ *      Wrapper function to linearize an skb, if necessary.
  *
  * Results:
- *      non zero if skb is nonlinear (contains unmapped page buffers and
- *		additional chained struct sk_buffs).
- *      0 if skb is linear
+ *      non zero if skb is can't be converted to linear.
+ *      0 if skb is already linear or successfully converted.
  *
  * Side effects:
  *      None
@@ -395,10 +394,11 @@
 SMACL_IsSkbNonlinear(struct sk_buff* skb) // IN: packet to process
 {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 4)
-   return skb->data_len;
-#else
-   return 0;
+   if (skb_is_nonlinear(skb)) {
+      return compat_skb_linearize(skb);
+   }
 #endif
+   return 0;
 }
 
 
diff -uNr vmnet-only-org/smac_compat.h vmnet-only/smac_compat.h
--- vmnet-only-org/smac_compat.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/smac_compat.h	2008-03-07 15:31:40.000000000 +0900
@@ -21,8 +21,8 @@
 #define SMACINT __attribute__((cdecl, regparm(3)))
 #endif
 
-void   SMACINT SMACL_Memcpy(void *d, void *s, size_t l);
-int    SMACINT SMACL_Memcmp(void *p1, void *p2, size_t l);
+void   SMACINT SMACL_Memcpy(void *d, const void *s, size_t l);
+int    SMACINT SMACL_Memcmp(const void *p1, const void *p2, size_t l);
 void   SMACINT SMACL_Memset(void *p1, int val, size_t l);
 void*  SMACINT SMACL_Alloc(size_t s);
 void   SMACINT SMACL_Free(void *p);
@@ -37,10 +37,10 @@
 struct sk_buff* SMACINT SMACL_DupPacket(struct sk_buff *skb);
 void*  SMACINT SMACL_PacketData(struct sk_buff *skb);
 unsigned int SMACINT SMACL_PacketLength(struct sk_buff *skb);
-int    SMACINT SMACL_IsSkbNonlinear(struct sk_buff* skb);
-int    SMACINT SMACL_IsSkbHostBound(struct sk_buff* skb);
+int    SMACINT SMACL_LinearizeSkb(struct sk_buff *skb);
+int    SMACINT SMACL_IsSkbHostBound(struct sk_buff *skb);
 #ifdef DBG
-void   SMACINT SMACL_Print(const char * m, ...);
+void   SMACINT SMACL_Print(const char *m, ...);
 void   SMACINT SMACL_PrintSkb(struct sk_buff *skb, char *type);
 int    SMACINT SMACL_Snprintf(char *str, size_t size, const char *format, ...);
 #endif /* DBG */
diff -uNr vmnet-only-org/socket.c vmnet-only/socket.c
--- vmnet-only-org/socket.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/socket.c	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2004 VMware, Inc.  All Rights Reserved. -- VMware Confidential
+ * **********************************************************/
+
 /*
  * Detect whether there is 'sk_wmem_alloc' member in 'sock'
  * It got renamed from wmem_alloc sometime during 2.5.x.
diff -uNr vmnet-only-org/userif.c vmnet-only/userif.c
--- vmnet-only-org/userif.c	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/userif.c	2008-03-07 15:31:40.000000000 +0900
@@ -60,7 +60,9 @@
    Atomic_uint32*         actPtr;
    uint32                 pollMask;
    uint32                 actMask;
-   uint32*                recvClusterCount;
+   uint32		  pollMaskAct;
+   uint32                 clusterCount;
+   uint32*                recvClusterPtr;
    wait_queue_head_t      waitQueue;
    struct page*           actPage;
    struct page*           pollPage;
@@ -69,7 +71,7 @@
 } VNetUserIF;
 
 static void VNetUserIfUnsetupNotify(VNetUserIF *userIf);
-static int  VNetUserIfSetupNotify(VNetUserIF *userIf, VNet_Notify *vn);
+static int  VNetUserIfSetupNotify(VNetUserIF *userIf, VNet_Notify3 *vn);
 
 /*
  *-----------------------------------------------------------------------------
@@ -234,11 +236,11 @@
 
 static INLINE int
 VNetUserIfSetupNotify(VNetUserIF *userIf, // IN
-                      VNet_Notify *vn)           // IN
+                      VNet_Notify3 *vn)   // IN
 {
    int retval;
 
-   if (userIf->pollPtr || userIf->actPtr || userIf->recvClusterCount) {
+   if (userIf->pollPage || userIf->actPage || userIf->recvClusterPage) {
       LOG(0, (KERN_DEBUG "vmnet: Notification mechanism already active\n"));
       return -EBUSY;
    }
@@ -254,14 +256,19 @@
       return retval;
    }
 
-   if ((retval = VNetUserIfMapUint32Ptr((VA)vn->recvClusterPtr, 
-					&userIf->recvClusterPage,
-					&userIf->recvClusterCount)) < 0) {
-      VNetUserIfUnsetupNotify(userIf);
-      return retval;
+   if (vn->version >= 2) {
+      if ((retval = VNetUserIfMapUint32Ptr((VA)vn->recvClusterPtr, 
+					   &userIf->recvClusterPage,
+					   &userIf->recvClusterPtr)) < 0) {
+         VNetUserIfUnsetupNotify(userIf);
+         return retval;
+      }
+   } else {
+      userIf->recvClusterPage = NULL;
+      userIf->recvClusterPtr = &userIf->clusterCount;
    }
 
-   userIf->pollMask = vn->pollMask;
+   userIf->pollMask = userIf->pollMaskAct = vn->pollMask;
    userIf->actMask = vn->actMask;
    return 0;
 }
@@ -289,28 +296,23 @@
    if (userIf->pollPage) {
       kunmap(userIf->pollPage);
       put_page(userIf->pollPage);
-   } else {
-      LOG(0, (KERN_DEBUG "vmnet: pollPtr was already deactivated\n"));
    }
    if (userIf->actPage) {
       kunmap(userIf->actPage);
       put_page(userIf->actPage);
-   } else {
-      LOG(0, (KERN_DEBUG "vmnet: actPtr was already deactivated\n"));
    }
    if (userIf->recvClusterPage) {
       kunmap(userIf->recvClusterPage);
       put_page(userIf->recvClusterPage);
-   } else {
-      LOG(0, (KERN_DEBUG "vmnet: recvClusterPtr was already deactivated\n"));
    }
    userIf->pollPtr = NULL;
    userIf->pollPage = NULL;
    userIf->actPtr = NULL;
    userIf->actPage = NULL;
-   userIf->recvClusterCount = NULL;
+   userIf->recvClusterPtr = &userIf->clusterCount;
    userIf->recvClusterPage = NULL;
    userIf->pollMask = 0;
+   userIf->pollMaskAct = 0;
    userIf->actMask = 0;
 }
 
@@ -347,6 +349,7 @@
    
    if (userIf->pollPtr) {
       VNetUserIfUnsetupNotify(userIf);
+      userIf->clusterCount = 0;
    }
 
    if (this->procEntry) {
@@ -408,7 +411,7 @@
    skb_queue_tail(&userIf->packetQueue, skb);
    if (userIf->pollPtr) {
       *userIf->pollPtr |= userIf->pollMask;
-      if (skb_queue_len(&userIf->packetQueue) >= (*userIf->recvClusterCount)) {
+      if (skb_queue_len(&userIf->packetQueue) >= (*userIf->recvClusterPtr)) {
          Atomic_Or(userIf->actPtr, userIf->actMask);
       }
    }
@@ -838,31 +841,106 @@
    VNetUserIF *userIf = (VNetUserIF*)port->jack.private;
 
    switch (iocmd) {
+   case OLD_SIOCSETNOTIFY:
+      iocmd = SIOCSETNOTIFY;
+      break;
+   case OLD_SIOCSETNOTIFY2:
+      iocmd = SIOCSETNOTIFY2;
+      break;
+   case OLD_SIOCUNSETNOTIFY:
+      iocmd = SIOCUNSETNOTIFY;
+      break;
+   case OLD_SIOCSETCLUSTERSIZE:
+      iocmd = SIOCSETCLUSTERSIZE;
+      break;
+   }
+
+   switch (iocmd) {
    case SIOCSETNOTIFY:
-      return -EINVAL;
+   {
+      int retval;
+      struct {
+         uint32    ptr;
+	 uint32    mask;
+      } vn0;
+      VNet_Notify3 vn3;
+      if (copy_from_user(&vn0, (void *)ioarg, sizeof vn0)) {
+         return -EFAULT;
+      }
+      vn3.version = 1;
+      vn3.pad1 = 0;
+      vn3.actPtr = vn0.ptr;
+      vn3.pollPtr = vn0.ptr;
+      vn3.recvClusterPtr = 0;
+      vn3.actMask = vn0.mask;
+      vn3.pollMask = vn0.mask;
+
+      retval = VNetUserIfSetupNotify(userIf, &vn3);
+      if (retval < 0) {
+         return retval;
+      }
+      userIf->pollMaskAct = 0;
+
+      userIf->clusterCount = 1;
+      break;
+   }
+
    case SIOCSETNOTIFY2:
-#ifdef VMX86_SERVER
-      /* 
-       * This ioctl always return failure on ESX since we cannot map pages into 
-       * the console os that are from the VMKernel address space which  was the
-       * only case we used this.
-       */
-      return -EINVAL;
-#else // VMX86_SERVER
    /*
     * ORs pollMask into the integer pointed to by ptr if pending packet. Is
     * cleared when all packets are drained.
     */
    {
       int retval;
-      VNet_Notify vn;
+      VNet_NotifyH vnh;
+      VNet_Notify3 vn;
 
-      if (copy_from_user(&vn, (void *)ioarg, sizeof vn)) {
+      if (copy_from_user(&vnh, (void *)ioarg, sizeof vnh)) {
          return -EFAULT;
       }
 
-      if (vn.version != 3) {
-         return -EINVAL;
+      switch (vnh.version) {
+	 case 1:
+	    {
+	       VNet_Notify1 vn1;
+
+	       if (copy_from_user(&vn1, (void *)ioarg, sizeof vn1)) {
+		  return -EFAULT;
+	       }
+	       vn.version = 1;
+	       vn.pad1 = 0;
+	       vn.actPtr = vn1.actPtr;
+	       vn.pollPtr = vn1.pollPtr;
+	       vn.recvClusterPtr = 0;
+	       vn.actMask = vn1.actMask;
+	       vn.pollMask = vn1.pollMask;
+	       break;
+	    }
+	 case 2:
+	    {
+	       VNet_Notify2 vn2;
+
+	       if (copy_from_user(&vn2, (void *)ioarg, sizeof vn2)) {
+	          return -EFAULT;
+	       }
+	       vn.version = 2;
+	       vn.pad1 = 0;
+	       vn.actPtr = vn2.actPtr;
+	       vn.pollPtr = vn2.pollPtr;
+	       vn.recvClusterPtr = vn2.recvClusterPtr;
+	       vn.actMask = vn2.actMask;
+	       vn.pollMask = vn2.pollMask;
+	       break;
+	    }
+	 case 3:
+	    {
+	       if (copy_from_user(&vn, (void *)ioarg, sizeof vn)) {
+	          return -EFAULT;
+	       }
+	       break;
+	    }
+	 default:
+	    return -EINVAL;
       }
 
       retval = VNetUserIfSetupNotify(userIf, &vn);
@@ -870,34 +948,40 @@
          return retval;
       }
 
+      userIf->clusterCount = 1;
       break;
    }
-#endif // VMX86_SERVER
    case SIOCUNSETNOTIFY:
       if (!userIf->pollPtr) {
 	 /* This should always happen on ESX. */
          return -EINVAL;
       }
       VNetUserIfUnsetupNotify(userIf);
+      userIf->clusterCount = 0;
       break;
 
    case SIOCSETCLUSTERSIZE:
-      return -EINVAL;
+      if (!userIf->pollPtr) {
+	 /* This should always happen on ESX. */
+         return -EINVAL;
+      }
+      userIf->clusterCount = ioarg;
+
       break;
 
    case SIOCSIFFLAGS:
-      /* 
-       * Drain queue when interface is no longer active. We drain the queue to 
+      /*
+       * Drain queue when interface is no longer active. We drain the queue to
        * avoid having old packets delivered to the guest when reneabled.
        */
-      
+
       if (!UP_AND_RUNNING(userIf->port.flags)) {
          struct sk_buff *skb;
-         
+
          while ((skb = skb_dequeue(&userIf->packetQueue)) != NULL) {
             dev_kfree_skb(skb);
          }
-         
+
          if (userIf->pollPtr) {
             /* Clear the pending bit as no packets are pending at this point. */
             *userIf->pollPtr &= ~userIf->pollMask;
@@ -997,11 +1081,12 @@
    userIf->port.jack.isBridged = NULL;
    userIf->pollPtr = NULL;
    userIf->actPtr = NULL;
-   userIf->recvClusterCount = NULL;
    userIf->pollPage = NULL;
    userIf->actPage = NULL;
    userIf->recvClusterPage = NULL;
-   userIf->pollMask = userIf->actMask = 0;
+   userIf->recvClusterPtr = &userIf->clusterCount;
+   userIf->clusterCount = 0;
+   userIf->pollMask = userIf->pollMaskAct = userIf->actMask = 0;
 
    /*
     * Make proc entry for this jack.
diff -uNr vmnet-only-org/vm_atomic.h vmnet-only/vm_atomic.h
--- vmnet-only-org/vm_atomic.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vm_atomic.h	2008-03-07 15:31:40.000000000 +0900
@@ -16,6 +16,7 @@
 #define INCLUDE_ALLOW_MODULE
 #define INCLUDE_ALLOW_VMMON
 #define INCLUDE_ALLOW_VMNIXMOD
+#define INCLUDE_ALLOW_VMKDRIVERS
 #define INCLUDE_ALLOW_VMK_MODULE
 #define INCLUDE_ALLOW_VMKERNEL
 #define INCLUDE_ALLOW_DISTRIBUTE
@@ -137,7 +138,8 @@
 {
 // The freebsd assembler doesn't know the lfence instruction
 #if defined(__GNUC__) &&                                                \
-    !defined(VMX86_TFBSD) &&                                            \
+     __GNUC__ >= 3 &&                                                   \
+    !defined(BSD_VERSION) &&                                            \
     (!defined(MODULE) || defined(__VMKERNEL_MODULE__)) &&               \
     !defined(__APPLE__) /* PR136775 */
    if (UNLIKELY(AtomicUseFence)) {
@@ -1377,6 +1379,12 @@
  *
  *      Compare exchange: Read variable, if equal to oldVal, write newVal
  *
+ *      XXX: Ensure that if this function is to be inlined by gcc, it is 
+ *      compiled with -fno-strict-aliasing. Otherwise it will break. 
+ *      Unfortunately we know that gcc 2.95.3 (used to build the FreeBSD 3.2
+ *      Tools) does not honor -fno-strict-aliasing. As a workaround, we avoid 
+ *      inlining the function entirely for versions of gcc under 3.0.
+ *
  * Results:
  *      TRUE if equal, FALSE if not equal
  *
@@ -1386,7 +1394,11 @@
  *-----------------------------------------------------------------------------
  */
 
+#if defined(__GNUC__) && __GNUC__ < 3
+static Bool
+#else
 static INLINE Bool
+#endif
 Atomic_CMPXCHG64(Atomic_uint64 *var,   // IN/OUT
                  uint64 const *oldVal, // IN
                  uint64 const *newVal) // IN
@@ -1410,6 +1422,20 @@
 #else /* 32-bit version */
    int dummy1, dummy2;
 #   if defined __PIC__ && !vm_x86_64 // %ebx is reserved by the compiler.
+#      if defined __GNUC__ && __GNUC__ < 3 // Part of #188541 - for RHL 6.2 etc.
+   __asm__ __volatile__(
+      "xchg %%ebx, %6\n\t"
+      "mov (%%ebx), %%ecx\n\t"
+      "mov (%%ebx), %%ebx\n\t"
+      "lock; cmpxchg8b (%3)\n\t"
+      "xchg %%ebx, %6\n\t"
+      "sete %0"
+      : "=a" (equal), "=d" (dummy2), "=D" (dummy1)
+      : "S" (var), "0" (((S_uint64 const *)oldVal)->lowValue),
+        "1" (((S_uint64 const *)oldVal)->highValue), "D" (newVal)
+      : "ecx", "cc", "memory"
+      );
+#      else
    __asm__ __volatile__(
       "xchgl %%ebx, %6"      "\n\t"
       // %3 is a register to make sure it cannot be %ebx-relative.
@@ -1428,6 +1454,7 @@
         "c" (((S_uint64 const *)newVal)->highValue)
       : "cc", "memory"
    );
+#      endif
 #   else
    __asm__ __volatile__(
       "lock; cmpxchg8b %0" "\n\t"
diff -uNr vmnet-only-org/vm_basic_asm.h vmnet-only/vm_basic_asm.h
--- vmnet-only-org/vm_basic_asm.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vm_basic_asm.h	2008-03-07 15:31:40.000000000 +0900
@@ -761,14 +761,15 @@
 #ifdef __GNUC__
 {
 #ifdef VM_X86_64
-   uint32 tscLow, tscHigh;
+   uint64 tscLow;
+   uint64 tscHigh;
 
    __asm__ __volatile__(
       "rdtsc"
       : "=a" (tscLow), "=d" (tscHigh)
    );
 
-   return (uint64) tscHigh << 32 | tscLow;
+   return tscHigh << 32 | tscLow;
 #else
    uint64 tim;
 
diff -uNr vmnet-only-org/vm_basic_asm_x86_64.h vmnet-only/vm_basic_asm_x86_64.h
--- vmnet-only-org/vm_basic_asm_x86_64.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vm_basic_asm_x86_64.h	2008-03-07 15:31:40.000000000 +0900
@@ -20,6 +20,7 @@
 #define INCLUDE_ALLOW_VMKERNEL
 #define INCLUDE_ALLOW_DISTRIBUTE
 #define INCLUDE_ALLOW_VMCORE
+#define INCLUDE_ALLOW_VMNIXMOD
 #include "includeCheck.h"
 
 #ifndef VM_X86_64
diff -uNr vmnet-only-org/vm_basic_types.h vmnet-only/vm_basic_types.h
--- vmnet-only-org/vm_basic_types.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vm_basic_types.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,5 +1,5 @@
 /* **********************************************************
- * Copyright (c) 1998-2007 VMware, Inc.  All rights reserved.
+ * Copyright (c) 1998-2007 VMware, Inc.  All rights reserved. -- VMware Confidential
  * **********************************************************/
 
 /*
@@ -19,6 +19,7 @@
 #define INCLUDE_ALLOW_VMMON
 #define INCLUDE_ALLOW_VMNIXMOD
 #define INCLUDE_ALLOW_VMKERNEL
+#define INCLUDE_ALLOW_VMKDRIVERS
 #define INCLUDE_ALLOW_VMK_MODULE
 #define INCLUDE_ALLOW_DISTRIBUTE
 #define INCLUDE_ALLOW_VMCORE
@@ -48,10 +49,6 @@
 #define VM_I386
 #endif
 
-#ifdef __ia64__
-#define VM_IA64
-#endif
-
 #ifdef _WIN64
 #define __x86_64__
 #endif
@@ -71,10 +68,6 @@
 #define VM_I386
 #endif
 
-#if defined VM_I386 && defined VM_IA64
-#error "Only one CPU platform is allowed."
-#endif
-
 #ifdef _MSC_VER
 typedef unsigned __int64 uint64;
 typedef signed __int64 int64;
@@ -94,7 +87,7 @@
 #elif __GNUC__
 /* The Xserver source compiles with -ansi -pendantic */
 #ifndef __STRICT_ANSI__
-#if defined(VM_IA64) || defined(VM_X86_64)
+#if defined(VM_X86_64)
 typedef unsigned long uint64;
 typedef long int64;
 #else
@@ -125,54 +118,71 @@
  * This applies to Solaris as well.
  */
 
-#if defined(__FreeBSD__) || defined(sun)
-#   ifdef KLD_MODULE
-#      include <sys/types.h>
-#   else
-#      if BSD_VERSION >= 50
-#         include <inttypes.h>
+/*
+ * Before trying to do the includes based on OS defines, see if we can use
+ * feature-based defines to get as much functionality as possible
+ */
+
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_INTTYPES_H
+#include <sys/inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#if !defined(USING_AUTOCONF)
+#   if defined(__FreeBSD__) || defined(sun)
+#      ifdef KLD_MODULE
 #         include <sys/types.h>
 #      else
-#         include <sys/inttypes.h>
-#      endif
-#   endif
-#elif defined __APPLE__
-#   if KERNEL
-#       include <sys/types.h> /* mostly for size_t */
-#       include <stdint.h>
-#   else
-#       include <inttypes.h>
-#       include <stdlib.h>
-#       include <stdint.h>
-#   endif
-#else
-#   if !defined(__intptr_t_defined) && !defined(intptr_t)
-#      define __intptr_t_defined
-#      define intptr_t  intptr_t
-#      ifdef VM_I386
-#         ifdef VM_X86_64
-             typedef int64     intptr_t;
+#         if (BSD_VERSION >= 50)
+#            include <inttypes.h>
+#            include <sys/types.h>
 #         else
-             typedef int32     intptr_t;
+#            include <sys/inttypes.h>
 #         endif
 #      endif
-
-#      ifdef VM_IA64
-          typedef int64     intptr_t;
+#   elif defined __APPLE__
+#      if KERNEL
+#         include <sys/unistd.h>
+#         include <sys/types.h> /* mostly for size_t */
+#         include <stdint.h>
+#      else
+#         include <unistd.h>
+#         include <inttypes.h>
+#         include <stdlib.h>
+#         include <stdint.h>
 #      endif
-#   endif
-
-#   ifndef _STDINT_H
-#      ifdef VM_I386
-#         ifdef VM_X86_64
-             typedef uint64    uintptr_t;
-#         else
-             typedef uint32    uintptr_t;
+#   else
+#      if !defined(__intptr_t_defined) && !defined(intptr_t)
+#         define __intptr_t_defined
+#         define intptr_t  intptr_t
+#         ifdef VM_I386
+#            ifdef VM_X86_64
+typedef int64     intptr_t;
+#            else
+typedef int32     intptr_t;
+#            endif
 #         endif
 #      endif
 
-#      ifdef VM_IA64
-          typedef uint64    uintptr_t;
+#      ifndef _STDINT_H
+#         ifdef VM_I386
+#            ifdef VM_X86_64
+typedef uint64    uintptr_t;
+#            else
+typedef uint32    uintptr_t;
+#            endif
+#         endif
 #      endif
 #   endif
 #endif
@@ -191,22 +201,52 @@
  * Printf format specifiers for size_t and 64-bit number.
  * Use them like this:
  *    printf("%"FMT64"d\n", big);
+ *
+ * FMTH is for handles/fds.
  */
 
 #ifdef _MSC_VER
-   #define FMTSZ      "I"
    #define FMT64      "I64"
+   #ifdef VM_X86_64
+      #define FMTSZ      "I64"
+      #define FMTPD      "I64"
+      #define FMTH       "I64"
+   #else
+      #define FMTSZ      "I"
+      #define FMTPD      "I"
+      #define FMTH       "I"
+   #endif
 #elif __GNUC__
-   #if defined(N_PLAT_NLM) || defined(sun) || (defined(__FreeBSD__) \
-                                               && __FreeBSD__ < 5)
+   #define FMTH ""
+   #if defined(N_PLAT_NLM) || defined(sun) || \
+       (defined(__FreeBSD__) && (__FreeBSD__ + 0) && ((__FreeBSD__ + 0) < 5))
+      /*
+       * Why (__FreeBSD__ + 0)?  See bug 141008.
+       * Yes, we really need to test both (__FreeBSD__ + 0) and
+       * ((__FreeBSD__ + 0) < 5).  No, we can't remove "+ 0" from
+       * ((__FreeBSD__ + 0) < 5).
+       */
       #ifdef VM_X86_64
          #define FMTSZ  "l"
+         #define FMTPD  "l"
       #else
          #define FMTSZ  ""
+         #define FMTPD  ""
       #endif
-   #else
+   #elif (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) \
+      || (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) \
+      || (defined(_POSIX2_VERSION) && _POSIX2_VERSION >= 200112L)
       /* BSD/Darwin, Linux */
       #define FMTSZ     "z"
+      #define FMTPD     "t"
+   #else
+      /* Systems with a pre-C99 libc */
+      #define FMTSZ     "Z"
+      #ifdef VM_X86_64
+         #define FMTPD  "l"
+      #else
+         #define FMTPD  ""
+      #endif
    #endif
    #ifdef VM_X86_64
       #define FMT64     "l"
@@ -293,6 +333,12 @@
 typedef World_ID User_CartelID;
 #define INVALID_CARTEL_ID INVALID_WORLD_ID
 
+typedef User_CartelID User_SessionID;
+#define INVALID_SESSION_ID INVALID_CARTEL_ID
+
+typedef User_CartelID User_CartelGroupID;
+#define INVALID_CARTELGROUP_ID INVALID_CARTEL_ID
+
 /* world page number */
 typedef uint32    WPN;
 
@@ -362,12 +408,19 @@
 #endif
 
 
+/*
+ * Maximal possible PPN value (errors too) that PhysMem can handle.
+ * Must be at least as large as MAX_PPN which is the maximum PPN
+ * for any region other than buserror.
+ */
+#define PHYSMEM_MAX_PPN ((PPN)0xffffffff)
 #define MAX_PPN     ((PPN)0x0fffffff)   /* Maximal observable PPN value. */
 #define INVALID_PPN ((PPN)-1)
 
 #define INVALID_BPN  ((BPN) 0x3fffffff) /* BPNs don't use the high two bits. */
 
 #define INVALID_MPN  ((MPN)-1)
+#define MEMREF_MPN   ((MPN)-2)
 #define RESERVED_MPN ((MPN) 0)
 /* Support 39 bits of address space, minus one page. */
 #define MAX_MPN      ((MPN) 0x07ffffff)
@@ -445,7 +498,7 @@
  */
 #   define INLINE_SINGLE_CALLER INLINE __attribute__((__always_inline__))
 #   if    defined(VMM) \
-       && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 4))
+       && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 1))
 #      warning Verify INLINE_SINGLE_CALLER '__always_inline__' attribute (did \
              monitor size change?)
 #   endif
@@ -575,6 +628,16 @@
 #define ALIGNED(n)
 #endif
 
+/*
+ * __func__ is a stringified function name that is part of the C99 standard. The block
+ * below defines __func__ on older systems where the compiler does not support that
+ * macro.
+ */
+#if defined(__GNUC__) \
+   && ((__GNUC__ == 2 && __GNUC_MINOR < 96) \
+       || (__GNUC__ < 2))
+#   define __func__ __FUNCTION__
+#endif
 
 /*
  * Once upon a time, this was used to silence compiler warnings that
@@ -599,9 +662,6 @@
 #         endif
 #      endif /* VM_I386 */
 
-#      ifdef VM_IA64
-             typedef uint64 size_t;
-#      endif
 #   endif
 #else
 #   ifndef _SIZE_T
@@ -614,9 +674,6 @@
 #         endif
 #      endif /* VM_I386 */
 
-#      ifdef VM_IA64
-             typedef uint64 size_t;
-#      endif
 #   endif
 #   if !defined(FROBOS) && !defined(_SSIZE_T) && !defined(ssize_t)  && !defined(__ssize_t_defined) && !defined(_SSIZE_T_DECLARED)
 #      define _SSIZE_T
@@ -630,9 +687,6 @@
 #         endif
 #      endif /* VM_I386 */
 
-#      ifdef VM_IA64
-             typedef int64 ssize_t;
-#      endif
 #   endif
 #endif
 
@@ -681,4 +735,37 @@
 # define FMTMODE "o"
 #endif
 
+/*
+ * Format modifier for printing time_t. Most platforms define a time_t to be
+ * a long int, but on FreeBSD (as of 5.0, it seems), the time_t is a signed
+ * size quantity. Refer to the definition of FMTSZ to see why we need silly
+ * preprocessor arithmetic.
+ * Use this like this: printf("The mode is %"FMTTIME".\n", time);
+ */
+#if defined(__FreeBSD__) && (__FreeBSD__ + 0) && ((__FreeBSD__ + 0) >= 5)
+#   define FMTTIME FMTSZ"d"
+#else
+#   define FMTTIME "ld"
+#endif
+
+/*
+ * Define MXSemaHandle here so both vmmon and vmx see this definition.
+ */
+
+#ifdef _WIN32
+typedef uintptr_t MXSemaHandle;
+#else
+typedef int MXSemaHandle;
+#endif
+
+/*
+ * Define type for poll device handles.
+ */
+
+#ifdef _WIN32
+typedef uintptr_t PollDevHandle;
+#else
+typedef int PollDevHandle;
+#endif
+
 #endif  /* _VM_BASIC_TYPES_H_ */
diff -uNr vmnet-only-org/vm_device_version.h vmnet-only/vm_device_version.h
--- vmnet-only-org/vm_device_version.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vm_device_version.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,6 +1,5 @@
 /* **********************************************************
  * Copyright 1998 VMware, Inc.  All rights reserved. -- VMware Confidential
- * $Id$
  * **********************************************************/
 
 #ifndef VM_DEVICE_VERSION_H
@@ -13,6 +12,10 @@
 #define INCLUDE_ALLOW_VMCORE
 #include "includeCheck.h"
 
+#ifdef _WIN32
+#include "guiddef.h"
+#endif
+
 /* Our own PCI IDs
  *    VMware SVGA II (Unified VGA)
  *    VMware SVGA (PCI Accelerator)
@@ -20,6 +23,7 @@
  *    VMware vmxscsi (Abortive idealized SCSI controller)
  *    VMware chipset (Subsystem ID for our motherboards)
  *    VMware e1000 (Subsystem ID)
+ *    VMware vmxnet3 (Uniform Pass Through NIC)
  */
 #define PCI_VENDOR_ID_VMWARE            0x15AD
 #define PCI_DEVICE_ID_VMWARE_SVGA2      0x0405
@@ -33,6 +37,8 @@
 #define PCI_DEVICE_ID_VMWARE_EHCI       0x0770
 #define PCI_DEVICE_ID_VMWARE_1394       0x0780
 #define PCI_DEVICE_ID_VMWARE_BRIDGE     0x0790
+#define PCI_DEVICE_ID_VMWARE_ROOTPORT   0x07A0
+#define PCI_DEVICE_ID_VMWARE_VMXNET3    0x07B0
 
 /* The hypervisor device might grow.  Please leave room
  * for 7 more subfunctions.
@@ -111,14 +117,17 @@
 #define VBE_PRODUCT_NAME PRODUCT_GENERIC_NAME
 
 /************* PCI implementation limits ********************************/
-#define PCI_MAX_BRIDGES         2
+#define PCI_MAX_BRIDGES         15
 
 /************* Ethernet implementation limits ***************************/
 #define MAX_ETHERNET_CARDS      10
 
+/************* PCI Passthrough implementation limits ********************/
+#define MAX_PCI_PASSTHRU_DEVICES 2
+
 /************* Strings for Host USB Driver *******************************/
 
-#ifdef WIN32
+#ifdef _WIN32
 
 /*
  * Globally unique ID for the VMware device interface. Define INITGUID before including
diff -uNr vmnet-only-org/vmnetInt.h vmnet-only/vmnetInt.h
--- vmnet-only-org/vmnetInt.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vmnetInt.h	2008-03-07 15:31:40.000000000 +0900
@@ -15,6 +15,16 @@
  * Hide all kernel compatibility stuff in those macros
  */
 
+/* All kernels above 2.6.23 have net namespaces. */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) && !defined(VMW_NETDEV_HAS_NET)
+#   define VMW_NETDEV_HAS_NET
+#endif
+
+/* All kernels above 2.6.23 have skb argument in nf_hookfn. */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) && !defined(VMW_NFHOOK_USES_SKB)
+#   define VMW_NFHOOK_USES_SKB
+#endif
+
 
 #ifdef KERNEL_2_4_0
 #   define compat_fop_set_owner(_pFop) do { \
@@ -33,34 +43,81 @@
 #endif
 
 
-#ifdef VMW_HAVE_SK_ALLOC_WITH_PROTO
+#ifdef skb_shinfo
+#  define SKB_IS_CLONE_OF(clone, skb)   (  \
+      skb_shinfo(clone) == skb_shinfo(skb) \
+   )
+#else
+#  define SKB_IS_CLONE_OF(clone, skb)   (      \
+      skb_datarefp(clone) == skb_datarefp(skb) \
+   )
+#endif
+#define DEV_QUEUE_XMIT(skb, dev, pri)   (                 \
+    (skb)->dev = (dev),                                   \
+    (skb)->priority = (pri),                              \
+    compat_skb_reset_mac_header(skb),                     \
+    compat_skb_set_network_header(skb, sizeof (struct ethhdr)),  \
+    dev_queue_xmit(skb)                                   \
+  )
+#ifdef KERNEL_2_3_15
+#   define dev_lock_list()    read_lock(&dev_base_lock)
+#   define dev_unlock_list()  read_unlock(&dev_base_lock)
+#   ifdef VMW_NETDEV_HAS_NET
+#      define DEV_GET(x)      __dev_get_by_name((x)->internalDev->nd_net, (x)->name)
+#   else
+#      define DEV_GET(x)      __dev_get_by_name((x)->name)
+#   endif
+#else
+#   define DEV_GET(x)         dev_get((x)->name)
+#endif
+
+
+/*
+ * Various fields (including 'dead') of struct sock are replaced with the
+ * 'flags' bitfield in 2.5.65 --hpreg
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 65)
+#   define SET_SK_DEAD(_sk, _val) (_sk)->dead = (_val)
+#else
+#   define SET_SK_DEAD(_sk, _val) sock_valbool_flag(_sk, SOCK_DEAD, _val)
+#endif
+
+
+#ifdef VMW_NETDEV_HAS_NET
+extern struct proto vmnet_proto;
+#   define compat_sk_alloc(_bri, _pri) sk_alloc((_bri)->internalDev->nd_net, \
+                                                PF_NETLINK, _pri, &vmnet_proto)
+#elif defined(VMW_HAVE_SK_ALLOC_WITH_PROTO)
 extern struct proto vmnet_proto;
-#   define compat_sk_alloc(_pri) sk_alloc(PF_NETLINK, _pri, &vmnet_proto, 1)
+#   define compat_sk_alloc(_bri, _pri) sk_alloc(PF_NETLINK, _pri, &vmnet_proto, 1)
 #elif defined(KERNEL_2_5_5)
-#   define compat_sk_alloc(_pri) sk_alloc(PF_NETLINK, _pri, 1, NULL)
+#   define compat_sk_alloc(_bri, _pri) sk_alloc(PF_NETLINK, _pri, 1, NULL)
 #else
-#   define compat_sk_alloc(_pri) sk_alloc(0, _pri, 1)
+#   define compat_sk_alloc(_bri, _pri) sk_alloc(0, _pri, 1)
 #endif
 
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-   #define fileTraversalLock(lock) spin_lock(lock)
-   #define fileTraversalUnLock(lock) spin_unlock(lock)
+#   define fileTraversalLock(lock) spin_lock(lock)
+#   define fileTraversalUnLock(lock) spin_unlock(lock)
 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-   #define fileTraversalLock(lock) read_lock(lock)
-   #define fileTraversalUnLock(lock) read_unlock(lock)
+#   define fileTraversalLock(lock) read_lock(lock)
+#   define fileTraversalUnLock(lock) read_unlock(lock)
 #else //2.2 kernels
-   #define fileTraversalLock(lock) lock_kernel()
-   #define fileTraversalUnLock(lock) unlock_kernel()
+#   define fileTraversalLock(lock) lock_kernel()
+#   define fileTraversalUnLock(lock) unlock_kernel()
 #endif
 
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-   #define taskLock(lock) task_lock(lock)
-   #define taskUnLock(lock) task_unlock(lock)
+#   define taskLock(lock) task_lock(lock)
+#   define taskUnLock(lock) task_unlock(lock)
 #else //2.2 kernels
-   #define taskLock(lock) lock_kernel()
-   #define taskUnLock(lock) unlock_kernel()
+#   define taskLock(lock) lock_kernel()
+#   define taskUnLock(lock) unlock_kernel()
 #endif
 
+
 /* 
  * Use CHECKSUM_HW for old kernels, if they have CHECKSUM_HW.  Use CHECKSUM_PARTIAL for 
  * new ones even if CHECKSUM_HW is defined.  We do not do decision based on kernel version
@@ -68,18 +125,20 @@
  * for CHECKSUM_PARTIAL existence as it may get converted to enum in future.
  */
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) && defined(CHECKSUM_HW)
-#  define VM_CHECKSUM_PARTIAL  CHECKSUM_HW
+#   define VM_CHECKSUM_PARTIAL  CHECKSUM_HW
 #else
-#  define VM_CHECKSUM_PARTIAL  CHECKSUM_PARTIAL
+#   define VM_CHECKSUM_PARTIAL  CHECKSUM_PARTIAL
 #endif
 
+
 /*
  * The "owner" field in nf_hook_ops got added in 2.5.69
  */
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 69)
-#  define compat_nf_hook_owner  .owner = THIS_MODULE,
+#   define compat_nf_hook_owner  .owner = THIS_MODULE,
 #else
-#  define compat_nf_hook_owner
+#   define compat_nf_hook_owner
 #endif
 
+
 #endif /* __VMNETINT_H__ */
diff -uNr vmnet-only-org/vmware_pack_begin.h vmnet-only/vmware_pack_begin.h
--- vmnet-only-org/vmware_pack_begin.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vmware_pack_begin.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All rights reserved. -- VMware Confidential
+ * **********************************************************/
+
 /*
  * vmware_pack_begin.h --
  *
diff -uNr vmnet-only-org/vmware_pack_end.h vmnet-only/vmware_pack_end.h
--- vmnet-only-org/vmware_pack_end.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vmware_pack_end.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All rights reserved. -- VMware Confidential
+ * **********************************************************/
+
 /*
  * vmware_pack_end.h --
  *
diff -uNr vmnet-only-org/vmware_pack_init.h vmnet-only/vmware_pack_init.h
--- vmnet-only-org/vmware_pack_init.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vmware_pack_init.h	2008-03-07 15:31:40.000000000 +0900
@@ -1,3 +1,7 @@
+/* **********************************************************
+ * Copyright (C) 2002 VMware, Inc.  All rights reserved. -- VMware Confidential
+ * **********************************************************/
+
 #ifndef __VMWARE_PACK_INIT_H__
 #   define __VMWARE_PACK_INIT_H__
 
diff -uNr vmnet-only-org/vnet.h vmnet-only/vnet.h
--- vmnet-only-org/vnet.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vnet.h	2008-03-07 15:31:40.000000000 +0900
@@ -62,9 +62,30 @@
 #define SIOCSFILTERRULES    _IOW(0x99, 0xE1, VNet_RuleHeader)
 #endif
 
+// #define OLD_SIOCSKEEP          0x89F0  // not used
+// #define OLD_SIOCGKEEP          0x89F1  // not used
+#define OLD_SIOCSLADRF         0x89F2
+#define OLD_SIOCPORT           0x89F3
+#define OLD_SIOCBRIDGE         0x89F4
+#define OLD_SIOCNETIF          0x89F5
+#define OLD_SIOCSETMACADDR     0x89F6
+#define OLD_SIOCSSWITCHMAP     0x89F7
+#define OLD_SIOCSETNOTIFY      0x89F8
+#define OLD_SIOCUNSETNOTIFY    0x89F9
+#define OLD_SIOCSETCLUSTERSIZE 0x89FA
+#define OLD_SIOCSETNOTIFY2     0x89FB
+#define OLD_SIOCGETAPIVERSION  0x89FC
+
 #ifdef __APPLE__
 
-#define VMNET_KEXT_NAME "com.vmware.kext.vmnet"
+#define VMNET_KEXT_NAME_BASE "com.vmware.kext.vmnet"
+
+#ifdef VMX86_DEVEL
+#define VMNET_KEXT_NAME VMNET_KEXT_NAME_BASE ".devel"
+#else
+#define VMNET_KEXT_NAME VMNET_KEXT_NAME_BASE
+#endif
+
 /*
  * We use [gs]etsockopt on Mac OS instead of ioctls for operations on vmnet
  */
@@ -77,14 +98,28 @@
    VMNET_SO_NETIFCREATE,
    VMNET_SO_IFFLAGS,
    VMNET_SO_LADRF,
-   VMNET_SO_BRCREATE
+   VMNET_SO_BRCREATE,
+   VMNET_SO_SETNOTIFY,
+   VMNET_SO_READDATA,
+   VMNET_SO_UNSETNOTIFY
 };
 
+/*
+ * This magic value is populated in VNet_Notify.actMask and VNet_Notify.pollMask
+ * to request the driver to clear the Notify pollPtr if the receive queue is empty.
+ */
+#define VNET_NOTIFY_CLR_MAGIC   0xDECAFBAD
+
 typedef struct VNet_NetIf {
    char name[16];               // The BSD name of the interface
    uint8 instance;              // The "unit number" of the interface
 } VNet_NetIf;
 
+typedef struct VNet_Read {
+   VA uAddr;            // Buffer to read into
+   size_t len;          // Max number of bytes to read
+} VNet_Read;
+
 #endif
 
 /*
@@ -100,6 +135,7 @@
  * also remove all code under the VNET_API_DEPRECATED define. --hpreg
  */
 
+#define VNET_API_VERSION_WS45		(2 << 16 | 0)
 #ifdef linux
 #define VNET_API_VERSION		(3 << 16 | 0)
 #else
@@ -113,7 +149,7 @@
  * next major version. --hpreg
  */
 #ifdef linux
-#   if VNET_API_VERSION < (3 << 16 | 0)
+#   if VNET_API_VERSION < (999 << 16 | 0)
 #      define VNET_API_DEPRECATED 1
 #   endif
 #else
@@ -130,15 +166,36 @@
    unsigned        flags;
 } VNet_SetMacAddrIOCTL;
 
-typedef struct VNet_Notify {
+typedef struct VNet_NotifyH {
+   uint32           version;
+} VNet_NotifyH;
+
+typedef struct VNet_Notify1 {
+   uint32           version;
+   uint32           actPtr;
+   uint32           pollPtr;
+   uint32           actMask;
+   uint32           pollMask;
+} VNet_Notify1;
+
+typedef struct VNet_Notify2 {
+   uint32           version;
+   uint32           actPtr;
+   uint32           pollPtr;
+   uint32           recvClusterPtr;
+   uint32           actMask;
+   uint32           pollMask;
+} VNet_Notify2;
+
+typedef struct VNet_Notify3 {
    uint32           version;
-   uint32           padding;        /* Make gcc 64bit abi padding explicit */
-   uint64           actPtr;         /* (Atomic_uint32 *) */
-   uint64           pollPtr;        /* (uint32 volatile *) */
-   uint64           recvClusterPtr; /* (uint32 volatile *) */
+   uint32           pad1;
+   uint64           actPtr;
+   uint64           pollPtr;
+   uint64           recvClusterPtr;
    uint32           actMask;
    uint32           pollMask;
-} VNet_Notify;
+} VNet_Notify3;
 
 #define VNET_SETMACADDRF_UNIQUE      0x01
 /*
diff -uNr vmnet-only-org/vnetFilter.h vmnet-only/vnetFilter.h
--- vmnet-only-org/vnetFilter.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vnetFilter.h	2008-03-07 15:31:40.000000000 +0900
@@ -21,7 +21,6 @@
 #include "includeCheck.h"
 
 #include "vm_basic_types.h"
-#include "vmware_pack_init.h"
 
 /*
  * Call:
diff -uNr vmnet-only-org/vnetInt.h vmnet-only/vnetInt.h
--- vmnet-only-org/vnetInt.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/vnetInt.h	2008-03-07 15:31:40.000000000 +0900
@@ -13,42 +13,6 @@
 
 #include <asm/page.h>
 
-#ifdef skb_shinfo
-#  define SKB_IS_CLONE_OF(clone, skb)	(  \
-      skb_shinfo(clone) == skb_shinfo(skb) \
-   )
-#else
-#  define SKB_IS_CLONE_OF(clone, skb)	(      \
-      skb_datarefp(clone) == skb_datarefp(skb) \
-   )
-#endif
-#define DEV_QUEUE_XMIT(skb, dev, pri)	(                 \
-    (skb)->dev = (dev),                                   \
-    (skb)->priority = (pri),                              \
-    compat_skb_reset_mac_header(skb),                     \
-    compat_skb_set_network_header(skb, sizeof (struct ethhdr)),  \
-    dev_queue_xmit(skb)                                   \
-  )
-#ifdef KERNEL_2_3_15
-#  define dev_lock_list()		read_lock(&dev_base_lock)
-#  define dev_unlock_list()		read_unlock(&dev_base_lock)
-#  define DEV_GET(x)                    __dev_get_by_name(x)
-#else
-#  define DEV_GET(x)			dev_get(x)
-#endif
-
-
-/*
- * Various fields (including 'dead') of struct sock are replaced with the
- * 'flags' bitfield in 2.5.65 --hpreg
- */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 65)
-#   define SET_SK_DEAD(_sk, _val) (_sk)->dead = (_val)
-#else
-#   define SET_SK_DEAD(_sk, _val) sock_valbool_flag(_sk, SOCK_DEAD, _val)
-#endif
-
-
 #define INLINE inline
 
      
@@ -190,14 +154,14 @@
 
 VNetJack *VNetDisconnect(VNetJack *jack);
 
-void VNetSend(VNetJack *jack, struct sk_buff *skb);
+void VNetSend(const VNetJack *jack, struct sk_buff *skb);
 
 int VNetProc_MakeEntry(VNetProcEntry *parent, char *name, int mode,
                        VNetProcEntry **ret);
 
 void VNetProc_RemoveEntry(VNetProcEntry *node, VNetProcEntry *parent);
 
-int VNetPrintJack(VNetJack *jack, char *buf);
+int VNetPrintJack(const VNetJack *jack, char *buf);
 
 int VNet_MakeMACAddress(VNetPort *port);
 
@@ -208,15 +172,17 @@
  *  Utility functions
  */
 
-extern uint8 AllMultiFilter[VNET_LADRF_LEN];
-
-Bool VNetPacketMatch(uint8 *destAddr, uint8 *ifAddr, uint8 *ladrf, uint32 flags);
+extern const uint8 allMultiFilter[VNET_LADRF_LEN];
+extern const uint8 broadcast[ETH_ALEN];
+ 
+Bool VNetPacketMatch(const uint8 *destAddr, const uint8 *ifAddr, 
+		     const uint8 *ladrf, uint32 flags);
 
-Bool VNetCycleDetectIf(char *name, int generation);
+Bool VNetCycleDetectIf(const char *name, int generation);
 
 void VNetIncrModCount(int delta);
 
-int VNetPrintPort(VNetPort *port, char *buf);
+int VNetPrintPort(const VNetPort *port, char *buf);
 
 int VNetSnprintf(char *str, size_t size, const char *format, ...);
 
diff -uNr vmnet-only-org/x86cpuid.h vmnet-only/x86cpuid.h
--- vmnet-only-org/x86cpuid.h	2007-10-08 23:29:31.000000000 +0900
+++ vmnet-only/x86cpuid.h	2008-03-07 15:31:40.000000000 +0900
@@ -60,6 +60,10 @@
  * during power-on/migration.  Any level which is marked as FALSE here
  * *must* have all field masks defined as IGNORE in CPUID_FIELD_DATA.
  * A static assert in lib/cpuidcompat/cpuidcompat.c will check this.
+ *
+ * IMPORTANT: WHEN ADDING A NEW FIELD TO THE CACHED LEVELS, make sure
+ * you update vmcore/vmm/cpu/priv.c:Priv_CPUID() and vmcore/vmm64/bt/
+ * cpuid_shared.S (and geninfo) to include the new level.
  */
 
 #define CPUID_CACHED_LEVELS                     \
@@ -198,15 +202,15 @@
                                                         
 /*    LEVEL, REG, VENDOR, POS, SIZE, NAME,        MASK TYPE, SET TO, [FUNC] */
 #define CPUID_FIELD_DATA_LEVEL_1                                               \
-FIELDDEFA( 1, EAX, COMMON,  0,  4, STEPPING,            IGNORE,  0, Stepping)  \
-FIELDDEFA( 1, EAX, COMMON,  4,  4, MODEL,               IGNORE,  0, Model)     \
-FIELDDEFA( 1, EAX, COMMON,  8,  4, FAMILY,              HOST,    0, Family)    \
+FIELDDEFA( 1, EAX, COMMON,  0,  4, STEPPING,            IGNORE,  0, STEPPING)  \
+FIELDDEFA( 1, EAX, COMMON,  4,  4, MODEL,               IGNORE,  0, MODEL)     \
+FIELDDEFA( 1, EAX, COMMON,  8,  4, FAMILY,              HOST,    0, FAMILY)    \
 FIELDDEF(  1, EAX, COMMON, 12,  2, TYPE,                IGNORE,  0)            \
-FIELDDEFA( 1, EAX, COMMON, 16,  4, EXTMODEL,            IGNORE,  0, ExtModel)  \
-FIELDDEFA( 1, EAX, COMMON, 20,  8, EXTFAMILY,           HOST,    0, ExtFamily) \
+FIELDDEFA( 1, EAX, COMMON, 16,  4, EXTMODEL,            IGNORE,  0, EXT_MODEL) \
+FIELDDEFA( 1, EAX, COMMON, 20,  8, EXTFAMILY,           HOST,    0, EXT_FAMILY) \
 FIELDDEF(  1, EBX, COMMON,  0,  8, BRAND_ID,            IGNORE,  0)            \
 FIELDDEF(  1, EBX, COMMON,  8,  8, CLFL_SIZE,           IGNORE,  0)            \
-FIELDDEFA( 1, EBX, COMMON, 16,  8, LCPU_COUNT,          IGNORE,  0, LCPUCount) \
+FIELDDEFA( 1, EBX, COMMON, 16,  8, LCPU_COUNT,          IGNORE,  0, LCPU_COUNT) \
 FIELDDEFA( 1, EBX, COMMON, 24,  8, APICID,              IGNORE,  0, APICID)    \
 FLAGDEFA(  1, ECX, COMMON, 0,   1, SSE3,                HOST,    0, SSE3)      \
 FLAGDEFA(  1, ECX, INTEL,  3,   1, MWAIT,               MASK,    0, MWAIT)     \
@@ -221,10 +225,11 @@
 FLAGDEF(   1, ECX, INTEL,  14,  1, xPPR,                MASK,    0)            \
 FLAGDEF(   1, ECX, INTEL,  15,  1, PERF_MSR,            MASK,    0)            \
 FLAGDEF(   1, ECX, INTEL,  16,  1, NDA16,               MASK,    0)            \
+FLAGDEF(   1, ECX, INTEL,  18,  1, DCA,                 MASK,    0)            \
 FLAGDEFA(  1, ECX, INTEL,  19,  1, SSE41,               HOST,    0, SSE41)     \
 FLAGDEFA(  1, ECX, INTEL,  20,  1, SSE42,               HOST,    0, SSE42)     \
 FLAGDEFA(  1, ECX, COMMON, 23,  1, POPCNT,              HOST,    0, POPCNT)    \
-FLAGDEF(   1, EDX, COMMON, 0,   1, FPU,                 HOST,    0)            \
+FLAGDEFA(  1, EDX, COMMON, 0,   1, FPU,                 HOST,    0, FPU)       \
 FLAGDEFA(  1, EDX, COMMON, 1,   1, VME,                 HOST,    0, VME)       \
 FLAGDEF(   1, EDX, COMMON, 2,   1, DBGE,                HOST,    0)            \
 FLAGDEF(   1, EDX, COMMON, 3,   1, PGSZE,               HOST,    0)            \
@@ -239,10 +244,10 @@
 FLAGDEFA(  1, EDX, COMMON, 13,  1, PGE,                 HOST,    0, PGE)       \
 FLAGDEFA(  1, EDX, COMMON, 14,  1, MCA,                 HOST,    0, MCA)       \
 FLAGDEFA(  1, EDX, COMMON, 15,  1, CMOV,                HOST,    0, CMOV)      \
-FLAGDEF(   1, EDX, COMMON, 16,  1, PAT,                 HOST,    0)            \
+FLAGDEFA(  1, EDX, COMMON, 16,  1, PAT,                 HOST,    0, PAT)       \
 FLAGDEF(   1, EDX, COMMON, 17,  1, 36PG,                HOST,    0)            \
 FLAGDEF(   1, EDX, INTEL,  18,  1, PSN,                 HOST,    0)            \
-FLAGDEFA(   1, EDX, COMMON, 19,  1, CLFL,                HOST,    0, CLFL)     \
+FLAGDEFA(  1, EDX, COMMON, 19,  1, CLFL,                HOST,    0, CLFL)      \
 FLAGDEF(   1, EDX, INTEL,  21,  1, DTES,                HOST,    0)            \
 FLAGDEF(   1, EDX, INTEL,  22,  1, ACPI,                HOST,    0)            \
 FLAGDEFA(  1, EDX, COMMON, 23,  1, MMX,                 HOST,    0, MMX)       \
@@ -260,7 +265,7 @@
 FIELDDEF(  4, EAX, INTEL,   0,  5, CACHE_TYPE,          IGNORE,  0)            \
 FIELDDEF(  4, EAX, INTEL,   5,  3, CACHE_LEVEL,         IGNORE,  0)            \
 FIELDDEF(  4, EAX, INTEL,  14, 12, CACHE_NUMHT_SHARING, IGNORE,  0)            \
-FIELDDEFA( 4, EAX, INTEL,  26,  6, CORE_COUNT,          IGNORE,  0, IntelCoreCount)  \
+FIELDDEFA( 4, EAX, INTEL,  26,  6, CORE_COUNT,          IGNORE,  0, INTEL_CORE_COUNT)  \
 FIELDDEF(  4, EBX, INTEL,   0, 12, CACHE_LINE,          IGNORE,  0)            \
 FIELDDEF(  4, EBX, INTEL,  12, 10, CACHE_PART,          IGNORE,  0)            \
 FIELDDEF(  4, EBX, INTEL,  22, 10, CACHE_WAYS,          IGNORE,  0)
@@ -268,7 +273,7 @@
 /*    LEVEL, REG, VENDOR, POS, SIZE, NAME,           MASK TYPE, SET TO, [FUNC] */
 #define CPUID_FIELD_DATA_LEVEL_A                                               \
 FIELDDEF(  A, EAX, INTEL,   0,  8, PMC_VERSION,         IGNORE,  0)            \
-FIELDDEFA( A, EAX, INTEL,   8,  8, NUM_PMCS,            IGNORE,  0, NumPMCs)   \
+FIELDDEFA( A, EAX, INTEL,   8,  8, NUM_PMCS,            IGNORE,  0, NUM_PMCS)  \
 FIELDDEF(  A, EAX, INTEL,  16,  8, PMC_BIT_WIDTH,       IGNORE,  0)            \
 FIELDDEF(  A, EAX, INTEL,  24,  8, PMC_EBX_LENGTH,      IGNORE,  0)            \
 FLAGDEF(   A, EBX, INTEL,   0,  1, PMC_CORE_CYCLE,      IGNORE,  0)            \
@@ -299,10 +304,10 @@
 FIELDDEF( 81, EBX, AMD,     0, 16, BRAND_ID,            IGNORE,  0)            \
 FIELDDEF( 81, EBX, AMD,    16, 16, UNDEF,               IGNORE,  0)            \
 FLAGDEFA( 81, ECX, COMMON,  0,  1, LAHF,                HOST,    0, LAHF64)    \
-FLAGDEF(  81, ECX, AMD,     1,  1, CMPLEGACY,           MASK,    0)            \
+FLAGDEFA( 81, ECX, AMD,     1,  1, CMPLEGACY,           MASK,    0, CMPLEGACY) \
 FLAGDEFA( 81, ECX, AMD,     2,  1, SVM,                 MASK,    0, SVM)       \
-FLAGDEF(  81, ECX, AMD,     3,  1, EXTAPICSPC,          MASK,    0)            \
-FLAGDEF(  81, ECX, AMD,     4,  1, CR8AVAIL,            MASK,    0)            \
+FLAGDEFA( 81, ECX, AMD,     3,  1, EXTAPICSPC,          HOST,    0, EXTAPICSPC) \
+FLAGDEFA( 81, ECX, AMD,     4,  1, CR8AVAIL,            MASK,    0, CR8AVAIL)  \
 FLAGDEFA( 81, ECX, AMD,     5,  1, ABM,                 HOST,    0, ABM)       \
 FLAGDEFA( 81, ECX, AMD,     6,  1, SSE4A,               HOST,    0, SSE4A)     \
 FLAGDEF(  81, ECX, AMD,     7,  1, MISALIGNED_SSE,      HOST,    0)            \
@@ -317,7 +322,7 @@
 FLAGDEF(  81, EDX, AMD,     7,  1, MCK,                 HOST,    0)            \
 FLAGDEF(  81, EDX, AMD,     8,  1, CPMX,                HOST,    0)            \
 FLAGDEF(  81, EDX, AMD,     9,  1, APIC,                MASK,    1)            \
-FLAGDEFA( 81, EDX, COMMON, 11,  1, SYSC,                HOST,    0, SYSC)      \
+FLAGDEFA( 81, EDX, COMMON, 11,  1, SYSC,                IGNORE,  0, SYSC)      \
 FLAGDEF(  81, EDX, AMD,    12,  1, MTRR,                HOST,    0)            \
 FLAGDEF(  81, EDX, AMD,    13,  1, PGE,                 HOST,    0)            \
 FLAGDEF(  81, EDX, AMD,    14,  1, MCA,                 HOST,    0)            \
@@ -331,7 +336,7 @@
 FLAGDEFA( 81, EDX, AMD,    25,  1, FFXSR,               HOST,    0, FFXSR)     \
 FLAGDEF(  81, EDX, AMD,    26,  1, PDPE1GB,             MASK,    0)            \
 FLAGDEFA( 81, EDX, AMD,    27,  1, RDTSCP,              HOST,    0, RDTSCP)    \
-FLAGDEFA( 81, EDX, COMMON, 29,  1, LM,                  HOST,    0, LM)        \
+FLAGDEFA( 81, EDX, COMMON, 29,  1, LM,                  TEST,    1, LM)        \
 FLAGDEFA( 81, EDX, AMD,    30,  1, 3DNOWPLUS,           HOST,    0, 3DNOWPLUS) \
 FLAGDEFA( 81, EDX, AMD,    31,  1, 3DNOW,               HOST,    0, 3DNOW)
 
@@ -342,11 +347,11 @@
 FIELDDEF( 86, ECX, AMD,    12,  4, CACHE_WAYS,          IGNORE,  0)            \
 FIELDDEF( 86, ECX, AMD,    16, 16, CACHE_SIZE,          IGNORE,  0)            \
 FLAGDEF(  87, EDX, AMD,     8,  1, TSC_INVARIANT,       IGNORE,  0)            \
-FIELDDEFA(88, EAX, COMMON,  0,  8, PHYSBITS,            IGNORE,  0, PhysBits)  \
-FIELDDEFA(88, EAX, COMMON,  8,  8, VIRTBITS,            IGNORE,  0, VirtBits)  \
-FIELDDEFA(88, ECX, AMD,     0,  8, CORE_COUNT,          IGNORE,  0, AMDCoreCount) \
+FIELDDEFA(88, EAX, COMMON,  0,  8, PHYSBITS,            IGNORE,  0, PHYS_BITS) \
+FIELDDEFA(88, EAX, COMMON,  8,  8, VIRTBITS,            IGNORE,  0, VIRT_BITS) \
+FIELDDEFA(88, ECX, AMD,     0,  8, CORE_COUNT,          IGNORE,  0, AMD_CORE_COUNT) \
 FIELDDEF( 88, ECX, AMD,    12,  4, APICID_COREID_SIZE,  IGNORE,  0)            \
-FIELDDEFA(8A, EAX, AMD,     0,  8, SVM_REVISION,        MASK,    0, SVMRevision) \
+FIELDDEFA(8A, EAX, AMD,     0,  8, SVM_REVISION,        MASK,    0, SVM_REVISION) \
 FLAGDEF(  8A, EAX, AMD,     8,  1, SVM_HYPERVISOR,      MASK,    0)            \
 FIELDDEF( 8A, EAX, AMD,     9, 23, SVMEAX_RSVD,         MASK,    0)            \
 FIELDDEF( 8A, EBX, AMD,     0, 32, SVM_N_ASIDS,         MASK,    0)            \
@@ -354,7 +359,8 @@
 FLAGDEF(  8A, EDX, AMD,     0,  1, SVM_NP,              MASK,    0)            \
 FLAGDEF(  8A, EDX, AMD,     1,  1, SVM_LBR,             MASK,    0)            \
 FLAGDEF(  8A, EDX, AMD,     2,  1, SVM_LOCK,            MASK,    0)            \
-FIELDDEF( 8A, EDX, AMD,     3, 29, SVMEDX_RSVD,         MASK,    0)
+FLAGDEF(  8A, EDX, AMD,     3,  1, SVM_NRIP,            MASK,    0)            \
+FIELDDEF( 8A, EDX, AMD,     4, 28, SVMEDX_RSVD,         MASK,    0)
 
 #define CPUID_FIELD_DATA                                              \
    CPUID_FIELD_DATA_LEVEL_0                                           \
@@ -380,12 +386,12 @@
  * Note: The FEATURE/MASK definitions must use some gymnastics to get
  * around a warning when shifting left by 32.
  */
-#define BIT_MASK(shift)  (((1 << (shift - 1)) << 1) - 1)
+#define VMW_BIT_MASK(shift)  (((1 << (shift - 1)) << 1) - 1)
 
 #define FIELDDEF(lvl, reg, vend, bitpos, size, name, m, v)              \
    CPUID_##vend##_ID##lvl##reg##_##name##_SHIFT = bitpos,               \
    CPUID_##vend##_ID##lvl##reg##_##name##_MASK  =                       \
-                      BIT_MASK(size) << bitpos,                         \
+                      VMW_BIT_MASK(size) << bitpos,                     \
    CPUID_FEATURE_##vend##_ID##lvl##reg##_##name =                       \
                       CPUID_##vend##_ID##lvl##reg##_##name##_MASK,
 
@@ -399,7 +405,7 @@
    /* Define data for every CPUID field we have */
    CPUID_FIELD_DATA
 };
-#undef BIT_MASK
+#undef VMW_BIT_MASK
 #undef FIELDDEF
 #undef FLAGDEF
 #undef FIELDDEFA
@@ -485,6 +491,8 @@
 FIELD_FUNC(SVM_N_ASIDS,      CPUID_AMD_ID8AEBX_SVM_N_ASIDS)
 FIELD_FUNC(INTEL_CORE_COUNT, CPUID_INTEL_ID4EAX_CORE_COUNT)
 FIELD_FUNC(AMD_CORE_COUNT,   CPUID_AMD_ID88ECX_CORE_COUNT)
+FIELD_FUNC(AMD_APICID_COREID_SIZE, CPUID_AMD_ID88ECX_APICID_COREID_SIZE)
+FIELD_FUNC(AMD_EXTAPICSPC,   CPUID_AMD_ID81ECX_EXTAPICSPC)
 FIELD_FUNC(NUM_PMCS,         CPUID_INTEL_IDAEAX_NUM_PMCS)
 #undef FIELD_FUNC
 
@@ -495,21 +503,33 @@
  */
 
 /* Effective Intel CPU Families */
-#define CPUID_FAMILY_486     4
-#define CPUID_FAMILY_P5      5
-#define CPUID_FAMILY_P6      6
-#define CPUID_FAMILY_P4      15
+#define CPUID_FAMILY_486      4
+#define CPUID_FAMILY_P5       5
+#define CPUID_FAMILY_P6       6
+#define CPUID_FAMILY_P4       15
 
 /* Effective AMD CPU Families */
-#define CPUID_FAMILY_5x86    4
-#define CPUID_FAMILY_K5      5
-#define CPUID_FAMILY_K6      5
-#define CPUID_FAMILY_K7      6
-#define CPUID_FAMILY_K8      15
-#define CPUID_FAMILY_K8L     16
-
+#define CPUID_FAMILY_5x86     4
+#define CPUID_FAMILY_K5       5
+#define CPUID_FAMILY_K6       5
+#define CPUID_FAMILY_K7       6
+#define CPUID_FAMILY_K8       15
+#define CPUID_FAMILY_K8L      16
+#define CPUID_FAMILY_K8MOBILE 17
 #define CPUID_FAMILY_EXTENDED 15
 
+/* Intel model information */
+#define CPUID_MODEL_PPRO       1
+#define CPUID_MODEL_PII_3      3
+#define CPUID_MODEL_PII_5      5
+#define CPUID_MODEL_CELERON_6  6
+#define CPUID_MODEL_PIII_7     7
+#define CPUID_MODEL_PIII_8     8
+#define CPUID_MODEL_PM         9
+#define CPUID_MODEL_PIII_A     10
+#define CPUID_MODEL_CORE       14
+#define CPUID_MODEL_CORE2      15
+
 static INLINE uint32
 CPUID_EFFECTIVE_FAMILY(uint32 v) /* %eax from CPUID with %eax=1. */
 {
@@ -563,7 +583,8 @@
 CPUID_FAMILY_IS_CORE(uint32 v) // IN: %eax from CPUID with %eax=1.
 {
    /* Assumes the CPU manufacturer is Intel. */
-   return CPUID_FAMILY_IS_P6(v) && CPUID_EFFECTIVE_MODEL(v) > 13;
+   return CPUID_FAMILY_IS_P6(v) &&
+          CPUID_EFFECTIVE_MODEL(v) >= CPUID_MODEL_CORE;
 }
 
 
@@ -597,23 +618,23 @@
 }
 
 static INLINE Bool
+CPUID_FAMILY_IS_K8MOBILE(uint32 _eax)
+{
+   /* Essentially a K8 (not K8L) part, but with mobile features. */
+   return CPUID_EFFECTIVE_FAMILY(_eax) == CPUID_FAMILY_K8MOBILE;
+}
+
+static INLINE Bool
 CPUID_FAMILY_IS_K8STAR(uint32 _eax)
 {
-   /* Read function name as "K8*", as in wildcard.  Matches K8 or K8L */
-   return CPUID_FAMILY_IS_K8(_eax) || CPUID_FAMILY_IS_K8L(_eax);
+   /*
+    * Read function name as "K8*", as in wildcard.
+    * Matches K8 or K8L or K8MOBILE
+    */
+   return CPUID_FAMILY_IS_K8(_eax) || CPUID_FAMILY_IS_K8L(_eax) ||
+          CPUID_FAMILY_IS_K8MOBILE(_eax);
 }
 
-#define CPUID_MODEL_PPRO       1
-#define CPUID_MODEL_PII_3      3
-#define CPUID_MODEL_PII_5      5
-#define CPUID_MODEL_CELERON_6  6
-#define CPUID_MODEL_PIII_7     7
-#define CPUID_MODEL_PIII_8     8
-#define CPUID_MODEL_PM         9
-#define CPUID_MODEL_PIII_A     10
-#define CPUID_MODEL_CORE       14
-#define CPUID_MODEL_CORE2      15
-#define CPUID_MODEL_EXTENDED   15
 
 #define CPUID_TYPE_PRIMARY     0
 #define CPUID_TYPE_OVERDRIVE   1
@@ -636,9 +657,20 @@
 CPUID_FullyWritableTSC(Bool isIntel, // IN
                        uint32 v)     // IN: %eax from CPUID with %eax=1.
 {
-   return (isIntel && CPUID_FAMILY_IS_CORE(v)) ||
-          (CPUID_FAMILY(v) == CPUID_FAMILY_EXTENDED &&
-           !(isIntel && CPUID_FAMILY_IS_PENTIUM4(v) && CPUID_MODEL(v) < 3));
+   /*
+    * Returns FALSE if:
+    *   - Intel && P6 (pre-core) or
+    *   - Intel && P4 (model < 3) or
+    *   - !Intel && pre-K8 Opteron
+    * Otherwise, returns TRUE.
+    */
+   return !((isIntel &&
+             ((CPUID_FAMILY_IS_P6(v) &&
+               CPUID_EFFECTIVE_MODEL(v) < CPUID_MODEL_CORE) ||
+              (CPUID_FAMILY_IS_PENTIUM4(v) &&
+               CPUID_EFFECTIVE_MODEL(v) < 3))) ||
+            (!isIntel &&
+             CPUID_FAMILY(v) < CPUID_FAMILY_K8));
 }
 
 /*
@@ -663,14 +695,14 @@
  */
 
 static INLINE uint32
-CPUID_IntelCoresPerPCPU(uint32 v) /* %eax from CPUID with %eax=4 and %ecx=0. */
+CPUID_IntelCoresPerPackage(uint32 v) /* %eax from CPUID with %eax=4 and %ecx=0. */
 {
    // Note: This is not guaranteed to work on older Intel CPUs.
    return 1 + CPUID_INTEL_CORE_COUNT(v);
 }
 
 static INLINE uint32
-CPUID_AMDCoresPerPCPU(uint32 v) /* %ecx from CPUID with %eax=0x80000008. */
+CPUID_AMDCoresPerPackage(uint32 v) /* %ecx from CPUID with %eax=0x80000008. */
 {
    // Note: This is not guaranteed to work on older AMD CPUs.
    return 1 + CPUID_AMD_CORE_COUNT(v);
