]> git.pld-linux.org Git - packages/kernel.git/commitdiff
-started update to 2.6.30; patches apply when using --without grsecurity
authorArkadiusz Miśkiewicz <arekm@maven.pl>
Mon, 20 Jul 2009 12:57:26 +0000 (12:57 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    kernel-apparmor-common.patch -> 1.3
    kernel-apparmor.patch -> 1.3
    kernel-bzip2-lzma.patch -> 1.3
    kernel-mpt-fusion.patch -> 1.4
    kernel-owner-xid.patch -> 1.3
    kernel-routes.patch -> 1.3
    kernel-tuxonice-headers.patch -> 1.3
    kernel-tuxonice.patch -> 1.5
    kernel-unionfs.patch -> 1.3
    kernel-vserver-2.3.patch -> 1.12
    kernel-warnings.patch -> 1.3
    kernel.spec -> 1.677

12 files changed:
kernel-apparmor-common.patch [deleted file]
kernel-apparmor.patch
kernel-bzip2-lzma.patch [deleted file]
kernel-mpt-fusion.patch
kernel-owner-xid.patch
kernel-routes.patch
kernel-tuxonice-headers.patch
kernel-tuxonice.patch
kernel-unionfs.patch
kernel-vserver-2.3.patch
kernel-warnings.patch
kernel.spec

diff --git a/kernel-apparmor-common.patch b/kernel-apparmor-common.patch
deleted file mode 100644 (file)
index e3fb589..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-===
-=== apparmor api in vserver addons
-===
---- i/fs/namei.c       2008-10-29 15:18:09.918901818 +0100
-+++ i/fs/namei.c~      2008-10-29 15:16:48.000000000 +0100
-@@ -3212,8 +3212,8 @@
-               new_path.dentry->d_name.len,
-               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
-               old_path.dentry->d_name.len);
--      ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
--              old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
-+      ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry, new_path.mnt,
-+              old_nd.path.dentry->d_parent->d_inode, old_path.dentry, old_path.mnt);
-       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
-       res = new_path.dentry;
-@@ -3238,7 +3238,7 @@
-               goto out_redo;
-       /* error path cleanup */
--      vfs_unlink(dir->d_inode, new_path.dentry);
-+      vfs_unlink(dir->d_inode, new_path.dentry, new_path.mnt);
-       dput(new_path.dentry);
- out_redo:
-===
-=== we add this export in small_fixes.patch with regard to unionfs
-===
---- i/security/security.c~     2008-10-29 15:38:27.000000000 +0100
-+++ i/security/security.c      2008-10-29 15:45:30.761065898 +0100
-@@ -415,7 +415,6 @@ int security_inode_mknod(struct inode *d
-               return 0;
-       return security_ops->inode_mknod(dir, dentry, mnt, mode, dev);
- }
--EXPORT_SYMBOL_GPL(security_inode_permission);
- int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
-                         struct vfsmount *old_mnt, struct inode *new_dir,
-===
-=== support for security= in cmdline
-===
---- i/security/apparmor/lsm.c~ 2008-10-31 14:35:08.000000000 +0100
-+++ i/security/apparmor/lsm.c  2008-10-31 15:00:32.222153300 +0100
-@@ -988,6 +988,9 @@ void info_message(const char *str)
- static int __init apparmor_init(void)
- {
-       int error;
-+
-+      if (!security_module_enable(&apparmor_ops))
-+                      return 0;
-       if (!apparmor_enabled) {
-               info_message("AppArmor disabled by boottime parameter\n");
index 049b85887818f177745d497b2588108fef263663..1a5695e22419961a9095f2d075eea48136e1ac4d 100644 (file)
-diff -uprN e/fs/afs/dir.c f/fs/afs/dir.c
---- e/fs/afs/dir.c     2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/afs/dir.c     2008-05-28 20:29:29.410207000 +0000
-@@ -45,6 +45,7 @@ const struct file_operations afs_dir_fil
-       .release        = afs_release,
-       .readdir        = afs_readdir,
-       .lock           = afs_lock,
-+      .fsetattr       = afs_fsetattr,
- };
- const struct inode_operations afs_dir_inode_operations = {
-diff -uprN e/fs/afs/file.c f/fs/afs/file.c
---- e/fs/afs/file.c    2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/afs/file.c    2008-05-28 20:29:29.410207000 +0000
-@@ -36,6 +36,7 @@ const struct file_operations afs_file_op
-       .fsync          = afs_fsync,
-       .lock           = afs_lock,
-       .flock          = afs_flock,
-+      .fsetattr       = afs_fsetattr,
- };
- const struct inode_operations afs_file_inode_operations = {
-diff -uprN e/fs/afs/inode.c f/fs/afs/inode.c
---- e/fs/afs/inode.c   2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/afs/inode.c   2008-05-28 20:29:29.410207000 +0000
-@@ -358,7 +358,8 @@ void afs_clear_inode(struct inode *inode
- /*
-  * set the attributes of an inode
-  */
--int afs_setattr(struct dentry *dentry, struct iattr *attr)
-+static int afs_do_setattr(struct dentry *dentry, struct iattr *attr,
-+                 struct file *file)
- {
-       struct afs_vnode *vnode = AFS_FS_I(dentry->d_inode);
-       struct key *key;
-@@ -380,8 +381,8 @@ int afs_setattr(struct dentry *dentry, s
-               afs_writeback_all(vnode);
-       }
--      if (attr->ia_valid & ATTR_FILE) {
--              key = attr->ia_file->private_data;
-+      if (file) {
-+              key = file->private_data;
-       } else {
-               key = afs_request_key(vnode->volume->cell);
-               if (IS_ERR(key)) {
-@@ -391,10 +392,20 @@ int afs_setattr(struct dentry *dentry, s
-       }
+diff --git a/include/linux/audit.h b/include/linux/audit.h
+index 4fa2810..9f87073 100644
+--- a/include/linux/audit.h
++++ b/include/linux/audit.h
+@@ -33,7 +33,7 @@
+  * 1200 - 1299 messages internal to the audit daemon
+  * 1300 - 1399 audit event messages
+  * 1400 - 1499 SE Linux use
+- * 1500 - 1599 kernel LSPP events
++ * 1500 - 1599 AppArmor use
+  * 1600 - 1699 kernel crypto events
+  * 1700 - 1799 kernel anomaly records
+  * 1800 - 1899 kernel integrity events
+@@ -122,6 +122,14 @@
+ #define AUDIT_MAC_UNLBL_STCADD        1416    /* NetLabel: add a static label */
+ #define AUDIT_MAC_UNLBL_STCDEL        1417    /* NetLabel: del a static label */
  
-       ret = afs_vnode_setattr(vnode, key, attr);
--      if (!(attr->ia_valid & ATTR_FILE))
-+      if (!file)
-               key_put(key);
++#define AUDIT_APPARMOR_AUDIT  1501    /* AppArmor audited grants */
++#define AUDIT_APPARMOR_ALLOWED        1502    /* Allowed Access for learning */
++#define AUDIT_APPARMOR_DENIED 1503
++#define AUDIT_APPARMOR_HINT   1504    /* Process Tracking information */
++#define AUDIT_APPARMOR_STATUS 1505    /* Changes in config */
++#define AUDIT_APPARMOR_ERROR  1506    /* Internal AppArmor Errors */
++#define AUDIT_APPARMOR_KILL   1507    /* AppArmor killing processes */
++
+ #define AUDIT_FIRST_KERN_ANOM_MSG   1700
+ #define AUDIT_LAST_KERN_ANOM_MSG    1799
+ #define AUDIT_ANOM_PROMISCUOUS      1700 /* Device changed promiscuous mode */
+diff --git a/security/Kconfig b/security/Kconfig
+index bb24477..f3db74c 100644
+--- a/security/Kconfig
++++ b/security/Kconfig
+@@ -136,6 +136,7 @@ config SECURITY_DEFAULT_MMAP_MIN_ADDR
+ source security/selinux/Kconfig
+ source security/smack/Kconfig
+ source security/tomoyo/Kconfig
++source security/apparmor/Kconfig
  
- error:
-       _leave(" = %d", ret);
-       return ret;
- }
+ source security/integrity/ima/Kconfig
+diff --git a/security/Makefile b/security/Makefile
+index fa77021..60aa7c5 100644
+--- a/security/Makefile
++++ b/security/Makefile
+@@ -6,6 +6,7 @@ obj-$(CONFIG_KEYS)                     += keys/
+ subdir-$(CONFIG_SECURITY_SELINUX)     += selinux
+ subdir-$(CONFIG_SECURITY_SMACK)               += smack
+ subdir-$(CONFIG_SECURITY_TOMOYO)        += tomoyo
++subdir-$(CONFIG_SECURITY_APPARMOR)        += apparmor
+ # always enable default capabilities
+ obj-y         += commoncap.o
+@@ -17,6 +18,7 @@ obj-$(CONFIG_SECURITYFS)             += inode.o
+ obj-$(CONFIG_SECURITY_SELINUX)                += selinux/built-in.o
+ obj-$(CONFIG_SECURITY_SMACK)          += smack/built-in.o
+ obj-$(CONFIG_SECURITY_TOMOYO)         += tomoyo/built-in.o
++obj-$(CONFIG_SECURITY_APPARMOR)         += apparmor/built-in.o
+ obj-$(CONFIG_SECURITY_ROOTPLUG)               += root_plug.o
+ obj-$(CONFIG_CGROUP_DEVICE)           += device_cgroup.o
+diff --git a/security/apparmor/Kconfig b/security/apparmor/Kconfig
+new file mode 100644
+index 0000000..0f7ba5e
+--- /dev/null
++++ b/security/apparmor/Kconfig
+@@ -0,0 +1,53 @@
++config SECURITY_APPARMOR
++      bool "AppArmor support"
++      depends on SECURITY && SECURITY_NETWORK && NET && INET
++      select AUDIT
++      select SECURITY_PATH
++      select SECURITYFS
++      default n
++      help
++        This enables the AppArmor security module.
++        Required userspace tools (if they are not included in your
++        distribution) and further information may be found at
++        <http://forge.novell.com/modules/xfmod/project/?apparmor>
 +
-+int afs_setattr(struct dentry *dentry, struct iattr *attr)
-+{
-+      return afs_do_setattr(dentry, attr, NULL);
-+}
++        If you are unsure how to answer this question, answer N.
 +
-+int afs_fsetattr(struct file *file, struct iattr *attr)
-+{
-+      return afs_do_setattr(file->f_path.dentry, attr, file);
-+}
-diff -uprN e/fs/afs/internal.h f/fs/afs/internal.h
---- e/fs/afs/internal.h        2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/afs/internal.h        2008-05-28 20:29:29.410207000 +0000
-@@ -550,6 +550,7 @@ extern void afs_zap_data(struct afs_vnod
- extern int afs_validate(struct afs_vnode *, struct key *);
- extern int afs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
- extern int afs_setattr(struct dentry *, struct iattr *);
-+extern int afs_fsetattr(struct file *, struct iattr *);
- extern void afs_clear_inode(struct inode *);
- /*
-diff -uprN e/fs/attr.c f/fs/attr.c
---- e/fs/attr.c        2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/attr.c        2008-05-28 20:29:29.410207000 +0000
-@@ -100,7 +100,8 @@ int inode_setattr(struct inode * inode, 
- }
- EXPORT_SYMBOL(inode_setattr);
--int notify_change(struct dentry * dentry, struct iattr * attr)
-+int fnotify_change(struct dentry *dentry, struct vfsmount *mnt,
-+                 struct iattr *attr, struct file *file)
- {
-       struct inode *inode = dentry->d_inode;
-       mode_t mode = inode->i_mode;
-@@ -158,13 +159,17 @@ int notify_change(struct dentry * dentry
-               down_write(&dentry->d_inode->i_alloc_sem);
-       if (inode->i_op && inode->i_op->setattr) {
--              error = security_inode_setattr(dentry, attr);
--              if (!error)
--                      error = inode->i_op->setattr(dentry, attr);
-+              error = security_inode_setattr(dentry, mnt, attr);
-+              if (!error) {
-+                      if (file && file->f_op && file->f_op->fsetattr)
-+                              error = file->f_op->fsetattr(file, attr);
-+                      else
-+                              error = inode->i_op->setattr(dentry, attr);
-+              }
-       } else {
-               error = inode_change_ok(inode, attr);
-               if (!error)
--                      error = security_inode_setattr(dentry, attr);
-+                      error = security_inode_setattr(dentry, mnt, attr);
-               if (!error) {
-                       if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
-                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
-@@ -182,5 +187,12 @@ int notify_change(struct dentry * dentry
-       return error;
- }
-+EXPORT_SYMBOL_GPL(fnotify_change);
++config SECURITY_APPARMOR_NETWORK
++       bool "AppArmor network support"
++       depends on SECURITY_APPARMOR
++       default n
++       help
++       This enables AppArmor to mediate applications network use.
++       This will enable the SECURITY_NETWORK hooks.
++
++config SECURITY_APPARMOR_BOOTPARAM_VALUE
++      int "AppArmor boot parameter default value"
++      depends on SECURITY_APPARMOR
++      range 0 1
++      default 1
++      help
++        This option sets the default value for the kernel parameter
++        'apparmor', which allows AppArmor to be enabled or disabled
++          at boot.  If this option is set to 0 (zero), the AppArmor
++        kernel parameter will default to 0, disabling AppArmor at
++        bootup.  If this option is set to 1 (one), the AppArmor
++        kernel parameter will default to 1, enabling AppArmor at
++        bootup.
++
++        If you are unsure how to answer this question, answer 1.
++
++config SECURITY_APPARMOR_DISABLE
++      bool "AppArmor runtime disable"
++      depends on SECURITY_APPARMOR
++      default n
++      help
++        This option enables writing to a apparmorfs node 'disable', which
++        allows AppArmor to be disabled at runtime prior to the policy load.
++        AppArmor will then remain disabled until the next boot.
++        This option is similar to the apparmor.enabled=0 boot parameter,
++        but is to support runtime disabling of AppArmor, e.g. from
++        /sbin/init, for portability across platforms where boot
++        parameters are difficult to employ.
++
++        If you are unsure how to answer this question, answer N.
+diff --git a/security/apparmor/Makefile b/security/apparmor/Makefile
+new file mode 100644
+index 0000000..6e186ce
+--- /dev/null
++++ b/security/apparmor/Makefile
+@@ -0,0 +1,24 @@
++# Makefile for AppArmor Linux Security Module
++#
++obj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o
++
++apparmor-y := apparmorfs.o audit.o capability.o context.o ipc.o lib.o match.o \
++              path.o domain.o policy.o policy_interface.o procattr.o lsm.o \
++              resource.o sid.o file.o
++
++apparmor-$(CONFIG_SECURITY_APPARMOR_NETWORK) += net.o
++
++clean-files: capability_names.h af_names.h
++
++quiet_cmd_make-caps = GEN     $@
++cmd_make-caps = echo "static const char *capability_names[] = {" > $@ ; sed -n -e "/CAP_FS_MASK/d" -e "s/^\#define[ \\t]\\+CAP_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\$$/[\\2]  = \"\\1\",/p" $< | tr A-Z a-z >> $@ ; echo "};" >> $@
++
++quiet_cmd_make-af = GEN     $@
++cmd_make-af = echo "static const char *address_family_names[] = {" > $@ ; sed -n -e "/AF_MAX/d" -e "/AF_LOCAL/d" -e "s/^\#define[ \\t]\\+AF_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\\(.*\\)\$$/[\\2]  = \"\\1\",/p" $< | tr A-Z a-z >> $@ ; echo "};" >> $@
++
++$(obj)/capability.o : $(obj)/capability_names.h
++$(obj)/net.o : $(obj)/af_names.h
++$(obj)/capability_names.h : $(srctree)/include/linux/capability.h
++      $(call cmd,make-caps)
++$(obj)/af_names.h : $(srctree)/include/linux/socket.h
++      $(call cmd,make-af)
+diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
+new file mode 100644
+index 0000000..02ba36f
+--- /dev/null
++++ b/security/apparmor/apparmorfs.c
+@@ -0,0 +1,395 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor /proc/<pid>/attr interface functions
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
++
++#include <linux/security.h>
++#include <linux/vmalloc.h>
++#include <linux/module.h>
++#include <linux/seq_file.h>
++#include <linux/uaccess.h>
++#include <linux/namei.h>
 +
-+int notify_change(struct dentry *dentry, struct vfsmount *mnt,
-+                struct iattr *attr)
++#include "include/apparmor.h"
++#include "include/audit.h"
++#include "include/context.h"
++#include "include/policy.h"
++#include "include/policy_interface.h"
++
++static char *aa_simple_write_to_buffer(const char __user *userbuf,
++                                     size_t alloc_size, size_t copy_size,
++                                     loff_t *pos, const char *operation)
 +{
-+      return fnotify_change(dentry, mnt, attr, NULL);
-+}
- EXPORT_SYMBOL(notify_change);
-diff -uprN e/fs/dcache.c f/fs/dcache.c
---- e/fs/dcache.c      2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/dcache.c      2008-05-28 20:29:29.410207000 +0000
-@@ -1747,86 +1747,118 @@ shouldnt_be_hashed:
- }
- /**
-- * d_path - return the path of a dentry
-+ * __d_path - return the path of a dentry
-  * @dentry: dentry to report
-  * @vfsmnt: vfsmnt to which the dentry belongs
-  * @root: root dentry
-  * @rootmnt: vfsmnt to which the root dentry belongs
-  * @buffer: buffer to return value in
-  * @buflen: buffer length
-+ * @fail_deleted: what to return for deleted files
-+ * @disconnect: don't return a path starting with / when disconnected
-  *
-- * Convert a dentry into an ASCII path name. If the entry has been deleted
-+ * Convert a dentry into an ASCII path name. If the entry has been deleted,
-+ * then if @fail_deleted is true, ERR_PTR(-ENOENT) is returned. Otherwise,
-  * the string " (deleted)" is appended. Note that this is ambiguous.
-  *
-  * Returns the buffer or an error code if the path was too long.
-+ * If @dentry is not connected to @root, the path returned will be relative
-+ * (i.e., it will not start with a slash).
-  *
-- * "buflen" should be positive. Caller holds the dcache_lock.
-+ * Returns the buffer or an error code.
-  */
--static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
--                     struct path *root, char *buffer, int buflen)
-+char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
-+             struct path *root, char *buffer, int buflen,
-+             int fail_deleted, int disconnect)
- {
--      char * end = buffer+buflen;
--      char * retval;
--      int namelen;
-+      int namelen, vfsmount_locked = 0;
-+      const unsigned char *name;
-+
-+      if (buflen < 2)
-+              return ERR_PTR(-ENAMETOOLONG);
-+      buffer += --buflen;
-+      *buffer = '\0';
--      *--end = '\0';
--      buflen--;
-+      spin_lock(&dcache_lock);
-       if (!IS_ROOT(dentry) && d_unhashed(dentry)) {
--              buflen -= 10;
--              end -= 10;
--              if (buflen < 0)
-+              if (fail_deleted) {
-+                      buffer = ERR_PTR(-ENOENT);
-+                      goto out;
-+              }
-+              if (buflen < 10)
-                       goto Elong;
--              memcpy(end, " (deleted)", 10);
-+              buflen -= 10;
-+              buffer -= 10;
-+              memcpy(buffer, " (deleted)", 10);
-       }
--      if (buflen < 1)
--              goto Elong;
--      /* Get '/' right */
--      retval = end-1;
--      *retval = '/';
--
--      for (;;) {
-+      while (dentry != root->dentry || vfsmnt != root->mnt) {
-               struct dentry * parent;
--              if (dentry == root->dentry && vfsmnt == root->mnt)
--                      break;
-               if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
--                      /* Global root? */
--                      spin_lock(&vfsmount_lock);
--                      if (vfsmnt->mnt_parent == vfsmnt) {
--                              spin_unlock(&vfsmount_lock);
--                              goto global_root;
-+                      if (!vfsmount_locked) {
-+                              spin_lock(&vfsmount_lock);
-+                              vfsmount_locked = 1;
-                       }
-+                      if (vfsmnt->mnt_parent == vfsmnt)
-+                              goto global_root;
-                       dentry = vfsmnt->mnt_mountpoint;
-                       vfsmnt = vfsmnt->mnt_parent;
--                      spin_unlock(&vfsmount_lock);
-                       continue;
-               }
-               parent = dentry->d_parent;
-               prefetch(parent);
-               namelen = dentry->d_name.len;
--              buflen -= namelen + 1;
--              if (buflen < 0)
-+              if (buflen < namelen + 1)
-                       goto Elong;
--              end -= namelen;
--              memcpy(end, dentry->d_name.name, namelen);
--              *--end = '/';
--              retval = end;
-+              buflen -= namelen + 1;
-+              buffer -= namelen;
-+              memcpy(buffer, dentry->d_name.name, namelen);
-+              *--buffer = '/';
-               dentry = parent;
-       }
-+      /* Get '/' right. */
-+      if (*buffer != '/')
-+              *--buffer = '/';
--      return retval;
-+out:
-+      if (vfsmount_locked)
-+              spin_unlock(&vfsmount_lock);
-+      spin_unlock(&dcache_lock);
-+      return buffer;
- global_root:
-+      /*
-+       * We went past the (vfsmount, dentry) we were looking for and have
-+       * either hit a root dentry, a lazily unmounted dentry, an
-+       * unconnected dentry, or the file is on a pseudo filesystem.
-+       */
-       namelen = dentry->d_name.len;
--      buflen -= namelen;
--      if (buflen < 0)
-+      name = dentry->d_name.name;
++      const struct cred *cred;
++      struct aa_profile *profile;
++      char *data;
++
++      if (*pos != 0) {
++              /* only writes from pos 0, that is complete writes */
++              data = ERR_PTR(-ESPIPE);
++              goto out;
++      }
 +
 +      /*
-+       * If this is a root dentry, then overwrite the slash.  This
-+       * will also DTRT with pseudo filesystems which have root
-+       * dentries named "foo:".
++       * Don't allow confined processes to load/replace/remove profiles.
++       * No sane person would add rules allowing this to a profile
++       * but we enforce the restriction anyways.
 +       */
-+      if (IS_ROOT(dentry)) {
-+              buffer++;
-+              buflen++;
-+      }
-+      if (disconnect && *name == '/') {
-+          /* Make sure we won't return a pathname starting with '/' */
-+              name++;
-+              namelen--;
-+      }
-+      if (buflen < namelen)
-               goto Elong;
--      retval -= namelen-1;    /* hit the slash */
--      memcpy(retval, dentry->d_name.name, namelen);
--      return retval;
-+      buffer -= namelen;
-+      memcpy(buffer, dentry->d_name.name, namelen);
-+      goto out;
-+
- Elong:
--      return ERR_PTR(-ENAMETOOLONG);
-+      buffer = ERR_PTR(-ENAMETOOLONG);
-+      goto out;
- }
- /**
-@@ -1861,9 +1893,7 @@ char *d_path(struct path *path, char *bu
-       root = current->fs->root;
-       path_get(&current->fs->root);
-       read_unlock(&current->fs->lock);
--      spin_lock(&dcache_lock);
--      res = __d_path(path->dentry, path->mnt, &root, buf, buflen);
--      spin_unlock(&dcache_lock);
-+      res = __d_path(path->dentry, path->mnt, &root, buf, buflen, 0, 0);
-       path_put(&root);
-       return res;
- }
-@@ -1909,9 +1939,9 @@ char *dynamic_dname(struct dentry *dentr
-  */
- asmlinkage long sys_getcwd(char __user *buf, unsigned long size)
- {
--      int error;
-+      int error, len;
-       struct path pwd, root;
--      char *page = (char *) __get_free_page(GFP_USER);
-+      char *page = (char *) __get_free_page(GFP_USER), *cwd;
-       if (!page)
-               return -ENOMEM;
-@@ -1923,29 +1953,18 @@ asmlinkage long sys_getcwd(char __user *
-       path_get(&current->fs->root);
-       read_unlock(&current->fs->lock);
--      error = -ENOENT;
--      /* Has the current directory has been unlinked? */
--      spin_lock(&dcache_lock);
--      if (pwd.dentry->d_parent == pwd.dentry || !d_unhashed(pwd.dentry)) {
--              unsigned long len;
--              char * cwd;
--
--              cwd = __d_path(pwd.dentry, pwd.mnt, &root, page, PAGE_SIZE);
--              spin_unlock(&dcache_lock);
--
--              error = PTR_ERR(cwd);
--              if (IS_ERR(cwd))
--                      goto out;
--
--              error = -ERANGE;
--              len = PAGE_SIZE + page - cwd;
--              if (len <= size) {
--                      error = len;
--                      if (copy_to_user(buf, cwd, len))
--                              error = -EFAULT;
--              }
--      } else
--              spin_unlock(&dcache_lock);
-+      cwd = __d_path(pwd.dentry, pwd.mnt, &root, page, PAGE_SIZE, 1, 0);
-+      error = PTR_ERR(cwd);
-+      if (IS_ERR(cwd))
++      cred = aa_current_policy(&profile);
++      if (profile) {
++              struct aa_audit sa;
++              memset(&sa, 0, sizeof(sa));
++              sa.operation = operation;
++              sa.gfp_mask = GFP_KERNEL;
++              sa.error = -EACCES;
++              data = ERR_PTR(aa_audit(AUDIT_APPARMOR_DENIED, profile, &sa,
++                                      NULL));
 +              goto out;
++      }
 +
-+      error = -ERANGE;
-+      len = PAGE_SIZE + page - cwd;
-+      if (len <= size) {
-+              error = len;
-+              if (copy_to_user(buf, cwd, len))
-+                      error = -EFAULT;
++      data = vmalloc(alloc_size);
++      if (data == NULL) {
++              data = ERR_PTR(-ENOMEM);
++              goto out;
 +      }
- out:
-       path_put(&pwd);
-diff -uprN e/fs/ecryptfs/inode.c f/fs/ecryptfs/inode.c
---- e/fs/ecryptfs/inode.c      2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/ecryptfs/inode.c      2008-05-28 20:29:28.910241000 +0000
-@@ -388,19 +388,24 @@ static int ecryptfs_link(struct dentry *
-                        struct dentry *new_dentry)
- {
-       struct dentry *lower_old_dentry;
-+      struct vfsmount *lower_old_mnt;
-       struct dentry *lower_new_dentry;
-+      struct vfsmount *lower_new_mnt;
-       struct dentry *lower_dir_dentry;
-       u64 file_size_save;
-       int rc;
-       file_size_save = i_size_read(old_dentry->d_inode);
-       lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
-+      lower_old_mnt = ecryptfs_dentry_to_lower_mnt(old_dentry);
-       lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
-+      lower_new_mnt = ecryptfs_dentry_to_lower_mnt(new_dentry);
-       dget(lower_old_dentry);
-       dget(lower_new_dentry);
-       lower_dir_dentry = lock_parent(lower_new_dentry);
--      rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
--                    lower_new_dentry, NULL);
-+      rc = vfs_link(lower_old_dentry, lower_old_mnt,
-+                    lower_dir_dentry->d_inode, lower_new_dentry,
-+                    lower_new_mnt, NULL);
-       if (rc || !lower_new_dentry->d_inode)
-               goto out_lock;
-       rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0);
-@@ -425,10 +430,11 @@ static int ecryptfs_unlink(struct inode 
-       int rc = 0;
-       struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
-+      struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
-       struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
-       struct dentry *lower_dir_dentry;
-       lower_dir_dentry = lock_parent(lower_dentry);
--      rc = vfs_unlink(lower_dir_inode, lower_dentry, NULL);
-+      rc = vfs_unlink(lower_dir_inode, lower_dentry, NULL, lower_mnt);
-       if (rc) {
-               printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
-               goto out_unlock;
-@@ -448,6 +454,7 @@ static int ecryptfs_symlink(struct inode
- {
-       int rc;
-       struct dentry *lower_dentry;
-+      struct vfsmount *lower_mnt;
-       struct dentry *lower_dir_dentry;
-       umode_t mode;
-       char *encoded_symname;
-@@ -456,6 +463,7 @@ static int ecryptfs_symlink(struct inode
-       lower_dentry = ecryptfs_dentry_to_lower(dentry);
-       dget(lower_dentry);
-+      lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
-       lower_dir_dentry = lock_parent(lower_dentry);
-       mode = S_IALLUGO;
-       encoded_symlen = ecryptfs_encode_filename(crypt_stat, symname,
-@@ -465,7 +473,7 @@ static int ecryptfs_symlink(struct inode
-               rc = encoded_symlen;
-               goto out_lock;
-       }
--      rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
-+      rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry, lower_mnt,
-                        encoded_symname, mode, NULL);
-       kfree(encoded_symname);
-       if (rc || !lower_dentry->d_inode)
-@@ -487,11 +495,14 @@ static int ecryptfs_mkdir(struct inode *
- {
-       int rc;
-       struct dentry *lower_dentry;
-+      struct vfsmount *lower_mnt;
-       struct dentry *lower_dir_dentry;
-       lower_dentry = ecryptfs_dentry_to_lower(dentry);
-+      lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
-       lower_dir_dentry = lock_parent(lower_dentry);
--      rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode, NULL);
-+      rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, lower_mnt,
-+                     mode, NULL);
-       if (rc || !lower_dentry->d_inode)
-               goto out;
-       rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
-@@ -510,14 +521,16 @@ out:
- static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
- {
-       struct dentry *lower_dentry;
-+      struct vfsmount *lower_mnt;
-       struct dentry *lower_dir_dentry;
-       int rc;
-       lower_dentry = ecryptfs_dentry_to_lower(dentry);
-+      lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
-       dget(dentry);
-       lower_dir_dentry = lock_parent(lower_dentry);
-       dget(lower_dentry);
--      rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry, NULL);
-+      rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry, NULL, lower_mnt);
-       dput(lower_dentry);
-       if (!rc)
-               d_delete(lower_dentry);
-@@ -535,11 +548,14 @@ ecryptfs_mknod(struct inode *dir, struct
- {
-       int rc;
-       struct dentry *lower_dentry;
-+      struct vfsmount *lower_mnt;
-       struct dentry *lower_dir_dentry;
-       lower_dentry = ecryptfs_dentry_to_lower(dentry);
-+      lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
-       lower_dir_dentry = lock_parent(lower_dentry);
--      rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev, NULL);
-+      rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, lower_mnt, mode,
-+                     dev, NULL);
-       if (rc || !lower_dentry->d_inode)
-               goto out;
-       rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
-@@ -560,19 +576,24 @@ ecryptfs_rename(struct inode *old_dir, s
- {
-       int rc;
-       struct dentry *lower_old_dentry;
-+      struct vfsmount *lower_old_mnt;
-       struct dentry *lower_new_dentry;
-+      struct vfsmount *lower_new_mnt;
-       struct dentry *lower_old_dir_dentry;
-       struct dentry *lower_new_dir_dentry;
-       lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
-+      lower_old_mnt = ecryptfs_dentry_to_lower_mnt(old_dentry);
-       lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
-+      lower_new_mnt = ecryptfs_dentry_to_lower_mnt(new_dentry);
-       dget(lower_old_dentry);
-       dget(lower_new_dentry);
-       lower_old_dir_dentry = dget_parent(lower_old_dentry);
-       lower_new_dir_dentry = dget_parent(lower_new_dentry);
-       lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
-       rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry,
--                      lower_new_dir_dentry->d_inode, lower_new_dentry);
-+                      lower_old_mnt, lower_new_dir_dentry->d_inode,
-+                      lower_new_dentry, lower_new_mnt);
-       if (rc)
-               goto out_lock;
-       fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode, NULL);
-@@ -848,6 +869,7 @@ static int ecryptfs_setattr(struct dentr
- {
-       int rc = 0;
-       struct dentry *lower_dentry;
-+      struct vfsmount *lower_mnt;
-       struct inode *inode;
-       struct inode *lower_inode;
-       struct ecryptfs_crypt_stat *crypt_stat;
-@@ -858,6 +880,7 @@ static int ecryptfs_setattr(struct dentr
-       inode = dentry->d_inode;
-       lower_inode = ecryptfs_inode_to_lower(inode);
-       lower_dentry = ecryptfs_dentry_to_lower(dentry);
-+      lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
-       mutex_lock(&crypt_stat->cs_mutex);
-       if (S_ISDIR(dentry->d_inode->i_mode))
-               crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
-@@ -927,7 +927,7 @@
-               ia->ia_valid &= ~ATTR_MODE;
-       mutex_lock(&lower_dentry->d_inode->i_mutex);
--      rc = notify_change(lower_dentry, ia);
-+      rc = notify_change(lower_dentry, lower_mnt, ia);
-       mutex_unlock(&lower_dentry->d_inode->i_mutex);
- out:
-       fsstack_copy_attr_all(inode, lower_inode);
-diff -uprN e/fs/exec.c f/fs/exec.c
---- e/fs/exec.c        2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/exec.c        2008-05-28 20:29:28.910241000 +0000
-@@ -1777,7 +1777,8 @@ int do_coredump(long signr, int exit_cod
-               goto close_fail;
-       if (!file->f_op->write)
-               goto close_fail;
--      if (!ispipe && do_truncate(file->f_path.dentry, 0, 0, file) != 0)
-+      if (!ispipe &&
-+          do_truncate(file->f_path.dentry, file->f_path.mnt, 0, 0, file) != 0)
-               goto close_fail;
-       retval = binfmt->core_dump(signr, regs, file, core_limit);
-diff -uprN e/fs/fat/file.c f/fs/fat/file.c
---- e/fs/fat/file.c    2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/fat/file.c    2008-05-28 20:29:28.910241000 +0000
-@@ -92,7 +92,7 @@ int fat_generic_ioctl(struct inode *inod
-               }
-               /* This MUST be done before doing anything irreversible... */
--              err = notify_change(filp->f_path.dentry, &ia);
-+              err = notify_change(filp->f_path.dentry, filp->f_path.mnt, &ia);
-               if (err)
-                       goto up;
-diff -uprN e/fs/fuse/dir.c f/fs/fuse/dir.c
---- e/fs/fuse/dir.c    2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/fuse/dir.c    2008-05-28 20:29:29.410207000 +0000
-@@ -1064,21 +1064,22 @@ static int fuse_dir_fsync(struct file *f
-       return file ? fuse_fsync_common(file, de, datasync, 1) : 0;
- }
--static bool update_mtime(unsigned ivalid)
-+static bool update_mtime(unsigned ivalid, bool have_file)
- {
-       /* Always update if mtime is explicitly set  */
-       if (ivalid & ATTR_MTIME_SET)
-               return true;
-       /* If it's an open(O_TRUNC) or an ftruncate(), don't update */
--      if ((ivalid & ATTR_SIZE) && (ivalid & (ATTR_OPEN | ATTR_FILE)))
-+      if ((ivalid & ATTR_SIZE) && ((ivalid & ATTR_OPEN) || have_file))
-               return false;
-       /* In all other cases update */
-       return true;
- }
--static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
-+static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg,
-+                         bool have_file)
- {
-       unsigned ivalid = iattr->ia_valid;
-@@ -1097,7 +1098,7 @@ static void iattr_to_fattr(struct iattr 
-               if (!(ivalid & ATTR_ATIME_SET))
-                       arg->valid |= FATTR_ATIME_NOW;
-       }
--      if ((ivalid & ATTR_MTIME) && update_mtime(ivalid)) {
-+      if ((ivalid & ATTR_MTIME) && update_mtime(ivalid, have_file)) {
-               arg->valid |= FATTR_MTIME;
-               arg->mtime = iattr->ia_mtime.tv_sec;
-               arg->mtimensec = iattr->ia_mtime.tv_nsec;
-@@ -1114,8 +1115,8 @@ static void iattr_to_fattr(struct iattr 
-  * vmtruncate() doesn't allow for this case, so do the rlimit checking
-  * and the actual truncation by hand.
-  */
--static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
--                         struct file *file)
-+int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
-+                  struct file *file)
- {
-       struct inode *inode = entry->d_inode;
-       struct fuse_conn *fc = get_fuse_conn(inode);
-@@ -1153,7 +1154,7 @@ static int fuse_do_setattr(struct dentry
-       memset(&inarg, 0, sizeof(inarg));
-       memset(&outarg, 0, sizeof(outarg));
--      iattr_to_fattr(attr, &inarg);
-+      iattr_to_fattr(attr, &inarg, file != NULL);
-       if (file) {
-               struct fuse_file *ff = file->private_data;
-               inarg.valid |= FATTR_FH;
-@@ -1195,10 +1196,7 @@ static int fuse_do_setattr(struct dentry
- static int fuse_setattr(struct dentry *entry, struct iattr *attr)
- {
--      if (attr->ia_valid & ATTR_FILE)
--              return fuse_do_setattr(entry, attr, attr->ia_file);
--      else
--              return fuse_do_setattr(entry, attr, NULL);
-+      return fuse_do_setattr(entry, attr, NULL);
- }
- static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
-diff -uprN e/fs/fuse/file.c f/fs/fuse/file.c
---- e/fs/fuse/file.c   2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/fuse/file.c   2008-05-28 20:29:29.410207000 +0000
-@@ -909,6 +909,11 @@ static sector_t fuse_bmap(struct address
-       return err ? 0 : outarg.block;
- }
-+static int fuse_fsetattr(struct file *file, struct iattr *attr)
-+{
-+      return fuse_do_setattr(file->f_path.dentry, attr, file);
++
++      if (copy_from_user(data, userbuf, copy_size)) {
++              vfree(data);
++              data = ERR_PTR(-EFAULT);
++              goto out;
++      }
++
++out:
++      return data;
 +}
 +
- static const struct file_operations fuse_file_operations = {
-       .llseek         = generic_file_llseek,
-       .read           = do_sync_read,
-@@ -922,6 +927,7 @@ static const struct file_operations fuse
-       .fsync          = fuse_fsync,
-       .lock           = fuse_file_lock,
-       .flock          = fuse_file_flock,
-+      .fsetattr       = fuse_fsetattr,
-       .splice_read    = generic_file_splice_read,
- };
-@@ -935,6 +941,7 @@ static const struct file_operations fuse
-       .fsync          = fuse_fsync,
-       .lock           = fuse_file_lock,
-       .flock          = fuse_file_flock,
-+      .fsetattr       = fuse_fsetattr,
-       /* no mmap and splice_read */
- };
-diff -uprN e/fs/fuse/fuse_i.h f/fs/fuse/fuse_i.h
---- e/fs/fuse/fuse_i.h 2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/fuse/fuse_i.h 2008-05-28 20:29:29.410207000 +0000
-@@ -509,6 +509,10 @@ void fuse_change_attributes(struct inode
-  */
- int fuse_dev_init(void);
++static struct aa_profile *next_profile(struct aa_profile *profile)
++{
++      struct aa_profile *next = profile;
++      struct aa_namespace *ns;
 +
-+int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
-+                  struct file *file);
-+
- /**
-  * Cleanup the client device
-  */
-diff -uprN e/fs/hpfs/namei.c f/fs/hpfs/namei.c
---- e/fs/hpfs/namei.c  2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/hpfs/namei.c  2008-05-28 20:29:28.910241000 +0000
-@@ -426,7 +426,7 @@ again:
-                       /*printk("HPFS: truncating file before delete.\n");*/
-                       newattrs.ia_size = 0;
-                       newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
--                      err = notify_change(dentry, &newattrs);
-+                      err = notify_change(dentry, NULL, &newattrs);
-                       put_write_access(inode);
-                       if (!err)
-                               goto again;
-diff -uprN e/fs/namei.c f/fs/namei.c
---- e/fs/namei.c       2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/namei.c       2008-05-28 20:29:29.410207000 +0000
-@@ -313,7 +313,12 @@ int vfs_permission(struct nameidata *nd,
-  */
- int file_permission(struct file *file, int mask)
- {
--      return permission(file->f_path.dentry->d_inode, mask, NULL);
-+      struct nameidata nd;
-+
-+      nd.path = file->f_path;
-+      nd.flags = LOOKUP_ACCESS;
-+
-+      return permission(nd.path.dentry->d_inode, mask, &nd);
- }
- /*
-@@ -1150,24 +1155,21 @@ static int do_path_lookup(int dfd, const
-               path_get(&fs->pwd);
-               read_unlock(&fs->lock);
-       } else {
--              struct dentry *dentry;
--
-               file = fget_light(dfd, &fput_needed);
-               retval = -EBADF;
-               if (!file)
-                       goto out_fail;
--              dentry = file->f_path.dentry;
-+              nd->path = file->f_path;
-               retval = -ENOTDIR;
--              if (!S_ISDIR(dentry->d_inode->i_mode))
-+              if (!S_ISDIR(nd->path.dentry->d_inode->i_mode))
-                       goto fput_fail;
-               retval = file_permission(file, MAY_EXEC);
-               if (retval)
-                       goto fput_fail;
--              nd->path = file->f_path;
-               path_get(&file->f_path);
-               fput_light(file, fput_needed);
-@@ -1511,6 +1513,8 @@ static inline int may_create(struct inod
-               return -EEXIST;
-       if (IS_DEADDIR(dir))
-               return -ENOENT;
-+      if (nd)
-+              nd->flags |= LOOKUP_CONTINUE;
-       return permission(dir,MAY_WRITE | MAY_EXEC, nd);
- }
-@@ -1586,7 +1590,7 @@ int vfs_create(struct inode *dir, struct
-               return -EACCES; /* shouldn't it be ENOSYS? */
-       mode &= S_IALLUGO;
-       mode |= S_IFREG;
--      error = security_inode_create(dir, dentry, mode);
-+      error = security_inode_create(dir, dentry, nd ? nd->path.mnt : NULL, mode);
-       if (error)
-               return error;
-       DQUOT_INIT(dir);
-@@ -1663,7 +1667,7 @@ int may_open(struct nameidata *nd, int a
-               if (!error) {
-                       DQUOT_INIT(inode);
--                      error = do_truncate(dentry, 0,
-+                      error = do_truncate(dentry, nd->path.mnt, 0,
-                                           ATTR_MTIME|ATTR_CTIME|ATTR_OPEN,
-                                           NULL);
-               }
-@@ -1921,8 +1925,8 @@ fail:
- }
- EXPORT_SYMBOL_GPL(lookup_create);
--int vfs_mknod(struct inode *dir, struct dentry *dentry,
--      int mode, dev_t dev, struct nameidata *nd)
-+int vfs_mknod(struct inode *dir, struct dentry *dentry, struct vfsmount *mnt,
-+      int mode, dev_t dev, struct nameidata *nd)
- {
-       int error = may_create(dir, dentry, NULL);
-@@ -1934,7 +1939,7 @@ int vfs_mknod(struct inode *dir, struct 
-       if (!dir->i_op || !dir->i_op->mknod)
-               return -EPERM;
--      error = security_inode_mknod(dir, dentry, mode, dev);
-+      error = security_inode_mknod(dir, dentry, mnt, mode, dev);
-       if (error)
-               return error;
-@@ -1973,12 +1978,12 @@ asmlinkage long sys_mknodat(int dfd, con
-                       error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
-                       break;
-               case S_IFCHR: case S_IFBLK:
--                      error = vfs_mknod(nd.path.dentry->d_inode, dentry, mode,
--                                      new_decode_dev(dev), &nd);
-+                      error = vfs_mknod(nd.path.dentry->d_inode, dentry,
-+                                        nd.path.mnt, mode, new_decode_dev(dev), &nd);
-                       break;
-               case S_IFIFO: case S_IFSOCK:
--                      error = vfs_mknod(nd.path.dentry->d_inode, dentry, mode,
--                                      0, &nd);
-+                      error = vfs_mknod(nd.path.dentry->d_inode, dentry,
-+                                        nd.path.mnt, mode, 0, &nd);
-                       break;
-               case S_IFDIR:
-                       error = -EPERM;
-@@ -2000,8 +2006,8 @@ asmlinkage long sys_mknod(const char __u
-       return sys_mknodat(AT_FDCWD, filename, mode, dev);
- }
--int vfs_mkdir(struct inode *dir, struct dentry *dentry,
--      int mode, struct nameidata *nd)
-+int vfs_mkdir(struct inode *dir, struct dentry *dentry, struct vfsmount *mnt,
-+            int mode, struct nameidata *nd)
- {
-       int error = may_create(dir, dentry, nd);
-@@ -2011,7 +2018,7 @@ int vfs_mkdir(struct inode *dir, struct 
-               return -EPERM;
-       mode &= (S_IRWXUGO|S_ISVTX);
--      error = security_inode_mkdir(dir, dentry, mode);
-+      error = security_inode_mkdir(dir, dentry, mnt, mode);
-       if (error)
-               return error;
-@@ -2044,7 +2051,7 @@ asmlinkage long sys_mkdirat(int dfd, con
-       if (!IS_POSIXACL(nd.path.dentry->d_inode))
-               mode &= ~current->fs->umask;
--      error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode, &nd);
-+      error = vfs_mkdir(nd.path.dentry->d_inode, dentry, nd.path.mnt, mode, &nd);
-       dput(dentry);
- out_unlock:
-       mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
-@@ -2087,8 +2094,8 @@ void dentry_unhash(struct dentry *dentry
-       spin_unlock(&dcache_lock);
- }
--int vfs_rmdir(struct inode *dir, struct dentry *dentry,
--      struct nameidata *nd)
-+int vfs_rmdir(struct inode *dir, struct dentry *dentry,
-+      struct nameidata *nd, struct vfsmount *mnt)
- {
-       int error = may_delete(dir, dentry, 1);
-@@ -2097,6 +2104,10 @@ int vfs_rmdir(struct inode *dir, struct 
-       if (!dir->i_op || !dir->i_op->rmdir)
-               return -EPERM;
-+      error = security_inode_rmdir(dir, dentry, mnt);
-+      if (error)
-+              return error;
++      if (!list_empty(&profile->base.profiles)) {
++              list_for_each_entry(next, &profile->base.profiles, base.list)
++                      return next;
++      }
 +
-       DQUOT_INIT(dir);
-       mutex_lock(&dentry->d_inode->i_mutex);
-@@ -2104,12 +2115,9 @@ int vfs_rmdir(struct inode *dir, struct 
-       if (d_mountpoint(dentry))
-               error = -EBUSY;
-       else {
--              error = security_inode_rmdir(dir, dentry);
--              if (!error) {
--                      error = dir->i_op->rmdir(dir, dentry);
--                      if (!error)
--                              dentry->d_inode->i_flags |= S_DEAD;
--              }
-+              error = dir->i_op->rmdir(dir, dentry);
-+              if (!error)
-+                      dentry->d_inode->i_flags |= S_DEAD;
-       }
-       mutex_unlock(&dentry->d_inode->i_mutex);
-       if (!error) {
-@@ -2151,7 +2159,7 @@ static long do_rmdir(int dfd, const char
-       error = PTR_ERR(dentry);
-       if (IS_ERR(dentry))
-               goto exit2;
--      error = vfs_rmdir(nd.path.dentry->d_inode, dentry, &nd);
-+      error = vfs_rmdir(nd.path.dentry->d_inode, dentry, &nd, nd.path.mnt);
-       dput(dentry);
- exit2:
-       mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
-@@ -2167,8 +2175,8 @@ asmlinkage long sys_rmdir(const char __u
-       return do_rmdir(AT_FDCWD, pathname);
- }
--int vfs_unlink(struct inode *dir, struct dentry *dentry,
--      struct nameidata *nd)
-+int vfs_unlink(struct inode *dir, struct dentry *dentry, 
-+      struct nameidata *nd, struct vfsmount *mnt)
- {
-       int error = may_delete(dir, dentry, 0, nd);
-@@ -2183,7 +2191,7 @@ int vfs_unlink(struct inode *dir, struct
-       if (d_mountpoint(dentry))
-               error = -EBUSY;
-       else {
--              error = security_inode_unlink(dir, dentry);
-+              error = security_inode_unlink(dir, dentry, mnt);
-               if (!error)
-                       error = dir->i_op->unlink(dir, dentry);
-       }
-@@ -2232,7 +2240,7 @@ static long do_unlinkat(int dfd, const c
-               inode = dentry->d_inode;
-               if (inode)
-                       atomic_inc(&inode->i_count);
--              error = vfs_unlink(nd.path.dentry->d_inode, dentry, &nd);
-+              error = vfs_unlink(nd.path.dentry->d_inode, dentry, &nd, nd.path.mnt);
-       exit2:
-               dput(dentry);
-       }
-@@ -2267,7 +2275,7 @@ asmlinkage long sys_unlink(const char __
-       return do_unlinkat(AT_FDCWD, pathname);
- }
--int vfs_symlink(struct inode *dir, struct dentry *dentry,
-+int vfs_symlink(struct inode *dir, struct dentry *dentry, struct vfsmount *mnt,
-       const char *oldname, int mode, struct nameidata *nd)
-       const char *oldname, int mode, struct nameidata *nd)
- {
-@@ -2277,7 +2286,7 @@ int vfs_symlink(struct inode *dir, struc
-       if (!dir->i_op || !dir->i_op->symlink)
-               return -EPERM;
--      error = security_inode_symlink(dir, dentry, oldname);
-+      error = security_inode_symlink(dir, dentry, mnt, oldname);
-       if (error)
-               return error;
-@@ -2313,8 +2322,8 @@ asmlinkage long sys_symlinkat(const char
-       if (IS_ERR(dentry))
-               goto out_unlock;
--      error = vfs_symlink(nd.path.dentry->d_inode, dentry, from,
--              S_IALLUGO, &nd);
-+      error = vfs_symlink(nd.path.dentry->d_inode, dentry, nd.path.mnt, from,
-+                          S_IALLUGO, &nd);
-       dput(dentry);
- out_unlock:
-       mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
-@@ -2330,8 +2340,8 @@ asmlinkage long sys_symlink(const char _
-       return sys_symlinkat(oldname, AT_FDCWD, newname);
- }
--int vfs_link(struct dentry *old_dentry, struct inode *dir,
--      struct dentry *new_dentry, struct nameidata *nd)
-+int vfs_link(struct dentry *old_dentry, struct vfsmount *old_mnt, struct inode *dir,
-+      struct dentry *new_dentry, struct vfsmount *new_mnt, struct nameidata *nd)
- {
-       struct inode *inode = old_dentry->d_inode;
-       int error;
-@@ -2355,7 +2365,8 @@ int vfs_link(struct dentry *old_dentry, 
-       if (S_ISDIR(old_dentry->d_inode->i_mode))
-               return -EPERM;
--      error = security_inode_link(old_dentry, dir, new_dentry);
-+      error = security_inode_link(old_dentry, old_mnt, dir, new_dentry,
-+                                  new_mnt);
-       if (error)
-               return error;
-@@ -2408,8 +2419,8 @@ asmlinkage long sys_linkat(int olddfd, c
-               goto out_unlock_dput;
-       }
--      error = vfs_link(old_nd.path.dentry, nd.path.dentry->d_inode,
--              new_dentry, &nd);
-+      error = vfs_link(old_nd.path.dentry, old_nd.path.mnt, nd.path.dentry->d_inode,
-+                       new_dentry, nd.path.mnt, &nd);
- out_unlock_dput:
-       dput(new_dentry);
- out_unlock:
-@@ -2460,7 +2472,8 @@ asmlinkage long sys_link(const char __us
-  *       locking].
-  */
- static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
--                        struct inode *new_dir, struct dentry *new_dentry)
-+                        struct vfsmount *old_mnt, struct inode *new_dir,
-+                        struct dentry *new_dentry, struct vfsmount *new_mnt)
- {
-       int error = 0;
-       struct inode *target;
-@@ -2475,7 +2488,8 @@ static int vfs_rename_dir(struct inode *
-                       return error;
-       }
--      error = security_inode_rename(old_dir, old_dentry, new_dir, new_dentry);
-+      error = security_inode_rename(old_dir, old_dentry, old_mnt,
-+                                    new_dir, new_dentry, new_mnt);
-       if (error)
-               return error;
-@@ -2503,12 +2517,14 @@ static int vfs_rename_dir(struct inode *
- }
- static int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
--                          struct inode *new_dir, struct dentry *new_dentry)
-+                          struct vfsmount *old_mnt, struct inode *new_dir,
-+                          struct dentry *new_dentry, struct vfsmount *new_mnt)
- {
-       struct inode *target;
-       int error;
--      error = security_inode_rename(old_dir, old_dentry, new_dir, new_dentry);
-+      error = security_inode_rename(old_dir, old_dentry, old_mnt,
-+                                    new_dir, new_dentry, new_mnt);
-       if (error)
-               return error;
-@@ -2531,7 +2547,8 @@ static int vfs_rename_other(struct inode
- }
- int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
--             struct inode *new_dir, struct dentry *new_dentry)
-+              struct vfsmount *old_mnt, struct inode *new_dir,
-+              struct dentry *new_dentry, struct vfsmount *new_mnt)
- {
-       int error;
-       int is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
-@@ -2560,9 +2577,11 @@ int vfs_rename(struct inode *old_dir, st
-       old_name = fsnotify_oldname_init(old_dentry->d_name.name);
-       if (is_dir)
--              error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
-+              error = vfs_rename_dir(old_dir, old_dentry, old_mnt,
-+                                     new_dir, new_dentry, new_mnt);
-       else
--              error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
-+              error = vfs_rename_other(old_dir, old_dentry, old_mnt,
-+                                       new_dir, new_dentry, new_mnt);
-       if (!error) {
-               const char *new_name = old_dentry->d_name.name;
-               fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
-@@ -2634,8 +2653,8 @@ static int do_rename(int olddfd, const c
-       if (new_dentry == trap)
-               goto exit5;
--      error = vfs_rename(old_dir->d_inode, old_dentry,
--                                 new_dir->d_inode, new_dentry);
-+      error = vfs_rename(old_dir->d_inode, old_dentry, oldnd.path.mnt,
-+                         new_dir->d_inode, new_dentry, newnd.path.mnt);
- exit5:
-       dput(new_dentry);
- exit4:
-diff -uprN e/fs/namespace.c f/fs/namespace.c
---- e/fs/namespace.c   2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/namespace.c   2008-05-28 20:29:29.410207000 +0000
-@@ -1852,3 +1852,30 @@ void __put_mnt_ns(struct mnt_namespace *
-       release_mounts(&umount_list);
-       kfree(ns);
- }
-+
-+char *d_namespace_path(struct dentry *dentry, struct vfsmount *vfsmnt,
-+                     char *buf, int buflen)
-+{
-+      struct path root, ns_root = { };
-+      char *res;
++      while (profile->parent) {
++              next = profile->parent;
++              list_for_each_entry_continue(next,
++                                           &profile->parent->base.profiles,
++                                           base.list)
++                      return next;
++              profile = profile->parent;
++      }
 +
-+      read_lock(&current->fs->lock);
-+      root = current->fs->root;
-+      path_get(&current->fs->root);
-+      read_unlock(&current->fs->lock);
-+      spin_lock(&vfsmount_lock);
-+      if (root.mnt)
-+              ns_root.mnt = mntget(root.mnt->mnt_ns->root);
-+      if (ns_root.mnt)
-+              ns_root.dentry = dget(ns_root.mnt->mnt_root);
-+      spin_unlock(&vfsmount_lock);
-+      res = __d_path(dentry, vfsmnt, &ns_root, buf, buflen, 1, 1);
-+      path_put(&root);
-+      path_put(&ns_root);
++      next = profile;
++      list_for_each_entry_continue(next, &profile->ns->base.profiles,
++                                   base.list)
++              return next;
 +
-+      /* Prevent empty path for lazily unmounted filesystems. */
-+      if (!IS_ERR(res) && *res == '\0')
-+              *--res = '.';
-+      return res;
++      ns = profile->ns;
++      read_unlock(&ns->base.lock);
++      list_for_each_entry_continue(ns, &ns_list, base.list) {
++              read_lock(&ns->base.lock);
++              list_for_each_entry(profile, &ns->base.profiles, base.list)
++                      return profile;
++              read_unlock(&ns->base.lock);
++      }
++      return NULL;
 +}
-+EXPORT_SYMBOL(d_namespace_path);
-diff -uprN e/fs/nfsd/nfs4recover.c f/fs/nfsd/nfs4recover.c
---- e/fs/nfsd/nfs4recover.c    2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/nfsd/nfs4recover.c    2008-05-28 20:29:28.910241000 +0000
-@@ -154,7 +154,8 @@ nfsd4_create_clid_dir(struct nfs4_client
-               dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
-               goto out_put;
-       }
--      status = vfs_mkdir(rec_dir.path.dentry->d_inode, dentry, S_IRWXU, NULL);
-+      status = vfs_mkdir(rec_dir.path.dentry->d_inode, dentry,
-+                         rec_dir.path.mnt, S_IRWXU, NULL);
- out_put:
-       dput(dentry);
- out_unlock:
-@@ -258,7 +259,7 @@ nfsd4_remove_clid_file(struct dentry *di
-               return -EINVAL;
-       }
-       mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
--      status = vfs_unlink(dir->d_inode, dentry, NULL);
-+      status = vfs_unlink(dir->d_inode, dentry, NULL, rec_dir.path.mnt);
-       mutex_unlock(&dir->d_inode->i_mutex);
-       return status;
- }
-@@ -273,7 +274,7 @@ nfsd4_clear_clid_dir(struct dentry *dir,
-        * a kernel from the future.... */
-       nfsd4_list_rec_dir(dentry, nfsd4_remove_clid_file);
-       mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
--      status = vfs_rmdir(dir->d_inode, dentry, NULL);
-+      status = vfs_rmdir(dir->d_inode, dentry, NULL, rec_dir.path.mnt);
-       mutex_unlock(&dir->d_inode->i_mutex);
-       return status;
- }
-diff -uprN e/fs/nfsd/nfs4xdr.c f/fs/nfsd/nfs4xdr.c
---- e/fs/nfsd/nfs4xdr.c        2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/nfsd/nfs4xdr.c        2008-05-28 20:29:28.910241000 +0000
-@@ -1501,7 +1501,7 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
-       }
-       if (bmval0 & (FATTR4_WORD0_ACL | FATTR4_WORD0_ACLSUPPORT
-                       | FATTR4_WORD0_SUPPORTED_ATTRS)) {
--              err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl);
-+              err = nfsd4_get_nfs4_acl(rqstp, dentry, exp->ex_path.mnt, &acl);
-               aclsupport = (err == 0);
-               if (bmval0 & FATTR4_WORD0_ACL) {
-                       if (err == -EOPNOTSUPP)
-diff -uprN e/fs/nfsd/vfs.c f/fs/nfsd/vfs.c
---- e/fs/nfsd/vfs.c    2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/nfsd/vfs.c    2008-05-28 20:29:29.410207000 +0000
-@@ -388,7 +388,7 @@ nfsd_setattr(struct svc_rqst *rqstp, str
-       err = nfserr_notsync;
-       if (!check_guard || guardtime == inode->i_ctime.tv_sec) {
-               fh_lock(fhp);
--              host_err = notify_change(dentry, iap);
-+              host_err = notify_change(dentry, fhp->fh_export->ex_path.mnt, iap);
-               err = nfserrno(host_err);
-               fh_unlock(fhp);
-       }
-@@ -408,11 +408,12 @@ out_nfserr:
- #if defined(CONFIG_NFSD_V2_ACL) || \
-     defined(CONFIG_NFSD_V3_ACL) || \
-     defined(CONFIG_NFSD_V4)
--static ssize_t nfsd_getxattr(struct dentry *dentry, char *key, void **buf)
-+static ssize_t nfsd_getxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                           char *key, void **buf)
- {
-       ssize_t buflen;
--      buflen = vfs_getxattr(dentry, key, NULL, 0);
-+      buflen = vfs_getxattr(dentry, mnt, key, NULL, 0, NULL);
-       if (buflen <= 0)
-               return buflen;
-@@ -420,13 +421,14 @@ static ssize_t nfsd_getxattr(struct dent
-       if (!*buf)
-               return -ENOMEM;
--      return vfs_getxattr(dentry, key, *buf, buflen);
-+      return vfs_getxattr(dentry, mnt, key, *buf, buflen, NULL);
- }
- #endif
- #if defined(CONFIG_NFSD_V4)
- static int
--set_nfsv4_acl_one(struct dentry *dentry, struct posix_acl *pacl, char *key)
-+set_nfsv4_acl_one(struct dentry *dentry, struct vfsmount *mnt,
-+                struct posix_acl *pacl, char *key)
- {
-       int len;
-       size_t buflen;
-@@ -445,7 +447,7 @@ set_nfsv4_acl_one(struct dentry *dentry,
-               goto out;
-       }
--      error = vfs_setxattr(dentry, key, buf, len, 0);
-+      error = vfs_setxattr(dentry, mnt, key, buf, len, 0, NULL);
- out:
-       kfree(buf);
-       return error;
-@@ -458,6 +460,7 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqst
-       __be32 error;
-       int host_error;
-       struct dentry *dentry;
-+      struct vfsmount *mnt;
-       struct inode *inode;
-       struct posix_acl *pacl = NULL, *dpacl = NULL;
-       unsigned int flags = 0;
-@@ -468,6 +471,7 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqst
-               return error;
-       dentry = fhp->fh_dentry;
-+      mnt = fhp->fh_export->ex_path.mnt;
-       inode = dentry->d_inode;
-       if (S_ISDIR(inode->i_mode))
-               flags = NFS4_ACL_DIR;
-@@ -478,12 +482,14 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqst
-       } else if (host_error < 0)
-               goto out_nfserr;
--      host_error = set_nfsv4_acl_one(dentry, pacl, POSIX_ACL_XATTR_ACCESS);
-+      host_error = set_nfsv4_acl_one(dentry, mnt, pacl,
-+                                     POSIX_ACL_XATTR_ACCESS);
-       if (host_error < 0)
-               goto out_release;
-       if (S_ISDIR(inode->i_mode))
--              host_error = set_nfsv4_acl_one(dentry, dpacl, POSIX_ACL_XATTR_DEFAULT);
-+              host_error = set_nfsv4_acl_one(dentry, mnt, dpacl,
-+                                             POSIX_ACL_XATTR_DEFAULT);
- out_release:
-       posix_acl_release(pacl);
-@@ -496,13 +502,13 @@ out_nfserr:
- }
- static struct posix_acl *
--_get_posix_acl(struct dentry *dentry, char *key)
-+_get_posix_acl(struct dentry *dentry, struct vfsmount *mnt, char *key)
- {
-       void *buf = NULL;
-       struct posix_acl *pacl = NULL;
-       int buflen;
--      buflen = nfsd_getxattr(dentry, key, &buf);
-+      buflen = nfsd_getxattr(dentry, mnt, key, &buf);
-       if (!buflen)
-               buflen = -ENODATA;
-       if (buflen <= 0)
-@@ -514,14 +520,15 @@ _get_posix_acl(struct dentry *dentry, ch
- }
- int
--nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry, struct nfs4_acl **acl)
-+nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry,
-+                 struct vfsmount *mnt, struct nfs4_acl **acl)
- {
-       struct inode *inode = dentry->d_inode;
-       int error = 0;
-       struct posix_acl *pacl = NULL, *dpacl = NULL;
-       unsigned int flags = 0;
--      pacl = _get_posix_acl(dentry, POSIX_ACL_XATTR_ACCESS);
-+      pacl = _get_posix_acl(dentry, mnt, POSIX_ACL_XATTR_ACCESS);
-       if (IS_ERR(pacl) && PTR_ERR(pacl) == -ENODATA)
-               pacl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
-       if (IS_ERR(pacl)) {
-@@ -531,7 +538,7 @@ nfsd4_get_nfs4_acl(struct svc_rqst *rqst
-       }
-       if (S_ISDIR(inode->i_mode)) {
--              dpacl = _get_posix_acl(dentry, POSIX_ACL_XATTR_DEFAULT);
-+              dpacl = _get_posix_acl(dentry, mnt, POSIX_ACL_XATTR_DEFAULT);
-               if (IS_ERR(dpacl) && PTR_ERR(dpacl) == -ENODATA)
-                       dpacl = NULL;
-               else if (IS_ERR(dpacl)) {
-@@ -944,13 +951,13 @@ out:
-       return err;
- }
--static void kill_suid(struct dentry *dentry)
-+static void kill_suid(struct dentry *dentry, struct vfsmount *mnt)
- {
-       struct iattr    ia;
-       ia.ia_valid = ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_KILL_PRIV;
-       mutex_lock(&dentry->d_inode->i_mutex);
--      notify_change(dentry, &ia);
-+      notify_change(dentry, mnt, &ia);
-       mutex_unlock(&dentry->d_inode->i_mutex);
- }
-@@ -1009,7 +1016,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
-       /* clear setuid/setgid flag after write */
-       if (host_err >= 0 && (inode->i_mode & (S_ISUID | S_ISGID)))
--              kill_suid(dentry);
-+              kill_suid(dentry, exp->ex_path.mnt);
-       if (host_err >= 0 && stable) {
-               static ino_t    last_ino;
-@@ -1186,6 +1193,7 @@ nfsd_create(struct svc_rqst *rqstp, stru
-               int type, dev_t rdev, struct svc_fh *resfhp)
- {
-       struct dentry   *dentry, *dchild = NULL;
-+      struct svc_export *exp;
-       struct inode    *dirp;
-       __be32          err;
-       __be32          err2;
-@@ -1203,6 +1211,7 @@ nfsd_create(struct svc_rqst *rqstp, stru
-               goto out;
-       dentry = fhp->fh_dentry;
-+      exp = fhp->fh_export;
-       dirp = dentry->d_inode;
-       err = nfserr_notdir;
-@@ -1219,7 +1228,7 @@ nfsd_create(struct svc_rqst *rqstp, stru
-               host_err = PTR_ERR(dchild);
-               if (IS_ERR(dchild))
-                       goto out_nfserr;
--              err = fh_compose(resfhp, fhp->fh_export, dchild, fhp);
-+              err = fh_compose(resfhp, exp, dchild, fhp);
-               if (err)
-                       goto out;
-       } else {
-@@ -1258,13 +1267,14 @@ nfsd_create(struct svc_rqst *rqstp, stru
-               host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
-               break;
-       case S_IFDIR:
--              host_err = vfs_mkdir(dirp, dchild, iap->ia_mode, NULL);
-+              host_err = vfs_mkdir(dirp, dchild, exp->ex_path.mnt, iap->ia_mode, NULL);
-               break;
-       case S_IFCHR:
-       case S_IFBLK:
-       case S_IFIFO:
-       case S_IFSOCK:
--              host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev, NULL);
-+              host_err = vfs_mknod(dirp, dchild, exp->ex_path.mnt,
-+                                   iap->ia_mode, rdev, NULL);
-               break;
-       default:
-               printk("nfsd: bad file type %o in nfsd_create\n", type);
-@@ -1273,7 +1283,7 @@ nfsd_create(struct svc_rqst *rqstp, stru
-       if (host_err < 0)
-               goto out_nfserr;
--      if (EX_ISSYNC(fhp->fh_export)) {
-+      if (EX_ISSYNC(exp)) {
-               err = nfserrno(nfsd_sync_dir(dentry));
-               write_inode_now(dchild->d_inode, 1);
-       }
-@@ -1496,6 +1506,7 @@ nfsd_symlink(struct svc_rqst *rqstp, str
-                               struct iattr *iap)
- {
-       struct dentry   *dentry, *dnew;
-+      struct svc_export *exp;
-       __be32          err, cerr;
-       int             host_err;
-       umode_t         mode;
-@@ -1522,6 +1533,7 @@ nfsd_symlink(struct svc_rqst *rqstp, str
-       if (iap && (iap->ia_valid & ATTR_MODE))
-               mode = iap->ia_mode & S_IALLUGO;
-+      exp = fhp->fh_export;
-       if (unlikely(path[plen] != 0)) {
-               char *path_alloced = kmalloc(plen+1, GFP_KERNEL);
-               if (path_alloced == NULL)
-@@ -1529,21 +1541,21 @@ nfsd_symlink(struct svc_rqst *rqstp, str
-                       strncpy(path_alloced, path, plen);
-                       path_alloced[plen] = 0;
-                       host_err = vfs_symlink(dentry->d_inode, dnew,
--                              path_alloced, mode, NULL);
-+                              exp->ex_path.mnt, path_alloced, mode, NULL);
-                       kfree(path_alloced);
-               }
-       } else
--              host_err = vfs_symlink(dentry->d_inode, dnew,
--                      path, mode, NULL);
-+              host_err = vfs_symlink(dentry->d_inode, dnew, exp->ex_path.mnt,
-+                                     path, mode, NULL);
-       if (!host_err) {
--              if (EX_ISSYNC(fhp->fh_export))
-+              if (EX_ISSYNC(exp))
-                       host_err = nfsd_sync_dir(dentry);
-       }
-       err = nfserrno(host_err);
-       fh_unlock(fhp);
--      cerr = fh_compose(resfhp, fhp->fh_export, dnew, fhp);
-+      cerr = fh_compose(resfhp, exp, dnew, fhp);
-       dput(dnew);
-       if (err==0) err = cerr;
- out:
-@@ -1592,7 +1606,8 @@ nfsd_link(struct svc_rqst *rqstp, struct
-       dold = tfhp->fh_dentry;
-       dest = dold->d_inode;
--      host_err = vfs_link(dold, dirp, dnew, NULL);
-+      host_err = vfs_link(dold, tfhp->fh_export->ex_path.mnt, dirp,
-+                          dnew, ffhp->fh_export->ex_path.mnt, NULL);
-       if (!host_err) {
-               if (EX_ISSYNC(ffhp->fh_export)) {
-                       err = nfserrno(nfsd_sync_dir(ddir));
-@@ -1685,7 +1700,8 @@ nfsd_rename(struct svc_rqst *rqstp, stru
-                       host_err = -EPERM;
-       } else
- #endif
--      host_err = vfs_rename(fdir, odentry, tdir, ndentry);
-+      host_err = vfs_rename(fdir, odentry, ffhp->fh_export->ex_path.mnt,
-+                            tdir, ndentry, tfhp->fh_export->ex_path.mnt);
-       if (!host_err && EX_ISSYNC(tfhp->fh_export)) {
-               host_err = nfsd_sync_dir(tdentry);
-               if (!host_err)
-@@ -1721,6 +1737,7 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
-                               char *fname, int flen)
- {
-       struct dentry   *dentry, *rdentry;
-+      struct svc_export *exp;
-       struct inode    *dirp;
-       __be32          err;
-       int             host_err;
-@@ -1735,6 +1752,7 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
-       fh_lock_nested(fhp, I_MUTEX_PARENT);
-       dentry = fhp->fh_dentry;
-       dirp = dentry->d_inode;
-+      exp = fhp->fh_export;
-       rdentry = lookup_one_len(fname, dentry, flen);
-       host_err = PTR_ERR(rdentry);
-@@ -1752,21 +1770,21 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
-       if (type != S_IFDIR) { /* It's UNLINK */
- #ifdef MSNFS
--              if ((fhp->fh_export->ex_flags & NFSEXP_MSNFS) &&
-+              if ((exp->ex_flags & NFSEXP_MSNFS) &&
-                       (atomic_read(&rdentry->d_count) > 1)) {
-                       host_err = -EPERM;
-               } else
- #endif
--              host_err = vfs_unlink(dirp, rdentry, NULL);
-+              host_err = vfs_unlink(dirp, rdentry, NULL, exp->ex_path.mnt);
-       } else { /* It's RMDIR */
--              host_err = vfs_rmdir(dirp, rdentry, NULL);
-+              host_err = vfs_rmdir(dirp, rdentry, NULL, exp->ex_path.mnt);
-       }
-       dput(rdentry);
-       if (host_err)
-               goto out_nfserr;
--      if (EX_ISSYNC(fhp->fh_export))
-+      if (EX_ISSYNC(exp))
-               host_err = nfsd_sync_dir(dentry);
- out_nfserr:
-@@ -1995,7 +2013,8 @@ nfsd_get_posix_acl(struct svc_fh *fhp, i
-               return ERR_PTR(-EOPNOTSUPP);
-       }
--      size = nfsd_getxattr(fhp->fh_dentry, name, &value);
-+      size = nfsd_getxattr(fhp->fh_dentry, fhp->fh_export->ex_path.mnt, name,
-+                           &value);
-       if (size < 0)
-               return ERR_PTR(size);
-@@ -2007,6 +2026,7 @@ nfsd_get_posix_acl(struct svc_fh *fhp, i
- int
- nfsd_set_posix_acl(struct svc_fh *fhp, int type, struct posix_acl *acl)
- {
-+      struct vfsmount *mnt;
-       struct inode *inode = fhp->fh_dentry->d_inode;
-       char *name;
-       void *value = NULL;
-@@ -2039,13 +2059,16 @@ nfsd_set_posix_acl(struct svc_fh *fhp, i
-       } else
-               size = 0;
-+      mnt = fhp->fh_export->ex_path.mnt;
-       if (size)
--              error = vfs_setxattr(fhp->fh_dentry, name, value, size, 0);
-+              error = vfs_setxattr(fhp->fh_dentry, mnt, name, value, size, 0,
-+                                   NULL);
-       else {
-               if (!S_ISDIR(inode->i_mode) && type == ACL_TYPE_DEFAULT)
-                       error = 0;
-               else {
--                      error = vfs_removexattr(fhp->fh_dentry, name);
-+                      error = vfs_removexattr(fhp->fh_dentry, mnt, name,
-+                                              NULL);
-                       if (error == -ENODATA)
-                               error = 0;
-               }
-diff -uprN e/fs/ntfs/file.c f/fs/ntfs/file.c
---- e/fs/ntfs/file.c   2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/ntfs/file.c   2008-05-28 20:29:28.910241000 +0000
-@@ -2118,7 +2118,7 @@ static ssize_t ntfs_file_aio_write_noloc
-               goto out;
-       if (!count)
-               goto out;
--      err = remove_suid(file->f_path.dentry);
-+      err = remove_suid(&file->f_path);
-       if (err)
-               goto out;
-       file_update_time(file);
-diff -uprN e/fs/open.c f/fs/open.c
---- e/fs/open.c        2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/open.c        2008-05-28 20:29:29.410207000 +0000
-@@ -194,8 +194,8 @@ out:
-       return error;
- }
--int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
--      struct file *filp)
-+int do_truncate(struct dentry *dentry, struct vfsmount *mnt, loff_t length,
-+              unsigned int time_attrs, struct file *filp)
- {
-       int err;
-       struct iattr newattrs;
-@@ -206,16 +206,15 @@ int do_truncate(struct dentry *dentry, l
-       newattrs.ia_size = length;
-       newattrs.ia_valid = ATTR_SIZE | time_attrs;
--      if (filp) {
--              newattrs.ia_file = filp;
-+
-+      if (filp)
-               newattrs.ia_valid |= ATTR_FILE;
--      }
-       /* Remove suid/sgid on truncate too */
-       newattrs.ia_valid |= should_remove_suid(dentry);
-       mutex_lock(&dentry->d_inode->i_mutex);
--      err = notify_change(dentry, &newattrs);
-+      err = fnotify_change(dentry, mnt, &newattrs, filp);
-       mutex_unlock(&dentry->d_inode->i_mutex);
-       return err;
- }
-@@ -271,7 +270,7 @@ static long do_sys_truncate(const char _
-       error = locks_verify_truncate(inode, NULL, length);
-       if (!error) {
-               DQUOT_INIT(inode);
--              error = do_truncate(nd.path.dentry, length, 0, NULL);
-+              error = do_truncate(nd.path.dentry, nd.path.mnt, length, 0, NULL);
-       }
- put_write_and_out:
-@@ -324,7 +323,8 @@ static long do_sys_ftruncate(unsigned in
-       error = locks_verify_truncate(inode, file, length);
-       if (!error)
--              error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
-+              error = do_truncate(dentry, file->f_path.mnt, length,
-+                                  ATTR_MTIME|ATTR_CTIME, file);
- out_putf:
-       fput(file);
- out:
-@@ -500,8 +500,8 @@ out:
- asmlinkage long sys_fchdir(unsigned int fd)
- {
-+      struct nameidata nd = { .flags = 0 };
-       struct file *file;
--      struct inode *inode;
-       int error;
-       error = -EBADF;
-@@ -509,12 +509,11 @@ asmlinkage long sys_fchdir(unsigned int 
-       if (!file)
-               goto out;
--      inode = file->f_path.dentry->d_inode;
--
-       error = -ENOTDIR;
--      if (!S_ISDIR(inode->i_mode))
-+      if (!S_ISDIR(file->f_path.dentry->d_inode->i_mode))
-               goto out_putf;
-+      nd.path = file->f_path;
-       error = file_permission(file, MAY_EXEC);
-       if (!error)
-               set_fs_pwd(current->fs, &file->f_path);
-@@ -577,8 +576,8 @@ asmlinkage long sys_fchmod(unsigned int 
-       if (mode == (mode_t) -1)
-               mode = inode->i_mode;
-       newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
--      newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
--      err = notify_change(dentry, &newattrs);
-+      newattrs.ia_valid = ATTR_MODE | ATTR_CTIME | ATTR_FILE;
-+      err = fnotify_change(dentry, file->f_path.mnt, &newattrs, file);
-       mutex_unlock(&inode->i_mutex);
- out_putf:
-@@ -613,7 +612,7 @@ asmlinkage long sys_fchmodat(int dfd, co
-               mode = inode->i_mode;
-       newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
-       newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
--      error = notify_change(nd.path.dentry, &newattrs);
-+      error = notify_change(nd.path.dentry, nd.path.mnt, &newattrs);
-       mutex_unlock(&inode->i_mutex);
- dput_and_out:
-@@ -627,7 +626,7 @@ asmlinkage long sys_chmod(const char __u
- }
- static int chown_common(struct dentry *dentry, struct vfsmount *mnt,
--      uid_t user, gid_t group)
-+                      uid_t user, gid_t group, struct file *file)
- {
-       struct inode * inode;
-       int error;
-@@ -666,8 +666,11 @@ static int chown_common(struct dentry * 
-       if (!S_ISDIR(inode->i_mode))
-               newattrs.ia_valid |=
-                       ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_KILL_PRIV;
-+      if (file)
-+              newattrs.ia_valid |= ATTR_FILE;
-+
-       mutex_lock(&inode->i_mutex);
--      error = notify_change(dentry, &newattrs);
-+      error = fnotify_change(dentry, mnt, &newattrs, file);
-       mutex_unlock(&inode->i_mutex);
- out:
-       return error;
-@@ -671,7 +686,7 @@ asmlinkage long sys_chown(const char __u
-       error = cow_check_and_break(&nd);
-       if (!error)
- #endif
--              error = chown_common(nd.path.dentry, nd.path.mnt, user, group);
-+              error = chown_common(nd.path.dentry, nd.path.mnt, user, group, NULL);
-       path_put(&nd.path);
- out:
-       return error;
-@@ -691,7 +710,7 @@ asmlinkage long sys_fchownat(int dfd, co
-       error = __user_walk_fd(dfd, filename, follow, &nd);
-       if (!error)
- #endif
--              error = chown_common(nd.path.dentry, nd.path.mnt, user, group);
-+              error = chown_common(nd.path.dentry, nd.path.mnt, user, group, NULL);
-       path_put(&nd.path);
- out:
-       return error;
-@@ -705,7 +708,7 @@ asmlinkage long sys_lchown(const char __
-       error = cow_check_and_break(&nd);
-       if (!error)
- #endif
--              error = chown_common(nd.path.dentry, nd.path.mnt, user, group);
-+              error = chown_common(nd.path.dentry, nd.path.mnt, user, group, NULL);
-       path_put(&nd.path);
- out:
-       return error;
-@@ -724,7 +727,7 @@ asmlinkage long sys_fchown(unsigned int 
-       dentry = file->f_path.dentry;
-       audit_inode(NULL, dentry);
--      error = chown_common(dentry, file->f_vfsmnt, user, group);
-+      error = chown_common(dentry, file->f_path.mnt, user, group, file);
-       fput(file);
- out:
-       return error;
-diff -uprN e/fs/reiserfs/xattr.c f/fs/reiserfs/xattr.c
---- e/fs/reiserfs/xattr.c      2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/reiserfs/xattr.c      2008-05-28 20:29:28.910241000 +0000
-@@ -460,7 +460,7 @@ reiserfs_xattr_set(struct inode *inode, 
-       newattrs.ia_size = buffer_size;
-       newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
-       mutex_lock_nested(&xinode->i_mutex, I_MUTEX_XATTR);
--      err = notify_change(dentry, &newattrs);
-+      err = notify_change(dentry, NULL, &newattrs);
-       if (err)
-               goto out_filp;
-@@ -747,7 +747,7 @@ int reiserfs_delete_xattrs(struct inode 
-       if (dir->d_inode->i_nlink <= 2) {
-               root = get_xa_root(inode->i_sb, XATTR_REPLACE);
-               reiserfs_write_lock_xattrs(inode->i_sb);
--              err = vfs_rmdir(root->d_inode, dir, NULL);
-+              err = vfs_rmdir(root->d_inode, dir, NULL, NULL);
-               reiserfs_write_unlock_xattrs(inode->i_sb);
-               dput(root);
-       } else {
-@@ -791,7 +791,7 @@ reiserfs_chown_xattrs_filler(void *buf, 
-       }
-       if (!S_ISDIR(xafile->d_inode->i_mode))
--              err = notify_change(xafile, attrs);
-+              err = notify_change(xafile, NULL, attrs);
-       dput(xafile);
-       return err;
-@@ -835,7 +835,7 @@ int reiserfs_chown_xattrs(struct inode *
-               goto out_dir;
-       }
--      err = notify_change(dir, attrs);
-+      err = notify_change(dir, NULL, attrs);
-       unlock_kernel();
-       out_dir:
-diff -uprN e/fs/splice.c f/fs/splice.c
---- e/fs/splice.c      2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/splice.c      2008-05-28 20:29:28.910241000 +0000
-@@ -762,7 +762,7 @@ generic_file_splice_write_nolock(struct 
-       ssize_t ret;
-       int err;
--      err = remove_suid(out->f_path.dentry);
-+      err = remove_suid(&out->f_path);
-       if (unlikely(err))
-               return err;
-@@ -822,7 +822,7 @@ generic_file_splice_write(struct pipe_in
-               if (killpriv)
-                       err = security_inode_killpriv(out->f_path.dentry);
-               if (!err && killsuid)
--                      err = __remove_suid(out->f_path.dentry, killsuid);
-+                      err = __remove_suid(&out->f_path, killsuid);
-               mutex_unlock(&inode->i_mutex);
-               if (err)
-                       return err;
-diff -uprN e/fs/stat.c f/fs/stat.c
---- e/fs/stat.c        2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/stat.c        2008-05-28 20:29:28.910241000 +0000
-@@ -306,7 +306,7 @@ asmlinkage long sys_readlinkat(int dfd, 
-               error = -EINVAL;
-               if (inode->i_op && inode->i_op->readlink) {
--                      error = security_inode_readlink(nd.path.dentry);
-+                      error = security_inode_readlink(nd.path.dentry, nd.path.mnt);
-                       if (!error) {
-                               touch_atime(nd.path.mnt, nd.path.dentry);
-                               error = inode->i_op->readlink(nd.path.dentry,
-diff -uprN e/fs/sysfs/file.c f/fs/sysfs/file.c
---- e/fs/sysfs/file.c  2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/sysfs/file.c  2008-05-28 20:29:28.910241000 +0000
-@@ -579,7 +579,7 @@ int sysfs_chmod_file(struct kobject *kob
-       newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
-       newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
--      rc = notify_change(victim, &newattrs);
-+      rc = notify_change(victim, NULL, &newattrs);
-       if (rc == 0) {
-               mutex_lock(&sysfs_mutex);
-diff -uprN e/fs/utimes.c f/fs/utimes.c
---- e/fs/utimes.c      2008-05-28 20:32:27.897940261 +0000
-+++ f/fs/utimes.c      2008-05-28 20:29:29.410207000 +0000
-@@ -60,7 +60,7 @@ long do_utimes(int dfd, char __user *fil
- {
-       int error;
-       struct nameidata nd;
--      struct dentry *dentry;
-+      struct path path;
-       struct inode *inode;
-       struct iattr newattrs;
-       struct file *f = NULL;
-@@ -83,19 +83,19 @@ long do_utimes(int dfd, char __user *fil
-               f = fget(dfd);
-               if (!f)
-                       goto out;
--              dentry = f->f_path.dentry;
-+              path = f->f_path;
-       } else {
-               error = __user_walk_fd(dfd, filename, (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW, &nd);
-               if (error)
-                       goto out;
-               error = cow_check_and_break(&nd);
-               if (error)
-                       goto dput_and_out;
--              dentry = nd.path.dentry;
-+              path = nd.path;
-       }
--      inode = dentry->d_inode;
-+      inode = path.dentry->d_inode;
-       error = -EROFS;
-       if (IS_RDONLY(inode))
-@@ -145,7 +145,7 @@ long do_utimes(int dfd, char __user *fil
-               }
-       }
-       mutex_lock(&inode->i_mutex);
--      error = notify_change(dentry, &newattrs);
-+      error = fnotify_change(path.dentry, path.mnt, &newattrs, f);
-       mutex_unlock(&inode->i_mutex);
- dput_and_out:
-       if (f)
-diff -uprN e/fs/xattr.c f/fs/xattr.c
---- e/fs/xattr.c       2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/xattr.c       2008-05-28 20:29:29.410207000 +0000
-@@ -68,8 +68,8 @@ xattr_permission(struct inode *inode, co
- }
- int
--vfs_setxattr(struct dentry *dentry, char *name, void *value,
--              size_t size, int flags)
-+vfs_setxattr(struct dentry *dentry, struct vfsmount *mnt, char *name,
-+           void *value, size_t size, int flags, struct file *file)
- {
-       struct inode *inode = dentry->d_inode;
-       int error;
-@@ -79,7 +79,7 @@ vfs_setxattr(struct dentry *dentry, char
-               return error;
-       mutex_lock(&inode->i_mutex);
--      error = security_inode_setxattr(dentry, name, value, size, flags);
-+      error = security_inode_setxattr(dentry, mnt, name, value, size, flags,                                          file);
-       if (error)
-               goto out;
-       error = -EOPNOTSUPP;
-@@ -87,7 +87,7 @@ vfs_setxattr(struct dentry *dentry, char
-               error = inode->i_op->setxattr(dentry, name, value, size, flags);
-               if (!error) {
-                       fsnotify_xattr(dentry);
--                      security_inode_post_setxattr(dentry, name, value,
-+                      security_inode_post_setxattr(dentry, mnt, name, value,
-                                                    size, flags);
-               }
-       } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
-@@ -132,7 +132,8 @@ out_noalloc:
- EXPORT_SYMBOL_GPL(xattr_getsecurity);
- ssize_t
--vfs_getxattr(struct dentry *dentry, char *name, void *value, size_t size)
-+vfs_getxattr(struct dentry *dentry, struct vfsmount *mnt, char *name,
-+           void *value, size_t size, struct file *file)
- {
-       struct inode *inode = dentry->d_inode;
-       int error;
-@@ -141,7 +142,7 @@ vfs_getxattr(struct dentry *dentry, char
-       if (error)
-               return error;
--      error = security_inode_getxattr(dentry, name);
-+      error = security_inode_getxattr(dentry, mnt, name, file);
-       if (error)
-               return error;
-@@ -168,18 +169,20 @@ nolsm:
- EXPORT_SYMBOL_GPL(vfs_getxattr);
- ssize_t
--vfs_listxattr(struct dentry *d, char *list, size_t size)
-+vfs_listxattr(struct dentry *dentry, struct vfsmount *mnt, char *list,
-+            size_t size, struct file *file)
- {
-+      struct inode *inode = dentry->d_inode;
-       ssize_t error;
--      error = security_inode_listxattr(d);
-+      error = security_inode_listxattr(dentry, mnt, file);
-       if (error)
-               return error;
-       error = -EOPNOTSUPP;
--      if (d->d_inode->i_op && d->d_inode->i_op->listxattr) {
--              error = d->d_inode->i_op->listxattr(d, list, size);
--      } else {
--              error = security_inode_listsecurity(d->d_inode, list, size);
-+      if (inode->i_op && inode->i_op->listxattr)
-+              error = inode->i_op->listxattr(dentry, list, size);
-+      else {
-+              error = security_inode_listsecurity(inode, list, size);
-               if (size && error > size)
-                       error = -ERANGE;
-       }
-@@ -188,7 +191,8 @@ vfs_listxattr(struct dentry *d, char *li
- EXPORT_SYMBOL_GPL(vfs_listxattr);
- int
--vfs_removexattr(struct dentry *dentry, char *name)
-+vfs_removexattr(struct dentry *dentry, struct vfsmount *mnt, char *name,
-+              struct file *file)
- {
-       struct inode *inode = dentry->d_inode;
-       int error;
-@@ -200,7 +204,7 @@ vfs_removexattr(struct dentry *dentry, c
-       if (error)
-               return error;
--      error = security_inode_removexattr(dentry, name);
-+      error = security_inode_removexattr(dentry, mnt, name, file);
-       if (error)
-               return error;
-@@ -219,7 +223,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
-  */
- static long
- setxattr(struct dentry *d, char __user *name, void __user *value,
--       size_t size, int flags, struct vfsmount *mnt)
-+       size_t size, int flags, struct vfsmount *mnt, struct file *file)
- {
-       int error;
-       void *kvalue = NULL;
-@@ -247,7 +251,7 @@ setxattr(struct dentry *d, char __user *
-               }
-       }
--      error = vfs_setxattr(d, kname, kvalue, size, flags);
-+      error = vfs_setxattr(d, mnt, kname, kvalue, size, flags, file);
-       kfree(kvalue);
-       return error;
- }
-@@ -262,7 +266,7 @@ sys_setxattr(char __user *path, char __u
-       error = user_path_walk(path, &nd);
-       if (error)
-               return error;
--      error = setxattr(nd.path.dentry, name, value, size, flags, nd.path.mnt);
-+      error = setxattr(nd.path.dentry, name, value, size, flags, nd.path.mnt, NULL);
-       path_put(&nd.path);
-       return error;
- }
-@@ -277,7 +281,7 @@ sys_lsetxattr(char __user *path, char __
-       error = user_path_walk_link(path, &nd);
-       if (error)
-               return error;
--      error = setxattr(nd.path.dentry, name, value, size, flags, nd.path.mnt);
-+      error = setxattr(nd.path.dentry, name, value, size, flags, nd.path.mnt, NULL);
-       path_put(&nd.path);
-       return error;
- }
-@@ -295,7 +299,7 @@ sys_fsetxattr(int fd, char __user *name,
-               return error;
-       dentry = f->f_path.dentry;
-       audit_inode(NULL, dentry);
--      error = setxattr(dentry, name, value, size, flags, f->f_vfsmnt);
-+      error = setxattr(dentry, name, value, size, flags, f->f_vfsmnt, f);
-       fput(f);
-       return error;
- }
-@@ -304,7 +308,8 @@ sys_fsetxattr(int fd, char __user *name,
-  * Extended attribute GET operations
-  */
- static ssize_t
--getxattr(struct dentry *d, char __user *name, void __user *value, size_t size)
-+getxattr(struct dentry *dentry, struct vfsmount *mnt, char __user *name,
-+       void __user *value, size_t size, struct file *file)
- {
-       ssize_t error;
-       void *kvalue = NULL;
-@@ -324,7 +329,7 @@ getxattr(struct dentry *d, char __user *
-                       return -ENOMEM;
-       }
--      error = vfs_getxattr(d, kname, kvalue, size);
-+      error = vfs_getxattr(dentry, mnt, kname, kvalue, size, file);
-       if (error > 0) {
-               if (size && copy_to_user(value, kvalue, error))
-                       error = -EFAULT;
-@@ -347,7 +352,7 @@ sys_getxattr(char __user *path, char __u
-       error = user_path_walk(path, &nd);
-       if (error)
-               return error;
--      error = getxattr(nd.path.dentry, name, value, size);
-+      error = getxattr(nd.path.dentry, nd.path.mnt, name, value, size, NULL);
-       path_put(&nd.path);
-       return error;
- }
-@@ -362,7 +367,7 @@ sys_lgetxattr(char __user *path, char __
-       error = user_path_walk_link(path, &nd);
-       if (error)
-               return error;
--      error = getxattr(nd.path.dentry, name, value, size);
-+      error = getxattr(nd.path.dentry, nd.path.mnt, name, value, size, NULL);
-       path_put(&nd.path);
-       return error;
- }
-@@ -377,7 +382,7 @@ sys_fgetxattr(int fd, char __user *name,
-       if (!f)
-               return error;
-       audit_inode(NULL, f->f_path.dentry);
--      error = getxattr(f->f_path.dentry, name, value, size);
-+      error = getxattr(f->f_path.dentry, f->f_path.mnt, name, value, size, f);
-       fput(f);
-       return error;
- }
-@@ -386,7 +391,8 @@ sys_fgetxattr(int fd, char __user *name,
-  * Extended attribute LIST operations
-  */
- static ssize_t
--listxattr(struct dentry *d, char __user *list, size_t size)
-+listxattr(struct dentry *dentry, struct vfsmount *mnt, char __user *list,
-+        size_t size, struct file *file)
- {
-       ssize_t error;
-       char *klist = NULL;
-@@ -399,7 +405,7 @@ listxattr(struct dentry *d, char __user 
-                       return -ENOMEM;
-       }
--      error = vfs_listxattr(d, klist, size);
-+      error = vfs_listxattr(dentry, mnt, klist, size, file);
-       if (error > 0) {
-               if (size && copy_to_user(list, klist, error))
-                       error = -EFAULT;
-@@ -421,7 +427,7 @@ sys_listxattr(char __user *path, char __
-       error = user_path_walk(path, &nd);
-       if (error)
-               return error;
--      error = listxattr(nd.path.dentry, list, size);
-+      error = listxattr(nd.path.dentry, nd.path.mnt, list, size, NULL);
-       path_put(&nd.path);
-       return error;
- }
-@@ -435,7 +441,7 @@ sys_llistxattr(char __user *path, char _
-       error = user_path_walk_link(path, &nd);
-       if (error)
-               return error;
--      error = listxattr(nd.path.dentry, list, size);
-+      error = listxattr(nd.path.dentry, nd.path.mnt, list, size, NULL);
-       path_put(&nd.path);
-       return error;
- }
-@@ -450,7 +456,7 @@ sys_flistxattr(int fd, char __user *list
-       if (!f)
-               return error;
-       audit_inode(NULL, f->f_path.dentry);
--      error = listxattr(f->f_path.dentry, list, size);
-+      error = listxattr(f->f_path.dentry, f->f_path.mnt, list, size, f);
-       fput(f);
-       return error;
- }
-@@ -459,7 +465,8 @@ sys_flistxattr(int fd, char __user *list
-  * Extended attribute REMOVE operations
-  */
- static long
--removexattr(struct dentry *d, char __user *name, struct vfsmount *mnt)
-+removexattr(struct dentry *dentry, char __user *name, struct vfsmount *mnt,
-+          struct file *file)
- {
-       int error;
-       char kname[XATTR_NAME_MAX + 1];
-@@ -470,7 +477,7 @@ removexattr(struct dentry *d, char __use
-       if (error < 0)
-               return error;
--      return vfs_removexattr(d, kname);
-+      return vfs_removexattr(dentry, mnt, kname, file);
- }
- asmlinkage long
-@@ -482,7 +489,7 @@ sys_removexattr(char __user *path, char 
-       error = user_path_walk(path, &nd);
-       if (error)
-               return error;
--      error = removexattr(nd.path.dentry, name, nd.path.mnt);
-+      error = removexattr(nd.path.dentry, name, nd.path.mnt, NULL);
-       path_put(&nd.path);
-       return error;
- }
-@@ -496,7 +503,7 @@ sys_lremovexattr(char __user *path, char
-       error = user_path_walk_link(path, &nd);
-       if (error)
-               return error;
--      error = removexattr(nd.path.dentry, name, nd.path.mnt);
-+      error = removexattr(nd.path.dentry, name, nd.path.mnt, NULL);
-       path_put(&nd.path);
-       return error;
- }
-@@ -513,7 +520,7 @@ sys_fremovexattr(int fd, char __user *na
-               return error;
-       dentry = f->f_path.dentry;
-       audit_inode(NULL, dentry);
--      error = removexattr(dentry, name, f->f_vfsmnt);
-+      error = removexattr(dentry, name, f->f_path.mnt, f);
-       fput(f);
-       return error;
- }
-diff -uprN e/fs/xfs/linux-2.6/xfs_lrw.c f/fs/xfs/linux-2.6/xfs_lrw.c
---- e/fs/xfs/linux-2.6/xfs_lrw.c       2008-04-17 02:49:44.000000000 +0000
-+++ f/fs/xfs/linux-2.6/xfs_lrw.c       2008-05-28 20:29:28.910241000 +0000
-@@ -716,7 +716,7 @@ start:
-            !capable(CAP_FSETID)) {
-               error = xfs_write_clear_setuid(xip);
-               if (likely(!error))
--                      error = -remove_suid(file->f_path.dentry);
-+                      error = -remove_suid(&file->f_path);
-               if (unlikely(error)) {
-                       goto out_unlock_internal;
-               }
-diff -uprN e/include/linux/audit.h f/include/linux/audit.h
---- e/include/linux/audit.h    2008-04-17 02:49:44.000000000 +0000
-+++ f/include/linux/audit.h    2008-05-28 20:29:29.410207000 +0000
-@@ -33,7 +33,7 @@
-  * 1200 - 1299 messages internal to the audit daemon
-  * 1300 - 1399 audit event messages
-  * 1400 - 1499 SE Linux use
-- * 1500 - 1599 kernel LSPP events
-+ * 1500 - 1599 AppArmor use
-  * 1600 - 1699 kernel crypto events
-  * 1700 - 1799 kernel anomaly records
-  * 1800 - 1999 future kernel use (maybe integrity labels and related events)
-@@ -119,6 +119,13 @@
- #define AUDIT_MAC_UNLBL_STCADD        1416    /* NetLabel: add a static label */
- #define AUDIT_MAC_UNLBL_STCDEL        1417    /* NetLabel: del a static label */
-+#define AUDIT_APPARMOR_AUDIT  1501    /* AppArmor audited grants */
-+#define AUDIT_APPARMOR_ALLOWED        1502    /* Allowed Access for learning */
-+#define AUDIT_APPARMOR_DENIED 1503
-+#define AUDIT_APPARMOR_HINT   1504    /* Process Tracking information */
-+#define AUDIT_APPARMOR_STATUS 1505    /* Changes in config */
-+#define AUDIT_APPARMOR_ERROR  1506    /* Internal AppArmor Errors */
 +
- #define AUDIT_FIRST_KERN_ANOM_MSG   1700
- #define AUDIT_LAST_KERN_ANOM_MSG    1799
- #define AUDIT_ANOM_PROMISCUOUS      1700 /* Device changed promiscuous mode */
-@@ -518,6 +525,9 @@ extern void                    audit_log(struct audit_
-                                     __attribute__((format(printf,4,5)));
- extern struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type);
-+extern void               audit_log_vformat(struct audit_buffer *ab,
-+                                            const char *fmt, va_list args)
-+                          __attribute__((format(printf,2,0)));
- extern void               audit_log_format(struct audit_buffer *ab,
-                                            const char *fmt, ...)
-                           __attribute__((format(printf,2,3)));
-diff -uprN e/include/linux/dcache.h f/include/linux/dcache.h
---- e/include/linux/dcache.h   2008-04-17 02:49:44.000000000 +0000
-+++ f/include/linux/dcache.h   2008-05-28 20:29:29.410207000 +0000
-@@ -300,7 +300,8 @@ extern int d_validate(struct dentry *, s
-  * helper function for dentry_operations.d_dname() members
-  */
- extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
--
-+extern char *__d_path(struct dentry *, struct vfsmount *, struct path *,
-+                    char *, int, int, int);
- extern char *d_path(struct path *, char *, int);
- /* Allocation counts.. */
-diff -uprN e/include/linux/fs.h f/include/linux/fs.h
---- e/include/linux/fs.h       2008-04-17 02:49:44.000000000 +0000
-+++ f/include/linux/fs.h       2008-05-28 20:29:29.410207000 +0000
-@@ -353,13 +353,6 @@ struct iattr {
-       struct timespec ia_atime;
-       struct timespec ia_mtime;
-       struct timespec ia_ctime;
--
--      /*
--       * Not an attribute, but an auxilary info for filesystems wanting to
--       * implement an ftruncate() like method.  NOTE: filesystem should
--       * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
--       */
--      struct file     *ia_file;
- };
- /*
-@@ -1076,13 +1069,13 @@ extern void unlock_super(struct super_bl
-  */
- extern int vfs_permission(struct nameidata *, int);
- extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
--extern int vfs_mkdir(struct inode *, struct dentry *, int, struct nameidata *);
--extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t, struct nameidata *);
--extern int vfs_symlink(struct inode *, struct dentry *, const char *, int, struct nameidata *);
--extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct nameidata *);
--extern int vfs_rmdir(struct inode *, struct dentry *, struct nameidata *);
--extern int vfs_unlink(struct inode *, struct dentry *, struct nameidata *);
--extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
-+extern int vfs_mkdir(struct inode *, struct dentry *, struct vfsmount *, int, struct nameidata *);
-+extern int vfs_mknod(struct inode *, struct dentry *, struct vfsmount *, int, dev_t, struct nameidata *);
-+extern int vfs_symlink(struct inode *, struct dentry *, struct vfsmount *, const char *, int, struct nameidata *);
-+extern int vfs_link(struct dentry *, struct vfsmount *, struct inode *, struct dentry *, struct vfsmount *, struct nameidata *);
-+extern int vfs_rmdir(struct inode *, struct dentry *, struct nameidata *, struct vfsmount *);
-+extern int vfs_unlink(struct inode *, struct dentry *, struct nameidata *, struct vfsmount *);
-+extern int vfs_rename(struct inode *, struct dentry *, struct vfsmount *, struct inode *, struct dentry *, struct vfsmount *);
- /*
-  * VFS dentry helper functions.
-@@ -1196,6 +1189,7 @@ struct file_operations {
-       ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
-       ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
-       int (*setlease)(struct file *, long, struct file_lock **);
-+      int (*fsetattr)(struct file *, struct iattr *);
- };
- struct inode_operations {
-@@ -1559,8 +1553,8 @@ static inline int break_lease(struct ino
- /* fs/open.c */
--extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
--                     struct file *filp);
-+extern int do_truncate(struct dentry *, struct vfsmount *, loff_t start,
-+                     unsigned int time_attrs, struct file *filp);
- extern long do_sys_open(int dfd, const char __user *filename, int flags,
-                       int mode);
- extern struct file *filp_open(const char *, int, int);
-@@ -1714,7 +1708,8 @@ extern int do_remount_sb(struct super_bl
- #ifdef CONFIG_BLOCK
- extern sector_t bmap(struct inode *, sector_t);
- #endif
--extern int notify_change(struct dentry *, struct iattr *);
-+extern int notify_change(struct dentry *, struct vfsmount *, struct iattr *);
-+extern int fnotify_change(struct dentry *, struct vfsmount *, struct iattr *, struct file *);
- extern int permission(struct inode *, int, struct nameidata *);
- extern int generic_permission(struct inode *, int,
-               int (*check_acl)(struct inode *, int));
-@@ -1776,9 +1771,9 @@ extern void iget_failed(struct inode *);
- extern void clear_inode(struct inode *);
- extern void destroy_inode(struct inode *);
- extern struct inode *new_inode(struct super_block *);
--extern int __remove_suid(struct dentry *, int);
-+extern int __remove_suid(struct path *, int);
- extern int should_remove_suid(struct dentry *);
--extern int remove_suid(struct dentry *);
-+extern int remove_suid(struct path *);
- extern void __insert_inode_hash(struct inode *, unsigned long hashval);
- extern void remove_inode_hash(struct inode *);
-diff -uprN e/include/linux/mount.h f/include/linux/mount.h
---- e/include/linux/mount.h    2008-04-17 02:49:44.000000000 +0000
-+++ f/include/linux/mount.h    2008-05-28 20:29:29.410207000 +0000
-@@ -103,5 +103,7 @@ extern void mark_mounts_for_expiry(struc
- extern spinlock_t vfsmount_lock;
- extern dev_t name_to_dev_t(char *name);
-+extern char *d_namespace_path(struct dentry *, struct vfsmount *, char *, int);
-+
- #endif
- #endif /* _LINUX_MOUNT_H */
-diff -uprN e/include/linux/nfsd/nfsd.h f/include/linux/nfsd/nfsd.h
---- e/include/linux/nfsd/nfsd.h        2008-04-17 02:49:44.000000000 +0000
-+++ f/include/linux/nfsd/nfsd.h        2008-05-28 20:29:28.910241000 +0000
-@@ -78,7 +78,8 @@ __be32               nfsd_setattr(struct svc_rqst *, 
- #ifdef CONFIG_NFSD_V4
- __be32          nfsd4_set_nfs4_acl(struct svc_rqst *, struct svc_fh *,
-                     struct nfs4_acl *);
--int             nfsd4_get_nfs4_acl(struct svc_rqst *, struct dentry *, struct nfs4_acl **);
-+int             nfsd4_get_nfs4_acl(struct svc_rqst *, struct dentry *,
-+                              struct vfsmount *mnt, struct nfs4_acl **);
- #endif /* CONFIG_NFSD_V4 */
- __be32                nfsd_create(struct svc_rqst *, struct svc_fh *,
-                               char *name, int len, struct iattr *attrs,
-diff -uprN e/include/linux/security.h f/include/linux/security.h
---- e/include/linux/security.h 2008-04-17 02:49:44.000000000 +0000
-+++ f/include/linux/security.h 2008-05-28 20:29:29.410207000 +0000
-@@ -51,8 +51,8 @@ extern void cap_capset_set (struct task_
- extern int cap_bprm_set_security (struct linux_binprm *bprm);
- extern void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe);
- extern int cap_bprm_secureexec(struct linux_binprm *bprm);
--extern int cap_inode_setxattr(struct dentry *dentry, char *name, void *value, size_t size, int flags);
--extern int cap_inode_removexattr(struct dentry *dentry, char *name);
-+extern int cap_inode_setxattr(struct dentry *dentry, struct vfsmount *mnt, char *name, void *value, size_t size, int flags, struct file *file);
-+extern int cap_inode_removexattr(struct dentry *dentry, struct vfsmount *mnt, char *name, struct file *file);
- extern int cap_inode_need_killpriv(struct dentry *dentry);
- extern int cap_inode_killpriv(struct dentry *dentry);
- extern int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags);
-@@ -330,23 +330,28 @@ static inline void security_free_mnt_opt
-  *    Check permission to create a regular file.
-  *    @dir contains inode structure of the parent of the new file.
-  *    @dentry contains the dentry structure for the file to be created.
-+ *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
-  *    @mode contains the file mode of the file to be created.
-  *    Return 0 if permission is granted.
-  * @inode_link:
-  *    Check permission before creating a new hard link to a file.
-  *    @old_dentry contains the dentry structure for an existing link to the file.
-+ *    @old_mnt is the vfsmount corresponding to @old_dentry (may be NULL).
-  *    @dir contains the inode structure of the parent directory of the new link.
-  *    @new_dentry contains the dentry structure for the new link.
-+ *    @new_mnt is the vfsmount corresponding to @new_dentry (may be NULL).
-  *    Return 0 if permission is granted.
-  * @inode_unlink:
-  *    Check the permission to remove a hard link to a file. 
-  *    @dir contains the inode structure of parent directory of the file.
-  *    @dentry contains the dentry structure for file to be unlinked.
-+ *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
-  *    Return 0 if permission is granted.
-  * @inode_symlink:
-  *    Check the permission to create a symbolic link to a file.
-  *    @dir contains the inode structure of parent directory of the symbolic link.
-  *    @dentry contains the dentry structure of the symbolic link.
-+ *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
-  *    @old_name contains the pathname of file.
-  *    Return 0 if permission is granted.
-  * @inode_mkdir:
-@@ -354,12 +359,14 @@ static inline void security_free_mnt_opt
-  *    associated with inode strcture @dir. 
-  *    @dir containst the inode structure of parent of the directory to be created.
-  *    @dentry contains the dentry structure of new directory.
-+ *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
-  *    @mode contains the mode of new directory.
-  *    Return 0 if permission is granted.
-  * @inode_rmdir:
-  *    Check the permission to remove a directory.
-  *    @dir contains the inode structure of parent of the directory to be removed.
-  *    @dentry contains the dentry structure of directory to be removed.
-+ *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
-  *    Return 0 if permission is granted.
-  * @inode_mknod:
-  *    Check permissions when creating a special file (or a socket or a fifo
-@@ -368,6 +375,7 @@ static inline void security_free_mnt_opt
-  *    and not this hook.
-  *    @dir contains the inode structure of parent of the new file.
-  *    @dentry contains the dentry structure of the new file.
-+ *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
-  *    @mode contains the mode of the new file.
-  *    @dev contains the device number.
-  *    Return 0 if permission is granted.
-@@ -375,12 +383,15 @@ static inline void security_free_mnt_opt
-  *    Check for permission to rename a file or directory.
-  *    @old_dir contains the inode structure for parent of the old link.
-  *    @old_dentry contains the dentry structure of the old link.
-+ *    @old_mnt is the vfsmount corresponding to @old_dentry (may be NULL).
-  *    @new_dir contains the inode structure for parent of the new link.
-  *    @new_dentry contains the dentry structure of the new link.
-+ *    @new_mnt is the vfsmount corresponding to @new_dentry (may be NULL).
-  *    Return 0 if permission is granted.
-  * @inode_readlink:
-  *    Check the permission to read the symbolic link.
-  *    @dentry contains the dentry structure for the file link.
-+ *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
-  *    Return 0 if permission is granted.
-  * @inode_follow_link:
-  *    Check permission to follow a symbolic link when looking up a pathname.
-@@ -404,6 +415,7 @@ static inline void security_free_mnt_opt
-  *    file attributes change (such as when a file is truncated, chown/chmod
-  *    operations, transferring disk quotas, etc).
-  *    @dentry contains the dentry structure for the file.
-+ *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
-  *    @attr is the iattr structure containing the new file attributes.
-  *    Return 0 if permission is granted.
-  * @inode_getattr:
-@@ -419,18 +431,18 @@ static inline void security_free_mnt_opt
-  *    inode.
-  * @inode_setxattr:
-  *    Check permission before setting the extended attributes
-- *    @value identified by @name for @dentry.
-+ *    @value identified by @name for @dentry and @mnt.
-  *    Return 0 if permission is granted.
-  * @inode_post_setxattr:
-  *    Update inode security field after successful setxattr operation.
-- *    @value identified by @name for @dentry.
-+ *    @value identified by @name for @dentry and @mnt.
-  * @inode_getxattr:
-  *    Check permission before obtaining the extended attributes
-- *    identified by @name for @dentry.
-+ *    identified by @name for @dentry and @mnt.
-  *    Return 0 if permission is granted.
-  * @inode_listxattr:
-  *    Check permission before obtaining the list of extended attribute 
-- *    names for @dentry.
-+ *    names for @dentry and @mnt.
-  *    Return 0 if permission is granted.
-  * @inode_removexattr:
-  *    Check permission before removing the extended attribute
-@@ -1286,32 +1298,45 @@ struct security_operations {
-       void (*inode_free_security) (struct inode *inode);
-       int (*inode_init_security) (struct inode *inode, struct inode *dir,
-                                   char **name, void **value, size_t *len);
--      int (*inode_create) (struct inode *dir,
--                           struct dentry *dentry, int mode);
--      int (*inode_link) (struct dentry *old_dentry,
--                         struct inode *dir, struct dentry *new_dentry);
--      int (*inode_unlink) (struct inode *dir, struct dentry *dentry);
--      int (*inode_symlink) (struct inode *dir,
--                            struct dentry *dentry, const char *old_name);
--      int (*inode_mkdir) (struct inode *dir, struct dentry *dentry, int mode);
--      int (*inode_rmdir) (struct inode *dir, struct dentry *dentry);
-+      int (*inode_create) (struct inode *dir, struct dentry *dentry,
-+                           struct vfsmount *mnt, int mode);
-+      int (*inode_link) (struct dentry *old_dentry, struct vfsmount *old_mnt,
-+                         struct inode *dir, struct dentry *new_dentry,
-+                         struct vfsmount *new_mnt);
-+      int (*inode_unlink) (struct inode *dir, struct dentry *dentry,
-+                           struct vfsmount *mnt);
-+      int (*inode_symlink) (struct inode *dir, struct dentry *dentry,
-+                            struct vfsmount *mnt, const char *old_name);
-+      int (*inode_mkdir) (struct inode *dir, struct dentry *dentry,
-+                          struct vfsmount *mnt, int mode);
-+      int (*inode_rmdir) (struct inode *dir, struct dentry *dentry,
-+                          struct vfsmount *mnt);
-       int (*inode_mknod) (struct inode *dir, struct dentry *dentry,
--                          int mode, dev_t dev);
-+                          struct vfsmount *mnt, int mode, dev_t dev);
-       int (*inode_rename) (struct inode *old_dir, struct dentry *old_dentry,
--                           struct inode *new_dir, struct dentry *new_dentry);
--      int (*inode_readlink) (struct dentry *dentry);
-+                           struct vfsmount *old_mnt,
-+                           struct inode *new_dir, struct dentry *new_dentry,
-+                           struct vfsmount *new_mnt);
-+      int (*inode_readlink) (struct dentry *dentry, struct vfsmount *mnt);
-       int (*inode_follow_link) (struct dentry *dentry, struct nameidata *nd);
-       int (*inode_permission) (struct inode *inode, int mask, struct nameidata *nd);
--      int (*inode_setattr)    (struct dentry *dentry, struct iattr *attr);
-+      int (*inode_setattr) (struct dentry *dentry, struct vfsmount *mnt,
-+                            struct iattr *attr);
-       int (*inode_getattr) (struct vfsmount *mnt, struct dentry *dentry);
-         void (*inode_delete) (struct inode *inode);
--      int (*inode_setxattr) (struct dentry *dentry, char *name, void *value,
--                             size_t size, int flags);
--      void (*inode_post_setxattr) (struct dentry *dentry, char *name, void *value,
-+      int (*inode_setxattr) (struct dentry *dentry, struct vfsmount *mnt,
-+                             char *name, void *value, size_t size, int flags,
-+                             struct file *file);
-+      void (*inode_post_setxattr) (struct dentry *dentry,
-+                                   struct vfsmount *mnt,
-+                                   char *name, void *value,
-                                    size_t size, int flags);
--      int (*inode_getxattr) (struct dentry *dentry, char *name);
--      int (*inode_listxattr) (struct dentry *dentry);
--      int (*inode_removexattr) (struct dentry *dentry, char *name);
-+      int (*inode_getxattr) (struct dentry *dentry, struct vfsmount *mnt,
-+                             char *name, struct file *file);
-+      int (*inode_listxattr) (struct dentry *dentry, struct vfsmount *mnt,
-+                              struct file *file);
-+      int (*inode_removexattr) (struct dentry *dentry, struct vfsmount *mnt,
-+                                char *name, struct file *file);
-       int (*inode_need_killpriv) (struct dentry *dentry);
-       int (*inode_killpriv) (struct dentry *dentry);
-       int (*inode_getsecurity)(const struct inode *inode, const char *name, void **buffer, bool alloc);
-@@ -1549,30 +1574,43 @@ int security_inode_alloc(struct inode *i
- void security_inode_free(struct inode *inode);
- int security_inode_init_security(struct inode *inode, struct inode *dir,
-                                 char **name, void **value, size_t *len);
--int security_inode_create(struct inode *dir, struct dentry *dentry, int mode);
--int security_inode_link(struct dentry *old_dentry, struct inode *dir,
--                       struct dentry *new_dentry);
--int security_inode_unlink(struct inode *dir, struct dentry *dentry);
-+int security_inode_create(struct inode *dir, struct dentry *dentry,
-+                        struct vfsmount *mnt, int mode);
-+int security_inode_link(struct dentry *old_dentry, struct vfsmount *old_mnt,
-+                      struct inode *dir, struct dentry *new_dentry,
-+                      struct vfsmount *new_mnt);
-+int security_inode_unlink(struct inode *dir, struct dentry *dentry,
-+                        struct vfsmount *mnt);
- int security_inode_symlink(struct inode *dir, struct dentry *dentry,
--                          const char *old_name);
--int security_inode_mkdir(struct inode *dir, struct dentry *dentry, int mode);
--int security_inode_rmdir(struct inode *dir, struct dentry *dentry);
--int security_inode_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
-+                         struct vfsmount *mnt, const char *old_name);
-+int security_inode_mkdir(struct inode *dir, struct dentry *dentry,
-+                       struct vfsmount *mnt, int mode);
-+int security_inode_rmdir(struct inode *dir, struct dentry *dentry,
-+                       struct vfsmount *mnt);
-+int security_inode_mknod(struct inode *dir, struct dentry *dentry,
-+                       struct vfsmount *mnt, int mode, dev_t dev);
- int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
--                         struct inode *new_dir, struct dentry *new_dentry);
--int security_inode_readlink(struct dentry *dentry);
-+                        struct vfsmount *old_mnt, struct inode *new_dir,
-+                        struct dentry *new_dentry, struct vfsmount *new_mnt);
-+int security_inode_readlink(struct dentry *dentry, struct vfsmount *mnt);
- int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd);
- int security_inode_permission(struct inode *inode, int mask, struct nameidata *nd);
--int security_inode_setattr(struct dentry *dentry, struct iattr *attr);
-+int security_inode_setattr(struct dentry *dentry, struct vfsmount *mnt,
-+                         struct iattr *attr);
- int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry);
- void security_inode_delete(struct inode *inode);
--int security_inode_setxattr(struct dentry *dentry, char *name,
--                           void *value, size_t size, int flags);
--void security_inode_post_setxattr(struct dentry *dentry, char *name,
--                                 void *value, size_t size, int flags);
--int security_inode_getxattr(struct dentry *dentry, char *name);
--int security_inode_listxattr(struct dentry *dentry);
--int security_inode_removexattr(struct dentry *dentry, char *name);
-+int security_inode_setxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                          char *name, void *value, size_t size, int flags,
-+                          struct file *file);
-+void security_inode_post_setxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                                char *name, void *value, size_t size,
-+                                int flags);
-+int security_inode_getxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                          char *name, struct file *file);
-+int security_inode_listxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                           struct file *file);
-+int security_inode_removexattr(struct dentry *dentry, struct vfsmount *mnt,
-+                             char *name, struct file *file);
- int security_inode_need_killpriv(struct dentry *dentry);
- int security_inode_killpriv(struct dentry *dentry);
- int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc);
-@@ -1887,26 +1925,31 @@ static inline int security_inode_init_se
-       
- static inline int security_inode_create (struct inode *dir,
-                                        struct dentry *dentry,
-+                                       struct vfsmount *mnt,
-                                        int mode)
- {
-       return 0;
- }
- static inline int security_inode_link (struct dentry *old_dentry,
-+                                     struct vfsmount *old_mnt,
-                                      struct inode *dir,
--                                     struct dentry *new_dentry)
-+                                     struct dentry *new_dentry,
-+                                     struct vfsmount *new_mnt)
- {
-       return 0;
- }
- static inline int security_inode_unlink (struct inode *dir,
--                                       struct dentry *dentry)
-+                                       struct dentry *dentry,
-+                                       struct vfsmount *mnt)
- {
-       return 0;
- }
- static inline int security_inode_symlink (struct inode *dir,
-                                         struct dentry *dentry,
-+                                        struct vfsmount *mnt,
-                                         const char *old_name)
- {
-       return 0;
-@@ -1914,19 +1957,22 @@ static inline int security_inode_symlink
- static inline int security_inode_mkdir (struct inode *dir,
-                                       struct dentry *dentry,
-+                                      struct vfsmount *mnt,
-                                       int mode)
- {
-       return 0;
- }
- static inline int security_inode_rmdir (struct inode *dir,
--                                      struct dentry *dentry)
-+                                      struct dentry *dentry,
-+                                      struct vfsmount *mnt)
- {
-       return 0;
- }
- static inline int security_inode_mknod (struct inode *dir,
-                                       struct dentry *dentry,
-+                                      struct vfsmount *mnt,
-                                       int mode, dev_t dev)
- {
-       return 0;
-@@ -1934,13 +1980,16 @@ static inline int security_inode_mknod (
- static inline int security_inode_rename (struct inode *old_dir,
-                                        struct dentry *old_dentry,
-+                                       struct vfsmount *old_mnt,
-                                        struct inode *new_dir,
--                                       struct dentry *new_dentry)
-+                                       struct dentry *new_dentry,
-+                                       struct vfsmount *new_mnt)
- {
-       return 0;
- }
--static inline int security_inode_readlink (struct dentry *dentry)
-+static inline int security_inode_readlink(struct dentry *dentry,
-+                                         struct vfsmount *mnt)
- {
-       return 0;
- }
-@@ -1958,6 +2007,7 @@ static inline int security_inode_permiss
- }
- static inline int security_inode_setattr (struct dentry *dentry,
-+                                        struct vfsmount *mnt,
-                                         struct iattr *attr)
- {
-       return 0;
-@@ -1972,29 +2022,40 @@ static inline int security_inode_getattr
- static inline void security_inode_delete (struct inode *inode)
- { }
--static inline int security_inode_setxattr (struct dentry *dentry, char *name,
--                                         void *value, size_t size, int flags)
--{
--      return cap_inode_setxattr(dentry, name, value, size, flags);
-+static inline int security_inode_setxattr (struct dentry *dentry,
-+                                         struct vfsmount *mnt, char *name,
-+                                         void *value, size_t size, int flags,
-+                                         struct file *file)
-+{
-+      return cap_inode_setxattr(dentry, mnt, name, value, size, flags, file);
- }
--static inline void security_inode_post_setxattr (struct dentry *dentry, char *name,
--                                               void *value, size_t size, int flags)
-+static inline void security_inode_post_setxattr (struct dentry *dentry,
-+                                               struct vfsmount *mnt,
-+                                               char *name,
-+                                               void *value, size_t size,
-+                                               int flags)
- { }
--static inline int security_inode_getxattr (struct dentry *dentry, char *name)
-+static inline int security_inode_getxattr (struct dentry *dentry,
-+                                         struct vfsmount *mnt, char *name,
-+                                         struct file *file)
- {
-       return 0;
- }
--static inline int security_inode_listxattr (struct dentry *dentry)
-+static inline int security_inode_listxattr (struct dentry *dentry,
-+                                         struct vfsmount *mnt,
-+                                         struct file *file)
- {
-       return 0;
- }
--static inline int security_inode_removexattr (struct dentry *dentry, char *name)
-+static inline int security_inode_removexattr (struct dentry *dentry,
-+                                           struct vfsmount *mnt, char *name,
-+                                           struct file *file)
- {
--      return cap_inode_removexattr(dentry, name);
-+      return cap_inode_removexattr(dentry, mnt, name, file);
- }
- static inline int security_inode_need_killpriv(struct dentry *dentry)
-diff -uprN e/include/linux/sysctl.h f/include/linux/sysctl.h
---- e/include/linux/sysctl.h   2008-04-17 02:49:44.000000000 +0000
-+++ f/include/linux/sysctl.h   2008-05-28 20:29:29.410207000 +0000
-@@ -977,6 +977,8 @@ extern int proc_doulongvec_minmax(struct
- extern int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int,
-                                     struct file *, void __user *, size_t *, loff_t *);
-+extern char *sysctl_pathname(ctl_table *, char *, int);
-+
- extern int do_sysctl (int __user *name, int nlen,
-                     void __user *oldval, size_t __user *oldlenp,
-                     void __user *newval, size_t newlen);
-diff -uprN e/include/linux/xattr.h f/include/linux/xattr.h
---- e/include/linux/xattr.h    2008-04-17 02:49:44.000000000 +0000
-+++ f/include/linux/xattr.h    2008-05-28 20:29:29.410207000 +0000
-@@ -47,10 +47,13 @@ struct xattr_handler {
- };
- ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
--ssize_t vfs_getxattr(struct dentry *, char *, void *, size_t);
--ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
--int vfs_setxattr(struct dentry *, char *, void *, size_t, int);
--int vfs_removexattr(struct dentry *, char *);
-+ssize_t vfs_getxattr(struct dentry *, struct vfsmount *, char *, void *,
-+                   size_t, struct file *);
-+ssize_t vfs_listxattr(struct dentry *d, struct vfsmount *, char *list,
-+                    size_t size, struct file *);
-+int vfs_setxattr(struct dentry *, struct vfsmount *, char *, void *, size_t,
-+               int, struct file *);
-+int vfs_removexattr(struct dentry *, struct vfsmount *, char *, struct file *);
- ssize_t generic_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t size);
- ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size);
-diff -uprN e/ipc/mqueue.c f/ipc/mqueue.c
---- e/ipc/mqueue.c     2008-04-17 02:49:44.000000000 +0000
-+++ f/ipc/mqueue.c     2008-05-28 20:29:28.910241000 +0000
-@@ -743,7 +743,7 @@ asmlinkage long sys_mq_unlink(const char
-       if (inode)
-               atomic_inc(&inode->i_count);
--      err = vfs_unlink(dentry->d_parent->d_inode, dentry, NULL);
-+      err = vfs_unlink(dentry->d_parent->d_inode, dentry, NULL, mqueue_mnt);
- out_err:
-       dput(dentry);
-diff -uprN e/kernel/audit.c f/kernel/audit.c
---- e/kernel/audit.c   2008-04-17 02:49:44.000000000 +0000
-+++ f/kernel/audit.c   2008-05-28 20:29:29.410207000 +0000
-@@ -1136,8 +1136,7 @@ static inline int audit_expand(struct au
-  * will be called a second time.  Currently, we assume that a printk
-  * can't format message larger than 1024 bytes, so we don't either.
-  */
--static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
--                            va_list args)
-+void audit_log_vformat(struct audit_buffer *ab, const char *fmt, va_list args)
- {
-       int len, avail;
-       struct sk_buff *skb;
-@@ -1407,3 +1406,6 @@ EXPORT_SYMBOL(audit_log_start);
- EXPORT_SYMBOL(audit_log_end);
- EXPORT_SYMBOL(audit_log_format);
- EXPORT_SYMBOL(audit_log);
-+EXPORT_SYMBOL_GPL(audit_log_vformat);
-+EXPORT_SYMBOL_GPL(audit_log_untrustedstring);
-+EXPORT_SYMBOL_GPL(audit_log_d_path);
-diff -uprN e/kernel/cgroup.c f/kernel/cgroup.c
---- e/kernel/cgroup.c  2008-05-28 20:32:27.897940261 +0000
-+++ f/kernel/cgroup.c  2008-05-28 20:29:28.910241000 +0000
-@@ -2833,7 +2833,7 @@ int cgroup_clone(struct task_struct *tsk
-       }
-       /* Create the cgroup directory, which also creates the cgroup */
--      ret = vfs_mkdir(inode, dentry, S_IFDIR | 0755, NULL);
-+      ret = vfs_mkdir(inode, dentry, NULL, S_IFDIR | 0755, NULL);
-       child = __d_cgrp(dentry);
-       dput(dentry);
-       if (ret) {
-diff -uprN e/kernel/sysctl.c f/kernel/sysctl.c
---- e/kernel/sysctl.c  2008-04-17 02:49:44.000000000 +0000
-+++ f/kernel/sysctl.c  2008-05-28 20:29:29.410207000 +0000
-@@ -1440,6 +1440,33 @@ void register_sysctl_root(struct ctl_tab
-       spin_unlock(&sysctl_lock);
- }
-+char *sysctl_pathname(struct ctl_table *table, char *buffer, int buflen)
++static void *p_start(struct seq_file *f, loff_t *pos)
++      __acquires(ns_list_lock)
++{
++      struct aa_namespace *ns;
++      loff_t l = *pos;
++
++      read_lock(&ns_list_lock);
++      if (!list_empty(&ns_list)) {
++              struct aa_profile *profile = NULL;
++              ns = list_first_entry(&ns_list, typeof(*ns), base.list);
++              read_lock(&ns->base.lock);
++              if (!list_empty(&ns->base.profiles)) {
++                      profile = list_first_entry(&ns->base.profiles,
++                                                 typeof(*profile), base.list);
++                      for ( ; profile && l > 0; l--)
++                              profile = next_profile(profile);
++                      return profile;
++              } else
++                      read_unlock(&ns->base.lock);
++      }
++      return NULL;
++}
++
++static void *p_next(struct seq_file *f, void *p, loff_t *pos)
++{
++      struct aa_profile *profile = (struct aa_profile *) p;
++
++      (*pos)++;
++      profile = next_profile(profile);
++
++      return profile;
++}
++
++static void p_stop(struct seq_file *f, void *p)
++      __releases(ns_list_lock)
++{
++      struct aa_profile *profile = (struct aa_profile *) p;
++
++      if (profile)
++              read_unlock(&profile->ns->base.lock);
++      read_unlock(&ns_list_lock);
++}
++
++static void print_name(struct seq_file *f, struct aa_profile *profile)
++{
++      if (profile->parent) {
++              print_name(f, profile->parent);
++              seq_printf(f, "//");
++      }
++      seq_printf(f, "%s", profile->base.name);
++}
++
++static int seq_show_profile(struct seq_file *f, void *p)
++{
++      struct aa_profile *profile = (struct aa_profile *)p;
++
++      if (profile->ns != default_namespace)
++              seq_printf(f, ":%s:", profile->ns->base.name);
++      print_name(f, profile);
++      seq_printf(f, " (%s)\n",
++                 PROFILE_COMPLAIN(profile) ? "complain" : "enforce");
++
++      return 0;
++}
++
++/* Used in apparmorfs.c */
++static struct seq_operations apparmorfs_profiles_op = {
++      .start =        p_start,
++      .next =         p_next,
++      .stop =         p_stop,
++      .show =         seq_show_profile,
++};
++
++static int aa_profiles_open(struct inode *inode, struct file *file)
++{
++      return seq_open(file, &apparmorfs_profiles_op);
++}
++
++
++static int aa_profiles_release(struct inode *inode, struct file *file)
++{
++      return seq_release(inode, file);
++}
++
++static struct file_operations apparmorfs_profiles_fops = {
++      .open =         aa_profiles_open,
++      .read =         seq_read,
++      .llseek =       seq_lseek,
++      .release =      aa_profiles_release,
++};
++
++/* apparmor/matching */
++static ssize_t aa_matching_read(struct file *file, char __user *buf,
++                             size_t size, loff_t *ppos)
++{
++      const char *matching = "pattern=aadfa audit perms=crwxamlk/ user::other";
++
++      return simple_read_from_buffer(buf, size, ppos, matching,
++                                     strlen(matching));
++}
++
++static struct file_operations apparmorfs_matching_fops = {
++      .read =         aa_matching_read,
++};
++
++/* apparmor/features */
++static ssize_t aa_features_read(struct file *file, char __user *buf,
++                              size_t size, loff_t *ppos)
++{
++      const char *features = "file=3.1 capability=2.0 network=1.0 "
++                             "change_hat=1.5 change_profile=1.1 "
++                             "aanamespaces=1.1 rlimit=1.1";
++
++      return simple_read_from_buffer(buf, size, ppos, features,
++                                     strlen(features));
++}
++
++static struct file_operations apparmorfs_features_fops = {
++      .read =         aa_features_read,
++};
++
++/* apparmor/.load */
++static ssize_t aa_profile_load(struct file *f, const char __user *buf,
++                             size_t size, loff_t *pos)
++{
++      char *data;
++      ssize_t error;
++
++      data = aa_simple_write_to_buffer(buf, size, size, pos, "profile_load");
++
++      error = PTR_ERR(data);
++      if (!IS_ERR(data)) {
++              error = aa_interface_add_profiles(data, size);
++              vfree(data);
++      }
++
++      return error;
++}
++
++
++static struct file_operations apparmorfs_profile_load = {
++      .write = aa_profile_load
++};
++
++/* apparmor/.replace */
++static ssize_t aa_profile_replace(struct file *f, const char __user *buf,
++                                size_t size, loff_t *pos)
++{
++      char *data;
++      ssize_t error;
++
++      data = aa_simple_write_to_buffer(buf, size, size, pos,
++                                       "profile_replace");
++      error = PTR_ERR(data);
++      if (!IS_ERR(data)) {
++              error = aa_interface_replace_profiles(data, size);
++              vfree(data);
++      }
++
++      return error;
++}
++
++
++static struct file_operations apparmorfs_profile_replace = {
++      .write = aa_profile_replace
++};
++
++/* apparmor/.remove */
++static ssize_t aa_profile_remove(struct file *f, const char __user *buf,
++                                size_t size, loff_t *pos)
++{
++      char *data;
++      ssize_t error;
++
++      /*
++       * aa_remove_profile needs a null terminated string so 1 extra
++       * byte is allocated and the copied data is null terminated.
++       */
++      data = aa_simple_write_to_buffer(buf, size + 1, size, pos,
++                                       "profile_remove");
++
++      error = PTR_ERR(data);
++      if (!IS_ERR(data)) {
++              data[size] = 0;
++              error = aa_interface_remove_profiles(data, size);
++              vfree(data);
++      }
++
++      return error;
++}
++
++static struct file_operations apparmorfs_profile_remove = {
++      .write = aa_profile_remove
++};
++
++static struct dentry *apparmorfs_dentry;
++struct dentry *apparmorfs_null;
++struct vfsmount *apparmorfs_mnt;
++
++static void aafs_remove(const char *name)
++{
++      struct dentry *dentry;
++
++      dentry = lookup_one_len(name, apparmorfs_dentry, strlen(name));
++      if (!IS_ERR(dentry)) {
++              securityfs_remove(dentry);
++              dput(dentry);
++      }
++}
++
++static int aafs_create(const char *name, int mask, struct file_operations *fops)
++{
++      struct dentry *dentry;
++
++      dentry = securityfs_create_file(name, S_IFREG | mask, apparmorfs_dentry,
++                                      NULL, fops);
++
++      return IS_ERR(dentry) ? PTR_ERR(dentry) : 0;
++}
++
++void destroy_apparmorfs(void)
++{
++      if (apparmorfs_dentry) {
++              aafs_remove(".remove");
++              aafs_remove(".replace");
++              aafs_remove(".load");
++              aafs_remove("matching");
++              aafs_remove("features");
++              aafs_remove("profiles");
++              securityfs_remove(apparmorfs_dentry);
++              apparmorfs_dentry = NULL;
++      }
++}
++
++int create_apparmorfs(void)
++{
++      int error;
++
++      if (!apparmor_initialized)
++              return 0;
++
++      if (apparmorfs_dentry) {
++              AA_ERROR("%s: AppArmor securityfs already exists\n", __func__);
++              return -EEXIST;
++      }
++
++      apparmorfs_dentry = securityfs_create_dir("apparmor", NULL);
++      if (IS_ERR(apparmorfs_dentry)) {
++              error = PTR_ERR(apparmorfs_dentry);
++              apparmorfs_dentry = NULL;
++              goto error;
++      }
++      error = aafs_create("profiles", 0440, &apparmorfs_profiles_fops);
++      if (error)
++              goto error;
++      error = aafs_create("matching", 0444, &apparmorfs_matching_fops);
++      if (error)
++              goto error;
++      error = aafs_create("features", 0444, &apparmorfs_features_fops);
++      if (error)
++              goto error;
++      error = aafs_create(".load", 0640, &apparmorfs_profile_load);
++      if (error)
++              goto error;
++      error = aafs_create(".replace", 0640, &apparmorfs_profile_replace);
++      if (error)
++              goto error;
++      error = aafs_create(".remove", 0640, &apparmorfs_profile_remove);
++      if (error)
++              goto error;
++
++      /* TODO: add support for apparmorfs_null and apparmorfs_mnt */
++
++      /* Report that AppArmor fs is enabled */
++      info_message("AppArmor Filesystem Enabled");
++      return 0;
++
++error:
++      destroy_apparmorfs();
++      AA_ERROR("Error creating AppArmor securityfs\n");
++      apparmor_disable();
++      return error;
++}
++
++fs_initcall(create_apparmorfs);
++
+diff --git a/security/apparmor/audit.c b/security/apparmor/audit.c
+new file mode 100644
+index 0000000..834a4f5
+--- /dev/null
++++ b/security/apparmor/audit.c
+@@ -0,0 +1,151 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor auditing functions
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
++
++#include <linux/audit.h>
++#include <linux/socket.h>
++
++#include "include/apparmor.h"
++#include "include/audit.h"
++#include "include/policy.h"
++
++const char *audit_mode_names[] = {
++      "normal",
++      "quiet_denied",
++      "quiet"
++      "noquiet",
++      "all"
++};
++
++static char* aa_audit_type[] = {
++      "APPARMOR_AUDIT",
++      "APPARMOR_ALLOWED",
++      "APPARMOR_DENIED",
++      "APPARMOR_HINT",
++      "APPARMOR_STATUS",
++      "APPARMOR_ERROR",
++      "APPARMOR_KILLED"
++};
++
++/*
++ * TODO:
++ * user auditing - netlink interface
++ * system control of whether user audit messages go to system log
++ */
++static int aa_audit_base(int type, struct aa_profile *profile,
++                       struct aa_audit *sa, struct audit_context *audit_cxt,
++                       void(*cb)(struct audit_buffer *, void *))
++{
++      struct audit_buffer *ab = NULL;
++
++      if (profile && PROFILE_KILL(profile) && type == AUDIT_APPARMOR_DENIED)
++              type = AUDIT_APPARMOR_KILL;
++
++      ab = audit_log_start(audit_cxt, sa->gfp_mask, type);
++
++      if (!ab) {
++              AA_ERROR("(%d) Unable to log event of type (%d)\n",
++                       -ENOMEM, type);
++               /* don't fail operations in complain mode even if logging
++                * fails */
++              return type == AUDIT_APPARMOR_ALLOWED ? 0 : -ENOMEM;
++      }
++
++      if (g_apparmor_audit_header)
++              audit_log_format(ab, "type=%s ",
++                               aa_audit_type[type - AUDIT_APPARMOR_AUDIT]);
++
++      if (sa->operation)
++              audit_log_format(ab, "operation=\"%s\"", sa->operation);
++
++      if (sa->info) {
++              audit_log_format(ab, " info=\"%s\"", sa->info);
++              if (sa->error)
++                      audit_log_format(ab, " error=%d", sa->error);
++      }
++
++      audit_log_format(ab, " pid=%d", sa->task ?sa->task->pid : current->pid);
++
++      if (profile) {
++              pid_t pid = sa->task ? sa->task->real_parent->pid :
++                                     current->real_parent->pid;
++              audit_log_format(ab, " parent=%d", pid);
++              audit_log_format(ab, " profile=");
++              audit_log_untrustedstring(ab, profile->fqname);
++
++              if (profile->ns != default_namespace) {
++                      audit_log_format(ab, " namespace=");
++                      audit_log_untrustedstring(ab, profile->ns->base.name);
++              }
++      }
++
++      if (cb)
++              cb(ab, sa);
++
++      audit_log_end(ab);
++
++      if (type == AUDIT_APPARMOR_KILL)
++              (void)send_sig_info(SIGKILL, NULL,
++                                  sa->task ? sa->task : current);
++
++      return type == AUDIT_APPARMOR_ALLOWED ? 0 : sa->error;
++}
++
++/**
++ * aa_audit - Log an audit event to the audit subsystem
++ * @type: audit type for the message
++ * @profile: profile to check against
++ * @sa: audit event
++ */
++int aa_audit(int type, struct aa_profile *profile, struct aa_audit *sa,
++           void(*cb)(struct audit_buffer *, void *))
++{
++      struct audit_context *audit_cxt;
++      audit_cxt = g_apparmor_logsyscall ? current->audit_context : NULL;
++
++      if (type == AUDIT_APPARMOR_AUTO) {
++              if (likely(!sa->error))
++                      type = AUDIT_APPARMOR_AUDIT;
++              else if (PROFILE_COMPLAIN(profile))
++                      type = AUDIT_APPARMOR_ALLOWED;
++              else
++                      type = AUDIT_APPARMOR_DENIED;
++      }
++      if (PROFILE_AUDIT_MODE(profile) == AUDIT_QUIET ||
++          (type == AUDIT_APPARMOR_DENIED &&
++           PROFILE_AUDIT_MODE(profile) == AUDIT_QUIET))
++              return sa->error;
++
++      return aa_audit_base(type, profile, sa, audit_cxt, cb);
++}
++
++/**
++ * aa_audit_syscallreject - Log a syscall rejection to the audit subsystem
++ * @profile: profile to check against
++ * @gfp: memory allocation flags
++ * @msg: string describing syscall being rejected
++ */
++int aa_audit_syscallreject(struct aa_profile *profile, gfp_t gfp,
++                         const char *msg,
++                         void(*cb)(struct audit_buffer *, void *))
++{
++      struct aa_audit sa;
++      memset(&sa, 0, sizeof(sa));
++      sa.operation = "syscall";
++      sa.info = msg;
++      sa.gfp_mask = gfp;
++      sa.error = -EACCES;
++
++      return aa_audit_base(AUDIT_APPARMOR_DENIED, profile, &sa,
++                           current->audit_context, NULL);
++}
+diff --git a/security/apparmor/capability.c b/security/apparmor/capability.c
+new file mode 100644
+index 0000000..79097e8
+--- /dev/null
++++ b/security/apparmor/capability.c
+@@ -0,0 +1,121 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor capability mediation functions
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
++
++#include <linux/capability.h>
++#include <linux/errno.h>
++#include <linux/gfp.h>
++
++#include "include/apparmor.h"
++#include "include/capability.h"
++#include "include/context.h"
++#include "include/policy.h"
++#include "include/audit.h"
++
++/*
++ * Table of capability names: we generate it from capabilities.h.
++ */
++#include "capability_names.h"
++
++struct audit_cache {
++      struct task_struct *task;
++      kernel_cap_t caps;
++};
++
++static DEFINE_PER_CPU(struct audit_cache, audit_cache);
++
++struct aa_audit_caps {
++      struct aa_audit base;
++
++      int cap;
++};
++
++static void audit_cb(struct audit_buffer *ab, void *va)
++{
++      struct aa_audit_caps *sa = va;
++
++      audit_log_format(ab, " name=");
++      audit_log_untrustedstring(ab, capability_names[sa->cap]);
++}
++
++static int aa_audit_caps(struct aa_profile *profile, struct aa_audit_caps *sa)
++{
++      struct audit_cache *ent;
++      int type = AUDIT_APPARMOR_AUTO;
++
++      if (likely(!sa->base.error)) {
++              /* test if auditing is being forced */
++              if (likely((PROFILE_AUDIT_MODE(profile) != AUDIT_ALL) &&
++                         !cap_raised(profile->caps.audit, sa->cap)))
++                      return 0;
++      } else if (PROFILE_KILL(profile) ||
++                 cap_raised(profile->caps.kill, sa->cap)) {
++              type = AUDIT_APPARMOR_KILL;
++      } else if (cap_raised(profile->caps.quiet, sa->cap) &&
++                 PROFILE_AUDIT_MODE(profile) != AUDIT_NOQUIET &&
++                 PROFILE_AUDIT_MODE(profile) != AUDIT_ALL) {
++              /* quiet auditing */
++              return sa->base.error;
++      }
++
++      /* Do simple duplicate message elimination */
++      ent = &get_cpu_var(audit_cache);
++      if (sa->base.task == ent->task && cap_raised(ent->caps, sa->cap)) {
++              if (PROFILE_COMPLAIN(profile))
++                      return 0;
++              return sa->base.error;
++      } else {
++              ent->task = sa->base.task;
++              cap_raise(ent->caps, sa->cap);
++      }
++      put_cpu_var(audit_cache);
++
++      return aa_audit(type, profile, &sa->base, audit_cb);
++}
++
++int aa_profile_capable(struct aa_profile *profile, int cap)
++{
++      return cap_raised(profile->caps.allowed, cap) ? 0 : -EPERM;
++}
++
++/**
++ * aa_capable - test permission to use capability
++ * @task: task doing capability test against
++ * @profile: profile confining @task
++ * @cap: capability to be tested
++ * @audit: whether an audit record should be generated
++ *
++ * Look up capability in profile capability set.
++ * Returns 0 on success, or else an error code.
++ */
++int aa_capable(struct task_struct *task, struct aa_profile *profile, int cap,
++             int audit)
++{
++      int error = aa_profile_capable(profile, cap);
++      struct aa_audit_caps sa;
++
++      if (!audit) {
++              if (PROFILE_COMPLAIN(profile))
++                      return 0;
++              return error;
++      }
++
++      memset(&sa, 0, sizeof(sa));
++      sa.base.operation = "capable";
++      sa.base.task = task;
++      sa.base.gfp_mask = GFP_ATOMIC;
++      sa.base.error = error;
++      sa.cap = cap;
++
++      return aa_audit_caps(profile, &sa);
++}
+diff --git a/security/apparmor/context.c b/security/apparmor/context.c
+new file mode 100644
+index 0000000..02e0b70
+--- /dev/null
++++ b/security/apparmor/context.c
+@@ -0,0 +1,209 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor functions used to manipulate object security
++ * contexts.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
++
++#include "include/context.h"
++#include "include/policy.h"
++
++
++
++struct aa_task_context *aa_alloc_task_context(gfp_t flags)
++{
++      return kzalloc(sizeof(struct aa_task_context), flags);
++}
++
++void aa_free_task_context(struct aa_task_context *cxt)
++{
++      if (cxt) {
++              aa_put_profile(cxt->sys.profile);
++              aa_put_profile(cxt->sys.previous);
++              aa_put_profile(cxt->sys.onexec);
++
++              memset(cxt, 0, sizeof(*cxt));
++              kfree(cxt);
++      }
++}
++
++/*
++ * duplicate a task context, incrementing reference counts
++ */
++struct aa_task_context *aa_dup_task_context(struct aa_task_context *old_cxt,
++                                          gfp_t gfp)
++{
++      struct aa_task_context *cxt;
++
++      cxt = kmemdup(old_cxt, sizeof(*cxt), gfp);
++      if (!cxt)
++              return NULL;
++
++      aa_get_profile(cxt->sys.profile);
++      aa_get_profile(cxt->sys.previous);
++      aa_get_profile(cxt->sys.onexec);
++
++      return cxt;
++}
++
++/**
++ * aa_cred_policy - obtain cred's profiles
++ * @cred: cred to obtain profiles from
++ * @sys: return system profile
++ * does NOT increment reference count
++ */
++void aa_cred_policy(const struct cred *cred, struct aa_profile **sys)
++{
++      struct aa_task_context *cxt = cred->security;
++      BUG_ON(!cxt);
++      *sys = aa_filtered_profile(aa_profile_newest(cxt->sys.profile));
++}
++
++/**
++ * aa_get_task_policy - get the cred with the task policy, and current profiles
++ * @task: task to get policy of
++ * @sys: return - pointer to system profile
++ *
++ * Only gets the cred ref count which has ref counts on the profiles returned
++ */
++struct cred *aa_get_task_policy(const struct task_struct *task,
++                              struct aa_profile **sys)
++{
++      struct cred *cred = get_task_cred(task);
++      aa_cred_policy(cred, sys);
++      return cred;
++}
++
++void aa_put_task_policy(struct cred *cred)
++{
++      put_cred(cred);
++}
++
++static void replace_group(struct aa_task_cxt_group *cgrp,
++                        struct aa_profile *profile)
++{
++      if (cgrp->profile == profile)
++              return;
++
++      if (!profile || (profile->flags & PFLAG_UNCONFINED) ||
++          (cgrp->profile && cgrp->profile->ns != profile->ns)) {
++              aa_put_profile(cgrp->previous);
++              aa_put_profile(cgrp->onexec);
++              cgrp->previous = NULL;
++              cgrp->onexec = NULL;
++              cgrp->token = 0;
++      }
++      aa_put_profile(cgrp->profile);
++      cgrp->profile = aa_get_profile(profile);
++}
++
++/**
++ * aa_replace_current_profiles - replace the current tasks profiles
++ * @sys: new system profile
++ *
++ * Returns: error on failure
++ */
++int aa_replace_current_profiles(struct aa_profile *sys)
++{
++      struct aa_task_context *cxt;
++      struct cred *new = prepare_creds();
++      if (!new)
++              return -ENOMEM;
++
++      cxt = new->security;
++      replace_group(&cxt->sys, sys);
++
++      commit_creds(new);
++      return 0;
++}
++
++int aa_set_current_onexec(struct aa_profile *sys)
++{
++      struct aa_task_context *cxt;
++      struct cred *new = prepare_creds();
++      if (!new)
++              return -ENOMEM;
++
++      cxt = new->security;
++      aa_put_profile(cxt->sys.onexec);
++      cxt->sys.onexec = aa_get_profile(sys);
++
++      commit_creds(new);
++      return 0;
++}
++
++/*
++ * Do the actual cred switching of a changehat
++ * profile must be valid
++ */
++int aa_set_current_hat(struct aa_profile *profile, u64 token)
++{
++      struct aa_task_context *cxt;
++      struct cred *new = prepare_creds();
++      if (!new)
++              return -ENOMEM;
++
++      cxt = new->security;
++      if (!cxt->sys.previous) {
++              cxt->sys.previous = cxt->sys.profile;
++              cxt->sys.token = token;
++      } else if (cxt->sys.token == token) {
++              aa_put_profile(cxt->sys.profile);
++      } else {
++              /* previous_profile && cxt->token != token */
++              abort_creds(new);
++              return -EACCES;
++      }
++      cxt->sys.profile = aa_get_profile(profile);
++      /* clear exec on switching context */
++      aa_put_profile(cxt->sys.onexec);
++      cxt->sys.onexec = NULL;
++
++      commit_creds(new);
++      return 0;
++}
++
++/*
++ * Attempt to return out of a hat to the previous profile
++ */
++int aa_restore_previous_profile(u64 token)
++{
++      struct aa_task_context *cxt;
++      struct cred *new = prepare_creds();
++      if (!new)
++              return -ENOMEM;
++
++      cxt = new->security;
++      if (cxt->sys.token != token) {
++              abort_creds(new);
++              return -EACCES;
++      }
++      /* ignore restores when there is no saved profile */
++      if (!cxt->sys.previous) {
++              abort_creds(new);
++              return 0;
++      }
++
++      aa_put_profile(cxt->sys.profile);
++      cxt->sys.profile = aa_profile_newest(cxt->sys.previous);
++      if (unlikely(cxt->sys.profile != cxt->sys.previous)) {
++              aa_get_profile(cxt->sys.profile);
++              aa_put_profile(cxt->sys.previous);
++      }
++      /* clear exec && prev information when restoring to previous context */
++      cxt->sys.previous = NULL;
++      cxt->sys.token = 0;
++      aa_put_profile(cxt->sys.onexec);
++      cxt->sys.onexec = NULL;
++
++      commit_creds(new);
++      return 0;
++}
+diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
+new file mode 100644
+index 0000000..34f337c
+--- /dev/null
++++ b/security/apparmor/domain.c
+@@ -0,0 +1,699 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor policy attachment and domain transitions
++ *
++ * Copyright (C) 2002-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
++
++#include <linux/errno.h>
++#include <linux/fdtable.h>
++#include <linux/file.h>
++#include <linux/mount.h>
++#include <linux/personality.h>
++#include <linux/syscalls.h>
++#include <linux/tracehook.h>
++
++#include "include/audit.h"
++#include "include/apparmorfs.h"
++#include "include/context.h"
++#include "include/domain.h"
++#include "include/file.h"
++#include "include/ipc.h"
++#include "include/match.h"
++#include "include/path.h"
++#include "include/policy.h"
++
++/**
++ * aa_free_domain_entries - free entries in a domain table
++ * @domain: the domain table to free
++ */
++void aa_free_domain_entries(struct aa_domain *domain)
++{
++      int i;
++
++      if (!domain->table)
++              return;
++
++      for (i = 0; i < domain->size; i++)
++              kfree(domain->table[i]);
++      kfree(domain->table);
++}
++
++/*
++ * check if the task is ptraced and if so if the tracing task is allowed
++ * to trace the new domain
++ */
++static int aa_may_change_ptraced_domain(struct task_struct *task,
++                                      struct aa_profile *to_profile)
++{
++      struct task_struct *tracer;
++      struct cred *cred = NULL;
++      struct aa_profile *tracerp = NULL;
++      int error = 0;
++
++      rcu_read_lock();
++      tracer = tracehook_tracer_task(task);
++      if (tracer)
++              cred = aa_get_task_policy(tracer, &tracerp);
++      rcu_read_unlock();
++
++      if (!tracerp)
++              return error;
++
++      error = aa_may_ptrace(tracer, tracerp, to_profile, PTRACE_MODE_ATTACH);
++      put_cred(cred);
++
++      return error;
++}
++
++/**
++ * change_profile_perms
++ */
++static struct file_perms change_profile_perms(struct aa_profile *profile,
++                                            struct aa_namespace *ns,
++                                            const char *name,
++                                            unsigned int *rstate)
++{
++      struct file_perms perms;
++      struct path_cond cond = { 0, 0 };
++      unsigned int state;
++
++      if (!profile) {
++              /* unconfined */
++              perms.allowed = AA_MAY_CHANGE_PROFILE;
++              perms.xindex = perms.dindex = 0;
++              perms.audit = perms.quiet = perms.kill = 0;
++              *rstate = 0;
++              return perms;
++      } else if ((ns == profile->ns)) {
++              /* try matching against rules with out namespace prependend */
++              perms = aa_str_perms(profile->file.dfa, DFA_START, name, &cond,
++                                   rstate);
++              if (COMBINED_PERM_MASK(perms) & AA_MAY_CHANGE_PROFILE)
++                      return perms;
++      }
++
++      /* try matching with namespace name and then profile */
++      if (!profile->file.dfa)
++              return nullperms;
++
++      state = aa_dfa_match(profile->file.dfa, DFA_START, ns->base.name);
++      state = aa_dfa_null_transition(profile->file.dfa, state);
++      return aa_str_perms(profile->file.dfa, state, name, &cond, rstate);
++}
++
++/*
++ * TODO: fix parser to detect unconfined, inherit,
++ * check for next name in list of names that is double null terminated
++ * The names list is a set of strings that \0 seperated with a double
++ * \0 terminating the list
++ * names that belong to namespaces begin with a :
++ * and are followed by a name a \0 seperated name.  If the name is
++ * unspecified it is 0 length.  This double \0\0 does not count as
++ * the end of the list
++ *
++ * profile\0\0                        # single profile
++ * profile\0profile\0\0               # 2 profiles in list
++ * :namespace\0profile\0\0    # profile & namespace
++ * :namespace\0\0\0           # namespace without profile
++ * :namespace\0\0profile\0\0  # namespace without profile followed by profile
++*/
++static const char *next_name(int xtype, const char *name)
++{
++/* TODO: fix parser and enable
++      if (xtype == AA_X_TABLE) {
++              name = name + strlen(name) + 1;
++              if (*name != 0)
++                      return name;
++      }
++*/
++      return NULL;
++}
++
++/*
++ * get target profile for xindex
++ */
++static struct aa_profile *x_to_profile(struct aa_namespace *ns,
++                                     struct aa_profile *profile,
++                                     const char *name, u16 xindex)
++
++{
++      struct aa_profile *new_profile = NULL;
++      u16 xtype = xindex & AA_X_TYPE_MASK;
++      int index = xindex & AA_X_INDEX_MASK;
++
++      if (!profile)
++              profile = ns->unconfined;
++
++      switch(xtype) {
++      case AA_X_NONE:
++              /* fail exec unless ix || ux fallback - handled by caller */
++              return ERR_PTR(-EACCES);
++      case AA_X_NAME:
++              break;
++      case AA_X_TABLE:
++              if (index > profile->file.trans.size) {
++                      AA_ERROR("Invalid named transition\n");
++                      return ERR_PTR(-EACCES);
++              }
++              name = profile->file.trans.table[index];
++              break;
++      }
++
++      for (; !new_profile && name; name = next_name(xtype, name)) {
++              struct aa_namespace *new_ns;
++              const char *xname = NULL;
++
++              new_ns = NULL;
++              if (xindex & AA_X_CHILD) {
++                      new_profile = aa_find_child(profile, name);
++                      if (new_profile)
++                              return new_profile;
++                      continue;
++              } else if (*name == ':') {
++                      /* switching namespace */
++                      const char *ns_name = name + 1;
++                      name = xname = ns_name + strlen(ns_name) + 1;
++                      if (!*xname)
++                              /* no name so use profile name */
++                              xname = profile->fqname;
++                      if (*ns_name == '@') {
++                              /* TODO: variable support */
++                              ;
++                      }
++                      new_ns = aa_find_namespace(ns_name);
++                      if (!new_ns)
++                              continue;
++              } else if (*name == '@') {
++                      /* TODO: variable support */
++
++              } else {
++                      xname = name;
++              }
++
++              new_profile = aa_find_profile_by_fqname(new_ns ? new_ns : ns,
++                                                      xname);
++              aa_put_namespace(new_ns);
++      }
++
++      if (!new_profile)
++              return ERR_PTR(-ENOENT);
++
++      return new_profile;
++}
++
++int apparmor_bprm_set_creds(struct linux_binprm *bprm)
++{
++      struct aa_task_context *cxt;
++      struct aa_profile *profile, *new_profile = NULL;
++      struct aa_namespace *ns;
++      char *buffer = NULL;
++      unsigned int state = DFA_START;
++      struct aa_audit_file sa;
++      struct path_cond cond = { bprm->file->f_path.dentry->d_inode->i_uid,
++                                bprm->file->f_path.dentry->d_inode->i_mode }; 
++
++      sa.base.error = cap_bprm_set_creds(bprm);
++      if (sa.base.error)
++              return sa.base.error;
++
++      if (bprm->cred_prepared)
++              return 0;
++
++      memset(&sa, 0, sizeof(sa));
++      sa.base.operation = "exec";
++      sa.base.gfp_mask = GFP_KERNEL;
++      sa.request = MAY_EXEC;
++      sa.cond = &cond;
++
++      cxt = bprm->cred->security;
++      BUG_ON(!cxt);
++
++      profile = aa_filtered_profile(aa_profile_newest(cxt->sys.profile));
++      ns = cxt->sys.profile->ns;
++
++      sa.base.error = aa_get_name(&bprm->file->f_path, 0, &buffer,
++                                  (char **) &sa.name);
++      if (sa.base.error) {
++              if (profile || profile->flags & PFLAG_IX_ON_NAME_ERROR)
++                      sa.base.error = 0;
++              sa.base.info = "Exec failed name resolution";
++              sa.name = bprm->filename;
++              goto audit;
++      }
++
++      if (!profile) {
++              /* unconfined task - attach profile if one matches */
++              new_profile = aa_sys_find_attach(ns, sa.name);
++              if (!new_profile)
++                      goto cleanup;
++              goto apply;
++      } else if (cxt->sys.onexec) {
++              /*
++               * onexec permissions are stored in a pair, rewalk the
++               * dfa to get start of the exec path match.
++               */
++              sa.perms = change_profile_perms(profile, cxt->sys.onexec->ns,
++                                              sa.name, &state);
++              state = aa_dfa_null_transition(profile->file.dfa, state);
++      }
++      sa.perms = aa_str_perms(profile->file.dfa, state, sa.name, &cond,
++                              NULL);
++      if (cxt->sys.onexec && sa.perms.allowed & AA_MAY_ONEXEC) {
++              new_profile = cxt->sys.onexec;
++              cxt->sys.onexec = NULL;
++              sa.base.info = "change_profile onexec";
++      } else if (sa.perms.allowed & MAY_EXEC) {
++              new_profile = x_to_profile(ns, profile, sa.name,
++                                         sa.perms.xindex);
++              if (IS_ERR(new_profile)) {
++                      if (sa.perms.xindex & AA_X_INHERIT) {
++                              /* (p|c|n)ix - don't change profile */
++                              sa.base.info = "ix fallback";
++                              goto x_clear;
++                      } else if (sa.perms.xindex & AA_X_UNCONFINED) {
++                              new_profile = aa_get_profile(ns->unconfined);
++                              sa.base.info = "ux fallback";
++                      } else {
++                              sa.base.error = PTR_ERR(new_profile);
++                              if (sa.base.error == -ENOENT)
++                                      sa.base.info = "profile not found";
++                              new_profile = NULL;
++                      }
++              }
++      } else if (PROFILE_COMPLAIN(profile)) {
++              new_profile = aa_alloc_null_profile(profile, 0);
++              sa.base.error = -EACCES;
++              if (!new_profile)
++                      sa.base.error = -ENOMEM;
++              sa.name2 = new_profile->fqname;
++              sa.perms.xindex |= AA_X_UNSAFE;
++      } else {
++              sa.base.error = -EACCES;
++      }
++
++      if (!new_profile)
++              goto audit;
++
++      if (profile == new_profile) {
++              aa_put_profile(new_profile);
++              goto audit;
++      }
++
++      if (bprm->unsafe & LSM_UNSAFE_SHARE) {
++              /* FIXME: currently don't mediate shared state */
++              ;
++      }
++
++      if (bprm->unsafe & (LSM_UNSAFE_PTRACE | LSM_UNSAFE_PTRACE_CAP)) {
++              sa.base.error = aa_may_change_ptraced_domain(current,
++                                                           new_profile);
++              if (sa.base.error)
++                      goto audit;
++      }
++
++      /* Determine if secure exec is needed.
++       * Can be at this point for the following reasons:
++       * 1. unconfined switching to confined
++       * 2. confined switching to different confinement
++       * 3. confined switching to unconfined
++       *
++       * Cases 2 and 3 are marked as requiring secure exec
++       * (unless policy specified "unsafe exec")
++       *
++       * bprm->unsafe is used to cache the AA_X_UNSAFE permission
++       * to avoid having to recompute in secureexec
++       */
++      if (!(sa.perms.xindex & AA_X_UNSAFE))
++              bprm->unsafe |= AA_SECURE_X_NEEDED;
++
++apply:
++      sa.name2 = new_profile->fqname;
++      /* When switching namespace ensure its part of audit message */
++      if (new_profile->ns != profile->ns)
++              sa.name3 = new_profile->ns->base.name;
++
++      /* when transitioning profiles clear unsafe personality bits */
++      bprm->per_clear |= PER_CLEAR_ON_SETID;
++
++      aa_put_profile(cxt->sys.profile);
++      cxt->sys.profile = new_profile;
++
++x_clear:
++      aa_put_profile(cxt->sys.previous);
++      aa_put_profile(cxt->sys.onexec);
++      cxt->sys.previous = NULL;
++      cxt->sys.onexec = NULL;
++      cxt->sys.token = 0;
++
++audit:
++      sa.base.error = aa_audit_file(profile, &sa);
++
++cleanup:
++      kfree(buffer);
++
++      return sa.base.error;
++}
++
++int apparmor_bprm_secureexec(struct linux_binprm *bprm)
++{
++      int ret = cap_bprm_secureexec(bprm);
++
++      /* the decision to use secure exec is computed in set_creds
++       * and stored in bprm->unsafe.  The AppArmor X_UNSAFE flag is
++       * indicates don't 
++       */
++      if (!ret && (bprm->unsafe & AA_SECURE_X_NEEDED))
++              ret = 1;
++
++      return ret;
++}
++
++
++static int aa_revalidate_perm(struct aa_profile *profile, struct file *file,
++                            char *buffer, int size)
 +{
-+      if (buflen < 1)
-+              return NULL;
-+      buffer += --buflen;
-+      *buffer = '\0';
++      umode_t mode = file->f_path.dentry->d_inode->i_mode;
++      char *name;
++      int error;
 +
-+      while (table) {
-+              int namelen = strlen(table->procname);
++      error = aa_get_name_to_buffer(&file->f_path, S_ISDIR(mode), buffer,
++                                    size, &name);
++      return aa_file_common_perm(profile, "file_inherit", file,
++                                 aa_map_file_to_perms(file), name,
++                                 error);
++}
++
++static void revalidate_file(struct aa_profile *profile, struct file *file,
++                          unsigned long i, char *buffer, int size,
++                          struct cred *cred)
++{
++      if (aa_revalidate_perm(profile, file, buffer, size)) {
++              struct file *devnull = NULL;
++              int fd = get_unused_fd();
++              sys_close(i);
++              if (fd != i) {
++                      if (fd >= 0)
++                              put_unused_fd(fd);
++                      return;
++              }
++              if (devnull) {
++                      get_file(devnull);
++              } else if (apparmorfs_null) {
++                      devnull = dentry_open(dget(apparmorfs_null),
++                                            mntget(apparmorfs_mnt),
++                                            O_RDWR, cred);
++                      if (IS_ERR(devnull)) {
++                              devnull = NULL;
++                              put_unused_fd(fd);
++                              return;
++                      }
++              } else {
++                      /* apparmorfs_null not setup */
++                      put_unused_fd(fd);
++                      return;
++              }
++              fd_install(fd, devnull);
++      }
++}
 +
-+              if (buflen < namelen + 1)
-+                      return NULL;
-+              buflen -= namelen + 1;
-+              buffer -= namelen;
-+              memcpy(buffer, table->procname, namelen);
-+              *--buffer = '/';
-+              table = table->parent;
++/* 
++ * derived from security/selinux/hooks.c: flush_unauthorized_files &&
++ * fs/exec.c:flush_old_files
++ */
++static int revalidate_files(struct aa_profile *profile,
++                          struct files_struct *files, gfp_t gfp,
++                          struct cred *cred)
++{
++      struct file *file;
++      struct fdtable *fdt;
++      long j = -1;
++      char *buffer = kmalloc(g_apparmor_path_max, gfp);
++      if (!buffer)
++              return -ENOMEM;
++
++      spin_lock(&files->file_lock);
++      for (;;) {
++              unsigned long set, i;
++
++              j++;
++              i = j * __NFDBITS;
++              fdt = files_fdtable(files);
++              if (i >= fdt->max_fds)
++                      break;
++              set = fdt->open_fds->fds_bits[j];
++              if (!set)
++                      continue;
++              spin_unlock(&files->file_lock);
++              for ( ; set ; i++,set >>= 1) {
++                      if (set & 1) {
++                              file = fget(i);
++                              if (!file)
++                                      continue;
++                              revalidate_file(profile, file, i, buffer,
++                                              g_apparmor_path_max, cred);
++                              fput(file);
++                      }
++              }
++              spin_lock(&files->file_lock);
 +      }
-+      if (buflen < 4)
-+              return NULL;
-+      buffer -= 4;
-+      memcpy(buffer, "/sys", 4);
++      spin_unlock(&files->file_lock); 
++      kfree(buffer);
++      return 0;
++}
 +
-+      return buffer;
++int apparmor_bprm_committing_creds(struct linux_binprm *bprm)
++{
++      struct aa_profile *profile;
++      struct cred *cred = aa_get_task_policy(current, &profile);
++      struct aa_task_context *new_cxt = bprm->cred->security;
++      int error;
++
++      if ((new_cxt->sys.profile == profile) ||
++          (new_cxt->sys.profile->flags & PFLAG_UNCONFINED)) {
++              put_cred(cred);
++              return 0;
++      }
++      put_cred(cred);
++
++      error = revalidate_files(new_cxt->sys.profile, current->files,
++                               GFP_KERNEL, bprm->cred);
++      if (error)
++              return error;
++
++      current->pdeath_signal = 0;
++
++      /* reset soft limits and set hard limits for the new profile */
++      __aa_transition_rlimits(profile, new_cxt->sys.profile);
++      return 0;
 +}
-+EXPORT_SYMBOL_GPL(sysctl_pathname);
-+
- #ifdef CONFIG_SYSCTL_SYSCALL
- int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
-              void __user *newval, size_t newlen)
-diff -uprN e/mm/filemap.c f/mm/filemap.c
---- e/mm/filemap.c     2008-04-17 02:49:44.000000000 +0000
-+++ f/mm/filemap.c     2008-05-28 20:29:28.910241000 +0000
-@@ -1653,26 +1653,26 @@ int should_remove_suid(struct dentry *de
- }
- EXPORT_SYMBOL(should_remove_suid);
--int __remove_suid(struct dentry *dentry, int kill)
-+int __remove_suid(struct path *path, int kill)
- {
-       struct iattr newattrs;
-       newattrs.ia_valid = ATTR_FORCE | kill;
--      return notify_change(dentry, &newattrs);
-+      return notify_change(path->dentry, path->mnt, &newattrs);
- }
--int remove_suid(struct dentry *dentry)
-+int remove_suid(struct path *path)
- {
--      int killsuid = should_remove_suid(dentry);
--      int killpriv = security_inode_need_killpriv(dentry);
-+      int killsuid = should_remove_suid(path->dentry);
-+      int killpriv = security_inode_need_killpriv(path->dentry);
-       int error = 0;
-       if (killpriv < 0)
-               return killpriv;
-       if (killpriv)
--              error = security_inode_killpriv(dentry);
-+              error = security_inode_killpriv(path->dentry);
-       if (!error && killsuid)
--              error = __remove_suid(dentry, killsuid);
-+              error = __remove_suid(path, killsuid);
-       return error;
- }
-@@ -2387,7 +2387,7 @@ __generic_file_aio_write_nolock(struct k
-       if (count == 0)
-               goto out;
--      err = remove_suid(file->f_path.dentry);
-+      err = remove_suid(&file->f_path);
-       if (err)
-               goto out;
-diff -uprN e/mm/filemap_xip.c f/mm/filemap_xip.c
---- e/mm/filemap_xip.c 2008-04-17 02:49:44.000000000 +0000
-+++ f/mm/filemap_xip.c 2008-05-28 20:29:28.910241000 +0000
-@@ -380,7 +380,7 @@ xip_file_write(struct file *filp, const 
-       if (count == 0)
-               goto out_backing;
--      ret = remove_suid(filp->f_path.dentry);
-+      ret = remove_suid(&filp->f_path);
-       if (ret)
-               goto out_backing;
-diff -uprN e/mm/tiny-shmem.c f/mm/tiny-shmem.c
---- e/mm/tiny-shmem.c  2008-04-17 02:49:44.000000000 +0000
-+++ f/mm/tiny-shmem.c  2008-05-28 20:29:28.910241000 +0000
-@@ -80,7 +80,7 @@ struct file *shmem_file_setup(char *name
-       inode->i_nlink = 0;     /* It is unlinked */
-       /* notify everyone as to the change of file size */
--      error = do_truncate(dentry, size, 0, file);
-+      error = do_truncate(dentry, file->f_path.mnt, size, 0, file);
-       if (error < 0)
-               goto close_file;
-diff -uprN e/net/unix/af_unix.c f/net/unix/af_unix.c
---- e/net/unix/af_unix.c       2008-04-17 02:49:44.000000000 +0000
-+++ f/net/unix/af_unix.c       2008-05-28 20:29:28.910241000 +0000
-@@ -819,7 +819,8 @@ static int unix_bind(struct socket *sock
-                */
-               mode = S_IFSOCK |
-                      (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
--              err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0, NULL);
-+              err = vfs_mknod(nd.path.dentry->d_inode, dentry, nd.path.mnt,
-+                              mode, 0, NULL);
-               if (err)
-                       goto out_mknod_dput;
-               mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
-diff -uprN e/security/Kconfig f/security/Kconfig
---- e/security/Kconfig 2008-04-17 02:49:44.000000000 +0000
-+++ f/security/Kconfig 2008-05-28 20:29:29.410207000 +0000
-@@ -124,6 +124,7 @@ config SECURITY_DEFAULT_MMAP_MIN_ADDR
- source security/selinux/Kconfig
- source security/smack/Kconfig
-+source security/apparmor/Kconfig
- endmenu
-diff -uprN e/security/Makefile f/security/Makefile
---- e/security/Makefile        2008-04-17 02:49:44.000000000 +0000
-+++ f/security/Makefile        2008-05-28 20:29:29.410207000 +0000
-@@ -16,5 +16,6 @@ obj-$(CONFIG_SECURITY)                       += security.o d
- # Must precede capability.o in order to stack properly.
- obj-$(CONFIG_SECURITY_SELINUX)                += selinux/built-in.o
- obj-$(CONFIG_SECURITY_SMACK)          += commoncap.o smack/built-in.o
-+obj-$(CONFIG_SECURITY_APPARMOR)               += commoncap.o apparmor/
- obj-$(CONFIG_SECURITY_CAPABILITIES)   += commoncap.o capability.o
- obj-$(CONFIG_SECURITY_ROOTPLUG)               += commoncap.o root_plug.o
-diff -uprN e/security/apparmor/Kconfig f/security/apparmor/Kconfig
---- e/security/apparmor/Kconfig        1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/Kconfig        2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,42 @@
-+config SECURITY_APPARMOR
-+      bool "AppArmor support"
-+      depends on SECURITY
-+      select AUDIT
-+      help
-+        This enables the AppArmor security module.
-+        Required userspace tools (if they are not included in your
-+        distribution) and further information may be found at
-+        <http://forge.novell.com/modules/xfmod/project/?apparmor>
 +
-+        If you are unsure how to answer this question, answer N.
++void apparmor_bprm_committed_creds(struct linux_binprm *bprm)
++{
++      /* TODO: cleanup signals - ipc mediation */
++      return;
++}
 +
-+config SECURITY_APPARMOR_BOOTPARAM_VALUE
-+      int "AppArmor boot parameter default value"
-+      depends on SECURITY_APPARMOR
-+      range 0 1
-+      default 1
-+      help
-+        This option sets the default value for the kernel parameter
-+        'apparmor', which allows AppArmor to be enabled or disabled
-+          at boot.  If this option is set to 0 (zero), the AppArmor
-+        kernel parameter will default to 0, disabling AppArmor at
-+        bootup.  If this option is set to 1 (one), the AppArmor
-+        kernel parameter will default to 1, enabling AppArmor at
-+        bootup.
++/**
++ * aa_change_hat - change hat to/from subprofile
++ * @hat_name: hat to change to
++ * @token: magic value to validate the hat change
++ * @permtest: true if this is just a permission test
++ *
++ * Change to new @hat_name, and store the @hat_magic in the current task
++ * context.  If the new @hat_name is %NULL and the @token matches that
++ * stored in the current task context and is not 0, return to the top level
++ * profile.
++ * Returns %0 on success, error otherwise.
++ */
++int aa_change_hat(const char *hat_name, u64 token, int permtest)
++{
++      const struct cred *cred;
++      struct aa_task_context *cxt;
++      struct aa_profile *profile, *previous_profile, *hat = NULL;
++      struct aa_audit_file sa;
 +
-+        If you are unsure how to answer this question, answer 1.
++      memset(&sa, 0, sizeof(sa));
++      sa.base.gfp_mask = GFP_KERNEL;
++      sa.base.operation = "change_hat";
 +
-+config SECURITY_APPARMOR_DISABLE
-+      bool "AppArmor runtime disable"
-+      depends on SECURITY_APPARMOR
-+      default n
-+      help
-+        This option enables writing to a apparmorfs node 'disable', which
-+        allows AppArmor to be disabled at runtime prior to the policy load.
-+        AppArmor will then remain disabled until the next boot.
-+        This option is similar to the apparmor.enabled=0 boot parameter,
-+        but is to support runtime disabling of AppArmor, e.g. from
-+        /sbin/init, for portability across platforms where boot
-+        parameters are difficult to employ.
++      cred = aa_current_policy(&profile);
++      cxt = cred->security;
++      previous_profile = cxt->sys.previous;
++      token = cxt->sys.token;
 +
-+        If you are unsure how to answer this question, answer N.
-diff -uprN e/security/apparmor/Makefile f/security/apparmor/Makefile
---- e/security/apparmor/Makefile       1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/Makefile       2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,18 @@
-+# Makefile for AppArmor Linux Security Module
-+#
-+obj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o
++      if (!profile) {
++              sa.base.info = "unconfined";
++              sa.base.error = -EPERM;
++              goto audit;
++      }
 +
-+apparmor-y := main.o list.o procattr.o lsm.o apparmorfs.o \
-+            module_interface.o match.o
++      if (hat_name) {
++              if (previous_profile)
++                      sa.name = previous_profile->fqname;
++              else
++                      sa.name = profile->fqname;
 +
-+quiet_cmd_make-caps = GEN     $@
-+cmd_make-caps = sed -n -e "/CAP_FS_MASK/d" -e "s/^\#define[ \\t]\\+CAP_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\$$/[\\2]  = \"\\1\",/p" $< | tr A-Z a-z > $@
++              sa.name2 = profile->ns->base.name;
 +
-+quiet_cmd_make-af = GEN     $@
-+cmd_make-af = sed -n -e "/AF_MAX/d" -e "/AF_LOCAL/d" -e "s/^\#define[ \\t]\\+AF_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\\(.*\\)\$$/[\\2]  = \"\\1\",/p" $< | tr A-Z a-z > $@
++              if (PROFILE_IS_HAT(profile))
++                      hat = aa_find_child(profile->parent, hat_name);
++              else
++                      hat = aa_find_child(profile, hat_name);
++              if (!hat) {
++                      sa.base.info = "hat not found";
++                      sa.base.error = -ENOENT;
++                      if (permtest || !PROFILE_COMPLAIN(profile))
++                              goto audit;
++                      hat = aa_alloc_null_profile(profile, 1);
++                      if (!hat) {
++                              sa.base.info = "failed null profile create";
++                              sa.base.error = -ENOMEM;
++                              goto audit;
++                      }
++              } else if (!PROFILE_IS_HAT(hat)) {
++                      sa.base.info = "target not hat";
++                      sa.base.error = -EPERM;
++                      goto audit;
++              }
 +
-+$(obj)/main.o : $(obj)/capability_names.h $(obj)/af_names.h
-+$(obj)/capability_names.h : $(srctree)/include/linux/capability.h
-+      $(call cmd,make-caps)
-+$(obj)/af_names.h : $(srctree)/include/linux/socket.h
-+      $(call cmd,make-af)
-diff -uprN e/security/apparmor/apparmor.h f/security/apparmor/apparmor.h
---- e/security/apparmor/apparmor.h     1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/apparmor.h     2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,403 @@
-+/*
-+ *    Copyright (C) 1998-2007 Novell/SUSE
++              sa.base.error = aa_may_change_ptraced_domain(current, hat);
++              if (sa.base.error) {
++                      sa.base.info = "ptraced";
++                      sa.base.error = -EPERM;
++                      goto audit;
++              }
++
++              if (!permtest) {
++                      sa.base.error = aa_set_current_hat(hat, token);
++                      if (sa.base.error == -EACCES) {
++                              (void)send_sig_info(SIGKILL, NULL, current);
++                              sa.base.error = aa_audit(AUDIT_APPARMOR_KILL,
++                                                       profile, &sa.base,
++                                                       file_audit_cb);
++                              goto out;
++                      }
++              }
++      } else if (previous_profile)
++              sa.base.error = aa_restore_previous_profile(token);
++      /* else
++               ignore restores when there is no saved profile
++      */
++
++audit:
++      if (!permtest)
++              sa.base.error = aa_audit_file(profile, &sa);
++
++
++out:
++      aa_put_profile(hat);
++
++      return sa.base.error;
++}
++
++/**
++ * aa_change_profile - perform a one-way profile transition
++ * @ns_name: name of the profile namespace to change to
++ * @fqname: name of profile to change to
++ * @onexec: whether this transition is to take place immediately or at exec
++ * @permtest: true if this is just a permission test
 + *
-+ *    This program is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU General Public License as
-+ *    published by the Free Software Foundation, version 2 of the
-+ *    License.
++ * Change to new profile @name.  Unlike with hats, there is no way
++ * to change back.  If @onexec then the transition is delayed until
++ * the next exec.
 + *
-+ *    AppArmor internal prototypes
++ * Returns %0 on success, error otherwise.
 + */
++int aa_change_profile(const char *ns_name, const char *fqname, int onexec,
++                    int permtest)
++{
++      const struct cred *cred;
++      struct aa_task_context *cxt;
++      struct aa_profile *profile, *target = NULL;
++      struct aa_namespace *ns = NULL;
++      struct aa_audit_file sa;
++      char *name = NULL;
 +
-+#ifndef __APPARMOR_H
-+#define __APPARMOR_H
++      if (!name && !ns_name)
++              return -EINVAL;
 +
-+#include <linux/sched.h>
-+#include <linux/fs.h>
-+#include <linux/binfmts.h>
-+#include <linux/rcupdate.h>
-+#include <linux/resource.h>
-+#include <linux/socket.h>
-+#include <net/sock.h>
++      memset(&sa, 0, sizeof(sa));
++      sa.base.gfp_mask = GFP_KERNEL;
++      if (onexec)
++              sa.base.operation = "change_onexec";
++      else
++              sa.base.operation = "change_profile";
++
++      cred = aa_current_policy(&profile);
++      cxt = cred->security;
++      ns = aa_get_namespace(cxt->sys.profile->ns);
++
++      if (ns_name) {
++              sa.name2 = ns_name;
++              aa_put_namespace(ns);
++              ns = aa_find_namespace(ns_name);
++              if (!ns) {
++                      /* we don't create new namespace in complain mode */
++                      sa.base.info = "namespace not found";
++                      sa.base.error = -ENOENT;
++                      goto audit;
++              }
++      } else
++              sa.name2 = ns->base.name;
++
++      /* if the name was not specified, use the name of the current profile */
++      if (!fqname) {
++              if (!profile)
++                      fqname = ns->unconfined->fqname;
++              else
++                      fqname = profile->fqname;
++      }
++      sa.name = fqname;
++
++      sa.perms = change_profile_perms(profile, ns, fqname, NULL);
++
++      if (!(sa.perms.allowed & AA_MAY_CHANGE_PROFILE)) {
++              sa.base.error = -EACCES;
++              goto audit;
++      }
++
++      target = aa_find_profile_by_fqname(ns, fqname);
++      if (!target) {
++              sa.base.info = "profile not found";
++              sa.base.error = -ENOENT;
++              if (permtest || !PROFILE_COMPLAIN(profile))
++                      goto audit;
++              target = aa_alloc_null_profile(profile, 0);
++      }
++      
++      /* check if tracing task is allowed to trace target domain */
++      sa.base.error = aa_may_change_ptraced_domain(current, target);
++      if (sa.base.error) {
++              sa.base.info = "ptrace prevents transition";
++              goto audit;
++      }
++
++      if (permtest)
++              goto audit;
++
++      if (onexec)
++              sa.base.error = aa_set_current_onexec(target);
++      else
++              sa.base.error = aa_replace_current_profiles(target);
 +
++audit:
++      if (!permtest)
++              sa.base.error = aa_audit_file(profile, &sa);
++
++      aa_put_namespace(ns);
++      aa_put_profile(target);
++
++      return sa.base.error;
++}
+diff --git a/security/apparmor/file.c b/security/apparmor/file.c
+new file mode 100644
+index 0000000..fdade01
+--- /dev/null
++++ b/security/apparmor/file.c
+@@ -0,0 +1,425 @@
 +/*
-+ * We use MAY_READ, MAY_WRITE, MAY_EXEC, MAY_APPEND and the following flags
-+ * for profile permissions
++ * AppArmor security module
++ *
++ * This file contains AppArmor mediation of files
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
 + */
-+#define AA_MAY_LINK                   0x0010
-+#define AA_MAY_LOCK                   0x0020
-+#define AA_EXEC_MMAP                  0x0040
-+#define AA_MAY_MOUNT                  0x0080  /* no direct audit mapping */
-+#define AA_EXEC_UNSAFE                        0x0100
-+#define AA_EXEC_INHERIT                       0x0200
-+#define AA_EXEC_MOD_0                 0x0400
-+#define AA_EXEC_MOD_1                 0x0800
-+#define AA_EXEC_MOD_2                 0x1000
-+#define AA_EXEC_MOD_3                 0x2000
 +
-+#define AA_BASE_PERMS                 (MAY_READ | MAY_WRITE | MAY_EXEC | \
-+                                       MAY_APPEND | AA_MAY_LINK | \
-+                                       AA_MAY_LOCK | AA_EXEC_MMAP | \
-+                                       AA_MAY_MOUNT | AA_EXEC_UNSAFE | \
-+                                       AA_EXEC_INHERIT | AA_EXEC_MOD_0 | \
-+                                       AA_EXEC_MOD_1 | AA_EXEC_MOD_2 | \
-+                                       AA_EXEC_MOD_3)
++#include "include/apparmor.h"
++#include "include/audit.h"
++#include "include/file.h"
++#include "include/match.h"
++#include "include/path.h"
++#include "include/policy.h"
++
++struct file_perms nullperms;
++
++static void aa_audit_file_sub_mask(struct audit_buffer *ab, char *buffer,
++                                 u16 mask, u16 xindex)
++{
++
++  /*  const char xchar[] = "PpCc";*/
++
++      char *m = buffer;
++
++      if (mask & AA_EXEC_MMAP)
++              *m++ = 'm';
++      if (mask & MAY_READ)
++              *m++ = 'r';
++      if (mask & (MAY_WRITE | AA_MAY_CREATE))
++              *m++ = 'w';
++      else if (mask & MAY_APPEND)
++              *m++ = 'a';
++      if (mask & AA_MAY_LINK)
++              *m++ = 'l';
++      if (mask & AA_MAY_LOCK)
++              *m++ = 'k';
++      if (mask & MAY_EXEC) {
++              *m++ = 'x';
++
++/* FIXME: only want more advanced auditing of x if in audit/hint mode
++              u16 index = xindex & AA_X_INDEX_MASK;
++              u16 xtype = xindex & AA_X_TYPE_MASK;
++              if (xtype > AA_X_NONE)
++                      *m++ = xchar[(xindex >> 12) & 0x3];
++              if (xindex & AA_X_INHERIT) {
++                      *m++ = 'i';
++              } else if (xindex & AA_X_UNCONFINED) {
++                      if (xindex & AA_X_UNSAFE)
++                              *m++ = 'u';
++                      else
++                              *m++ = 'U';
++              }
++              *m++ = 'x';
++              / * at most 7 character including trailing \0 * /
++              if (xtype == AA_X_VARIABLE) {
++                      m += sprintf(m, "->v%x", index);
++              } else if (xtype == AA_X_TABLE) {
++                      m += sprintf(m, "->n%x", index);
++              }
++*/
++      }
++      *m++ = '\0';
++}
 +
-+#define AA_EXEC_MODIFIERS             (AA_EXEC_MOD_0 | AA_EXEC_MOD_1 | \
-+                                       AA_EXEC_MOD_2 | AA_EXEC_MOD_3)
++static void aa_audit_file_mask(struct audit_buffer *ab, const char *name,
++                             u16 mask, int xindex, int owner)
++{
++/*    char str[18]; */
++      char str[10];
 +
-+#define AA_EXEC_TYPE                  (AA_EXEC_UNSAFE | AA_EXEC_INHERIT | \
-+                                       AA_EXEC_MODIFIERS)
++      aa_audit_file_sub_mask(ab, str, mask, xindex);
++      if (owner)
++              audit_log_format(ab, " %s=\"%s::\"", name, str);
++      else
++              audit_log_format(ab, " %s=\"::%s\"", name, str);
++}
 +
-+#define AA_EXEC_UNCONFINED            AA_EXEC_MOD_0
-+#define AA_EXEC_PROFILE                       AA_EXEC_MOD_1
-+#define AA_EXEC_CHILD                 (AA_EXEC_MOD_0 | AA_EXEC_MOD_1)
-+/* remaining exec modes are index into profile name table */
-+#define AA_EXEC_INDEX(mode)           ((mode & AA_EXEC_MODIFIERS) >> 10)
++void file_audit_cb(struct audit_buffer *ab, void *va)
++{
++      struct aa_audit_file *sa = va;
++      u16 denied = sa->request & ~sa->perms.allowed;
++      uid_t fsuid;
 +
-+#define AA_USER_SHIFT                 0
-+#define AA_OTHER_SHIFT                        14
++      if (sa->base.task)
++              fsuid = task_uid(sa->base.task);
++      else
++              fsuid = current_fsuid();
 +
-+#define AA_USER_PERMS                 (AA_BASE_PERMS << AA_USER_SHIFT)
-+#define AA_OTHER_PERMS                        (AA_BASE_PERMS << AA_OTHER_SHIFT)
++      if (sa->request & AA_AUDIT_FILE_MASK)
++              aa_audit_file_mask(ab, "requested_mask", sa->request,
++                                 AA_X_NONE, fsuid == sa->cond->uid);
 +
-+#define AA_FILE_PERMS                 (AA_USER_PERMS | AA_OTHER_PERMS)
++      if (denied & AA_AUDIT_FILE_MASK)
++              aa_audit_file_mask(ab, "denied_mask", denied, sa->perms.xindex,
++                      fsuid == sa->cond->uid);
 +
-+#define AA_LINK_BITS                  ((AA_MAY_LINK << AA_USER_SHIFT) | \
-+                                       (AA_MAY_LINK << AA_OTHER_SHIFT))
++      if (sa->request & AA_AUDIT_FILE_MASK) {
++              audit_log_format(ab, " fsuid=%d", fsuid);
++              audit_log_format(ab, " ouid=%d", sa->cond->uid);
++      }
 +
-+#define AA_USER_EXEC                  (MAY_EXEC << AA_USER_SHIFT)
-+#define AA_OTHER_EXEC                 (MAY_EXEC << AA_OTHER_SHIFT)
++      if (sa->name) {
++              audit_log_format(ab, " name=");
++              audit_log_untrustedstring(ab, sa->name);
++      }
 +
-+#define AA_USER_EXEC_TYPE             (AA_EXEC_TYPE << AA_USER_SHIFT)
-+#define AA_OTHER_EXEC_TYPE            (AA_EXEC_TYPE << AA_OTHER_SHIFT)
++      if (sa->name2) {
++              audit_log_format(ab, " name2=");
++              audit_log_untrustedstring(ab, sa->name2);
++      }
 +
-+#define AA_EXEC_BITS                  (AA_USER_EXEC | AA_OTHER_EXEC)
++      if (sa->name3) {
++              audit_log_format(ab, " name3=");
++              audit_log_untrustedstring(ab, sa->name3);
++      }
++}
 +
-+#define ALL_AA_EXEC_UNSAFE            ((AA_EXEC_UNSAFE << AA_USER_SHIFT) | \
-+                                       (AA_EXEC_UNSAFE << AA_OTHER_SHIFT))
++int aa_audit_file(struct aa_profile *profile, struct aa_audit_file *sa)
++{
++      int type = AUDIT_APPARMOR_AUTO;
 +
-+#define ALL_AA_EXEC_TYPE              (AA_USER_EXEC_TYPE | AA_OTHER_EXEC_TYPE)
++      if (likely(!sa->base.error)) {
++              u16 mask = sa->perms.audit;
 +
-+/* overloaded permissions for link pairs */
-+#define AA_LINK_SUBSET_TEST           0x0020
++              if (unlikely(PROFILE_AUDIT_MODE(profile) == AUDIT_ALL))
++                      mask = 0xffff;
 +
-+#define AA_USER_PTRACE                        0x10000000
-+#define AA_OTHER_PTRACE                       0x20000000
-+#define AA_PTRACE_PERMS                       (AA_USER_PTRACE | AA_OTHER_PTRACE)
++              /* mask off perms that are not being force audited */
++              sa->request &= mask;
 +
-+/* shared permissions that are not duplicated in user::other */
-+#define AA_CHANGE_HAT                 0x40000000
-+#define AA_CHANGE_PROFILE             0x80000000
++              if (likely(!sa->request))
++                      return 0;
++      } else {
++              /* quiet auditing of specific known rejects */
++              u16 mask = sa->perms.quiet;
++              u16 denied = sa->request & ~sa->perms.allowed;
 +
-+#define AA_SHARED_PERMS                       (AA_CHANGE_HAT | AA_CHANGE_PROFILE)
++              if (denied & sa->perms.kill)
++                      type = AUDIT_APPARMOR_KILL;
 +
-+#define AA_VALID_PERM_MASK            (AA_FILE_PERMS | AA_PTRACE_PERMS | \
-+                                       AA_SHARED_PERMS)
++              /* assumes quiet and kill do not overlap */
++              if ((denied & mask) &&
++                  PROFILE_AUDIT_MODE(profile) != AUDIT_NOQUIET &&
++                  PROFILE_AUDIT_MODE(profile) != AUDIT_ALL)
++                      sa->request &= ~mask;
 +
-+/* audit bits for the second accept field */
-+#define AUDIT_FILE_MASK 0x1fc07f
-+#define AUDIT_QUIET_MASK(mask)                ((mask >> 7) & AUDIT_FILE_MASK)
-+#define AA_VALID_PERM2_MASK           0x0fffffff
++              if (!sa->request)
++                      return PROFILE_COMPLAIN(profile) ? 0 : sa->base.error;
++      }
++      return aa_audit(type, profile, (struct aa_audit *)sa, file_audit_cb);
++}
 +
-+#define AA_SECURE_EXEC_NEEDED         1
++/* FIXME: convert from dfa + state to permission entry */
++struct file_perms aa_compute_perms(struct aa_dfa *dfa, unsigned int state,
++                                 struct path_cond *cond)
++{
++      struct file_perms perms;
 +
-+/* Control parameters (0 or 1), settable thru module/boot flags or
-+ * via /sys/kernel/security/apparmor/control */
-+extern int apparmor_complain;
-+extern int apparmor_debug;
-+extern int apparmor_audit;
-+extern int apparmor_logsyscall;
-+extern unsigned int apparmor_path_max;
++      /* FIXME: change over to new dfa format */
++      /* currently file perms are encoded in the dfa */
++      perms.kill = 0;
++      perms.dindex = 0;
 +
-+#define PROFILE_COMPLAIN(_profile) \
-+      (apparmor_complain == 1 || ((_profile) && (_profile)->flags.complain))
++      if (current_fsuid() == cond->uid) {
++              perms.allowed = dfa_user_allow(dfa, state);
++              perms.audit = dfa_user_audit(dfa, state);
++              perms.quiet = dfa_user_quiet(dfa, state);
++              perms.xindex = dfa_user_xindex(dfa, state);
++      } else {
++              perms.allowed = dfa_other_allow(dfa, state);
++              perms.audit = dfa_other_audit(dfa, state);
++              perms.quiet = dfa_other_quiet(dfa, state);
++              perms.xindex = dfa_other_xindex(dfa, state);
++      }
++      /* in the old mapping MAY_WRITE implies AA_MAY_CREATE */
++      perms.allowed |= (perms.allowed & MAY_WRITE) << 6;
++      perms.audit |= (perms.audit & MAY_WRITE) << 6;
++      perms.quiet |= (perms.quiet & MAY_WRITE) << 6;
++
++      /* in the old mapping AA_MAY_LOCK and link subset are overlayed
++       * and only determined by which part of a pair they are  in
++       */
++      if (perms.allowed & AA_MAY_LOCK)
++              perms.allowed |= AA_LINK_SUBSET;
 +
-+#define APPARMOR_COMPLAIN(_cxt) \
-+      (apparmor_complain == 1 || \
-+       ((_cxt) && (_cxt)->profile && (_cxt)->profile->flags.complain))
++      /* change_profile wasn't determined by ownership in old mapping */
++      if (ACCEPT_TABLE2(dfa)[state] & 0x80000000)
++              perms.allowed |= AA_MAY_CHANGE_PROFILE;
 +
-+#define PROFILE_AUDIT(_profile) \
-+      (apparmor_audit == 1 || ((_profile) && (_profile)->flags.audit))
++      return perms;
++}
 +
-+#define APPARMOR_AUDIT(_cxt) \
-+      (apparmor_audit == 1 || \
-+       ((_cxt) && (_cxt)->profile && (_cxt)->profile->flags.audit))
++struct file_perms aa_str_perms(struct aa_dfa *dfa, unsigned int start,
++                             const char *name, struct path_cond *cond,
++                             unsigned int *rstate)
++{
++      unsigned int state;
++      if (!dfa)
++              return nullperms;
 +
-+#define PROFILE_IS_HAT(_profile) \
-+      ((_profile) && (_profile)->flags.hat)
++      state = aa_dfa_match(dfa, start, name);
 +
-+/*
-+ * DEBUG remains global (no per profile flag) since it is mostly used in sysctl
-+ * which is not related to profile accesses.
-+ */
++      if (rstate)
++              *rstate = state;
 +
-+#define AA_DEBUG(fmt, args...)                                                \
-+      do {                                                            \
-+              if (apparmor_debug)                                     \
-+                      printk(KERN_DEBUG "AppArmor: " fmt, ##args);    \
-+      } while (0)
++      /* TODO: convert to new dfa format */
 +
-+#define AA_ERROR(fmt, args...)        do { if (printk_ratelimit()) printk(KERN_ERR "AppArmor: " fmt, ##args); } while (0)
++      return aa_compute_perms(dfa, state, cond);
++}
 +
-+/* struct aa_rlimit - rlimits settings for the profile
-+ * @mask: which hard limits to set
-+ * @limits: rlimit values that override task limits
-+ *
-+ * AppArmor rlimits are used to set confined task rlimits.  Only the
-+ * limits specified in @mask will be controlled by apparmor.
-+ */
-+struct aa_rlimit {
-+      unsigned int mask;
-+      struct rlimit limits[RLIM_NLIMITS];
-+};
++int aa_pathstr_perm(struct aa_profile *profile, const char *op,
++                  const char *name, u16 request, struct path_cond *cond)
++{
++      struct aa_audit_file sa;
 +
-+struct aa_profile;
++      memset(&sa, 0, sizeof(sa));
++      sa.base.operation = op;
++      sa.base.gfp_mask = GFP_KERNEL;
++      sa.request = request;
++      sa.name = name;
++      sa.cond = cond;
 +
-+/* struct aa_namespace - namespace for a set of profiles
-+ * @name: the name of the namespace
-+ * @list: list the namespace is on
-+ * @profiles: list of profile in the namespace
-+ * @profile_count: the number of profiles in the namespace
-+ * @null_complain_profile: special profile used for learning in this namespace
-+ * @count: reference count on the namespace
-+ * @lock: lock for adding/removing profile to the namespace
-+ */
-+struct aa_namespace {
-+      char *name;
-+      struct list_head list;
-+      struct list_head profiles;
-+      int profile_count;
-+      struct aa_profile *null_complain_profile;
++      sa.perms = aa_str_perms(profile->file.dfa, DFA_START, sa.name, cond,
++                              NULL);
++      if (request & ~sa.perms.allowed)
++              sa.base.error = -EACCES;
++      return aa_audit_file(profile, &sa);
++}
 +
-+      struct kref count;
-+      rwlock_t lock;
-+};
++int aa_path_perm(struct aa_profile *profile, const char *operation,
++               struct path *path, u16 request, struct path_cond *cond)
++{
++      struct aa_audit_file sa;
++      char *buffer, *name;
 +
-+/* struct aa_profile - basic confinement data
-+ * @name: the profiles name
-+ * @list: list this profile is on
-+ * @ns: namespace the profile is in
-+ * @file_rules: dfa containing the profiles file rules
-+ * @flags: flags controlling profile behavior
-+ * @isstale: flag indicating if profile is stale
-+ * @set_caps: capabilities that are being set
-+ * @capabilities: capabilities mask
-+ * @audit_caps: caps that are to be audited
-+ * @quiet_caps: caps that should not be audited
-+ * @capabilities: capabilities granted by the process
-+ * @rlimits: rlimits for the profile
-+ * @task_count: how many tasks the profile is attached to
-+ * @count: reference count of the profile
-+ * @task_contexts: list of tasks confined by profile
-+ * @lock: lock for the task_contexts list
-+ * @network_families: basic network permissions
-+ * @audit_network: which network permissions to force audit
-+ * @quiet_network: which network permissions to quiet rejects
-+ *
-+ * The AppArmor profile contains the basic confinement data.  Each profile
-+ * has a name, and all nonstale profile are in a profile namespace.
-+ *
-+ * The task_contexts list and the isstale flag are protected by the
-+ * profile lock.
-+ *
-+ * If a task context is moved between two profiles, we first need to grab
-+ * both profile locks. lock_both_profiles() does that in a deadlock-safe
-+ * way.
-+ */
-+struct aa_profile {
-+      char *name;
-+      struct list_head list;
-+      struct aa_namespace *ns;
++      memset(&sa, 0, sizeof(sa));
++      sa.base.operation = operation;
++      sa.base.gfp_mask = GFP_KERNEL;
++      sa.request = request;
++      sa.cond = cond;
 +
-+      int exec_table_size;
-+      char **exec_table;
-+      struct aa_dfa *file_rules;
-+      struct {
-+              int hat;
-+              int complain;
-+              int audit;
-+      } flags;
-+      int isstale;
-+
-+      kernel_cap_t set_caps;
-+      kernel_cap_t capabilities;
-+      kernel_cap_t audit_caps;
-+      kernel_cap_t quiet_caps;
++      sa.base.error = aa_get_name(path, S_ISDIR(cond->mode), &buffer,
++                                  &name);
++      sa.name = name;
++      if (sa.base.error) {
++              sa.perms = nullperms;
++              if (sa.base.error == -ENOENT)
++                      sa.base.info = "Failed name lookup - deleted entry";
++              else if (sa.base.error == -ESTALE)
++                      sa.base.info = "Failed name lookup - disconnected path";
++              else if (sa.base.error == -ENAMETOOLONG)
++                      sa.base.info = "Failed name lookup - name too long";
++              else
++                      sa.base.info = "Failed name lookup";
++      } else {
++              sa.perms = aa_str_perms(profile->file.dfa, DFA_START, sa.name,
++                                      cond, NULL);
++              if (request & ~sa.perms.allowed)
++                      sa.base.error = -EACCES;
++      }
++      sa.base.error = aa_audit_file(profile, &sa);
++      kfree(buffer);
 +
-+      struct aa_rlimit rlimits;
-+      unsigned int task_count;
++      return sa.base.error;
++}
 +
-+      struct kref count;
-+      struct list_head task_contexts;
-+      spinlock_t lock;
-+      unsigned long int_flags;
-+      u16 network_families[AF_MAX];
-+      u16 audit_network[AF_MAX];
-+      u16 quiet_network[AF_MAX];
-+};
++int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
++               struct path *new_dir, struct dentry *new_dentry)
++{
++      struct path link = { new_dir->mnt, new_dentry };
++      struct path target = { new_dir->mnt, old_dentry };
++      struct path_cond cond = { old_dentry->d_inode->i_uid,
++                                old_dentry->d_inode->i_mode };
++      char *buffer = NULL, *buffer2 = NULL;
++      char *lname, *tname;
++      struct file_perms perms;
++      unsigned int state;
 +
-+extern struct list_head profile_ns_list;
-+extern rwlock_t profile_ns_list_lock;
-+extern struct mutex aa_interface_lock;
++      struct aa_audit_file sa;
++      memset(&sa, 0, sizeof(sa));
++      sa.base.operation = "link";
++      sa.base.gfp_mask = GFP_KERNEL;
++      sa.request = AA_MAY_LINK;
++      sa.cond = &cond;
++      sa.perms = nullperms;
 +
-+/**
-+ * struct aa_task_context - primary label for confined tasks
-+ * @profile: the current profile
-+ * @previous_profile: profile the task may return to
-+ * @cookie: magic value the task must know for returning to @previous_profile
-+ * @list: list this aa_task_context is on
-+ * @task: task that the aa_task_context confines
-+ * @rcu: rcu head used when freeing the aa_task_context
-+ * @caps_logged: caps that have previously generated log entries
-+ *
-+ * Contains the task's current profile (which could change due to
-+ * change_hat).  Plus the hat_magic needed during change_hat.
-+ */
-+struct aa_task_context {
-+      struct aa_profile *profile;
-+      struct aa_profile *previous_profile;
-+      u64 cookie;
-+      struct list_head list;
-+      struct task_struct *task;
-+      struct rcu_head rcu;
-+      kernel_cap_t caps_logged;
-+};
++      sa.base.error = aa_get_name(&link, 0, &buffer, &lname);
++      sa.name = lname;
++      if (sa.base.error)
++              goto audit;
 +
-+extern struct aa_namespace *default_namespace;
++      sa.base.error = aa_get_name(&target, 0, &buffer2, &tname);
++      sa.name2 = tname;
++      if (sa.base.error)
++              goto audit;
 +
-+/* aa_audit - AppArmor auditing structure
-+ * Structure is populated by access control code and passed to aa_audit which
-+ * provides for a single point of logging.
-+ */
 +
-+struct aa_audit {
-+      const char *operation;
-+      gfp_t gfp_mask;
-+      const char *info;
-+      const char *name;
-+      const char *name2;
-+      const char *name3;
-+      int request_mask, denied_mask, audit_mask;
-+      int rlimit;
-+      struct iattr *iattr;
-+      pid_t task, parent;
-+      int family, type, protocol;
-+      int error_code;
-+};
++      sa.perms = aa_str_perms(profile->file.dfa, DFA_START, sa.name, &cond,
++                           &state);
++      sa.perms.audit &= AA_MAY_LINK;
++      sa.perms.quiet &= AA_MAY_LINK;
++      sa.perms.kill &= AA_MAY_LINK;
 +
-+/* Flags for the permission check functions */
-+#define AA_CHECK_FD   1  /* coming from a file descriptor */
-+#define AA_CHECK_DIR  2  /* file type is directory */
++      if (!(sa.perms.allowed & AA_MAY_LINK)) {
++              sa.base.error = -EACCES;
++              goto audit;
++      }
 +
-+/* lock subtypes so lockdep does not raise false dependencies */
-+enum aa_lock_class {
-+      aa_lock_normal,
-+      aa_lock_nested,
-+      aa_lock_task_release
-+};
++      /* test to see if target can be paired with link */
++      state = aa_dfa_null_transition(profile->file.dfa, state);
++      perms = aa_str_perms(profile->file.dfa, state, sa.name2, &cond, NULL);
++      if (!(perms.allowed & AA_MAY_LINK)) {
++              sa.base.error = -EACCES;
++              sa.base.info = "target restricted";
++              goto audit;
++      }
 +
-+/* main.c */
-+extern int alloc_default_namespace(void);
-+extern void free_default_namespace(void);
-+extern int aa_audit_message(struct aa_profile *profile, struct aa_audit *sa,
-+                          int type);
-+void aa_audit_hint(struct aa_profile *profile, struct aa_audit *sa);
-+void aa_audit_status(struct aa_profile *profile, struct aa_audit *sa);
-+int aa_audit_reject(struct aa_profile *profile, struct aa_audit *sa);
-+extern int aa_audit_syscallreject(struct aa_profile *profile, gfp_t gfp,
-+                                const char *);
-+extern int aa_audit(struct aa_profile *profile, struct aa_audit *);
-+
-+extern int aa_attr(struct aa_profile *profile, struct dentry *dentry,
-+                 struct vfsmount *mnt, struct iattr *iattr);
-+extern int aa_perm_xattr(struct aa_profile *profile, const char *operation,
-+                       struct dentry *dentry, struct vfsmount *mnt,
-+                       int mask, int check);
-+extern int aa_capability(struct aa_task_context *cxt, int cap);
-+extern int aa_perm(struct aa_profile *profile, const char *operation,
-+                 struct dentry *dentry, struct vfsmount *mnt, int mask,
-+                 int check);
-+extern int aa_perm_dir(struct aa_profile *profile, const char *operation,
-+                     struct dentry *dentry, struct vfsmount *mnt,
-+                     int mask);
-+extern int aa_perm_path(struct aa_profile *, const char *operation,
-+                      const char *name, int mask, uid_t uid);
-+extern int aa_link(struct aa_profile *profile,
-+                 struct dentry *link, struct vfsmount *link_mnt,
-+                 struct dentry *target, struct vfsmount *target_mnt);
-+extern int aa_clone(struct task_struct *task);
-+extern int aa_register(struct linux_binprm *bprm);
-+extern void aa_release(struct task_struct *task);
-+extern int aa_change_hat(const char *id, u64 hat_magic);
-+extern int aa_change_profile(const char *ns_name, const char *name);
-+extern struct aa_profile *__aa_replace_profile(struct task_struct *task,
-+                                             struct aa_profile *profile);
-+extern struct aa_task_context *lock_task_and_profiles(struct task_struct *task,
-+                                                    struct aa_profile *profile);
-+extern void unlock_task_and_profiles(struct task_struct *task,
-+                                   struct aa_task_context *cxt,
-+                                   struct aa_profile *profile);
-+extern void aa_change_task_context(struct task_struct *task,
-+                                 struct aa_task_context *new_cxt,
-+                                 struct aa_profile *profile, u64 cookie,
-+                                 struct aa_profile *previous_profile);
-+extern int aa_may_ptrace(struct aa_task_context *cxt,
-+                       struct aa_profile *tracee);
-+extern int aa_net_perm(struct aa_profile *profile, char *operation,
-+                      int family, int type, int protocol);
-+extern int aa_revalidate_sk(struct sock *sk, char *operation);
-+extern int aa_task_setrlimit(struct aa_profile *profile, unsigned int resource,
-+                           struct rlimit *new_rlim);
-+extern void aa_set_rlimits(struct task_struct *task, struct aa_profile *profile);
++      /* done if link subset test is not required */
++      if (!(perms.allowed & AA_LINK_SUBSET))
++              goto audit;
 +
++      /* Do link perm subset test requiring allowed permission on link are a
++       * subset of the allowed permissions on target.
++       */
++      perms = aa_str_perms(profile->file.dfa, DFA_START, sa.name2, &cond,
++                           NULL);
 +
-+/* lsm.c */
-+extern int apparmor_initialized;
-+extern void info_message(const char *str, const char *name);
-+extern void apparmor_disable(void);
-+
-+/* list.c */
-+extern struct aa_namespace *__aa_find_namespace(const char *name,
-+                                              struct list_head *list);
-+extern struct aa_profile *__aa_find_profile(const char *name,
-+                                          struct list_head *list);
-+extern void aa_profile_ns_list_release(void);
-+
-+/* module_interface.c */
-+extern ssize_t aa_add_profile(void *, size_t);
-+extern ssize_t aa_replace_profile(void *, size_t);
-+extern ssize_t aa_remove_profile(char *, size_t);
-+extern struct aa_namespace *alloc_aa_namespace(char *name);
-+extern void free_aa_namespace(struct aa_namespace *ns);
-+extern void free_aa_namespace_kref(struct kref *kref);
-+extern struct aa_profile *alloc_aa_profile(void);
-+extern void free_aa_profile(struct aa_profile *profile);
-+extern void free_aa_profile_kref(struct kref *kref);
-+extern void aa_unconfine_tasks(struct aa_profile *profile);
-+
-+/* procattr.c */
-+extern int aa_getprocattr(struct aa_profile *profile, char **string,
-+                        unsigned *len);
-+extern int aa_setprocattr_changehat(char *args);
-+extern int aa_setprocattr_changeprofile(char *args);
-+extern int aa_setprocattr_setprofile(struct task_struct *task, char *args);
-+
-+/* apparmorfs.c */
-+extern int create_apparmorfs(void);
-+extern void destroy_apparmorfs(void);
++      /* AA_MAY_LINK is not considered in the subset test */
++      sa.request = sa.perms.allowed & ~AA_MAY_LINK;
++      sa.perms.allowed &= perms.allowed | AA_MAY_LINK;
++
++      sa.request |= AA_AUDIT_FILE_MASK & (sa.perms.allowed & ~perms.allowed);
++      if (sa.request & ~sa.perms.allowed)
++              sa.base.error = -EACCES;
++      else if (sa.perms.allowed & MAY_EXEC) {
++              if (((sa.perms.xindex & ~AA_X_UNSAFE) !=
++                   (perms.xindex &~AA_X_UNSAFE)) ||
++                  ((sa.perms.xindex & AA_X_UNSAFE) &&
++                   !(perms.xindex & AA_X_UNSAFE))) {
++                      sa.perms.allowed &= ~MAY_EXEC;
++                      sa.request |= MAY_EXEC;
++                      sa.base.error = -EACCES;
++                      sa.base.info = "link not subset of target";
++              }
++      }
 +
-+/* match.c */
-+extern struct aa_dfa *aa_match_alloc(void);
-+extern void aa_match_free(struct aa_dfa *dfa);
-+extern int unpack_dfa(struct aa_dfa *dfa, void *blob, size_t size);
-+extern int verify_dfa(struct aa_dfa *dfa);
-+extern unsigned int aa_dfa_match(struct aa_dfa *dfa, const char *str, int *);
-+extern unsigned int aa_dfa_next_state(struct aa_dfa *dfa, unsigned int start,
-+                                    const char *str);
-+extern unsigned int aa_match_state(struct aa_dfa *dfa, unsigned int start,
-+                                 const char *str, unsigned int *final);
-+extern unsigned int aa_dfa_null_transition(struct aa_dfa *dfa,
-+                                         unsigned int start);
-+
-+#endif  /* __APPARMOR_H */
-diff -uprN e/security/apparmor/apparmorfs.c f/security/apparmor/apparmorfs.c
---- e/security/apparmor/apparmorfs.c   1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/apparmorfs.c   2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,279 @@
-+/*
-+ *    Copyright (C) 1998-2007 Novell/SUSE
-+ *
-+ *    This program is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU General Public License as
-+ *    published by the Free Software Foundation, version 2 of the
-+ *
-+ *    AppArmor filesystem (part of securityfs)
-+ */
++audit:
++      sa.base.error = aa_audit_file(profile, &sa);
++      kfree(buffer);
++      kfree(buffer2);
 +
-+#include <linux/security.h>
-+#include <linux/vmalloc.h>
-+#include <linux/module.h>
-+#include <linux/seq_file.h>
-+#include <asm/uaccess.h>
++      return sa.base.error;
++}
 +
-+#include "apparmor.h"
-+#include "inline.h"
 +
-+static char *aa_simple_write_to_buffer(const char __user *userbuf,
-+                                     size_t alloc_size, size_t copy_size,
-+                                     loff_t *pos, const char *operation)
++static inline int aa_is_deleted_file(struct dentry *dentry)
 +{
-+      struct aa_profile *profile;
-+      char *data;
++      if (d_unhashed(dentry) && dentry->d_inode->i_nlink == 0)
++              return 1;
++      return 0;
++}
 +
-+      if (*pos != 0) {
-+              /* only writes from pos 0, that is complete writes */
-+              data = ERR_PTR(-ESPIPE);
-+              goto out;
-+      }
++int aa_file_common_perm(struct aa_profile *profile, const char *operation,
++                      struct file *file, u16 request, const char *name,
++                      int error)
++{
++      struct path_cond cond = { .uid = file->f_path.dentry->d_inode->i_uid,
++                               .mode = file->f_path.dentry->d_inode->i_mode };
++      struct aa_audit_file sa;
 +
-+      /*
-+       * Don't allow confined processes to load/replace/remove profiles.
-+       * No sane person would add rules allowing this to a profile
-+       * but we enforce the restriction anyways.
-+       */
-+      profile = aa_get_profile(current);
-+      if (profile) {
-+              struct aa_audit sa;
-+              memset(&sa, 0, sizeof(sa));
-+              sa.operation = operation;
-+              sa.gfp_mask = GFP_KERNEL;
-+              sa.error_code = -EACCES;
-+              data = ERR_PTR(aa_audit_reject(profile, &sa));
-+              aa_put_profile(profile);
-+              goto out;
++      memset(&sa, 0, sizeof(sa));
++      sa.base.operation = operation;
++      sa.base.gfp_mask = GFP_KERNEL;
++      sa.request = request;
++      sa.base.error = error;
++      sa.name = name;
++      sa.cond = &cond;
++
++      if (sa.base.error) {
++              sa.perms = nullperms;
++              if (sa.base.error == -ENOENT &&
++                  aa_is_deleted_file(file->f_path.dentry)) {
++                      /* Access to open files that are deleted are
++                       * give a pass (implicit delegation
++                       */
++                      sa.base.error = 0;
++                      sa.perms.allowed = sa.request;
++              } else if (sa.base.error == -ENOENT)
++                      sa.base.info = "Failed name lookup - deleted entry";
++              else if (sa.base.error == -ESTALE)
++                      sa.base.info = "Failed name lookup - disconnected path";
++              else if (sa.base.error == -ENAMETOOLONG)
++                      sa.base.info = "Failed name lookup - name too long";
++              else
++                      sa.base.info = "Failed name lookup";
++      } else {
++              sa.perms = aa_str_perms(profile->file.dfa, DFA_START, sa.name,
++                                      &cond, NULL);
++              if (request & ~sa.perms.allowed)
++                      sa.base.error = -EACCES;
 +      }
++      sa.base.error = aa_audit_file(profile, &sa);
 +
-+      data = vmalloc(alloc_size);
-+      if (data == NULL) {
-+              data = ERR_PTR(-ENOMEM);
-+              goto out;
-+      }
++      return sa.base.error;
++}
 +
-+      if (copy_from_user(data, userbuf, copy_size)) {
-+              vfree(data);
-+              data = ERR_PTR(-EFAULT);
-+              goto out;
-+      }
++int aa_file_perm(struct aa_profile *profile, const char *operation,
++               struct file *file, u16 request)
++{
++      char *buffer, *name;
++      umode_t mode = file->f_path.dentry->d_inode->i_mode;
++      int error = aa_get_name(&file->f_path, S_ISDIR(mode), &buffer, &name);
 +
-+out:
-+      return data;
++      error = aa_file_common_perm(profile, operation, file, request, name,
++                                  error);
++      kfree(buffer);
++      return error;
 +}
+diff --git a/security/apparmor/include/apparmor.h b/security/apparmor/include/apparmor.h
+new file mode 100644
+index 0000000..fbbc961
+--- /dev/null
++++ b/security/apparmor/include/apparmor.h
+@@ -0,0 +1,65 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor basic global and lib definitions
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+/* apparmor/profiles */
-+extern struct seq_operations apparmorfs_profiles_op;
++#ifndef __APPARMOR_H
++#define __APPARMOR_H
 +
-+static int aa_profiles_open(struct inode *inode, struct file *file)
-+{
-+      return seq_open(file, &apparmorfs_profiles_op);
-+}
++#include <linux/fs.h>
 +
++/* Control parameters settable thru module/boot flags or
++ * via /sys/kernel/security/apparmor/control */
++extern enum audit_mode g_apparmor_audit;
++extern int g_apparmor_audit_header;
++extern int g_apparmor_debug;
++extern int g_apparmor_lock_policy;
++extern int g_apparmor_logsyscall;
++extern unsigned int g_apparmor_path_max;
 +
-+static int aa_profiles_release(struct inode *inode, struct file *file)
-+{
-+      return seq_release(inode, file);
-+}
 +
-+static struct file_operations apparmorfs_profiles_fops = {
-+      .open =         aa_profiles_open,
-+      .read =         seq_read,
-+      .llseek =       seq_lseek,
-+      .release =      aa_profiles_release,
-+};
++/*
++ * DEBUG remains global (no per profile flag) since it is mostly used in sysctl
++ * which is not related to profile accesses.
++ */
 +
-+/* apparmor/matching */
-+static ssize_t aa_matching_read(struct file *file, char __user *buf,
-+                             size_t size, loff_t *ppos)
-+{
-+      const char *matching = "pattern=aadfa audit perms=rwxamlk/ user::other";
++#define AA_DEBUG(fmt, args...)                                                \
++      do {                                                            \
++              if (g_apparmor_debug && printk_ratelimit())             \
++                      printk(KERN_DEBUG "AppArmor: " fmt, ##args);    \
++      } while (0)
 +
-+      return simple_read_from_buffer(buf, size, ppos, matching,
-+                                     strlen(matching));
-+}
++#define AA_ERROR(fmt, args...)                                                \
++      do {                                                            \
++              if (printk_ratelimit())                                 \
++                      printk(KERN_ERR "AppArmor: " fmt, ##args);      \
++      } while (0)
++
++/* Flag indicating whether initialization completed */
++extern int apparmor_initialized;
++void apparmor_disable(void);
 +
-+static struct file_operations apparmorfs_matching_fops = {
-+      .read =         aa_matching_read,
-+};
++/* fn's in lib */
++void info_message(const char *str);
++char *aa_split_name_from_ns(char *args, char **ns_name);
++char *new_compound_name(const char *n1, const char *n2);
++int aa_strneq(const char *str, const char *sub, int len);
++char *strchrnul(const char *s, int c);
++const char *fqname_subname(const char *name);
 +
-+/* apparmor/features */
-+static ssize_t aa_features_read(struct file *file, char __user *buf,
-+                              size_t size, loff_t *ppos)
++static inline int mediated_filesystem(struct inode *inode)
 +{
-+      const char *features = "file=3.0 capability=2.0 network=1.0 "
-+                             "change_hat=1.4 change_profile=1.0 "
-+                             "aanamespaces=1.0 rlimit=1.0";
-+
-+      return simple_read_from_buffer(buf, size, ppos, features,
-+                                     strlen(features));
++      return !(inode->i_sb->s_flags & MS_NOUSER);
 +}
 +
-+static struct file_operations apparmorfs_features_fops = {
-+      .read =         aa_features_read,
-+};
++#endif        /* __APPARMOR_H */
 +
-+/* apparmor/.load */
-+static ssize_t aa_profile_load(struct file *f, const char __user *buf,
-+                             size_t size, loff_t *pos)
-+{
-+      char *data;
-+      ssize_t error;
+diff --git a/security/apparmor/include/apparmorfs.h b/security/apparmor/include/apparmorfs.h
+new file mode 100644
+index 0000000..1af7723
+--- /dev/null
++++ b/security/apparmor/include/apparmorfs.h
+@@ -0,0 +1,24 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor filesystem definitions.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+      data = aa_simple_write_to_buffer(buf, size, size, pos, "profile_load");
++#ifndef __AA_APPARMORFS_H
++#define __AA_APPARMORFS_H
 +
-+      error = PTR_ERR(data);
-+      if (!IS_ERR(data)) {
-+              error = aa_add_profile(data, size);
-+              vfree(data);
-+      }
++extern struct dentry *apparmorfs_null;
++extern struct vfsmount *apparmorfs_mnt;
 +
-+      return error;
-+}
++extern int create_apparmorfs(void);
++extern void destroy_apparmorfs(void);
 +
++#endif        /* __AA_APPARMORFS_H */
+diff --git a/security/apparmor/include/audit.h b/security/apparmor/include/audit.h
+new file mode 100644
+index 0000000..2180dd7
+--- /dev/null
++++ b/security/apparmor/include/audit.h
+@@ -0,0 +1,59 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor auditing function definitions.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+static struct file_operations apparmorfs_profile_load = {
-+      .write = aa_profile_load
-+};
++#ifndef __AA_AUDIT_H
++#define __AA_AUDIT_H
 +
-+/* apparmor/.replace */
-+static ssize_t aa_profile_replace(struct file *f, const char __user *buf,
-+                                size_t size, loff_t *pos)
-+{
-+      char *data;
-+      ssize_t error;
++#include <linux/audit.h>
++#include <linux/fs.h>
++#include <linux/sched.h>
++#include <linux/slab.h>
 +
-+      data = aa_simple_write_to_buffer(buf, size, size, pos,
-+                                       "profile_replace");
++struct aa_profile;
 +
-+      error = PTR_ERR(data);
-+      if (!IS_ERR(data)) {
-+              error = aa_replace_profile(data, size);
-+              vfree(data);
-+      }
 +
-+      return error;
-+}
++extern const char *audit_mode_names[];
++#define AUDIT_MAX_INDEX 5
 +
++#define AUDIT_APPARMOR_AUTO 0 /* auto choose audit message type */
 +
-+static struct file_operations apparmorfs_profile_replace = {
-+      .write = aa_profile_replace
++enum audit_mode {
++      AUDIT_NORMAL,           /* follow normal auditing of accesses */
++      AUDIT_QUIET_DENIED,     /* quiet all denied access messages */
++      AUDIT_QUIET,            /* quiet all messages */
++      AUDIT_NOQUIET,          /* do not quiet audit messages */
++      AUDIT_ALL               /* audit all accesses */
 +};
 +
-+/* apparmor/.remove */
-+static ssize_t aa_profile_remove(struct file *f, const char __user *buf,
-+                                size_t size, loff_t *pos)
-+{
-+      char *data;
-+      ssize_t error;
++/*
++ * aa_audit - AppArmor auditing structure
++ * Structure is populated by access control code and passed to aa_audit which
++ * provides for a single point of logging.
++ */
++struct aa_audit {
++      struct task_struct *task;
++      gfp_t gfp_mask;
++      int error;
++      const char *operation;
++      const char *info;
++};
 +
-+      /*
-+       * aa_remove_profile needs a null terminated string so 1 extra
-+       * byte is allocated and the copied data is null terminated.
-+       */
-+      data = aa_simple_write_to_buffer(buf, size + 1, size, pos,
-+                                       "profile_remove");
++int aa_audit(int type, struct aa_profile *profile, struct aa_audit *sa,
++           void(*cb)(struct audit_buffer *, void *));
 +
-+      error = PTR_ERR(data);
-+      if (!IS_ERR(data)) {
-+              data[size] = 0;
-+              error = aa_remove_profile(data, size);
-+              vfree(data);
-+      }
++int aa_audit_syscallreject(struct aa_profile *profile, gfp_t gfp, const char *,
++                         void(*cb)(struct audit_buffer *, void *));
 +
-+      return error;
-+}
 +
-+static struct file_operations apparmorfs_profile_remove = {
-+      .write = aa_profile_remove
++#endif        /* __AA_AUDIT_H */
+diff --git a/security/apparmor/include/capability.h b/security/apparmor/include/capability.h
+new file mode 100644
+index 0000000..43bb7eb
+--- /dev/null
++++ b/security/apparmor/include/capability.h
+@@ -0,0 +1,45 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor capability mediation definitions.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
++
++#ifndef __AA_CAPABILITY_H
++#define __AA_CAPABILITY_H
++
++#include <linux/sched.h>
++
++struct aa_profile;
++
++/* aa_caps - confinement data for capabilities
++ * @set_caps: capabilities that are being set
++ * @capabilities: capabilities mask
++ * @audit_caps: caps that are to be audited
++ * @quiet_caps: caps that should not be audited
++ */
++struct aa_caps {
++      kernel_cap_t set;
++      kernel_cap_t allowed;
++      kernel_cap_t audit;
++      kernel_cap_t quiet;
++      kernel_cap_t kill;
 +};
 +
-+static struct dentry *apparmor_dentry;
++int aa_profile_capable(struct aa_profile *profile, int cap);
++int aa_capable(struct task_struct *task, struct aa_profile *profile, int cap,
++             int audit);
 +
-+static void aafs_remove(const char *name)
++static inline void aa_free_cap_rules(struct aa_caps *caps)
 +{
-+      struct dentry *dentry;
-+
-+      dentry = lookup_one_len(name, apparmor_dentry, strlen(name));
-+      if (!IS_ERR(dentry)) {
-+              securityfs_remove(dentry);
-+              dput(dentry);
-+      }
++      /* NOP */
 +}
 +
-+static int aafs_create(const char *name, int mask, struct file_operations *fops)
-+{
-+      struct dentry *dentry;
++#endif        /* __AA_CAPBILITY_H */
+diff --git a/security/apparmor/include/context.h b/security/apparmor/include/context.h
+new file mode 100644
+index 0000000..202a66a
+--- /dev/null
++++ b/security/apparmor/include/context.h
+@@ -0,0 +1,153 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor contexts used to associate "labels" to objects.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+      dentry = securityfs_create_file(name, S_IFREG | mask, apparmor_dentry,
-+                                      NULL, fops);
++#ifndef __AA_CONTEXT_H
++#define __AA_CONTEXT_H
 +
-+      return IS_ERR(dentry) ? PTR_ERR(dentry) : 0;
-+}
++#include <linux/cred.h>
++#include <linux/slab.h>
++#include <linux/sched.h>
 +
-+void destroy_apparmorfs(void)
++#include "policy.h"
++
++
++/* struct aa_file_cxt - the AppArmor context the file was opened in
++ * @profile: the profile the file was opened under
++ * @perms: the permission the file was opened with
++ */
++struct aa_file_cxt {
++      struct aa_profile *profile;
++      u16 allowed;
++};
++
++static inline struct aa_file_cxt *aa_alloc_file_context(gfp_t gfp)
 +{
-+      if (apparmor_dentry) {
-+              aafs_remove(".remove");
-+              aafs_remove(".replace");
-+              aafs_remove(".load");
-+              aafs_remove("matching");
-+              aafs_remove("features");
-+              aafs_remove("profiles");
-+              securityfs_remove(apparmor_dentry);
-+              apparmor_dentry = NULL;
-+      }
++      return kzalloc(sizeof(struct aa_file_cxt), gfp);
 +}
 +
-+int create_apparmorfs(void)
++static inline void aa_free_file_context(struct aa_file_cxt *cxt)
 +{
-+      int error;
-+
-+      if (!apparmor_initialized)
-+              return 0;
-+
-+      if (apparmor_dentry) {
-+              AA_ERROR("%s: AppArmor securityfs already exists\n",
-+                      __FUNCTION__);
-+              return -EEXIST;
-+      }
++      aa_put_profile(cxt->profile);
++      memset(cxt, 0, sizeof(struct aa_file_cxt));
++      kfree(cxt);
++}
 +
-+      apparmor_dentry = securityfs_create_dir("apparmor", NULL);
-+      if (IS_ERR(apparmor_dentry)) {
-+              error = PTR_ERR(apparmor_dentry);
-+              apparmor_dentry = NULL;
-+              goto error;
-+      }
-+      error = aafs_create("profiles", 0440, &apparmorfs_profiles_fops);
-+      if (error)
-+              goto error;
-+      error = aafs_create("matching", 0444, &apparmorfs_matching_fops);
-+      if (error)
-+              goto error;
-+      error = aafs_create("features", 0444, &apparmorfs_features_fops);
-+      if (error)
-+              goto error;
-+      error = aafs_create(".load", 0640, &apparmorfs_profile_load);
-+      if (error)
-+              goto error;
-+      error = aafs_create(".replace", 0640, &apparmorfs_profile_replace);
-+      if (error)
-+              goto error;
-+      error = aafs_create(".remove", 0640, &apparmorfs_profile_remove);
-+      if (error)
-+              goto error;
 +
-+      /* Report that AppArmor fs is enabled */
-+      info_message("AppArmor Filesystem Enabled", "");
-+      return 0;
 +
-+error:
-+      destroy_apparmorfs();
-+      AA_ERROR("Error creating AppArmor securityfs\n");
-+      apparmor_disable();
-+      return error;
-+}
 +
-+fs_initcall(create_apparmorfs);
 +
-diff -uprN e/security/apparmor/inline.h f/security/apparmor/inline.h
---- e/security/apparmor/inline.h       1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/inline.h       2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,250 @@
-+/*
-+ *    Copyright (C) 1998-2007 Novell/SUSE
++/* struct aa_task_cxt_group - a grouping label data for confined tasks
++ * @profile: the current profile
++ * @exec: profile to transition to on next exec
++ * @previous: profile the task may return to
++ * @token: magic value the task must know for returning to @previous_profile
 + *
-+ *    This program is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU General Public License as
-+ *    published by the Free Software Foundation, version 2 of the
-+ *    License.
++ * Contains the task's current profile (which could change due to
++ * change_hat).  Plus the hat_magic needed during change_hat.
 + */
++struct aa_task_cxt_group {
++      struct aa_profile *profile;
++      struct aa_profile *onexec;
++      struct aa_profile *previous;
++      u64 token;
++};
 +
-+#ifndef __INLINE_H
-+#define __INLINE_H
++/**
++ * struct aa_task_context - primary label for confined tasks
++ * @sys: the system labeling for the task
++ *
++ * A task is confined by the intersection of its system and user profiles
++ */
++struct aa_task_context {
++      struct aa_task_cxt_group sys;
++};
 +
-+#include <linux/sched.h>
++struct aa_task_context *aa_alloc_task_context(gfp_t flags);
++void aa_free_task_context(struct aa_task_context *cxt);
++struct aa_task_context *aa_dup_task_context(struct aa_task_context *old_cxt,
++                                          gfp_t gfp);
++void aa_cred_policy(const struct cred *cred, struct aa_profile **sys);
++struct cred *aa_get_task_policy(const struct task_struct *task,
++                              struct aa_profile **sys);
++int aa_replace_current_profiles(struct aa_profile *sys);
++void aa_put_task_policy(struct cred *cred);
++int aa_set_current_onexec(struct aa_profile *sys);
++int aa_set_current_hat(struct aa_profile *profile, u64 token);
++int aa_restore_previous_profile(u64 cookie);
 +
-+#include "match.h"
 +
-+static inline int mediated_filesystem(struct inode *inode)
++static inline struct aa_task_context *__aa_task_cxt(struct task_struct *task)
 +{
-+      return !(inode->i_sb->s_flags & MS_NOUSER);
++      return __task_cred(task)->security;
 +}
 +
-+static inline struct aa_task_context *aa_task_context(struct task_struct *task)
++/**
++ * __aa_task_is_confined - determine if @task has any confinement
++ * @task: task to check confinement of
++ *
++ * If @task != current needs to be in RCU safe critical section
++ */
++static inline int __aa_task_is_confined(struct task_struct *task)
 +{
-+      return (struct aa_task_context *) rcu_dereference(task->security);
-+}
++      struct aa_task_context *cxt;
++      int rc = 1;
 +
-+static inline struct aa_namespace *aa_get_namespace(struct aa_namespace *ns)
-+{
-+      if (ns)
-+              kref_get(&(ns->count));
++      cxt = __aa_task_cxt(task);
++      if (!cxt || (cxt->sys.profile->flags & PFLAG_UNCONFINED))
++              rc = 0;
 +
-+      return ns;
++      return rc;
 +}
 +
-+static inline void aa_put_namespace(struct aa_namespace *ns)
++static inline const struct cred *aa_current_policy(struct aa_profile **sys)
 +{
-+      if (ns)
-+              kref_put(&ns->count, free_aa_namespace_kref);
-+}
++      const struct cred *cred = current_cred();
++      struct aa_task_context *cxt = cred->security;
++      BUG_ON(!cxt);
++      *sys = aa_filtered_profile(aa_profile_newest(cxt->sys.profile));
 +
++      return cred;
++}
 +
-+static inline struct aa_namespace *aa_find_namespace(const char *name)
++static inline const struct cred *aa_current_policy_wupd(struct aa_profile **sys)
 +{
-+      struct aa_namespace *ns = NULL;
++      const struct cred *cred = current_cred();
++      struct aa_task_context *cxt = cred->security;
++      BUG_ON(!cxt);
 +
-+      read_lock(&profile_ns_list_lock);
-+      ns = aa_get_namespace(__aa_find_namespace(name, &profile_ns_list));
-+      read_unlock(&profile_ns_list_lock);
++      *sys = aa_profile_newest(cxt->sys.profile);
++      if (unlikely((cxt->sys.profile != *sys)))
++              aa_replace_current_profiles(*sys);
++      *sys = aa_filtered_profile(*sys);
 +
-+      return ns;
++      return cred;
 +}
 +
-+/**
-+ * aa_dup_profile - increment refcount on profile @p
-+ * @p: profile
-+ */
-+static inline struct aa_profile *aa_dup_profile(struct aa_profile *p)
++static inline struct aa_profile *aa_current_profile(void)
 +{
-+      if (p)
-+              kref_get(&(p->count));
++      const struct cred *cred = current_cred();
++      struct aa_task_context *cxt = cred->security;
++      BUG_ON(!cxt);
++      return aa_filtered_profile(aa_profile_newest(cxt->sys.profile));
++}
 +
++static inline struct aa_profile *aa_current_profile_wupd(void)
++{
++      struct aa_profile *p;
++      aa_current_policy_wupd(&p);
 +      return p;
 +}
 +
-+/**
-+ * aa_put_profile - decrement refcount on profile @p
-+ * @p: profile
++
++#endif        /* __AA_CONTEXT_H */
+diff --git a/security/apparmor/include/domain.h b/security/apparmor/include/domain.h
+new file mode 100644
+index 0000000..a340e62
+--- /dev/null
++++ b/security/apparmor/include/domain.h
+@@ -0,0 +1,37 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor security domain transition function definitions.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
 + */
-+static inline void aa_put_profile(struct aa_profile *p)
-+{
-+      if (p)
-+              kref_put(&p->count, free_aa_profile_kref);
-+}
 +
-+static inline struct aa_profile *aa_get_profile(struct task_struct *task)
-+{
-+      struct aa_task_context *cxt;
-+      struct aa_profile *profile = NULL;
++#include <linux/binfmts.h>
++#include <linux/types.h>
++
++#ifndef __AA_DOMAIN_H
++#define __AA_DOMAIN_H
++
++struct aa_domain {
++      int size;
++      char **table;
++};
++
++int apparmor_bprm_set_creds(struct linux_binprm *bprm);
++int apparmor_bprm_secureexec(struct linux_binprm *bprm);
++int apparmor_bprm_committing_creds(struct linux_binprm *bprm);
++void apparmor_bprm_committed_creds(struct linux_binprm *bprm);
++
++void aa_free_domain_entries(struct aa_domain *domain);
++int aa_change_hat(const char *hat_name, u64 token, int permtest);
++int aa_change_profile(const char *ns_name, const char *name, int onexec,
++                    int permtest);
++
++
++#endif        /* __AA_DOMAIN_H */
+diff --git a/security/apparmor/include/file.h b/security/apparmor/include/file.h
+new file mode 100644
+index 0000000..e99e6fe
+--- /dev/null
++++ b/security/apparmor/include/file.h
+@@ -0,0 +1,227 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor file mediation function definitions.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
++
++#ifndef __AA_FILE_H
++#define __AA_FILE_H
++
++#include <linux/path.h>
++
++#include "audit.h"
++#include "domain.h"
++#include "match.h"
++
++struct aa_profile;
++
++/*
++ * We use MAY_EXEC, MAY_WRITE, MAY_READ, MAY_APPEND and the following flags
++ * for profile permissions
++ */
++#define AA_MAY_LINK                   0x0010
++#define AA_MAY_LOCK                   0x0020
++#define AA_EXEC_MMAP                  0x0040
++
++#define AA_MAY_CREATE                 0x0080
++#define AA_LINK_SUBSET                        0x0100
++#define AA_MAY_DELEGATE                       0x0200
++#define AA_EXEC_DELEGATE              0x0400          /*exec allows delegate*/
 +
-+      rcu_read_lock();
-+      cxt = aa_task_context(task);
-+      if (cxt) {
-+              profile = cxt->profile;
-+              aa_dup_profile(profile);
-+      }
-+      rcu_read_unlock();
++#define AA_MAY_CHANGEHAT              0x2000          /* ctrl auditing only */
++#define AA_MAY_ONEXEC                 0x4000          /* exec allows onexec */
++#define AA_MAY_CHANGE_PROFILE         0x8000
 +
-+      return profile;
-+}
 +
-+static inline struct aa_profile *aa_find_profile(struct aa_namespace *ns,
-+                                               const char *name)
-+{
-+      struct aa_profile *profile = NULL;
++#define AA_AUDIT_FILE_MASK    (MAY_READ | MAY_WRITE | MAY_EXEC | MAY_APPEND |\
++                               AA_MAY_LINK | AA_MAY_LOCK | AA_EXEC_MMAP | \
++                               AA_MAY_CREATE)
 +
-+      read_lock(&ns->lock);
-+      profile = aa_dup_profile(__aa_find_profile(name, &ns->profiles));
-+      read_unlock(&ns->lock);
++/*
++ * The xindex is broken into 3 parts
++ * - index - an index into either the exec name table or the variable table
++ * - exec type - which determines how the executable name and index are used
++ * - flags - which modify how the destination name is applied
++ */
++#define AA_X_INDEX_MASK               0x03ff
 +
-+      return profile;
-+}
++#define AA_X_TYPE_MASK                0x0c00
++#define AA_X_TYPE_SHIFT               10              
++#define AA_X_NONE             0x0000
++#define AA_X_NAME             0x0400  /* use executable name px */
++#define AA_X_TABLE            0x0800  /* use a specified name ->n# */
 +
-+static inline struct aa_task_context *aa_alloc_task_context(gfp_t flags)
-+{
-+      struct aa_task_context *cxt;
++#define AA_X_UNSAFE           0x1000
++#define AA_X_CHILD            0x2000  /* make >AA_X_NONE apply to children */
++#define AA_X_INHERIT          0x4000
++#define AA_X_UNCONFINED               0x8000
 +
-+      cxt = kzalloc(sizeof(*cxt), flags);
-+      if (cxt) {
-+              INIT_LIST_HEAD(&cxt->list);
-+              INIT_RCU_HEAD(&cxt->rcu);
-+      }
 +
-+      return cxt;
-+}
++/* AA_SECURE_X_NEEDED - is passed in the bprm->unsafe field */
++#define AA_SECURE_X_NEEDED    0x8000
 +
-+static inline void aa_free_task_context(struct aa_task_context *cxt)
-+{
-+      if (cxt) {
-+              aa_put_profile(cxt->profile);
-+              aa_put_profile(cxt->previous_profile);
-+              kfree(cxt);
-+      }
-+}
++/* need to conditionalize which ones are being set */
++struct path_cond {
++      uid_t uid;
++      umode_t mode;
++};
 +
-+/**
-+ * lock_profile - lock a profile
-+ * @profile: the profile to lock
++/* struct file_perms - file permission fo
++ * @allowed: mask of permissions that are allowed
++ * @audit: mask of permissions to force an audit message for
++ * @quiet: mask of permissions to quiet audit messages for
++ * @kill: mask of permissions that when matched will kill the task
++ * @xindex: exec transition index if @allowed contains MAY_EXEC
++ * @dindex: delegate table index if @allowed contain AA_MAY_DELEGATE
 + *
-+ * While the profile is locked, local interrupts are disabled. This also
-+ * gives us RCU reader safety.
++ * The @audit and @queit mask should be mutually exclusive.
 + */
-+static inline void lock_profile_nested(struct aa_profile *profile,
-+                                     enum aa_lock_class lock_class)
-+{
-+      /*
-+       * Lock the profile.
-+       *
-+       * Need to disable interrupts here because this lock is used in
-+       * the task_free_security hook, which may run in RCU context.
-+       */
-+      if (profile)
-+              spin_lock_irqsave_nested(&profile->lock, profile->int_flags,
-+                                       lock_class);
-+}
++struct file_perms {
++      u16 allowed;
++      u16 audit;
++      u16 quiet;
++      u16 kill;
++      u16 xindex;
++      u16 dindex;
++};
 +
-+static inline void lock_profile(struct aa_profile *profile)
-+{
-+      lock_profile_nested(profile, aa_lock_normal);
-+}
++extern struct file_perms nullperms;
 +
-+/**
-+ * unlock_profile - unlock a profile
-+ * @profile: the profile to unlock
-+ */
-+static inline void unlock_profile(struct aa_profile *profile)
-+{
-+      /* Unlock the profile. */
-+      if (profile)
-+              spin_unlock_irqrestore(&profile->lock, profile->int_flags);
-+}
++#define COMBINED_PERM_MASK(X) ((X).allowed | (X).audit | (X).quiet | (X).kill)
 +
-+/**
-+ * lock_both_profiles  -  lock two profiles in a deadlock-free way
-+ * @profile1: profile to lock (may be NULL)
-+ * @profile2: profile to lock (may be NULL)
-+ *
-+ * The order in which profiles are passed into lock_both_profiles() /
-+ * unlock_both_profiles() does not matter.
-+ * While the profile is locked, local interrupts are disabled. This also
-+ * gives us RCU reader safety.
++/* FIXME: split perms from dfa and match this to description
++ *        also add delegation info.
 + */
-+static inline void lock_both_profiles(struct aa_profile *profile1,
-+                                    struct aa_profile *profile2)
-+{
-+      /*
-+       * Lock the two profiles.
-+       *
-+       * We need to disable interrupts because the profile locks are
-+       * used in the task_free_security hook, which may run in RCU
-+       * context.
-+       *
-+       * Do not nest spin_lock_irqsave()/spin_unlock_irqresore():
-+       * interrupts only need to be turned off once.
-+       */
-+      if (!profile1 || profile1 == profile2) {
-+              if (profile2)
-+                      spin_lock_irqsave_nested(&profile2->lock,
-+                                               profile2->int_flags,
-+                                               aa_lock_normal);
-+      } else if (profile1 > profile2) {
-+              /* profile1 cannot be NULL here. */
-+              spin_lock_irqsave_nested(&profile1->lock, profile1->int_flags,
-+                                       aa_lock_normal);
-+              if (profile2)
-+                      spin_lock_nested(&profile2->lock, aa_lock_nested);
-+
++static inline u16 dfa_map_xindex(u16 mask)
++{
++      u16 old_index = (mask >> 10) & 0xf;
++      u16 index = 0;
++
++//printk("mask x%x\n", mask);
++      if (mask & 0x100)
++              index |= AA_X_UNSAFE;
++      if (mask & 0x200)
++              index |= AA_X_INHERIT;
++
++      if (old_index == 1) {
++              index |= AA_X_UNCONFINED;
++      } else if (old_index == 2) {
++              index |= AA_X_NAME;
++      } else if (old_index == 3) {
++              index |= AA_X_NAME | AA_X_CHILD;
 +      } else {
-+              /* profile2 cannot be NULL here. */
-+              spin_lock_irqsave_nested(&profile2->lock, profile2->int_flags,
-+                                       aa_lock_normal);
-+              spin_lock_nested(&profile1->lock, aa_lock_nested);
++              index |= AA_X_TABLE;
++              index |= old_index - 4;
 +      }
++
++      return index;
 +}
 +
++/*
++ * map old dfa inline permissions to new format
++ */
++#define dfa_user_allow(dfa, state)    ((ACCEPT_TABLE(dfa)[state]) & 0x7f)
++#define dfa_user_audit(dfa, state)    ((ACCEPT_TABLE2(dfa)[state]) & 0x7f)
++#define dfa_user_quiet(dfa, state)    (((ACCEPT_TABLE2(dfa)[state]) >> 7) & 0x7f)
++#define dfa_user_xindex(dfa, state) \
++      (dfa_map_xindex(ACCEPT_TABLE(dfa)[state] & 0x3fff))
++
++#define dfa_other_allow(dfa, state)   (((ACCEPT_TABLE(dfa)[state]) >> 14) & 0x7f)
++#define dfa_other_audit(dfa, state)   (((ACCEPT_TABLE2(dfa)[state]) >> 14) & 0x7f)
++#define dfa_other_quiet(dfa, state)   ((((ACCEPT_TABLE2(dfa)[state]) >> 7) >> 14) & 0x7f)
++#define dfa_other_xindex(dfa, state) \
++      dfa_map_xindex((ACCEPT_TABLE(dfa)[state] >> 14) & 0x3fff)
++
++
++struct aa_audit_file {
++      struct aa_audit base;
++
++      const char *name;
++      const char *name2;
++      const char *name3;
++      struct file_perms perms;
++      u16 request;
++      struct path_cond *cond;
++};
++
++int aa_audit_file(struct aa_profile *profile, struct aa_audit_file *sa);
++void file_audit_cb(struct audit_buffer *ab, void *va);
++
 +/**
-+ * unlock_both_profiles  -  unlock two profiles in a deadlock-free way
-+ * @profile1: profile to unlock (may be NULL)
-+ * @profile2: profile to unlock (may be NULL)
-+ *
-+ * The order in which profiles are passed into lock_both_profiles() /
-+ * unlock_both_profiles() does not matter.
-+ * While the profile is locked, local interrupts are disabled. This also
-+ * gives us RCU reader safety.
++ * struct aa_file_rules - components used for file rule permissions
++ * @dfa: dfa to match path names and conditionals against
++ * @perms: permission table indexed by the matched state accept entry of @dfa
++ * @trans: transition table for indexed by named x transitions
++ *
++ * File permission are determined by matching a path against @dfa and then
++ * then using the value of the accept entry for the matching state as
++ * an index into @perms.  If a named exec transition is required it is
++ * looked up in the transition table.
 + */
-+static inline void unlock_both_profiles(struct aa_profile *profile1,
-+                                      struct aa_profile *profile2)
-+{
-+      /* Unlock the two profiles. */
-+      if (!profile1 || profile1 == profile2) {
-+              if (profile2)
-+                      spin_unlock_irqrestore(&profile2->lock,
-+                                             profile2->int_flags);
-+      } else if (profile1 > profile2) {
-+              /* profile1 cannot be NULL here. */
-+              if (profile2)
-+                      spin_unlock(&profile2->lock);
-+              spin_unlock_irqrestore(&profile1->lock, profile1->int_flags);
-+      } else {
-+              /* profile2 cannot be NULL here. */
-+              spin_unlock(&profile1->lock);
-+              spin_unlock_irqrestore(&profile2->lock, profile2->int_flags);
-+      }
-+}
++struct aa_file_rules {
++      struct aa_dfa *dfa;
++      /* struct perms perms; */
++      struct aa_domain trans;
++      /* TODO: add delegate table */
++};
++
++struct file_perms aa_str_perms(struct aa_dfa *dfa, unsigned int start,
++                             const char *name, struct path_cond *cond,
++                             unsigned int *rstate);
 +
-+static inline unsigned int aa_match(struct aa_dfa *dfa, const char *pathname,
-+                                  int *audit_mask)
++int aa_pathstr_perm(struct aa_profile *profile, const char *op,
++                  const char *name, u16 request, struct path_cond *cond);
++
++int aa_path_perm(struct aa_profile *profile, const char *operation,
++               struct path *path, u16 request, struct path_cond *cond);
++
++int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
++               struct path *new_dir, struct dentry *new_dentry);
++
++int aa_file_common_perm(struct aa_profile *profile, const char *operation,
++                      struct file *file, u16 request, const char *name,
++                      int error);
++
++int aa_file_perm(struct aa_profile *profile, const char *operation,
++               struct file *file, u16 request);
++
++
++static inline void aa_free_file_rules(struct aa_file_rules *rules)
 +{
-+      if (dfa)
-+              return aa_dfa_match(dfa, pathname, audit_mask);
-+      if (audit_mask)
-+              *audit_mask = 0;
-+      return 0;
++      aa_match_free(rules->dfa);
++      aa_free_domain_entries(&rules->trans);
 +}
 +
-+static inline int dfa_audit_mask(struct aa_dfa *dfa, unsigned int state)
++#define ACC_FMODE(x) (("\000\004\002\006"[(x)&O_ACCMODE]) | (((x) << 1) & 0x40))
++
++/* from namei.c */
++#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
++#define MAP_OPEN_FLAGS(x) ((((x) + 1) & O_ACCMODE) ? (x) + 1 : (x))
++/*
++ * map file flags to AppArmor permissions
++ */
++static inline u16 aa_map_file_to_perms(struct file *file)
 +{
-+      return  ACCEPT_TABLE2(dfa)[state];
++      int flags = MAP_OPEN_FLAGS(file->f_flags);
++      u16 perms = ACC_FMODE(file->f_mode);
++
++      if ((flags & O_APPEND) && (perms & MAY_WRITE))
++              perms = (perms & ~MAY_WRITE) | MAY_APPEND;
++      /* trunc implies write permission */
++      if (flags & O_TRUNC)
++              perms |= MAY_WRITE;
++      if (flags & O_CREAT)
++              perms |= AA_MAY_CREATE;
++
++      return perms;
 +}
 +
-+#endif /* __INLINE_H__ */
-diff -uprN e/security/apparmor/list.c f/security/apparmor/list.c
---- e/security/apparmor/list.c 1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/list.c 2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,172 @@
++#endif        /* __AA_FILE_H */
+diff --git a/security/apparmor/include/ipc.h b/security/apparmor/include/ipc.h
+new file mode 100644
+index 0000000..e80a95e
+--- /dev/null
++++ b/security/apparmor/include/ipc.h
+@@ -0,0 +1,28 @@
 +/*
-+ *    Copyright (C) 1998-2007 Novell/SUSE
++ * AppArmor security module
 + *
-+ *    This program is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU General Public License as
-+ *    published by the Free Software Foundation, version 2 of the
-+ *    License.
++ * This file contains AppArmor ipc mediation function definitions.
 + *
-+ *    AppArmor Profile List Management
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
 + */
 +
-+#include <linux/seq_file.h>
-+#include "apparmor.h"
-+#include "inline.h"
++#ifndef __AA_IPC_H
++#define __AA_IPC_H
 +
-+/* list of profile namespaces and lock */
-+LIST_HEAD(profile_ns_list);
-+rwlock_t profile_ns_list_lock = RW_LOCK_UNLOCKED;
++#include <linux/sched.h>
 +
-+/**
-+ * __aa_find_namespace  -  look up a profile namespace on the namespace list
-+ * @name: name of namespace to find
-+ * @head: list to search
-+ *
-+ * Returns a pointer to the namespace on the list, or NULL if no namespace
-+ * called @name exists. The caller must hold the profile_ns_list_lock.
-+ */
-+struct aa_namespace *__aa_find_namespace(const char *name,
-+                                     struct list_head *head)
-+{
-+      struct aa_namespace *ns;
++struct aa_profile;
 +
-+      list_for_each_entry(ns, head, list) {
-+              if (!strcmp(ns->name, name))
-+                      return ns;
-+      }
++int aa_may_ptrace(struct task_struct *tracer_task, struct aa_profile *tracer,
++                struct aa_profile *tracee, unsigned int mode);
 +
-+      return NULL;
-+}
++int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee,
++            unsigned int mode);
 +
-+/**
-+ * __aa_find_profile  -  look up a profile on the profile list
-+ * @name: name of profile to find
-+ * @head: list to search
++#endif        /* __AA_IPC_H */
+diff --git a/security/apparmor/include/match.h b/security/apparmor/include/match.h
+new file mode 100644
+index 0000000..8a0f59c
+--- /dev/null
++++ b/security/apparmor/include/match.h
+@@ -0,0 +1,105 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor policy dfa matching engine definitions.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
 + *
-+ * Returns a pointer to the profile on the list, or NULL if no profile
-+ * called @name exists. The caller must hold the profile_list_lock.
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
 + */
-+struct aa_profile *__aa_find_profile(const char *name, struct list_head *head)
-+{
-+      struct aa_profile *profile;
 +
-+      list_for_each_entry(profile, head, list) {
-+              if (!strcmp(profile->name, name))
-+                      return profile;
-+      }
++#ifndef __AA_MATCH_H
++#define __AA_MATCH_H
 +
-+      return NULL;
-+}
++#define DFA_NOMATCH                   0
++#define DFA_START                     1
++
++#define DFA_VALID_PERM_MASK           0xffffffff
++#define DFA_VALID_PERM2_MASK          0xffffffff
 +
-+static void aa_profile_list_release(struct list_head *head)
-+{
-+      struct aa_profile *profile, *tmp;
-+      list_for_each_entry_safe(profile, tmp, head, list) {
-+              /* Remove the profile from each task context it is on. */
-+              lock_profile(profile);
-+              profile->isstale = 1;
-+              aa_unconfine_tasks(profile);
-+              list_del_init(&profile->list);
-+              unlock_profile(profile);
-+              aa_put_profile(profile);
-+      }
-+}
 +
 +/**
-+ * aa_profilelist_release - Remove all profiles from profile_list
++ * The format used for transition tables is based on the GNU flex table
++ * file format (--tables-file option; see Table File Format in the flex
++ * info pages and the flex sources for documentation). The magic number
++ * used in the header is 0x1B5E783D insted of 0xF13C57B1 though, because
++ * the YY_ID_CHK (check) and YY_ID_DEF (default) tables are used
++ * slightly differently (see the apparmor-parser package).
 + */
-+void aa_profile_ns_list_release(void)
-+{
-+      struct aa_namespace *ns, *tmp;
-+
-+      /* Remove and release all the profiles on namespace profile lists. */
-+      write_lock(&profile_ns_list_lock);
-+      list_for_each_entry_safe(ns, tmp, &profile_ns_list, list) {
-+              write_lock(&ns->lock);
-+              aa_profile_list_release(&ns->profiles);
-+              list_del_init(&ns->list);
-+              write_unlock(&ns->lock);
-+              aa_put_namespace(ns);
-+      }
-+      write_unlock(&profile_ns_list_lock);
-+}
 +
-+static struct aa_profile *next_profile(struct aa_profile *profile)
-+{
-+      struct aa_profile *next = profile;
-+      struct aa_namespace *ns;
++#define YYTH_MAGIC    0x1B5E783D
 +
-+      list_for_each_entry_continue(next, &profile->ns->profiles, list)
-+              return next;
++struct table_set_header {
++      u32             th_magic;       /* YYTH_MAGIC */
++      u32             th_hsize;
++      u32             th_ssize;
++      u16             th_flags;
++      char            th_version[];
++};
 +
-+      ns = profile->ns;
-+      read_unlock(&ns->lock);
-+      list_for_each_entry_continue(ns, &profile_ns_list, list) {
-+              read_lock(&ns->lock);
-+              list_for_each_entry(profile, &ns->profiles, list)
-+                      return profile;
-+              read_unlock(&ns->lock);
-+      }
-+      return NULL;
-+}
++#define       YYTD_ID_ACCEPT  1
++#define YYTD_ID_BASE  2
++#define YYTD_ID_CHK   3
++#define YYTD_ID_DEF   4
++#define YYTD_ID_EC    5
++#define YYTD_ID_META  6
++#define YYTD_ID_ACCEPT2 7
++#define YYTD_ID_NXT   8
 +
-+static void *p_start(struct seq_file *f, loff_t *pos)
-+{
-+      struct aa_namespace *ns;
-+      loff_t l = *pos;
 +
-+      read_lock(&profile_ns_list_lock);
-+      if (!list_empty(&profile_ns_list)) {
-+              struct aa_profile *profile = NULL;
-+              ns = list_first_entry(&profile_ns_list, typeof(*ns), list);
-+              read_lock(&ns->lock);
-+              if (!list_empty(&ns->profiles))
-+                      profile = list_first_entry(&ns->profiles,
-+                                                 typeof(*profile), list);
-+              else
-+                      read_unlock(&ns->lock);
-+              for ( ; profile && l > 0; l--)
-+                      profile = next_profile(profile);
-+              return profile;
-+      }
-+      return NULL;
-+}
++#define YYTD_DATA8    1
++#define YYTD_DATA16   2
++#define YYTD_DATA32   4
 +
-+static void *p_next(struct seq_file *f, void *p, loff_t *pos)
-+{
-+      struct aa_profile *profile = (struct aa_profile *) p;
++struct table_header {
++      u16             td_id;
++      u16             td_flags;
++      u32             td_hilen;
++      u32             td_lolen;
++      char            td_data[];
++};
 +
-+      (*pos)++;
-+      profile = next_profile(profile);
++#define DEFAULT_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_DEF - 1]->td_data))
++#define BASE_TABLE(DFA) ((u32 *)((DFA)->tables[YYTD_ID_BASE - 1]->td_data))
++#define NEXT_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_NXT - 1]->td_data))
++#define CHECK_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_CHK - 1]->td_data))
++#define EQUIV_TABLE(DFA) ((u8 *)((DFA)->tables[YYTD_ID_EC - 1]->td_data))
++#define ACCEPT_TABLE(DFA) ((u32 *)((DFA)->tables[YYTD_ID_ACCEPT - 1]->td_data))
++#define ACCEPT_TABLE2(DFA) ((u32 *)((DFA)->tables[YYTD_ID_ACCEPT2 - 1]->td_data))
 +
-+      return profile;
-+}
++struct aa_dfa {
++      struct table_header *tables[YYTD_ID_NXT];
++};
 +
-+static void p_stop(struct seq_file *f, void *p)
-+{
-+      struct aa_profile *profile = (struct aa_profile *) p;
++#define byte_to_byte(X) (X)
 +
-+      if (profile)
-+              read_unlock(&profile->ns->lock);
-+      read_unlock(&profile_ns_list_lock);
-+}
++#define UNPACK_ARRAY(TABLE, BLOB, LEN, TYPE, NTOHX) \
++      do { \
++              typeof(LEN) __i; \
++              TYPE *__t = (TYPE *) TABLE; \
++              TYPE *__b = (TYPE *) BLOB; \
++              for (__i = 0; __i < LEN; __i++) { \
++                      __t[__i] = NTOHX(__b[__i]); \
++              } \
++      } while (0)
 +
-+static int seq_show_profile(struct seq_file *f, void *p)
++static inline size_t table_size(size_t len, size_t el_size)
 +{
-+      struct aa_profile *profile = (struct aa_profile *)p;
-+      if (profile->ns == default_namespace)
-+          seq_printf(f, "%s (%s)\n", profile->name,
-+                     PROFILE_COMPLAIN(profile) ? "complain" : "enforce");
-+      else
-+          seq_printf(f, ":%s:%s (%s)\n", profile->ns->name, profile->name,
-+                     PROFILE_COMPLAIN(profile) ? "complain" : "enforce");
-+      return 0;
++      return ALIGN(sizeof(struct table_header) + len * el_size, 8);
 +}
 +
-+/* Used in apparmorfs.c */
-+struct seq_operations apparmorfs_profiles_op = {
-+      .start =        p_start,
-+      .next =         p_next,
-+      .stop =         p_stop,
-+      .show =         seq_show_profile,
-+};
-diff -uprN e/security/apparmor/locking.txt f/security/apparmor/locking.txt
---- e/security/apparmor/locking.txt    1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/locking.txt    2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,68 @@
-+Locking in AppArmor
-+===================
-+
-+Lock hierarchy:
-+
-+      aa_interface_lock
-+        profile_list_lock
-+          aa_profile->lock
-+            task_lock()
-+
-+
-+Which lock protects what?
-+
-+      /-----------------------+-------------------------------\
-+      | Variable              | Lock                          |
-+      >-----------------------+-------------------------------<
-+      | profile_list          | profile_list_lock             |
-+      +-----------------------+-------------------------------+
-+      | aa_profile            | (reference count)             |
-+      +-----------------------+-------------------------------+
-+      | aa_profile->          | aa_profile->lock              |
-+      |   isstale,            |                               |
-+      |   task_contexts       |                               |
-+      +-----------------------+-------------------------------+
-+      | task_struct->security | read: RCU                     |
-+      |                       | write: task_lock()            |
-+      +-----------------------+-------------------------------+
-+      | aa_profile->sub       | handle on the profile (list   |
-+      |                       | is never modified)            |
-+      \-----------------------+-------------------------------/
-+
-+(Obviously, the list_heads embedded in data structures are always
-+protected with the lock that also protects the list.)
-+
-+When moving a task context from one profile to another, we grab both
-+profile locks with lock_both_profiles(). This ensures that both locks
-+are always taken in the same order, and so we won't deadlock.
-+
-+Since task_struct->security is RCU protected the aa_task_struct it
-+references is only guarenteed to exist for the rcu cycle.  Where
-+aa_task_context->profile is needed in blocking operations the
-+profile's reference count is incremented and the profile reference
-+is used.
-+
-+Profiles on profile_list are never stale: when a profile becomes stale,
-+it is removed from profile_list at the same time (under profile_list_lock
-+and aa_profile->lock).
-+
-+The aa_interface_lock is taken whenever user-space modifies the profile
-+list, and can sleep. This ensures that profile loading/replacement/removal
-+won't race with itself. We release the profile_list_lock as soon as
-+possible to avoid stalling exec during profile loading/replacement/removal.
-+
-+AppArmor uses lock subtyping to avoid false positives from lockdep.  The
-+profile lock is often taken nested, but it is guaranteed to be in a lock
-+safe order and not the same lock when done, so it is safe.
-+
-+A third lock type (aa_lock_task_release) is given to the profile lock
-+when it is taken in soft irq context during task release (aa_release).
-+This is to avoid a false positive between the task lock and the profile
-+lock.  In task context the profile lock wraps the task lock with irqs
-+off, but the kernel takes the task lock with irqs enabled.  This won't
-+result in a deadlock because for a deadlock to occur the kernel must
-+take dead task A's lock (irqs on), the rcu callback hook freeing
-+dead task A must be run and AppArmor must be changing the profile on
-+dead task A.  The kernel should not be taking a dead task's task_lock
-+at the same time the task is being freed by task rcu cleanup other wise
-+the task would not be out of its quiescent period.
-diff -uprN e/security/apparmor/lsm.c f/security/apparmor/lsm.c
---- e/security/apparmor/lsm.c  1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/lsm.c  2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,1108 @@
++struct aa_dfa *aa_match_alloc(void);
++void aa_match_free(struct aa_dfa *dfa);
++int unpack_dfa(struct aa_dfa *dfa, void *blob, size_t size);
++int verify_dfa(struct aa_dfa *dfa);
++unsigned int aa_dfa_match_len(struct aa_dfa *dfa, unsigned int start,
++                            const char *str, int len);
++unsigned int aa_dfa_match(struct aa_dfa *dfa, unsigned int start,
++                        const char *str);
++unsigned int aa_dfa_null_transition(struct aa_dfa *dfa, unsigned int start);
++
++#endif /* __AA_MATCH_H */
+diff --git a/security/apparmor/include/net.h b/security/apparmor/include/net.h
+new file mode 100644
+index 0000000..ece94b2
+--- /dev/null
++++ b/security/apparmor/include/net.h
+@@ -0,0 +1,40 @@
 +/*
-+ *    Copyright (C) 1998-2007 Novell/SUSE
++ * AppArmor security module
++ *
++ * This file contains AppArmor network mediation definitions.
 + *
-+ *    This program is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU General Public License as
-+ *    published by the Free Software Foundation, version 2 of the
-+ *    License.
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
 + *
-+ *    AppArmor LSM interface
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
 + */
-+#include <linux/security.h>
-+#include <linux/module.h>
-+#include <linux/mm.h>
-+#include <linux/mman.h>
-+#include <linux/mount.h>
-+#include <linux/namei.h>
-+#include <linux/ctype.h>
-+#include <linux/sysctl.h>
-+#include <linux/audit.h>
-+#include <net/sock.h>
-+
-+#include "apparmor.h"
-+#include "inline.h"
 +
-+/* Flag indicating whether initialization completed */
-+int apparmor_initialized = 0;
++#ifndef __AA_NET_H
++#define __AA_NET_H
 +
-+/* point to the apparmor module */
-+struct module *aa_module = NULL;
++#include <net/sock.h>
 +
-+/* secondary ops if apparmor is stacked */
-+static struct security_operations *aa_secondary_ops = NULL;
-+static DEFINE_MUTEX(aa_secondary_lock);
++/* struct aa_net - network confinement data
++ * @allowed: basic network families permissions
++ * @audit_network: which network permissions to force audit
++ * @quiet_network: which network permissions to quiet rejects
++ */
++struct aa_net {
++      u16 allowed[AF_MAX];
++      u16 audit[AF_MAX];
++      u16 quiet[AF_MAX];
++};
 +
-+#define AA_SECONDARY(FN, ARGS...) \
-+       ({ \
-+               struct security_operations *__f1; \
-+               __f1 = rcu_dereference(aa_secondary_ops); \
-+               (unlikely(__f1) && __f1->FN) ? __f1->FN(ARGS) : 0; \
-+       })
++extern int aa_net_perm(struct aa_profile *profile, char *operation,
++                      int family, int type, int protocol);
++extern int aa_revalidate_sk(struct sock *sk, char *operation);
 +
-+static int param_set_aabool(const char *val, struct kernel_param *kp);
-+static int param_get_aabool(char *buffer, struct kernel_param *kp);
-+#define param_check_aabool(name, p) __param_check(name, p, int)
++static inline void aa_free_net_rules(struct aa_net *new)
++{
++      /* NOP */
++}
 +
-+static int param_set_aauint(const char *val, struct kernel_param *kp);
-+static int param_get_aauint(char *buffer, struct kernel_param *kp);
-+#define param_check_aauint(name, p) __param_check(name, p, int)
++#endif        /* __AA_NET_H */
+diff --git a/security/apparmor/include/path.h b/security/apparmor/include/path.h
+new file mode 100644
+index 0000000..d238e42
+--- /dev/null
++++ b/security/apparmor/include/path.h
+@@ -0,0 +1,24 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor basic path manipulation function definitions.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+/* Flag values, also controllable via /sys/module/apparmor/parameters
-+ * We define special types as we want to do additional mediation.
++#ifndef __AA_PATH_H
++#define __AA_PATH_H
++
++int aa_get_name_to_buffer(struct path *path, int is_dir, char *buffer, int size,
++                        char **name);
++int aa_get_name(struct path *path, int is_dir, char **buffer, char **name);
++int d_namespace_path(struct path *path, char *buf, int buflen, char **name);
++char *sysctl_pathname(struct ctl_table *table, char *buffer, int buflen);
++
++#endif        /* __AA_PATH_H */
+diff --git a/security/apparmor/include/policy.h b/security/apparmor/include/policy.h
+new file mode 100644
+index 0000000..98cd0d9
+--- /dev/null
++++ b/security/apparmor/include/policy.h
+@@ -0,0 +1,301 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor policy definitions.
 + *
-+ * Complain mode -- in complain mode access failures result in auditing only
-+ * and task is allowed access.  audit events are processed by userspace to
-+ * generate policy.  Default is 'enforce' (0).
-+ * Value is also togglable per profile and referenced when global value is
-+ * enforce.
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
 + */
-+int apparmor_complain = 0;
-+module_param_named(complain, apparmor_complain, aabool, S_IRUSR | S_IWUSR);
-+MODULE_PARM_DESC(apparmor_complain, "Toggle AppArmor complain mode");
 +
-+/* Debug mode */
-+int apparmor_debug = 0;
-+module_param_named(debug, apparmor_debug, aabool, S_IRUSR | S_IWUSR);
-+MODULE_PARM_DESC(apparmor_debug, "Toggle AppArmor debug mode");
++#ifndef __AA_POLICY_H
++#define __AA_POLICY_H
 +
-+/* Audit mode */
-+int apparmor_audit = 0;
-+module_param_named(audit, apparmor_audit, aabool, S_IRUSR | S_IWUSR);
-+MODULE_PARM_DESC(apparmor_audit, "Toggle AppArmor audit mode");
++#include <linux/capability.h>
++#include <linux/cred.h>
++#include <linux/kref.h>
++#include <linux/sched.h>
++#include <linux/slab.h>
++#include <linux/socket.h>
 +
-+/* Syscall logging mode */
-+int apparmor_logsyscall = 0;
-+module_param_named(logsyscall, apparmor_logsyscall, aabool, S_IRUSR | S_IWUSR);
-+MODULE_PARM_DESC(apparmor_logsyscall, "Toggle AppArmor logsyscall mode");
++#include "apparmor.h"
++#include "audit.h"
++#include "capability.h"
++#include "domain.h"
++#include "file.h"
++#include "net.h"
++#include "resource.h"
 +
-+/* Maximum pathname length before accesses will start getting rejected */
-+unsigned int apparmor_path_max = 2 * PATH_MAX;
-+module_param_named(path_max, apparmor_path_max, aauint, S_IRUSR | S_IWUSR);
-+MODULE_PARM_DESC(apparmor_path_max, "Maximum pathname length allowed");
++extern const char *profile_mode_names[];
++#define APPARMOR_NAMES_MAX_INDEX 3
 +
-+/* Boot time disable flag */
-+#ifdef CONFIG_SECURITY_APPARMOR_DISABLE
-+#define AA_ENABLED_PERMS 0600
-+#else
-+#define AA_ENABLED_PERMS 0400
-+#endif
-+static int param_set_aa_enabled(const char *val, struct kernel_param *kp);
-+unsigned int apparmor_enabled = CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE;
-+module_param_call(enabled, param_set_aa_enabled, param_get_aauint,
-+                &apparmor_enabled, AA_ENABLED_PERMS);
-+MODULE_PARM_DESC(apparmor_enabled, "Enable/Disable Apparmor on boot");
++#define PROFILE_COMPLAIN(_profile)                            \
++      ((g_profile_mode == APPARMOR_COMPLAIN) || ((_profile) &&        \
++                                      (_profile)->mode == APPARMOR_COMPLAIN))
 +
-+static int __init apparmor_enabled_setup(char *str)
-+{
-+      apparmor_enabled = simple_strtol(str, NULL, 0);
-+      return 1;
-+}
-+__setup("apparmor=", apparmor_enabled_setup);
++#define PROFILE_KILL(_profile)                                        \
++      ((g_profile_mode == APPARMOR_KILL) || ((_profile) &&    \
++                                      (_profile)->mode == APPARMOR_KILL))
 +
-+static int param_set_aabool(const char *val, struct kernel_param *kp)
-+{
-+      if (aa_task_context(current))
-+              return -EPERM;
-+      return param_set_bool(val, kp);
-+}
++#define PROFILE_IS_HAT(_profile) \
++      ((_profile) && (_profile)->flags & PFLAG_HAT)
 +
-+static int param_get_aabool(char *buffer, struct kernel_param *kp)
-+{
-+      if (aa_task_context(current))
-+              return -EPERM;
-+      return param_get_bool(buffer, kp);
-+}
 +
-+static int param_set_aauint(const char *val, struct kernel_param *kp)
-+{
-+      if (aa_task_context(current))
-+              return -EPERM;
-+      return param_set_uint(val, kp);
-+}
++/*
++ * FIXME: currently need a clean way to replace and remove profiles as a
++ * set.  It should be done at the namespace level.
++ * Either, with a set of profiles loaded at the namespace level or via
++ * a mark and remove marked interface.
++ */
++enum profile_mode {
++      APPARMOR_ENFORCE,               /* enforce access rules */
++      APPARMOR_COMPLAIN,              /* allow and log access violations */
++      APPARMOR_KILL,                  /* kill task on access violation */
++};
 +
-+static int param_get_aauint(char *buffer, struct kernel_param *kp)
-+{
-+      if (aa_task_context(current))
-+              return -EPERM;
-+      return param_get_uint(buffer, kp);
-+}
++enum profile_flags {
++      PFLAG_HAT = 1,                  /* profile is a hat */
++      PFLAG_UNCONFINED = 2,           /* profile is the unconfined profile */
++      PFLAG_NULL = 4,                 /* profile is null learning profile */
++      PFLAG_IX_ON_NAME_ERROR = 8,     /* fallback to ix on name lookup fail */
++      PFLAG_IMMUTABLE = 0x10,         /* don't allow changes/replacement */
++      PFLAG_USER_DEFINED = 0x20,      /* user based profile */
++      PFLAG_NO_LIST_REF = 0x40,       /* list doesn't keep profile ref */
++};
 +
-+/* allow run time disabling of apparmor */
-+static int param_set_aa_enabled(const char *val, struct kernel_param *kp)
-+{
-+      char *endp;
-+      unsigned long l;
++#define AA_NEW_SID 0
 +
-+      if (!apparmor_initialized) {
-+              apparmor_enabled = 0;
-+              return 0;
-+      }
++struct aa_profile;
 +
-+      if (aa_task_context(current))
-+              return -EPERM;
++/* struct aa_policy_common - common part of both namespaces and profiles
++ * @name: name of the object
++ * @count: reference count of the obj
++ * lock: lock for modifying the object
++ * @list: list object is on
++ * @profiles: head of the profiles list contained in the object
++ */
++struct aa_policy_common {
++      char *name;
++      struct kref count;
++      rwlock_t lock;
++      struct list_head list;
++      struct list_head profiles;
++};
 +
-+      if (!apparmor_enabled)
-+              return -EINVAL;
++/* struct aa_ns_acct - accounting of profiles in namespace
++ * @max_size: maximum space allowed for all profiles in namespace
++ * @max_count: maximum number of profiles that can be in this namespace
++ * @size: current size of profiles
++ * @count: current count of profiles (includes null profiles)
++ */
++struct aa_ns_acct {
++      int max_size;
++      int max_count;
++      int size;
++      int count;
++};
 +
-+      if (!val)
-+              return -EINVAL;
++/* struct aa_namespace - namespace for a set of profiles
++ * @name: the name of the namespace
++ * @list: list the namespace is on
++ * @profiles: list of profile in the namespace
++ * @acct: accounting for the namespace
++ * @profile_count: count of profiles on @profiles list
++ * @size: accounting of how much memory is consumed by the contained profiles
++ * @unconfined: special unconfined profile for the namespace
++ * @count: reference count on the namespace
++ * @lock: lock for adding/removing profile to the namespace
++ *
++ * An aa_namespace defines the set profiles that are searched to determine
++ * which profile to attach to a task.  Profiles can not be shared between
++ * aa_namespaces and profile names within a namespace are guarenteed to be
++ * unique.  When profiles in seperate namespaces have the same name they
++ * are NOT considered to be equivalent.
++ *
++ * Namespace names must be unique and can not contain the characters :/\0
++ *
++ * FIXME TODO: add vserver support so a vserer gets a default namespace
++ */
++struct aa_namespace {
++      struct aa_policy_common base;
++      struct aa_ns_acct acct;
++      int is_stale;
++      struct aa_profile *unconfined;
++};
 +
-+      l = simple_strtoul(val, &endp, 0);
-+      if (endp == val || l != 0)
-+              return -EINVAL;
 +
-+      apparmor_enabled = 0;
-+      apparmor_disable();
-+      return 0;
-+}
++/* struct aa_profile - basic confinement data
++ * @base - base componets of the profile (name, refcount, lists, lock ...)
++ * @fqname - The fully qualified profile name, less the namespace name
++ * @ns: namespace the profile is in
++ * @parent: parent profile of this profile, if one exists
++ * @replacedby: is set profile that replaced this profile
++ * @xmatch: optional extended matching for unconfined executables names
++ * @xmatch_plen: xmatch prefix len, used to determine xmatch priority
++ * @sid: the unique security id number of this profile
++ * @audit: the auditing mode of the profile
++ * @mode: the enforcement mode of the profile
++ * @flags: flags controlling profile behavior
++ * @size: the memory consumed by this profiles rules
++ * @file: The set of rules governing basic file access and domain transitions
++ * @caps: capabilities for the profile
++ * @net: network controls for the profile
++ * @rlimits: rlimits for the profile
++ *
++ * The AppArmor profile contains the basic confinement data.  Each profile
++ * has a name, and exist in a namespace.  The @name and @exec_match are
++ * used to determine profile attachment against unconfined tasks.  All other
++ * attachments are determined by in profile X transition rules.
++ *
++ * The @replacedby field is write protected by the profile lock.  Reads
++ * are assumed to be atomic, and are done without locking.
++ *
++ * Profiles have a hierachy where hats and children profiles keep
++ * a reference to their parent.
++ *
++ * Profile names can not begin with a : and can not contain the \0
++ * character.  If a profile name begins with / it will be considered when
++ * determining profile attachment on "unconfined" tasks.
++ */
++struct aa_profile {
++      struct aa_policy_common base;
++      char *fqname;
 +
-+static int aa_reject_syscall(struct task_struct *task, gfp_t flags,
-+                           const char *name)
-+{
-+      struct aa_profile *profile = aa_get_profile(task);
-+      int error = 0;
++      struct aa_namespace *ns;
++      struct aa_profile *parent;
++      struct aa_profile *replacedby;
++
++      struct aa_dfa *xmatch;
++      int xmatch_len;
++      u32 sid;
++      enum audit_mode audit;
++      enum profile_mode mode;
++      u32 flags;
++      int size;
++
++      struct aa_file_rules file;
++      struct aa_caps caps;
++      struct aa_net net;
++      struct aa_rlimit rlimits;
++};
 +
-+      if (profile) {
-+              error = aa_audit_syscallreject(profile, flags, name);
-+              aa_put_profile(profile);
-+      }
 +
-+      return error;
-+}
++extern struct list_head ns_list;
++extern rwlock_t ns_list_lock;
 +
-+static int apparmor_ptrace(struct task_struct *parent,
-+                         struct task_struct *child)
-+{
-+      struct aa_task_context *cxt;
-+      int error = 0;
++extern struct aa_namespace *default_namespace;
++extern enum profile_mode g_profile_mode;
++ 
 +
-+      /*
-+       * parent can ptrace child when
-+       * - parent is unconfined
-+       * - parent & child are in the same namespace &&
-+       *   - parent is in complain mode
-+       *   - parent and child are confined by the same profile
-+       *   - parent profile has CAP_SYS_PTRACE
-+       */
++void aa_add_profile(struct aa_policy_common *common,
++                  struct aa_profile *profile);
 +
-+      rcu_read_lock();
-+      cxt = aa_task_context(parent);
-+      if (cxt) {
-+              if (parent->nsproxy != child->nsproxy) {
-+                      struct aa_audit sa;
-+                      memset(&sa, 0, sizeof(sa));
-+                      sa.operation = "ptrace";
-+                      sa.gfp_mask = GFP_ATOMIC;
-+                      sa.parent = parent->pid;
-+                      sa.task = child->pid;
-+                      sa.info = "different namespaces";
-+                      aa_audit_reject(cxt->profile, &sa);
-+                      error = -EPERM;
-+              } else {
-+                      struct aa_task_context *child_cxt =
-+                              aa_task_context(child);
-+
-+                      error = aa_may_ptrace(cxt, child_cxt ?
-+                                                 child_cxt->profile : NULL);
-+                      if (PROFILE_COMPLAIN(cxt->profile)) {
-+                              struct aa_audit sa;
-+                              memset(&sa, 0, sizeof(sa));
-+                              sa.operation = "ptrace";
-+                              sa.gfp_mask = GFP_ATOMIC;
-+                              sa.parent = parent->pid;
-+                              sa.task = child->pid;
-+                              aa_audit_hint(cxt->profile, &sa);
-+                      }
-+              }
-+      }
-+      rcu_read_unlock();
++int alloc_default_namespace(void);
++void free_default_namespace(void);
++struct aa_namespace *alloc_aa_namespace(const char *name);
++void free_aa_namespace_kref(struct kref *kref);
++void free_aa_namespace(struct aa_namespace *ns);
++struct aa_namespace *__aa_find_namespace(struct list_head *head,
++                                       const char *name);
++                                       
++struct aa_namespace *aa_find_namespace(const char *name);
++struct aa_namespace *aa_prepare_namespace(const char *name);
++void aa_remove_namespace(struct aa_namespace *ns);
++struct aa_namespace *aa_prepare_namespace(const char *name);
++void aa_profile_list_release(struct list_head *head);
++void aa_profile_ns_list_release(void);
++void __aa_remove_namespace(struct aa_namespace *ns);
 +
-+      return error;
-+}
 +
-+static int apparmor_capable(struct task_struct *task, int cap)
++static inline struct aa_policy_common *aa_get_common(struct aa_policy_common *c)
 +{
-+      int error;
-+      struct aa_task_context *cxt;
-+
-+      /* cap_capable returns 0 on success, else -EPERM */
-+      error = cap_capable(task, cap);
-+
-+      rcu_read_lock();
-+      cxt = aa_task_context(task);
-+      if (cxt && (!error || cap_raised(cxt->profile->set_caps, cap)))
-+              error = aa_capability(cxt, cap);
-+      rcu_read_unlock();
++      if (c)
++              kref_get(&c->count);
 +
-+      return error;
++      return c;
 +}
 +
-+static int apparmor_sysctl(struct ctl_table *table, int op)
++static inline struct aa_namespace *aa_get_namespace(struct aa_namespace *ns)
 +{
-+      struct aa_profile *profile = aa_get_profile(current);
-+      int error = 0;
-+
-+      if (profile) {
-+              char *buffer, *name;
-+              int mask;
-+
-+              mask = 0;
-+              if (op & 4)
-+                      mask |= MAY_READ;
-+              if (op & 2)
-+                      mask |= MAY_WRITE;
-+
-+              error = -ENOMEM;
-+              buffer = (char*)__get_free_page(GFP_KERNEL);
-+              if (!buffer)
-+                      goto out;
-+              name = sysctl_pathname(table, buffer, PAGE_SIZE);
-+              if (name && name - buffer >= 5) {
-+                      name -= 5;
-+                      memcpy(name, "/proc", 5);
-+                      error = aa_perm_path(profile, "sysctl", name, mask, 0);
-+              }
-+              free_page((unsigned long)buffer);
-+      }
++      if (ns)
++              kref_get(&(ns->base.count));
 +
-+out:
-+      aa_put_profile(profile);
-+      return error;
++      return ns;
 +}
 +
-+static int apparmor_bprm_set_security(struct linux_binprm *bprm)
++static inline void aa_put_namespace(struct aa_namespace *ns)
 +{
-+      /* handle capability bits with setuid, etc */
-+      cap_bprm_set_security(bprm);
-+      /* already set based on script name */
-+      if (bprm->sh_bang)
-+              return 0;
-+      return aa_register(bprm);
++      if (ns)
++              kref_put(&ns->base.count, free_aa_namespace_kref);
++}
++
++
++
++struct aa_profile *alloc_aa_profile(const char *name);
++struct aa_profile *aa_alloc_null_profile(struct aa_profile *parent, int hat);
++void free_aa_profile_kref(struct kref *kref);
++void free_aa_profile(struct aa_profile *profile);
++struct aa_profile *__aa_find_profile(struct list_head *head, const char *name);
++struct aa_profile *aa_find_child(struct aa_profile *parent, const char *name);
++struct aa_policy_common *__aa_find_parent_by_fqname(struct aa_namespace *ns,
++                                                  const char *fqname);
++struct aa_profile *__aa_find_profile_by_fqname(struct aa_namespace *ns,
++                                             const char *fqname);
++struct aa_profile *aa_find_profile_by_fqname(struct aa_namespace *ns,
++                                           const char *name);
++struct aa_profile *aa_match_profile(struct aa_namespace *ns, const char *name);
++struct aa_profile *aa_profile_newest(struct aa_profile *profile);
++struct aa_profile *aa_sys_find_attach(struct aa_namespace *ns,
++                                    const char *name);
++void __aa_add_profile(struct aa_policy_common *common,
++                    struct aa_profile *profile);
++void __aa_remove_profile(struct aa_profile *profile,
++                       struct aa_profile *replacement);
++void __aa_replace_profile(struct aa_profile *profile,
++                        struct aa_profile *replacement);
++void __aa_profile_list_release(struct list_head *head);
++
++static inline struct aa_profile *aa_filtered_profile(struct aa_profile *profile)
++{
++      if (profile->flags & PFLAG_UNCONFINED)
++              return NULL;
++      return profile;
 +}
 +
-+static int apparmor_bprm_secureexec(struct linux_binprm *bprm)
++/**
++ * aa_get_profile - increment refcount on profile @p
++ * @p: profile
++ */
++static inline struct aa_profile *aa_get_profile(struct aa_profile *p)
 +{
-+      int ret = cap_bprm_secureexec(bprm);
-+
-+      if (!ret && (unsigned long)bprm->security & AA_SECURE_EXEC_NEEDED) {
-+              AA_DEBUG("%s: secureexec required for %s\n",
-+                       __FUNCTION__, bprm->filename);
-+              ret = 1;
-+      }
++      if (p)
++              kref_get(&(p->base.count));
 +
-+      return ret;
++      return p;
 +}
 +
-+static int apparmor_sb_mount(char *dev_name, struct nameidata *nd, char *type,
-+                            unsigned long flags, void *data)
++/**
++ * aa_put_profile - decrement refcount on profile @p
++ * @p: profile
++ */
++static inline void aa_put_profile(struct aa_profile *p)
 +{
-+      return aa_reject_syscall(current, GFP_KERNEL, "mount");
++      if (p)
++              kref_put(&p->base.count, free_aa_profile_kref);
 +}
 +
-+static int apparmor_umount(struct vfsmount *mnt, int flags)
++static inline int PROFILE_AUDIT_MODE(struct aa_profile *profile)
 +{
-+      return aa_reject_syscall(current, GFP_KERNEL, "umount");
++      if (g_apparmor_audit != AUDIT_NORMAL)
++              return g_apparmor_audit;
++      if (profile)
++              return profile->audit;
++      return AUDIT_NORMAL;
 +}
 +
-+static int apparmor_inode_mkdir(struct inode *dir, struct dentry *dentry,
-+                              struct vfsmount *mnt, int mask)
-+{
-+      struct aa_profile *profile;
-+      int error = 0;
++#endif        /* __AA_POLICY_H */
 +
-+      if (!mnt || !mediated_filesystem(dir))
-+              goto out;
+diff --git a/security/apparmor/include/policy_interface.h b/security/apparmor/include/policy_interface.h
+new file mode 100644
+index 0000000..1440876
+--- /dev/null
++++ b/security/apparmor/include/policy_interface.h
+@@ -0,0 +1,22 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor policy loading interface function definitions.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+      profile = aa_get_profile(current);
++#ifndef __POLICY_INTERFACE_H
++#define __POLICY_INTERFACE_H
 +
-+      if (profile)
-+              error = aa_perm_dir(profile, "inode_mkdir", dentry, mnt,
-+                                  MAY_WRITE);
++ssize_t aa_interface_add_profiles(void *data, size_t size);
++ssize_t aa_interface_replace_profiles(void *udata, size_t size);
++ssize_t aa_interface_remove_profiles(char *name, size_t size);
 +
-+      aa_put_profile(profile);
++#endif        /* __POLICY_INTERFACE_H */
+diff --git a/security/apparmor/include/procattr.h b/security/apparmor/include/procattr.h
+new file mode 100644
+index 0000000..52e46c5
+--- /dev/null
++++ b/security/apparmor/include/procattr.h
+@@ -0,0 +1,26 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor /proc/<pid>/attr/ interface function defintions.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+out:
-+      return error;
-+}
++#ifndef __AA_PROCATTR_H
++#define __AA_PROCATTR_H
 +
-+static int apparmor_inode_rmdir(struct inode *dir, struct dentry *dentry,
-+                              struct vfsmount *mnt)
-+{
-+      struct aa_profile *profile;
-+      int error = 0;
++#define AA_DO_TEST 1
 +
-+      if (!mnt || !mediated_filesystem(dir))
-+              goto out;
++int aa_getprocattr(struct aa_namespace *ns, struct aa_profile *profile,
++                 char **string);
++int aa_setprocattr_changehat(char *args, int test);
++int aa_setprocattr_changeprofile(char *args, int onexec, int test);
++int aa_setprocattr_permipc(char *args);
 +
-+      profile = aa_get_profile(current);
++#endif        /* __AA_PROCATTR_H */
+diff --git a/security/apparmor/include/resource.h b/security/apparmor/include/resource.h
+new file mode 100644
+index 0000000..0662c91
+--- /dev/null
++++ b/security/apparmor/include/resource.h
+@@ -0,0 +1,46 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor resource limits function defintions.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+      if (profile)
-+              error = aa_perm_dir(profile, "inode_rmdir", dentry, mnt,
-+                                  MAY_WRITE);
++#ifndef __AA_RESOURCE_H
++#define __AA_RESOURCE_H
 +
-+      aa_put_profile(profile);
++#include <linux/resource.h>
++#include <linux/sched.h>
 +
-+out:
-+      return error;
-+}
++struct aa_profile;
 +
-+static int aa_permission(const char *operation, struct inode *inode,
-+                       struct dentry *dentry, struct vfsmount *mnt,
-+                       int mask, int check)
-+{
-+      int error = 0;
++/* struct aa_rlimit - rlimits settings for the profile
++ * @mask: which hard limits to set
++ * @limits: rlimit values that override task limits
++ *
++ * AppArmor rlimits are used to set confined task rlimits.  Only the
++ * limits specified in @mask will be controlled by apparmor.
++ */
++struct aa_rlimit {
++      unsigned int mask;
++      struct rlimit limits[RLIM_NLIMITS];
++};
 +
-+      if (mnt && mediated_filesystem(inode)) {
-+              struct aa_profile *profile;
 +
-+              profile = aa_get_profile(current);
-+              if (profile)
-+                      error = aa_perm(profile, operation, dentry, mnt, mask,
-+                                      check);
-+              aa_put_profile(profile);
-+      }
-+      return error;
++int aa_task_setrlimit(struct aa_profile *profile, unsigned int resource,
++                    struct rlimit *new_rlim);
++
++void __aa_transition_rlimits(struct aa_profile *old, struct aa_profile *new);
++
++static inline void aa_free_rlimit_rules(struct aa_rlimit *rlims)
++{
++      /* NOP */
 +}
 +
-+static inline int aa_mask_permissions(int mask)
++#endif        /* __AA_RESOURCE_H */
+diff --git a/security/apparmor/include/sid.h b/security/apparmor/include/sid.h
+new file mode 100644
+index 0000000..83e3590
+--- /dev/null
++++ b/security/apparmor/include/sid.h
+@@ -0,0 +1,46 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor security identifier (sid) definitions
++ *
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
++
++#ifndef __AA_SID_H
++#define __AA_SID_H
++
++#include <linux/types.h>
++
++struct aa_profile;
++
++#define AA_ALLOC_USR_SID 1
++#define AA_ALLOC_SYS_SID 0
++
++u32 aa_alloc_sid(int is_usr);
++void aa_free_sid(u32 sid);
++int aa_add_sid_profile(u32 sid, struct aa_profile *profile);
++int aa_replace_sid_profile(u32 sid, struct aa_profile *profile);
++struct aa_profile *aa_get_sid_profile(u32 sid);
++
++
++static inline u32 aa_compound_sid(u32 sys, u32 usr)
 +{
-+      if (mask & MAY_APPEND)
-+              mask &= (MAY_READ | MAY_APPEND | MAY_EXEC);
-+      else
-+              mask &= (MAY_READ | MAY_WRITE | MAY_EXEC);
-+      return mask;
++      return sys | usr;
 +}
 +
-+static int apparmor_inode_create(struct inode *dir, struct dentry *dentry,
-+                               struct vfsmount *mnt, int mask)
++static inline u32 aa_usr_sid(u32 sid)
 +{
-+      return aa_permission("inode_create", dir, dentry, mnt, MAY_APPEND, 0);
++      return sid & 0xffff0000;
 +}
 +
-+static int apparmor_inode_link(struct dentry *old_dentry,
-+                             struct vfsmount *old_mnt, struct inode *dir,
-+                             struct dentry *new_dentry,
-+                             struct vfsmount *new_mnt)
++static inline u32 aa_sys_sid(u32 sid)
 +{
-+      int error = 0;
-+      struct aa_profile *profile;
++      return sid & 0xffff;
++}
 +
-+      if (!old_mnt || !new_mnt || !mediated_filesystem(dir))
-+              goto out;
++#endif        /* __AA_SID_H */
+diff --git a/security/apparmor/ipc.c b/security/apparmor/ipc.c
+new file mode 100644
+index 0000000..381c164
+--- /dev/null
++++ b/security/apparmor/ipc.c
+@@ -0,0 +1,106 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor ipc mediation
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+      profile = aa_get_profile(current);
++#include <linux/gfp.h>
++#include <linux/ptrace.h>
 +
-+      if (profile)
-+              error = aa_link(profile, new_dentry, new_mnt,
-+                              old_dentry, old_mnt);
++#include "include/audit.h"
++#include "include/capability.h"
++#include "include/context.h"
++#include "include/policy.h"
 +
-+      aa_put_profile(profile);
 +
-+out:
-+      return error;
-+}
++struct aa_audit_ptrace {
++      struct aa_audit base;
 +
-+static int apparmor_inode_unlink(struct inode *dir, struct dentry *dentry,
-+                               struct vfsmount *mnt)
-+{
-+      int check = 0;
++      pid_t tracer, tracee;
++};
 +
-+      if (S_ISDIR(dentry->d_inode->i_mode))
-+              check |= AA_CHECK_DIR;
-+      return aa_permission("inode_unlink", dir, dentry, mnt, MAY_WRITE,
-+                           check);
++/* call back to audit ptrace fields */
++static void audit_cb(struct audit_buffer *ab, void *va)
++{
++      struct aa_audit_ptrace *sa = va;
++      audit_log_format(ab, " tracer=%d tracee=%d", sa->tracer, sa->tracee);
 +}
 +
-+static int apparmor_inode_symlink(struct inode *dir, struct dentry *dentry,
-+                                struct vfsmount *mnt, const char *old_name)
++static int aa_audit_ptrace(struct aa_profile *profile,
++                         struct aa_audit_ptrace *sa)
 +{
-+      return aa_permission("inode_symlink", dir, dentry, mnt, MAY_WRITE, 0);
++      return aa_audit(AUDIT_APPARMOR_AUTO, profile, (struct aa_audit *)sa,
++                      audit_cb);
 +}
 +
-+static int apparmor_inode_mknod(struct inode *dir, struct dentry *dentry,
-+                              struct vfsmount *mnt, int mode, dev_t dev)
++int aa_may_ptrace(struct task_struct *tracer_task, struct aa_profile *tracer,
++                struct aa_profile *tracee, unsigned int mode)
 +{
-+      return aa_permission("inode_mknod", dir, dentry, mnt, MAY_WRITE, 0);
++      /* TODO: currently only based on capability, not extended ptrace
++       *       rules,
++       *       Test mode for PTRACE_MODE_READ || PTRACE_MODE_ATTACH
++       */
++
++      if (!tracer || tracer == tracee)
++              return 0;
++      /* log this capability request */
++      return aa_capable(tracer_task, tracer, CAP_SYS_PTRACE, 1);
 +}
 +
-+static int apparmor_inode_rename(struct inode *old_dir,
-+                               struct dentry *old_dentry,
-+                               struct vfsmount *old_mnt,
-+                               struct inode *new_dir,
-+                               struct dentry *new_dentry,
-+                               struct vfsmount *new_mnt)
++int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee,
++            unsigned int mode)
 +{
-+      struct aa_profile *profile;
++      /*
++       * tracer can ptrace tracee when
++       * - tracer is unconfined ||
++       * - tracer & tracee are in the same namespace &&
++       *   - tracer is in complain mode
++       *   - tracer has rules allowing it to trace tracee currently this is:
++       *       - confined by the same profile ||
++       *       - tracer profile has CAP_SYS_PTRACE
++       */
++
++      struct aa_profile *tracer_p;
++      const struct cred *cred = aa_get_task_policy(tracer, &tracer_p);
 +      int error = 0;
 +
-+      if ((!old_mnt && !new_mnt) || !mediated_filesystem(old_dir))
-+              goto out;
++      if (tracer_p) {
++              struct aa_audit_ptrace sa;
++              memset(&sa, 0, sizeof(sa));
++              sa.base.operation = "ptrace";
++              sa.base.gfp_mask = GFP_ATOMIC;
++              sa.tracer = tracer->pid;
++              sa.tracee = tracee->pid;
++              /* FIXME: different namespace restriction can be lifted
++               * if, namespace are matched to AppArmor namespaces
++               */
++              if (tracer->nsproxy != tracee->nsproxy) {
++                      sa.base.info = "different namespaces";
++                      sa.base.error = -EPERM;
++                      aa_audit(AUDIT_APPARMOR_DENIED, tracer_p, &sa.base,
++                               audit_cb);
++              } else {
++                      struct aa_profile *tracee_p;
++                      struct cred *lcred = aa_get_task_policy(tracee,
++                                                              &tracee_p);
 +
-+      profile = aa_get_profile(current);
++                      sa.base.error = aa_may_ptrace(tracer, tracer_p,
++                                                    tracee_p, mode);
++                      sa.base.error = aa_audit_ptrace(tracer_p, &sa);
 +
-+      if (profile) {
-+              struct inode *inode = old_dentry->d_inode;
-+              int check = 0;
-+
-+              if (inode && S_ISDIR(inode->i_mode))
-+                      check |= AA_CHECK_DIR;
-+              if (old_mnt)
-+                      error = aa_perm(profile, "inode_rename", old_dentry,
-+                                      old_mnt, MAY_READ | MAY_WRITE, check);
-+
-+              if (!error && new_mnt) {
-+                      error = aa_perm(profile, "inode_rename", new_dentry,
-+                                      new_mnt, MAY_WRITE, check);
++                      put_cred(lcred);
 +              }
++              error = sa.base.error;
 +      }
++      put_cred(cred);
 +
-+      aa_put_profile(profile);
-+
-+out:
 +      return error;
 +}
+diff --git a/security/apparmor/lib.c b/security/apparmor/lib.c
+new file mode 100644
+index 0000000..5dbd16d
+--- /dev/null
++++ b/security/apparmor/lib.c
+@@ -0,0 +1,100 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains basic common functions used in AppArmor
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+static int apparmor_inode_permission(struct inode *inode, int mask,
-+                                   struct nameidata *nd)
-+{
-+      int check = 0, error = 0;
-+
-+      if (!nd || nd->flags & (LOOKUP_PARENT | LOOKUP_CONTINUE))
-+              goto out;
-+      mask = aa_mask_permissions(mask);
-+      if (S_ISDIR(inode->i_mode)) {
-+              check |= AA_CHECK_DIR;
-+              /* allow traverse accesses to directories */
-+              mask &= ~MAY_EXEC;
-+      }
-+      error = aa_permission("inode_permission", inode, nd->path.dentry,
-+                            nd->path.mnt,
-+                            mask, check);
++#include <linux/slab.h>
++#include <linux/string.h>
 +
-+out:
-+      if (!error)
-+              error = AA_SECONDARY(inode_permission, inode, mask, nd);
++#include "include/audit.h"
 +
-+      return error;
++void info_message(const char *str)
++{
++      struct aa_audit sa;
++      memset(&sa, 0, sizeof(sa));
++      sa.gfp_mask = GFP_KERNEL;
++      sa.info = str;
++      printk(KERN_INFO "AppArmor: %s\n", str);
++      if (audit_enabled)
++              aa_audit(AUDIT_APPARMOR_STATUS, NULL, &sa, NULL);
 +}
 +
-+static int apparmor_inode_setattr(struct dentry *dentry, struct vfsmount *mnt,
-+                                struct iattr *iattr)
++char *strchrnul(const char *s, int c)
 +{
-+      int error = 0;
++      for (; *s != (char)c && *s != '\0'; ++s)
++              ;
++      return (char *)s;
++}
 +
-+      if (!mnt)
-+              goto out;
++char *aa_split_name_from_ns(char *args, char **ns_name)
++{
++      char *name = strstrip(args);
 +
-+      if (mediated_filesystem(dentry->d_inode)) {
-+              struct aa_profile *profile;
++      *ns_name  = NULL;
++      if (args[0] == ':') {
++              char *split = strstrip(strchr(&args[1], ':'));
 +
-+              profile = aa_get_profile(current);
-+              /*
-+               * Mediate any attempt to change attributes of a file
-+               * (chmod, chown, chgrp, etc)
-+               */
-+              if (profile)
-+                      error = aa_attr(profile, dentry, mnt, iattr);
++              if (!split)
++                      return NULL;
 +
-+              aa_put_profile(profile);
++              *split = 0;
++              *ns_name = &args[1];
++              name = strstrip(split + 1);
 +      }
++      if (*name == 0)
++              name = NULL;
 +
-+out:
-+      return error;
++      return name;
 +}
 +
-+static int aa_xattr_permission(struct dentry *dentry, struct vfsmount *mnt,
-+                             const char *operation, int mask,
-+                             struct file *file)
++char *new_compound_name(const char *n1, const char *n2)
 +{
-+      int error = 0;
++      char *name = kmalloc(strlen(n1) + strlen(n2) + 3, GFP_KERNEL);
++      if (name)
++              sprintf(name, "%s//%s", n1, n2);
++      return name;
++}
 +
-+      if (mnt && mediated_filesystem(dentry->d_inode)) {
-+              struct aa_profile *profile = aa_get_profile(current);
-+              int check = file ? AA_CHECK_FD : 0;
++/**
++ * aa_strneq - compare null terminated @str to a non null terminated substring
++ * @str: a null terminated string
++ * @sub: a substring, not necessarily null terminated
++ * @len: length of @sub to compare
++ *
++ * The @str string must be full consumed for this to be considered a match
++ */
++int aa_strneq(const char *str, const char *sub, int len)
++{
++      int res = strncmp(str, sub, len);
++      if (res)
++              return 0;
++      if (str[len] == 0)
++              return 1;
++      return 0;
++}
 +
-+              if (profile)
-+                      error = aa_perm_xattr(profile, operation, dentry, mnt,
-+                                            mask, check);
-+              aa_put_profile(profile);
++const char *fqname_subname(const char *name)
++{
++      char *split;
++      /* check for namespace which begins with a : and ends with : or \0 */
++      name = strstrip((char *) name);
++      if (*name == ':') {
++              split = strchrnul(name + 1, ':');
++              if (*split == '\0')
++                      return NULL;
++              name = strstrip(split + 1);
 +      }
-+
-+      return error;
++      for (split = strstr(name, "//"); split; split = strstr(name, "//")) {
++              name = split + 2;
++      }
++      return name;
 +}
+diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
+new file mode 100644
+index 0000000..5becf5e
+--- /dev/null
++++ b/security/apparmor/lsm.c
+@@ -0,0 +1,1063 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor LSM hooks.
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+static int apparmor_inode_setxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                                 char *name, void *value, size_t size,
-+                                 int flags, struct file *file)
++#include <linux/security.h>
++#include <linux/moduleparam.h>
++#include <linux/mm.h>
++#include <linux/mman.h>
++#include <linux/mount.h>
++#include <linux/namei.h>
++#include <linux/ptrace.h>
++#include <linux/ctype.h>
++#include <linux/sysctl.h>
++#include <linux/audit.h>
++#include <net/sock.h>
++
++#include "include/apparmor.h"
++#include "include/apparmorfs.h"
++#include "include/audit.h"
++#include "include/capability.h"
++#include "include/context.h"
++#include "include/file.h"
++#include "include/ipc.h"
++#include "include/net.h"
++#include "include/path.h"
++#include "include/policy.h"
++#include "include/procattr.h"
++
++/* Flag indicating whether initialization completed */
++int apparmor_initialized;
++
++
++/*
++ * LSM hook functions
++ */
++
++/*
++ * prepare new aa_task_context for modification by prepare_cred block
++ */
++static int apparmor_cred_prepare(struct cred *new, const struct cred *old,
++                               gfp_t gfp)
 +{
-+      return aa_xattr_permission(dentry, mnt, "xattr set", MAY_WRITE, file);
++      struct aa_task_context *cxt = aa_dup_task_context(old->security, gfp);
++      if (!cxt)
++              return -ENOMEM;
++      new->security = cxt;
++      return 0;
 +}
 +
-+static int apparmor_inode_getxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                                 char *name, struct file *file)
++/*
++ * free the associated aa_task_context and put its profiles
++ */
++static void apparmor_cred_free(struct cred *cred)
 +{
-+      return aa_xattr_permission(dentry, mnt, "xattr get", MAY_READ, file);
++      struct aa_task_context *cxt = cred->security;
++      cred->security = NULL;
++      aa_free_task_context(cxt);
 +}
 +
-+static int apparmor_inode_listxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                                  struct file *file)
++
++static int apparmor_ptrace_may_access(struct task_struct *child,
++                                    unsigned int mode)
 +{
-+      return aa_xattr_permission(dentry, mnt, "xattr list", MAY_READ, file);
++      return aa_ptrace(current, child, mode);
 +}
 +
-+static int apparmor_inode_removexattr(struct dentry *dentry,
-+                                    struct vfsmount *mnt, char *name,
-+                                    struct file *file)
++
++static int apparmor_ptrace_traceme(struct task_struct *parent)
 +{
-+      return aa_xattr_permission(dentry, mnt, "xattr remove", MAY_WRITE,
-+                                 file);
++      return aa_ptrace(parent, current, PTRACE_MODE_ATTACH);
 +}
 +
-+static int aa_file_permission(const char *op, struct file *file, int mask)
++/* Derived from security/commoncap.c:cap_capget */
++static int apparmor_capget(struct task_struct *target, kernel_cap_t *effective,
++                         kernel_cap_t *inheritable, kernel_cap_t *permitted)
 +{
 +      struct aa_profile *profile;
-+      struct aa_profile *file_profile = (struct aa_profile*)file->f_security;
-+      int error = 0;
++      const struct cred *cred;
 +
-+      if (!file_profile)
-+              goto out;
++      rcu_read_lock();
++      cred = __task_cred(target);
++      aa_cred_policy(cred, &profile);
 +
-+      /*
-+       * If this file was opened under a different profile, we
-+       * revalidate the access against the current profile.
-+       */
-+      profile = aa_get_profile(current);
-+      if (profile && (file_profile != profile || mask & AA_MAY_LOCK)) {
-+              struct dentry *dentry = file->f_dentry;
-+              struct vfsmount *mnt = file->f_vfsmnt;
-+              struct inode *inode = dentry->d_inode;
-+              int check = AA_CHECK_FD;
++      *effective   = cred->cap_effective;
++      *inheritable = cred->cap_inheritable;
++      *permitted   = cred->cap_permitted;
 +
-+              /*
-+               * FIXME: We should remember which profiles we revalidated
-+               *        against.
-+               */
-+              if (S_ISDIR(inode->i_mode))
-+                      check |= AA_CHECK_DIR;
-+              error = aa_permission(op, inode, dentry, mnt, mask, check);
++      if (profile) {
++              *effective = cap_combine(*effective, profile->caps.set);
++              *effective = cap_intersect(*effective, profile->caps.allowed);
 +      }
-+      aa_put_profile(profile);
++      rcu_read_unlock();
 +
-+out:
-+      return error;
++      return 0;
 +}
 +
-+static int apparmor_file_permission(struct file *file, int mask)
++static int apparmor_capable(struct task_struct *task, const struct cred *cred,
++                          int cap, int audit)
 +{
-+      return aa_file_permission("file_permission", file,
-+                                aa_mask_permissions(mask));
++      struct aa_profile *profile;
++      /* cap_capable returns 0 on success, else -EPERM */
++      int error = cap_capable(task, cred, cap, audit);
++
++      aa_cred_policy(cred, &profile);
++      if (profile && (!error || cap_raised(profile->caps.set, cap)))
++              error = aa_capable(task, profile, cap, audit);
++
++      return error;
 +}
 +
-+static inline int apparmor_file_lock (struct file *file, unsigned int cmd)
++static int apparmor_sysctl(struct ctl_table *table, int op)
 +{
-+      int mask = AA_MAY_LOCK;
-+      if (cmd == F_WRLCK)
-+              mask |= MAY_WRITE;
-+      return aa_file_permission("file_lock", file, mask);
++      int error = 0;
++      struct aa_profile *profile = aa_current_profile_wupd();
++
++      if (profile) {
++              char *buffer, *name;
++              int mask;
++
++              mask = 0;
++              if (op & 4)
++                      mask |= MAY_READ;
++              if (op & 2)
++                      mask |= MAY_WRITE;
++
++              error = -ENOMEM;
++              buffer = (char *)__get_free_page(GFP_KERNEL);
++              if (!buffer)
++                      goto out;
++
++              /* 
++               * TODO: convert this over to using a global or per
++               * namespace control instead of a hard coded /proc
++               */
++              name = sysctl_pathname(table, buffer, PAGE_SIZE);
++              if (name && name - buffer >= 5) {
++                      struct path_cond cond = { 0, S_IFREG };
++                      name -= 5;
++                      memcpy(name, "/proc", 5);
++                      error = aa_pathstr_perm(profile, "sysctl", name, mask,
++                                              &cond);
++              }
++              free_page((unsigned long)buffer);
++      }
++
++out:
++      return error;
 +}
 +
-+static int apparmor_file_alloc_security(struct file *file)
++static int common_perm(const char *op, struct path *path, u16 mask,
++                     struct path_cond *cond)
 +{
 +      struct aa_profile *profile;
++      int error = 0;
 +
-+      profile = aa_get_profile(current);
++      profile = aa_current_profile();
 +      if (profile)
-+              file->f_security = profile;
++              error = aa_path_perm(profile, op, path, mask, cond);
 +
-+      return 0;
++      return error;
 +}
 +
-+static void apparmor_file_free_security(struct file *file)
++static int common_perm_dentry(const char *op, struct path *dir,
++                            struct dentry *dentry, u16 mask, 
++                            struct path_cond *cond)
 +{
-+      struct aa_profile *file_profile = (struct aa_profile*)file->f_security;
++      struct path path = { dir->mnt, dentry };
 +
-+      aa_put_profile(file_profile);
++      return common_perm(op, &path, mask, cond);
 +}
 +
-+static inline int aa_mmap(struct file *file, const char *operation,
-+                        unsigned long prot, unsigned long flags)
++static int common_perm_rm(const char *op, struct path *dir,
++                        struct dentry *dentry, u16 mask)
 +{
-+      struct dentry *dentry;
-+      int mask = 0;
++      struct inode *inode = dentry->d_inode;
++      struct path_cond cond = {};
 +
-+      if (!file || !file->f_security)
++      if (!dir->mnt || !inode || !mediated_filesystem(inode))
 +              return 0;
 +
-+      if (prot & PROT_READ)
-+              mask |= MAY_READ;
-+      /* Private mappings don't require write perms since they don't
-+       * write back to the files */
-+      if ((prot & PROT_WRITE) && !(flags & MAP_PRIVATE))
-+              mask |= MAY_WRITE;
-+      if (prot & PROT_EXEC)
-+              mask |= AA_EXEC_MMAP;
++      cond.uid = inode->i_uid;
++      cond.mode = inode->i_mode;
 +
-+      dentry = file->f_dentry;
-+      return aa_permission(operation, dentry->d_inode, dentry,
-+                           file->f_vfsmnt, mask, AA_CHECK_FD);
++      return common_perm_dentry(op, dir, dentry, mask, &cond);
 +}
 +
-+static int apparmor_file_mmap(struct file *file, unsigned long reqprot,
-+                            unsigned long prot, unsigned long flags,
-+                            unsigned long addr, unsigned long addr_only)
++static int common_perm_create(const char *op, struct path *dir,
++                            struct dentry *dentry, u16 mask, umode_t mode)
 +{
-+      if ((addr < mmap_min_addr) && !capable(CAP_SYS_RAWIO)) {
-+              struct aa_profile *profile = aa_get_profile(current);
-+              if (profile)
-+                      /* future control check here */
-+                      return -EACCES;
-+              else
-+                      return -EACCES;
-+              aa_put_profile(profile);
-+      }
++      struct path_cond cond = { current_fsuid(), mode };
++
++      if (!dir->mnt || !mediated_filesystem(dir->dentry->d_inode))
++              return 0;
 +
-+      return aa_mmap(file, "file_mmap", prot, flags);
++      return common_perm_dentry(op, dir, dentry, mask, &cond);
 +}
 +
-+static int apparmor_file_mprotect(struct vm_area_struct *vma,
-+                                unsigned long reqprot, unsigned long prot)
++static int apparmor_path_unlink(struct path *dir, struct dentry *dentry)
 +{
-+      return aa_mmap(vma->vm_file, "file_mprotect", prot,
-+                     !(vma->vm_flags & VM_SHARED) ? MAP_PRIVATE : 0);
++      return common_perm_rm("unlink", dir, dentry, MAY_WRITE);
 +}
 +
-+static int apparmor_task_alloc_security(struct task_struct *task)
++static int apparmor_path_mkdir(struct path *dir, struct dentry *dentry,
++                             int mode)
 +{
-+      return aa_clone(task);
++      return common_perm_create("mkdir", dir, dentry, AA_MAY_CREATE, S_IFDIR);
 +}
 +
-+/*
-+ * Called from IRQ context from RCU callback.
-+ */
-+static void apparmor_task_free_security(struct task_struct *task)
++static int apparmor_path_rmdir(struct path *dir, struct dentry *dentry)
++{
++      return common_perm_rm("rmdir", dir, dentry, MAY_WRITE);
++}
++
++static int apparmor_path_mknod(struct path *dir, struct dentry *dentry,
++                             int mode, unsigned int dev)
++{
++      return common_perm_create("mknod", dir, dentry, AA_MAY_CREATE, mode);
++}
++
++static int apparmor_path_truncate(struct path *path, loff_t length,
++                                unsigned int time_attrs)
++{
++      struct path_cond cond = { path->dentry->d_inode->i_uid,
++                                path->dentry->d_inode->i_mode };
++
++      if (!path->mnt || !mediated_filesystem(path->dentry->d_inode))
++              return 0;
++      return common_perm("truncate", path, MAY_WRITE, &cond);
++}
++
++static int apparmor_path_symlink(struct path *dir, struct dentry *dentry,
++                        const char *old_name)
 +{
-+      aa_release(task);
++      return common_perm_create("symlink_create", dir, dentry, AA_MAY_CREATE,
++                                S_IFLNK);
 +}
 +
-+static int apparmor_socket_create(int family, int type, int protocol, int kern)
++static int apparmor_path_link(struct dentry *old_dentry, struct path *new_dir,
++                            struct dentry *new_dentry)
 +{
 +      struct aa_profile *profile;
 +      int error = 0;
 +
-+      if (kern)
++      if (!mediated_filesystem(old_dentry->d_inode))
 +              return 0;
 +
-+      profile = aa_get_profile(current);
++      profile = aa_current_profile_wupd();
 +      if (profile)
-+              error = aa_net_perm(profile, "socket_create", family,
-+                                                      type, protocol);
-+      aa_put_profile(profile);
-+
++              error = aa_path_link(profile, old_dentry, new_dir, new_dentry);
 +      return error;
 +}
 +
-+static int apparmor_socket_post_create(struct socket *sock, int family,
-+                                      int type, int protocol, int kern)
++static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
++                       struct path *new_dir, struct dentry *new_dentry)
 +{
-+      struct sock *sk = sock->sk;
++      struct aa_profile *profile;
++      int error = 0;
 +
-+      if (kern)
++      if (!mediated_filesystem(old_dentry->d_inode))
 +              return 0;
 +
-+      return aa_revalidate_sk(sk, "socket_post_create");
++      profile = aa_current_profile_wupd();
++      if (profile) {
++              struct path old_path = { old_dir->mnt, old_dentry };
++              struct path new_path = { new_dir->mnt, new_dentry };
++              struct path_cond cond = { old_dentry->d_inode->i_uid,
++                                        old_dentry->d_inode->i_mode };
++
++              error = aa_path_perm(profile, "rename_src", &old_path,
++                                   MAY_READ | MAY_WRITE, &cond);
++              if (!error)
++                      error = aa_path_perm(profile, "rename_dest", &new_path,
++                                           AA_MAY_CREATE | MAY_WRITE, &cond);
++                                           
++      }
++      return error;
 +}
 +
-+static int apparmor_socket_bind(struct socket *sock,
-+                              struct sockaddr *address, int addrlen)
++static int apparmor_dentry_open(struct file *file, const struct cred *cred)
 +{
-+      struct sock *sk = sock->sk;
++      struct aa_profile *profile;
++      int error = 0;
++        
++      /* If in exec permission is handled by bprm hooks */
++      if (current->in_execve ||
++          !mediated_filesystem(file->f_path.dentry->d_inode))
++              return 0;
 +
-+      return aa_revalidate_sk(sk, "socket_bind");
-+}
++      aa_cred_policy(cred, &profile);
++      if (profile) {
++              struct aa_file_cxt *fcxt = file->f_security;
++              struct inode *inode = file->f_path.dentry->d_inode; 
++              struct path_cond cond = { inode->i_uid, inode->i_mode };
 +
-+static int apparmor_socket_connect(struct socket *sock,
-+                                      struct sockaddr *address, int addrlen)
-+{
-+      struct sock *sk = sock->sk;
++              error = aa_path_perm(profile, "open", &file->f_path,
++                                   aa_map_file_to_perms(file), &cond);
++              fcxt->profile = aa_get_profile(profile);
++              /* todo cache actual allowed permissions */
++              fcxt->allowed = 0;
++      }
 +
-+      return aa_revalidate_sk(sk, "socket_connect");
++      return error;
 +}
 +
-+static int apparmor_socket_listen(struct socket *sock, int backlog)
++static int apparmor_file_alloc_security(struct file *file)
 +{
-+      struct sock *sk = sock->sk;
++      file->f_security = aa_alloc_file_context(GFP_KERNEL);
++      if (!file->f_security)
++              return -ENOMEM;
++      return 0;
 +
-+      return aa_revalidate_sk(sk, "socket_listen");
 +}
 +
-+static int apparmor_socket_accept(struct socket *sock, struct socket *newsock)
++static void apparmor_file_free_security(struct file *file)
 +{
-+      struct sock *sk = sock->sk;
++      struct aa_file_cxt *cxt = file->f_security;
 +
-+      return aa_revalidate_sk(sk, "socket_accept");
++      aa_free_file_context(cxt);
 +}
 +
-+static int apparmor_socket_sendmsg(struct socket *sock,
-+                                      struct msghdr *msg, int size)
++static int apparmor_file_permission(struct file *file, int mask)
 +{
-+      struct sock *sk = sock->sk;
++      /*
++       * Most basic (rw) file access is revalidated at exec.
++       * The revalidation done here is for parent/child hat
++       * file accesses.
++       *
++       * Currently profile replacement does not cause revalidation
++       * or file revocation.
++       *
++       * TODO: cache profiles that have revalidated?
++       */
++      struct aa_file_cxt *fcxt = file->f_security;
++      struct aa_profile *profile, *fprofile = fcxt->profile;
++      int error = 0;
 +
-+      return aa_revalidate_sk(sk, "socket_sendmsg");
++      if (!fprofile || !file->f_path.mnt ||
++          !mediated_filesystem(file->f_path.dentry->d_inode))
++              return 0;
++
++      profile = aa_current_profile();
++      /* TODO: Enable at exec time revalidation of files
++      if (profile && (fprofile != profile) &&
++          ((PROFILE_IS_HAT(profile) && (profile->parent == fprofile)) ||
++           (PROFILE_IS_HAT(fprofile) && (fprofile->parent == profile))))
++              error = aa_file_perm(profile, "file_perm", file, mask);
++      */
++      if (profile && ((fprofile != profile) || (mask & ~fcxt->allowed)))
++              error = aa_file_perm(profile, "file_perm", file, mask);
++
++      return error;
 +}
 +
-+static int apparmor_socket_recvmsg(struct socket *sock,
-+                                 struct msghdr *msg, int size, int flags)
++static int common_file_perm(const char *op, struct file *file, u16 mask)
 +{
-+      struct sock *sk = sock->sk;
++      const struct aa_file_cxt *fcxt = file->f_security;
++      struct aa_profile *profile, *fprofile = fcxt->profile;
++      int error = 0;
 +
-+      return aa_revalidate_sk(sk, "socket_recvmsg");
++      if (!fprofile || !file->f_path.mnt ||
++          !mediated_filesystem(file->f_path.dentry->d_inode))
++              return 0;
++
++      profile = aa_current_profile_wupd();
++      if (profile && ((fprofile != profile) || (mask & ~fcxt->allowed)))
++              error = aa_file_perm(profile, op, file, mask);
++
++      return error;
 +}
 +
-+static int apparmor_socket_getsockname(struct socket *sock)
++static int apparmor_file_lock(struct file *file, unsigned int cmd)
 +{
-+      struct sock *sk = sock->sk;
++      u16 mask = AA_MAY_LOCK;
 +
-+      return aa_revalidate_sk(sk, "socket_getsockname");
++      if (cmd == F_WRLCK)
++              mask |= MAY_WRITE;
++
++      return common_file_perm("file_lock", file, mask);
 +}
 +
-+static int apparmor_socket_getpeername(struct socket *sock)
-+{
-+      struct sock *sk = sock->sk;
 +
-+      return aa_revalidate_sk(sk, "socket_getpeername");
++/*
++ * AppArmor doesn't current use the fcntl hook.
++ * 
++ * FIXME - these are not implemented yet - REMOVE file_fcntl hook
++ * NOTE: some of the file control commands are further mediated
++ *       by other hooks
++ * F_SETOWN - security_file_set_fowner
++ * F_SETLK - security_file_lock
++ * F_SETLKW - security_file_lock
++ * O_APPEND - AppArmor mediates append as a subset of full write
++ *            so changing from full write to appending write is
++ *            dropping priviledge and not restricted.
++
++
++static int apparmor_file_fcntl(struct file *file, unsigned int cmd,
++                           unsigned long arg)
++{
++      return 0;
 +}
++*/
 +
-+static int apparmor_socket_getsockopt(struct socket *sock, int level,
-+                                      int optname)
++static int common_mmap(struct file *file, const char *operation,
++                 unsigned long prot, unsigned long flags)
 +{
-+      struct sock *sk = sock->sk;
++      struct dentry *dentry;
++      int mask = 0;
 +
-+      return aa_revalidate_sk(sk, "socket_getsockopt");
++      if (!file || !file->f_security)
++              return 0;
++
++      if (prot & PROT_READ)
++              mask |= MAY_READ;
++      /* Private mappings don't require write perms since they don't
++       * write back to the files */
++      if ((prot & PROT_WRITE) && !(flags & MAP_PRIVATE))
++              mask |= MAY_WRITE;
++      if (prot & PROT_EXEC)
++              mask |= AA_EXEC_MMAP;
++
++      dentry = file->f_path.dentry;
++      return common_file_perm(operation, file, mask);
 +}
 +
-+static int apparmor_socket_setsockopt(struct socket *sock, int level,
-+                                      int optname)
++static int apparmor_file_mmap(struct file *file, unsigned long reqprot,
++                            unsigned long prot, unsigned long flags,
++                            unsigned long addr, unsigned long addr_only)
 +{
-+      struct sock *sk = sock->sk;
++      if ((addr < mmap_min_addr) && !capable(CAP_SYS_RAWIO)) {
++              struct aa_profile *profile = aa_current_profile_wupd();
++              if (profile)
++                      /* future control check here */
++                      return -EACCES;
++              else
++                      return -EACCES;
++      }
 +
-+      return aa_revalidate_sk(sk, "socket_setsockopt");
++      return common_mmap(file, "file_mmap", prot, flags);
 +}
 +
-+static int apparmor_socket_shutdown(struct socket *sock, int how)
++static int apparmor_file_mprotect(struct vm_area_struct *vma,
++                                unsigned long reqprot, unsigned long prot)
 +{
-+      struct sock *sk = sock->sk;
-+
-+      return aa_revalidate_sk(sk, "socket_shutdown");
++      return common_mmap(vma->vm_file, "file_mprotect", prot,
++                     !(vma->vm_flags & VM_SHARED) ? MAP_PRIVATE : 0);
 +}
 +
 +static int apparmor_getprocattr(struct task_struct *task, char *name,
 +                              char **value)
 +{
-+      unsigned len;
-+      int error;
-+      struct aa_profile *profile;
-+
-+      /* AppArmor only supports the "current" process attribute */
-+      if (strcmp(name, "current") != 0)
-+              return -EINVAL;
-+
-+      /* must be task querying itself or admin */
-+      if (current != task && !capable(CAP_SYS_ADMIN))
-+              return -EPERM;
++      int error = -ENOENT;
++      struct aa_namespace *ns;
++      struct aa_profile *profile, *onexec, *prev;
++      const struct cred *cred = aa_get_task_policy(task, &profile);
++      struct aa_task_context *cxt = cred->security;
++      ns = cxt->sys.profile->ns;
++      onexec = cxt->sys.onexec;
++      prev = cxt->sys.previous;
++
++      /* task must be either querying itself, unconfined or can ptrace */
++      if (current != task && profile && !capable(CAP_SYS_PTRACE)) {
++              error = -EPERM;
++      } else {
++              if (strcmp(name, "current") == 0) {
++                      error = aa_getprocattr(ns, profile, value);
++              } else if (strcmp(name, "prev") == 0) {
++                      if (prev)
++                              error = aa_getprocattr(ns, prev, value);
++              } else if (strcmp(name, "exec") == 0) {
++                      if (onexec)
++                              error = aa_getprocattr(ns, onexec, value);
++              } else {
++                      error = -EINVAL;
++              }
++      }
 +
-+      profile = aa_get_profile(task);
-+      error = aa_getprocattr(profile, value, &len);
-+      aa_put_profile(profile);
-+      if (!error)
-+              error = len;
++      put_cred(cred);
 +
 +      return error;
 +}
@@ -4870,8 +4248,13 @@ diff -uprN e/security/apparmor/lsm.c f/security/apparmor/lsm.c
 +      char *command, *args;
 +      int error;
 +
-+      if (strcmp(name, "current") != 0 || size == 0 || size >= PAGE_SIZE)
++      if (size == 0 || size >= PAGE_SIZE)
 +              return -EINVAL;
++
++      /* task can only write its own attributes */
++      if (current != task)
++              return -EACCES;
++
 +      args = value;
 +      args[size] = '\0';
 +      args = strstrip(args);
@@ -4883,49 +4266,35 @@ diff -uprN e/security/apparmor/lsm.c f/security/apparmor/lsm.c
 +      if (!*args)
 +              return -EINVAL;
 +
-+      if (strcmp(command, "changehat") == 0) {
-+              if (current != task)
-+                      return -EACCES;
-+              error = aa_setprocattr_changehat(args);
-+      } else if (strcmp(command, "changeprofile") == 0) {
-+              if (current != task)
-+                      return -EACCES;
-+              error = aa_setprocattr_changeprofile(args);
-+      } else if (strcmp(command, "setprofile") == 0) {
-+              struct aa_profile *profile;
-+
-+              /* Only an unconfined process with admin capabilities
-+               * may change the profile of another task.
-+               */
-+
-+              if (!capable(CAP_SYS_ADMIN))
-+                      return -EACCES;
-+
-+              profile = aa_get_profile(current);
-+              if (profile) {
++      if (strcmp(name, "current") == 0) {
++              if (strcmp(command, "changehat") == 0) {
++                      error = aa_setprocattr_changehat(args, !AA_DO_TEST);
++              } else if (strcmp(command, "permhat") == 0) {
++                      error = aa_setprocattr_changehat(args, AA_DO_TEST);
++              } else if (strcmp(command, "changeprofile") == 0) {
++                      error = aa_setprocattr_changeprofile(args, 0,
++                                                           !AA_DO_TEST);
++              } else if (strcmp(command, "permprofile") == 0) {
++                      error = aa_setprocattr_changeprofile(args, 0,
++                                                           AA_DO_TEST);
++              } else if (strcmp(command, "permipc") == 0) {
++                      error = aa_setprocattr_permipc(args);
++              } else {
 +                      struct aa_audit sa;
 +                      memset(&sa, 0, sizeof(sa));
-+                      sa.operation = "profile_set";
++                      sa.operation = "setprocattr";
 +                      sa.gfp_mask = GFP_KERNEL;
-+                      sa.task = task->pid;
-+                      sa.info = "from confined process";
-+                      aa_audit_reject(profile, &sa);
-+                      aa_put_profile(profile);
-+                      return -EACCES;
++                      sa.info = name;
++                      sa.error = -EINVAL;
++                      return aa_audit(AUDIT_APPARMOR_DENIED, NULL, &sa, NULL);
 +              }
-+              error = aa_setprocattr_setprofile(task, args);
++      } else if (strcmp(name, "exec") == 0) {
++              error = aa_setprocattr_changeprofile(strstrip(args), 1,
++                                                   !AA_DO_TEST);
 +      } else {
-+              struct aa_audit sa;
-+              memset(&sa, 0, sizeof(sa));
-+              sa.operation = "setprocattr";
-+              sa.gfp_mask = GFP_KERNEL;
-+              sa.info = "invalid command";
-+              sa.name = command;
-+              sa.task = task->pid;
-+              aa_audit_reject(NULL, &sa);
++              /* only support the "current" and "exec" process attributes */
 +              return -EINVAL;
 +      }
-+
 +      if (!error)
 +              error = size;
 +      return error;
@@ -4934,2403 +4303,1902 @@ diff -uprN e/security/apparmor/lsm.c f/security/apparmor/lsm.c
 +static int apparmor_task_setrlimit(unsigned int resource,
 +                                 struct rlimit *new_rlim)
 +{
-+      struct aa_profile *profile;
++      struct aa_profile *profile = aa_current_profile_wupd();
 +      int error = 0;
 +
-+      profile = aa_get_profile(current);
 +      if (profile) {
 +              error = aa_task_setrlimit(profile, resource, new_rlim);
 +      }
-+      aa_put_profile(profile);
 +
 +      return error;
 +}
 +
-+int apparmor_register_subsecurity(const char *name,
-+                                 struct security_operations *ops)
-+{
-+       int error = 0;
-+
-+       if (mutex_lock_interruptible(&aa_secondary_lock))
-+               return -ERESTARTSYS;
-+
-+       /* allow dazuko and capability to stack.  The stacking with
-+        * capability is not needed since apparmor already composes
-+        * capability using common cap.
-+        */
-+       if (!aa_secondary_ops && (strcmp(name, "dazuko") == 0 ||
-+                                 strcmp(name, "capability") == 0)){
-+               /* The apparmor module needs to be pinned while a secondary is
-+                * registered
-+                */
-+               if (try_module_get(aa_module)) {
-+                       aa_secondary_ops = ops;
-+                       info_message("Registered secondary security module",
-+                                    name);
-+               } else {
-+                       error = -EINVAL;
-+               }
-+       } else {
-+               info_message("Unable to register %s as a secondary security "
-+                            "module", name);
-+               error = -EPERM;
-+       }
-+       mutex_unlock(&aa_secondary_lock);
-+       return error;
-+}
-+
-+int apparmor_unregister_subsecurity(const char *name,
-+                                   struct security_operations *ops)
-+{
-+       int error = 0;
-+
-+       if (mutex_lock_interruptible(&aa_secondary_lock))
-+               return -ERESTARTSYS;
-+
-+       if (aa_secondary_ops && aa_secondary_ops == ops) {
-+               rcu_assign_pointer(aa_secondary_ops, NULL);
-+               synchronize_rcu();
-+               module_put(aa_module);
-+               info_message("Unregistered secondary security module", name);
-+       } else {
-+               info_message("Unable to unregister secondary security module",
-+                            name);
-+               error = -EPERM;
-+       }
-+       mutex_unlock(&aa_secondary_lock);
-+       return error;
-+}
-+
-+struct security_operations apparmor_ops = {
-+      .name =                         "apparmor",
-+      .ptrace =                       apparmor_ptrace,
-+      .capget =                       cap_capget,
-+      .capset_check =                 cap_capset_check,
-+      .capset_set =                   cap_capset_set,
-+      .sysctl =                       apparmor_sysctl,
-+      .capable =                      apparmor_capable,
-+      .syslog =                       cap_syslog,
-+
-+      .bprm_apply_creds =             cap_bprm_apply_creds,
-+      .bprm_set_security =            apparmor_bprm_set_security,
-+      .bprm_secureexec =              apparmor_bprm_secureexec,
-+
-+      .sb_mount =                     apparmor_sb_mount,
-+      .sb_umount =                    apparmor_umount,
-+
-+      .inode_mkdir =                  apparmor_inode_mkdir,
-+      .inode_rmdir =                  apparmor_inode_rmdir,
-+      .inode_create =                 apparmor_inode_create,
-+      .inode_link =                   apparmor_inode_link,
-+      .inode_unlink =                 apparmor_inode_unlink,
-+      .inode_symlink =                apparmor_inode_symlink,
-+      .inode_mknod =                  apparmor_inode_mknod,
-+      .inode_rename =                 apparmor_inode_rename,
-+      .inode_permission =             apparmor_inode_permission,
-+      .inode_setattr =                apparmor_inode_setattr,
-+      .inode_setxattr =               apparmor_inode_setxattr,
-+      .inode_getxattr =               apparmor_inode_getxattr,
-+      .inode_listxattr =              apparmor_inode_listxattr,
-+      .inode_removexattr =            apparmor_inode_removexattr,
-+      .file_permission =              apparmor_file_permission,
-+      .file_alloc_security =          apparmor_file_alloc_security,
-+      .file_free_security =           apparmor_file_free_security,
-+      .file_mmap =                    apparmor_file_mmap,
-+      .file_mprotect =                apparmor_file_mprotect,
-+      .file_lock =                    apparmor_file_lock,
-+
-+      .task_alloc_security =          apparmor_task_alloc_security,
-+      .task_free_security =           apparmor_task_free_security,
-+      .task_post_setuid =             cap_task_post_setuid,
-+      .task_reparent_to_init =        cap_task_reparent_to_init,
-+      .task_setrlimit =               apparmor_task_setrlimit,
-+
-+      .getprocattr =                  apparmor_getprocattr,
-+      .setprocattr =                  apparmor_setprocattr,
-+
-+      .register_security =            apparmor_register_subsecurity,
++#ifdef CONFIG_SECURITY_APPARMOR_NETWORK
++static int apparmor_socket_create(int family, int type, int protocol, int kern){
++      struct aa_profile *profile;
++      int error = 0;
 +
-+      .socket_create =                apparmor_socket_create,
-+      .socket_post_create =           apparmor_socket_post_create,
-+      .socket_bind =                  apparmor_socket_bind,
-+      .socket_connect =               apparmor_socket_connect,
-+      .socket_listen =                apparmor_socket_listen,
-+      .socket_accept =                apparmor_socket_accept,
-+      .socket_sendmsg =               apparmor_socket_sendmsg,
-+      .socket_recvmsg =               apparmor_socket_recvmsg,
-+      .socket_getsockname =           apparmor_socket_getsockname,
-+      .socket_getpeername =           apparmor_socket_getpeername,
-+      .socket_getsockopt =            apparmor_socket_getsockopt,
-+      .socket_setsockopt =            apparmor_socket_setsockopt,
-+      .socket_shutdown =              apparmor_socket_shutdown,
-+};
++      if (kern)
++              return 0;
 +
-+void info_message(const char *str, const char *name)
-+{
-+      struct aa_audit sa;
-+      memset(&sa, 0, sizeof(sa));
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.info = str;
-+      sa.name = name;
-+      printk(KERN_INFO "AppArmor: %s %s\n", str, name);
-+      if (audit_enabled)
-+              aa_audit_message(NULL, &sa, AUDIT_APPARMOR_STATUS);
++      profile = aa_current_profile();
++      if (profile)
++              error = aa_net_perm(profile, "socket_create", family,
++                                                      type, protocol);
++      return error;
 +}
 +
-+static int __init apparmor_init(void)
++static int apparmor_socket_post_create(struct socket *sock, int family,
++                                      int type, int protocol, int kern)
 +{
-+      int error;
++      struct sock *sk = sock->sk;
 +
-+      if (!apparmor_enabled) {
-+              info_message("AppArmor disabled by boottime parameter", "");
++      if (kern)
 +              return 0;
-+      }
-+
-+      if ((error = create_apparmorfs())) {
-+              AA_ERROR("Unable to activate AppArmor filesystem\n");
-+              goto createfs_out;
-+      }
-+
-+      if ((error = alloc_default_namespace())){
-+              AA_ERROR("Unable to allocate default profile namespace\n");
-+              goto alloc_out;
-+      }
-+
-+      if ((error = register_security(&apparmor_ops))) {
-+              AA_ERROR("Unable to register AppArmor\n");
-+              goto register_security_out;
-+      }
-+
-+      /* Report that AppArmor successfully initialized */
-+      apparmor_initialized = 1;
-+      if (apparmor_complain)
-+              info_message("AppArmor initialized: complainmode enabled",
-+                           NULL);
-+      else
-+              info_message("AppArmor initialized", NULL);
-+
-+      return error;
-+
-+register_security_out:
-+      free_default_namespace();
-+
-+alloc_out:
-+      destroy_apparmorfs();
-+
-+createfs_out:
-+      return error;
 +
++      return aa_revalidate_sk(sk, "socket_post_create");
 +}
 +
-+security_initcall(apparmor_init);
-+
-+void apparmor_disable(void)
++static int apparmor_socket_bind(struct socket *sock,
++                              struct sockaddr *address, int addrlen)
 +{
-+      /* Remove and release all the profiles on the profile list. */
-+      mutex_lock(&aa_interface_lock);
-+      aa_profile_ns_list_release();
-+
-+      /* FIXME: cleanup profiles references on files */
-+      free_default_namespace();
-+
-+      /*
-+       * Delay for an rcu cycle to make sure that all active task
-+       * context readers have finished, and all profiles have been
-+       * freed by their rcu callbacks.
-+       */
-+      synchronize_rcu();
-+
-+      destroy_apparmorfs();
-+      mutex_unlock(&aa_interface_lock);
-+
-+      apparmor_initialized = 0;
++      struct sock *sk = sock->sk;
 +
-+      info_message("AppArmor protection removed", NULL);
++      return aa_revalidate_sk(sk, "socket_bind");
 +}
 +
-+MODULE_DESCRIPTION("AppArmor process confinement");
-+MODULE_AUTHOR("Novell/Immunix, http://bugs.opensuse.org");
-+MODULE_LICENSE("GPL");
-diff -uprN e/security/apparmor/main.c f/security/apparmor/main.c
---- e/security/apparmor/main.c 1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/main.c 2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,1689 @@
-+/*
-+ *    Copyright (C) 2002-2007 Novell/SUSE
-+ *
-+ *    This program is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU General Public License as
-+ *    published by the Free Software Foundation, version 2 of the
-+ *    License.
-+ *
-+ *    AppArmor Core
-+ */
++static int apparmor_socket_connect(struct socket *sock,
++                                      struct sockaddr *address, int addrlen)
++{
++      struct sock *sk = sock->sk;
 +
-+#include <linux/security.h>
-+#include <linux/namei.h>
-+#include <linux/audit.h>
-+#include <linux/mount.h>
-+#include <linux/ptrace.h>
-+#include <linux/socket.h>
-+#include <linux/net.h>
-+#include <net/sock.h>
++      return aa_revalidate_sk(sk, "socket_connect");
++}
 +
-+#include "apparmor.h"
++static int apparmor_socket_listen(struct socket *sock, int backlog)
++{
++      struct sock *sk = sock->sk;
 +
-+#include "inline.h"
++      return aa_revalidate_sk(sk, "socket_listen");
++}
 +
-+/*
-+ * Table of capability names: we generate it from capabilities.h.
-+ */
-+static const char *capability_names[] = {
-+#include "capability_names.h"
-+};
++static int apparmor_socket_accept(struct socket *sock, struct socket *newsock)
++{
++      struct sock *sk = sock->sk;
 +
-+struct aa_namespace *default_namespace;
++      return aa_revalidate_sk(sk, "socket_accept");
++}
 +
-+static int aa_inode_mode(struct inode *inode)
++static int apparmor_socket_sendmsg(struct socket *sock,
++                                      struct msghdr *msg, int size)
 +{
-+      /* if the inode doesn't exist the user is creating it */
-+      if (!inode || current->fsuid == inode->i_uid)
-+              return AA_USER_SHIFT;
-+      return AA_OTHER_SHIFT;
++      struct sock *sk = sock->sk;
++
++      return aa_revalidate_sk(sk, "socket_sendmsg");
 +}
 +
-+int alloc_default_namespace(void)
++static int apparmor_socket_recvmsg(struct socket *sock,
++                                 struct msghdr *msg, int size, int flags)
 +{
-+      struct aa_namespace *ns;
-+      char *name = kstrdup("default", GFP_KERNEL);
-+      if (!name)
-+              return -ENOMEM;
-+      ns = alloc_aa_namespace(name);
-+      if (!ns) {
-+              kfree(name);
-+              return -ENOMEM;
-+      }
-+
-+      write_lock(&profile_ns_list_lock);
-+      default_namespace = ns;
-+      aa_get_namespace(ns);
-+      list_add(&ns->list, &profile_ns_list);
-+      write_unlock(&profile_ns_list_lock);
++      struct sock *sk = sock->sk;
 +
-+      return 0;
++      return aa_revalidate_sk(sk, "socket_recvmsg");
 +}
 +
-+void free_default_namespace(void)
++static int apparmor_socket_getsockname(struct socket *sock)
 +{
-+      write_lock(&profile_ns_list_lock);
-+      list_del_init(&default_namespace->list);
-+      write_unlock(&profile_ns_list_lock);
-+      aa_put_namespace(default_namespace);
-+      default_namespace = NULL;
++      struct sock *sk = sock->sk;
++
++      return aa_revalidate_sk(sk, "socket_getsockname");
 +}
 +
-+static void aa_audit_file_sub_mask(struct audit_buffer *ab, char *buffer,
-+                                 int mask)
++static int apparmor_socket_getpeername(struct socket *sock)
 +{
-+      const char unsafex[] = "upcn";
-+      const char safex[] = "UPCN";
-+      char *m = buffer;
++      struct sock *sk = sock->sk;
 +
-+      if (mask & AA_EXEC_MMAP)
-+              *m++ = 'm';
-+      if (mask & MAY_READ)
-+              *m++ = 'r';
-+      if (mask & MAY_WRITE)
-+              *m++ = 'w';
-+      else if (mask & MAY_APPEND)
-+              *m++ = 'a';
-+      if (mask & MAY_EXEC) {
-+              int index = AA_EXEC_INDEX(mask);
-+              /* all indexes > 4 are also named transitions */
-+              if (index > 4)
-+                      index = 4;
-+              if (index > 0) {
-+                      if (mask & AA_EXEC_UNSAFE)
-+                              *m++ = unsafex[index - 1];
-+                      else
-+                              *m++ = safex[index - 1];
-+              }
-+              if (mask & AA_EXEC_INHERIT)
-+                      *m++ = 'i';
-+              *m++ = 'x';
-+      }
-+      if (mask & AA_MAY_LINK)
-+              *m++ = 'l';
-+      if (mask & AA_MAY_LOCK)
-+              *m++ = 'k';
-+      *m++ = '\0';
++      return aa_revalidate_sk(sk, "socket_getpeername");
 +}
 +
-+static void aa_audit_file_mask(struct audit_buffer *ab, const char *name,
-+                             int mask)
++static int apparmor_socket_getsockopt(struct socket *sock, int level,
++                                      int optname)
 +{
-+      char user[10], other[10];
-+
-+      aa_audit_file_sub_mask(ab, user,
-+                             (mask & AA_USER_PERMS) >> AA_USER_SHIFT);
-+      aa_audit_file_sub_mask(ab, other,
-+                             (mask & AA_OTHER_PERMS) >> AA_OTHER_SHIFT);
++      struct sock *sk = sock->sk;
 +
-+      audit_log_format(ab, " %s=\"%s::%s\"", name, user, other);
++      return aa_revalidate_sk(sk, "socket_getsockopt");
 +}
 +
-+static const char *address_families[] = {
-+#include "af_names.h"
-+};
++static int apparmor_socket_setsockopt(struct socket *sock, int level,
++                                      int optname)
++{
++      struct sock *sk = sock->sk;
 +
-+static const char *sock_types[] = {
-+      "unknown(0)",
-+      "stream",
-+      "dgram",
-+      "raw",
-+      "rdm",
-+      "seqpacket",
-+      "dccp",
-+      "unknown(7)",
-+      "unknown(8)",
-+      "unknown(9)",
-+      "packet",
-+};
++      return aa_revalidate_sk(sk, "socket_setsockopt");
++}
 +
-+/**
-+ * aa_audit - Log an audit event to the audit subsystem
-+ * @profile: profile to check against
-+ * @sa: audit event
-+ * @audit_cxt: audit context to log message to
-+ * @type: audit event number
-+ */
-+static int aa_audit_base(struct aa_profile *profile, struct aa_audit *sa,
-+                       struct audit_context *audit_cxt, int type)
++static int apparmor_socket_shutdown(struct socket *sock, int how)
 +{
-+      struct audit_buffer *ab = NULL;
++      struct sock *sk = sock->sk;
 +
-+      ab = audit_log_start(audit_cxt, sa->gfp_mask, type);
++      return aa_revalidate_sk(sk, "socket_shutdown");
++}
++#endif
 +
-+      if (!ab) {
-+              AA_ERROR("Unable to log event (%d) to audit subsys\n",
-+                       type);
-+               /* don't fail operations in complain mode even if logging
-+                * fails */
-+              return type == AUDIT_APPARMOR_ALLOWED ? 0 : -ENOMEM;
-+      }
++static struct security_operations apparmor_ops = {
++      .name =                         "apparmor",
 +
-+      if (sa->operation)
-+              audit_log_format(ab, "operation=\"%s\"", sa->operation);
++      .ptrace_may_access =            apparmor_ptrace_may_access,
++      .ptrace_traceme =               apparmor_ptrace_traceme,
++      .capget =                       apparmor_capget,
++      .sysctl =                       apparmor_sysctl,
++      .capable =                      apparmor_capable,
++/*
++      .inode_create =                 apparmor_inode_create,
++      .inode_setattr =                apparmor_inode_setattr,
++      .inode_setxattr =               apparmor_inode_setxattr,
++      .inode_getxattr =               apparmor_inode_getxattr,
++      .inode_listxattr =              apparmor_inode_listxattr,
++      .inode_removexattr =            apparmor_inode_removexattr,
++      .inode_permission = ??? use to mediate owner access to non-mediated fs
++*/
++
++      .path_link =                    apparmor_path_link,
++      .path_unlink =                  apparmor_path_unlink,
++      .path_symlink =                 apparmor_path_symlink,
++      .path_mkdir =                   apparmor_path_mkdir,
++      .path_rmdir =                   apparmor_path_rmdir,
++      .path_mknod =                   apparmor_path_mknod,
++      .path_rename =                  apparmor_path_rename,
++      .path_truncate =                apparmor_path_truncate,
++      .dentry_open =                  apparmor_dentry_open,
 +
-+      if (sa->info) {
-+              audit_log_format(ab, " info=\"%s\"", sa->info);
-+              if (sa->error_code)
-+                      audit_log_format(ab, " error=%d", sa->error_code);
-+      }
++      .file_permission =              apparmor_file_permission,
++      .file_alloc_security =          apparmor_file_alloc_security,
++      .file_free_security =           apparmor_file_free_security,
++      .file_mmap =                    apparmor_file_mmap,
++      .file_mprotect =                apparmor_file_mprotect,
++      .file_lock =                    apparmor_file_lock,
 +
-+      if (sa->request_mask)
-+              aa_audit_file_mask(ab, "requested_mask", sa->request_mask);
++/*    .file_fcntl =                   apparmor_file_fcntl, */
 +
-+      if (sa->denied_mask)
-+              aa_audit_file_mask(ab, "denied_mask", sa->denied_mask);
++      .getprocattr =                  apparmor_getprocattr,
++      .setprocattr =                  apparmor_setprocattr,
 +
-+      if (sa->request_mask)
-+              audit_log_format(ab, " fsuid=%d", current->fsuid);
++#ifdef CONFIG_SECURITY_APPARMOR_NETWORK
++      .socket_create =                apparmor_socket_create,
++      .socket_post_create =           apparmor_socket_post_create,
++      .socket_bind =                  apparmor_socket_bind,
++      .socket_connect =               apparmor_socket_connect,
++      .socket_listen =                apparmor_socket_listen,
++      .socket_accept =                apparmor_socket_accept,
++      .socket_sendmsg =               apparmor_socket_sendmsg,
++      .socket_recvmsg =               apparmor_socket_recvmsg,
++      .socket_getsockname =           apparmor_socket_getsockname,
++      .socket_getpeername =           apparmor_socket_getpeername,
++      .socket_getsockopt =            apparmor_socket_getsockopt,
++      .socket_setsockopt =            apparmor_socket_setsockopt,
++      .socket_shutdown =              apparmor_socket_shutdown,
++#endif
 +
-+      if (sa->rlimit)
-+              audit_log_format(ab, " rlimit=%d", sa->rlimit - 1);
++      .cred_free =                    apparmor_cred_free,
++      .cred_prepare =                 apparmor_cred_prepare,
 +
-+      if (sa->iattr) {
-+              struct iattr *iattr = sa->iattr;
++      .bprm_set_creds =               apparmor_bprm_set_creds,
++      //      .bprm_committing_creds =        apparmor_bprm_committing_creds,
++      .bprm_committed_creds =         apparmor_bprm_committed_creds,
++      .bprm_secureexec =              apparmor_bprm_secureexec,
 +
-+              audit_log_format(ab, " attribute=\"%s%s%s%s%s%s%s\"",
-+                      iattr->ia_valid & ATTR_MODE ? "mode," : "",
-+                      iattr->ia_valid & ATTR_UID ? "uid," : "",
-+                      iattr->ia_valid & ATTR_GID ? "gid," : "",
-+                      iattr->ia_valid & ATTR_SIZE ? "size," : "",
-+                      iattr->ia_valid & (ATTR_ATIME | ATTR_ATIME_SET) ?
-+                              "atime," : "",
-+                      iattr->ia_valid & (ATTR_MTIME | ATTR_MTIME_SET) ?
-+                              "mtime," : "",
-+                      iattr->ia_valid & ATTR_CTIME ? "ctime," : "");
-+      }
++      .task_setrlimit =               apparmor_task_setrlimit,
++};
 +
-+      if (sa->task)
-+              audit_log_format(ab, " task=%d", sa->task);
 +
-+      if (sa->parent)
-+              audit_log_format(ab, " parent=%d", sa->parent);
++/*
++ * AppArmor sysfs module parameters
++ */
 +
-+      if (sa->name) {
-+              audit_log_format(ab, " name=");
-+              audit_log_untrustedstring(ab, sa->name);
-+      }
++static int param_set_aabool(const char *val, struct kernel_param *kp);
++static int param_get_aabool(char *buffer, struct kernel_param *kp);
++#define param_check_aabool(name, p) __param_check(name, p, int)
 +
-+      if (sa->name2) {
-+              audit_log_format(ab, " name2=");
-+              audit_log_untrustedstring(ab, sa->name2);
-+      }
++static int param_set_aauint(const char *val, struct kernel_param *kp);
++static int param_get_aauint(char *buffer, struct kernel_param *kp);
++#define param_check_aauint(name, p) __param_check(name, p, int)
 +
-+      if (sa->family || sa->type) {
-+              if (address_families[sa->family])
-+                      audit_log_format(ab, " family=\"%s\"",
-+                                       address_families[sa->family]);
-+              else
-+                      audit_log_format(ab, " family=\"unknown(%d)\"",
-+                                       sa->family);
++static int param_set_aalockpolicy(const char *val, struct kernel_param *kp);
++static int param_get_aalockpolicy(char *buffer, struct kernel_param *kp);
++#define param_check_aalockpolicy(name, p) __param_check(name, p, int)
 +
-+              if (sock_types[sa->type])
-+                      audit_log_format(ab, " sock_type=\"%s\"",
-+                                       sock_types[sa->type]);
-+              else
-+                      audit_log_format(ab, " sock_type=\"unknown(%d)\"",
-+                                       sa->type);
++static int param_set_audit(const char *val, struct kernel_param *kp);
++static int param_get_audit(char *buffer, struct kernel_param *kp);
++#define param_check_audit(name, p) __param_check(name, p, int)
 +
-+              audit_log_format(ab, " protocol=%d", sa->protocol);
-+      }
++static int param_set_mode(const char *val, struct kernel_param *kp);
++static int param_get_mode(char *buffer, struct kernel_param *kp);
++#define param_check_mode(name, p) __param_check(name, p, int)
 +
-+        audit_log_format(ab, " pid=%d", current->pid);
++/* Flag values, also controllable via /sys/module/apparmor/parameters
++ * We define special types as we want to do additional mediation.
++ */
 +
-+      if (profile) {
-+              audit_log_format(ab, " profile=");
-+              audit_log_untrustedstring(ab, profile->name);
++/* AppArmor global enforcement switch - complain, enforce, kill */
++enum profile_mode g_profile_mode = APPARMOR_ENFORCE;
++module_param_call(mode, param_set_mode, param_get_mode,
++                &g_profile_mode, S_IRUSR | S_IWUSR);
 +
-+              if (profile->ns != default_namespace) {
-+                      audit_log_format(ab, " namespace=");
-+                      audit_log_untrustedstring(ab, profile->ns->name);
-+              }
-+      }
++/* Debug mode */
++int g_apparmor_debug;
++module_param_named(debug, g_apparmor_debug, aabool, S_IRUSR | S_IWUSR);
 +
-+      audit_log_end(ab);
++/* Audit mode */
++enum audit_mode g_apparmor_audit;
++module_param_call(audit, param_set_audit, param_get_audit,
++                &g_apparmor_audit, S_IRUSR | S_IWUSR);
 +
-+      return type == AUDIT_APPARMOR_ALLOWED ? 0 : sa->error_code;
-+}
++/* Determines if audit header is included in audited messages.  This
++ * provides more context if the audit daemon is not running
++ */
++int g_apparmor_audit_header;
++module_param_named(audit_header, g_apparmor_audit_header, aabool,
++                 S_IRUSR | S_IWUSR);
 +
-+/**
-+ * aa_audit_syscallreject - Log a syscall rejection to the audit subsystem
-+ * @profile: profile to check against
-+ * @gfp: memory allocation flags
-+ * @msg: string describing syscall being rejected
++/* lock out loading/removal of policy
++ * TODO: add in at boot loading of policy, which is the only way to
++ *       load policy, if lock_policy is set
 + */
-+int aa_audit_syscallreject(struct aa_profile *profile, gfp_t gfp,
-+                         const char *msg)
-+{
-+      struct aa_audit sa;
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "syscall";
-+      sa.name = msg;
-+      sa.gfp_mask = gfp;
-+      sa.error_code = -EPERM;
++int g_apparmor_lock_policy;
++module_param_named(lock_policy, g_apparmor_lock_policy, aalockpolicy,
++                 S_IRUSR | S_IWUSR);
 +
-+      return aa_audit_base(profile, &sa, current->audit_context,
-+                           AUDIT_APPARMOR_DENIED);
-+}
++/* Syscall logging mode */
++int g_apparmor_logsyscall;
++module_param_named(logsyscall, g_apparmor_logsyscall, aabool,
++                 S_IRUSR | S_IWUSR);
 +
-+int aa_audit_message(struct aa_profile *profile, struct aa_audit *sa,
-+                    int type)
-+{
-+      struct audit_context *audit_cxt;
++/* Maximum pathname length before accesses will start getting rejected */
++unsigned int g_apparmor_path_max = 2 * PATH_MAX;
++module_param_named(path_max, g_apparmor_path_max, aauint, S_IRUSR | S_IWUSR);
 +
-+      audit_cxt = apparmor_logsyscall ? current->audit_context : NULL;
-+      return aa_audit_base(profile, sa, audit_cxt, type);
-+}
++/* Boot time disable flag */
++#ifdef CONFIG_SECURITY_APPARMOR_DISABLE
++#define AA_ENABLED_PERMS 0600
++#else
++#define AA_ENABLED_PERMS 0400
++#endif
++static int param_set_aa_enabled(const char *val, struct kernel_param *kp);
++static unsigned int apparmor_enabled = CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE;
++module_param_call(enabled, param_set_aa_enabled, param_get_aauint,
++                &apparmor_enabled, AA_ENABLED_PERMS);
 +
-+void aa_audit_hint(struct aa_profile *profile, struct aa_audit *sa)
++static int __init apparmor_enabled_setup(char *str)
 +{
-+      aa_audit_message(profile, sa, AUDIT_APPARMOR_HINT);
++      apparmor_enabled = simple_strtol(str, NULL, 0);
++      return 1;
 +}
++__setup("apparmor=", apparmor_enabled_setup);
 +
-+void aa_audit_status(struct aa_profile *profile, struct aa_audit *sa)
++static int param_set_aalockpolicy(const char *val, struct kernel_param *kp)
 +{
-+      aa_audit_message(profile, sa, AUDIT_APPARMOR_STATUS);
++      if (__aa_task_is_confined(current))
++              return -EPERM;
++      if (g_apparmor_lock_policy)
++              return -EACCES;
++      return param_set_bool(val, kp);
 +}
 +
-+int aa_audit_reject(struct aa_profile *profile, struct aa_audit *sa)
++static int param_get_aalockpolicy(char *buffer, struct kernel_param *kp)
 +{
-+      return aa_audit_message(profile, sa, AUDIT_APPARMOR_DENIED);
++      if (__aa_task_is_confined(current))
++              return -EPERM;
++      return param_get_bool(buffer, kp);
 +}
 +
-+/**
-+ * aa_audit - Log an audit event to the audit subsystem
-+ * @profile: profile to check against
-+ * @sa: audit event
-+ */
-+int aa_audit(struct aa_profile *profile, struct aa_audit *sa)
++static int param_set_aabool(const char *val, struct kernel_param *kp)
 +{
-+      int type = AUDIT_APPARMOR_DENIED;
-+      struct audit_context *audit_cxt;
-+
-+      if (likely(!sa->error_code))
-+              type = AUDIT_APPARMOR_AUDIT;
-+      else if (PROFILE_COMPLAIN(profile))
-+              type = AUDIT_APPARMOR_ALLOWED;
-+
-+      audit_cxt = apparmor_logsyscall ? current->audit_context : NULL;
-+      return aa_audit_base(profile, sa, audit_cxt, type);
++      if (__aa_task_is_confined(current))
++              return -EPERM;
++      return param_set_bool(val, kp);
 +}
 +
-+static int aa_audit_file(struct aa_profile *profile, struct aa_audit *sa)
++static int param_get_aabool(char *buffer, struct kernel_param *kp)
 +{
-+      if (likely(!sa->error_code)) {
-+              int mask = sa->audit_mask & AUDIT_FILE_MASK;
-+
-+              if (unlikely(PROFILE_AUDIT(profile)))
-+                      mask |= AUDIT_FILE_MASK;
-+
-+              if (likely(!(sa->request_mask & mask)))
-+                      return 0;
-+
-+              /* mask off perms that are not being force audited */
-+              sa->request_mask &= mask | ALL_AA_EXEC_TYPE;
-+      } else {
-+              int mask = AUDIT_QUIET_MASK(sa->audit_mask);
-+
-+              if (!(sa->denied_mask & ~mask))
-+                      return sa->error_code;
-+
-+              /* mask off perms whose denial is being silenced */
-+              sa->denied_mask &= (~mask) | ALL_AA_EXEC_TYPE;
-+      }
-+
-+      return aa_audit(profile, sa);
++      if (__aa_task_is_confined(current))
++              return -EPERM;
++      return param_get_bool(buffer, kp);
 +}
 +
-+static int aa_audit_caps(struct aa_profile *profile, struct aa_audit *sa,
-+                       int cap)
++static int param_set_aauint(const char *val, struct kernel_param *kp)
 +{
-+      if (likely(!sa->error_code)) {
-+              if (likely(!PROFILE_AUDIT(profile) &&
-+                         !cap_raised(profile->audit_caps, cap)))
-+                      return 0;
-+      }
-+
-+      /* quieting of capabilities is handled the caps_logged cache */
-+      return aa_audit(profile, sa);
++      if (__aa_task_is_confined(current))
++              return -EPERM;
++      return param_set_uint(val, kp);
 +}
 +
-+/**
-+ * aa_file_denied - check for @mask access on a file
-+ * @profile: profile to check against
-+ * @name: pathname of file
-+ * @mask: permission mask requested for file
-+ * @audit_mask: return audit mask for the match
-+ *
-+ * Return %0 on success, or else the permissions in @mask that the
-+ * profile denies.
-+ */
-+static int aa_file_denied(struct aa_profile *profile, const char *name,
-+                        int mask, int *audit_mask)
++static int param_get_aauint(char *buffer, struct kernel_param *kp)
 +{
-+      return (mask & ~aa_match(profile->file_rules, name, audit_mask));
++      if (__aa_task_is_confined(current))
++              return -EPERM;
++      return param_get_uint(buffer, kp);
 +}
 +
-+/**
-+ * aa_link_denied - check for permission to link a file
-+ * @profile: profile to check against
-+ * @link: pathname of link being created
-+ * @target: pathname of target to be linked to
-+ * @target_mode: UGO shift for target inode
-+ * @request_mask: the permissions subset valid only if link succeeds
-+ * @audit_mask: return the audit_mask for the link permission
-+ * Return %0 on success, or else the permissions that the profile denies.
-+ */
-+static int aa_link_denied(struct aa_profile *profile, const char *link,
-+                        const char *target, int target_mode,
-+                        int *request_mask, int *audit_mask)
-+{
-+      unsigned int state;
-+      int l_mode, t_mode, l_x, t_x, denied_mask = 0;
-+      int link_mask = AA_MAY_LINK << target_mode;
-+
-+      *request_mask = link_mask;
-+
-+      l_mode = aa_match_state(profile->file_rules, DFA_START, link, &state);
-+
-+      if (l_mode & link_mask) {
-+              int mode;
-+              /* test to see if target can be paired with link */
-+              state = aa_dfa_null_transition(profile->file_rules, state);
-+              mode = aa_match_state(profile->file_rules, state, target,
-+                                    &state);
-+
-+              if (!(mode & link_mask))
-+                      denied_mask |= link_mask;
-+
-+              *audit_mask = dfa_audit_mask(profile->file_rules, state);
++/* allow run time disabling of apparmor */
++static int param_set_aa_enabled(const char *val, struct kernel_param *kp)
++{
++      unsigned long l;
 +
-+              /* return if link subset test is not required */
-+              if (!(mode & (AA_LINK_SUBSET_TEST << target_mode)))
-+                      return denied_mask;
++      if (!apparmor_initialized) {
++              apparmor_enabled = 0;
++              return 0;
 +      }
 +
-+      /* Do link perm subset test requiring permission on link are a
-+       * subset of the permissions on target.
-+       * If a subset test is required a permission subset test of the
-+       * perms for the link are done against the user::other of the
-+       * target's 'r', 'w', 'x', 'a', 'k', and 'm' permissions.
-+       *
-+       * If the link has 'x', an exact match of all the execute flags
-+       * must match.
-+       */
-+      denied_mask |= ~l_mode & link_mask;
++      if (__aa_task_is_confined(current))
++              return -EPERM;
 +
-+      t_mode = aa_match(profile->file_rules, target, NULL);
++      if (!apparmor_enabled)
++              return -EINVAL;
 +
-+      l_x = l_mode & (ALL_AA_EXEC_TYPE | AA_EXEC_BITS);
-+      t_x = t_mode & (ALL_AA_EXEC_TYPE | AA_EXEC_BITS);
++      if (!val)
++              return -EINVAL;
 +
-+      /* For actual subset test ignore valid-profile-transition flags,
-+       * and link bits
-+       */
-+      l_mode &= AA_FILE_PERMS & ~AA_LINK_BITS;
-+      t_mode &= AA_FILE_PERMS & ~AA_LINK_BITS;
++      if (strict_strtoul(val, 0, &l) || l != 0)
++              return -EINVAL;
 +
-+      *request_mask = l_mode | link_mask;
++      apparmor_enabled = 0;
++      apparmor_disable();
++      return 0;
++}
 +
-+      if (l_mode) {
-+              int x = l_x | (t_x & ALL_AA_EXEC_UNSAFE);
-+              denied_mask |= l_mode & ~t_mode;
-+              /* mask off x modes not used by link */
++static int param_get_audit(char *buffer, struct kernel_param *kp)
++{
++      if (__aa_task_is_confined(current))
++              return -EPERM;
 +
-+              /* handle exec subset
-+               * - link safe exec issubset of unsafe exec
-+               * - no link x perm is subset of target having x perm
-+               */
-+              if ((l_mode & AA_USER_EXEC) &&
-+                  (x & AA_USER_EXEC_TYPE) != (t_x & AA_USER_EXEC_TYPE))
-+                      denied_mask = AA_USER_EXEC | (l_x & AA_USER_EXEC_TYPE);
-+              if ((l_mode & AA_OTHER_EXEC) &&
-+                  (x & AA_OTHER_EXEC_TYPE) != (t_x & AA_OTHER_EXEC_TYPE))
-+                      denied_mask = AA_OTHER_EXEC | (l_x & AA_OTHER_EXEC_TYPE);
-+      }
++      if (!apparmor_enabled)
++              return -EINVAL;
 +
-+      return denied_mask;
++      return sprintf(buffer, "%s", audit_mode_names[g_apparmor_audit]);
 +}
 +
-+/**
-+ * aa_get_name - compute the pathname of a file
-+ * @dentry: dentry of the file
-+ * @mnt: vfsmount of the file
-+ * @buffer: buffer that aa_get_name() allocated
-+ * @check: AA_CHECK_DIR is set if the file is a directory
-+ *
-+ * Returns a pointer to the beginning of the pathname (which usually differs
-+ * from the beginning of the buffer), or an error code.
-+ *
-+ * We need @check to indicate whether the file is a directory or not because
-+ * the file may not yet exist, and so we cannot check the inode's file type.
-+ */
-+static char *aa_get_name(struct dentry *dentry, struct vfsmount *mnt,
-+                       char **buffer, int check)
++static int param_set_audit(const char *val, struct kernel_param *kp)
 +{
-+      char *name;
-+      int is_dir, size = 256;
++      int i;
++      if (__aa_task_is_confined(current))
++              return -EPERM;
 +
-+      is_dir = (check & AA_CHECK_DIR) ? 1 : 0;
++      if (!apparmor_enabled)
++              return -EINVAL;
 +
-+      for (;;) {
-+              char *buf = kmalloc(size, GFP_KERNEL);
-+              if (!buf)
-+                      return ERR_PTR(-ENOMEM);
-+
-+              name = d_namespace_path(dentry, mnt, buf, size - is_dir);
-+              if (!IS_ERR(name)) {
-+                      if (name[0] != '/') {
-+                              /*
-+                               * This dentry is not connected to the
-+                               * namespace root -- reject access.
-+                               */
-+                              kfree(buf);
-+                              return ERR_PTR(-ENOENT);
-+                      }
-+                      if (is_dir && name[1] != '\0') {
-+                              /*
-+                               * Append "/" to the pathname. The root
-+                               * directory is a special case; it already
-+                               * ends in slash.
-+                               */
-+                              buf[size - 2] = '/';
-+                              buf[size - 1] = '\0';
-+                      }
++      if (!val)
++              return -EINVAL;
 +
-+                      *buffer = buf;
-+                      return name;
++      for (i = 0; i < AUDIT_MAX_INDEX; i++) {
++              if (strcmp(val, audit_mode_names[i]) == 0) {
++                      g_apparmor_audit = i;
++                      return 0;
 +              }
-+              if (PTR_ERR(name) != -ENAMETOOLONG)
-+                      return name;
-+
-+              kfree(buf);
-+              size <<= 1;
-+              if (size > apparmor_path_max)
-+                      return ERR_PTR(-ENAMETOOLONG);
 +      }
-+}
 +
-+static char *new_compound_name(const char *n1, const char *n2)
-+{
-+      char *name = kmalloc(strlen(n1) + strlen(n2) + 3, GFP_KERNEL);
-+      if (name)
-+              sprintf(name, "%s//%s", n1, n2);
-+      return name;
-+}
-+static inline void aa_put_name_buffer(char *buffer)
-+{
-+      kfree(buffer);
++      return -EINVAL;
 +}
 +
-+/**
-+ * aa_perm_dentry - check if @profile allows @mask for a file
-+ * @profile: profile to check against
-+ * @dentry: dentry of the file
-+ * @mnt: vfsmount o the file
-+ * @sa: audit context
-+ * @mask: requested profile permissions
-+ * @check: kind of check to perform
-+ *
-+ * Returns 0 upon success, or else an error code.
-+ *
-+ * @check indicates the file type, and whether the file was accessed through
-+ * an open file descriptor (AA_CHECK_FD) or not.
-+ */
-+static int aa_perm_dentry(struct aa_profile *profile, struct dentry *dentry,
-+                        struct vfsmount *mnt, struct aa_audit *sa, int check)
++static int param_get_mode(char *buffer, struct kernel_param *kp)
 +{
-+      int error;
-+      char *buffer = NULL;
-+
-+      sa->name = aa_get_name(dentry, mnt, &buffer, check);
-+      sa->request_mask <<= aa_inode_mode(dentry->d_inode);
-+      if (IS_ERR(sa->name)) {
-+              /*
-+               * deleted files are given a pass on permission checks when
-+               * accessed through a file descriptor.
-+               */
-+              if (PTR_ERR(sa->name) == -ENOENT && (check & AA_CHECK_FD))
-+                      sa->denied_mask = 0;
-+              else {
-+                      sa->denied_mask = sa->request_mask;
-+                      sa->error_code = PTR_ERR(sa->name);
-+                      if (sa->error_code == -ENOENT)
-+                              sa->info = "Failed name resolution - object not a valid entry";
-+                      else if (sa->error_code == -ENAMETOOLONG)
-+                              sa->info = "Failed name resolution - name too long";
-+                      else
-+                              sa->info = "Failed name resolution";
-+              }
-+              sa->name = NULL;
-+      } else
-+              sa->denied_mask = aa_file_denied(profile, sa->name,
-+                                               sa->request_mask,
-+                                               &sa->audit_mask);
-+
-+      if (!sa->denied_mask)
-+              sa->error_code = 0;
++      if (__aa_task_is_confined(current))
++              return -EPERM;
 +
-+      error = aa_audit_file(profile, sa);
-+      aa_put_name_buffer(buffer);
++      if (!apparmor_enabled)
++              return -EINVAL;
 +
-+      return error;
++      return sprintf(buffer, "%s", profile_mode_names[g_profile_mode]);
 +}
 +
-+/**
-+ * aa_attr - check if attribute change is allowed
-+ * @profile: profile to check against
-+ * @dentry: dentry of the file to check
-+ * @mnt: vfsmount of the file to check
-+ * @iattr: attribute changes requested
-+ */
-+int aa_attr(struct aa_profile *profile, struct dentry *dentry,
-+          struct vfsmount *mnt, struct iattr *iattr)
++static int param_set_mode(const char *val, struct kernel_param *kp)
 +{
-+      struct inode *inode = dentry->d_inode;
-+      int error, check;
-+      struct aa_audit sa;
++      int i;
++      if (__aa_task_is_confined(current))
++              return -EPERM;
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "setattr";
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.iattr = iattr;
-+      sa.request_mask = MAY_WRITE;
-+      sa.error_code = -EACCES;
++      if (!apparmor_enabled)
++              return -EINVAL;
 +
-+      check = 0;
-+      if (inode && S_ISDIR(inode->i_mode))
-+              check |= AA_CHECK_DIR;
-+      if (iattr->ia_valid & ATTR_FILE)
-+              check |= AA_CHECK_FD;
++      if (!val)
++              return -EINVAL;
 +
-+      error = aa_perm_dentry(profile, dentry, mnt, &sa, check);
++      for (i = 0; i < APPARMOR_NAMES_MAX_INDEX; i++) {
++              if (strcmp(val, profile_mode_names[i]) == 0) {
++                      g_profile_mode = i;
++                      return 0;
++              }
++      }
 +
-+      return error;
++      return -EINVAL;
 +}
 +
-+/**
-+ * aa_perm_xattr - check if xattr attribute change is allowed
-+ * @profile: profile to check against
-+ * @dentry: dentry of the file to check
-+ * @mnt: vfsmount of the file to check
-+ * @operation: xattr operation being done
-+ * @mask: access mode requested
-+ * @check: kind of check to perform
++
++/*
++ * AppArmor init functions
 + */
-+int aa_perm_xattr(struct aa_profile *profile, const char *operation,
-+                struct dentry *dentry, struct vfsmount *mnt, int mask,
-+                int check)
-+{
-+      struct inode *inode = dentry->d_inode;
-+      int error;
-+      struct aa_audit sa;
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = operation;
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.request_mask = mask;
-+      sa.error_code = -EACCES;
++static int set_init_cxt(void)
++{
++      struct cred *cred = (struct cred *) current->real_cred;
++      struct aa_task_context *cxt;
 +
-+      if (inode && S_ISDIR(inode->i_mode))
-+              check |= AA_CHECK_DIR;
++      cxt = aa_alloc_task_context(GFP_KERNEL);
++      if (!cxt)
++              return -ENOMEM;
 +
-+      error = aa_perm_dentry(profile, dentry, mnt, &sa, check);
++      cxt->sys.profile = aa_get_profile(default_namespace->unconfined);
++      cred->security = cxt;
 +
-+      return error;
++      return 0;
 +}
 +
-+/**
-+ * aa_perm - basic apparmor permissions check
-+ * @profile: profile to check against
-+ * @dentry: dentry of the file to check
-+ * @mnt: vfsmount of the file to check
-+ * @mask: access mode requested
-+ * @check: kind of check to perform
-+ *
-+ * Determine if access @mask for the file is authorized by @profile.
-+ * Returns 0 on success, or else an error code.
-+ */
-+int aa_perm(struct aa_profile *profile, const char *operation,
-+          struct dentry *dentry, struct vfsmount *mnt, int mask, int check)
++static int __init apparmor_init(void)
 +{
-+      struct aa_audit sa;
-+      int error = 0;
++      int error;
 +
-+      if (mask == 0)
-+              goto out;
++      if (!apparmor_enabled || !security_module_enable(&apparmor_ops)) {
++              info_message("AppArmor disabled by boot time parameter\n");
++              apparmor_enabled = 0;
++              return 0;
++      }
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = operation;
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.request_mask = mask;
-+      sa.error_code = -EACCES;
++      /*
++       * Activated with fs_initcall
++      error = create_apparmorfs();
++      if (error) {
++              AA_ERROR("Unable to activate AppArmor filesystem\n");
++              goto createfs_out;
++      }
++      */
 +
-+      error = aa_perm_dentry(profile, dentry, mnt, &sa, check);
++      error = alloc_default_namespace();
++      if (error) {
++              AA_ERROR("Unable to allocate default profile namespace\n");
++              goto alloc_out;
++      }
 +
-+out:
-+      return error;
-+}
++      error = set_init_cxt();
++      if (error) {
++              AA_ERROR("Failed to set context on init task\n");
++              goto alloc_out;
++      }
 +
-+/**
-+ * aa_perm_dir
-+ * @profile: profile to check against
-+ * @dentry: dentry of directory to check
-+ * @mnt: vfsmount of directory to check
-+ * @operation: directory operation being performed
-+ * @mask: access mode requested
-+ *
-+ * Determine if directory operation (make/remove) for dentry is authorized
-+ * by @profile.
-+ * Returns 0 on success, or else an error code.
-+ */
-+int aa_perm_dir(struct aa_profile *profile, const char *operation,
-+              struct dentry *dentry, struct vfsmount *mnt, int mask)
-+{
-+      struct aa_audit sa;
++      error = register_security(&apparmor_ops);
++      if (error) {
++              AA_ERROR("Unable to register AppArmor\n");
++              goto register_security_out;
++      }
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = operation;
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.request_mask = mask;
-+      sa.error_code = -EACCES;
++      /* Report that AppArmor successfully initialized */
++      apparmor_initialized = 1;
++      if (g_profile_mode == APPARMOR_COMPLAIN)
++              info_message("AppArmor initialized: complain mode enabled");
++      else if (g_profile_mode == APPARMOR_KILL)
++              info_message("AppArmor initialized: kill mode enabled");
++      else
++              info_message("AppArmor initialized");
 +
-+      return aa_perm_dentry(profile, dentry, mnt, &sa, AA_CHECK_DIR);
-+}
++      return error;
 +
-+int aa_perm_path(struct aa_profile *profile, const char *operation,
-+               const char *name, int mask, uid_t uid)
-+{
-+      struct aa_audit sa;
++register_security_out:
++      free_default_namespace();
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = operation;
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.request_mask = mask;
-+      sa.name = name;
-+      if (current->fsuid == uid)
-+              sa.request_mask = mask << AA_USER_SHIFT;
-+      else
-+              sa.request_mask = mask << AA_OTHER_SHIFT;
++alloc_out:
++      destroy_apparmorfs();
 +
-+      sa.denied_mask = aa_file_denied(profile, name, sa.request_mask,
-+                                      &sa.audit_mask) ;
-+      sa.error_code = sa.denied_mask ? -EACCES : 0;
++/*createfs_out:*/
++      apparmor_enabled = 0;
++      return error;
 +
-+      return aa_audit_file(profile, &sa);
 +}
 +
-+/**
-+ * aa_capability - test permission to use capability
-+ * @cxt: aa_task_context with profile to check against
-+ * @cap: capability to be tested
-+ *
-+ * Look up capability in profile capability set.
-+ * Returns 0 on success, or else an error code.
-+ */
-+int aa_capability(struct aa_task_context *cxt, int cap)
-+{
-+      int error = cap_raised(cxt->profile->capabilities, cap) ? 0 : -EPERM;
-+      struct aa_audit sa;
-+
-+      /* test if cap has alread been logged */
-+      if (cap_raised(cxt->caps_logged, cap)) {
-+              if (PROFILE_COMPLAIN(cxt->profile))
-+                      error = 0;
-+              return error;
-+      } else
-+              /* don't worry about rcu replacement of the cxt here.
-+               * caps_logged is a cache to reduce the occurence of
-+               * duplicate messages in the log.  The worst that can
-+               * happen is duplicate capability messages shows up in
-+               * the audit log
-+               */
-+              cap_raise(cxt->caps_logged, cap);
++security_initcall(apparmor_init);
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "capable";
-+      sa.gfp_mask = GFP_ATOMIC;
-+      sa.name = capability_names[cap];
-+      sa.error_code = error;
++void apparmor_disable(void)
++{
++      /* Remove and release all the profiles on the profile list. */
++      aa_profile_ns_list_release();
 +
-+      error = aa_audit_caps(cxt->profile, &sa, cap);
++      /* FIXME: cleanup profiles references on files */
++      free_default_namespace();
 +
-+      return error;
-+}
++      /*
++       * Delay for an rcu cycle to make sure that all active task
++       * context readers have finished, and all profiles have been
++       * freed by their rcu callbacks.
++       */
++      synchronize_rcu();
++      destroy_apparmorfs();
++      apparmor_initialized = 0;
 +
-+/* must be used inside rcu_read_lock or task_lock */
-+int aa_may_ptrace(struct aa_task_context *cxt, struct aa_profile *tracee)
-+{
-+      if (!cxt || cxt->profile == tracee)
-+              return 0;
-+      return aa_capability(cxt, CAP_SYS_PTRACE);
++      info_message("AppArmor protection disabled");
 +}
 +
-+/**
-+ * aa_link - hard link check
-+ * @profile: profile to check against
-+ * @link: dentry of link being created
-+ * @link_mnt: vfsmount of link being created
-+ * @target: dentry of link target
-+ * @target_mnt: vfsmunt of link target
+diff --git a/security/apparmor/match.c b/security/apparmor/match.c
+new file mode 100644
+index 0000000..a22d106
+--- /dev/null
++++ b/security/apparmor/match.c
+@@ -0,0 +1,293 @@
++/*
++ * AppArmor security module
 + *
-+ * Returns 0 on success, or else an error code.
++ * This file contains AppArmor dfa based regular expression matching engine
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
 + */
-+int aa_link(struct aa_profile *profile,
-+          struct dentry *link, struct vfsmount *link_mnt,
-+          struct dentry *target, struct vfsmount *target_mnt)
-+{
-+      int error;
-+      struct aa_audit sa;
-+      char *buffer = NULL, *buffer2 = NULL;
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "inode_link";
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.name = aa_get_name(link, link_mnt, &buffer, 0);
-+      sa.name2 = aa_get_name(target, target_mnt, &buffer2, 0);
++#include <linux/kernel.h>
++#include <linux/slab.h>
++#include <linux/errno.h>
 +
-+      if (IS_ERR(sa.name)) {
-+              sa.error_code = PTR_ERR(sa.name);
-+              sa.name = NULL;
-+      }
-+      if (IS_ERR(sa.name2)) {
-+              sa.error_code = PTR_ERR(sa.name2);
-+              sa.name2 = NULL;
-+      }
++/* TODO: remove !!!! */
++// #include <linux/fs.h>
 +
-+      if (sa.name && sa.name2) {
-+              sa.denied_mask = aa_link_denied(profile, sa.name, sa.name2,
-+                                              aa_inode_mode(target->d_inode),
-+                                              &sa.request_mask,
-+                                              &sa.audit_mask);
-+              sa.error_code = sa.denied_mask ? -EACCES : 0;
-+      }
++#include "include/apparmor.h"
++#include "include/match.h"
++#include "include/file.h"
 +
-+      error = aa_audit_file(profile, &sa);
++static struct table_header *unpack_table(void *blob, size_t bsize)
++{
++      struct table_header *table = NULL;
++      struct table_header th;
++      size_t tsize;
 +
-+      aa_put_name_buffer(buffer);
-+      aa_put_name_buffer(buffer2);
++      if (bsize < sizeof(struct table_header))
++              goto out;
 +
-+      return error;
-+}
++      th.td_id = be16_to_cpu(*(u16 *) (blob));
++      th.td_flags = be16_to_cpu(*(u16 *) (blob + 2));
++      th.td_lolen = be32_to_cpu(*(u32 *) (blob + 8));
++      blob += sizeof(struct table_header);
 +
-+int aa_net_perm(struct aa_profile *profile, char *operation,
-+              int family, int type, int protocol)
-+{
-+      struct aa_audit sa;
-+      int error = 0;
-+      u16 family_mask, audit_mask, quiet_mask;
++      if (!(th.td_flags == YYTD_DATA16 || th.td_flags == YYTD_DATA32 ||
++              th.td_flags == YYTD_DATA8))
++              goto out;
 +
-+      if ((family < 0) || (family >= AF_MAX))
-+              return -EINVAL;
++      tsize = table_size(th.td_lolen, th.td_flags);
++      if (bsize < tsize)
++              goto out;
 +
-+      if ((type < 0) || (type >= SOCK_MAX))
-+              return -EINVAL;
++      table = kmalloc(tsize, GFP_KERNEL);
++      if (table) {
++              *table = th;
++              if (th.td_flags == YYTD_DATA8)
++                      UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
++                                   u8, byte_to_byte);
++              else if (th.td_flags == YYTD_DATA16)
++                      UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
++                                   u16, be16_to_cpu);
++              else
++                      UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
++                                   u32, be32_to_cpu);
++      }
 +
-+      /* unix domain and netlink sockets are handled by ipc */
-+      if (family == AF_UNIX || family == AF_NETLINK)
-+              return 0;
++out:
++      return table;
++}
 +
-+      family_mask = profile->network_families[family];
-+      audit_mask = profile->audit_network[family];
-+      quiet_mask = profile->quiet_network[family];
++int unpack_dfa(struct aa_dfa *dfa, void *blob, size_t size)
++{
++      int hsize, i;
++      int error = -ENOMEM;
 +
-+      error = (family_mask & (1 << type)) ? 0 : -EACCES;
++      /* get dfa table set header */
++      if (size < sizeof(struct table_set_header))
++              goto fail;
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = operation;
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.family = family;
-+      sa.type = type;
-+      sa.protocol = protocol;
-+      sa.error_code = error;
++      if (ntohl(*(u32 *)blob) != YYTH_MAGIC)
++              goto fail;
 +
-+      if (likely(!error)) {
-+              if (!PROFILE_AUDIT(profile) && !(family_mask & audit_mask))
-+                      return 0;
-+      } else if (!((1 << type) & ~quiet_mask)) {
-+              return error;
-+      }
++      hsize = ntohl(*(u32 *)(blob + 4));
++      if (size < hsize)
++              goto fail;
 +
-+      error = aa_audit(profile, &sa);
++      blob += hsize;
++      size -= hsize;
 +
-+      return error;
-+}
++      error = -EPROTO;
++      while (size > 0) {
++              struct table_header *table;
++              table = unpack_table(blob, size);
++              if (!table)
++                      goto fail;
 +
-+int aa_revalidate_sk(struct sock *sk, char *operation)
-+{
-+      struct aa_profile *profile;
-+      int error = 0;
++              switch (table->td_id) {
++              case YYTD_ID_ACCEPT:
++              case YYTD_ID_ACCEPT2:
++              case YYTD_ID_BASE:
++                      dfa->tables[table->td_id - 1] = table;
++                      if (table->td_flags != YYTD_DATA32)
++                              goto fail;
++                      break;
++              case YYTD_ID_DEF:
++              case YYTD_ID_NXT:
++              case YYTD_ID_CHK:
++                      dfa->tables[table->td_id - 1] = table;
++                      if (table->td_flags != YYTD_DATA16)
++                              goto fail;
++                      break;
++              case YYTD_ID_EC:
++                      dfa->tables[table->td_id - 1] = table;
++                      if (table->td_flags != YYTD_DATA8)
++                              goto fail;
++                      break;
++              default:
++                      kfree(table);
++                      goto fail;
++              }
 +
-+      /* this is some debugging code to flush out the network hooks that
-+         that are called in interrupt context */
-+      if (in_interrupt()) {
-+              printk("AppArmor Debug: Hook being called from interrupt context\n");
-+              dump_stack();
-+              return 0;
++              blob += table_size(table->td_lolen, table->td_flags);
++              size -= table_size(table->td_lolen, table->td_flags);
 +      }
 +
-+      profile = aa_get_profile(current);
-+      if (profile)
-+              error = aa_net_perm(profile, operation,
-+                                  sk->sk_family, sk->sk_type,
-+                                  sk->sk_protocol);
-+      aa_put_profile(profile);
++      return 0;
 +
++fail:
++      for (i = 0; i < ARRAY_SIZE(dfa->tables); i++) {
++              kfree(dfa->tables[i]);
++              dfa->tables[i] = NULL;
++      }
 +      return error;
 +}
++
 +/**
-+ * aa_task_setrlimit - test permission to set an rlimit
-+ * @profile - profile confining the task
-+ * @resource - the resource being set
-+ * @new_rlim - the new resource limit
++ * verify_dfa - verify that all the transitions and states in the dfa tables
++ *              are in bounds.
++ * @dfa: dfa to test
 + *
-+ * Control raising the processes hard limit.
++ * assumes dfa has gone through the verification done by unpacking
 + */
-+int aa_task_setrlimit(struct aa_profile *profile, unsigned int resource,
-+                    struct rlimit *new_rlim)
++int verify_dfa(struct aa_dfa *dfa)
 +{
-+      struct aa_audit sa;
-+      int error = 0;
++      size_t i, state_count, trans_count;
++      int error = -EPROTO;
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "setrlimit";
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.rlimit = resource + 1;
++      /* check that required tables exist */
++      if (!(dfa->tables[YYTD_ID_ACCEPT - 1] &&
++            dfa->tables[YYTD_ID_ACCEPT2 - 1] &&
++            dfa->tables[YYTD_ID_DEF - 1] &&
++            dfa->tables[YYTD_ID_BASE - 1] &&
++            dfa->tables[YYTD_ID_NXT - 1] &&
++            dfa->tables[YYTD_ID_CHK - 1]))
++              goto out;
 +
-+      if (profile->rlimits.mask & (1 << resource) &&
-+          new_rlim->rlim_max > profile->rlimits.limits[resource].rlim_max) {
-+              sa.error_code = -EACCES;
++      /* accept.size == default.size == base.size */
++      state_count = dfa->tables[YYTD_ID_BASE - 1]->td_lolen;
++      if (!(state_count == dfa->tables[YYTD_ID_DEF - 1]->td_lolen &&
++            state_count == dfa->tables[YYTD_ID_ACCEPT - 1]->td_lolen &&
++            state_count == dfa->tables[YYTD_ID_ACCEPT2 - 1]->td_lolen))
++              goto out;
 +
-+              error = aa_audit(profile, &sa);
-+      }
++      /* next.size == chk.size */
++      trans_count = dfa->tables[YYTD_ID_NXT - 1]->td_lolen;
++      if (trans_count != dfa->tables[YYTD_ID_CHK - 1]->td_lolen)
++              goto out;
 +
-+      return error;
-+}
++      /* if equivalence classes then its table size must be 256 */
++      if (dfa->tables[YYTD_ID_EC - 1] &&
++          dfa->tables[YYTD_ID_EC - 1]->td_lolen != 256)
++              goto out;
 +
-+static int aa_rlimit_nproc(struct aa_profile *profile) {
-+      if (profile && (profile->rlimits.mask & (1 << RLIMIT_NPROC)) &&
-+          profile->task_count >= profile->rlimits.limits[RLIMIT_NPROC].rlim_max)
-+              return -EAGAIN;
-+      return 0;
-+}
++      for (i = 0; i < state_count; i++) {
++              if (DEFAULT_TABLE(dfa)[i] >= state_count)
++                      goto out;
++              if (BASE_TABLE(dfa)[i] >= trans_count + 256)
++                      goto out;
++      }
 +
-+void aa_set_rlimits(struct task_struct *task, struct aa_profile *profile)
-+{
-+      int i, mask;
++      for (i = 0; i < trans_count ; i++) {
++              if (NEXT_TABLE(dfa)[i] >= state_count)
++                      goto out;
++              if (CHECK_TABLE(dfa)[i] >= state_count)
++                      goto out;
++      }
 +
-+      if (!profile)
-+              return;
++      /* verify accept permissions */
++      for (i = 0; i < state_count; i++) {
++              int mode = ACCEPT_TABLE(dfa)[i];
 +
-+      if (!profile->rlimits.mask)
-+              return;
++              if (mode & ~DFA_VALID_PERM_MASK)
++                      goto out;
++              if (ACCEPT_TABLE2(dfa)[i] & ~DFA_VALID_PERM2_MASK)
++                      goto out;
 +
-+      task_lock(task->group_leader);
-+      mask = 1;
-+      for (i = 0; i < RLIM_NLIMITS; i++, mask <<= 1) {
-+              struct rlimit new_rlim, *old_rlim;
++      }
 +
-+              /* check to see if NPROC which is per profile and handled
-+               * in clone/exec or whether this is a limit to be set
-+               * can't set cpu limit either right now
-+               */
-+              if (i == RLIMIT_NPROC || i == RLIMIT_CPU)
-+                      continue;
++      error = 0;
++out:
++      return error;
++}
 +
-+              old_rlim = task->signal->rlim + i;
-+              new_rlim = *old_rlim;
++struct aa_dfa *aa_match_alloc(void)
++{
++      return kzalloc(sizeof(struct aa_dfa), GFP_KERNEL);
++}
 +
-+              if (mask & profile->rlimits.mask &&
-+                  profile->rlimits.limits[i].rlim_max < new_rlim.rlim_max) {
-+                      new_rlim.rlim_max = profile->rlimits.limits[i].rlim_max;
-+                      /* soft limit should not exceed hard limit */
-+                      if (new_rlim.rlim_cur > new_rlim.rlim_max)
-+                              new_rlim.rlim_cur = new_rlim.rlim_max;
-+              }
++void aa_match_free(struct aa_dfa *dfa)
++{
++      if (dfa) {
++              int i;
 +
-+              *old_rlim = new_rlim;
++              for (i = 0; i < ARRAY_SIZE(dfa->tables); i++)
++                      kfree(dfa->tables[i]);
 +      }
-+      task_unlock(task->group_leader);
++      kfree(dfa);
 +}
 +
-+/*******************************
-+ * Global task related functions
-+ *******************************/
-+
 +/**
-+ * aa_clone - initialize the task context for a new task
-+ * @child: task that is being created
++ * aa_dfa_match_len - traverse @dfa to find state @str stops at
++ * @dfa: the dfa to match @str against
++ * @start: the state of the dfa to start matching in
++ * @str: the string of bytes to match against the dfa
++ * @len: length of the string of bytes to match
 + *
-+ * Returns 0 on success, or else an error code.
++ * aa_dfa_match_len will match @str against the dfa and return the state it
++ * finished matching in. The final state can be used to look up the accepting
++ * label, or as the start state of a continuing match.
++ *
++ * This function will happily match again the 0 byte and only finishes
++ * when @len input is consumed.
 + */
-+int aa_clone(struct task_struct *child)
++unsigned int aa_dfa_match_len(struct aa_dfa *dfa, unsigned int start,
++                            const char *str, int len)
 +{
-+      struct aa_audit sa;
-+      struct aa_task_context *cxt, *child_cxt;
-+      struct aa_profile *profile;
++      u16 *def = DEFAULT_TABLE(dfa);
++      u32 *base = BASE_TABLE(dfa);
++      u16 *next = NEXT_TABLE(dfa);
++      u16 *check = CHECK_TABLE(dfa);
++      unsigned int state = start, pos;
 +
-+      if (!aa_task_context(current))
++      if (state == 0)
 +              return 0;
-+      child_cxt = aa_alloc_task_context(GFP_KERNEL);
-+      if (!child_cxt)
-+              return -ENOMEM;
-+
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "clone";
-+      sa.task = child->pid;
-+      sa.gfp_mask = GFP_KERNEL;
-+
-+repeat:
-+      profile = aa_get_profile(current);
-+      if (profile) {
-+              lock_profile(profile);
-+              cxt = aa_task_context(current);
-+              if (unlikely(profile->isstale || !cxt ||
-+                           cxt->profile != profile)) {
-+                      /**
-+                       * Race with profile replacement or removal, or with
-+                       * task context removal.
-+                       */
-+                      unlock_profile(profile);
-+                      aa_put_profile(profile);
-+                      goto repeat;
-+              }
-+
-+              if (aa_rlimit_nproc(profile)) {
-+                      sa.info = "rlimit nproc limit exceeded";
-+                      unlock_profile(profile);
-+                      aa_audit_reject(profile, &sa);
-+                      aa_put_profile(profile);
-+                      return -EAGAIN;
-+              }
-+
-+              /* No need to grab the child's task lock here. */
-+              aa_change_task_context(child, child_cxt, profile,
-+                                     cxt->cookie, cxt->previous_profile);
 +
-+              unlock_profile(profile);
-+
-+              if (APPARMOR_COMPLAIN(child_cxt) &&
-+                  profile == profile->ns->null_complain_profile) {
-+                      aa_audit_hint(profile, &sa);
-+              }
-+              aa_put_profile(profile);
-+      } else
-+              aa_free_task_context(child_cxt);
-+
-+      return 0;
-+}
-+
-+static struct aa_profile *
-+aa_register_find(struct aa_profile *profile, const char* ns_name,
-+               const char *name, int mandatory, int complain,
-+               struct aa_audit *sa)
-+{
-+      struct aa_namespace *ns;
-+      struct aa_profile *new_profile;
-+      int ns_ref = 0;
-+
-+      if (profile)
-+              ns = profile->ns;
-+      else
-+              ns = default_namespace;
-+
-+      if (ns_name) {
-+              /* locate the profile namespace */
-+              ns = aa_find_namespace(ns_name);
-+              if (!ns) {
-+                      if (mandatory) {
-+                              sa->info = "profile namespace not found";
-+                              sa->denied_mask = sa->request_mask;
-+                              sa->error_code = -ENOENT;
-+                              return ERR_PTR(-ENOENT);
-+                      } else {
-+                              return NULL;
-+                      }
-+              }
-+              ns_ref++;
-+      }
-+
-+      /* Locate new profile */
-+      new_profile = aa_find_profile(ns, name);
-+
-+      if (new_profile) {
-+              AA_DEBUG("%s: setting profile %s\n",
-+                       __FUNCTION__, new_profile->name);
-+      } else if (mandatory && profile) {
-+              sa->info = "mandatory profile missing";
-+              sa->denied_mask = sa->request_mask;     /* shifted MAY_EXEC */
-+              if (complain) {
-+                      aa_audit_hint(profile, sa);
-+                      new_profile =
-+                          aa_dup_profile(profile->ns->null_complain_profile);
-+              } else {
-+                      sa->error_code = -EACCES;
-+                      if (ns_ref)
-+                              aa_put_namespace(ns);
-+                      return ERR_PTR(-EACCES);
++      /* current state is <state>, matching character *str */
++      if (dfa->tables[YYTD_ID_EC - 1]) {
++              u8 *equiv = EQUIV_TABLE(dfa);
++              for (; len; len--) {
++                      pos = base[state] + equiv[(u8)*str++];
++                      if (check[pos] == state)
++                              state = next[pos];
++                      else
++                              state = def[state];
 +              }
 +      } else {
-+              /* Only way we can get into this code is if task
-+               * is unconfined, pix, nix.
-+               */
-+              AA_DEBUG("%s: No profile found for exec image '%s'\n",
-+                       __FUNCTION__,
-+                       name);
++              for (; len; len--) {
++                      pos = base[state] + (u8)*str++;
++                      if (check[pos] == state)
++                              state = next[pos];
++                      else
++                              state = def[state];
++              }
 +      }
-+      if (ns_ref)
-+              aa_put_namespace(ns);
-+      return new_profile;
++      return state;
 +}
 +
-+static struct aa_profile *
-+aa_x_to_profile(struct aa_profile *profile, const char *filename, int xmode,
-+              struct aa_audit *sa, char **child)
-+{
-+      struct aa_profile *new_profile = NULL;
-+      int ix = xmode & AA_EXEC_INHERIT;
-+      int complain = PROFILE_COMPLAIN(profile);
-+      int index;
-+
-+      *child = NULL;
-+      switch (xmode & AA_EXEC_MODIFIERS) {
-+      case 0:
-+              /* only valid with ix flag */
-+              ix = 1;
-+              break;
-+      case AA_EXEC_UNCONFINED:
-+              /* only valid without ix flag */
-+              ix = 0;
-+              break;
-+      case AA_EXEC_PROFILE:
-+              new_profile = aa_register_find(profile, NULL, filename, !ix,
-+                                             complain, sa);
-+              break;
-+      case AA_EXEC_CHILD:
-+              *child = new_compound_name(profile->name, filename);
-+              sa->name2 = *child;
-+              if (!*child) {
-+                      sa->info = "Failed name resolution - exec failed";
-+                      sa->error_code = -ENOMEM;
-+                      new_profile = ERR_PTR(-ENOMEM);
-+              } else {
-+                      new_profile = aa_register_find(profile, NULL, *child,
-+                                                     !ix, complain, sa);
-+              }
-+              break;
-+      default:
-+              /* all other indexes are named transitions */
-+              index = AA_EXEC_INDEX(xmode);
-+              if (index - 4 > profile->exec_table_size) {
-+                      sa->info = "invalid named transition - exec failed";
-+                      sa->error_code = -EACCES;
-+                      new_profile = ERR_PTR(-EACCES);
-+              } else {
-+                      char *ns_name = NULL;
-+                      char *name = profile->exec_table[index - 4];
-+                      if (*name == ':') {
-+                              ns_name = name + 1;
-+                              name = ns_name + strlen(ns_name) + 1;
-+                      }
-+                      sa->name2 = name;
-+                      sa->name3 = ns_name;
-+                      new_profile =
-+                              aa_register_find(profile, ns_name, name,
-+                                               !ix, complain, sa);
-+              }
-+      }
-+      if (IS_ERR(new_profile))
-+              /* all these failures must be audited - no quieting */
-+              return ERR_PTR(aa_audit_reject(profile, sa));
-+      return new_profile;
++
++/**
++ * aa_dfa_next_state - traverse @dfa to find state @str stops at
++ * @dfa: the dfa to match @str against
++ * @start: the state of the dfa to start matching in
++ * @str: the null terminated string of bytes to match against the dfa
++ *
++ * aa_dfa_next_state will match @str against the dfa and return the state it
++ * finished matching in. The final state can be used to look up the accepting
++ * label, or as the start state of a continuing match.
++ */
++unsigned int aa_dfa_match(struct aa_dfa *dfa, unsigned int start,
++                        const char *str)
++{
++      return aa_dfa_match_len(dfa, start, str, strlen(str));
 +}
 +
 +/**
-+ * aa_register - register a new program
-+ * @bprm: binprm of program being registered
++ * aa_dfa_null_transition - step to next state after null character
++ * @dfa: the dfa to match against
++ * @start: the state of the dfa to start matching in
 + *
-+ * Try to register a new program during execve().  This should give the
-+ * new program a valid aa_task_context if confined.
++ * aa_dfa_null_transition transitions to the next state after a null
++ * character which is not used in standard matching and is only
++ * used to seperate pairs.
 + */
-+int aa_register(struct linux_binprm *bprm)
++unsigned int aa_dfa_null_transition(struct aa_dfa *dfa, unsigned int start)
 +{
-+      const char *filename;
-+      char  *buffer = NULL, *child = NULL;
-+      struct file *filp = bprm->file;
-+      struct aa_profile *profile, *old_profile, *new_profile = NULL;
-+      int exec_mode, complain = 0, shift;
-+      struct aa_audit sa;
++      return aa_dfa_match_len(dfa, start, "", 1);
++}
 +
-+      AA_DEBUG("%s\n", __FUNCTION__);
+diff --git a/security/apparmor/net.c b/security/apparmor/net.c
+new file mode 100644
+index 0000000..beb8715
+--- /dev/null
++++ b/security/apparmor/net.c
+@@ -0,0 +1,146 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor network mediation
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+      profile = aa_get_profile(current);
++#include "include/apparmor.h"
++#include "include/audit.h"
++#include "include/context.h"
++#include "include/net.h"
++#include "include/policy.h"
 +
-+      shift = aa_inode_mode(filp->f_dentry->d_inode);
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "exec";
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.request_mask = MAY_EXEC << shift;
-+
-+      filename = aa_get_name(filp->f_dentry, filp->f_vfsmnt, &buffer, 0);
-+      if (IS_ERR(filename)) {
-+              if (profile) {
-+                      sa.info = "Failed name resolution - exec failed";
-+                      sa.error_code = PTR_ERR(filename);
-+                      aa_audit_file(profile, &sa);
-+                      return sa.error_code;
-+              } else
-+                      return 0;
-+      }
-+      sa.name = filename;
++#include "af_names.h"
 +
-+      exec_mode = AA_EXEC_UNSAFE << shift;
++static const char *sock_type_names[] = {
++      "unknown(0)",
++      "stream",
++      "dgram",
++      "raw",
++      "rdm",
++      "seqpacket",
++      "dccp",
++      "unknown(7)",
++      "unknown(8)",
++      "unknown(9)",
++      "packet",
++};
 +
-+repeat:
-+      if (profile) {
-+              complain = PROFILE_COMPLAIN(profile);
++struct aa_audit_net {
++      struct aa_audit base;
 +
-+              /* Confined task, determine what mode inherit, unconfined or
-+               * mandatory to load new profile
-+               */
-+              exec_mode = aa_match(profile->file_rules, filename,
-+                                   &sa.audit_mask);
-+
-+
-+              if (exec_mode & sa.request_mask) {
-+                      int xm = exec_mode >> shift;
-+                      new_profile = aa_x_to_profile(profile, filename,
-+                                                    xm, &sa, &child);
-+
-+                      if (!new_profile && (xm & AA_EXEC_INHERIT))
-+                              /* (p|c|n|)ix - don't change profile */
-+                              goto cleanup;
-+                      /* error case caught below */
-+
-+              } else if (sa.request_mask & AUDIT_QUIET_MASK(sa.audit_mask)) {
-+                      /* quiet failed exit */
-+                      new_profile = ERR_PTR(-EACCES);
-+              } else if (complain) {
-+                      /* There was no entry in calling profile
-+                       * describing mode to execute image in.
-+                       * Drop into null-profile (disabling secure exec).
-+                       */
-+                      new_profile =
-+                          aa_dup_profile(profile->ns->null_complain_profile);
-+                      exec_mode |= AA_EXEC_UNSAFE << shift;
-+              } else {
-+                      sa.denied_mask = sa.request_mask;
-+                      sa.error_code = -EACCES;
-+                      new_profile = ERR_PTR(aa_audit_file(profile, &sa));
-+              }
-+      } else {
-+              /* Unconfined task, load profile if it exists */
-+              new_profile = aa_register_find(NULL, NULL, filename, 0, 0, &sa);
-+              if (new_profile == NULL)
-+                      goto cleanup;
-+      }
++      int family, type, protocol;
 +
-+      if (IS_ERR(new_profile))
-+              goto cleanup;
++};
 +
-+      old_profile = __aa_replace_profile(current, new_profile);
-+      if (IS_ERR(old_profile)) {
-+              aa_put_profile(new_profile);
-+              aa_put_profile(profile);
-+              if (PTR_ERR(old_profile) == -ESTALE) {
-+                      profile = aa_get_profile(current);
-+                      goto repeat;
-+              }
-+              if (PTR_ERR(old_profile) == -EPERM) {
-+                      sa.denied_mask = sa.request_mask;
-+                      sa.info = "unable to set profile due to ptrace";
-+                      sa.task = current->parent->pid;
-+                      aa_audit_reject(profile, &sa);
-+              }
-+              if (PTR_ERR(old_profile) == -EAGAIN) {
-+                      sa.info = "rlimit nproc limit exceeded";
-+                      aa_audit_reject(profile, &sa);
-+              }
-+              new_profile = old_profile;
-+              goto cleanup;
-+      }
-+      aa_put_profile(old_profile);
-+      aa_put_profile(profile);
++static void audit_cb(struct audit_buffer *ab, void *va)
++{
++      struct aa_audit_net *sa = va;
 +
-+      /* Handle confined exec.
-+       * Can be at this point for the following reasons:
-+       * 1. unconfined switching to confined
-+       * 2. confined switching to different confinement
-+       * 3. confined switching to unconfined
-+       *
-+       * Cases 2 and 3 are marked as requiring secure exec
-+       * (unless policy specified "unsafe exec")
-+       */
-+      if (!(exec_mode & (AA_EXEC_UNSAFE << shift))) {
-+              unsigned long bprm_flags;
++      if (sa->family || sa->type) {
++              if (address_family_names[sa->family])
++                      audit_log_format(ab, " family=\"%s\"",
++                                       address_family_names[sa->family]);
++              else
++                      audit_log_format(ab, " family=\"unknown(%d)\"",
++                                       sa->family);
 +
-+              bprm_flags = AA_SECURE_EXEC_NEEDED;
-+              bprm->security = (void*)
-+                      ((unsigned long)bprm->security | bprm_flags);
-+      }
++              if (sock_type_names[sa->type])
++                      audit_log_format(ab, " sock_type=\"%s\"",
++                                       sock_type_names[sa->type]);
++              else
++                      audit_log_format(ab, " sock_type=\"unknown(%d)\"",
++                                       sa->type);
 +
-+      if (complain && new_profile &&
-+          new_profile == new_profile->ns->null_complain_profile) {
-+              sa.request_mask = 0;
-+              sa.name = NULL;
-+              sa.info = "set profile";
-+              aa_audit_hint(new_profile, &sa);
++              audit_log_format(ab, " protocol=%d", sa->protocol);
 +      }
-+
-+cleanup:
-+      aa_put_name_buffer(child);
-+      aa_put_name_buffer(buffer);
-+      if (IS_ERR(new_profile))
-+              return PTR_ERR(new_profile);
-+      aa_put_profile(new_profile);
-+      return 0;
++      
 +}
 +
-+/**
-+ * aa_release - release a task context
-+ * @task: task being released
-+ *
-+ * This is called after a task has exited and the parent has reaped it.
-+ */
-+void aa_release(struct task_struct *task)
++static int aa_audit_net(struct aa_profile *profile, struct aa_audit_net *sa)
 +{
-+      struct aa_task_context *cxt;
-+      struct aa_profile *profile;
-+      /*
-+       * While the task context is still on a profile's task context
-+       * list, another process could replace the profile under us,
-+       * leaving us with a locked profile that is no longer attached
-+       * to this task. So after locking the profile, we check that
-+       * the profile is still attached.  The profile lock is
-+       * sufficient to prevent the replacement race so we do not lock
-+       * the task.
-+       *
-+       * Use lock subtyping to avoid lockdep reporting a false irq
-+       * possible inversion between the task_lock and profile_lock
-+       *
-+       * We also avoid taking the task_lock here because lock_dep
-+       * would report another false {softirq-on-W} potential irq_lock
-+       * inversion.
-+       *
-+       * If the task does not have a profile attached we are safe;
-+       * nothing can race with us at this point.
-+       */
++      int type = AUDIT_APPARMOR_AUTO;
 +
-+repeat:
-+      profile = aa_get_profile(task);
-+      if (profile) {
-+              lock_profile_nested(profile, aa_lock_task_release);
-+              cxt = aa_task_context(task);
-+              if (unlikely(!cxt || cxt->profile != profile)) {
-+                      unlock_profile(profile);
-+                      aa_put_profile(profile);
-+                      goto repeat;
-+              }
-+              aa_change_task_context(task, NULL, NULL, 0, NULL);
-+              unlock_profile(profile);
-+              aa_put_profile(profile);
++      if (likely(!sa->base.error)) {
++              u16 audit_mask = profile->net.audit[sa->family];
++              if (likely((PROFILE_AUDIT_MODE(profile) != AUDIT_ALL) &&
++                         !(1 << sa->type & audit_mask)))
++                      return 0;
++      } else {
++              u16 quiet_mask = profile->net.quiet[sa->family];
++              u16 kill_mask = 0;
++              u16 denied = (1 << sa->type) & ~quiet_mask;
++
++              if (denied & kill_mask)
++                      type = AUDIT_APPARMOR_KILL;
++
++              if ((denied & quiet_mask) &&
++                  PROFILE_AUDIT_MODE(profile) != AUDIT_NOQUIET &&
++                  PROFILE_AUDIT_MODE(profile) != AUDIT_ALL)
++                      return PROFILE_COMPLAIN(profile) ? 0 : sa->base.error;
 +      }
++
++      return aa_audit(type, profile, (struct aa_audit *)sa, audit_cb);
 +}
 +
-+static int do_change_profile(struct aa_profile *expected,
-+                           struct aa_namespace *ns, const char *name,
-+                           u64 cookie, int restore, int hat,
-+                           struct aa_audit *sa)
++int aa_net_perm(struct aa_profile *profile, char *operation,
++              int family, int type, int protocol)
 +{
-+      struct aa_profile *new_profile = NULL, *old_profile = NULL,
-+              *previous_profile = NULL;
-+      struct aa_task_context *new_cxt, *cxt;
-+      int error = 0;
++      struct aa_audit_net sa;
++      u16 family_mask;
 +
-+      sa->name = name;
++      if ((family < 0) || (family >= AF_MAX))
++              return -EINVAL;
 +
-+      new_cxt = aa_alloc_task_context(GFP_KERNEL);
-+      if (!new_cxt)
-+              return -ENOMEM;
++      if ((type < 0) || (type >= SOCK_MAX))
++              return -EINVAL;
 +
-+      new_profile = aa_find_profile(ns, name);
-+      if (!new_profile && !restore) {
-+              if (!PROFILE_COMPLAIN(expected)) {
-+                      aa_free_task_context(new_cxt);
-+                      return -ENOENT;
-+              }
-+              new_profile = aa_dup_profile(ns->null_complain_profile);
-+      } else if (new_profile && hat && !PROFILE_IS_HAT(new_profile)) {
-+              aa_free_task_context(new_cxt);
-+              aa_put_profile(new_profile);
-+              return error;
-+      }
++      /* unix domain and netlink sockets are handled by ipc */
++      if (family == AF_UNIX || family == AF_NETLINK)
++              return 0;
 +
-+      cxt = lock_task_and_profiles(current, new_profile);
-+      if (!cxt) {
-+              error = -EPERM;
-+              goto out;
-+      }
-+      old_profile = cxt->profile;
++      family_mask = profile->net.allowed[family];
 +
-+      if (cxt->profile != expected || (new_profile && new_profile->isstale)) {
-+              error = -ESTALE;
-+              goto out;
-+      }
++      sa.base.error = (family_mask & (1 << type)) ? 0 : -EACCES;
 +
-+      if (cxt->previous_profile) {
-+              if (cxt->cookie != cookie) {
-+                      error = -EACCES;
-+                      sa->info = "killing process";
-+                      aa_audit_reject(cxt->profile, sa);
-+                      /* terminate process */
-+                      (void)send_sig_info(SIGKILL, NULL, current);
-+                      goto out;
-+              }
++      memset(&sa, 0, sizeof(sa));
++      sa.base.operation = operation;
++      sa.base.gfp_mask = GFP_KERNEL;
++      sa.family = family;
++      sa.type = type;
++      sa.protocol = protocol;
 +
-+              if (!restore)
-+                      previous_profile = cxt->previous_profile;
-+      } else
-+              previous_profile = cxt->profile;
++      return  aa_audit_net(profile, &sa);
++}
 +
-+      if ((current->ptrace & PT_PTRACED) && aa_may_ptrace(cxt, new_profile)) {
-+              error = -EACCES;
-+              goto out;
-+      }
++int aa_revalidate_sk(struct sock *sk, char *operation)
++{
++      struct aa_profile *profile;
++      struct cred *cred;
++      int error = 0;
 +
-+      if ((error = aa_rlimit_nproc(new_profile))) {
-+              sa->info = "rlimit nproc limit exceeded";
-+              aa_audit_reject(cxt->profile, sa);
-+              goto out;
++      /* this is some debugging code to flush out the network hooks that
++         that are called in interrupt context */
++      if (in_interrupt()) {
++              printk(KERN_WARNING "AppArmor Debug: Hook being called from interrupt context\n");
++              dump_stack();
++              return 0;
 +      }
 +
-+      if (new_profile == ns->null_complain_profile)
-+              aa_audit_hint(cxt->profile, sa);
++      cred = aa_get_task_policy(current, &profile);
++      if (profile)
++              error = aa_net_perm(profile, operation,
++                                  sk->sk_family, sk->sk_type,
++                                  sk->sk_protocol);
++      put_cred(cred);
++
++      return error;
++}
+diff --git a/security/apparmor/path.c b/security/apparmor/path.c
+new file mode 100644
+index 0000000..21f3e67
+--- /dev/null
++++ b/security/apparmor/path.c
+@@ -0,0 +1,155 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor function for pathnames
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
 +
-+      if (APPARMOR_AUDIT(cxt))
-+              aa_audit_message(cxt->profile, sa, AUDIT_APPARMOR_AUDIT);
++#include <linux/mnt_namespace.h>
++#include <linux/mount.h>
++#include <linux/namei.h>
++#include <linux/path.h>
++#include <linux/sched.h>
++#include <linux/slab.h>
++#include <linux/fs_struct.h>
 +
-+      if (!restore && cookie)
-+              aa_change_task_context(current, new_cxt, new_profile, cookie,
-+                                     previous_profile);
-+      else
-+              /* either return to previous_profile, or a permanent change */
-+              aa_change_task_context(current, new_cxt, new_profile, 0, NULL);
++#include "include/apparmor.h"
++#include "include/path.h"
++
++int aa_get_name_to_buffer(struct path *path, int is_dir, char *buffer, int size,
++                        char **name)
++{
++      int error = d_namespace_path(path, buffer, size - is_dir, name);
++
++      if (!error && is_dir && (*name)[1] != '\0')
++              /*
++               * Append "/" to the pathname.  The root directory is a special
++               * case; it already ends in slash.
++               */
++              strcpy(&buffer[size - 2], "/");
 +
-+out:
-+      if (aa_task_context(current) != new_cxt)
-+              aa_free_task_context(new_cxt);
-+      task_unlock(current);
-+      unlock_both_profiles(old_profile, new_profile);
-+      aa_put_profile(new_profile);
 +      return error;
 +}
 +
 +/**
-+ * aa_change_profile - perform a one-way profile transition
-+ * @ns_name: name of the profile namespace to change to
-+ * @name: name of profile to change to
-+ * Change to new profile @name.  Unlike with hats, there is no way
-+ * to change back.
++ * aa_get_name - compute the pathname of a file
++ * @path: path the file
++ * @is_dir: set if the file is a directory
++ * @buffer: buffer that aa_get_name() allocated
++ * @name: the error code indicating whether aa_get_name failed
 + *
-+ * Returns %0 on success, error otherwise.
++ * Returns an error code if the there was a failure in obtaining the
++ * name.
++ *
++ * @name is apointer to the beginning of the pathname (which usually differs
++ * from the beginning of the buffer), or NULL.  If there is an error @name
++ * may contain a partial or invalid name (in the case of a deleted file), that
++ * can be used for audit purposes, but it can not be used for mediation.
++ *
++ * We need @is_dir to indicate whether the file is a directory or not because
++ * the file may not yet exist, and so we cannot check the inode's file type.
 + */
-+int aa_change_profile(const char *ns_name, const char *name)
++int aa_get_name(struct path *path, int is_dir, char **buffer, char **name)
 +{
-+      struct aa_task_context *cxt;
-+      struct aa_profile *profile = NULL;
-+      struct aa_namespace *ns = NULL;
-+      struct aa_audit sa;
-+      unsigned int state;
-+      int error = -EINVAL;
++      char *buf, *str = NULL;
++      int size = 256;
++      int error;
 +
-+      if (!name)
-+              return -EINVAL;
++      *name = NULL;
++      *buffer = NULL;
++      for (;;) {
++              buf = kmalloc(size, GFP_KERNEL);
++              if (!buf)
++                      return -ENOMEM;
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.gfp_mask = GFP_ATOMIC;
-+      sa.operation = "change_profile";
++              error = aa_get_name_to_buffer(path, is_dir, buf, size, &str);
++              if (!error || (error == -ENOENT) || (error == -ESTALE))
++                      break;
 +
-+repeat:
-+      task_lock(current);
-+      cxt = aa_task_context(current);
-+      if (cxt)
-+              profile = aa_dup_profile(cxt->profile);
-+      task_unlock(current);
++              kfree(buf);
++              size <<= 1;
++              if (size > g_apparmor_path_max)
++                      return -ENAMETOOLONG;
++      }
++      *buffer = buf;
++      *name = str;
 +
-+      if (ns_name)
-+              ns = aa_find_namespace(ns_name);
-+      else if (profile)
-+              ns = aa_get_namespace(profile->ns);
-+      else
-+              ns = aa_get_namespace(default_namespace);
++      return error;
++}
 +
-+      if (!ns) {
-+              aa_put_profile(profile);
-+              return -ENOENT;
-+      }
-+
-+      if (!profile || PROFILE_COMPLAIN(profile) ||
-+          (ns == profile->ns &&
-+           (aa_match(profile->file_rules, name, NULL) & AA_CHANGE_PROFILE)))
-+              error = do_change_profile(profile, ns, name, 0, 0, 0, &sa);
-+      else {
-+              /* check for a rule with a namespace prepended */
-+              aa_match_state(profile->file_rules, DFA_START, ns->name,
-+                             &state);
-+              state = aa_dfa_null_transition(profile->file_rules, state);
-+              if ((aa_match_state(profile->file_rules, state, name, NULL) &
-+                    AA_CHANGE_PROFILE))
-+                      error = do_change_profile(profile, ns, name, 0, 0, 0,
-+                                                &sa);
-+              else
-+                      /* no permission to transition to profile @name */
-+                      error = -EACCES;
++int d_namespace_path(struct path *path, char *buf, int buflen, char **name)
++{
++      struct path root, tmp, ns_root = { };
++      char *res;
++      int error = 0;
++
++      read_lock(&current->fs->lock);
++      root = current->fs->root;
++      path_get(&current->fs->root);
++      read_unlock(&current->fs->lock);
++      spin_lock(&vfsmount_lock);
++      if (root.mnt && root.mnt->mnt_ns)
++              ns_root.mnt = mntget(root.mnt->mnt_ns->root);
++      if (ns_root.mnt)
++              ns_root.dentry = dget(ns_root.mnt->mnt_root);
++      spin_unlock(&vfsmount_lock);
++      spin_lock(&dcache_lock);
++      tmp = ns_root;
++      res = __d_path(path, &tmp, buf, buflen);
++
++      *name = res;
++      /* handle error conditions - and still allow a partial path to
++       * be returned */
++      if (IS_ERR(res)) {
++              error = PTR_ERR(res);
++              *name = buf;
++      } else if (!IS_ROOT(path->dentry) && d_unhashed(path->dentry)) {
++              error = -ENOENT;
++#if 0
++      } else if (tmp.dentry != ns_root.dentry && tmp.mnt != ns_root.mnt) {
++              /* disconnected path don return pathname starting with '/' */
++              error = -ESTALE;
++              if (*res == '/')
++                      *name = res + 1;
++#endif
 +      }
 +
-+      aa_put_namespace(ns);
-+      aa_put_profile(profile);
-+      if (error == -ESTALE)
-+              goto repeat;
++      spin_unlock(&dcache_lock);
++      path_put(&root);
++      path_put(&ns_root);
 +
 +      return error;
 +}
 +
-+/**
-+ * aa_change_hat - change hat to/from subprofile
-+ * @hat_name: hat to change to
-+ * @cookie: magic value to validate the hat change
++char *sysctl_pathname(struct ctl_table *table, char *buffer, int buflen)
++{
++      if (buflen < 1)
++              return NULL;
++      buffer += --buflen;
++      *buffer = '\0';
++
++      while (table) {
++              int namelen = strlen(table->procname);
++
++              if (buflen < namelen + 1)
++                      return NULL;
++              buflen -= namelen + 1;
++              buffer -= namelen;
++              memcpy(buffer, table->procname, namelen);
++              *--buffer = '/';
++              table = table->parent;
++      }
++      if (buflen < 4)
++              return NULL;
++      buffer -= 4;
++      memcpy(buffer, "/sys", 4);
++
++      return buffer;
++}
+diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
+new file mode 100644
+index 0000000..3ba2642
+--- /dev/null
++++ b/security/apparmor/policy.c
+@@ -0,0 +1,727 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor policy manipulation functions
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ *
++ *
++ * AppArmor policy is based around profiles, which contain the rules a
++ * task is confined by.  Every task in the sytem has a profile attached
++ * to it determined either by matching "unconfined" tasks against the
++ * visible set of profiles or by following a profiles attachment rules.
++ *
++ * Each profile exists in an AppArmor profile namespace which is a
++ * container of related profiles.  Each namespace contains a special
++ * "unconfined" profile, which doesn't efforce any confinement on
++ * a task beyond DAC.
++ *
++ * Namespace and profile names can be written together in either
++ * of two syntaxes.
++ *    :namespace:profile - used by kernel interfaces for easy detection
++ *    namespace://profile - used by policy
++ *
++ * Profile names name not start with : or @ and may not contain \0
++ * a // in a profile name indicates a compound name with the name before
++ * the // being the parent profile and the name after the child
++ *
++ * Reserved profile names
++ *    unconfined - special automatically generated unconfined profile
++ *    inherit - special name to indicate profile inheritance
++ *    null-XXXX-YYYY - special automically generated learning profiles
 + *
-+ * Change to new @hat_name, and store the @hat_magic in the current task
-+ * context.  If the new @hat_name is %NULL and the @cookie matches that
-+ * stored in the current task context and is not 0, return to the top level
-+ * profile.
-+ * Returns %0 on success, error otherwise.
++ * Namespace names may not start with / or @ and may not contain \0 or //
++ * it is recommend that they do not contain any '/' characters
++ * Reserved namespace namespace
++ *    default - the default namespace setup by AppArmor
++ *    user-XXXX - user defined profiles
 + */
-+int aa_change_hat(const char *hat_name, u64 cookie)
-+{
-+      struct aa_task_context *cxt;
-+      struct aa_profile *profile, *previous_profile;
-+      struct aa_audit sa;
-+      int error = 0;
 +
-+      memset(&sa, 0, sizeof(sa));
-+      sa.gfp_mask = GFP_ATOMIC;
-+      sa.operation = "change_hat";
-+
-+repeat:
-+      task_lock(current);
-+      cxt = aa_task_context(current);
-+      if (!cxt) {
-+              task_unlock(current);
-+              return -EPERM;
-+      }
-+      profile = aa_dup_profile(cxt->profile);
-+      previous_profile = aa_dup_profile(cxt->previous_profile);
-+      task_unlock(current);
++#include <linux/slab.h>
++#include <linux/spinlock.h>
++#include <linux/string.h>
++
++#include "include/apparmor.h"
++#include "include/capability.h"
++#include "include/file.h"
++#include "include/ipc.h"
++#include "include/match.h"
++#include "include/policy.h"
++#include "include/resource.h"
++#include "include/sid.h"
 +
-+      if (hat_name) {
-+              char *name, *profile_name;
++/* list of profile namespaces and lock */
++LIST_HEAD(ns_list);
++DEFINE_RWLOCK(ns_list_lock);
 +
-+              if (previous_profile)
-+                      profile_name = previous_profile->name;
-+              else
-+                      profile_name = profile->name;
++struct aa_namespace *default_namespace;
 +
-+              name = new_compound_name(profile_name, hat_name);
-+              if (!name) {
-+                      error = -ENOMEM;
-+                      goto out;
-+              }
-+              error = do_change_profile(profile, profile->ns, name, cookie,
-+                                        0, 1, &sa);
-+              aa_put_name_buffer(name);
-+      } else if (previous_profile)
-+              error = do_change_profile(profile, profile->ns,
-+                                        previous_profile->name, cookie, 1, 0,
-+                                        &sa);
-+      /* else ignore restores when there is no saved profile */
++const char *profile_mode_names[] = {
++      "enforce",
++      "complain",
++      "kill",
++};
 +
-+out:
-+      aa_put_profile(previous_profile);
-+      aa_put_profile(profile);
-+      if (error == -ESTALE)
-+              goto repeat;
++#define AA_SYS_SID 0
++#define AA_USR_SID 1
 +
-+      return error;
-+}
 +
-+/**
-+ * __aa_replace_profile - replace a task's profile
-+ * @task: task to switch the profile of
-+ * @profile: profile to switch to
-+ *
-+ * Returns a handle to the previous profile upon success, or else an
-+ * error code.
-+ */
-+struct aa_profile *__aa_replace_profile(struct task_struct *task,
-+                                      struct aa_profile *profile)
++static int common_init(struct aa_policy_common *common, const char *name)
 +{
-+      struct aa_task_context *cxt, *new_cxt = NULL;
-+      struct aa_profile *old_profile = NULL;
++      common->name = kstrdup(name, GFP_KERNEL);
++      if (!common->name)
++              return 0;
++      INIT_LIST_HEAD(&common->list);
++      INIT_LIST_HEAD(&common->profiles);
++      kref_init(&common->count);
++      rwlock_init(&common->lock);
 +
-+      if (profile) {
-+              new_cxt = aa_alloc_task_context(GFP_KERNEL);
-+              if (!new_cxt)
-+                      return ERR_PTR(-ENOMEM);
-+      }
++      return 1;
++}
 +
-+      cxt = lock_task_and_profiles(task, profile);
-+      if (unlikely(profile && profile->isstale)) {
-+              old_profile = ERR_PTR(-ESTALE);
-+              goto error;
++static void common_free(struct aa_policy_common *common)
++{
++      /* still contains profiles -- invalid */
++      if (!list_empty(&common->profiles)) {
++              AA_ERROR("%s: internal error, "
++                       "policy '%s' still contains profiles\n",
++                       __func__, common->name);
++              BUG();
 +      }
-+
-+      if ((current->ptrace & PT_PTRACED) && aa_may_ptrace(cxt, profile)) {
-+              old_profile = ERR_PTR(-EPERM);
-+              goto error;
++      if (!list_empty(&common->list)) {
++              AA_ERROR("%s: internal error, policy '%s' still on list\n",
++                       __func__, common->name);
++              BUG();
 +      }
 +
-+      if (aa_rlimit_nproc(profile)) {
-+              old_profile = ERR_PTR(-EAGAIN);
-+              goto error;
++      kfree(common->name);
++}
++
++static struct aa_policy_common *__common_find(struct list_head *head,
++                                            const char *name)
++                                            
++{
++      struct aa_policy_common *common;
++
++      list_for_each_entry(common, head, list) {
++              if (!strcmp(common->name, name))
++                      return common;
 +      }
++      return NULL;
++}
 +
-+      if (cxt)
-+              old_profile = aa_dup_profile(cxt->profile);
-+      aa_change_task_context(task, new_cxt, profile, 0, NULL);
++static struct aa_policy_common *__common_find_strn(struct list_head *head,
++                                                 const char *str, int len)
++{
++      struct aa_policy_common *common;
 +
-+      task_unlock(task);
-+      aa_set_rlimits(task, profile);
-+      unlock_both_profiles(profile, old_profile);
-+      return old_profile;
++      list_for_each_entry(common, head, list) {
++              if (aa_strneq(common->name, str, len))
++                      return common;
++      }
 +
-+error:
-+      task_unlock(task);
-+      unlock_both_profiles(profile, cxt ? cxt->profile : NULL);
-+      aa_free_task_context(new_cxt);
-+      return old_profile;
++      return NULL;
 +}
 +
-+/**
-+ * lock_task_and_profiles - lock the task and confining profiles and @profile
-+ * @task: task to lock
-+ * @profile: extra profile to lock in addition to the current profile
-+ *
-+ * Handle the spinning on locking to make sure the task context and
-+ * profile are consistent once all locks are aquired.
-+ *
-+ * return the aa_task_context currently confining the task.  The task lock
-+ * will be held whether or not the task is confined.
++/*
++ * Routines for AppArmor namespaces
 + */
-+struct aa_task_context *
-+lock_task_and_profiles(struct task_struct *task, struct aa_profile *profile)
-+{
-+      struct aa_task_context *cxt;
-+      struct aa_profile *old_profile = NULL;
 +
-+      rcu_read_lock();
-+repeat:
-+      cxt = aa_task_context(task);
-+      if (cxt)
-+              old_profile = cxt->profile;
++int alloc_default_namespace(void)
++{
++      struct aa_namespace *ns;
++      ns = alloc_aa_namespace("default");
++      if (!ns)
++              return -ENOMEM;
 +
-+      lock_both_profiles(profile, old_profile);
-+      task_lock(task);
++      default_namespace = aa_get_namespace(ns);
++      write_lock(&ns_list_lock);
++      list_add(&ns->base.list, &ns_list);
++      write_unlock(&ns_list_lock);
 +
-+      /* check for race with profile transition, replacement or removal */
-+      if (unlikely(cxt != aa_task_context(task))) {
-+              task_unlock(task);
-+              unlock_both_profiles(profile, old_profile);
-+              old_profile = NULL;
-+              goto repeat;
-+      }
-+      rcu_read_unlock();
-+      return cxt;
++      return 0;
 +}
 +
-+static void free_aa_task_context_rcu_callback(struct rcu_head *head)
++void free_default_namespace(void)
 +{
-+      struct aa_task_context *cxt;
-+
-+      cxt = container_of(head, struct aa_task_context, rcu);
-+      aa_free_task_context(cxt);
++      write_lock(&ns_list_lock);
++      list_del_init(&default_namespace->base.list);
++      aa_put_namespace(default_namespace);
++      write_unlock(&ns_list_lock);
++      aa_put_namespace(default_namespace);
++      default_namespace = NULL;
 +}
 +
 +/**
-+ * aa_change_task_context - switch a task to use a new context and profile
-+ * @task: task that is having its task context changed
-+ * @new_cxt: new task context to use after the switch
-+ * @profile: new profile to use after the switch
-+ * @cookie: magic value to switch to
-+ * @previous_profile: profile the task can return to
-+ */
-+void aa_change_task_context(struct task_struct *task,
-+                          struct aa_task_context *new_cxt,
-+                          struct aa_profile *profile, u64 cookie,
-+                          struct aa_profile *previous_profile)
-+{
-+      struct aa_task_context *old_cxt = aa_task_context(task);
-+
-+      if (old_cxt) {
-+              list_del_init(&old_cxt->list);
-+              old_cxt->profile->task_count--;
-+              call_rcu(&old_cxt->rcu, free_aa_task_context_rcu_callback);
-+      }
-+      if (new_cxt) {
-+              /* set the caps_logged cache to the quiet_caps mask
-+               * this has the effect of quieting caps that are not
-+               * supposed to be logged
-+               */
-+              new_cxt->caps_logged = profile->quiet_caps;
-+              new_cxt->cookie = cookie;
-+              new_cxt->task = task;
-+              new_cxt->profile = aa_dup_profile(profile);
-+              profile->task_count++;
-+              new_cxt->previous_profile = aa_dup_profile(previous_profile);
-+              list_move(&new_cxt->list, &profile->task_contexts);
-+      }
-+      rcu_assign_pointer(task->security, new_cxt);
-+}
-diff -uprN e/security/apparmor/match.c f/security/apparmor/match.c
---- e/security/apparmor/match.c        1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/match.c        2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,364 @@
-+/*
-+ *    Copyright (C) 2007 Novell/SUSE
-+ *
-+ *    This program is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU General Public License as
-+ *    published by the Free Software Foundation, version 2 of the
-+ *    License.
-+ *
-+ *    Regular expression transition table matching
++ * alloc_aa_namespace - allocate, initialize and return a new namespace
++ * @name: a preallocated name
++ * Returns NULL on failure.
 + */
-+
-+#include <linux/kernel.h>
-+#include <linux/slab.h>
-+#include <linux/errno.h>
-+#include "apparmor.h"
-+#include "match.h"
-+#include "inline.h"
-+
-+static struct table_header *unpack_table(void *blob, size_t bsize)
++struct aa_namespace *alloc_aa_namespace(const char *name)
 +{
-+      struct table_header *table = NULL;
-+      struct table_header th;
-+      size_t tsize;
++      struct aa_namespace *ns;
 +
-+      if (bsize < sizeof(struct table_header))
-+              goto out;
++      ns = kzalloc(sizeof(*ns), GFP_KERNEL);
++      AA_DEBUG("%s(%p)\n", __func__, ns);
++      if (!ns)
++              return NULL;
 +
-+      th.td_id = be16_to_cpu(*(u16 *) (blob));
-+      th.td_flags = be16_to_cpu(*(u16 *) (blob + 2));
-+      th.td_lolen = be32_to_cpu(*(u32 *) (blob + 8));
-+      blob += sizeof(struct table_header);
++      if (!common_init(&ns->base, name))
++              goto fail_ns;
 +
-+      if (!(th.td_flags == YYTD_DATA16 || th.td_flags == YYTD_DATA32 ||
-+              th.td_flags == YYTD_DATA8))
-+              goto out;
++      /* null profile is not added to the profile list */
++      ns->unconfined = alloc_aa_profile("unconfined");
++      if (!ns->unconfined)
++              goto fail_unconfined;
 +
-+      tsize = table_size(th.td_lolen, th.td_flags);
-+      if (bsize < tsize)
-+              goto out;
++      ns->unconfined->sid = aa_alloc_sid(AA_ALLOC_SYS_SID);
++      ns->unconfined->flags = PFLAG_UNCONFINED | PFLAG_IX_ON_NAME_ERROR |
++              PFLAG_IMMUTABLE;
++      ns->unconfined->ns = aa_get_namespace(ns);
 +
-+      table = kmalloc(tsize, GFP_KERNEL);
-+      if (table) {
-+              *table = th;
-+              if (th.td_flags == YYTD_DATA8)
-+                      UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
-+                                   u8, byte_to_byte);
-+              else if (th.td_flags == YYTD_DATA16)
-+                      UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
-+                                   u16, be16_to_cpu);
-+              else
-+                      UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
-+                                   u32, be32_to_cpu);
-+      }
++      return ns;
 +
-+out:
-+      return table;
++fail_unconfined:
++      if (ns->base.name)
++              kfree(ns->base.name);
++fail_ns:
++      kfree(ns);
++      return NULL;
 +}
 +
-+int unpack_dfa(struct aa_dfa *dfa, void *blob, size_t size)
++/**
++ * free_aa_namespace_kref - free aa_namespace by kref (see aa_put_namespace)
++ * @kr: kref callback for freeing of a namespace
++ */
++void free_aa_namespace_kref(struct kref *kref)
 +{
-+      int hsize, i;
-+      int error = -ENOMEM;
-+
-+      /* get dfa table set header */
-+      if (size < sizeof(struct table_set_header))
-+              goto fail;
-+
-+      if (ntohl(*(u32 *)blob) != YYTH_MAGIC)
-+              goto fail;
-+
-+      hsize = ntohl(*(u32 *)(blob + 4));
-+      if (size < hsize)
-+              goto fail;
-+
-+      blob += hsize;
-+      size -= hsize;
++      free_aa_namespace(container_of(kref, struct aa_namespace, base.count));
++}
 +
-+      error = -EPROTO;
-+      while (size > 0) {
-+              struct table_header *table;
-+              table = unpack_table(blob, size);
-+              if (!table)
-+                      goto fail;
++/**
++ * free_aa_namespace - free a profile namespace
++ * @namespace: the namespace to free
++ *
++ * Free a namespace.  All references to the namespace must have been put.
++ * If the namespace was referenced by a profile confining a task,
++ */
++void free_aa_namespace(struct aa_namespace *ns)
++{
++      if (!ns)
++              return;
 +
-+              switch(table->td_id) {
-+              case YYTD_ID_ACCEPT:
-+              case YYTD_ID_ACCEPT2:
-+              case YYTD_ID_BASE:
-+                      dfa->tables[table->td_id - 1] = table;
-+                      if (table->td_flags != YYTD_DATA32)
-+                              goto fail;
-+                      break;
-+              case YYTD_ID_DEF:
-+              case YYTD_ID_NXT:
-+              case YYTD_ID_CHK:
-+                      dfa->tables[table->td_id - 1] = table;
-+                      if (table->td_flags != YYTD_DATA16)
-+                              goto fail;
-+                      break;
-+              case YYTD_ID_EC:
-+                      dfa->tables[table->td_id - 1] = table;
-+                      if (table->td_flags != YYTD_DATA8)
-+                              goto fail;
-+                      break;
-+              default:
-+                      kfree(table);
-+                      goto fail;
-+              }
++      common_free(&ns->base);
 +
-+              blob += table_size(table->td_lolen, table->td_flags);
-+              size -= table_size(table->td_lolen, table->td_flags);
-+      }
++      if (ns->unconfined && ns->unconfined->ns == ns)
++              ns->unconfined->ns = NULL;
 +
-+      return 0;
++      aa_put_profile(ns->unconfined);
++      memset(ns, 0, sizeof(*ns));
++      kfree(ns);
++}
 +
-+fail:
-+      for (i = 0; i < ARRAY_SIZE(dfa->tables); i++) {
-+              if (dfa->tables[i]) {
-+                      kfree(dfa->tables[i]);
-+                      dfa->tables[i] = NULL;
-+              }
-+      }
-+      return error;
++struct aa_namespace *__aa_find_namespace(struct list_head *head,
++                                       const char *name)
++                                       
++{
++      return (struct aa_namespace *) __common_find(head, name);
 +}
 +
 +/**
-+ * verify_dfa - verify that all the transitions and states in the dfa tables
-+ *              are in bounds.
-+ * @dfa: dfa to test
++ * aa_find_namespace  -  look up a profile namespace on the namespace list
++ * @name: name of namespace to find
 + *
-+ * assumes dfa has gone through the verification done by unpacking
++ * Returns a pointer to the namespace on the list, or NULL if no namespace
++ * called @name exists.
 + */
-+int verify_dfa(struct aa_dfa *dfa)
++struct aa_namespace *aa_find_namespace(const char *name)
 +{
-+      size_t i, state_count, trans_count;
-+      int error = -EPROTO;
-+
-+      /* check that required tables exist */
-+      if (!(dfa->tables[YYTD_ID_ACCEPT - 1] &&
-+            dfa->tables[YYTD_ID_ACCEPT2 - 1] &&
-+            dfa->tables[YYTD_ID_DEF - 1] &&
-+            dfa->tables[YYTD_ID_BASE - 1] &&
-+            dfa->tables[YYTD_ID_NXT - 1] &&
-+            dfa->tables[YYTD_ID_CHK - 1]))
-+              goto out;
-+
-+      /* accept.size == default.size == base.size */
-+      state_count = dfa->tables[YYTD_ID_BASE - 1]->td_lolen;
-+      if (!(state_count == dfa->tables[YYTD_ID_DEF - 1]->td_lolen &&
-+            state_count == dfa->tables[YYTD_ID_ACCEPT - 1]->td_lolen &&
-+            state_count == dfa->tables[YYTD_ID_ACCEPT2 - 1]->td_lolen))
-+              goto out;
++      struct aa_namespace *ns = NULL;
 +
-+      /* next.size == chk.size */
-+      trans_count = dfa->tables[YYTD_ID_NXT - 1]->td_lolen;
-+      if (trans_count != dfa->tables[YYTD_ID_CHK - 1]->td_lolen)
-+              goto out;
++      read_lock(&ns_list_lock);
++      ns = aa_get_namespace(__aa_find_namespace(&ns_list, name));
++      read_unlock(&ns_list_lock);
 +
-+      /* if equivalence classes then its table size must be 256 */
-+      if (dfa->tables[YYTD_ID_EC - 1] &&
-+          dfa->tables[YYTD_ID_EC - 1]->td_lolen != 256)
-+              goto out;
++      return ns;
++}
 +
-+      for (i = 0; i < state_count; i++) {
-+              if (DEFAULT_TABLE(dfa)[i] >= state_count)
-+                      goto out;
-+              if (BASE_TABLE(dfa)[i] >= trans_count + 256)
-+                      goto out;
-+      }
++static struct aa_namespace *__aa_find_namespace_by_strn(struct list_head *head,
++                                                      const char *name,
++                                                      int len)
++{
++      return (struct aa_namespace *) __common_find_strn(head, name, len);
++}
 +
-+      for (i = 0; i < trans_count ; i++) {
-+              if (NEXT_TABLE(dfa)[i] >= state_count)
-+                      goto out;
-+              if (CHECK_TABLE(dfa)[i] >= state_count)
-+                      goto out;
-+      }
++struct aa_namespace *aa_find_namespace_by_strn(const char *name, int len)
++{
++      struct aa_namespace *ns = NULL;
 +
-+      /* verify accept permissions */
-+      for (i = 0; i < state_count; i++) {
-+              int mode = ACCEPT_TABLE(dfa)[i];
++      read_lock(&ns_list_lock);
++      ns = aa_get_namespace(__aa_find_namespace_by_strn(&ns_list, name, len));
++      read_unlock(&ns_list_lock);
 +
-+              if (mode & ~AA_VALID_PERM_MASK)
-+                      goto out;
-+              if (ACCEPT_TABLE2(dfa)[i] & ~AA_VALID_PERM2_MASK)
-+                      goto out;
++      return ns;
++}
 +
-+              /* if any exec modifier is set MAY_EXEC must be set */
-+              if ((mode & AA_USER_EXEC_TYPE) && !(mode & AA_USER_EXEC))
-+                      goto out;
-+              if ((mode & AA_OTHER_EXEC_TYPE) && !(mode & AA_OTHER_EXEC))
-+                      goto out;
++/**
++ * aa_prepare_namespace - find an existing or create a new namespace of @name
++ * @name: the namespace to find or add
++ */
++struct aa_namespace *aa_prepare_namespace(const char *name)
++{
++      struct aa_namespace *ns;
++ 
++      write_lock(&ns_list_lock);
++      if (name)
++              ns = aa_get_namespace(__aa_find_namespace(&ns_list, name));
++      else
++              ns = aa_get_namespace(default_namespace);
++      if (!ns) {
++              struct aa_namespace *new_ns;
++              write_unlock(&ns_list_lock);
++              new_ns = alloc_aa_namespace(name);
++              if (!new_ns)
++                      return NULL;
++              write_lock(&ns_list_lock);
++              ns = __aa_find_namespace(&ns_list, name);
++              if (!ns) {
++                      list_add(&new_ns->base.list, &ns_list);
++                      ns = new_ns;
++              } else {
++                      /* raced so free the new one */
++                      free_aa_namespace(new_ns);
++                      aa_get_namespace(ns);
++              }
 +      }
++      write_unlock(&ns_list_lock);
 +
-+      error = 0;
-+out:
-+      return error;
++      return ns;
 +}
 +
-+struct aa_dfa *aa_match_alloc(void)
++/*
++ * requires profile->ns set first, takes profiles refcount
++ * TODO: add accounting
++ */
++void __aa_add_profile(struct aa_policy_common *common,
++                    struct aa_profile *profile)
 +{
-+      return kzalloc(sizeof(struct aa_dfa), GFP_KERNEL);
++      list_add(&profile->base.list, &common->profiles);
++      if (!(profile->flags & PFLAG_NO_LIST_REF))
++              aa_get_profile(profile);
 +}
 +
-+void aa_match_free(struct aa_dfa *dfa)
++void __aa_remove_profile(struct aa_profile *profile,
++                       struct aa_profile *replacement)
 +{
-+      if (dfa) {
-+              int i;
++      if (replacement)
++              profile->replacedby = aa_get_profile(replacement);
++      else
++              profile->replacedby = ERR_PTR(-EINVAL);
++      list_del_init(&profile->base.list);
++      if (!(profile->flags & PFLAG_NO_LIST_REF))
++              aa_put_profile(profile);
++}
 +
-+              for (i = 0; i < ARRAY_SIZE(dfa->tables); i++)
-+                      kfree(dfa->tables[i]);
-+      }
-+      kfree(dfa);
++/* TODO: add accounting */
++void __aa_replace_profile(struct aa_profile *profile,
++                        struct aa_profile *replacement)
++{
++      if (replacement) {
++              struct aa_policy_common *common;
++
++              if (profile->parent)
++                      common = &profile->parent->base;
++              else
++                      common = &profile->ns->base;
++
++              __aa_remove_profile(profile, replacement);
++              __aa_add_profile(common, replacement);
++      } else
++              __aa_remove_profile(profile, NULL);
 +}
 +
 +/**
-+ * aa_dfa_next_state_len - traverse @dfa to find state @str stops at
-+ * @dfa: the dfa to match @str against
-+ * @start: the state of the dfa to start matching in
-+ * @str: the string of bytes to match against the dfa
-+ * @len: length of the string of bytes to match
-+ *
-+ * aa_dfa_next_state will match @str against the dfa and return the state it
-+ * finished matching in. The final state can be used to look up the accepting
-+ * label, or as the start state of a continuing match.
-+ *
-+ * aa_dfa_next_state could be implement using this function by doing
-+ * return aa_dfa_next_state_len(dfa, start, str, strlen(str));
-+ * but that would require traversing the string twice and be slightly
-+ * slower.
++ * __aa_profile_list_release - remove all profiles on the list and put refs
++ * @head: list of profiles
 + */
-+unsigned int aa_dfa_next_state_len(struct aa_dfa *dfa, unsigned int start,
-+                                 const char *str, int len)
++void __aa_profile_list_release(struct list_head *head)
 +{
-+      u16 *def = DEFAULT_TABLE(dfa);
-+      u32 *base = BASE_TABLE(dfa);
-+      u16 *next = NEXT_TABLE(dfa);
-+      u16 *check = CHECK_TABLE(dfa);
-+      unsigned int state = start, pos;
++      struct aa_profile *profile, *tmp;
++      list_for_each_entry_safe(profile, tmp, head, base.list) {
++              __aa_profile_list_release(&profile->base.profiles);
++              __aa_remove_profile(profile, NULL);
++      }
++}
 +
-+      if (state == 0)
-+              return 0;
++void __aa_remove_namespace(struct aa_namespace *ns)
++{
++      struct aa_profile *unconfined = ns->unconfined;
++      list_del_init(&ns->base.list);
 +
-+      /* current state is <state>, matching character *str */
-+      if (dfa->tables[YYTD_ID_EC - 1]) {
-+              u8 *equiv = EQUIV_TABLE(dfa);
-+              for (; len; len--) {
-+                      pos = base[state] + equiv[(u8)*str++];
-+                      if (check[pos] == state)
-+                              state = next[pos];
-+                      else
-+                              state = def[state];
-+              }
-+      } else {
-+              for (; len; len--) {
-+                      pos = base[state] + (u8)*str++;
-+                      if (check[pos] == state)
-+                              state = next[pos];
-+                      else
-+                              state = def[state];
-+              }
-+      }
-+      return state;
++      /*
++       * break the ns, unconfined profile cyclic reference and forward
++       * all new unconfined profiles requests to the default namespace
++       */
++      ns->unconfined = aa_get_profile(default_namespace->unconfined);
++      __aa_profile_list_release(&ns->base.profiles);
++      aa_put_profile(unconfined);
++      aa_put_namespace(ns);
 +}
 +
 +/**
-+ * aa_dfa_next_state - traverse @dfa to find state @str stops at
-+ * @dfa: the dfa to match @str against
-+ * @start: the state of the dfa to start matching in
-+ * @str: the null terminated string of bytes to match against the dfa
-+ *
-+ * aa_dfa_next_state will match @str against the dfa and return the state it
-+ * finished matching in. The final state can be used to look up the accepting
-+ * label, or as the start state of a continuing match.
++ * aa_remove_namespace = Remove namespace from the list
++ * @ns: namespace to remove
 + */
-+unsigned int aa_dfa_next_state(struct aa_dfa *dfa, unsigned int start,
-+                             const char *str)
++void aa_remove_namespace(struct aa_namespace *ns)
 +{
-+      u16 *def = DEFAULT_TABLE(dfa);
-+      u32 *base = BASE_TABLE(dfa);
-+      u16 *next = NEXT_TABLE(dfa);
-+      u16 *check = CHECK_TABLE(dfa);
-+      unsigned int state = start, pos;
++      write_lock(&ns_list_lock);
++      write_lock(&ns->base.lock);
++      __aa_remove_namespace(ns);
++      write_unlock(&ns->base.lock);
++      write_unlock(&ns_list_lock);
++}
 +
-+      if (state == 0)
-+              return 0;
++/**
++ * aa_profilelist_release - remove all namespaces and all associated profiles
++ */
++void aa_profile_ns_list_release(void)
++{
++      struct aa_namespace *ns, *tmp;
 +
-+      /* current state is <state>, matching character *str */
-+      if (dfa->tables[YYTD_ID_EC - 1]) {
-+              u8 *equiv = EQUIV_TABLE(dfa);
-+              while (*str) {
-+                      pos = base[state] + equiv[(u8)*str++];
-+                      if (check[pos] == state)
-+                              state = next[pos];
-+                      else
-+                              state = def[state];
-+              }
-+      } else {
-+              while (*str) {
-+                      pos = base[state] + (u8)*str++;
-+                      if (check[pos] == state)
-+                              state = next[pos];
-+                      else
-+                              state = def[state];
-+              }
++      /* Remove and release all the profiles on namespace profile lists. */
++      write_lock(&ns_list_lock);
++      list_for_each_entry_safe(ns, tmp, &ns_list, base.list) {
++              write_lock(&ns->base.lock);
++              __aa_remove_namespace(ns);
++              write_unlock(&ns->base.lock);
 +      }
-+      return state;
++      write_unlock(&ns_list_lock);
 +}
 +
 +/**
-+ * aa_dfa_null_transition - step to next state after null character
-+ * @dfa: the dfa to match against
-+ * @start: the state of the dfa to start matching in
++ * alloc_aa_profile - allocate, initialize and return a new profile
++ * @fqname: name of the profile
 + *
-+ * aa_dfa_null_transition transitions to the next state after a null
-+ * character which is not used in standard matching and is only
-+ * used to seperate pairs.
++ * Returns NULL on failure.
 + */
-+unsigned int aa_dfa_null_transition(struct aa_dfa *dfa, unsigned int start)
++struct aa_profile *alloc_aa_profile(const char *fqname)
 +{
-+      return aa_dfa_next_state_len(dfa, start, "", 1);
++      struct aa_profile *profile;
++
++      profile = kzalloc(sizeof(*profile), GFP_KERNEL);
++      if (!profile)
++              return NULL;
++ 
++      if (!common_init(&profile->base, fqname)) {
++              kfree(profile);
++              return NULL;
++      }
++      
++      profile->fqname = profile->base.name;
++      profile->base.name = (char *) fqname_subname((const char *) profile->fqname);
++      return profile;
 +}
 +
 +/**
-+ * aa_dfa_match - find accept perm for @str in @dfa
-+ * @dfa: the dfa to match @str against
-+ * @str: the string to match against the dfa
-+ * @audit_mask: the audit_mask for the final state
++ * aa_new_null_profile - create a new null-X learning profile
++ * @parent: profile that caused this profile to be created
++ * @hat: true if the null- learning profile is a hat
++ *
++ * Create a null- complain mode profile used in learning mode.  The name of
++ * the profile is unique and follows the format of parent//null-sid.
 + *
-+ * aa_dfa_match will match @str and return the accept perms for the
-+ * final state.
++ * null profiles are added to the profile list but the list does not
++ * hold a count on them so that they are automatically released when
++ * not in use.
 + */
-+unsigned int aa_dfa_match(struct aa_dfa *dfa, const char *str, int *audit_mask)
++struct aa_profile *aa_alloc_null_profile(struct aa_profile *parent, int hat)
 +{
-+      int state = aa_dfa_next_state(dfa, DFA_START, str);
-+      if (audit_mask)
-+              *audit_mask = dfa_audit_mask(dfa, state);
-+      return ACCEPT_TABLE(dfa)[state];
++      struct aa_profile *profile = NULL;
++      char *name;
++      u32 sid = aa_alloc_sid(AA_ALLOC_SYS_SID);
++
++      name = kmalloc(strlen(parent->fqname) + 2 + 7 + 8, GFP_KERNEL);
++      if (!name)
++              goto fail;
++      sprintf(name, "%s//null-%x", parent->fqname, sid);
++
++      profile = alloc_aa_profile(name);
++      kfree(name);
++      if (!profile)
++              goto fail;
++
++      profile->sid = aa_alloc_sid(AA_ALLOC_SYS_SID);
++      profile->mode = APPARMOR_COMPLAIN;
++      profile->flags = PFLAG_NULL | PFLAG_NO_LIST_REF;
++      if (hat)
++        profile->flags |= PFLAG_HAT;
++
++      profile->parent = aa_get_profile(parent);
++      profile->ns = aa_get_namespace(parent->ns);
++
++      write_lock(&profile->ns->base.lock);
++      __aa_add_profile(&parent->base, profile);
++      write_unlock(&profile->ns->base.lock);
++
++      return profile;
++
++fail:
++      aa_free_sid(sid);
++      return NULL;
 +}
 +
 +/**
-+ * aa_match_state - find accept perm and state for @str in @dfa
-+ * @dfa: the dfa to match @str against
-+ * @start: the state to start the match from
-+ * @str: the string to match against the dfa
-+ * @final: the state that the match finished in
-+ *
-+ * aa_match_state will match @str and return the accept perms, and @final
-+ * state, the match occured in.
++ * free_aa_profile_kref - free aa_profile by kref (called by aa_put_profile)
++ * @kr: kref callback for freeing of a profile
 + */
-+unsigned int aa_match_state(struct aa_dfa *dfa, unsigned int start,
-+                          const char *str, unsigned int *final)
++void free_aa_profile_kref(struct kref *kref)
 +{
-+      unsigned int state;
-+      if (dfa) {
-+              state = aa_dfa_next_state(dfa, start, str);
-+              if (final)
-+                      *final = state;
-+              return ACCEPT_TABLE(dfa)[state];
-+      }
-+      if (final)
-+              *final = 0;
-+      return 0;
++      struct aa_profile *p = container_of(kref, struct aa_profile,
++                                          base.count);
++
++      free_aa_profile(p);
 +}
 +
-diff -uprN e/security/apparmor/match.h f/security/apparmor/match.h
---- e/security/apparmor/match.h        1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/match.h        2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,87 @@
-+/*
-+ *    Copyright (C) 2007 Novell/SUSE
++/**
++ * free_aa_profile - free a profile
++ * @profile: the profile to free
 + *
-+ *    This program is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU General Public License as
-+ *    published by the Free Software Foundation, version 2 of the
-+ *    License.
++ * Free a profile, its hats and null_profile. All references to the profile,
++ * its hats and null_profile must have been put.
 + *
-+ *    AppArmor submodule (match) prototypes
++ * If the profile was referenced from a task context, free_aa_profile() will
++ * be called from an rcu callback routine, so we must not sleep here.
 + */
++void free_aa_profile(struct aa_profile *profile)
++{
++      AA_DEBUG("%s(%p)\n", __func__, profile);
 +
-+#ifndef __MATCH_H
-+#define __MATCH_H
++      if (!profile)
++              return;
++
++      /*
++       * profile can still be on the list if the list doesn't hold a
++       * reference.  There is no race as NULL profiles can't be attached
++       */
++      if (!list_empty(&profile->base.list)) {
++              if ((profile->flags & PFLAG_NULL) && profile->ns) {
++                      write_lock(&profile->ns->base.lock);
++                      list_del_init(&profile->base.list);
++                      write_unlock(&profile->ns->base.lock);
++              } else {
++                      AA_ERROR("%s: internal error, "
++                               "profile '%s' still on ns list\n",
++                               __func__, profile->base.name);
++                      BUG();
++              }
++      }
++
++      /* profile->name is a substring of fqname */
++      profile->base.name = NULL;
++      common_free(&profile->base);
++
++      BUG_ON(!list_empty(&profile->base.profiles));
++
++      kfree(profile->fqname);
++
++      aa_put_namespace(profile->ns);
++      aa_put_profile(profile->parent);
++
++      aa_free_file_rules(&profile->file);
++      aa_free_cap_rules(&profile->caps);
++      aa_free_net_rules(&profile->net);
++      aa_free_rlimit_rules(&profile->rlimits);
++
++      aa_free_sid(profile->sid);
++      aa_match_free(profile->xmatch);
++
++      if (profile->replacedby && !PTR_ERR(profile->replacedby))
++              aa_put_profile(profile->replacedby);
++
++      memset(profile, 0, sizeof(profile));
++      kfree(profile);
++}
++
++
++/* TODO: profile count accounting - setup in remove */
++
++
++struct aa_profile *__aa_find_profile(struct list_head *head, const char *name)
++{
++      return (struct aa_profile *) __common_find(head, name);
++}
++
++struct aa_profile *__aa_find_profile_by_strn(struct list_head *head,
++                                           const char *name, int len)
++{
++      return (struct aa_profile *) __common_find_strn(head, name, len);
++}
 +
-+#define DFA_START                     1
 +
 +/**
-+ * The format used for transition tables is based on the GNU flex table
-+ * file format (--tables-file option; see Table File Format in the flex
-+ * info pages and the flex sources for documentation). The magic number
-+ * used in the header is 0x1B5E783D insted of 0xF13C57B1 though, because
-+ * the YY_ID_CHK (check) and YY_ID_DEF (default) tables are used
-+ * slightly differently (see the apparmor-parser package).
++ * aa_find_child - find a profile by @name in @parent
++ * @parent: profile to search
++ * @name: profile name to search for
++ *
++ * Returns a ref counted profile or NULL if not found
 + */
++struct aa_profile *aa_find_child(struct aa_profile *parent, const char *name)
++{
++      struct aa_profile *profile;
 +
-+#define YYTH_MAGIC    0x1B5E783D
++      read_lock(&parent->ns->base.lock);
++      profile = aa_get_profile(__aa_find_profile(&parent->base.profiles,
++                                                 name));
++      read_unlock(&parent->ns->base.lock);
 +
-+struct table_set_header {
-+      u32             th_magic;       /* YYTH_MAGIC */
-+      u32             th_hsize;
-+      u32             th_ssize;
-+      u16             th_flags;
-+      char            th_version[];
-+};
++      return profile;
++}
 +
-+#define       YYTD_ID_ACCEPT  1
-+#define YYTD_ID_BASE  2
-+#define YYTD_ID_CHK   3
-+#define YYTD_ID_DEF   4
-+#define YYTD_ID_EC    5
-+#define YYTD_ID_META  6
-+#define YYTD_ID_ACCEPT2 7
-+#define YYTD_ID_NXT   8
 +
++struct aa_policy_common *__aa_find_parent_by_fqname(struct aa_namespace *ns,
++                                                  const char *fqname)
++{
++      struct aa_policy_common *common;
++      struct aa_profile *profile = NULL;
++      char *split;
++
++      common = &ns->base;
++
++      
++      for (split = strstr(fqname, "//"); split; ) {
++              profile = __aa_find_profile_by_strn(&common->profiles, fqname,
++                                                  split - fqname);
++              if (!profile)
++                      return NULL;
++              common = &profile->base;
++              fqname = split + 2;
++              split = strstr(fqname, "//");
++      }
++      if (!profile)
++              return &ns->base;
++      return &profile->base;
++}
++
++struct aa_profile *__aa_find_profile_by_fqname(struct aa_namespace *ns,
++                                             const char *fqname)
++{
++      struct aa_policy_common *common;
++      struct aa_profile *profile = NULL;
++      char *split;
++
++      common = &ns->base;
++      for (split = strstr(fqname, "//"); split; ) {
++              profile = __aa_find_profile_by_strn(&common->profiles, fqname,
++                                                  split - fqname);
++              if (!profile)
++                      return NULL;
++
++              common = &profile->base;
++              fqname = split + 2;
++              split = strstr(fqname, "//");
++      }
++
++      profile = __aa_find_profile(&common->profiles, fqname);
 +
-+#define YYTD_DATA8    1
-+#define YYTD_DATA16   2
-+#define YYTD_DATA32   4
++      return profile;
++}
 +
-+struct table_header {
-+      u16             td_id;
-+      u16             td_flags;
-+      u32             td_hilen;
-+      u32             td_lolen;
-+      char            td_data[];
-+};
++/**
++ * aa_find_profile_by_name - find a profile by its full or partial name
++ * @ns: the namespace to start from
++ * @fqname: name to do lookup on.  Does not contain namespace prefix
++ */
++struct aa_profile *aa_find_profile_by_fqname(struct aa_namespace *ns,
++                                           const char *fqname)
++{
++      struct aa_profile *profile;
 +
-+#define DEFAULT_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_DEF - 1]->td_data))
-+#define BASE_TABLE(DFA) ((u32 *)((DFA)->tables[YYTD_ID_BASE - 1]->td_data))
-+#define NEXT_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_NXT - 1]->td_data))
-+#define CHECK_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_CHK - 1]->td_data))
-+#define EQUIV_TABLE(DFA) ((u8 *)((DFA)->tables[YYTD_ID_EC - 1]->td_data))
-+#define ACCEPT_TABLE(DFA) ((u32 *)((DFA)->tables[YYTD_ID_ACCEPT - 1]->td_data))
-+#define ACCEPT_TABLE2(DFA) ((u32 *)((DFA)->tables[YYTD_ID_ACCEPT2 -1]->td_data))
++      read_lock(&ns->base.lock);
++      profile = aa_get_profile(__aa_find_profile_by_fqname(ns, fqname));
++      read_unlock(&ns->base.lock);
++      return profile;
++}
 +
-+struct aa_dfa {
-+      struct table_header *tables[YYTD_ID_NXT];
-+};
 +
-+#define byte_to_byte(X) (X)
++/* __aa_attach_match_ - find an attachment match
++ * @name - to match against
++ * @head - profile list to walk
++ *
++ * Do a linear search on the profiles in the list.  There is a matching
++ * preference where an exact match is prefered over a name which uses
++ * expressions to match, and matching expressions with the greatest
++ * xmatch_len are prefered.
++ */
++static struct aa_profile *__aa_attach_match(const char *name,
++                                          struct list_head *head)
++{
++      int len = 0;
++      struct aa_profile *profile, *candidate = NULL;
 +
-+#define UNPACK_ARRAY(TABLE, BLOB, LEN, TYPE, NTOHX) \
-+      do { \
-+              typeof(LEN) __i; \
-+              TYPE *__t = (TYPE *) TABLE; \
-+              TYPE *__b = (TYPE *) BLOB; \
-+              for (__i = 0; __i < LEN; __i++) { \
-+                      __t[__i] = NTOHX(__b[__i]); \
-+              } \
-+      } while (0)
++      list_for_each_entry(profile, head, base.list) {
++              if (profile->flags & PFLAG_NULL)
++                      continue;
++              if (profile->xmatch && profile->xmatch_len > len) {
++                      unsigned int state = aa_dfa_match(profile->xmatch,
++                                                        DFA_START, name);
++                      /* any accepting state means a valid match */
++                      if (state > DFA_START) {
++                              candidate = profile;
++                              len = profile->xmatch_len;
++                      }
++              } else if (!strcmp(profile->base.name, name))
++                      /* exact non-re match, no more searching required */
++                      return profile;
++      }
 +
-+static inline size_t table_size(size_t len, size_t el_size)
++      return candidate;
++}
++
++/**
++ * aa_sys_find_attach - do attachment search for sys unconfined processes
++ * @ns: the namespace to search
++ * name: the executable name to match against
++ */
++struct aa_profile *aa_sys_find_attach(struct aa_namespace *ns, const char *name)
 +{
-+      return ALIGN(sizeof(struct table_header) + len * el_size, 8);
++      struct aa_profile *profile;
++
++      read_lock(&ns->base.lock);
++      profile = aa_get_profile(__aa_attach_match(name, &ns->base.profiles));
++      read_unlock(&ns->base.lock);
++
++      return profile;
++}
++
++/**
++ * aa_profile_newest - find the newest version of @profile
++ * @profile: the profile to check for newer versions of
++ *
++ * Find the newest version of @profile, if @profile is the newest version
++ * return @profile.  If @profile has been removed return NULL.
++ *
++ * NOTE: the profile returned is not refcounted, The refcount on @profile
++ * must be held until the caller decides what to do with the returned newest
++ * version.
++ */
++struct aa_profile *aa_profile_newest(struct aa_profile *profile)
++{
++      if (unlikely(profile && profile->replacedby)) {
++              for (;profile->replacedby; profile = profile->replacedby) {
++                      if (IS_ERR(profile->replacedby)) {
++                              /* profile has been removed */
++                              profile = NULL;
++                              break;
++                      }
++              } 
++      }
++
++      return profile;
 +}
 +
-+#endif /* __MATCH_H */
-diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_interface.c
---- e/security/apparmor/module_interface.c     1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/module_interface.c     2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,966 @@
+diff --git a/security/apparmor/policy_interface.c b/security/apparmor/policy_interface.c
+new file mode 100644
+index 0000000..24277dc
+--- /dev/null
++++ b/security/apparmor/policy_interface.c
+@@ -0,0 +1,850 @@
 +/*
-+ *    Copyright (C) 1998-2007 Novell/SUSE
++ * AppArmor security module
++ *
++ * This file contains AppArmor functions for unpacking policy loaded from
++ * userspace.
 + *
-+ *    This program is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU General Public License as
-+ *    published by the Free Software Foundation, version 2 of the
-+ *    License.
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
 + *
-+ *    AppArmor userspace policy interface
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ *
++ * AppArmor uses a serialized binary format for loading policy.
++ * The policy format is documented in Documentation/???
++ * All policy is validated all before it is used.
 + */
 +
 +#include <asm/unaligned.h>
++#include <linux/errno.h>
 +
-+#include "apparmor.h"
-+#include "inline.h"
-+
-+/*
-+ * This mutex is used to synchronize profile adds, replacements, and
-+ * removals: we only allow one of these operations at a time.
-+ * We do not use the profile list lock here in order to avoid blocking
-+ * exec during those operations.  (Exec involves a profile list lookup
-+ * for named-profile transitions.)
++#include "include/apparmor.h"
++#include "include/audit.h"
++#include "include/context.h"
++#include "include/match.h"
++#include "include/policy.h"
++#include "include/policy_interface.h"
++#include "include/sid.h"
++
++/* FIXME: convert profiles to internal hieracy, accounting
++ * FIXME: have replacement routines set replaced_by profile instead of error
++ * FIXME: name mapping to hierarchy
 + */
-+DEFINE_MUTEX(aa_interface_lock);
 +
 +/*
 + * The AppArmor interface treats data as a type byte followed by the
@@ -7370,7 +6238,47 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +      char *ns_name;
 +};
 +
-+static inline int aa_inbounds(struct aa_ext *e, size_t size)
++
++struct aa_audit_iface {
++      struct aa_audit base;
++
++      const char *name;
++      const char *name2;
++      const struct aa_ext *e;
++};
++
++static void aa_audit_init(struct aa_audit_iface *sa, const char *operation,
++                        struct aa_ext *e)
++{
++      memset(sa, 0, sizeof(*sa));
++      sa->base.operation = operation;
++      sa->base.gfp_mask = GFP_KERNEL;
++      sa->e = e;
++}
++
++static void audit_cb(struct audit_buffer *ab, void *va)
++{
++      struct aa_audit_iface *sa = va;
++
++      if (sa->name)
++              audit_log_format(ab, " name=%s", sa->name);
++      if (sa->name2)
++              audit_log_format(ab, " namespace=%s", sa->name2);
++      if (sa->base.error && sa->e)
++              audit_log_format(ab, " offset=%d", sa->e->pos - sa->e->start);
++}
++
++static int aa_audit_iface(struct aa_audit_iface *sa)
++{
++      struct aa_profile *profile;
++      struct cred *cred = aa_get_task_policy(current, &profile);
++      int error = aa_audit(AUDIT_APPARMOR_STATUS, profile, &sa->base,
++                           audit_cb);
++      put_cred(cred);
++      return error;
++}
++
++static int aa_inbounds(struct aa_ext *e, size_t size)
 +{
 +      return (size <= e->end - e->pos);
 +}
@@ -7403,7 +6311,7 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +      return 0;
 +}
 +
-+static inline int aa_is_X(struct aa_ext *e, enum aa_code code)
++static int aa_is_X(struct aa_ext *e, enum aa_code code)
 +{
 +      if (!aa_inbounds(e, 1))
 +              return 0;
@@ -7435,7 +6343,7 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +       * AA_NAME tag value is a u16.
 +       */
 +      if (aa_is_X(e, AA_NAME)) {
-+              char *tag;
++              char *tag = NULL;
 +              size_t size = aa_is_u16_chunk(e, &tag);
 +              /* if a name is specified it must match. otherwise skip tag */
 +              if (name && (!size || strcmp(name, tag)))
@@ -7528,7 +6436,7 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +              size = le32_to_cpu(get_unaligned((u32 *)e->pos));
 +              e->pos += sizeof(u32);
 +              if (aa_inbounds(e, (size_t) size)) {
-+                      * blob = e->pos;
++                      *blob = e->pos;
 +                      e->pos += size;
 +                      return size;
 +              }
@@ -7538,7 +6446,7 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +      return 0;
 +}
 +
-+static int aa_is_dynstring(struct aa_ext *e, char **string, const char *name)
++static int aa_is_string(struct aa_ext *e, char **string, const char *name)
 +{
 +      char *src_str;
 +      size_t size = 0;
@@ -7546,11 +6454,10 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +      *string = NULL;
 +      if (aa_is_nameX(e, AA_STRING, name) &&
 +          (size = aa_is_u16_chunk(e, &src_str))) {
-+              char *str;
-+              if (!(str = kmalloc(size, GFP_KERNEL)))
++              /* strings are null terminated, length is size - 1 */
++              if (src_str[size - 1] != 0)
 +                      goto fail;
-+              memcpy(str, src_str, size);
-+              *string = str;
++              *string = src_str;
 +      }
 +
 +      return size;
@@ -7560,6 +6467,25 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +      return 0;
 +}
 +
++static int aa_is_dynstring(struct aa_ext *e, char **string, const char *name)
++{
++      char *tmp;
++      void *pos = e->pos;
++      int res = aa_is_string(e, &tmp, name);
++      *string = NULL;
++
++      if (!res)
++              return res;
++
++      *string = kstrdup(tmp, GFP_KERNEL);
++      if (!*string) {
++              e->pos = pos;
++              return 0;
++      }
++
++      return res;
++}
++
 +/**
 + * aa_unpack_dfa - unpack a file rule dfa
 + * @e: serialized data extent information
@@ -7598,7 +6524,7 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +      return dfa;
 +}
 +
-+static int aa_unpack_exec_table(struct aa_ext *e, struct aa_profile *profile)
++static int aa_unpack_trans_table(struct aa_ext *e, struct aa_profile *profile)
 +{
 +      void *pos = e->pos;
 +
@@ -7610,9 +6536,9 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +              /* currently 4 exec bits and entries 0-3 are reserved iupcx */
 +              if (size > 16 - 4)
 +                      goto fail;
-+              profile->exec_table = kzalloc(sizeof(char *) * size,
-+                                            GFP_KERNEL);
-+              if (!profile->exec_table)
++              profile->file.trans.table = kzalloc(sizeof(char *) * size,
++                                                        GFP_KERNEL);
++              if (!profile->file.trans.table)
 +                      goto fail;
 +
 +              for (i = 0; i < size; i++) {
@@ -7622,12 +6548,13 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +                      /* note: strings beginning with a : have an embedded
 +                         \0 seperating the profile ns name from the profile
 +                         name */
-+                      profile->exec_table[i] = tmp;
++                      profile->file.trans.table[i] = tmp;
 +              }
 +              if (!aa_is_nameX(e, AA_ARRAYEND, NULL))
 +                      goto fail;
 +              if (!aa_is_nameX(e, AA_STRUCTEND, NULL))
 +                      goto fail;
++              profile->file.trans.size = size;
 +      }
 +      return 1;
 +
@@ -7675,52 +6602,73 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 + * @sa: audit struct for the operation
 + */
 +static struct aa_profile *aa_unpack_profile(struct aa_ext *e,
-+                                          struct aa_audit *sa)
++                                          struct aa_audit_iface *sa)
 +{
 +      struct aa_profile *profile = NULL;
++      char *name;
 +      size_t size = 0;
 +      int i, error = -EPROTO;
++      u32 tmp;
++
++      /* check that we have the right struct being passed */
++      if (!aa_is_nameX(e, AA_STRUCT, "profile"))
++              goto fail;
++      if (!aa_is_string(e, &name, NULL))
++              goto fail;
 +
-+      profile = alloc_aa_profile();
++      profile = alloc_aa_profile(name);
 +      if (!profile)
 +              return ERR_PTR(-ENOMEM);
 +
-+      /* check that we have the right struct being passed */
-+      if (!aa_is_nameX(e, AA_STRUCT, "profile"))
++      /* xmatch is optional and may be NULL */
++      profile->xmatch = aa_unpack_dfa(e);
++      if (IS_ERR(profile->xmatch)) {
++              error = PTR_ERR(profile->xmatch);
++              profile->xmatch = NULL;
 +              goto fail;
-+      if (!aa_is_dynstring(e, &profile->name, NULL))
++      }
++      /* xmatch_len is not optional is xmatch is set */
++      if (profile->xmatch && !aa_is_u32(e, &tmp, NULL))
 +              goto fail;
++      profile->xmatch_len = tmp;
 +
 +      /* per profile debug flags (complain, audit) */
 +      if (!aa_is_nameX(e, AA_STRUCT, "flags"))
 +              goto fail;
-+      if (!aa_is_u32(e, &(profile->flags.hat), NULL))
++      if (!aa_is_u32(e, &tmp, NULL))
 +              goto fail;
-+      if (!aa_is_u32(e, &(profile->flags.complain), NULL))
++      if (tmp)
++              profile->flags |= PFLAG_HAT;
++      if (!aa_is_u32(e, &tmp, NULL))
 +              goto fail;
-+      if (!aa_is_u32(e, &(profile->flags.audit), NULL))
++      if (tmp)
++              profile->mode = APPARMOR_COMPLAIN;
++      if (!aa_is_u32(e, &tmp, NULL))
 +              goto fail;
++      if (tmp)
++              profile->audit = AUDIT_ALL;
++
 +      if (!aa_is_nameX(e, AA_STRUCTEND, NULL))
 +              goto fail;
 +
-+      if (!aa_is_u32(e, &(profile->capabilities.cap[0]), NULL))
++      if (!aa_is_u32(e, &(profile->caps.allowed.cap[0]), NULL))
 +              goto fail;
-+      if (!aa_is_u32(e, &(profile->audit_caps.cap[0]), NULL))
++      if (!aa_is_u32(e, &(profile->caps.audit.cap[0]), NULL))
 +              goto fail;
-+      if (!aa_is_u32(e, &(profile->quiet_caps.cap[0]), NULL))
++      if (!aa_is_u32(e, &(profile->caps.quiet.cap[0]), NULL))
 +              goto fail;
-+      if (!aa_is_u32(e, &(profile->set_caps.cap[0]), NULL))
++      if (!aa_is_u32(e, &(profile->caps.set.cap[0]), NULL))
 +              goto fail;
 +
 +      if (aa_is_nameX(e, AA_STRUCT, "caps64")) {
 +              /* optional upper half of 64 bit caps */
-+              if (!aa_is_u32(e, &(profile->capabilities.cap[1]), NULL))
++              if (!aa_is_u32(e, &(profile->caps.allowed.cap[1]), NULL))
 +                      goto fail;
-+              if (!aa_is_u32(e, &(profile->audit_caps.cap[1]), NULL))
++              if (!aa_is_u32(e, &(profile->caps.audit.cap[1]), NULL))
 +                      goto fail;
-+              if (!aa_is_u32(e, &(profile->quiet_caps.cap[1]), NULL))
++              if (!aa_is_u32(e, &(profile->caps.quiet.cap[1]), NULL))
 +                      goto fail;
-+              if (!aa_is_u32(e, &(profile->set_caps.cap[1]), NULL))
++              if (!aa_is_u32(e, &(profile->caps.set.cap[1]), NULL))
 +                      goto fail;
 +              if (!aa_is_nameX(e, AA_STRUCTEND, NULL))
 +                      goto fail;
@@ -7735,11 +6683,11 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +                      goto fail;
 +
 +              for (i = 0; i < size; i++) {
-+                      if (!aa_is_u16(e, &profile->network_families[i], NULL))
++                      if (!aa_is_u16(e, &profile->net.allowed[i], NULL))
 +                              goto fail;
-+                      if (!aa_is_u16(e, &profile->audit_network[i], NULL))
++                      if (!aa_is_u16(e, &profile->net.audit[i], NULL))
 +                              goto fail;
-+                      if (!aa_is_u16(e, &profile->quiet_network[i], NULL))
++                      if (!aa_is_u16(e, &profile->net.quiet[i], NULL))
 +                              goto fail;
 +              }
 +              if (!aa_is_nameX(e, AA_ARRAYEND, NULL))
@@ -7748,18 +6696,18 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +               * by IPC
 +               */
 +      }
-+      profile->network_families[AF_UNIX] = 0xffff;
-+      profile->network_families[AF_NETLINK] = 0xffff;
++      profile->net.allowed[AF_UNIX] = 0xffff;
++      profile->net.allowed[AF_NETLINK] = 0xffff;
 +
 +      /* get file rules */
-+      profile->file_rules = aa_unpack_dfa(e);
-+      if (IS_ERR(profile->file_rules)) {
-+              error = PTR_ERR(profile->file_rules);
-+              profile->file_rules = NULL;
++      profile->file.dfa = aa_unpack_dfa(e);
++      if (IS_ERR(profile->file.dfa)) {
++              error = PTR_ERR(profile->file.dfa);
++              profile->file.dfa = NULL;
 +              goto fail;
 +      }
 +
-+      if (!aa_unpack_exec_table(e, profile))
++      if (!aa_unpack_trans_table(e, profile))
 +              goto fail;
 +
 +      if (!aa_is_nameX(e, AA_STRUCTEND, NULL))
@@ -7768,13 +6716,13 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +      return profile;
 +
 +fail:
-+      sa->name = profile && profile->name ? profile->name : "unknown";
-+      if (!sa->info)
-+              sa->info = "failed to unpack profile";
-+      aa_audit_status(NULL, sa);
++      sa->name = profile && profile->base.name ? profile->base.name :
++                                                 "unknown";
++      if (!sa->base.info)
++              sa->base.info = "failed to unpack profile";
++      aa_audit_iface(sa);
 +
-+      if (profile)
-+              free_aa_profile(profile);
++      free_aa_profile(profile);
 +
 +      return ERR_PTR(error);
 +}
@@ -7786,39 +6734,41 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 + *
 + * returns error or 0 if header is good
 + */
-+static int aa_verify_header(struct aa_ext *e, struct aa_audit *sa)
++static int aa_verify_header(struct aa_ext *e, struct aa_audit_iface *sa)
 +{
 +      /* get the interface version */
 +      if (!aa_is_u32(e, &e->version, "version")) {
-+              sa->info = "invalid profile format";
-+              aa_audit_status(NULL, sa);
++              sa->base.info = "invalid profile format";
++              aa_audit_iface(sa);
 +              return -EPROTONOSUPPORT;
 +      }
 +
 +      /* check that the interface version is currently supported */
 +      if (e->version != 5) {
-+              sa->info = "unsupported interface version";
-+              aa_audit_status(NULL, sa);
++              sa->base.info = "unsupported interface version";
++              aa_audit_iface(sa);
 +              return -EPROTONOSUPPORT;
 +      }
 +
 +      /* read the namespace if present */
-+      if (!aa_is_dynstring(e, &e->ns_name, "namespace")) {
++      if (!aa_is_string(e, &e->ns_name, "namespace"))
 +              e->ns_name = NULL;
-+      }
 +
 +      return 0;
 +}
 +
++
++
 +/**
-+ * aa_add_profile - Unpack and add a new profile to the profile list
++ * aa_interface_add_profiles - Unpack and add new profile(s) to the profile list
 + * @data: serialized data stream
 + * @size: size of the serialized data stream
 + */
-+ssize_t aa_add_profile(void *data, size_t size)
++ssize_t aa_interface_add_profiles(void *data, size_t size)
 +{
-+      struct aa_profile *profile = NULL;
++      struct aa_profile *profile;
 +      struct aa_namespace *ns = NULL;
++      struct aa_policy_common *common;
 +      struct aa_ext e = {
 +              .start = data,
 +              .end = data + size,
@@ -7826,10 +6776,8 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +              .ns_name = NULL
 +      };
 +      ssize_t error;
-+      struct aa_audit sa;
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "profile_load";
-+      sa.gfp_mask = GFP_KERNEL;
++      struct aa_audit_iface sa;
++      aa_audit_init(&sa, "profile_load", &e);
 +
 +      error = aa_verify_header(&e, &sa);
 +      if (error)
@@ -7839,79 +6787,58 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +      if (IS_ERR(profile))
 +              return PTR_ERR(profile);
 +
-+      mutex_lock(&aa_interface_lock);
-+      write_lock(&profile_ns_list_lock);
-+      if (e.ns_name)
-+              ns = __aa_find_namespace(e.ns_name, &profile_ns_list);
-+      else
-+              ns = default_namespace;
-+      if (!ns) {
-+              struct aa_namespace *new_ns;
-+              write_unlock(&profile_ns_list_lock);
-+              new_ns = alloc_aa_namespace(e.ns_name);
-+              if (!new_ns) {
-+                      mutex_unlock(&aa_interface_lock);
-+                      return -ENOMEM;
-+              }
-+              write_lock(&profile_ns_list_lock);
-+              ns = __aa_find_namespace(e.ns_name, &profile_ns_list);
-+              if (!ns) {
-+                      list_add(&new_ns->list, &profile_ns_list);
-+                      ns = new_ns;
-+              } else
-+                      free_aa_namespace(new_ns);
++      sa.name2 = e.ns_name;
++      ns = aa_prepare_namespace(e.ns_name);
++      if (IS_ERR(ns)) {
++              sa.base.info = "failed to prepare namespace";
++              sa.base.error = PTR_ERR(ns);
++              goto fail;
++      }
++      /* profiles are currently loaded flat with fqnames */
++      sa.name = profile->fqname;
++
++      write_lock(&ns->base.lock);
++
++      common = __aa_find_parent_by_fqname(ns, sa.name);
++      if (!common) {
++              sa.base.info = "parent does not exist";
++              sa.base.error = -ENOENT;
++              goto fail2;
 +      }
 +
-+      write_lock(&ns->lock);
-+      if (__aa_find_profile(profile->name, &ns->profiles)) {
++      if (common != &ns->base)
++              profile->parent = aa_get_profile((struct aa_profile *) common);
++
++      if (__aa_find_profile(&common->profiles, profile->base.name)) {
 +              /* A profile with this name exists already. */
-+              write_unlock(&ns->lock);
-+              write_unlock(&profile_ns_list_lock);
-+              sa.name = profile->name;
-+              sa.name2 = ns->name;
-+              sa.info = "failed: profile already loaded";
-+              aa_audit_status(NULL, &sa);
-+              mutex_unlock(&aa_interface_lock);
-+              aa_put_profile(profile);
-+              return -EEXIST;
++              sa.base.info = "profile already exists";
++              goto fail2;
 +      }
++      profile->sid = aa_alloc_sid(AA_ALLOC_SYS_SID);
 +      profile->ns = aa_get_namespace(ns);
-+      ns->profile_count++;
-+      list_add(&profile->list, &ns->profiles);
-+      write_unlock(&ns->lock);
-+      write_unlock(&profile_ns_list_lock);
-+
-+      sa.name = profile->name;
-+      sa.name2 = ns->name;
-+      aa_audit_status(NULL, &sa);
-+      mutex_unlock(&aa_interface_lock);
-+      return size;
-+}
 +
-+/**
-+ * task_replace - replace a task's profile
-+ * @task: task to replace profile on
-+ * @new_cxt: new aa_task_context to do replacement with
-+ * @new_profile: new profile
-+ */
-+static inline void task_replace(struct task_struct *task,
-+                              struct aa_task_context *new_cxt,
-+                              struct aa_profile *new_profile)
-+{
-+      struct aa_task_context *cxt = aa_task_context(task);
++      __aa_add_profile(common, profile);
++      write_unlock(&ns->base.lock);
++
++      aa_audit_iface(&sa);
++      aa_put_namespace(ns);
++      kfree(e.ns_name);
++      return size;
 +
-+      AA_DEBUG("%s: replacing profile for task %d "
-+               "profile=%s (%p)\n",
-+               __FUNCTION__,
-+               cxt->task->pid,
-+               cxt->profile->name, cxt->profile);
++fail2:
++      write_unlock(&ns->base.lock);
++      sa.base.error = -EEXIST;
 +
-+      aa_change_task_context(task, new_cxt, new_profile, cxt->cookie,
-+                             cxt->previous_profile);
++fail:
++      error = aa_audit_iface(&sa);
++      aa_put_namespace(ns);
++      aa_put_profile(profile);
++      kfree(e.ns_name);
++      return error;
 +}
 +
 +/**
-+ * aa_replace_profile - replace a profile on the profile list
++ * aa_interface_replace_profiles - replace profile(s) on the profile list
 + * @udata: serialized data stream
 + * @size: size of the serialized data stream
 + *
@@ -7919,11 +6846,11 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 + * by any aa_task_context.  If the profile does not exist on the profile list
 + * it is added.  Return %0 or error.
 + */
-+ssize_t aa_replace_profile(void *udata, size_t size)
++ssize_t aa_interface_replace_profiles(void *udata, size_t size)
 +{
-+      struct aa_profile *old_profile, *new_profile;
++      struct aa_policy_common *common;
++      struct aa_profile *old_profile = NULL, *new_profile;
 +      struct aa_namespace *ns;
-+      struct aa_task_context *new_cxt;
 +      struct aa_ext e = {
 +              .start = udata,
 +              .end = udata + size,
@@ -7931,10 +6858,11 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +              .ns_name = NULL
 +      };
 +      ssize_t error;
-+      struct aa_audit sa;
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "profile_replace";
-+      sa.gfp_mask = GFP_KERNEL;
++      struct aa_audit_iface sa;
++      aa_audit_init(&sa, "profile_replace", &e);
++
++      if (g_apparmor_lock_policy)
++              return -EACCES;
 +
 +      error = aa_verify_header(&e, &sa);
 +      if (error)
@@ -7944,403 +6872,227 @@ diff -uprN e/security/apparmor/module_interface.c f/security/apparmor/module_int
 +      if (IS_ERR(new_profile))
 +              return PTR_ERR(new_profile);
 +
-+      mutex_lock(&aa_interface_lock);
-+      write_lock(&profile_ns_list_lock);
-+      if (e.ns_name)
-+              ns = __aa_find_namespace(e.ns_name, &profile_ns_list);
-+      else
-+              ns = default_namespace;
++      sa.name2 = e.ns_name;
++      ns = aa_prepare_namespace(e.ns_name);
 +      if (!ns) {
-+              struct aa_namespace *new_ns;
-+              write_unlock(&profile_ns_list_lock);
-+              new_ns = alloc_aa_namespace(e.ns_name);
-+              if (!new_ns) {
-+                      mutex_unlock(&aa_interface_lock);
-+                      return -ENOMEM;
-+              }
-+              write_lock(&profile_ns_list_lock);
-+              ns = __aa_find_namespace(e.ns_name, &profile_ns_list);
-+              if (!ns) {
-+                      list_add(&new_ns->list, &profile_ns_list);
-+                      ns = new_ns;
-+              } else
-+                      free_aa_namespace(new_ns);
-+      }
-+
-+      write_lock(&ns->lock);
-+      old_profile = __aa_find_profile(new_profile->name, &ns->profiles);
-+      if (old_profile) {
-+              lock_profile(old_profile);
-+              old_profile->isstale = 1;
-+              list_del_init(&old_profile->list);
-+              unlock_profile(old_profile);
-+              ns->profile_count--;
-+      }
-+      new_profile->ns = aa_get_namespace(ns);
-+      ns->profile_count++;
-+      /* not don't need an extra ref count to keep new_profile as
-+       * it is protect by the interface mutex */
-+      list_add(&new_profile->list, &ns->profiles);
-+      write_unlock(&ns->lock);
-+      write_unlock(&profile_ns_list_lock);
-+
-+      if (!old_profile) {
-+              sa.operation = "profile_load";
-+              goto out;
-+      }
-+      /* do not fail replacement based off of profile's NPROC rlimit */
-+
-+      /*
-+       * Replacement needs to allocate a new aa_task_context for each
-+       * task confined by old_profile.  To do this the profile locks
-+       * are only held when the actual switch is done per task.  While
-+       * looping to allocate a new aa_task_context the old_task list
-+       * may get shorter if tasks exit/change their profile but will
-+       * not get longer as new task will not use old_profile detecting
-+       * that is stale.
-+       */
-+      do {
-+              new_cxt = aa_alloc_task_context(GFP_KERNEL | __GFP_NOFAIL);
-+
-+              lock_both_profiles(old_profile, new_profile);
-+              if (!list_empty(&old_profile->task_contexts)) {
-+                      struct task_struct *task =
-+                              list_entry(old_profile->task_contexts.next,
-+                                         struct aa_task_context, list)->task;
-+                      task_lock(task);
-+                      task_replace(task, new_cxt, new_profile);
-+                      task_unlock(task);
-+                      aa_set_rlimits(task, new_profile);
-+                      new_cxt = NULL;
++              sa.base.info = "failed to prepare namespace";
++              sa.base.error = -ENOMEM;
++              goto fail;
++      }               
++
++      sa.name = new_profile->fqname;
++
++      write_lock(&ns->base.lock);
++      common = __aa_find_parent_by_fqname(ns, sa.name);
++
++      if (!common) {
++              sa.base.info = "parent does not exist";
++              sa.base.error = -ENOENT;
++              goto fail2;
++      }
++
++      if (common != &ns->base)
++              new_profile->parent = aa_get_profile((struct aa_profile *)
++                                                   common);
++
++      old_profile = __aa_find_profile(&common->profiles,
++                                      new_profile->base.name);
++      aa_get_profile(old_profile);
++      if (old_profile && old_profile->flags & PFLAG_IMMUTABLE) {
++              sa.base.info = "cannot replace immutible profile";
++              sa.base.error = -EPERM;
++              goto fail2;
++      } else  if (old_profile) {
++        //            __aa_profile_list_release(&old_profile->base.profiles);
++              /* TODO: remove for new interface
++               * move children profiles over to the new profile so
++               * that replacement behaves correctly
++               */
++        //            list_replace_init(&old_profile->base.profiles,
++        //                              &new_profile->base.profiles);
++        struct aa_profile *profile, *tmp;
++        list_for_each_entry_safe(profile, tmp, &old_profile->base.profiles,
++                                  base.list) {
++                      aa_put_profile(profile->parent);
++                      list_del(&profile->base.list);
++                      profile->parent = aa_get_profile(new_profile);
++                      list_add(&profile->base.list,
++                               &new_profile->base.profiles);
 +              }
-+              unlock_both_profiles(old_profile, new_profile);
-+      } while (!new_cxt);
-+      aa_free_task_context(new_cxt);
-+      aa_put_profile(old_profile);
-+
-+out:
-+      sa.name = new_profile->name;
-+      sa.name2 = ns->name;
-+      aa_audit_status(NULL, &sa);
-+      mutex_unlock(&aa_interface_lock);
-+      return size;
-+}
-+
-+/**
-+ * aa_remove_profile - remove a profile from the system
-+ * @name: name of the profile to remove
-+ * @size: size of the name
-+ *
-+ * remove a profile from the profile list and all aa_task_context references
-+ * to said profile.
-+ * NOTE: removing confinement does not restore rlimits to preconfinemnet values
-+ */
-+ssize_t aa_remove_profile(char *name, size_t size)
-+{
-+      struct aa_namespace *ns;
-+      struct aa_profile *profile;
-+      struct aa_audit sa;
-+      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "profile_remove";
-+      sa.gfp_mask = GFP_KERNEL;
-+
-+      mutex_lock(&aa_interface_lock);
-+      write_lock(&profile_ns_list_lock);
-+
-+      if (name[0] == ':') {
-+              char *split = strchr(name + 1, ':');
-+              if (!split)
-+                      goto noent;
-+              *split = 0;
-+              ns = __aa_find_namespace(name + 1, &profile_ns_list);
-+              name = split + 1;
++              __aa_replace_profile(old_profile, new_profile);
++              new_profile->sid = old_profile->sid;
 +      } else {
-+              ns = default_namespace;
-+      }
-+
-+      if (!ns)
-+              goto noent;
-+      sa.name2 = ns->name;
-+      write_lock(&ns->lock);
-+      profile = __aa_find_profile(name, &ns->profiles);
-+      if (!profile) {
-+              write_unlock(&ns->lock);
-+              goto noent;
-+      }
-+      sa.name = profile->name;
-+
-+      /* Remove the profile from each task context it is on. */
-+      lock_profile(profile);
-+      profile->isstale = 1;
-+      aa_unconfine_tasks(profile);
-+      list_del_init(&profile->list);
-+      ns->profile_count--;
-+      unlock_profile(profile);
-+      /* Release the profile itself. */
-+      write_unlock(&ns->lock);
-+      /* check to see if the namespace has become stale */
-+      if (ns != default_namespace && ns->profile_count == 0) {
-+              list_del_init(&ns->list);
-+              aa_put_namespace(ns);
-+      }
-+      write_unlock(&profile_ns_list_lock);
-+
-+      aa_audit_status(NULL, &sa);
-+      mutex_unlock(&aa_interface_lock);
-+      aa_put_profile(profile);
-+
-+      return size;
-+
-+noent:
-+      write_unlock(&profile_ns_list_lock);
-+      sa.info = "failed: profile does not exist";
-+      aa_audit_status(NULL, &sa);
-+      mutex_unlock(&aa_interface_lock);
-+      return -ENOENT;
-+}
-+
-+/**
-+ * free_aa_namespace_kref - free aa_namespace by kref (see aa_put_namespace)
-+ * @kr: kref callback for freeing of a namespace
-+ */
-+void free_aa_namespace_kref(struct kref *kref)
-+{
-+      struct aa_namespace *ns=container_of(kref, struct aa_namespace, count);
-+
-+      free_aa_namespace(ns);
-+}
-+
-+/**
-+ * alloc_aa_namespace - allocate, initialize and return a new namespace
-+ * @name: a preallocated name
-+ * Returns NULL on failure.
-+ */
-+struct aa_namespace *alloc_aa_namespace(char *name)
-+{
-+      struct aa_namespace *ns;
-+
-+      ns = kzalloc(sizeof(*ns), GFP_KERNEL);
-+      AA_DEBUG("%s(%p)\n", __FUNCTION__, ns);
-+      if (ns) {
-+              ns->name = name;
-+              INIT_LIST_HEAD(&ns->list);
-+              INIT_LIST_HEAD(&ns->profiles);
-+              kref_init(&ns->count);
-+              rwlock_init(&ns->lock);
-+
-+              ns->null_complain_profile = alloc_aa_profile();
-+              if (!ns->null_complain_profile) {
-+                      if (!name)
-+                              kfree(ns->name);
-+                      kfree(ns);
-+                      return NULL;
-+              }
-+              ns->null_complain_profile->name =
-+                      kstrdup("null-complain-profile", GFP_KERNEL);
-+              if (!ns->null_complain_profile->name) {
-+                      free_aa_profile(ns->null_complain_profile);
-+                      if (!name)
-+                              kfree(ns->name);
-+                      kfree(ns);
-+                      return NULL;
-+              }
-+              ns->null_complain_profile->flags.complain = 1;
-+              /* null_complain_profile doesn't contribute to ns ref count */
-+              ns->null_complain_profile->ns = ns;
-+      }
-+      return ns;
-+}
-+
-+/**
-+ * free_aa_namespace - free a profile namespace
-+ * @namespace: the namespace to free
-+ *
-+ * Free a namespace.  All references to the namespace must have been put.
-+ * If the namespace was referenced by a profile confining a task,
-+ * free_aa_namespace will be called indirectly (through free_aa_profile)
-+ * from an rcu callback routine, so we must not sleep here.
-+ */
-+void free_aa_namespace(struct aa_namespace *ns)
-+{
-+      AA_DEBUG("%s(%p)\n", __FUNCTION__, ns);
-+
-+      if (!ns)
-+              return;
-+
-+      /* namespace still contains profiles -- invalid */
-+      if (!list_empty(&ns->profiles)) {
-+              AA_ERROR("%s: internal error, "
-+                       "namespace '%s' still contains profiles\n",
-+                       __FUNCTION__,
-+                       ns->name);
-+              BUG();
-+      }
-+      if (!list_empty(&ns->list)) {
-+              AA_ERROR("%s: internal error, "
-+                       "namespace '%s' still on list\n",
-+                       __FUNCTION__,
-+                       ns->name);
-+              BUG();
++              __aa_add_profile(common, new_profile);
++              new_profile->sid = aa_alloc_sid(AA_ALLOC_SYS_SID);
 +      }
-+      /* null_complain_profile doesn't contribute to ns ref counting */
-+      ns->null_complain_profile->ns = NULL;
-+      aa_put_profile(ns->null_complain_profile);
-+      kfree(ns->name);
-+      kfree(ns);
-+}
 +
-+/**
-+ * free_aa_profile_kref - free aa_profile by kref (called by aa_put_profile)
-+ * @kr: kref callback for freeing of a profile
-+ */
-+void free_aa_profile_kref(struct kref *kref)
-+{
-+      struct aa_profile *p=container_of(kref, struct aa_profile, count);
++      new_profile->ns = aa_get_namespace(ns);
 +
-+      free_aa_profile(p);
-+}
++      write_unlock(&ns->base.lock);
 +
-+/**
-+ * alloc_aa_profile - allocate, initialize and return a new profile
-+ * Returns NULL on failure.
-+ */
-+struct aa_profile *alloc_aa_profile(void)
-+{
-+      struct aa_profile *profile;
++      if (!old_profile)
++              sa.base.operation = "profile_load";
 +
-+      profile = kzalloc(sizeof(*profile), GFP_KERNEL);
-+      AA_DEBUG("%s(%p)\n", __FUNCTION__, profile);
-+      if (profile) {
-+              INIT_LIST_HEAD(&profile->list);
-+              kref_init(&profile->count);
-+              INIT_LIST_HEAD(&profile->task_contexts);
-+              spin_lock_init(&profile->lock);
-+      }
-+      return profile;
++      aa_audit_iface(&sa);
++      aa_put_namespace(ns);
++      aa_put_profile(old_profile);
++      kfree(e.ns_name);
++      return size;
++
++fail2:
++      write_unlock(&ns->base.lock);
++fail:
++      error = aa_audit_iface(&sa);
++      aa_put_namespace(ns);
++      aa_put_profile(old_profile);
++      aa_put_profile(new_profile);
++      kfree(e.ns_name);
++      return error;
 +}
 +
 +/**
-+ * free_aa_profile - free a profile
-+ * @profile: the profile to free
-+ *
-+ * Free a profile, its hats and null_profile. All references to the profile,
-+ * its hats and null_profile must have been put.
++ * aa_interface_remove_profiles - remove profile(s) from the system
++ * @name: name of the profile to remove
++ * @size: size of the name
 + *
-+ * If the profile was referenced from a task context, free_aa_profile() will
-+ * be called from an rcu callback routine, so we must not sleep here.
++ * remove a profile from the profile list and all aa_task_context references
++ * to said profile.
++ * NOTE: removing confinement does not restore rlimits to preconfinemnet values
 + */
-+void free_aa_profile(struct aa_profile *profile)
++ssize_t aa_interface_remove_profiles(char *name, size_t size)
 +{
-+      AA_DEBUG("%s(%p)\n", __FUNCTION__, profile);
++      struct aa_namespace *ns;
++      struct aa_profile *profile;
++      struct aa_audit_iface sa;
++      aa_audit_init(&sa, "profile_remove", NULL);
 +
-+      if (!profile)
-+              return;
++      if (g_apparmor_lock_policy)
++              return -EACCES;
 +
-+      /* profile is still on profile namespace list -- invalid */
-+      if (!list_empty(&profile->list)) {
-+              AA_ERROR("%s: internal error, "
-+                       "profile '%s' still on global list\n",
-+                       __FUNCTION__,
-+                       profile->name);
-+              BUG();
++      write_lock(&ns_list_lock);
++      if (name[0] == ':') {
++              char *ns_name;
++              name = aa_split_name_from_ns(name, &ns_name);
++              ns = __aa_find_namespace(&ns_list, ns_name);
++      } else {
++              ns = aa_get_namespace(default_namespace);
 +      }
-+      aa_put_namespace(profile->ns);
 +
-+      aa_match_free(profile->file_rules);
++      if (!ns) {
++              sa.base.info = "failed: namespace does not exist";
++              goto fail_ns_list_lock;
++      }
 +
-+      if (profile->name) {
-+              AA_DEBUG("%s: %s\n", __FUNCTION__, profile->name);
-+              kfree(profile->name);
++      sa.name2 = ns->base.name;
++      write_lock(&ns->base.lock);
++      if (!name) {
++              /* remove namespace */
++        //            __aa_remove_namespace(ns);
++      } else {
++              /* remove profile */
++              profile = __aa_find_profile_by_fqname(ns, name);
++              if (!profile) {
++                      sa.name = name;
++                      sa.base.info = "failed: profile does not exist";
++                      goto fail_ns_lock;
++              }
++              sa.name = profile->fqname;
++              __aa_profile_list_release(&profile->base.profiles);
++              __aa_remove_profile(profile, profile->ns->unconfined);
 +      }
++      write_unlock(&ns->base.lock);
++      write_unlock(&ns_list_lock);
 +
-+      kfree(profile);
-+}
++      aa_audit_iface(&sa);
++      aa_put_namespace(ns);
++      return size;
 +
-+/**
-+ * aa_unconfine_tasks - remove tasks on a profile's task context list
-+ * @profile: profile to remove tasks from
-+ *
-+ * Assumes that @profile lock is held.
-+ */
-+void aa_unconfine_tasks(struct aa_profile *profile)
-+{
-+      while (!list_empty(&profile->task_contexts)) {
-+              struct task_struct *task =
-+                      list_entry(profile->task_contexts.next,
-+                                 struct aa_task_context, list)->task;
-+              task_lock(task);
-+              aa_change_task_context(task, NULL, NULL, 0, NULL);
-+              task_unlock(task);
-+      }
++fail_ns_lock:
++      write_unlock(&ns->base.lock);
++
++fail_ns_list_lock:
++      write_unlock(&ns_list_lock);
++      aa_audit_iface(&sa);
++      return 0; //-ENOENT;
 +}
-diff -uprN e/security/apparmor/procattr.c f/security/apparmor/procattr.c
---- e/security/apparmor/procattr.c     1970-01-01 00:00:00.000000000 +0000
-+++ f/security/apparmor/procattr.c     2008-05-28 20:29:29.410207000 +0000
-@@ -0,0 +1,195 @@
+diff --git a/security/apparmor/procattr.c b/security/apparmor/procattr.c
+new file mode 100644
+index 0000000..834cfab
+--- /dev/null
++++ b/security/apparmor/procattr.c
+@@ -0,0 +1,117 @@
 +/*
-+ *    Copyright (C) 1998-2007 Novell/SUSE
++ * AppArmor security module
++ *
++ * This file contains AppArmor /proc/<pid>/attr/ interface functions
 + *
-+ *    This program is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU General Public License as
-+ *    published by the Free Software Foundation, version 2 of the
-+ *    License.
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
 + *
-+ *    AppArmor /proc/pid/attr handling
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
 + */
 +
-+#include "apparmor.h"
-+#include "inline.h"
++#include "include/apparmor.h"
++#include "include/policy.h"
++#include "include/domain.h"
 +
-+int aa_getprocattr(struct aa_profile *profile, char **string, unsigned *len)
++/* FIXME show profile multiplexing */
++int aa_getprocattr(struct aa_namespace *ns, struct aa_profile *profile,
++                 char **string)
 +{
 +      char *str;
++      int len = 0;
 +
 +      if (profile) {
-+              const char *mode_str = PROFILE_COMPLAIN(profile) ?
-+                      " (complain)" : " (enforce)";
 +              int mode_len, name_len, ns_len = 0;
-+
-+              mode_len = strlen(mode_str);
-+              name_len = strlen(profile->name);
-+              if (profile->ns != default_namespace)
-+                      ns_len = strlen(profile->ns->name) + 2;
-+              *len = mode_len + ns_len + name_len + 1;
-+              str = kmalloc(*len, GFP_ATOMIC);
++              const char *mode_str = profile_mode_names[profile->mode];
++              char *s;
++
++              mode_len = strlen(mode_str) + 3;  /* _(mode_str)\n */
++              name_len = strlen(profile->fqname);
++              if (ns != default_namespace)
++                      ns_len = strlen(ns->base.name) + 3;
++              len = mode_len + ns_len + name_len + 1;
++              s = str = kmalloc(len + 1, GFP_ATOMIC);
 +              if (!str)
 +                      return -ENOMEM;
 +
 +              if (ns_len) {
-+                      *str++ = ':';
-+                      memcpy(str, profile->ns->name, ns_len - 2);
-+                      str += ns_len - 2;
-+                      *str++ = ':';
++                      sprintf(s, "%s://", ns->base.name);
++                      s += ns_len;
 +              }
-+              memcpy(str, profile->name, name_len);
-+              str += name_len;
-+              memcpy(str, mode_str, mode_len);
-+              str += mode_len;
-+              *str++ = '\n';
-+              str -= *len;
++              memcpy(s, profile->fqname, name_len);
++              s += name_len;
++              sprintf(s, " (%s)\n", mode_str);
 +      } else {
 +              const char *unconfined_str = "unconfined\n";
 +
-+              *len = strlen(unconfined_str);
-+              str = kmalloc(*len, GFP_ATOMIC);
++              len = strlen(unconfined_str);
++              if (ns != default_namespace)
++                      len += strlen(ns->base.name) + 1;
++
++              str = kmalloc(len + 1, GFP_ATOMIC);
 +              if (!str)
 +                      return -ENOMEM;
 +
-+              memcpy(str, unconfined_str, *len);
++              if (ns != default_namespace)
++                      sprintf(str, "%s://%s", ns->base.name, unconfined_str);
++              else
++                      memcpy(str, unconfined_str, len);
 +      }
 +      *string = str;
 +
-+      return 0;
++      return len;
 +}
 +
-+static char *split_token_from_name(const char *op, char *args, u64 *cookie)
++static char *split_token_from_name(const char *op, char *args, u64 *token)
 +{
 +      char *name;
 +
-+      *cookie = simple_strtoull(args, &name, 16);
++      *token = simple_strtoull(args, &name, 16);
 +      if ((name == args) || *name != '^') {
 +              AA_ERROR("%s: Invalid input '%s'", op, args);
 +              return ERR_PTR(-EINVAL);
@@ -8352,712 +7104,266 @@ diff -uprN e/security/apparmor/procattr.c f/security/apparmor/procattr.c
 +      return name;
 +}
 +
-+int aa_setprocattr_changehat(char *args)
++int aa_setprocattr_changehat(char *args, int test)
 +{
 +      char *hat;
-+      u64 cookie;
++      u64 token;
 +
-+      hat = split_token_from_name("change_hat", args, &cookie);
++      hat = split_token_from_name("change_hat", args, &token);
 +      if (IS_ERR(hat))
 +              return PTR_ERR(hat);
 +
-+      if (!hat && !cookie) {
++      if (!hat && !token) {
 +              AA_ERROR("change_hat: Invalid input, NULL hat and NULL magic");
 +              return -EINVAL;
 +      }
 +
 +      AA_DEBUG("%s: Magic 0x%llx Hat '%s'\n",
-+               __FUNCTION__, cookie, hat ? hat : NULL);
++               __func__, token, hat ? hat : NULL);
 +
-+      return aa_change_hat(hat, cookie);
++      return aa_change_hat(hat, token, test);
 +}
 +
-+int aa_setprocattr_changeprofile(char *args)
++int aa_setprocattr_changeprofile(char *args, int onexec, int test)
 +{
-+      char *name = args, *ns_name = NULL;
++      char *name, *ns_name;
++
++      name = aa_split_name_from_ns(args, &ns_name);
++      return aa_change_profile(ns_name, name, onexec, test);
++}
 +
-+      if (name[0] == ':') {
-+              char *split = strchr(&name[1], ':');
-+              if (split) {
-+                      *split = 0;
-+                      ns_name = &name[1];
-+                      name = split + 1;
-+              }
-+      }
 +
-+      return aa_change_profile(ns_name, name);
++int aa_setprocattr_permipc(char *args)
++{
++      /* TODO: add ipc permission querying */
++      return -ENOTSUPP;
 +}
+diff --git a/security/apparmor/resource.c b/security/apparmor/resource.c
+new file mode 100644
+index 0000000..f00165b
+--- /dev/null
++++ b/security/apparmor/resource.c
+@@ -0,0 +1,104 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor resource mediation and attachment
++ *
++ * Copyright (C) 1998-2008 Novell/SUSE
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ */
++
++#include <linux/audit.h>
++
++#include "include/audit.h"
++#include "include/resource.h"
++#include "include/policy.h"
++
++struct aa_audit_resource {
++      struct aa_audit base;
++
++      int rlimit;
++};
 +
-+int aa_setprocattr_setprofile(struct task_struct *task, char *args)
++static void audit_cb(struct audit_buffer *ab, void *va)
 +{
-+      struct aa_profile *old_profile, *new_profile;
-+      struct aa_namespace *ns;
-+      struct aa_audit sa;
-+      char *name, *ns_name = NULL;
++      struct aa_audit_resource *sa = va;
++
++      if (sa->rlimit)
++              audit_log_format(ab, " rlimit=%d", sa->rlimit - 1);
++}
++
++static int aa_audit_resource(struct aa_profile *profile,
++                           struct aa_audit_resource *sa)
++{
++      return aa_audit(AUDIT_APPARMOR_AUTO, profile, (struct aa_audit *)sa,
++                      audit_cb);
++}
++
++/**
++ * aa_task_setrlimit - test permission to set an rlimit
++ * @profile - profile confining the task
++ * @resource - the resource being set
++ * @new_rlim - the new resource limit
++ *
++ * Control raising the processes hard limit.
++ */
++int aa_task_setrlimit(struct aa_profile *profile, unsigned int resource,
++                    struct rlimit *new_rlim)
++{
++      struct aa_audit_resource sa;
++      int error = 0;
 +
 +      memset(&sa, 0, sizeof(sa));
-+      sa.operation = "profile_set";
-+      sa.gfp_mask = GFP_KERNEL;
-+      sa.task = task->pid;
-+
-+      AA_DEBUG("%s: current %d\n",
-+               __FUNCTION__, current->pid);
-+
-+      name = args;
-+      if (args[0] != '/') {
-+              char *split = strchr(args, ':');
-+              if (split) {
-+                      *split = 0;
-+                      ns_name = args;
-+                      name = split + 1;
-+              }
-+      }
-+      if (ns_name)
-+              ns = aa_find_namespace(ns_name);
-+      else
-+              ns = aa_get_namespace(default_namespace);
-+      if (!ns) {
-+              sa.name = ns_name;
-+              sa.info = "unknown namespace";
-+              aa_audit_reject(NULL, &sa);
-+              aa_put_namespace(ns);
-+              return -EINVAL;
++      sa.base.operation = "setrlimit";
++      sa.base.gfp_mask = GFP_KERNEL;
++      sa.rlimit = resource + 1;
++
++      if (profile->rlimits.mask & (1 << resource) &&
++          new_rlim->rlim_max > profile->rlimits.limits[resource].rlim_max) {
++              sa.base.error = -EACCES;
++
++              error = aa_audit_resource(profile, &sa);
 +      }
 +
-+repeat:
-+      if (strcmp(name, "unconfined") == 0)
-+              new_profile = NULL;
-+      else {
-+              new_profile = aa_find_profile(ns, name);
-+              if (!new_profile) {
-+                      sa.name = ns_name;
-+                      sa.name2 = name;
-+                      sa.info = "unknown profile";
-+                      aa_audit_reject(NULL, &sa);
-+                      aa_put_namespace(ns);
-+                      return -EINVAL;
++      return error;
++}
++
++void __aa_transition_rlimits(struct aa_profile *old, struct aa_profile *new)
++{
++      unsigned int mask = 0;
++      struct rlimit *rlim, *initrlim;
++      int i;
++
++      /* for any rlimits the profile controlled reset the soft limit
++       * to the less of the tasks hard limit and the init tasks soft limit
++       */
++      if (old && old->rlimits.mask) {
++              for (i = 0, mask = 1; i < RLIM_NLIMITS; i++, mask <<=1) {
++                      if (old->rlimits.mask & mask) {
++                              rlim = current->signal->rlim + i;
++                              initrlim = init_task.signal->rlim + i;
++                              rlim->rlim_cur = min(rlim->rlim_max,
++                                                   initrlim->rlim_cur);
++                      }
 +              }
 +      }
 +
-+      old_profile = __aa_replace_profile(task, new_profile);
-+      if (IS_ERR(old_profile)) {
-+              int error;
++      /* set any new hard limits as dictated by the new profile */
++      if (!(new && new->rlimits.mask))
++              return;
++      for (i = 0, mask = 1; i < RLIM_NLIMITS; i++, mask <<=1) {
++              if (!(new->rlimits.mask & mask))
++                      continue;
 +
-+              aa_put_profile(new_profile);
-+              error = PTR_ERR(old_profile);
-+              if (error == -ESTALE)
-+                      goto repeat;
-+              aa_put_namespace(ns);
-+              return error;
++              rlim = current->signal->rlim + i;
++              rlim->rlim_max = min(rlim->rlim_max,
++                                   new->rlimits.limits[i].rlim_max);
++              /* soft limit should not exceed hard limit */
++              rlim->rlim_cur = min(rlim->rlim_cur, rlim->rlim_max);
 +      }
++}
+diff --git a/security/apparmor/sid.c b/security/apparmor/sid.c
+new file mode 100644
+index 0000000..aa41a35
+--- /dev/null
++++ b/security/apparmor/sid.c
+@@ -0,0 +1,113 @@
++/*
++ * AppArmor security module
++ *
++ * This file contains AppArmor security identifier (sid) manipulation fns
++ *
++ * Copyright 2009 Canonical Ltd.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation, version 2 of the
++ * License.
++ *
++ *
++ * AppArmor allocates a unique sid for every profile loaded.  If a profile
++ * is replaced it receive the sid of the profile it is replacing.  Each sid
++ * is a u32 with the lower u16 being sids of system profiles and the
++ * upper u16 being user profile sids.
++ *
++ * The sid value of 0 is invalid for system sids and is used to indicate
++ * unconfined for user sids.
++ *
++ * A compound sid is a pair of user and system sids that is used to identify
++ * both profiles confining a task.
++ *
++ * Both system and user sids are globally unique with all users pulling
++ * from the same sid pool.  User sid allocation is limited by the
++ * user controls, that can limit how many profiles are loaded by a user.
++ */
++
++#include <linux/spinlock.h>
++#include <linux/errno.h>
++#include <linux/err.h>
++
++#include "include/sid.h"
++
++/* global counter from which sids are allocated */
++static u16 global_sys_sid;
++static u16 global_usr_sid;
++static DEFINE_SPINLOCK(sid_lock);
 +
-+      if (new_profile) {
-+              sa.name = ns_name;
-+              sa.name2 = name;
-+              sa.name3 = old_profile ? old_profile->name :
-+                      "unconfined";
-+              aa_audit_status(NULL, &sa);
++
++/* TODO FIXME: add sid to profile mapping, and sid recycling */
++
++
++/**
++ * aa_alloc_sid - allocate a new sid for a profile
++ * @is_usr: true if the new sid is a user based sid
++ */
++u32 aa_alloc_sid(int is_usr)
++{
++      u32 sid;
++
++      /* 
++       * TODO FIXME: sid recycling - part of profile mapping table
++       */
++      spin_lock(&sid_lock);
++      if (is_usr) {
++              sid = (++global_usr_sid) << 16;
++              
 +      } else {
-+              if (old_profile) {
-+                      sa.name = "unconfined";
-+                      sa.name2 = old_profile->name;
-+                      aa_audit_status(NULL, &sa);
-+              } else {
-+                      sa.info = "task is unconfined";
-+                      aa_audit_status(NULL, &sa);
-+              }
++              sid = ++global_sys_sid;
 +      }
-+      aa_put_namespace(ns);
-+      aa_put_profile(old_profile);
-+      aa_put_profile(new_profile);
++      spin_unlock(&sid_lock);
++      return sid;
++}
++
++/**
++ * aa_free_sid - free a sid
++ * @sid: sid to free
++ */
++void aa_free_sid(u32 sid)
++{
++      ;       /* NOP ATM */
++}
++
++/**
++ * aa_add_sid_profile - associate a profile to a sid for sid -> profile lookup
++ * @sid: sid of te profile
++ * @profile: profile to associate
++ *
++ * return 0 or error
++ */
++int aa_add_sid_profile(u32 sid, struct aa_profile *profile)
++{
++      /* NOP ATM */
 +      return 0;
 +}
-diff -uprN e/security/commoncap.c f/security/commoncap.c
---- e/security/commoncap.c     2008-04-17 02:49:44.000000000 +0000
-+++ f/security/commoncap.c     2008-05-28 20:29:29.410207000 +0000
-@@ -386,8 +386,8 @@ int cap_bprm_secureexec (struct linux_bi
-               current->egid != current->gid);
- }
--int cap_inode_setxattr(struct dentry *dentry, char *name, void *value,
--                     size_t size, int flags)
-+int cap_inode_setxattr(struct dentry *dentry, struct vfsmount *mnt, char *name,
-+                     void *value, size_t size, int flags, struct file *file)
- {
-       if (!strcmp(name, XATTR_NAME_CAPS)) {
-               if (!capable(CAP_SETFCAP))
-@@ -400,7 +400,8 @@ int cap_inode_setxattr(struct dentry *de
-       return 0;
- }
--int cap_inode_removexattr(struct dentry *dentry, char *name)
-+int cap_inode_removexattr(struct dentry *dentry, struct vfsmount *mnt,
-+                        char *name, struct file *file)
- {
-       if (!strcmp(name, XATTR_NAME_CAPS)) {
-               if (!capable(CAP_SETFCAP))
-diff -uprN e/security/dummy.c f/security/dummy.c
---- e/security/dummy.c 2008-04-17 02:49:44.000000000 +0000
-+++ f/security/dummy.c 2008-05-28 20:29:29.410207000 +0000
-@@ -287,54 +287,60 @@ static int dummy_inode_init_security (st
- }
- static int dummy_inode_create (struct inode *inode, struct dentry *dentry,
--                             int mask)
-+                             struct vfsmount *mnt, int mask)
- {
-       return 0;
- }
--static int dummy_inode_link (struct dentry *old_dentry, struct inode *inode,
--                           struct dentry *new_dentry)
-+static int dummy_inode_link (struct dentry *old_dentry,
-+                           struct vfsmount *old_mnt, struct inode *inode,
-+                           struct dentry *new_dentry,
-+                           struct vfsmount *new_mnt)
- {
-       return 0;
- }
--static int dummy_inode_unlink (struct inode *inode, struct dentry *dentry)
-+static int dummy_inode_unlink (struct inode *inode, struct dentry *dentry,
-+                             struct vfsmount *mnt)
- {
-       return 0;
- }
- static int dummy_inode_symlink (struct inode *inode, struct dentry *dentry,
--                              const char *name)
-+                              struct vfsmount *mnt, const char *name)
- {
-       return 0;
- }
- static int dummy_inode_mkdir (struct inode *inode, struct dentry *dentry,
--                            int mask)
-+                            struct vfsmount *mnt, int mask)
- {
-       return 0;
- }
--static int dummy_inode_rmdir (struct inode *inode, struct dentry *dentry)
-+static int dummy_inode_rmdir (struct inode *inode, struct dentry *dentry,
-+                            struct vfsmount *mnt)
- {
-       return 0;
- }
- static int dummy_inode_mknod (struct inode *inode, struct dentry *dentry,
--                            int mode, dev_t dev)
-+                            struct vfsmount *mnt, int mode, dev_t dev)
- {
-       return 0;
- }
- static int dummy_inode_rename (struct inode *old_inode,
-                              struct dentry *old_dentry,
-+                             struct vfsmount *old_mnt,
-                              struct inode *new_inode,
--                             struct dentry *new_dentry)
-+                             struct dentry *new_dentry,
-+                             struct vfsmount *new_mnt)
- {
-       return 0;
- }
--static int dummy_inode_readlink (struct dentry *dentry)
-+static int dummy_inode_readlink (struct dentry *dentry, struct vfsmount *mnt)
- {
-       return 0;
- }
-@@ -350,7 +356,8 @@ static int dummy_inode_permission (struc
-       return 0;
- }
--static int dummy_inode_setattr (struct dentry *dentry, struct iattr *iattr)
-+static int dummy_inode_setattr (struct dentry *dentry, struct vfsmount *mnt,
-+                              struct iattr *iattr)
- {
-       return 0;
- }
-@@ -365,8 +372,9 @@ static void dummy_inode_delete (struct i
-       return;
- }
--static int dummy_inode_setxattr (struct dentry *dentry, char *name, void *value,
--                              size_t size, int flags)
-+static int dummy_inode_setxattr (struct dentry *dentry, struct vfsmount *mnt,
-+                               char *name, void *value, size_t size,
-+                               int flags, struct file *file)
- {
-       if (!strncmp(name, XATTR_SECURITY_PREFIX,
-                    sizeof(XATTR_SECURITY_PREFIX) - 1) &&
-@@ -375,22 +383,28 @@ static int dummy_inode_setxattr (struct 
-       return 0;
- }
--static void dummy_inode_post_setxattr (struct dentry *dentry, char *name, void *value,
-+static void dummy_inode_post_setxattr (struct dentry *dentry,
-+                                     struct vfsmount *mnt,
-+                                     char *name, void *value,
-                                      size_t size, int flags)
- {
- }
--static int dummy_inode_getxattr (struct dentry *dentry, char *name)
-+static int dummy_inode_getxattr (struct dentry *dentry,
-+                                struct vfsmount *mnt, char *name,
-+                                struct file *file)
- {
-       return 0;
- }
--static int dummy_inode_listxattr (struct dentry *dentry)
-+static int dummy_inode_listxattr (struct dentry *dentry, struct vfsmount *mnt,
-+                                struct file *file)
- {
-       return 0;
- }
--static int dummy_inode_removexattr (struct dentry *dentry, char *name)
-+static int dummy_inode_removexattr (struct dentry *dentry, struct vfsmount *mnt,
-+                                  char *name, struct file *file)
- {
-       if (!strncmp(name, XATTR_SECURITY_PREFIX,
-                    sizeof(XATTR_SECURITY_PREFIX) - 1) &&
-diff -uprN e/security/security.c f/security/security.c
---- e/security/security.c      2008-04-17 02:49:44.000000000 +0000
-+++ f/security/security.c      2008-05-28 20:29:29.410207000 +0000
-@@ -352,72 +352,80 @@ int security_inode_init_security(struct 
- }
- EXPORT_SYMBOL(security_inode_init_security);
--int security_inode_create(struct inode *dir, struct dentry *dentry, int mode)
-+int security_inode_create(struct inode *dir, struct dentry *dentry,
-+                        struct vfsmount *mnt, int mode)
- {
-       if (unlikely(IS_PRIVATE(dir)))
-               return 0;
--      return security_ops->inode_create(dir, dentry, mode);
-+      return security_ops->inode_create(dir, dentry, mnt, mode);
- }
--int security_inode_link(struct dentry *old_dentry, struct inode *dir,
--                       struct dentry *new_dentry)
-+int security_inode_link(struct dentry *old_dentry, struct vfsmount *old_mnt,
-+                      struct inode *dir, struct dentry *new_dentry,
-+                      struct vfsmount *new_mnt)
- {
-       if (unlikely(IS_PRIVATE(old_dentry->d_inode)))
-               return 0;
--      return security_ops->inode_link(old_dentry, dir, new_dentry);
-+      return security_ops->inode_link(old_dentry, old_mnt, dir,
-+                                       new_dentry, new_mnt);
- }
--int security_inode_unlink(struct inode *dir, struct dentry *dentry)
-+int security_inode_unlink(struct inode *dir, struct dentry *dentry,
-+                        struct vfsmount *mnt)
- {
-       if (unlikely(IS_PRIVATE(dentry->d_inode)))
-               return 0;
--      return security_ops->inode_unlink(dir, dentry);
-+      return security_ops->inode_unlink(dir, dentry, mnt);
- }
- int security_inode_symlink(struct inode *dir, struct dentry *dentry,
--                          const char *old_name)
-+                         struct vfsmount *mnt, const char *old_name)
- {
-       if (unlikely(IS_PRIVATE(dir)))
-               return 0;
--      return security_ops->inode_symlink(dir, dentry, old_name);
-+      return security_ops->inode_symlink(dir, dentry, mnt, old_name);
- }
--int security_inode_mkdir(struct inode *dir, struct dentry *dentry, int mode)
-+int security_inode_mkdir(struct inode *dir, struct dentry *dentry,
-+                       struct vfsmount *mnt, int mode)
- {
-       if (unlikely(IS_PRIVATE(dir)))
-               return 0;
--      return security_ops->inode_mkdir(dir, dentry, mode);
-+      return security_ops->inode_mkdir(dir, dentry, mnt, mode);
- }
--int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
-+int security_inode_rmdir(struct inode *dir, struct dentry *dentry,
-+                       struct vfsmount *mnt)
- {
-       if (unlikely(IS_PRIVATE(dentry->d_inode)))
-               return 0;
--      return security_ops->inode_rmdir(dir, dentry);
-+      return security_ops->inode_rmdir(dir, dentry, mnt);
- }
--int security_inode_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
-+int security_inode_mknod(struct inode *dir, struct dentry *dentry,
-+                       struct vfsmount *mnt, int mode, dev_t dev)
- {
-       if (unlikely(IS_PRIVATE(dir)))
-               return 0;
--      return security_ops->inode_mknod(dir, dentry, mode, dev);
-+      return security_ops->inode_mknod(dir, dentry, mnt, mode, dev);
- }
- int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
--                         struct inode *new_dir, struct dentry *new_dentry)
-+                        struct vfsmount *old_mnt, struct inode *new_dir,
-+                        struct dentry *new_dentry, struct vfsmount *new_mnt)
- {
-         if (unlikely(IS_PRIVATE(old_dentry->d_inode) ||
-             (new_dentry->d_inode && IS_PRIVATE(new_dentry->d_inode))))
-               return 0;
--      return security_ops->inode_rename(old_dir, old_dentry,
--                                         new_dir, new_dentry);
-+      return security_ops->inode_rename(old_dir, old_dentry, old_mnt,
-+                                         new_dir, new_dentry, new_mnt);
- }
--int security_inode_readlink(struct dentry *dentry)
-+int security_inode_readlink(struct dentry *dentry, struct vfsmount *mnt)
- {
-       if (unlikely(IS_PRIVATE(dentry->d_inode)))
-               return 0;
--      return security_ops->inode_readlink(dentry);
-+      return security_ops->inode_readlink(dentry, mnt);
- }
- int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
-@@ -434,11 +442,12 @@ int security_inode_permission(struct ino
-       return security_ops->inode_permission(inode, mask, nd);
- }
--int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
-+int security_inode_setattr(struct dentry *dentry, struct vfsmount *mnt,
-+                         struct iattr *attr)
- {
-       if (unlikely(IS_PRIVATE(dentry->d_inode)))
-               return 0;
--      return security_ops->inode_setattr(dentry, attr);
-+      return security_ops->inode_setattr(dentry, mnt, attr);
- }
- int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
-@@ -455,41 +464,48 @@ void security_inode_delete(struct inode 
-       security_ops->inode_delete(inode);
- }
--int security_inode_setxattr(struct dentry *dentry, char *name,
--                           void *value, size_t size, int flags)
-+int security_inode_setxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                          char *name, void *value, size_t size, int flags,
-+                          struct file *file)
- {
-       if (unlikely(IS_PRIVATE(dentry->d_inode)))
-               return 0;
--      return security_ops->inode_setxattr(dentry, name, value, size, flags);
-+      return security_ops->inode_setxattr(dentry, mnt, name, value, size,
-+                                          flags, file);
- }
--void security_inode_post_setxattr(struct dentry *dentry, char *name,
--                                 void *value, size_t size, int flags)
-+void security_inode_post_setxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                                char *name, void *value, size_t size,
-+                                int flags)
- {
-       if (unlikely(IS_PRIVATE(dentry->d_inode)))
-               return;
--      security_ops->inode_post_setxattr(dentry, name, value, size, flags);
-+      security_ops->inode_post_setxattr(dentry, mnt, name, value, size,
-+                                       flags);
- }
--int security_inode_getxattr(struct dentry *dentry, char *name)
-+int security_inode_getxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                          char *name, struct file *file)
- {
-       if (unlikely(IS_PRIVATE(dentry->d_inode)))
-               return 0;
--      return security_ops->inode_getxattr(dentry, name);
-+      return security_ops->inode_getxattr(dentry, mnt, name, file);
- }
--int security_inode_listxattr(struct dentry *dentry)
-+int security_inode_listxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                           struct file *file)
- {
-       if (unlikely(IS_PRIVATE(dentry->d_inode)))
-               return 0;
--      return security_ops->inode_listxattr(dentry);
-+      return security_ops->inode_listxattr(dentry, mnt, file);
- }
--int security_inode_removexattr(struct dentry *dentry, char *name)
-+int security_inode_removexattr(struct dentry *dentry, struct vfsmount *mnt,
-+                             char *name, struct file *file)
- {
-       if (unlikely(IS_PRIVATE(dentry->d_inode)))
-               return 0;
--      return security_ops->inode_removexattr(dentry, name);
-+      return security_ops->inode_removexattr(dentry, mnt, name, file);
- }
- int security_inode_need_killpriv(struct dentry *dentry)
-diff -uprN e/security/selinux/hooks.c f/security/selinux/hooks.c
---- e/security/selinux/hooks.c 2008-05-28 20:32:27.897940261 +0000
-+++ f/security/selinux/hooks.c 2008-05-28 20:29:29.410207000 +0000
-@@ -1712,40 +1712,15 @@ static int selinux_capable(struct task_s
- static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
- {
--      int buflen, rc;
--      char *buffer, *path, *end;
-+      char *buffer, *path;
-+      int rc = -ENOMEM;
--      rc = -ENOMEM;
-       buffer = (char*)__get_free_page(GFP_KERNEL);
-       if (!buffer)
-               goto out;
--
--      buflen = PAGE_SIZE;
--      end = buffer+buflen;
--      *--end = '\0';
--      buflen--;
--      path = end-1;
--      *path = '/';
--      while (table) {
--              const char *name = table->procname;
--              size_t namelen = strlen(name);
--              buflen -= namelen + 1;
--              if (buflen < 0)
--                      goto out_free;
--              end -= namelen;
--              memcpy(end, name, namelen);
--              *--end = '/';
--              path = end;
--              table = table->parent;
--      }
--      buflen -= 4;
--      if (buflen < 0)
--              goto out_free;
--      end -= 4;
--      memcpy(end, "/sys", 4);
--      path = end;
--      rc = security_genfs_sid("proc", path, tclass, sid);
--out_free:
-+      path = sysctl_pathname(table, buffer, PAGE_SIZE);
-+      if (path)
-+              rc = security_genfs_sid("proc", path, tclass, sid);
-       free_page((unsigned long)buffer);
- out:
-       return rc;
-@@ -2458,64 +2433,79 @@ static int selinux_inode_init_security(s
-       return 0;
- }
--static int selinux_inode_create(struct inode *dir, struct dentry *dentry, int mask)
-+static int selinux_inode_create(struct inode *dir, struct dentry *dentry,
-+                               struct vfsmount *mnt, int mask)
- {
-       return may_create(dir, dentry, SECCLASS_FILE);
- }
--static int selinux_inode_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
-+static int selinux_inode_link(struct dentry *old_dentry,
-+                            struct vfsmount *old_mnt,
-+                            struct inode *dir,
-+                            struct dentry *new_dentry,
-+                            struct vfsmount *new_mnt)
- {
-       int rc;
--      rc = secondary_ops->inode_link(old_dentry,dir,new_dentry);
-+      rc = secondary_ops->inode_link(old_dentry, old_mnt, dir, new_dentry,
-+                                     new_mnt);
-       if (rc)
-               return rc;
-       return may_link(dir, old_dentry, MAY_LINK);
- }
--static int selinux_inode_unlink(struct inode *dir, struct dentry *dentry)
-+static int selinux_inode_unlink(struct inode *dir, struct dentry *dentry,
-+                              struct vfsmount *mnt)
- {
-       int rc;
--      rc = secondary_ops->inode_unlink(dir, dentry);
-+      rc = secondary_ops->inode_unlink(dir, dentry, mnt);
-       if (rc)
-               return rc;
-       return may_link(dir, dentry, MAY_UNLINK);
- }
--static int selinux_inode_symlink(struct inode *dir, struct dentry *dentry, const char *name)
-+static int selinux_inode_symlink(struct inode *dir, struct dentry *dentry,
-+                               struct vfsmount *mnt, const char *name)
- {
-       return may_create(dir, dentry, SECCLASS_LNK_FILE);
- }
--static int selinux_inode_mkdir(struct inode *dir, struct dentry *dentry, int mask)
-+static int selinux_inode_mkdir(struct inode *dir, struct dentry *dentry,
-+                             struct vfsmount *mnt, int mask)
- {
-       return may_create(dir, dentry, SECCLASS_DIR);
- }
--static int selinux_inode_rmdir(struct inode *dir, struct dentry *dentry)
-+static int selinux_inode_rmdir(struct inode *dir, struct dentry *dentry,
-+                             struct vfsmount *mnt)
- {
-       return may_link(dir, dentry, MAY_RMDIR);
- }
--static int selinux_inode_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
-+static int selinux_inode_mknod(struct inode *dir, struct dentry *dentry,
-+                             struct vfsmount *mnt, int mode, dev_t dev)
- {
-       int rc;
--      rc = secondary_ops->inode_mknod(dir, dentry, mode, dev);
-+      rc = secondary_ops->inode_mknod(dir, dentry, mnt, mode, dev);
-       if (rc)
-               return rc;
-       return may_create(dir, dentry, inode_mode_to_security_class(mode));
- }
--static int selinux_inode_rename(struct inode *old_inode, struct dentry *old_dentry,
--                                struct inode *new_inode, struct dentry *new_dentry)
-+static int selinux_inode_rename(struct inode *old_inode,
-+                              struct dentry *old_dentry,
-+                              struct vfsmount *old_mnt,
-+                                struct inode *new_inode,
-+                              struct dentry *new_dentry,
-+                              struct vfsmount *new_mnt)
- {
-       return may_rename(old_inode, old_dentry, new_inode, new_dentry);
- }
--static int selinux_inode_readlink(struct dentry *dentry)
-+static int selinux_inode_readlink(struct dentry *dentry, struct vfsmount *mnt)
- {
-       return dentry_has_perm(current, NULL, dentry, FILE__READ);
- }
-@@ -2548,11 +2538,12 @@ static int selinux_inode_permission(stru
-                              file_mask_to_av(inode->i_mode, mask), NULL);
- }
--static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr)
-+static int selinux_inode_setattr(struct dentry *dentry, struct vfsmount *mnt,
-+                               struct iattr *iattr)
- {
-       int rc;
--      rc = secondary_ops->inode_setattr(dentry, iattr);
-+      rc = secondary_ops->inode_setattr(dentry, mnt, iattr);
-       if (rc)
-               return rc;
-@@ -2590,7 +2581,9 @@ static int selinux_inode_setotherxattr(s
-       return dentry_has_perm(current, NULL, dentry, FILE__SETATTR);
- }
--static int selinux_inode_setxattr(struct dentry *dentry, char *name, void *value, size_t size, int flags)
-+static int selinux_inode_setxattr(struct dentry *dentry, struct vfsmount *mnt,
-+                                char *name, void *value, size_t size,
-+                                int flags, struct file *file)
- {
-       struct task_security_struct *tsec = current->security;
-       struct inode *inode = dentry->d_inode;
-@@ -2639,7 +2632,9 @@ static int selinux_inode_setxattr(struct
-                           &ad);
- }
--static void selinux_inode_post_setxattr(struct dentry *dentry, char *name,
-+static void selinux_inode_post_setxattr(struct dentry *dentry,
-+                                      struct vfsmount *mnt,
-+                                      char *name,
-                                         void *value, size_t size, int flags)
- {
-       struct inode *inode = dentry->d_inode;
-@@ -2663,17 +2658,21 @@ static void selinux_inode_post_setxattr(
-       return;
- }
--static int selinux_inode_getxattr (struct dentry *dentry, char *name)
-+static int selinux_inode_getxattr (struct dentry *dentry, struct vfsmount *mnt,
-+                                 char *name, struct file *file)
- {
-       return dentry_has_perm(current, NULL, dentry, FILE__GETATTR);
- }
--static int selinux_inode_listxattr (struct dentry *dentry)
-+static int selinux_inode_listxattr (struct dentry *dentry, struct vfsmount *mnt,
-+                                  struct file *file)
- {
-       return dentry_has_perm(current, NULL, dentry, FILE__GETATTR);
- }
--static int selinux_inode_removexattr (struct dentry *dentry, char *name)
-+static int selinux_inode_removexattr (struct dentry *dentry,
-+                                    struct vfsmount *mnt, char *name,
-+                                    struct file *file)
- {
-       if (strcmp(name, XATTR_NAME_SELINUX))
-               return selinux_inode_setotherxattr(dentry, name);
---- s/fs/namei.c~      2008-05-29 00:47:22.000000000 +0200
-+++ s/fs/namei.c       2008-05-29 00:53:55.814585231 +0200
-@@ -3022,8 +3022,8 @@
-               new_path.dentry->d_name.len,
-               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
-               old_path.dentry->d_name.len);
--      ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
--              old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
-+      ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry, new_path.mnt,
-+              old_nd.path.dentry->d_parent->d_inode, old_path.dentry, old_path.mnt);
-       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
-       res = new_path.dentry;
---- s/fs/namei.c~      2008-05-29 00:59:12.000000000 +0200
-+++ s/fs/namei.c       2008-05-29 00:59:40.790875766 +0200
-@@ -3048,7 +3048,7 @@
-               goto out_redo;
-       /* error path cleanup */
--      vfs_unlink(dir->d_inode, new_path.dentry, &dir_nd);
-+      vfs_unlink(dir->d_inode, new_path.dentry, &dir_nd, new_path.mnt);
-       dput(new_path.dentry);
- out_redo:
---- s/include/linux/xattr.h~   2008-05-29 01:40:01.000000000 +0200
-+++ s/include/linux/xattr.h    2008-05-29 01:40:06.624153911 +0200
-@@ -16,6 +16,7 @@
- #ifdef  __KERNEL__
- #include <linux/types.h>
-+#include <linux/fs.h>
- /* Namespaces */
- #define XATTR_OS2_PREFIX "os2."
----
- security/apparmor/main.c |    2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
---- a/security/apparmor/main.c
-+++ b/security/apparmor/main.c
-@@ -503,10 +503,10 @@ static char *aa_get_name(struct dentry *
-                       *buffer = buf;
-                       return name;
-               }
-+              kfree(buf);
-               if (PTR_ERR(name) != -ENAMETOOLONG)
-                       return name;
--              kfree(buf);
-               size <<= 1;
-               if (size > apparmor_path_max)
-                       return ERR_PTR(-ENAMETOOLONG);
++
++/**
++ * aa_replace_sid_profile - replace the profile associated with a sid
++ * @sid: sid to associate a new profile with
++ * @profile: profile to associate with side
++ *
++ * return 0 or error
++ */
++int aa_replace_sid_profile(u32 sid, struct aa_profile *profile)
++{
++      /* NOP ATM */
++      return 0;
++}
++
++/**
++ * aa_get_sid_profile - get the profile associated with the sid
++ * @sid: sid to lookup
++ *
++ * returns - the profile, or NULL for unconfined user.
++ *         - if there is an error -ENOENT, -EINVAL
++ */
++struct aa_profile *aa_get_sid_profile(u32 sid)
++{
++      return ERR_PTR(-EINVAL);
++}
++
diff --git a/kernel-bzip2-lzma.patch b/kernel-bzip2-lzma.patch
deleted file mode 100644 (file)
index 76899a6..0000000
+++ /dev/null
@@ -1,3252 +0,0 @@
-Linus,
-
-Please pull the latest bzip2-lzma-for-linus git tree from:
-
-   git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git bzip2-lzma-for-linus
-
-We are sending this as a separate tree as it affects generic
-files as well.
-
-Highlights:
-
- - Add kernel image compression mode config options:
-
-    Kernel compression mode
-    > 1. Gzip (KERNEL_GZIP) (NEW)
-      2. Bzip2 (KERNEL_BZIP2) (NEW)
-      3. LZMA (KERNEL_LZMA) (NEW)
-
-    Initial ramdisk compressed using gzip (RD_GZIP) [Y/n/?] (NEW)
-    Initial ramdisk compressed using bzip2 (RD_BZIP2) [N/y/?] (NEW)
-    Initial ramdisk compressed using lzma (RD_LZMA) [N/y/?] (NEW)
-
-    Built-in initramfs compression mode
-    > 1. None (INITRAMFS_COMPRESSION_NONE) (NEW)
-      2. Gzip (INITRAMFS_COMPRESSION_GZIP) (NEW)
-    choice[1-2?]:
-
-   ... and matching compression and decompression implementations.
-
-Risks:
-
- - This has been a historically problematic topic thus we skipped 
-   the v2.6.28 and v2.6.29 merge windows with it. Boot failures, 
-   panics, initrd decompression problems have been observed and 
-   fixed.
-
- - On x86 we switch over from lib/inflate.c to zlib - same 
-   functionality but different library. Other architectures are not 
-   affected by that, use of this new facility is opt-in. (This was 
-   the last in-kernel user of lib/inflate.c on x86.)
-
- - To build a kernel with a different compressor the 'bzip2' or 'lzma'
-   tools are needed. If the kernel is built with CONFIG_KERNEL_LZMA=y
-   and the tool is not available the kernel build will fail with a clear
-   message. This tool is available in all major kernel distros, but
-   it is not generally a default-installed package. bzip2 is generally
-   installed by default.
-
- - There are no known regressions.
-
- Thanks,
-
-       Ingo
-
------------------->
-Alain Knaff (8):
-      bzip2/lzma: library support for gzip, bzip2 and lzma decompression
-      bzip2/lzma: config and initramfs support for bzip2/lzma decompression
-      bzip2/lzma: x86 kernel compression support
-      bzip2/lzma: fix built-in initramfs vs CONFIG_RD_GZIP
-      bzip2/lzma: fix decompress_inflate.c vs multi-block-with-embedded-filename
-      bzip2/lzma: don't stop search at first unconfigured compression
-      bzip2/lzma: don't leave empty files around on failure
-      bzip2/lzma: make internal initramfs compression configurable
-
-Cyrill Gorcunov (1):
-      x86: headers cleanup - boot.h
-
-H. Peter Anvin (11):
-      bzip2/lzma: use a table to search for initramfs compression formats
-      bzip2/lzma: handle failures from bzip2 and lzma correctly
-      bzip2/lzma: make config machinery an arch configurable
-      bzip2/lzma: proper Kconfig dependencies for the ramdisk options
-      bzip2/lzma: DECOMPRESS_GZIP should select ZLIB_INFLATE
-      bzip2/lzma: move initrd/ramfs options out of BLK_DEV
-      bzip2/lzma: fix constant in decompress_inflate
-      bzip2/lzma: centralize format detection
-      bzip2/lzma: comprehensible error messages for missing decompressor
-      init: make initrd/initramfs decompression failure a KERN_EMERG event
-      bzip2/lzma: update boot protocol specification
-
-Ingo Molnar (1):
-      bzip2/lzma: make flush_buffer() unconditional
-
-
- Documentation/x86/boot.txt         |    5 +-
- arch/x86/Kconfig                   |    3 +
- arch/x86/boot/compressed/Makefile  |   21 +-
- arch/x86/boot/compressed/misc.c    |  118 +-----
- arch/x86/include/asm/boot.h        |   16 +-
- include/linux/decompress/bunzip2.h |   10 +
- include/linux/decompress/generic.h |   33 ++
- include/linux/decompress/inflate.h |   13 +
- include/linux/decompress/mm.h      |   87 +++++
- include/linux/decompress/unlzma.h  |   12 +
- init/Kconfig                       |   60 +++
- init/do_mounts_rd.c                |  178 +++-------
- init/initramfs.c                   |  122 ++-----
- lib/Kconfig                        |   14 +
- lib/Makefile                       |    7 +-
- lib/decompress.c                   |   54 +++
- lib/decompress_bunzip2.c           |  735 ++++++++++++++++++++++++++++++++++++
- lib/decompress_inflate.c           |  167 ++++++++
- lib/decompress_unlzma.c            |  647 +++++++++++++++++++++++++++++++
- lib/zlib_inflate/inflate.h         |    4 +
- lib/zlib_inflate/inftrees.h        |    4 +
- scripts/Makefile.lib               |   14 +
- scripts/bin_size                   |   10 +
- scripts/gen_initramfs_list.sh      |   18 +-
- usr/Kconfig                        |   89 +++++
- usr/Makefile                       |   36 ++-
- usr/initramfs_data.S               |    2 +-
- usr/initramfs_data.bz2.S           |   29 ++
- usr/initramfs_data.gz.S            |   29 ++
- usr/initramfs_data.lzma.S          |   29 ++
- 30 files changed, 2222 insertions(+), 344 deletions(-)
- create mode 100644 include/linux/decompress/bunzip2.h
- create mode 100644 include/linux/decompress/generic.h
- create mode 100644 include/linux/decompress/inflate.h
- create mode 100644 include/linux/decompress/mm.h
- create mode 100644 include/linux/decompress/unlzma.h
- create mode 100644 lib/decompress.c
- create mode 100644 lib/decompress_bunzip2.c
- create mode 100644 lib/decompress_inflate.c
- create mode 100644 lib/decompress_unlzma.c
- create mode 100644 scripts/bin_size
- create mode 100644 usr/initramfs_data.bz2.S
- create mode 100644 usr/initramfs_data.gz.S
- create mode 100644 usr/initramfs_data.lzma.S
-
-diff --git a/Documentation/x86/boot.txt b/Documentation/x86/boot.txt
-index 7b4596a..d05730e 100644
---- a/Documentation/x86/boot.txt
-+++ b/Documentation/x86/boot.txt
-@@ -542,7 +542,10 @@ Protocol: 2.08+
-   The payload may be compressed. The format of both the compressed and
-   uncompressed data should be determined using the standard magic
--  numbers. Currently only gzip compressed ELF is used.
-+  numbers.  The currently supported compression formats are gzip
-+  (magic numbers 1F 8B or 1F 9E), bzip2 (magic number 42 5A) and LZMA
-+  (magic number 5D 00).  The uncompressed payload is currently always ELF
-+  (magic number 7F 45 4C 46).
-   
- Field name:   payload_length
- Type:         read
-diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
-index bc2fbad..a233768 100644
---- a/arch/x86/Kconfig
-+++ b/arch/x86/Kconfig
-@@ -40,6 +40,9 @@ config X86
-       select HAVE_GENERIC_DMA_COHERENT if X86_32
-       select HAVE_EFFICIENT_UNALIGNED_ACCESS
-       select USER_STACKTRACE_SUPPORT
-+      select HAVE_KERNEL_GZIP
-+      select HAVE_KERNEL_BZIP2
-+      select HAVE_KERNEL_LZMA
- config ARCH_DEFCONFIG
-       string
-diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
-index 1771c80..3ca4c19 100644
---- a/arch/x86/boot/compressed/Makefile
-+++ b/arch/x86/boot/compressed/Makefile
-@@ -4,7 +4,7 @@
- # create a compressed vmlinux image from the original vmlinux
- #
--targets := vmlinux vmlinux.bin vmlinux.bin.gz head_$(BITS).o misc.o piggy.o
-+targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma head_$(BITS).o misc.o piggy.o
- KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
- KBUILD_CFLAGS += -fno-strict-aliasing -fPIC
-@@ -47,18 +47,35 @@ ifeq ($(CONFIG_X86_32),y)
- ifdef CONFIG_RELOCATABLE
- $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin.all FORCE
-       $(call if_changed,gzip)
-+$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin.all FORCE
-+      $(call if_changed,bzip2)
-+$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin.all FORCE
-+      $(call if_changed,lzma)
- else
- $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
-       $(call if_changed,gzip)
-+$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE
-+      $(call if_changed,bzip2)
-+$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
-+      $(call if_changed,lzma)
- endif
- LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
- else
-+
- $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
-       $(call if_changed,gzip)
-+$(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE
-+      $(call if_changed,bzip2)
-+$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
-+      $(call if_changed,lzma)
- LDFLAGS_piggy.o := -r --format binary --oformat elf64-x86-64 -T
- endif
--$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
-+suffix_$(CONFIG_KERNEL_GZIP)  = gz
-+suffix_$(CONFIG_KERNEL_BZIP2) = bz2
-+suffix_$(CONFIG_KERNEL_LZMA)  = lzma
-+
-+$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.$(suffix_y) FORCE
-       $(call if_changed,ld)
-diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
-index da06221..e45be73 100644
---- a/arch/x86/boot/compressed/misc.c
-+++ b/arch/x86/boot/compressed/misc.c
-@@ -116,71 +116,13 @@
- /*
-  * gzip declarations
-  */
--
--#define OF(args)      args
- #define STATIC                static
- #undef memset
- #undef memcpy
- #define memzero(s, n) memset((s), 0, (n))
--typedef unsigned char uch;
--typedef unsigned short        ush;
--typedef unsigned long ulg;
--
--/*
-- * Window size must be at least 32k, and a power of two.
-- * We don't actually have a window just a huge output buffer,
-- * so we report a 2G window size, as that should always be
-- * larger than our output buffer:
-- */
--#define WSIZE         0x80000000
--
--/* Input buffer: */
--static unsigned char  *inbuf;
--
--/* Sliding window buffer (and final output buffer): */
--static unsigned char  *window;
--
--/* Valid bytes in inbuf: */
--static unsigned               insize;
--
--/* Index of next byte to be processed in inbuf: */
--static unsigned               inptr;
--
--/* Bytes in output buffer: */
--static unsigned               outcnt;
--
--/* gzip flag byte */
--#define ASCII_FLAG    0x01 /* bit 0 set: file probably ASCII text */
--#define CONTINUATION  0x02 /* bit 1 set: continuation of multi-part gz file */
--#define EXTRA_FIELD   0x04 /* bit 2 set: extra field present */
--#define ORIG_NAM      0x08 /* bit 3 set: original file name present */
--#define COMMENT               0x10 /* bit 4 set: file comment present */
--#define ENCRYPTED     0x20 /* bit 5 set: file is encrypted */
--#define RESERVED      0xC0 /* bit 6, 7:  reserved */
--
--#define get_byte()    (inptr < insize ? inbuf[inptr++] : fill_inbuf())
--
--/* Diagnostic functions */
--#ifdef DEBUG
--#  define Assert(cond, msg) do { if (!(cond)) error(msg); } while (0)
--#  define Trace(x)    do { fprintf x; } while (0)
--#  define Tracev(x)   do { if (verbose) fprintf x ; } while (0)
--#  define Tracevv(x)  do { if (verbose > 1) fprintf x ; } while (0)
--#  define Tracec(c, x)        do { if (verbose && (c)) fprintf x ; } while (0)
--#  define Tracecv(c, x)       do { if (verbose > 1 && (c)) fprintf x ; } while (0)
--#else
--#  define Assert(cond, msg)
--#  define Trace(x)
--#  define Tracev(x)
--#  define Tracevv(x)
--#  define Tracec(c, x)
--#  define Tracecv(c, x)
--#endif
--static int  fill_inbuf(void);
--static void flush_window(void);
- static void error(char *m);
- /*
-@@ -189,13 +131,8 @@ static void error(char *m);
- static struct boot_params *real_mode;         /* Pointer to real-mode data */
- static int quiet;
--extern unsigned char input_data[];
--extern int input_len;
--
--static long bytes_out;
--
- static void *memset(void *s, int c, unsigned n);
--static void *memcpy(void *dest, const void *src, unsigned n);
-+void *memcpy(void *dest, const void *src, unsigned n);
- static void __putstr(int, const char *);
- #define putstr(__x)  __putstr(0, __x)
-@@ -213,7 +150,17 @@ static char *vidmem;
- static int vidport;
- static int lines, cols;
--#include "../../../../lib/inflate.c"
-+#ifdef CONFIG_KERNEL_GZIP
-+#include "../../../../lib/decompress_inflate.c"
-+#endif
-+
-+#ifdef CONFIG_KERNEL_BZIP2
-+#include "../../../../lib/decompress_bunzip2.c"
-+#endif
-+
-+#ifdef CONFIG_KERNEL_LZMA
-+#include "../../../../lib/decompress_unlzma.c"
-+#endif
- static void scroll(void)
- {
-@@ -282,7 +229,7 @@ static void *memset(void *s, int c, unsigned n)
-       return s;
- }
--static void *memcpy(void *dest, const void *src, unsigned n)
-+void *memcpy(void *dest, const void *src, unsigned n)
- {
-       int i;
-       const char *s = src;
-@@ -293,38 +240,6 @@ static void *memcpy(void *dest, const void *src, unsigned n)
-       return dest;
- }
--/* ===========================================================================
-- * Fill the input buffer. This is called only when the buffer is empty
-- * and at least one byte is really needed.
-- */
--static int fill_inbuf(void)
--{
--      error("ran out of input data");
--      return 0;
--}
--
--/* ===========================================================================
-- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
-- * (Used for the decompressed data only.)
-- */
--static void flush_window(void)
--{
--      /* With my window equal to my output buffer
--       * I only need to compute the crc here.
--       */
--      unsigned long c = crc;         /* temporary variable */
--      unsigned n;
--      unsigned char *in, ch;
--
--      in = window;
--      for (n = 0; n < outcnt; n++) {
--              ch = *in++;
--              c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
--      }
--      crc = c;
--      bytes_out += (unsigned long)outcnt;
--      outcnt = 0;
--}
- static void error(char *x)
- {
-@@ -407,12 +322,8 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
-       lines = real_mode->screen_info.orig_video_lines;
-       cols = real_mode->screen_info.orig_video_cols;
--      window = output;                /* Output buffer (Normally at 1M) */
-       free_mem_ptr     = heap;        /* Heap */
-       free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
--      inbuf  = input_data;            /* Input buffer */
--      insize = input_len;
--      inptr  = 0;
- #ifdef CONFIG_X86_64
-       if ((unsigned long)output & (__KERNEL_ALIGN - 1))
-@@ -430,10 +341,9 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
- #endif
- #endif
--      makecrc();
-       if (!quiet)
-               putstr("\nDecompressing Linux... ");
--      gunzip();
-+      decompress(input_data, input_len, NULL, NULL, output, NULL, error);
-       parse_elf(output);
-       if (!quiet)
-               putstr("done.\nBooting the kernel.\n");
-diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
-index dd61616..6526cf0 100644
---- a/arch/x86/include/asm/boot.h
-+++ b/arch/x86/include/asm/boot.h
-@@ -10,17 +10,31 @@
- #define EXTENDED_VGA  0xfffe          /* 80x50 mode */
- #define ASK_VGA               0xfffd          /* ask for it at bootup */
-+#ifdef __KERNEL__
-+
- /* Physical address where kernel should be loaded. */
- #define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
-                               + (CONFIG_PHYSICAL_ALIGN - 1)) \
-                               & ~(CONFIG_PHYSICAL_ALIGN - 1))
-+#ifdef CONFIG_KERNEL_BZIP2
-+#define BOOT_HEAP_SIZE             0x400000
-+#else /* !CONFIG_KERNEL_BZIP2 */
-+
- #ifdef CONFIG_X86_64
- #define BOOT_HEAP_SIZE        0x7000
--#define BOOT_STACK_SIZE       0x4000
- #else
- #define BOOT_HEAP_SIZE        0x4000
-+#endif
-+
-+#endif /* !CONFIG_KERNEL_BZIP2 */
-+
-+#ifdef CONFIG_X86_64
-+#define BOOT_STACK_SIZE       0x4000
-+#else
- #define BOOT_STACK_SIZE       0x1000
- #endif
-+#endif /* __KERNEL__ */
-+
- #endif /* _ASM_X86_BOOT_H */
-diff --git a/include/linux/decompress/bunzip2.h b/include/linux/decompress/bunzip2.h
-new file mode 100644
-index 0000000..1152721
---- /dev/null
-+++ b/include/linux/decompress/bunzip2.h
-@@ -0,0 +1,10 @@
-+#ifndef DECOMPRESS_BUNZIP2_H
-+#define DECOMPRESS_BUNZIP2_H
-+
-+int bunzip2(unsigned char *inbuf, int len,
-+          int(*fill)(void*, unsigned int),
-+          int(*flush)(void*, unsigned int),
-+          unsigned char *output,
-+          int *pos,
-+          void(*error)(char *x));
-+#endif
-diff --git a/include/linux/decompress/generic.h b/include/linux/decompress/generic.h
-new file mode 100644
-index 0000000..6dfb856
---- /dev/null
-+++ b/include/linux/decompress/generic.h
-@@ -0,0 +1,33 @@
-+#ifndef DECOMPRESS_GENERIC_H
-+#define DECOMPRESS_GENERIC_H
-+
-+/* Minimal chunksize to be read.
-+ *Bzip2 prefers at least 4096
-+ *Lzma prefers 0x10000 */
-+#define COMPR_IOBUF_SIZE      4096
-+
-+typedef int (*decompress_fn) (unsigned char *inbuf, int len,
-+                            int(*fill)(void*, unsigned int),
-+                            int(*writebb)(void*, unsigned int),
-+                            unsigned char *output,
-+                            int *posp,
-+                            void(*error)(char *x));
-+
-+/* inbuf   - input buffer
-+ *len     - len of pre-read data in inbuf
-+ *fill    - function to fill inbuf if empty
-+ *writebb - function to write out outbug
-+ *posp    - if non-null, input position (number of bytes read) will be
-+ *      returned here
-+ *
-+ *If len != 0, the inbuf is initialized (with as much data), and fill
-+ *should not be called
-+ *If len = 0, the inbuf is allocated, but empty. Its size is IOBUF_SIZE
-+ *fill should be called (repeatedly...) to read data, at most IOBUF_SIZE
-+ */
-+
-+/* Utility routine to detect the decompression method */
-+decompress_fn decompress_method(const unsigned char *inbuf, int len,
-+                              const char **name);
-+
-+#endif
-diff --git a/include/linux/decompress/inflate.h b/include/linux/decompress/inflate.h
-new file mode 100644
-index 0000000..f9b06cc
---- /dev/null
-+++ b/include/linux/decompress/inflate.h
-@@ -0,0 +1,13 @@
-+#ifndef INFLATE_H
-+#define INFLATE_H
-+
-+/* Other housekeeping constants */
-+#define INBUFSIZ 4096
-+
-+int gunzip(unsigned char *inbuf, int len,
-+         int(*fill)(void*, unsigned int),
-+         int(*flush)(void*, unsigned int),
-+         unsigned char *output,
-+         int *pos,
-+         void(*error_fn)(char *x));
-+#endif
-diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
-new file mode 100644
-index 0000000..12ff8c3
---- /dev/null
-+++ b/include/linux/decompress/mm.h
-@@ -0,0 +1,87 @@
-+/*
-+ * linux/compr_mm.h
-+ *
-+ * Memory management for pre-boot and ramdisk uncompressors
-+ *
-+ * Authors: Alain Knaff <alain@knaff.lu>
-+ *
-+ */
-+
-+#ifndef DECOMPR_MM_H
-+#define DECOMPR_MM_H
-+
-+#ifdef STATIC
-+
-+/* Code active when included from pre-boot environment: */
-+
-+/* A trivial malloc implementation, adapted from
-+ *  malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
-+ */
-+static unsigned long malloc_ptr;
-+static int malloc_count;
-+
-+static void *malloc(int size)
-+{
-+      void *p;
-+
-+      if (size < 0)
-+              error("Malloc error");
-+      if (!malloc_ptr)
-+              malloc_ptr = free_mem_ptr;
-+
-+      malloc_ptr = (malloc_ptr + 3) & ~3;     /* Align */
-+
-+      p = (void *)malloc_ptr;
-+      malloc_ptr += size;
-+
-+      if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr)
-+              error("Out of memory");
-+
-+      malloc_count++;
-+      return p;
-+}
-+
-+static void free(void *where)
-+{
-+      malloc_count--;
-+      if (!malloc_count)
-+              malloc_ptr = free_mem_ptr;
-+}
-+
-+#define large_malloc(a) malloc(a)
-+#define large_free(a) free(a)
-+
-+#define set_error_fn(x)
-+
-+#define INIT
-+
-+#else /* STATIC */
-+
-+/* Code active when compiled standalone for use when loading ramdisk: */
-+
-+#include <linux/kernel.h>
-+#include <linux/fs.h>
-+#include <linux/string.h>
-+#include <linux/vmalloc.h>
-+
-+/* Use defines rather than static inline in order to avoid spurious
-+ * warnings when not needed (indeed large_malloc / large_free are not
-+ * needed by inflate */
-+
-+#define malloc(a) kmalloc(a, GFP_KERNEL)
-+#define free(a) kfree(a)
-+
-+#define large_malloc(a) vmalloc(a)
-+#define large_free(a) vfree(a)
-+
-+static void(*error)(char *m);
-+#define set_error_fn(x) error = x;
-+
-+#define INIT __init
-+#define STATIC
-+
-+#include <linux/init.h>
-+
-+#endif /* STATIC */
-+
-+#endif /* DECOMPR_MM_H */
-diff --git a/include/linux/decompress/unlzma.h b/include/linux/decompress/unlzma.h
-new file mode 100644
-index 0000000..7796538
---- /dev/null
-+++ b/include/linux/decompress/unlzma.h
-@@ -0,0 +1,12 @@
-+#ifndef DECOMPRESS_UNLZMA_H
-+#define DECOMPRESS_UNLZMA_H
-+
-+int unlzma(unsigned char *, int,
-+         int(*fill)(void*, unsigned int),
-+         int(*flush)(void*, unsigned int),
-+         unsigned char *output,
-+         int *posp,
-+         void(*error)(char *x)
-+      );
-+
-+#endif
-diff --git a/init/Kconfig b/init/Kconfig
-index 6a5c5fe..38396ec 100644
---- a/init/Kconfig
-+++ b/init/Kconfig
-@@ -101,6 +101,66 @@ config LOCALVERSION_AUTO
-         which is done within the script "scripts/setlocalversion".)
-+config HAVE_KERNEL_GZIP
-+      bool
-+
-+config HAVE_KERNEL_BZIP2
-+      bool
-+
-+config HAVE_KERNEL_LZMA
-+      bool
-+
-+choice
-+      prompt "Kernel compression mode"
-+      default KERNEL_GZIP
-+      depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA
-+      help
-+        The linux kernel is a kind of self-extracting executable.
-+        Several compression algorithms are available, which differ
-+        in efficiency, compression and decompression speed.
-+        Compression speed is only relevant when building a kernel.
-+        Decompression speed is relevant at each boot.
-+
-+        If you have any problems with bzip2 or lzma compressed
-+        kernels, mail me (Alain Knaff) <alain@knaff.lu>. (An older
-+        version of this functionality (bzip2 only), for 2.4, was
-+        supplied by Christian Ludwig)
-+
-+        High compression options are mostly useful for users, who
-+        are low on disk space (embedded systems), but for whom ram
-+        size matters less.
-+
-+        If in doubt, select 'gzip'
-+
-+config KERNEL_GZIP
-+      bool "Gzip"
-+      depends on HAVE_KERNEL_GZIP
-+      help
-+        The old and tried gzip compression. Its compression ratio is
-+        the poorest among the 3 choices; however its speed (both
-+        compression and decompression) is the fastest.
-+
-+config KERNEL_BZIP2
-+      bool "Bzip2"
-+      depends on HAVE_KERNEL_BZIP2
-+      help
-+        Its compression ratio and speed is intermediate.
-+        Decompression speed is slowest among the three.  The kernel
-+        size is about 10% smaller with bzip2, in comparison to gzip.
-+        Bzip2 uses a large amount of memory. For modern kernels you
-+        will need at least 8MB RAM or more for booting.
-+
-+config KERNEL_LZMA
-+      bool "LZMA"
-+      depends on HAVE_KERNEL_LZMA
-+      help
-+        The most recent compression algorithm.
-+        Its ratio is best, decompression speed is between the other
-+        two. Compression is slowest.  The kernel size is about 33%
-+        smaller with LZMA in comparison to gzip.
-+
-+endchoice
-+
- config SWAP
-       bool "Support for paging of anonymous memory (swap)"
-       depends on MMU && BLOCK
-diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
-index 0f0f0cf..027a402 100644
---- a/init/do_mounts_rd.c
-+++ b/init/do_mounts_rd.c
-@@ -11,6 +11,9 @@
- #include "do_mounts.h"
- #include "../fs/squashfs/squashfs_fs.h"
-+#include <linux/decompress/generic.h>
-+
-+
- int __initdata rd_prompt = 1;/* 1 = prompt for RAM disk, 0 = don't prompt */
- static int __init prompt_ramdisk(char *str)
-@@ -29,7 +32,7 @@ static int __init ramdisk_start_setup(char *str)
- }
- __setup("ramdisk_start=", ramdisk_start_setup);
--static int __init crd_load(int in_fd, int out_fd);
-+static int __init crd_load(int in_fd, int out_fd, decompress_fn deco);
- /*
-  * This routine tries to find a RAM disk image to load, and returns the
-@@ -38,15 +41,15 @@ static int __init crd_load(int in_fd, int out_fd);
-  * numbers could not be found.
-  *
-  * We currently check for the following magic numbers:
-- *    minix
-- *    ext2
-+ *    minix
-+ *    ext2
-  *    romfs
-  *    cramfs
-  *    squashfs
-- *    gzip
-+ *    gzip
-  */
--static int __init 
--identify_ramdisk_image(int fd, int start_block)
-+static int __init
-+identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)
- {
-       const int size = 512;
-       struct minix_super_block *minixsb;
-@@ -56,6 +59,7 @@ identify_ramdisk_image(int fd, int start_block)
-       struct squashfs_super_block *squashfsb;
-       int nblocks = -1;
-       unsigned char *buf;
-+      const char *compress_name;
-       buf = kmalloc(size, GFP_KERNEL);
-       if (!buf)
-@@ -69,18 +73,19 @@ identify_ramdisk_image(int fd, int start_block)
-       memset(buf, 0xe5, size);
-       /*
--       * Read block 0 to test for gzipped kernel
-+       * Read block 0 to test for compressed kernel
-        */
-       sys_lseek(fd, start_block * BLOCK_SIZE, 0);
-       sys_read(fd, buf, size);
--      /*
--       * If it matches the gzip magic numbers, return 0
--       */
--      if (buf[0] == 037 && ((buf[1] == 0213) || (buf[1] == 0236))) {
--              printk(KERN_NOTICE
--                     "RAMDISK: Compressed image found at block %d\n",
--                     start_block);
-+      *decompressor = decompress_method(buf, size, &compress_name);
-+      if (compress_name) {
-+              printk(KERN_NOTICE "RAMDISK: %s image found at block %d\n",
-+                     compress_name, start_block);
-+              if (!*decompressor)
-+                      printk(KERN_EMERG
-+                             "RAMDISK: %s decompressor not configured!\n",
-+                             compress_name);
-               nblocks = 0;
-               goto done;
-       }
-@@ -142,7 +147,7 @@ identify_ramdisk_image(int fd, int start_block)
-       printk(KERN_NOTICE
-              "RAMDISK: Couldn't find valid RAM disk image starting at %d.\n",
-              start_block);
--      
-+
- done:
-       sys_lseek(fd, start_block * BLOCK_SIZE, 0);
-       kfree(buf);
-@@ -157,6 +162,7 @@ int __init rd_load_image(char *from)
-       int nblocks, i, disk;
-       char *buf = NULL;
-       unsigned short rotate = 0;
-+      decompress_fn decompressor = NULL;
- #if !defined(CONFIG_S390) && !defined(CONFIG_PPC_ISERIES)
-       char rotator[4] = { '|' , '/' , '-' , '\\' };
- #endif
-@@ -169,12 +175,12 @@ int __init rd_load_image(char *from)
-       if (in_fd < 0)
-               goto noclose_input;
--      nblocks = identify_ramdisk_image(in_fd, rd_image_start);
-+      nblocks = identify_ramdisk_image(in_fd, rd_image_start, &decompressor);
-       if (nblocks < 0)
-               goto done;
-       if (nblocks == 0) {
--              if (crd_load(in_fd, out_fd) == 0)
-+              if (crd_load(in_fd, out_fd, decompressor) == 0)
-                       goto successful_load;
-               goto done;
-       }
-@@ -200,7 +206,7 @@ int __init rd_load_image(char *from)
-                      nblocks, rd_blocks);
-               goto done;
-       }
--              
-+
-       /*
-        * OK, time to copy in the data
-        */
-@@ -273,138 +279,48 @@ int __init rd_load_disk(int n)
-       return rd_load_image("/dev/root");
- }
--/*
-- * gzip declarations
-- */
--
--#define OF(args)  args
--
--#ifndef memzero
--#define memzero(s, n)     memset ((s), 0, (n))
--#endif
--
--typedef unsigned char  uch;
--typedef unsigned short ush;
--typedef unsigned long  ulg;
--
--#define INBUFSIZ 4096
--#define WSIZE 0x8000    /* window size--must be a power of two, and */
--                      /*  at least 32K for zip's deflate method */
--
--static uch *inbuf;
--static uch *window;
--
--static unsigned insize;  /* valid bytes in inbuf */
--static unsigned inptr;   /* index of next byte to be processed in inbuf */
--static unsigned outcnt;  /* bytes in output buffer */
- static int exit_code;
--static int unzip_error;
--static long bytes_out;
-+static int decompress_error;
- static int crd_infd, crd_outfd;
--#define get_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf())
--              
--/* Diagnostic functions (stubbed out) */
--#define Assert(cond,msg)
--#define Trace(x)
--#define Tracev(x)
--#define Tracevv(x)
--#define Tracec(c,x)
--#define Tracecv(c,x)
--
--#define STATIC static
--#define INIT __init
--
--static int  __init fill_inbuf(void);
--static void __init flush_window(void);
--static void __init error(char *m);
--
--#define NO_INFLATE_MALLOC
--
--#include "../lib/inflate.c"
--
--/* ===========================================================================
-- * Fill the input buffer. This is called only when the buffer is empty
-- * and at least one byte is really needed.
-- * Returning -1 does not guarantee that gunzip() will ever return.
-- */
--static int __init fill_inbuf(void)
-+static int __init compr_fill(void *buf, unsigned int len)
- {
--      if (exit_code) return -1;
--      
--      insize = sys_read(crd_infd, inbuf, INBUFSIZ);
--      if (insize == 0) {
--              error("RAMDISK: ran out of compressed data");
--              return -1;
--      }
--
--      inptr = 1;
--
--      return inbuf[0];
-+      int r = sys_read(crd_infd, buf, len);
-+      if (r < 0)
-+              printk(KERN_ERR "RAMDISK: error while reading compressed data");
-+      else if (r == 0)
-+              printk(KERN_ERR "RAMDISK: EOF while reading compressed data");
-+      return r;
- }
--/* ===========================================================================
-- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
-- * (Used for the decompressed data only.)
-- */
--static void __init flush_window(void)
-+static int __init compr_flush(void *window, unsigned int outcnt)
- {
--    ulg c = crc;         /* temporary variable */
--    unsigned n, written;
--    uch *in, ch;
--    
--    written = sys_write(crd_outfd, window, outcnt);
--    if (written != outcnt && unzip_error == 0) {
--      printk(KERN_ERR "RAMDISK: incomplete write (%d != %d) %ld\n",
--             written, outcnt, bytes_out);
--      unzip_error = 1;
--    }
--    in = window;
--    for (n = 0; n < outcnt; n++) {
--          ch = *in++;
--          c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
--    }
--    crc = c;
--    bytes_out += (ulg)outcnt;
--    outcnt = 0;
-+      int written = sys_write(crd_outfd, window, outcnt);
-+      if (written != outcnt) {
-+              if (decompress_error == 0)
-+                      printk(KERN_ERR
-+                             "RAMDISK: incomplete write (%d != %d)\n",
-+                             written, outcnt);
-+              decompress_error = 1;
-+              return -1;
-+      }
-+      return outcnt;
- }
- static void __init error(char *x)
- {
-       printk(KERN_ERR "%s\n", x);
-       exit_code = 1;
--      unzip_error = 1;
-+      decompress_error = 1;
- }
--static int __init crd_load(int in_fd, int out_fd)
-+static int __init crd_load(int in_fd, int out_fd, decompress_fn deco)
- {
-       int result;
--
--      insize = 0;             /* valid bytes in inbuf */
--      inptr = 0;              /* index of next byte to be processed in inbuf */
--      outcnt = 0;             /* bytes in output buffer */
--      exit_code = 0;
--      bytes_out = 0;
--      crc = (ulg)0xffffffffL; /* shift register contents */
--
-       crd_infd = in_fd;
-       crd_outfd = out_fd;
--      inbuf = kmalloc(INBUFSIZ, GFP_KERNEL);
--      if (!inbuf) {
--              printk(KERN_ERR "RAMDISK: Couldn't allocate gzip buffer\n");
--              return -1;
--      }
--      window = kmalloc(WSIZE, GFP_KERNEL);
--      if (!window) {
--              printk(KERN_ERR "RAMDISK: Couldn't allocate gzip window\n");
--              kfree(inbuf);
--              return -1;
--      }
--      makecrc();
--      result = gunzip();
--      if (unzip_error)
-+      result = deco(NULL, 0, compr_fill, compr_flush, NULL, NULL, error);
-+      if (decompress_error)
-               result = 1;
--      kfree(inbuf);
--      kfree(window);
-       return result;
- }
-diff --git a/init/initramfs.c b/init/initramfs.c
-index d9c941c..7dcde7e 100644
---- a/init/initramfs.c
-+++ b/init/initramfs.c
-@@ -390,11 +390,13 @@ static int __init write_buffer(char *buf, unsigned len)
-       return len - count;
- }
--static void __init flush_buffer(char *buf, unsigned len)
-+static int __init flush_buffer(void *bufv, unsigned len)
- {
-+      char *buf = (char *) bufv;
-       int written;
-+      int origLen = len;
-       if (message)
--              return;
-+              return -1;
-       while ((written = write_buffer(buf, len)) < len && !message) {
-               char c = buf[written];
-               if (c == '0') {
-@@ -408,84 +410,28 @@ static void __init flush_buffer(char *buf, unsigned len)
-               } else
-                       error("junk in compressed archive");
-       }
-+      return origLen;
- }
--/*
-- * gzip declarations
-- */
-+static unsigned my_inptr;   /* index of next byte to be processed in inbuf */
--#define OF(args)  args
--
--#ifndef memzero
--#define memzero(s, n)     memset ((s), 0, (n))
--#endif
--
--typedef unsigned char  uch;
--typedef unsigned short ush;
--typedef unsigned long  ulg;
--
--#define WSIZE 0x8000    /* window size--must be a power of two, and */
--                      /*  at least 32K for zip's deflate method */
--
--static uch *inbuf;
--static uch *window;
--
--static unsigned insize;  /* valid bytes in inbuf */
--static unsigned inptr;   /* index of next byte to be processed in inbuf */
--static unsigned outcnt;  /* bytes in output buffer */
--static long bytes_out;
--
--#define get_byte()  (inptr < insize ? inbuf[inptr++] : -1)
--              
--/* Diagnostic functions (stubbed out) */
--#define Assert(cond,msg)
--#define Trace(x)
--#define Tracev(x)
--#define Tracevv(x)
--#define Tracec(c,x)
--#define Tracecv(c,x)
--
--#define STATIC static
--#define INIT __init
--
--static void __init flush_window(void);
--static void __init error(char *m);
--
--#define NO_INFLATE_MALLOC
--
--#include "../lib/inflate.c"
--
--/* ===========================================================================
-- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
-- * (Used for the decompressed data only.)
-- */
--static void __init flush_window(void)
--{
--      ulg c = crc;         /* temporary variable */
--      unsigned n;
--      uch *in, ch;
--
--      flush_buffer(window, outcnt);
--      in = window;
--      for (n = 0; n < outcnt; n++) {
--              ch = *in++;
--              c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
--      }
--      crc = c;
--      bytes_out += (ulg)outcnt;
--      outcnt = 0;
--}
-+#include <linux/decompress/generic.h>
- static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
- {
-       int written;
-+      decompress_fn decompress;
-+      const char *compress_name;
-+      static __initdata char msg_buf[64];
-+
-       dry_run = check_only;
-       header_buf = kmalloc(110, GFP_KERNEL);
-       symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
-       name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
--      window = kmalloc(WSIZE, GFP_KERNEL);
--      if (!window || !header_buf || !symlink_buf || !name_buf)
-+
-+      if (!header_buf || !symlink_buf || !name_buf)
-               panic("can't allocate buffers");
-+
-       state = Start;
-       this_header = 0;
-       message = NULL;
-@@ -505,22 +451,25 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
-                       continue;
-               }
-               this_header = 0;
--              insize = len;
--              inbuf = buf;
--              inptr = 0;
--              outcnt = 0;             /* bytes in output buffer */
--              bytes_out = 0;
--              crc = (ulg)0xffffffffL; /* shift register contents */
--              makecrc();
--              gunzip();
-+              decompress = decompress_method(buf, len, &compress_name);
-+              if (decompress)
-+                      decompress(buf, len, NULL, flush_buffer, NULL,
-+                                 &my_inptr, error);
-+              else if (compress_name) {
-+                      if (!message) {
-+                              snprintf(msg_buf, sizeof msg_buf,
-+                                       "compression method %s not configured",
-+                                       compress_name);
-+                              message = msg_buf;
-+                      }
-+              }
-               if (state != Reset)
--                      error("junk in gzipped archive");
--              this_header = saved_offset + inptr;
--              buf += inptr;
--              len -= inptr;
-+                      error("junk in compressed archive");
-+              this_header = saved_offset + my_inptr;
-+              buf += my_inptr;
-+              len -= my_inptr;
-       }
-       dir_utime();
--      kfree(window);
-       kfree(name_buf);
-       kfree(symlink_buf);
-       kfree(header_buf);
-@@ -579,7 +528,7 @@ static int __init populate_rootfs(void)
-       char *err = unpack_to_rootfs(__initramfs_start,
-                        __initramfs_end - __initramfs_start, 0);
-       if (err)
--              panic(err);
-+              panic(err);     /* Failed to decompress INTERNAL initramfs */
-       if (initrd_start) {
- #ifdef CONFIG_BLK_DEV_RAM
-               int fd;
-@@ -605,9 +554,12 @@ static int __init populate_rootfs(void)
-               printk(KERN_INFO "Unpacking initramfs...");
-               err = unpack_to_rootfs((char *)initrd_start,
-                       initrd_end - initrd_start, 0);
--              if (err)
--                      panic(err);
--              printk(" done\n");
-+              if (err) {
-+                      printk(" failed!\n");
-+                      printk(KERN_EMERG "%s\n", err);
-+              } else {
-+                      printk(" done\n");
-+              }
-               free_initrd();
- #endif
-       }
-diff --git a/lib/Kconfig b/lib/Kconfig
-index 03c2c24..daa4818 100644
---- a/lib/Kconfig
-+++ b/lib/Kconfig
-@@ -98,6 +98,20 @@ config LZO_DECOMPRESS
-       tristate
- #
-+# These all provide a common interface (hence the apparent duplication with
-+# ZLIB_INFLATE; DECOMPRESS_GZIP is just a wrapper.)
-+#
-+config DECOMPRESS_GZIP
-+      select ZLIB_INFLATE
-+      tristate
-+
-+config DECOMPRESS_BZIP2
-+      tristate
-+
-+config DECOMPRESS_LZMA
-+      tristate
-+
-+#
- # Generic allocator support is selected if needed
- #
- config GENERIC_ALLOCATOR
-diff --git a/lib/Makefile b/lib/Makefile
-index 32b0e64..790de7c 100644
---- a/lib/Makefile
-+++ b/lib/Makefile
-@@ -11,7 +11,8 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
-        rbtree.o radix-tree.o dump_stack.o \
-        idr.o int_sqrt.o extable.o prio_tree.o \
-        sha1.o irq_regs.o reciprocal_div.o argv_split.o \
--       proportions.o prio_heap.o ratelimit.o show_mem.o is_single_threaded.o
-+       proportions.o prio_heap.o ratelimit.o show_mem.o \
-+       is_single_threaded.o decompress.o
- lib-$(CONFIG_MMU) += ioremap.o
- lib-$(CONFIG_SMP) += cpumask.o
-@@ -65,6 +66,10 @@ obj-$(CONFIG_REED_SOLOMON) += reed_solomon/
- obj-$(CONFIG_LZO_COMPRESS) += lzo/
- obj-$(CONFIG_LZO_DECOMPRESS) += lzo/
-+lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o
-+lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o
-+lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
-+
- obj-$(CONFIG_TEXTSEARCH) += textsearch.o
- obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o
- obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o
-diff --git a/lib/decompress.c b/lib/decompress.c
-new file mode 100644
-index 0000000..d2842f5
---- /dev/null
-+++ b/lib/decompress.c
-@@ -0,0 +1,54 @@
-+/*
-+ * decompress.c
-+ *
-+ * Detect the decompression method based on magic number
-+ */
-+
-+#include <linux/decompress/generic.h>
-+
-+#include <linux/decompress/bunzip2.h>
-+#include <linux/decompress/unlzma.h>
-+#include <linux/decompress/inflate.h>
-+
-+#include <linux/types.h>
-+#include <linux/string.h>
-+
-+#ifndef CONFIG_DECOMPRESS_GZIP
-+# define gunzip NULL
-+#endif
-+#ifndef CONFIG_DECOMPRESS_BZIP2
-+# define bunzip2 NULL
-+#endif
-+#ifndef CONFIG_DECOMPRESS_LZMA
-+# define unlzma NULL
-+#endif
-+
-+static const struct compress_format {
-+      unsigned char magic[2];
-+      const char *name;
-+      decompress_fn decompressor;
-+} compressed_formats[] = {
-+      { {037, 0213}, "gzip", gunzip },
-+      { {037, 0236}, "gzip", gunzip },
-+      { {0x42, 0x5a}, "bzip2", bunzip2 },
-+      { {0x5d, 0x00}, "lzma", unlzma },
-+      { {0, 0}, NULL, NULL }
-+};
-+
-+decompress_fn decompress_method(const unsigned char *inbuf, int len,
-+                              const char **name)
-+{
-+      const struct compress_format *cf;
-+
-+      if (len < 2)
-+              return NULL;    /* Need at least this much... */
-+
-+      for (cf = compressed_formats; cf->name; cf++) {
-+              if (!memcmp(inbuf, cf->magic, 2))
-+                      break;
-+
-+      }
-+      if (name)
-+              *name = cf->name;
-+      return cf->decompressor;
-+}
-diff --git a/lib/decompress_bunzip2.c b/lib/decompress_bunzip2.c
-new file mode 100644
-index 0000000..5d3ddb5
---- /dev/null
-+++ b/lib/decompress_bunzip2.c
-@@ -0,0 +1,735 @@
-+/* vi: set sw = 4 ts = 4: */
-+/*    Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
-+
-+      Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
-+      which also acknowledges contributions by Mike Burrows, David Wheeler,
-+      Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
-+      Robert Sedgewick, and Jon L. Bentley.
-+
-+      This code is licensed under the LGPLv2:
-+              LGPL (http://www.gnu.org/copyleft/lgpl.html
-+*/
-+
-+/*
-+      Size and speed optimizations by Manuel Novoa III  (mjn3@codepoet.org).
-+
-+      More efficient reading of Huffman codes, a streamlined read_bunzip()
-+      function, and various other tweaks.  In (limited) tests, approximately
-+      20% faster than bzcat on x86 and about 10% faster on arm.
-+
-+      Note that about 2/3 of the time is spent in read_unzip() reversing
-+      the Burrows-Wheeler transformation.  Much of that time is delay
-+      resulting from cache misses.
-+
-+      I would ask that anyone benefiting from this work, especially those
-+      using it in commercial products, consider making a donation to my local
-+      non-profit hospice organization in the name of the woman I loved, who
-+      passed away Feb. 12, 2003.
-+
-+              In memory of Toni W. Hagan
-+
-+              Hospice of Acadiana, Inc.
-+              2600 Johnston St., Suite 200
-+              Lafayette, LA 70503-3240
-+
-+              Phone (337) 232-1234 or 1-800-738-2226
-+              Fax   (337) 232-1297
-+
-+              http://www.hospiceacadiana.com/
-+
-+      Manuel
-+ */
-+
-+/*
-+      Made it fit for running in Linux Kernel by Alain Knaff (alain@knaff.lu)
-+*/
-+
-+
-+#ifndef STATIC
-+#include <linux/decompress/bunzip2.h>
-+#endif /* !STATIC */
-+
-+#include <linux/decompress/mm.h>
-+
-+#ifndef INT_MAX
-+#define INT_MAX 0x7fffffff
-+#endif
-+
-+/* Constants for Huffman coding */
-+#define MAX_GROUPS            6
-+#define GROUP_SIZE            50      /* 64 would have been more efficient */
-+#define MAX_HUFCODE_BITS      20      /* Longest Huffman code allowed */
-+#define MAX_SYMBOLS           258     /* 256 literals + RUNA + RUNB */
-+#define SYMBOL_RUNA           0
-+#define SYMBOL_RUNB           1
-+
-+/* Status return values */
-+#define RETVAL_OK                     0
-+#define RETVAL_LAST_BLOCK             (-1)
-+#define RETVAL_NOT_BZIP_DATA          (-2)
-+#define RETVAL_UNEXPECTED_INPUT_EOF   (-3)
-+#define RETVAL_UNEXPECTED_OUTPUT_EOF  (-4)
-+#define RETVAL_DATA_ERROR             (-5)
-+#define RETVAL_OUT_OF_MEMORY          (-6)
-+#define RETVAL_OBSOLETE_INPUT         (-7)
-+
-+/* Other housekeeping constants */
-+#define BZIP2_IOBUF_SIZE              4096
-+
-+/* This is what we know about each Huffman coding group */
-+struct group_data {
-+      /* We have an extra slot at the end of limit[] for a sentinal value. */
-+      int limit[MAX_HUFCODE_BITS+1];
-+      int base[MAX_HUFCODE_BITS];
-+      int permute[MAX_SYMBOLS];
-+      int minLen, maxLen;
-+};
-+
-+/* Structure holding all the housekeeping data, including IO buffers and
-+   memory that persists between calls to bunzip */
-+struct bunzip_data {
-+      /* State for interrupting output loop */
-+      int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent;
-+      /* I/O tracking data (file handles, buffers, positions, etc.) */
-+      int (*fill)(void*, unsigned int);
-+      int inbufCount, inbufPos /*, outbufPos*/;
-+      unsigned char *inbuf /*,*outbuf*/;
-+      unsigned int inbufBitCount, inbufBits;
-+      /* The CRC values stored in the block header and calculated from the
-+      data */
-+      unsigned int crc32Table[256], headerCRC, totalCRC, writeCRC;
-+      /* Intermediate buffer and its size (in bytes) */
-+      unsigned int *dbuf, dbufSize;
-+      /* These things are a bit too big to go on the stack */
-+      unsigned char selectors[32768];         /* nSelectors = 15 bits */
-+      struct group_data groups[MAX_GROUPS];   /* Huffman coding tables */
-+      int io_error;                   /* non-zero if we have IO error */
-+};
-+
-+
-+/* Return the next nnn bits of input.  All reads from the compressed input
-+   are done through this function.  All reads are big endian */
-+static unsigned int INIT get_bits(struct bunzip_data *bd, char bits_wanted)
-+{
-+      unsigned int bits = 0;
-+
-+      /* If we need to get more data from the byte buffer, do so.
-+         (Loop getting one byte at a time to enforce endianness and avoid
-+         unaligned access.) */
-+      while (bd->inbufBitCount < bits_wanted) {
-+              /* If we need to read more data from file into byte buffer, do
-+                 so */
-+              if (bd->inbufPos == bd->inbufCount) {
-+                      if (bd->io_error)
-+                              return 0;
-+                      bd->inbufCount = bd->fill(bd->inbuf, BZIP2_IOBUF_SIZE);
-+                      if (bd->inbufCount <= 0) {
-+                              bd->io_error = RETVAL_UNEXPECTED_INPUT_EOF;
-+                              return 0;
-+                      }
-+                      bd->inbufPos = 0;
-+              }
-+              /* Avoid 32-bit overflow (dump bit buffer to top of output) */
-+              if (bd->inbufBitCount >= 24) {
-+                      bits = bd->inbufBits&((1 << bd->inbufBitCount)-1);
-+                      bits_wanted -= bd->inbufBitCount;
-+                      bits <<= bits_wanted;
-+                      bd->inbufBitCount = 0;
-+              }
-+              /* Grab next 8 bits of input from buffer. */
-+              bd->inbufBits = (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++];
-+              bd->inbufBitCount += 8;
-+      }
-+      /* Calculate result */
-+      bd->inbufBitCount -= bits_wanted;
-+      bits |= (bd->inbufBits >> bd->inbufBitCount)&((1 << bits_wanted)-1);
-+
-+      return bits;
-+}
-+
-+/* Unpacks the next block and sets up for the inverse burrows-wheeler step. */
-+
-+static int INIT get_next_block(struct bunzip_data *bd)
-+{
-+      struct group_data *hufGroup = NULL;
-+      int *base = NULL;
-+      int *limit = NULL;
-+      int dbufCount, nextSym, dbufSize, groupCount, selector,
-+              i, j, k, t, runPos, symCount, symTotal, nSelectors,
-+              byteCount[256];
-+      unsigned char uc, symToByte[256], mtfSymbol[256], *selectors;
-+      unsigned int *dbuf, origPtr;
-+
-+      dbuf = bd->dbuf;
-+      dbufSize = bd->dbufSize;
-+      selectors = bd->selectors;
-+
-+      /* Read in header signature and CRC, then validate signature.
-+         (last block signature means CRC is for whole file, return now) */
-+      i = get_bits(bd, 24);
-+      j = get_bits(bd, 24);
-+      bd->headerCRC = get_bits(bd, 32);
-+      if ((i == 0x177245) && (j == 0x385090))
-+              return RETVAL_LAST_BLOCK;
-+      if ((i != 0x314159) || (j != 0x265359))
-+              return RETVAL_NOT_BZIP_DATA;
-+      /* We can add support for blockRandomised if anybody complains.
-+         There was some code for this in busybox 1.0.0-pre3, but nobody ever
-+         noticed that it didn't actually work. */
-+      if (get_bits(bd, 1))
-+              return RETVAL_OBSOLETE_INPUT;
-+      origPtr = get_bits(bd, 24);
-+      if (origPtr > dbufSize)
-+              return RETVAL_DATA_ERROR;
-+      /* mapping table: if some byte values are never used (encoding things
-+         like ascii text), the compression code removes the gaps to have fewer
-+         symbols to deal with, and writes a sparse bitfield indicating which
-+         values were present.  We make a translation table to convert the
-+         symbols back to the corresponding bytes. */
-+      t = get_bits(bd, 16);
-+      symTotal = 0;
-+      for (i = 0; i < 16; i++) {
-+              if (t&(1 << (15-i))) {
-+                      k = get_bits(bd, 16);
-+                      for (j = 0; j < 16; j++)
-+                              if (k&(1 << (15-j)))
-+                                      symToByte[symTotal++] = (16*i)+j;
-+              }
-+      }
-+      /* How many different Huffman coding groups does this block use? */
-+      groupCount = get_bits(bd, 3);
-+      if (groupCount < 2 || groupCount > MAX_GROUPS)
-+              return RETVAL_DATA_ERROR;
-+      /* nSelectors: Every GROUP_SIZE many symbols we select a new
-+         Huffman coding group.  Read in the group selector list,
-+         which is stored as MTF encoded bit runs.  (MTF = Move To
-+         Front, as each value is used it's moved to the start of the
-+         list.) */
-+      nSelectors = get_bits(bd, 15);
-+      if (!nSelectors)
-+              return RETVAL_DATA_ERROR;
-+      for (i = 0; i < groupCount; i++)
-+              mtfSymbol[i] = i;
-+      for (i = 0; i < nSelectors; i++) {
-+              /* Get next value */
-+              for (j = 0; get_bits(bd, 1); j++)
-+                      if (j >= groupCount)
-+                              return RETVAL_DATA_ERROR;
-+              /* Decode MTF to get the next selector */
-+              uc = mtfSymbol[j];
-+              for (; j; j--)
-+                      mtfSymbol[j] = mtfSymbol[j-1];
-+              mtfSymbol[0] = selectors[i] = uc;
-+      }
-+      /* Read the Huffman coding tables for each group, which code
-+         for symTotal literal symbols, plus two run symbols (RUNA,
-+         RUNB) */
-+      symCount = symTotal+2;
-+      for (j = 0; j < groupCount; j++) {
-+              unsigned char length[MAX_SYMBOLS], temp[MAX_HUFCODE_BITS+1];
-+              int     minLen, maxLen, pp;
-+              /* Read Huffman code lengths for each symbol.  They're
-+                 stored in a way similar to mtf; record a starting
-+                 value for the first symbol, and an offset from the
-+                 previous value for everys symbol after that.
-+                 (Subtracting 1 before the loop and then adding it
-+                 back at the end is an optimization that makes the
-+                 test inside the loop simpler: symbol length 0
-+                 becomes negative, so an unsigned inequality catches
-+                 it.) */
-+              t = get_bits(bd, 5)-1;
-+              for (i = 0; i < symCount; i++) {
-+                      for (;;) {
-+                              if (((unsigned)t) > (MAX_HUFCODE_BITS-1))
-+                                      return RETVAL_DATA_ERROR;
-+
-+                              /* If first bit is 0, stop.  Else
-+                                 second bit indicates whether to
-+                                 increment or decrement the value.
-+                                 Optimization: grab 2 bits and unget
-+                                 the second if the first was 0. */
-+
-+                              k = get_bits(bd, 2);
-+                              if (k < 2) {
-+                                      bd->inbufBitCount++;
-+                                      break;
-+                              }
-+                              /* Add one if second bit 1, else
-+                               * subtract 1.  Avoids if/else */
-+                              t += (((k+1)&2)-1);
-+                      }
-+                      /* Correct for the initial -1, to get the
-+                       * final symbol length */
-+                      length[i] = t+1;
-+              }
-+              /* Find largest and smallest lengths in this group */
-+              minLen = maxLen = length[0];
-+
-+              for (i = 1; i < symCount; i++) {
-+                      if (length[i] > maxLen)
-+                              maxLen = length[i];
-+                      else if (length[i] < minLen)
-+                              minLen = length[i];
-+              }
-+
-+              /* Calculate permute[], base[], and limit[] tables from
-+               * length[].
-+               *
-+               * permute[] is the lookup table for converting
-+               * Huffman coded symbols into decoded symbols.  base[]
-+               * is the amount to subtract from the value of a
-+               * Huffman symbol of a given length when using
-+               * permute[].
-+               *
-+               * limit[] indicates the largest numerical value a
-+               * symbol with a given number of bits can have.  This
-+               * is how the Huffman codes can vary in length: each
-+               * code with a value > limit[length] needs another
-+               * bit.
-+               */
-+              hufGroup = bd->groups+j;
-+              hufGroup->minLen = minLen;
-+              hufGroup->maxLen = maxLen;
-+              /* Note that minLen can't be smaller than 1, so we
-+                 adjust the base and limit array pointers so we're
-+                 not always wasting the first entry.  We do this
-+                 again when using them (during symbol decoding).*/
-+              base = hufGroup->base-1;
-+              limit = hufGroup->limit-1;
-+              /* Calculate permute[].  Concurently, initialize
-+               * temp[] and limit[]. */
-+              pp = 0;
-+              for (i = minLen; i <= maxLen; i++) {
-+                      temp[i] = limit[i] = 0;
-+                      for (t = 0; t < symCount; t++)
-+                              if (length[t] == i)
-+                                      hufGroup->permute[pp++] = t;
-+              }
-+              /* Count symbols coded for at each bit length */
-+              for (i = 0; i < symCount; i++)
-+                      temp[length[i]]++;
-+              /* Calculate limit[] (the largest symbol-coding value
-+               *at each bit length, which is (previous limit <<
-+               *1)+symbols at this level), and base[] (number of
-+               *symbols to ignore at each bit length, which is limit
-+               *minus the cumulative count of symbols coded for
-+               *already). */
-+              pp = t = 0;
-+              for (i = minLen; i < maxLen; i++) {
-+                      pp += temp[i];
-+                      /* We read the largest possible symbol size
-+                         and then unget bits after determining how
-+                         many we need, and those extra bits could be
-+                         set to anything.  (They're noise from
-+                         future symbols.)  At each level we're
-+                         really only interested in the first few
-+                         bits, so here we set all the trailing
-+                         to-be-ignored bits to 1 so they don't
-+                         affect the value > limit[length]
-+                         comparison. */
-+                      limit[i] = (pp << (maxLen - i)) - 1;
-+                      pp <<= 1;
-+                      base[i+1] = pp-(t += temp[i]);
-+              }
-+              limit[maxLen+1] = INT_MAX; /* Sentinal value for
-+                                          * reading next sym. */
-+              limit[maxLen] = pp+temp[maxLen]-1;
-+              base[minLen] = 0;
-+      }
-+      /* We've finished reading and digesting the block header.  Now
-+         read this block's Huffman coded symbols from the file and
-+         undo the Huffman coding and run length encoding, saving the
-+         result into dbuf[dbufCount++] = uc */
-+
-+      /* Initialize symbol occurrence counters and symbol Move To
-+       * Front table */
-+      for (i = 0; i < 256; i++) {
-+              byteCount[i] = 0;
-+              mtfSymbol[i] = (unsigned char)i;
-+      }
-+      /* Loop through compressed symbols. */
-+      runPos = dbufCount = symCount = selector = 0;
-+      for (;;) {
-+              /* Determine which Huffman coding group to use. */
-+              if (!(symCount--)) {
-+                      symCount = GROUP_SIZE-1;
-+                      if (selector >= nSelectors)
-+                              return RETVAL_DATA_ERROR;
-+                      hufGroup = bd->groups+selectors[selector++];
-+                      base = hufGroup->base-1;
-+                      limit = hufGroup->limit-1;
-+              }
-+              /* Read next Huffman-coded symbol. */
-+              /* Note: It is far cheaper to read maxLen bits and
-+                 back up than it is to read minLen bits and then an
-+                 additional bit at a time, testing as we go.
-+                 Because there is a trailing last block (with file
-+                 CRC), there is no danger of the overread causing an
-+                 unexpected EOF for a valid compressed file.  As a
-+                 further optimization, we do the read inline
-+                 (falling back to a call to get_bits if the buffer
-+                 runs dry).  The following (up to got_huff_bits:) is
-+                 equivalent to j = get_bits(bd, hufGroup->maxLen);
-+               */
-+              while (bd->inbufBitCount < hufGroup->maxLen) {
-+                      if (bd->inbufPos == bd->inbufCount) {
-+                              j = get_bits(bd, hufGroup->maxLen);
-+                              goto got_huff_bits;
-+                      }
-+                      bd->inbufBits =
-+                              (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++];
-+                      bd->inbufBitCount += 8;
-+              };
-+              bd->inbufBitCount -= hufGroup->maxLen;
-+              j = (bd->inbufBits >> bd->inbufBitCount)&
-+                      ((1 << hufGroup->maxLen)-1);
-+got_huff_bits:
-+              /* Figure how how many bits are in next symbol and
-+               * unget extras */
-+              i = hufGroup->minLen;
-+              while (j > limit[i])
-+                      ++i;
-+              bd->inbufBitCount += (hufGroup->maxLen - i);
-+              /* Huffman decode value to get nextSym (with bounds checking) */
-+              if ((i > hufGroup->maxLen)
-+                      || (((unsigned)(j = (j>>(hufGroup->maxLen-i))-base[i]))
-+                              >= MAX_SYMBOLS))
-+                      return RETVAL_DATA_ERROR;
-+              nextSym = hufGroup->permute[j];
-+              /* We have now decoded the symbol, which indicates
-+                 either a new literal byte, or a repeated run of the
-+                 most recent literal byte.  First, check if nextSym
-+                 indicates a repeated run, and if so loop collecting
-+                 how many times to repeat the last literal. */
-+              if (((unsigned)nextSym) <= SYMBOL_RUNB) { /* RUNA or RUNB */
-+                      /* If this is the start of a new run, zero out
-+                       * counter */
-+                      if (!runPos) {
-+                              runPos = 1;
-+                              t = 0;
-+                      }
-+                      /* Neat trick that saves 1 symbol: instead of
-+                         or-ing 0 or 1 at each bit position, add 1
-+                         or 2 instead.  For example, 1011 is 1 << 0
-+                         + 1 << 1 + 2 << 2.  1010 is 2 << 0 + 2 << 1
-+                         + 1 << 2.  You can make any bit pattern
-+                         that way using 1 less symbol than the basic
-+                         or 0/1 method (except all bits 0, which
-+                         would use no symbols, but a run of length 0
-+                         doesn't mean anything in this context).
-+                         Thus space is saved. */
-+                      t += (runPos << nextSym);
-+                      /* +runPos if RUNA; +2*runPos if RUNB */
-+
-+                      runPos <<= 1;
-+                      continue;
-+              }
-+              /* When we hit the first non-run symbol after a run,
-+                 we now know how many times to repeat the last
-+                 literal, so append that many copies to our buffer
-+                 of decoded symbols (dbuf) now.  (The last literal
-+                 used is the one at the head of the mtfSymbol
-+                 array.) */
-+              if (runPos) {
-+                      runPos = 0;
-+                      if (dbufCount+t >= dbufSize)
-+                              return RETVAL_DATA_ERROR;
-+
-+                      uc = symToByte[mtfSymbol[0]];
-+                      byteCount[uc] += t;
-+                      while (t--)
-+                              dbuf[dbufCount++] = uc;
-+              }
-+              /* Is this the terminating symbol? */
-+              if (nextSym > symTotal)
-+                      break;
-+              /* At this point, nextSym indicates a new literal
-+                 character.  Subtract one to get the position in the
-+                 MTF array at which this literal is currently to be
-+                 found.  (Note that the result can't be -1 or 0,
-+                 because 0 and 1 are RUNA and RUNB.  But another
-+                 instance of the first symbol in the mtf array,
-+                 position 0, would have been handled as part of a
-+                 run above.  Therefore 1 unused mtf position minus 2
-+                 non-literal nextSym values equals -1.) */
-+              if (dbufCount >= dbufSize)
-+                      return RETVAL_DATA_ERROR;
-+              i = nextSym - 1;
-+              uc = mtfSymbol[i];
-+              /* Adjust the MTF array.  Since we typically expect to
-+               *move only a small number of symbols, and are bound
-+               *by 256 in any case, using memmove here would
-+               *typically be bigger and slower due to function call
-+               *overhead and other assorted setup costs. */
-+              do {
-+                      mtfSymbol[i] = mtfSymbol[i-1];
-+              } while (--i);
-+              mtfSymbol[0] = uc;
-+              uc = symToByte[uc];
-+              /* We have our literal byte.  Save it into dbuf. */
-+              byteCount[uc]++;
-+              dbuf[dbufCount++] = (unsigned int)uc;
-+      }
-+      /* At this point, we've read all the Huffman-coded symbols
-+         (and repeated runs) for this block from the input stream,
-+         and decoded them into the intermediate buffer.  There are
-+         dbufCount many decoded bytes in dbuf[].  Now undo the
-+         Burrows-Wheeler transform on dbuf.  See
-+         http://dogma.net/markn/articles/bwt/bwt.htm
-+       */
-+      /* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
-+      j = 0;
-+      for (i = 0; i < 256; i++) {
-+              k = j+byteCount[i];
-+              byteCount[i] = j;
-+              j = k;
-+      }
-+      /* Figure out what order dbuf would be in if we sorted it. */
-+      for (i = 0; i < dbufCount; i++) {
-+              uc = (unsigned char)(dbuf[i] & 0xff);
-+              dbuf[byteCount[uc]] |= (i << 8);
-+              byteCount[uc]++;
-+      }
-+      /* Decode first byte by hand to initialize "previous" byte.
-+         Note that it doesn't get output, and if the first three
-+         characters are identical it doesn't qualify as a run (hence
-+         writeRunCountdown = 5). */
-+      if (dbufCount) {
-+              if (origPtr >= dbufCount)
-+                      return RETVAL_DATA_ERROR;
-+              bd->writePos = dbuf[origPtr];
-+              bd->writeCurrent = (unsigned char)(bd->writePos&0xff);
-+              bd->writePos >>= 8;
-+              bd->writeRunCountdown = 5;
-+      }
-+      bd->writeCount = dbufCount;
-+
-+      return RETVAL_OK;
-+}
-+
-+/* Undo burrows-wheeler transform on intermediate buffer to produce output.
-+   If start_bunzip was initialized with out_fd =-1, then up to len bytes of
-+   data are written to outbuf.  Return value is number of bytes written or
-+   error (all errors are negative numbers).  If out_fd!=-1, outbuf and len
-+   are ignored, data is written to out_fd and return is RETVAL_OK or error.
-+*/
-+
-+static int INIT read_bunzip(struct bunzip_data *bd, char *outbuf, int len)
-+{
-+      const unsigned int *dbuf;
-+      int pos, xcurrent, previous, gotcount;
-+
-+      /* If last read was short due to end of file, return last block now */
-+      if (bd->writeCount < 0)
-+              return bd->writeCount;
-+
-+      gotcount = 0;
-+      dbuf = bd->dbuf;
-+      pos = bd->writePos;
-+      xcurrent = bd->writeCurrent;
-+
-+      /* We will always have pending decoded data to write into the output
-+         buffer unless this is the very first call (in which case we haven't
-+         Huffman-decoded a block into the intermediate buffer yet). */
-+
-+      if (bd->writeCopies) {
-+              /* Inside the loop, writeCopies means extra copies (beyond 1) */
-+              --bd->writeCopies;
-+              /* Loop outputting bytes */
-+              for (;;) {
-+                      /* If the output buffer is full, snapshot
-+                       * state and return */
-+                      if (gotcount >= len) {
-+                              bd->writePos = pos;
-+                              bd->writeCurrent = xcurrent;
-+                              bd->writeCopies++;
-+                              return len;
-+                      }
-+                      /* Write next byte into output buffer, updating CRC */
-+                      outbuf[gotcount++] = xcurrent;
-+                      bd->writeCRC = (((bd->writeCRC) << 8)
-+                              ^bd->crc32Table[((bd->writeCRC) >> 24)
-+                              ^xcurrent]);
-+                      /* Loop now if we're outputting multiple
-+                       * copies of this byte */
-+                      if (bd->writeCopies) {
-+                              --bd->writeCopies;
-+                              continue;
-+                      }
-+decode_next_byte:
-+                      if (!bd->writeCount--)
-+                              break;
-+                      /* Follow sequence vector to undo
-+                       * Burrows-Wheeler transform */
-+                      previous = xcurrent;
-+                      pos = dbuf[pos];
-+                      xcurrent = pos&0xff;
-+                      pos >>= 8;
-+                      /* After 3 consecutive copies of the same
-+                         byte, the 4th is a repeat count.  We count
-+                         down from 4 instead *of counting up because
-+                         testing for non-zero is faster */
-+                      if (--bd->writeRunCountdown) {
-+                              if (xcurrent != previous)
-+                                      bd->writeRunCountdown = 4;
-+                      } else {
-+                              /* We have a repeated run, this byte
-+                               * indicates the count */
-+                              bd->writeCopies = xcurrent;
-+                              xcurrent = previous;
-+                              bd->writeRunCountdown = 5;
-+                              /* Sometimes there are just 3 bytes
-+                               * (run length 0) */
-+                              if (!bd->writeCopies)
-+                                      goto decode_next_byte;
-+                              /* Subtract the 1 copy we'd output
-+                               * anyway to get extras */
-+                              --bd->writeCopies;
-+                      }
-+              }
-+              /* Decompression of this block completed successfully */
-+              bd->writeCRC = ~bd->writeCRC;
-+              bd->totalCRC = ((bd->totalCRC << 1) |
-+                              (bd->totalCRC >> 31)) ^ bd->writeCRC;
-+              /* If this block had a CRC error, force file level CRC error. */
-+              if (bd->writeCRC != bd->headerCRC) {
-+                      bd->totalCRC = bd->headerCRC+1;
-+                      return RETVAL_LAST_BLOCK;
-+              }
-+      }
-+
-+      /* Refill the intermediate buffer by Huffman-decoding next
-+       * block of input */
-+      /* (previous is just a convenient unused temp variable here) */
-+      previous = get_next_block(bd);
-+      if (previous) {
-+              bd->writeCount = previous;
-+              return (previous != RETVAL_LAST_BLOCK) ? previous : gotcount;
-+      }
-+      bd->writeCRC = 0xffffffffUL;
-+      pos = bd->writePos;
-+      xcurrent = bd->writeCurrent;
-+      goto decode_next_byte;
-+}
-+
-+static int INIT nofill(void *buf, unsigned int len)
-+{
-+      return -1;
-+}
-+
-+/* Allocate the structure, read file header.  If in_fd ==-1, inbuf must contain
-+   a complete bunzip file (len bytes long).  If in_fd!=-1, inbuf and len are
-+   ignored, and data is read from file handle into temporary buffer. */
-+static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len,
-+                           int (*fill)(void*, unsigned int))
-+{
-+      struct bunzip_data *bd;
-+      unsigned int i, j, c;
-+      const unsigned int BZh0 =
-+              (((unsigned int)'B') << 24)+(((unsigned int)'Z') << 16)
-+              +(((unsigned int)'h') << 8)+(unsigned int)'0';
-+
-+      /* Figure out how much data to allocate */
-+      i = sizeof(struct bunzip_data);
-+
-+      /* Allocate bunzip_data.  Most fields initialize to zero. */
-+      bd = *bdp = malloc(i);
-+      memset(bd, 0, sizeof(struct bunzip_data));
-+      /* Setup input buffer */
-+      bd->inbuf = inbuf;
-+      bd->inbufCount = len;
-+      if (fill != NULL)
-+              bd->fill = fill;
-+      else
-+              bd->fill = nofill;
-+
-+      /* Init the CRC32 table (big endian) */
-+      for (i = 0; i < 256; i++) {
-+              c = i << 24;
-+              for (j = 8; j; j--)
-+                      c = c&0x80000000 ? (c << 1)^0x04c11db7 : (c << 1);
-+              bd->crc32Table[i] = c;
-+      }
-+
-+      /* Ensure that file starts with "BZh['1'-'9']." */
-+      i = get_bits(bd, 32);
-+      if (((unsigned int)(i-BZh0-1)) >= 9)
-+              return RETVAL_NOT_BZIP_DATA;
-+
-+      /* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of
-+         uncompressed data.  Allocate intermediate buffer for block. */
-+      bd->dbufSize = 100000*(i-BZh0);
-+
-+      bd->dbuf = large_malloc(bd->dbufSize * sizeof(int));
-+      return RETVAL_OK;
-+}
-+
-+/* Example usage: decompress src_fd to dst_fd.  (Stops at end of bzip2 data,
-+   not end of file.) */
-+STATIC int INIT bunzip2(unsigned char *buf, int len,
-+                      int(*fill)(void*, unsigned int),
-+                      int(*flush)(void*, unsigned int),
-+                      unsigned char *outbuf,
-+                      int *pos,
-+                      void(*error_fn)(char *x))
-+{
-+      struct bunzip_data *bd;
-+      int i = -1;
-+      unsigned char *inbuf;
-+
-+      set_error_fn(error_fn);
-+      if (flush)
-+              outbuf = malloc(BZIP2_IOBUF_SIZE);
-+      else
-+              len -= 4; /* Uncompressed size hack active in pre-boot
-+                           environment */
-+      if (!outbuf) {
-+              error("Could not allocate output bufer");
-+              return -1;
-+      }
-+      if (buf)
-+              inbuf = buf;
-+      else
-+              inbuf = malloc(BZIP2_IOBUF_SIZE);
-+      if (!inbuf) {
-+              error("Could not allocate input bufer");
-+              goto exit_0;
-+      }
-+      i = start_bunzip(&bd, inbuf, len, fill);
-+      if (!i) {
-+              for (;;) {
-+                      i = read_bunzip(bd, outbuf, BZIP2_IOBUF_SIZE);
-+                      if (i <= 0)
-+                              break;
-+                      if (!flush)
-+                              outbuf += i;
-+                      else
-+                              if (i != flush(outbuf, i)) {
-+                                      i = RETVAL_UNEXPECTED_OUTPUT_EOF;
-+                                      break;
-+                              }
-+              }
-+      }
-+      /* Check CRC and release memory */
-+      if (i == RETVAL_LAST_BLOCK) {
-+              if (bd->headerCRC != bd->totalCRC)
-+                      error("Data integrity error when decompressing.");
-+              else
-+                      i = RETVAL_OK;
-+      } else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) {
-+              error("Compressed file ends unexpectedly");
-+      }
-+      if (bd->dbuf)
-+              large_free(bd->dbuf);
-+      if (pos)
-+              *pos = bd->inbufPos;
-+      free(bd);
-+      if (!buf)
-+              free(inbuf);
-+exit_0:
-+      if (flush)
-+              free(outbuf);
-+      return i;
-+}
-+
-+#define decompress bunzip2
-diff --git a/lib/decompress_inflate.c b/lib/decompress_inflate.c
-new file mode 100644
-index 0000000..839a329
---- /dev/null
-+++ b/lib/decompress_inflate.c
-@@ -0,0 +1,167 @@
-+#ifdef STATIC
-+/* Pre-boot environment: included */
-+
-+/* prevent inclusion of _LINUX_KERNEL_H in pre-boot environment: lots
-+ * errors about console_printk etc... on ARM */
-+#define _LINUX_KERNEL_H
-+
-+#include "zlib_inflate/inftrees.c"
-+#include "zlib_inflate/inffast.c"
-+#include "zlib_inflate/inflate.c"
-+
-+#else /* STATIC */
-+/* initramfs et al: linked */
-+
-+#include <linux/zutil.h>
-+
-+#include "zlib_inflate/inftrees.h"
-+#include "zlib_inflate/inffast.h"
-+#include "zlib_inflate/inflate.h"
-+
-+#include "zlib_inflate/infutil.h"
-+
-+#endif /* STATIC */
-+
-+#include <linux/decompress/mm.h>
-+
-+#define INBUF_LEN (16*1024)
-+
-+/* Included from initramfs et al code */
-+STATIC int INIT gunzip(unsigned char *buf, int len,
-+                     int(*fill)(void*, unsigned int),
-+                     int(*flush)(void*, unsigned int),
-+                     unsigned char *out_buf,
-+                     int *pos,
-+                     void(*error_fn)(char *x)) {
-+      u8 *zbuf;
-+      struct z_stream_s *strm;
-+      int rc;
-+      size_t out_len;
-+
-+      set_error_fn(error_fn);
-+      rc = -1;
-+      if (flush) {
-+              out_len = 0x8000; /* 32 K */
-+              out_buf = malloc(out_len);
-+      } else {
-+              out_len = 0x7fffffff; /* no limit */
-+      }
-+      if (!out_buf) {
-+              error("Out of memory while allocating output buffer");
-+              goto gunzip_nomem1;
-+      }
-+
-+      if (buf)
-+              zbuf = buf;
-+      else {
-+              zbuf = malloc(INBUF_LEN);
-+              len = 0;
-+      }
-+      if (!zbuf) {
-+              error("Out of memory while allocating input buffer");
-+              goto gunzip_nomem2;
-+      }
-+
-+      strm = malloc(sizeof(*strm));
-+      if (strm == NULL) {
-+              error("Out of memory while allocating z_stream");
-+              goto gunzip_nomem3;
-+      }
-+
-+      strm->workspace = malloc(flush ? zlib_inflate_workspacesize() :
-+                               sizeof(struct inflate_state));
-+      if (strm->workspace == NULL) {
-+              error("Out of memory while allocating workspace");
-+              goto gunzip_nomem4;
-+      }
-+
-+      if (len == 0)
-+              len = fill(zbuf, INBUF_LEN);
-+
-+      /* verify the gzip header */
-+      if (len < 10 ||
-+         zbuf[0] != 0x1f || zbuf[1] != 0x8b || zbuf[2] != 0x08) {
-+              if (pos)
-+                      *pos = 0;
-+              error("Not a gzip file");
-+              goto gunzip_5;
-+      }
-+
-+      /* skip over gzip header (1f,8b,08... 10 bytes total +
-+       * possible asciz filename)
-+       */
-+      strm->next_in = zbuf + 10;
-+      /* skip over asciz filename */
-+      if (zbuf[3] & 0x8) {
-+              while (strm->next_in[0])
-+                      strm->next_in++;
-+              strm->next_in++;
-+      }
-+      strm->avail_in = len - (strm->next_in - zbuf);
-+
-+      strm->next_out = out_buf;
-+      strm->avail_out = out_len;
-+
-+      rc = zlib_inflateInit2(strm, -MAX_WBITS);
-+
-+      if (!flush) {
-+              WS(strm)->inflate_state.wsize = 0;
-+              WS(strm)->inflate_state.window = NULL;
-+      }
-+
-+      while (rc == Z_OK) {
-+              if (strm->avail_in == 0) {
-+                      /* TODO: handle case where both pos and fill are set */
-+                      len = fill(zbuf, INBUF_LEN);
-+                      if (len < 0) {
-+                              rc = -1;
-+                              error("read error");
-+                              break;
-+                      }
-+                      strm->next_in = zbuf;
-+                      strm->avail_in = len;
-+              }
-+              rc = zlib_inflate(strm, 0);
-+
-+              /* Write any data generated */
-+              if (flush && strm->next_out > out_buf) {
-+                      int l = strm->next_out - out_buf;
-+                      if (l != flush(out_buf, l)) {
-+                              rc = -1;
-+                              error("write error");
-+                              break;
-+                      }
-+                      strm->next_out = out_buf;
-+                      strm->avail_out = out_len;
-+              }
-+
-+              /* after Z_FINISH, only Z_STREAM_END is "we unpacked it all" */
-+              if (rc == Z_STREAM_END) {
-+                      rc = 0;
-+                      break;
-+              } else if (rc != Z_OK) {
-+                      error("uncompression error");
-+                      rc = -1;
-+              }
-+      }
-+
-+      zlib_inflateEnd(strm);
-+      if (pos)
-+              /* add + 8 to skip over trailer */
-+              *pos = strm->next_in - zbuf+8;
-+
-+gunzip_5:
-+      free(strm->workspace);
-+gunzip_nomem4:
-+      free(strm);
-+gunzip_nomem3:
-+      if (!buf)
-+              free(zbuf);
-+gunzip_nomem2:
-+      if (flush)
-+              free(out_buf);
-+gunzip_nomem1:
-+      return rc; /* returns Z_OK (0) if successful */
-+}
-+
-+#define decompress gunzip
-diff --git a/lib/decompress_unlzma.c b/lib/decompress_unlzma.c
-new file mode 100644
-index 0000000..546f2f4
---- /dev/null
-+++ b/lib/decompress_unlzma.c
-@@ -0,0 +1,647 @@
-+/* Lzma decompressor for Linux kernel. Shamelessly snarfed
-+ *from busybox 1.1.1
-+ *
-+ *Linux kernel adaptation
-+ *Copyright (C) 2006  Alain < alain@knaff.lu >
-+ *
-+ *Based on small lzma deflate implementation/Small range coder
-+ *implementation for lzma.
-+ *Copyright (C) 2006  Aurelien Jacobs < aurel@gnuage.org >
-+ *
-+ *Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
-+ *Copyright (C) 1999-2005  Igor Pavlov
-+ *
-+ *Copyrights of the parts, see headers below.
-+ *
-+ *
-+ *This program is free software; you can redistribute it and/or
-+ *modify it under the terms of the GNU Lesser General Public
-+ *License as published by the Free Software Foundation; either
-+ *version 2.1 of the License, or (at your option) any later version.
-+ *
-+ *This program is distributed in the hope that it will be useful,
-+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-+ *Lesser General Public License for more details.
-+ *
-+ *You should have received a copy of the GNU Lesser General Public
-+ *License along with this library; if not, write to the Free Software
-+ *Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-+ */
-+
-+#ifndef STATIC
-+#include <linux/decompress/unlzma.h>
-+#endif /* STATIC */
-+
-+#include <linux/decompress/mm.h>
-+
-+#define       MIN(a, b) (((a) < (b)) ? (a) : (b))
-+
-+static long long INIT read_int(unsigned char *ptr, int size)
-+{
-+      int i;
-+      long long ret = 0;
-+
-+      for (i = 0; i < size; i++)
-+              ret = (ret << 8) | ptr[size-i-1];
-+      return ret;
-+}
-+
-+#define ENDIAN_CONVERT(x) \
-+  x = (typeof(x))read_int((unsigned char *)&x, sizeof(x))
-+
-+
-+/* Small range coder implementation for lzma.
-+ *Copyright (C) 2006  Aurelien Jacobs < aurel@gnuage.org >
-+ *
-+ *Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
-+ *Copyright (c) 1999-2005  Igor Pavlov
-+ */
-+
-+#include <linux/compiler.h>
-+
-+#define LZMA_IOBUF_SIZE       0x10000
-+
-+struct rc {
-+      int (*fill)(void*, unsigned int);
-+      uint8_t *ptr;
-+      uint8_t *buffer;
-+      uint8_t *buffer_end;
-+      int buffer_size;
-+      uint32_t code;
-+      uint32_t range;
-+      uint32_t bound;
-+};
-+
-+
-+#define RC_TOP_BITS 24
-+#define RC_MOVE_BITS 5
-+#define RC_MODEL_TOTAL_BITS 11
-+
-+
-+/* Called twice: once at startup and once in rc_normalize() */
-+static void INIT rc_read(struct rc *rc)
-+{
-+      rc->buffer_size = rc->fill((char *)rc->buffer, LZMA_IOBUF_SIZE);
-+      if (rc->buffer_size <= 0)
-+              error("unexpected EOF");
-+      rc->ptr = rc->buffer;
-+      rc->buffer_end = rc->buffer + rc->buffer_size;
-+}
-+
-+/* Called once */
-+static inline void INIT rc_init(struct rc *rc,
-+                                     int (*fill)(void*, unsigned int),
-+                                     char *buffer, int buffer_size)
-+{
-+      rc->fill = fill;
-+      rc->buffer = (uint8_t *)buffer;
-+      rc->buffer_size = buffer_size;
-+      rc->buffer_end = rc->buffer + rc->buffer_size;
-+      rc->ptr = rc->buffer;
-+
-+      rc->code = 0;
-+      rc->range = 0xFFFFFFFF;
-+}
-+
-+static inline void INIT rc_init_code(struct rc *rc)
-+{
-+      int i;
-+
-+      for (i = 0; i < 5; i++) {
-+              if (rc->ptr >= rc->buffer_end)
-+                      rc_read(rc);
-+              rc->code = (rc->code << 8) | *rc->ptr++;
-+      }
-+}
-+
-+
-+/* Called once. TODO: bb_maybe_free() */
-+static inline void INIT rc_free(struct rc *rc)
-+{
-+      free(rc->buffer);
-+}
-+
-+/* Called twice, but one callsite is in inline'd rc_is_bit_0_helper() */
-+static void INIT rc_do_normalize(struct rc *rc)
-+{
-+      if (rc->ptr >= rc->buffer_end)
-+              rc_read(rc);
-+      rc->range <<= 8;
-+      rc->code = (rc->code << 8) | *rc->ptr++;
-+}
-+static inline void INIT rc_normalize(struct rc *rc)
-+{
-+      if (rc->range < (1 << RC_TOP_BITS))
-+              rc_do_normalize(rc);
-+}
-+
-+/* Called 9 times */
-+/* Why rc_is_bit_0_helper exists?
-+ *Because we want to always expose (rc->code < rc->bound) to optimizer
-+ */
-+static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p)
-+{
-+      rc_normalize(rc);
-+      rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
-+      return rc->bound;
-+}
-+static inline int INIT rc_is_bit_0(struct rc *rc, uint16_t *p)
-+{
-+      uint32_t t = rc_is_bit_0_helper(rc, p);
-+      return rc->code < t;
-+}
-+
-+/* Called ~10 times, but very small, thus inlined */
-+static inline void INIT rc_update_bit_0(struct rc *rc, uint16_t *p)
-+{
-+      rc->range = rc->bound;
-+      *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
-+}
-+static inline void rc_update_bit_1(struct rc *rc, uint16_t *p)
-+{
-+      rc->range -= rc->bound;
-+      rc->code -= rc->bound;
-+      *p -= *p >> RC_MOVE_BITS;
-+}
-+
-+/* Called 4 times in unlzma loop */
-+static int INIT rc_get_bit(struct rc *rc, uint16_t *p, int *symbol)
-+{
-+      if (rc_is_bit_0(rc, p)) {
-+              rc_update_bit_0(rc, p);
-+              *symbol *= 2;
-+              return 0;
-+      } else {
-+              rc_update_bit_1(rc, p);
-+              *symbol = *symbol * 2 + 1;
-+              return 1;
-+      }
-+}
-+
-+/* Called once */
-+static inline int INIT rc_direct_bit(struct rc *rc)
-+{
-+      rc_normalize(rc);
-+      rc->range >>= 1;
-+      if (rc->code >= rc->range) {
-+              rc->code -= rc->range;
-+              return 1;
-+      }
-+      return 0;
-+}
-+
-+/* Called twice */
-+static inline void INIT
-+rc_bit_tree_decode(struct rc *rc, uint16_t *p, int num_levels, int *symbol)
-+{
-+      int i = num_levels;
-+
-+      *symbol = 1;
-+      while (i--)
-+              rc_get_bit(rc, p + *symbol, symbol);
-+      *symbol -= 1 << num_levels;
-+}
-+
-+
-+/*
-+ * Small lzma deflate implementation.
-+ * Copyright (C) 2006  Aurelien Jacobs < aurel@gnuage.org >
-+ *
-+ * Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
-+ * Copyright (C) 1999-2005  Igor Pavlov
-+ */
-+
-+
-+struct lzma_header {
-+      uint8_t pos;
-+      uint32_t dict_size;
-+      uint64_t dst_size;
-+} __attribute__ ((packed)) ;
-+
-+
-+#define LZMA_BASE_SIZE 1846
-+#define LZMA_LIT_SIZE 768
-+
-+#define LZMA_NUM_POS_BITS_MAX 4
-+
-+#define LZMA_LEN_NUM_LOW_BITS 3
-+#define LZMA_LEN_NUM_MID_BITS 3
-+#define LZMA_LEN_NUM_HIGH_BITS 8
-+
-+#define LZMA_LEN_CHOICE 0
-+#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1)
-+#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1)
-+#define LZMA_LEN_MID (LZMA_LEN_LOW \
-+                    + (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS)))
-+#define LZMA_LEN_HIGH (LZMA_LEN_MID \
-+                     +(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS)))
-+#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS))
-+
-+#define LZMA_NUM_STATES 12
-+#define LZMA_NUM_LIT_STATES 7
-+
-+#define LZMA_START_POS_MODEL_INDEX 4
-+#define LZMA_END_POS_MODEL_INDEX 14
-+#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1))
-+
-+#define LZMA_NUM_POS_SLOT_BITS 6
-+#define LZMA_NUM_LEN_TO_POS_STATES 4
-+
-+#define LZMA_NUM_ALIGN_BITS 4
-+
-+#define LZMA_MATCH_MIN_LEN 2
-+
-+#define LZMA_IS_MATCH 0
-+#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
-+#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES)
-+#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES)
-+#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES)
-+#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES)
-+#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \
-+                     + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
-+#define LZMA_SPEC_POS (LZMA_POS_SLOT \
-+                     +(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS))
-+#define LZMA_ALIGN (LZMA_SPEC_POS \
-+                  + LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX)
-+#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS))
-+#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS)
-+#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS)
-+
-+
-+struct writer {
-+      uint8_t *buffer;
-+      uint8_t previous_byte;
-+      size_t buffer_pos;
-+      int bufsize;
-+      size_t global_pos;
-+      int(*flush)(void*, unsigned int);
-+      struct lzma_header *header;
-+};
-+
-+struct cstate {
-+      int state;
-+      uint32_t rep0, rep1, rep2, rep3;
-+};
-+
-+static inline size_t INIT get_pos(struct writer *wr)
-+{
-+      return
-+              wr->global_pos + wr->buffer_pos;
-+}
-+
-+static inline uint8_t INIT peek_old_byte(struct writer *wr,
-+                                              uint32_t offs)
-+{
-+      if (!wr->flush) {
-+              int32_t pos;
-+              while (offs > wr->header->dict_size)
-+                      offs -= wr->header->dict_size;
-+              pos = wr->buffer_pos - offs;
-+              return wr->buffer[pos];
-+      } else {
-+              uint32_t pos = wr->buffer_pos - offs;
-+              while (pos >= wr->header->dict_size)
-+                      pos += wr->header->dict_size;
-+              return wr->buffer[pos];
-+      }
-+
-+}
-+
-+static inline void INIT write_byte(struct writer *wr, uint8_t byte)
-+{
-+      wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte;
-+      if (wr->flush && wr->buffer_pos == wr->header->dict_size) {
-+              wr->buffer_pos = 0;
-+              wr->global_pos += wr->header->dict_size;
-+              wr->flush((char *)wr->buffer, wr->header->dict_size);
-+      }
-+}
-+
-+
-+static inline void INIT copy_byte(struct writer *wr, uint32_t offs)
-+{
-+      write_byte(wr, peek_old_byte(wr, offs));
-+}
-+
-+static inline void INIT copy_bytes(struct writer *wr,
-+                                       uint32_t rep0, int len)
-+{
-+      do {
-+              copy_byte(wr, rep0);
-+              len--;
-+      } while (len != 0 && wr->buffer_pos < wr->header->dst_size);
-+}
-+
-+static inline void INIT process_bit0(struct writer *wr, struct rc *rc,
-+                                   struct cstate *cst, uint16_t *p,
-+                                   int pos_state, uint16_t *prob,
-+                                   int lc, uint32_t literal_pos_mask) {
-+      int mi = 1;
-+      rc_update_bit_0(rc, prob);
-+      prob = (p + LZMA_LITERAL +
-+              (LZMA_LIT_SIZE
-+               * (((get_pos(wr) & literal_pos_mask) << lc)
-+                  + (wr->previous_byte >> (8 - lc))))
-+              );
-+
-+      if (cst->state >= LZMA_NUM_LIT_STATES) {
-+              int match_byte = peek_old_byte(wr, cst->rep0);
-+              do {
-+                      int bit;
-+                      uint16_t *prob_lit;
-+
-+                      match_byte <<= 1;
-+                      bit = match_byte & 0x100;
-+                      prob_lit = prob + 0x100 + bit + mi;
-+                      if (rc_get_bit(rc, prob_lit, &mi)) {
-+                              if (!bit)
-+                                      break;
-+                      } else {
-+                              if (bit)
-+                                      break;
-+                      }
-+              } while (mi < 0x100);
-+      }
-+      while (mi < 0x100) {
-+              uint16_t *prob_lit = prob + mi;
-+              rc_get_bit(rc, prob_lit, &mi);
-+      }
-+      write_byte(wr, mi);
-+      if (cst->state < 4)
-+              cst->state = 0;
-+      else if (cst->state < 10)
-+              cst->state -= 3;
-+      else
-+              cst->state -= 6;
-+}
-+
-+static inline void INIT process_bit1(struct writer *wr, struct rc *rc,
-+                                          struct cstate *cst, uint16_t *p,
-+                                          int pos_state, uint16_t *prob) {
-+  int offset;
-+      uint16_t *prob_len;
-+      int num_bits;
-+      int len;
-+
-+      rc_update_bit_1(rc, prob);
-+      prob = p + LZMA_IS_REP + cst->state;
-+      if (rc_is_bit_0(rc, prob)) {
-+              rc_update_bit_0(rc, prob);
-+              cst->rep3 = cst->rep2;
-+              cst->rep2 = cst->rep1;
-+              cst->rep1 = cst->rep0;
-+              cst->state = cst->state < LZMA_NUM_LIT_STATES ? 0 : 3;
-+              prob = p + LZMA_LEN_CODER;
-+      } else {
-+              rc_update_bit_1(rc, prob);
-+              prob = p + LZMA_IS_REP_G0 + cst->state;
-+              if (rc_is_bit_0(rc, prob)) {
-+                      rc_update_bit_0(rc, prob);
-+                      prob = (p + LZMA_IS_REP_0_LONG
-+                              + (cst->state <<
-+                                 LZMA_NUM_POS_BITS_MAX) +
-+                              pos_state);
-+                      if (rc_is_bit_0(rc, prob)) {
-+                              rc_update_bit_0(rc, prob);
-+
-+                              cst->state = cst->state < LZMA_NUM_LIT_STATES ?
-+                                      9 : 11;
-+                              copy_byte(wr, cst->rep0);
-+                              return;
-+                      } else {
-+                              rc_update_bit_1(rc, prob);
-+                      }
-+              } else {
-+                      uint32_t distance;
-+
-+                      rc_update_bit_1(rc, prob);
-+                      prob = p + LZMA_IS_REP_G1 + cst->state;
-+                      if (rc_is_bit_0(rc, prob)) {
-+                              rc_update_bit_0(rc, prob);
-+                              distance = cst->rep1;
-+                      } else {
-+                              rc_update_bit_1(rc, prob);
-+                              prob = p + LZMA_IS_REP_G2 + cst->state;
-+                              if (rc_is_bit_0(rc, prob)) {
-+                                      rc_update_bit_0(rc, prob);
-+                                      distance = cst->rep2;
-+                              } else {
-+                                      rc_update_bit_1(rc, prob);
-+                                      distance = cst->rep3;
-+                                      cst->rep3 = cst->rep2;
-+                              }
-+                              cst->rep2 = cst->rep1;
-+                      }
-+                      cst->rep1 = cst->rep0;
-+                      cst->rep0 = distance;
-+              }
-+              cst->state = cst->state < LZMA_NUM_LIT_STATES ? 8 : 11;
-+              prob = p + LZMA_REP_LEN_CODER;
-+      }
-+
-+      prob_len = prob + LZMA_LEN_CHOICE;
-+      if (rc_is_bit_0(rc, prob_len)) {
-+              rc_update_bit_0(rc, prob_len);
-+              prob_len = (prob + LZMA_LEN_LOW
-+                          + (pos_state <<
-+                             LZMA_LEN_NUM_LOW_BITS));
-+              offset = 0;
-+              num_bits = LZMA_LEN_NUM_LOW_BITS;
-+      } else {
-+              rc_update_bit_1(rc, prob_len);
-+              prob_len = prob + LZMA_LEN_CHOICE_2;
-+              if (rc_is_bit_0(rc, prob_len)) {
-+                      rc_update_bit_0(rc, prob_len);
-+                      prob_len = (prob + LZMA_LEN_MID
-+                                  + (pos_state <<
-+                                     LZMA_LEN_NUM_MID_BITS));
-+                      offset = 1 << LZMA_LEN_NUM_LOW_BITS;
-+                      num_bits = LZMA_LEN_NUM_MID_BITS;
-+              } else {
-+                      rc_update_bit_1(rc, prob_len);
-+                      prob_len = prob + LZMA_LEN_HIGH;
-+                      offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
-+                                + (1 << LZMA_LEN_NUM_MID_BITS));
-+                      num_bits = LZMA_LEN_NUM_HIGH_BITS;
-+              }
-+      }
-+
-+      rc_bit_tree_decode(rc, prob_len, num_bits, &len);
-+      len += offset;
-+
-+      if (cst->state < 4) {
-+              int pos_slot;
-+
-+              cst->state += LZMA_NUM_LIT_STATES;
-+              prob =
-+                      p + LZMA_POS_SLOT +
-+                      ((len <
-+                        LZMA_NUM_LEN_TO_POS_STATES ? len :
-+                        LZMA_NUM_LEN_TO_POS_STATES - 1)
-+                       << LZMA_NUM_POS_SLOT_BITS);
-+              rc_bit_tree_decode(rc, prob,
-+                                 LZMA_NUM_POS_SLOT_BITS,
-+                                 &pos_slot);
-+              if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
-+                      int i, mi;
-+                      num_bits = (pos_slot >> 1) - 1;
-+                      cst->rep0 = 2 | (pos_slot & 1);
-+                      if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
-+                              cst->rep0 <<= num_bits;
-+                              prob = p + LZMA_SPEC_POS +
-+                                      cst->rep0 - pos_slot - 1;
-+                      } else {
-+                              num_bits -= LZMA_NUM_ALIGN_BITS;
-+                              while (num_bits--)
-+                                      cst->rep0 = (cst->rep0 << 1) |
-+                                              rc_direct_bit(rc);
-+                              prob = p + LZMA_ALIGN;
-+                              cst->rep0 <<= LZMA_NUM_ALIGN_BITS;
-+                              num_bits = LZMA_NUM_ALIGN_BITS;
-+                      }
-+                      i = 1;
-+                      mi = 1;
-+                      while (num_bits--) {
-+                              if (rc_get_bit(rc, prob + mi, &mi))
-+                                      cst->rep0 |= i;
-+                              i <<= 1;
-+                      }
-+              } else
-+                      cst->rep0 = pos_slot;
-+              if (++(cst->rep0) == 0)
-+                      return;
-+      }
-+
-+      len += LZMA_MATCH_MIN_LEN;
-+
-+      copy_bytes(wr, cst->rep0, len);
-+}
-+
-+
-+
-+STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
-+                            int(*fill)(void*, unsigned int),
-+                            int(*flush)(void*, unsigned int),
-+                            unsigned char *output,
-+                            int *posp,
-+                            void(*error_fn)(char *x)
-+      )
-+{
-+      struct lzma_header header;
-+      int lc, pb, lp;
-+      uint32_t pos_state_mask;
-+      uint32_t literal_pos_mask;
-+      uint16_t *p;
-+      int num_probs;
-+      struct rc rc;
-+      int i, mi;
-+      struct writer wr;
-+      struct cstate cst;
-+      unsigned char *inbuf;
-+      int ret = -1;
-+
-+      set_error_fn(error_fn);
-+      if (!flush)
-+              in_len -= 4; /* Uncompressed size hack active in pre-boot
-+                              environment */
-+      if (buf)
-+              inbuf = buf;
-+      else
-+              inbuf = malloc(LZMA_IOBUF_SIZE);
-+      if (!inbuf) {
-+              error("Could not allocate input bufer");
-+              goto exit_0;
-+      }
-+
-+      cst.state = 0;
-+      cst.rep0 = cst.rep1 = cst.rep2 = cst.rep3 = 1;
-+
-+      wr.header = &header;
-+      wr.flush = flush;
-+      wr.global_pos = 0;
-+      wr.previous_byte = 0;
-+      wr.buffer_pos = 0;
-+
-+      rc_init(&rc, fill, inbuf, in_len);
-+
-+      for (i = 0; i < sizeof(header); i++) {
-+              if (rc.ptr >= rc.buffer_end)
-+                      rc_read(&rc);
-+              ((unsigned char *)&header)[i] = *rc.ptr++;
-+      }
-+
-+      if (header.pos >= (9 * 5 * 5))
-+              error("bad header");
-+
-+      mi = 0;
-+      lc = header.pos;
-+      while (lc >= 9) {
-+              mi++;
-+              lc -= 9;
-+      }
-+      pb = 0;
-+      lp = mi;
-+      while (lp >= 5) {
-+              pb++;
-+              lp -= 5;
-+      }
-+      pos_state_mask = (1 << pb) - 1;
-+      literal_pos_mask = (1 << lp) - 1;
-+
-+      ENDIAN_CONVERT(header.dict_size);
-+      ENDIAN_CONVERT(header.dst_size);
-+
-+      if (header.dict_size == 0)
-+              header.dict_size = 1;
-+
-+      if (output)
-+              wr.buffer = output;
-+      else {
-+              wr.bufsize = MIN(header.dst_size, header.dict_size);
-+              wr.buffer = large_malloc(wr.bufsize);
-+      }
-+      if (wr.buffer == NULL)
-+              goto exit_1;
-+
-+      num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
-+      p = (uint16_t *) large_malloc(num_probs * sizeof(*p));
-+      if (p == 0)
-+              goto exit_2;
-+      num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
-+      for (i = 0; i < num_probs; i++)
-+              p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
-+
-+      rc_init_code(&rc);
-+
-+      while (get_pos(&wr) < header.dst_size) {
-+              int pos_state = get_pos(&wr) & pos_state_mask;
-+              uint16_t *prob = p + LZMA_IS_MATCH +
-+                      (cst.state << LZMA_NUM_POS_BITS_MAX) + pos_state;
-+              if (rc_is_bit_0(&rc, prob))
-+                      process_bit0(&wr, &rc, &cst, p, pos_state, prob,
-+                                   lc, literal_pos_mask);
-+              else {
-+                      process_bit1(&wr, &rc, &cst, p, pos_state, prob);
-+                      if (cst.rep0 == 0)
-+                              break;
-+              }
-+      }
-+
-+      if (posp)
-+              *posp = rc.ptr-rc.buffer;
-+      if (wr.flush)
-+              wr.flush(wr.buffer, wr.buffer_pos);
-+      ret = 0;
-+      large_free(p);
-+exit_2:
-+      if (!output)
-+              large_free(wr.buffer);
-+exit_1:
-+      if (!buf)
-+              free(inbuf);
-+exit_0:
-+      return ret;
-+}
-+
-+#define decompress unlzma
-diff --git a/lib/zlib_inflate/inflate.h b/lib/zlib_inflate/inflate.h
-index df8a6c9..3d17b3d 100644
---- a/lib/zlib_inflate/inflate.h
-+++ b/lib/zlib_inflate/inflate.h
-@@ -1,3 +1,6 @@
-+#ifndef INFLATE_H
-+#define INFLATE_H
-+
- /* inflate.h -- internal inflate state definition
-  * Copyright (C) 1995-2004 Mark Adler
-  * For conditions of distribution and use, see copyright notice in zlib.h
-@@ -105,3 +108,4 @@ struct inflate_state {
-     unsigned short work[288];   /* work area for code table building */
-     code codes[ENOUGH];         /* space for code tables */
- };
-+#endif
-diff --git a/lib/zlib_inflate/inftrees.h b/lib/zlib_inflate/inftrees.h
-index 5f5219b..b70b473 100644
---- a/lib/zlib_inflate/inftrees.h
-+++ b/lib/zlib_inflate/inftrees.h
-@@ -1,3 +1,6 @@
-+#ifndef INFTREES_H
-+#define INFTREES_H
-+
- /* inftrees.h -- header to use inftrees.c
-  * Copyright (C) 1995-2005 Mark Adler
-  * For conditions of distribution and use, see copyright notice in zlib.h
-@@ -53,3 +56,4 @@ typedef enum {
- extern int zlib_inflate_table (codetype type, unsigned short *lens,
-                              unsigned codes, code **table,
-                              unsigned *bits, unsigned short *work);
-+#endif
-diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
-index e063657..3b949a3 100644
---- a/scripts/Makefile.lib
-+++ b/scripts/Makefile.lib
-@@ -186,3 +186,17 @@ quiet_cmd_gzip = GZIP    $@
- cmd_gzip = gzip -f -9 < $< > $@
-+# Bzip2
-+# ---------------------------------------------------------------------------
-+
-+# Bzip2 does not include size in file... so we have to fake that
-+size_append=$(CONFIG_SHELL) $(srctree)/scripts/bin_size
-+
-+quiet_cmd_bzip2 = BZIP2    $@
-+cmd_bzip2 = (bzip2 -9 < $< && $(size_append) $<) > $@ || (rm -f $@ ; false)
-+
-+# Lzma
-+# ---------------------------------------------------------------------------
-+
-+quiet_cmd_lzma = LZMA    $@
-+cmd_lzma = (lzma -9 -c $< && $(size_append) $<) >$@ || (rm -f $@ ; false)
-diff --git a/scripts/bin_size b/scripts/bin_size
-new file mode 100644
-index 0000000..43e1b36
---- /dev/null
-+++ b/scripts/bin_size
-@@ -0,0 +1,10 @@
-+#!/bin/sh
-+
-+if [ $# = 0 ] ; then
-+   echo Usage: $0 file
-+fi
-+
-+size_dec=`stat -c "%s" $1`
-+size_hex_echo_string=`printf "%08x" $size_dec |
-+     sed 's/\(..\)\(..\)\(..\)\(..\)/\\\\x\4\\\\x\3\\\\x\2\\\\x\1/g'`
-+/bin/echo -ne $size_hex_echo_string
-diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh
-index 5f3415f..3eea8f1 100644
---- a/scripts/gen_initramfs_list.sh
-+++ b/scripts/gen_initramfs_list.sh
-@@ -5,7 +5,7 @@
- # Released under the terms of the GNU GPL
- #
- # Generate a cpio packed initramfs. It uses gen_init_cpio to generate
--# the cpio archive, and gzip to pack it.
-+# the cpio archive, and then compresses it.
- # The script may also be used to generate the inputfile used for gen_init_cpio
- # This script assumes that gen_init_cpio is located in usr/ directory
-@@ -16,8 +16,8 @@ usage() {
- cat << EOF
- Usage:
- $0 [-o <file>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ...
--      -o <file>      Create gzipped initramfs file named <file> using
--                     gen_init_cpio and gzip
-+      -o <file>      Create compressed initramfs file named <file> using
-+                     gen_init_cpio and compressor depending on the extension
-       -u <uid>       User ID to map to user ID 0 (root).
-                      <uid> is only meaningful if <cpio_source> is a
-                      directory.  "squash" forces all files to uid 0.
-@@ -225,6 +225,7 @@ cpio_list=
- output="/dev/stdout"
- output_file=""
- is_cpio_compressed=
-+compr="gzip -9 -f"
- arg="$1"
- case "$arg" in
-@@ -233,11 +234,15 @@ case "$arg" in
-               echo "deps_initramfs := \\"
-               shift
-               ;;
--      "-o")   # generate gzipped cpio image named $1
-+      "-o")   # generate compressed cpio image named $1
-               shift
-               output_file="$1"
-               cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)"
-               output=${cpio_list}
-+              echo "$output_file" | grep -q "\.gz$" && compr="gzip -9 -f"
-+              echo "$output_file" | grep -q "\.bz2$" && compr="bzip2 -9 -f"
-+              echo "$output_file" | grep -q "\.lzma$" && compr="lzma -9 -f"
-+              echo "$output_file" | grep -q "\.cpio$" && compr="cat"
-               shift
-               ;;
- esac
-@@ -274,7 +279,7 @@ while [ $# -gt 0 ]; do
-       esac
- done
--# If output_file is set we will generate cpio archive and gzip it
-+# If output_file is set we will generate cpio archive and compress it
- # we are carefull to delete tmp files
- if [ ! -z ${output_file} ]; then
-       if [ -z ${cpio_file} ]; then
-@@ -287,7 +292,8 @@ if [ ! -z ${output_file} ]; then
-       if [ "${is_cpio_compressed}" = "compressed" ]; then
-               cat ${cpio_tfile} > ${output_file}
-       else
--              cat ${cpio_tfile} | gzip -f -9 - > ${output_file}
-+              (cat ${cpio_tfile} | ${compr}  - > ${output_file}) \
-+              || (rm -f ${output_file} ; false)
-       fi
-       [ -z ${cpio_file} ] && rm ${cpio_tfile}
- fi
-diff --git a/usr/Kconfig b/usr/Kconfig
-index 86cecb5..43a3a0f 100644
---- a/usr/Kconfig
-+++ b/usr/Kconfig
-@@ -44,3 +44,92 @@ config INITRAMFS_ROOT_GID
-         owned by group root in the initial ramdisk image.
-         If you are not sure, leave it set to "0".
-+
-+config RD_GZIP
-+      bool "Initial ramdisk compressed using gzip"
-+      default y
-+      depends on BLK_DEV_INITRD=y
-+      select DECOMPRESS_GZIP
-+      help
-+        Support loading of a gzip encoded initial ramdisk or cpio buffer.
-+        If unsure, say Y.
-+
-+config RD_BZIP2
-+      bool "Initial ramdisk compressed using bzip2"
-+      default n
-+      depends on BLK_DEV_INITRD=y
-+      select DECOMPRESS_BZIP2
-+      help
-+        Support loading of a bzip2 encoded initial ramdisk or cpio buffer
-+        If unsure, say N.
-+
-+config RD_LZMA
-+      bool "Initial ramdisk compressed using lzma"
-+      default n
-+      depends on BLK_DEV_INITRD=y
-+      select DECOMPRESS_LZMA
-+      help
-+        Support loading of a lzma encoded initial ramdisk or cpio buffer
-+        If unsure, say N.
-+
-+choice
-+      prompt "Built-in initramfs compression mode"
-+      help
-+        This setting is only meaningful if the INITRAMFS_SOURCE is
-+        set. It decides by which algorithm the INITRAMFS_SOURCE will
-+        be compressed.
-+        Several compression algorithms are available, which differ
-+        in efficiency, compression and decompression speed.
-+        Compression speed is only relevant when building a kernel.
-+        Decompression speed is relevant at each boot.
-+
-+        If you have any problems with bzip2 or lzma compressed
-+        initramfs, mail me (Alain Knaff) <alain@knaff.lu>.
-+
-+        High compression options are mostly useful for users who
-+        are low on disk space (embedded systems), but for whom ram
-+        size matters less.
-+
-+        If in doubt, select 'gzip'
-+
-+config INITRAMFS_COMPRESSION_NONE
-+      bool "None"
-+      help
-+        Do not compress the built-in initramfs at all. This may
-+        sound wasteful in space, but, you should be aware that the
-+        built-in initramfs will be compressed at a later stage
-+        anyways along with the rest of the kernel, on those
-+        architectures that support this.
-+        However, not compressing the initramfs may lead to slightly
-+        higher memory consumption during a short time at boot, while
-+        both the cpio image and the unpacked filesystem image will
-+        be present in memory simultaneously
-+
-+config INITRAMFS_COMPRESSION_GZIP
-+      bool "Gzip"
-+      depends on RD_GZIP
-+      help
-+        The old and tried gzip compression. Its compression ratio is
-+        the poorest among the 3 choices; however its speed (both
-+        compression and decompression) is the fastest.
-+
-+config INITRAMFS_COMPRESSION_BZIP2
-+      bool "Bzip2"
-+      depends on RD_BZIP2
-+      help
-+        Its compression ratio and speed is intermediate.
-+        Decompression speed is slowest among the three.  The initramfs
-+        size is about 10% smaller with bzip2, in comparison to gzip.
-+        Bzip2 uses a large amount of memory. For modern kernels you
-+        will need at least 8MB RAM or more for booting.
-+
-+config INITRAMFS_COMPRESSION_LZMA
-+      bool "LZMA"
-+      depends on RD_LZMA
-+      help
-+        The most recent compression algorithm.
-+        Its ratio is best, decompression speed is between the other
-+        two. Compression is slowest.  The initramfs size is about 33%
-+        smaller with LZMA in comparison to gzip.
-+
-+endchoice
-diff --git a/usr/Makefile b/usr/Makefile
-index 201f27f..b84894b 100644
---- a/usr/Makefile
-+++ b/usr/Makefile
-@@ -6,13 +6,25 @@ klibcdirs:;
- PHONY += klibcdirs
-+# No compression
-+suffix_$(CONFIG_INITRAMFS_COMPRESSION_NONE)   =
-+
-+# Gzip, but no bzip2
-+suffix_$(CONFIG_INITRAMFS_COMPRESSION_GZIP)   = .gz
-+
-+# Bzip2
-+suffix_$(CONFIG_INITRAMFS_COMPRESSION_BZIP2)  = .bz2
-+
-+# Lzma
-+suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZMA)   = .lzma
-+
- # Generate builtin.o based on initramfs_data.o
--obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
-+obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data$(suffix_y).o
--# initramfs_data.o contains the initramfs_data.cpio.gz image.
-+# initramfs_data.o contains the compressed initramfs_data.cpio image.
- # The image is included using .incbin, a dependency which is not
- # tracked automatically.
--$(obj)/initramfs_data.o: $(obj)/initramfs_data.cpio.gz FORCE
-+$(obj)/initramfs_data$(suffix_y).o: $(obj)/initramfs_data.cpio$(suffix_y) FORCE
- #####
- # Generate the initramfs cpio archive
-@@ -25,28 +37,28 @@ ramfs-args  := \
-         $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
-         $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
--# .initramfs_data.cpio.gz.d is used to identify all files included
-+# .initramfs_data.cpio.d is used to identify all files included
- # in initramfs and to detect if any files are added/removed.
- # Removed files are identified by directory timestamp being updated
- # The dependency list is generated by gen_initramfs.sh -l
--ifneq ($(wildcard $(obj)/.initramfs_data.cpio.gz.d),)
--      include $(obj)/.initramfs_data.cpio.gz.d
-+ifneq ($(wildcard $(obj)/.initramfs_data.cpio.d),)
-+      include $(obj)/.initramfs_data.cpio.d
- endif
- quiet_cmd_initfs = GEN     $@
-       cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
--targets := initramfs_data.cpio.gz
-+targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 initramfs_data.cpio.lzma initramfs_data.cpio
- # do not try to update files included in initramfs
- $(deps_initramfs): ;
- $(deps_initramfs): klibcdirs
--# We rebuild initramfs_data.cpio.gz if:
--# 1) Any included file is newer then initramfs_data.cpio.gz
-+# We rebuild initramfs_data.cpio if:
-+# 1) Any included file is newer then initramfs_data.cpio
- # 2) There are changes in which files are included (added or deleted)
--# 3) If gen_init_cpio are newer than initramfs_data.cpio.gz
-+# 3) If gen_init_cpio are newer than initramfs_data.cpio
- # 4) arguments to gen_initramfs.sh changes
--$(obj)/initramfs_data.cpio.gz: $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
--      $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.gz.d
-+$(obj)/initramfs_data.cpio$(suffix_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
-+      $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d
-       $(call if_changed,initfs)
-diff --git a/usr/initramfs_data.S b/usr/initramfs_data.S
-index c2e1ad4..7c6973d 100644
---- a/usr/initramfs_data.S
-+++ b/usr/initramfs_data.S
-@@ -26,5 +26,5 @@ SECTIONS
- */
- .section .init.ramfs,"a"
--.incbin "usr/initramfs_data.cpio.gz"
-+.incbin "usr/initramfs_data.cpio"
-diff --git a/usr/initramfs_data.bz2.S b/usr/initramfs_data.bz2.S
-new file mode 100644
-index 0000000..bc54d09
---- /dev/null
-+++ b/usr/initramfs_data.bz2.S
-@@ -0,0 +1,29 @@
-+/*
-+  initramfs_data includes the compressed binary that is the
-+  filesystem used for early user space.
-+  Note: Older versions of "as" (prior to binutils 2.11.90.0.23
-+  released on 2001-07-14) dit not support .incbin.
-+  If you are forced to use older binutils than that then the
-+  following trick can be applied to create the resulting binary:
-+
-+
-+  ld -m elf_i386  --format binary --oformat elf32-i386 -r \
-+  -T initramfs_data.scr initramfs_data.cpio.gz -o initramfs_data.o
-+   ld -m elf_i386  -r -o built-in.o initramfs_data.o
-+
-+  initramfs_data.scr looks like this:
-+SECTIONS
-+{
-+       .init.ramfs : { *(.data) }
-+}
-+
-+  The above example is for i386 - the parameters vary from architectures.
-+  Eventually look up LDFLAGS_BLOB in an older version of the
-+  arch/$(ARCH)/Makefile to see the flags used before .incbin was introduced.
-+
-+  Using .incbin has the advantage over ld that the correct flags are set
-+  in the ELF header, as required by certain architectures.
-+*/
-+
-+.section .init.ramfs,"a"
-+.incbin "usr/initramfs_data.cpio.bz2"
-diff --git a/usr/initramfs_data.gz.S b/usr/initramfs_data.gz.S
-new file mode 100644
-index 0000000..890c8dd
---- /dev/null
-+++ b/usr/initramfs_data.gz.S
-@@ -0,0 +1,29 @@
-+/*
-+  initramfs_data includes the compressed binary that is the
-+  filesystem used for early user space.
-+  Note: Older versions of "as" (prior to binutils 2.11.90.0.23
-+  released on 2001-07-14) dit not support .incbin.
-+  If you are forced to use older binutils than that then the
-+  following trick can be applied to create the resulting binary:
-+
-+
-+  ld -m elf_i386  --format binary --oformat elf32-i386 -r \
-+  -T initramfs_data.scr initramfs_data.cpio.gz -o initramfs_data.o
-+   ld -m elf_i386  -r -o built-in.o initramfs_data.o
-+
-+  initramfs_data.scr looks like this:
-+SECTIONS
-+{
-+       .init.ramfs : { *(.data) }
-+}
-+
-+  The above example is for i386 - the parameters vary from architectures.
-+  Eventually look up LDFLAGS_BLOB in an older version of the
-+  arch/$(ARCH)/Makefile to see the flags used before .incbin was introduced.
-+
-+  Using .incbin has the advantage over ld that the correct flags are set
-+  in the ELF header, as required by certain architectures.
-+*/
-+
-+.section .init.ramfs,"a"
-+.incbin "usr/initramfs_data.cpio.gz"
-diff --git a/usr/initramfs_data.lzma.S b/usr/initramfs_data.lzma.S
-new file mode 100644
-index 0000000..e11469e
---- /dev/null
-+++ b/usr/initramfs_data.lzma.S
-@@ -0,0 +1,29 @@
-+/*
-+  initramfs_data includes the compressed binary that is the
-+  filesystem used for early user space.
-+  Note: Older versions of "as" (prior to binutils 2.11.90.0.23
-+  released on 2001-07-14) dit not support .incbin.
-+  If you are forced to use older binutils than that then the
-+  following trick can be applied to create the resulting binary:
-+
-+
-+  ld -m elf_i386  --format binary --oformat elf32-i386 -r \
-+  -T initramfs_data.scr initramfs_data.cpio.gz -o initramfs_data.o
-+   ld -m elf_i386  -r -o built-in.o initramfs_data.o
-+
-+  initramfs_data.scr looks like this:
-+SECTIONS
-+{
-+       .init.ramfs : { *(.data) }
-+}
-+
-+  The above example is for i386 - the parameters vary from architectures.
-+  Eventually look up LDFLAGS_BLOB in an older version of the
-+  arch/$(ARCH)/Makefile to see the flags used before .incbin was introduced.
-+
-+  Using .incbin has the advantage over ld that the correct flags are set
-+  in the ELF header, as required by certain architectures.
-+*/
-+
-+.section .init.ramfs,"a"
-+.incbin "usr/initramfs_data.cpio.lzma"
---
-To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
-the body of a message to majordomo@vger.kernel.org
-More majordomo info at  http://vger.kernel.org/majordomo-info.html
-Please read the FAQ at  http://www.tux.org/lkml/
index a5d441d54bca02ffc8892f42826cfd6d1ccee084..4179cb02a1adc254f0db831c9316dcb7329a04eb 100644 (file)
-Subject: Update MPT Fusion driver to v4.00.43.00
-From: Hannes Reinecke <hare@suse.de>
-Date: Tue Sep 30 13:38:53 2008 +0200:
-Git: a958ec0d1685af04282982f2e53b66c947fc7426
-
-References: bnc#425660
-
-This patch updates the MPT fusion drivers to v4.00.43.00.
-
-Signed-off-by: Sathya Prakash <Sathya.Prakash@lsi.com>
-Signed-off-by: Hannes Reinecke <hare@suse.de>
-
----
- drivers/message/fusion/Kconfig                       |   16 
- drivers/message/fusion/Makefile                      |   13 
- drivers/message/fusion/csmi/csmisas.c                | 5888 ++++++++++++++++++
- drivers/message/fusion/csmi/csmisas.h                | 1854 +++++
- drivers/message/fusion/lsi/mpi.h                     |    7 
- drivers/message/fusion/lsi/mpi_cnfg.h                |   47 
- drivers/message/fusion/lsi/mpi_fc.h                  |    2 
- drivers/message/fusion/lsi/mpi_history.txt           |   86 
- drivers/message/fusion/lsi/mpi_init.h                |    2 
- drivers/message/fusion/lsi/mpi_ioc.h                 |   22 
- drivers/message/fusion/lsi/mpi_lan.h                 |    2 
- drivers/message/fusion/lsi/mpi_log_fc.h              |    2 
- drivers/message/fusion/lsi/mpi_log_sas.h             |   31 
- drivers/message/fusion/lsi/mpi_raid.h                |   11 
- drivers/message/fusion/lsi/mpi_sas.h                 |   18 
- drivers/message/fusion/lsi/mpi_targ.h                |    2 
- drivers/message/fusion/lsi/mpi_tool.h                |    2 
- drivers/message/fusion/lsi/mpi_type.h                |   19 
- drivers/message/fusion/mptbase.c                     | 2700 +++++---
- drivers/message/fusion/mptbase.h                     |  291 
- drivers/message/fusion/mptctl.c                      | 1020 +--
- drivers/message/fusion/mptctl.h                      |    5 
- drivers/message/fusion/mptdebug.h                    |   12 
- drivers/message/fusion/mptfc.c                       |  189 
- drivers/message/fusion/mptlan.c                      |   56 
- drivers/message/fusion/mptlan.h                      |    3 
- drivers/message/fusion/mptsas.c                      | 5921 ++++++++++++-------
- drivers/message/fusion/mptsas.h                      |   71 
- drivers/message/fusion/mptscsih.c                    | 2252 +++----
- drivers/message/fusion/mptscsih.h                    |   13 
- drivers/message/fusion/mptspi.c                      |  265 
- drivers/message/fusion/rejected_ioctls/diag_buffer.c |  667 ++
- drivers/message/fusion/rejected_ioctls/diag_buffer.h |  101 
- 33 files changed, 16615 insertions(+), 4975 deletions(-)
-
---- /dev/null
-+++ b/drivers/message/fusion/csmi/csmisas.c
-@@ -0,0 +1,5888 @@
-+/*
-+ *  linux/drivers/message/fusion/csmi/csmisas.c
-+ *      For use with LSI PCI chip/adapter(s)
-+ *      running LSI Fusion MPT (Message Passing Technology) firmware.
-+ *
-+ *  Copyright (c) 1999-2008 LSI Corporation
-+ *  (mailto:DL-MPTFusionLinux@lsi.com)
-+ */
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/*
-+    This program is free software; you can redistribute it and/or modify
-+    it under the terms of the GNU General Public License as published by
-+    the Free Software Foundation; version 2 of the License.
-+
-+    This program is distributed in the hope that it will be useful,
-+    but WITHOUT ANY WARRANTY; without even the implied warranty of
-+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+    GNU General Public License for more details.
-+
-+    NO WARRANTY
-+    THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
-+    CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
-+    LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
-+    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
-+    solely responsible for determining the appropriateness of using and
-+    distributing the Program and assumes all risks associated with its
-+    exercise of rights under this Agreement, including but not limited to
-+    the risks and costs of program errors, damage to or loss of data,
-+    programs or equipment, and unavailability or interruption of operations.
-+
-+    DISCLAIMER OF LIABILITY
-+    NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
-+    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-+    DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
-+    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-+    TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
-+    USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
-+    HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
-+
-+    You should have received a copy of the GNU General Public License
-+    along with this program; if not, write to the Free Software
-+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-+*/
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+
-+#define MPT_CSMI_DESCRIPTION "LSI Corporation: Fusion MPT Driver "MPT_LINUX_VERSION_COMMON
-+#define csmisas_is_this_sas_cntr(ioc) (ioc->bus_type == SAS) ? 1 : 0
-+
-+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
-+#define __user
-+#include <asm/div64.h>
-+#endif
-+
-+static int csmisas_do_raid(MPT_ADAPTER *ioc, u8 action, u8 PhysDiskNum, u8 VolumeBus,
-+    u8 VolumeId, pMpiRaidActionReply_t reply);
-+static u8  map_sas_status_to_csmi(u8 mpi_sas_status);
-+
-+/**
-+ * reverse_byte_order64
-+ *
-+ * @data64
-+ *
-+ **/
-+static u64
-+reverse_byte_order64(u64 data64)
-+{
-+      int i;
-+      u64 rc;
-+      u8  *inWord = (u8*)&data64, *outWord = (u8*)&rc;
-+
-+      for (i = 0 ; i < 8 ; i++)
-+              outWord[i] = inWord[7-i];
-+
-+      return rc;
-+}
-+
-+/**
-+ * csmisas_is_sata
-+ *
-+ * @phys_disk
-+ *
-+ **/
-+static int
-+csmisas_is_sata(RaidPhysDiskPage0_t *phys_disk)
-+{
-+      if ((phys_disk->ExtDiskIdentifier[0] == 'A') &&
-+          (phys_disk->ExtDiskIdentifier[1] == 'T') &&
-+          (phys_disk->ExtDiskIdentifier[2] == 'A'))
-+              return 1;
-+      else
-+              return 0;
-+}
-+
-+/**
-+ * csmisas_is_end_device
-+ *
-+ * @attached
-+ *
-+ **/
-+static inline int
-+csmisas_is_end_device(struct mptsas_devinfo * attached)
-+{
-+      if ((attached->sas_address) &&
-+          (attached->device_info &
-+          MPI_SAS_DEVICE_INFO_END_DEVICE) &&
-+          ((attached->device_info &
-+          MPI_SAS_DEVICE_INFO_SSP_TARGET) |
-+          (attached->device_info &
-+          MPI_SAS_DEVICE_INFO_STP_TARGET) |
-+          (attached->device_info &
-+          MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
-+              return 1;
-+      else
-+              return 0;
-+}
-+
-+/**
-+ * csmisas_is_phys_disk
-+ *
-+ * returns (1) success (0) fail - not a phys disk
-+ **/
-+static int
-+csmisas_is_phys_disk(MPT_ADAPTER *ioc, int channel, int id)
-+{
-+      struct inactive_raid_component_info *component_info;
-+      int i;
-+      int rc = 0;
-+
-+      if (!ioc->raid_data.pIocPg3)
-+              goto out;
-+      for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
-+              if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
-+                  (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
-+                      rc = 1;
-+                      goto out;
-+              }
-+      }
-+
-+      /*
-+       * Check inactive list for matching phys disks
-+       */
-+      if (list_empty(&ioc->raid_data.inactive_list))
-+              goto out;
-+
-+      down(&ioc->raid_data.inactive_list_mutex);
-+      list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
-+          list) {
-+              if ((component_info->d.PhysDiskID == id) &&
-+                  (component_info->d.PhysDiskBus == channel))
-+                      rc = 1;
-+      }
-+      up(&ioc->raid_data.inactive_list_mutex);
-+
-+ out:
-+      return rc;
-+}
-+
-+/**
-+ * csmisas_raid_id_to_num
-+ *
-+ * Obtains the phys disk num for given H:C:T nexus
-+ *
-+ * input (channel/id)
-+ * output (phys disk number - used by SCSI_IO_PASSTHRU to access hidden component)
-+ *
-+ * returns - signed return means failure
-+ **/
-+static s8
-+csmisas_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
-+{
-+      struct inactive_raid_component_info *component_info;
-+      int i;
-+      s8 rc = -ENXIO;
-+
-+      if (!ioc->raid_data.pIocPg3)
-+              goto out;
-+      for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
-+              if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
-+                  (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
-+                      rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
-+                      goto out;
-+              }
-+      }
-+
-+      /*
-+       * Check inactive list for matching phys disks
-+       */
-+      if (list_empty(&ioc->raid_data.inactive_list))
-+              goto out;
-+
-+      down(&ioc->raid_data.inactive_list_mutex);
-+      list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
-+          list) {
-+              if ((component_info->d.PhysDiskID == id) &&
-+                  (component_info->d.PhysDiskBus == channel))
-+                      rc = component_info->d.PhysDiskNum;
-+      }
-+      up(&ioc->raid_data.inactive_list_mutex);
-+
-+ out:
-+      return rc;
-+}
-+
-+/**
-+ * csmisas_get_device_component_by_os
-+ *
-+ * Obtain device component object by operating system mapping
-+ *
-+ * @ioc
-+ * @channel
-+ * @id
-+ *
-+ **/
-+static struct sas_device_info *
-+csmisas_get_device_component_by_os(MPT_ADAPTER *ioc, u8 channel, u8 id)
-+{
-+      struct sas_device_info *sas_info, *p;
-+
-+      sas_info = NULL;
-+
-+      down(&ioc->sas_device_info_mutex);
-+      list_for_each_entry(p, &ioc->sas_device_info_list, list) {
-+              if (p->os.channel == channel && p->os.id == id) {
-+                      sas_info = p;
-+                      goto out;
-+              }
-+      }
-+
-+ out:
-+      up(&ioc->sas_device_info_mutex);
-+      return sas_info;
-+}
-+
-+/**
-+ * csmisas_get_device_component
-+ *
-+ * Obtain device component object by firmware system mapping
-+ *
-+ * @ioc
-+ * @channel
-+ * @id
-+ *
-+ **/
-+static struct sas_device_info *
-+csmisas_get_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id)
-+{
-+      struct sas_device_info *sas_info, *p;
-+
-+      sas_info = NULL;
-+
-+      down(&ioc->sas_device_info_mutex);
-+      list_for_each_entry(p, &ioc->sas_device_info_list, list) {
-+              if (p->fw.channel == channel && p->fw.id == id) {
-+                      sas_info = p;
-+                      goto out;
-+              }
-+      }
-+
-+ out:
-+      up(&ioc->sas_device_info_mutex);
-+      return sas_info;
-+}
-+
-+
-+/**
-+ * csmisas_get_device_component_by_sas_addr
-+ *
-+ * Obtain device component object by sas address
-+ *
-+ * @ioc
-+ * @channel
-+ * @id
-+ *
-+ **/
-+static struct sas_device_info *
-+csmisas_get_device_component_by_sas_addr(MPT_ADAPTER *ioc, u64 sas_address)
-+{
-+      struct sas_device_info *sas_info, *p;
-+
-+      sas_info = NULL;
-+
-+      down(&ioc->sas_device_info_mutex);
-+      list_for_each_entry(p, &ioc->sas_device_info_list, list) {
-+              if (p->sas_address == sas_address) {
-+                      sas_info = p;
-+                      goto out;
-+              }
-+      }
-+
-+ out:
-+      up(&ioc->sas_device_info_mutex);
-+      return sas_info;
-+}
-+
-+/**
-+ * csmisas_send_command_wait
-+ *
-+ * Send mf to firmware
-+ *
-+ * @ioc
-+ * @mf
-+ * @timeout - timeout
-+ *
-+ *    Return: 0 for success
-+ *    non-zero, failure
-+ **/
-+static int
-+csmisas_send_command_wait(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, unsigned long timeout)
-+{
-+      int rc;
-+      unsigned long timeleft;
-+
-+      timeout = max_t(unsigned long, MPT_IOCTL_DEFAULT_TIMEOUT, timeout);
-+      rc = 0;
-+      timeleft = 0;
-+
-+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
-+
-+      INITIALIZE_IOCTL_STATUS(ioc->ioctl_cmds.status)
-+      ioc->ioctl_cmds.wait_done = 0;
-+      ioc->ioctl_cmds.timer.expires = jiffies + (MPT_JIFFY * timeout);
-+      ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_TIMER_ACTIVE;
-+      ADD_TIMER(&ioc->ioctl_cmds.timer);
-+      mpt_put_msg_frame(mptctl_id, ioc, mf);
-+      WAIT_EVENT(mptctl_wait, ioc->ioctl_cmds.wait_done);
-+
-+#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
-+
-+      INITIALIZE_IOCTL_STATUS(ioc->ioctl_cmds.status)
-+      ioc->ioctl_cmds.wait_done = 0;
-+      mpt_put_msg_frame(mptctl_id, ioc, mf);
-+
-+      if ((wait_event_timeout(mptctl_wait,
-+          ioc->ioctl_cmds.wait_done == 1, HZ * timeout) <=0) &&
-+          ioc->ioctl_cmds.wait_done != 1 ) {
-+              mptctl_timeout_expired(ioc,mf);
-+              mpt_free_msg_frame(ioc, mf);
-+              rc = -1;
-+      }
-+
-+#else
-+
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
-+          mf->u.hdr.MsgContext);
-+      INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
-+      mpt_put_msg_frame(mptctl_id, ioc, mf);
-+      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, timeout*HZ);
-+      if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              rc = -1;
-+              printk("%s: failed\n", __FUNCTION__);
-+              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
-+                      mpt_free_msg_frame(ioc, mf);
-+                      CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
-+                      return rc;
-+              }
-+              if (!timeleft)
-+                      mptctl_timeout_expired(ioc, mf);
-+      }
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
-+#endif
-+      return rc;
-+}
-+
-+/**
-+ * csmisas_send_handshake_wait
-+ *
-+ * Handshake a mf to firmware
-+ *
-+ * @ioc
-+ * @mf
-+ * @mf_size
-+ * @timeout - timeout
-+ *
-+ *    Return: 0 for success
-+ *    non-zero, failure
-+ **/
-+static int
-+csmisas_send_handshake_wait(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, unsigned long timeout)
-+{
-+      int rc;
-+      unsigned long timeleft;
-+
-+      timeout = max_t(unsigned long, MPT_IOCTL_DEFAULT_TIMEOUT, timeout);
-+      rc = 0;
-+      timeleft = 0;
-+
-+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
-+
-+      INITIALIZE_IOCTL_STATUS(ioc->taskmgmt_cmds.status)
-+      ioc->taskmgmt_cmds.timer.expires = jiffies + (MPT_JIFFY*timeout);
-+      ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_TIMER_ACTIVE;
-+      ioc->taskmgmt_cmds.wait_done = 0;
-+      ADD_TIMER(&ioc->taskmgmt_cmds.timer);
-+      rc = mpt_send_special_message(mptctl_taskmgmt_id, ioc,
-+          sizeof(SCSITaskMgmt_t), (u32*)mf, timeout, CAN_SLEEP);
-+      if (rc != 0)
-+              return rc;
-+      WAIT_EVENT(mptctl_taskmgmt_wait, ioc->taskmgmt_cmds.wait_done);
-+
-+#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
-+
-+      INITIALIZE_IOCTL_STATUS(ioc->taskmgmt_cmds.status)
-+      ioc->taskmgmt_cmds.wait_done = 0;
-+      rc = mpt_send_special_message(mptctl_taskmgmt_id, ioc,
-+          sizeof(SCSITaskMgmt_t), (u32*)mf, timeout, CAN_SLEEP);
-+      if (rc != 0)
-+              return rc;
-+      if ((wait_event_timeout(mptctl_taskmgmt_wait,
-+          ioc->taskmgmt_cmds.wait_done == 1, HZ * timeout) <=0) &&
-+          ioc->taskmgmt_cmds.wait_done != 1 ) {
-+              mptctl_timeout_expired(ioc, mf);
-+              mpt_free_msg_frame(ioc, mf);
-+              rc = -1;
-+      }
-+
-+#else
-+      INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+      mpt_put_msg_frame_hi_pri(mptctl_taskmgmt_id, ioc, mf);
-+      timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ);
-+      if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              rc = -1;
-+              printk("%s: failed\n", __FUNCTION__);
-+              mpt_clear_taskmgmt_in_progress_flag(ioc);
-+              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
-+                      mpt_free_msg_frame(ioc, mf);
-+                      CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+                      return rc;
-+              }
-+              if (!timeleft)
-+                      mptctl_timeout_expired(ioc, mf);
-+      }
-+#endif
-+      return rc;
-+}
-+
-+/**
-+ *    csmisas_get_number_hotspares - returns num hot spares in this ioc
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *
-+ *    Return: number of hotspares
-+ *
-+ **/
-+static int
-+csmisas_get_number_hotspares(MPT_ADAPTER *ioc)
-+{
-+      ConfigPageHeader_t       hdr;
-+      CONFIGPARMS              cfg;
-+      IOCPage5_t               *buffer = NULL;
-+      dma_addr_t               dma_handle;
-+      int                      data_sz;
-+      int                      rc;
-+
-+      memset(&hdr, 0, sizeof(ConfigPageHeader_t));
-+      memset(&cfg, 0, sizeof(CONFIGPARMS));
-+
-+      rc = 0;
-+      data_sz = 0;
-+      hdr.PageNumber = 5;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_IOC;
-+      cfg.cfghdr.hdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+      if (mpt_config(ioc, &cfg) != 0)
-+              goto get_ioc_pg5;
-+
-+      if (hdr.PageLength == 0)
-+              goto get_ioc_pg5;
-+
-+      data_sz = hdr.PageLength * 4;
-+      buffer = (IOCPage5_t *) pci_alloc_consistent(ioc->pcidev,
-+              data_sz, &dma_handle);
-+      if (!buffer)
-+              goto get_ioc_pg5;
-+
-+      memset((u8 *)buffer, 0, data_sz);
-+      cfg.physAddr = dma_handle;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if (mpt_config(ioc, &cfg) != 0)
-+              goto get_ioc_pg5;
-+
-+      rc = buffer->NumHotSpares;
-+
-+ get_ioc_pg5:
-+
-+      if (buffer)
-+              pci_free_consistent(ioc->pcidev, data_sz,
-+                  (u8 *) buffer, dma_handle);
-+
-+      return rc;
-+}
-+
-+
-+/**
-+ *    csmisas_get_ioc_pg5 - ioc Page 5 hot spares
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @pIocPage5: ioc page 5
-+ *    @data_size: expected data size(units=bytes)
-+ *
-+ *    Return: 0 for success
-+ *    -ENOMEM if no memory available
-+ *            -EPERM if not allowed due to ISR context
-+ *            -EAGAIN if no msg frames currently available
-+ *            -EFAULT for non-successful reply or no reply (timeout)
-+ **/
-+static int
-+csmisas_get_ioc_pg5(MPT_ADAPTER *ioc, IOCPage5_t *iocPage5, int data_size)
-+{
-+      ConfigPageHeader_t       hdr;
-+      CONFIGPARMS              cfg;
-+      IOCPage5_t               *buffer = NULL;
-+      dma_addr_t               dma_handle;
-+      int                      data_sz;
-+      int                      rc;
-+
-+      memset(&hdr, 0, sizeof(ConfigPageHeader_t));
-+      memset(&cfg, 0, sizeof(CONFIGPARMS));
-+
-+      rc = 0;
-+      data_sz = 0;
-+      hdr.PageNumber = 5;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_IOC;
-+      cfg.cfghdr.hdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0)
-+              goto get_ioc_pg5;
-+
-+      if (hdr.PageLength == 0) {
-+              rc = -EFAULT;
-+              goto get_ioc_pg5;
-+      }
-+
-+      data_sz = hdr.PageLength * 4;
-+      buffer = (IOCPage5_t *) pci_alloc_consistent(ioc->pcidev,
-+              data_sz, &dma_handle);
-+      if (!buffer) {
-+              rc = -ENOMEM;
-+              goto get_ioc_pg5;
-+      }
-+
-+      memset((u8 *)buffer, 0, data_sz);
-+      cfg.physAddr = dma_handle;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0)
-+              goto get_ioc_pg5;
-+
-+      memcpy(iocPage5, buffer, data_size);
-+
-+ get_ioc_pg5:
-+
-+      if (buffer)
-+              pci_free_consistent(ioc->pcidev, data_sz,
-+                  (u8 *) buffer, dma_handle);
-+
-+      return rc;
-+}
-+
-+/**
-+ *    csmisas_sas_device_pg0 - sas device page 0
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @mptsas_devinfo: structure found in mptsas.h
-+ *    @form, @form_specific - defines the Page Address field in the config page
-+ *            (pls refer to chapter 5.1 in the mpi spec)
-+ *
-+ *    Return: 0 for success
-+ *    -ENOMEM if no memory available
-+ *            -EPERM if not allowed due to ISR context
-+ *            -EAGAIN if no msg frames currently available
-+ *            -EFAULT for non-successful reply or no reply (timeout)
-+ **/
-+static int
-+csmisas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
-+              u32 form, u32 form_specific)
-+{
-+      ConfigExtendedPageHeader_t hdr;
-+      CONFIGPARMS cfg;
-+      SasDevicePage0_t *buffer;
-+      dma_addr_t dma_handle;
-+      u64 sas_address;
-+      int rc;
-+
-+      rc = 0;
-+      hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
-+      hdr.ExtPageLength = 0;
-+      hdr.PageNumber = 0;
-+      hdr.Reserved1 = 0;
-+      hdr.Reserved2 = 0;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
-+
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.pageAddr = form + form_specific;
-+      cfg.physAddr = -1;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = 10;
-+
-+      memset(device_info, 0, sizeof(struct mptsas_devinfo));
-+      if ((rc = mpt_config(ioc, &cfg)) != 0)
-+              goto out;
-+
-+      if (!hdr.ExtPageLength) {
-+              rc = -ENXIO;
-+              goto out;
-+      }
-+
-+      buffer = pci_alloc_consistent(ioc->pcidev,
-+          hdr.ExtPageLength * 4, &dma_handle);
-+      if (!buffer) {
-+              rc = -ENOMEM;
-+              goto out;
-+      }
-+
-+      cfg.physAddr = dma_handle;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0)
-+              goto out_free_consistent;
-+
-+      device_info->handle = le16_to_cpu(buffer->DevHandle);
-+      device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
-+      device_info->handle_enclosure =
-+          le16_to_cpu(buffer->EnclosureHandle);
-+      device_info->slot = le16_to_cpu(buffer->Slot);
-+      device_info->phy_id = buffer->PhyNum;
-+      device_info->port_id = buffer->PhysicalPort;
-+      device_info->id = buffer->TargetID;
-+      device_info->channel = buffer->Bus;
-+      memcpy(&sas_address, &buffer->SASAddress, sizeof(u64));
-+      device_info->sas_address = le64_to_cpu(sas_address);
-+      device_info->device_info =
-+          le32_to_cpu(buffer->DeviceInfo);
-+
-+ out_free_consistent:
-+      pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-+                          buffer, dma_handle);
-+ out:
-+      return rc;
-+}
-+
-+/**
-+ * Routine for the CSMI Sas Get Driver Info command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_driver_info(unsigned long arg)
-+{
-+
-+      CSMI_SAS_DRIVER_INFO_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_DRIVER_INFO_BUFFER     karg;
-+      MPT_ADAPTER     *ioc = NULL;
-+      int             iocnum;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_DRIVER_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+            "Unable to read in csmi_sas_get_driver_info_buffer struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      /* Fill in the data and return the structure to the calling
-+       * program
-+       */
-+      memcpy( karg.Information.szName, MPT_MISCDEV_BASENAME,
-+          sizeof(MPT_MISCDEV_BASENAME));
-+      memcpy( karg.Information.szDescription, MPT_CSMI_DESCRIPTION,
-+          sizeof(MPT_CSMI_DESCRIPTION));
-+
-+      karg.Information.usMajorRevision = MPT_LINUX_MAJOR_VERSION;
-+      karg.Information.usMinorRevision = MPT_LINUX_MINOR_VERSION;
-+      karg.Information.usBuildRevision = MPT_LINUX_BUILD_VERSION;
-+      karg.Information.usReleaseRevision = MPT_LINUX_RELEASE_VERSION;
-+
-+      karg.Information.usCSMIMajorRevision = CSMI_MAJOR_REVISION;
-+      karg.Information.usCSMIMinorRevision = CSMI_MINOR_REVISION;
-+
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+              sizeof(CSMI_SAS_DRIVER_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+                 "Unable to write out csmi_sas_get_driver_info_buffer @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI_SAS_GET_CNTLR_CONFIG command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_cntlr_config(unsigned long arg)
-+{
-+
-+      CSMI_SAS_CNTLR_CONFIG_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_CNTLR_CONFIG_BUFFER    karg;
-+      MPT_ADAPTER     *ioc = NULL;
-+      int             iocnum;
-+      u64             mem_phys;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_CNTLR_CONFIG_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+           "Unable to read in csmi_sas_get_cntlr_config_buffer struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      /* Clear the struct before filling in data. */
-+      memset( &karg.Configuration, 0, sizeof(CSMI_SAS_CNTLR_CONFIG));
-+
-+      /* Fill in the data and return the structure to the calling
-+       * program
-+       */
-+
-+      karg.Configuration.uBaseIoAddress = ioc->pio_mem_phys;
-+      karg.Configuration.BaseMemoryAddress.uLowPart = ioc->mem_phys;
-+      if (sizeof(ioc->mem_phys) == sizeof(u64)) {
-+              mem_phys = ioc->mem_phys;
-+              karg.Configuration.BaseMemoryAddress.uHighPart =
-+                  (u32)(mem_phys >> 32);
-+      }
-+
-+      karg.Configuration.uBoardID = (ioc->pcidev->subsystem_device << 16) |
-+          (ioc->pcidev->subsystem_vendor);
-+
-+      karg.Configuration.usSlotNumber =
-+          (ioc->pci_slot_number = 0xff) ?
-+          SLOT_NUMBER_UNKNOWN : ioc->pci_slot_number;
-+      karg.Configuration.bControllerClass = CSMI_SAS_CNTLR_CLASS_HBA;
-+      karg.Configuration.bIoBusType = CSMI_SAS_BUS_TYPE_PCI;
-+      karg.Configuration.BusAddress.PciAddress.bBusNumber =
-+          ioc->pcidev->bus->number;
-+      karg.Configuration.BusAddress.PciAddress.bDeviceNumber =
-+          PCI_SLOT(ioc->pcidev->devfn);
-+      karg.Configuration.BusAddress.PciAddress.bFunctionNumber =
-+          PCI_FUNC(ioc->pcidev->devfn);
-+      karg.Configuration.BusAddress.PciAddress.bReserved = 0;
-+      memcpy( &karg.Configuration.szSerialNumber, ioc->board_tracer, 16 );
-+      karg.Configuration.usMajorRevision = ioc->facts.FWVersion.Struct.Major;
-+      karg.Configuration.usMinorRevision = ioc->facts.FWVersion.Struct.Minor;
-+      karg.Configuration.usBuildRevision = ioc->facts.FWVersion.Struct.Unit;
-+      karg.Configuration.usReleaseRevision = ioc->facts.FWVersion.Struct.Dev;
-+      karg.Configuration.usBIOSMajorRevision =
-+          (ioc->biosVersion & 0xFF000000) >> 24;
-+      karg.Configuration.usBIOSMinorRevision =
-+          (ioc->biosVersion & 0x00FF0000) >> 16;
-+      karg.Configuration.usBIOSBuildRevision =
-+          (ioc->biosVersion & 0x0000FF00) >> 8;
-+      karg.Configuration.usBIOSReleaseRevision =
-+          (ioc->biosVersion & 0x000000FF);
-+      karg.Configuration.uControllerFlags = CSMI_SAS_CNTLR_SAS_HBA |
-+          CSMI_SAS_CNTLR_FWD_SUPPORT | CSMI_SAS_CNTLR_FWD_ONLINE |
-+          CSMI_SAS_CNTLR_FWD_SRESET ;
-+
-+      /*
-+       * Enabling CSMI_SAS_CNTLR_SAS_RAID bit when IR fw detected
-+       */
-+      if (ioc->ir_firmware)
-+              karg.Configuration.uControllerFlags |= CSMI_SAS_CNTLR_SAS_RAID;
-+
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+      /* All Rrom entries will be zero. Skip them. */
-+      /* bReserved will also be zeros. */
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+              sizeof(CSMI_SAS_DRIVER_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+              "Unable to write out csmi_sas_get_driver_info_buffer @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI Sas Get Controller Status command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_cntlr_status(unsigned long arg)
-+{
-+
-+      CSMI_SAS_CNTLR_STATUS_BUFFER  __user *uarg = (void __user *) arg;
-+      MPT_ADAPTER             *ioc = NULL;
-+      CSMI_SAS_CNTLR_STATUS_BUFFER    karg;
-+      int                     iocnum;
-+      int                     rc;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_CNTLR_STATUS_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+           "Unable to read in csmi_sas_get_cntlr_status_buffer struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      /* Fill in the data and return the structure to the calling
-+       * program
-+       */
-+
-+      rc = mpt_GetIocState(ioc, 1);
-+      switch (rc) {
-+      case MPI_IOC_STATE_OPERATIONAL:
-+              karg.Status.uStatus =  CSMI_SAS_CNTLR_STATUS_GOOD;
-+              karg.Status.uOfflineReason = 0;
-+              break;
-+
-+      case MPI_IOC_STATE_FAULT:
-+              karg.Status.uStatus = CSMI_SAS_CNTLR_STATUS_FAILED;
-+              karg.Status.uOfflineReason = 0;
-+              break;
-+
-+      case MPI_IOC_STATE_RESET:
-+      case MPI_IOC_STATE_READY:
-+      default:
-+              karg.Status.uStatus =  CSMI_SAS_CNTLR_STATUS_OFFLINE;
-+              karg.Status.uOfflineReason =
-+                  CSMI_SAS_OFFLINE_REASON_INITIALIZING;
-+              break;
-+      }
-+
-+      memset(&karg.Status.bReserved, 0, 28);
-+
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+              sizeof(CSMI_SAS_CNTLR_STATUS_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+                  "Unable to write out csmi_sas_get_cntlr_status @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI Sas Get Phy Info command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_phy_info(unsigned long arg)
-+{
-+      CSMI_SAS_PHY_INFO_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_PHY_INFO_BUFFER  *karg;
-+      MPT_ADAPTER             *ioc = NULL;
-+      ConfigExtendedPageHeader_t  hdr;
-+      CONFIGPARMS             cfg;
-+      SasIOUnitPage0_t        *sasIoUnitPg0;
-+      dma_addr_t              sasIoUnitPg0_dma;
-+      int                     sasIoUnitPg0_data_sz;
-+      SasPhyPage0_t           *sasPhyPg0;
-+      dma_addr_t              sasPhyPg0_dma;
-+      int                     sasPhyPg0_data_sz;
-+      u16                     protocol;
-+      int                     iocnum;
-+      int                     rc;
-+      int                     ii;
-+      u64                     sas_address;
-+      struct mptsas_devinfo   device_info;
-+      int                     memory_pages;
-+
-+      sasIoUnitPg0=NULL;
-+      sasPhyPg0=NULL;
-+      sasIoUnitPg0_data_sz=0;
-+      sasPhyPg0_data_sz=0;
-+
-+      memory_pages = get_order(sizeof(CSMI_SAS_PHY_INFO_BUFFER));
-+      karg = (CSMI_SAS_PHY_INFO_BUFFER *)__get_free_pages(
-+              GFP_KERNEL, memory_pages);
-+      if (!karg){
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to malloc CSMI_SAS_PHY_INFO_BUFFER "
-+                      "malloc_data_sz=%d memory_pages=%d\n",
-+                      __FILE__, __LINE__, __FUNCTION__,
-+                      (int)sizeof(CSMI_SAS_PHY_INFO_BUFFER), memory_pages);
-+              return -ENOMEM;
-+      }
-+
-+      memset(karg, 0, sizeof(*karg));
-+
-+      if (copy_from_user(karg, uarg, sizeof(CSMI_SAS_PHY_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+              "Unable to read in csmisas_get_phy_info_buffer struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg->IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      /* Fill in the data and return the structure to the calling
-+       * program
-+       */
-+
-+      /* Issue a config request to get the number of phys
-+       */
-+      hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
-+      hdr.ExtPageLength = 0;
-+      hdr.PageNumber = 0;
-+      hdr.Reserved1 = 0;
-+      hdr.Reserved2 = 0;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
-+
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = 0;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              /* Don't check if this failed.  Already in a
-+               * failure case.
-+               */
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED: MPI_SASIOUNITPAGE0_PAGEVERSION: HEADER\n"));
-+              dcsmisasprintk(ioc, printk(": rc=%x\n",rc));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto sas_get_phy_info_exit;
-+      }
-+
-+      if (hdr.ExtPageLength == 0) {
-+              /* Don't check if this failed.  Already in a
-+               * failure case.
-+               */
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto sas_get_phy_info_exit;
-+      }
-+
-+      sasIoUnitPg0_data_sz = hdr.ExtPageLength * 4;
-+      rc = -ENOMEM;
-+
-+      sasIoUnitPg0 = (SasIOUnitPage0_t *) pci_alloc_consistent(ioc->pcidev,
-+          sasIoUnitPg0_data_sz, &sasIoUnitPg0_dma);
-+
-+      if (!sasIoUnitPg0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto sas_get_phy_info_exit;
-+      }
-+
-+      memset((u8 *)sasIoUnitPg0, 0, sasIoUnitPg0_data_sz);
-+      cfg.physAddr = sasIoUnitPg0_dma;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+
-+              /* Don't check if this failed.  Already in a
-+               * failure case.
-+               */
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED: MPI_SASIOUNITPAGE0_PAGEVERSION: PAGE\n"));
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto sas_get_phy_info_exit;
-+      }
-+
-+      /* Number of Phys. */
-+      karg->Information.bNumberOfPhys = sasIoUnitPg0->NumPhys;
-+
-+      /* Fill in information for each phy. */
-+      for (ii = 0; ii < karg->Information.bNumberOfPhys; ii++) {
-+
-+/* EDM : dump IO Unit Page 0 data*/
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "---- IO UNIT PAGE 0 ------------\n"));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Handle=0x%X\n",
-+                  le16_to_cpu(sasIoUnitPg0->PhyData[ii].AttachedDeviceHandle)));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Controller Handle=0x%X\n",
-+                  le16_to_cpu(sasIoUnitPg0->PhyData[ii].ControllerDevHandle)));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Port=0x%X\n",
-+                  sasIoUnitPg0->PhyData[ii].Port));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Port Flags=0x%X\n",
-+                  sasIoUnitPg0->PhyData[ii].PortFlags));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "PHY Flags=0x%X\n",
-+                  sasIoUnitPg0->PhyData[ii].PhyFlags));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Negotiated Link Rate=0x%X\n",
-+                  sasIoUnitPg0->PhyData[ii].NegotiatedLinkRate));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Controller PHY Device Info=0x%X\n",
-+                  le32_to_cpu(sasIoUnitPg0->PhyData[ii].ControllerPhyDeviceInfo)));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "DiscoveryStatus=0x%X\n",
-+                  le32_to_cpu(sasIoUnitPg0->PhyData[ii].DiscoveryStatus)));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "\n"));
-+/* EDM : debug data */
-+
-+              /* PHY stuff. */
-+              karg->Information.Phy[ii].bPortIdentifier =
-+                  sasIoUnitPg0->PhyData[ii].Port;
-+
-+              /* Get the negotiated link rate for the phy. */
-+              switch (sasIoUnitPg0->PhyData[ii].NegotiatedLinkRate) {
-+
-+              case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
-+                      karg->Information.Phy[ii].bNegotiatedLinkRate =
-+                          CSMI_SAS_PHY_DISABLED;
-+                      break;
-+
-+              case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
-+                      karg->Information.Phy[ii].bNegotiatedLinkRate =
-+                          CSMI_SAS_LINK_RATE_FAILED;
-+                      break;
-+
-+              case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
-+                      break;
-+
-+              case MPI_SAS_IOUNIT0_RATE_1_5:
-+                      karg->Information.Phy[ii].bNegotiatedLinkRate =
-+                          CSMI_SAS_LINK_RATE_1_5_GBPS;
-+                      break;
-+
-+              case MPI_SAS_IOUNIT0_RATE_3_0:
-+                      karg->Information.Phy[ii].bNegotiatedLinkRate =
-+                          CSMI_SAS_LINK_RATE_3_0_GBPS;
-+                      break;
-+
-+              case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
-+              default:
-+                      karg->Information.Phy[ii].bNegotiatedLinkRate =
-+                          CSMI_SAS_LINK_RATE_UNKNOWN;
-+                      break;
-+              }
-+
-+              if (sasIoUnitPg0->PhyData[ii].PortFlags &
-+                  MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS) {
-+                      karg->Information.Phy[ii].bAutoDiscover =
-+                          CSMI_SAS_DISCOVER_IN_PROGRESS;
-+              } else {
-+                      karg->Information.Phy[ii].bAutoDiscover =
-+                          CSMI_SAS_DISCOVER_COMPLETE;
-+              }
-+
-+              /* Issue a config request to get
-+               * phy information.
-+               */
-+              hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
-+              hdr.ExtPageLength = 0;
-+              hdr.PageNumber = 0;
-+              hdr.Reserved1 = 0;
-+              hdr.Reserved2 = 0;
-+              hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+              hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
-+
-+              cfg.cfghdr.ehdr = &hdr;
-+              cfg.physAddr = -1;
-+              cfg.pageAddr = ii;
-+              cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+              cfg.dir = 0;    /* read */
-+              cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+              if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR
-+                          ": FAILED: MPI_SASPHY0_PAGEVERSION: HEADER\n"));
-+                      dcsmisasprintk(ioc, printk(": rc=%x\n",rc));
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto sas_get_phy_info_exit;
-+              }
-+
-+              if (hdr.ExtPageLength == 0) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto sas_get_phy_info_exit;
-+              }
-+
-+              sasPhyPg0_data_sz = hdr.ExtPageLength * 4;
-+              rc = -ENOMEM;
-+
-+              sasPhyPg0 = (SasPhyPage0_t *) pci_alloc_consistent(
-+                  ioc->pcidev, sasPhyPg0_data_sz, &sasPhyPg0_dma);
-+
-+              if (! sasPhyPg0) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto sas_get_phy_info_exit;
-+              }
-+
-+              memset((u8 *)sasPhyPg0, 0, sasPhyPg0_data_sz);
-+              cfg.physAddr = sasPhyPg0_dma;
-+              cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+              if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR
-+                          ": FAILED: MPI_SASPHY0_PAGEVERSION: PAGE\n"));
-+                      dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      pci_free_consistent(ioc->pcidev, sasPhyPg0_data_sz,
-+                          (u8 *) sasPhyPg0, sasPhyPg0_dma);
-+                      goto sas_get_phy_info_exit;
-+              }
-+
-+/* EDM : dump PHY Page 0 data*/
-+              memcpy(&sas_address, &sasPhyPg0->SASAddress, sizeof(u64));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "---- SAS PHY PAGE 0 ------------\n"));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Handle=0x%X\n",
-+                  le16_to_cpu(sasPhyPg0->AttachedDevHandle)));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "SAS Address=0x%llX\n",
-+                  (unsigned long long)sas_address));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Attached PHY Identifier=0x%X\n",
-+                  sasPhyPg0->AttachedPhyIdentifier));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Attached Device Info=0x%X\n",
-+                  le32_to_cpu(sasPhyPg0->AttachedDeviceInfo)));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Programmed Link Rate=0x%X\n",
-+                  sasPhyPg0->ProgrammedLinkRate));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Hardware Link Rate=0x%X\n",
-+                  sasPhyPg0->HwLinkRate));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "Change Count=0x%X\n",
-+                  sasPhyPg0->ChangeCount));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "PHY Info=0x%X\n",
-+                  le32_to_cpu(sasPhyPg0->PhyInfo)));
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "\n"));
-+/* EDM : debug data */
-+
-+              /* save the data */
-+
-+              /* Set Max hardware link rate.
-+               * This value is hard coded
-+               * because the HW link rate
-+               * is currently being
-+               * overwritten in FW.
-+               */
-+
-+              /* Set Max hardware link rate. */
-+              switch (sasPhyPg0->HwLinkRate &
-+                  MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
-+
-+              case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
-+                      karg->Information.Phy[ii].bMaximumLinkRate =
-+                          CSMI_SAS_LINK_RATE_1_5_GBPS;
-+                      break;
-+
-+              case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
-+                      karg->Information.Phy[ii].bMaximumLinkRate =
-+                          CSMI_SAS_LINK_RATE_3_0_GBPS;
-+                      break;
-+              default:
-+                      break;
-+              }
-+
-+              /* Set Max programmed link rate. */
-+              switch (sasPhyPg0->ProgrammedLinkRate &
-+                  MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
-+
-+              case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
-+                      karg->Information.Phy[ii].bMaximumLinkRate |=
-+                          (CSMI_SAS_PROGRAMMED_LINK_RATE_1_5_GBPS << 4);
-+                      break;
-+
-+              case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
-+                      karg->Information.Phy[ii].bMaximumLinkRate |=
-+                          (CSMI_SAS_PROGRAMMED_LINK_RATE_3_0_GBPS << 4);
-+                      break;
-+              default:
-+                      break;
-+              }
-+
-+              /* Set Min hardware link rate. */
-+              switch (sasPhyPg0->HwLinkRate &
-+                  MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
-+
-+              case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
-+                      karg->Information.Phy[ii].bMinimumLinkRate =
-+                          CSMI_SAS_LINK_RATE_1_5_GBPS;
-+                      break;
-+
-+              case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
-+                      karg->Information.Phy[ii].bMinimumLinkRate =
-+                          CSMI_SAS_LINK_RATE_3_0_GBPS;
-+                      break;
-+              default:
-+                      break;
-+              }
-+
-+              /* Set Min programmed link rate. */
-+              switch (sasPhyPg0->ProgrammedLinkRate &
-+                  MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
-+
-+              case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
-+                      karg->Information.Phy[ii].bMinimumLinkRate |=
-+                          (CSMI_SAS_PROGRAMMED_LINK_RATE_1_5_GBPS << 4);
-+                      break;
-+
-+              case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
-+                      karg->Information.Phy[ii].bMinimumLinkRate |=
-+                          (CSMI_SAS_PROGRAMMED_LINK_RATE_3_0_GBPS << 4);
-+                      break;
-+              default:
-+                      break;
-+              }
-+
-+              karg->Information.Phy[ii].bPhyChangeCount = sasPhyPg0->ChangeCount;
-+              if( sasPhyPg0->PhyInfo & MPI_SAS_PHY0_PHYINFO_VIRTUAL_PHY )
-+                      karg->Information.Phy[ii].bPhyFeatures = CSMI_SAS_PHY_VIRTUAL_SMP;
-+
-+              /* Fill in Attached Device
-+               * Initiator Port Protocol.
-+               * Bits 6:3
-+               * More than one bit can be set.
-+               */
-+              protocol = le32_to_cpu(sasPhyPg0->AttachedDeviceInfo) & 0x78;
-+              karg->Information.Phy[ii].Attached.bInitiatorPortProtocol = 0;
-+              if (protocol & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
-+                    karg->Information.Phy[ii].Attached.bInitiatorPortProtocol =
-+                          CSMI_SAS_PROTOCOL_SSP;
-+              if (protocol & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
-+                   karg->Information.Phy[ii].Attached.bInitiatorPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_STP;
-+              if (protocol & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
-+                   karg->Information.Phy[ii].Attached.bInitiatorPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SMP;
-+              if (protocol & MPI_SAS_DEVICE_INFO_SATA_HOST)
-+                   karg->Information.Phy[ii].Attached.bInitiatorPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SATA;
-+
-+              /* Fill in Phy Target Port
-+               * Protocol. Bits 10:7
-+               * More than one bit can be set.
-+               */
-+              protocol = le32_to_cpu(sasPhyPg0->AttachedDeviceInfo) & 0x780;
-+              karg->Information.Phy[ii].Attached.bTargetPortProtocol = 0;
-+              if (protocol & MPI_SAS_DEVICE_INFO_SSP_TARGET)
-+                      karg->Information.Phy[ii].Attached.bTargetPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SSP;
-+              if (protocol & MPI_SAS_DEVICE_INFO_STP_TARGET)
-+                      karg->Information.Phy[ii].Attached.bTargetPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_STP;
-+              if (protocol & MPI_SAS_DEVICE_INFO_SMP_TARGET)
-+                      karg->Information.Phy[ii].Attached.bTargetPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SMP;
-+              if (protocol & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
-+                      karg->Information.Phy[ii].Attached.bTargetPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SATA;
-+
-+
-+              /* Fill in Attached device type */
-+              switch (le32_to_cpu(sasPhyPg0->AttachedDeviceInfo) &
-+                  MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
-+
-+              case MPI_SAS_DEVICE_INFO_NO_DEVICE:
-+                      karg->Information.Phy[ii].Attached.bDeviceType =
-+                          CSMI_SAS_NO_DEVICE_ATTACHED;
-+                      break;
-+
-+              case MPI_SAS_DEVICE_INFO_END_DEVICE:
-+                      karg->Information.Phy[ii].Attached.bDeviceType =
-+                          CSMI_SAS_END_DEVICE;
-+                      break;
-+
-+              case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
-+                      karg->Information.Phy[ii].Attached.bDeviceType =
-+                          CSMI_SAS_EDGE_EXPANDER_DEVICE;
-+                      break;
-+
-+              case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
-+                      karg->Information.Phy[ii].Attached.bDeviceType =
-+                          CSMI_SAS_FANOUT_EXPANDER_DEVICE;
-+                      break;
-+              }
-+
-+              /* Identify Info. */
-+              switch (le32_to_cpu(sasIoUnitPg0->PhyData[ii].ControllerPhyDeviceInfo) &
-+                  MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
-+
-+              case MPI_SAS_DEVICE_INFO_NO_DEVICE:
-+                      karg->Information.Phy[ii].Identify.bDeviceType =
-+                          CSMI_SAS_NO_DEVICE_ATTACHED;
-+                      break;
-+
-+              case MPI_SAS_DEVICE_INFO_END_DEVICE:
-+                      karg->Information.Phy[ii].Identify.bDeviceType =
-+                          CSMI_SAS_END_DEVICE;
-+                      break;
-+
-+              case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
-+                      karg->Information.Phy[ii].Identify.bDeviceType =
-+                          CSMI_SAS_EDGE_EXPANDER_DEVICE;
-+                      break;
-+
-+              case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
-+                      karg->Information.Phy[ii].Identify.bDeviceType =
-+                          CSMI_SAS_FANOUT_EXPANDER_DEVICE;
-+                      break;
-+              }
-+
-+              /* Fill in Phy Initiator Port Protocol. Bits 6:3
-+               * More than one bit can be set, fall through cases.
-+               */
-+              protocol = le32_to_cpu(
-+                  sasIoUnitPg0->PhyData[ii].ControllerPhyDeviceInfo) & 0x78;
-+              karg->Information.Phy[ii].Identify.bInitiatorPortProtocol = 0;
-+              if( protocol & MPI_SAS_DEVICE_INFO_SSP_INITIATOR )
-+                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SSP;
-+              if( protocol & MPI_SAS_DEVICE_INFO_STP_INITIATOR )
-+                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_STP;
-+              if( protocol & MPI_SAS_DEVICE_INFO_SMP_INITIATOR )
-+                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SMP;
-+              if( protocol & MPI_SAS_DEVICE_INFO_SATA_HOST )
-+                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SATA;
-+
-+              /* Fill in Phy Target Port Protocol. Bits 10:7
-+               * More than one bit can be set, fall through cases.
-+               */
-+              protocol = le32_to_cpu(
-+                  sasIoUnitPg0->PhyData[ii].ControllerPhyDeviceInfo) & 0x780;
-+              karg->Information.Phy[ii].Identify.bTargetPortProtocol = 0;
-+              if( protocol & MPI_SAS_DEVICE_INFO_SSP_TARGET )
-+                      karg->Information.Phy[ii].Identify.bTargetPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SSP;
-+              if( protocol & MPI_SAS_DEVICE_INFO_STP_TARGET )
-+                      karg->Information.Phy[ii].Identify.bTargetPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_STP;
-+              if( protocol & MPI_SAS_DEVICE_INFO_SMP_TARGET )
-+                      karg->Information.Phy[ii].Identify.bTargetPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SMP;
-+              if( protocol & MPI_SAS_DEVICE_INFO_SATA_DEVICE )
-+                      karg->Information.Phy[ii].Identify.bTargetPortProtocol |=
-+                          CSMI_SAS_PROTOCOL_SATA;
-+
-+              /* Setup SAS Address for the attached device */
-+              if (sasPhyPg0->AttachedDevHandle) {
-+                      sas_address = reverse_byte_order64(sas_address);
-+                      memcpy(karg->Information.Phy[ii].Attached.bSASAddress,
-+                          &sas_address, sizeof(u64));
-+                      karg->Information.Phy[ii].Attached.bPhyIdentifier =
-+                          sasPhyPg0->AttachedPhyIdentifier;
-+              }
-+
-+              /* Setup SAS Address for the parent device */
-+              csmisas_sas_device_pg0(ioc, &device_info,
-+                  (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
-+                  MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+                  sasIoUnitPg0->PhyData[ii].ControllerDevHandle);
-+              sas_address = reverse_byte_order64(device_info.sas_address);
-+              memcpy(karg->Information.Phy[ii].Identify.bSASAddress,
-+                  &sas_address, sizeof(u64));
-+              karg->Information.Phy[ii].Identify.bPhyIdentifier = ii;
-+
-+              pci_free_consistent(ioc->pcidev, sasPhyPg0_data_sz,
-+                  (u8 *) sasPhyPg0, sasPhyPg0_dma);
-+      }
-+
-+sas_get_phy_info_exit:
-+
-+      if (sasIoUnitPg0)
-+              pci_free_consistent(ioc->pcidev, sasIoUnitPg0_data_sz,
-+                  (u8 *) sasIoUnitPg0, sasIoUnitPg0_dma);
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, karg,
-+          sizeof(CSMI_SAS_PHY_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+                  "Unable to write out csmisas_get_phy_info_buffer @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      free_pages((unsigned long)karg, memory_pages);
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Set PHY Info command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_set_phy_info(unsigned long arg)
-+{
-+      CSMI_SAS_SET_PHY_INFO_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_SET_PHY_INFO_BUFFER     karg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      int                             iocnum;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_SET_PHY_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_set_phy_info struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+/* TODO - implement IOCTL here */
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_BAD_CNTL_CODE;
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG ": not implemented\n"));
-+
-+// cim_set_phy_info_exit:
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+                              sizeof(CSMI_SAS_SET_PHY_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to write out csmi_sas_set_phy_info @ %p\n",
-+                              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI Sas Get SCSI Address command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_scsi_address(unsigned long arg)
-+{
-+      CSMI_SAS_GET_SCSI_ADDRESS_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_GET_SCSI_ADDRESS_BUFFER         karg;
-+      MPT_ADAPTER             *ioc = NULL;
-+      int                     iocnum;
-+      u64                     sas_address;
-+      struct sas_device_info  *sas_info;
-+
-+      if (copy_from_user(&karg, uarg,
-+          sizeof(CSMI_SAS_GET_SCSI_ADDRESS_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_get_scsi_address struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      /* reverse byte order the sas address */
-+      memcpy(&sas_address, karg.bSASAddress, sizeof(u64));
-+      sas_address = reverse_byte_order64(sas_address);
-+
-+      /* Search the list for the matching SAS address. */
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_NO_SCSI_ADDRESS;
-+      karg.bPathId = 0;
-+      karg.bTargetId = 0;
-+      karg.bLun = 0;
-+
-+      sas_info = csmisas_get_device_component_by_sas_addr(ioc, sas_address);
-+      if (!sas_info || sas_info->is_cached || sas_info->is_logical_volume)
-+              goto csmisas_get_scsi_address_exit;
-+
-+      karg.bPathId = sas_info->os.channel;
-+      karg.bTargetId = sas_info->os.id;
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+ csmisas_get_scsi_address_exit:
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+          sizeof(CSMI_SAS_GET_SCSI_ADDRESS_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to write out csmi_sas_get_scsi_address @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI Sas Get SCSI Address command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_sata_signature(unsigned long arg)
-+{
-+      CSMI_SAS_SATA_SIGNATURE_BUFFER  __user *uarg = (void __user *) arg;
-+      CSMI_SAS_SATA_SIGNATURE_BUFFER   karg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      int                             iocnum;
-+      int                             rc, jj;
-+      ConfigExtendedPageHeader_t      hdr;
-+      CONFIGPARMS                     cfg;
-+      SasPhyPage0_t                   *sasPhyPg0;
-+      dma_addr_t                      sasPhyPg0_dma;
-+      int                             sasPhyPg0_data_sz;
-+      SasDevicePage1_t                *sasDevicePg1;
-+      dma_addr_t                      sasDevicePg1_dma;
-+      int                             sasDevicePg1_data_sz;
-+      u8                              phyId;
-+      u64                             sas_address;
-+
-+      sasPhyPg0=NULL;
-+      sasPhyPg0_data_sz=0;
-+      sasDevicePg1=NULL;
-+      sasDevicePg1_data_sz=0;
-+
-+      if (copy_from_user(&karg, uarg,
-+           sizeof(CSMI_SAS_SATA_SIGNATURE_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_sata_signature struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                   __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+      phyId = karg.Signature.bPhyIdentifier;
-+      if (phyId >= ioc->num_ports) {
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_PHY_DOES_NOT_EXIST;
-+              dcsmisasprintk(ioc, printk(KERN_WARNING ": phyId >= ioc->num_ports\n"));
-+              goto cim_sata_signature_exit;
-+      }
-+
-+      /* Default to success.*/
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+      /* Issue a config request to get the devHandle of the attached device
-+       */
-+
-+      /* Issue a config request to get phy information. */
-+      hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
-+      hdr.ExtPageLength = 0;
-+      hdr.PageNumber = 0;
-+      hdr.Reserved1 = 0;
-+      hdr.Reserved2 = 0;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
-+
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = phyId;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              /* Don't check if this failed.  Already in a
-+               * failure case.
-+               */
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED: MPI_SASPHY0_PAGEVERSION: HEADER\n"));
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sata_signature_exit;
-+      }
-+
-+      if (hdr.ExtPageLength == 0) {
-+              /* Don't check if this failed.  Already in a
-+               * failure case.
-+               */
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sata_signature_exit;
-+      }
-+
-+
-+      sasPhyPg0_data_sz = hdr.ExtPageLength * 4;
-+      rc = -ENOMEM;
-+
-+      sasPhyPg0 = (SasPhyPage0_t *) pci_alloc_consistent(ioc->pcidev,
-+          sasPhyPg0_data_sz, &sasPhyPg0_dma);
-+
-+      if (! sasPhyPg0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sata_signature_exit;
-+      }
-+
-+      memset((u8 *)sasPhyPg0, 0, sasPhyPg0_data_sz);
-+      cfg.physAddr = sasPhyPg0_dma;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              /* Don't check if this failed.  Already in a
-+               * failure case.
-+               */
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED: MPI_SASPHY0_PAGEVERSION: PAGE\n"));
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sata_signature_exit;
-+      }
-+
-+      /* Make sure a SATA device is attached. */
-+      if ((le32_to_cpu(sasPhyPg0->AttachedDeviceInfo) &
-+          MPI_SAS_DEVICE_INFO_SATA_DEVICE) == 0) {
-+              dcsmisasprintk(ioc, printk(KERN_WARNING ": NOT A SATA DEVICE\n"));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_NO_SATA_DEVICE;
-+              goto cim_sata_signature_exit;
-+      }
-+
-+      /* Get device page 1 for FIS  signature. */
-+      hdr.PageVersion = MPI_SASDEVICE1_PAGEVERSION;
-+      hdr.ExtPageLength = 0;
-+      hdr.PageNumber = 1 /* page number 1 */;
-+      hdr.Reserved1 = 0;
-+      hdr.Reserved2 = 0;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
-+
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.physAddr = -1;
-+
-+      cfg.pageAddr = ((MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
-+          MPI_SAS_DEVICE_PGAD_FORM_SHIFT) |
-+          le16_to_cpu(sasPhyPg0->AttachedDevHandle));
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED: MPI_SASDEVICE1_PAGEVERSION: HEADER\n"));
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sata_signature_exit;
-+      }
-+
-+      if (hdr.ExtPageLength == 0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sata_signature_exit;
-+      }
-+
-+      sasDevicePg1_data_sz = hdr.ExtPageLength * 4;
-+      rc = -ENOMEM;
-+
-+      sasDevicePg1 = (SasDevicePage1_t *) pci_alloc_consistent
-+          (ioc->pcidev, sasDevicePg1_data_sz, &sasDevicePg1_dma);
-+
-+      if (! sasDevicePg1) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sata_signature_exit;
-+      }
-+
-+      memset((u8 *)sasDevicePg1, 0, sasDevicePg1_data_sz);
-+      cfg.physAddr = sasDevicePg1_dma;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED: MPI_SASDEVICE1_PAGEVERSION: PAGE\n"));
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sata_signature_exit;
-+      }
-+
-+/* EDM : dump Device Page 1 data*/
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "---- SAS DEVICE PAGE 1 ---------\n"));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "Handle=0x%x\n",sasDevicePg1->DevHandle));
-+      memcpy(&sas_address, &sasDevicePg1->SASAddress, sizeof(u64));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "SAS Address=0x%llX\n",
-+          (unsigned long long)sas_address));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "\n"));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "Target ID=0x%x\n",sasDevicePg1->TargetID));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "Bus=0x%x\n",sasDevicePg1->Bus));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "Initial Reg Device FIS="));
-+      for(jj=0;jj<20;jj++)
-+              dcsmisasprintk(ioc, printk("%02x ",
-+              ((u8 *)&sasDevicePg1->InitialRegDeviceFIS)[jj]));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "\n\n"));
-+/* EDM : debug data */
-+
-+      memcpy(karg.Signature.bSignatureFIS,
-+              sasDevicePg1->InitialRegDeviceFIS,20);
-+
-+ cim_sata_signature_exit:
-+
-+      if (sasPhyPg0)
-+              pci_free_consistent(ioc->pcidev, sasPhyPg0_data_sz,
-+                  (u8 *) sasPhyPg0, sasPhyPg0_dma);
-+
-+      if (sasDevicePg1)
-+              pci_free_consistent(ioc->pcidev, sasDevicePg1_data_sz,
-+                  (u8 *) sasDevicePg1, sasDevicePg1_dma);
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+          sizeof(CSMI_SAS_SATA_SIGNATURE_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to write out csmi_sas_sata_signature @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI Sas Get SCSI Address command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_device_address(unsigned long arg)
-+{
-+      CSMI_SAS_GET_DEVICE_ADDRESS_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_GET_DEVICE_ADDRESS_BUFFER       karg;
-+      MPT_ADAPTER             *ioc = NULL;
-+      int                     iocnum;
-+      struct sas_device_info  *sas_info;
-+      u64                     sas_address;
-+
-+      if (copy_from_user(&karg, uarg,
-+          sizeof(CSMI_SAS_GET_DEVICE_ADDRESS_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+         "Unable to read in csmi_sas_get_device_address_buffer struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_NO_DEVICE_ADDRESS;
-+      memset(karg.bSASAddress, 0, sizeof(u64));
-+      memset(karg.bSASLun, 0, sizeof(karg.bSASLun));
-+
-+      /* Search the list for the matching SAS address. */
-+      sas_info = csmisas_get_device_component_by_os(ioc, karg.bPathId,
-+          karg.bTargetId);
-+      if (!sas_info || sas_info->is_cached || sas_info->is_logical_volume)
-+              goto csmisas_get_device_address_exit;
-+
-+      sas_address = reverse_byte_order64(sas_info->sas_address);
-+      memcpy(karg.bSASAddress, &sas_address, sizeof(u64));
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+ csmisas_get_device_address_exit:
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+          sizeof(CSMI_SAS_GET_DEVICE_ADDRESS_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+              "Unable to write out csmi_sas_get_device_address_buffer @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI Sas Get Link Errors command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_link_errors(unsigned long arg)
-+{
-+      CSMI_SAS_LINK_ERRORS_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_LINK_ERRORS_BUFFER      karg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      MPT_FRAME_HDR                   *mf = NULL;
-+      MPIHeader_t                     *mpi_hdr;
-+      int                             iocnum;
-+      int                             rc;
-+      ConfigExtendedPageHeader_t      hdr;
-+      CONFIGPARMS                     cfg;
-+      SasPhyPage1_t                   *sasPhyPage1;
-+      dma_addr_t                      sasPhyPage1_dma;
-+      int                             sasPhyPage1_data_sz;
-+      SasIoUnitControlRequest_t       *sasIoUnitCntrReq;
-+      SasIoUnitControlReply_t         *sasIoUnitCntrReply;
-+      u8                              phyId;
-+      u16                             ioc_status;
-+      u32                             MsgContext;
-+
-+      sasPhyPage1=NULL;
-+      sasPhyPage1_data_sz=0;
-+
-+      if (copy_from_user(&karg, uarg,
-+           sizeof(CSMI_SAS_LINK_ERRORS_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmisas_get_link_errors struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                   __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+      phyId = karg.Information.bPhyIdentifier;
-+      if (phyId >= ioc->num_ports) {
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_PHY_DOES_NOT_EXIST;
-+              dcsmisasprintk(ioc, printk(KERN_WARNING ": phyId >= ioc->num_ports\n"));
-+              goto cim_get_link_errors_exit;
-+      }
-+
-+      /* Default to success.*/
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+      /* Issue a config request to get the devHandle of the attached device
-+       */
-+
-+      /* Issue a config request to get phy information. */
-+      hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
-+      hdr.ExtPageLength = 0;
-+      hdr.PageNumber = 1 /* page number 1*/;
-+      hdr.Reserved1 = 0;
-+      hdr.Reserved2 = 0;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
-+
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = phyId;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              /* Don't check if this failed.  Already in a
-+               * failure case.
-+               */
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED: MPI_SASPHY1_PAGEVERSION: HEADER\n"));
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_link_errors_exit;
-+      }
-+
-+      if (hdr.ExtPageLength == 0) {
-+              /* Don't check if this failed.  Already in a
-+               * failure case.
-+               */
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_link_errors_exit;
-+      }
-+
-+
-+      sasPhyPage1_data_sz = hdr.ExtPageLength * 4;
-+      rc = -ENOMEM;
-+
-+      sasPhyPage1 = (SasPhyPage1_t *) pci_alloc_consistent(ioc->pcidev,
-+          sasPhyPage1_data_sz, &sasPhyPage1_dma);
-+
-+      if (! sasPhyPage1) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_link_errors_exit;
-+      }
-+
-+      memset((u8 *)sasPhyPage1, 0, sasPhyPage1_data_sz);
-+      cfg.physAddr = sasPhyPage1_dma;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              /* Don't check if this failed.  Already in a
-+               * failure case.
-+               */
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": FAILED: MPI_SASPHY1_PAGEVERSION: PAGE\n"));
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_link_errors_exit;
-+      }
-+
-+/* EDM : dump PHY Page 1 data*/
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "---- SAS PHY PAGE 1 ------------\n"));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "Invalid Dword Count=0x%x\n",
-+          sasPhyPage1->InvalidDwordCount));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "Running Disparity Error Count=0x%x\n",
-+          sasPhyPage1->RunningDisparityErrorCount));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "Loss Dword Synch Count=0x%x\n",
-+          sasPhyPage1->LossDwordSynchCount));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "PHY Reset Problem Count=0x%x\n",
-+          sasPhyPage1->PhyResetProblemCount));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "\n\n"));
-+/* EDM : debug data */
-+
-+      karg.Information.uInvalidDwordCount =
-+              le32_to_cpu(sasPhyPage1->InvalidDwordCount);
-+      karg.Information.uRunningDisparityErrorCount =
-+              le32_to_cpu(sasPhyPage1->RunningDisparityErrorCount);
-+      karg.Information.uLossOfDwordSyncCount =
-+              le32_to_cpu(sasPhyPage1->LossDwordSynchCount);
-+      karg.Information.uPhyResetProblemCount =
-+              le32_to_cpu(sasPhyPage1->PhyResetProblemCount);
-+
-+      if (karg.Information.bResetCounts ==
-+          CSMI_SAS_LINK_ERROR_DONT_RESET_COUNTS ) {
-+              goto cim_get_link_errors_exit;
-+      }
-+
-+      /* Clear Error log
-+       *
-+       * Issue IOUNIT Control Reqeust Message
-+       */
-+
-+      /* Get a MF for this command.
-+       */
-+      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_link_errors_exit;
-+        }
-+
-+      mpi_hdr = (MPIHeader_t *) mf;
-+      MsgContext = mpi_hdr->MsgContext;
-+      sasIoUnitCntrReq = (SasIoUnitControlRequest_t *)mf;
-+      memset(sasIoUnitCntrReq,0,sizeof(SasIoUnitControlRequest_t));
-+      sasIoUnitCntrReq->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
-+      sasIoUnitCntrReq->MsgContext = MsgContext;
-+      sasIoUnitCntrReq->PhyNum = phyId;
-+      sasIoUnitCntrReq->Operation = MPI_SAS_OP_PHY_CLEAR_ERROR_LOG;
-+
-+      if (csmisas_send_command_wait(ioc, mf, karg.IoctlHeader.Timeout) != 0) {
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_link_errors_exit;
-+      }
-+
-+      /* process the completed Reply Message Frame */
-+      if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
-+
-+              sasIoUnitCntrReply =
-+                  (SasIoUnitControlReply_t *)ioc->ioctl_cmds.reply;
-+              ioc_status = le16_to_cpu(sasIoUnitCntrReply->IOCStatus)
-+                  & MPI_IOCSTATUS_MASK;
-+
-+              if (ioc_status != MPI_IOCSTATUS_SUCCESS) {
-+                      dcsmisasprintk(ioc, printk(KERN_DEBUG ": SAS IO Unit Control: "));
-+                      dcsmisasprintk(ioc, printk("IOCStatus=0x%X IOCLogInfo=0x%X\n",
-+                          sasIoUnitCntrReply->IOCStatus,
-+                          sasIoUnitCntrReply->IOCLogInfo));
-+              }
-+      }
-+
-+ cim_get_link_errors_exit:
-+
-+      if (sasPhyPage1)
-+              pci_free_consistent(ioc->pcidev, sasPhyPage1_data_sz,
-+                  (u8 *) sasPhyPage1, sasPhyPage1_dma);
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+          sizeof(CSMI_SAS_LINK_ERRORS_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to write out csmisas_get_link_errors @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS SMP Passthru command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_smp_passthru(unsigned long arg)
-+{
-+      CSMI_SAS_SMP_PASSTHRU_BUFFER __user *uarg = (void __user *) arg;
-+      MPT_ADAPTER                     *ioc;
-+      CSMI_SAS_SMP_PASSTHRU_BUFFER     *karg;
-+      pSmpPassthroughRequest_t        smpReq;
-+      pSmpPassthroughReply_t          smpReply;
-+      MPT_FRAME_HDR                   *mf = NULL;
-+      MPIHeader_t                     *mpi_hdr;
-+      char                            *psge;
-+      int                             iocnum, flagsLength;
-+      void *                          request_data;
-+      dma_addr_t                      request_data_dma;
-+      u32                             request_data_sz;
-+      void *                          response_data;
-+      dma_addr_t                      response_data_dma;
-+      u32                             response_data_sz;
-+      u16                             ioc_status;
-+      u64                             sas_address;
-+      u32                             MsgContext;
-+      int                             malloc_data_sz;
-+      int                             memory_pages;
-+
-+      malloc_data_sz = sizeof(CSMI_SAS_SMP_PASSTHRU_BUFFER);
-+      memory_pages = get_order(malloc_data_sz);
-+      karg = (CSMI_SAS_SMP_PASSTHRU_BUFFER *)__get_free_pages(
-+              GFP_KERNEL, memory_pages);
-+      if (!karg){
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to malloc CSMI_SAS_SMP_PASSTHRU_BUFFER "
-+                      "malloc_data_sz=%d memory_pages=%d\n",
-+                      __FILE__, __LINE__, __FUNCTION__,
-+                      malloc_data_sz, memory_pages);
-+              return -ENOMEM;
-+      }
-+
-+      if (copy_from_user(karg, uarg, sizeof(CSMI_SAS_SMP_PASSTHRU_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_smp_passthru struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      request_data = NULL;
-+      response_data = NULL;
-+      response_data_sz = sizeof(CSMI_SAS_SMP_RESPONSE);
-+      request_data_sz  = karg->Parameters.uRequestLength;
-+
-+      if (((iocnum = mpt_verify_adapter(karg->IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      if (ioc->ioc_reset_in_progress) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+                  "Busy with IOC Reset \n",
-+                  __FILE__, __LINE__,__FUNCTION__);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EBUSY;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      /* Default to success.*/
-+      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+      /* Do some error checking on the request. */
-+      if (karg->Parameters.bPortIdentifier == CSMI_SAS_IGNORE_PORT) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_SELECT_PHY_OR_PORT;
-+              goto cim_smp_passthru_exit;
-+      }
-+
-+      if ((request_data_sz > 0xFFFF) || (!request_data_sz)) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_smp_passthru_exit;
-+      }
-+
-+      /* Get a free request frame and save the message context.
-+       */
-+      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_smp_passthru_exit;
-+        }
-+
-+      mpi_hdr = (MPIHeader_t *) mf;
-+      MsgContext = mpi_hdr->MsgContext;
-+      smpReq = (pSmpPassthroughRequest_t ) mf;
-+
-+      memset(smpReq,0,ioc->req_sz);
-+
-+      memcpy(&sas_address, karg->Parameters.bDestinationSASAddress,
-+          sizeof(u64));
-+      sas_address = cpu_to_le64(reverse_byte_order64(sas_address));
-+      memcpy(&smpReq->SASAddress, &sas_address, sizeof(u64));
-+
-+      /* Fill in smp request. */
-+      smpReq->PhysicalPort = karg->Parameters.bPortIdentifier;
-+      smpReq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
-+      smpReq->RequestDataLength = cpu_to_le16(request_data_sz);
-+      smpReq->ConnectionRate = karg->Parameters.bConnectionRate;
-+      smpReq->MsgContext = MsgContext;
-+      smpReq->Reserved2 = 0;
-+      smpReq->Reserved3 = 0;
-+
-+      /*
-+       * Prepare the necessary pointers to run
-+       * through the SGL generation
-+       */
-+
-+      psge = (char *)&smpReq->SGL;
-+
-+      /* setup the *Request* payload SGE */
-+      flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
-+              MPI_SGE_FLAGS_SYSTEM_ADDRESS |
-+              MPI_SGE_FLAGS_HOST_TO_IOC |
-+              MPI_SGE_FLAGS_END_OF_BUFFER;
-+
-+      flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
-+      flagsLength |= request_data_sz;
-+
-+      request_data = pci_alloc_consistent(
-+          ioc->pcidev, request_data_sz, &request_data_dma);
-+
-+      if (!request_data) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              mpt_free_msg_frame(ioc, mf);
-+              goto cim_smp_passthru_exit;
-+      }
-+
-+      ioc->add_sge(psge, flagsLength, request_data_dma);
-+      psge += ioc->SGE_size;
-+
-+      memcpy(request_data, &karg->Parameters.Request, request_data_sz);
-+
-+      /* setup the *Response* payload SGE */
-+      response_data = pci_alloc_consistent(
-+          ioc->pcidev, response_data_sz, &response_data_dma);
-+
-+      if (!response_data) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              mpt_free_msg_frame(ioc, mf);
-+              goto cim_smp_passthru_exit;
-+      }
-+
-+      flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
-+              MPI_SGE_FLAGS_SYSTEM_ADDRESS |
-+              MPI_SGE_FLAGS_IOC_TO_HOST |
-+              MPI_SGE_FLAGS_END_OF_BUFFER;
-+
-+      flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
-+      flagsLength |= response_data_sz;
-+
-+      ioc->add_sge(psge, flagsLength, response_data_dma);
-+
-+      if (csmisas_send_command_wait(ioc, mf, karg->IoctlHeader.Timeout) != 0) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_smp_passthru_exit;
-+      }
-+
-+      if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0) {
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG ": SMP Passthru: oh no, there is no reply!!"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_smp_passthru_exit;
-+      }
-+
-+      /* process the completed Reply Message Frame */
-+      smpReply = (pSmpPassthroughReply_t )ioc->ioctl_cmds.reply;
-+      ioc_status = le16_to_cpu(smpReply->IOCStatus) & MPI_IOCSTATUS_MASK;
-+
-+      if ((ioc_status != MPI_IOCSTATUS_SUCCESS) &&
-+          (ioc_status != MPI_IOCSTATUS_SCSI_DATA_UNDERRUN)) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG ": SMP Passthru: "));
-+              dcsmisasprintk(ioc, printk("IOCStatus=0x%X IOCLogInfo=0x%X SASStatus=0x%X\n",
-+                  le16_to_cpu(smpReply->IOCStatus),
-+                  le32_to_cpu(smpReply->IOCLogInfo),
-+                  smpReply->SASStatus));
-+              goto cim_smp_passthru_exit;
-+      }
-+
-+      karg->Parameters.bConnectionStatus =
-+          map_sas_status_to_csmi(smpReply->SASStatus);
-+
-+
-+      if (le16_to_cpu(smpReply->ResponseDataLength)) {
-+              karg->Parameters.uResponseBytes = le16_to_cpu(smpReply->ResponseDataLength);
-+              memcpy(&karg->Parameters.Response,
-+                  response_data, le16_to_cpu(smpReply->ResponseDataLength));
-+      }
-+
-+ cim_smp_passthru_exit:
-+
-+      if (request_data)
-+              pci_free_consistent(ioc->pcidev, request_data_sz,
-+                  (u8 *)request_data, request_data_dma);
-+
-+      if (response_data)
-+              pci_free_consistent(ioc->pcidev, response_data_sz,
-+                  (u8 *)response_data, response_data_dma);
-+
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, karg,
-+          sizeof(CSMI_SAS_SMP_PASSTHRU_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to write out csmi_sas_smp_passthru @ %p\n",
-+                              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      free_pages((unsigned long)karg, memory_pages);
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG ": %s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS SSP Passthru command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int csmisas_ssp_passthru(unsigned long arg)
-+{
-+      CSMI_SAS_SSP_PASSTHRU_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_SSP_PASSTHRU_BUFFER     karg_hdr, * karg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      pSCSIIORequest_t                pScsiRequest;
-+      pSCSIIOReply_t                  pScsiReply;
-+      MPT_FRAME_HDR                   *mf = NULL;
-+      MPIHeader_t                     *mpi_hdr;
-+      int                             iocnum,ii;
-+      u64                             sas_address;
-+      u16                             req_idx;
-+      char                            *psge;
-+      int                             flagsLength;
-+      void *                          request_data;
-+      dma_addr_t                      request_data_dma;
-+      u32                             request_data_sz;
-+      int                             malloc_data_sz;
-+      int                             memory_pages;
-+      u16                             ioc_status;
-+      u8                              volume_id;
-+      u8                              volume_bus;
-+      u8                              is_hidden_raid_component;
-+      u8                              channel;
-+      u8                              id;
-+      struct sas_device_info          *sas_info;
-+      u8                              skey, asc, ascq;
-+      u32                             MsgContext;
-+
-+      if (copy_from_user(&karg_hdr, uarg, sizeof(CSMI_SAS_SSP_PASSTHRU_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_ssp_passthru struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      request_data = NULL;
-+      request_data_sz = karg_hdr.Parameters.uDataLength;
-+      channel = 0;
-+      id = 0;
-+      volume_id = 0;
-+      volume_bus = 0;
-+      is_hidden_raid_component = 0;
-+
-+      malloc_data_sz = (request_data_sz +
-+          offsetof(CSMI_SAS_SSP_PASSTHRU_BUFFER, bDataBuffer));
-+      memory_pages = get_order(malloc_data_sz);
-+      karg = (CSMI_SAS_SSP_PASSTHRU_BUFFER *)__get_free_pages(
-+              GFP_KERNEL, memory_pages);
-+      if (!karg){
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to malloc SAS_SSP_PASSTHRU_BUFFER "
-+                      "malloc_data_sz=%d memory_pages=%d\n",
-+                      __FILE__, __LINE__, __FUNCTION__,
-+                      malloc_data_sz, memory_pages);
-+              return -ENOMEM;
-+      }
-+
-+      memset(karg, 0, sizeof(*karg));
-+
-+      if (copy_from_user(karg, uarg, request_data_sz +
-+          offsetof(CSMI_SAS_SSP_PASSTHRU_BUFFER,bDataBuffer))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_ssp_passthru struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      /*
-+       * some checks of the incoming frame
-+       */
-+      if ( offsetof(CSMI_SAS_SSP_PASSTHRU_BUFFER,bDataBuffer) +
-+          request_data_sz - sizeof(IOCTL_HEADER) >
-+          karg->IoctlHeader.Length ) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  "%s::%s()"
-+                  " @%d - expected datalen incorrect!\n",
-+                  __FILE__, __FUNCTION__, __LINE__));
-+              goto cim_ssp_passthru_exit;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg->IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              goto cim_ssp_passthru_exit;
-+      }
-+
-+      if (ioc->ioc_reset_in_progress) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+                  "Busy with IOC Reset \n",
-+                  __FILE__, __LINE__,__FUNCTION__);
-+              return -EBUSY;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              printk(KERN_ERR "%s::%s()@%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              goto cim_ssp_passthru_exit;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      /* Default to success.
-+       */
-+      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+      /* Neither a phy nor a port has been selected.
-+       */
-+      if ((karg->Parameters.bPhyIdentifier == CSMI_SAS_USE_PORT_IDENTIFIER) &&
-+              (karg->Parameters.bPortIdentifier == CSMI_SAS_IGNORE_PORT)) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_SELECT_PHY_OR_PORT;
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  "%s::%s()"
-+                  " @%d - incorrect bPhyIdentifier and bPortIdentifier!\n",
-+                  __FILE__, __FUNCTION__, __LINE__));
-+              goto cim_ssp_passthru_exit;
-+      }
-+
-+      /* A phy has been selected. Verify that it's valid.
-+       */
-+      if (karg->Parameters.bPortIdentifier == CSMI_SAS_IGNORE_PORT) {
-+
-+              /* Is the phy in range? */
-+              if (karg->Parameters.bPhyIdentifier >= ioc->num_ports) {
-+                      dcsmisasprintk(ioc, printk(KERN_WARNING ": phyId >= ioc->num_ports (%d %d)\n",
-+                          karg->Parameters.bPhyIdentifier,
-+                          ioc->num_ports));
-+                      karg->IoctlHeader.ReturnCode =
-+                          CSMI_SAS_PHY_DOES_NOT_EXIST;
-+                      goto cim_ssp_passthru_exit;
-+              }
-+      }
-+
-+      if(karg->Parameters.bAdditionalCDBLength) {
-+      /* TODO - SCSI IO (32) Request Message support
-+       */
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG ": greater than 16-byte cdb "
-+                  "is not supported!\n"));
-+                  karg->IoctlHeader.ReturnCode =
-+                      CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              goto cim_ssp_passthru_exit;
-+      }
-+
-+      /* we will use SAS address to resolve the scsi adddressing
-+       */
-+      memcpy(&sas_address, karg->Parameters.bDestinationSASAddress,
-+          sizeof(u64));
-+      sas_address = reverse_byte_order64(sas_address);
-+
-+      /* Search the list for the matching SAS address.
-+       */
-+      sas_info = csmisas_get_device_component_by_sas_addr(ioc, sas_address);
-+      if (!sas_info || sas_info->is_cached) {
-+              /*
-+               *Invalid SAS address
-+               */
-+              karg->IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  "%s::%s() @%d - couldn't find associated "
-+                  "SASAddress=%llX!\n", __FILE__, __FUNCTION__, __LINE__,
-+                  (unsigned long long)sas_address));
-+              goto cim_ssp_passthru_exit;
-+      }
-+
-+      id = sas_info->fw.id;
-+      channel = sas_info->fw.channel;
-+
-+      if (csmisas_is_phys_disk(ioc, channel, id)) {
-+              id = csmisas_raid_id_to_num(ioc, channel, id);
-+              channel = 0;
-+              is_hidden_raid_component = 1;
-+      }
-+
-+      /* Get a free request frame and save the message context.
-+       */
-+      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_ssp_passthru_exit;
-+        }
-+
-+      mpi_hdr = (MPIHeader_t *) mf;
-+      MsgContext = mpi_hdr->MsgContext;
-+      pScsiRequest = (pSCSIIORequest_t) mf;
-+      req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
-+
-+      memset(pScsiRequest,0,sizeof(SCSIIORequest_t));
-+
-+      /* Fill in SCSI IO (16) request.
-+       */
-+
-+      pScsiRequest->Function = (is_hidden_raid_component == 1) ?
-+          MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH : MPI_FUNCTION_SCSI_IO_REQUEST;
-+      pScsiRequest->TargetID = id;
-+      pScsiRequest->Bus = channel;
-+      memcpy(pScsiRequest->LUN, &karg->Parameters.bLun, 8);
-+      pScsiRequest->CDBLength = karg->Parameters.bCDBLength;
-+      pScsiRequest->DataLength = cpu_to_le32(request_data_sz);
-+      pScsiRequest->MsgContext = MsgContext;
-+      memcpy(pScsiRequest->CDB, karg->Parameters.bCDB,
-+          pScsiRequest->CDBLength);
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "\tchannel = %d id = %d ",
-+          sas_info->fw.channel, sas_info->fw.id));
-+      dcsmisasprintk(ioc, if(is_hidden_raid_component)
-+          printk(KERN_DEBUG "num_id = %d ", id));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "\n"));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "\tcdb_len = %d request_len = %d\n",
-+          pScsiRequest->CDBLength, request_data_sz));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "\t"));
-+      dcsmisasprintk(ioc, for (ii = 0; ii < pScsiRequest->CDBLength; ++ii)
-+          printk(" %02x", pScsiRequest->CDB[ii]));
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "\n"));
-+
-+      /* direction
-+       */
-+      if (karg->Parameters.uFlags & CSMI_SAS_SSP_READ) {
-+              pScsiRequest->Control = cpu_to_le32(MPI_SCSIIO_CONTROL_READ);
-+      } else if (karg->Parameters.uFlags & CSMI_SAS_SSP_WRITE) {
-+              pScsiRequest->Control = cpu_to_le32(MPI_SCSIIO_CONTROL_WRITE);
-+      } else if ((karg->Parameters.uFlags & CSMI_SAS_SSP_UNSPECIFIED) &&
-+          (!karg->Parameters.uDataLength)) {
-+              /* no data transfer
-+               */
-+              pScsiRequest->Control = cpu_to_le32(MPI_SCSIIO_CONTROL_NODATATRANSFER);
-+      } else {
-+              /* no direction specified
-+               */
-+              pScsiRequest->Control = cpu_to_le32(MPI_SCSIIO_CONTROL_READ);
-+              pScsiRequest->MsgFlags =
-+                  MPI_SCSIIO_MSGFLGS_CMD_DETERMINES_DATA_DIR;
-+      }
-+
-+      pScsiRequest->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
-+      if (ioc->sg_addr_size == sizeof(u64))
-+              pScsiRequest->MsgFlags |= MPI_SCSIIO_MSGFLGS_SENSE_WIDTH_64;
-+
-+      /* task attributes
-+       */
-+      if((karg->Parameters.uFlags && 0xFF) == 0) {
-+              pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_SIMPLEQ);
-+      } else if (karg->Parameters.uFlags &
-+          CSMI_SAS_SSP_TASK_ATTRIBUTE_HEAD_OF_QUEUE) {
-+              pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_HEADOFQ);
-+      } else if (karg->Parameters.uFlags &
-+          CSMI_SAS_SSP_TASK_ATTRIBUTE_ORDERED) {
-+              pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_ORDEREDQ);
-+      } else if (karg->Parameters.uFlags &
-+          CSMI_SAS_SSP_TASK_ATTRIBUTE_ACA) {
-+              pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_ACAQ);
-+      } else {
-+              pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_UNTAGGED);
-+      }
-+
-+      /* setup sense
-+       */
-+      pScsiRequest->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
-+      pScsiRequest->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma +
-+          (req_idx * MPT_SENSE_BUFFER_ALLOC));
-+
-+      /* setup databuffer sg, assuming we fit everything one contiguous buffer
-+       */
-+      psge = (char *)&pScsiRequest->SGL;
-+
-+      if (karg->Parameters.uFlags & CSMI_SAS_SSP_WRITE) {
-+              flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
-+      } else if (karg->Parameters.uFlags & CSMI_SAS_SSP_READ) {
-+              flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
-+      }else {
-+              flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
-+                              MPI_SGE_FLAGS_DIRECTION )
-+                              << MPI_SGE_FLAGS_SHIFT;
-+      }
-+      flagsLength |= request_data_sz;
-+
-+      if ( request_data_sz > 0) {
-+              request_data = pci_alloc_consistent(
-+                  ioc->pcidev, request_data_sz, &request_data_dma);
-+
-+              if (request_data == NULL) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED "
-+                          "request_data_sz=%d\n", request_data_sz));
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      mpt_free_msg_frame(ioc, mf);
-+                      goto cim_ssp_passthru_exit;
-+              }
-+
-+              ioc->add_sge(psge, flagsLength, request_data_dma);
-+              if (karg->Parameters.uFlags & CSMI_SAS_SSP_WRITE)
-+                      memcpy(request_data, karg->bDataBuffer, request_data_sz);
-+      } else {
-+              ioc->add_sge(psge, flagsLength, (dma_addr_t) -1);
-+      }
-+
-+      if (csmisas_send_command_wait(ioc, mf, karg->IoctlHeader.Timeout) != 0) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_ssp_passthru_exit;
-+      }
-+
-+      memset(&karg->Status,0,sizeof(CSMI_SAS_SSP_PASSTHRU_STATUS));
-+      karg->Status.bConnectionStatus = CSMI_SAS_OPEN_ACCEPT;
-+      karg->Status.bDataPresent = CSMI_SAS_SSP_NO_DATA_PRESENT;
-+      karg->Status.bStatus = GOOD;
-+      karg->Status.bResponseLength[0] = 0;
-+      karg->Status.bResponseLength[1] = 0;
-+      karg->Status.uDataBytes = request_data_sz;
-+
-+      /* process the completed Reply Message Frame */
-+      if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
-+
-+              pScsiReply = (pSCSIIOReply_t ) ioc->ioctl_cmds.reply;
-+              karg->Status.bStatus = pScsiReply->SCSIStatus;
-+              karg->Status.uDataBytes = min(le32_to_cpu(pScsiReply->TransferCount),
-+                  request_data_sz);
-+              ioc_status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
-+
-+              if (pScsiReply->SCSIState ==
-+                  MPI_SCSI_STATE_AUTOSENSE_VALID) {
-+                      karg->Status.bConnectionStatus =
-+                          CSMI_SAS_SSP_SENSE_DATA_PRESENT;
-+                      karg->Status.bResponseLength[0] =
-+                              (u8)le32_to_cpu(pScsiReply->SenseCount) & 0xFF;
-+                      memcpy(karg->Status.bResponse,
-+                          ioc->ioctl_cmds.sense, le32_to_cpu(pScsiReply->SenseCount));
-+
-+                      skey = ioc->ioctl_cmds.sense[2] & 0x0F;
-+                      asc = ioc->ioctl_cmds.sense[12];
-+                      ascq = ioc->ioctl_cmds.sense[13];
-+
-+                      dcsmisasprintk(ioc, printk(KERN_DEBUG "\t [sense_key,asc,ascq]: "
-+                          "[0x%02x,0x%02x,0x%02x]\n",
-+                          skey, asc, ascq));
-+
-+              } else if(pScsiReply->SCSIState ==
-+                  MPI_SCSI_STATE_RESPONSE_INFO_VALID) {
-+                      karg->Status.bDataPresent =
-+                          CSMI_SAS_SSP_RESPONSE_DATA_PRESENT;
-+                      karg->Status.bResponseLength[0] =
-+                              sizeof(pScsiReply->ResponseInfo);
-+                      for (ii=0;ii<sizeof(pScsiReply->ResponseInfo);ii++) {
-+                              karg->Status.bResponse[ii] =
-+                              ((u8*)&pScsiReply->ResponseInfo)[
-+                                  (sizeof(pScsiReply->ResponseInfo)-1)-ii];
-+                      }
-+              } else if ((ioc_status != MPI_IOCSTATUS_SUCCESS) &&
-+                  (ioc_status !=  MPI_IOCSTATUS_SCSI_RECOVERED_ERROR) &&
-+                  (ioc_status != MPI_IOCSTATUS_SCSI_DATA_UNDERRUN)) {
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      dcsmisasprintk(ioc, printk(KERN_DEBUG ": SCSI IO : "));
-+                      dcsmisasprintk(ioc, printk("IOCStatus=0x%X IOCLogInfo=0x%X\n",
-+                          pScsiReply->IOCStatus,
-+                          pScsiReply->IOCLogInfo));
-+              }
-+      }
-+
-+      if ((karg->Status.uDataBytes) && (request_data) &&
-+          (karg->Parameters.uFlags & CSMI_SAS_SSP_READ)) {
-+              if (copy_to_user((void __user *)uarg->bDataBuffer,
-+                  request_data, karg->Status.uDataBytes)) {
-+                      printk(KERN_ERR "%s@%d::%s - "
-+                          "Unable to write data to user %p\n",
-+                          __FILE__, __LINE__,__FUNCTION__,
-+                          (void*)karg->bDataBuffer);
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              }
-+      }
-+
-+ cim_ssp_passthru_exit:
-+
-+
-+      if (request_data)
-+              pci_free_consistent(ioc->pcidev, request_data_sz,
-+                  (u8 *)request_data, request_data_dma);
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, karg,
-+          offsetof(CSMI_SAS_SSP_PASSTHRU_BUFFER, bDataBuffer))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to write out csmi_sas_ssp_passthru @ %p\n",
-+                              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      free_pages((unsigned long)karg, memory_pages);
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS STP Passthru command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_stp_passthru(unsigned long arg)
-+{
-+      CSMI_SAS_STP_PASSTHRU_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_STP_PASSTHRU_BUFFER    karg_hdr, *karg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      pSataPassthroughRequest_t       pSataRequest;
-+      pSataPassthroughReply_t         pSataReply;
-+      MPT_FRAME_HDR                   *mf = NULL;
-+      MPIHeader_t                     *mpi_hdr;
-+      int                             iocnum;
-+      u32                             data_sz;
-+      u64                             sas_address;
-+      u16                             req_idx;
-+      char                            *psge;
-+      int                             flagsLength;
-+      void *                          request_data;
-+      dma_addr_t                      request_data_dma;
-+      u32                             request_data_sz;
-+      int                             malloc_data_sz;
-+      int                             memory_pages;
-+      u8                              channel;
-+      u8                              id;
-+      u8                              volume_id;
-+      u8                              volume_bus;
-+      struct sas_device_info          *sas_info;
-+      u16                             ioc_status;
-+      u32                             MsgContext;
-+
-+      if (copy_from_user(&karg_hdr, uarg, sizeof(CSMI_SAS_STP_PASSTHRU_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      request_data=NULL;
-+      request_data_sz = karg_hdr.Parameters.uDataLength;
-+      volume_id = 0;
-+      volume_bus = 0;
-+      channel = 0;
-+      id = 0;
-+
-+      malloc_data_sz = (request_data_sz +
-+          offsetof(CSMI_SAS_STP_PASSTHRU_BUFFER, bDataBuffer));
-+      memory_pages = get_order(malloc_data_sz);
-+      karg = (CSMI_SAS_STP_PASSTHRU_BUFFER *)__get_free_pages(
-+              GFP_KERNEL, memory_pages);
-+      if (!karg){
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to malloc CSMI_SAS_STP_PASSTHRU_BUFFER "
-+                      "malloc_data_sz=%d memory_pages=%d\n",
-+                      __FILE__, __LINE__, __FUNCTION__,
-+                      malloc_data_sz, memory_pages);
-+              return -ENOMEM;
-+      }
-+
-+      memset(karg, 0, sizeof(*karg));
-+
-+      if (copy_from_user(karg, uarg, malloc_data_sz)) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_ssp_passthru struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg->IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      if (ioc->ioc_reset_in_progress) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+                  "Busy with IOC Reset \n",
-+                  __FILE__, __LINE__,__FUNCTION__);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EBUSY;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      /* Default to success.
-+       */
-+      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+      /* Neither a phy nor a port has been selected.
-+       */
-+      if ((karg->Parameters.bPhyIdentifier == CSMI_SAS_USE_PORT_IDENTIFIER) &&
-+              (karg->Parameters.bPortIdentifier == CSMI_SAS_IGNORE_PORT)) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_SELECT_PHY_OR_PORT;
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  "%s::%s() @%d - incorrect bPhyIdentifier and bPortIdentifier!\n",
-+                  __FILE__,__FUNCTION__, __LINE__));
-+              goto cim_stp_passthru_exit;
-+      }
-+
-+      /* A phy has been selected. Verify that it's valid.
-+       */
-+      if (karg->Parameters.bPortIdentifier == CSMI_SAS_IGNORE_PORT) {
-+
-+              /* Is the phy in range? */
-+              if (karg->Parameters.bPhyIdentifier >= ioc->num_ports) {
-+                      karg->IoctlHeader.ReturnCode =
-+                          CSMI_SAS_PHY_DOES_NOT_EXIST;
-+                      goto cim_stp_passthru_exit;
-+              }
-+      }
-+
-+      data_sz = sizeof(CSMI_SAS_STP_PASSTHRU_BUFFER) -
-+          sizeof(IOCTL_HEADER) - sizeof(u8*) +
-+          request_data_sz;
-+
-+      if ( data_sz > karg->IoctlHeader.Length ) {
-+              karg->IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  "%s::%s() @%d - expected datalen incorrect!\n",
-+                  __FILE__, __FUNCTION__,__LINE__));
-+              goto cim_stp_passthru_exit;
-+      }
-+
-+
-+      /* we will use SAS address to resolve the scsi adddressing
-+       */
-+      memcpy(&sas_address, karg->Parameters.bDestinationSASAddress,
-+          sizeof(u64));
-+      sas_address = reverse_byte_order64(sas_address);
-+
-+      /* Search the list for the matching SAS address.
-+       */
-+      sas_info = csmisas_get_device_component_by_sas_addr(ioc, sas_address);
-+      if (!sas_info || sas_info->is_cached || sas_info->is_logical_volume) {
-+              /*
-+               *Invalid SAS address
-+               */
-+              karg->IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  "%s::%s() @%d - couldn't find associated "
-+                  "SASAddress=%llX!\n", __FILE__, __FUNCTION__, __LINE__,
-+                  (unsigned long long)sas_address));
-+              goto cim_stp_passthru_exit;
-+      }
-+
-+      id = sas_info->fw.id;
-+      channel = sas_info->fw.channel;
-+
-+      /* check that this is an STP or SATA target device
-+       */
-+      if ( !(sas_info->device_info & MPI_SAS_DEVICE_INFO_STP_TARGET ) &&
-+           !(sas_info->device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE )) {
-+              karg->IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              goto cim_stp_passthru_exit;
-+      }
-+
-+      /* Get a free request frame and save the message context.
-+       */
-+      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_stp_passthru_exit;
-+        }
-+
-+      mpi_hdr = (MPIHeader_t *) mf;
-+      MsgContext = mpi_hdr->MsgContext;
-+      pSataRequest = (pSataPassthroughRequest_t) mf;
-+      req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
-+
-+      memset(pSataRequest,0,sizeof(pSataPassthroughRequest_t));
-+
-+      pSataRequest->TargetID = id;
-+      pSataRequest->Bus = channel;
-+      pSataRequest->Function = MPI_FUNCTION_SATA_PASSTHROUGH;
-+      pSataRequest->PassthroughFlags = cpu_to_le16(karg->Parameters.uFlags);
-+      pSataRequest->ConnectionRate = karg->Parameters.bConnectionRate;
-+      pSataRequest->MsgContext = MsgContext;
-+      pSataRequest->DataLength = cpu_to_le32(request_data_sz);
-+      pSataRequest->MsgFlags = 0;
-+      memcpy( pSataRequest->CommandFIS,karg->Parameters.bCommandFIS, 20);
-+
-+      psge = (char *)&pSataRequest->SGL;
-+      if (karg->Parameters.uFlags & CSMI_SAS_STP_WRITE) {
-+              flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
-+      } else if (karg->Parameters.uFlags & CSMI_SAS_STP_READ) {
-+              flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
-+      }else {
-+              flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
-+                              MPI_SGE_FLAGS_DIRECTION )
-+                              << MPI_SGE_FLAGS_SHIFT;
-+      }
-+
-+      flagsLength |= request_data_sz;
-+      if (request_data_sz > 0) {
-+              request_data = pci_alloc_consistent(
-+                  ioc->pcidev, request_data_sz, &request_data_dma);
-+
-+              if (request_data == NULL) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      mpt_free_msg_frame(ioc, mf);
-+                      goto cim_stp_passthru_exit;
-+              }
-+
-+              ioc->add_sge(psge, flagsLength, request_data_dma);
-+              if (karg->Parameters.uFlags & CSMI_SAS_SSP_WRITE)
-+                      memcpy(request_data, karg->bDataBuffer, request_data_sz);
-+      } else {
-+              ioc->add_sge(psge, flagsLength, (dma_addr_t) -1);
-+      }
-+
-+      if (csmisas_send_command_wait(ioc, mf, karg->IoctlHeader.Timeout) != 0) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_stp_passthru_exit;
-+      }
-+
-+      memset(&karg->Status,0,sizeof(CSMI_SAS_STP_PASSTHRU_STATUS));
-+
-+      if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0) {
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG  ": STP Passthru: oh no, there is no reply!!"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_stp_passthru_exit;
-+      }
-+
-+      /* process the completed Reply Message Frame */
-+      pSataReply = (pSataPassthroughReply_t ) ioc->ioctl_cmds.reply;
-+      ioc_status = le16_to_cpu(pSataReply->IOCStatus) & MPI_IOCSTATUS_MASK;
-+
-+      if (ioc_status != MPI_IOCSTATUS_SUCCESS &&
-+          ioc_status != MPI_IOCSTATUS_SCSI_DATA_UNDERRUN) {
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG ": STP Passthru: "));
-+              dcsmisasprintk(ioc, printk("IOCStatus=0x%X IOCLogInfo=0x%X SASStatus=0x%X\n",
-+                  le16_to_cpu(pSataReply->IOCStatus),
-+                  le32_to_cpu(pSataReply->IOCLogInfo),
-+                  pSataReply->SASStatus));
-+      }
-+
-+      karg->Status.bConnectionStatus =
-+          map_sas_status_to_csmi(pSataReply->SASStatus);
-+
-+      memcpy(karg->Status.bStatusFIS,pSataReply->StatusFIS, 20);
-+
-+      /*
-+       * for now, just zero out uSCR array,
-+       * then copy the one dword returned
-+       * in the reply frame into uSCR[0]
-+       */
-+      memset( karg->Status.uSCR, 0, 64);
-+      karg->Status.uSCR[0] = le32_to_cpu(pSataReply->StatusControlRegisters);
-+
-+      if((le32_to_cpu(pSataReply->TransferCount)) && (request_data) &&
-+          (karg->Parameters.uFlags & CSMI_SAS_STP_READ)) {
-+              karg->Status.uDataBytes =
-+                  min(le32_to_cpu(pSataReply->TransferCount),request_data_sz);
-+              if (copy_to_user((void __user *)uarg->bDataBuffer,
-+                  request_data, karg->Status.uDataBytes)) {
-+                      printk(KERN_ERR "%s::%s() @%d - "
-+                          "Unable to write data to user %p\n",
-+                          __FILE__, __FUNCTION__, __LINE__,
-+                          (void*)karg->bDataBuffer);
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              }
-+      }
-+
-+ cim_stp_passthru_exit:
-+
-+      if (request_data)
-+              pci_free_consistent(ioc->pcidev, request_data_sz,
-+                  (u8 *)request_data, request_data_dma);
-+
-+      /* Copy th data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, karg,
-+          offsetof(CSMI_SAS_STP_PASSTHRU_BUFFER, bDataBuffer))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to write out csmi_sas_ssp_passthru @ %p\n",
-+                              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      free_pages((unsigned long)karg, memory_pages);
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG ": %s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Firmware Download command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_firmware_download(unsigned long arg)
-+{
-+      CSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER        karg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      int                             iocnum;
-+      pMpiFwHeader_t                  pFwHeader=NULL;
-+
-+      if (copy_from_user(&karg, uarg,
-+              sizeof(CSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_firmware_download struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      /* Default to success.*/
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+      karg.Information.usStatus = CSMI_SAS_FWD_SUCCESS;
-+      karg.Information.usSeverity = CSMI_SAS_FWD_INFORMATION;
-+
-+      /* some checks of the incoming frame */
-+      if ((karg.Information.uBufferLength +
-+          sizeof(CSMI_SAS_FIRMWARE_DOWNLOAD)) >
-+          karg.IoctlHeader.Length) {
-+              karg.IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              karg.Information.usStatus = CSMI_SAS_FWD_FAILED;
-+              goto cim_firmware_download_exit;
-+      }
-+
-+      if ( karg.Information.uDownloadFlags &
-+          (CSMI_SAS_FWD_SOFT_RESET | CSMI_SAS_FWD_VALIDATE)) {
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              karg.Information.usStatus = CSMI_SAS_FWD_REJECT;
-+              karg.Information.usSeverity = CSMI_SAS_FWD_ERROR;
-+              goto cim_firmware_download_exit;
-+      }
-+
-+      /* now we need to alloc memory so we can pull in the
-+       * fw image attached to end of incoming packet.
-+       */
-+      pFwHeader = kmalloc(karg.Information.uBufferLength, GFP_KERNEL);
-+      if (!pFwHeader){
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              karg.Information.usStatus = CSMI_SAS_FWD_REJECT;
-+              karg.Information.usSeverity = CSMI_SAS_FWD_ERROR;
-+              goto cim_firmware_download_exit;
-+      }
-+      memset(pFwHeader, 0, sizeof(*pFwHeader));
-+
-+      if (copy_from_user(pFwHeader, uarg->bDataBuffer,
-+              karg.Information.uBufferLength)) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in pFwHeader @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if ( !((pFwHeader->Signature0 == MPI_FW_HEADER_SIGNATURE_0) &&
-+          (pFwHeader->Signature1 == MPI_FW_HEADER_SIGNATURE_1) &&
-+          (pFwHeader->Signature2 == MPI_FW_HEADER_SIGNATURE_2))) {
-+              // the signature check failed
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              karg.Information.usStatus = CSMI_SAS_FWD_REJECT;
-+              karg.Information.usSeverity = CSMI_SAS_FWD_ERROR;
-+              goto cim_firmware_download_exit;
-+      }
-+
-+      if ( mptctl_do_fw_download(karg.IoctlHeader.IOControllerNumber,
-+          uarg->bDataBuffer, karg.Information.uBufferLength)
-+          != 0) {
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              karg.Information.usStatus = CSMI_SAS_FWD_FAILED;
-+              karg.Information.usSeverity = CSMI_SAS_FWD_FATAL;
-+              goto cim_firmware_download_exit;
-+      }
-+
-+      if((karg.Information.uDownloadFlags & CSMI_SAS_FWD_SOFT_RESET) ||
-+          (karg.Information.uDownloadFlags & CSMI_SAS_FWD_HARD_RESET)) {
-+              if (mpt_HardResetHandler(ioc, CAN_SLEEP) != 0) {
-+                      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      karg.Information.usStatus = CSMI_SAS_FWD_FAILED;
-+                      karg.Information.usSeverity = CSMI_SAS_FWD_FATAL;
-+              }
-+      }
-+
-+ cim_firmware_download_exit:
-+
-+      if(pFwHeader)
-+              kfree(pFwHeader);
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+                              sizeof(CSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to write out csmi_sas_firmware_download @ %p\n",
-+                              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Get RAID Info command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_raid_info(unsigned long arg)
-+{
-+      CSMI_SAS_RAID_INFO_BUFFER __user *uarg =  (void __user *) arg;
-+      CSMI_SAS_RAID_INFO_BUFFER        karg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      int                             iocnum;
-+      u32                             raidFlags;
-+      u8                              maxRaidTypes;
-+      u8                              maxDrivesPerSet;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_RAID_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_get_raid_info struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+      if (!ioc->raid_data.pIocPg2)
-+              goto csmisas_get_raid_info_out;
-+      karg.Information.uNumRaidSets =
-+          ioc->raid_data.pIocPg2->NumActiveVolumes;
-+      karg.Information.uMaxRaidSets = ioc->raid_data.pIocPg2->MaxVolumes;
-+      if( ioc->raid_data.pIocPg6 ) {
-+              // get absolute maximum for all RAID sets
-+              maxDrivesPerSet = ioc->raid_data.pIocPg6->MaxDrivesIS;
-+              maxDrivesPerSet = max(ioc->raid_data.pIocPg6->MaxDrivesIM,
-+                  maxDrivesPerSet);
-+              maxDrivesPerSet = max(ioc->raid_data.pIocPg6->MaxDrivesIME,
-+                  maxDrivesPerSet);
-+              karg.Information.uMaxDrivesPerSet = maxDrivesPerSet;
-+      }
-+      else
-+              karg.Information.uMaxDrivesPerSet = 8;
-+      // For bMaxRaidSets, count bits set in bits 0-6 of CapabilitiesFlags
-+      raidFlags = ioc->raid_data.pIocPg2->CapabilitiesFlags & 0x0000007F;
-+      for( maxRaidTypes=0; raidFlags; maxRaidTypes++ )
-+              raidFlags &= raidFlags - 1;
-+      karg.Information.bMaxRaidTypes = maxRaidTypes;
-+      // ulMinRaidSetBlocks hard coded to 1MB until available from config page
-+      karg.Information.ulMinRaidSetBlocks.uLowPart = 2048;
-+      karg.Information.ulMinRaidSetBlocks.uHighPart = 0;
-+      karg.Information.ulMaxRaidSetBlocks.uLowPart = 0xffffffff;
-+      if( ioc->raid_data.pIocPg2->CapabilitiesFlags &
-+          MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING )
-+              karg.Information.ulMaxRaidSetBlocks.uHighPart = 0xffffffff;
-+      else
-+              karg.Information.ulMaxRaidSetBlocks.uHighPart = 0;
-+      karg.Information.uMaxPhysicalDrives =
-+          ioc->raid_data.pIocPg2->MaxPhysDisks;
-+      karg.Information.uMaxExtents = 1;
-+      karg.Information.uMaxModules = 0;
-+      karg.Information.uMaxTransformationMemory = 0;
-+      karg.Information.uChangeCount = ioc->csmi_change_count;
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+csmisas_get_raid_info_out:
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+                              sizeof(CSMI_SAS_RAID_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to write out csmi_sas_get_raid_info @ %p\n",
-+                              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ *    csmisas_do_raid - Format and Issue a RAID volume request message.
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @action: What do be done.
-+ *    @PhysDiskNum: Logical target id.
-+ *    @VolumeBus: Target locations bus.
-+ *    @VolumeId: Volume id
-+ *
-+ *    Returns: < 0 on a fatal error
-+ *            0 on success
-+ *
-+ *    Remark: Wait to return until reply processed by the ISR.
-+ **/
-+static int
-+csmisas_do_raid(MPT_ADAPTER *ioc, u8 action, u8 PhysDiskNum, u8 VolumeBus, u8 VolumeId, pMpiRaidActionReply_t reply)
-+{
-+      MpiRaidActionRequest_t  *pReq;
-+      MpiRaidActionReply_t    *pReply;
-+      MPT_FRAME_HDR           *mf;
-+
-+      /* Get and Populate a free Frame
-+       */
-+      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
-+              return -EAGAIN;
-+      }
-+      pReq = (MpiRaidActionRequest_t *)mf;
-+      pReq->Action = action;
-+      pReq->Reserved1 = 0;
-+      pReq->ChainOffset = 0;
-+      pReq->Function = MPI_FUNCTION_RAID_ACTION;
-+      pReq->VolumeID = VolumeId;
-+      pReq->VolumeBus = VolumeBus;
-+      pReq->PhysDiskNum = PhysDiskNum;
-+      pReq->MsgFlags = 0;
-+      pReq->Reserved2 = 0;
-+      pReq->ActionDataWord = 0; /* Reserved for this action */
-+      //pReq->ActionDataSGE = 0;
-+
-+      ioc->add_sge((char *)&pReq->ActionDataSGE,
-+              MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
-+
-+      if (csmisas_send_command_wait(ioc, mf, MPT_IOCTL_DEFAULT_TIMEOUT) != 0)
-+              return -ENODATA;
-+
-+      if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) &&
-+          (reply != NULL)){
-+              pReply = (MpiRaidActionReply_t *)&(ioc->ioctl_cmds.reply);
-+              memcpy(reply, pReply,
-+                      min(ioc->reply_sz,
-+                      4*pReply->MsgLength));
-+      }
-+
-+      return 0;
-+}
-+
-+/**
-+ * csmisas_raid_inq
-+ * @ioc = per host instance
-+ * @opcode = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH or
-+ *         MPI_FUNCTION_SCSI_IO_REQUEST
-+ * @id = target id
-+ * @bus = target bus
-+ * @inq_vpd = inquiry data, returned
-+ * @inq_vpd_sz = maximum size of inquiry data
-+ *
-+ * Return = 0(sucess), non-zero(failure)
-+ **/
-+static int
-+csmisas_raid_inq(MPT_ADAPTER *ioc, u8 opcode, u8 bus, u8 id, u8 inq_vpd_page,
-+    u8 * inq_vpd, u32 inq_vpd_sz)
-+{
-+      MPT_FRAME_HDR           *mf = NULL;
-+      MPIHeader_t             *mpi_hdr;
-+      pSCSIIORequest_t        pScsiRequest;
-+      u16                     req_idx;
-+      char                    *psge;
-+      u8                      inq_vpd_cdb[6];
-+      u8                      *request_data=NULL;
-+      dma_addr_t              request_data_dma;
-+      u32                     request_data_sz;
-+      int                     rc = 0;
-+      u32                     MsgContext;
-+
-+      request_data_sz = inq_vpd_sz;
-+
-+      /* fill-in cdb */
-+      memset(inq_vpd_cdb, 0, sizeof(inq_vpd_cdb));
-+      inq_vpd_cdb[0] = 0x12;
-+      if (inq_vpd_page) {
-+              inq_vpd_cdb[1] = 0x01; /* evpd bit */
-+              inq_vpd_cdb[2] = inq_vpd_page;
-+      }
-+      inq_vpd_cdb[3] = (u8)(request_data_sz >> 8);
-+      inq_vpd_cdb[4] = (u8)request_data_sz;
-+
-+      /* Get a free request frame and save the message context.
-+       */
-+      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
-+              goto csmisas_raid_inq_exit;
-+      }
-+
-+      mpi_hdr = (MPIHeader_t *) mf;
-+      MsgContext = mpi_hdr->MsgContext;
-+      pScsiRequest = (pSCSIIORequest_t) mf;
-+      req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
-+
-+      memset(pScsiRequest,0,sizeof(SCSIIORequest_t));
-+      pScsiRequest->Function = opcode;
-+      pScsiRequest->TargetID = id;
-+      pScsiRequest->Bus = bus;
-+      pScsiRequest->CDBLength = 6;
-+      pScsiRequest->DataLength = cpu_to_le32(request_data_sz);
-+      pScsiRequest->MsgContext = MsgContext;
-+      memcpy(pScsiRequest->CDB,inq_vpd_cdb,pScsiRequest->CDBLength);
-+      pScsiRequest->Control = cpu_to_le32(MPI_SCSIIO_CONTROL_READ);
-+      pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_SIMPLEQ);
-+      pScsiRequest->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
-+      if (ioc->sg_addr_size == sizeof(u64))
-+              pScsiRequest->MsgFlags |= MPI_SCSIIO_MSGFLGS_SENSE_WIDTH_64;
-+
-+      /* setup sense
-+       */
-+      pScsiRequest->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
-+      pScsiRequest->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma +
-+          (req_idx * MPT_SENSE_BUFFER_ALLOC));
-+
-+      request_data = pci_alloc_consistent(
-+          ioc->pcidev, request_data_sz, &request_data_dma);
-+
-+      if (request_data == NULL) {
-+              mpt_free_msg_frame(ioc, mf);
-+              rc=-1;
-+              goto csmisas_raid_inq_exit;
-+      }
-+
-+      memset(request_data,0,request_data_sz);
-+      psge = (char *)&pScsiRequest->SGL;
-+      ioc->add_sge(psge, (MPT_SGE_FLAGS_SSIMPLE_READ | 0xFC) ,
-+          request_data_dma);
-+
-+      if (csmisas_send_command_wait(ioc, mf, MPT_IOCTL_DEFAULT_TIMEOUT) != 0) {
-+              rc=-1;
-+              goto csmisas_raid_inq_exit;
-+      }
-+
-+      /* copy the request_data */
-+      memcpy(inq_vpd, request_data, request_data_sz);
-+
-+ csmisas_raid_inq_exit:
-+
-+      if (request_data)
-+              pci_free_consistent(ioc->pcidev, request_data_sz,
-+                  request_data, request_data_dma);
-+
-+      return rc;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Get RAID Config command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_raid_config(unsigned long arg)
-+{
-+      CSMI_SAS_RAID_CONFIG_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_RAID_CONFIG_BUFFER      karg,*pKarg=NULL;
-+      CONFIGPARMS                     cfg;
-+      ConfigPageHeader_t              header;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      int                             iocnum;
-+      u8                              volumeID, VolumeBus;
-+      u8                              physDiskNum, physDiskNumMax;
-+      int                             volumepage0sz = 0;
-+      int                             physdiskpage0sz = 0, ioc_page5_sz = 0;
-+      dma_addr_t                      volume0_dma, physdisk0_dma;
-+      dma_addr_t                      ioc_page5_dma = 0;
-+      pRaidVolumePage0_t              pVolume0 = NULL;
-+      pRaidPhysDiskPage0_t            pPhysDisk0 = NULL;
-+      pMpiRaidActionReply_t           pRaidActionReply = NULL;
-+      u32                             device_info = 0;
-+      pIOCPage5_t                     pIocPage5 = NULL;
-+      int                             i, idx, csmi_sas_raid_config_buffer_sz;
-+      int                             memory_pages;
-+      int                             copy_buffer_sz = 0;
-+      u64                             totalMaxLBA, tmpTotalMaxLBA;
-+      u64                             sas_address;
-+      struct sas_device_info          *sas_info;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(IOCTL_HEADER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmisas_get_raid_config struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      csmi_sas_raid_config_buffer_sz = karg.IoctlHeader.Length;
-+      memory_pages = get_order(csmi_sas_raid_config_buffer_sz);
-+      pKarg = (CSMI_SAS_RAID_CONFIG_BUFFER *)__get_free_pages(
-+              GFP_KERNEL, memory_pages);
-+      if (!pKarg){
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to malloc RAID_CONFIG_BUFFER "
-+                      "csmi_sas_raid_config_buffer_sz=%d memory_pages=%d\n",
-+                      __FILE__, __LINE__, __FUNCTION__,
-+                      csmi_sas_raid_config_buffer_sz, memory_pages);
-+              return -ENOMEM;
-+      }
-+      memset(pKarg, 0, sizeof(*pKarg));
-+
-+      if (copy_from_user(pKarg, uarg, csmi_sas_raid_config_buffer_sz)) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmisas_get_raid_config struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(pKarg->IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      if (pKarg->Configuration.uChangeCount != 0 &&
-+              pKarg->Configuration.uChangeCount != ioc->csmi_change_count ) {
-+              pKarg->IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              pKarg->Configuration.uFailureCode =
-+                  CSMI_SAS_FAIL_CODE_CHANGE_COUNT_INVALID;
-+              goto cim_get_raid_config_exit;
-+      }
-+
-+      if (!ioc->raid_data.pIocPg2) {
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_raid_config_exit;
-+      }
-+
-+      /*
-+       * Check to see if the input uRaidSetIndex is
-+       * greater than the number of RAID sets
-+       */
-+      if (pKarg->Configuration.uRaidSetIndex >=
-+          ioc->raid_data.pIocPg2->NumActiveVolumes) {
-+              pKarg->IoctlHeader.ReturnCode = CSMI_SAS_RAID_SET_OUT_OF_RANGE;
-+              goto cim_get_raid_config_exit;
-+      }
-+
-+      /*
-+       * get RAID Volume Page 0
-+       */
-+      volumeID = ioc->raid_data.pIocPg2->RaidVolume[pKarg->Configuration.uRaidSetIndex].VolumeID;
-+      VolumeBus = ioc->raid_data.pIocPg2->RaidVolume[pKarg->Configuration.uRaidSetIndex].VolumeBus;
-+
-+      header.PageVersion = 0;
-+      header.PageLength = 0;
-+      header.PageNumber = 0;
-+      header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
-+      cfg.cfghdr.hdr = &header;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = (VolumeBus << 8) + volumeID;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_raid_config_exit;
-+      }
-+
-+      if (header.PageLength == 0) {
-+              pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_raid_config_exit;
-+      }
-+
-+      volumepage0sz = header.PageLength * 4;
-+      pVolume0 = pci_alloc_consistent(ioc->pcidev, volumepage0sz,
-+          &volume0_dma);
-+      if (!pVolume0) {
-+              pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_raid_config_exit;
-+      }
-+
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+      cfg.physAddr = volume0_dma;
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_raid_config_exit;
-+      }
-+
-+      totalMaxLBA = (u64)le32_to_cpu(pVolume0->MaxLBA) |
-+          ((u64)le32_to_cpu(pVolume0->MaxLBAHigh)) << 32;
-+      tmpTotalMaxLBA = totalMaxLBA + 1;
-+      do_div(tmpTotalMaxLBA, 2048);
-+      pKarg->Configuration.bDriveCount = 0;
-+      pKarg->Configuration.uCapacity = tmpTotalMaxLBA;
-+      pKarg->Configuration.uStripeSize =
-+              le32_to_cpu(pVolume0->StripeSize)/2;
-+
-+      switch(pVolume0->VolumeType) {
-+      case MPI_RAID_VOL_TYPE_IS:
-+              pKarg->Configuration.bRaidType = CSMI_SAS_RAID_TYPE_0;
-+              break;
-+      case MPI_RAID_VOL_TYPE_IME:
-+              pKarg->Configuration.bRaidType = CSMI_SAS_RAID_TYPE_10;
-+              break;
-+      case MPI_RAID_VOL_TYPE_IM:
-+              pKarg->Configuration.bRaidType = CSMI_SAS_RAID_TYPE_1;
-+              break;
-+      default:
-+              pKarg->Configuration.bRaidType = CSMI_SAS_RAID_TYPE_OTHER;
-+              break;
-+      }
-+
-+      switch (pVolume0->VolumeStatus.State) {
-+      case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
-+              pKarg->Configuration.bStatus = CSMI_SAS_RAID_SET_STATUS_OK;
-+              break;
-+      case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
-+              /* Volume is degraded, check if Resyncing or Inactive */
-+              pKarg->Configuration.bStatus = CSMI_SAS_RAID_SET_STATUS_DEGRADED;
-+              break;
-+      case MPI_RAIDVOL0_STATUS_STATE_FAILED:
-+              pKarg->Configuration.bStatus = CSMI_SAS_RAID_SET_STATUS_FAILED;
-+              break;
-+      }
-+
-+      /* check flags */
-+      if (pVolume0->VolumeStatus.Flags &
-+          MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE)
-+              pKarg->Configuration.bStatus = CSMI_SAS_RAID_SET_STATUS_OFFLINE;
-+      else if (pVolume0->VolumeStatus.Flags &
-+          MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
-+              pKarg->Configuration.bStatus = CSMI_SAS_RAID_SET_STATUS_REBUILDING;
-+
-+      pKarg->Configuration.bInformation = 0;  /* default */
-+      if(pVolume0->VolumeStatus.Flags &
-+          MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS ) {
-+
-+              uint64_t        * ptrUint64;
-+              uint64_t        totalBlocks64, blocksRemaining64;
-+              uint32_t        totalBlocks32, blocksRemaining32;
-+
-+              /* get percentage complete */
-+              pRaidActionReply = kmalloc( sizeof(MPI_RAID_VOL_INDICATOR) +
-+                  offsetof(MSG_RAID_ACTION_REPLY,ActionData),
-+                  GFP_KERNEL);
-+
-+              if (!pRaidActionReply){
-+                      printk(KERN_ERR "%s@%d::%s() - "
-+                          "Unable to malloc @ %p\n",
-+                          __FILE__, __LINE__, __FUNCTION__,pKarg);
-+                      goto cim_get_raid_config_exit;
-+              }
-+              memset(pRaidActionReply, 0, sizeof(*pRaidActionReply));
-+
-+              csmisas_do_raid(ioc,
-+                  MPI_RAID_ACTION_INDICATOR_STRUCT,
-+                  0, VolumeBus, volumeID, pRaidActionReply);
-+
-+              ptrUint64       = (uint64_t *)&pRaidActionReply->ActionData;
-+              totalBlocks64     = *ptrUint64;
-+              ptrUint64++;
-+              blocksRemaining64 = *ptrUint64;
-+              while(totalBlocks64 > 0xFFFFFFFFUL){
-+                      totalBlocks64 = totalBlocks64 >> 1;
-+                      blocksRemaining64 = blocksRemaining64 >> 1;
-+              }
-+              totalBlocks32 = (uint32_t)totalBlocks64;
-+              blocksRemaining32 = (uint32_t)blocksRemaining64;
-+
-+              if(totalBlocks32)
-+                      pKarg->Configuration.bInformation =
-+                          (totalBlocks32 - blocksRemaining32) /
-+                          (totalBlocks32 / 100);
-+
-+              kfree(pRaidActionReply);
-+      }
-+
-+      /* fill-in more information depending on data type */
-+      if (pKarg->Configuration.bDataType ==
-+          CSMI_SAS_RAID_DATA_ADDITIONAL_DATA) {
-+              pKarg->Configuration.Data->bLabel[0] = '\0';
-+              pKarg->Configuration.Data->bRaidSetLun[1] = 0;
-+              pKarg->Configuration.Data->bWriteProtection =
-+                      CSMI_SAS_RAID_SET_WRITE_PROTECT_UNKNOWN;
-+              pKarg->Configuration.Data->bCacheSetting =
-+                      CSMI_SAS_RAID_SET_CACHE_UNKNOWN;
-+              pKarg->Configuration.Data->bCacheRatio = 0;
-+              pKarg->Configuration.Data->usBlockSize = 512;
-+              pKarg->Configuration.Data->ulRaidSetExtentOffset.uLowPart = 0;
-+              pKarg->Configuration.Data->ulRaidSetExtentOffset.uHighPart = 0;
-+              pKarg->Configuration.Data->ulRaidSetBlocks.uLowPart =
-+                  le32_to_cpu(pVolume0->MaxLBA);
-+              pKarg->Configuration.Data->ulRaidSetBlocks.uHighPart =
-+                  le32_to_cpu(pVolume0->MaxLBAHigh);
-+              if (pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IS ||
-+                  pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IME ) {
-+                      pKarg->Configuration.Data->uStripeSizeInBlocks =
-+                          le32_to_cpu(pVolume0->StripeSize);
-+              } else {
-+                      pKarg->Configuration.Data->uStripeSizeInBlocks = 0;
-+              }
-+              pKarg->Configuration.Data->uSectorsPerTrack = 128;
-+              for (i=0; i<16; i++) {
-+                      // unsupported
-+                      pKarg->Configuration.Data->bApplicationScratchPad[i] =
-+                          0xFF;
-+              }
-+              pKarg->Configuration.Data->uNumberOfHeads = 16;
-+
-+              tmpTotalMaxLBA = totalMaxLBA;
-+              do_div(tmpTotalMaxLBA,
-+                  (pKarg->Configuration.Data->uNumberOfHeads *
-+                   pKarg->Configuration.Data->uSectorsPerTrack));
-+              pKarg->Configuration.Data->uNumberOfTracks = tmpTotalMaxLBA;
-+      } else if ( pKarg->Configuration.bDataType ==
-+          CSMI_SAS_RAID_DATA_DEVICE_ID ) {
-+              /* Send inquiry to get VPD Page 0x83 */
-+              u32 vpd_page_sz;
-+              vpd_page_sz = csmi_sas_raid_config_buffer_sz -
-+                  offsetof(CSMI_SAS_RAID_CONFIG,DeviceId);
-+              if (csmisas_raid_inq(ioc, MPI_FUNCTION_SCSI_IO_REQUEST,
-+                      VolumeBus, volumeID, 0x83,
-+                      (u8*)&pKarg->Configuration.DeviceId->bDeviceIdentificationVPDPage,
-+                      vpd_page_sz) != 0) {
-+                      pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto cim_get_raid_config_exit;
-+              }
-+      } else {
-+              /* suppress drive information */
-+              if (pKarg->Configuration.bDriveCount ==
-+                      CSMI_SAS_RAID_DRIVE_COUNT_SUPRESSED) {
-+                      pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+                      goto cim_get_raid_config_exit;
-+              }
-+      }
-+
-+      /* get hotspare info, used later in this function */
-+      if (pVolume0->VolumeSettings.HotSparePool) {
-+              /* Read and save IOC Page 5
-+               */
-+              header.PageVersion = 0;
-+              header.PageLength = 0;
-+              header.PageNumber = 5;
-+              header.PageType = MPI_CONFIG_PAGETYPE_IOC;
-+              cfg.cfghdr.hdr = &header;
-+              cfg.physAddr = -1;
-+              cfg.pageAddr = 0;
-+              cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+              cfg.dir = 0;
-+              cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+              if ((mpt_config(ioc, &cfg) == 0) && (header.PageLength)) {
-+                      ioc_page5_sz = header.PageLength * 4;
-+                      pIocPage5 = pci_alloc_consistent(ioc->pcidev,
-+                          ioc_page5_sz,
-+                          &ioc_page5_dma);
-+                      memset(pIocPage5,0,ioc_page5_sz);
-+                      if (ioc_page5_dma) {
-+                              cfg.physAddr = ioc_page5_dma;
-+                              cfg.action =
-+                                  MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+                              mpt_config(ioc, &cfg);
-+                      }
-+              }
-+      }
-+
-+      /*
-+       * get RAID Physical Disk Page 0
-+       */
-+      header.PageVersion = 0;
-+      header.PageLength = 0;
-+      header.PageNumber = 0;
-+      header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
-+      cfg.cfghdr.hdr = &header;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = 0;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_raid_config_exit;
-+      }
-+
-+      if (header.PageLength == 0) {
-+              pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_raid_config_exit;
-+      }
-+
-+      physdiskpage0sz = header.PageLength * 4;
-+      pPhysDisk0 = pci_alloc_consistent(ioc->pcidev, physdiskpage0sz,
-+          &physdisk0_dma);
-+      if (!pPhysDisk0) {
-+              pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_get_raid_config_exit;
-+      }
-+      cfg.physAddr = physdisk0_dma;
-+
-+      physDiskNumMax = (csmi_sas_raid_config_buffer_sz -
-+          offsetof(CSMI_SAS_RAID_CONFIG,Drives))
-+          / sizeof(CSMI_SAS_RAID_DRIVES);
-+
-+      tmpTotalMaxLBA = totalMaxLBA;
-+      if (pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IS) {
-+              do_div(tmpTotalMaxLBA, pVolume0->NumPhysDisks);
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "IS Volume tmpTotalMaxLBA=%llX\n",
-+              (unsigned long long)tmpTotalMaxLBA));
-+      }
-+      else if (pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IME) {
-+              do_div(tmpTotalMaxLBA, pVolume0->NumPhysDisks * 2);
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "IME Volume tmpTotalMaxLBA=%llX\n",
-+              (unsigned long long)tmpTotalMaxLBA));
-+      } else {
-+              dcsmisasprintk(ioc, printk(KERN_DEBUG "IM Volume tmpTotalMaxLBA=%llX\n",
-+              (unsigned long long)tmpTotalMaxLBA));
-+      }
-+
-+      for (i=0; i< min(pVolume0->NumPhysDisks, physDiskNumMax); i++) {
-+
-+              physDiskNum = pVolume0->PhysDisk[i].PhysDiskNum;
-+              cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+              cfg.pageAddr = physDiskNum;
-+              if (mpt_config(ioc, &cfg) != 0){
-+                      pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto cim_get_raid_config_exit;
-+              }
-+
-+              pKarg->Configuration.bDriveCount++;
-+              if (pKarg->Configuration.bDataType != CSMI_SAS_RAID_DATA_DRIVES)
-+                      continue;
-+
-+              /* Search the list for the matching SAS address. */
-+              sas_info = csmisas_get_device_component_by_fw(ioc, pPhysDisk0->PhysDiskBus,
-+                  pPhysDisk0->PhysDiskID);
-+              if (sas_info) {
-+                      sas_address = reverse_byte_order64(sas_info->sas_address);
-+                      memcpy(pKarg->Configuration.Drives[i].bSASAddress,
-+                         &sas_address,sizeof(u64));
-+                      if (!device_info)
-+                              device_info = sas_info->device_info;
-+              }
-+
-+              memcpy(pKarg->Configuration.Drives[i].bModel,
-+                  pPhysDisk0->InquiryData.VendorID,
-+                  offsetof(RAID_PHYS_DISK0_INQUIRY_DATA,ProductRevLevel));
-+              memcpy(pKarg->Configuration.Drives[i].bFirmware,
-+                      pPhysDisk0->InquiryData.ProductRevLevel,
-+                      sizeof(pPhysDisk0->InquiryData.ProductRevLevel));
-+              if (csmisas_is_sata(pPhysDisk0)) {
-+                      memcpy(&pKarg->Configuration.Drives[i].bSerialNumber,
-+                              &pPhysDisk0->ExtDiskIdentifier[4],
-+                              4);
-+                      memcpy(&pKarg->Configuration.Drives[i].bSerialNumber[4],
-+                              &pPhysDisk0->DiskIdentifier,
-+                              sizeof(pPhysDisk0->DiskIdentifier));
-+              } else {
-+                      memcpy(pKarg->Configuration.Drives[i].bSerialNumber,
-+                              pPhysDisk0->DiskIdentifier,
-+                              sizeof(pPhysDisk0->DiskIdentifier));
-+              }
-+
-+              pKarg->Configuration.Drives[i].bDriveUsage =
-+                  (pPhysDisk0->PhysDiskStatus.Flags &
-+                  MPI_PHYSDISK0_STATUS_FLAG_INACTIVE_VOLUME) ?
-+                  CSMI_SAS_DRIVE_CONFIG_NOT_USED :
-+                  CSMI_SAS_DRIVE_CONFIG_MEMBER;
-+
-+              pKarg->Configuration.Drives[i].bDriveStatus =
-+                  CSMI_SAS_DRIVE_STATUS_OK;
-+              if (pPhysDisk0->PhysDiskStatus.State ==
-+                  MPI_PHYSDISK0_STATUS_OFFLINE_REQUESTED) {
-+                      pKarg->Configuration.Drives[i].bDriveStatus =
-+                          CSMI_SAS_DRIVE_STATUS_OFFLINE;
-+              } else if(pPhysDisk0->PhysDiskStatus.State) {
-+                      pKarg->Configuration.Drives[i].bDriveStatus =
-+                          CSMI_SAS_DRIVE_STATUS_FAILED;
-+                      if(pKarg->Configuration.bStatus ==
-+                          CSMI_SAS_RAID_SET_STATUS_DEGRADED)
-+                              pKarg->Configuration.bInformation = i;
-+              } else if((pVolume0->VolumeStatus.Flags &
-+                  MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) &&
-+                  (pPhysDisk0->PhysDiskStatus.Flags &
-+                  MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC))
-+                      pKarg->Configuration.Drives[i].bDriveStatus =
-+                          CSMI_SAS_DRIVE_STATUS_REBUILDING;
-+              else if(pPhysDisk0->ErrorData.SmartCount ||
-+                  (pPhysDisk0->PhysDiskStatus.Flags &
-+                  MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC))
-+                      pKarg->Configuration.Drives[i].bDriveStatus =
-+                      CSMI_SAS_DRIVE_STATUS_DEGRADED;
-+
-+              memset(pKarg->Configuration.Drives[i].bSASLun,
-+                  0, sizeof(pKarg->Configuration.Drives[i].bSASLun));
-+              if (csmisas_is_sata(pPhysDisk0)) {
-+                      pKarg->Configuration.Drives[i].bDriveType =
-+                      CSMI_SAS_DRIVE_TYPE_SATA;
-+              } else { /* drive in a volume can only be SAS/SATA */
-+                      pKarg->Configuration.Drives[i].bDriveType =
-+                              CSMI_SAS_DRIVE_TYPE_SINGLE_PORT_SAS;
-+                      if (mpt_raid_phys_disk_get_num_paths(ioc,
-+                          pVolume0->PhysDisk[i].PhysDiskNum) > 1)
-+                                      pKarg->Configuration.Drives[i].bDriveType =
-+                                          CSMI_SAS_DRIVE_TYPE_DUAL_PORT_SAS;
-+              }
-+
-+              pKarg->Configuration.Drives[i].usBlockSize = 512;
-+                      pKarg->Configuration.Drives[i].uDriveIndex =
-+                          pPhysDisk0->PhysDiskNum;
-+              pKarg->Configuration.Drives[i].ulTotalUserBlocks.uLowPart =
-+                  (u32)tmpTotalMaxLBA;
-+              pKarg->Configuration.Drives[i].ulTotalUserBlocks.uHighPart =
-+                  (u32)(tmpTotalMaxLBA >> 32);
-+      }
-+
-+      /* adding hot spare info at the end */
-+      if ((pVolume0->VolumeSettings.HotSparePool) && (pIocPage5) &&
-+          (pVolume0->VolumeType != MPI_RAID_VOL_TYPE_IS)) {
-+              for (idx = 0, i = pVolume0->NumPhysDisks ;
-+                  idx < pIocPage5->NumHotSpares ; idx++) {
-+                      if (i >= physDiskNumMax)
-+                              break;
-+                      if ((pVolume0->VolumeSettings.HotSparePool &
-+                          pIocPage5->HotSpare[idx].HotSparePool) == 0)
-+                              continue;
-+                      if(pIocPage5->HotSpare[idx].Flags !=
-+                          MPI_IOC_PAGE_5_HOT_SPARE_ACTIVE)
-+                          continue;
-+                      physDiskNum = pIocPage5->HotSpare[idx].PhysDiskNum;
-+                      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+                      cfg.pageAddr = physDiskNum;
-+                      if (mpt_config(ioc, &cfg) != 0)
-+                              continue;
-+
-+                      /* don't mix SSP hot spare
-+                       * in SATA volume
-+                       */
-+                      if (!csmisas_is_sata(pPhysDisk0) &&
-+                          (device_info &
-+                          MPI_SAS_DEVICE_INFO_SATA_DEVICE))
-+                              continue;
-+
-+                      /* don't mix SATA hot spare
-+                       * in SSP volume
-+                       */
-+                      if (csmisas_is_sata(pPhysDisk0) &&
-+                          (device_info &
-+                          MPI_SAS_DEVICE_INFO_SSP_TARGET))
-+                              continue;
-+
-+                      /* capacity check for IM volumes*/
-+                      if ((pVolume0->VolumeType ==
-+                          MPI_RAID_VOL_TYPE_IM) &&
-+                          (totalMaxLBA +
-+                          (64*2*1024) /* metadata = 64MB*/ >
-+                          le32_to_cpu(pPhysDisk0->MaxLBA)))
-+                              continue;
-+
-+                      tmpTotalMaxLBA = totalMaxLBA;
-+                      do_div(tmpTotalMaxLBA, pVolume0->NumPhysDisks);
-+                      /* capacity check for IME volumes*/
-+                      if ((pVolume0->VolumeType ==
-+                          MPI_RAID_VOL_TYPE_IME) &&
-+                          (((totalMaxLBA +
-+                          pVolume0->NumPhysDisks) * 2) +
-+                          (64*2*1024 ) /*metadata = 64MB*/ >
-+                          le32_to_cpu(pPhysDisk0->MaxLBA)))
-+                              continue;
-+
-+                      pKarg->Configuration.bDriveCount++;
-+                      if (pKarg->Configuration.bDataType !=
-+                          CSMI_SAS_RAID_DATA_DRIVES) {
-+                              i++;
-+                              continue;
-+                      }
-+
-+                      /* Search the list for the matching SAS address. */
-+                      sas_info = csmisas_get_device_component_by_fw(ioc,
-+                          pPhysDisk0->PhysDiskBus, pPhysDisk0->PhysDiskID);
-+                      if (sas_info) {
-+                              sas_address = reverse_byte_order64(sas_info->sas_address);
-+                              memcpy(pKarg->Configuration.Drives[i].bSASAddress,
-+                                 &sas_address,sizeof(u64));
-+                      }
-+
-+                      memcpy(pKarg->Configuration.Drives[i].bModel,
-+                          pPhysDisk0->InquiryData.VendorID,
-+                          offsetof(RAID_PHYS_DISK0_INQUIRY_DATA,ProductRevLevel));
-+                      memcpy(pKarg->Configuration.Drives[i].bFirmware,
-+                              pPhysDisk0->InquiryData.ProductRevLevel,
-+                              sizeof(pPhysDisk0->InquiryData.ProductRevLevel));
-+                      if (csmisas_is_sata(pPhysDisk0)) {
-+                              memcpy(&pKarg->Configuration.Drives[i].bSerialNumber,
-+                                      &pPhysDisk0->ExtDiskIdentifier[4],
-+                                      4);
-+                              memcpy(&pKarg->Configuration.Drives[i].bSerialNumber[4],
-+                                      &pPhysDisk0->DiskIdentifier,
-+                                      sizeof(pPhysDisk0->DiskIdentifier));
-+                      } else {
-+                              memcpy(pKarg->Configuration.Drives[i].bSerialNumber,
-+                                      pPhysDisk0->DiskIdentifier,
-+                                      sizeof(pPhysDisk0->DiskIdentifier));
-+                      }
-+                      pKarg->Configuration.Drives[i].bDriveStatus =
-+                          CSMI_SAS_DRIVE_STATUS_OK;
-+                      if(pPhysDisk0->PhysDiskStatus.State)
-+                              pKarg->Configuration.Drives[i].bDriveStatus =
-+                                  CSMI_SAS_DRIVE_STATUS_FAILED;
-+                      else if(pPhysDisk0->ErrorData.SmartCount)
-+                              pKarg->Configuration.Drives[i].bDriveStatus =
-+                                  CSMI_SAS_DRIVE_STATUS_DEGRADED;
-+                      pKarg->Configuration.Drives[i].bDriveUsage =
-+                          CSMI_SAS_DRIVE_CONFIG_SPARE;
-+                      pKarg->Configuration.Drives[i].usBlockSize = 512;
-+                      pKarg->Configuration.Drives[i].uDriveIndex =
-+                          pPhysDisk0->PhysDiskNum;
-+                      if (csmisas_is_sata(pPhysDisk0)) {
-+                              pKarg->Configuration.Drives[i].bDriveType =
-+                              CSMI_SAS_DRIVE_TYPE_SATA;
-+                      } else { /* drive in a volume can only be SAS/SATA */
-+                              pKarg->Configuration.Drives[i].bDriveType =
-+                                      CSMI_SAS_DRIVE_TYPE_SINGLE_PORT_SAS;
-+                              if (mpt_raid_phys_disk_get_num_paths(ioc,
-+                                  pVolume0->PhysDisk[i].PhysDiskNum) > 1)
-+                                      pKarg->Configuration.Drives[i].bDriveType =
-+                                          CSMI_SAS_DRIVE_TYPE_DUAL_PORT_SAS;
-+                      }
-+                      i++;
-+              }
-+      }
-+
-+      // Only return data on the first 240 drives
-+      if( pKarg->Configuration.bDriveCount > 0xF0 )
-+              pKarg->Configuration.bDriveCount =
-+                  CSMI_SAS_RAID_DRIVE_COUNT_TOO_BIG;
-+
-+      pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+ cim_get_raid_config_exit:
-+
-+      if (pVolume0 != NULL)
-+              pci_free_consistent(ioc->pcidev, volumepage0sz, pVolume0,
-+                  volume0_dma);
-+
-+      if(pPhysDisk0 != NULL)
-+              pci_free_consistent(ioc->pcidev, physdiskpage0sz, pPhysDisk0,
-+                  physdisk0_dma);
-+
-+      if(pIocPage5 != NULL)
-+              pci_free_consistent(ioc->pcidev, ioc_page5_sz, pIocPage5,
-+                  ioc_page5_dma);
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+
-+      /* find the buffer size to copy depending on how much is filled-in */
-+      switch (pKarg->Configuration.bDataType) {
-+      case CSMI_SAS_RAID_DATA_ADDITIONAL_DATA:
-+              copy_buffer_sz = sizeof(IOCTL_HEADER) +
-+                  offsetof(CSMI_SAS_RAID_CONFIG,Data) +
-+                  sizeof(CSMI_SAS_RAID_SET_ADDITIONAL_DATA);
-+              break;
-+      case CSMI_SAS_RAID_DATA_DRIVES:
-+              if (pKarg->Configuration.bDriveCount ==
-+                  CSMI_SAS_RAID_DRIVE_COUNT_SUPRESSED)
-+                      copy_buffer_sz = sizeof(IOCTL_HEADER) +
-+                          offsetof(CSMI_SAS_RAID_CONFIG,Drives);
-+              else
-+                      copy_buffer_sz = sizeof(IOCTL_HEADER) +
-+                          offsetof(CSMI_SAS_RAID_CONFIG,Drives) +
-+                          (pKarg->Configuration.bDriveCount *
-+                          sizeof(CSMI_SAS_RAID_DRIVES));
-+              break;
-+      case CSMI_SAS_RAID_DATA_DEVICE_ID:
-+              copy_buffer_sz = csmi_sas_raid_config_buffer_sz;
-+              break;
-+      }
-+
-+      if (copy_to_user(uarg, pKarg, copy_buffer_sz)) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                     "Unable to write out csmi_sas_get_raid_config @ %p\n",
-+                         __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      free_pages((unsigned long)pKarg, memory_pages);
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Get RAID Features command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_raid_features(unsigned long arg)
-+{
-+      CSMI_SAS_RAID_FEATURES_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_RAID_FEATURES_BUFFER karg, *pKarg=NULL;
-+      int csmi_sas_raid_features_buffer_sz, iocnum;
-+      int                             memory_pages;
-+      MPT_ADAPTER             *ioc = NULL;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(IOCTL_HEADER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_get_raid_features struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      csmi_sas_raid_features_buffer_sz = karg.IoctlHeader.Length;
-+      memory_pages = get_order(csmi_sas_raid_features_buffer_sz);
-+      pKarg = (CSMI_SAS_RAID_FEATURES_BUFFER *)__get_free_pages(
-+              GFP_KERNEL, memory_pages);
-+      if (!pKarg){
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to malloc RAID_FEATURES_BUFFER "
-+                      "csmi_sas_raid_features_buffer_sz=%d memory_pages=%d\n",
-+                      __FILE__, __LINE__, __FUNCTION__,
-+                      csmi_sas_raid_features_buffer_sz, memory_pages);
-+              return -ENOMEM;
-+      }
-+      memset(pKarg, 0, sizeof(*pKarg));
-+
-+      if (copy_from_user(pKarg, uarg, csmi_sas_raid_features_buffer_sz)) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_get_raid_features struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(pKarg->IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      if (pKarg->Information.uChangeCount != 0 &&
-+          pKarg->Information.uChangeCount != ioc->csmi_change_count ) {
-+              pKarg->IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              pKarg->Information.uFailureCode =
-+                  CSMI_SAS_FAIL_CODE_CHANGE_COUNT_INVALID;
-+              goto cim_get_raid_features_exit;
-+      }
-+
-+      pKarg->Information.uFeatures = CSMI_SAS_RAID_FEATURE_REBUILD |
-+          CSMI_SAS_RAID_FEATURE_SURFACE_SCAN |
-+          CSMI_SAS_RAID_FEATURE_SPARES_SHARED;
-+      pKarg->Information.bDefaultTransformPriority =
-+          CSMI_SAS_PRIORITY_UNKNOWN;
-+      pKarg->Information.bTransformPriority = CSMI_SAS_PRIORITY_UNKNOWN;
-+      pKarg->Information.bDefaultRebuildPriority = CSMI_SAS_PRIORITY_UNKNOWN;
-+      pKarg->Information.bRebuildPriority =
-+          pKarg->Information.bDefaultRebuildPriority;
-+      pKarg->Information.bDefaultSurfaceScanPriority =
-+          CSMI_SAS_PRIORITY_UNKNOWN;
-+      pKarg->Information.bSurfaceScanPriority = CSMI_SAS_PRIORITY_UNKNOWN;
-+      pKarg->Information.uRaidSetTransformationRules = 0;
-+
-+       /* IS */
-+      pKarg->Information.RaidType[0].bRaidType = CSMI_SAS_RAID_TYPE_0;
-+      pKarg->Information.RaidType[0].uSupportedStripeSizeMap = 0x80;
-+
-+      /* IM */
-+      pKarg->Information.RaidType[1].bRaidType = CSMI_SAS_RAID_TYPE_1;
-+      pKarg->Information.RaidType[1].uSupportedStripeSizeMap = 0;
-+
-+      /* IME */
-+      pKarg->Information.RaidType[2].bRaidType = CSMI_SAS_RAID_TYPE_1E;
-+      pKarg->Information.RaidType[2].uSupportedStripeSizeMap = 0x80;
-+
-+      pKarg->Information.RaidType[3].bRaidType = CSMI_SAS_RAID_TYPE_END;
-+      pKarg->Information.bCacheRatiosSupported[0] =
-+          CSMI_SAS_RAID_CACHE_RATIO_END;
-+
-+ cim_get_raid_features_exit:
-+
-+      /*
-+       * Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, pKarg,
-+          sizeof(CSMI_SAS_RAID_FEATURES_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+              "Unable to write out csmi_sas_get_raid_features @ %p\n",
-+              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      free_pages((unsigned long)pKarg, memory_pages);
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Set RAID Control command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_set_raid_control(unsigned long arg)
-+{
-+      CSMI_SAS_RAID_CONTROL_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_RAID_CONTROL_BUFFER karg, *pKarg=NULL;
-+      int csmi_sas_raid_control_buffer_sz, iocnum;
-+      int                             memory_pages;
-+      MPT_ADAPTER     *ioc = NULL;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(IOCTL_HEADER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_set_raid_control struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      csmi_sas_raid_control_buffer_sz = karg.IoctlHeader.Length;
-+      memory_pages = get_order(csmi_sas_raid_control_buffer_sz);
-+      pKarg = (CSMI_SAS_RAID_CONTROL_BUFFER *)__get_free_pages(
-+              GFP_KERNEL, memory_pages);
-+      if (!pKarg){
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to malloc RAID_CONTROL_BUFFER "
-+                      "csmi_sas_raid_control_buffer_sz=%d memory_pages=%d\n",
-+                      __FILE__, __LINE__, __FUNCTION__,
-+                      csmi_sas_raid_control_buffer_sz, memory_pages);
-+              return -ENOMEM;
-+      }
-+      memset(pKarg, 0, sizeof(*pKarg));
-+
-+      if (copy_from_user(pKarg, uarg, csmi_sas_raid_control_buffer_sz)) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_set_raid_control struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(pKarg->IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      if (pKarg->Information.uChangeCount != 0 &&
-+              pKarg->Information.uChangeCount != ioc->csmi_change_count ) {
-+              pKarg->IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              pKarg->Information.uFailureCode =
-+                  CSMI_SAS_FAIL_CODE_CHANGE_COUNT_INVALID;
-+              goto cim_set_raid_control_exit;
-+      }
-+
-+      if (pKarg->Information.bTransformPriority !=
-+          CSMI_SAS_PRIORITY_UNCHANGED) {
-+              pKarg->IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              pKarg->Information.uFailureCode =
-+                  CSMI_SAS_FAIL_CODE_TRANSFORM_PRIORITY_INVALID;
-+              goto cim_set_raid_control_exit;
-+      }
-+
-+      if (pKarg->Information.bRebuildPriority !=
-+          CSMI_SAS_PRIORITY_AUTO &&
-+              pKarg->Information.bRebuildPriority !=
-+              CSMI_SAS_PRIORITY_UNCHANGED) {
-+              pKarg->IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              pKarg->Information.uFailureCode =
-+                  CSMI_SAS_FAIL_CODE_REBUILD_PRIORITY_INVALID;
-+              goto cim_set_raid_control_exit;
-+      }
-+
-+      if (pKarg->Information.bCacheRatioFlag ==
-+          CSMI_SAS_RAID_CACHE_RATIO_DISABLE) {
-+              pKarg->IoctlHeader.ReturnCode =
-+                  CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              pKarg->Information.uFailureCode =
-+                  CSMI_SAS_FAIL_CODE_CACHE_RATIO_INVALID;
-+              goto cim_set_raid_control_exit;
-+      }
-+
-+      if( !strcmp(pKarg->Information.bClearConfiguration,
-+              CSMI_SAS_RAID_CLEAR_CONFIGURATION_SIGNATURE) ) {
-+              pKarg->IoctlHeader.ReturnCode =
-+                      CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              pKarg->Information.uFailureCode =
-+                      CSMI_SAS_FAIL_CODE_CLEAR_CONFIGURATION_INVALID;
-+              goto cim_set_raid_control_exit;
-+      }
-+
-+      pKarg->Information.bFailureDescription[0] = '\0';
-+
-+ cim_set_raid_control_exit:
-+
-+      /*
-+       * Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, pKarg,
-+              sizeof(CSMI_SAS_RAID_CONTROL_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+              "Unable to write out csmi_sas_set_raid_control @ %p\n",
-+              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)pKarg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      free_pages((unsigned long)pKarg, memory_pages);
-+      return 0;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Get Raid Element.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_raid_element(unsigned long arg)
-+{
-+      CSMI_SAS_RAID_ELEMENT_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_RAID_ELEMENT_BUFFER     karg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      int                             iocnum;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_RAID_ELEMENT_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmisas_get_raid_element struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+/* TODO - implement IOCTL here */
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_BAD_CNTL_CODE;
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG ": not implemented\n"));
-+
-+// csmisas_get_raid_element_exit:
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+                              sizeof(CSMI_SAS_RAID_ELEMENT_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to write out csmisas_get_raid_element @ %p\n",
-+                              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Set Raid Operation
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_set_raid_operation(unsigned long arg)
-+{
-+      CSMI_SAS_RAID_SET_OPERATION_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_RAID_SET_OPERATION_BUFFER       karg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      int                             iocnum;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_RAID_SET_OPERATION_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_set_raid_operation struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+/* TODO - implement IOCTL here */
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_BAD_CNTL_CODE;
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG ": not implemented\n"));
-+
-+// cim_set_raid_operation:
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+                              sizeof(CSMI_SAS_RAID_SET_OPERATION_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to write out csmi_set_raid_operation @ %p\n",
-+                              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+
-+}
-+
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Task Managment Config command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_task_managment(unsigned long arg)
-+{
-+      CSMI_SAS_SSP_TASK_IU_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_SSP_TASK_IU_BUFFER      karg;
-+      pSCSITaskMgmt_t                 pScsiTm;
-+      pSCSITaskMgmtReply_t            pScsiTmReply;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      MPT_SCSI_HOST                   *hd;
-+      MPT_FRAME_HDR                   *mf = NULL;
-+      MPIHeader_t                     *mpi_hdr;
-+      int                             iocnum;
-+      u8                              taskType;
-+      u8                              channel;
-+      u8                              id;
-+      u8                              queueTag;
-+      u32                             TaskMsgContext = 0;
-+      int                             i;
-+      u8                              found_qtag;
-+      struct sas_device_info          *sas_info;
-+      u16                             ioc_status;
-+      u32                             MsgContext;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_SSP_TASK_IU_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_task_managment struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
-+
-+      sas_info = csmisas_get_device_component_by_os(ioc,
-+          karg.Parameters.bPathId, karg.Parameters.bTargetId);
-+      if (!sas_info || sas_info->is_cached || sas_info->is_logical_volume)
-+              goto cim_get_task_managment_exit;
-+
-+      channel = sas_info->fw.channel;
-+      id = sas_info->fw.id;
-+      queueTag = (u8)karg.Parameters.uQueueTag & 0xFF;
-+      hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
-+
-+      /* try to catch an error
-+       */
-+      if ((karg.Parameters.uFlags & CSMI_SAS_TASK_IU) &&
-+          (karg.Parameters.uFlags & CSMI_SAS_HARD_RESET_SEQUENCE))
-+              goto cim_get_task_managment_exit;
-+
-+      if (karg.Parameters.uFlags & CSMI_SAS_TASK_IU) {
-+              switch (karg.Parameters.bTaskManagementFunction) {
-+
-+              case CSMI_SAS_SSP_ABORT_TASK:
-+                      taskType = MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK;
-+                      break;
-+              case CSMI_SAS_SSP_ABORT_TASK_SET:
-+                      taskType = MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET;
-+                      break;
-+              case CSMI_SAS_SSP_CLEAR_TASK_SET:
-+                      taskType = MPI_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET;
-+                      break;
-+              case CSMI_SAS_SSP_LOGICAL_UNIT_RESET:
-+                      taskType = MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET;
-+                      break;
-+              case CSMI_SAS_SSP_CLEAR_ACA:
-+              case CSMI_SAS_SSP_QUERY_TASK:
-+              default:
-+                      goto cim_get_task_managment_exit;
-+              }
-+      } else if (karg.Parameters.uFlags & CSMI_SAS_HARD_RESET_SEQUENCE)
-+              taskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
-+      else
-+              goto cim_get_task_managment_exit;
-+
-+      switch (karg.Parameters.uInformation) {
-+              case CSMI_SAS_SSP_TEST:
-+                      dcsmisasprintk(ioc, printk(KERN_DEBUG "TM request for test purposes\n"));
-+                      break;
-+              case CSMI_SAS_SSP_EXCEEDED:
-+                      dcsmisasprintk(ioc, printk(KERN_DEBUG "TM request due to timeout\n"));
-+                      break;
-+              case CSMI_SAS_SSP_DEMAND:
-+                      dcsmisasprintk(ioc, printk(KERN_DEBUG "TM request demanded by app\n"));
-+                      break;
-+              case CSMI_SAS_SSP_TRIGGER:
-+                      dcsmisasprintk(ioc, printk(KERN_DEBUG "TM request sent to trigger event\n"));
-+                      break;
-+      }
-+
-+      switch (taskType) {
-+
-+      case MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
-+      /*
-+       * look up qtag in the ScsiLookup[] table
-+       */
-+              for (i = 0, found_qtag = 0; i < hd->ioc->req_depth; i++) {
-+                      if ((ioc->ScsiLookup[i]) &&
-+                          (ioc->ScsiLookup[i]->tag == queueTag)) {
-+                              mf = MPT_INDEX_2_MFPTR(hd->ioc, i);
-+                              TaskMsgContext =
-+                                  mf->u.frame.hwhdr.msgctxu.MsgContext;
-+                              found_qtag=1;
-+                              break;
-+                      }
-+              }
-+
-+              if(!found_qtag)
-+                      goto cim_get_task_managment_exit;
-+
-+      case MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
-+      case MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
-+      case MPI_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET:
-+      /* for now, this should work
-+       */
-+      case MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
-+
-+              /* Single threading ....
-+               */
-+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15))
-+              mutex_lock(&ioc->taskmgmt_cmds.mutex);
-+              if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
-+                      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+                      karg.IoctlHeader.ReturnCode =
-+                          CSMI_SAS_STATUS_FAILED;
-+                      goto cim_get_task_managment_exit;
-+              }
-+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0))
-+              if (mptctl_set_tm_flags(hd) != 0) {
-+                      karg.IoctlHeader.ReturnCode =
-+                          CSMI_SAS_STATUS_FAILED;
-+                      goto cim_get_task_managment_exit;
-+              }
-+#endif
-+              /* Send request
-+               */
-+              if ((mf = mpt_get_msg_frame(mptctl_taskmgmt_id, ioc)) == NULL) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
-+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15))
-+                      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+                      mpt_clear_taskmgmt_in_progress_flag(ioc);
-+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0))
-+                      mptctl_free_tm_flags(ioc);
-+#endif
-+                      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto cim_get_task_managment_exit;
-+              }
-+
-+              mpi_hdr = (MPIHeader_t *) mf;
-+              MsgContext = mpi_hdr->MsgContext;
-+              pScsiTm = (pSCSITaskMgmt_t ) mf;
-+
-+              memset(pScsiTm,0,sizeof(SCSITaskMgmt_t));
-+              pScsiTm->TaskType = taskType;
-+              pScsiTm->Bus = channel;
-+              pScsiTm->TargetID = id;
-+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15))
-+              int_to_scsilun(karg.Parameters.bLun,
-+                  (struct scsi_lun *)pScsiTm->LUN);
-+#else
-+              pScsiTm->LUN[1] = karg.Parameters.bLun;
-+#endif
-+              pScsiTm->MsgContext = MsgContext;
-+              pScsiTm->TaskMsgContext = TaskMsgContext;
-+              pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
-+
-+              if (csmisas_send_handshake_wait(ioc, mf,
-+                  karg.IoctlHeader.Timeout) != 0)  {
-+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15))
-+                      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+#endif
-+                      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto cim_get_task_managment_exit;
-+              }
-+
-+              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
-+
-+                      pScsiTmReply =
-+                          (pSCSITaskMgmtReply_t ) ioc->ioctl_cmds.reply;
-+
-+                      ioc_status = le16_to_cpu(pScsiTmReply->IOCStatus)
-+                          & MPI_IOCSTATUS_MASK;
-+
-+                      memset(&karg.Status,0,
-+                          sizeof(CSMI_SAS_SSP_PASSTHRU_STATUS));
-+
-+                      if(ioc_status == MPI_IOCSTATUS_SUCCESS) {
-+                              karg.IoctlHeader.ReturnCode =
-+                                  CSMI_SAS_STATUS_SUCCESS;
-+                              karg.Status.bSSPStatus =
-+                                  CSMI_SAS_SSP_STATUS_COMPLETED;
-+                      }else if(ioc_status == MPI_IOCSTATUS_INSUFFICIENT_RESOURCES) {
-+                              karg.IoctlHeader.ReturnCode =
-+                                  CSMI_SAS_STATUS_SUCCESS;
-+                              karg.Status.bSSPStatus =
-+                                  CSMI_SAS_SSP_STATUS_RETRY;
-+                      }else {
-+                              karg.IoctlHeader.ReturnCode =
-+                                  CSMI_SAS_STATUS_FAILED;
-+                              karg.Status.bSSPStatus =
-+                                  CSMI_SAS_SSP_STATUS_FATAL_ERROR;
-+                      }
-+              } else
-+                      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+
-+              break;
-+
-+      default:
-+              karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              break;
-+      }
-+
-+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15))
-+      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+#endif
-+
-+ cim_get_task_managment_exit:
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+                              sizeof(CSMI_SAS_SSP_TASK_IU_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to write out csmi_sas_task_managment @ %p\n",
-+                              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ *    map_sas_status_to_csmi - Conversion  for Connection Status
-+ *    @mpi_sas_status: Sas status returned by the firmware
-+ *
-+ *    Returns converted connection status
-+ *
-+ **/
-+static u8
-+map_sas_status_to_csmi(u8 mpi_sas_status)
-+{
-+      u8  csmi_connect_status;
-+
-+      switch (mpi_sas_status) {
-+
-+      case MPI_SASSTATUS_SUCCESS:
-+              csmi_connect_status = CSMI_SAS_OPEN_ACCEPT;
-+              break;
-+
-+      case MPI_SASSTATUS_UTC_BAD_DEST:
-+              csmi_connect_status = CSMI_SAS_OPEN_REJECT_BAD_DESTINATION;
-+              break;
-+
-+      case MPI_SASSTATUS_UTC_CONNECT_RATE_NOT_SUPPORTED:
-+              csmi_connect_status = CSMI_SAS_OPEN_REJECT_RATE_NOT_SUPPORTED;
-+              break;
-+
-+      case MPI_SASSTATUS_UTC_PROTOCOL_NOT_SUPPORTED:
-+              csmi_connect_status =
-+                  CSMI_SAS_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED;
-+              break;
-+
-+      case MPI_SASSTATUS_UTC_STP_RESOURCES_BUSY:
-+              csmi_connect_status = CSMI_SAS_OPEN_REJECT_STP_RESOURCES_BUSY;
-+              break;
-+
-+      case MPI_SASSTATUS_UTC_WRONG_DESTINATION:
-+              csmi_connect_status = CSMI_SAS_OPEN_REJECT_WRONG_DESTINATION;
-+              break;
-+
-+      case MPI_SASSTATUS_SDSF_NAK_RECEIVED:
-+              csmi_connect_status = CSMI_SAS_OPEN_REJECT_RETRY;
-+              break;
-+
-+      case MPI_SASSTATUS_SDSF_CONNECTION_FAILED:
-+              csmi_connect_status = CSMI_SAS_OPEN_REJECT_PATHWAY_BLOCKED;
-+              break;
-+
-+      case MPI_SASSTATUS_INITIATOR_RESPONSE_TIMEOUT:
-+              csmi_connect_status =  CSMI_SAS_OPEN_REJECT_NO_DESTINATION;
-+              break;
-+
-+      case MPI_SASSTATUS_UNKNOWN_ERROR:
-+      case MPI_SASSTATUS_INVALID_FRAME:
-+      case MPI_SASSTATUS_UTC_BREAK_RECEIVED:
-+      case MPI_SASSTATUS_UTC_PORT_LAYER_REQUEST:
-+      case MPI_SASSTATUS_SHORT_INFORMATION_UNIT:
-+      case MPI_SASSTATUS_LONG_INFORMATION_UNIT:
-+      case MPI_SASSTATUS_XFER_RDY_INCORRECT_WRITE_DATA:
-+      case MPI_SASSTATUS_XFER_RDY_REQUEST_OFFSET_ERROR:
-+      case MPI_SASSTATUS_XFER_RDY_NOT_EXPECTED:
-+      case MPI_SASSTATUS_DATA_INCORRECT_DATA_LENGTH:
-+      case MPI_SASSTATUS_DATA_TOO_MUCH_READ_DATA:
-+      case MPI_SASSTATUS_DATA_OFFSET_ERROR:
-+              csmi_connect_status = CSMI_SAS_OPEN_REJECT_RESERVE_STOP;
-+              break;
-+
-+      default:
-+              csmi_connect_status = CSMI_SAS_OPEN_REJECT_RESERVE_STOP;
-+              break;
-+      }
-+
-+      return csmi_connect_status;
-+}
-+
-+/**
-+ *                      csmisas_phy_reset
-+ *    Issues a phy link reset or phy hard reset
-+ *
-+ *    @ioc - Pointer to MPT_ADAPTER structure
-+ *    @PhyNum - phy number
-+ *    @opcode - {MPI_SAS_OP_PHY_LINK_RESET,MPI_SAS_OP_PHY_HARD_RESET}
-+ *
-+ *    Returns: 0 for success, non-zero error
-+ **/
-+static int
-+csmisas_phy_reset(MPT_ADAPTER *ioc, u8 PhyNum, u8 opcode)
-+{
-+      SasIoUnitControlRequest_t       *sasIoUnitCntrReq;
-+      SasIoUnitControlReply_t         *sasIoUnitCntrReply;
-+      MPT_FRAME_HDR                   *mf = NULL;
-+      MPIHeader_t                     *mpi_hdr;
-+      u16                             ioc_status;
-+      u32                             MsgContext;
-+
-+      if ((opcode != MPI_SAS_OP_PHY_LINK_RESET) &&
-+          (opcode != MPI_SAS_OP_PHY_HARD_RESET))
-+          return -1;
-+
-+      /* Get a MF for this command.
-+       */
-+      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
-+              return -1;
-+        }
-+
-+      mpi_hdr = (MPIHeader_t *) mf;
-+      MsgContext =  mpi_hdr->MsgContext;
-+      sasIoUnitCntrReq = (SasIoUnitControlRequest_t *)mf;
-+      memset(sasIoUnitCntrReq,0,sizeof(SasIoUnitControlRequest_t));
-+      sasIoUnitCntrReq->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
-+      sasIoUnitCntrReq->MsgContext = MsgContext;
-+      sasIoUnitCntrReq->Operation = opcode;
-+      sasIoUnitCntrReq->PhyNum = PhyNum;
-+
-+      if (csmisas_send_command_wait(ioc, mf, MPT_IOCTL_DEFAULT_TIMEOUT) != 0)
-+              return -1;
-+
-+      if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0)
-+              return -1;
-+
-+      /* process the completed Reply Message Frame */
-+      sasIoUnitCntrReply = (SasIoUnitControlReply_t *)ioc->ioctl_cmds.reply;
-+      ioc_status = le16_to_cpu(sasIoUnitCntrReply->IOCStatus)
-+          & MPI_IOCSTATUS_MASK;
-+      if (ioc_status != MPI_IOCSTATUS_SUCCESS) {
-+              printk(KERN_DEBUG "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
-+                  __FUNCTION__,
-+                  sasIoUnitCntrReply->IOCStatus,
-+                  sasIoUnitCntrReply->IOCLogInfo);
-+              return -1;
-+      }
-+      return 0;
-+}
-+
-+/** Prototype Routine for the CSMI SAS Phy Control command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_phy_control(unsigned long arg)
-+{
-+      CSMI_SAS_PHY_CONTROL_BUFFER __user *uarg = (void __user *) arg;
-+      IOCTL_HEADER                    ioctl_header;
-+      PCSMI_SAS_PHY_CONTROL_BUFFER    karg;
-+      SasIOUnitPage0_t                *sasIoUnitPg0=NULL;
-+      dma_addr_t                      sasIoUnitPg0_dma;
-+      int                             sasIoUnitPg0_data_sz=0;
-+      SasIOUnitPage1_t                *sasIoUnitPg1=NULL;
-+      dma_addr_t                      sasIoUnitPg1_dma;
-+      int                             sasIoUnitPg1_data_sz=0;
-+      ConfigExtendedPageHeader_t      hdr;
-+      CONFIGPARMS                     cfg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      int                             iocnum;
-+      int                             csmi_sas_phy_control_buffer_sz;
-+      int                             memory_pages;
-+
-+      if (copy_from_user(&ioctl_header, uarg, sizeof(IOCTL_HEADER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in IOCTL_HEADER"
-+                  "struct @ %p\n", __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      csmi_sas_phy_control_buffer_sz = ioctl_header.Length;
-+      memory_pages = get_order(csmi_sas_phy_control_buffer_sz);
-+      karg = (PCSMI_SAS_PHY_CONTROL_BUFFER)__get_free_pages(
-+              GFP_KERNEL, memory_pages);
-+      if (!karg){
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to malloc SAS_PHY_CONTROL_BUFFER "
-+                      "csmi_sas_phy_control_buffer_sz=%d memory_pages=%d\n",
-+                      __FILE__, __LINE__, __FUNCTION__,
-+                      csmi_sas_phy_control_buffer_sz, memory_pages);
-+              return -ENOMEM;
-+      }
-+      memset(karg, 0, sizeof(*karg));
-+
-+      if (copy_from_user(karg, uarg, csmi_sas_phy_control_buffer_sz)) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_phy_control_buffer "
-+                  "struct @ %p\n", __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(ioctl_header.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      if (karg->bPhyIdentifier >= ioc->num_ports) {
-+              karg->IoctlHeader.ReturnCode =
-+                 CSMI_SAS_STATUS_INVALID_PARAMETER;
-+              goto cim_sas_phy_control_exit;
-+      }
-+
-+      /*
-+       *  Retreive SAS IOUNIT PAGE 0
-+       */
-+
-+      hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
-+      hdr.ExtPageLength = 0;
-+      hdr.PageNumber = 0;
-+      hdr.Reserved1 = 0;
-+      hdr.Reserved2 = 0;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
-+
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = 0;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED: READ MPI_SASIOUNITPAGE0: HEADER\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sas_phy_control_exit;
-+      }
-+
-+      if (hdr.ExtPageLength == 0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sas_phy_control_exit;
-+      }
-+
-+      sasIoUnitPg0_data_sz = hdr.ExtPageLength * 4;
-+      sasIoUnitPg0 = (SasIOUnitPage0_t *) pci_alloc_consistent(ioc->pcidev,
-+          sasIoUnitPg0_data_sz, &sasIoUnitPg0_dma);
-+
-+      if (!sasIoUnitPg0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sas_phy_control_exit;
-+      }
-+
-+      memset((u8 *)sasIoUnitPg0, 0, sasIoUnitPg0_data_sz);
-+      cfg.physAddr = sasIoUnitPg0_dma;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED: READ MPI_SASIOUNITPAGE0: CURRENT\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sas_phy_control_exit;
-+      }
-+
-+      /*
-+       *  Retreive SAS IOUNIT PAGE 1
-+       */
-+
-+      hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
-+      hdr.ExtPageLength = 0;
-+      hdr.PageNumber = 1;
-+      hdr.Reserved1 = 0;
-+      hdr.Reserved2 = 0;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
-+
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = 0;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED: READ MPI_SASIOUNITPAGE1: HEADER\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sas_phy_control_exit;
-+      }
-+
-+      if (hdr.ExtPageLength == 0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sas_phy_control_exit;
-+      }
-+
-+      sasIoUnitPg1_data_sz = hdr.ExtPageLength * 4;
-+      sasIoUnitPg1 = (SasIOUnitPage1_t *) pci_alloc_consistent(ioc->pcidev,
-+          sasIoUnitPg1_data_sz, &sasIoUnitPg1_dma);
-+
-+      if (!sasIoUnitPg1) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sas_phy_control_exit;
-+      }
-+
-+      memset((u8 *)sasIoUnitPg1, 0, sasIoUnitPg1_data_sz);
-+      cfg.physAddr = sasIoUnitPg1_dma;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              dcsmisasprintk(ioc, printk(KERN_ERR
-+                  ": FAILED:  READ MPI_SASIOUNITPAGE1: CURRENT\n"));
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+              goto cim_sas_phy_control_exit;
-+      }
-+
-+      switch (karg->uFunction) {
-+
-+      case CSMI_SAS_PC_LINK_RESET:
-+      case CSMI_SAS_PC_HARD_RESET:
-+      {
-+              u8 opcode = (karg->uFunction==CSMI_SAS_PC_LINK_RESET) ?
-+                  MPI_SAS_OP_PHY_LINK_RESET : MPI_SAS_OP_PHY_HARD_RESET;
-+
-+              if((karg->uLinkFlags & CSMI_SAS_PHY_ACTIVATE_CONTROL) &&
-+                  (karg->usLengthOfControl >= sizeof(CSMI_SAS_PHY_CONTROL)) &&
-+                  (karg->bNumberOfControls > 0)){
-+                      if(karg->Control[0].bRate ==
-+                         CSMI_SAS_LINK_RATE_1_5_GBPS) {
-+                              sasIoUnitPg1->PhyData[karg->bPhyIdentifier].MaxMinLinkRate =
-+                              MPI_SAS_IOUNIT1_MAX_RATE_1_5 |
-+                              MPI_SAS_IOUNIT1_MIN_RATE_1_5;
-+                      }
-+                      else if(karg->Control[0].bRate ==
-+                         CSMI_SAS_LINK_RATE_3_0_GBPS) {
-+                              sasIoUnitPg1->PhyData[karg->bPhyIdentifier].MaxMinLinkRate =
-+                              MPI_SAS_IOUNIT1_MAX_RATE_3_0 |
-+                              MPI_SAS_IOUNIT1_MIN_RATE_3_0;
-+                      }
-+                      sasIoUnitPg1->PhyData[karg->bPhyIdentifier].PhyFlags &=
-+                          ~MPI_SAS_IOUNIT1_PHY_FLAGS_PHY_DISABLE;
-+                      cfg.dir = 1;
-+                      cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
-+                      if (mpt_config(ioc, &cfg) != 0) {
-+                              dcsmisasprintk(ioc, printk(KERN_ERR
-+                          ": FAILED: WRITE MPI_SASIOUNITPAGE1 NVRAM\n"));
-+                              karg->IoctlHeader.ReturnCode =
-+                                 CSMI_SAS_STATUS_FAILED;
-+                              goto cim_sas_phy_control_exit;
-+                      }
-+                      cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
-+                      if (mpt_config(ioc, &cfg) != 0) {
-+                              dcsmisasprintk(ioc, printk(KERN_ERR
-+                       ": FAILED: WRITE MPI_SASIOUNITPAGE1 CURRENT\n"));
-+                              karg->IoctlHeader.ReturnCode =
-+                                 CSMI_SAS_STATUS_FAILED;
-+                              goto cim_sas_phy_control_exit;
-+                      }
-+              }
-+              if (csmisas_phy_reset(ioc,
-+                  karg->bPhyIdentifier, opcode) != 0) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR
-+                          ": FAILED: csmisas_phy_reset\n"));
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto cim_sas_phy_control_exit;
-+              }
-+              break;
-+
-+      }
-+      case CSMI_SAS_PC_PHY_DISABLE:
-+              if(karg->usLengthOfControl || karg->bNumberOfControls) {
-+                      karg->IoctlHeader.ReturnCode =
-+                          CSMI_SAS_STATUS_INVALID_PARAMETER;
-+                      break;
-+              }
-+              sasIoUnitPg1->PhyData[karg->bPhyIdentifier].PhyFlags |=
-+                  MPI_SAS_IOUNIT1_PHY_FLAGS_PHY_DISABLE;
-+              cfg.dir = 1;
-+              cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
-+              if (mpt_config(ioc, &cfg) != 0) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR
-+                          ": FAILED: WRITE MPI_SASIOUNITPAGE1 NVRAM\n"));
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto cim_sas_phy_control_exit;
-+              }
-+              cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
-+              if (mpt_config(ioc, &cfg) != 0) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR
-+                          ": FAILED: WRITE MPI_SASIOUNITPAGE1 CURRENT\n"));
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto cim_sas_phy_control_exit;
-+              }
-+              if (csmisas_phy_reset(ioc,
-+                  karg->bPhyIdentifier, MPI_SAS_OP_PHY_HARD_RESET) != 0) {
-+                      dcsmisasprintk(ioc, printk(KERN_ERR
-+                          ": FAILED: csmisas_phy_reset\n"));
-+                      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+                      goto cim_sas_phy_control_exit;
-+              }
-+              break;
-+
-+      case CSMI_SAS_PC_GET_PHY_SETTINGS:
-+              if(karg->usLengthOfControl || karg->bNumberOfControls) {
-+                      karg->IoctlHeader.ReturnCode =
-+                          CSMI_SAS_STATUS_INVALID_PARAMETER;
-+                      break;
-+              }
-+              if(csmi_sas_phy_control_buffer_sz <
-+                  offsetof(CSMI_SAS_PHY_CONTROL_BUFFER,Control) +
-+                  (4* sizeof(CSMI_SAS_PHY_CONTROL))) {
-+                      karg->IoctlHeader.ReturnCode =
-+                          CSMI_SAS_STATUS_INVALID_PARAMETER;
-+                      break;
-+              }
-+              karg->usLengthOfControl = sizeof(CSMI_SAS_PHY_CONTROL);
-+              karg->bNumberOfControls = 4;
-+              karg->Control[0].bType = CSMI_SAS_SAS;
-+              karg->Control[0].bRate = CSMI_SAS_LINK_RATE_1_5_GBPS;
-+              karg->Control[1].bType = CSMI_SAS_SAS;
-+              karg->Control[1].bRate = CSMI_SAS_LINK_RATE_3_0_GBPS;
-+              karg->Control[2].bType = CSMI_SAS_SATA;
-+              karg->Control[2].bRate = CSMI_SAS_LINK_RATE_1_5_GBPS;
-+              karg->Control[3].bType = CSMI_SAS_SATA;
-+              karg->Control[3].bRate = CSMI_SAS_LINK_RATE_3_0_GBPS;
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+              break;
-+      default:
-+              break;
-+      }
-+
-+ cim_sas_phy_control_exit:
-+
-+      if (sasIoUnitPg0)
-+              pci_free_consistent(ioc->pcidev, sasIoUnitPg0_data_sz,
-+                  (u8 *) sasIoUnitPg0, sasIoUnitPg0_dma);
-+
-+      if (sasIoUnitPg1)
-+              pci_free_consistent(ioc->pcidev, sasIoUnitPg1_data_sz,
-+                  (u8 *) sasIoUnitPg1, sasIoUnitPg1_dma);
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, karg,csmi_sas_phy_control_buffer_sz)) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to write out csmi_sas_phy_control_buffer @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      free_pages((unsigned long)karg, memory_pages);
-+      return 0;
-+}
-+
-+/**
-+ *    csmisas_get_manuf_pg_7 - Fetch Manufacturing config Page7.
-+ * @ioc: Pointer to MPT_ADAPTER structure
-+ * @mfgpage7_buffer: pointer to ManufacturingPage7_t that returns config
-+ *                    page data
-+ * @mfg_size - max size of buffer
-+ *
-+ *    Return: 0 for success
-+ *    -ENOMEM if no memory available
-+ *            -EPERM if not allowed due to ISR context
-+ *            -EAGAIN if no msg frames currently available
-+ *            -EFAULT for non-successful reply or no reply (timeout)
-+ **/
-+static int
-+csmisas_get_manuf_pg_7(MPT_ADAPTER *ioc, ManufacturingPage7_t *mfgpage7_buffer, int mfg_size)
-+{
-+      ConfigPageHeader_t hdr;
-+      CONFIGPARMS     cfg;
-+      ManufacturingPage7_t *mfgPage7 = NULL;
-+      dma_addr_t      mfgPage7_dma;
-+      int             data_sz = 0;
-+      int             rc;
-+
-+      /* Get Manufacturing Page 7 header */
-+      hdr.PageVersion = MPI_MANUFACTURING0_PAGEVERSION;
-+      hdr.PageLength = 0;
-+      hdr.PageNumber = 7;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
-+      cfg.cfghdr.hdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;
-+      cfg.pageAddr = 0;
-+      cfg.timeout = 0;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0)
-+              goto csmisas_get_manuf_pg_7_exit;
-+
-+      if (hdr.PageLength == 0) {
-+              rc = -EFAULT;
-+              goto csmisas_get_manuf_pg_7_exit;
-+      }
-+
-+      data_sz = hdr.PageLength * 4;
-+      mfgPage7 = pci_alloc_consistent(ioc->pcidev, data_sz, &mfgPage7_dma);
-+      if (!mfgPage7) {
-+              rc = -ENOMEM;
-+              goto csmisas_get_manuf_pg_7_exit;
-+      }
-+
-+      memset((u8 *)mfgPage7, 0, data_sz);
-+      cfg.physAddr = mfgPage7_dma;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0)
-+              goto csmisas_get_manuf_pg_7_exit;
-+
-+      /* copy buffer back to user */
-+      memcpy(mfgpage7_buffer, mfgPage7, min(data_sz, mfg_size));
-+
-+ csmisas_get_manuf_pg_7_exit:
-+
-+      if (mfgPage7)
-+              pci_free_consistent(ioc->pcidev, data_sz, (u8 *)mfgPage7,
-+                  mfgPage7_dma);
-+
-+      return rc;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Get Connector info command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ **/
-+static int
-+csmisas_get_connector_info(unsigned long arg)
-+{
-+      CSMI_SAS_CONNECTOR_INFO_BUFFER __user *uarg = (void __user *) arg;
-+      CSMI_SAS_CONNECTOR_INFO_BUFFER   karg;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      ManufacturingPage7_t            *mfgPg7 = NULL;
-+      int                             mfgPg7_sz;
-+      int                             iocnum;
-+      int                             i;
-+
-+      if (copy_from_user(&karg, uarg,
-+              sizeof(CSMI_SAS_CONNECTOR_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                 "Unable to read in csmi_sas_connector_info_buffer"
-+                 " struct @ %p\n",
-+                 __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+
-+      /* `32` is the sizeof MPI_MANPAGE7_CONNECTOR_INFO */
-+      for (i = 0; i < 32; i++) {
-+              karg.Reference[i].uPinout = CSMI_SAS_CON_UNKNOWN;
-+              strcpy(karg.Reference[i].bConnector,"");
-+              karg.Reference[i].bLocation = CSMI_SAS_CON_UNKNOWN;
-+      }
-+
-+      mfgPg7_sz = offsetof(CONFIG_PAGE_MANUFACTURING_7,ConnectorInfo) +
-+          (ioc->num_ports * sizeof(MPI_MANPAGE7_CONNECTOR_INFO));
-+      mfgPg7 = kmalloc(mfgPg7_sz, GFP_KERNEL);
-+      if (!mfgPg7){
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to malloc @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, mfgPg7);
-+              return -EFAULT;
-+      }
-+      memset(mfgPg7, 0, mfgPg7_sz);
-+
-+      if (!csmisas_get_manuf_pg_7(ioc, mfgPg7, mfgPg7_sz)) {
-+              for (i = 0; i < ioc->num_ports; i++) {
-+                      karg.Reference[i].uPinout =
-+                          le32_to_cpu(mfgPg7->ConnectorInfo[i].Pinout);
-+                      /*endian conversion , this is u8 * 16 ?? */
-+                      strncpy(karg.Reference[i].bConnector,
-+                          mfgPg7->ConnectorInfo[i].Connector, 16);
-+                      karg.Reference[i].bLocation =
-+                          mfgPg7->ConnectorInfo[i].Location;
-+              }
-+      }
-+
-+      kfree(mfgPg7);
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, &karg,
-+              sizeof(CSMI_SAS_CONNECTOR_INFO_BUFFER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+              "Unable to write out csmi_sas_connector_info_buffer @"
-+             "%p\n",
-+              __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return 0;
-+}
-+
-+/**
-+ *                 csmisas_fill_location_data
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ **/
-+static int
-+csmisas_fill_location_data(MPT_ADAPTER *ioc, u8 bus, u8 id, u8 opcode,
-+      CSMI_SAS_LOCATION_IDENTIFIER * location_ident)
-+{
-+
-+      ConfigExtendedPageHeader_t      hdr;
-+      CONFIGPARMS                     cfg;
-+      int                             rc;
-+      SasDevicePage0_t                *sasDevicePg0=NULL;
-+      SasEnclosurePage0_t             *sasEnclosurePg0=NULL;
-+      dma_addr_t                      sasDevicePg0_dma,sasEnclosurePg0_dma;
-+      int                             sasDevicePg0_data_sz=0;
-+      int                             sasEnclosurePg0_data_sz=0;
-+      u64                             sas_address;
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+      memset (location_ident, 0, sizeof(*location_ident));
-+
-+      /* SAS Device Page 0 */
-+      hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
-+      hdr.ExtPageLength = 0;
-+      hdr.PageNumber = 0;
-+      hdr.Reserved1 = 0;
-+      hdr.Reserved2 = 0;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
-+
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              rc=-1;
-+              goto fill_location_data_exit;
-+      }
-+
-+      if (hdr.ExtPageLength == 0) {
-+              rc=-1;
-+              goto fill_location_data_exit;
-+      }
-+
-+      sasDevicePg0_data_sz = hdr.ExtPageLength * 4;
-+      sasDevicePg0 = (SasDevicePage0_t *) pci_alloc_consistent(
-+          ioc->pcidev, sasDevicePg0_data_sz, &sasDevicePg0_dma);
-+      if (!sasDevicePg0) {
-+              rc=-1;
-+              goto fill_location_data_exit;
-+      }
-+
-+      memset((u8 *)sasDevicePg0, 0, sasDevicePg0_data_sz);
-+      cfg.physAddr = sasDevicePg0_dma;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+      cfg.pageAddr = (bus << 8) + id
-+          + (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
-+              MPI_SAS_DEVICE_PGAD_FORM_SHIFT);
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              rc=-1;
-+              goto fill_location_data_exit;
-+      }
-+
-+      location_ident->bLocationFlags |= CSMI_SAS_LOCATE_SAS_ADDRESS_VALID;
-+      memcpy(&sas_address, &sasDevicePg0->SASAddress, sizeof(u64));
-+      sas_address = reverse_byte_order64(sas_address);
-+      memcpy(location_ident->bSASAddress, &sas_address, sizeof(u64));
-+
-+      location_ident->bLocationFlags |= CSMI_SAS_LOCATE_SAS_LUN_VALID;
-+      memset(location_ident->bSASLun, 0, sizeof(location_ident->bSASLun));
-+
-+      /* SAS Enclosure Page 0 */
-+      hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
-+      hdr.ExtPageLength = 0;
-+      hdr.PageNumber = 0;
-+      hdr.Reserved1 = 0;
-+      hdr.Reserved2 = 0;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
-+
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              rc=0;
-+              goto fill_location_data_exit;
-+      }
-+
-+      if (hdr.ExtPageLength == 0) {
-+              rc=0;
-+              goto fill_location_data_exit;
-+      }
-+
-+      sasEnclosurePg0_data_sz = hdr.ExtPageLength * 4;
-+      sasEnclosurePg0 = (SasEnclosurePage0_t *) pci_alloc_consistent(
-+          ioc->pcidev, sasEnclosurePg0_data_sz, &sasEnclosurePg0_dma);
-+      if (!sasEnclosurePg0) {
-+              rc=0;
-+              goto fill_location_data_exit;
-+      }
-+      cfg.physAddr = sasEnclosurePg0_dma;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+      cfg.pageAddr = sasDevicePg0->EnclosureHandle
-+          + (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE << MPI_SAS_ENCLOS_PGAD_FORM_SHIFT);
-+
-+      if ((rc = mpt_config(ioc, &cfg)) != 0) {
-+              rc=0;
-+              goto fill_location_data_exit;
-+      }
-+
-+      location_ident->bLocationFlags |= CSMI_SAS_LOCATE_ENCLOSURE_IDENTIFIER_VALID;
-+      memcpy(&sas_address, &sasEnclosurePg0->EnclosureLogicalID, sizeof(u64));
-+      sas_address = reverse_byte_order64(sas_address);
-+      if (sas_address)
-+              memcpy(location_ident->bEnclosureIdentifier, &sas_address, sizeof(u64));
-+      else
-+              strcpy(location_ident->bEnclosureIdentifier,"Internal");
-+
-+// bBayPrefix - not supported
-+
-+// TODO - We need to look at sasEnclosurePg0-.Flags , to determine
-+//    whether SEP BUS/TargetID is valid.  Ifs its a SES device, then
-+//    issue internal inquiry to (bus/id) to gather the Enclosure name.
-+//    If the device is SMP, then issue SMP_MANUFACTURING to get enclosure name
-+//    If its direct attached, there is no enclosure name
-+      location_ident->bLocationFlags |= CSMI_SAS_LOCATE_ENCLOSURE_NAME_VALID;
-+      strcpy(location_ident->bEnclosureName,"Not Supported");
-+
-+      location_ident->bLocationFlags |= CSMI_SAS_LOCATE_LOCATION_STATE_VALID;
-+      location_ident->bLocationState = CSMI_SAS_LOCATE_UNKNOWN;
-+
-+      location_ident->bLocationFlags |= CSMI_SAS_LOCATE_BAY_IDENTIFIER_VALID;
-+      location_ident->bBayIdentifier = le16_to_cpu(sasDevicePg0->Slot);
-+
-+
-+// TODO - illuminating LEDs,
-+// karg->bIdentify = CSMI_SAS_LOCATE_FORCE_OFF, CSMI_SAS_LOCATE_FORCE_ON
-+// We can enable/disable LEDs by SCSI Enclosure Processor MPI request message
-+// printk("Flags=0x%x\n",sasEnclosurePg0->Flags);
-+
-+/* check sasEnclosurePg0->Flags -
-+ * to validate whether we need to send the SEPRequest
-+ * bit:5 should be set
-+ * bit:3-0 any bit should be set.  If zero, then SEPRequest will fail
-+*/
-+
-+/* MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
-+ * Look in mpi_init.h
-+ * SEPRequest_t = structure
-+ *
-+ * SEPRequest_t->Action should be set to MPI_SEP_REQ_ACTION_WRITE_STATUS
-+ *
-+ * SEPRequest_t->Flags should be set to
-+ * MPI_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS, to pass along enclosure/slot ids
-+ *
-+ * SEPRequest_t->SlotStatus |= MPI_SEP_REQ_SLOTSTATUS_IDENTIFY_REQUEST - this
-+ * will illuminate the LEDs
-+ */
-+
-+fill_location_data_exit:
-+
-+      if (sasDevicePg0 != NULL)
-+              pci_free_consistent(ioc->pcidev, sasDevicePg0_data_sz,
-+                  sasDevicePg0, sasDevicePg0_dma);
-+
-+      if (sasEnclosurePg0 != NULL)
-+              pci_free_consistent(ioc->pcidev, sasEnclosurePg0_data_sz,
-+                  sasEnclosurePg0, sasEnclosurePg0_dma);
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      return rc;
-+}
-+
-+static int
-+csmisas_fill_location_data_raid(MPT_ADAPTER *ioc, PCSMI_SAS_GET_LOCATION_BUFFER karg, u8 VolumeBus,
-+      u8 volumeID)
-+{
-+      pRaidVolumePage0_t              pVolume0 = NULL;
-+      pRaidPhysDiskPage0_t            pPhysDisk0 = NULL;
-+      CONFIGPARMS                     cfg;
-+      ConfigPageHeader_t              header;
-+      u8                              physDiskNumMax;
-+      int                             volumepage0sz = 0, physdiskpage0sz = 0;
-+      dma_addr_t                      volume0_dma, physdisk0_dma;
-+      int                             csmi_sas_get_location_sz;
-+      int                             rc = 0, i, idx;
-+      int                             num_hotpares;
-+      u64                             totalMaxLBA, tmpTotalMaxLBA;
-+      IOCPage5_t                      *iocPage5 = NULL;
-+      u32                             device_info = 0;
-+      struct sas_device_info          *sas_info;
-+
-+      int                             sz;
-+
-+      csmi_sas_get_location_sz = karg->IoctlHeader.Length;
-+      physDiskNumMax = (csmi_sas_get_location_sz -
-+          offsetof(CSMI_SAS_GET_LOCATION_BUFFER,Location))
-+          / sizeof(CSMI_SAS_LOCATION_IDENTIFIER);
-+      karg->bNumberOfLocationIdentifiers=0;
-+
-+      /*
-+       * get RAID Volume Page 0
-+       */
-+
-+      header.PageVersion = 0;
-+      header.PageLength = 0;
-+      header.PageNumber = 0;
-+      header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
-+      cfg.cfghdr.hdr = &header;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = (VolumeBus << 8) + volumeID;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              rc = -1;
-+              goto sas_fill_location_data_raid_exit;
-+      }
-+
-+      if (header.PageLength == 0) {
-+              rc = -1;
-+              goto sas_fill_location_data_raid_exit;
-+      }
-+
-+      volumepage0sz = header.PageLength * 4;
-+      pVolume0 = pci_alloc_consistent(ioc->pcidev, volumepage0sz,
-+          &volume0_dma);
-+      if (!pVolume0) {
-+              rc = -1;
-+              goto sas_fill_location_data_raid_exit;
-+      }
-+
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+      cfg.physAddr = volume0_dma;
-+      if (mpt_config(ioc, &cfg) != 0){
-+              rc = -1;
-+              goto sas_fill_location_data_raid_exit;
-+      }
-+
-+      totalMaxLBA = (u64)le32_to_cpu(pVolume0->MaxLBA) |
-+          ((u64)le32_to_cpu(pVolume0->MaxLBAHigh)) << 32;
-+
-+      /*
-+       * get RAID Physical Disk Page 0
-+       */
-+      header.PageVersion = 0;
-+      header.PageLength = 0;
-+      header.PageNumber = 0;
-+      header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
-+      cfg.cfghdr.hdr = &header;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = 0;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;
-+      cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              rc = -1;
-+              goto sas_fill_location_data_raid_exit;
-+      }
-+
-+      if (header.PageLength == 0) {
-+              rc = -1;
-+              goto sas_fill_location_data_raid_exit;
-+      }
-+
-+      physdiskpage0sz = header.PageLength * 4;
-+      pPhysDisk0 = pci_alloc_consistent(ioc->pcidev, physdiskpage0sz,
-+          &physdisk0_dma);
-+      if (!pPhysDisk0) {
-+              rc = -1;
-+              goto sas_fill_location_data_raid_exit;
-+      }
-+      cfg.physAddr = physdisk0_dma;
-+
-+      for (i=0; i < min(pVolume0->NumPhysDisks, physDiskNumMax); i++) {
-+
-+              /* obtain a refresh of pPhysDisk0 */
-+              cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+              cfg.pageAddr = pVolume0->PhysDisk[i].PhysDiskNum;
-+              if (mpt_config(ioc, &cfg) != 0){
-+                      rc = -1;
-+                      goto sas_fill_location_data_raid_exit;
-+              }
-+
-+              if((csmisas_fill_location_data(ioc, pPhysDisk0->PhysDiskBus,
-+                  pPhysDisk0->PhysDiskID, karg->bIdentify,
-+                  &karg->Location[karg->bNumberOfLocationIdentifiers])) == 0)
-+                      karg->bNumberOfLocationIdentifiers++;
-+
-+              if (device_info)
-+                      continue;
-+              sas_info = csmisas_get_device_component_by_fw(ioc,
-+                  pPhysDisk0->PhysDiskBus, pPhysDisk0->PhysDiskID);
-+              if (!sas_info || sas_info->is_cached)
-+                      continue;
-+              device_info = sas_info->device_info;
-+      }
-+
-+      if (pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IS)
-+              goto sas_fill_location_data_raid_exit;
-+
-+      /*
-+       * hot spare support
-+       *
-+       */
-+
-+      num_hotpares = csmisas_get_number_hotspares(ioc);
-+
-+      if (num_hotpares) {
-+
-+              sz = offsetof(IOCPage5_t, HotSpare) +
-+                  num_hotpares * sizeof(IOC_5_HOT_SPARE);
-+              iocPage5 = kmalloc(sz, GFP_KERNEL);
-+
-+              if (!iocPage5)
-+                      goto sas_fill_location_data_raid_exit;
-+              memset(iocPage5, 0, sizeof(*iocPage5));
-+
-+              if (csmisas_get_ioc_pg5(ioc, iocPage5, sz) != 0)
-+                      goto sas_fill_location_data_raid_exit;
-+
-+              for(i = 0, idx = pVolume0->NumPhysDisks ; i < num_hotpares;
-+                  i++, idx++) {
-+
-+                      if (idx >= physDiskNumMax)
-+                              break;
-+
-+                      /* obtain a refresh of pPhysDisk0 */
-+                      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+                      cfg.pageAddr = iocPage5->HotSpare[i].PhysDiskNum;
-+                      if (mpt_config(ioc, &cfg) != 0)
-+                              goto sas_fill_location_data_raid_exit;
-+
-+                      /* Search the list for the matching SAS address. */
-+                      sas_info = csmisas_get_device_component_by_fw(ioc,
-+                          pPhysDisk0->PhysDiskBus, pPhysDisk0->PhysDiskID);
-+
-+                      if (!sas_info || sas_info->is_cached)
-+                              continue;
-+
-+                      /* don't mix SSP hot spare
-+                       * in SATA volume
-+                       */
-+                      if (!csmisas_is_sata(pPhysDisk0) &&
-+                          (device_info &
-+                          MPI_SAS_DEVICE_INFO_SATA_DEVICE))
-+                              continue;
-+
-+                      /* don't mix SATA hot spare
-+                       * in SSP volume
-+                       */
-+                      if (csmisas_is_sata(pPhysDisk0) &&
-+                          (device_info &
-+                          MPI_SAS_DEVICE_INFO_SSP_TARGET))
-+                              continue;
-+
-+                      /* capacity check for IM volumes*/
-+                      if ((pVolume0->VolumeType ==
-+                          MPI_RAID_VOL_TYPE_IM) &&
-+                          (totalMaxLBA +
-+                          (64*2*1024) /* metadata = 64MB*/ >
-+                          le32_to_cpu(pPhysDisk0->MaxLBA)))
-+                              continue;
-+
-+                      tmpTotalMaxLBA = totalMaxLBA;
-+                      do_div(tmpTotalMaxLBA, pVolume0->NumPhysDisks);
-+                      /* capacity check for IME volumes*/
-+                      if ((pVolume0->VolumeType ==
-+                              MPI_RAID_VOL_TYPE_IME) &&
-+                          ((tmpTotalMaxLBA * 2) +
-+                           (64*2*1024 ) /*metadata = 64MB*/ >
-+                          le32_to_cpu(pPhysDisk0->MaxLBA)))
-+                              continue;
-+
-+                      if((csmisas_fill_location_data(ioc,
-+                          pPhysDisk0->PhysDiskBus, pPhysDisk0->PhysDiskID,
-+                          karg->bIdentify,
-+                          &karg->Location[karg->bNumberOfLocationIdentifiers])) == 0)
-+                              karg->bNumberOfLocationIdentifiers++;
-+              }
-+      }
-+
-+
-+ sas_fill_location_data_raid_exit:
-+
-+      kfree(iocPage5);
-+
-+      if (pVolume0)
-+              pci_free_consistent(ioc->pcidev, volumepage0sz, pVolume0,
-+                  volume0_dma);
-+
-+      if(pPhysDisk0)
-+              pci_free_consistent(ioc->pcidev, physdiskpage0sz, pPhysDisk0,
-+                  physdisk0_dma);
-+
-+      return rc;
-+}
-+
-+/**
-+ * Prototype Routine for the CSMI SAS Get location command.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -ENODEV if no such device/adapter
-+ */
-+static int
-+csmisas_get_location(unsigned long arg)
-+{
-+      CSMI_SAS_GET_LOCATION_BUFFER __user *uarg = (void __user *) arg;
-+      PCSMI_SAS_GET_LOCATION_BUFFER   karg;
-+      IOCTL_HEADER                    ioctl_header;
-+      MPT_ADAPTER                     *ioc = NULL;
-+      int                             iocnum,i;
-+      int                             csmi_sas_get_location_sz;
-+      int                             memory_pages;
-+      struct sas_device_info          *sas_info;
-+
-+      if (copy_from_user(&ioctl_header, uarg, sizeof(IOCTL_HEADER))) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in IOCTL_HEADER"
-+                  "struct @ %p\n", __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      csmi_sas_get_location_sz = ioctl_header.Length;
-+      memory_pages = get_order(csmi_sas_get_location_sz);
-+      karg = (PCSMI_SAS_GET_LOCATION_BUFFER)__get_free_pages(
-+              GFP_KERNEL, memory_pages);
-+      if (!karg){
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                      "Unable to malloc GET_LOCATION_BUFFER "
-+                      "csmi_sas_get_location_sz=%d memory_pages=%d\n",
-+                      __FILE__, __LINE__, __FUNCTION__,
-+                      csmi_sas_get_location_sz, memory_pages);
-+              return -ENOMEM;
-+      }
-+      memset(karg, 0, sizeof(*karg));
-+
-+      if (copy_from_user(karg, uarg, csmi_sas_get_location_sz)) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to read in csmi_sas_phy_control_buffer "
-+                  "struct @ %p\n", __FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg->IoctlHeader.IOControllerNumber,
-+          &ioc)) < 0) || (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      if (!csmisas_is_this_sas_cntr(ioc)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -ENODEV;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
-+
-+      karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
-+      if(karg->bLengthOfLocationIdentifier !=
-+          sizeof(CSMI_SAS_LOCATION_IDENTIFIER))
-+              goto cim_sas_get_location_exit;
-+
-+      sas_info = csmisas_get_device_component_by_os(ioc, karg->bPathId,
-+          karg->bTargetId);
-+      if (!sas_info)
-+              goto cim_sas_get_location_exit;
-+
-+      /* RAID SUPPORT */
-+      if (ioc->raid_data.pIocPg2 && sas_info->is_logical_volume) {
-+              for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++){
-+                      if (sas_info->fw.id ==
-+                          ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID &&
-+                          sas_info->fw.channel ==
-+                          ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus) {
-+                              if(csmisas_fill_location_data_raid(ioc, karg,
-+                                  ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus,
-+                                  ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID) == 0)
-+                                      karg->IoctlHeader.ReturnCode =
-+                                          CSMI_SAS_STATUS_SUCCESS;
-+                              else
-+                                      karg->IoctlHeader.ReturnCode =
-+                                          CSMI_SAS_STATUS_FAILED;
-+                              goto cim_sas_get_location_exit;
-+                      }
-+              }
-+      }
-+
-+      /* NON-RAID SUPPORT */
-+      if (sas_info->is_cached || sas_info->is_logical_volume)
-+              goto cim_sas_get_location_exit;
-+
-+      /* make sure there's enough room to populate the Location[] struct */
-+      if ((csmi_sas_get_location_sz -
-+          offsetof(CSMI_SAS_GET_LOCATION_BUFFER,Location)) <
-+          sizeof(CSMI_SAS_LOCATION_IDENTIFIER))
-+              goto cim_sas_get_location_exit;
-+
-+      karg->bNumberOfLocationIdentifiers=1;
-+      karg->Location[0].bLocationFlags=0;
-+      if((csmisas_fill_location_data(ioc, sas_info->fw.channel,
-+          sas_info->fw.id, karg->bIdentify, &karg->Location[0])) == 0)
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
-+      else
-+              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
-+
-+ cim_sas_get_location_exit:
-+
-+      /* Copy the data from kernel memory to user memory
-+       */
-+      if (copy_to_user(uarg, karg, csmi_sas_get_location_sz)) {
-+              printk(KERN_ERR "%s@%d::%s() - "
-+                  "Unable to write out csmi_sas_get_location_buffer "
-+                  "@ %p\n",__FILE__, __LINE__, __FUNCTION__, uarg);
-+              free_pages((unsigned long)karg, memory_pages);
-+              return -EFAULT;
-+      }
-+
-+      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
-+      free_pages((unsigned long)karg, memory_pages);
-+      return 0;
-+}
---- /dev/null
-+++ b/drivers/message/fusion/csmi/csmisas.h
-@@ -0,0 +1,1854 @@
-+/**************************************************************************
-+
-+Module Name:
-+
-+   CSMISAS.H
-+
-+
-+Abstract:
-+
-+   This file contains constants and data structure definitions used by drivers
-+   that support the Common Storage Management Interface specification for
-+   SAS or SATA in either the Windows or Linux.
-+
-+   This should be considered as a reference implementation only.  Changes may
-+   be necessary to accommodate a specific build environment or target OS.
-+
-+Revision History:
-+
-+   001  SEF   8/12/03  Initial release.
-+   002  SEF   8/20/03  Cleanup to match documentation.
-+   003  SEF   9/12/03  Additional cleanup, created combined header
-+   004  SEF   9/23/03  Changed base types to match linux defaults
-+                       Added RAID signature
-+                       Added bControllerFlags to CSMI_SAS_CNTLR_CONFIG
-+                       Changed CSMI_SAS_BEGIN_PACK to 8 for common structures
-+                       Fixed other typos identified in first compilation test
-+   005  SEF  10/03/03  Additions to match first version of CSMI document
-+   006  SEF  10/14/03  Fixed typedef struct _CSMI_SAS_SMP_PASSTHRU_BUFFER
-+                       Added defines for bConnectionRate
-+   007  SEF  10/15/03  Added Firmware Download Control Code and support
-+                       Added CSMI revision support
-+   008  SEF  10/30/03  No functional change, just updated version to track
-+                       spec changes
-+   009  SEF  12/09/03  No functional change, just updated version to track
-+                       spec changes
-+   010  SEF   3/11/04  Fixed typedef struct CSMI_SAS_RAID_DRIVES to include the
-+                       bFirmware member that is defined in the spec, but
-+                       was missing in this file,
-+                       added CC_CSMI_SAS_TASK_MANAGEMENT
-+   011  SEF   4/02/04  No functional change, added comment line before
-+                       CC_CSMI_SAS_TASK_MANAGEMENT
-+   012  SEF   4/16/04  Added IOControllerNumber to linux header,
-+                       Modified linux control codes to have upper word of
-+                       0xCC77.... to indicate CSMI version 77
-+                       Added bSignalClass to CC_CSMI_SET_PHY_INFO
-+                       Added CC_CSMI_SAS_PHY_CONTROL support
-+   013  SEF   5/14/04  Added CC_CSMI_SAS_GET_CONNECTOR_INFO support
-+   014  SEF   5/24/04  No functional change, just updated version to track spec
-+                       changes
-+   015  SEF   6/16/04  changed bPinout to uPinout to reflect proper size,
-+                       changed width of bLocation defines to reflect size
-+   016  SEF   6/17/04  changed bLengthOfControls in CSMI_SAS_PHY_CONTROL
-+                       to be proper size
-+   017  SEF   9/17/04  added CSMI_SAS_SATA_PORT_SELECTOR,
-+                       CSMI_SAS_LINK_VIRTUAL, CSMI_SAS_CON_NOT_PRESENT, and
-+                       CSMI_SAS_CON_NOT_CONNECTED
-+   018  SEF   9/20/04  added CSMI_SAS_PHY_USER_PATTERN,
-+                       changed definition of CSMI_SAS_PHY_FIXED_PATTERN to not
-+                       conflict with activate definition
-+   019  SEF  12/06/04  added CSMI_SAS_GET_LOCATION
-+                       added bSSPStatus to CSMI_SAS_SSP_PASSTHRU_STATUS
-+                       structure
-+   020  SEF   5/25/05  added CSMI_SAS_PHY_VIRTUAL_SMP, and changes to
-+                       CSMI_SAS_GET_LOCATION
-+   021  SEF  11/03/05  added new RAID creation functionality
-+   022  SEF   2/01/06  corrected typo bNegotitiatedLInkRate
-+                       Added two more RAID_TYPES, 7 and 8
-+   023  SEF   4/04/06  added CSMI_RAID_TYPE_1E
-+                       changed structures that contained surface scan
-+                       to priority approach rather than time, causes
-+                       0.89 to incompatible with 0.87, so a version
-+                       check is necessary when interpreting the
-+                       raid structures
-+                       Added netware section
-+   024 DRG    5/22/06  Added uFailureCode to CSMI_SAS_RAID_CONFIG and
-+                       CSMI_SAS_RAID_FEATURES
-+                       Changed __u64 fields to high and low __u32 fields in
-+                       order to avoid backward compatibility issues with
-+                       packing and alignment.
-+                       Fixed alignment problem in CSMI_SAS_RAID_DRIVES.
-+                       Added CSMI_SAS_CNTLR_SMART_ARRAY to uControllerFlags
-+                       Reassigned the value of CSMI_SAS_CNTLR_RAID_CFG_SUPPORT
-+                       to avoid a conflict.
-+
-+**************************************************************************/
-+
-+#ifndef _CSMI_SAS_H_
-+#define _CSMI_SAS_H_
-+
-+// CSMI Specification Revision, the intent is that all versions of the
-+// specification will be backward compatible after the 1.00 release.
-+// Major revision number, corresponds to xxxx. of CSMI specification
-+// Minor revision number, corresponds to .xxxx of CSMI specification
-+#define CSMI_MAJOR_REVISION   0
-+#define CSMI_MINOR_REVISION   90
-+
-+/*************************************************************************/
-+/* PATCHES FOR TYPOS                                                     */
-+/*************************************************************************/
-+
-+#define bNegotitiatedLInkRate bNegotiatedLinkRate
-+
-+/*************************************************************************/
-+/* TARGET OS LINUX SPECIFIC CODE                                         */
-+/*************************************************************************/
-+
-+// EDM #ifdef _linux
-+#ifdef __KERNEL__
-+
-+// Linux base types
-+
-+#include <linux/types.h>
-+
-+#define __i8    char
-+
-+// pack definition
-+
-+// EDM #define CSMI_SAS_BEGIN_PACK(x)    pack(x)
-+// EDM #define CSMI_SAS_END_PACK         pack()
-+
-+// IOCTL Control Codes
-+// (IoctlHeader.ControlCode)
-+
-+// Control Codes prior to 0.77
-+
-+// Control Codes requiring CSMI_ALL_SIGNATURE
-+
-+// #define CC_CSMI_SAS_GET_DRIVER_INFO    0x12345678
-+// #define CC_CSMI_SAS_GET_CNTLR_CONFIG   0x23456781
-+// #define CC_CSMI_SAS_GET_CNTLR_STATUS   0x34567812
-+// #define CC_CSMI_SAS_FIRMWARE_DOWNLOAD  0x92345678
-+
-+// Control Codes requiring CSMI_RAID_SIGNATURE
-+
-+// #define CC_CSMI_SAS_GET_RAID_INFO      0x45678123
-+// #define CC_CSMI_SAS_GET_RAID_CONFIG    0x56781234
-+
-+// Control Codes requiring CSMI_SAS_SIGNATURE
-+
-+// #define CC_CSMI_SAS_GET_PHY_INFO       0x67812345
-+// #define CC_CSMI_SAS_SET_PHY_INFO       0x78123456
-+// #define CC_CSMI_SAS_GET_LINK_ERRORS    0x81234567
-+// #define CC_CSMI_SAS_SMP_PASSTHRU       0xA1234567
-+// #define CC_CSMI_SAS_SSP_PASSTHRU       0xB1234567
-+// #define CC_CSMI_SAS_STP_PASSTHRU       0xC1234567
-+// #define CC_CSMI_SAS_GET_SATA_SIGNATURE 0xD1234567
-+// #define CC_CSMI_SAS_GET_SCSI_ADDRESS   0xE1234567
-+// #define CC_CSMI_SAS_GET_DEVICE_ADDRESS 0xF1234567
-+// #define CC_CSMI_SAS_TASK_MANAGEMENT    0xA2345678
-+
-+// Control Codes for 0.77 and later
-+
-+// Control Codes requiring CSMI_ALL_SIGNATURE
-+
-+#define CC_CSMI_SAS_GET_DRIVER_INFO    0xCC770001
-+#define CC_CSMI_SAS_GET_CNTLR_CONFIG   0xCC770002
-+#define CC_CSMI_SAS_GET_CNTLR_STATUS   0xCC770003
-+#define CC_CSMI_SAS_FIRMWARE_DOWNLOAD  0xCC770004
-+
-+// Control Codes requiring CSMI_RAID_SIGNATURE
-+
-+#define CC_CSMI_SAS_GET_RAID_INFO      0xCC77000A
-+#define CC_CSMI_SAS_GET_RAID_CONFIG    0xCC77000B
-+#define CC_CSMI_SAS_GET_RAID_FEATURES  0xCC77000C
-+#define CC_CSMI_SAS_SET_RAID_CONTROL   0xCC77000D
-+#define CC_CSMI_SAS_GET_RAID_ELEMENT   0xCC77000E
-+#define CC_CSMI_SAS_SET_RAID_OPERATION 0xCC77000F
-+
-+// Control Codes requiring CSMI_SAS_SIGNATURE
-+
-+#define CC_CSMI_SAS_GET_PHY_INFO       0xCC770014
-+#define CC_CSMI_SAS_SET_PHY_INFO       0xCC770015
-+#define CC_CSMI_SAS_GET_LINK_ERRORS    0xCC770016
-+#define CC_CSMI_SAS_SMP_PASSTHRU       0xCC770017
-+#define CC_CSMI_SAS_SSP_PASSTHRU       0xCC770018
-+#define CC_CSMI_SAS_STP_PASSTHRU       0xCC770019
-+#define CC_CSMI_SAS_GET_SATA_SIGNATURE 0xCC770020
-+#define CC_CSMI_SAS_GET_SCSI_ADDRESS   0xCC770021
-+#define CC_CSMI_SAS_GET_DEVICE_ADDRESS 0xCC770022
-+#define CC_CSMI_SAS_TASK_MANAGEMENT    0xCC770023
-+#define CC_CSMI_SAS_GET_CONNECTOR_INFO 0xCC770024
-+#define CC_CSMI_SAS_GET_LOCATION       0xCC770025
-+
-+
-+// Control Codes requiring CSMI_PHY_SIGNATURE
-+
-+#define CC_CSMI_SAS_PHY_CONTROL        0xCC77003C
-+
-+// EDM #pragma CSMI_SAS_BEGIN_PACK(8)
-+#pragma pack(8)
-+
-+// IOCTL_HEADER
-+typedef struct _IOCTL_HEADER {
-+    __u32 IOControllerNumber;
-+    __u32 Length;
-+    __u32 ReturnCode;
-+    __u32 Timeout;
-+    __u16 Direction;
-+} IOCTL_HEADER,
-+  *PIOCTL_HEADER;
-+
-+// EDM #pragma CSMI_SAS_END_PACK
-+#pragma pack()
-+
-+#endif
-+
-+/*************************************************************************/
-+/* TARGET OS WINDOWS SPECIFIC CODE                                       */
-+/*************************************************************************/
-+
-+#ifdef _WIN32
-+
-+// windows IOCTL definitions
-+
-+#ifndef _NTDDSCSIH_
-+#include <ntddscsi.h>
-+#endif
-+
-+// pack definition
-+
-+#if defined _MSC_VER
-+   #define CSMI_SAS_BEGIN_PACK(x)    pack(push,x)
-+   #define CSMI_SAS_END_PACK         pack(pop)
-+#elif defined __BORLANDC__
-+   #define CSMI_SAS_BEGIN_PACK(x)    option -a##x
-+   #define CSMI_SAS_END_PACK         option -a.
-+#else
-+   #error "CSMISAS.H - Must externally define a pack compiler designator."
-+#endif
-+
-+// base types
-+
-+#define __u8    unsigned char
-+#define __u16   unsigned short
-+#define __u32   unsigned long
-+#define __u64   unsigned __int64
-+
-+#define __i8    char
-+
-+// IOCTL Control Codes
-+// (IoctlHeader.ControlCode)
-+
-+// Control Codes requiring CSMI_ALL_SIGNATURE
-+
-+#define CC_CSMI_SAS_GET_DRIVER_INFO    1
-+#define CC_CSMI_SAS_GET_CNTLR_CONFIG   2
-+#define CC_CSMI_SAS_GET_CNTLR_STATUS   3
-+#define CC_CSMI_SAS_FIRMWARE_DOWNLOAD  4
-+
-+// Control Codes requiring CSMI_RAID_SIGNATURE
-+
-+#define CC_CSMI_SAS_GET_RAID_INFO      10
-+#define CC_CSMI_SAS_GET_RAID_CONFIG    11
-+#define CC_CSMI_SAS_GET_RAID_FEATURES  12
-+#define CC_CSMI_SAS_SET_RAID_CONTROL   13
-+#define CC_CSMI_SAS_GET_RAID_ELEMENT   14
-+#define CC_CSMI_SAS_SET_RAID_OPERATION 15
-+
-+// Control Codes requiring CSMI_SAS_SIGNATURE
-+
-+#define CC_CSMI_SAS_GET_PHY_INFO       20
-+#define CC_CSMI_SAS_SET_PHY_INFO       21
-+#define CC_CSMI_SAS_GET_LINK_ERRORS    22
-+#define CC_CSMI_SAS_SMP_PASSTHRU       23
-+#define CC_CSMI_SAS_SSP_PASSTHRU       24
-+#define CC_CSMI_SAS_STP_PASSTHRU       25
-+#define CC_CSMI_SAS_GET_SATA_SIGNATURE 26
-+#define CC_CSMI_SAS_GET_SCSI_ADDRESS   27
-+#define CC_CSMI_SAS_GET_DEVICE_ADDRESS 28
-+#define CC_CSMI_SAS_TASK_MANAGEMENT    29
-+#define CC_CSMI_SAS_GET_CONNECTOR_INFO 30
-+#define CC_CSMI_SAS_GET_LOCATION       31
-+
-+// Control Codes requiring CSMI_PHY_SIGNATURE
-+
-+#define CC_CSMI_SAS_PHY_CONTROL        60
-+
-+#define IOCTL_HEADER SRB_IO_CONTROL
-+#define PIOCTL_HEADER PSRB_IO_CONTROL
-+
-+#endif
-+
-+/*************************************************************************/
-+/* TARGET OS NETWARE SPECIFIC CODE                                       */
-+/*************************************************************************/
-+
-+#ifdef _NETWARE
-+
-+// NetWare IOCTL definitions
-+
-+#define CSMI_SAS_BEGIN_PACK(x)    pack(x)
-+#define CSMI_SAS_END_PACK         pack()
-+
-+#ifndef LONG
-+typedef unsigned long LONG;
-+#endif
-+
-+#ifndef WORD
-+typedef unsigned short WORD;
-+#endif
-+
-+#ifndef BYTE
-+typedef unsigned char BYTE;
-+#endif
-+
-+/* Need to have these definitions for Netware */
-+#define __u8    unsigned char
-+#define __u16   unsigned short
-+#define __u32   unsigned long
-+#define __u64   unsigned __int64
-+
-+#define __i8    char
-+
-+
-+// EDM #pragma CSMI_SAS_BEGIN_PACK(8)
-+#pragma pack(8)
-+
-+// IOCTL_HEADER
-+typedef struct _IOCTL_HEADER {
-+    __u32 Length;
-+    __u32 ReturnCode;
-+} IOCTL_HEADER,
-+  *PIOCTL_HEADER;
-+
-+// EDM #pragma CSMI_SAS_END_PACK
-+#pragma pack()
-+
-+// IOCTL Control Codes
-+// (IoctlHeader.ControlCode)
-+
-+// Control Codes requiring CSMI_ALL_SIGNATURE
-+
-+#define CC_CSMI_SAS_GET_DRIVER_INFO    0x01FF0001
-+#define CC_CSMI_SAS_GET_CNTLR_CONFIG   0x01FF0002
-+#define CC_CSMI_SAS_GET_CNTLR_STATUS   0x01FF0003
-+#define CC_CSMI_SAS_FIRMWARE_DOWNLOAD  0x01FF0004
-+
-+// Control Codes requiring CSMI_RAID_SIGNATURE
-+
-+#define CC_CSMI_SAS_GET_RAID_INFO      0x01FF000A
-+#define CC_CSMI_SAS_GET_RAID_CONFIG    0x01FF000B
-+#define CC_CSMI_SAS_GET_RAID_FEATURES  0x01FF000C
-+#define CC_CSMI_SAS_SET_RAID_CONTROL   0x01FF000D
-+#define CC_CSMI_SAS_GET_RAID_ELEMENT   0x01FF000E
-+#define CC_CSMI_SAS_SET_RAID_OPERATION 0x01FF000F
-+
-+// Control Codes requiring CSMI_SAS_SIGNATURE
-+
-+#define CC_CSMI_SAS_GET_PHY_INFO       0x01FF0014
-+#define CC_CSMI_SAS_SET_PHY_INFO       0x01FF0015
-+#define CC_CSMI_SAS_GET_LINK_ERRORS    0x01FF0016
-+#define CC_CSMI_SAS_SMP_PASSTHRU       0x01FF0017
-+#define CC_CSMI_SAS_SSP_PASSTHRU       0x01FF0018
-+#define CC_CSMI_SAS_STP_PASSTHRU       0x01FF0019
-+#define CC_CSMI_SAS_GET_SATA_SIGNATURE 0x01FF001A
-+#define CC_CSMI_SAS_GET_SCSI_ADDRESS   0x01FF001B
-+#define CC_CSMI_SAS_GET_DEVICE_ADDRESS 0x01FF001C
-+#define CC_CSMI_SAS_TASK_MANAGEMENT    0x01FF001D
-+#define CC_CSMI_SAS_GET_CONNECTOR_INFO 0x01FF001E
-+#define CC_CSMI_SAS_GET_LOCATION       0x01FF001F
-+
-+// Control Codes requiring CSMI_PHY_SIGNATURE
-+
-+#define CC_CSMI_SAS_PHY_CONTROL        60
-+
-+#endif
-+
-+/*************************************************************************/
-+/* TARGET OS NOT DEFINED ERROR                                           */
-+/*************************************************************************/
-+
-+// EDM
-+//#if (!_WIN32 && !_linux && !_NETWARE)
-+//   #error "Unknown target OS."
-+//#endif
-+
-+/*************************************************************************/
-+/* OS INDEPENDENT CODE                                                   */
-+/*************************************************************************/
-+
-+/* * * * * * * * * * Class Independent IOCTL Constants * * * * * * * * * */
-+
-+// Return codes for all IOCTL's regardless of class
-+// (IoctlHeader.ReturnCode)
-+
-+#define CSMI_SAS_STATUS_SUCCESS              0
-+#define CSMI_SAS_STATUS_FAILED               1
-+#define CSMI_SAS_STATUS_BAD_CNTL_CODE        2
-+#define CSMI_SAS_STATUS_INVALID_PARAMETER    3
-+#define CSMI_SAS_STATUS_WRITE_ATTEMPTED      4
-+
-+// Signature value
-+// (IoctlHeader.Signature)
-+
-+#define CSMI_ALL_SIGNATURE    "CSMIALL"
-+
-+// Timeout value default of 60 seconds
-+// (IoctlHeader.Timeout)
-+
-+#define CSMI_ALL_TIMEOUT      60
-+
-+//  Direction values for data flow on this IOCTL
-+// (IoctlHeader.Direction, Linux only)
-+#define CSMI_SAS_DATA_READ    0
-+#define CSMI_SAS_DATA_WRITE   1
-+
-+// I/O Bus Types
-+// ISA and EISA bus types are not supported
-+// (bIoBusType)
-+
-+#define CSMI_SAS_BUS_TYPE_PCI       3
-+#define CSMI_SAS_BUS_TYPE_PCMCIA    4
-+
-+// Controller Status
-+// (uStatus)
-+
-+#define CSMI_SAS_CNTLR_STATUS_GOOD     1
-+#define CSMI_SAS_CNTLR_STATUS_FAILED   2
-+#define CSMI_SAS_CNTLR_STATUS_OFFLINE  3
-+#define CSMI_SAS_CNTLR_STATUS_POWEROFF 4
-+
-+// Offline Status Reason
-+// (uOfflineReason)
-+
-+#define CSMI_SAS_OFFLINE_REASON_NO_REASON             0
-+#define CSMI_SAS_OFFLINE_REASON_INITIALIZING          1
-+#define CSMI_SAS_OFFLINE_REASON_BACKSIDE_BUS_DEGRADED 2
-+#define CSMI_SAS_OFFLINE_REASON_BACKSIDE_BUS_FAILURE  3
-+
-+// Controller Class
-+// (bControllerClass)
-+
-+#define CSMI_SAS_CNTLR_CLASS_HBA    5
-+
-+// Controller Flag bits
-+// (uControllerFlags)
-+
-+#define CSMI_SAS_CNTLR_SAS_HBA          0x00000001
-+#define CSMI_SAS_CNTLR_SAS_RAID         0x00000002
-+#define CSMI_SAS_CNTLR_SATA_HBA         0x00000004
-+#define CSMI_SAS_CNTLR_SATA_RAID        0x00000008
-+#define CSMI_SAS_CNTLR_SMART_ARRAY      0x00000010
-+
-+// for firmware download
-+#define CSMI_SAS_CNTLR_FWD_SUPPORT      0x00010000
-+#define CSMI_SAS_CNTLR_FWD_ONLINE       0x00020000
-+#define CSMI_SAS_CNTLR_FWD_SRESET       0x00040000
-+#define CSMI_SAS_CNTLR_FWD_HRESET       0x00080000
-+#define CSMI_SAS_CNTLR_FWD_RROM         0x00100000
-+
-+// for RAID configuration supported
-+#define CSMI_SAS_CNTLR_RAID_CFG_SUPPORT 0x01000000
-+
-+// Download Flag bits
-+// (uDownloadFlags)
-+#define CSMI_SAS_FWD_VALIDATE       0x00000001
-+#define CSMI_SAS_FWD_SOFT_RESET     0x00000002
-+#define CSMI_SAS_FWD_HARD_RESET     0x00000004
-+
-+// Firmware Download Status
-+// (usStatus)
-+#define CSMI_SAS_FWD_SUCCESS        0
-+#define CSMI_SAS_FWD_FAILED         1
-+#define CSMI_SAS_FWD_USING_RROM     2
-+#define CSMI_SAS_FWD_REJECT         3
-+#define CSMI_SAS_FWD_DOWNREV        4
-+
-+// Firmware Download Severity
-+// (usSeverity>
-+#define CSMI_SAS_FWD_INFORMATION    0
-+#define CSMI_SAS_FWD_WARNING        1
-+#define CSMI_SAS_FWD_ERROR          2
-+#define CSMI_SAS_FWD_FATAL          3
-+
-+/* * * * * * * * * * SAS RAID Class IOCTL Constants  * * * * * * * * */
-+
-+// Return codes for the RAID IOCTL's regardless of class
-+// (IoctlHeader.ReturnCode)
-+
-+#define CSMI_SAS_RAID_SET_OUT_OF_RANGE       1000
-+#define CSMI_SAS_RAID_SET_BUFFER_TOO_SMALL   1001
-+#define CSMI_SAS_RAID_SET_DATA_CHANGED       1002
-+
-+// Signature value
-+// (IoctlHeader.Signature)
-+
-+#define CSMI_RAID_SIGNATURE    "CSMIARY"
-+
-+// Timeout value default of 60 seconds
-+// (IoctlHeader.Timeout)
-+
-+#define CSMI_RAID_TIMEOUT      60
-+
-+// RAID Types
-+// (bRaidType)
-+#define CSMI_SAS_RAID_TYPE_NONE     0
-+#define CSMI_SAS_RAID_TYPE_0        1
-+#define CSMI_SAS_RAID_TYPE_1        2
-+#define CSMI_SAS_RAID_TYPE_10       3
-+#define CSMI_SAS_RAID_TYPE_5        4
-+#define CSMI_SAS_RAID_TYPE_15       5
-+#define CSMI_SAS_RAID_TYPE_6        6
-+#define CSMI_SAS_RAID_TYPE_50       7
-+#define CSMI_SAS_RAID_TYPE_VOLUME   8
-+#define CSMI_SAS_RAID_TYPE_1E       9
-+#define CSMI_SAS_RAID_TYPE_OTHER    255
-+// the last value 255 was already defined for other
-+// so end is defined as 254
-+#define CSMI_SAS_RAID_TYPE_END      254
-+
-+// RAID Status
-+// (bStatus)
-+#define CSMI_SAS_RAID_SET_STATUS_OK             0
-+#define CSMI_SAS_RAID_SET_STATUS_DEGRADED       1
-+#define CSMI_SAS_RAID_SET_STATUS_REBUILDING     2
-+#define CSMI_SAS_RAID_SET_STATUS_FAILED         3
-+#define CSMI_SAS_RAID_SET_STATUS_OFFLINE        4
-+#define CSMI_SAS_RAID_SET_STATUS_TRANSFORMING   5
-+#define CSMI_SAS_RAID_SET_STATUS_QUEUED_FOR_REBUILD         6
-+#define CSMI_SAS_RAID_SET_STATUS_QUEUED_FOR_TRANSFORMATION  7
-+
-+// RAID Drive Count
-+// (bDriveCount, 0xF1 to 0xFF are reserved)
-+#define CSMI_SAS_RAID_DRIVE_COUNT_TOO_BIG   0xF1
-+#define CSMI_SAS_RAID_DRIVE_COUNT_SUPRESSED 0xF2
-+
-+// RAID Data Type
-+// (bDataType)
-+#define CSMI_SAS_RAID_DATA_DRIVES           0
-+#define CSMI_SAS_RAID_DATA_DEVICE_ID        1
-+#define CSMI_SAS_RAID_DATA_ADDITIONAL_DATA  2
-+
-+// RAID Drive Status
-+// (bDriveStatus)
-+#define CSMI_SAS_DRIVE_STATUS_OK          0
-+#define CSMI_SAS_DRIVE_STATUS_REBUILDING  1
-+#define CSMI_SAS_DRIVE_STATUS_FAILED      2
-+#define CSMI_SAS_DRIVE_STATUS_DEGRADED    3
-+#define CSMI_SAS_DRIVE_STATUS_OFFLINE     4
-+#define CSMI_SAS_DRIVE_STATUS_QUEUED_FOR_REBUILD 5
-+
-+// RAID Drive Usage
-+// (bDriveUsage)
-+#define CSMI_SAS_DRIVE_CONFIG_NOT_USED      0
-+#define CSMI_SAS_DRIVE_CONFIG_MEMBER        1
-+#define CSMI_SAS_DRIVE_CONFIG_SPARE         2
-+#define CSMI_SAS_DRIVE_CONFIG_SPARE_ACTIVE  3
-+
-+// RAID Drive Type
-+// (bDriveType)
-+#define CSMI_SAS_DRIVE_TYPE_UNKNOWN         0
-+#define CSMI_SAS_DRIVE_TYPE_SINGLE_PORT_SAS 1
-+#define CSMI_SAS_DRIVE_TYPE_DUAL_PORT_SAS   2
-+#define CSMI_SAS_DRIVE_TYPE_SATA            3
-+#define CSMI_SAS_DRIVE_TYPE_SATA_PS         4
-+#define CSMI_SAS_DRIVE_TYPE_OTHER           255
-+
-+// RAID Write Protect
-+// (bWriteProtect)
-+#define CSMI_SAS_RAID_SET_WRITE_PROTECT_UNKNOWN     0
-+#define CSMI_SAS_RAID_SET_WRITE_PROTECT_UNCHANGED   0
-+#define CSMI_SAS_RAID_SET_WRITE_PROTECT_ENABLED     1
-+#define CSMI_SAS_RAID_SET_WRITE_PROTECT_DISABLED    2
-+
-+// RAID Cache Setting
-+// (bCacheSetting)
-+#define CSMI_SAS_RAID_SET_CACHE_UNKNOWN             0
-+#define CSMI_SAS_RAID_SET_CACHE_UNCHANGED           0
-+#define CSMI_SAS_RAID_SET_CACHE_ENABLED             1
-+#define CSMI_SAS_RAID_SET_CACHE_DISABLED            2
-+#define CSMI_SAS_RAID_SET_CACHE_CORRUPT             3
-+
-+// RAID Features
-+// (uFeatures)
-+#define CSMI_SAS_RAID_FEATURE_TRANSFORMATION    0x00000001
-+#define CSMI_SAS_RAID_FEATURE_REBUILD           0x00000002
-+#define CSMI_SAS_RAID_FEATURE_SPLIT_MIRROR      0x00000004
-+#define CSMI_SAS_RAID_FEATURE_MERGE_MIRROR      0x00000008
-+#define CSMI_SAS_RAID_FEATURE_LUN_RENUMBER      0x00000010
-+#define CSMI_SAS_RAID_FEATURE_SURFACE_SCAN      0x00000020
-+#define CSMI_SAS_RAID_FEATURE_SPARES_SHARED     0x00000040
-+
-+// RAID Priority
-+// (bDefaultTransformPriority, etc.)
-+#define CSMI_SAS_PRIORITY_UNKNOWN   0
-+#define CSMI_SAS_PRIORITY_UNCHANGED 0
-+#define CSMI_SAS_PRIORITY_AUTO      1
-+#define CSMI_SAS_PRIORITY_OFF       2
-+#define CSMI_SAS_PRIORITY_LOW       3
-+#define CSMI_SAS_PRIORITY_MEDIUM    4
-+#define CSMI_SAS_PRIORITY_HIGH      5
-+
-+// RAID Transformation Rules
-+// (uRaidSetTransformationRules)
-+#define CSMI_SAS_RAID_RULE_AVAILABLE_MEMORY     0x00000001
-+#define CSMI_SAS_RAID_RULE_OVERLAPPED_EXTENTS   0x00000002
-+
-+// RAID Cache Ratios Supported
-+// (bCacheRatiosSupported)
-+// from 0 to 100 defines the write to read ratio, 0 is 100% write
-+#define CSMI_SAS_RAID_CACHE_RATIO_RANGE     101
-+#define CSMI_SAS_RAID_CACHE_RATIO_FIXED     102
-+#define CSMI_SAS_RAID_CACHE_RATIO_AUTO      103
-+#define CSMI_SAS_RAID_CACHE_RATIO_END       255
-+
-+// RAID Cache Ratio Flag
-+// (bCacheRatioFlag)
-+#define CSMI_SAS_RAID_CACHE_RATIO_DISABLE   0
-+#define CSMI_SAS_RAID_CACHE_RATIO_ENABLE    1
-+
-+// RAID Clear Configuration Signature
-+// (bClearConfiguration)
-+#define CSMI_SAS_RAID_CLEAR_CONFIGURATION_SIGNATURE "RAIDCLR"
-+
-+// RAID Failure Codes
-+// (uFailureCode)
-+#define CSMI_SAS_FAIL_CODE_OK                           0
-+#define CSMI_SAS_FAIL_CODE_PARAMETER_INVALID            1000
-+#define CSMI_SAS_FAIL_CODE_TRANSFORM_PRIORITY_INVALID   1001
-+#define CSMI_SAS_FAIL_CODE_REBUILD_PRIORITY_INVALID     1002
-+#define CSMI_SAS_FAIL_CODE_CACHE_RATIO_INVALID          1003
-+#define CSMI_SAS_FAIL_CODE_SURFACE_SCAN_INVALID         1004
-+#define CSMI_SAS_FAIL_CODE_CLEAR_CONFIGURATION_INVALID  1005
-+#define CSMI_SAS_FAIL_CODE_ELEMENT_INDEX_INVALID        1006
-+#define CSMI_SAS_FAIL_CODE_SUBELEMENT_INDEX_INVALID     1007
-+#define CSMI_SAS_FAIL_CODE_EXTENT_INVALID               1008
-+#define CSMI_SAS_FAIL_CODE_BLOCK_COUNT_INVALID          1009
-+#define CSMI_SAS_FAIL_CODE_DRIVE_INDEX_INVALID          1010
-+#define CSMI_SAS_FAIL_CODE_EXISTING_LUN_INVALID         1011
-+#define CSMI_SAS_FAIL_CODE_RAID_TYPE_INVALID            1012
-+#define CSMI_SAS_FAIL_CODE_STRIPE_SIZE_INVALID          1013
-+#define CSMI_SAS_FAIL_CODE_TRANSFORMATION_INVALID       1014
-+#define CSMI_SAS_FAIL_CODE_CHANGE_COUNT_INVALID         1015
-+#define CSMI_SAS_FAIL_CODE_ENUMERATION_TYPE_INVALID     1016
-+
-+#define CSMI_SAS_FAIL_CODE_EXCEEDED_RAID_SET_COUNT      2000
-+#define CSMI_SAS_FAIL_CODE_DUPLICATE_LUN                2001
-+
-+#define CSMI_SAS_FAIL_CODE_WAIT_FOR_OPERATION           3000
-+
-+// RAID Enumeration Types
-+// (uEnumerationType)
-+#define CSMI_SAS_RAID_ELEMENT_TYPE_DRIVE                0
-+#define CSMI_SAS_RAID_ELEMENT_TYPE_MODULE               1
-+#define CSMI_SAS_RAID_ELEMENT_TYPE_DRIVE_RAID_SET       2
-+#define CSMI_SAS_RAID_ELEMENT_TYPE_EXTENT_DRIVE         3
-+
-+// RAID Extent Types
-+// (bExtentType)
-+#define CSMI_SAS_RAID_EXTENT_RESERVED       0
-+#define CSMI_SAS_RAID_EXTENT_METADATA       1
-+#define CSMI_SAS_RAID_EXTENT_ALLOCATED      2
-+#define CSMI_SAS_RAID_EXTENT_UNALLOCATED    3
-+
-+// RAID Operation Types
-+// (uOperationType)
-+#define CSMI_SAS_RAID_SET_CREATE            0
-+#define CSMI_SAS_RAID_SET_LABEL             1
-+#define CSMI_SAS_RAID_SET_TRANSFORM         2
-+#define CSMI_SAS_RAID_SET_DELETE            3
-+#define CSMI_SAS_RAID_SET_WRITE_PROTECT     4
-+#define CSMI_SAS_RAID_SET_CACHE             5
-+#define CSMI_SAS_RAID_SET_ONLINE_STATE      6
-+#define CSMI_SAS_RAID_SET_SPARE             7
-+
-+// RAID Transform Types
-+// (bTransformType)
-+#define CSMI_SAS_RAID_SET_TRANSFORM_SPLIT_MIRROR    0
-+#define CSMI_SAS_RAID_SET_TRANSFORM_MERGE_RAID_0    1
-+#define CSMI_SAS_RAID_SET_TRANSFORM_LUN_RENUMBER    2
-+#define CSMI_SAS_RAID_SET_TRANSFORM_RAID_SET        3
-+
-+// RAID Online State
-+// (bOnlineState)
-+#define CSMI_SAS_RAID_SET_STATE_UNKNOWN     0
-+#define CSMI_SAS_RAID_SET_STATE_ONLINE      1
-+#define CSMI_SAS_RAID_SET_STATE_OFFLINE     2
-+
-+/* * * * * * * * * * SAS HBA Class IOCTL Constants * * * * * * * * * */
-+
-+// Return codes for SAS IOCTL's
-+// (IoctlHeader.ReturnCode)
-+
-+#define CSMI_SAS_PHY_INFO_CHANGED            CSMI_SAS_STATUS_SUCCESS
-+#define CSMI_SAS_PHY_INFO_NOT_CHANGEABLE     2000
-+#define CSMI_SAS_LINK_RATE_OUT_OF_RANGE      2001
-+
-+#define CSMI_SAS_PHY_DOES_NOT_EXIST          2002
-+#define CSMI_SAS_PHY_DOES_NOT_MATCH_PORT     2003
-+#define CSMI_SAS_PHY_CANNOT_BE_SELECTED      2004
-+#define CSMI_SAS_SELECT_PHY_OR_PORT          2005
-+#define CSMI_SAS_PORT_DOES_NOT_EXIST         2006
-+#define CSMI_SAS_PORT_CANNOT_BE_SELECTED     2007
-+#define CSMI_SAS_CONNECTION_FAILED           2008
-+
-+#define CSMI_SAS_NO_SATA_DEVICE              2009
-+#define CSMI_SAS_NO_SATA_SIGNATURE           2010
-+#define CSMI_SAS_SCSI_EMULATION              2011
-+#define CSMI_SAS_NOT_AN_END_DEVICE           2012
-+#define CSMI_SAS_NO_SCSI_ADDRESS             2013
-+#define CSMI_SAS_NO_DEVICE_ADDRESS           2014
-+
-+// Signature value
-+// (IoctlHeader.Signature)
-+
-+#define CSMI_SAS_SIGNATURE    "CSMISAS"
-+
-+// Timeout value default of 60 seconds
-+// (IoctlHeader.Timeout)
-+
-+#define CSMI_SAS_TIMEOUT      60
-+
-+// Device types
-+// (bDeviceType)
-+
-+#define CSMI_SAS_PHY_UNUSED               0x00
-+#define CSMI_SAS_NO_DEVICE_ATTACHED       0x00
-+#define CSMI_SAS_END_DEVICE               0x10
-+#define CSMI_SAS_EDGE_EXPANDER_DEVICE     0x20
-+#define CSMI_SAS_FANOUT_EXPANDER_DEVICE   0x30
-+
-+// Protocol options
-+// (bInitiatorPortProtocol, bTargetPortProtocol)
-+
-+#define CSMI_SAS_PROTOCOL_SATA   0x01
-+#define CSMI_SAS_PROTOCOL_SMP    0x02
-+#define CSMI_SAS_PROTOCOL_STP    0x04
-+#define CSMI_SAS_PROTOCOL_SSP    0x08
-+
-+// Negotiated and hardware link rates
-+// (bNegotiatedLinkRate, bMinimumLinkRate, bMaximumLinkRate)
-+
-+#define CSMI_SAS_LINK_RATE_UNKNOWN  0x00
-+#define CSMI_SAS_PHY_DISABLED       0x01
-+#define CSMI_SAS_LINK_RATE_FAILED   0x02
-+#define CSMI_SAS_SATA_SPINUP_HOLD   0x03
-+#define CSMI_SAS_SATA_PORT_SELECTOR 0x04
-+#define CSMI_SAS_LINK_RATE_1_5_GBPS 0x08
-+#define CSMI_SAS_LINK_RATE_3_0_GBPS 0x09
-+#define CSMI_SAS_LINK_VIRTUAL       0x10
-+
-+// Discover state
-+// (bAutoDiscover)
-+
-+#define CSMI_SAS_DISCOVER_NOT_SUPPORTED   0x00
-+#define CSMI_SAS_DISCOVER_NOT_STARTED     0x01
-+#define CSMI_SAS_DISCOVER_IN_PROGRESS     0x02
-+#define CSMI_SAS_DISCOVER_COMPLETE        0x03
-+#define CSMI_SAS_DISCOVER_ERROR           0x04
-+
-+// Phy features
-+
-+#define CSMI_SAS_PHY_VIRTUAL_SMP          0x01
-+
-+// Programmed link rates
-+// (bMinimumLinkRate, bMaximumLinkRate)
-+// (bProgrammedMinimumLinkRate, bProgrammedMaximumLinkRate)
-+
-+#define CSMI_SAS_PROGRAMMED_LINK_RATE_UNCHANGED 0x00
-+#define CSMI_SAS_PROGRAMMED_LINK_RATE_1_5_GBPS  0x08
-+#define CSMI_SAS_PROGRAMMED_LINK_RATE_3_0_GBPS  0x09
-+
-+// Link rate
-+// (bNegotiatedLinkRate in CSMI_SAS_SET_PHY_INFO)
-+
-+#define CSMI_SAS_LINK_RATE_NEGOTIATE      0x00
-+#define CSMI_SAS_LINK_RATE_PHY_DISABLED   0x01
-+
-+// Signal class
-+// (bSignalClass in CSMI_SAS_SET_PHY_INFO)
-+
-+#define CSMI_SAS_SIGNAL_CLASS_UNKNOWN     0x00
-+#define CSMI_SAS_SIGNAL_CLASS_DIRECT      0x01
-+#define CSMI_SAS_SIGNAL_CLASS_SERVER      0x02
-+#define CSMI_SAS_SIGNAL_CLASS_ENCLOSURE   0x03
-+
-+// Link error reset
-+// (bResetCounts)
-+
-+#define CSMI_SAS_LINK_ERROR_DONT_RESET_COUNTS   0x00
-+#define CSMI_SAS_LINK_ERROR_RESET_COUNTS        0x01
-+
-+// Phy identifier
-+// (bPhyIdentifier)
-+
-+#define CSMI_SAS_USE_PORT_IDENTIFIER   0xFF
-+
-+// Port identifier
-+// (bPortIdentifier)
-+
-+#define CSMI_SAS_IGNORE_PORT           0xFF
-+
-+// Programmed link rates
-+// (bConnectionRate)
-+
-+#define CSMI_SAS_LINK_RATE_NEGOTIATED  0x00
-+#define CSMI_SAS_LINK_RATE_1_5_GBPS    0x08
-+#define CSMI_SAS_LINK_RATE_3_0_GBPS    0x09
-+
-+// Connection status
-+// (bConnectionStatus)
-+
-+#define CSMI_SAS_OPEN_ACCEPT                          0
-+#define CSMI_SAS_OPEN_REJECT_BAD_DESTINATION          1
-+#define CSMI_SAS_OPEN_REJECT_RATE_NOT_SUPPORTED       2
-+#define CSMI_SAS_OPEN_REJECT_NO_DESTINATION           3
-+#define CSMI_SAS_OPEN_REJECT_PATHWAY_BLOCKED          4
-+#define CSMI_SAS_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED   5
-+#define CSMI_SAS_OPEN_REJECT_RESERVE_ABANDON          6
-+#define CSMI_SAS_OPEN_REJECT_RESERVE_CONTINUE         7
-+#define CSMI_SAS_OPEN_REJECT_RESERVE_INITIALIZE       8
-+#define CSMI_SAS_OPEN_REJECT_RESERVE_STOP             9
-+#define CSMI_SAS_OPEN_REJECT_RETRY                    10
-+#define CSMI_SAS_OPEN_REJECT_STP_RESOURCES_BUSY       11
-+#define CSMI_SAS_OPEN_REJECT_WRONG_DESTINATION        12
-+
-+// SSP Status
-+// (bSSPStatus)
-+
-+#define CSMI_SAS_SSP_STATUS_UNKNOWN     0x00
-+#define CSMI_SAS_SSP_STATUS_WAITING     0x01
-+#define CSMI_SAS_SSP_STATUS_COMPLETED   0x02
-+#define CSMI_SAS_SSP_STATUS_FATAL_ERROR 0x03
-+#define CSMI_SAS_SSP_STATUS_RETRY       0x04
-+#define CSMI_SAS_SSP_STATUS_NO_TAG      0x05
-+
-+// SSP Flags
-+// (uFlags)
-+
-+#define CSMI_SAS_SSP_READ           0x00000001
-+#define CSMI_SAS_SSP_WRITE          0x00000002
-+#define CSMI_SAS_SSP_UNSPECIFIED    0x00000004
-+
-+#define CSMI_SAS_SSP_TASK_ATTRIBUTE_SIMPLE         0x00000000
-+#define CSMI_SAS_SSP_TASK_ATTRIBUTE_HEAD_OF_QUEUE  0x00000010
-+#define CSMI_SAS_SSP_TASK_ATTRIBUTE_ORDERED        0x00000020
-+#define CSMI_SAS_SSP_TASK_ATTRIBUTE_ACA            0x00000040
-+
-+// SSP Data present
-+// (bDataPresent)
-+
-+#define CSMI_SAS_SSP_NO_DATA_PRESENT         0x00
-+#define CSMI_SAS_SSP_RESPONSE_DATA_PRESENT   0x01
-+#define CSMI_SAS_SSP_SENSE_DATA_PRESENT      0x02
-+
-+// STP Flags
-+// (uFlags)
-+
-+#define CSMI_SAS_STP_READ           0x00000001
-+#define CSMI_SAS_STP_WRITE          0x00000002
-+#define CSMI_SAS_STP_UNSPECIFIED    0x00000004
-+#define CSMI_SAS_STP_PIO            0x00000010
-+#define CSMI_SAS_STP_DMA            0x00000020
-+#define CSMI_SAS_STP_PACKET         0x00000040
-+#define CSMI_SAS_STP_DMA_QUEUED     0x00000080
-+#define CSMI_SAS_STP_EXECUTE_DIAG   0x00000100
-+#define CSMI_SAS_STP_RESET_DEVICE   0x00000200
-+
-+// Task Management Flags
-+// (uFlags)
-+
-+#define CSMI_SAS_TASK_IU               0x00000001
-+#define CSMI_SAS_HARD_RESET_SEQUENCE   0x00000002
-+#define CSMI_SAS_SUPPRESS_RESULT       0x00000004
-+
-+// Task Management Functions
-+// (bTaskManagement)
-+
-+#define CSMI_SAS_SSP_ABORT_TASK           0x01
-+#define CSMI_SAS_SSP_ABORT_TASK_SET       0x02
-+#define CSMI_SAS_SSP_CLEAR_TASK_SET       0x04
-+#define CSMI_SAS_SSP_LOGICAL_UNIT_RESET   0x08
-+#define CSMI_SAS_SSP_CLEAR_ACA            0x40
-+#define CSMI_SAS_SSP_QUERY_TASK           0x80
-+
-+// Task Management Information
-+// (uInformation)
-+
-+#define CSMI_SAS_SSP_TEST           1
-+#define CSMI_SAS_SSP_EXCEEDED       2
-+#define CSMI_SAS_SSP_DEMAND         3
-+#define CSMI_SAS_SSP_TRIGGER        4
-+
-+// Connector Pinout Information
-+// (uPinout)
-+
-+#define CSMI_SAS_CON_UNKNOWN              0x00000001
-+#define CSMI_SAS_CON_SFF_8482             0x00000002
-+#define CSMI_SAS_CON_SFF_8470_LANE_1      0x00000100
-+#define CSMI_SAS_CON_SFF_8470_LANE_2      0x00000200
-+#define CSMI_SAS_CON_SFF_8470_LANE_3      0x00000400
-+#define CSMI_SAS_CON_SFF_8470_LANE_4      0x00000800
-+#define CSMI_SAS_CON_SFF_8484_LANE_1      0x00010000
-+#define CSMI_SAS_CON_SFF_8484_LANE_2      0x00020000
-+#define CSMI_SAS_CON_SFF_8484_LANE_3      0x00040000
-+#define CSMI_SAS_CON_SFF_8484_LANE_4      0x00080000
-+
-+// Connector Location Information
-+// (bLocation)
-+
-+// same as uPinout above...
-+// #define CSMI_SAS_CON_UNKNOWN              0x01
-+#define CSMI_SAS_CON_INTERNAL             0x02
-+#define CSMI_SAS_CON_EXTERNAL             0x04
-+#define CSMI_SAS_CON_SWITCHABLE           0x08
-+#define CSMI_SAS_CON_AUTO                 0x10
-+#define CSMI_SAS_CON_NOT_PRESENT          0x20
-+#define CSMI_SAS_CON_NOT_CONNECTED        0x80
-+
-+// Device location identification
-+// (bIdentify)
-+
-+#define CSMI_SAS_LOCATE_UNKNOWN           0x00
-+#define CSMI_SAS_LOCATE_FORCE_OFF         0x01
-+#define CSMI_SAS_LOCATE_FORCE_ON          0x02
-+
-+// Location Valid flags
-+// (uLocationFlags)
-+
-+#define CSMI_SAS_LOCATE_SAS_ADDRESS_VALID           0x00000001
-+#define CSMI_SAS_LOCATE_SAS_LUN_VALID               0x00000002
-+#define CSMI_SAS_LOCATE_ENCLOSURE_IDENTIFIER_VALID  0x00000004
-+#define CSMI_SAS_LOCATE_ENCLOSURE_NAME_VALID        0x00000008
-+#define CSMI_SAS_LOCATE_BAY_PREFIX_VALID            0x00000010
-+#define CSMI_SAS_LOCATE_BAY_IDENTIFIER_VALID        0x00000020
-+#define CSMI_SAS_LOCATE_LOCATION_STATE_VALID        0x00000040
-+
-+/* * * * * * * * SAS Phy Control Class IOCTL Constants * * * * * * * * */
-+
-+// Return codes for SAS Phy Control IOCTL's
-+// (IoctlHeader.ReturnCode)
-+
-+// Signature value
-+// (IoctlHeader.Signature)
-+
-+#define CSMI_PHY_SIGNATURE    "CSMIPHY"
-+
-+// Phy Control Functions
-+// (bFunction)
-+
-+// values 0x00 to 0xFF are consistent in definition with the SMP PHY CONTROL
-+// function defined in the SAS spec
-+#define CSMI_SAS_PC_NOP                   0x00000000
-+#define CSMI_SAS_PC_LINK_RESET            0x00000001
-+#define CSMI_SAS_PC_HARD_RESET            0x00000002
-+#define CSMI_SAS_PC_PHY_DISABLE           0x00000003
-+// 0x04 to 0xFF reserved...
-+#define CSMI_SAS_PC_GET_PHY_SETTINGS      0x00000100
-+
-+// Link Flags
-+#define CSMI_SAS_PHY_ACTIVATE_CONTROL     0x00000001
-+#define CSMI_SAS_PHY_UPDATE_SPINUP_RATE   0x00000002
-+#define CSMI_SAS_PHY_AUTO_COMWAKE         0x00000004
-+
-+// Device Types for Phy Settings
-+// (bType)
-+#define CSMI_SAS_UNDEFINED 0x00
-+#define CSMI_SAS_SATA      0x01
-+#define CSMI_SAS_SAS       0x02
-+
-+// Transmitter Flags
-+// (uTransmitterFlags)
-+#define CSMI_SAS_PHY_PREEMPHASIS_DISABLED    0x00000001
-+
-+// Receiver Flags
-+// (uReceiverFlags)
-+#define CSMI_SAS_PHY_EQUALIZATION_DISABLED   0x00000001
-+
-+// Pattern Flags
-+// (uPatternFlags)
-+// #define CSMI_SAS_PHY_ACTIVATE_CONTROL     0x00000001
-+#define CSMI_SAS_PHY_DISABLE_SCRAMBLING      0x00000002
-+#define CSMI_SAS_PHY_DISABLE_ALIGN           0x00000004
-+#define CSMI_SAS_PHY_DISABLE_SSC             0x00000008
-+
-+#define CSMI_SAS_PHY_FIXED_PATTERN           0x00000010
-+#define CSMI_SAS_PHY_USER_PATTERN            0x00000020
-+
-+// Fixed Patterns
-+// (bFixedPattern)
-+#define CSMI_SAS_PHY_CJPAT                   0x00000001
-+#define CSMI_SAS_PHY_ALIGN                   0x00000002
-+
-+// Type Flags
-+// (bTypeFlags)
-+#define CSMI_SAS_PHY_POSITIVE_DISPARITY      0x01
-+#define CSMI_SAS_PHY_NEGATIVE_DISPARITY      0x02
-+#define CSMI_SAS_PHY_CONTROL_CHARACTER       0x04
-+
-+// Miscellaneous
-+#define SLOT_NUMBER_UNKNOWN   0xFFFF
-+
-+/*************************************************************************/
-+/* DATA STRUCTURES                                                       */
-+/*************************************************************************/
-+
-+/* * * * * * * * * * Class Independent Structures * * * * * * * * * */
-+
-+// EDM #pragma CSMI_SAS_BEGIN_PACK(8)
-+#pragma pack(8)
-+
-+// CC_CSMI_SAS_DRIVER_INFO
-+
-+typedef struct _CSMI_SAS_DRIVER_INFO {
-+   __u8  szName[81];
-+   __u8  szDescription[81];
-+   __u16 usMajorRevision;
-+   __u16 usMinorRevision;
-+   __u16 usBuildRevision;
-+   __u16 usReleaseRevision;
-+   __u16 usCSMIMajorRevision;
-+   __u16 usCSMIMinorRevision;
-+} CSMI_SAS_DRIVER_INFO,
-+  *PCSMI_SAS_DRIVER_INFO;
-+
-+typedef struct _CSMI_SAS_DRIVER_INFO_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_DRIVER_INFO Information;
-+} CSMI_SAS_DRIVER_INFO_BUFFER,
-+  *PCSMI_SAS_DRIVER_INFO_BUFFER;
-+
-+// CC_CSMI_SAS_CNTLR_CONFIGURATION
-+
-+typedef struct _CSMI_SAS_PCI_BUS_ADDRESS {
-+   __u8  bBusNumber;
-+   __u8  bDeviceNumber;
-+   __u8  bFunctionNumber;
-+   __u8  bReserved;
-+} CSMI_SAS_PCI_BUS_ADDRESS,
-+  *PCSMI_SAS_PCI_BUS_ADDRESS;
-+
-+typedef union _CSMI_SAS_IO_BUS_ADDRESS {
-+   CSMI_SAS_PCI_BUS_ADDRESS PciAddress;
-+   __u8  bReserved[32];
-+} CSMI_SAS_IO_BUS_ADDRESS,
-+  *PCSMI_SAS_IO_BUS_ADDRESS;
-+
-+typedef struct _CSMI_SAS_CNTLR_CONFIG {
-+   __u32 uBaseIoAddress;
-+   struct {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } BaseMemoryAddress;
-+   __u32 uBoardID;
-+   __u16 usSlotNumber;
-+   __u8  bControllerClass;
-+   __u8  bIoBusType;
-+   CSMI_SAS_IO_BUS_ADDRESS BusAddress;
-+   __u8  szSerialNumber[81];
-+   __u16 usMajorRevision;
-+   __u16 usMinorRevision;
-+   __u16 usBuildRevision;
-+   __u16 usReleaseRevision;
-+   __u16 usBIOSMajorRevision;
-+   __u16 usBIOSMinorRevision;
-+   __u16 usBIOSBuildRevision;
-+   __u16 usBIOSReleaseRevision;
-+   __u32 uControllerFlags;
-+   __u16 usRromMajorRevision;
-+   __u16 usRromMinorRevision;
-+   __u16 usRromBuildRevision;
-+   __u16 usRromReleaseRevision;
-+   __u16 usRromBIOSMajorRevision;
-+   __u16 usRromBIOSMinorRevision;
-+   __u16 usRromBIOSBuildRevision;
-+   __u16 usRromBIOSReleaseRevision;
-+   __u8  bReserved[7];
-+} CSMI_SAS_CNTLR_CONFIG,
-+  *PCSMI_SAS_CNTLR_CONFIG;
-+
-+typedef struct _CSMI_SAS_CNTLR_CONFIG_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_CNTLR_CONFIG Configuration;
-+} CSMI_SAS_CNTLR_CONFIG_BUFFER,
-+  *PCSMI_SAS_CNTLR_CONFIG_BUFFER;
-+
-+// CC_CSMI_SAS_CNTLR_STATUS
-+
-+typedef struct _CSMI_SAS_CNTLR_STATUS {
-+   __u32 uStatus;
-+   __u32 uOfflineReason;
-+   __u8  bReserved[28];
-+} CSMI_SAS_CNTLR_STATUS,
-+  *PCSMI_SAS_CNTLR_STATUS;
-+
-+typedef struct _CSMI_SAS_CNTLR_STATUS_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_CNTLR_STATUS Status;
-+} CSMI_SAS_CNTLR_STATUS_BUFFER,
-+  *PCSMI_SAS_CNTLR_STATUS_BUFFER;
-+
-+// CC_CSMI_SAS_FIRMWARE_DOWNLOAD
-+
-+typedef struct _CSMI_SAS_FIRMWARE_DOWNLOAD {
-+   __u32 uBufferLength;
-+   __u32 uDownloadFlags;
-+   __u8  bReserved[32];
-+   __u16 usStatus;
-+   __u16 usSeverity;
-+} CSMI_SAS_FIRMWARE_DOWNLOAD,
-+  *PCSMI_SAS_FIRMWARE_DOWNLOAD;
-+
-+typedef struct _CSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_FIRMWARE_DOWNLOAD Information;
-+   __u8  bDataBuffer[1];
-+} CSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER,
-+  *PCSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER;
-+
-+// CC_CSMI_SAS_RAID_INFO
-+
-+typedef struct _CSMI_SAS_RAID_INFO {
-+   __u32 uNumRaidSets;
-+   __u32 uMaxDrivesPerSet;
-+   __u32 uMaxRaidSets;
-+   __u8  bMaxRaidTypes;
-+   __u8  bReservedByteFields[7];
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulMinRaidSetBlocks;
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulMaxRaidSetBlocks;
-+   __u32 uMaxPhysicalDrives;
-+   __u32 uMaxExtents;
-+   __u32 uMaxModules;
-+   __u32 uMaxTransformationMemory;
-+   __u32 uChangeCount;
-+   __u8  bReserved[44];
-+} CSMI_SAS_RAID_INFO,
-+  *PCSMI_SAS_RAID_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_INFO_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_RAID_INFO Information;
-+} CSMI_SAS_RAID_INFO_BUFFER,
-+  *PCSMI_SAS_RAID_INFO_BUFFER;
-+
-+// CC_CSMI_SAS_GET_RAID_CONFIG
-+
-+typedef struct _CSMI_SAS_RAID_DRIVES {
-+   __u8  bModel[40];
-+   __u8  bFirmware[8];
-+   __u8  bSerialNumber[40];
-+   __u8  bSASAddress[8];
-+   __u8  bSASLun[8];
-+   __u8  bDriveStatus;
-+   __u8  bDriveUsage;
-+   __u16 usBlockSize;
-+   __u8  bDriveType;
-+   __u8  bReserved[15];
-+   __u32 uDriveIndex;
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulTotalUserBlocks;
-+} CSMI_SAS_RAID_DRIVES,
-+  *PCSMI_SAS_RAID_DRIVES;
-+
-+typedef struct _CSMI_SAS_RAID_DEVICE_ID {
-+   __u8  bDeviceIdentificationVPDPage[1];
-+} CSMI_SAS_RAID_DEVICE_ID,
-+  *PCSMI_SAS_RAID_DEVICE_ID;
-+
-+typedef struct _CSMI_SAS_RAID_SET_ADDITIONAL_DATA {
-+   __u8  bLabel[16];
-+   __u8  bRaidSetLun[8];
-+   __u8  bWriteProtection;
-+   __u8  bCacheSetting;
-+   __u8  bCacheRatio;
-+   __u16 usBlockSize;
-+   __u8  bReservedBytes[11];
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulRaidSetExtentOffset;
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulRaidSetBlocks;
-+   __u32 uStripeSizeInBlocks;
-+   __u32 uSectorsPerTrack;
-+   __u8  bApplicationScratchPad[16];
-+   __u32 uNumberOfHeads;
-+   __u32 uNumberOfTracks;
-+   __u8  bReserved[24];
-+} CSMI_SAS_RAID_SET_ADDITIONAL_DATA,
-+  *PCSMI_SAS_RAID_SET_ADDITIONAL_DATA;
-+
-+typedef struct _CSMI_SAS_RAID_CONFIG {
-+   __u32 uRaidSetIndex;
-+   __u32 uCapacity;
-+   __u32 uStripeSize;
-+   __u8  bRaidType;
-+   __u8  bStatus;
-+   __u8  bInformation;
-+   __u8  bDriveCount;
-+   __u8  bDataType;
-+   __u8  bReserved[11];
-+   __u32 uFailureCode;
-+   __u32 uChangeCount;
-+   union {
-+      CSMI_SAS_RAID_DRIVES Drives[1];
-+      CSMI_SAS_RAID_DEVICE_ID DeviceId[1];
-+      CSMI_SAS_RAID_SET_ADDITIONAL_DATA Data[1];
-+   };
-+} CSMI_SAS_RAID_CONFIG,
-+   *PCSMI_SAS_RAID_CONFIG;
-+
-+typedef struct _CSMI_SAS_RAID_CONFIG_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_RAID_CONFIG Configuration;
-+} CSMI_SAS_RAID_CONFIG_BUFFER,
-+  *PCSMI_SAS_RAID_CONFIG_BUFFER;
-+
-+// CC_CSMI_SAS_GET_RAID_FEATURES
-+
-+typedef struct _CSMI_SAS_RAID_TYPE_DESCRIPTION {
-+  __u8  bRaidType;
-+  __u8  bReservedBytes[7];
-+  __u32 uSupportedStripeSizeMap;
-+  __u8  bReserved[24];
-+} CSMI_SAS_RAID_TYPE_DESCRIPTION,
-+  *PCSMI_SAS_RAID_TYPE_DESCRIPTION;
-+
-+typedef struct _CSMI_SAS_RAID_FEATURES {
-+   __u32 uFeatures;
-+   __u8  bReservedFeatures[32];
-+   __u8  bDefaultTransformPriority;
-+   __u8  bTransformPriority;
-+   __u8  bDefaultRebuildPriority;
-+   __u8  bRebuildPriority;
-+   __u8  bDefaultSurfaceScanPriority;
-+   __u8  bSurfaceScanPriority;
-+   __u16 usReserved;
-+   __u32 uRaidSetTransformationRules;
-+   __u32 uReserved[11];
-+   CSMI_SAS_RAID_TYPE_DESCRIPTION RaidType[24];
-+   __u8  bCacheRatiosSupported[104];
-+   __u32 uChangeCount;
-+   __u32 uFailureCode;
-+   __u8  bReserved[120];
-+} CSMI_SAS_RAID_FEATURES,
-+  *PCSMI_SAS_RAID_FEATURES;
-+
-+typedef struct _CSMI_SAS_RAID_FEATURES_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_RAID_FEATURES Information;
-+} CSMI_SAS_RAID_FEATURES_BUFFER,
-+  *PCSMI_SAS_RAID_FEATURES_BUFFER;
-+
-+// CC_CSMI_SAS_SET_RAID_CONTROL
-+
-+typedef struct _CSMI_SAS_RAID_CONTROL {
-+   __u8  bTransformPriority;
-+   __u8  bRebuildPriority;
-+   __u8  bCacheRatioFlag;
-+   __u8  bCacheRatio;
-+   __u8  bSurfaceScanPriority;
-+   __u8  bReservedBytes[15];
-+   __u8  bClearConfiguration[8];
-+   __u32 uChangeCount;
-+   __u8  bReserved[88];
-+   __u32 uFailureCode;
-+   __u8  bFailureDescription[80];
-+} CSMI_SAS_RAID_CONTROL,
-+  *PCSMI_SAS_RAID_CONTROL;
-+
-+typedef struct _CSMI_SAS_RAID_CONTROL_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_RAID_CONTROL Information;
-+} CSMI_SAS_RAID_CONTROL_BUFFER,
-+  *PCSMI_SAS_RAID_CONTROL_BUFFER;
-+
-+// CC_CSMI_SAS_GET_RAID_ELEMENT
-+
-+typedef struct _CSMI_SAS_DRIVE_EXTENT_INFO {
-+   __u32 uDriveIndex;
-+   __u8  bExtentType;
-+   __u8  bReservedBytes[7];
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulExtentOffset;
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulExtentBlocks;
-+   __u32 uRaidSetIndex;
-+   __u8  bReserved[96];
-+} CSMI_SAS_DRIVE_EXTENT_INFO,
-+  *PCSMI_SAS_DRIVE_EXTENT_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_MODULE_INFO {
-+   __u8  bReserved[128];
-+} CSMI_SAS_RAID_MODULE_INFO,
-+  *PCSMI_SAS_RAID_MODULE_INFO;
-+
-+typedef struct _CSMI_SAS_DRIVE_LOCATION {
-+   __u8  bConnector[16];
-+   __u8  bBoxName[16];
-+   __u32 uBay;
-+   __u8  bReservedBytes[4];
-+   __u8  bAttachedSASAddress[8];
-+   __u8  bAttachedPhyIdentifier;
-+   __u8  bReserved[79];
-+} CSMI_SAS_DRIVE_LOCATION,
-+  *PCSMI_SAS_DRIVE_LOCATION;
-+
-+typedef struct _CSMI_SAS_RAID_DRIVES_ADDITIONAL_DATA {
-+   __u8  bNegotiatedLinkRate[2];
-+   __u8  bReserved[126];
-+} CSMI_SAS_RAID_DRIVES_ADDITIONAL_DATA,
-+  *PCSMI_SAS_RAID_DRIVES_ADDITIONAL_DATA;
-+
-+typedef struct _CSMI_SAS_DRIVE_INFO {
-+   CSMI_SAS_RAID_DRIVES Device;
-+   CSMI_SAS_RAID_DRIVES_ADDITIONAL_DATA Data;
-+   CSMI_SAS_DRIVE_LOCATION Location;
-+   __u8  bReserved[16];
-+} CSMI_SAS_DRIVE_INFO,
-+  *PCSMI_SAS_DRIVE_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_ELEMENT {
-+   __u32 uEnumerationType;
-+   __u32 uElementIndex;
-+   __u32 uNumElements;
-+   __u32 uChangeCount;
-+   __u32 uSubElementIndex;
-+   __u8  bReserved[32];
-+   __u32 uFailureCode;
-+   __u8  bFailureDescription[80];
-+   union {
-+       CSMI_SAS_DRIVE_INFO Drive;
-+       CSMI_SAS_RAID_MODULE_INFO Module;
-+       CSMI_SAS_DRIVE_EXTENT_INFO Extent;
-+   } Element;
-+} CSMI_SAS_RAID_ELEMENT,
-+  *PCSMI_SAS_RAID_ELEMENT;
-+
-+typedef struct _CSMI_SAS_RAID_ELEMENT_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_RAID_ELEMENT Information;
-+} CSMI_SAS_RAID_ELEMENT_BUFFER,
-+  *PCSMI_SAS_RAID_ELEMENT_BUFFER;
-+
-+// CC_CSMI_SAS_SET_RAID_OPERATION
-+
-+typedef struct _CSMI_SAS_RAID_SET_LIST {
-+   __u32 uRaidSetIndex;
-+   __u8  bExistingLun[8];
-+   __u8  bNewLun[8];
-+   __u8  bReserved[12];
-+} CSMI_SAS_RAID_SET_LIST,
-+  *PCSMI_SAS_RAID_SET_LIST;
-+
-+typedef struct _CSMI_SAS_RAID_SET_DRIVE_LIST {
-+   __u32 uDriveIndex;
-+   __u8  bDriveUsage;
-+   __u8  bReserved[27];
-+} CSMI_SAS_RAID_SET_DRIVE_LIST,
-+  *PCSMI_SAS_RAID_SET_DRIVE_LIST;
-+
-+typedef struct _CSMI_SAS_RAID_SET_SPARE_INFO {
-+   __u32 uRaidSetIndex;
-+   __u32 uDriveCount;
-+   __u8  bApplicationScratchPad[16];
-+   __u8  bReserved[104];
-+} CSMI_SAS_RAID_SET_SPARE_INFO,
-+  *PCSMI_SAS_RAID_SET_SPARE_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_SET_ONLINE_STATE_INFO {
-+   __u32 uRaidSetIndex;
-+   __u8  bOnlineState;
-+   __u8  bReserved[123];
-+} CSMI_SAS_RAID_SET_ONLINE_STATE_INFO,
-+  *PCSMI_SAS_RAID_SET_ONLINE_STATE_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_SET_CACHE_INFO {
-+   __u32 uRaidSetIndex;
-+   __u8  bCacheSetting;
-+   __u8  bCacheRatioFlag;
-+   __u8  bCacheRatio;
-+   __u8  bReserved[121];
-+} CSMI_SAS_RAID_SET_CACHE_INFO,
-+  *PCSMI_SAS_RAID_SET_CACHE_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_SET_WRITE_PROTECT_INFO {
-+   __u32 uRaidSetIndex;
-+   __u8  bWriteProtectSetting;
-+   __u8  bReserved[123];
-+} CSMI_SAS_RAID_SET_WRITE_PROTECT_INFO,
-+  *PCSMI_SAS_RAID_SET_WRITE_PROTECT_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_SET_DELETE_INFO {
-+   __u32 uRaidSetIndex;
-+   __u8  bReserved[124];
-+} CSMI_SAS_RAID_SET_DELETE_INFO,
-+  *PCSMI_SAS_RAID_SET_DELETE_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_SET_MODIFY_INFO {
-+   __u8  bRaidType;
-+   __u8  bReservedBytes[7];
-+   __u32 uStripeSize;
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulRaidSetBlocks;
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulRaidSetExtentOffset;
-+   __u32 uDriveCount;
-+   __u8  bReserved[96];
-+} CSMI_SAS_RAID_SET_MODIFY_INFO,
-+  *PCSMI_SAS_RAID_SET_MODIFY_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_SET_TRANSFORM_INFO {
-+   __u8  bTransformType;
-+   __u8  bReservedBytes[3];
-+   __u32 uRaidSetIndex;
-+   __u8  bRaidType;
-+   __u8  bReservedBytes2[11];
-+   __u32 uAdditionalRaidSetIndex;
-+   __u32 uRaidSetCount;
-+   __u8  bApplicationScratchPad[16];
-+   CSMI_SAS_RAID_SET_MODIFY_INFO Modify;
-+   __u8  bReserved[80];
-+} CSMI_SAS_RAID_SET_TRANSFORM_INFO,
-+  *PCSMI_SAS_RAID_SET_TRANSFORM_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_SET_LABEL_INFO {
-+   __u32 uRaidSetIndex;
-+   __u8  bLabel[16];
-+   __u8  bReserved[108];
-+} CSMI_SAS_RAID_SET_LABEL_INFO,
-+  *PCSMI_SAS_RAID_SET_LABEL_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_SET_CREATE_INFO {
-+   __u8  bRaidType;
-+   __u8  bReservedBytes[7];
-+   __u32 uStripeSize;
-+   __u32 uTrackSectorCount;
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulRaidSetBlocks;
-+   struct
-+   {
-+      __u32 uLowPart;
-+      __u32 uHighPart;
-+   } ulRaidSetExtentOffset;
-+   __u32 uDriveCount;
-+   __u8  bLabel[16];
-+   __u32 uRaidSetIndex;
-+   __u8  bApplicationScratchPad[16];
-+   __u32 uNumberOfHeads;
-+   __u32 uNumberOfTracks;
-+   __u8  bReserved[48];
-+} CSMI_SAS_RAID_SET_CREATE_INFO,
-+  *PCSMI_SAS_RAID_SET_CREATE_INFO;
-+
-+typedef struct _CSMI_SAS_RAID_SET_OPERATION {
-+   __u32 uOperationType;
-+   __u32 uChangeCount;
-+   __u32 uFailureCode;
-+   __u8  bFailureDescription[80];
-+   __u8  bReserved[28];
-+   union {
-+       CSMI_SAS_RAID_SET_CREATE_INFO Create;
-+       CSMI_SAS_RAID_SET_LABEL_INFO Label;
-+       CSMI_SAS_RAID_SET_TRANSFORM_INFO Transform;
-+       CSMI_SAS_RAID_SET_DELETE_INFO Delete;
-+       CSMI_SAS_RAID_SET_WRITE_PROTECT_INFO Protect;
-+       CSMI_SAS_RAID_SET_CACHE_INFO Cache;
-+       CSMI_SAS_RAID_SET_ONLINE_STATE_INFO State;
-+       CSMI_SAS_RAID_SET_SPARE_INFO Spare;
-+   } Operation;
-+   union {
-+       CSMI_SAS_RAID_SET_DRIVE_LIST DriveList[1];
-+       CSMI_SAS_RAID_SET_LIST RaidSetList[1];
-+   } Parameters;
-+} CSMI_SAS_RAID_SET_OPERATION,
-+  *PCSMI_SAS_RAID_SET_OPERATION;
-+
-+typedef struct _CSMI_SAS_RAID_SET_OPERATION_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_RAID_SET_OPERATION Information;
-+} CSMI_SAS_RAID_SET_OPERATION_BUFFER,
-+  *PCSMI_SAS_RAID_SET_OPERATION_BUFFER;
-+
-+/* * * * * * * * * * SAS HBA Class Structures * * * * * * * * * */
-+
-+// CC_CSMI_SAS_GET_PHY_INFO
-+
-+typedef struct _CSMI_SAS_IDENTIFY {
-+   __u8  bDeviceType;
-+   __u8  bRestricted;
-+   __u8  bInitiatorPortProtocol;
-+   __u8  bTargetPortProtocol;
-+   __u8  bRestricted2[8];
-+   __u8  bSASAddress[8];
-+   __u8  bPhyIdentifier;
-+   __u8  bSignalClass;
-+   __u8  bReserved[6];
-+} CSMI_SAS_IDENTIFY,
-+  *PCSMI_SAS_IDENTIFY;
-+
-+typedef struct _CSMI_SAS_PHY_ENTITY {
-+   CSMI_SAS_IDENTIFY Identify;
-+   __u8  bPortIdentifier;
-+   __u8  bNegotiatedLinkRate;
-+   __u8  bMinimumLinkRate;
-+   __u8  bMaximumLinkRate;
-+   __u8  bPhyChangeCount;
-+   __u8  bAutoDiscover;
-+   __u8  bPhyFeatures;
-+   __u8  bReserved;
-+   CSMI_SAS_IDENTIFY Attached;
-+} CSMI_SAS_PHY_ENTITY,
-+  *PCSMI_SAS_PHY_ENTITY;
-+
-+typedef struct _CSMI_SAS_PHY_INFO {
-+   __u8  bNumberOfPhys;
-+   __u8  bReserved[3];
-+   CSMI_SAS_PHY_ENTITY Phy[32];
-+} CSMI_SAS_PHY_INFO,
-+  *PCSMI_SAS_PHY_INFO;
-+
-+typedef struct _CSMI_SAS_PHY_INFO_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_PHY_INFO Information;
-+} CSMI_SAS_PHY_INFO_BUFFER,
-+  *PCSMI_SAS_PHY_INFO_BUFFER;
-+
-+// CC_CSMI_SAS_SET_PHY_INFO
-+
-+typedef struct _CSMI_SAS_SET_PHY_INFO {
-+   __u8  bPhyIdentifier;
-+   __u8  bNegotiatedLinkRate;
-+   __u8  bProgrammedMinimumLinkRate;
-+   __u8  bProgrammedMaximumLinkRate;
-+   __u8  bSignalClass;
-+   __u8  bReserved[3];
-+} CSMI_SAS_SET_PHY_INFO,
-+  *PCSMI_SAS_SET_PHY_INFO;
-+
-+typedef struct _CSMI_SAS_SET_PHY_INFO_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_SET_PHY_INFO Information;
-+} CSMI_SAS_SET_PHY_INFO_BUFFER,
-+  *PCSMI_SAS_SET_PHY_INFO_BUFFER;
-+
-+// CC_CSMI_SAS_GET_LINK_ERRORS
-+
-+typedef struct _CSMI_SAS_LINK_ERRORS {
-+   __u8  bPhyIdentifier;
-+   __u8  bResetCounts;
-+   __u8  bReserved[2];
-+   __u32 uInvalidDwordCount;
-+   __u32 uRunningDisparityErrorCount;
-+   __u32 uLossOfDwordSyncCount;
-+   __u32 uPhyResetProblemCount;
-+} CSMI_SAS_LINK_ERRORS,
-+  *PCSMI_SAS_LINK_ERRORS;
-+
-+typedef struct _CSMI_SAS_LINK_ERRORS_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_LINK_ERRORS Information;
-+} CSMI_SAS_LINK_ERRORS_BUFFER,
-+  *PCSMI_SAS_LINK_ERRORS_BUFFER;
-+
-+// CC_CSMI_SAS_SMP_PASSTHRU
-+
-+typedef struct _CSMI_SAS_SMP_REQUEST {
-+   __u8  bFrameType;
-+   __u8  bFunction;
-+   __u8  bReserved[2];
-+   __u8  bAdditionalRequestBytes[1016];
-+} CSMI_SAS_SMP_REQUEST,
-+  *PCSMI_SAS_SMP_REQUEST;
-+
-+typedef struct _CSMI_SAS_SMP_RESPONSE {
-+   __u8  bFrameType;
-+   __u8  bFunction;
-+   __u8  bFunctionResult;
-+   __u8  bReserved;
-+   __u8  bAdditionalResponseBytes[1016];
-+} CSMI_SAS_SMP_RESPONSE,
-+  *PCSMI_SAS_SMP_RESPONSE;
-+
-+typedef struct _CSMI_SAS_SMP_PASSTHRU {
-+   __u8  bPhyIdentifier;
-+   __u8  bPortIdentifier;
-+   __u8  bConnectionRate;
-+   __u8  bReserved;
-+   __u8  bDestinationSASAddress[8];
-+   __u32 uRequestLength;
-+   CSMI_SAS_SMP_REQUEST Request;
-+   __u8  bConnectionStatus;
-+   __u8  bReserved2[3];
-+   __u32 uResponseBytes;
-+   CSMI_SAS_SMP_RESPONSE Response;
-+} CSMI_SAS_SMP_PASSTHRU,
-+  *PCSMI_SAS_SMP_PASSTHRU;
-+
-+typedef struct _CSMI_SAS_SMP_PASSTHRU_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_SMP_PASSTHRU Parameters;
-+} CSMI_SAS_SMP_PASSTHRU_BUFFER,
-+  *PCSMI_SAS_SMP_PASSTHRU_BUFFER;
-+
-+// CC_CSMI_SAS_SSP_PASSTHRU
-+
-+typedef struct _CSMI_SAS_SSP_PASSTHRU {
-+   __u8  bPhyIdentifier;
-+   __u8  bPortIdentifier;
-+   __u8  bConnectionRate;
-+   __u8  bReserved;
-+   __u8  bDestinationSASAddress[8];
-+   __u8  bLun[8];
-+   __u8  bCDBLength;
-+   __u8  bAdditionalCDBLength;
-+   __u8  bReserved2[2];
-+   __u8  bCDB[16];
-+   __u32 uFlags;
-+   __u8  bAdditionalCDB[24];
-+   __u32 uDataLength;
-+} CSMI_SAS_SSP_PASSTHRU,
-+  *PCSMI_SAS_SSP_PASSTHRU;
-+
-+typedef struct _CSMI_SAS_SSP_PASSTHRU_STATUS {
-+   __u8  bConnectionStatus;
-+   __u8  bSSPStatus;
-+   __u8  bReserved[2];
-+   __u8  bDataPresent;
-+   __u8  bStatus;
-+   __u8  bResponseLength[2];
-+   __u8  bResponse[256];
-+   __u32 uDataBytes;
-+} CSMI_SAS_SSP_PASSTHRU_STATUS,
-+  *PCSMI_SAS_SSP_PASSTHRU_STATUS;
-+
-+typedef struct _CSMI_SAS_SSP_PASSTHRU_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_SSP_PASSTHRU Parameters;
-+   CSMI_SAS_SSP_PASSTHRU_STATUS Status;
-+   __u8  bDataBuffer[1];
-+} CSMI_SAS_SSP_PASSTHRU_BUFFER,
-+  *PCSMI_SAS_SSP_PASSTHRU_BUFFER;
-+
-+// CC_CSMI_SAS_STP_PASSTHRU
-+
-+typedef struct _CSMI_SAS_STP_PASSTHRU {
-+   __u8  bPhyIdentifier;
-+   __u8  bPortIdentifier;
-+   __u8  bConnectionRate;
-+   __u8  bReserved;
-+   __u8  bDestinationSASAddress[8];
-+   __u8  bReserved2[4];
-+   __u8  bCommandFIS[20];
-+   __u32 uFlags;
-+   __u32 uDataLength;
-+} CSMI_SAS_STP_PASSTHRU,
-+  *PCSMI_SAS_STP_PASSTHRU;
-+
-+typedef struct _CSMI_SAS_STP_PASSTHRU_STATUS {
-+   __u8  bConnectionStatus;
-+   __u8  bReserved[3];
-+   __u8  bStatusFIS[20];
-+   __u32 uSCR[16];
-+   __u32 uDataBytes;
-+} CSMI_SAS_STP_PASSTHRU_STATUS,
-+  *PCSMI_SAS_STP_PASSTHRU_STATUS;
-+
-+typedef struct _CSMI_SAS_STP_PASSTHRU_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_STP_PASSTHRU Parameters;
-+   CSMI_SAS_STP_PASSTHRU_STATUS Status;
-+   __u8  bDataBuffer[1];
-+} CSMI_SAS_STP_PASSTHRU_BUFFER,
-+  *PCSMI_SAS_STP_PASSTHRU_BUFFER;
-+
-+// CC_CSMI_SAS_GET_SATA_SIGNATURE
-+
-+typedef struct _CSMI_SAS_SATA_SIGNATURE {
-+   __u8  bPhyIdentifier;
-+   __u8  bReserved[3];
-+   __u8  bSignatureFIS[20];
-+} CSMI_SAS_SATA_SIGNATURE,
-+  *PCSMI_SAS_SATA_SIGNATURE;
-+
-+typedef struct _CSMI_SAS_SATA_SIGNATURE_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_SATA_SIGNATURE Signature;
-+} CSMI_SAS_SATA_SIGNATURE_BUFFER,
-+  *PCSMI_SAS_SATA_SIGNATURE_BUFFER;
-+
-+// CC_CSMI_SAS_GET_SCSI_ADDRESS
-+
-+typedef struct _CSMI_SAS_GET_SCSI_ADDRESS_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   __u8  bSASAddress[8];
-+   __u8  bSASLun[8];
-+   __u8  bHostIndex;
-+   __u8  bPathId;
-+   __u8  bTargetId;
-+   __u8  bLun;
-+} CSMI_SAS_GET_SCSI_ADDRESS_BUFFER,
-+   *PCSMI_SAS_GET_SCSI_ADDRESS_BUFFER;
-+
-+// CC_CSMI_SAS_GET_DEVICE_ADDRESS
-+
-+typedef struct _CSMI_SAS_GET_DEVICE_ADDRESS_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   __u8  bHostIndex;
-+   __u8  bPathId;
-+   __u8  bTargetId;
-+   __u8  bLun;
-+   __u8  bSASAddress[8];
-+   __u8  bSASLun[8];
-+} CSMI_SAS_GET_DEVICE_ADDRESS_BUFFER,
-+  *PCSMI_SAS_GET_DEVICE_ADDRESS_BUFFER;
-+
-+// CC_CSMI_SAS_TASK_MANAGEMENT
-+
-+typedef struct _CSMI_SAS_SSP_TASK_IU {
-+   __u8  bHostIndex;
-+   __u8  bPathId;
-+   __u8  bTargetId;
-+   __u8  bLun;
-+   __u32 uFlags;
-+   __u32 uQueueTag;
-+   __u32 uReserved;
-+   __u8  bTaskManagementFunction;
-+   __u8  bReserved[7];
-+   __u32 uInformation;
-+} CSMI_SAS_SSP_TASK_IU,
-+  *PCSMI_SAS_SSP_TASK_IU;
-+
-+typedef struct _CSMI_SAS_SSP_TASK_IU_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_SSP_TASK_IU Parameters;
-+   CSMI_SAS_SSP_PASSTHRU_STATUS Status;
-+} CSMI_SAS_SSP_TASK_IU_BUFFER,
-+  *PCSMI_SAS_SSP_TASK_IU_BUFFER;
-+
-+// CC_CSMI_SAS_GET_CONNECTOR_INFO
-+
-+typedef struct _CSMI_SAS_GET_CONNECTOR_INFO {
-+   __u32 uPinout;
-+   __u8  bConnector[16];
-+   __u8  bLocation;
-+   __u8  bReserved[15];
-+} CSMI_SAS_CONNECTOR_INFO,
-+  *PCSMI_SAS_CONNECTOR_INFO;
-+
-+typedef struct _CSMI_SAS_CONNECTOR_INFO_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   CSMI_SAS_CONNECTOR_INFO Reference[32];
-+} CSMI_SAS_CONNECTOR_INFO_BUFFER,
-+  *PCSMI_SAS_CONNECTOR_INFO_BUFFER;
-+
-+// CC_CSMI_SAS_GET_LOCATION
-+
-+typedef struct _CSMI_SAS_LOCATION_IDENTIFIER {
-+   __u32 bLocationFlags;
-+   __u8  bSASAddress[8];
-+   __u8  bSASLun[8];
-+   __u8  bEnclosureIdentifier[8];
-+   __u8  bEnclosureName[32];
-+   __u8  bBayPrefix[32];
-+   __u8  bBayIdentifier;
-+   __u8  bLocationState;
-+   __u8  bReserved[2];
-+} CSMI_SAS_LOCATION_IDENTIFIER,
-+  *PCSMI_SAS_LOCATION_IDENTIFIER;
-+
-+typedef struct _CSMI_SAS_GET_LOCATION_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   __u8  bHostIndex;
-+   __u8  bPathId;
-+   __u8  bTargetId;
-+   __u8  bLun;
-+   __u8  bIdentify;
-+   __u8  bNumberOfLocationIdentifiers;
-+   __u8  bLengthOfLocationIdentifier;
-+   CSMI_SAS_LOCATION_IDENTIFIER Location[1];
-+} CSMI_SAS_GET_LOCATION_BUFFER,
-+  *PCSMI_SAS_GET_LOCATION_BUFFER;
-+
-+// CC_CSMI_SAS_PHY_CONTROL
-+
-+typedef struct _CSMI_SAS_CHARACTER {
-+   __u8  bTypeFlags;
-+   __u8  bValue;
-+} CSMI_SAS_CHARACTER,
-+  *PCSMI_SAS_CHARACTER;
-+
-+typedef struct _CSMI_SAS_PHY_CONTROL {
-+   __u8  bType;
-+   __u8  bRate;
-+   __u8  bReserved[6];
-+   __u32 uVendorUnique[8];
-+   __u32 uTransmitterFlags;
-+   __i8  bTransmitAmplitude;
-+   __i8  bTransmitterPreemphasis;
-+   __i8  bTransmitterSlewRate;
-+   __i8  bTransmitterReserved[13];
-+   __u8  bTransmitterVendorUnique[64];
-+   __u32 uReceiverFlags;
-+   __i8  bReceiverThreshold;
-+   __i8  bReceiverEqualizationGain;
-+   __i8  bReceiverReserved[14];
-+   __u8  bReceiverVendorUnique[64];
-+   __u32 uPatternFlags;
-+   __u8  bFixedPattern;
-+   __u8  bUserPatternLength;
-+   __u8  bPatternReserved[6];
-+   CSMI_SAS_CHARACTER UserPatternBuffer[16];
-+} CSMI_SAS_PHY_CONTROL,
-+  *PCSMI_SAS_PHY_CONTROL;
-+
-+typedef struct _CSMI_SAS_PHY_CONTROL_BUFFER {
-+   IOCTL_HEADER IoctlHeader;
-+   __u32 uFunction;
-+   __u8  bPhyIdentifier;
-+   __u16 usLengthOfControl;
-+   __u8  bNumberOfControls;
-+   __u8  bReserved[4];
-+   __u32 uLinkFlags;
-+   __u8  bSpinupRate;
-+   __u8  bLinkReserved[7];
-+   __u32 uVendorUnique[8];
-+   CSMI_SAS_PHY_CONTROL Control[1];
-+} CSMI_SAS_PHY_CONTROL_BUFFER,
-+  *PCSMI_SAS_PHY_CONTROL_BUFFER;
-+
-+//EDM #pragma CSMI_SAS_END_PACK
-+#pragma pack()
-+
-+#endif // _CSMI_SAS_H_
---- a/drivers/message/fusion/Kconfig
-+++ b/drivers/message/fusion/Kconfig
-@@ -61,13 +61,25 @@ config FUSION_SAS
-         LSISAS1078
- config FUSION_MAX_SGE
--      int "Maximum number of scatter gather entries (16 - 128)"
-+      int "Maximum number of scatter gather entries for SAS and SPI (16 - 128)"
-       default "128"
-       range 16 128
-       help
-         This option allows you to specify the maximum number of scatter-
-         gather entries per I/O. The driver default is 128, which matches
--        SCSI_MAX_PHYS_SEGMENTS. However, it may decreased down to 16.
-+        SAFE_PHYS_SEGMENTS.  However, it may decreased down to 16.
-+        Decreasing this parameter will reduce memory requirements
-+        on a per controller instance.
-+
-+config FUSION_MAX_FC_SGE
-+      int "Maximum number of scatter gather entries for FC (16 - 256)"
-+      depends on FUSION_FC
-+      default "256"
-+      range 16 256
-+      help
-+        This option allows you to specify the maximum number of scatter-
-+        gather entries per I/O. The driver default is 256, which matches
-+        MAX_PHYS_SEGMENTS.  However, it may decreased down to 16.
-         Decreasing this parameter will reduce memory requirements
-         on a per controller instance.
---- a/drivers/message/fusion/Makefile
-+++ b/drivers/message/fusion/Makefile
-@@ -1,12 +1,17 @@
--# Fusion MPT drivers; recognized debug defines...
-+#
-+# LSI mpt fusion
-+#
-+
-+# csmi ioctls enable
-+EXTRA_CFLAGS += -DCPQ_CIM
-+EXTRA_CFLAGS += -DDIAG_BUFFER_SUPPORT
-+
-+EXTRA_CFLAGS += -DCONFIG_FUSION_LOGGING
- # enable verbose logging
- # CONFIG_FUSION_LOGGING needs to be enabled in Kconfig
- #EXTRA_CFLAGS += -DMPT_DEBUG_VERBOSE
--
--#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-} LSI_LOGIC
--
- obj-$(CONFIG_FUSION_SPI)      += mptbase.o mptscsih.o mptspi.o
- obj-$(CONFIG_FUSION_FC)               += mptbase.o mptscsih.o mptfc.o
- obj-$(CONFIG_FUSION_SAS)      += mptbase.o mptscsih.o mptsas.o
---- a/drivers/message/fusion/mptbase.c
-+++ b/drivers/message/fusion/mptbase.c
-@@ -58,6 +58,7 @@
- #include <linux/delay.h>
- #include <linux/interrupt.h>          /* needed for in_interrupt() proto */
- #include <linux/dma-mapping.h>
-+#include <linux/sort.h>
- #include <asm/io.h>
- #ifdef CONFIG_MTRR
- #include <asm/mtrr.h>
-@@ -79,12 +80,13 @@ MODULE_VERSION(my_VERSION);
- module_param(mpt_channel_mapping, int, 0);
- MODULE_PARM_DESC(mpt_channel_mapping, " Mapping id's to channels (default=0)");
--static int mpt_debug_level;
-+int mpt_debug_level;
- static int mpt_set_debug_level(const char *val, struct kernel_param *kp);
- module_param_call(mpt_debug_level, mpt_set_debug_level, param_get_int,
-                 &mpt_debug_level, 0600);
- MODULE_PARM_DESC(mpt_debug_level, " debug level - refer to mptdebug.h \
-       - (default=0)");
-+EXPORT_SYMBOL(mpt_debug_level);
- int mpt_fwfault_debug;
- EXPORT_SYMBOL(mpt_fwfault_debug);
-@@ -102,8 +122,7 @@ static int mfcounter = 0;
- /*
-  *  Public data...
-  */
--
--static struct proc_dir_entry *mpt_proc_root_dir;
-+struct proc_dir_entry *mpt_proc_root_dir;
- #define WHOINIT_UNKNOWN               0xAA
-@@ -125,6 +144,8 @@ static struct mpt_pci_driver       *MptDevice
- static DECLARE_WAIT_QUEUE_HEAD(mpt_waitq);
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+
- /*
-  *  Driver Callback Index's
-  */
-@@ -135,8 +156,7 @@ static u8 last_drv_idx;
- /*
-  *  Forward protos...
-  */
--static irqreturn_t mpt_interrupt(int irq, void *bus_id);
--static int    mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
-+static int    mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
- static int    mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
-                       u32 *req, int replyBytes, u16 *u16reply, int maxwait,
-                       int sleepFlag);
-@@ -167,9 +187,8 @@ static int mpt_GetScsiPortSettings(MPT_A
- static int    mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
- static void   mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
- static void   mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
--static void   mpt_timer_expired(unsigned long data);
- static void   mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc);
--static int    SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch);
-+static int    SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch, int sleepFlag);
- static int    SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
- static int    mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag);
- static int    mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
-@@ -184,7 +203,6 @@ static int procmpt_iocinfo_read(char *bu
- #endif
- static void   mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
--//int         mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
- static int    ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
- static void   mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
- static void   mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
-@@ -193,6 +211,7 @@ static void        mpt_sas_log_info(MPT_ADAPTER
- static int    mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
- static void   mpt_inactive_raid_list_free(MPT_ADAPTER *ioc);
-+
- /* module entry point */
- static int  __init    fusion_init  (void);
- static void __exit    fusion_exit  (void);
-@@ -223,7 +242,16 @@ pci_enable_io_access(struct pci_dev *pde
-       pci_write_config_word(pdev, PCI_COMMAND, command_reg);
- }
--static int mpt_set_debug_level(const char *val, struct kernel_param *kp)
-+/**
-+ *    mpt_set_debug_level - global setting of the mpt_debug_level
-+ *    found via /sys/module/mptbase/parameters/mpt_debug_level
-+ *    @val:
-+ *    @kp:
-+ *
-+ *    Returns
-+ **/
-+static int
-+mpt_set_debug_level(const char *val, struct kernel_param *kp)
- {
-       int ret = param_set_int(val, kp);
-       MPT_ADAPTER *ioc;
-@@ -254,6 +282,56 @@ mpt_get_cb_idx(MPT_DRIVER_CLASS dclass)
- }
- /**
-+ * mpt_is_discovery_complete - determine if discovery has completed
-+ * @ioc: per adatper instance
-+ *
-+ * Returns 1 when discovery completed, else zero.
-+ */
-+static int
-+mpt_is_discovery_complete(MPT_ADAPTER *ioc)
-+{
-+      ConfigExtendedPageHeader_t hdr;
-+      CONFIGPARMS cfg;
-+      SasIOUnitPage0_t *buffer;
-+      dma_addr_t dma_handle;
-+      int rc = 0;
-+
-+      memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
-+      memset(&cfg, 0, sizeof(CONFIGPARMS));
-+      hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+
-+      if ((mpt_config(ioc, &cfg)))
-+              goto out;
-+      if (!hdr.ExtPageLength)
-+              goto out;
-+
-+      buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-+          &dma_handle);
-+      if (!buffer)
-+              goto out;
-+
-+      cfg.physAddr = dma_handle;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      if ((mpt_config(ioc, &cfg)))
-+              goto out_free_consistent;
-+
-+      if (!(buffer->PhyData[0].PortFlags &
-+          MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS))
-+              rc = 1;
-+
-+ out_free_consistent:
-+      pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-+          buffer, dma_handle);
-+ out:
-+      return rc;
-+}
-+
-+/**
-  *    mpt_fault_reset_work - work performed on workq after ioc fault
-  *    @work: input argument, used to derive ioc
-  *
-@@ -267,23 +345,29 @@ mpt_fault_reset_work(struct work_struct 
-       int              rc;
-       unsigned long    flags;
--      if (ioc->diagPending || !ioc->active)
-+      if (ioc->ioc_reset_in_progress || !ioc->active)
-               goto out;
-       ioc_raw_state = mpt_GetIocState(ioc, 0);
-       if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
-               printk(MYIOC_s_WARN_FMT "IOC is in FAULT state (%04xh)!!!\n",
--                     ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
-+                  ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
-               printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
--                     ioc->name, __func__);
-+                  ioc->name, __FUNCTION__);
-               rc = mpt_HardResetHandler(ioc, CAN_SLEEP);
-               printk(MYIOC_s_WARN_FMT "%s: HardReset: %s\n", ioc->name,
--                     __func__, (rc == 0) ? "success" : "failed");
-+                  __FUNCTION__, (rc == 0) ? "success" : "failed");
-               ioc_raw_state = mpt_GetIocState(ioc, 0);
-               if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT)
-                       printk(MYIOC_s_WARN_FMT "IOC is in FAULT state after "
-                           "reset (%04xh)\n", ioc->name, ioc_raw_state &
-                           MPI_DOORBELL_DATA_MASK);
-+      } else if (ioc->bus_type == SAS && ioc->sas_discovery_quiesce_io) {
-+              if ((mpt_is_discovery_complete(ioc))) {
-+                      devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "clearing "
-+                          "discovery_quiesce_io flag\n", ioc->name));
-+                      ioc->sas_discovery_quiesce_io = 0;
-+              }
-       }
-  out:
-@@ -294,14 +378,13 @@ mpt_fault_reset_work(struct work_struct 
-               ioc = ioc->alt_ioc;
-       /* rearm the timer */
--      spin_lock_irqsave(&ioc->fault_reset_work_lock, flags);
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-       if (ioc->reset_work_q)
-               queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
-                       msecs_to_jiffies(MPT_POLLING_INTERVAL));
--      spin_unlock_irqrestore(&ioc->fault_reset_work_lock, flags);
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
- }
--
- /*
-  *  Process turbo (context) reply...
-  */
-@@ -354,9 +437,9 @@ mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa
-       /*  Check for (valid) IO callback!  */
-       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
--              MptCallbacks[cb_idx] == NULL) {
-+          MptCallbacks[cb_idx] == NULL) {
-               printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
--                              __func__, ioc->name, cb_idx);
-+                              __FUNCTION__, ioc->name, cb_idx);
-               goto out;
-       }
-@@ -398,6 +481,7 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
-       dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
-                       ioc->name, mr, req_idx, cb_idx, mr->u.hdr.Function));
-+
-       DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mr);
-        /*  Check/log IOC log info
-@@ -413,14 +497,17 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
-                       mpt_sas_log_info(ioc, log_info);
-       }
-+      /* TODO - add shost_attrs, or command line option, and
-+       * extend this to SAS/FC
-+       */
-       if (ioc_stat & MPI_IOCSTATUS_MASK)
-               mpt_iocstatus_info(ioc, (u32)ioc_stat, mf);
-       /*  Check for (valid) IO callback!  */
-       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
--              MptCallbacks[cb_idx] == NULL) {
-+          MptCallbacks[cb_idx] == NULL) {
-               printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
--                              __func__, ioc->name, cb_idx);
-+                              __FUNCTION__, ioc->name, cb_idx);
-               freeme = 0;
-               goto out;
-       }
-@@ -436,11 +523,11 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
-       mb();
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
-  *    @irq: irq number (not used)
-  *    @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
-+ *    @r: pt_regs pointer (not used)
-  *
-  *    This routine is registered via the request_irq() kernel API call,
-  *    and handles all interrupts generated from a specific MPT adapter
-@@ -452,7 +539,7 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
-  *    This routine handles register-level access of the adapter but
-  *    dispatches (calls) a protocol-specific callback routine to handle
-  *    the protocol-specific details of the MPT request completion.
-- */
-+ **/
- static irqreturn_t
- mpt_interrupt(int irq, void *bus_id)
- {
-@@ -478,9 +565,9 @@ mpt_interrupt(int irq, void *bus_id)
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-- *    mpt_base_reply - MPT base driver's callback routine
-+ *    mptbase_reply - MPT base driver's callback routine
-  *    @ioc: Pointer to MPT_ADAPTER structure
-- *    @mf: Pointer to original MPT request frame
-+ *    @req: Pointer to original MPT request frame
-  *    @reply: Pointer to MPT reply frame (NULL if TurboReply)
-  *
-  *    MPT base driver's callback routine; all base driver
-@@ -491,122 +578,49 @@ mpt_interrupt(int irq, void *bus_id)
-  *    should be freed, or 0 if it shouldn't.
-  */
- static int
--mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
-+mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
- {
-+      EventNotificationReply_t *pEventReply;
-+      u8 event;
-+      int evHandlers;
-       int freereq = 1;
--      u8 func;
--
--      dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_base_reply() called\n", ioc->name));
--#ifdef CONFIG_FUSION_LOGGING
--      if ((ioc->debug_level & MPT_DEBUG_MSG_FRAME) &&
--                      !(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
--              dmfprintk(ioc, printk(MYIOC_s_INFO_FMT ": Original request frame (@%p) header\n",
--                  ioc->name, mf));
--              DBG_DUMP_REQUEST_FRAME_HDR(ioc, (u32 *)mf);
--      }
--#endif
--
--      func = reply->u.hdr.Function;
--      dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_base_reply, Function=%02Xh\n",
--                      ioc->name, func));
--
--      if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
--              EventNotificationReply_t *pEvReply = (EventNotificationReply_t *) reply;
--              int evHandlers = 0;
--              int results;
--
--              results = ProcessEventNotification(ioc, pEvReply, &evHandlers);
--              if (results != evHandlers) {
--                      /* CHECKME! Any special handling needed here? */
--                      devtverboseprintk(ioc, printk(MYIOC_s_WARN_FMT "Called %d event handlers, sum results = %d\n",
--                                      ioc->name, evHandlers, results));
--              }
--              /*
--               *      Hmmm...  It seems that EventNotificationReply is an exception
--               *      to the rule of one reply per request.
--               */
--              if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) {
-+      switch (reply->u.hdr.Function) {
-+      case MPI_FUNCTION_EVENT_NOTIFICATION:
-+              pEventReply = (EventNotificationReply_t *)reply;
-+              evHandlers = 0;
-+              ProcessEventNotification(ioc, pEventReply, &evHandlers);
-+              event = le32_to_cpu(pEventReply->Event) & 0xFF;
-+              if (pEventReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)
-                       freereq = 0;
--              } else {
--                      devtverboseprintk(ioc, printk(MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p returns Request frame\n",
--                              ioc->name, pEvReply));
--              }
--
--#ifdef CONFIG_PROC_FS
--//            LogEvent(ioc, pEvReply);
--#endif
--
--      } else if (func == MPI_FUNCTION_EVENT_ACK) {
--              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_base_reply, EventAck reply received\n",
--                              ioc->name));
--      } else if (func == MPI_FUNCTION_CONFIG) {
--              CONFIGPARMS *pCfg;
--              unsigned long flags;
--
--              dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "config_complete (mf=%p,mr=%p)\n",
--                              ioc->name, mf, reply));
--
--              pCfg = * ((CONFIGPARMS **)((u8 *) mf + ioc->req_sz - sizeof(void *)));
--
--              if (pCfg) {
--                      /* disable timer and remove from linked list */
--                      del_timer(&pCfg->timer);
--
--                      spin_lock_irqsave(&ioc->FreeQlock, flags);
--                      list_del(&pCfg->linkage);
--                      spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--
--                      /*
--                       *      If IOC Status is SUCCESS, save the header
--                       *      and set the status code to GOOD.
--                       */
--                      pCfg->status = MPT_CONFIG_ERROR;
--                      if (reply) {
--                              ConfigReply_t   *pReply = (ConfigReply_t *)reply;
--                              u16              status;
--
--                              status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
--                              dcprintk(ioc, printk(MYIOC_s_NOTE_FMT "  IOCStatus=%04xh, IOCLogInfo=%08xh\n",
--                                   ioc->name, status, le32_to_cpu(pReply->IOCLogInfo)));
--
--                              pCfg->status = status;
--                              if (status == MPI_IOCSTATUS_SUCCESS) {
--                                      if ((pReply->Header.PageType &
--                                          MPI_CONFIG_PAGETYPE_MASK) ==
--                                          MPI_CONFIG_PAGETYPE_EXTENDED) {
--                                              pCfg->cfghdr.ehdr->ExtPageLength =
--                                                  le16_to_cpu(pReply->ExtPageLength);
--                                              pCfg->cfghdr.ehdr->ExtPageType =
--                                                  pReply->ExtPageType;
--                                      }
--                                      pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
--
--                                      /* If this is a regular header, save PageLength. */
--                                      /* LMP Do this better so not using a reserved field! */
--                                      pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
--                                      pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
--                                      pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
--                              }
--                      }
--
--                      /*
--                       *      Wake up the original calling thread
--                       */
--                      pCfg->wait_done = 1;
--                      wake_up(&mpt_waitq);
--              }
--      } else if (func == MPI_FUNCTION_SAS_IO_UNIT_CONTROL) {
--              /* we should be always getting a reply frame */
--              memcpy(ioc->persist_reply_frame, reply,
--                  min(MPT_DEFAULT_FRAME_SIZE,
--                  4*reply->u.reply.MsgLength));
--              del_timer(&ioc->persist_timer);
--              ioc->persist_wait_done = 1;
--              wake_up(&mpt_waitq);
--      } else {
--              printk(MYIOC_s_ERR_FMT "Unexpected msg function (=%02Xh) reply received!\n",
--                              ioc->name, func);
-+              if (event != MPI_EVENT_EVENT_CHANGE)
-+                      break;
-+      case MPI_FUNCTION_CONFIG:
-+      case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
-+              ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
-+              if (reply) {
-+                      ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
-+                      memcpy(ioc->mptbase_cmds.reply, reply,
-+                          min(MPT_DEFAULT_FRAME_SIZE,
-+                              4 * reply->u.reply.MsgLength));
-+              }
-+              if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
-+                      ioc->mptbase_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
-+                      complete(&ioc->mptbase_cmds.done);
-+              } else
-+                      freereq = 0;
-+              if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_FREE_MF)
-+                      freereq = 1;
-+              break;
-+      case MPI_FUNCTION_EVENT_ACK:
-+              devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "EventAck reply received\n", ioc->name));
-+              break;
-+      default:
-+              printk(MYIOC_s_ERR_FMT
-+                  "Unexpected msg function (=%02Xh) reply received!\n",
-+                  ioc->name, reply->u.hdr.Function);
-+              break;
-       }
-       /*
-@@ -616,7 +630,6 @@ mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRA
-       return freereq;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_register - Register protocol-specific main callback handler.
-  *    @cbfunc: callback function pointer
-@@ -635,7 +648,7 @@ mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRA
-  *    {N,...,7,6,5,...,1} if successful.
-  *    A return value of MPT_MAX_PROTOCOL_DRIVERS (including zero!) should be
-  *    considered an error by the caller.
-- */
-+ **/
- u8
- mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
- {
-@@ -659,14 +672,13 @@ mpt_register(MPT_CALLBACK cbfunc, MPT_DR
-       return last_drv_idx;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_deregister - Deregister a protocol drivers resources.
-  *    @cb_idx: previously registered callback handle
-  *
-  *    Each protocol-specific driver should call this routine when its
-  *    module is unloaded.
-- */
-+ **/
- void
- mpt_deregister(u8 cb_idx)
- {
-@@ -679,9 +691,9 @@ mpt_deregister(u8 cb_idx)
-       }
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-- *    mpt_event_register - Register protocol-specific event callback handler.
-+ *    mpt_event_register - Register protocol-specific event callback
-+ *    handler.
-  *    @cb_idx: previously registered (via mpt_register) callback handle
-  *    @ev_cbfunc: callback function
-  *
-@@ -689,7 +701,7 @@ mpt_deregister(u8 cb_idx)
-  *    if/when they choose to be notified of MPT events.
-  *
-  *    Returns 0 for success.
-- */
-+ **/
- int
- mpt_event_register(u8 cb_idx, MPT_EVHANDLER ev_cbfunc)
- {
-@@ -700,15 +712,15 @@ mpt_event_register(u8 cb_idx, MPT_EVHAND
-       return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-- *    mpt_event_deregister - Deregister protocol-specific event callback handler
-+ *    mpt_event_deregister - Deregister protocol-specific event callback
-+ *    handler.
-  *    @cb_idx: previously registered callback handle
-  *
-  *    Each protocol-specific driver should call this routine
-  *    when it does not (or can no longer) handle events,
-  *    or when its module is unloaded.
-- */
-+ **/
- void
- mpt_event_deregister(u8 cb_idx)
- {
-@@ -718,7 +730,6 @@ mpt_event_deregister(u8 cb_idx)
-       MptEvHandlers[cb_idx] = NULL;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_reset_register - Register protocol-specific IOC reset handler.
-  *    @cb_idx: previously registered (via mpt_register) callback handle
-@@ -728,7 +739,7 @@ mpt_event_deregister(u8 cb_idx)
-  *    if/when they choose to be notified of IOC resets.
-  *
-  *    Returns 0 for success.
-- */
-+ **/
- int
- mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func)
- {
-@@ -739,7 +750,6 @@ mpt_reset_register(u8 cb_idx, MPT_RESETH
-       return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
-  *    @cb_idx: previously registered callback handle
-@@ -747,7 +757,7 @@ mpt_reset_register(u8 cb_idx, MPT_RESETH
-  *    Each protocol-specific driver should call this routine
-  *    when it does not (or can no longer) handle IOC reset handling,
-  *    or when its module is unloaded.
-- */
-+ **/
- void
- mpt_reset_deregister(u8 cb_idx)
- {
-@@ -757,12 +767,11 @@ mpt_reset_deregister(u8 cb_idx)
-       MptResetHandlers[cb_idx] = NULL;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_device_driver_register - Register device driver hooks
-  *    @dd_cbfunc: driver callbacks struct
-  *    @cb_idx: MPT protocol driver index
-- */
-+ **/
- int
- mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
- {
-@@ -776,20 +785,21 @@ mpt_device_driver_register(struct mpt_pc
-       /* call per pci device probe entry point */
-       list_for_each_entry(ioc, &ioc_list, list) {
-+              if (!pci_get_drvdata(ioc->pcidev))
-+                      continue;
-               id = ioc->pcidev->driver ?
-                   ioc->pcidev->driver->id_table : NULL;
-               if (dd_cbfunc->probe)
-                       dd_cbfunc->probe(ioc->pcidev, id);
--       }
-+      }
-       return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_device_driver_deregister - DeRegister device driver hooks
-  *    @cb_idx: MPT protocol driver index
-- */
-+ **/
- void
- mpt_device_driver_deregister(u8 cb_idx)
- {
-@@ -809,19 +819,15 @@ mpt_device_driver_deregister(u8 cb_idx)
-       MptDeviceDriverHandlers[cb_idx] = NULL;
- }
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-- *    mpt_get_msg_frame - Obtain an MPT request frame from the pool
-+ *    mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
-+ *    allocated per MPT adapter.
-  *    @cb_idx: Handle of registered MPT protocol driver
-  *    @ioc: Pointer to MPT adapter structure
-  *
-- *    Obtain an MPT request frame from the pool (of 1024) that are
-- *    allocated per MPT adapter.
-- *
-  *    Returns pointer to a MPT request frame or %NULL if none are available
-  *    or IOC is not active.
-- */
-+ **/
- MPT_FRAME_HDR*
- mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc)
- {
-@@ -851,7 +857,6 @@ mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER
-               mf->u.frame.linkage.arg1 = 0;
-               mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;  /* byte */
-               req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
--                                                              /* u16! */
-               req_idx = req_offset / ioc->req_sz;
-               mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
-               mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
-@@ -881,16 +886,16 @@ mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER
-       return mf;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-- *    mpt_put_msg_frame - Send a protocol-specific MPT request frame to an IOC
-+ *    mpt_put_msg_frame - Send a protocol specific MPT request frame
-+ *    to a IOC.
-  *    @cb_idx: Handle of registered MPT protocol driver
-  *    @ioc: Pointer to MPT adapter structure
-  *    @mf: Pointer to MPT request frame
-  *
-- *    This routine posts an MPT request frame to the request post FIFO of a
-+ *    This routine posts a MPT request frame to the request post FIFO of a
-  *    specific MPT adapter.
-- */
-+ **/
- void
- mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
- {
-@@ -901,14 +906,14 @@ mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER
-       /* ensure values are reset properly! */
-       mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;          /* byte */
-       req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
--                                                              /* u16! */
-       req_idx = req_offset / ioc->req_sz;
-       mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
-       mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
-       DBG_DUMP_PUT_MSG_FRAME(ioc, (u32 *)mf);
--      mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
-+      mf_dma_addr = (ioc->req_frames_low_dma + req_offset) |
-+          ioc->RequestNB[req_idx];
-       dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d "
-           "RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx,
-           ioc->RequestNB[req_idx]));
-@@ -916,15 +921,13 @@ mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER
- }
- /**
-- *    mpt_put_msg_frame_hi_pri - Send a hi-pri protocol-specific MPT request frame
-+ *    mpt_put_msg_frame_hi_pri - Send a protocol specific MPT request frame
-+ *    to a IOC using hi priority request queue.
-  *    @cb_idx: Handle of registered MPT protocol driver
-  *    @ioc: Pointer to MPT adapter structure
-  *    @mf: Pointer to MPT request frame
-  *
-- *    Send a protocol-specific MPT request frame to an IOC using
-- *    hi-priority request queue.
-- *
-- *    This routine posts an MPT request frame to the request post FIFO of a
-+ *    This routine posts a MPT request frame to the request post FIFO of a
-  *    specific MPT adapter.
-  **/
- void
-@@ -949,7 +952,6 @@ mpt_put_msg_frame_hi_pri(u8 cb_idx, MPT_
-       CHIPREG_WRITE32(&ioc->chip->RequestHiPriFifo, mf_dma_addr);
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_free_msg_frame - Place MPT request frame back on FreeQ.
-  *    @ioc: Pointer to MPT adapter structure
-@@ -958,7 +960,7 @@ mpt_put_msg_frame_hi_pri(u8 cb_idx, MPT_
-  *
-  *    This routine places a MPT request frame back on the MPT adapter's
-  *    FreeQ.
-- */
-+ **/
- void
- mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
- {
-@@ -966,43 +968,144 @@ mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT
-       /*  Put Request back on FreeQ!  */
-       spin_lock_irqsave(&ioc->FreeQlock, flags);
--      mf->u.frame.linkage.arg1 = 0xdeadbeaf; /* signature to know if this mf is freed */
-+      if (cpu_to_le32(mf->u.frame.linkage.arg1) == 0xdeadbeaf)
-+              goto out;
-+      mf->u.frame.linkage.arg1 = cpu_to_le32(0xdeadbeaf); /* signature to know if this mf is freed */
-       list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
- #ifdef MFCNT
-       ioc->mfcnt--;
- #endif
-+ out:
-       spin_unlock_irqrestore(&ioc->FreeQlock, flags);
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-- *    mpt_add_sge - Place a simple SGE at address pAddr.
-+ *    mpt_add_sge - Place a simple 32 bit SGE at address pAddr.
-  *    @pAddr: virtual address for SGE
-  *    @flagslength: SGE flags and data transfer length
-  *    @dma_addr: Physical address
-  *
-  *    This routine places a MPT request frame back on the MPT adapter's
-  *    FreeQ.
-- */
--void
-+ **/
-+static void
- mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
- {
--      if (sizeof(dma_addr_t) == sizeof(u64)) {
--              SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
--              u32 tmp = dma_addr & 0xFFFFFFFF;
-+      SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
-+      pSge->FlagsLength = cpu_to_le32(flagslength);
-+      pSge->Address = cpu_to_le32(dma_addr);
-+}
--              pSge->FlagsLength = cpu_to_le32(flagslength);
--              pSge->Address.Low = cpu_to_le32(tmp);
--              tmp = (u32) ((u64)dma_addr >> 32);
--              pSge->Address.High = cpu_to_le32(tmp);
--      } else {
--              SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
--              pSge->FlagsLength = cpu_to_le32(flagslength);
--              pSge->Address = cpu_to_le32(dma_addr);
-+/**
-+ *    mpt_add_sge_64bit - Place a simple 64 bit SGE at address pAddr.
-+ *    @pAddr: virtual address for SGE
-+ *    @flagslength: SGE flags and data transfer length
-+ *    @dma_addr: Physical address
-+ *
-+ *    This routine places a MPT request frame back on the MPT adapter's
-+ *    FreeQ.
-+ **/
-+static void
-+mpt_add_sge_64bit(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
-+{
-+      SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
-+      u32 tmp;
-+
-+      tmp = dma_addr & 0xFFFFFFFF;
-+      pSge->Address.Low = cpu_to_le32(tmp);
-+      tmp = (u32) ((u64)dma_addr >> 32);
-+      pSge->Address.High = cpu_to_le32(tmp);
-+      pSge->FlagsLength = cpu_to_le32(
-+              (flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
-+}
-+
-+
-+/**
-+ *    mpt_add_sge_64bit_1078 - Place a simple 64 bit SGE at address pAddr
-+ *    (1078 workaround).
-+ *    @pAddr: virtual address for SGE
-+ *    @flagslength: SGE flags and data transfer length
-+ *    @dma_addr: Physical address
-+ *
-+ *    This routine places a MPT request frame back on the MPT adapter's
-+ *    FreeQ.
-+ **/
-+static void
-+mpt_add_sge_64bit_1078(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
-+{
-+      SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
-+      u32 tmp;
-+
-+      tmp = dma_addr & 0xFFFFFFFF;
-+      pSge->Address.Low = cpu_to_le32(tmp);
-+      tmp = (u32) ((u64)dma_addr >> 32);
-+
-+      /*
-+       * 1078 errata workaround for the 36GB limitation
-+       */
-+      if ((((u64)dma_addr + MPI_SGE_LENGTH(flagslength)) >> 32)  == 9) {
-+              flagslength |=
-+                  MPI_SGE_SET_FLAGS(MPI_SGE_FLAGS_LOCAL_ADDRESS);
-+              tmp |= (1<<31);
-+              if (mpt_debug_level & MPT_DEBUG_36GB_MEM)
-+                      printk(KERN_DEBUG "1078 P0M2 addressing for "
-+                          "addr = 0x%llx len = %d\n",
-+                          (unsigned long long)dma_addr,
-+                          MPI_SGE_LENGTH(flagslength));
-       }
-+
-+      pSge->Address.High = cpu_to_le32(tmp);
-+      pSge->FlagsLength = cpu_to_le32(
-+              (flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
-+}
-+
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/**
-+ *    mpt_add_chain - Place a 32 bit chain SGE at address pAddr.
-+ *    @pAddr: virtual address for SGE
-+ *    @next: nextChainOffset value (u32's)
-+ *    @length: length of next SGL segment
-+ *    @dma_addr: Physical address
-+ *
-+ */
-+static void
-+mpt_add_chain(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
-+{
-+              SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
-+              pChain->Length = cpu_to_le16(length);
-+              pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT;
-+              pChain->NextChainOffset = next;
-+              pChain->Address = cpu_to_le32(dma_addr);
-+}
-+
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/**
-+ *    mpt_add_chain_64bit - Place a 64 bit chain SGE at address pAddr.
-+ *    @pAddr: virtual address for SGE
-+ *    @next: nextChainOffset value (u32's)
-+ *    @length: length of next SGL segment
-+ *    @dma_addr: Physical address
-+ *
-+ */
-+static void
-+mpt_add_chain_64bit(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
-+{
-+              SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
-+              u32 tmp = dma_addr & 0xFFFFFFFF;
-+
-+              pChain->Length = cpu_to_le16(length);
-+              pChain->Flags = (MPI_SGE_FLAGS_CHAIN_ELEMENT |
-+                               MPI_SGE_FLAGS_64_BIT_ADDRESSING);
-+
-+              pChain->NextChainOffset = next;
-+
-+              pChain->Address.Low = cpu_to_le32(tmp);
-+              tmp = (u32) ((u64)dma_addr >> 32);
-+              pChain->Address.High = cpu_to_le32(tmp);
- }
-+
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_send_handshake_request - Send MPT request via doorbell handshake method.
-@@ -1019,11 +1122,11 @@ mpt_add_sge(char *pAddr, u32 flagslength
-  *    request which are greater than 1 byte in size.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- int
- mpt_send_handshake_request(u8 cb_idx, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
- {
--      int     r = 0;
-+      int      r = 0;
-       u8      *req_as_bytes;
-       int      ii;
-@@ -1038,7 +1141,7 @@ mpt_send_handshake_request(u8 cb_idx, MP
-        * is in proper (pre-alloc'd) request buffer range...
-        */
-       ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
--      if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
-+      if (ii >= 0 && ii < ioc->req_depth) {
-               MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
-               mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
-               mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;
-@@ -1096,7 +1199,6 @@ mpt_send_handshake_request(u8 cb_idx, MP
-       return r;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  * mpt_host_page_access_control - control the IOC's Host Page Buffer access
-  * @ioc: Pointer to MPT adapter structure
-@@ -1113,8 +1215,7 @@ mpt_send_handshake_request(u8 cb_idx, MP
-  * 3h Free Buffer { MPI_DB_HPBAC_FREE_BUFFER }
-  *
-  * Returns 0 for success, non-zero for failure.
-- */
--
-+ **/
- static int
- mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag)
- {
-@@ -1139,7 +1240,6 @@ mpt_host_page_access_control(MPT_ADAPTER
-               return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_host_page_alloc - allocate system memory for the fw
-  *    @ioc: Pointer to pointer to IOC adapter
-@@ -1147,7 +1247,7 @@ mpt_host_page_access_control(MPT_ADAPTER
-  *
-  *    If we already allocated memory in past, then resend the same pointer.
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int
- mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
- {
-@@ -1171,7 +1271,7 @@ mpt_host_page_alloc(MPT_ADAPTER *ioc, pI
-                           host_page_buffer_sz,
-                           &ioc->HostPageBuffer_dma)) != NULL) {
--                              dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
-                                   "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
-                                   ioc->name, ioc->HostPageBuffer,
-                                   (u32)ioc->HostPageBuffer_dma,
-@@ -1195,21 +1295,16 @@ mpt_host_page_alloc(MPT_ADAPTER *ioc, pI
-       psge = (char *)&ioc_init->HostPageBufferSGE;
-       flags_length = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
-           MPI_SGE_FLAGS_SYSTEM_ADDRESS |
--          MPI_SGE_FLAGS_32_BIT_ADDRESSING |
-           MPI_SGE_FLAGS_HOST_TO_IOC |
-           MPI_SGE_FLAGS_END_OF_BUFFER;
--      if (sizeof(dma_addr_t) == sizeof(u64)) {
--          flags_length |= MPI_SGE_FLAGS_64_BIT_ADDRESSING;
--      }
-       flags_length = flags_length << MPI_SGE_FLAGS_SHIFT;
-       flags_length |= ioc->HostPageBuffer_sz;
--      mpt_add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
-+      ioc->add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
-       ioc->facts.HostPageBufferSGE = ioc_init->HostPageBufferSGE;
- return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_verify_adapter - Given IOC identifier, set pointer to its adapter structure.
-  *    @iocid: IOC unique identifier (integer)
-@@ -1220,7 +1315,7 @@ return 0;
-  *
-  *    Returns iocid and sets iocpp if iocid is found.
-  *    Returns -1 if iocid is not found.
-- */
-+ **/
- int
- mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
- {
-@@ -1493,7 +1588,6 @@ mpt_mapresources(MPT_ADAPTER *ioc)
-       unsigned long    port;
-       u32              msize;
-       u32              psize;
--      u8               revision;
-       int              r = -ENODEV;
-       struct pci_dev *pdev;
-@@ -1509,24 +1603,39 @@ mpt_mapresources(MPT_ADAPTER *ioc)
-                   "MEM failed\n", ioc->name);
-               return r;
-       }
-+      if (sizeof(dma_addr_t) > 4) {
-+              const uint64_t required_mask = dma_get_required_mask(&pdev->dev);
-+              if (required_mask > DMA_32BIT_MASK
-+                  && !pci_set_dma_mask(pdev, DMA_64BIT_MASK)
-+                  && !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
-+                      ioc->dma_mask = DMA_64BIT_MASK;
-+                      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
-+                          ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
-+                          ioc->name));
-+              } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)
-+                  && !pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)) {
-+                      ioc->dma_mask = DMA_32BIT_MASK;
-+                      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
-+                          ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
-+                          ioc->name));
-+              } else {
-+                      printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
-+                          ioc->name, pci_name(pdev));
-+                      return r;
-+              }
--      pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
--
--      if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)
--          && !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
--              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
--                  ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
--                  ioc->name));
--      } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)
--          && !pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)) {
--              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
--                  ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
--                  ioc->name));
-       } else {
--              printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
--                  ioc->name, pci_name(pdev));
--              pci_release_selected_regions(pdev, ioc->bars);
--              return r;
-+              if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)
-+                  && !pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)) {
-+                      ioc->dma_mask = DMA_32BIT_MASK;
-+                      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
-+                          ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
-+                          ioc->name));
-+              } else {
-+                      printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
-+                          ioc->name, pci_name(pdev));
-+                      return r;
-+              }
-       }
-       mem_phys = msize = 0;
-@@ -1554,7 +1663,7 @@ mpt_mapresources(MPT_ADAPTER *ioc)
-       mem = ioremap(mem_phys, msize);
-       if (mem == NULL) {
-               printk(MYIOC_s_ERR_FMT ": ERROR - Unable to map adapter"
--                      " memory!\n", ioc->name);
-+                     "memory!\n", ioc->name);
-               return -EINVAL;
-       }
-       ioc->memmap = mem;
-@@ -1565,13 +1674,15 @@ mpt_mapresources(MPT_ADAPTER *ioc)
-       ioc->chip = (SYSIF_REGS __iomem *)mem;
-       /* Save Port IO values in case we need to do downloadboot */
--      ioc->pio_mem_phys = port;
--      ioc->pio_chip = (SYSIF_REGS __iomem *)port;
-+      {
-+              u8 *pmem = (u8*)port;
-+              ioc->pio_mem_phys = port;
-+              ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
-+      }
-       return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_attach - Install a PCI intelligent MPT adapter.
-  *    @pdev: Pointer to pci_dev structure
-@@ -1588,7 +1699,7 @@ mpt_mapresources(MPT_ADAPTER *ioc)
-  *    Returns 0 for success, non-zero for failure.
-  *
-  *    TODO: Add support for polled controllers
-- */
-+ **/
- int
- mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
- {
-@@ -1610,6 +1721,7 @@ mpt_attach(struct pci_dev *pdev, const s
-       ioc->id = mpt_ids++;
-       sprintf(ioc->name, "ioc%d", ioc->id);
-+      dinitprintk(ioc, printk(KERN_WARNING MYNAM ": mpt_adapter_install\n"));
-       /*
-        * set initial debug level
-@@ -1620,7 +1732,6 @@ mpt_attach(struct pci_dev *pdev, const s
-       if (mpt_debug_level)
-               printk(KERN_INFO "mpt_debug_level=%xh\n", mpt_debug_level);
--      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": mpt_adapter_install\n", ioc->name));
-       ioc->pcidev = pdev;
-       if (mpt_mapresources(ioc)) {
-@@ -1628,14 +1739,34 @@ mpt_attach(struct pci_dev *pdev, const s
-               return r;
-       }
-+      /*
-+       * Setting up proper handlers for scatter gather handling
-+       */
-+      if (ioc->dma_mask == DMA_64BIT_MASK) {
-+              if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078)
-+                      ioc->add_sge = &mpt_add_sge_64bit_1078;
-+              else
-+                      ioc->add_sge = &mpt_add_sge_64bit;
-+              ioc->add_chain = &mpt_add_chain_64bit;
-+              ioc->sg_addr_size = 8;
-+      } else {
-+              ioc->add_sge = &mpt_add_sge;
-+              ioc->add_chain = &mpt_add_chain;
-+              ioc->sg_addr_size = 4;
-+      }
-+      ioc->SGE_size = sizeof(u32) + ioc->sg_addr_size;
-+
-       ioc->alloc_total = sizeof(MPT_ADAPTER);
-       ioc->req_sz = MPT_DEFAULT_FRAME_SIZE;           /* avoid div by zero! */
-       ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
--      ioc->pcidev = pdev;
--      ioc->diagPending = 0;
--      spin_lock_init(&ioc->diagLock);
--      spin_lock_init(&ioc->initializing_hba_lock);
-+      spin_lock_init(&ioc->taskmgmt_lock);
-+      mutex_init(&ioc->internal_cmds.mutex);
-+      init_completion(&ioc->internal_cmds.done);
-+      mutex_init(&ioc->mptbase_cmds.mutex);
-+      init_completion(&ioc->mptbase_cmds.done);
-+      mutex_init(&ioc->taskmgmt_cmds.mutex);
-+      init_completion(&ioc->taskmgmt_cmds.done);
-       /* Initialize the event logging.
-        */
-@@ -1648,16 +1779,13 @@ mpt_attach(struct pci_dev *pdev, const s
-       ioc->mfcnt = 0;
- #endif
-+      ioc->sh = NULL;
-       ioc->cached_fw = NULL;
-       /* Initilize SCSI Config Data structure
-        */
-       memset(&ioc->spi_data, 0, sizeof(SpiCfgData));
--      /* Initialize the running configQ head.
--       */
--      INIT_LIST_HEAD(&ioc->configQ);
--
-       /* Initialize the fc rport list head.
-        */
-       INIT_LIST_HEAD(&ioc->fc_rports);
-@@ -1665,11 +1793,10 @@ mpt_attach(struct pci_dev *pdev, const s
-       /* Find lookup slot. */
-       INIT_LIST_HEAD(&ioc->list);
--
--      /* Initialize workqueue */
-+      /* Initialize work */
-       INIT_DELAYED_WORK(&ioc->fault_reset_work, mpt_fault_reset_work);
--      spin_lock_init(&ioc->fault_reset_work_lock);
-+      /* Initialize workqueue */
-       snprintf(ioc->reset_work_q_name, sizeof(ioc->reset_work_q_name),
-                "mpt_poll_%d", ioc->id);
-       ioc->reset_work_q =
-@@ -1682,8 +1809,8 @@ mpt_attach(struct pci_dev *pdev, const s
-               return -ENOMEM;
-       }
--      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "facts @ %p, pfacts[0] @ %p\n",
--          ioc->name, &ioc->facts, &ioc->pfacts[0]));
-+      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "facts @ %p, pfacts[0] @ %p\n",
-+              ioc->name, &ioc->facts, &ioc->pfacts[0]));
-       pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
-       mpt_get_product_name(pdev->vendor, pdev->device, revision, ioc->prod_name);
-@@ -1703,14 +1830,14 @@ mpt_attach(struct pci_dev *pdev, const s
-       case MPI_MANUFACTPAGE_DEVICEID_FC929X:
-               if (revision < XL_929) {
-                       /* 929X Chip Fix. Set Split transactions level
--                      * for PCIX. Set MOST bits to zero.
--                      */
-+                      * for PCIX. Set MOST bits to zero.
-+                      */
-                       pci_read_config_byte(pdev, 0x6a, &pcixcmd);
-                       pcixcmd &= 0x8F;
-                       pci_write_config_byte(pdev, 0x6a, pcixcmd);
-               } else {
-                       /* 929XL Chip Fix. Set MMRBC to 0x08.
--                      */
-+                      */
-                       pci_read_config_byte(pdev, 0x6a, &pcixcmd);
-                       pcixcmd |= 0x08;
-                       pci_write_config_byte(pdev, 0x6a, pcixcmd);
-@@ -1728,6 +1855,7 @@ mpt_attach(struct pci_dev *pdev, const s
-               ioc->bus_type = FC;
-               break;
-+
-       case MPI_MANUFACTPAGE_DEVID_53C1030:
-               /* 1030 Chip Fix. Disable Split transactions
-                * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
-@@ -1745,11 +1873,14 @@ mpt_attach(struct pci_dev *pdev, const s
-       case MPI_MANUFACTPAGE_DEVID_SAS1064:
-       case MPI_MANUFACTPAGE_DEVID_SAS1068:
-               ioc->errata_flag_1064 = 1;
-+              ioc->bus_type = SAS;
-+              break;
-       case MPI_MANUFACTPAGE_DEVID_SAS1064E:
-       case MPI_MANUFACTPAGE_DEVID_SAS1068E:
-       case MPI_MANUFACTPAGE_DEVID_SAS1078:
-               ioc->bus_type = SAS;
-+              break;
-       }
-
-@@ -1772,9 +1911,6 @@ mpt_attach(struct pci_dev *pdev, const s
-       ioc->active = 0;
-       CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
--      /* Set IOC ptr in the pcidev's driver data. */
--      pci_set_drvdata(ioc->pcidev, ioc);
--
-       /* Set lookup ptr. */
-       list_add_tail(&ioc->list, &ioc_list);
-@@ -1782,10 +1918,17 @@ mpt_attach(struct pci_dev *pdev, const s
-        */
-       mpt_detect_bound_ports(ioc, pdev);
-+
-+      INIT_LIST_HEAD(&ioc->fw_event_list);
-+      spin_lock_init(&ioc->fw_event_lock);
-+      snprintf(ioc->fw_event_q_name, sizeof(ioc->fw_event_q_name),
-+               "mpt/%d", ioc->id);
-+      ioc->fw_event_q = create_singlethread_workqueue(ioc->fw_event_q_name);
-+
-       if ((r = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
-           CAN_SLEEP)) != 0){
-               printk(MYIOC_s_ERR_FMT "didn't initialize properly! (%d)\n",
--                  ioc->name, r);
-+                     ioc->name, r);
-               list_del(&ioc->list);
-               if (ioc->alt_ioc)
-@@ -1796,7 +1939,8 @@ mpt_attach(struct pci_dev *pdev, const s
-               destroy_workqueue(ioc->reset_work_q);
-               ioc->reset_work_q = NULL;
--
-+              destroy_workqueue(ioc->fw_event_q);
-+              ioc->fw_event_q = NULL;
-               kfree(ioc);
-               pci_set_drvdata(pdev, NULL);
-               return r;
-@@ -1832,35 +1976,37 @@ mpt_attach(struct pci_dev *pdev, const s
-       if (!ioc->alt_ioc)
-               queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
-                       msecs_to_jiffies(MPT_POLLING_INTERVAL));
--
-       return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_detach - Remove a PCI intelligent MPT adapter.
-  *    @pdev: Pointer to pci_dev structure
-- */
--
-+ **/
- void
- mpt_detach(struct pci_dev *pdev)
- {
-       MPT_ADAPTER     *ioc = pci_get_drvdata(pdev);
-       char pname[32];
-       u8 cb_idx;
--      unsigned long flags;
-+      unsigned long    flags;
-       struct workqueue_struct *wq;
-       /*
-        * Stop polling ioc for fault condition
-        */
--      spin_lock_irqsave(&ioc->fault_reset_work_lock, flags);
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-       wq = ioc->reset_work_q;
-       ioc->reset_work_q = NULL;
--      spin_unlock_irqrestore(&ioc->fault_reset_work_lock, flags);
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-       cancel_delayed_work(&ioc->fault_reset_work);
-       destroy_workqueue(wq);
-+      spin_lock_irqsave(&ioc->fw_event_lock, flags);
-+      wq = ioc->fw_event_q;
-+      ioc->fw_event_q = NULL;
-+      spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
-+      destroy_workqueue(wq);
-       sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
-       remove_proc_entry(pname, NULL);
-@@ -1877,32 +2023,18 @@ mpt_detach(struct pci_dev *pdev)
-               }
-       }
--      /* Disable interrupts! */
--      CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
--
--      ioc->active = 0;
--      synchronize_irq(pdev->irq);
--
--      /* Clear any lingering interrupt */
--      CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
--
--      CHIPREG_READ32(&ioc->chip->IntStatus);
--
--      mpt_adapter_dispose(ioc);
--
--      pci_set_drvdata(pdev, NULL);
--}
-+      mpt_adapter_dispose(ioc);
-+}
- /**************************************************************************
-  * Power Management
-  */
- #ifdef CONFIG_PM
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_suspend - Fusion MPT base driver suspend routine.
-  *    @pdev: Pointer to pci_dev structure
-  *    @state: new state to enter
-- */
-+ **/
- int
- mpt_suspend(struct pci_dev *pdev, pm_message_t state)
- {
-@@ -1923,7 +2055,6 @@ mpt_suspend(struct pci_dev *pdev, pm_mes
-       /* disable interrupts */
-       CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
-       ioc->active = 0;
--
-       /* Clear any lingering interrupt */
-       CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
-@@ -1938,11 +2069,10 @@ mpt_suspend(struct pci_dev *pdev, pm_mes
-       return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_resume - Fusion MPT base driver resume routine.
-  *    @pdev: Pointer to pci_dev structure
-- */
-+ **/
- int
- mpt_resume(struct pci_dev *pdev)
- {
-@@ -1962,6 +2092,22 @@ mpt_resume(struct pci_dev *pdev)
-       err = mpt_mapresources(ioc);
-       if (err)
-               return err;
-+
-+      if (ioc->dma_mask == DMA_64BIT_MASK) {
-+              if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078)
-+                      ioc->add_sge = &mpt_add_sge_64bit_1078;
-+              else
-+                      ioc->add_sge = &mpt_add_sge_64bit;
-+              ioc->add_chain = &mpt_add_chain_64bit;
-+              ioc->sg_addr_size = 8;
-+      } else {
-+
-+              ioc->add_sge = &mpt_add_sge;
-+              ioc->add_chain = &mpt_add_chain;
-+              ioc->sg_addr_size = 4;
-+      }
-+      ioc->SGE_size = sizeof(u32) + ioc->sg_addr_size;
-+
-       printk(MYIOC_s_INFO_FMT "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
-           ioc->name, (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
-@@ -1986,9 +2132,7 @@ mpt_resume(struct pci_dev *pdev)
-       /* bring ioc to operational state */
-       printk(MYIOC_s_INFO_FMT "Sending mpt_do_ioc_recovery\n", ioc->name);
--      recovery_state = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
--                                               CAN_SLEEP);
--      if (recovery_state != 0)
-+      if ((recovery_state = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP, CAN_SLEEP)) != 0)
-               printk(MYIOC_s_WARN_FMT "pci-resume: Cannot recover, "
-                   "error:[%x]\n", ioc->name, recovery_state);
-       else
-@@ -1996,7 +2140,6 @@ mpt_resume(struct pci_dev *pdev)
-                   "pci-resume: success\n", ioc->name);
-  out:
-       return 0;
--
- }
- #endif
-@@ -2015,7 +2158,6 @@ mpt_signal_reset(u8 index, MPT_ADAPTER *
-       return (MptResetHandlers[index])(ioc, reset_phase);
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_do_ioc_recovery - Initialize or recover MPT adapter.
-  *    @ioc: Pointer to MPT adapter structure
-@@ -2034,9 +2176,7 @@ mpt_signal_reset(u8 index, MPT_ADAPTER *
-  *            -2 if READY but IOCFacts Failed
-  *            -3 if READY but PrimeIOCFifos Failed
-  *            -4 if READY but IOCInit Failed
-- *            -5 if failed to enable_device and/or request_selected_regions
-- *            -6 if failed to upload firmware
-- */
-+ **/
- static int
- mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
- {
-@@ -2045,14 +2185,12 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-       int      hard;
-       int      rc=0;
-       int      ii;
--      u8       cb_idx;
--      int      handlers;
-       int      ret = 0;
-       int      reset_alt_ioc_active = 0;
-       int      irq_allocated = 0;
-       u8      *a;
--      printk(MYIOC_s_INFO_FMT "Initiating %s\n", ioc->name,
-+      printk(MYIOC_s_DEBUG_FMT "Initiating %s\n", ioc->name,
-           reason == MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
-       /* Disable reply interrupts (also blocks FreeQ) */
-@@ -2060,7 +2198,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-       ioc->active = 0;
-       if (ioc->alt_ioc) {
--              if (ioc->alt_ioc->active)
-+              if (ioc->alt_ioc->active || reason == MPT_HOSTEVENT_IOC_RECOVER)
-                       reset_alt_ioc_active = 1;
-               /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
-@@ -2079,16 +2217,17 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-                       if (reset_alt_ioc_active && ioc->alt_ioc) {
-                               /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
--                              dprintk(ioc, printk(MYIOC_s_INFO_FMT
--                                  "alt_ioc reply irq re-enabled\n", ioc->alt_ioc->name));
-+                              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": alt-ioc reply irq re-enabled\n",
-+                                  ioc->alt_ioc->name));
-                               CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
-                               ioc->alt_ioc->active = 1;
-                       }
-               } else {
--                      printk(MYIOC_s_WARN_FMT "NOT READY!\n", ioc->name);
-+                      printk(MYIOC_s_WARN_FMT "NOT READY WARNING!\n", ioc->name);
-               }
--              return -1;
-+              ret = -1;
-+              goto out;
-       }
-       /* hard_reset_done = 0 if a soft reset was performed
-@@ -2098,7 +2237,8 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-               if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
-                       alt_ioc_ready = 1;
-               else
--                      printk(MYIOC_s_WARN_FMT "alt_ioc not ready!\n", ioc->alt_ioc->name);
-+                      printk(MYIOC_s_WARN_FMT
-+                          ": alt-ioc Not ready WARNING!\n", ioc->alt_ioc->name);
-       }
-       for (ii=0; ii<5; ii++) {
-@@ -2156,23 +2296,28 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-               if (ioc->pcidev->irq) {
-                       if (ioc->msi_enable && !pci_enable_msi(ioc->pcidev))
-                               printk(MYIOC_s_INFO_FMT "PCI-MSI enabled\n",
--                                  ioc->name);
-+                                      ioc->name);
-                       else
-                               ioc->msi_enable = 0;
-+
-                       rc = request_irq(ioc->pcidev->irq, mpt_interrupt,
-                           IRQF_SHARED, ioc->name, ioc);
-                       if (rc < 0) {
-                               printk(MYIOC_s_ERR_FMT "Unable to allocate "
--                                  "interrupt %d!\n", ioc->name, ioc->pcidev->irq);
-+                                      "interrupt %d!\n", ioc->name,
-+                                      ioc->pcidev->irq);
-                               if (ioc->msi_enable)
-                                       pci_disable_msi(ioc->pcidev);
--                              return -EBUSY;
-+                              ret = -EBUSY;
-+                              goto out;
-                       }
-                       irq_allocated = 1;
-                       ioc->pci_irq = ioc->pcidev->irq;
-                       pci_set_master(ioc->pcidev);            /* ?? */
--                      dprintk(ioc, printk(MYIOC_s_INFO_FMT "installed at interrupt "
--                          "%d\n", ioc->name, ioc->pcidev->irq));
-+                      pci_set_drvdata(ioc->pcidev, ioc);
-+                      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
-+                          "installed at interrupt %d\n", ioc->name,
-+                          ioc->pcidev->irq));
-               }
-       }
-@@ -2181,18 +2326,22 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-        * init as upper addresses are needed for init.
-        * If fails, continue with alt-ioc processing
-        */
-+      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "PrimeIocFifos\n",
-+          ioc->name));
-       if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
-               ret = -3;
-       /* May need to check/upload firmware & data here!
-        * If fails, continue with alt-ioc processing
-        */
-+      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "SendIocInit\n",
-+          ioc->name));
-       if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
-               ret = -4;
- // NEW!
-       if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
--              printk(MYIOC_s_WARN_FMT ": alt_ioc (%d) FIFO mgmt alloc!\n",
--                  ioc->alt_ioc->name, rc);
-+              printk(MYIOC_s_WARN_FMT ": alt-ioc (%d) FIFO mgmt alloc WARNING!\n",
-+                              ioc->alt_ioc->name, rc);
-               alt_ioc_ready = 0;
-               reset_alt_ioc_active = 0;
-       }
-@@ -2201,15 +2350,16 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-               if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
-                       alt_ioc_ready = 0;
-                       reset_alt_ioc_active = 0;
--                      printk(MYIOC_s_WARN_FMT "alt_ioc (%d) init failure!\n",
--                          ioc->alt_ioc->name, rc);
-+                      printk(MYIOC_s_WARN_FMT
-+                              ": alt-ioc: (%d) init failure WARNING!\n",
-+                                      ioc->alt_ioc->name, rc);
-               }
-       }
-       if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
-               if (ioc->upload_fw) {
-                       ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                          "firmware upload required!\n", ioc->name));
-+                              "firmware upload required!\n", ioc->name));
-                       /* Controller is not operational, cannot do upload
-                        */
-@@ -2232,34 +2382,39 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-                               } else {
-                                       printk(MYIOC_s_WARN_FMT
-                                           "firmware upload failure!\n", ioc->name);
--                                      ret = -6;
-+                                      ret = -5;
-                               }
-                       }
-               }
-       }
-+      /*  Enable MPT base driver management of EventNotification
-+       *  and EventAck handling.
-+       */
-+      if ((ret == 0) && (!ioc->facts.EventState)) {
-+              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "SendEventNotification\n",
-+                  ioc->name));
-+              ret = SendEventNotification(ioc, 1, sleepFlag); /* 1=Enable */
-+      }
-+
-+      if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
-+              rc = SendEventNotification(ioc->alt_ioc, 1, sleepFlag);
-+
-       if (ret == 0) {
-               /* Enable! (reply interrupt) */
-               CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
-               ioc->active = 1;
-       }
--
--      if (reset_alt_ioc_active && ioc->alt_ioc) {
--              /* (re)Enable alt-IOC! (reply interrupt) */
--              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "alt_ioc reply irq re-enabled\n",
--                  ioc->alt_ioc->name));
--              CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
--              ioc->alt_ioc->active = 1;
-+      if (rc == 0) {  /* alt ioc */
-+              if (reset_alt_ioc_active && ioc->alt_ioc) {
-+                      /* (re)Enable alt-IOC! (reply interrupt) */
-+                      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "alt-ioc reply irq re-enabled\n",
-+                              ioc->alt_ioc->name));
-+                      CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
-+                      ioc->alt_ioc->active = 1;
-+              }
-       }
--      /*  Enable MPT base driver management of EventNotification
--       *  and EventAck handling.
--       */
--      if ((ret == 0) && (!ioc->facts.EventState))
--              (void) SendEventNotification(ioc, 1);   /* 1=Enable EventNotification */
--
--      if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
--              (void) SendEventNotification(ioc->alt_ioc, 1);  /* 1=Enable EventNotification */
-       /*      Add additional "reason" check before call to GetLanConfigPages
-        *      (combined with GetIoUnitPage2 call).  This prevents a somewhat
-@@ -2272,11 +2427,12 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-               /*
-                * Initalize link list for inactive raid volumes.
-                */
--              mutex_init(&ioc->raid_data.inactive_list_mutex);
-+              init_MUTEX(&ioc->raid_data.inactive_list_mutex);
-               INIT_LIST_HEAD(&ioc->raid_data.inactive_list);
--              if (ioc->bus_type == SAS) {
-+              switch (ioc->bus_type) {
-+              case SAS:
-                       /* clear persistency table */
-                       if(ioc->facts.IOCExceptions &
-                           MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL) {
-@@ -2290,8 +2446,15 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-                        */
-                       mpt_findImVolumes(ioc);
--              } else if (ioc->bus_type == FC) {
--                      if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
-+                      /* Check, and possibly reset, the coalescing value
-+                       */
-+                      mpt_read_ioc_pg_1(ioc);
-+
-+                      break;
-+
-+              case FC:
-+                      if ((ioc->pfacts[0].ProtocolFlags &
-+                              MPI_PORTFACTS_PROTOCOL_LAN) &&
-                           (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
-                               /*
-                                *  Pre-fetch the ports LAN MAC address!
-@@ -2300,11 +2463,14 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-                               (void) GetLanConfigPages(ioc);
-                               a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
-                               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                  "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
--                                  ioc->name, a[5], a[4], a[3], a[2], a[1], a[0]));
--
-+                                      "LanAddr = %02X:%02X:%02X"
-+                                      ":%02X:%02X:%02X\n",
-+                                      ioc->name, a[5], a[4],
-+                                      a[3], a[2], a[1], a[0]));
-                       }
--              } else {
-+                      break;
-+
-+              case SPI:
-                       /* Get NVRAM and adapter maximums from SPP 0 and 2
-                        */
-                       mpt_GetScsiPortSettings(ioc, 0);
-@@ -2323,41 +2489,16 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-                       mpt_read_ioc_pg_1(ioc);
-                       mpt_read_ioc_pg_4(ioc);
-+
-+                      break;
-               }
-               GetIoUnitPage2(ioc);
-               mpt_get_manufacturing_pg_0(ioc);
-       }
--      /*
--       * Call each currently registered protocol IOC reset handler
--       * with post-reset indication.
--       * NOTE: If we're doing _IOC_BRINGUP, there can be no
--       * MptResetHandlers[] registered yet.
--       */
--      if (hard_reset_done) {
--              rc = handlers = 0;
--              for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
--                      if ((ret == 0) && MptResetHandlers[cb_idx]) {
--                              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                  "Calling IOC post_reset handler #%d\n",
--                                  ioc->name, cb_idx));
--                              rc += mpt_signal_reset(cb_idx, ioc, MPT_IOC_POST_RESET);
--                              handlers++;
--                      }
--
--                      if (alt_ioc_ready && MptResetHandlers[cb_idx]) {
--                              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                  "Calling IOC post_reset handler #%d\n",
--                                  ioc->alt_ioc->name, cb_idx));
--                              rc += mpt_signal_reset(cb_idx, ioc->alt_ioc, MPT_IOC_POST_RESET);
--                              handlers++;
--                      }
--              }
--              /* FIXME?  Examine results here? */
--      }
--
-  out:
-+
-       if ((ret != 0) && irq_allocated) {
-               free_irq(ioc->pci_irq, ioc);
-               if (ioc->msi_enable)
-@@ -2366,7 +2507,6 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-       return ret;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_detect_bound_ports - Search for matching PCI bus/dev_function
-  *    @ioc: Pointer to MPT adapter structure
-@@ -2378,7 +2518,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
-  *
-  *    If match on PCI dev_function +/-1 is found, bind the two MPT adapters
-  *    using alt_ioc pointer fields in their %MPT_ADAPTER structures.
-- */
-+ **/
- static void
- mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
- {
-@@ -2389,8 +2529,8 @@ mpt_detect_bound_ports(MPT_ADAPTER *ioc,
-       dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PCI device %s devfn=%x/%x,"
-           " searching for devfn match on %x or %x\n",
--          ioc->name, pci_name(pdev), pdev->bus->number,
--          pdev->devfn, func-1, func+1));
-+              ioc->name, pci_name(pdev), pdev->bus->number,
-+              pdev->devfn, func-1, func+1));
-       peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
-       if (!peer) {
-@@ -2404,16 +2544,16 @@ mpt_detect_bound_ports(MPT_ADAPTER *ioc,
-               if (_pcidev == peer) {
-                       /* Paranoia checks */
-                       if (ioc->alt_ioc != NULL) {
--                              printk(MYIOC_s_WARN_FMT "Oops, already bound to %s!\n",
--                                      ioc->name, ioc->alt_ioc->name);
-+                              printk(MYIOC_s_WARN_FMT "Oops, already bound (%s <==> %s)!\n",
-+                                      ioc->name, ioc->name, ioc->alt_ioc->name);
-                               break;
-                       } else if (ioc_srch->alt_ioc != NULL) {
--                              printk(MYIOC_s_WARN_FMT "Oops, already bound to %s!\n",
--                                      ioc_srch->name, ioc_srch->alt_ioc->name);
-+                              printk(MYIOC_s_WARN_FMT "Oops, already bound (%s <==> %s)!\n",
-+                                      ioc_srch->name, ioc_srch->name, ioc_srch->alt_ioc->name);
-                               break;
-                       }
--                      dprintk(ioc, printk(MYIOC_s_INFO_FMT "FOUND! binding to %s\n",
--                              ioc->name, ioc_srch->name));
-+                      dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FOUND! binding %s <==> %s\n",
-+                              ioc->name, ioc->name, ioc_srch->name));
-                       ioc_srch->alt_ioc = ioc;
-                       ioc->alt_ioc = ioc_srch;
-               }
-@@ -2421,11 +2561,10 @@ mpt_detect_bound_ports(MPT_ADAPTER *ioc,
-       pci_dev_put(peer);
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_adapter_disable - Disable misbehaving MPT adapter.
-  *    @ioc: Pointer to MPT adapter structure
-- */
-+ **/
- static void
- mpt_adapter_disable(MPT_ADAPTER *ioc)
- {
-@@ -2433,26 +2572,43 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
-       int ret;
-       if (ioc->cached_fw != NULL) {
--              ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: Pushing FW onto "
--                  "adapter\n", __func__, ioc->name));
-+              ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_adapter_disable: "
-+                      "Pushing FW onto adapter\n", ioc->name));
-               if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)
-                   ioc->cached_fw, CAN_SLEEP)) < 0) {
-                       printk(MYIOC_s_WARN_FMT
--                          ": firmware downloadboot failure (%d)!\n",
--                          ioc->name, ret);
-+                          ": firmware downloadboot failure (%d)!\n", ioc->name, ret);
-               }
-       }
-+      /*
-+       * Put the controller into ready state (if its not already)
-+       */
-+      if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY) {
-+              if(!SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET,
-+                  CAN_SLEEP)) {
-+                      if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY)
-+                              printk(MYIOC_s_ERR_FMT "%s:  IOC msg unit "
-+                                  "reset failed to put ioc in ready state!\n",
-+                                  ioc->name, __FUNCTION__);
-+              } else
-+                      printk(MYIOC_s_ERR_FMT "%s:  IOC msg unit reset "
-+                          "failed!\n", ioc->name, __FUNCTION__);
-+      }
-+
-       /* Disable adapter interrupts! */
-+      synchronize_irq(ioc->pcidev->irq);
-       CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
-       ioc->active = 0;
-+
-       /* Clear any lingering interrupt */
-       CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
-+      CHIPREG_READ32(&ioc->chip->IntStatus);
-       if (ioc->alloc != NULL) {
-               sz = ioc->alloc_sz;
--              dexitprintk(ioc, printk(MYIOC_s_INFO_FMT "free  @ %p, sz=%d bytes\n",
--                  ioc->name, ioc->alloc, ioc->alloc_sz));
-+              dexitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "free  @ %p, sz=%d bytes\n",
-+                      ioc->name, ioc->alloc, ioc->alloc_sz));
-               pci_free_consistent(ioc->pcidev, sz,
-                               ioc->alloc, ioc->alloc_dma);
-               ioc->reply_frames = NULL;
-@@ -2482,8 +2638,10 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
-       mpt_inactive_raid_list_free(ioc);
-       kfree(ioc->raid_data.pIocPg2);
-       kfree(ioc->raid_data.pIocPg3);
-+      kfree(ioc->raid_data.pIocPg6);
-       ioc->spi_data.nvram = NULL;
-       ioc->raid_data.pIocPg3 = NULL;
-+      ioc->raid_data.pIocPg6 = NULL;
-       if (ioc->spi_data.pIocPg4 != NULL) {
-               sz = ioc->spi_data.IocPg4Sz;
-@@ -2507,27 +2665,29 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
-               if((ret = mpt_host_page_access_control(ioc,
-                   MPI_DB_HPBAC_FREE_BUFFER, NO_SLEEP)) != 0) {
-                       printk(MYIOC_s_ERR_FMT
--                         "host page buffers free failed (%d)!\n",
--                          ioc->name, ret);
-+                         ": %s: host page buffers free failed (%d)!\n",
-+                          ioc->name, __FUNCTION__, ret);
-               }
--              dexitprintk(ioc, printk(MYIOC_s_INFO_FMT "HostPageBuffer free  @ %p, sz=%d bytes\n",
-+              dexitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HostPageBuffer free  @ %p, sz=%d bytes\n",
-                       ioc->name, ioc->HostPageBuffer, ioc->HostPageBuffer_sz));
-               pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
--                  ioc->HostPageBuffer, ioc->HostPageBuffer_dma);
-+                              ioc->HostPageBuffer,
-+                              ioc->HostPageBuffer_dma);
-               ioc->HostPageBuffer = NULL;
-               ioc->HostPageBuffer_sz = 0;
-               ioc->alloc_total -= ioc->HostPageBuffer_sz;
-       }
-+
-+      pci_set_drvdata(ioc->pcidev, NULL);
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_adapter_dispose - Free all resources associated with an MPT adapter
-  *    @ioc: Pointer to MPT adapter structure
-  *
-  *    This routine unregisters h/w resources and frees all alloc'd memory
-  *    associated with a MPT adapter structure.
-- */
-+ **/
- static void
- mpt_adapter_dispose(MPT_ADAPTER *ioc)
- {
-@@ -2558,7 +2718,7 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)
- #if defined(CONFIG_MTRR) && 0
-       if (ioc->mtrr_reg > 0) {
-               mtrr_del(ioc->mtrr_reg, 0, 0);
--              dprintk(ioc, printk(MYIOC_s_INFO_FMT "MTRR region de-registered\n", ioc->name));
-+              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MTRR region de-registered\n", ioc->name));
-       }
- #endif
-@@ -2566,8 +2726,8 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)
-       list_del(&ioc->list);
-       sz_last = ioc->alloc_total;
--      dprintk(ioc, printk(MYIOC_s_INFO_FMT "free'd %d of %d bytes\n",
--          ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
-+      dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "free'd %d of %d bytes\n",
-+                      ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
-       if (ioc->alt_ioc)
-               ioc->alt_ioc->alt_ioc = NULL;
-@@ -2575,11 +2735,10 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)
-       kfree(ioc);
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    MptDisplayIocCapabilities - Disply IOC's capabilities.
-  *    @ioc: Pointer to MPT adapter structure
-- */
-+ **/
- static void
- MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
- {
-@@ -2618,7 +2777,6 @@ MptDisplayIocCapabilities(MPT_ADAPTER *i
-       printk("}\n");
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    MakeIocReady - Get IOC to a READY state, using KickStart if needed.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -2632,7 +2790,7 @@ MptDisplayIocCapabilities(MPT_ADAPTER *i
-  *            -2 - Msg Unit Reset Failed
-  *            -3 - IO Unit Reset Failed
-  *            -4 - IOC owned by a PEER
-- */
-+ **/
- static int
- MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
- {
-@@ -2646,7 +2804,7 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
-       /* Get current [raw] IOC state  */
-       ioc_state = mpt_GetIocState(ioc, 0);
--      dhsprintk(ioc, printk(MYIOC_s_INFO_FMT "MakeIocReady [raw] state=%08x\n", ioc->name, ioc_state));
-+      dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MakeIocReady, [raw] state=%08x\n", ioc->name, ioc_state));
-       /*
-        *      Check to see if IOC got left/stuck in doorbell handshake
-@@ -2659,8 +2817,11 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
-       }
-       /* Is it already READY? */
--      if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
-+      if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY) {
-+              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "IOC is in READY state\n",
-+                  ioc->name));
-               return 0;
-+      }
-       /*
-        *      Check to see if IOC is in FAULT state.
-@@ -2668,9 +2829,9 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
-       if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
-               statefault = 2;
-               printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
--                  ioc->name);
--              printk(MYIOC_s_WARN_FMT "           FAULT code = %04xh\n",
--                  ioc->name, ioc_state & MPI_DOORBELL_DATA_MASK);
-+                              ioc->name);
-+              printk(KERN_WARNING "           FAULT code = %04xh\n",
-+                              ioc_state & MPI_DOORBELL_DATA_MASK);
-       }
-       /*
-@@ -2686,7 +2847,7 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
-                * Else, fall through to KickStart case
-                */
-               whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
--              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
-+              dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                       "whoinit 0x%x statefault %d force %d\n",
-                       ioc->name, whoinit, statefault, force));
-               if (whoinit == MPI_WHOINIT_PCI_PEER)
-@@ -2733,15 +2894,15 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
-               ii++; cntdn--;
-               if (!cntdn) {
--                      printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
--                                      ioc->name, (int)((ii+5)/HZ));
-+                      printk(MYIOC_s_ERR_FMT "Wait IOC_READY state (0x%x) timeout(%d)!\n",
-+                                      ioc->name, ioc_state, (int)((ii+5)/HZ));
-                       return -ETIME;
-               }
-               if (sleepFlag == CAN_SLEEP) {
-                       msleep(1);
-               } else {
--                      mdelay (1);     /* 1 msec delay */
-+                      mdelay(1);      /* 1 msec delay */
-               }
-       }
-@@ -2755,7 +2916,6 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
-       return hard_reset_done;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_GetIocState - Get the current state of a MPT adapter.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -2763,7 +2923,7 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
-  *
-  *    Returns all IOC Doorbell register bits if cooked==0, else just the
-  *    Doorbell bits in MPI_IOC_STATE_MASK.
-- */
-+ **/
- u32
- mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
- {
-@@ -2779,7 +2939,6 @@ mpt_GetIocState(MPT_ADAPTER *ioc, int co
-       return cooked ? sc : s;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    GetIocFacts - Send IOCFacts request to MPT adapter.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -2787,7 +2946,7 @@ mpt_GetIocState(MPT_ADAPTER *ioc, int co
-  *    @reason: If recovery, only update facts.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int
- GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
- {
-@@ -2802,8 +2961,9 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
-       /* IOC *must* NOT be in RESET state! */
-       if (ioc->last_state == MPI_IOC_STATE_RESET) {
--              printk(MYIOC_s_ERR_FMT "Can't get IOCFacts NOT READY! (%08x)\n",
--                  ioc->name, ioc->last_state );
-+              printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
-+                              ioc->name,
-+                              ioc->last_state );
-               return -44;
-       }
-@@ -2820,7 +2980,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
-       get_facts.Function = MPI_FUNCTION_IOC_FACTS;
-       /* Assert: All other get_facts fields are zero! */
--      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
-           "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
-           ioc->name, req_sz, reply_sz));
-@@ -2850,6 +3010,8 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
-               }
-               facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
-+              if (facts->MsgVersion == MPI_VERSION_01_05)
-+                      facts->HeaderVersion = le16_to_cpu(facts->HeaderVersion);
-               facts->MsgContext = le32_to_cpu(facts->MsgContext);
-               facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
-               facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
-@@ -2865,7 +3027,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
-                *      Old: u16{Major(4),Minor(4),SubMinor(8)}
-                *      New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
-                */
--              if (facts->MsgVersion < 0x0102) {
-+              if (facts->MsgVersion < MPI_VERSION_01_02) {
-                       /*
-                        *      Handle old FC f/w style, convert to new...
-                        */
-@@ -2877,9 +3039,11 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
-                       facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
-               facts->ProductID = le16_to_cpu(facts->ProductID);
-+
-               if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
-                   > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
-                       ioc->ir_firmware = 1;
-+
-               facts->CurrentHostMfaHighAddr =
-                               le32_to_cpu(facts->CurrentHostMfaHighAddr);
-               facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
-@@ -2895,7 +3059,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
-                * to 14 in MPI-1.01.0x.
-                */
-               if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
--                  facts->MsgVersion > 0x0100) {
-+                  facts->MsgVersion > MPI_VERSION_01_00) {
-                       facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
-               }
-@@ -2956,7 +3120,6 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
-       return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    GetPortFacts - Send PortFacts request to MPT adapter.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -2964,7 +3127,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
-  *    @sleepFlag: Specifies whether the process can sleep
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int
- GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
- {
-@@ -2977,8 +3140,8 @@ GetPortFacts(MPT_ADAPTER *ioc, int portn
-       /* IOC *must* NOT be in RESET state! */
-       if (ioc->last_state == MPI_IOC_STATE_RESET) {
--              printk(MYIOC_s_ERR_FMT "Can't get PortFacts NOT READY! (%08x)\n",
--                  ioc->name, ioc->last_state );
-+              printk(MYIOC_s_ERR_FMT "Can't get PortFacts, "
-+                 " NOT READY! (%08x)\n", ioc->name, ioc->last_state );
-               return -4;
-       }
-@@ -2996,14 +3159,14 @@ GetPortFacts(MPT_ADAPTER *ioc, int portn
-       get_pfacts.PortNumber = portnum;
-       /* Assert: All other get_pfacts fields are zero! */
--      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending get PortFacts(%d) request\n",
--                      ioc->name, portnum));
-+      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
-+              ioc->name, portnum));
-       /* No non-zero fields in the get_pfacts request are greater than
-        * 1 byte in size, so we can just fire it off as is.
-        */
-       ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
--                              reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
-+              reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
-       if (ii != 0)
-               return ii;
-@@ -3038,7 +3201,6 @@ GetPortFacts(MPT_ADAPTER *ioc, int portn
-       return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    SendIocInit - Send IOCInit request to MPT adapter.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -3047,7 +3209,7 @@ GetPortFacts(MPT_ADAPTER *ioc, int portn
-  *    Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int
- SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
- {
-@@ -3077,7 +3239,8 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepF
-       ioc_init.MaxDevices = (U8)ioc->devices_per_bus;
-       ioc_init.MaxBuses = (U8)ioc->number_of_buses;
--      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "facts.MsgVersion=%x\n",
-+
-+      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "facts.MsgVersion=%x\n",
-                  ioc->name, ioc->facts.MsgVersion));
-       if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) {
-               // set MsgVersion and HeaderVersion host driver was built with
-@@ -3091,7 +3254,7 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepF
-       }
-       ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz);   /* in BYTES */
--      if (sizeof(dma_addr_t) == sizeof(u64)) {
-+      if (ioc->sg_addr_size == sizeof(u64)) {
-               /* Save the upper 32-bits of the request
-                * (reply) and sense buffers.
-                */
-@@ -3160,7 +3323,6 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepF
-       return r;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    SendPortEnable - Send PortEnable request to MPT adapter port.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -3170,7 +3332,7 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepF
-  *    Send PortEnable to bring IOC to OPERATIONAL state.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int
- SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
- {
-@@ -3193,7 +3355,7 @@ SendPortEnable(MPT_ADAPTER *ioc, int por
- /*    port_enable.MsgFlags = 0;               */
- /*    port_enable.MsgContext = 0;             */
--      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Port(%d)Enable (req @ %p)\n",
-+      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
-                       ioc->name, portnum, &port_enable));
-       /* RAID FW may take a long time to enable
-@@ -3273,7 +3435,6 @@ mpt_free_fw_memory(MPT_ADAPTER *ioc)
-       ioc->cached_fw = NULL;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -3286,7 +3447,7 @@ mpt_free_fw_memory(MPT_ADAPTER *ioc)
-  *    on the bound IOC, the second image is discarded
-  *    and memory is free'd. Both channels must upload to prevent
-  *    IOC from running in degraded mode.
-- */
-+ **/
- static int
- mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
- {
-@@ -3294,22 +3455,19 @@ mpt_do_upload(MPT_ADAPTER *ioc, int slee
-       FWUpload_t              *prequest;
-       FWUploadReply_t         *preply;
-       FWUploadTCSGE_t         *ptcsge;
--      int                      sgeoffset;
-       u32                      flagsLength;
--      int                      ii, sz, reply_sz;
-+      int                      ii, reply_sz;
-       int                      cmdStatus;
-+      int                      request_size;
-       /* If the image size is 0, we are done.
-        */
--      if ((sz = ioc->facts.FWImageSize) == 0)
-+      if (!ioc->facts.FWImageSize)
-               return 0;
-       if (mpt_alloc_fw_memory(ioc, ioc->facts.FWImageSize) != 0)
-               return -ENOMEM;
--      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": FW Image  @ %p[%p], sz=%d[%x] bytes\n",
--          ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
--
-       prequest = (sleepFlag == NO_SLEEP) ? kzalloc(ioc->req_sz, GFP_ATOMIC) :
-           kzalloc(ioc->req_sz, GFP_KERNEL);
-       if (!prequest) {
-@@ -3326,49 +3484,47 @@ mpt_do_upload(MPT_ADAPTER *ioc, int slee
-       prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
-       prequest->Function = MPI_FUNCTION_FW_UPLOAD;
--
-       ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
-       ptcsge->DetailsLength = 12;
-       ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
--      ptcsge->ImageSize = cpu_to_le32(sz);
-+      ptcsge->ImageSize = cpu_to_le32(ioc->facts.FWImageSize);
-       ptcsge++;
--      sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
--
--      flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
--      mpt_add_sge((char *)ptcsge, flagsLength, ioc->cached_fw_dma);
--
--      sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
--      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": Sending FW Upload (req @ %p) sgeoffset=%d \n",
--          ioc->name, prequest, sgeoffset));
-+      flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | ioc->facts.FWImageSize;
-+      ioc->add_sge((char *)ptcsge, flagsLength, ioc->cached_fw_dma);
-+      request_size = offsetof(FWUpload_t, SGL) + sizeof(FWUploadTCSGE_t) +
-+          ioc->SGE_size;
-+      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending FW Upload "
-+          " (req @ %p) fw_size=%d mf_request_size=%d\n", ioc->name, prequest,
-+          ioc->facts.FWImageSize, request_size));
-       DBG_DUMP_FW_REQUEST_FRAME(ioc, (u32 *)prequest);
--      ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
--                              reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
-+      ii = mpt_handshake_req_reply_wait(ioc, request_size, (u32*)prequest,
-+          reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
--      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": FW Upload completed rc=%x \n", ioc->name, ii));
-+      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FW Upload completed "
-+          "rc=%x \n", ioc->name, ii));
-       cmdStatus = -EFAULT;
-       if (ii == 0) {
-               /* Handshake transfer was complete and successful.
-                * Check the Reply Frame.
-                */
--              int status, transfer_sz;
--              status = le16_to_cpu(preply->IOCStatus);
--              if (status == MPI_IOCSTATUS_SUCCESS) {
--                      transfer_sz = le32_to_cpu(preply->ActualImageSize);
--                      if (transfer_sz == sz)
--                              cmdStatus = 0;
--              }
-+              int status;
-+              status = le16_to_cpu(preply->IOCStatus) &
-+                  MPI_IOCSTATUS_MASK;
-+              if (status == MPI_IOCSTATUS_SUCCESS &&
-+                  ioc->facts.FWImageSize ==
-+                  le32_to_cpu(preply->ActualImageSize));
-+                      cmdStatus = 0;
-       }
--      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": do_upload cmdStatus=%d \n",
--                      ioc->name, cmdStatus));
-+      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "do_upload cmdStatus=%d \n",
-+              ioc->name, cmdStatus));
-       if (cmdStatus) {
--
--              ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": fw upload failed, freeing image \n",
--                      ioc->name));
-+              ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "fw upload failed, "
-+                  "freeing image \n", ioc->name));
-               mpt_free_fw_memory(ioc);
-       }
-       kfree(prequest);
-@@ -3376,7 +3532,6 @@ mpt_do_upload(MPT_ADAPTER *ioc, int slee
-       return cmdStatus;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_downloadboot - DownloadBoot code
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -3389,7 +3544,7 @@ mpt_do_upload(MPT_ADAPTER *ioc, int slee
-  *            -1 FW Image size is 0
-  *            -2 No valid cached_fw Pointer
-  *            <0 for fw upload failure.
-- */
-+ **/
- static int
- mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag)
- {
-@@ -3401,10 +3556,10 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
-       u32                      diagRwData;
-       u32                      nextImage;
-       u32                      load_addr;
--      u32                      ioc_state=0;
-+      u32                      doorbell;
-       ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot: fw size 0x%x (%d), FW Ptr %p\n",
--                              ioc->name, pFwHeader->ImageSize, pFwHeader->ImageSize, pFwHeader));
-+          ioc->name, pFwHeader->ImageSize, pFwHeader->ImageSize, pFwHeader));
-       CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
-       CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
-@@ -3416,11 +3571,10 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
-       CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
-       /* wait 1 msec */
--      if (sleepFlag == CAN_SLEEP) {
-+      if (sleepFlag == CAN_SLEEP)
-               msleep(1);
--      } else {
--              mdelay (1);
--      }
-+      else
-+              mdelay(1);
-       diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
-       CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
-@@ -3433,11 +3587,10 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
-                       break;
-               }
-               /* wait .1 sec */
--              if (sleepFlag == CAN_SLEEP) {
-+              if (sleepFlag == CAN_SLEEP)
-                       msleep (100);
--              } else {
-+              else
-                       mdelay (100);
--              }
-       }
-       if ( count == 30 ) {
-@@ -3455,6 +3608,7 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
-       CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
-       /* Set the DiagRwEn and Disable ARM bits */
-+      diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
-       CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
-       fwSize = (pFwHeader->ImageSize + 3)/4;
-@@ -3468,13 +3622,12 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
-       CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
-       ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "LoadStart addr written 0x%x \n",
--              ioc->name, pFwHeader->LoadStartAddress));
-+          ioc->name, pFwHeader->LoadStartAddress));
-       ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write FW Image: 0x%x bytes @ %p\n",
--                              ioc->name, fwSize*4, ptrFw));
--      while (fwSize--) {
-+          ioc->name, fwSize*4, ptrFw));
-+      while (fwSize--)
-               CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
--      }
-       nextImage = pFwHeader->NextImageHeaderOffset;
-       while (nextImage) {
-@@ -3486,21 +3639,22 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
-               ptrFw = (u32 *)pExtImage;
-               ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write Ext Image: 0x%x (%d) bytes @ %p load_addr=%x\n",
--                                              ioc->name, fwSize*4, fwSize*4, ptrFw, load_addr));
-+                  ioc->name, fwSize*4, fwSize*4, ptrFw, load_addr));
-               CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
--              while (fwSize--) {
-+              while (fwSize--)
-                       CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
--              }
-               nextImage = pExtImage->NextImageHeaderOffset;
-       }
-       /* Write the IopResetVectorRegAddr */
--      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Addr=%x! \n", ioc->name,  pFwHeader->IopResetRegAddr));
-+      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Addr=%x! \n",
-+          ioc->name, pFwHeader->IopResetRegAddr));
-       CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
-       /* Write the IopResetVectorValue */
--      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
-+      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Value=%x! \n",
-+          ioc->name, pFwHeader->IopResetVectorValue));
-       CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
-       /* Clear the internal flash bad bit - autoincrementing register,
-@@ -3517,75 +3671,75 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
-               CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
-               CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
--      } else /* if((ioc->bus_type == SAS) || (ioc->bus_type == FC)) */ {
--              diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
--              CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val |
--                  MPI_DIAG_CLEAR_FLASH_BAD_SIG);
--
--              /* wait 1 msec */
--              if (sleepFlag == CAN_SLEEP) {
--                      msleep (1);
--              } else {
--                      mdelay (1);
--              }
-       }
-       if (ioc->errata_flag_1064)
-               pci_disable_io_access(ioc->pcidev);
-       diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
--      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot diag0val=%x, "
--              "turning off PREVENT_IOC_BOOT, DISABLE_ARM, RW_ENABLE\n",
--              ioc->name, diag0val));
--      diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM | MPI_DIAG_RW_ENABLE);
--      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot now diag0val=%x\n",
--              ioc->name, diag0val));
-+      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "diag0val=%x, turning off"
-+          " PREVENT_IOC_BOOT and DISABLE_ARM\n", ioc->name, diag0val));
-+      diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM);
-+      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "diag0val=%x\n",
-+          ioc->name, diag0val));
-       CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
--      /* Write 0xFF to reset the sequencer */
--      CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
-+      if (ioc->bus_type == SAS ) {
-+              /* wait 1 sec */
-+              if (sleepFlag == CAN_SLEEP)
-+                      msleep(1000);
-+              else
-+                      mdelay(1000);
--      if (ioc->bus_type == SAS) {
--              ioc_state = mpt_GetIocState(ioc, 0);
--              if ( (GetIocFacts(ioc, sleepFlag,
--                              MPT_HOSTEVENT_IOC_BRINGUP)) != 0 ) {
--                      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "GetIocFacts failed: IocState=%x\n",
--                                      ioc->name, ioc_state));
--                      return -EFAULT;
-+              diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
-+              ddlprintk(ioc, printk (MYIOC_s_DEBUG_FMT
-+                  "diag0val=%x, turning off RW_ENABLE\n", ioc->name,
-+                  diag0val));
-+              diag0val &= ~(MPI_DIAG_RW_ENABLE);
-+              ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "now diag0val=%x\n", ioc->name, diag0val));
-+              CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
-+
-+              diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
-+              if (diag0val & MPI_DIAG_FLASH_BAD_SIG) {
-+                      diag0val |= MPI_DIAG_CLEAR_FLASH_BAD_SIG;
-+                      CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
-+                      diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
-               }
-+              diag0val &= ~(MPI_DIAG_DISABLE_ARM);
-+              CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
-+              diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
-+              CHIPREG_WRITE32(&ioc->chip->DiagRwAddress, 0x3f000004);
-       }
--      for (count=0; count<HZ*20; count++) {
--              if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
--                      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                              "downloadboot successful! (count=%d) IocState=%x\n",
--                              ioc->name, count, ioc_state));
--                      if (ioc->bus_type == SAS) {
-+      /* Write 0xFF to reset the sequencer */
-+      CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
-+
-+      for (count = 0; count < 30; count ++) {
-+              doorbell = CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_IOC_STATE_MASK;
-+              if (doorbell == MPI_IOC_STATE_READY) {
-+                      if (ioc->bus_type == SAS)
-                               return 0;
--                      }
-                       if ((SendIocInit(ioc, sleepFlag)) != 0) {
--                              ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                      "downloadboot: SendIocInit failed\n",
--                                      ioc->name));
-+                              ddlprintk(ioc, printk(MYIOC_s_WARN_FMT
-+                                  "SendIocInit failed\n", ioc->name));
-                               return -EFAULT;
-                       }
-                       ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                      "downloadboot: SendIocInit successful\n",
--                                      ioc->name));
-+                          "SendIocInit successful\n", ioc->name));
-                       return 0;
-               }
--              if (sleepFlag == CAN_SLEEP) {
--                      msleep (10);
--              } else {
--                      mdelay (10);
--              }
-+              ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "looking for READY STATE:"
-+                  " doorbell=%x count=%d\n", ioc->name, doorbell, count));
-+              if (sleepFlag == CAN_SLEEP)
-+                      msleep(1000);
-+              else
-+                      mdelay(1000);
-       }
--      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--              "downloadboot failed! IocState=%x\n",ioc->name, ioc_state));
-+      ddlprintk(ioc, printk(MYIOC_s_WARN_FMT "downloadboot failed! count=%d\n", ioc->name, count));
-       return -EFAULT;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    KickStart - Perform hard reset of MPT adapter.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -3610,7 +3764,7 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
-  *                 OR reset but failed to come READY
-  *            -2 - no reset, could not enter DIAG mode
-  *            -3 - reset but bad FW bit
-- */
-+ **/
- static int
- KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
- {
-@@ -3618,7 +3772,7 @@ KickStart(MPT_ADAPTER *ioc, int force, i
-       u32 ioc_state=0;
-       int cnt,cntdn;
--      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "KickStarting!\n", ioc->name));
-+      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": KickStart\n", ioc->name));
-       if (ioc->bus_type == SPI) {
-               /* Always issue a Msg Unit Reset first. This will clear some
-                * SCSI bus hang conditions.
-@@ -3636,14 +3790,15 @@ KickStart(MPT_ADAPTER *ioc, int force, i
-       if (hard_reset_done < 0)
-               return hard_reset_done;
--      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset successful!\n",
--              ioc->name));
-+      /* may not have worked but hard_reset_done doesn't always signal failure */
-+      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "Diagnostic reset completed!\n",
-+                      ioc->name));
-       cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2;     /* 2 seconds */
-       for (cnt=0; cnt<cntdn; cnt++) {
-               ioc_state = mpt_GetIocState(ioc, 1);
-               if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
--                      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "KickStart successful! (cnt=%d)\n",
-+                      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "KickStart successful! (cnt=%d)\n",
-                                       ioc->name, cnt));
-                       return hard_reset_done;
-               }
-@@ -3655,11 +3810,10 @@ KickStart(MPT_ADAPTER *ioc, int force, i
-       }
-       dinitprintk(ioc, printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
--              ioc->name, mpt_GetIocState(ioc, 0)));
-+                      ioc->name, mpt_GetIocState(ioc, 0)));
-       return -1;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_diag_reset - Perform hard reset of the adapter.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -3677,30 +3831,46 @@ KickStart(MPT_ADAPTER *ioc, int force, i
-  *              0  no reset performed because reset history bit set
-  *             -2  enabling diagnostic mode failed
-  *             -3  diagnostic reset failed
-- */
-+ **/
- static int
- mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
- {
-       u32 diag0val;
--      u32 doorbell;
-+      u32 doorbell = 0;
-       int hard_reset_done = 0;
-       int count = 0;
-       u32 diag1val = 0;
-       MpiFwHeader_t *cached_fw;       /* Pointer to FW */
-+      u8       cb_idx;
-       /* Clear any existing interrupts */
-       CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
-       if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
-+
-+              if (!ignore)
-+                      return 0;
-+
-               drsprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset "
--                      "address=%p\n",  ioc->name, __func__,
--                      &ioc->chip->Doorbell, &ioc->chip->Reset_1078));
-+                  "address=%p\n",  ioc->name, __FUNCTION__, &ioc->chip->Doorbell,
-+                  &ioc->chip->Reset_1078));
-               CHIPREG_WRITE32(&ioc->chip->Reset_1078, 0x07);
-               if (sleepFlag == CAN_SLEEP)
-                       msleep(1);
-               else
-                       mdelay(1);
-+              /*
-+               * Call each currently registered protocol IOC reset handler
-+               * with pre-reset indication.
-+               * NOTE: If we're doing _IOC_BRINGUP, there can be no
-+               * MptResetHandlers[] registered yet.
-+               */
-+              for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
-+                      if (MptResetHandlers[cb_idx])
-+                              (*(MptResetHandlers[cb_idx]))(ioc, MPT_IOC_PRE_RESET);
-+              }
-+
-               for (count = 0; count < 60; count ++) {
-                       doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
-                       doorbell &= MPI_IOC_STATE_MASK;
-@@ -3709,9 +3879,15 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-                               "looking for READY STATE: doorbell=%x"
-                               " count=%d\n",
-                               ioc->name, doorbell, count));
--                      if (doorbell == MPI_IOC_STATE_READY) {
-+
-+                      if (doorbell == MPI_IOC_STATE_READY)
-                               return 1;
--                      }
-+
-+                      /*
-+                       * Early out for hard fault
-+                       */
-+                      if (count && doorbell == MPI_IOC_STATE_FAULT)
-+                              break;
-                       /* wait 1 sec */
-                       if (sleepFlag == CAN_SLEEP)
-@@ -3719,16 +3895,20 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-                       else
-                               mdelay(1000);
-               }
-+
-+              if (doorbell != MPI_IOC_STATE_READY)
-+                      printk(MYIOC_s_ERR_FMT "Failed to come READY after "
-+                          "reset! IocState=%x", ioc->name, doorbell);
-               return -1;
-       }
-       /* Use "Diagnostic reset" method! (only thing available!) */
-       diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
--      if (ioc->debug_level & MPT_DEBUG) {
-+      if (ioc->debug_level & MPT_DEBUG_RESET) {
-               if (ioc->alt_ioc)
-                       diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
--              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG1: diag0=%08x, diag1=%08x\n",
-+              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG1: diag0=%08x, diag1=%08x\n",
-                       ioc->name, diag0val, diag1val));
-       }
-@@ -3748,11 +3928,10 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-                       CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
-                       /* wait 100 msec */
--                      if (sleepFlag == CAN_SLEEP) {
-+                      if (sleepFlag == CAN_SLEEP)
-                               msleep (100);
--                      } else {
-+                      else
-                               mdelay (100);
--                      }
-                       count++;
-                       if (count > 20) {
-@@ -3764,14 +3943,14 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-                       diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
--                      dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
-+                      drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
-                                       ioc->name, diag0val));
-               }
--              if (ioc->debug_level & MPT_DEBUG) {
-+              if (ioc->debug_level & MPT_DEBUG_RESET) {
-                       if (ioc->alt_ioc)
-                               diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
--                      dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG2: diag0=%08x, diag1=%08x\n",
-+                      drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG2: diag0=%08x, diag1=%08x\n",
-                               ioc->name, diag0val, diag1val));
-               }
-               /*
-@@ -3787,7 +3966,7 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-                */
-               CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
-               hard_reset_done = 1;
--              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset performed\n",
-+              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset performed\n",
-                               ioc->name));
-               /*
-@@ -3796,25 +3975,13 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-                * NOTE: If we're doing _IOC_BRINGUP, there can be no
-                * MptResetHandlers[] registered yet.
-                */
--              {
--                      u8       cb_idx;
--                      int      r = 0;
--
--                      for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
--                              if (MptResetHandlers[cb_idx]) {
--                                      dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                              "Calling IOC pre_reset handler #%d\n",
--                                              ioc->name, cb_idx));
--                                      r += mpt_signal_reset(cb_idx, ioc, MPT_IOC_PRE_RESET);
--                                      if (ioc->alt_ioc) {
--                                              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                                      "Calling alt-%s pre_reset handler #%d\n",
--                                                      ioc->name, ioc->alt_ioc->name, cb_idx));
--                                              r += mpt_signal_reset(cb_idx, ioc->alt_ioc, MPT_IOC_PRE_RESET);
--                                      }
-+              for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
-+                      if (MptResetHandlers[cb_idx]) {
-+                              mpt_signal_reset(cb_idx, ioc, MPT_IOC_PRE_RESET);
-+                              if (ioc->alt_ioc) {
-+                                      mpt_signal_reset(cb_idx, ioc->alt_ioc, MPT_IOC_PRE_RESET);
-                               }
-                       }
--                      /* FIXME?  Examine results here? */
-               }
-               if (ioc->cached_fw)
-@@ -3834,20 +4001,18 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-                                       break;
-                               }
--                              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "cached_fw: diag0val=%x count=%d\n",
-+                              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "cached_fw: diag0val=%x count=%d\n",
-                                       ioc->name, diag0val, count));
-                               /* wait 1 sec */
--                              if (sleepFlag == CAN_SLEEP) {
-+                              if (sleepFlag == CAN_SLEEP)
-                                       msleep (1000);
--                              } else {
-+                              else
-                                       mdelay (1000);
--                              }
-                       }
-                       if ((count = mpt_downloadboot(ioc, cached_fw, sleepFlag)) < 0) {
-                               printk(MYIOC_s_WARN_FMT
-                                       "firmware downloadboot failure (%d)!\n", ioc->name, count);
-                       }
--
-               } else {
-                       /* Wait for FW to reload and for board
-                        * to go to the READY state.
-@@ -3859,25 +4024,38 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-                               doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
-                               doorbell &= MPI_IOC_STATE_MASK;
--                              if (doorbell == MPI_IOC_STATE_READY) {
-+                              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                                  "looking for READY STATE: doorbell=%x"
-+                                  " count=%d\n", ioc->name, doorbell, count));
-+
-+                              if (doorbell == MPI_IOC_STATE_READY)
-+                                      break;
-+
-+                              /*
-+                               * Early out for hard fault
-+                               */
-+                              if (count && doorbell == MPI_IOC_STATE_FAULT)
-                                       break;
--                              }
-                               /* wait 1 sec */
--                              if (sleepFlag == CAN_SLEEP) {
-+                              if (sleepFlag == CAN_SLEEP)
-                                       msleep (1000);
--                              } else {
-+                              else
-                                       mdelay (1000);
--                              }
-                       }
-+
-+                      if (doorbell != MPI_IOC_STATE_READY)
-+                              printk(MYIOC_s_ERR_FMT "Failed to come READY "
-+                                  "after reset! IocState=%x", ioc->name,
-+                                  doorbell);
-               }
-       }
-       diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
--      if (ioc->debug_level & MPT_DEBUG) {
-+      if (ioc->debug_level & MPT_DEBUG_RESET) {
-               if (ioc->alt_ioc)
-                       diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
--              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG3: diag0=%08x, diag1=%08x\n",
-+              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG3: diag0=%08x, diag1=%08x\n",
-                       ioc->name, diag0val, diag1val));
-       }
-@@ -3898,11 +4076,10 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-               CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
-               /* wait 100 msec */
--              if (sleepFlag == CAN_SLEEP) {
-+              if (sleepFlag == CAN_SLEEP)
-                       msleep (100);
--              } else {
-+              else
-                       mdelay (100);
--              }
-               count++;
-               if (count > 20) {
-@@ -3933,11 +4110,11 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-               return -3;
-       }
--      if (ioc->debug_level & MPT_DEBUG) {
-+      if (ioc->debug_level & MPT_DEBUG_RESET) {
-               if (ioc->alt_ioc)
-                       diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
--              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG4: diag0=%08x, diag1=%08x\n",
--                      ioc->name, diag0val, diag1val));
-+              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG4: diag0=%08x, diag1=%08x\n",
-+                              ioc->name, diag0val, diag1val));
-       }
-       /*
-@@ -3951,7 +4128,6 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-       return hard_reset_done;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    SendIocReset - Send IOCReset request to MPT adapter.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -3962,7 +4138,7 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
-  *    Send IOCReset request to the MPT adapter.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int
- SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
- {
-@@ -3973,7 +4149,7 @@ SendIocReset(MPT_ADAPTER *ioc, u8 reset_
-       drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending IOC reset(0x%02x)!\n",
-                       ioc->name, reset_type));
-       CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
--      if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
-+      if ((r = WaitForDoorbellAck(ioc, 15, sleepFlag)) < 0)
-               return r;
-       /* FW ACK'd request, wait for READY state
-@@ -3988,15 +4164,15 @@ SendIocReset(MPT_ADAPTER *ioc, u8 reset_
-                       if (sleepFlag != CAN_SLEEP)
-                               count *= 10;
--                      printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
--                          ioc->name, (int)((count+5)/HZ));
-+                      printk(MYIOC_s_ERR_FMT "Wait IOC_READY state (0x%x) timeout(%d)!\n",
-+                                      ioc->name, state, (int)((count+5)/HZ));
-                       return -ETIME;
-               }
-               if (sleepFlag == CAN_SLEEP) {
-                       msleep(1);
-               } else {
--                      mdelay (1);     /* 1 msec delay */
-+                      mdelay(1);      /* 1 msec delay */
-               }
-       }
-@@ -4010,14 +4186,13 @@ SendIocReset(MPT_ADAPTER *ioc, u8 reset_
-       return 0;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    initChainBuffers - Allocate memory for and initialize chain buffers
-  *    @ioc: Pointer to MPT_ADAPTER structure
-  *
-  *    Allocates memory for and initializes chain buffers,
-  *    chain buffer control arrays and spinlock.
-- */
-+ **/
- static int
- initChainBuffers(MPT_ADAPTER *ioc)
- {
-@@ -4059,24 +4234,30 @@ initChainBuffers(MPT_ADAPTER *ioc)
-        * num_sge = num sge in request frame + last chain buffer
-        * scale = num sge per chain buffer if no chain element
-        */
--      scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
--      if (sizeof(dma_addr_t) == sizeof(u64))
--              num_sge =  scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
-+      scale = ioc->req_sz/ ioc->SGE_size;
-+      if (ioc->sg_addr_size == sizeof(u64))
-+              num_sge =  scale + (ioc->req_sz - 60) / ioc->SGE_size;
-       else
--              num_sge =  1+ scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
-+              num_sge =  1+ scale + (ioc->req_sz - 64) / ioc->SGE_size;
--      if (sizeof(dma_addr_t) == sizeof(u64)) {
-+      if (ioc->sg_addr_size == sizeof(u64)) {
-               numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
--                      (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
-+                      (ioc->req_sz - 60) / ioc->SGE_size;
-       } else {
-               numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
--                      (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
-+                      (ioc->req_sz - 64) / ioc->SGE_size;
-       }
-       dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "num_sge=%d numSGE=%d\n",
-               ioc->name, num_sge, numSGE));
--      if ( numSGE > MPT_SCSI_SG_DEPTH )
--              numSGE = MPT_SCSI_SG_DEPTH;
-+      if (ioc->bus_type == FC) {
-+              if (numSGE > MPT_SCSI_FC_SG_DEPTH)
-+                      numSGE = MPT_SCSI_FC_SG_DEPTH;
-+      }
-+      else {
-+              if (numSGE > MPT_SCSI_SG_DEPTH)
-+                      numSGE = MPT_SCSI_SG_DEPTH;
-+      }
-       num_chain = 1;
-       while (numSGE - num_sge > 0) {
-@@ -4111,7 +4292,6 @@ initChainBuffers(MPT_ADAPTER *ioc)
-       return num_chain;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    PrimeIocFifos - Initialize IOC request and reply FIFOs.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -4121,7 +4301,7 @@ initChainBuffers(MPT_ADAPTER *ioc)
-  *    reply frames.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int
- PrimeIocFifos(MPT_ADAPTER *ioc)
- {
-@@ -4130,13 +4310,36 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
-       dma_addr_t alloc_dma;
-       u8 *mem;
-       int i, reply_sz, sz, total_size, num_chain;
-+      u64     dma_mask;
--      /*  Prime reply FIFO...  */
-+      dma_mask = 0;
-+      /*  Prime reply FIFO...  */
-       if (ioc->reply_frames == NULL) {
-               if ( (num_chain = initChainBuffers(ioc)) < 0)
-                       return -1;
-+              /*
-+               * 1078 errata workaround for the 36GB limitation
-+               */
-+              if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078 &&
-+                  ioc->dma_mask > MPT_DMA_35BIT_MASK) {
-+                      if (!pci_set_dma_mask(ioc->pcidev, DMA_32BIT_MASK)
-+                          && !pci_set_consistent_dma_mask(ioc->pcidev,
-+                          DMA_32BIT_MASK)) {
-+                              dma_mask = MPT_DMA_35BIT_MASK;
-+                              d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                                  "setting 35 bit addressing for "
-+                                  "Request/Reply/Chain and Sense Buffers\n",
-+                                  ioc->name));
-+                      } else {
-+                              d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                                  "failed setting 35 bit addressing for "
-+                                  "Request/Reply/Chain and Sense Buffers\n",
-+                                  ioc->name));
-+                      }
-+              }
-+
-               total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
-               dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
-                               ioc->name, ioc->reply_sz, ioc->reply_depth));
-@@ -4274,9 +4477,16 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
-               alloc_dma += ioc->reply_sz;
-       }
-+      if (dma_mask == MPT_DMA_35BIT_MASK && !pci_set_dma_mask(ioc->pcidev,
-+          ioc->dma_mask) && !pci_set_consistent_dma_mask(ioc->pcidev,
-+          ioc->dma_mask))
-+              d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "restoring 64 bit addressing\n", ioc->name));
-+
-       return 0;
- out_fail:
-+
-       if (ioc->alloc != NULL) {
-               sz = ioc->alloc_sz;
-               pci_free_consistent(ioc->pcidev,
-@@ -4293,10 +4503,16 @@ out_fail:
-                               ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
-               ioc->sense_buf_pool = NULL;
-       }
-+
-+      if (dma_mask == MPT_DMA_35BIT_MASK && !pci_set_dma_mask(ioc->pcidev,
-+          DMA_64BIT_MASK) && !pci_set_consistent_dma_mask(ioc->pcidev,
-+          DMA_64BIT_MASK))
-+              d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "restoring 64 bit addressing\n", ioc->name));
-+
-       return -1;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_handshake_req_reply_wait - Send MPT request to and receive reply
-  *    from IOC via doorbell handshake method.
-@@ -4314,7 +4530,7 @@ out_fail:
-  *    greater than 1 byte in size.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int
- mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
-               int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
-@@ -4408,7 +4624,6 @@ mpt_handshake_req_reply_wait(MPT_ADAPTER
-       return -failcnt;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    WaitForDoorbellAck - Wait for IOC doorbell handshake acknowledge
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -4420,7 +4635,7 @@ mpt_handshake_req_reply_wait(MPT_ADAPTER
-  *    bit in its IntStatus register being clear.
-  *
-  *    Returns a negative value on failure, else wait loop count.
-- */
-+ **/
- static int
- WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
- {
-@@ -4459,7 +4674,6 @@ WaitForDoorbellAck(MPT_ADAPTER *ioc, int
-       return -1;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    WaitForDoorbellInt - Wait for IOC to set its doorbell interrupt bit
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -4470,7 +4684,7 @@ WaitForDoorbellAck(MPT_ADAPTER *ioc, int
-  *    (MPI_HIS_DOORBELL_INTERRUPT) to be set in the IntStatus register.
-  *
-  *    Returns a negative value on failure, else wait loop count.
-- */
-+ **/
- static int
- WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
- {
-@@ -4481,18 +4695,18 @@ WaitForDoorbellInt(MPT_ADAPTER *ioc, int
-       cntdn = 1000 * howlong;
-       if (sleepFlag == CAN_SLEEP) {
-               while (--cntdn) {
-+                      msleep(1);
-                       intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
-                       if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
-                               break;
--                      msleep(1);
-                       count++;
-               }
-       } else {
-               while (--cntdn) {
-+                      udelay (1000);
-                       intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
-                       if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
-                               break;
--                      udelay (1000);
-                       count++;
-               }
-       }
-@@ -4508,7 +4722,6 @@ WaitForDoorbellInt(MPT_ADAPTER *ioc, int
-       return -1;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    WaitForDoorbellReply - Wait for and capture an IOC handshake reply.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -4520,7 +4733,7 @@ WaitForDoorbellInt(MPT_ADAPTER *ioc, int
-  *    of 128 bytes of reply data.
-  *
-  *    Returns a negative value on failure, else size of reply in WORDS.
-- */
-+ **/
- static int
- WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
- {
-@@ -4594,7 +4807,6 @@ WaitForDoorbellReply(MPT_ADAPTER *ioc, i
-       return u16cnt/2;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    GetLanConfigPages - Fetch LANConfig pages.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -4604,7 +4816,7 @@ WaitForDoorbellReply(MPT_ADAPTER *ioc, i
-  *            -EPERM if not allowed due to ISR context
-  *            -EAGAIN if no msg frames currently available
-  *            -EFAULT for non-successful reply or no reply (timeout)
-- */
-+ **/
- static int
- GetLanConfigPages(MPT_ADAPTER *ioc)
- {
-@@ -4705,7 +4917,6 @@ GetLanConfigPages(MPT_ADAPTER *ioc)
-       return rc;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mptbase_sas_persist_operation - Perform operation on SAS Persistent Table
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -4718,9 +4929,7 @@ GetLanConfigPages(MPT_ADAPTER *ioc)
-  *    NOTE: Don't use not this function during interrupt time.
-  *
-  *    Returns 0 for success, non-zero error
-- */
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+ **/
- int
- mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode)
- {
-@@ -4728,7 +4937,14 @@ mptbase_sas_persist_operation(MPT_ADAPTE
-       SasIoUnitControlReply_t         *sasIoUnitCntrReply;
-       MPT_FRAME_HDR                   *mf = NULL;
-       MPIHeader_t                     *mpi_hdr;
-+      int                             ret = 0;
-+      unsigned long                   timeleft;
-+
-+      mutex_lock(&ioc->mptbase_cmds.mutex);
-+      /* init the internal cmd struct */
-+      memset(ioc->mptbase_cmds.reply, 0 , MPT_DEFAULT_FRAME_SIZE);
-+      INITIALIZE_MGMT_STATUS(ioc->mptbase_cmds.status)
-       /* insure garbage is not sent to fw */
-       switch(persist_opcode) {
-@@ -4738,17 +4954,18 @@ mptbase_sas_persist_operation(MPT_ADAPTE
-               break;
-       default:
--              return -1;
--              break;
-+              ret = -1;
-+              goto out;
-       }
--      printk("%s: persist_opcode=%x\n",__func__, persist_opcode);
-+      printk("%s: persist_opcode=%x\n",__FUNCTION__, persist_opcode);
-       /* Get a MF for this command.
-        */
-       if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
--              printk("%s: no msg frames!\n",__func__);
--              return -1;
-+              printk("%s: no msg frames!\n",__FUNCTION__);
-+              ret = -1;
-+              goto out;
-         }
-       mpi_hdr = (MPIHeader_t *) mf;
-@@ -4758,31 +4975,44 @@ mptbase_sas_persist_operation(MPT_ADAPTE
-       sasIoUnitCntrReq->MsgContext = mpi_hdr->MsgContext;
-       sasIoUnitCntrReq->Operation = persist_opcode;
--      init_timer(&ioc->persist_timer);
--      ioc->persist_timer.data = (unsigned long) ioc;
--      ioc->persist_timer.function = mpt_timer_expired;
--      ioc->persist_timer.expires = jiffies + HZ*10 /* 10 sec */;
--      ioc->persist_wait_done=0;
--      add_timer(&ioc->persist_timer);
-       mpt_put_msg_frame(mpt_base_index, ioc, mf);
--      wait_event(mpt_waitq, ioc->persist_wait_done);
-+      timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done, 10*HZ);
-+      if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              ret = -ETIME;
-+              printk("%s: failed\n", __FUNCTION__);
-+              if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
-+                      goto out;
-+              if (!timeleft) {
-+                      printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
-+                          ioc->name, __FUNCTION__);
-+                      if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
-+                              mpt_HardResetHandler(ioc, CAN_SLEEP);
-+                      mpt_free_msg_frame(ioc, mf);
-+              }
-+              goto out;
-+      }
-+
-+      if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
-+              ret = -1;
-+              goto out;
-+      }
-       sasIoUnitCntrReply =
--          (SasIoUnitControlReply_t *)ioc->persist_reply_frame;
-+          (SasIoUnitControlReply_t *)ioc->mptbase_cmds.reply;
-       if (le16_to_cpu(sasIoUnitCntrReply->IOCStatus) != MPI_IOCSTATUS_SUCCESS) {
--              printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
--                  __func__,
--                  sasIoUnitCntrReply->IOCStatus,
--                  sasIoUnitCntrReply->IOCLogInfo);
--              return -1;
--      }
-+              printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n", __FUNCTION__,
-+                  sasIoUnitCntrReply->IOCStatus, sasIoUnitCntrReply->IOCLogInfo);
-+              printk("%s: failed\n",__FUNCTION__);
-+              ret = -1;
-+      } else
-+              printk("%s: success\n",__FUNCTION__);
-+ out:
--      printk("%s: success\n",__func__);
--      return 0;
-+      CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
-+      mutex_unlock(&ioc->mptbase_cmds.mutex);
-+      return ret;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--
- static void
- mptbase_raid_process_event_data(MPT_ADAPTER *ioc,
-     MpiEventDataRaid_t * pRaidEventData)
-@@ -4913,7 +5143,6 @@ mptbase_raid_process_event_data(MPT_ADAP
-       }
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    GetIoUnitPage2 - Retrieve BIOS version and boot order information.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -4923,7 +5152,7 @@ mptbase_raid_process_event_data(MPT_ADAP
-  *            -EPERM if not allowed due to ISR context
-  *            -EAGAIN if no msg frames currently available
-  *            -EFAULT for non-successful reply or no reply (timeout)
-- */
-+ **/
- static int
- GetIoUnitPage2(MPT_ADAPTER *ioc)
- {
-@@ -4971,7 +5200,6 @@ GetIoUnitPage2(MPT_ADAPTER *ioc)
-       return rc;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
-  *    @ioc: Pointer to a Adapter Strucutre
-@@ -4991,7 +5219,7 @@ GetIoUnitPage2(MPT_ADAPTER *ioc)
-  *            Both valid
-  *            Return 0
-  *    CHECK - what type of locking mechanisms should be used????
-- */
-+ **/
- static int
- mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
- {
-@@ -5051,8 +5279,8 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
-                               ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
-                               rc = 1;
-                               ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                      "Unable to read PortPage0 minSyncFactor=%x\n",
--                                      ioc->name, ioc->spi_data.minSyncFactor));
-+                                  "Unable to read PortPage0 minSyncFactor=%x\n",
-+                                  ioc->name, ioc->spi_data.minSyncFactor));
-                       } else {
-                               /* Save the Port Page 0 data
-                                */
-@@ -5062,8 +5290,7 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
-                               if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
-                                       ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
--                                      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                              "noQas due to Capabilities=%x\n",
-+                                      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "noQas due to Capabilities=%x\n",
-                                               ioc->name, pPP0->Capabilities));
-                               }
-                               ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
-@@ -5072,8 +5299,7 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
-                                       ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
-                                       data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
-                                       ioc->spi_data.minSyncFactor = (u8) (data >> 8);
--                                      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                              "PortPage0 minSyncFactor=%x\n",
-+                                      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PortPage0 minSyncFactor=%x\n",
-                                               ioc->name, ioc->spi_data.minSyncFactor));
-                               } else {
-                                       ioc->spi_data.maxSyncOffset = 0;
-@@ -5089,8 +5315,7 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
-                                       if (ioc->spi_data.minSyncFactor < MPT_ULTRA) {
-                                               ioc->spi_data.minSyncFactor = MPT_ULTRA;
--                                              ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                                      "HVD or SE detected, minSyncFactor=%x\n",
-+                                              ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HVD or SE detected, minSyncFactor=%x\n",
-                                                       ioc->name, ioc->spi_data.minSyncFactor));
-                                       }
-                               }
-@@ -5195,7 +5420,6 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
-       return rc;
- }
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_readScsiDevicePageHeaders - save version and length of SDP1
-  *    @ioc: Pointer to a Adapter Strucutre
-@@ -5203,7 +5427,7 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
-  *
-  *    Return: -EFAULT if read of config page header fails
-  *            or 0 if success.
-- */
-+ **/
- static int
- mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
- {
-@@ -5246,9 +5470,73 @@ mpt_readScsiDevicePageHeaders(MPT_ADAPTE
-       return 0;
- }
-+static void
-+mpt_read_ioc_pg_6(MPT_ADAPTER *ioc)
-+{
-+      CONFIGPARMS              cfg;
-+      ConfigPageHeader_t       header;
-+      IOCPage6_t              *pIoc6=NULL;
-+      dma_addr_t               ioc6_dma;
-+      int                      iocpage6sz;
-+      void                    *mem;
-+
-+      /* Free the old page
-+       */
-+      if (ioc->raid_data.pIocPg6) {
-+              kfree(ioc->raid_data.pIocPg6);
-+              ioc->raid_data.pIocPg6 = NULL;
-+      }
-+
-+      /* There is at least one physical disk.
-+       * Read and save IOC Page 3
-+       */
-+      header.PageVersion = 0;
-+      header.PageLength = 0;
-+      header.PageNumber = 6;
-+      header.PageType = MPI_CONFIG_PAGETYPE_IOC;
-+      cfg.cfghdr.hdr = &header;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = 0;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;
-+      cfg.timeout = 0;
-+      if (mpt_config(ioc, &cfg) != 0)
-+              goto out;
-+
-+      if (header.PageLength == 0)
-+              goto out;
-+
-+      /* Read Header good, alloc memory
-+       */
-+      iocpage6sz = header.PageLength * 4;
-+      pIoc6 = pci_alloc_consistent(ioc->pcidev, iocpage6sz, &ioc6_dma);
-+      if (!pIoc6)
-+              goto out;
-+
-+      /* Read the Page and save the data
-+       * into malloc'd memory.
-+       */
-+      cfg.physAddr = ioc6_dma;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+      if (mpt_config(ioc, &cfg) != 0)
-+              goto out;
-+
-+      mem = kmalloc(iocpage6sz, GFP_ATOMIC);
-+      if (!mem)
-+              goto out;
-+
-+      memcpy(mem, pIoc6, iocpage6sz);
-+      ioc->raid_data.pIocPg6 = mem;
-+
-+ out:
-+      if (pIoc6)
-+              pci_free_consistent(ioc->pcidev, iocpage6sz, pIoc6, ioc6_dma);
-+}
-+
- /**
-- * mpt_inactive_raid_list_free - This clears this link list.
-- * @ioc : pointer to per adapter structure
-+  * mpt_inactive_raid_list_free - This clears this link list.
-+  * @ioc : pointer to per adapter structure
-+  *
-  **/
- static void
- mpt_inactive_raid_list_free(MPT_ADAPTER *ioc)
-@@ -5258,21 +5546,23 @@ mpt_inactive_raid_list_free(MPT_ADAPTER 
-       if (list_empty(&ioc->raid_data.inactive_list))
-               return;
--      mutex_lock(&ioc->raid_data.inactive_list_mutex);
-+      down(&ioc->raid_data.inactive_list_mutex);
-       list_for_each_entry_safe(component_info, pNext,
-           &ioc->raid_data.inactive_list, list) {
-               list_del(&component_info->list);
-               kfree(component_info);
-       }
--      mutex_unlock(&ioc->raid_data.inactive_list_mutex);
-+      up(&ioc->raid_data.inactive_list_mutex);
- }
- /**
-- * mpt_inactive_raid_volumes - sets up link list of phy_disk_nums for devices belonging in an inactive volume
-- *
-- * @ioc : pointer to per adapter structure
-- * @channel : volume channel
-- * @id : volume target id
-+  * mpt_inactive_raid_volumes - sets up link list of phy_disk_nums
-+  * for devices belonging in an inactive volume
-+  *
-+  * @ioc : pointer to per adapter structure
-+  * @channel : volume channel
-+  * @id : volume target id
-+  *
-  **/
- static void
- mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
-@@ -5281,10 +5571,12 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *i
-       ConfigPageHeader_t              hdr;
-       dma_addr_t                      dma_handle;
-       pRaidVolumePage0_t              buffer = NULL;
--      int                             i;
-+      int                             i, j;
-       RaidPhysDiskPage0_t             phys_disk;
-+      RaidPhysDiskPage1_t             *phys_disk_1;
-       struct inactive_raid_component_info *component_info;
-       int                             handle_inactive_volumes;
-+      int                             num_paths, device_is_online;
-       memset(&cfg, 0 , sizeof(CONFIGPARMS));
-       memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
-@@ -5323,14 +5615,37 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *i
-       if (!handle_inactive_volumes)
-               goto out;
--      mutex_lock(&ioc->raid_data.inactive_list_mutex);
-+      down(&ioc->raid_data.inactive_list_mutex);
-       for (i = 0; i < buffer->NumPhysDisks; i++) {
-               if(mpt_raid_phys_disk_pg0(ioc,
-                   buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
-                       continue;
-+              if (phys_disk.PhysDiskStatus.State !=
-+                  MPI_PHYSDISK0_STATUS_ONLINE)
-+                      continue;
-+
-+              /* check to see if device is online by checking phys_disk_pg1 */
-+              device_is_online = 0;
-+              num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
-+                  buffer->PhysDisk[i].PhysDiskNum);
-+              if (num_paths < 2)
-+                      continue;
-+              phys_disk_1 = kzalloc(offsetof(RaidPhysDiskPage1_t,Path) +
-+                 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
-+              if (!phys_disk_1)
-+                      continue;
-+              mpt_raid_phys_disk_pg1(ioc, buffer->PhysDisk[i].PhysDiskNum,
-+                  phys_disk_1);
-+              for (j = 0; j < num_paths && !device_is_online; j++)
-+                      if (!phys_disk_1->Path[j].Flags)
-+                              device_is_online = 1;
-+              kfree(phys_disk_1);
-+              if (!device_is_online)
-+                      continue;
-+
-               if ((component_info = kmalloc(sizeof (*component_info),
--               GFP_KERNEL)) == NULL)
-+                  GFP_KERNEL)) == NULL)
-                       continue;
-               component_info->volumeID = id;
-@@ -5343,7 +5658,7 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *i
-               list_add_tail(&component_info->list,
-                   &ioc->raid_data.inactive_list);
-       }
--      mutex_unlock(&ioc->raid_data.inactive_list_mutex);
-+      up(&ioc->raid_data.inactive_list_mutex);
-  out:
-       if (buffer)
-@@ -5363,7 +5678,7 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *i
-  *    -ENOMEM if pci_alloc failed
-  **/
- int
--mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage0_t phys_disk)
-+mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, RaidPhysDiskPage0_t *phys_disk)
- {
-       CONFIGPARMS                     cfg;
-       ConfigPageHeader_t              hdr;
-@@ -5373,7 +5688,9 @@ mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc,
-       memset(&cfg, 0 , sizeof(CONFIGPARMS));
-       memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
-+      memset(phys_disk, 0, sizeof(RaidPhysDiskPage0_t));
-+      hdr.PageVersion = MPI_RAIDPHYSDISKPAGE0_PAGEVERSION;
-       hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
-       cfg.cfghdr.hdr = &hdr;
-       cfg.physAddr = -1;
-@@ -5420,6 +5737,181 @@ mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc,
- }
- /**
-+ *    mpt_raid_phys_disk_get_num_paths - returns number paths associated to this phys_num
-+ *    @ioc: Pointer to a Adapter Structure
-+ *    @phys_disk_num: io unit unique phys disk num generated by the ioc
-+ *
-+ *    Return:
-+ *    returns number paths
-+ **/
-+int
-+mpt_raid_phys_disk_get_num_paths(MPT_ADAPTER *ioc, u8 phys_disk_num)
-+{
-+      CONFIGPARMS                     cfg;
-+      ConfigPageHeader_t              hdr;
-+      dma_addr_t                      dma_handle;
-+      pRaidPhysDiskPage1_t            buffer = NULL;
-+      int                             rc;
-+
-+      memset(&cfg, 0 , sizeof(CONFIGPARMS));
-+      memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
-+
-+      hdr.PageVersion = MPI_RAIDPHYSDISKPAGE1_PAGEVERSION;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
-+      hdr.PageNumber = 1;
-+      cfg.cfghdr.hdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              rc = 0;
-+              goto out;
-+      }
-+
-+      if (!hdr.PageLength) {
-+              rc = 0;
-+              goto out;
-+      }
-+
-+      buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
-+          &dma_handle);
-+
-+      if (!buffer) {
-+              rc = 0;
-+              goto out;
-+      }
-+
-+      cfg.physAddr = dma_handle;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+      cfg.pageAddr = phys_disk_num;
-+
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              rc = 0;
-+              goto out;
-+      }
-+
-+      rc = buffer->NumPhysDiskPaths;
-+ out:
-+
-+      if (buffer)
-+              pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
-+                  dma_handle);
-+
-+      return rc;
-+}
-+
-+/**
-+ *    mpt_raid_phys_disk_pg1 - returns phys disk page 1
-+ *    @ioc: Pointer to a Adapter Structure
-+ *    @phys_disk_num: io unit unique phys disk num generated by the ioc
-+ *    @phys_disk: requested payload data returned
-+ *
-+ *    Return:
-+ *    0 on success
-+ *    -EFAULT if read of config page header fails or data pointer not NULL
-+ *    -ENOMEM if pci_alloc failed
-+ **/
-+int
-+mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc, u8 phys_disk_num, RaidPhysDiskPage1_t *phys_disk)
-+{
-+      CONFIGPARMS                     cfg;
-+      ConfigPageHeader_t              hdr;
-+      dma_addr_t                      dma_handle;
-+      pRaidPhysDiskPage1_t            buffer = NULL;
-+      int                             rc;
-+      int                             i;
-+      __le64                          sas_address;
-+
-+      memset(&cfg, 0 , sizeof(CONFIGPARMS));
-+      memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
-+      rc = 0;
-+
-+      hdr.PageVersion = MPI_RAIDPHYSDISKPAGE1_PAGEVERSION;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
-+      hdr.PageNumber = 1;
-+      cfg.cfghdr.hdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              rc = -EFAULT;
-+              goto out;
-+      }
-+
-+      if (!hdr.PageLength) {
-+              rc = -EFAULT;
-+              goto out;
-+      }
-+
-+      buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
-+          &dma_handle);
-+
-+      if (!buffer) {
-+              rc = -ENOMEM;
-+              goto out;
-+      }
-+
-+      cfg.physAddr = dma_handle;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+      cfg.pageAddr = phys_disk_num;
-+
-+      if (mpt_config(ioc, &cfg) != 0) {
-+              rc = -EFAULT;
-+              goto out;
-+      }
-+
-+      phys_disk->NumPhysDiskPaths = buffer->NumPhysDiskPaths;
-+      phys_disk->PhysDiskNum = phys_disk_num;
-+      for (i = 0; i < phys_disk->NumPhysDiskPaths; i++) {
-+              phys_disk->Path[i].PhysDiskID = buffer->Path[i].PhysDiskID;
-+              phys_disk->Path[i].PhysDiskBus = buffer->Path[i].PhysDiskBus;
-+              phys_disk->Path[i].OwnerIdentifier = buffer->Path[i].OwnerIdentifier;
-+              phys_disk->Path[i].Flags = le16_to_cpu(buffer->Path[i].Flags);
-+              memcpy(&sas_address, &buffer->Path[i].WWID, sizeof(__le64));
-+              sas_address = le64_to_cpu(sas_address);
-+              memcpy(&phys_disk->Path[i].WWID, &sas_address, sizeof(__le64));
-+              memcpy(&sas_address, &buffer->Path[i].OwnerWWID, sizeof(__le64));
-+              sas_address = le64_to_cpu(sas_address);
-+              memcpy(&phys_disk->Path[i].OwnerWWID, &sas_address, sizeof(__le64));
-+      }
-+
-+ out:
-+
-+      if (buffer)
-+              pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
-+                  dma_handle);
-+
-+      return rc;
-+}
-+
-+/**
-+ *    mpt_sort_ioc_pg2 - compare function for sorting volumes
-+ *    in ascending order
-+ *    @a: ioc_pg2 raid volume page
-+ *    @b: ioc_pg2 raid volume page
-+ *
-+ *    Return:
-+ *    0 same, 1 (a is bigger), -1 (b is bigger)
-+ **/
-+static int
-+mpt_sort_ioc_pg2(const void *a, const void *b)
-+{
-+      ConfigPageIoc2RaidVol_t * volume_a = (ConfigPageIoc2RaidVol_t *)a;
-+      ConfigPageIoc2RaidVol_t * volume_b = (ConfigPageIoc2RaidVol_t *)b;
-+
-+      if (volume_a->VolumeBus == volume_b->VolumeBus) {
-+              if (volume_a->VolumeID == volume_b->VolumeID)
-+                      return 0;
-+              if (volume_a->VolumeID < volume_b->VolumeID)
-+                      return -1;
-+              return 1;
-+      }
-+      if (volume_a->VolumeBus < volume_b->VolumeBus)
-+              return -1;
-+      return 1;
-+}
-+
-+/**
-  *    mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
-  *    @ioc: Pointer to a Adapter Strucutre
-  *
-@@ -5482,16 +5974,22 @@ mpt_findImVolumes(MPT_ADAPTER *ioc)
-       if (!mem)
-               goto out;
-+      /*
-+       * sort volumes in ascending order
-+       */
-+      sort(pIoc2->RaidVolume, pIoc2->NumActiveVolumes,
-+          sizeof(ConfigPageIoc2RaidVol_t), mpt_sort_ioc_pg2, NULL);
-       memcpy(mem, (u8 *)pIoc2, iocpage2sz);
-       ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
--      mpt_read_ioc_pg_3(ioc);
--
-       for (i = 0; i < pIoc2->NumActiveVolumes ; i++)
-               mpt_inactive_raid_volumes(ioc,
-                   pIoc2->RaidVolume[i].VolumeBus,
-                   pIoc2->RaidVolume[i].VolumeID);
-+      mpt_read_ioc_pg_3(ioc);
-+      mpt_read_ioc_pg_6(ioc);
-+
-  out:
-       pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
-@@ -5651,6 +6149,9 @@ mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
-       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-       if (mpt_config(ioc, &cfg) == 0) {
-+#if defined(CPQ_CIM)
-+              ioc->pci_slot_number = pIoc1->PCISlotNum;
-+#endif
-               tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
-               if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
-                       tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
-@@ -5671,19 +6172,16 @@ mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
-                                       cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
-                                       if (mpt_config(ioc, &cfg) == 0) {
--                                              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                                              "Reset NVRAM Coalescing Timeout to = %d\n",
-+                                              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Reset NVRAM Coalescing Timeout to = %d\n",
-                                                               ioc->name, MPT_COALESCING_TIMEOUT));
-                                       } else {
--                                              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                                              "Reset NVRAM Coalescing Timeout Failed\n",
--                                                              ioc->name));
-+                                              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Reset NVRAM Coalescing Timeout Failed\n",
-+                                                                      ioc->name));
-                                       }
+Subject: MPT fusion driver update to 4.16.00.00
+From: Satya Prakash <sathya.prakash@lsi.com>
+Date: Thu Nov 20 14:13:01 2008 +0100:
+References: bnc#425660
+
+Update the mpt fusion driver to internal version 4.16.00.00.
+
+Signed-off-by: Satya Prakash <sathya.prakash@lsi.com>
+Acked-by: Hannes Reinecke <hare@suse.de>
+
+Index: linux-2.6.27/drivers/message/fusion/csmi/csmisas.c
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/csmi/csmisas.c
++++ linux-2.6.27/drivers/message/fusion/csmi/csmisas.c
+@@ -43,16 +43,13 @@
+ */
+ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  
-                               } else {
--                                      dprintk(ioc, printk(MYIOC_s_WARN_FMT
--                                              "Reset of Current Coalescing Timeout Failed!\n",
--                                              ioc->name));
-+                                      dprintk(ioc, printk(MYIOC_s_WARN_FMT "Reset of Current Coalescing Timeout Failed!\n",
-+                                                              ioc->name));
-                               }
-                       }
+-#define MPT_CSMI_DESCRIPTION "LSI Corporation: Fusion MPT Driver "MPT_LINUX_VERSION_COMMON
++#define MPT_CSMI_DESCRIPTION \
++    "LSI Corporation: Fusion MPT Driver "MPT_LINUX_VERSION_COMMON
+ #define csmisas_is_this_sas_cntr(ioc) (ioc->bus_type == SAS) ? 1 : 0
  
-@@ -5740,43 +6238,39 @@ mpt_get_manufacturing_pg_0(MPT_ADAPTER *
-               pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
- }
+-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
+-#define __user
+-#include <asm/div64.h>
+-#endif
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    SendEventNotification - Send EventNotification (on or off) request to adapter
-  *    @ioc: Pointer to MPT_ADAPTER structure
-  *    @EvSwitch: Event switch flags
-- */
-+ *    @sleepFlag: Specifies whether the process can sleep
-+ **/
- static int
--SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
-+SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch, int sleepFlag)
- {
--      EventNotification_t     *evnp;
--
--      evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
--      if (evnp == NULL) {
--              devtverboseprintk(ioc, printk(MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
--                              ioc->name));
--              return 0;
--      }
--      memset(evnp, 0, sizeof(*evnp));
-+      EventNotification_t     evn;
-+      MPIDefaultReply_t       reply_buf;
--      devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending EventNotification (%d) request %p\n", ioc->name, EvSwitch, evnp));
-+      memset(&evn, 0, sizeof(EventNotification_t));
-+      memset(&reply_buf, 0, sizeof(MPIDefaultReply_t));
--      evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
--      evnp->ChainOffset = 0;
--      evnp->MsgFlags = 0;
--      evnp->Switch = EvSwitch;
-+      evn.Function = MPI_FUNCTION_EVENT_NOTIFICATION;
-+      evn.Switch = EvSwitch;
-+      evn.MsgContext = cpu_to_le32(mpt_base_index << 16);
--      mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)evnp);
-+      devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "Sending EventNotification (%d) request %p\n",
-+          ioc->name, EvSwitch, &evn));
--      return 0;
-+      return mpt_handshake_req_reply_wait(ioc, sizeof(EventNotification_t),
-+          (u32*)&evn, sizeof(MPIDefaultReply_t), (u16*)&reply_buf, 30,
-+          sleepFlag);
- }
+-static int csmisas_do_raid(MPT_ADAPTER *ioc, u8 action, u8 PhysDiskNum, u8 VolumeBus,
+-    u8 VolumeId, pMpiRaidActionReply_t reply);
++static int csmisas_do_raid(MPT_ADAPTER *ioc, u8 action, u8 PhysDiskNum,
++    u8 VolumeBus, u8 VolumeId, pMpiRaidActionReply_t reply);
+ static u8  map_sas_status_to_csmi(u8 mpi_sas_status);
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  /**
-  *    SendEventAck - Send EventAck request to MPT adapter.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-  *    @evnp: Pointer to original EventNotification request
-- */
-+ **/
- static int
- SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
+@@ -66,7 +63,7 @@ reverse_byte_order64(u64 data64)
  {
-@@ -5784,7 +6278,7 @@ SendEventAck(MPT_ADAPTER *ioc, EventNoti
-       if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
-               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
--                  ioc->name,__func__));
-+                  ioc->name,__FUNCTION__));
-               return -1;
-       }
-@@ -5803,7 +6297,6 @@ SendEventAck(MPT_ADAPTER *ioc, EventNoti
-       return 0;
- }
+       int i;
+       u64 rc;
+-      u8  *inWord = (u8*)&data64, *outWord = (u8*)&rc;
++      u8  *inWord = (u8 *)&data64, *outWord = (u8 *)&rc;
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_config - Generic function to issue config message
-  *    @ioc:   Pointer to an adapter structure
-@@ -5816,35 +6309,62 @@ SendEventAck(MPT_ADAPTER *ioc, EventNoti
-  *    -EPERM if not allowed due to ISR context
-  *    -EAGAIN if no msg frames currently available
-  *    -EFAULT for non-successful reply or no reply (timeout)
-- */
-+ **/
- int
- mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
+       for (i = 0 ; i < 8 ; i++)
+               outWord[i] = inWord[7-i];
+@@ -98,7 +95,7 @@ csmisas_is_sata(RaidPhysDiskPage0_t *phy
+  *
+  **/
+ static inline int
+-csmisas_is_end_device(struct mptsas_devinfo * attached)
++csmisas_is_end_device(struct mptsas_devinfo *attached)
  {
-       Config_t        *pReq;
-+      ConfigReply_t   *pReply;
-       ConfigExtendedPageHeader_t  *pExtHdr = NULL;
-       MPT_FRAME_HDR   *mf;
--      unsigned long    flags;
--      int              ii, rc;
-+      int              ii;
-       int              flagsLength;
--      int              in_isr;
-+      long             timeout;
-+      int              ret;
-+      u8               page_type = 0, extend_page;
-+      unsigned long    timeleft;
-+      unsigned long    flags;
-+      u8               issue_hard_reset = 0;
-+      u8               retry_count = 0;
--      /*      Prevent calling wait_event() (below), if caller happens
--       *      to be in ISR context, because that is fatal!
--       */
--      in_isr = in_interrupt();
--      if (in_isr) {
--              dcprintk(ioc, printk(MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
--                              ioc->name));
-+      if (in_interrupt())
-               return -EPERM;
-+
-+      /* don't send a config page during diag reset */
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-+      if (ioc->ioc_reset_in_progress) {
-+              dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: busy with host reset\n", ioc->name, __FUNCTION__));
-+              spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+              return -EBUSY;
-+      }
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+
-+      /* don't send if no chance of success */
-+      if (!ioc->active ||
-+          mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_OPERATIONAL) {
-+              dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: ioc not operational, %d, %xh\n",
-+                  ioc->name, __FUNCTION__, ioc->active,
-+                  mpt_GetIocState(ioc, 0)));
-+              return -EFAULT;
-       }
-+ retry_config:
-+      mutex_lock(&ioc->mptbase_cmds.mutex);
-+      /* init the internal cmd struct */
-+      memset(ioc->mptbase_cmds.reply, 0 , MPT_DEFAULT_FRAME_SIZE);
-+      INITIALIZE_MGMT_STATUS(ioc->mptbase_cmds.status)
-+
-       /* Get and Populate a free Frame
-        */
-       if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
--              dcprintk(ioc, printk(MYIOC_s_WARN_FMT "mpt_config: no msg frames!\n",
--                              ioc->name));
--              return -EAGAIN;
-+              dcprintk(ioc, printk(MYIOC_s_WARN_FMT
-+              "mpt_config: no msg frames!\n", ioc->name));
-+              ret = -EAGAIN;
-+              goto out;
-       }
-+
-       pReq = (Config_t *)mf;
-       pReq->Action = pCfg->action;
-       pReq->Reserved = 0;
-@@ -5870,7 +6390,9 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS
-               pReq->ExtPageType = pExtHdr->ExtPageType;
-               pReq->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
--              /* Page Length must be treated as a reserved field for the extended header. */
-+              /* Page Length must be treated as a reserved field for the
-+               * extended header.
-+               */
-               pReq->Header.PageLength = 0;
-       }
-@@ -5883,126 +6405,126 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS
-       else
-               flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
+       if ((attached->sas_address) &&
+           (attached->device_info &
+@@ -130,7 +127,8 @@ csmisas_is_phys_disk(MPT_ADAPTER *ioc, i
+               goto out;
+       for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
+               if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
+-                  (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
++                  (channel ==
++                   ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
+                       rc = 1;
+                       goto out;
+               }
+@@ -142,14 +140,14 @@ csmisas_is_phys_disk(MPT_ADAPTER *ioc, i
+       if (list_empty(&ioc->raid_data.inactive_list))
+               goto out;
  
--      if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
-+      if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) ==
-+          MPI_CONFIG_PAGETYPE_EXTENDED) {
-               flagsLength |= pExtHdr->ExtPageLength * 4;
--
--              dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Config request type %d, page %d and action %d\n",
--                      ioc->name, pReq->ExtPageType, pReq->Header.PageNumber, pReq->Action));
--      }
--      else {
-+              page_type = pReq->ExtPageType;
-+              extend_page = 1;
-+      } else {
-               flagsLength |= pCfg->cfghdr.hdr->PageLength * 4;
--
--              dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Config request type %d, page %d and action %d\n",
--                      ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
-+              page_type = pReq->Header.PageType;
-+              extend_page = 0;
+-      down(&ioc->raid_data.inactive_list_mutex);
++      mutex_lock(&ioc->raid_data.inactive_list_mutex);
+       list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
+           list) {
+               if ((component_info->d.PhysDiskID == id) &&
+                   (component_info->d.PhysDiskBus == channel))
+                       rc = 1;
        }
+-      up(&ioc->raid_data.inactive_list_mutex);
++      mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  
--      mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
-+      dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "Sending Config request type 0x%x, page 0x%x and action %d\n",
-+          ioc->name, page_type, pReq->Header.PageNumber, pReq->Action));
--      /* Append pCfg pointer to end of mf
--       */
--      *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) =  (void *) pCfg;
--
--      /* Initalize the timer
--       */
--      init_timer_on_stack(&pCfg->timer);
--      pCfg->timer.data = (unsigned long) ioc;
--      pCfg->timer.function = mpt_timer_expired;
--      pCfg->wait_done = 0;
--
--      /* Set the timer; ensure 10 second minimum */
--      if (pCfg->timeout < 10)
--              pCfg->timer.expires = jiffies + HZ*10;
--      else
--              pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
--
--      /* Add to end of Q, set timer and then issue this command */
--      spin_lock_irqsave(&ioc->FreeQlock, flags);
--      list_add_tail(&pCfg->linkage, &ioc->configQ);
--      spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--
--      add_timer(&pCfg->timer);
-+      ioc->add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
-+      timeout = (pCfg->timeout < 15) ? HZ*15 : HZ*pCfg->timeout;
-       mpt_put_msg_frame(mpt_base_index, ioc, mf);
--      wait_event(mpt_waitq, pCfg->wait_done);
--
--      /* mf has been freed - do not access */
--
--      rc = pCfg->status;
-+      timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done, timeout);
-+      if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              ret = -ETIME;
-+              dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "Failed Sending Config request type 0x%x, page 0x%x,"
-+                  " action %d, status %xh, time left %ld\n\n",
-+                      ioc->name, page_type, pReq->Header.PageNumber,
-+                      pReq->Action, ioc->mptbase_cmds.status, timeleft));
-+              if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
-+                      goto out;
-+              if (!timeleft)
-+                      issue_hard_reset = 1;
-+              goto out;
-+      }
+  out:
+       return rc;
+@@ -161,7 +159,8 @@ csmisas_is_phys_disk(MPT_ADAPTER *ioc, i
+  * Obtains the phys disk num for given H:C:T nexus
+  *
+  * input (channel/id)
+- * output (phys disk number - used by SCSI_IO_PASSTHRU to access hidden component)
++ * output (phys disk number - used by SCSI_IO_PASSTHRU to access hidden
++ * component)
+  *
+  * returns - signed return means failure
+  **/
+@@ -176,7 +175,8 @@ csmisas_raid_id_to_num(MPT_ADAPTER *ioc,
+               goto out;
+       for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
+               if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
+-                  (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
++                  (channel ==
++                   ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
+                       rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
+                       goto out;
+               }
+@@ -188,14 +188,14 @@ csmisas_raid_id_to_num(MPT_ADAPTER *ioc,
+       if (list_empty(&ioc->raid_data.inactive_list))
+               goto out;
  
--      return rc;
--}
-+      if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
-+              ret = -1;
-+              goto out;
-+      }
-+      pReply = (ConfigReply_t *)ioc->mptbase_cmds.reply;
-+      ret = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
-+      if (ret == MPI_IOCSTATUS_SUCCESS) {
-+              if (extend_page) {
-+                      pCfg->cfghdr.ehdr->ExtPageLength =
-+                          le16_to_cpu(pReply->ExtPageLength);
-+                      pCfg->cfghdr.ehdr->ExtPageType =
-+                          pReply->ExtPageType;
-+              }
-+              pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
-+              pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
-+              pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
-+              pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/**
-- *    mpt_timer_expired - Callback for timer process.
-- *    Used only internal config functionality.
-- *    @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
-- */
--static void
--mpt_timer_expired(unsigned long data)
--{
--      MPT_ADAPTER *ioc = (MPT_ADAPTER *) data;
-+      }
+-      down(&ioc->raid_data.inactive_list_mutex);
++      mutex_lock(&ioc->raid_data.inactive_list_mutex);
+       list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
+           list) {
+               if ((component_info->d.PhysDiskID == id) &&
+                   (component_info->d.PhysDiskBus == channel))
+                       rc = component_info->d.PhysDiskNum;
+       }
+-      up(&ioc->raid_data.inactive_list_mutex);
++      mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  
--      dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_timer_expired! \n", ioc->name));
-+      if (retry_count)
-+              printk(MYIOC_s_INFO_FMT "Retry completed ret=0x%x timeleft=%ld\n",
-+                  ioc->name, ret, timeleft);
+  out:
+       return rc;
+@@ -218,7 +218,7 @@ csmisas_get_device_component_by_os(MPT_A
  
--      /* Perform a FW reload */
--      if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
--              printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
-+      dcprintk(ioc, printk(KERN_DEBUG "IOCStatus=%04xh, IOCLogInfo=%08xh\n",
-+           ret, le32_to_cpu(pReply->IOCLogInfo)));
+       sas_info = NULL;
  
--      /* No more processing.
--       * Hard reset clean-up will wake up
--       * process and free all resources.
--       */
--      dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_timer_expired complete!\n", ioc->name));
-+ out:
+-      down(&ioc->sas_device_info_mutex);
++      mutex_lock(&ioc->sas_device_info_mutex);
+       list_for_each_entry(p, &ioc->sas_device_info_list, list) {
+               if (p->os.channel == channel && p->os.id == id) {
+                       sas_info = p;
+@@ -227,7 +227,7 @@ csmisas_get_device_component_by_os(MPT_A
+       }
  
--      return;
-+      CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
-+      mutex_unlock(&ioc->mptbase_cmds.mutex);
-+      if (issue_hard_reset) {
-+              issue_hard_reset = 0;
-+              printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
-+                  ioc->name, __FUNCTION__);
-+              if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
-+                      mpt_HardResetHandler(ioc, CAN_SLEEP);
-+              mpt_free_msg_frame(ioc, mf);
-+              /* attempt one retry for a timed out command */
-+              if (!retry_count) {
-+                      printk(MYIOC_s_INFO_FMT
-+                          "Attempting Retry Config request type 0x%x, page 0x%x,"
-+                          " action %d\n", ioc->name, page_type,
-+                          pCfg->cfghdr.hdr->PageNumber, pCfg->action);
-+                      retry_count++;
-+                      goto retry_config;
-+              }
-+      }
-+      return ret;
+  out:
+-      up(&ioc->sas_device_info_mutex);
++      mutex_unlock(&ioc->sas_device_info_mutex);
+       return sas_info;
  }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/**
-- *    mpt_ioc_reset - Base cleanup for hard reset
-- *    @ioc: Pointer to the adapter structure
-- *    @reset_phase: Indicates pre- or post-reset functionality
-- *
-- *    Remark: Frees resources with internally generated commands.
-- */
--static int
--mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
--{
--      CONFIGPARMS *pCfg;
--      unsigned long flags;
--
--      dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--          ": IOC %s_reset routed to MPT base driver!\n",
--          ioc->name, reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
--          reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
--
--      if (reset_phase == MPT_IOC_SETUP_RESET) {
--              ;
--      } else if (reset_phase == MPT_IOC_PRE_RESET) {
--              /* If the internal config Q is not empty -
--               * delete timer. MF resources will be freed when
--               * the FIFO's are primed.
--               */
--              spin_lock_irqsave(&ioc->FreeQlock, flags);
--              list_for_each_entry(pCfg, &ioc->configQ, linkage)
--                      del_timer(&pCfg->timer);
--              spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--
--      } else {
--              CONFIGPARMS *pNext;
--
--              /* Search the configQ for internal commands.
--               * Flush the Q, and wake up all suspended threads.
--               */
--              spin_lock_irqsave(&ioc->FreeQlock, flags);
--              list_for_each_entry_safe(pCfg, pNext, &ioc->configQ, linkage) {
--                      list_del(&pCfg->linkage);
--
--                      pCfg->status = MPT_CONFIG_ERROR;
--                      pCfg->wait_done = 1;
--                      wake_up(&mpt_waitq);
-+/**
-+ *    mpt_ioc_reset - Base cleanup for hard reset
-+ *    @ioc: Pointer to the adapter structure
-+ *    @reset_phase: Indicates pre- or post-reset functionality
-+ *
-+ *    Remark: Frees resources with internally generated commands.
-+ **/
-+static int
-+mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
-+{
-+      switch(reset_phase) {
-+      case MPT_IOC_SETUP_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __FUNCTION__));
-+              ioc->taskmgmt_quiesce_io = 1;
-+              break;
-+      case MPT_IOC_PRE_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __FUNCTION__));
-+              break;
-+      case MPT_IOC_POST_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_POST_RESET\n",  ioc->name, __FUNCTION__));
-+/* wake up mptbase_cmds */
-+              if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
-+                      ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
-+                      complete(&ioc->mptbase_cmds.done);
-+              }
-+/* wake up taskmgmt_cmds */
-+              if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
-+                      ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
-+                      complete(&ioc->taskmgmt_cmds.done);
-               }
--              spin_unlock_irqrestore(&ioc->FreeQlock, flags);
-+              break;
-+      default:
-+              break;
-       }
+@@ -248,7 +248,7 @@ csmisas_get_device_component_by_fw(MPT_A
  
-       return 1;               /* currently means nothing really */
-@@ -6010,16 +6532,11 @@ mpt_ioc_reset(MPT_ADAPTER *ioc, int rese
+       sas_info = NULL;
  
+-      down(&ioc->sas_device_info_mutex);
++      mutex_lock(&ioc->sas_device_info_mutex);
+       list_for_each_entry(p, &ioc->sas_device_info_list, list) {
+               if (p->fw.channel == channel && p->fw.id == id) {
+                       sas_info = p;
+@@ -257,7 +257,7 @@ csmisas_get_device_component_by_fw(MPT_A
+       }
  
- #ifdef CONFIG_PROC_FS         /* { */
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-- *    procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
-- */
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int
- procmpt_create(void)
- {
-@@ -6040,12 +6557,11 @@ procmpt_create(void)
-       return 0;
+  out:
+-      up(&ioc->sas_device_info_mutex);
++      mutex_unlock(&ioc->sas_device_info_mutex);
+       return sas_info;
  }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static void
- procmpt_destroy(void)
- {
-@@ -6054,7 +6570,6 @@ procmpt_destroy(void)
-       remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
- }
+@@ -279,7 +279,7 @@ csmisas_get_device_component_by_sas_addr
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    procmpt_summary_read - Handle read request of a summary file
-  *    @buf: Pointer to area to write information
-@@ -6066,7 +6581,7 @@ procmpt_destroy(void)
-  *
-  *    Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary.
-  *    Returns number of characters written to process performing the read.
-- */
-+ **/
- static int
- procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
- {
-@@ -6098,7 +6613,6 @@ procmpt_summary_read(char *buf, char **s
-       MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
+       sas_info = NULL;
+-      down(&ioc->sas_device_info_mutex);
++      mutex_lock(&ioc->sas_device_info_mutex);
+       list_for_each_entry(p, &ioc->sas_device_info_list, list) {
+               if (p->sas_address == sas_address) {
+                       sas_info = p;
+@@ -288,7 +288,7 @@ csmisas_get_device_component_by_sas_addr
+       }
+  out:
+-      up(&ioc->sas_device_info_mutex);
++      mutex_unlock(&ioc->sas_device_info_mutex);
+       return sas_info;
  }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    procmpt_version_read - Handle read request from /proc/mpt/version.
-  *    @buf: Pointer to area to write information
-@@ -6109,7 +6623,7 @@ procmpt_summary_read(char *buf, char **s
-  *    @data: Pointer
-  *
-  *    Returns number of characters written to process performing the read.
-- */
-+ **/
+@@ -305,7 +305,8 @@ csmisas_get_device_component_by_sas_addr
+  *    non-zero, failure
+  **/
  static int
- procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
+-csmisas_send_command_wait(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, unsigned long timeout)
++csmisas_send_command_wait(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf,
++    unsigned long timeout)
  {
-@@ -6154,7 +6668,6 @@ procmpt_version_read(char *buf, char **s
-       MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
+       int rc;
+       unsigned long timeleft;
+@@ -314,40 +315,15 @@ csmisas_send_command_wait(MPT_ADAPTER *i
+       rc = 0;
+       timeleft = 0;
+-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
+-
+-      INITIALIZE_IOCTL_STATUS(ioc->ioctl_cmds.status)
+-      ioc->ioctl_cmds.wait_done = 0;
+-      ioc->ioctl_cmds.timer.expires = jiffies + (MPT_JIFFY * timeout);
+-      ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_TIMER_ACTIVE;
+-      ADD_TIMER(&ioc->ioctl_cmds.timer);
+-      mpt_put_msg_frame(mptctl_id, ioc, mf);
+-      WAIT_EVENT(mptctl_wait, ioc->ioctl_cmds.wait_done);
+-
+-#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
+-
+-      INITIALIZE_IOCTL_STATUS(ioc->ioctl_cmds.status)
+-      ioc->ioctl_cmds.wait_done = 0;
+-      mpt_put_msg_frame(mptctl_id, ioc, mf);
+-
+-      if ((wait_event_timeout(mptctl_wait,
+-          ioc->ioctl_cmds.wait_done == 1, HZ * timeout) <=0) &&
+-          ioc->ioctl_cmds.wait_done != 1 ) {
+-              mptctl_timeout_expired(ioc,mf);
+-              mpt_free_msg_frame(ioc, mf);
+-              rc = -1;
+-      }
+-
+-#else
+-
+       SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
+           mf->u.hdr.MsgContext);
+       INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
+       mpt_put_msg_frame(mptctl_id, ioc, mf);
+-      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, timeout*HZ);
++      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
++          timeout*HZ);
+       if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               rc = -1;
+-              printk("%s: failed\n", __FUNCTION__);
++              printk(KERN_WARNING "%s: failed\n", __func__);
+               if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
+                       mpt_free_msg_frame(ioc, mf);
+                       CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
+@@ -357,7 +333,6 @@ csmisas_send_command_wait(MPT_ADAPTER *i
+                       mptctl_timeout_expired(ioc, mf);
+       }
+       SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
+-#endif
+       return rc;
  }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
-  *    @buf: Pointer to area to write information
-@@ -6165,7 +6678,7 @@ procmpt_version_read(char *buf, char **s
-  *    @data: Pointer
-  *
-  *    Returns number of characters written to process performing the read.
-- */
-+ **/
+@@ -375,7 +350,8 @@ csmisas_send_command_wait(MPT_ADAPTER *i
+  *    non-zero, failure
+  **/
  static int
- procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
- {
-@@ -6251,7 +6764,6 @@ procmpt_iocinfo_read(char *buf, char **s
- #endif                /* CONFIG_PROC_FS } */
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- static void
- mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
+-csmisas_send_handshake_wait(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, unsigned long timeout)
++csmisas_send_handshake_wait(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf,
++    unsigned long timeout)
  {
-@@ -6267,7 +6779,6 @@ mpt_get_fw_exp_ver(char *buf, MPT_ADAPTE
+       int rc;
+       unsigned long timeleft;
+@@ -384,42 +360,13 @@ csmisas_send_handshake_wait(MPT_ADAPTER 
+       rc = 0;
+       timeleft = 0;
+-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
+-
+-      INITIALIZE_IOCTL_STATUS(ioc->taskmgmt_cmds.status)
+-      ioc->taskmgmt_cmds.timer.expires = jiffies + (MPT_JIFFY*timeout);
+-      ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_TIMER_ACTIVE;
+-      ioc->taskmgmt_cmds.wait_done = 0;
+-      ADD_TIMER(&ioc->taskmgmt_cmds.timer);
+-      rc = mpt_send_special_message(mptctl_taskmgmt_id, ioc,
+-          sizeof(SCSITaskMgmt_t), (u32*)mf, timeout, CAN_SLEEP);
+-      if (rc != 0)
+-              return rc;
+-      WAIT_EVENT(mptctl_taskmgmt_wait, ioc->taskmgmt_cmds.wait_done);
+-
+-#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
+-
+-      INITIALIZE_IOCTL_STATUS(ioc->taskmgmt_cmds.status)
+-      ioc->taskmgmt_cmds.wait_done = 0;
+-      rc = mpt_send_special_message(mptctl_taskmgmt_id, ioc,
+-          sizeof(SCSITaskMgmt_t), (u32*)mf, timeout, CAN_SLEEP);
+-      if (rc != 0)
+-              return rc;
+-      if ((wait_event_timeout(mptctl_taskmgmt_wait,
+-          ioc->taskmgmt_cmds.wait_done == 1, HZ * timeout) <=0) &&
+-          ioc->taskmgmt_cmds.wait_done != 1 ) {
+-              mptctl_timeout_expired(ioc, mf);
+-              mpt_free_msg_frame(ioc, mf);
+-              rc = -1;
+-      }
+-
+-#else
+       INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
+       mpt_put_msg_frame_hi_pri(mptctl_taskmgmt_id, ioc, mf);
+-      timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ);
++      timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,
++          timeout*HZ);
+       if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               rc = -1;
+-              printk("%s: failed\n", __FUNCTION__);
++              printk(KERN_WARNING "%s: failed\n", __func__);
+               mpt_clear_taskmgmt_in_progress_flag(ioc);
+               if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
+                       mpt_free_msg_frame(ioc, mf);
+@@ -429,7 +376,6 @@ csmisas_send_handshake_wait(MPT_ADAPTER 
+               if (!timeleft)
+                       mptctl_timeout_expired(ioc, mf);
        }
+-#endif
+       return rc;
  }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -6278,7 +6789,7 @@ mpt_get_fw_exp_ver(char *buf, MPT_ADAPTE
-  *
-  *    This routine writes (english readable) ASCII text, which represents
-  *    a summary of IOC information, to a buffer.
-- */
-+ **/
- void
- mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
- {
-@@ -6319,16 +6830,204 @@ mpt_halt_firmware(MPT_ADAPTER *ioc)
-       if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
-               printk(MYIOC_s_ERR_FMT "IOC is in FAULT state (%04xh)!!!\n",
-                       ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
--              panic("%s: IOC Fault (%04xh)!!!\n", ioc->name,
--                      ioc_raw_state & MPI_DOORBELL_DATA_MASK);
-+              if(mpt_fwfault_debug == 2)
-+                      for(;;);
-+              else
-+                      panic("%s: IOC Fault (%04xh)!!!\n",ioc->name,
-+                              ioc_raw_state & MPI_DOORBELL_DATA_MASK);
-       } else {
-               CHIPREG_WRITE32(&ioc->chip->Doorbell, 0xC0FFEE00);
-+              if(mpt_fwfault_debug == 2) {
-+                      printk("%s: Firmware is halted due to command timeout\n"
-+                                      ,ioc->name);
-+                      for(;;);
-+              }
-+              else
--              panic("%s: Firmware is halted due to command timeout\n",
--                      ioc->name);
-+                      panic("%s: Firmware is halted due to command timeout\n",
-+                                      ioc->name);
-       }
- }
- EXPORT_SYMBOL(mpt_halt_firmware);
+@@ -527,7 +473,8 @@ csmisas_get_ioc_pg5(MPT_ADAPTER *ioc, IO
+       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
+       cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
  
-+/**
-+ *    mpt_set_taskmgmt_in_progress_flag - set flags associated with task managment
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *
-+ *    Returns 0 for SUCCESS or -1 if FAILED.
-+ *
-+ *    If -1 is return, then it was not possible to set the flags
-+ **/
-+int
-+mpt_set_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc)
-+{
-+      unsigned long    flags;
-+      int              retval;
-+
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-+      if (ioc->ioc_reset_in_progress || ioc->taskmgmt_in_progress ||
-+          (ioc->alt_ioc && ioc->alt_ioc->taskmgmt_in_progress)) {
-+              retval = -1;
-+              spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+              goto out;
-+      }
-+      retval = 0;
-+      ioc->taskmgmt_in_progress = 1;
-+      ioc->taskmgmt_quiesce_io = 1;
-+      if (ioc->alt_ioc) {
-+              ioc->alt_ioc->taskmgmt_in_progress = 1;
-+              ioc->alt_ioc->taskmgmt_quiesce_io = 1;
-+      }
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+
-+ out:
-+      return retval;
-+}
-+
-+/**
-+ *    mpt_clear_taskmgmt_in_progress_flag - clear flags associated with task managment
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *
-+ **/
-+void
-+mpt_clear_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc)
-+{
-+      unsigned long    flags;
-+
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-+      ioc->taskmgmt_in_progress = 0;
-+      ioc->taskmgmt_quiesce_io = 0;
-+      if (ioc->alt_ioc) {
-+              ioc->alt_ioc->taskmgmt_in_progress = 0;
-+              ioc->alt_ioc->taskmgmt_quiesce_io = 0;
-+      }
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+}
-+
-+/**
-+ *    mpt_SoftResetHandler - Issues a less expensive reset
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @sleepFlag: Indicates if sleep or schedule must be called.
-+
-+ *
-+ *    Returns 0 for SUCCESS or -1 if FAILED.
-+ *
-+ *    Message Unit Reset - instructs the IOC to reset the Reply Post and
-+ *    Free FIFO's. All the Message Frames on Reply Free FIFO are discarded.
-+ *    All posted buffers are freed, and event notification is turned off.
-+ *    IOC doesnt reply to any outstanding request. This will transfer IOC
-+ *    to READY state.
-+ **/
-+int
-+mpt_SoftResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
-+{
-+      int              rc;
-+      int              ii;
-+      u8               cb_idx;
-+      unsigned long    flags;
-+      u32              ioc_state;
-+      unsigned long    time_count;
-+
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SoftResetHandler Entered!\n", ioc->name));
-+
-+      ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
-+
-+      if(mpt_fwfault_debug)
-+              mpt_halt_firmware(ioc);
-+
-+      if (ioc_state == MPI_IOC_STATE_FAULT || ioc_state == MPI_IOC_STATE_RESET) {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "skipping, either in FAULT or RESET state!\n", ioc->name));
-+              return -1;
-+      }
-+
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-+      if (ioc->ioc_reset_in_progress) {
-+              spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+              return -1;
-+      }
-+      ioc->ioc_reset_in_progress = 1;
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+
-+      rc = -1;
-+
-+      for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
-+              if (MptResetHandlers[cb_idx])
-+                      mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
-+      }
-+
-+      /* Disable reply interrupts (also blocks FreeQ) */
-+      CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
-+      ioc->active = 0;
-+      time_count = jiffies;
-+
-+      rc = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
-+
-+      for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
-+              if (MptResetHandlers[cb_idx])
-+                      mpt_signal_reset(cb_idx, ioc, MPT_IOC_PRE_RESET);
-+      }
-+
-+      if (rc)
-+              goto out;
-+
-+      ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
-+      if (ioc_state != MPI_IOC_STATE_READY)
-+              goto out;
-+
-+      for (ii = 0; ii < 5; ii++) {
-+              /* Get IOC facts! Allow 5 retries */
-+              if ((rc = GetIocFacts(ioc, sleepFlag,
-+                          MPT_HOSTEVENT_IOC_RECOVER)) == 0)
-+                      break;
-+              if (sleepFlag == CAN_SLEEP) {
-+                      msleep(100);
-+              } else {
-+                      mdelay(100);
-+              }
-+      }
-+      if (ii == 5)
-+              goto out;
-+
-+      if ((rc = PrimeIocFifos(ioc)) != 0)
-+              goto out;
-+
-+      if ((rc = SendIocInit(ioc, sleepFlag)) != 0)
-+              goto out;
-+
-+      if ((rc = SendEventNotification(ioc, 1, sleepFlag)) != 0)
-+              goto out;
-+
-+      if (ioc->hard_resets < -1)
-+              ioc->hard_resets++;
-+
-+      /*
-+       * At this point, we know soft reset succeeded.
-+       */
-+
-+      ioc->active = 1;
-+      CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
-+
-+ out:
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-+      ioc->ioc_reset_in_progress = 0;
-+      ioc->taskmgmt_quiesce_io = 0;
-+      ioc->taskmgmt_in_progress = 0;
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+
-+      if (ioc->active) {      /* otherwise, hard reset coming */
-+              for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
-+                      if (MptResetHandlers[cb_idx])
-+                              mpt_signal_reset(cb_idx, ioc, MPT_IOC_POST_RESET);
-+              }
-+      }
-+
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SoftResetHandler: completed (%d seconds): %s\n",
-+          ioc->name, jiffies_to_msecs(jiffies - time_count)/1000,
-+          ((rc == 0) ? "SUCCESS" : "FAILED")));
-+
-+      return rc;
-+}
-+
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /*
-  *    Reset Handling
-@@ -6335,12 +7060,14 @@ mpt_print_ioc_summary(MPT_ADAPTER *ioc, 
-  *    FW reload/initialization failed.
-  *
-  *    Returns 0 for SUCCESS or -1 if FAILED.
-- */
-+ **/
- int
- mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
- {
--      int              rc;
-+      int      rc;
-+      u8       cb_idx;
-       unsigned long    flags;
-+      unsigned long    time_count;
+-      if ((rc = mpt_config(ioc, &cfg)) != 0)
++      rc = mpt_config(ioc, &cfg);
++      if (rc != 0)
+               goto get_ioc_pg5;
  
-       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HardResetHandler Entered!\n", ioc->name));
- #ifdef MFCNT
-@@ -6348,64 +7075,76 @@ mpt_HardResetHandler(MPT_ADAPTER *ioc, i
-       /* Reset the adapter. Prevent more than 1 call to
-        * mpt_do_ioc_recovery at any instant in time.
-        */
--      spin_lock_irqsave(&ioc->diagLock, flags);
--      if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)){
--              spin_unlock_irqrestore(&ioc->diagLock, flags);
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-+      if (ioc->ioc_reset_in_progress) {
-+              spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-               return 0;
--      } else {
--              ioc->diagPending = 1;
-       }
--      spin_unlock_irqrestore(&ioc->diagLock, flags);
-+      ioc->ioc_reset_in_progress = 1;
-+      if (ioc->alt_ioc)
-+          ioc->alt_ioc->ioc_reset_in_progress = 1;
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+       if (hdr.PageLength == 0) {
+@@ -547,7 +494,8 @@ csmisas_get_ioc_pg5(MPT_ADAPTER *ioc, IO
+       cfg.physAddr = dma_handle;
+       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  
--      /* FIXME: If do_ioc_recovery fails, repeat....
--       */
+-      if ((rc = mpt_config(ioc, &cfg)) != 0)
++      rc = mpt_config(ioc, &cfg);
++      if (rc != 0)
+               goto get_ioc_pg5;
  
-       /* The SCSI driver needs to adjust timeouts on all current
-        * commands prior to the diagnostic reset being issued.
-        * Prevents timeouts occurring during a diagnostic reset...very bad.
-        * For all other protocol drivers, this is a no-op.
-        */
--      {
--              u8       cb_idx;
--              int      r = 0;
--
--              for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
--                      if (MptResetHandlers[cb_idx]) {
--                              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling IOC reset_setup handler #%d\n",
--                                              ioc->name, cb_idx));
--                              r += mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
--                              if (ioc->alt_ioc) {
--                                      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling alt-%s setup reset handler #%d\n",
--                                                      ioc->name, ioc->alt_ioc->name, cb_idx));
--                                      r += mpt_signal_reset(cb_idx, ioc->alt_ioc, MPT_IOC_SETUP_RESET);
--                              }
--                      }
-+      for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
-+              if (MptResetHandlers[cb_idx]) {
-+                      mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
-+                      if (ioc->alt_ioc)
-+                              mpt_signal_reset(cb_idx, ioc->alt_ioc, MPT_IOC_SETUP_RESET);
-               }
-       }
+       memcpy(iocPage5, buffer, data_size);
+@@ -565,7 +513,8 @@ csmisas_get_ioc_pg5(MPT_ADAPTER *ioc, IO
+  *    csmisas_sas_device_pg0 - sas device page 0
+  *    @ioc: Pointer to MPT_ADAPTER structure
+  *    @mptsas_devinfo: structure found in mptsas.h
+- *    @form, @form_specific - defines the Page Address field in the config page
++ *    @form, @form_specific - defines the Page Address field in
++ *    the config page
+  *            (pls refer to chapter 5.1 in the mpi spec)
+  *
+  *    Return: 0 for success
+@@ -602,7 +551,8 @@ csmisas_sas_device_pg0(MPT_ADAPTER *ioc,
+       cfg.timeout = 10;
  
-+      time_count = jiffies;
-       if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
--              printk(MYIOC_s_WARN_FMT "Cannot recover rc = %d!\n", ioc->name, rc);
-+              printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
-+                      rc, ioc->name);
-+      } else {
-+              if (ioc->hard_resets < -1)
-+                      ioc->hard_resets++;
-       }
--      ioc->reload_fw = 0;
--      if (ioc->alt_ioc)
--              ioc->alt_ioc->reload_fw = 0;
--      spin_lock_irqsave(&ioc->diagLock, flags);
--      ioc->diagPending = 0;
--      if (ioc->alt_ioc)
--              ioc->alt_ioc->diagPending = 0;
--      spin_unlock_irqrestore(&ioc->diagLock, flags);
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-+      ioc->ioc_reset_in_progress = 0;
-+      ioc->taskmgmt_quiesce_io = 0;
-+      ioc->taskmgmt_in_progress = 0;
-+      if (ioc->alt_ioc) {
-+          ioc->alt_ioc->ioc_reset_in_progress = 0;
-+          ioc->alt_ioc->taskmgmt_quiesce_io = 0;
-+          ioc->alt_ioc->taskmgmt_in_progress = 0;
-+      }
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
--      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HardResetHandler rc = %d!\n", ioc->name, rc));
-+      for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
-+              if (MptResetHandlers[cb_idx]) {
-+                      mpt_signal_reset(cb_idx, ioc, MPT_IOC_POST_RESET);
-+                      if (ioc->alt_ioc)
-+                              mpt_signal_reset(cb_idx, ioc->alt_ioc, MPT_IOC_POST_RESET);
-+              }
-+      }
+       memset(device_info, 0, sizeof(struct mptsas_devinfo));
+-      if ((rc = mpt_config(ioc, &cfg)) != 0)
++      rc = mpt_config(ioc, &cfg);
++      if (rc != 0)
+               goto out;
  
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HardResetHandler: completed (%d seconds): %s\n",
-+          ioc->name, jiffies_to_msecs(jiffies - time_count)/1000,
-+          ((rc == 0) ? "SUCCESS" : "FAILED")));
-       return rc;
- }
+       if (!hdr.ExtPageLength) {
+@@ -620,7 +570,8 @@ csmisas_sas_device_pg0(MPT_ADAPTER *ioc,
+       cfg.physAddr = dma_handle;
+       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+#ifdef CONFIG_FUSION_LOGGING
- static void
--EventDescriptionStr(u8 event, u32 evData0, char *evStr)
-+mpt_display_event_info(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply)
- {
-       char *ds = NULL;
-+      u32 evData0;
-+      int ii;
-+      u8 event;
-+      char *evStr = ioc->evStr;
-+
-+      event = le32_to_cpu(pEventReply->Event) & 0xFF;
-+      evData0 = le32_to_cpu(pEventReply->Data[0]);
-       switch(event) {
-       case MPI_EVENT_NONE:
-@@ -6442,9 +7184,9 @@ EventDescriptionStr(u8 event, u32 evData
-               if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
-                       ds = "Loop State(LIP) Change";
-               else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
--                      ds = "Loop State(LPE) Change";          /* ??? */
-+                      ds = "Loop State(LPE) Change";
-               else
--                      ds = "Loop State(LPB) Change";          /* ??? */
-+                      ds = "Loop State(LPB) Change";
-               break;
-       case MPI_EVENT_LOGOUT:
-               ds = "Logout";
-@@ -6540,6 +7282,11 @@ EventDescriptionStr(u8 event, u32 evData
-                           "SAS Device Status Change: Internal Device "
-                           "Reset : id=%d channel=%d", id, channel);
-                       break;
-+              case MPI_EVENT_SAS_DEV_STAT_RC_CMPL_INTERNAL_DEV_RESET:
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "SAS Device Status Change: Internal Device "
-+                          "Reset Completed: id=%d channel=%d", id, channel);
-+                      break;
-               case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
-                       snprintf(evStr, EVENT_DESCR_STR_SZ,
-                           "SAS Device Status Change: Internal Task "
-@@ -6560,6 +7307,11 @@ EventDescriptionStr(u8 event, u32 evData
-                           "SAS Device Status Change: Internal Query "
-                           "Task : id=%d channel=%d", id, channel);
-                       break;
-+              case MPI_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "SAS Device Status Change: Async Notification "
-+                          "Task : id=%d channel=%d", id, channel);
-+                      break;
-               default:
-                       snprintf(evStr, EVENT_DESCR_STR_SZ,
-                           "SAS Device Status Change: Unknown: "
-@@ -6644,28 +7396,65 @@ EventDescriptionStr(u8 event, u32 evData
-       }
-       case MPI_EVENT_IR2:
-       {
-+              u8 id = (u8)(evData0);
-+              u8 channel = (u8)(evData0 >> 8);
-+              u8 phys_num = (u8)(evData0 >> 24);
-               u8 ReasonCode = (u8)(evData0 >> 16);
-+
-               switch (ReasonCode) {
-               case MPI_EVENT_IR2_RC_LD_STATE_CHANGED:
--                      ds = "IR2: LD State Changed";
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "IR2: LD State Changed: "
-+                          "id=%d channel=%d phys_num=%d",
-+                          id, channel, phys_num);
-                       break;
-               case MPI_EVENT_IR2_RC_PD_STATE_CHANGED:
--                      ds = "IR2: PD State Changed";
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "IR2: PD State Changed "
-+                          "id=%d channel=%d phys_num=%d",
-+                          id, channel, phys_num);
-                       break;
-               case MPI_EVENT_IR2_RC_BAD_BLOCK_TABLE_FULL:
--                      ds = "IR2: Bad Block Table Full";
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "IR2: Bad Block Table Full: "
-+                          "id=%d channel=%d phys_num=%d",
-+                          id, channel, phys_num);
-                       break;
-               case MPI_EVENT_IR2_RC_PD_INSERTED:
--                      ds = "IR2: PD Inserted";
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "IR2: PD Inserted: "
-+                          "id=%d channel=%d phys_num=%d",
-+                          id, channel, phys_num);
-                       break;
-               case MPI_EVENT_IR2_RC_PD_REMOVED:
--                      ds = "IR2: PD Removed";
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "IR2: PD Removed: "
-+                          "id=%d channel=%d phys_num=%d",
-+                          id, channel, phys_num);
-                       break;
-               case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
--                      ds = "IR2: Foreign CFG Detected";
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "IR2: Foreign CFG Detected: "
-+                          "id=%d channel=%d phys_num=%d",
-+                          id, channel, phys_num);
-                       break;
-               case MPI_EVENT_IR2_RC_REBUILD_MEDIUM_ERROR:
--                      ds = "IR2: Rebuild Medium Error";
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "IR2: Rebuild Medium Error: "
-+                          "id=%d channel=%d phys_num=%d",
-+                          id, channel, phys_num);
-+                      break;
-+              case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED:
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "IR2: Dual Port Added: "
-+                          "id=%d channel=%d phys_num=%d",
-+                          id, channel, phys_num);
-+                      break;
-+              case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED:
-+                      snprintf(evStr, EVENT_DESCR_STR_SZ,
-+                          "IR2: Dual Port Removed: "
-+                          "id=%d channel=%d phys_num=%d",
-+                          id, channel, phys_num);
-                       break;
-               default:
-                       ds = "IR2";
-@@ -6689,25 +7478,46 @@ EventDescriptionStr(u8 event, u32 evData
-       {
-               u8 phy_num = (u8)(evData0);
-               u8 port_num = (u8)(evData0 >> 8);
--              u8 port_width = (u8)(evData0 >> 16);
-+              u8 num_phys = (u8)(evData0 >> 16);
-               u8 primative = (u8)(evData0 >> 24);
-+              char *primative_str = NULL;
-+
-+              switch (primative) {
-+              case MPI_EVENT_PRIMITIVE_CHANGE:
-+                      primative_str = "change";
-+                      break;
-+              case MPI_EVENT_PRIMITIVE_EXPANDER:
-+                      primative_str = "expander";
-+                      break;
-+              case MPI_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT:
-+                      primative_str = "asyn event";
-+                      break;
-+              default:
-+                      primative_str = "reserved";
-+                      break;
-+              }
-               snprintf(evStr, EVENT_DESCR_STR_SZ,
--                  "SAS Broadcase Primative: phy=%d port=%d "
--                  "width=%d primative=0x%02x",
--                  phy_num, port_num, port_width, primative);
-+                  "SAS Broadcast Primative: phy=%d port=%d "
-+                  "num_phys=%d primative=%s (0x%02x)",
-+                  phy_num, port_num, num_phys, primative_str, primative);
-               break;
-       }
+-      if ((rc = mpt_config(ioc, &cfg)) != 0)
++      rc = mpt_config(ioc, &cfg);
++      if (rc != 0)
+               goto out_free_consistent;
  
-       case MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
-       {
-               u8 reason = (u8)(evData0);
--              u8 port_num = (u8)(evData0 >> 8);
--              u16 handle = le16_to_cpu(evData0 >> 16);
--              snprintf(evStr, EVENT_DESCR_STR_SZ,
--                  "SAS Initiator Device Status Change: reason=0x%02x "
--                  "port=%d handle=0x%04x",
--                  reason, port_num, handle);
-+              switch (reason) {
-+              case MPI_EVENT_SAS_INIT_RC_ADDED:
-+                      ds = "SAS Initiator Status Change: Added";
-+                      break;
-+              case MPI_EVENT_SAS_INIT_RC_REMOVED:
-+                      ds = "SAS Initiator Status Change: Deleted";
-+                      break;
-+              default:
-+                      ds = "SAS Initiator Status Change";
-+                      break;
-+              }
-               break;
+       device_info->handle = le16_to_cpu(buffer->DevHandle);
+@@ -664,31 +615,31 @@ csmisas_get_driver_info(unsigned long ar
+       if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_DRIVER_INFO_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s - "
+             "Unable to read in csmi_sas_get_driver_info_buffer struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
  
-@@ -6755,6 +7565,24 @@ EventDescriptionStr(u8 event, u32 evData
-               break;
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
        }
  
-+      case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
-+      {
-+              u8 reason = (u8)(evData0);
-+
-+              switch (reason) {
-+              case MPI_EVENT_SAS_EXP_RC_ADDED:
-+                      ds = "Expander Status Change: Added";
-+                      break;
-+              case MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING:
-+                      ds = "Expander Status Change: Deleted";
-+                      break;
-+              default:
-+                      ds = "Expander Status Change";
-+                      break;
-+              }
-+              break;
-+      }
-+
-       /*
-        *  MPT base "custom" events may be added here...
-        */
-@@ -6764,9 +7592,21 @@ EventDescriptionStr(u8 event, u32 evData
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
        }
-       if (ds)
-               strncpy(evStr, ds, EVENT_DESCR_STR_SZ);
-+
-+
-+      devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "MPT event:(%02Xh) : %s\n",
-+          ioc->name, event, evStr));
-+
-+      devtverboseprintk(ioc, printk(KERN_DEBUG MYNAM
-+          ": Event data:\n"));
-+      for (ii = 0; ii < le16_to_cpu(pEventReply->EventDataLength); ii++)
-+              devtverboseprintk(ioc, printk(" %08x",
-+                  le32_to_cpu(pEventReply->Data[ii])));
-+      devtverboseprintk(ioc, printk(KERN_DEBUG "\n"));
- }
-+#endif
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    ProcessEventNotification - Route EventNotificationReply to all event handlers
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -6776,43 +7616,30 @@ EventDescriptionStr(u8 event, u32 evData
-  *    Routes a received EventNotificationReply to all currently registered
-  *    event handlers.
-  *    Returns sum of event handlers return values.
-- */
-+ **/
- static int
- ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
- {
-       u16 evDataLen;
-       u32 evData0 = 0;
--//    u32 evCtx;
-       int ii;
-       u8 cb_idx;
-       int r = 0;
-       int handlers = 0;
--      char evStr[EVENT_DESCR_STR_SZ];
-       u8 event;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
-+
-       /*
-        *  Do platform normalization of values
+       /* Fill in the data and return the structure to the calling
+        * program
         */
-       event = le32_to_cpu(pEventReply->Event) & 0xFF;
--//    evCtx = le32_to_cpu(pEventReply->EventContext);
-       evDataLen = le16_to_cpu(pEventReply->EventDataLength);
--      if (evDataLen) {
-+      if (evDataLen)
-               evData0 = le32_to_cpu(pEventReply->Data[0]);
--      }
--
--      EventDescriptionStr(event, evData0, evStr);
--      devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MPT event:(%02Xh) : %s\n",
--                      ioc->name,
--                      event,
--                      evStr));
- #ifdef CONFIG_FUSION_LOGGING
--      devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--          ": Event data:\n", ioc->name));
--      for (ii = 0; ii < evDataLen; ii++)
--              devtverboseprintk(ioc, printk(" %08x",
--                  le32_to_cpu(pEventReply->Data[ii])));
--      devtverboseprintk(ioc, printk("\n"));
-+      if (evDataLen)
-+              mpt_display_event_info(ioc, pEventReply);
- #endif
+-      memcpy( karg.Information.szName, MPT_MISCDEV_BASENAME,
++      memcpy(karg.Information.szName, MPT_MISCDEV_BASENAME,
+           sizeof(MPT_MISCDEV_BASENAME));
+-      memcpy( karg.Information.szDescription, MPT_CSMI_DESCRIPTION,
++      memcpy(karg.Information.szDescription, MPT_CSMI_DESCRIPTION,
+           sizeof(MPT_CSMI_DESCRIPTION));
+       karg.Information.usMajorRevision = MPT_LINUX_MAJOR_VERSION;
+@@ -707,11 +658,11 @@ csmisas_get_driver_info(unsigned long ar
+               sizeof(CSMI_SAS_DRIVER_INFO_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s - "
+                  "Unable to write out csmi_sas_get_driver_info_buffer @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-       /*
-@@ -6867,8 +7694,8 @@ ProcessEventNotification(MPT_ADAPTER *io
-        */
-       for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
-               if (MptEvHandlers[cb_idx]) {
--                      devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Routing Event to event handler #%d\n",
--                                      ioc->name, cb_idx));
-+                      devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                          "Routing Event to event handler #%d\n", ioc->name, cb_idx));
-                       r += (*(MptEvHandlers[cb_idx]))(ioc, pEventReply);
-                       handlers++;
-               }
-@@ -6935,7 +7762,6 @@ mpt_fc_log_info(MPT_ADAPTER *ioc, u32 lo
-                       ioc->name, log_info, desc, (log_info & 0xFFFFFF));
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
  }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_spi_log_info - Log information returned from SCSI Parallel IOC.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -6943,7 +7769,7 @@ mpt_fc_log_info(MPT_ADAPTER *ioc, u32 lo
-  *    @log_info: U32 LogInfo word from the IOC
-  *
-  *    Refer to lsi/sp_log.h.
-- */
-+ **/
- static void
- mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
- {
-@@ -6953,8 +7779,6 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 l
-       switch (info) {
-       case 0x00010000:
-               desc = "bug! MID not found";
--              if (ioc->reload_fw == 0)
--                      ioc->reload_fw++;
-               break;
+@@ -736,28 +687,28 @@ csmisas_get_cntlr_config(unsigned long a
+       if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_CNTLR_CONFIG_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s - "
+            "Unable to read in csmi_sas_get_cntlr_config_buffer struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-       case 0x00020000:
-@@ -7149,7 +7973,6 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 l
-               "Compatibility Error: IME Size Limited to < 2TB", /* 3Dh */
-       };
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
+               return -ENODEV;
+       }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_sas_log_info - Log information returned from SAS IOC.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -7229,7 +8052,6 @@ union loginfo_type {
-                       sas_loginfo.dw.code, sas_loginfo.dw.subcode);
- }
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mpt_iocstatus_info_config - IOCSTATUS information for config pages
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -7531,8 +8353,7 @@ mpt_iocstatus_info(MPT_ADAPTER *ioc, u32
-       if (!desc)
-               return;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
--      dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s\n",
--          ioc->name, status, desc));
-+      dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s\n", ioc->name, status, desc));
- }
+       /* Clear the struct before filling in data. */
+-      memset( &karg.Configuration, 0, sizeof(CSMI_SAS_CNTLR_CONFIG));
++      memset(&karg.Configuration, 0, sizeof(CSMI_SAS_CNTLR_CONFIG));
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-@@ -7543,6 +8364,7 @@ EXPORT_SYMBOL(mpt_resume);
- EXPORT_SYMBOL(mpt_suspend);
- #endif
- EXPORT_SYMBOL(ioc_list);
-+EXPORT_SYMBOL(mpt_proc_root_dir);
- EXPORT_SYMBOL(mpt_register);
- EXPORT_SYMBOL(mpt_deregister);
- EXPORT_SYMBOL(mpt_event_register);
-@@ -7555,25 +8377,28 @@ EXPORT_SYMBOL(mpt_get_msg_frame);
- EXPORT_SYMBOL(mpt_put_msg_frame);
- EXPORT_SYMBOL(mpt_put_msg_frame_hi_pri);
- EXPORT_SYMBOL(mpt_free_msg_frame);
--EXPORT_SYMBOL(mpt_add_sge);
- EXPORT_SYMBOL(mpt_send_handshake_request);
- EXPORT_SYMBOL(mpt_verify_adapter);
- EXPORT_SYMBOL(mpt_GetIocState);
- EXPORT_SYMBOL(mpt_print_ioc_summary);
- EXPORT_SYMBOL(mpt_HardResetHandler);
-+EXPORT_SYMBOL(mpt_SoftResetHandler);
- EXPORT_SYMBOL(mpt_config);
- EXPORT_SYMBOL(mpt_findImVolumes);
- EXPORT_SYMBOL(mpt_alloc_fw_memory);
- EXPORT_SYMBOL(mpt_free_fw_memory);
- EXPORT_SYMBOL(mptbase_sas_persist_operation);
- EXPORT_SYMBOL(mpt_raid_phys_disk_pg0);
-+EXPORT_SYMBOL(mpt_raid_phys_disk_pg1);
-+EXPORT_SYMBOL(mpt_raid_phys_disk_get_num_paths);
-+EXPORT_SYMBOL(mpt_set_taskmgmt_in_progress_flag);
-+EXPORT_SYMBOL(mpt_clear_taskmgmt_in_progress_flag);
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    fusion_init - Fusion MPT base driver initialization routine.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int __init
- fusion_init(void)
- {
-@@ -7592,7 +8418,7 @@ fusion_init(void)
-       /*  Register ourselves (mptbase) in order to facilitate
-        *  EventNotification handling.
-        */
--      mpt_base_index = mpt_register(mpt_base_reply, MPTBASE_DRIVER);
-+      mpt_base_index = mpt_register(mptbase_reply, MPTBASE_DRIVER);
+       /* Fill in the data and return the structure to the calling
+        * program
+@@ -786,7 +737,7 @@ csmisas_get_cntlr_config(unsigned long a
+       karg.Configuration.BusAddress.PciAddress.bFunctionNumber =
+           PCI_FUNC(ioc->pcidev->devfn);
+       karg.Configuration.BusAddress.PciAddress.bReserved = 0;
+-      memcpy( &karg.Configuration.szSerialNumber, ioc->board_tracer, 16 );
++      memcpy(&karg.Configuration.szSerialNumber, ioc->board_tracer, 16);
+       karg.Configuration.usMajorRevision = ioc->facts.FWVersion.Struct.Major;
+       karg.Configuration.usMinorRevision = ioc->facts.FWVersion.Struct.Minor;
+       karg.Configuration.usBuildRevision = ioc->facts.FWVersion.Struct.Unit;
+@@ -819,11 +770,11 @@ csmisas_get_cntlr_config(unsigned long a
+               sizeof(CSMI_SAS_DRIVER_INFO_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s - "
+               "Unable to write out csmi_sas_get_driver_info_buffer @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-       /* Register for hard reset handling callbacks.
-        */
-@@ -7604,17 +8430,15 @@ fusion_init(void)
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
        return 0;
  }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    fusion_exit - Perform driver unload cleanup.
-  *
-  *    This routine frees all resources associated with each MPT adapter
-  *    and removes all %MPT_PROCFS_MPTBASEDIR entries.
-- */
-+ **/
- static void __exit
- fusion_exit(void)
- {
--
-       mpt_reset_deregister(mpt_base_index);
- #ifdef CONFIG_PROC_FS
---- a/drivers/message/fusion/mptbase.h
-+++ b/drivers/message/fusion/mptbase.h
-@@ -49,10 +49,6 @@
- #define MPTBASE_H_INCLUDED
- /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--#include <linux/kernel.h>
--#include <linux/pci.h>
--#include <linux/mutex.h>
--
- #include "lsi/mpi_type.h"
- #include "lsi/mpi.h"          /* Fusion MPI(nterface) basic defs */
- #include "lsi/mpi_ioc.h"      /* Fusion MPT IOC(ontroller) defs */
-@@ -76,9 +72,13 @@
- #define COPYRIGHT     "Copyright (c) 1999-2008 " MODULEAUTHOR
- #endif
+@@ -848,24 +799,24 @@ csmisas_get_cntlr_status(unsigned long a
+       if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_CNTLR_STATUS_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s - "
+            "Unable to read in csmi_sas_get_cntlr_status_buffer struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
--#define MPT_LINUX_VERSION_COMMON      "3.04.07"
--#define MPT_LINUX_PACKAGE_NAME                "@(#)mptlinux-3.04.07"
-+#define MPT_LINUX_VERSION_COMMON      "4.00.43.00"
-+#define MPT_LINUX_PACKAGE_NAME                "@(#)mptlinux-4.00.43.00"
- #define WHAT_MAGIC_STRING             "@" "(" "#" ")"
-+#define MPT_LINUX_MAJOR_VERSION               4
-+#define MPT_LINUX_MINOR_VERSION               00
-+#define MPT_LINUX_BUILD_VERSION               43
-+#define MPT_LINUX_RELEASE_VERSION     00
- #define show_mptmod_ver(s,ver)  \
-       printk(KERN_INFO "%s %s\n", s, ver);
-@@ -87,6 +87,8 @@
- /*
-  *  Fusion MPT(linux) driver configurable stuff...
-  */
-+#define MPT_POLLING_INTERVAL          1000    /* in milliseconds */
-+
- #define MPT_MAX_ADAPTERS              18
- #define MPT_MAX_PROTOCOL_DRIVERS      16
- #define MPT_MAX_BUS                   1       /* Do not change */
-@@ -134,6 +136,8 @@
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
- #define MPT_COALESCING_TIMEOUT                0x10
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
-+#define MPT_DMA_35BIT_MASK  0x00000007ffffffffULL
-+
- /*
-  * SCSI transfer rate defines.
-  */
-@@ -173,10 +177,21 @@
- #define MPT_SCSI_SG_DEPTH     40
- #endif
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
-+#ifdef  CONFIG_FUSION_MAX_FC_SGE
-+#if     CONFIG_FUSION_MAX_FC_SGE  < 16
-+#define MPT_SCSI_FC_SG_DEPTH  16
-+#elif   CONFIG_FUSION_MAX_FC_SGE  > 256
-+#define MPT_SCSI_FC_SG_DEPTH  256
-+#else
-+#define MPT_SCSI_FC_SG_DEPTH  CONFIG_FUSION_MAX_FC_SGE
-+#endif
-+#else
-+#define MPT_SCSI_FC_SG_DEPTH  40
-+#endif
-+
- /* debug print string length used for events and iocstatus */
--# define EVENT_DESCR_STR_SZ             100
-+# define EVENT_DESCR_STR_SZ           100
+       /* Fill in the data and return the structure to the calling
+        * program
+@@ -902,11 +853,11 @@ csmisas_get_cntlr_status(unsigned long a
+               sizeof(CSMI_SAS_CNTLR_STATUS_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s - "
+                   "Unable to write out csmi_sas_get_cntlr_status @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
--#define MPT_POLLING_INTERVAL          1000    /* in milliseconds */
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
+ }
  
- #ifdef __KERNEL__     /* { */
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-@@ -224,7 +239,6 @@ typedef struct _ATTO_CONFIG_PAGE_SCSI_PO
- } fATTO_CONFIG_PAGE_SCSI_PORT_2, MPI_POINTER PTR_ATTO_CONFIG_PAGE_SCSI_PORT_2,
-   ATTO_SCSIPortPage2_t, MPI_POINTER pATTO_SCSIPortPage2_t;
+@@ -940,19 +891,19 @@ csmisas_get_phy_info(unsigned long arg)
+       struct mptsas_devinfo   device_info;
+       int                     memory_pages;
+-      sasIoUnitPg0=NULL;
+-      sasPhyPg0=NULL;
+-      sasIoUnitPg0_data_sz=0;
+-      sasPhyPg0_data_sz=0;
++      sasIoUnitPg0 = NULL;
++      sasPhyPg0 = NULL;
++      sasIoUnitPg0_data_sz = 0;
++      sasPhyPg0_data_sz = 0;
+       memory_pages = get_order(sizeof(CSMI_SAS_PHY_INFO_BUFFER));
+       karg = (CSMI_SAS_PHY_INFO_BUFFER *)__get_free_pages(
+               GFP_KERNEL, memory_pages);
+-      if (!karg){
++      if (!karg) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to malloc CSMI_SAS_PHY_INFO_BUFFER "
+                       "malloc_data_sz=%d memory_pages=%d\n",
+-                      __FILE__, __LINE__, __FUNCTION__,
++                      __FILE__, __LINE__, __func__,
+                       (int)sizeof(CSMI_SAS_PHY_INFO_BUFFER), memory_pages);
+               return -ENOMEM;
+       }
+@@ -962,7 +913,7 @@ csmisas_get_phy_info(unsigned long arg)
+       if (copy_from_user(karg, uarg, sizeof(CSMI_SAS_PHY_INFO_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s - "
+               "Unable to read in csmisas_get_phy_info_buffer struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
+       }
+@@ -970,19 +921,19 @@ csmisas_get_phy_info(unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg->IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)karg, memory_pages);
+               return -ENODEV;
+       }
  
--
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /*
-  *  MPT protocol driver defs...
-@@ -372,8 +386,8 @@ typedef struct _VirtTarget {
-       struct scsi_target      *starget;
-       u8                       tflags;
-       u8                       ioc_id;
--      u8                       id;
--      u8                       channel;
-+      u8                       id;            /* logical target id */
-+      u8                       channel;       /* logical channel number */
-       u8                       minSyncFactor; /* 0xFF is async */
-       u8                       maxOffset;     /* 0 if async */
-       u8                       maxWidth;      /* 0 if narrow, 1 if wide */
-@@ -381,7 +395,7 @@ typedef struct _VirtTarget {
-       u8                       raidVolume;    /* set, if RAID Volume */
-       u8                       type;          /* byte 0 of Inquiry data */
-       u8                       deleted;       /* target in process of being removed */
--      u32                      num_luns;
-+      int                      num_luns;
- } VirtTarget;
- typedef struct _VirtDevice {
-@@ -427,42 +441,33 @@ do { \
- } while (0)
--/*
-- *    IOCTL structure and associated defines
-- */
--
--#define MPT_IOCTL_STATUS_DID_IOCRESET 0x01    /* IOC Reset occurred on the current*/
--#define MPT_IOCTL_STATUS_RF_VALID     0x02    /* The Reply Frame is VALID */
--#define MPT_IOCTL_STATUS_TIMER_ACTIVE 0x04    /* The timer is running */
--#define MPT_IOCTL_STATUS_SENSE_VALID  0x08    /* Sense data is valid */
--#define MPT_IOCTL_STATUS_COMMAND_GOOD 0x10    /* Command Status GOOD */
--#define MPT_IOCTL_STATUS_TMTIMER_ACTIVE       0x20    /* The TM timer is running */
--#define MPT_IOCTL_STATUS_TM_FAILED    0x40    /* User TM request failed */
--
--#define MPTCTL_RESET_OK                       0x01    /* Issue Bus Reset */
--
--typedef struct _MPT_IOCTL {
--      struct _MPT_ADAPTER     *ioc;
--      u8                       ReplyFrame[MPT_DEFAULT_FRAME_SIZE];    /* reply frame data */
--      u8                       sense[MPT_SENSE_BUFFER_ALLOC];
--      int                      wait_done;     /* wake-up value for this ioc */
--      u8                       rsvd;
--      u8                       status;        /* current command status */
--      u8                       reset;         /* 1 if bus reset allowed */
--      u8                       id;            /* target for reset */
--      struct mutex             ioctl_mutex;
--} MPT_IOCTL;
--
--#define MPT_SAS_MGMT_STATUS_RF_VALID  0x02    /* The Reply Frame is VALID */
--#define MPT_SAS_MGMT_STATUS_COMMAND_GOOD      0x10    /* Command Status GOOD */
--#define MPT_SAS_MGMT_STATUS_TM_FAILED 0x40    /* User TM request failed */
-+#define MPT_MGMT_STATUS_RF_VALID      0x01    /* The Reply Frame is VALID */
-+#define MPT_MGMT_STATUS_COMMAND_GOOD  0x02    /* Command Status GOOD */
-+#define MPT_MGMT_STATUS_PENDING               0x04    /* command is pending */
-+#define MPT_MGMT_STATUS_DID_IOCRESET  0x08    /* IOC Reset occurred on the current*/
-+#define MPT_MGMT_STATUS_SENSE_VALID   0x10    /* valid sense info */
-+#define MPT_MGMT_STATUS_TIMER_ACTIVE  0x20    /* obsolete */
-+#define MPT_MGMT_STATUS_FREE_MF               0x40    /* free the mf from complete routine */
-+
-+
-+#define INITIALIZE_MGMT_STATUS(status) \
-+      status = MPT_MGMT_STATUS_PENDING;
-+#define CLEAR_MGMT_STATUS(status) \
-+      status = 0;
-+#define CLEAR_MGMT_PENDING_STATUS(status) \
-+      status &= ~MPT_MGMT_STATUS_PENDING;
-+#define SET_MGMT_MSG_CONTEXT(msg_context, value) \
-+      msg_context = value;
--typedef struct _MPT_SAS_MGMT {
-+typedef struct _MPT_MGMT {
-       struct mutex             mutex;
-       struct completion        done;
-       u8                       reply[MPT_DEFAULT_FRAME_SIZE]; /* reply frame data */
-+      u8                       sense[MPT_SENSE_BUFFER_ALLOC];
-       u8                       status;        /* current command status */
--}MPT_SAS_MGMT;
-+      int                      completion_code;
-+      u32                      msg_context;
-+}MPT_MGMT;
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)karg, memory_pages);
+               return -ENODEV;
+       }
  
- /*
-  *  Event Structure and define
-@@ -534,7 +539,8 @@ struct inactive_raid_component_info {
- typedef       struct _RaidCfgData {
-       IOCPage2_t      *pIocPg2;               /* table of Raid Volumes */
-       IOCPage3_t      *pIocPg3;               /* table of physical disks */
--      struct mutex    inactive_list_mutex;
-+      IOCPage6_t      *pIocPg6;               /* table of IR static data */
-+      struct semaphore        inactive_list_mutex;
-       struct list_head        inactive_list; /* link list for physical
-                                               disk that belong in
-                                               inactive volumes */
-@@ -564,6 +570,9 @@ struct mptfc_rport_info
-       u8              flags;
- };
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
-+typedef void (*MPT_ADD_SGE)(char *pAddr, u32 flagslength, dma_addr_t dma_addr);
-+typedef void (*MPT_ADD_CHAIN)(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr);
-+
- /*
-  *  Adapter Structure - pci_dev specific. Maximum: MPT_MAX_ADAPTERS
-  */
-@@ -573,6 +582,9 @@ typedef struct _MPT_ADAPTER
-       int                      pci_irq;       /* This irq           */
-       char                     name[MPT_NAME_LENGTH]; /* "iocN"             */
-       char                     prod_name[MPT_NAME_LENGTH];    /* "LSIFC9x9"         */
-+#ifdef CONFIG_FUSION_LOGGING
-+      char                     evStr[EVENT_DESCR_STR_SZ]; /* used in mpt_display_event_info */
-+#endif
-       char                     board_name[16];
-       char                     board_assembly[16];
-       char                     board_tracer[16];
-@@ -584,8 +596,8 @@ typedef struct _MPT_ADAPTER
-       SYSIF_REGS __iomem      *chip;          /* == c8817000 (mmap) */
-       SYSIF_REGS __iomem      *pio_chip;      /* Programmed IO (downloadboot) */
-       u8                       bus_type;
--      u32                      mem_phys;      /* == f4020000 (mmap) */
--      u32                      pio_mem_phys;  /* Programmed IO (downloadboot) */
-+      unsigned long            mem_phys;      /* == f4020000 (mmap) */
-+      unsigned long            pio_mem_phys;  /* Programmed IO (downloadboot) */
-       int                      mem_size;      /* mmap memory size */
-       int                      number_of_buses;
-       int                      devices_per_bus;
-@@ -600,6 +612,8 @@ typedef struct _MPT_ADAPTER
-       int                      reply_depth;   /* Num Allocated reply frames */
-       int                      reply_sz;      /* Reply frame size */
-       int                      num_chain;     /* Number of chain buffers */
-+      MPT_ADD_SGE              add_sge;       /* Pointer to add_sge function */
-+      MPT_ADD_CHAIN            add_chain;     /* Pointer to add_chain function */
-               /* Pool of buffers for chaining. ReqToChain
-                * and ChainToChain track index of chain buffers.
-                * ChainBuffer (DMA) virt/phys addresses.
-@@ -628,31 +642,27 @@ typedef struct _MPT_ADAPTER
-       dma_addr_t               sense_buf_pool_dma;
-       u32                      sense_buf_low_dma;
-       u8                      *HostPageBuffer; /* SAS - host page buffer support */
--      u32                     HostPageBuffer_sz;
--      dma_addr_t              HostPageBuffer_dma;
-+      u32                      HostPageBuffer_sz;
-+      dma_addr_t               HostPageBuffer_dma;
-       int                      mtrr_reg;
-       struct pci_dev          *pcidev;        /* struct pci_dev pointer */
--      int                     bars;           /* bitmask of BAR's that must be configured */
--      int                     msi_enable;
-+      int                     bars;   /* bitmask of BAR's that must be configured */
-+      int                      msi_enable;
-       u8                      __iomem *memmap;        /* mmap address */
-       struct Scsi_Host        *sh;            /* Scsi Host pointer */
--      SpiCfgData              spi_data;       /* Scsi config. data */
--      RaidCfgData             raid_data;      /* Raid config. data */
--      SasCfgData              sas_data;       /* Sas config. data */
--      FcCfgData               fc_data;        /* Fc config. data */
--      MPT_IOCTL               *ioctl;         /* ioctl data pointer */
-+      SpiCfgData               spi_data;      /* Scsi config. data */
-+      RaidCfgData              raid_data;     /* Raid config. data */
-+      SasCfgData               sas_data;      /* Sas config. data */
-+      FcCfgData                fc_data;       /* Fc config. data */
-       struct proc_dir_entry   *ioc_dentry;
-       struct _MPT_ADAPTER     *alt_ioc;       /* ptr to 929 bound adapter port */
--      spinlock_t               diagLock;      /* diagnostic reset lock */
--      int                      diagPending;
-       u32                      biosVersion;   /* BIOS version from IO Unit Page 2 */
-       int                      eventTypes;    /* Event logging parameters */
-       int                      eventContext;  /* Next event context */
-       int                      eventLogSize;  /* Max number of cached events */
-       struct _mpt_ioctl_events *events;       /* pointer to event log */
-       u8                      *cached_fw;     /* Pointer to FW */
--      dma_addr_t              cached_fw_dma;
--      struct list_head         configQ;       /* linked list of config. requests */
-+      dma_addr_t               cached_fw_dma;
-       int                      hs_reply_idx;
- #ifndef MFCNT
-       u32                      pad0;
-@@ -665,13 +675,16 @@ typedef struct _MPT_ADAPTER
-       IOCFactsReply_t          facts;
-       PortFactsReply_t         pfacts[2];
-       FCPortPage0_t            fc_port_page0[2];
--      struct timer_list        persist_timer; /* persist table timer */
--      int                      persist_wait_done; /* persist completion flag */
--      u8                       persist_reply_frame[MPT_DEFAULT_FRAME_SIZE]; /* persist reply */
-       LANPage0_t               lan_cnfg_page0;
-       LANPage1_t               lan_cnfg_page1;
-+#if defined(CPQ_CIM)
-+      u32                      csmi_change_count;     /* count to track all IR
-+                                      events for CSMI */
-+      u8                       pci_slot_number; /* ioc page 1 - pci slot number */
-+#endif
+       /* Fill in the data and return the structure to the calling
+        * program
+@@ -1011,7 +962,7 @@ csmisas_get_phy_info(unsigned long arg)
+                */
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   ": FAILED: MPI_SASIOUNITPAGE0_PAGEVERSION: HEADER\n"));
+-              dcsmisasprintk(ioc, printk(": rc=%x\n",rc));
++              dcsmisasprintk(ioc, printk(": rc=%x\n", rc));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto sas_get_phy_info_exit;
+       }
+@@ -1020,7 +971,8 @@ csmisas_get_phy_info(unsigned long arg)
+               /* Don't check if this failed.  Already in a
+                * failure case.
+                */
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
++              dcsmisasprintk(ioc, printk(KERN_ERR
++                      ": hdr.ExtPageLength == 0\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto sas_get_phy_info_exit;
+       }
+@@ -1032,7 +984,8 @@ csmisas_get_phy_info(unsigned long arg)
+           sasIoUnitPg0_data_sz, &sasIoUnitPg0_dma);
  
-       u8                       ir_firmware; /* =1 if IR firmware detected */
-+
-       /*
-        * Description: errata_flag_1064
-        * If a PCIX read occurs within 1 or 2 cycles after the chip receives
-@@ -682,25 +695,46 @@ typedef struct _MPT_ADAPTER
-       int                      aen_event_read_flag; /* flag to indicate event log was read*/
-       u8                       FirstWhoInit;
-       u8                       upload_fw;     /* If set, do a fw upload */
--      u8                       reload_fw;     /* Force a FW Reload on next reset */
-       u8                       NBShiftFactor;  /* NB Shift Factor based on Block Size (Facts)  */
--      u8                       pad1[4];
-       u8                       DoneCtx;
-       u8                       TaskCtx;
-       u8                       InternalCtx;
--      spinlock_t               initializing_hba_lock;
--      int                      initializing_hba_lock_flag;
-       struct list_head         list;
-       struct net_device       *netdev;
-       struct list_head         sas_topology;
-       struct mutex             sas_topology_mutex;
--      struct mutex             sas_discovery_mutex;
--      u8                       sas_discovery_runtime;
--      u8                       sas_discovery_ignore_events;
-+      u8                       disable_hotplug_remove;
-+
-+      struct workqueue_struct  *fw_event_q;
-+      struct list_head         fw_event_list;
-+      spinlock_t               fw_event_lock;
-+      u8                       fw_events_off; /* if '1', then ignore events */
-+      char fw_event_q_name[20];
-+
-+      struct mptsas_portinfo  *hba_port_info; /* port_info object for the host */
-+      u64                      hba_port_sas_addr;
-+      u16                      hba_port_num_phy;
-+      struct list_head         sas_device_info_list;
-+      struct semaphore         sas_device_info_mutex;
-+      u8                       old_sas_discovery_protocal;
-+      u8                       sas_discovery_quiesce_io;
-       int                      sas_index; /* index refrencing */
--      MPT_SAS_MGMT             sas_mgmt;
--      struct work_struct       sas_persist_task;
-+      MPT_MGMT                 sas_mgmt;
-+      MPT_MGMT                 internal_cmds;
-+      MPT_MGMT                 mptbase_cmds; /* for sending config pages */
-+      MPT_MGMT                 taskmgmt_cmds;
-+      MPT_MGMT                 ioctl_cmds;            /* ioctl data pointer */
-+      spinlock_t               taskmgmt_lock; /* diagnostic reset lock */
-+      int                      taskmgmt_in_progress;
-+      u8                       taskmgmt_quiesce_io;
-+      u8                       ioc_reset_in_progress;
-+#if defined(CPQ_CIM)
-+      u8                       num_ports;
-+#endif
+       if (!sasIoUnitPg0) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++              dcsmisasprintk(ioc, printk(KERN_ERR
++                      ": pci_alloc_consistent: FAILED\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto sas_get_phy_info_exit;
+       }
+@@ -1048,7 +1001,7 @@ csmisas_get_phy_info(unsigned long arg)
+                */
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   ": FAILED: MPI_SASIOUNITPAGE0_PAGEVERSION: PAGE\n"));
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
++              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n", rc));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto sas_get_phy_info_exit;
+       }
+@@ -1058,27 +1011,30 @@ csmisas_get_phy_info(unsigned long arg)
+       /* Fill in information for each phy. */
+       for (ii = 0; ii < karg->Information.bNumberOfPhys; ii++) {
+-
+-/* EDM : dump IO Unit Page 0 data*/
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "---- IO UNIT PAGE 0 ------------\n"));
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "Handle=0x%X\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "---- IO UNIT PAGE 0 ------------\n"));
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "Handle=0x%X\n",
+                   le16_to_cpu(sasIoUnitPg0->PhyData[ii].AttachedDeviceHandle)));
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "Controller Handle=0x%X\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "Controller Handle=0x%X\n",
+                   le16_to_cpu(sasIoUnitPg0->PhyData[ii].ControllerDevHandle)));
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "Port=0x%X\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "Port=0x%X\n",
+                   sasIoUnitPg0->PhyData[ii].Port));
+               dcsmisasprintk(ioc, printk(KERN_DEBUG "Port Flags=0x%X\n",
+                   sasIoUnitPg0->PhyData[ii].PortFlags));
+               dcsmisasprintk(ioc, printk(KERN_DEBUG "PHY Flags=0x%X\n",
+                   sasIoUnitPg0->PhyData[ii].PhyFlags));
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "Negotiated Link Rate=0x%X\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "Negotiated Link Rate=0x%X\n",
+                   sasIoUnitPg0->PhyData[ii].NegotiatedLinkRate));
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "Controller PHY Device Info=0x%X\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "Controller PHY Device Info=0x%X\n",
+                   le32_to_cpu(sasIoUnitPg0->PhyData[ii].ControllerPhyDeviceInfo)));
+               dcsmisasprintk(ioc, printk(KERN_DEBUG "DiscoveryStatus=0x%X\n",
+                   le32_to_cpu(sasIoUnitPg0->PhyData[ii].DiscoveryStatus)));
+               dcsmisasprintk(ioc, printk(KERN_DEBUG "\n"));
+-/* EDM : debug data */
+               /* PHY stuff. */
+               karg->Information.Phy[ii].bPortIdentifier =
+@@ -1147,13 +1103,14 @@ csmisas_get_phy_info(unsigned long arg)
+               if ((rc = mpt_config(ioc, &cfg)) != 0) {
+                       dcsmisasprintk(ioc, printk(KERN_ERR
+                           ": FAILED: MPI_SASPHY0_PAGEVERSION: HEADER\n"));
+-                      dcsmisasprintk(ioc, printk(": rc=%x\n",rc));
++                      dcsmisasprintk(ioc, printk(": rc=%x\n", rc));
+                       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       goto sas_get_phy_info_exit;
+               }
  
-+      char                     reset_work_q_name[20];
-+      struct workqueue_struct *reset_work_q;
-+      struct delayed_work      fault_reset_work;
-       struct work_struct       fc_setup_reset_work;
-       struct list_head         fc_rports;
-       struct work_struct       fc_lsc_work;
-@@ -709,14 +743,27 @@ typedef struct _MPT_ADAPTER
-       struct work_struct       fc_rescan_work;
-       char                     fc_rescan_work_q_name[20];
-       struct workqueue_struct *fc_rescan_work_q;
-+      unsigned long             hard_resets;          /* driver forced bus resets count */
-+      unsigned long             soft_resets;          /* fw/external bus resets count */
-+      unsigned long             timeouts;             /* cmd timeouts */
-       struct scsi_cmnd        **ScsiLookup;
-       spinlock_t                scsi_lookup_lock;
--
--      char                     reset_work_q_name[20];
--      struct workqueue_struct *reset_work_q;
--      struct delayed_work      fault_reset_work;
--      spinlock_t               fault_reset_work_lock;
--
-+      int                       sdev_queue_depth;     /* sdev queue depth */
-+      u64                       dma_mask;
-+      u32                       broadcast_aen_busy;
-+#if defined(DIAG_BUFFER_SUPPORT)
-+      u8                      *DiagBuffer[MPI_DIAG_BUF_TYPE_COUNT];
-+      u32                     DataSize[MPI_DIAG_BUF_TYPE_COUNT];
-+      u32                     DiagBuffer_sz[MPI_DIAG_BUF_TYPE_COUNT];
-+      dma_addr_t              DiagBuffer_dma[MPI_DIAG_BUF_TYPE_COUNT];
-+      u8                      TraceLevel[MPI_DIAG_BUF_TYPE_COUNT];
-+      u8                      DiagBuffer_Status[MPI_DIAG_BUF_TYPE_COUNT];
-+      u32                     UniqueId[MPI_DIAG_BUF_TYPE_COUNT];
-+      u32                     ExtendedType[MPI_DIAG_BUF_TYPE_COUNT];
-+      u32                     ProductSpecific[MPI_DIAG_BUF_TYPE_COUNT][4];
-+#endif
-+      u8                      sg_addr_size;
-+      u8                      SGE_size;
- } MPT_ADAPTER;
+               if (hdr.ExtPageLength == 0) {
+-                      dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++                      dcsmisasprintk(ioc, printk(KERN_ERR
++                              ": pci_alloc_consistent: FAILED\n"));
+                       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       goto sas_get_phy_info_exit;
+               }
+@@ -1164,8 +1121,9 @@ csmisas_get_phy_info(unsigned long arg)
+               sasPhyPg0 = (SasPhyPage0_t *) pci_alloc_consistent(
+                   ioc->pcidev, sasPhyPg0_data_sz, &sasPhyPg0_dma);
  
- /*
-@@ -753,13 +800,12 @@ typedef struct _mpt_sge {
-       dma_addr_t      Address;
- } MptSge_t;
+-              if (! sasPhyPg0) {
+-                      dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++              if (!sasPhyPg0) {
++                      dcsmisasprintk(ioc, printk(KERN_ERR
++                              ": pci_alloc_consistent: FAILED\n"));
+                       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       goto sas_get_phy_info_exit;
+               }
+@@ -1177,34 +1135,37 @@ csmisas_get_phy_info(unsigned long arg)
+               if ((rc = mpt_config(ioc, &cfg)) != 0) {
+                       dcsmisasprintk(ioc, printk(KERN_ERR
+                           ": FAILED: MPI_SASPHY0_PAGEVERSION: PAGE\n"));
+-                      dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
++                      dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n", rc));
+                       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       pci_free_consistent(ioc->pcidev, sasPhyPg0_data_sz,
+                           (u8 *) sasPhyPg0, sasPhyPg0_dma);
+                       goto sas_get_phy_info_exit;
+               }
  
--#define mpt_addr_size() \
--      ((sizeof(dma_addr_t) == sizeof(u64)) ? MPI_SGE_FLAGS_64_BIT_ADDRESSING : \
--              MPI_SGE_FLAGS_32_BIT_ADDRESSING)
--
--#define mpt_msg_flags() \
--      ((sizeof(dma_addr_t) == sizeof(u64)) ? MPI_SCSIIO_MSGFLGS_SENSE_WIDTH_64 : \
--              MPI_SCSIIO_MSGFLGS_SENSE_WIDTH_32)
-+#define mpt_msg_flags(ioc) \
-+      (ioc->sg_addr_size == sizeof(u64)) ? MPI_SCSIIO_MSGFLGS_SENSE_WIDTH_64 : \
-+              MPI_SCSIIO_MSGFLGS_SENSE_WIDTH_32
-+
-+#define MPT_SGE_FLAGS_64_BIT_ADDRESSING \
-+      (MPI_SGE_FLAGS_64_BIT_ADDRESSING << MPI_SGE_FLAGS_SHIFT)
+-/* EDM : dump PHY Page 0 data*/
+               memcpy(&sas_address, &sasPhyPg0->SASAddress, sizeof(u64));
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "---- SAS PHY PAGE 0 ------------\n"));
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "---- SAS PHY PAGE 0 ------------\n"));
+               dcsmisasprintk(ioc, printk(KERN_DEBUG "Handle=0x%X\n",
+                   le16_to_cpu(sasPhyPg0->AttachedDevHandle)));
+               dcsmisasprintk(ioc, printk(KERN_DEBUG "SAS Address=0x%llX\n",
+                   (unsigned long long)sas_address));
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "Attached PHY Identifier=0x%X\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "Attached PHY Identifier=0x%X\n",
+                   sasPhyPg0->AttachedPhyIdentifier));
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "Attached Device Info=0x%X\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "Attached Device Info=0x%X\n",
+                   le32_to_cpu(sasPhyPg0->AttachedDeviceInfo)));
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "Programmed Link Rate=0x%X\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "Programmed Link Rate=0x%X\n",
+                   sasPhyPg0->ProgrammedLinkRate));
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "Hardware Link Rate=0x%X\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "Hardware Link Rate=0x%X\n",
+                   sasPhyPg0->HwLinkRate));
+               dcsmisasprintk(ioc, printk(KERN_DEBUG "Change Count=0x%X\n",
+                   sasPhyPg0->ChangeCount));
+               dcsmisasprintk(ioc, printk(KERN_DEBUG "PHY Info=0x%X\n",
+                   le32_to_cpu(sasPhyPg0->PhyInfo)));
+               dcsmisasprintk(ioc, printk(KERN_DEBUG "\n"));
+-/* EDM : debug data */
+               /* save the data */
+@@ -1284,8 +1245,9 @@ csmisas_get_phy_info(unsigned long arg)
+               }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /*
-@@ -778,26 +824,10 @@ typedef struct _mpt_sge {
+               karg->Information.Phy[ii].bPhyChangeCount = sasPhyPg0->ChangeCount;
+-              if( sasPhyPg0->PhyInfo & MPI_SAS_PHY0_PHYINFO_VIRTUAL_PHY )
+-                      karg->Information.Phy[ii].bPhyFeatures = CSMI_SAS_PHY_VIRTUAL_SMP;
++              if (sasPhyPg0->PhyInfo & MPI_SAS_PHY0_PHYINFO_VIRTUAL_PHY)
++                      karg->Information.Phy[ii].bPhyFeatures
++                         = CSMI_SAS_PHY_VIRTUAL_SMP;
+               /* Fill in Attached Device
+                * Initiator Port Protocol.
+@@ -1295,17 +1257,17 @@ csmisas_get_phy_info(unsigned long arg)
+               protocol = le32_to_cpu(sasPhyPg0->AttachedDeviceInfo) & 0x78;
+               karg->Information.Phy[ii].Attached.bInitiatorPortProtocol = 0;
+               if (protocol & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
+-                    karg->Information.Phy[ii].Attached.bInitiatorPortProtocol =
+-                          CSMI_SAS_PROTOCOL_SSP;
++                    karg->Information.Phy[ii].Attached.bInitiatorPortProtocol
++                        = CSMI_SAS_PROTOCOL_SSP;
+               if (protocol & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
+-                   karg->Information.Phy[ii].Attached.bInitiatorPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_STP;
++                   karg->Information.Phy[ii].Attached.bInitiatorPortProtocol
++                       |= CSMI_SAS_PROTOCOL_STP;
+               if (protocol & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
+-                   karg->Information.Phy[ii].Attached.bInitiatorPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SMP;
++                   karg->Information.Phy[ii].Attached.bInitiatorPortProtocol
++                       |= CSMI_SAS_PROTOCOL_SMP;
+               if (protocol & MPI_SAS_DEVICE_INFO_SATA_HOST)
+-                   karg->Information.Phy[ii].Attached.bInitiatorPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SATA;
++                   karg->Information.Phy[ii].Attached.bInitiatorPortProtocol
++                       |= CSMI_SAS_PROTOCOL_SATA;
+               /* Fill in Phy Target Port
+                * Protocol. Bits 10:7
+@@ -1314,17 +1276,17 @@ csmisas_get_phy_info(unsigned long arg)
+               protocol = le32_to_cpu(sasPhyPg0->AttachedDeviceInfo) & 0x780;
+               karg->Information.Phy[ii].Attached.bTargetPortProtocol = 0;
+               if (protocol & MPI_SAS_DEVICE_INFO_SSP_TARGET)
+-                      karg->Information.Phy[ii].Attached.bTargetPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SSP;
++                      karg->Information.Phy[ii].Attached.bTargetPortProtocol
++                          |= CSMI_SAS_PROTOCOL_SSP;
+               if (protocol & MPI_SAS_DEVICE_INFO_STP_TARGET)
+-                      karg->Information.Phy[ii].Attached.bTargetPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_STP;
++                      karg->Information.Phy[ii].Attached.bTargetPortProtocol
++                          |= CSMI_SAS_PROTOCOL_STP;
+               if (protocol & MPI_SAS_DEVICE_INFO_SMP_TARGET)
+-                      karg->Information.Phy[ii].Attached.bTargetPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SMP;
++                      karg->Information.Phy[ii].Attached.bTargetPortProtocol
++                          |= CSMI_SAS_PROTOCOL_SMP;
+               if (protocol & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
+-                      karg->Information.Phy[ii].Attached.bTargetPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SATA;
++                      karg->Information.Phy[ii].Attached.bTargetPortProtocol
++                          |= CSMI_SAS_PROTOCOL_SATA;
+               /* Fill in Attached device type */
+@@ -1353,7 +1315,8 @@ csmisas_get_phy_info(unsigned long arg)
+               }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+               /* Identify Info. */
+-              switch (le32_to_cpu(sasIoUnitPg0->PhyData[ii].ControllerPhyDeviceInfo) &
++              switch (le32_to_cpu
++                  (sasIoUnitPg0->PhyData[ii].ControllerPhyDeviceInfo) &
+                   MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
+               case MPI_SAS_DEVICE_INFO_NO_DEVICE:
+@@ -1383,18 +1346,18 @@ csmisas_get_phy_info(unsigned long arg)
+               protocol = le32_to_cpu(
+                   sasIoUnitPg0->PhyData[ii].ControllerPhyDeviceInfo) & 0x78;
+               karg->Information.Phy[ii].Identify.bInitiatorPortProtocol = 0;
+-              if( protocol & MPI_SAS_DEVICE_INFO_SSP_INITIATOR )
+-                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SSP;
+-              if( protocol & MPI_SAS_DEVICE_INFO_STP_INITIATOR )
+-                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_STP;
+-              if( protocol & MPI_SAS_DEVICE_INFO_SMP_INITIATOR )
+-                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SMP;
+-              if( protocol & MPI_SAS_DEVICE_INFO_SATA_HOST )
+-                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SATA;
++              if (protocol & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
++                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol
++                       |= CSMI_SAS_PROTOCOL_SSP;
++              if (protocol & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
++                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol
++                       |= CSMI_SAS_PROTOCOL_STP;
++              if (protocol & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
++                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol
++                       |= CSMI_SAS_PROTOCOL_SMP;
++              if (protocol & MPI_SAS_DEVICE_INFO_SATA_HOST)
++                   karg->Information.Phy[ii].Identify.bInitiatorPortProtocol
++                       |= CSMI_SAS_PROTOCOL_SATA;
+               /* Fill in Phy Target Port Protocol. Bits 10:7
+                * More than one bit can be set, fall through cases.
+@@ -1402,18 +1365,18 @@ csmisas_get_phy_info(unsigned long arg)
+               protocol = le32_to_cpu(
+                   sasIoUnitPg0->PhyData[ii].ControllerPhyDeviceInfo) & 0x780;
+               karg->Information.Phy[ii].Identify.bTargetPortProtocol = 0;
+-              if( protocol & MPI_SAS_DEVICE_INFO_SSP_TARGET )
+-                      karg->Information.Phy[ii].Identify.bTargetPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SSP;
+-              if( protocol & MPI_SAS_DEVICE_INFO_STP_TARGET )
+-                      karg->Information.Phy[ii].Identify.bTargetPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_STP;
+-              if( protocol & MPI_SAS_DEVICE_INFO_SMP_TARGET )
+-                      karg->Information.Phy[ii].Identify.bTargetPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SMP;
+-              if( protocol & MPI_SAS_DEVICE_INFO_SATA_DEVICE )
+-                      karg->Information.Phy[ii].Identify.bTargetPortProtocol |=
+-                          CSMI_SAS_PROTOCOL_SATA;
++              if (protocol & MPI_SAS_DEVICE_INFO_SSP_TARGET)
++                      karg->Information.Phy[ii].Identify.bTargetPortProtocol
++                          |= CSMI_SAS_PROTOCOL_SSP;
++              if (protocol & MPI_SAS_DEVICE_INFO_STP_TARGET)
++                      karg->Information.Phy[ii].Identify.bTargetPortProtocol
++                          |= CSMI_SAS_PROTOCOL_STP;
++              if (protocol & MPI_SAS_DEVICE_INFO_SMP_TARGET)
++                      karg->Information.Phy[ii].Identify.bTargetPortProtocol
++                          |= CSMI_SAS_PROTOCOL_SMP;
++              if (protocol & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
++                      karg->Information.Phy[ii].Identify.bTargetPortProtocol
++                          |= CSMI_SAS_PROTOCOL_SATA;
+               /* Setup SAS Address for the attached device */
+               if (sasPhyPg0->AttachedDevHandle) {
+@@ -1450,13 +1413,13 @@ sas_get_phy_info_exit:
+           sizeof(CSMI_SAS_PHY_INFO_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s - "
+                   "Unable to write out csmisas_get_phy_info_buffer @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__,  __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
+       }
  
--#define SCSI_STD_SENSE_BYTES    18
--#define SCSI_STD_INQUIRY_BYTES  36
--#define SCSI_MAX_INQUIRY_BYTES  96
--
- /*
-  * MPT_SCSI_HOST defines - Used by the IOCTL and the SCSI drivers
-  * Private to the driver.
-  */
--/* LOCAL structure and fields used when processing
-- * internally generated commands. These include:
-- * bus scan, dv and config requests.
-- */
--typedef struct _MPT_LOCAL_REPLY {
--      ConfigPageHeader_t header;
--      int     completion;
--      u8      sense[SCSI_STD_SENSE_BYTES];
--      u8      scsiStatus;
--      u8      skip;
--      u32     pad;
--} MPT_LOCAL_REPLY;
- #define MPT_HOST_BUS_UNKNOWN          (0xFF)
- #define MPT_HOST_TOO_MANY_TM          (0x05)
-@@ -813,13 +843,6 @@ typedef struct _MPT_LOCAL_REPLY {
- #define MPT_NVRAM_WIDE_DISABLE                (0x00100000)
- #define MPT_NVRAM_BOOT_CHOICE         (0x00200000)
--/* The TM_STATE variable is used to provide strict single threading of TM
-- * requests as well as communicate TM error conditions.
-- */
--#define TM_STATE_NONE          (0)
--#define       TM_STATE_IN_PROGRESS   (1)
--#define       TM_STATE_ERROR         (2)
--
- typedef enum {
-       FC,
-       SPI,
-@@ -828,63 +851,28 @@ typedef enum {
- typedef struct _MPT_SCSI_HOST {
-       MPT_ADAPTER              *ioc;
--      int                       port;
--      u32                       pad0;
--      MPT_LOCAL_REPLY          *pLocal;               /* used for internal commands */
--      struct timer_list         timer;
--              /* Pool of memory for holding SCpnts before doing
--               * OS callbacks. freeQ is the free pool.
--               */
--      u8                        tmPending;
--      u8                        resetPending;
--      u8                        negoNvram;            /* DV disabled, nego NVRAM */
--      u8                        pad1;
--      u8                        tmState;
--      u8                        rsvd[2];
--      MPT_FRAME_HDR            *cmdPtr;               /* Ptr to nonOS request */
--      struct scsi_cmnd         *abortSCpnt;
--      MPT_LOCAL_REPLY           localReply;           /* internal cmd reply struct */
--      unsigned long             hard_resets;          /* driver forced bus resets count */
--      unsigned long             soft_resets;          /* fw/external bus resets count */
--      unsigned long             timeouts;             /* cmd timeouts */
-       ushort                    sel_timeout[MPT_MAX_FC_DEVICES];
-       char                      *info_kbuf;
--      wait_queue_head_t         scandv_waitq;
--      int                       scandv_wait_done;
-       long                      last_queue_full;
--      u16                       tm_iocstatus;
-       u16                       spi_pending;
-       struct list_head          target_reset_list;
- } MPT_SCSI_HOST;
+       free_pages((unsigned long)karg, memory_pages);
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
+ }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /*
-- *    More Dynamic Multi-Pathing stuff...
-- */
--
--/* Forward decl, a strange C thing, to prevent gcc compiler warnings */
--struct scsi_cmnd;
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-  * Generic structure passed to the base mpt_config function.
-  */
- typedef struct _x_config_parms {
--      struct list_head         linkage;       /* linked list */
--      struct timer_list        timer;         /* timer function for this request  */
-       union {
-               ConfigExtendedPageHeader_t      *ehdr;
-               ConfigPageHeader_t      *hdr;
-       } cfghdr;
-       dma_addr_t               physAddr;
--      int                      wait_done;     /* wait for this request */
-       u32                      pageAddr;      /* properly formatted */
-+      u16                      status;
-       u8                       action;
-       u8                       dir;
-       u8                       timeout;       /* seconds */
--      u8                       pad1;
--      u16                      status;
--      u16                      pad2;
- } CONFIGPARMS;
+@@ -1479,30 +1442,28 @@ csmisas_set_phy_info(unsigned long arg)
+       if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_SET_PHY_INFO_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_set_phy_info struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-@@ -909,32 +897,38 @@ extern MPT_FRAME_HDR     *mpt_get_msg_frame(
- extern void    mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
- extern void    mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
- extern void    mpt_put_msg_frame_hi_pri(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
--extern void    mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr);
--
- extern int     mpt_send_handshake_request(u8 cb_idx, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag);
- extern int     mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp);
- extern u32     mpt_GetIocState(MPT_ADAPTER *ioc, int cooked);
- extern void    mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buf, int *size, int len, int showlan);
- extern int     mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
-+extern int     mpt_SoftResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
- extern int     mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *cfg);
- extern int     mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size);
- extern void    mpt_free_fw_memory(MPT_ADAPTER *ioc);
- extern int     mpt_findImVolumes(MPT_ADAPTER *ioc);
- extern int     mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
- extern int     mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage0_t phys_disk);
-+extern int     mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage1_t phys_disk);
-+extern int     mpt_raid_phys_disk_get_num_paths(MPT_ADAPTER *ioc, u8 phys_disk_num);
-+
-+extern int     mpt_set_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc);
-+extern void    mpt_clear_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc);
- extern void     mpt_halt_firmware(MPT_ADAPTER *ioc);
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__,  __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__,  __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
- /*
-  *  Public data decl's...
-  */
- extern struct list_head         ioc_list;
-+extern struct proc_dir_entry  *mpt_proc_root_dir;
-+extern int mpt_debug_level;
- extern int mpt_fwfault_debug;
+-/* TODO - implement IOCTL here */
+       karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_BAD_CNTL_CODE;
+       dcsmisasprintk(ioc, printk(KERN_DEBUG ": not implemented\n"));
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- #endif                /* } __KERNEL__ */
+-// cim_set_phy_info_exit:
  
--#ifdef CONFIG_64BIT
-+#if defined(__alpha__) || defined(__sparc_v9__) || defined(__ia64__) || defined(__x86_64__) || defined(__powerpc64__)
- #define CAST_U32_TO_PTR(x)    ((void *)(u64)x)
- #define CAST_PTR_TO_U32(x)    ((u32)(u64)x)
- #else
-@@ -956,7 +952,6 @@ extern struct list_head      ioc_list;
- #define MPT_SGE_FLAGS_END_OF_BUFFER           (0x40000000)
- #define MPT_SGE_FLAGS_LOCAL_ADDRESS           (0x08000000)
- #define MPT_SGE_FLAGS_DIRECTION                       (0x04000000)
--#define MPT_SGE_FLAGS_ADDRESSING              (mpt_addr_size() << MPI_SGE_FLAGS_SHIFT)
- #define MPT_SGE_FLAGS_END_OF_LIST             (0x01000000)
- #define MPT_SGE_FLAGS_TRANSACTION_ELEMENT     (0x00000000)
-@@ -969,14 +964,12 @@ extern struct list_head    ioc_list;
-        MPT_SGE_FLAGS_END_OF_BUFFER |  \
-        MPT_SGE_FLAGS_END_OF_LIST |    \
-        MPT_SGE_FLAGS_SIMPLE_ELEMENT | \
--       MPT_SGE_FLAGS_ADDRESSING | \
-        MPT_TRANSFER_IOC_TO_HOST)
- #define MPT_SGE_FLAGS_SSIMPLE_WRITE \
-       (MPT_SGE_FLAGS_LAST_ELEMENT |   \
-        MPT_SGE_FLAGS_END_OF_BUFFER |  \
-        MPT_SGE_FLAGS_END_OF_LIST |    \
-        MPT_SGE_FLAGS_SIMPLE_ELEMENT | \
--       MPT_SGE_FLAGS_ADDRESSING | \
-        MPT_TRANSFER_HOST_TO_IOC)
- /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
---- a/drivers/message/fusion/mptctl.c
-+++ b/drivers/message/fusion/mptctl.c
-@@ -45,6 +45,7 @@
- */
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+       /* Copy the data from kernel memory to user memory
+        */
+@@ -1510,11 +1471,11 @@ csmisas_set_phy_info(unsigned long arg)
+                               sizeof(CSMI_SAS_SET_PHY_INFO_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to write out csmi_sas_set_phy_info @ %p\n",
+-                              __FILE__, __LINE__, __FUNCTION__, uarg);
++                              __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-+#include <linux/version.h>
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/errno.h>
-@@ -71,6 +72,15 @@
- #include "mptbase.h"
- #include "mptctl.h"
-+#if defined(CPQ_CIM)
-+#include "mptsas.h"
-+#include "csmi/csmisas.h"
-+#endif // CPQ_CIM
-+
-+#if defined(DIAG_BUFFER_SUPPORT)
-+#include "rejected_ioctls/diag_buffer.h"
-+#endif
-+
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- #define my_NAME               "Fusion MPT misc device (ioctl) driver"
- #define my_VERSION    MPT_LINUX_VERSION_COMMON
-@@ -84,6 +94,7 @@ MODULE_VERSION(my_VERSION);
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
  
- static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS;
-+static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS;
- static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait );
-@@ -112,6 +123,42 @@ static int mptctl_do_reset(unsigned long
- static int mptctl_hp_hostinfo(unsigned long arg, unsigned int cmd);
- static int mptctl_hp_targetinfo(unsigned long arg);
-+#if defined(CPQ_CIM)
-+/* csmisas proto's*/
-+static int csmisas_get_driver_info(unsigned long arg);
-+static int csmisas_get_cntlr_status(unsigned long arg);
-+static int csmisas_get_cntlr_config(unsigned long arg);
-+static int csmisas_get_phy_info(unsigned long arg);
-+static int csmisas_get_scsi_address(unsigned long arg);
-+static int csmisas_get_link_errors(unsigned long arg);
-+static int csmisas_smp_passthru(unsigned long arg);
-+static int csmisas_firmware_download(unsigned long arg);
-+static int csmisas_get_raid_info(unsigned long arg);
-+static int csmisas_get_raid_config(unsigned long arg);
-+static int csmisas_get_raid_features(unsigned long arg);
-+static int csmisas_set_raid_control(unsigned long arg);
-+static int csmisas_get_raid_element(unsigned long arg);
-+static int csmisas_set_raid_operation(unsigned long arg);
-+static int csmisas_set_phy_info(unsigned long arg);
-+static int csmisas_ssp_passthru(unsigned long arg);
-+static int csmisas_stp_passthru(unsigned long arg);
-+static int csmisas_get_sata_signature(unsigned long arg);
-+static int csmisas_get_device_address(unsigned long arg);
-+static int csmisas_task_managment(unsigned long arg);
-+static int csmisas_phy_control(unsigned long arg);
-+static int csmisas_get_connector_info(unsigned long arg);
-+static int csmisas_get_location(unsigned long arg);
-+#endif // CPQ_CIM
-+
-+#if defined(DIAG_BUFFER_SUPPORT)
-+/* diag_buffer proto's */
-+static int mptctl_register_diag_buffer(unsigned long arg);
-+static int mptctl_release_diag_buffer(unsigned long arg);
-+static int mptctl_unregister_diag_buffer(unsigned long arg);
-+static int mptctl_query_diag_buffer(unsigned long arg);
-+static int mptctl_read_diag_buffer(unsigned long arg);
-+#endif // DIAG_BUFFER_SUPPORT
-+
- static int  mptctl_probe(struct pci_dev *, const struct pci_device_id *);
- static void mptctl_remove(struct pci_dev *);
+ }
+@@ -1541,24 +1502,24 @@ csmisas_get_scsi_address(unsigned long a
+           sizeof(CSMI_SAS_GET_SCSI_ADDRESS_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_get_scsi_address struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-@@ -127,10 +174,6 @@ static MptSge_t *kbuf_alloc_2_sgl(int by
-               struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc);
- static void kfree_sgl(MptSge_t *sgl, dma_addr_t sgl_dma,
-               struct buflist *buflist, MPT_ADAPTER *ioc);
--static void mptctl_timeout_expired (MPT_IOCTL *ioctl);
--static int  mptctl_bus_reset(MPT_IOCTL *ioctl);
--static int mptctl_set_tm_flags(MPT_SCSI_HOST *hd);
--static void mptctl_free_tm_flags(MPT_ADAPTER *ioc);
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
- /*
-  * Reset Handler cleanup function
-@@ -183,10 +226,10 @@ mptctl_syscall_down(MPT_ADAPTER *ioc, in
-       int rc = 0;
-       if (nonblock) {
--              if (!mutex_trylock(&ioc->ioctl->ioctl_mutex))
-+              if (!mutex_trylock(&ioc->ioctl_cmds.mutex))
-                       rc = -EAGAIN;
-       } else {
--              if (mutex_lock_interruptible(&ioc->ioctl->ioctl_mutex))
-+              if (mutex_lock_interruptible(&ioc->ioctl_cmds.mutex))
-                       rc = -ERESTARTSYS;
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
        }
-       return rc;
-@@ -202,132 +245,104 @@ mptctl_syscall_down(MPT_ADAPTER *ioc, in
- static int
- mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
- {
--      char *sense_data;
--      int sz, req_index;
--      u16 iocStatus;
--      u8 cmd;
--
--      if (req)
--               cmd = req->u.hdr.Function;
--      else
--              return 1;
--      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\tcompleting mpi function (0x%02X), req=%p, "
--          "reply=%p\n", ioc->name,  req->u.hdr.Function, req, reply));
--
--      if (ioc->ioctl) {
-+      char    *sense_data;
-+      int     req_index;
-+      int     sz;
--              if (reply==NULL) {
-+      if (!req)
-+              return 0;
--                      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_reply() NULL Reply "
--                              "Function=%x!\n", ioc->name, cmd));
-+      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "completing mpi function "
-+          "(0x%02X), req=%p, reply=%p\n", ioc->name,  req->u.hdr.Function,
-+          req, reply));
--                      ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
--                      ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
-+      /*
-+       * Handling continuation of the same reply. Processing the first
-+       * reply, and eating the other replys that come later.
-+       */
-+      if (ioc->ioctl_cmds.msg_context != req->u.hdr.MsgContext)
-+              goto out_continuation;
  
--                      /* We are done, issue wake up
--                      */
--                      ioc->ioctl->wait_done = 1;
--                      wake_up (&mptctl_wait);
--                      return 1;
-+      ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
--              }
-+      if (!reply)
-+              goto out;
+       /* reverse byte order the sas address */
+       memcpy(&sas_address, karg.bSASAddress, sizeof(u64));
+@@ -1586,11 +1547,11 @@ csmisas_get_scsi_address(unsigned long a
+           sizeof(CSMI_SAS_GET_SCSI_ADDRESS_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to write out csmi_sas_get_scsi_address @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
--              /* Copy the reply frame (which much exist
--               * for non-SCSI I/O) to the IOC structure.
--               */
--              memcpy(ioc->ioctl->ReplyFrame, reply,
--                      min(ioc->reply_sz, 4*reply->u.reply.MsgLength));
--              ioc->ioctl->status |= MPT_IOCTL_STATUS_RF_VALID;
-+      ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
-+      sz = min(ioc->reply_sz, 4*reply->u.reply.MsgLength);
-+      memcpy(ioc->ioctl_cmds.reply, reply, sz);
--              /* Set the command status to GOOD if IOC Status is GOOD
--               * OR if SCSI I/O cmd and data underrun or recovered error.
--               */
--              iocStatus = le16_to_cpu(reply->u.reply.IOCStatus) & MPI_IOCSTATUS_MASK;
--              if (iocStatus  == MPI_IOCSTATUS_SUCCESS)
--                      ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
--
--              if (iocStatus || reply->u.reply.IOCLogInfo)
--                      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\tiocstatus (0x%04X), "
--                              "loginfo (0x%08X)\n", ioc->name,
--                              iocStatus,
--                              le32_to_cpu(reply->u.reply.IOCLogInfo)));
--
--              if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
--                      (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
--
--                      if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState)
--                              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                                      "\tscsi_status (0x%02x), scsi_state (0x%02x), "
--                                      "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name,
--                                      reply->u.sreply.SCSIStatus,
--                                      reply->u.sreply.SCSIState,
--                                      le16_to_cpu(reply->u.sreply.TaskTag),
--                                      le32_to_cpu(reply->u.sreply.TransferCount)));
--
--                      ioc->ioctl->reset &= ~MPTCTL_RESET_OK;
--
--                      if ((iocStatus == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN) ||
--                      (iocStatus == MPI_IOCSTATUS_SCSI_RECOVERED_ERROR)) {
--                      ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
--                      }
--              }
-+      if (reply->u.reply.IOCStatus || reply->u.reply.IOCLogInfo)
-+              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "iocstatus (0x%04X), loginfo (0x%08X)\n", ioc->name,
-+                  le16_to_cpu(reply->u.reply.IOCStatus),
-+                  le32_to_cpu(reply->u.reply.IOCLogInfo)));
-+
-+      if ((req->u.hdr.Function == MPI_FUNCTION_SCSI_IO_REQUEST) ||
-+              (req->u.hdr.Function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
-+
-+              if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState)
-+                      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                      "scsi_status (0x%02x), scsi_state (0x%02x), "
-+                      "tag = (0x%04x), transfer_count (0x%08x)\n", ioc->name,
-+                      reply->u.sreply.SCSIStatus,
-+                      reply->u.sreply.SCSIState,
-+                      le16_to_cpu(reply->u.sreply.TaskTag),
-+                      le32_to_cpu(reply->u.sreply.TransferCount)));
--              /* Copy the sense data - if present
--               */
--              if ((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) &&
--                      (reply->u.sreply.SCSIState &
--                       MPI_SCSI_STATE_AUTOSENSE_VALID)){
-+              if (reply->u.sreply.SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
-                       sz = req->u.scsireq.SenseBufferLength;
-                       req_index =
-                           le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
--                      sense_data =
--                          ((u8 *)ioc->sense_buf_pool +
-+                      sense_data = ((u8 *)ioc->sense_buf_pool +
-                            (req_index * MPT_SENSE_BUFFER_ALLOC));
--                      memcpy(ioc->ioctl->sense, sense_data, sz);
--                      ioc->ioctl->status |= MPT_IOCTL_STATUS_SENSE_VALID;
-+                      memcpy(ioc->ioctl_cmds.sense, sense_data, sz);
-+                      ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_SENSE_VALID;
-               }
-+      }
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
+ }
  
--              if (cmd == MPI_FUNCTION_SCSI_TASK_MGMT)
--                      mptctl_free_tm_flags(ioc);
--
--              /* We are done, issue wake up
--               */
--              ioc->ioctl->wait_done = 1;
--              wake_up (&mptctl_wait);
-+ out:
-+      /* We are done, issue wake up
-+       */
-+      if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) {
-+              if (req->u.hdr.Function == MPI_FUNCTION_SCSI_TASK_MGMT)
-+                      mpt_clear_taskmgmt_in_progress_flag(ioc);
-+              ioc->ioctl_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
-+              complete(&ioc->ioctl_cmds.done);
+@@ -1621,37 +1582,38 @@ csmisas_get_sata_signature(unsigned long
+       u8                              phyId;
+       u64                             sas_address;
+-      sasPhyPg0=NULL;
+-      sasPhyPg0_data_sz=0;
+-      sasDevicePg1=NULL;
+-      sasDevicePg1_data_sz=0;
++      sasPhyPg0 = NULL;
++      sasPhyPg0_data_sz = 0;
++      sasDevicePg1 = NULL;
++      sasDevicePg1_data_sz = 0;
+       if (copy_from_user(&karg, uarg,
+            sizeof(CSMI_SAS_SATA_SIGNATURE_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_sata_signature struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
-+
-+ out_continuation:
-+      if (reply && (reply->u.reply.MsgFlags &
-+          MPI_MSGFLAGS_CONTINUATION_REPLY))
-+              return 0;
-       return 1;
- }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/* mptctl_timeout_expired
-- *
-- * Expecting an interrupt, however timed out.
-- *
-- */
--static void mptctl_timeout_expired (MPT_IOCTL *ioctl)
-+static int
-+mptctl_taskmgmt_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
- {
--      int rc = 1;
-+      if (!mf)
-+              return 0;
--      if (ioctl == NULL)
--              return;
--      dctlprintk(ioctl->ioc,
--                 printk(MYIOC_s_DEBUG_FMT ": Timeout Expired! Host %d\n",
--                 ioctl->ioc->name, ioctl->ioc->id));
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed (mf=%p, mr=%p)\n",
-+          ioc->name, mf, mr));
--      ioctl->wait_done = 0;
--      if (ioctl->reset & MPTCTL_RESET_OK)
--              rc = mptctl_bus_reset(ioctl);
--
--      if (rc) {
--              /* Issue a reset for this device.
--               * The IOC is not responding.
--               */
--              dctlprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "Calling HardReset! \n",
--                       ioctl->ioc->name));
--              mpt_HardResetHandler(ioctl->ioc, CAN_SLEEP);
--      }
--      return;
-+      ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
-+
-+      if (!mr)
-+              goto out;
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                   __FILE__, __FUNCTION__, __LINE__, iocnum);
++                   __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
-+      ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
-+      memcpy(ioc->taskmgmt_cmds.reply, mr,
-+          min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
-+ out:
-+      if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
-+              mpt_clear_taskmgmt_in_progress_flag(ioc);
-+              ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
-+              complete(&ioc->taskmgmt_cmds.done);
-+              return 1;
-+      }
-+      return 0;
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
+       phyId = karg.Signature.bPhyIdentifier;
+       if (phyId >= ioc->num_ports) {
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_PHY_DOES_NOT_EXIST;
+-              dcsmisasprintk(ioc, printk(KERN_WARNING ": phyId >= ioc->num_ports\n"));
++              dcsmisasprintk(ioc,
++                  printk(KERN_WARNING ": phyId >= ioc->num_ports\n"));
+               goto cim_sata_signature_exit;
+       }
+@@ -1683,7 +1645,7 @@ csmisas_get_sata_signature(unsigned long
+                */
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   ": FAILED: MPI_SASPHY0_PAGEVERSION: HEADER\n"));
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
++              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n", rc));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sata_signature_exit;
+       }
+@@ -1692,7 +1654,8 @@ csmisas_get_sata_signature(unsigned long
+               /* Don't check if this failed.  Already in a
+                * failure case.
+                */
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
++              dcsmisasprintk(ioc,
++                  printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sata_signature_exit;
+       }
+@@ -1704,8 +1667,9 @@ csmisas_get_sata_signature(unsigned long
+       sasPhyPg0 = (SasPhyPage0_t *) pci_alloc_consistent(ioc->pcidev,
+           sasPhyPg0_data_sz, &sasPhyPg0_dma);
+-      if (! sasPhyPg0) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++      if (!sasPhyPg0) {
++              dcsmisasprintk(ioc,
++                  printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sata_signature_exit;
+       }
+@@ -1720,7 +1684,7 @@ csmisas_get_sata_signature(unsigned long
+                */
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   ": FAILED: MPI_SASPHY0_PAGEVERSION: PAGE\n"));
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
++              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n", rc));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sata_signature_exit;
+       }
+@@ -1728,7 +1692,8 @@ csmisas_get_sata_signature(unsigned long
+       /* Make sure a SATA device is attached. */
+       if ((le32_to_cpu(sasPhyPg0->AttachedDeviceInfo) &
+           MPI_SAS_DEVICE_INFO_SATA_DEVICE) == 0) {
+-              dcsmisasprintk(ioc, printk(KERN_WARNING ": NOT A SATA DEVICE\n"));
++              dcsmisasprintk(ioc,
++                  printk(KERN_WARNING ": NOT A SATA DEVICE\n"));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_NO_SATA_DEVICE;
+               goto cim_sata_signature_exit;
+       }
+@@ -1755,13 +1720,14 @@ csmisas_get_sata_signature(unsigned long
+       if ((rc = mpt_config(ioc, &cfg)) != 0) {
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   ": FAILED: MPI_SASDEVICE1_PAGEVERSION: HEADER\n"));
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
++              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n", rc));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sata_signature_exit;
+       }
+       if (hdr.ExtPageLength == 0) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
++              dcsmisasprintk(ioc, printk(KERN_ERR
++                      ": hdr.ExtPageLength == 0\n"));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sata_signature_exit;
+       }
+@@ -1772,8 +1738,9 @@ csmisas_get_sata_signature(unsigned long
+       sasDevicePg1 = (SasDevicePage1_t *) pci_alloc_consistent
+           (ioc->pcidev, sasDevicePg1_data_sz, &sasDevicePg1_dma);
+-      if (! sasDevicePg1) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++      if (!sasDevicePg1) {
++              dcsmisasprintk(ioc, printk(KERN_ERR
++                      ": pci_alloc_consistent: FAILED\n"));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sata_signature_exit;
+       }
+@@ -1785,29 +1752,31 @@ csmisas_get_sata_signature(unsigned long
+       if ((rc = mpt_config(ioc, &cfg)) != 0) {
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   ": FAILED: MPI_SASDEVICE1_PAGEVERSION: PAGE\n"));
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
++              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n", rc));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sata_signature_exit;
+       }
+-/* EDM : dump Device Page 1 data*/
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "---- SAS DEVICE PAGE 1 ---------\n"));
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "Handle=0x%x\n",sasDevicePg1->DevHandle));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG
++              "---- SAS DEVICE PAGE 1 ---------\n"));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG
++              "Handle=0x%x\n", sasDevicePg1->DevHandle));
+       memcpy(&sas_address, &sasDevicePg1->SASAddress, sizeof(u64));
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "SAS Address=0x%llX\n",
+           (unsigned long long)sas_address));
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "\n"));
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "Target ID=0x%x\n",sasDevicePg1->TargetID));
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "Bus=0x%x\n",sasDevicePg1->Bus));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG
++              "Target ID=0x%x\n", sasDevicePg1->TargetID));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG
++              "Bus=0x%x\n", sasDevicePg1->Bus));
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "Initial Reg Device FIS="));
+-      for(jj=0;jj<20;jj++)
++      for (jj = 0; jj < 20; jj++)
+               dcsmisasprintk(ioc, printk("%02x ",
+               ((u8 *)&sasDevicePg1->InitialRegDeviceFIS)[jj]));
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "\n\n"));
+-/* EDM : debug data */
+       memcpy(karg.Signature.bSignatureFIS,
+-              sasDevicePg1->InitialRegDeviceFIS,20);
++              sasDevicePg1->InitialRegDeviceFIS, 20);
+  cim_sata_signature_exit:
+@@ -1825,11 +1794,11 @@ csmisas_get_sata_signature(unsigned long
+           sizeof(CSMI_SAS_SATA_SIGNATURE_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to write out csmi_sas_sata_signature @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
  }
  
- /* mptctl_bus_reset
-@@ -334,132 +350,181 @@ static void mptctl_timeout_expired (MPT_
-  * Bus reset code.
-  *
-  */
--static int mptctl_bus_reset(MPT_IOCTL *ioctl)
-+static int
-+mptctl_bus_reset(MPT_ADAPTER *ioc, u8 function)
- {
-       MPT_FRAME_HDR   *mf;
-       SCSITaskMgmt_t  *pScsiTm;
--      MPT_SCSI_HOST   *hd;
-+      SCSITaskMgmtReply_t *pScsiTmReply;
-       int              ii;
--      int              retval=0;
--
--
--      ioctl->reset &= ~MPTCTL_RESET_OK;
--
--      if (ioctl->ioc->sh == NULL)
-+      int              retval;
-+      unsigned long    timeout;
-+      unsigned long    time_count;
-+      u16              iocstatus;
-+
-+      /* bus reset is only good for SCSI IO, RAID PASSTHRU */
-+      if (!(function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) ||
-+          (function == MPI_FUNCTION_SCSI_IO_REQUEST)) {
-+              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt, not SCSI_IO!!\n",
-+                              ioc->name));
-               return -EPERM;
-+      }
+@@ -1855,24 +1824,24 @@ csmisas_get_device_address(unsigned long
+           sizeof(CSMI_SAS_GET_DEVICE_ADDRESS_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+          "Unable to read in csmi_sas_get_device_address_buffer struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
--      hd = shost_priv(ioctl->ioc->sh);
--      if (hd == NULL)
-+      mutex_lock(&ioc->taskmgmt_cmds.mutex);
-+      if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
-+              mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-               return -EPERM;
-+      }
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
--      /* Single threading ....
--       */
--      if (mptctl_set_tm_flags(hd) != 0)
--              return -EPERM;
-+      retval = 0;
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
-       /* Send request
-        */
--      if ((mf = mpt_get_msg_frame(mptctl_id, ioctl->ioc)) == NULL) {
--              dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt, no msg frames!!\n",
--                              ioctl->ioc->name));
--
--              mptctl_free_tm_flags(ioctl->ioc);
--              return -ENOMEM;
-+      if ((mf = mpt_get_msg_frame(mptctl_taskmgmt_id, ioc)) == NULL) {
-+              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt, no msg frames!!\n",
-+                              ioc->name));
-+              mpt_clear_taskmgmt_in_progress_flag(ioc);
-+              retval = -ENOMEM;
-+              goto mptctl_bus_reset_done;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
+       karg.IoctlHeader.ReturnCode = CSMI_SAS_NO_DEVICE_ADDRESS;
+       memset(karg.bSASAddress, 0, sizeof(u64));
+@@ -1896,11 +1865,11 @@ csmisas_get_device_address(unsigned long
+           sizeof(CSMI_SAS_GET_DEVICE_ADDRESS_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+               "Unable to write out csmi_sas_get_device_address_buffer @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
  
--      dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt request @ %p\n",
--                      ioctl->ioc->name, mf));
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
-+              ioc->name, mf));
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
+ }
  
-       pScsiTm = (SCSITaskMgmt_t *) mf;
--      pScsiTm->TargetID = ioctl->id;
--      pScsiTm->Bus = hd->port;        /* 0 */
--      pScsiTm->ChainOffset = 0;
-+      memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
-       pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
--      pScsiTm->Reserved = 0;
-       pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS;
--      pScsiTm->Reserved1 = 0;
-       pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
--
-+      pScsiTm->TargetID = 0;
-+      pScsiTm->Bus = 0;
-+      pScsiTm->ChainOffset = 0;
-+      pScsiTm->Reserved = 0;
-+      pScsiTm->Reserved1 = 0;
-+      pScsiTm->TaskMsgContext = 0;
-       for (ii= 0; ii < 8; ii++)
-               pScsiTm->LUN[ii] = 0;
--
-       for (ii=0; ii < 7; ii++)
-               pScsiTm->Reserved2[ii] = 0;
+@@ -1933,35 +1902,36 @@ csmisas_get_link_errors(unsigned long ar
+       u16                             ioc_status;
+       u32                             MsgContext;
  
--      pScsiTm->TaskMsgContext = 0;
--      dtmprintk(ioctl->ioc, printk(MYIOC_s_DEBUG_FMT
--              "mptctl_bus_reset: issued.\n", ioctl->ioc->name));
--
--      DBG_DUMP_TM_REQUEST_FRAME(ioctl->ioc, (u32 *)mf);
-+      switch (ioc->bus_type) {
-+              case FC:
-+                      timeout = 40;
-+                      break;
-+              case SAS:
-+                      timeout = 30;
-+                      break;
-+              case SPI:
-+              default:
-+                      timeout = 2;
-+                      break;
-+      }
+-      sasPhyPage1=NULL;
+-      sasPhyPage1_data_sz=0;
++      sasPhyPage1 = NULL;
++      sasPhyPage1_data_sz = 0;
  
--      ioctl->wait_done=0;
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt type=%d timeout=%ld\n",
-+          ioc->name, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, timeout));
--      if ((ioctl->ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
--          (ioctl->ioc->facts.MsgVersion >= MPI_VERSION_01_05))
--              mpt_put_msg_frame_hi_pri(mptctl_id, ioctl->ioc, mf);
-+      INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+      CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+      time_count = jiffies;
-+      if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
-+          (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
-+              mpt_put_msg_frame_hi_pri(mptctl_taskmgmt_id, ioc, mf);
-       else {
--              retval = mpt_send_handshake_request(mptctl_id, ioctl->ioc,
--                      sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
-+              retval = mpt_send_handshake_request(mptctl_taskmgmt_id, ioc,
-+                  sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
-               if (retval != 0) {
--                      dfailprintk(ioctl->ioc, printk(MYIOC_s_ERR_FMT "_send_handshake FAILED!"
--                              " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
--                              hd->ioc, mf));
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "TaskMgmt send_handshake FAILED!"
-+                              " (ioc %p, mf %p, rc=%d) \n", ioc->name,
-+                              ioc, mf, retval));
-+                      mpt_clear_taskmgmt_in_progress_flag(ioc);
-                       goto mptctl_bus_reset_done;
-               }
+       if (copy_from_user(&karg, uarg,
+            sizeof(CSMI_SAS_LINK_ERRORS_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmisas_get_link_errors struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
  
-       /* Now wait for the command to complete */
--      ii = wait_event_timeout(mptctl_wait,
--           ioctl->wait_done == 1,
--           HZ*5 /* 5 second timeout */);
--
--      if(ii <=0 && (ioctl->wait_done != 1 ))  {
--              mpt_free_msg_frame(hd->ioc, mf);
--              ioctl->wait_done = 0;
--              retval = -1; /* return failure */
-+      ii = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ);
-+      if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "TaskMgmt failed\n", ioc->name));
-+              mpt_free_msg_frame(ioc, mf);
-+              mpt_clear_taskmgmt_in_progress_flag(ioc);
-+              if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
-+                      retval = 0;
-+              else
-+                      retval = -1; /* return failure */
-+              goto mptctl_bus_reset_done;
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                   __FILE__, __FUNCTION__, __LINE__, iocnum);
++                   __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
        }
  
--mptctl_bus_reset_done:
--
--      mptctl_free_tm_flags(ioctl->ioc);
--      return retval;
--}
--
--static int
--mptctl_set_tm_flags(MPT_SCSI_HOST *hd) {
--      unsigned long flags;
--
--      spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
-+      if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "TaskMgmt failed\n", ioc->name));
-+              retval = -1; /* return failure */
-+              goto mptctl_bus_reset_done;
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
+       phyId = karg.Information.bPhyIdentifier;
+       if (phyId >= ioc->num_ports) {
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_PHY_DOES_NOT_EXIST;
+-              dcsmisasprintk(ioc, printk(KERN_WARNING ": phyId >= ioc->num_ports\n"));
++              dcsmisasprintk(ioc, printk(KERN_WARNING
++                      ": phyId >= ioc->num_ports\n"));
+               goto cim_get_link_errors_exit;
+       }
+@@ -1993,7 +1963,7 @@ csmisas_get_link_errors(unsigned long ar
+                */
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   ": FAILED: MPI_SASPHY1_PAGEVERSION: HEADER\n"));
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
++              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n", rc));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_get_link_errors_exit;
+       }
+@@ -2002,7 +1972,8 @@ csmisas_get_link_errors(unsigned long ar
+               /* Don't check if this failed.  Already in a
+                * failure case.
+                */
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
++              dcsmisasprintk(ioc, printk(KERN_ERR
++                      ": hdr.ExtPageLength == 0\n"));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_get_link_errors_exit;
+       }
+@@ -2014,8 +1985,9 @@ csmisas_get_link_errors(unsigned long ar
+       sasPhyPage1 = (SasPhyPage1_t *) pci_alloc_consistent(ioc->pcidev,
+           sasPhyPage1_data_sz, &sasPhyPage1_dma);
+-      if (! sasPhyPage1) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++      if (!sasPhyPage1) {
++              dcsmisasprintk(ioc, printk(KERN_ERR
++                      ": pci_alloc_consistent: FAILED\n"));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_get_link_errors_exit;
+       }
+@@ -2028,24 +2000,25 @@ csmisas_get_link_errors(unsigned long ar
+               /* Don't check if this failed.  Already in a
+                * failure case.
+                */
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": FAILED: MPI_SASPHY1_PAGEVERSION: PAGE\n"));
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n",rc));
++              dcsmisasprintk(ioc, printk(KERN_ERR
++                      ": FAILED: MPI_SASPHY1_PAGEVERSION: PAGE\n"));
++              dcsmisasprintk(ioc, printk(KERN_ERR ": rc=%x\n", rc));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_get_link_errors_exit;
+       }
+-/* EDM : dump PHY Page 1 data*/
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "---- SAS PHY PAGE 1 ------------\n"));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG
++              "---- SAS PHY PAGE 1 ------------\n"));
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "Invalid Dword Count=0x%x\n",
+           sasPhyPage1->InvalidDwordCount));
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "Running Disparity Error Count=0x%x\n",
++      dcsmisasprintk(ioc, printk(KERN_DEBUG
++              "Running Disparity Error Count=0x%x\n",
+           sasPhyPage1->RunningDisparityErrorCount));
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "Loss Dword Synch Count=0x%x\n",
+           sasPhyPage1->LossDwordSynchCount));
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "PHY Reset Problem Count=0x%x\n",
+           sasPhyPage1->PhyResetProblemCount));
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "\n\n"));
+-/* EDM : debug data */
+       karg.Information.uInvalidDwordCount =
+               le32_to_cpu(sasPhyPage1->InvalidDwordCount);
+@@ -2057,7 +2030,7 @@ csmisas_get_link_errors(unsigned long ar
+               le32_to_cpu(sasPhyPage1->PhyResetProblemCount);
+       if (karg.Information.bResetCounts ==
+-          CSMI_SAS_LINK_ERROR_DONT_RESET_COUNTS ) {
++          CSMI_SAS_LINK_ERROR_DONT_RESET_COUNTS) {
+               goto cim_get_link_errors_exit;
+       }
+@@ -2072,12 +2045,12 @@ csmisas_get_link_errors(unsigned long ar
+               dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_get_link_errors_exit;
+-        }
 +      }
  
--      if (hd->tmState == TM_STATE_NONE) {
--              hd->tmState = TM_STATE_IN_PROGRESS;
--              hd->tmPending = 1;
--              spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
--      } else {
--              spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
--              return -EBUSY;
-+      pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply;
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "TaskMgmt fw_channel = %d, fw_id = %d, task_type=0x%02X, "
-+          "iocstatus=0x%04X\n\tloginfo=0x%08X, response_code=0x%02X, "
-+          "term_cmnds=%d\n", ioc->name, pScsiTmReply->Bus,
-+          pScsiTmReply->TargetID, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
-+          le16_to_cpu(pScsiTmReply->IOCStatus),
-+          le32_to_cpu(pScsiTmReply->IOCLogInfo),
-+          pScsiTmReply->ResponseCode,
-+          le32_to_cpu(pScsiTmReply->TerminationCount)));
-+
-+      iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
-+
-+      if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
-+         iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED ||
-+         iocstatus == MPI_IOCSTATUS_SUCCESS)
-+              retval = 0;
-+      else {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "TaskMgmt failed\n", ioc->name));
-+              retval = -1; /* return failure */
+       mpi_hdr = (MPIHeader_t *) mf;
+       MsgContext = mpi_hdr->MsgContext;
+       sasIoUnitCntrReq = (SasIoUnitControlRequest_t *)mf;
+-      memset(sasIoUnitCntrReq,0,sizeof(SasIoUnitControlRequest_t));
++      memset(sasIoUnitCntrReq, 0, sizeof(SasIoUnitControlRequest_t));
+       sasIoUnitCntrReq->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
+       sasIoUnitCntrReq->MsgContext = MsgContext;
+       sasIoUnitCntrReq->PhyNum = phyId;
+@@ -2097,8 +2070,10 @@ csmisas_get_link_errors(unsigned long ar
+                   & MPI_IOCSTATUS_MASK;
+               if (ioc_status != MPI_IOCSTATUS_SUCCESS) {
+-                      dcsmisasprintk(ioc, printk(KERN_DEBUG ": SAS IO Unit Control: "));
+-                      dcsmisasprintk(ioc, printk("IOCStatus=0x%X IOCLogInfo=0x%X\n",
++                      dcsmisasprintk(ioc, printk(KERN_DEBUG
++                              ": SAS IO Unit Control: "));
++                      dcsmisasprintk(ioc, printk(
++                              "IOCStatus=0x%X IOCLogInfo=0x%X\n",
+                           sasIoUnitCntrReply->IOCStatus,
+                           sasIoUnitCntrReply->IOCLogInfo));
+               }
+@@ -2116,11 +2091,11 @@ csmisas_get_link_errors(unsigned long ar
+           sizeof(CSMI_SAS_LINK_ERRORS_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to write out csmisas_get_link_errors @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
  
--      return 0;
-+
-+ mptctl_bus_reset_done:
-+      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+      CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+      return retval;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
  }
+@@ -2145,10 +2120,10 @@ csmisas_smp_passthru(unsigned long arg)
+       MPIHeader_t                     *mpi_hdr;
+       char                            *psge;
+       int                             iocnum, flagsLength;
+-      void *                          request_data;
++      void                            *request_data;
+       dma_addr_t                      request_data_dma;
+       u32                             request_data_sz;
+-      void *                          response_data;
++      void                            *response_data;
+       dma_addr_t                      response_data_dma;
+       u32                             response_data_sz;
+       u16                             ioc_status;
+@@ -2161,11 +2136,11 @@ csmisas_smp_passthru(unsigned long arg)
+       memory_pages = get_order(malloc_data_sz);
+       karg = (CSMI_SAS_SMP_PASSTHRU_BUFFER *)__get_free_pages(
+               GFP_KERNEL, memory_pages);
+-      if (!karg){
++      if (!karg) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to malloc CSMI_SAS_SMP_PASSTHRU_BUFFER "
+                       "malloc_data_sz=%d memory_pages=%d\n",
+-                      __FILE__, __LINE__, __FUNCTION__,
++                      __FILE__, __LINE__, __func__,
+                       malloc_data_sz, memory_pages);
+               return -ENOMEM;
+       }
+@@ -2173,7 +2148,7 @@ csmisas_smp_passthru(unsigned long arg)
+       if (copy_from_user(karg, uarg, sizeof(CSMI_SAS_SMP_PASSTHRU_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_smp_passthru struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
+       }
+@@ -2186,7 +2161,7 @@ csmisas_smp_passthru(unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg->IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)karg, memory_pages);
+               return -ENODEV;
+       }
+@@ -2194,19 +2169,19 @@ csmisas_smp_passthru(unsigned long arg)
+       if (ioc->ioc_reset_in_progress) {
+               printk(KERN_ERR "%s@%d::%s - "
+                   "Busy with IOC Reset \n",
+-                  __FILE__, __LINE__,__FUNCTION__);
++                  __FILE__, __LINE__, __func__);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EBUSY;
+       }
  
- static void
--mptctl_free_tm_flags(MPT_ADAPTER *ioc)
-+mptctl_timeout_expired(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
- {
--      MPT_SCSI_HOST * hd;
-       unsigned long flags;
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)karg, memory_pages);
+               return -ENODEV;
+       }
  
--      hd = shost_priv(ioc->sh);
--      if (hd == NULL)
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": %s\n",
-+              ioc->name, __FUNCTION__));
-+
-+      if(mpt_fwfault_debug)
-+              mpt_halt_firmware(ioc);
-+
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-+      if (ioc->ioc_reset_in_progress) {
-+              spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+              CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status)
-+              mpt_free_msg_frame(ioc, mf);
-               return;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
+       /* Default to success.*/
+       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
+@@ -2228,13 +2203,13 @@ csmisas_smp_passthru(unsigned long arg)
+               dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_smp_passthru_exit;
+-        }
 +      }
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  
--      spin_lock_irqsave(&ioc->FreeQlock, flags);
+       mpi_hdr = (MPIHeader_t *) mf;
+       MsgContext = mpi_hdr->MsgContext;
+-      smpReq = (pSmpPassthroughRequest_t ) mf;
++      smpReq = (pSmpPassthroughRequest_t) mf;
  
--      hd->tmState = TM_STATE_NONE;
--      hd->tmPending = 0;
--      spin_unlock_irqrestore(&ioc->FreeQlock, flags);
-+      if (!mptctl_bus_reset(ioc, mf->u.hdr.Function))
-+              return;
+-      memset(smpReq,0,ioc->req_sz);
++      memset(smpReq, 0, ioc->req_sz);
  
--      return;
-+      /* Issue a reset for this device.
-+       * The IOC is not responding.
-+       */
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling HardReset! \n",
-+               ioc->name));
-+      CLEAR_MGMT_PENDING_STATUS(ioc->ioctl_cmds.status)
-+      if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
-+              mpt_HardResetHandler(ioc, CAN_SLEEP);
-+      mpt_free_msg_frame(ioc, mf);
- }
+       memcpy(&sas_address, karg->Parameters.bDestinationSASAddress,
+           sizeof(u64));
+@@ -2270,7 +2245,8 @@ csmisas_smp_passthru(unsigned long arg)
+           ioc->pcidev, request_data_sz, &request_data_dma);
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-@@ -472,22 +537,23 @@ mptctl_free_tm_flags(MPT_ADAPTER *ioc)
- static int
- mptctl_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
- {
--      MPT_IOCTL *ioctl = ioc->ioctl;
--      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOC %s_reset routed to IOCTL driver!\n", ioc->name,
--              reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
--              reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
--
--      if(ioctl == NULL)
--              return 1;
--
-       switch(reset_phase) {
-       case MPT_IOC_SETUP_RESET:
--              ioctl->status |= MPT_IOCTL_STATUS_DID_IOCRESET;
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __FUNCTION__));
-+              break;
-+      case MPT_IOC_PRE_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __FUNCTION__));
-               break;
-       case MPT_IOC_POST_RESET:
--              ioctl->status &= ~MPT_IOCTL_STATUS_DID_IOCRESET;
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_POST_RESET\n", ioc->name, __FUNCTION__));
-+              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) {
-+                      ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
-+                      complete(&ioc->ioctl_cmds.done);
-+              }
-               break;
--      case MPT_IOC_PRE_RESET:
-       default:
-               break;
-       }
-@@ -505,7 +571,7 @@ mptctl_event_process(MPT_ADAPTER *ioc, E
-       event = le32_to_cpu(pEvReply->Event) & 0xFF;
+       if (!request_data) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++              dcsmisasprintk(ioc, printk(KERN_ERR
++                      ": pci_alloc_consistent: FAILED\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               mpt_free_msg_frame(ioc, mf);
+               goto cim_smp_passthru_exit;
+@@ -2286,7 +2262,8 @@ csmisas_smp_passthru(unsigned long arg)
+           ioc->pcidev, response_data_sz, &response_data_dma);
  
-       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s() called\n",
--          ioc->name, __func__));
-+          ioc->name, __FUNCTION__));
-       if(async_queue == NULL)
-               return 1;
+       if (!response_data) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++              dcsmisasprintk(ioc, printk(KERN_ERR
++                      ": pci_alloc_consistent: FAILED\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               mpt_free_msg_frame(ioc, mf);
+               goto cim_smp_passthru_exit;
+@@ -2302,26 +2279,29 @@ csmisas_smp_passthru(unsigned long arg)
  
-@@ -548,15 +614,11 @@ static int
- mptctl_fasync(int fd, struct file *filep, int mode)
- {
-       MPT_ADAPTER     *ioc;
--      int ret;
+       ioc->add_sge(psge, flagsLength, response_data_dma);
  
--      lock_kernel();
-       list_for_each_entry(ioc, &ioc_list, list)
-               ioc->aen_event_read_flag=0;
+-      if (csmisas_send_command_wait(ioc, mf, karg->IoctlHeader.Timeout) != 0) {
++      if (csmisas_send_command_wait(ioc, mf, karg->IoctlHeader.Timeout)
++          != 0) {
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_smp_passthru_exit;
+       }
+       if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0) {
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG ": SMP Passthru: oh no, there is no reply!!"));
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      ": SMP Passthru: oh no, there is no reply!!"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_smp_passthru_exit;
+       }
+       /* process the completed Reply Message Frame */
+-      smpReply = (pSmpPassthroughReply_t )ioc->ioctl_cmds.reply;
++      smpReply = (pSmpPassthroughReply_t)ioc->ioctl_cmds.reply;
+       ioc_status = le16_to_cpu(smpReply->IOCStatus) & MPI_IOCSTATUS_MASK;
+       if ((ioc_status != MPI_IOCSTATUS_SUCCESS) &&
+           (ioc_status != MPI_IOCSTATUS_SCSI_DATA_UNDERRUN)) {
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               dcsmisasprintk(ioc, printk(KERN_DEBUG ": SMP Passthru: "));
+-              dcsmisasprintk(ioc, printk("IOCStatus=0x%X IOCLogInfo=0x%X SASStatus=0x%X\n",
++              dcsmisasprintk(ioc, printk(
++                      "IOCStatus=0x%X IOCLogInfo=0x%X SASStatus=0x%X\n",
+                   le16_to_cpu(smpReply->IOCStatus),
+                   le32_to_cpu(smpReply->IOCLogInfo),
+                   smpReply->SASStatus));
+@@ -2333,7 +2313,8 @@ csmisas_smp_passthru(unsigned long arg)
+       if (le16_to_cpu(smpReply->ResponseDataLength)) {
+-              karg->Parameters.uResponseBytes = le16_to_cpu(smpReply->ResponseDataLength);
++              karg->Parameters.uResponseBytes
++                  = le16_to_cpu(smpReply->ResponseDataLength);
+               memcpy(&karg->Parameters.Response,
+                   response_data, le16_to_cpu(smpReply->ResponseDataLength));
+       }
+@@ -2355,13 +2336,13 @@ csmisas_smp_passthru(unsigned long arg)
+           sizeof(CSMI_SAS_SMP_PASSTHRU_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to write out csmi_sas_smp_passthru @ %p\n",
+-                              __FILE__, __LINE__, __FUNCTION__, uarg);
++                              __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
+       }
  
--      ret = fasync_helper(fd, filep, mode, &async_queue);
--      unlock_kernel();
--      return ret;
-+      return fasync_helper(fd, filep, mode, &async_queue);
+       free_pages((unsigned long)karg, memory_pages);
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG ": %s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG ": %s exit.\n", __func__));
+       return 0;
  }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-@@ -582,6 +644,7 @@ __mptctl_ioctl(struct file *file, unsign
-       int ret;
-       MPT_ADAPTER *iocp = NULL;
+@@ -2376,18 +2357,18 @@ csmisas_smp_passthru(unsigned long arg)
+ static int csmisas_ssp_passthru(unsigned long arg)
+ {
+       CSMI_SAS_SSP_PASSTHRU_BUFFER __user *uarg = (void __user *) arg;
+-      CSMI_SAS_SSP_PASSTHRU_BUFFER     karg_hdr, * karg;
++      CSMI_SAS_SSP_PASSTHRU_BUFFER     karg_hdr, *karg;
+       MPT_ADAPTER                     *ioc = NULL;
+       pSCSIIORequest_t                pScsiRequest;
+       pSCSIIOReply_t                  pScsiReply;
+       MPT_FRAME_HDR                   *mf = NULL;
+       MPIHeader_t                     *mpi_hdr;
+-      int                             iocnum,ii;
++      int                             iocnum, ii;
+       u64                             sas_address;
+       u16                             req_idx;
+       char                            *psge;
+       int                             flagsLength;
+-      void *                          request_data;
++      void                            *request_data;
+       dma_addr_t                      request_data_dma;
+       u32                             request_data_sz;
+       int                             malloc_data_sz;
+@@ -2402,10 +2383,11 @@ static int csmisas_ssp_passthru(unsigned
+       u8                              skey, asc, ascq;
+       u32                             MsgContext;
+-      if (copy_from_user(&karg_hdr, uarg, sizeof(CSMI_SAS_SSP_PASSTHRU_BUFFER))) {
++      if (copy_from_user(&karg_hdr, uarg,
++              sizeof(CSMI_SAS_SSP_PASSTHRU_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_ssp_passthru struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-+
-       if (copy_from_user(&khdr, uhdr, sizeof(khdr))) {
-               printk(KERN_ERR MYNAM "%s::mptctl_ioctl() @%d - "
-                               "Unable to copy mpt_ioctl_header data @ %p\n",
-@@ -596,17 +659,12 @@ __mptctl_ioctl(struct file *file, unsign
-       iocnumX = khdr.iocnum & 0xFF;
-       if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
-           (iocp == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_ioctl() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnumX);
-               return -ENODEV;
+@@ -2422,11 +2404,11 @@ static int csmisas_ssp_passthru(unsigned
+       memory_pages = get_order(malloc_data_sz);
+       karg = (CSMI_SAS_SSP_PASSTHRU_BUFFER *)__get_free_pages(
+               GFP_KERNEL, memory_pages);
+-      if (!karg){
++      if (!karg) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to malloc SAS_SSP_PASSTHRU_BUFFER "
+                       "malloc_data_sz=%d memory_pages=%d\n",
+-                      __FILE__, __LINE__, __FUNCTION__,
++                      __FILE__, __LINE__, __func__,
+                       malloc_data_sz, memory_pages);
+               return -ENOMEM;
        }
+@@ -2434,10 +2416,10 @@ static int csmisas_ssp_passthru(unsigned
+       memset(karg, 0, sizeof(*karg));
  
--      if (!iocp->active) {
--              printk(KERN_DEBUG MYNAM "%s::mptctl_ioctl() @%d - Controller disabled.\n",
--                              __FILE__, __LINE__);
--              return -EFAULT;
--      }
--
-       /* Handle those commands that are just returning
-        * information stored in the driver.
-        * These commands should never time out and are unaffected
-@@ -626,6 +684,25 @@ __mptctl_ioctl(struct file *file, unsign
-               return mptctl_eventreport(arg);
-       } else if (cmd == MPTFWREPLACE) {
-               return mptctl_replace_fw(arg);
-+#if defined(DIAG_BUFFER_SUPPORT)
-+/* diag_buffer static data calls*/
-+      } else if (cmd == MPTDIAGQUERY) {
-+              return mptctl_query_diag_buffer(arg);
-+      } else if (cmd == MPTDIAGUNREGISTER) {
-+              return mptctl_unregister_diag_buffer(arg);
-+#endif
-+
-+#if defined(CPQ_CIM)
-+/* csmisas static data calls*/
-+      } else if (cmd == CC_CSMI_SAS_GET_DRIVER_INFO) {
-+              return csmisas_get_driver_info(arg);
-+      } else if (cmd == CC_CSMI_SAS_GET_CNTLR_STATUS) {
-+              return csmisas_get_cntlr_status(arg);
-+      } else if (cmd == CC_CSMI_SAS_GET_SCSI_ADDRESS) {
-+              return csmisas_get_scsi_address(arg);
-+      } else if (cmd == CC_CSMI_SAS_GET_DEVICE_ADDRESS){
-+              return csmisas_get_device_address(arg);
-+#endif // CPQ_CIM
+       if (copy_from_user(karg, uarg, request_data_sz +
+-          offsetof(CSMI_SAS_SSP_PASSTHRU_BUFFER,bDataBuffer))) {
++          offsetof(CSMI_SAS_SSP_PASSTHRU_BUFFER, bDataBuffer))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_ssp_passthru struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
+       }
+@@ -2445,40 +2427,43 @@ static int csmisas_ssp_passthru(unsigned
+       /*
+        * some checks of the incoming frame
+        */
+-      if ( offsetof(CSMI_SAS_SSP_PASSTHRU_BUFFER,bDataBuffer) +
++      if (offsetof(CSMI_SAS_SSP_PASSTHRU_BUFFER, bDataBuffer) +
+           request_data_sz - sizeof(IOCTL_HEADER) >
+-          karg->IoctlHeader.Length ) {
+-              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
++          karg->IoctlHeader.Length) {
++              karg->IoctlHeader.ReturnCode
++                  = CSMI_SAS_STATUS_INVALID_PARAMETER;
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   "%s::%s()"
+                   " @%d - expected datalen incorrect!\n",
+-                  __FILE__, __FUNCTION__, __LINE__));
++                  __FILE__, __func__, __LINE__));
+               goto cim_ssp_passthru_exit;
+       }
+       if (((iocnum = mpt_verify_adapter(karg->IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+-              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
++              karg->IoctlHeader.ReturnCode
++                  = CSMI_SAS_STATUS_INVALID_PARAMETER;
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               goto cim_ssp_passthru_exit;
+       }
+       if (ioc->ioc_reset_in_progress) {
+               printk(KERN_ERR "%s@%d::%s - "
+                   "Busy with IOC Reset \n",
+-                  __FILE__, __LINE__,__FUNCTION__);
++                  __FILE__, __LINE__, __func__);
+               return -EBUSY;
        }
  
-       /* All of these commands require an interrupt or
-@@ -634,6 +711,8 @@ __mptctl_ioctl(struct file *file, unsign
-       if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
-               return ret;
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+-              karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
++              karg->IoctlHeader.ReturnCode
++                  = CSMI_SAS_STATUS_INVALID_PARAMETER;
+               printk(KERN_ERR "%s::%s()@%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               goto cim_ssp_passthru_exit;
+       }
  
-+//    dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT ": mptctl_ioctl()\n", iocp->name));
-+
-       if (cmd == MPTFWDOWNLOAD)
-               ret = mptctl_fw_download(arg);
-       else if (cmd == MPTCOMMAND)
-@@ -644,10 +723,61 @@ __mptctl_ioctl(struct file *file, unsign
-               ret = mptctl_hp_hostinfo(arg, _IOC_SIZE(cmd));
-       else if (cmd == HP_GETTARGETINFO)
-               ret = mptctl_hp_targetinfo(arg);
-+#if defined(CPQ_CIM)
-+/* csmisas requiring fw calls*/
-+      else if (cmd == CC_CSMI_SAS_GET_CNTLR_CONFIG)
-+              ret = csmisas_get_cntlr_config(arg);
-+      else if (cmd == CC_CSMI_SAS_GET_PHY_INFO)
-+              ret = csmisas_get_phy_info(arg);
-+      else if (cmd == CC_CSMI_SAS_GET_SATA_SIGNATURE)
-+              ret = csmisas_get_sata_signature(arg);
-+      else if (cmd == CC_CSMI_SAS_GET_LINK_ERRORS)
-+              ret = csmisas_get_link_errors(arg);
-+      else if (cmd == CC_CSMI_SAS_SMP_PASSTHRU)
-+              ret = csmisas_smp_passthru(arg);
-+      else if (cmd == CC_CSMI_SAS_SSP_PASSTHRU)
-+              ret = csmisas_ssp_passthru(arg);
-+      else if (cmd == CC_CSMI_SAS_FIRMWARE_DOWNLOAD)
-+              ret = csmisas_firmware_download(arg);
-+      else if (cmd == CC_CSMI_SAS_GET_RAID_INFO)
-+              ret = csmisas_get_raid_info(arg);
-+      else if (cmd == CC_CSMI_SAS_GET_RAID_CONFIG)
-+              ret = csmisas_get_raid_config(arg);
-+      else if (cmd == CC_CSMI_SAS_GET_RAID_FEATURES)
-+              ret = csmisas_get_raid_features(arg);
-+      else if (cmd == CC_CSMI_SAS_SET_RAID_CONTROL)
-+              ret = csmisas_set_raid_control(arg);
-+      else if (cmd == CC_CSMI_SAS_GET_RAID_ELEMENT)
-+              ret = csmisas_get_raid_element(arg);
-+      else if (cmd == CC_CSMI_SAS_SET_RAID_OPERATION)
-+              ret = csmisas_set_raid_operation(arg);
-+      else if (cmd == CC_CSMI_SAS_SET_PHY_INFO)
-+              ret = csmisas_set_phy_info(arg);
-+      else if (cmd == CC_CSMI_SAS_STP_PASSTHRU)
-+              ret = csmisas_stp_passthru(arg);
-+      else if (cmd == CC_CSMI_SAS_TASK_MANAGEMENT)
-+              ret = csmisas_task_managment(arg);
-+      else if (cmd == CC_CSMI_SAS_PHY_CONTROL)
-+              ret = csmisas_phy_control(arg);
-+      else if (cmd == CC_CSMI_SAS_GET_CONNECTOR_INFO)
-+              ret = csmisas_get_connector_info(arg);
-+      else if (cmd == CC_CSMI_SAS_GET_LOCATION)
-+              ret = csmisas_get_location(arg);
-+#endif // CPQ_CIM
-+
-+#if defined(DIAG_BUFFER_SUPPORT)
-+/* diag_buffer requiring fw calls*/
-+      else if (cmd == MPTDIAGREGISTER)
-+              ret = mptctl_register_diag_buffer(arg);
-+      else if (cmd == MPTDIAGRELEASE)
-+              ret = mptctl_release_diag_buffer(arg);
-+      else if (cmd == MPTDIAGREADBUFFER)
-+              ret = mptctl_read_diag_buffer(arg);
-+#endif // DIAG_BUFFER_SUPPORT
-       else
-               ret = -EINVAL;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
+       /* Default to success.
+        */
+@@ -2492,7 +2477,7 @@ static int csmisas_ssp_passthru(unsigned
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   "%s::%s()"
+                   " @%d - incorrect bPhyIdentifier and bPortIdentifier!\n",
+-                  __FILE__, __FUNCTION__, __LINE__));
++                  __FILE__, __func__, __LINE__));
+               goto cim_ssp_passthru_exit;
+       }
+@@ -2502,7 +2487,8 @@ static int csmisas_ssp_passthru(unsigned
+               /* Is the phy in range? */
+               if (karg->Parameters.bPhyIdentifier >= ioc->num_ports) {
+-                      dcsmisasprintk(ioc, printk(KERN_WARNING ": phyId >= ioc->num_ports (%d %d)\n",
++                      dcsmisasprintk(ioc, printk(KERN_WARNING
++                              ": phyId >= ioc->num_ports (%d %d)\n",
+                           karg->Parameters.bPhyIdentifier,
+                           ioc->num_ports));
+                       karg->IoctlHeader.ReturnCode =
+@@ -2511,10 +2497,9 @@ static int csmisas_ssp_passthru(unsigned
+               }
+       }
+-      if(karg->Parameters.bAdditionalCDBLength) {
+-      /* TODO - SCSI IO (32) Request Message support
+-       */
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG ": greater than 16-byte cdb "
++      if (karg->Parameters.bAdditionalCDBLength) {
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      ": greater than 16-byte cdb "
+                   "is not supported!\n"));
+                   karg->IoctlHeader.ReturnCode =
+                       CSMI_SAS_STATUS_INVALID_PARAMETER;
+@@ -2538,7 +2523,7 @@ static int csmisas_ssp_passthru(unsigned
+                   CSMI_SAS_STATUS_INVALID_PARAMETER;
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   "%s::%s() @%d - couldn't find associated "
+-                  "SASAddress=%llX!\n", __FILE__, __FUNCTION__, __LINE__,
++                  "SASAddress=%llX!\n", __FILE__, __func__, __LINE__,
+                   (unsigned long long)sas_address));
+               goto cim_ssp_passthru_exit;
+       }
+@@ -2558,20 +2543,21 @@ static int csmisas_ssp_passthru(unsigned
+               dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_ssp_passthru_exit;
+-        }
++      }
  
--      mutex_unlock(&iocp->ioctl->ioctl_mutex);
-+      mutex_unlock(&iocp->ioctl_cmds.mutex);
+       mpi_hdr = (MPIHeader_t *) mf;
+       MsgContext = mpi_hdr->MsgContext;
+       pScsiRequest = (pSCSIIORequest_t) mf;
+       req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  
-       return ret;
- }
-@@ -676,6 +806,7 @@ static int mptctl_do_reset(unsigned long
-       }
+-      memset(pScsiRequest,0,sizeof(SCSIIORequest_t));
++      memset(pScsiRequest, 0, sizeof(SCSIIORequest_t));
  
-       if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s@%d::mptctl_do_reset - ioc%d not found!\n",
-                               __FILE__, __LINE__, krinfo.hdr.iocnum);
-               return -ENODEV; /* (-6) No such device or address */
-@@ -763,10 +894,11 @@ mptctl_do_fw_download(int ioc, char __us
-       int                      sge_offset = 0;
-       u16                      iocstat;
-       pFWDownloadReply_t       ReplyMsg = NULL;
-+      unsigned long            timeleft;
+       /* Fill in SCSI IO (16) request.
+        */
  
-       if (mpt_verify_adapter(ioc, &iocp) < 0) {
--              printk(KERN_DEBUG MYNAM "ioctl_fwdl - ioc%d not found!\n",
--                               ioc);
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-+              printk(KERN_DEBUG MYNAM "ioctl_fwdl - ioc%d not found!\n", ioc);
-               return -ENODEV; /* (-6) No such device or address */
+       pScsiRequest->Function = (is_hidden_raid_component == 1) ?
+-          MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH : MPI_FUNCTION_SCSI_IO_REQUEST;
++          MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
++          : MPI_FUNCTION_SCSI_IO_REQUEST;
+       pScsiRequest->TargetID = id;
+       pScsiRequest->Bus = channel;
+       memcpy(pScsiRequest->LUN, &karg->Parameters.bLun, 8);
+@@ -2583,10 +2569,11 @@ static int csmisas_ssp_passthru(unsigned
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "\tchannel = %d id = %d ",
+           sas_info->fw.channel, sas_info->fw.id));
+-      dcsmisasprintk(ioc, if(is_hidden_raid_component)
++      dcsmisasprintk(ioc, if (is_hidden_raid_component)
+           printk(KERN_DEBUG "num_id = %d ", id));
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "\n"));
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "\tcdb_len = %d request_len = %d\n",
++      dcsmisasprintk(ioc, printk(KERN_DEBUG
++              "\tcdb_len = %d request_len = %d\n",
+           pScsiRequest->CDBLength, request_data_sz));
+       dcsmisasprintk(ioc, printk(KERN_DEBUG "\t"));
+       dcsmisasprintk(ioc, for (ii = 0; ii < pScsiRequest->CDBLength; ++ii)
+@@ -2603,7 +2590,8 @@ static int csmisas_ssp_passthru(unsigned
+           (!karg->Parameters.uDataLength)) {
+               /* no data transfer
+                */
+-              pScsiRequest->Control = cpu_to_le32(MPI_SCSIIO_CONTROL_NODATATRANSFER);
++              pScsiRequest->Control
++                  = cpu_to_le32(MPI_SCSIIO_CONTROL_NODATATRANSFER);
        } else {
+               /* no direction specified
+                */
+@@ -2618,19 +2606,23 @@ static int csmisas_ssp_passthru(unsigned
  
-@@ -847,10 +979,10 @@ mptctl_do_fw_download(int ioc, char __us
-        *      64              4
+       /* task attributes
         */
-       maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - sizeof(FWDownloadTCSGE_t))
--                      / (sizeof(dma_addr_t) + sizeof(u32));
-+                      / iocp->SGE_size;
-       if (numfrags > maxfrags) {
-               ret = -EMLINK;
--              goto fwdl_out;
-+              goto fwdl_out;
+-      if((karg->Parameters.uFlags && 0xFF) == 0) {
+-              pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_SIMPLEQ);
++      if ((karg->Parameters.uFlags && 0xFF) == 0) {
++              pScsiRequest->Control
++                  |= cpu_to_le32(MPI_SCSIIO_CONTROL_SIMPLEQ);
+       } else if (karg->Parameters.uFlags &
+           CSMI_SAS_SSP_TASK_ATTRIBUTE_HEAD_OF_QUEUE) {
+-              pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_HEADOFQ);
++              pScsiRequest->Control
++                  |= cpu_to_le32(MPI_SCSIIO_CONTROL_HEADOFQ);
+       } else if (karg->Parameters.uFlags &
+           CSMI_SAS_SSP_TASK_ATTRIBUTE_ORDERED) {
+-              pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_ORDEREDQ);
++              pScsiRequest->Control
++                  |= cpu_to_le32(MPI_SCSIIO_CONTROL_ORDEREDQ);
+       } else if (karg->Parameters.uFlags &
+           CSMI_SAS_SSP_TASK_ATTRIBUTE_ACA) {
+               pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_ACAQ);
+       } else {
+-              pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_UNTAGGED);
++              pScsiRequest->Control
++                  |= cpu_to_le32(MPI_SCSIIO_CONTROL_UNTAGGED);
        }
  
-       dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: sgl buffer = %p, sgfrags = %d\n",
-@@ -875,19 +1007,19 @@ mptctl_do_fw_download(int ioc, char __us
-               if (nib == 0 || nib == 3) {
-                       ;
-               } else if (sgIn->Address) {
--                      mpt_add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
-+                      iocp->add_sge(sgOut, sgIn->FlagsLength, sgIn->Address);
-                       n++;
-                       if (copy_from_user(bl->kptr, ufwbuf+fw_bytes_copied, bl->len)) {
-                               printk(MYIOC_s_ERR_FMT "%s@%d::_ioctl_fwdl - "
--                                      "Unable to copy f/w buffer hunk#%d @ %p\n",
--                                      iocp->name, __FILE__, __LINE__, n, ufwbuf);
-+                                  "Unable to copy f/w buffer hunk#%d @ %p\n",
-+                                  iocp->name, __FILE__, __LINE__, n, ufwbuf);
-                               goto fwdl_out;
+       /* setup sense
+@@ -2647,19 +2639,20 @@ static int csmisas_ssp_passthru(unsigned
+               flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
+       } else if (karg->Parameters.uFlags & CSMI_SAS_SSP_READ) {
+               flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
+-      }else {
+-              flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
+-                              MPI_SGE_FLAGS_DIRECTION )
++      } else {
++              flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
++                              MPI_SGE_FLAGS_DIRECTION)
+                               << MPI_SGE_FLAGS_SHIFT;
+       }
+       flagsLength |= request_data_sz;
+-      if ( request_data_sz > 0) {
++      if (request_data_sz > 0) {
+               request_data = pci_alloc_consistent(
+                   ioc->pcidev, request_data_sz, &request_data_dma);
+               if (request_data == NULL) {
+-                      dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED "
++                      dcsmisasprintk(ioc, printk(KERN_ERR
++                              ": pci_alloc_consistent: FAILED "
+                           "request_data_sz=%d\n", request_data_sz));
+                       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       mpt_free_msg_frame(ioc, mf);
+@@ -2668,17 +2661,19 @@ static int csmisas_ssp_passthru(unsigned
+               ioc->add_sge(psge, flagsLength, request_data_dma);
+               if (karg->Parameters.uFlags & CSMI_SAS_SSP_WRITE)
+-                      memcpy(request_data, karg->bDataBuffer, request_data_sz);
++                      memcpy(request_data, karg->bDataBuffer,
++                          request_data_sz);
+       } else {
+               ioc->add_sge(psge, flagsLength, (dma_addr_t) -1);
+       }
+-      if (csmisas_send_command_wait(ioc, mf, karg->IoctlHeader.Timeout) != 0) {
++      if (csmisas_send_command_wait(ioc, mf, karg->IoctlHeader.Timeout)
++          != 0) {
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_ssp_passthru_exit;
+       }
+-      memset(&karg->Status,0,sizeof(CSMI_SAS_SSP_PASSTHRU_STATUS));
++      memset(&karg->Status, 0, sizeof(CSMI_SAS_SSP_PASSTHRU_STATUS));
+       karg->Status.bConnectionStatus = CSMI_SAS_OPEN_ACCEPT;
+       karg->Status.bDataPresent = CSMI_SAS_SSP_NO_DATA_PRESENT;
+       karg->Status.bStatus = GOOD;
+@@ -2689,11 +2684,13 @@ static int csmisas_ssp_passthru(unsigned
+       /* process the completed Reply Message Frame */
+       if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
+-              pScsiReply = (pSCSIIOReply_t ) ioc->ioctl_cmds.reply;
++              pScsiReply = (pSCSIIOReply_t) ioc->ioctl_cmds.reply;
+               karg->Status.bStatus = pScsiReply->SCSIStatus;
+-              karg->Status.uDataBytes = min(le32_to_cpu(pScsiReply->TransferCount),
++              karg->Status.uDataBytes
++                  = min(le32_to_cpu(pScsiReply->TransferCount),
+                   request_data_sz);
+-              ioc_status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
++              ioc_status
++                  = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
+               if (pScsiReply->SCSIState ==
+                   MPI_SCSI_STATE_AUTOSENSE_VALID) {
+@@ -2701,26 +2698,28 @@ static int csmisas_ssp_passthru(unsigned
+                           CSMI_SAS_SSP_SENSE_DATA_PRESENT;
+                       karg->Status.bResponseLength[0] =
+                               (u8)le32_to_cpu(pScsiReply->SenseCount) & 0xFF;
+-                      memcpy(karg->Status.bResponse,
+-                          ioc->ioctl_cmds.sense, le32_to_cpu(pScsiReply->SenseCount));
++                      memcpy(karg->Status.bResponse, ioc->ioctl_cmds.sense,
++                          le32_to_cpu(pScsiReply->SenseCount));
+                       skey = ioc->ioctl_cmds.sense[2] & 0x0F;
+                       asc = ioc->ioctl_cmds.sense[12];
+                       ascq = ioc->ioctl_cmds.sense[13];
+-                      dcsmisasprintk(ioc, printk(KERN_DEBUG "\t [sense_key,asc,ascq]: "
+-                          "[0x%02x,0x%02x,0x%02x]\n",
+-                          skey, asc, ascq));
++                      dcsmisasprintk(ioc, printk(KERN_DEBUG
++                              "\t [sense_key,asc,ascq]: "
++                              "[0x%02x,0x%02x,0x%02x]\n",
++                              skey, asc, ascq));
+-              } else if(pScsiReply->SCSIState ==
++              } else if (pScsiReply->SCSIState ==
+                   MPI_SCSI_STATE_RESPONSE_INFO_VALID) {
+                       karg->Status.bDataPresent =
+                           CSMI_SAS_SSP_RESPONSE_DATA_PRESENT;
+                       karg->Status.bResponseLength[0] =
+                               sizeof(pScsiReply->ResponseInfo);
+-                      for (ii=0;ii<sizeof(pScsiReply->ResponseInfo);ii++) {
++                      for (ii = 0; ii < sizeof(pScsiReply->ResponseInfo);
++                          ii++) {
+                               karg->Status.bResponse[ii] =
+-                              ((u8*)&pScsiReply->ResponseInfo)[
++                              ((u8 *)&pScsiReply->ResponseInfo)[
+                                   (sizeof(pScsiReply->ResponseInfo)-1)-ii];
                        }
-                       fw_bytes_copied += bl->len;
+               } else if ((ioc_status != MPI_IOCSTATUS_SUCCESS) &&
+@@ -2728,7 +2727,8 @@ static int csmisas_ssp_passthru(unsigned
+                   (ioc_status != MPI_IOCSTATUS_SCSI_DATA_UNDERRUN)) {
+                       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       dcsmisasprintk(ioc, printk(KERN_DEBUG ": SCSI IO : "));
+-                      dcsmisasprintk(ioc, printk("IOCStatus=0x%X IOCLogInfo=0x%X\n",
++                      dcsmisasprintk(ioc,
++                          printk("IOCStatus=0x%X IOCLogInfo=0x%X\n",
+                           pScsiReply->IOCStatus,
+                           pScsiReply->IOCLogInfo));
+               }
+@@ -2740,8 +2740,8 @@ static int csmisas_ssp_passthru(unsigned
+                   request_data, karg->Status.uDataBytes)) {
+                       printk(KERN_ERR "%s@%d::%s - "
+                           "Unable to write data to user %p\n",
+-                          __FILE__, __LINE__,__FUNCTION__,
+-                          (void*)karg->bDataBuffer);
++                          __FILE__, __LINE__, __func__,
++                          (void *)karg->bDataBuffer);
+                       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
                }
-               sgIn++;
-               bl++;
--              sgOut += (sizeof(dma_addr_t) + sizeof(u32));
-+              sgOut += iocp->SGE_size;
+       }
+@@ -2759,12 +2759,12 @@ static int csmisas_ssp_passthru(unsigned
+           offsetof(CSMI_SAS_SSP_PASSTHRU_BUFFER, bDataBuffer))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to write out csmi_sas_ssp_passthru @ %p\n",
+-                              __FILE__, __LINE__, __FUNCTION__, uarg);
++                              __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
        }
  
-       DBG_DUMP_FW_DOWNLOAD(iocp, (u32 *)mf, numfrags);
-@@ -896,16 +1028,27 @@ mptctl_do_fw_download(int ioc, char __us
-        * Finally, perform firmware download.
-        */
-       ReplyMsg = NULL;
-+      SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, dlmsg->MsgContext);
-+      INITIALIZE_MGMT_STATUS(iocp->ioctl_cmds.status)
-       mpt_put_msg_frame(mptctl_id, iocp, mf);
-       /* Now wait for the command to complete */
--      ret = wait_event_timeout(mptctl_wait,
--           iocp->ioctl->wait_done == 1,
--           HZ*60);
--
--      if(ret <=0 && (iocp->ioctl->wait_done != 1 )) {
--      /* Now we need to reset the board */
--              mptctl_timeout_expired(iocp->ioctl);
-+      timeleft = wait_for_completion_timeout(&iocp->ioctl_cmds.done, HZ*60);
-+      if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              ret = -ETIME;
-+              printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __FUNCTION__);
-+              if (iocp->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
-+                      mpt_free_msg_frame(iocp, mf);
-+                      goto fwdl_out;
-+              }
-+              if (!timeleft)
-+                      mptctl_timeout_expired(iocp, mf);
-+              goto fwdl_out;
-+      }
-+
-+      if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
-+              printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __FUNCTION__);
-+              mpt_free_msg_frame(iocp, mf);
-               ret = -ENODATA;
-               goto fwdl_out;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       free_pages((unsigned long)karg, memory_pages);
+       return 0;
+ }
+@@ -2793,7 +2793,7 @@ csmisas_stp_passthru(unsigned long arg)
+       u16                             req_idx;
+       char                            *psge;
+       int                             flagsLength;
+-      void *                          request_data;
++      void                            *request_data;
+       dma_addr_t                      request_data_dma;
+       u32                             request_data_sz;
+       int                             malloc_data_sz;
+@@ -2806,14 +2806,15 @@ csmisas_stp_passthru(unsigned long arg)
+       u16                             ioc_status;
+       u32                             MsgContext;
+-      if (copy_from_user(&karg_hdr, uarg, sizeof(CSMI_SAS_STP_PASSTHRU_BUFFER))) {
++      if (copy_from_user(&karg_hdr, uarg,
++              sizeof(CSMI_SAS_STP_PASSTHRU_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
-@@ -913,31 +1056,34 @@ mptctl_do_fw_download(int ioc, char __us
-       if (sgl)
-               kfree_sgl(sgl, sgl_dma, buflist, iocp);
  
--      ReplyMsg = (pFWDownloadReply_t)iocp->ioctl->ReplyFrame;
-+      ReplyMsg = (pFWDownloadReply_t)iocp->ioctl_cmds.reply;
-       iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK;
-       if (iocstat == MPI_IOCSTATUS_SUCCESS) {
--              printk(MYIOC_s_INFO_FMT "F/W update successfull!\n", iocp->name);
-+              printk(MYIOC_s_INFO_FMT ": F/W update successfully sent!\n", iocp->name);
-               return 0;
-       } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) {
--              printk(MYIOC_s_WARN_FMT "Hmmm...  F/W download not supported!?!\n",
--                      iocp->name);
-+              printk(MYIOC_s_WARN_FMT "Hmmm...  doesn't support F/W download?\n",
-+                  iocp->name);
-               printk(MYIOC_s_WARN_FMT "(time to go bang on somebodies door)\n",
--                      iocp->name);
-+                  iocp->name);
-               return -EBADRQC;
-       } else if (iocstat == MPI_IOCSTATUS_BUSY) {
-               printk(MYIOC_s_WARN_FMT "IOC_BUSY!\n", iocp->name);
-               printk(MYIOC_s_WARN_FMT "(try again later?)\n", iocp->name);
+-      request_data=NULL;
++      request_data = NULL;
+       request_data_sz = karg_hdr.Parameters.uDataLength;
+       volume_id = 0;
+       volume_bus = 0;
+@@ -2825,11 +2826,11 @@ csmisas_stp_passthru(unsigned long arg)
+       memory_pages = get_order(malloc_data_sz);
+       karg = (CSMI_SAS_STP_PASSTHRU_BUFFER *)__get_free_pages(
+               GFP_KERNEL, memory_pages);
+-      if (!karg){
++      if (!karg) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to malloc CSMI_SAS_STP_PASSTHRU_BUFFER "
+                       "malloc_data_sz=%d memory_pages=%d\n",
+-                      __FILE__, __LINE__, __FUNCTION__,
++                      __FILE__, __LINE__, __func__,
+                       malloc_data_sz, memory_pages);
+               return -ENOMEM;
+       }
+@@ -2839,7 +2840,7 @@ csmisas_stp_passthru(unsigned long arg)
+       if (copy_from_user(karg, uarg, malloc_data_sz)) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_ssp_passthru struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
+       }
+@@ -2847,7 +2848,7 @@ csmisas_stp_passthru(unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg->IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)karg, memory_pages);
+               return -ENODEV;
+       }
+@@ -2855,19 +2856,19 @@ csmisas_stp_passthru(unsigned long arg)
+       if (ioc->ioc_reset_in_progress) {
+               printk(KERN_ERR "%s@%d::%s - "
+                   "Busy with IOC Reset \n",
+-                  __FILE__, __LINE__,__FUNCTION__);
++                  __FILE__, __LINE__, __func__);
+               free_pages((unsigned long)karg, memory_pages);
                return -EBUSY;
-       } else {
--              printk(MYIOC_s_WARN_FMT "ioctl_fwdl() returned [bad] status = %04xh\n",
--                      iocp->name, iocstat);
-+              printk(MYIOC_s_WARN_FMT "returned [bad] status = %04xh\n",
-+                  iocp->name, iocstat);
-               printk(MYIOC_s_WARN_FMT "(bad VooDoo)\n", iocp->name);
-               return -ENOMSG;
        }
-       return 0;
  
- fwdl_out:
--        kfree_sgl(sgl, sgl_dma, buflist, iocp);
-+
-+      CLEAR_MGMT_STATUS(iocp->ioctl_cmds.status);
-+      SET_MGMT_MSG_CONTEXT(iocp->ioctl_cmds.msg_context, 0);
-+      kfree_sgl(sgl, sgl_dma, buflist, iocp);
-       return ret;
- }
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)karg, memory_pages);
+               return -ENODEV;
+       }
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
-@@ -1008,7 +1154,7 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, i
-        *
+       /* Default to success.
         */
-       sgl = sglbuf;
--      sg_spill = ((ioc->req_sz - sge_offset)/(sizeof(dma_addr_t) + sizeof(u32))) - 1;
-+      sg_spill = ((ioc->req_sz - sge_offset)/ioc->SGE_size) - 1;
-       while (bytes_allocd < bytes) {
-               this_alloc = min(alloc_sz, bytes-bytes_allocd);
-               buflist[buflist_ent].len = this_alloc;
-@@ -1019,9 +1165,9 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, i
-                       alloc_sz = alloc_sz / 2;
-                       if (alloc_sz == 0) {
-                               printk(MYIOC_s_WARN_FMT "-SG: No can do - "
--                                  "not enough memory!   :-(\n", ioc->name);
-+                                  "not enough memory! :-(\n", ioc->name);
-                               printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n",
--                                      ioc->name, numfrags);
-+                                  ioc->name, numfrags);
-                               goto free_and_fail;
-                       }
-                       continue;
-@@ -1029,7 +1175,9 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, i
-                       dma_addr_t dma_addr;
+@@ -2879,8 +2880,9 @@ csmisas_stp_passthru(unsigned long arg)
+               (karg->Parameters.bPortIdentifier == CSMI_SAS_IGNORE_PORT)) {
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_SELECT_PHY_OR_PORT;
+               dcsmisasprintk(ioc, printk(KERN_ERR
+-                  "%s::%s() @%d - incorrect bPhyIdentifier and bPortIdentifier!\n",
+-                  __FILE__,__FUNCTION__, __LINE__));
++                  "%s::%s() @%d -incorrect bPhyIdentifier"
++                  " and bPortIdentifier!\n",
++                  __FILE__, __func__, __LINE__));
+               goto cim_stp_passthru_exit;
+       }
+@@ -2897,15 +2899,15 @@ csmisas_stp_passthru(unsigned long arg)
+       }
+       data_sz = sizeof(CSMI_SAS_STP_PASSTHRU_BUFFER) -
+-          sizeof(IOCTL_HEADER) - sizeof(u8*) +
++          sizeof(IOCTL_HEADER) - sizeof(u8 *) +
+           request_data_sz;
+-      if ( data_sz > karg->IoctlHeader.Length ) {
++      if (data_sz > karg->IoctlHeader.Length) {
+               karg->IoctlHeader.ReturnCode =
+                   CSMI_SAS_STATUS_INVALID_PARAMETER;
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   "%s::%s() @%d - expected datalen incorrect!\n",
+-                  __FILE__, __FUNCTION__,__LINE__));
++                  __FILE__, __func__, __LINE__));
+               goto cim_stp_passthru_exit;
+       }
+@@ -2927,7 +2929,7 @@ csmisas_stp_passthru(unsigned long arg)
+                   CSMI_SAS_STATUS_INVALID_PARAMETER;
+               dcsmisasprintk(ioc, printk(KERN_ERR
+                   "%s::%s() @%d - couldn't find associated "
+-                  "SASAddress=%llX!\n", __FILE__, __FUNCTION__, __LINE__,
++                  "SASAddress=%llX!\n", __FILE__, __func__, __LINE__,
+                   (unsigned long long)sas_address));
+               goto cim_stp_passthru_exit;
+       }
+@@ -2937,8 +2939,8 @@ csmisas_stp_passthru(unsigned long arg)
+       /* check that this is an STP or SATA target device
+        */
+-      if ( !(sas_info->device_info & MPI_SAS_DEVICE_INFO_STP_TARGET ) &&
+-           !(sas_info->device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE )) {
++      if (!(sas_info->device_info & MPI_SAS_DEVICE_INFO_STP_TARGET) &&
++           !(sas_info->device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE)) {
+               karg->IoctlHeader.ReturnCode =
+                   CSMI_SAS_STATUS_INVALID_PARAMETER;
+               goto cim_stp_passthru_exit;
+@@ -2950,14 +2952,14 @@ csmisas_stp_passthru(unsigned long arg)
+               dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_stp_passthru_exit;
+-        }
++      }
  
-                       bytes_allocd += this_alloc;
--                      sgl->FlagsLength = (0x10000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|this_alloc);
-+                      sgl->FlagsLength = (0x10000000|sgdir|this_alloc);
-+                      if (ioc->sg_addr_size == sizeof(u64))
-+                              sgl->FlagsLength |= MPT_SGE_FLAGS_64_BIT_ADDRESSING;
-                       dma_addr = pci_map_single(ioc->pcidev, buflist[buflist_ent].kptr, this_alloc, dir);
-                       sgl->Address = dma_addr;
+       mpi_hdr = (MPIHeader_t *) mf;
+       MsgContext = mpi_hdr->MsgContext;
+       pSataRequest = (pSataPassthroughRequest_t) mf;
+       req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  
-@@ -1044,8 +1192,8 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, i
+-      memset(pSataRequest,0,sizeof(pSataPassthroughRequest_t));
++      memset(pSataRequest, 0, sizeof(pSataPassthroughRequest_t));
+       pSataRequest->TargetID = id;
+       pSataRequest->Bus = channel;
+@@ -2967,16 +2969,16 @@ csmisas_stp_passthru(unsigned long arg)
+       pSataRequest->MsgContext = MsgContext;
+       pSataRequest->DataLength = cpu_to_le32(request_data_sz);
+       pSataRequest->MsgFlags = 0;
+-      memcpy( pSataRequest->CommandFIS,karg->Parameters.bCommandFIS, 20);
++      memcpy(pSataRequest->CommandFIS, karg->Parameters.bCommandFIS, 20);
+       psge = (char *)&pSataRequest->SGL;
+       if (karg->Parameters.uFlags & CSMI_SAS_STP_WRITE) {
+               flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
+       } else if (karg->Parameters.uFlags & CSMI_SAS_STP_READ) {
+               flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
+-      }else {
+-              flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
+-                              MPI_SGE_FLAGS_DIRECTION )
++      } else {
++              flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
++                              MPI_SGE_FLAGS_DIRECTION)
+                               << MPI_SGE_FLAGS_SHIFT;
+       }
  
-               /* Need to chain? */
-               if (fragcnt == sg_spill) {
--                      printk(MYIOC_s_WARN_FMT
--                          "-SG: No can do - " "Chain required!   :-(\n", ioc->name);
-+                      printk(MYIOC_s_WARN_FMT "-SG: No can do - "
-+                          "Chain required! :-(\n", ioc->name);
-                       printk(MYIOC_s_WARN_FMT "(freeing %d frags)\n", ioc->name, numfrags);
-                       goto free_and_fail;
-               }
-@@ -1054,9 +1202,9 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, i
-               if (numfrags*8 > MAX_SGL_BYTES){
-                       /* GRRRRR... */
-                       printk(MYIOC_s_WARN_FMT "-SG: No can do - "
--                              "too many SG frags!   :-(\n", ioc->name);
-+                          "too many SG frags! :-(\n", ioc->name);
-                       printk(MYIOC_s_WARN_FMT "-SG: (freeing %d frags)\n",
--                              ioc->name, numfrags);
-+                          ioc->name, numfrags);
-                       goto free_and_fail;
+@@ -2986,7 +2988,8 @@ csmisas_stp_passthru(unsigned long arg)
+                   ioc->pcidev, request_data_sz, &request_data_dma);
+               if (request_data == NULL) {
+-                      dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++                      dcsmisasprintk(ioc, printk(KERN_ERR
++                              ": pci_alloc_consistent: FAILED\n"));
+                       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       mpt_free_msg_frame(ioc, mf);
+                       goto cim_stp_passthru_exit;
+@@ -2994,33 +2997,37 @@ csmisas_stp_passthru(unsigned long arg)
+               ioc->add_sge(psge, flagsLength, request_data_dma);
+               if (karg->Parameters.uFlags & CSMI_SAS_SSP_WRITE)
+-                      memcpy(request_data, karg->bDataBuffer, request_data_sz);
++                      memcpy(request_data, karg->bDataBuffer,
++                          request_data_sz);
+       } else {
+               ioc->add_sge(psge, flagsLength, (dma_addr_t) -1);
+       }
+-      if (csmisas_send_command_wait(ioc, mf, karg->IoctlHeader.Timeout) != 0) {
++      if (csmisas_send_command_wait(ioc, mf, karg->IoctlHeader.Timeout)
++          != 0) {
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_stp_passthru_exit;
+       }
+-      memset(&karg->Status,0,sizeof(CSMI_SAS_STP_PASSTHRU_STATUS));
++      memset(&karg->Status, 0, sizeof(CSMI_SAS_STP_PASSTHRU_STATUS));
+       if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0) {
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG  ": STP Passthru: oh no, there is no reply!!"));
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      ": STP Passthru: oh no, there is no reply!!"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_stp_passthru_exit;
+       }
+       /* process the completed Reply Message Frame */
+-      pSataReply = (pSataPassthroughReply_t ) ioc->ioctl_cmds.reply;
++      pSataReply = (pSataPassthroughReply_t) ioc->ioctl_cmds.reply;
+       ioc_status = le16_to_cpu(pSataReply->IOCStatus) & MPI_IOCSTATUS_MASK;
+       if (ioc_status != MPI_IOCSTATUS_SUCCESS &&
+           ioc_status != MPI_IOCSTATUS_SCSI_DATA_UNDERRUN) {
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               dcsmisasprintk(ioc, printk(KERN_DEBUG ": STP Passthru: "));
+-              dcsmisasprintk(ioc, printk("IOCStatus=0x%X IOCLogInfo=0x%X SASStatus=0x%X\n",
++              dcsmisasprintk(ioc,
++                  printk("IOCStatus=0x%X IOCLogInfo=0x%X SASStatus=0x%X\n",
+                   le16_to_cpu(pSataReply->IOCStatus),
+                   le32_to_cpu(pSataReply->IOCLogInfo),
+                   pSataReply->SASStatus));
+@@ -3029,26 +3036,27 @@ csmisas_stp_passthru(unsigned long arg)
+       karg->Status.bConnectionStatus =
+           map_sas_status_to_csmi(pSataReply->SASStatus);
+-      memcpy(karg->Status.bStatusFIS,pSataReply->StatusFIS, 20);
++      memcpy(karg->Status.bStatusFIS, pSataReply->StatusFIS, 20);
+       /*
+        * for now, just zero out uSCR array,
+        * then copy the one dword returned
+        * in the reply frame into uSCR[0]
+        */
+-      memset( karg->Status.uSCR, 0, 64);
++      memset(karg->Status.uSCR, 0, 64);
+       karg->Status.uSCR[0] = le32_to_cpu(pSataReply->StatusControlRegisters);
+-      if((le32_to_cpu(pSataReply->TransferCount)) && (request_data) &&
++      if ((le32_to_cpu(pSataReply->TransferCount)) && (request_data) &&
+           (karg->Parameters.uFlags & CSMI_SAS_STP_READ)) {
+               karg->Status.uDataBytes =
+-                  min(le32_to_cpu(pSataReply->TransferCount),request_data_sz);
++                  min(le32_to_cpu(pSataReply->TransferCount),
++                      request_data_sz);
+               if (copy_to_user((void __user *)uarg->bDataBuffer,
+                   request_data, karg->Status.uDataBytes)) {
+                       printk(KERN_ERR "%s::%s() @%d - "
+                           "Unable to write data to user %p\n",
+-                          __FILE__, __FUNCTION__, __LINE__,
+-                          (void*)karg->bDataBuffer);
++                          __FILE__, __func__, __LINE__,
++                          (void *)karg->bDataBuffer);
+                       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
                }
        }
-@@ -1213,6 +1361,7 @@ mptctl_getiocinfo (unsigned long arg, un
+@@ -3065,13 +3073,13 @@ csmisas_stp_passthru(unsigned long arg)
+           offsetof(CSMI_SAS_STP_PASSTHRU_BUFFER, bDataBuffer))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to write out csmi_sas_ssp_passthru @ %p\n",
+-                              __FILE__, __LINE__, __FUNCTION__, uarg);
++                              __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
+       }
  
-       if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
-           (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
-               kfree(karg);
-@@ -1222,8 +1371,8 @@ mptctl_getiocinfo (unsigned long arg, un
-       /* Verify the data transfer size is correct. */
-       if (karg->hdr.maxDataSize != data_size) {
-               printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_getiocinfo - "
--                      "Structure size mismatch. Command not completed.\n",
--                      ioc->name, __FILE__, __LINE__);
-+                  "Structure size mismatch. Command not completed.\n",
-+                  ioc->name, __FILE__, __LINE__);
-               kfree(karg);
+       free_pages((unsigned long)karg, memory_pages);
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG ": %s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG ": %s exit.\n", __func__));
+       return 0;
+ }
+@@ -3090,30 +3098,30 @@ csmisas_firmware_download(unsigned long 
+       CSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER        karg;
+       MPT_ADAPTER                     *ioc = NULL;
+       int                             iocnum;
+-      pMpiFwHeader_t                  pFwHeader=NULL;
++      pMpiFwHeader_t                  pFwHeader = NULL;
+       if (copy_from_user(&karg, uarg,
+               sizeof(CSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+-                  "Unable to read in csmi_sas_firmware_download struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  "Unable to read in csmi_sas_firmware_download struct@ %p\n",
++                  __FILE__, __LINE__, __func__, uarg);
                return -EFAULT;
        }
-@@ -1275,6 +1424,8 @@ mptctl_getiocinfo (unsigned long arg, un
-       if (ioc->sh) {
-               shost_for_each_device(sdev, ioc->sh) {
-                       vdevice = sdev->hostdata;
-+                      if (vdevice == NULL || vdevice->vtarget == NULL)
-+                              continue;
-                       if (vdevice->vtarget->tflags &
-                           MPT_TARGET_FLAGS_RAID_COMPONENT)
-                               continue;
-@@ -1346,6 +1497,7 @@ mptctl_gettargetinfo (unsigned long arg)
  
-       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-           (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
                return -ENODEV;
-@@ -1362,8 +1514,8 @@ mptctl_gettargetinfo (unsigned long arg)
-       port = karg.hdr.port;
+       }
  
-       if (maxWordsLeft <= 0) {
--              printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
--                      ioc->name, __FILE__, __LINE__);
-+              printk(MYIOC_s_ERR_FMT "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
-+                  ioc->name, __FILE__, __LINE__);
-               return -ENOMEM;
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
        }
  
-@@ -1383,8 +1535,8 @@ mptctl_gettargetinfo (unsigned long arg)
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
+       /* Default to success.*/
+       karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
+@@ -3130,7 +3138,7 @@ csmisas_firmware_download(unsigned long 
+               goto cim_firmware_download_exit;
+       }
+-      if ( karg.Information.uDownloadFlags &
++      if (karg.Information.uDownloadFlags &
+           (CSMI_SAS_FWD_SOFT_RESET | CSMI_SAS_FWD_VALIDATE)) {
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               karg.Information.usStatus = CSMI_SAS_FWD_REJECT;
+@@ -3142,7 +3150,7 @@ csmisas_firmware_download(unsigned long 
+        * fw image attached to end of incoming packet.
         */
-       pmem = kzalloc(numBytes, GFP_KERNEL);
-       if (!pmem) {
--              printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_gettargetinfo() - no memory available!\n",
--                      ioc->name, __FILE__, __LINE__);
-+              printk(MYIOC_s_ERR_FMT "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
-+                  ioc->name, __FILE__, __LINE__);
-               return -ENOMEM;
+       pFwHeader = kmalloc(karg.Information.uBufferLength, GFP_KERNEL);
+-      if (!pFwHeader){
++      if (!pFwHeader) {
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               karg.Information.usStatus = CSMI_SAS_FWD_REJECT;
+               karg.Information.usSeverity = CSMI_SAS_FWD_ERROR;
+@@ -3154,21 +3162,21 @@ csmisas_firmware_download(unsigned long 
+               karg.Information.uBufferLength)) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in pFwHeader @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
-       pdata =  (int *) pmem;
-@@ -1396,6 +1548,8 @@ mptctl_gettargetinfo (unsigned long arg)
-                       if (!maxWordsLeft)
-                               continue;
-                       vdevice = sdev->hostdata;
-+                      if (vdevice == NULL || vdevice->vtarget == NULL)
-+                              continue;
-                       if (vdevice->vtarget->tflags &
-                           MPT_TARGET_FLAGS_RAID_COMPONENT)
-                               continue;
-@@ -1460,6 +1614,7 @@ mptctl_readtest (unsigned long arg)
  
-       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-           (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_readtest() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
-               return -ENODEV;
-@@ -1521,6 +1676,7 @@ mptctl_eventquery (unsigned long arg)
+-      if ( !((pFwHeader->Signature0 == MPI_FW_HEADER_SIGNATURE_0) &&
++      if (!((pFwHeader->Signature0 == MPI_FW_HEADER_SIGNATURE_0) &&
+           (pFwHeader->Signature1 == MPI_FW_HEADER_SIGNATURE_1) &&
+           (pFwHeader->Signature2 == MPI_FW_HEADER_SIGNATURE_2))) {
+-              // the signature check failed
++              /* the signature check failed */
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               karg.Information.usStatus = CSMI_SAS_FWD_REJECT;
+               karg.Information.usSeverity = CSMI_SAS_FWD_ERROR;
+               goto cim_firmware_download_exit;
+       }
+-      if ( mptctl_do_fw_download(karg.IoctlHeader.IOControllerNumber,
++      if (mptctl_do_fw_download(karg.IoctlHeader.IOControllerNumber,
+           uarg->bDataBuffer, karg.Information.uBufferLength)
+           != 0) {
+               karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+@@ -3177,7 +3185,7 @@ csmisas_firmware_download(unsigned long 
+               goto cim_firmware_download_exit;
+       }
+-      if((karg.Information.uDownloadFlags & CSMI_SAS_FWD_SOFT_RESET) ||
++      if ((karg.Information.uDownloadFlags & CSMI_SAS_FWD_SOFT_RESET) ||
+           (karg.Information.uDownloadFlags & CSMI_SAS_FWD_HARD_RESET)) {
+               if (mpt_HardResetHandler(ioc, CAN_SLEEP) != 0) {
+                       karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+@@ -3188,7 +3196,7 @@ csmisas_firmware_download(unsigned long 
+  cim_firmware_download_exit:
+-      if(pFwHeader)
++      if (pFwHeader)
+               kfree(pFwHeader);
+       /* Copy the data from kernel memory to user memory
+@@ -3197,11 +3205,11 @@ csmisas_firmware_download(unsigned long 
+                               sizeof(CSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to write out csmi_sas_firmware_download @ %p\n",
+-                              __FILE__, __LINE__, __FUNCTION__, uarg);
++                              __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-           (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_eventquery() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
-               return -ENODEV;
-@@ -1560,6 +1716,7 @@ mptctl_eventenable (unsigned long arg)
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
+ }
  
-       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-           (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_eventenable() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
+@@ -3227,24 +3235,24 @@ csmisas_get_raid_info(unsigned long arg)
+       if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_RAID_INFO_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_get_raid_info struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
                return -ENODEV;
-@@ -1573,8 +1730,7 @@ mptctl_eventenable (unsigned long arg)
-               int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
-               ioc->events = kzalloc(sz, GFP_KERNEL);
-               if (!ioc->events) {
--                      printk(MYIOC_s_ERR_FMT
--                          ": ERROR - Insufficient memory to add adapter!\n",
-+                      printk(MYIOC_s_ERR_FMT "Insufficient memory to add adapter!\n",
-                           ioc->name);
-                       return -ENOMEM;
-               }
-@@ -1609,13 +1765,14 @@ mptctl_eventreport (unsigned long arg)
+       }
  
-       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-           (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_eventreport() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
                return -ENODEV;
        }
-+
-       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_eventreport called.\n",
-           ioc->name));
--
-       numBytes = karg.hdr.maxDataSize - sizeof(mpt_ioctl_header);
-       maxEvents = numBytes/sizeof(MPT_IOCTL_EVENTS);
  
-@@ -1663,6 +1820,7 @@ mptctl_replace_fw (unsigned long arg)
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
-       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-           (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
-               return -ENODEV;
-@@ -1694,8 +1852,8 @@ mptctl_replace_fw (unsigned long arg)
-        */
-       if (copy_from_user(ioc->cached_fw, uarg->newImage, newFwSize)) {
-               printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_replace_fw - "
--                              "Unable to read in mpt_ioctl_replace_fw image "
--                              "@ %p\n", ioc->name, __FILE__, __LINE__, uarg);
-+                      "Unable to read in mpt_ioctl_replace_fw image "
-+                      "@ %p\n", ioc->name, __FILE__, __LINE__, uarg);
-               mpt_free_fw_memory(ioc);
+       karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+       if (!ioc->raid_data.pIocPg2)
+@@ -3252,8 +3260,8 @@ csmisas_get_raid_info(unsigned long arg)
+       karg.Information.uNumRaidSets =
+           ioc->raid_data.pIocPg2->NumActiveVolumes;
+       karg.Information.uMaxRaidSets = ioc->raid_data.pIocPg2->MaxVolumes;
+-      if( ioc->raid_data.pIocPg6 ) {
+-              // get absolute maximum for all RAID sets
++      if (ioc->raid_data.pIocPg6) {
++              /* get absolute maximum for all RAID sets */
+               maxDrivesPerSet = ioc->raid_data.pIocPg6->MaxDrivesIS;
+               maxDrivesPerSet = max(ioc->raid_data.pIocPg6->MaxDrivesIM,
+                   maxDrivesPerSet);
+@@ -3263,17 +3271,19 @@ csmisas_get_raid_info(unsigned long arg)
+       }
+       else
+               karg.Information.uMaxDrivesPerSet = 8;
+-      // For bMaxRaidSets, count bits set in bits 0-6 of CapabilitiesFlags
++      /* For bMaxRaidSets, count bits set in bits 0-6 of CapabilitiesFlags */
+       raidFlags = ioc->raid_data.pIocPg2->CapabilitiesFlags & 0x0000007F;
+-      for( maxRaidTypes=0; raidFlags; maxRaidTypes++ )
++      for (maxRaidTypes = 0; raidFlags; maxRaidTypes++)
+               raidFlags &= raidFlags - 1;
+       karg.Information.bMaxRaidTypes = maxRaidTypes;
+-      // ulMinRaidSetBlocks hard coded to 1MB until available from config page
++      /* ulMinRaidSetBlocks hard coded to 1MB until available
++       * from config page
++       */
+       karg.Information.ulMinRaidSetBlocks.uLowPart = 2048;
+       karg.Information.ulMinRaidSetBlocks.uHighPart = 0;
+       karg.Information.ulMaxRaidSetBlocks.uLowPart = 0xffffffff;
+-      if( ioc->raid_data.pIocPg2->CapabilitiesFlags &
+-          MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING )
++      if (ioc->raid_data.pIocPg2->CapabilitiesFlags &
++          MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING)
+               karg.Information.ulMaxRaidSetBlocks.uHighPart = 0xffffffff;
+       else
+               karg.Information.ulMaxRaidSetBlocks.uHighPart = 0;
+@@ -3293,11 +3303,11 @@ csmisas_get_raid_info_out:
+                               sizeof(CSMI_SAS_RAID_INFO_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to write out csmi_sas_get_raid_info @ %p\n",
+-                              __FILE__, __LINE__, __FUNCTION__, uarg);
++                              __FILE__, __LINE__, __func__, uarg);
                return -EFAULT;
        }
-@@ -1712,7 +1870,7 @@ mptctl_replace_fw (unsigned long arg)
-  *
-  * Outputs:   None.
-  * Return:    0 if successful
-- *            -EBUSY  if previous command timeout and IOC reset is not complete.
-+ *            -EBUSY  if previous command timout and IOC reset is not complete.
-  *            -EFAULT if data unavailable
-  *            -ENODEV if no such device/adapter
-  *            -ETIME  if timer expires
-@@ -1737,6 +1895,7 @@ mptctl_mpt_command (unsigned long arg)
  
-       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-           (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
-               return -ENODEV;
-@@ -1752,7 +1911,7 @@ mptctl_mpt_command (unsigned long arg)
-  *
-  * Outputs:   None.
-  * Return:    0 if successful
-- *            -EBUSY  if previous command timeout and IOC reset is not complete.
-+ *            -EBUSY  if previous command timout and IOC reset is not complete.
-  *            -EFAULT if data unavailable
-  *            -ENODEV if no such device/adapter
-  *            -ETIME  if timer expires
-@@ -1775,8 +1934,11 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-       int             sz, rc = 0;
-       int             msgContext;
-       u16             req_idx;
--      ulong           timeout;
-+      unsigned long   timeout;
-+      unsigned long   timeleft;
-       struct scsi_device *sdev;
-+      unsigned long    flags;
-+      u8               function;
-       /* bufIn and bufOut are used for user to kernel space transfers
-        */
-@@ -1785,28 +1947,28 @@ mptctl_do_mpt_command (struct mpt_ioctl_
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
+ }
  
-       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-           (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
-               return -ENODEV;
-       }
--      if (!ioc->ioctl) {
--              printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - "
--                      "No memory available during driver init.\n",
--                              __FILE__, __LINE__);
--              return -ENOMEM;
--      } else if (ioc->ioctl->status & MPT_IOCTL_STATUS_DID_IOCRESET) {
-+
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-+      if (ioc->ioc_reset_in_progress) {
-+              spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-               printk(KERN_ERR MYNAM "%s@%d::mptctl_do_mpt_command - "
--                      "Busy with IOC Reset \n", __FILE__, __LINE__);
-+                      "Busy with diagnostic reset\n", __FILE__, __LINE__);
-               return -EBUSY;
+@@ -3315,7 +3325,8 @@ csmisas_get_raid_info_out:
+  *    Remark: Wait to return until reply processed by the ISR.
+  **/
+ static int
+-csmisas_do_raid(MPT_ADAPTER *ioc, u8 action, u8 PhysDiskNum, u8 VolumeBus, u8 VolumeId, pMpiRaidActionReply_t reply)
++csmisas_do_raid(MPT_ADAPTER *ioc, u8 action, u8 PhysDiskNum, u8 VolumeBus,
++    u8 VolumeId, pMpiRaidActionReply_t reply)
+ {
+       MpiRaidActionRequest_t  *pReq;
+       MpiRaidActionReply_t    *pReply;
+@@ -3338,7 +3349,6 @@ csmisas_do_raid(MPT_ADAPTER *ioc, u8 act
+       pReq->MsgFlags = 0;
+       pReq->Reserved2 = 0;
+       pReq->ActionDataWord = 0; /* Reserved for this action */
+-      //pReq->ActionDataSGE = 0;
+       ioc->add_sge((char *)&pReq->ActionDataSGE,
+               MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
+@@ -3347,7 +3357,7 @@ csmisas_do_raid(MPT_ADAPTER *ioc, u8 act
+               return -ENODATA;
+       if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) &&
+-          (reply != NULL)){
++          (reply != NULL)) {
+               pReply = (MpiRaidActionReply_t *)&(ioc->ioctl_cmds.reply);
+               memcpy(reply, pReply,
+                       min(ioc->reply_sz,
+@@ -3371,7 +3381,7 @@ csmisas_do_raid(MPT_ADAPTER *ioc, u8 act
+  **/
+ static int
+ csmisas_raid_inq(MPT_ADAPTER *ioc, u8 opcode, u8 bus, u8 id, u8 inq_vpd_page,
+-    u8 * inq_vpd, u32 inq_vpd_sz)
++    u8 *inq_vpd, u32 inq_vpd_sz)
+ {
+       MPT_FRAME_HDR           *mf = NULL;
+       MPIHeader_t             *mpi_hdr;
+@@ -3379,7 +3389,7 @@ csmisas_raid_inq(MPT_ADAPTER *ioc, u8 op
+       u16                     req_idx;
+       char                    *psge;
+       u8                      inq_vpd_cdb[6];
+-      u8                      *request_data=NULL;
++      u8                      *request_data = NULL;
+       dma_addr_t              request_data_dma;
+       u32                     request_data_sz;
+       int                     rc = 0;
+@@ -3409,14 +3419,14 @@ csmisas_raid_inq(MPT_ADAPTER *ioc, u8 op
+       pScsiRequest = (pSCSIIORequest_t) mf;
+       req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
+-      memset(pScsiRequest,0,sizeof(SCSIIORequest_t));
++      memset(pScsiRequest, 0, sizeof(SCSIIORequest_t));
+       pScsiRequest->Function = opcode;
+       pScsiRequest->TargetID = id;
+       pScsiRequest->Bus = bus;
+       pScsiRequest->CDBLength = 6;
+       pScsiRequest->DataLength = cpu_to_le32(request_data_sz);
+       pScsiRequest->MsgContext = MsgContext;
+-      memcpy(pScsiRequest->CDB,inq_vpd_cdb,pScsiRequest->CDBLength);
++      memcpy(pScsiRequest->CDB, inq_vpd_cdb, pScsiRequest->CDBLength);
+       pScsiRequest->Control = cpu_to_le32(MPI_SCSIIO_CONTROL_READ);
+       pScsiRequest->Control |= cpu_to_le32(MPI_SCSIIO_CONTROL_SIMPLEQ);
+       pScsiRequest->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
+@@ -3434,17 +3444,18 @@ csmisas_raid_inq(MPT_ADAPTER *ioc, u8 op
+       if (request_data == NULL) {
+               mpt_free_msg_frame(ioc, mf);
+-              rc=-1;
++              rc = -1;
+               goto csmisas_raid_inq_exit;
        }
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  
-       /* Verify that the final request frame will not be too large.
-        */
-       sz = karg.dataSgeOffset * 4;
-       if (karg.dataInSize > 0)
--              sz += sizeof(dma_addr_t) + sizeof(u32);
-+              sz += ioc->SGE_size;
-       if (karg.dataOutSize > 0)
--              sz += sizeof(dma_addr_t) + sizeof(u32);
-+              sz += ioc->SGE_size;
-       if (sz > ioc->req_sz) {
-               printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
-@@ -1832,18 +1994,19 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-               printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
-                       "Unable to read MF from mpt_ioctl_command struct @ %p\n",
-                       ioc->name, __FILE__, __LINE__, mfPtr);
-+              function = -1;
-               rc = -EFAULT;
-               goto done_free_mem;
+-      memset(request_data,0,request_data_sz);
++      memset(request_data, 0, request_data_sz);
+       psge = (char *)&pScsiRequest->SGL;
+       ioc->add_sge(psge, (MPT_SGE_FLAGS_SSIMPLE_READ | 0xFC) ,
+           request_data_dma);
+-      if (csmisas_send_command_wait(ioc, mf, MPT_IOCTL_DEFAULT_TIMEOUT) != 0) {
+-              rc=-1;
++      if (csmisas_send_command_wait(ioc, mf, MPT_IOCTL_DEFAULT_TIMEOUT)
++          != 0) {
++              rc = -1;
+               goto csmisas_raid_inq_exit;
        }
-       hdr->MsgContext = cpu_to_le32(msgContext);
--
-+      function = hdr->Function;
  
-       /* Verify that this request is allowed.
-        */
-       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sending mpi function (0x%02X), req=%p\n",
--          ioc->name, hdr->Function, mf));
-+          ioc->name, function, mf));
--      switch (hdr->Function) {
-+      switch (function) {
-       case MPI_FUNCTION_IOC_FACTS:
-       case MPI_FUNCTION_PORT_FACTS:
-               karg.dataOutSize  = karg.dataInSize = 0;
-@@ -1898,7 +2061,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                       }
+@@ -3472,7 +3483,7 @@ static int
+ csmisas_get_raid_config(unsigned long arg)
+ {
+       CSMI_SAS_RAID_CONFIG_BUFFER __user *uarg = (void __user *) arg;
+-      CSMI_SAS_RAID_CONFIG_BUFFER      karg,*pKarg=NULL;
++      CSMI_SAS_RAID_CONFIG_BUFFER      karg, *pKarg = NULL;
+       CONFIGPARMS                     cfg;
+       ConfigPageHeader_t              header;
+       MPT_ADAPTER                     *ioc = NULL;
+@@ -3498,7 +3509,7 @@ csmisas_get_raid_config(unsigned long ar
+       if (copy_from_user(&karg, uarg, sizeof(IOCTL_HEADER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmisas_get_raid_config struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-                       pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
--                      pScsiReq->MsgFlags |= mpt_msg_flags();
-+                      pScsiReq->MsgFlags |= mpt_msg_flags(ioc);
+@@ -3506,11 +3517,11 @@ csmisas_get_raid_config(unsigned long ar
+       memory_pages = get_order(csmi_sas_raid_config_buffer_sz);
+       pKarg = (CSMI_SAS_RAID_CONFIG_BUFFER *)__get_free_pages(
+               GFP_KERNEL, memory_pages);
+-      if (!pKarg){
++      if (!pKarg) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to malloc RAID_CONFIG_BUFFER "
+                       "csmi_sas_raid_config_buffer_sz=%d memory_pages=%d\n",
+-                      __FILE__, __LINE__, __FUNCTION__,
++                      __FILE__, __LINE__, __func__,
+                       csmi_sas_raid_config_buffer_sz, memory_pages);
+               return -ENOMEM;
+       }
+@@ -3519,7 +3530,7 @@ csmisas_get_raid_config(unsigned long ar
+       if (copy_from_user(pKarg, uarg, csmi_sas_raid_config_buffer_sz)) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmisas_get_raid_config struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -EFAULT;
+       }
+@@ -3527,22 +3538,22 @@ csmisas_get_raid_config(unsigned long ar
+       if (((iocnum = mpt_verify_adapter(pKarg->IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -ENODEV;
+       }
  
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -ENODEV;
+       }
  
-                       /* verify that app has not requested
-@@ -1920,6 +2083,8 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                               struct scsi_target *starget = scsi_target(sdev);
-                               VirtTarget *vtarget = starget->hostdata;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
-+                              if (vtarget == NULL)
-+                                      continue;
-                               if ((pScsiReq->TargetID == vtarget->id) &&
-                                   (pScsiReq->Bus == vtarget->channel) &&
-                                   (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
-@@ -1940,9 +2105,6 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                       pScsiReq->Control = cpu_to_le32(scsidir | qtag);
-                       pScsiReq->DataLength = cpu_to_le32(dataSize);
+       if (pKarg->Configuration.uChangeCount != 0 &&
+-              pKarg->Configuration.uChangeCount != ioc->csmi_change_count ) {
++              pKarg->Configuration.uChangeCount != ioc->csmi_change_count) {
+               pKarg->IoctlHeader.ReturnCode =
+                   CSMI_SAS_STATUS_INVALID_PARAMETER;
+               pKarg->Configuration.uFailureCode =
+@@ -3615,7 +3626,7 @@ csmisas_get_raid_config(unsigned long ar
+       pKarg->Configuration.uStripeSize =
+               le32_to_cpu(pVolume0->StripeSize)/2;
  
--                      ioc->ioctl->reset = MPTCTL_RESET_OK;
--                      ioc->ioctl->id = pScsiReq->TargetID;
--
+-      switch(pVolume0->VolumeType) {
++      switch (pVolume0->VolumeType) {
+       case MPI_RAID_VOL_TYPE_IS:
+               pKarg->Configuration.bRaidType = CSMI_SAS_RAID_TYPE_0;
+               break;
+@@ -3636,7 +3647,8 @@ csmisas_get_raid_config(unsigned long ar
+               break;
+       case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
+               /* Volume is degraded, check if Resyncing or Inactive */
+-              pKarg->Configuration.bStatus = CSMI_SAS_RAID_SET_STATUS_DEGRADED;
++              pKarg->Configuration.bStatus
++                  = CSMI_SAS_RAID_SET_STATUS_DEGRADED;
+               break;
+       case MPI_RAIDVOL0_STATUS_STATE_FAILED:
+               pKarg->Configuration.bStatus = CSMI_SAS_RAID_SET_STATUS_FAILED;
+@@ -3649,25 +3661,26 @@ csmisas_get_raid_config(unsigned long ar
+               pKarg->Configuration.bStatus = CSMI_SAS_RAID_SET_STATUS_OFFLINE;
+       else if (pVolume0->VolumeStatus.Flags &
+           MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
+-              pKarg->Configuration.bStatus = CSMI_SAS_RAID_SET_STATUS_REBUILDING;
++              pKarg->Configuration.bStatus
++                  = CSMI_SAS_RAID_SET_STATUS_REBUILDING;
+       pKarg->Configuration.bInformation = 0;  /* default */
+-      if(pVolume0->VolumeStatus.Flags &
+-          MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS ) {
++      if (pVolume0->VolumeStatus.Flags &
++          MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
+-              uint64_t        * ptrUint64;
++              uint64_t        *ptrUint64;
+               uint64_t        totalBlocks64, blocksRemaining64;
+               uint32_t        totalBlocks32, blocksRemaining32;
+               /* get percentage complete */
+-              pRaidActionReply = kmalloc( sizeof(MPI_RAID_VOL_INDICATOR) +
+-                  offsetof(MSG_RAID_ACTION_REPLY,ActionData),
++              pRaidActionReply = kmalloc(sizeof(MPI_RAID_VOL_INDICATOR) +
++                  offsetof(MSG_RAID_ACTION_REPLY, ActionData),
+                   GFP_KERNEL);
+-              if (!pRaidActionReply){
++              if (!pRaidActionReply) {
+                       printk(KERN_ERR "%s@%d::%s() - "
+                           "Unable to malloc @ %p\n",
+-                          __FILE__, __LINE__, __FUNCTION__,pKarg);
++                          __FILE__, __LINE__, __func__, pKarg);
+                       goto cim_get_raid_config_exit;
+               }
+               memset(pRaidActionReply, 0, sizeof(*pRaidActionReply));
+@@ -3680,14 +3693,14 @@ csmisas_get_raid_config(unsigned long ar
+               totalBlocks64     = *ptrUint64;
+               ptrUint64++;
+               blocksRemaining64 = *ptrUint64;
+-              while(totalBlocks64 > 0xFFFFFFFFUL){
++              while (totalBlocks64 > 0xFFFFFFFFUL) {
+                       totalBlocks64 = totalBlocks64 >> 1;
+                       blocksRemaining64 = blocksRemaining64 >> 1;
+               }
+               totalBlocks32 = (uint32_t)totalBlocks64;
+               blocksRemaining32 = (uint32_t)blocksRemaining64;
+-              if(totalBlocks32)
++              if (totalBlocks32)
+                       pKarg->Configuration.bInformation =
+                           (totalBlocks32 - blocksRemaining32) /
+                           (totalBlocks32 / 100);
+@@ -3713,15 +3726,14 @@ csmisas_get_raid_config(unsigned long ar
+               pKarg->Configuration.Data->ulRaidSetBlocks.uHighPart =
+                   le32_to_cpu(pVolume0->MaxLBAHigh);
+               if (pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IS ||
+-                  pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IME ) {
++                  pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IME) {
+                       pKarg->Configuration.Data->uStripeSizeInBlocks =
+                           le32_to_cpu(pVolume0->StripeSize);
                } else {
-                       printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
-                               "SCSI driver is not loaded. \n",
-@@ -1955,7 +2117,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-       case MPI_FUNCTION_SMP_PASSTHROUGH:
-               /* Check mf->PassthruFlags to determine if
-                * transfer is ImmediateMode or not.
--               * Immediate mode returns data in the ReplyFrame.
-+               * Immediate mode returns data in the reply.
-                * Else, we are sending request and response data
-                * in two SGLs at the end of the mf.
-                */
-@@ -1984,7 +2146,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                       int dataSize;
+                       pKarg->Configuration.Data->uStripeSizeInBlocks = 0;
+               }
+               pKarg->Configuration.Data->uSectorsPerTrack = 128;
+-              for (i=0; i<16; i++) {
+-                      // unsupported
++              for (i = 0; i < 16; i++) {
+                       pKarg->Configuration.Data->bApplicationScratchPad[i] =
+                           0xFF;
+               }
+@@ -3732,15 +3744,15 @@ csmisas_get_raid_config(unsigned long ar
+                   (pKarg->Configuration.Data->uNumberOfHeads *
+                    pKarg->Configuration.Data->uSectorsPerTrack));
+               pKarg->Configuration.Data->uNumberOfTracks = tmpTotalMaxLBA;
+-      } else if ( pKarg->Configuration.bDataType ==
+-          CSMI_SAS_RAID_DATA_DEVICE_ID ) {
++      } else if (pKarg->Configuration.bDataType ==
++          CSMI_SAS_RAID_DATA_DEVICE_ID) {
+               /* Send inquiry to get VPD Page 0x83 */
+               u32 vpd_page_sz;
+               vpd_page_sz = csmi_sas_raid_config_buffer_sz -
+-                  offsetof(CSMI_SAS_RAID_CONFIG,DeviceId);
++                  offsetof(CSMI_SAS_RAID_CONFIG, DeviceId);
+               if (csmisas_raid_inq(ioc, MPI_FUNCTION_SCSI_IO_REQUEST,
+                       VolumeBus, volumeID, 0x83,
+-                      (u8*)&pKarg->Configuration.DeviceId->bDeviceIdentificationVPDPage,
++                      (u8 *)&pKarg->Configuration.DeviceId->bDeviceIdentificationVPDPage,
+                       vpd_page_sz) != 0) {
+                       pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       goto cim_get_raid_config_exit;
+@@ -3773,7 +3785,7 @@ csmisas_get_raid_config(unsigned long ar
+                       pIocPage5 = pci_alloc_consistent(ioc->pcidev,
+                           ioc_page5_sz,
+                           &ioc_page5_dma);
+-                      memset(pIocPage5,0,ioc_page5_sz);
++                      memset(pIocPage5, 0, ioc_page5_sz);
+                       if (ioc_page5_dma) {
+                               cfg.physAddr = ioc_page5_dma;
+                               cfg.action =
+@@ -3816,52 +3828,55 @@ csmisas_get_raid_config(unsigned long ar
+       cfg.physAddr = physdisk0_dma;
+       physDiskNumMax = (csmi_sas_raid_config_buffer_sz -
+-          offsetof(CSMI_SAS_RAID_CONFIG,Drives))
++          offsetof(CSMI_SAS_RAID_CONFIG, Drives))
+           / sizeof(CSMI_SAS_RAID_DRIVES);
+       tmpTotalMaxLBA = totalMaxLBA;
+       if (pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IS) {
+               do_div(tmpTotalMaxLBA, pVolume0->NumPhysDisks);
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "IS Volume tmpTotalMaxLBA=%llX\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "IS Volume tmpTotalMaxLBA=%llX\n",
+               (unsigned long long)tmpTotalMaxLBA));
+-      }
+-      else if (pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IME) {
++      } else if (pVolume0->VolumeType == MPI_RAID_VOL_TYPE_IME) {
+               do_div(tmpTotalMaxLBA, pVolume0->NumPhysDisks * 2);
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "IME Volume tmpTotalMaxLBA=%llX\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "IME Volume tmpTotalMaxLBA=%llX\n",
+               (unsigned long long)tmpTotalMaxLBA));
+       } else {
+-              dcsmisasprintk(ioc, printk(KERN_DEBUG "IM Volume tmpTotalMaxLBA=%llX\n",
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "IM Volume tmpTotalMaxLBA=%llX\n",
+               (unsigned long long)tmpTotalMaxLBA));
+       }
+-      for (i=0; i< min(pVolume0->NumPhysDisks, physDiskNumMax); i++) {
++      for (i = 0; i < min(pVolume0->NumPhysDisks, physDiskNumMax); i++) {
  
-                       pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
--                      pScsiReq->MsgFlags |= mpt_msg_flags();
-+                      pScsiReq->MsgFlags |= mpt_msg_flags(ioc);
+               physDiskNum = pVolume0->PhysDisk[i].PhysDiskNum;
+               cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+               cfg.pageAddr = physDiskNum;
+-              if (mpt_config(ioc, &cfg) != 0){
++              if (mpt_config(ioc, &cfg) != 0) {
+                       pKarg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       goto cim_get_raid_config_exit;
+               }
  
+-              pKarg->Configuration.bDriveCount++;
++              pKarg->Configuration.bDriveCount++;
+               if (pKarg->Configuration.bDataType != CSMI_SAS_RAID_DATA_DRIVES)
+                       continue;
  
-                       /* verify that app has not requested
-@@ -2019,8 +2181,6 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                       pScsiReq->Control = cpu_to_le32(scsidir | qtag);
-                       pScsiReq->DataLength = cpu_to_le32(dataSize);
+               /* Search the list for the matching SAS address. */
+-              sas_info = csmisas_get_device_component_by_fw(ioc, pPhysDisk0->PhysDiskBus,
+-                  pPhysDisk0->PhysDiskID);
++              sas_info = csmisas_get_device_component_by_fw(ioc,
++                  pPhysDisk0->PhysDiskBus, pPhysDisk0->PhysDiskID);
+               if (sas_info) {
+-                      sas_address = reverse_byte_order64(sas_info->sas_address);
++                      sas_address
++                          = reverse_byte_order64(sas_info->sas_address);
+                       memcpy(pKarg->Configuration.Drives[i].bSASAddress,
+-                         &sas_address,sizeof(u64));
++                         &sas_address, sizeof(u64));
+                       if (!device_info)
+                               device_info = sas_info->device_info;
+               }
  
--                      ioc->ioctl->reset = MPTCTL_RESET_OK;
--                      ioc->ioctl->id = pScsiReq->TargetID;
-               } else {
-                       printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
-                               "SCSI driver is not loaded. \n",
-@@ -2031,20 +2191,15 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-               break;
+               memcpy(pKarg->Configuration.Drives[i].bModel,
+                   pPhysDisk0->InquiryData.VendorID,
+-                  offsetof(RAID_PHYS_DISK0_INQUIRY_DATA,ProductRevLevel));
++                  offsetof(RAID_PHYS_DISK0_INQUIRY_DATA, ProductRevLevel));
+               memcpy(pKarg->Configuration.Drives[i].bFirmware,
+                       pPhysDisk0->InquiryData.ProductRevLevel,
+                       sizeof(pPhysDisk0->InquiryData.ProductRevLevel));
+@@ -3890,19 +3905,19 @@ csmisas_get_raid_config(unsigned long ar
+                   MPI_PHYSDISK0_STATUS_OFFLINE_REQUESTED) {
+                       pKarg->Configuration.Drives[i].bDriveStatus =
+                           CSMI_SAS_DRIVE_STATUS_OFFLINE;
+-              } else if(pPhysDisk0->PhysDiskStatus.State) {
++              } else if (pPhysDisk0->PhysDiskStatus.State) {
+                       pKarg->Configuration.Drives[i].bDriveStatus =
+                           CSMI_SAS_DRIVE_STATUS_FAILED;
+-                      if(pKarg->Configuration.bStatus ==
++                      if (pKarg->Configuration.bStatus ==
+                           CSMI_SAS_RAID_SET_STATUS_DEGRADED)
+                               pKarg->Configuration.bInformation = i;
+-              } else if((pVolume0->VolumeStatus.Flags &
++              } else if ((pVolume0->VolumeStatus.Flags &
+                   MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) &&
+                   (pPhysDisk0->PhysDiskStatus.Flags &
+                   MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC))
+                       pKarg->Configuration.Drives[i].bDriveStatus =
+                           CSMI_SAS_DRIVE_STATUS_REBUILDING;
+-              else if(pPhysDisk0->ErrorData.SmartCount ||
++              else if (pPhysDisk0->ErrorData.SmartCount ||
+                   (pPhysDisk0->PhysDiskStatus.Flags &
+                   MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC))
+                       pKarg->Configuration.Drives[i].bDriveStatus =
+@@ -3918,7 +3933,7 @@ csmisas_get_raid_config(unsigned long ar
+                               CSMI_SAS_DRIVE_TYPE_SINGLE_PORT_SAS;
+                       if (mpt_raid_phys_disk_get_num_paths(ioc,
+                           pVolume0->PhysDisk[i].PhysDiskNum) > 1)
+-                                      pKarg->Configuration.Drives[i].bDriveType =
++                              pKarg->Configuration.Drives[i].bDriveType =
+                                           CSMI_SAS_DRIVE_TYPE_DUAL_PORT_SAS;
+               }
  
-       case MPI_FUNCTION_SCSI_TASK_MGMT:
--              {
--                      MPT_SCSI_HOST *hd = NULL;
--                      if ((ioc->sh == NULL) || ((hd = shost_priv(ioc->sh)) == NULL)) {
--                              printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
--                                      "SCSI driver not loaded or SCSI host not found. \n",
--                                      ioc->name, __FILE__, __LINE__);
--                              rc = -EFAULT;
--                              goto done_free_mem;
--                      } else if (mptctl_set_tm_flags(hd) != 0) {
--                              rc = -EPERM;
--                              goto done_free_mem;
--                      }
--              }
-+      {
-+              SCSITaskMgmt_t  *pScsiTm;
-+              pScsiTm = (SCSITaskMgmt_t *)mf;
-+              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\tTaskType=0x%x MsgFlags=0x%x "
-+                  "TaskMsgContext=0x%x id=%d channel=%d\n", ioc->name, pScsiTm->TaskType,
-+                  le32_to_cpu(pScsiTm->TaskMsgContext), pScsiTm->MsgFlags,
-+                  pScsiTm->TargetID, pScsiTm->Bus));
-               break;
-+      }
+@@ -3941,9 +3956,9 @@ csmisas_get_raid_config(unsigned long ar
+                       if ((pVolume0->VolumeSettings.HotSparePool &
+                           pIocPage5->HotSpare[idx].HotSparePool) == 0)
+                               continue;
+-                      if(pIocPage5->HotSpare[idx].Flags !=
++                      if (pIocPage5->HotSpare[idx].Flags !=
+                           MPI_IOC_PAGE_5_HOT_SPARE_ACTIVE)
+-                          continue;
++                              continue;
+                       physDiskNum = pIocPage5->HotSpare[idx].PhysDiskNum;
+                       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+                       cfg.pageAddr = physDiskNum;
+@@ -3981,11 +3996,11 @@ csmisas_get_raid_config(unsigned long ar
+                           MPI_RAID_VOL_TYPE_IME) &&
+                           (((totalMaxLBA +
+                           pVolume0->NumPhysDisks) * 2) +
+-                          (64*2*1024 ) /*metadata = 64MB*/ >
++                          (64*2*1024) /*metadata = 64MB*/ >
+                           le32_to_cpu(pPhysDisk0->MaxLBA)))
+                               continue;
  
-       case MPI_FUNCTION_IOC_INIT:
-               {
-@@ -2054,7 +2209,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                       /* Verify that all entries in the IOC INIT match
-                        * existing setup (and in LE format).
-                        */
--                      if (sizeof(dma_addr_t) == sizeof(u64)) {
-+                      if (ioc->sg_addr_size == sizeof(u64)) {
-                               high_addr = cpu_to_le32((u32)((u64)ioc->req_frames_dma >> 32));
-                               sense_high= cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
-                       } else {
-@@ -2062,6 +2217,11 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                               sense_high= 0;
+-                      pKarg->Configuration.bDriveCount++;
++                      pKarg->Configuration.bDriveCount++;
+                       if (pKarg->Configuration.bDataType !=
+                           CSMI_SAS_RAID_DATA_DRIVES) {
+                               i++;
+@@ -3996,14 +4011,16 @@ csmisas_get_raid_config(unsigned long ar
+                       sas_info = csmisas_get_device_component_by_fw(ioc,
+                           pPhysDisk0->PhysDiskBus, pPhysDisk0->PhysDiskID);
+                       if (sas_info) {
+-                              sas_address = reverse_byte_order64(sas_info->sas_address);
++                              sas_address =
++                                  reverse_byte_order64(sas_info->sas_address);
+                               memcpy(pKarg->Configuration.Drives[i].bSASAddress,
+-                                 &sas_address,sizeof(u64));
++                                 &sas_address, sizeof(u64));
                        }
  
-+                      if (!pInit->MaxDevices && !pInit->MaxBuses) {
-+                              pInit->MaxDevices = ioc->facts.MaxDevices;
-+                              pInit->MaxBuses = ioc->facts.MaxBuses;
-+                      }
-+
-                       if ((pInit->Flags != 0) || (pInit->MaxDevices != ioc->facts.MaxDevices) ||
-                               (pInit->MaxBuses != ioc->facts.MaxBuses) ||
-                               (pInit->ReplyFrameSize != cpu_to_le16(ioc->reply_sz)) ||
-@@ -2102,7 +2262,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-               printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
-                       "Illegal request (function 0x%x) \n",
--                      ioc->name, __FILE__, __LINE__, hdr->Function);
-+                      ioc->name, __FILE__, __LINE__, function);
-               rc = -EFAULT;
-               goto done_free_mem;
-       }
-@@ -2128,8 +2288,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                       if (karg.dataInSize > 0) {
-                               flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
-                                               MPI_SGE_FLAGS_END_OF_BUFFER |
--                                              MPI_SGE_FLAGS_DIRECTION |
--                                              mpt_addr_size() )
-+                                              MPI_SGE_FLAGS_DIRECTION )
-                                               << MPI_SGE_FLAGS_SHIFT;
-                       } else {
-                               flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
-@@ -2146,8 +2305,8 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                               /* Set up this SGE.
-                                * Copy to MF and to sglbuf
-                                */
--                              mpt_add_sge(psge, flagsLength, dma_addr_out);
--                              psge += (sizeof(u32) + sizeof(dma_addr_t));
-+                              ioc->add_sge(psge, flagsLength, dma_addr_out);
-+                              psge += ioc->SGE_size;
-                               /* Copy user data to kernel space.
-                                */
-@@ -2180,17 +2339,24 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                               /* Set up this SGE
-                                * Copy to MF and to sglbuf
-                                */
--                              mpt_add_sge(psge, flagsLength, dma_addr_in);
-+                              ioc->add_sge(psge, flagsLength, dma_addr_in);
+                       memcpy(pKarg->Configuration.Drives[i].bModel,
+                           pPhysDisk0->InquiryData.VendorID,
+-                          offsetof(RAID_PHYS_DISK0_INQUIRY_DATA,ProductRevLevel));
++                          offsetof(RAID_PHYS_DISK0_INQUIRY_DATA,
++                              ProductRevLevel));
+                       memcpy(pKarg->Configuration.Drives[i].bFirmware,
+                               pPhysDisk0->InquiryData.ProductRevLevel,
+                               sizeof(pPhysDisk0->InquiryData.ProductRevLevel));
+@@ -4021,10 +4038,10 @@ csmisas_get_raid_config(unsigned long ar
                        }
+                       pKarg->Configuration.Drives[i].bDriveStatus =
+                           CSMI_SAS_DRIVE_STATUS_OK;
+-                      if(pPhysDisk0->PhysDiskStatus.State)
++                      if (pPhysDisk0->PhysDiskStatus.State)
+                               pKarg->Configuration.Drives[i].bDriveStatus =
+                                   CSMI_SAS_DRIVE_STATUS_FAILED;
+-                      else if(pPhysDisk0->ErrorData.SmartCount)
++                      else if (pPhysDisk0->ErrorData.SmartCount)
+                               pKarg->Configuration.Drives[i].bDriveStatus =
+                                   CSMI_SAS_DRIVE_STATUS_DEGRADED;
+                       pKarg->Configuration.Drives[i].bDriveUsage =
+@@ -4047,8 +4064,8 @@ csmisas_get_raid_config(unsigned long ar
                }
-       } else  {
-               /* Add a NULL SGE
-                */
--              mpt_add_sge(psge, flagsLength, (dma_addr_t) -1);
-+              ioc->add_sge(psge, flagsLength, (dma_addr_t) -1);
        }
  
--      ioc->ioctl->wait_done = 0;
--      if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT) {
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, hdr->MsgContext);
-+      INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
-+      if (function == MPI_FUNCTION_SCSI_TASK_MGMT) {
-+
-+              mutex_lock(&ioc->taskmgmt_cmds.mutex);
-+              if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
-+                      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+                      goto done_free_mem;
-+              }
+-      // Only return data on the first 240 drives
+-      if( pKarg->Configuration.bDriveCount > 0xF0 )
++      /* Only return data on the first 240 drives */
++      if (pKarg->Configuration.bDriveCount > 0xF0)
+               pKarg->Configuration.bDriveCount =
+                   CSMI_SAS_RAID_DRIVE_COUNT_TOO_BIG;
+@@ -4060,11 +4077,11 @@ csmisas_get_raid_config(unsigned long ar
+               pci_free_consistent(ioc->pcidev, volumepage0sz, pVolume0,
+                   volume0_dma);
+-      if(pPhysDisk0 != NULL)
++      if (pPhysDisk0 != NULL)
+               pci_free_consistent(ioc->pcidev, physdiskpage0sz, pPhysDisk0,
+                   physdisk0_dma);
+-      if(pIocPage5 != NULL)
++      if (pIocPage5 != NULL)
+               pci_free_consistent(ioc->pcidev, ioc_page5_sz, pIocPage5,
+                   ioc_page5_dma);
+@@ -4075,17 +4092,17 @@ csmisas_get_raid_config(unsigned long ar
+       switch (pKarg->Configuration.bDataType) {
+       case CSMI_SAS_RAID_DATA_ADDITIONAL_DATA:
+               copy_buffer_sz = sizeof(IOCTL_HEADER) +
+-                  offsetof(CSMI_SAS_RAID_CONFIG,Data) +
++                  offsetof(CSMI_SAS_RAID_CONFIG, Data) +
+                   sizeof(CSMI_SAS_RAID_SET_ADDITIONAL_DATA);
+               break;
+       case CSMI_SAS_RAID_DATA_DRIVES:
+               if (pKarg->Configuration.bDriveCount ==
+                   CSMI_SAS_RAID_DRIVE_COUNT_SUPRESSED)
+                       copy_buffer_sz = sizeof(IOCTL_HEADER) +
+-                          offsetof(CSMI_SAS_RAID_CONFIG,Drives);
+-              else
++                          offsetof(CSMI_SAS_RAID_CONFIG, Drives);
++              else
+                       copy_buffer_sz = sizeof(IOCTL_HEADER) +
+-                          offsetof(CSMI_SAS_RAID_CONFIG,Drives) +
++                          offsetof(CSMI_SAS_RAID_CONFIG, Drives) +
+                           (pKarg->Configuration.bDriveCount *
+                           sizeof(CSMI_SAS_RAID_DRIVES));
+               break;
+@@ -4097,12 +4114,12 @@ csmisas_get_raid_config(unsigned long ar
+       if (copy_to_user(uarg, pKarg, copy_buffer_sz)) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                      "Unable to write out csmi_sas_get_raid_config @ %p\n",
+-                         __FILE__, __LINE__, __FUNCTION__, uarg);
++                     __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -EFAULT;
+       }
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       free_pages((unsigned long)pKarg, memory_pages);
+       return 0;
+ }
+@@ -4119,15 +4136,15 @@ static int
+ csmisas_get_raid_features(unsigned long arg)
+ {
+       CSMI_SAS_RAID_FEATURES_BUFFER __user *uarg = (void __user *) arg;
+-      CSMI_SAS_RAID_FEATURES_BUFFER karg, *pKarg=NULL;
++      CSMI_SAS_RAID_FEATURES_BUFFER karg, *pKarg = NULL;
+       int csmi_sas_raid_features_buffer_sz, iocnum;
+       int                             memory_pages;
+       MPT_ADAPTER             *ioc = NULL;
+       if (copy_from_user(&karg, uarg, sizeof(IOCTL_HEADER))) {
+-              printk(KERN_ERR "%s@%d::%s() - "
+-                  "Unable to read in csmi_sas_get_raid_features struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++              printk(KERN_ERR "%s@%d::%s() - Unable to "
++                  "read in csmi_sas_get_raid_features struct @ %p\n",
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-               DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
+@@ -4135,20 +4152,20 @@ csmisas_get_raid_features(unsigned long 
+       memory_pages = get_order(csmi_sas_raid_features_buffer_sz);
+       pKarg = (CSMI_SAS_RAID_FEATURES_BUFFER *)__get_free_pages(
+               GFP_KERNEL, memory_pages);
+-      if (!pKarg){
++      if (!pKarg) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to malloc RAID_FEATURES_BUFFER "
+                       "csmi_sas_raid_features_buffer_sz=%d memory_pages=%d\n",
+-                      __FILE__, __LINE__, __FUNCTION__,
++                      __FILE__, __LINE__, __func__,
+                       csmi_sas_raid_features_buffer_sz, memory_pages);
+               return -ENOMEM;
+       }
+       memset(pKarg, 0, sizeof(*pKarg));
  
-@@ -2198,53 +2364,57 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-                   (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
-                       mpt_put_msg_frame_hi_pri(mptctl_id, ioc, mf);
-               else {
--                      rc =mpt_send_handshake_request(mptctl_id, ioc,
--                              sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
-+                      rc = mpt_send_handshake_request(mptctl_id, ioc,
-+                          sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
-                       if (rc != 0) {
-                               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                                  "_send_handshake FAILED! (ioc %p, mf %p)\n",
-+                                  "send_handshake FAILED! (ioc %p, mf %p)\n",
-                                   ioc->name, ioc, mf));
--                              mptctl_free_tm_flags(ioc);
-+                              mpt_clear_taskmgmt_in_progress_flag(ioc);
-                               rc = -ENODATA;
-+                              mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-                               goto done_free_mem;
-                       }
-               }
--
-       } else
-               mpt_put_msg_frame(mptctl_id, ioc, mf);
+       if (copy_from_user(pKarg, uarg, csmi_sas_raid_features_buffer_sz)) {
+-              printk(KERN_ERR "%s@%d::%s() - "
+-                  "Unable to read in csmi_sas_get_raid_features struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++              printk(KERN_ERR "%s@%d::%s() -  Unable to "
++                  "read in csmi_sas_get_raid_features struct @ %p\n",
++                  __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -EFAULT;
+       }
+@@ -4156,22 +4173,22 @@ csmisas_get_raid_features(unsigned long 
+       if (((iocnum = mpt_verify_adapter(pKarg->IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -ENODEV;
+       }
  
-       /* Now wait for the command to complete */
-       timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT;
--      timeout = wait_event_timeout(mptctl_wait,
--           ioc->ioctl->wait_done == 1,
--           HZ*timeout);
--
--      if(timeout <=0 && (ioc->ioctl->wait_done != 1 )) {
--      /* Now we need to reset the board */
--
--              if (hdr->Function == MPI_FUNCTION_SCSI_TASK_MGMT)
--                      mptctl_free_tm_flags(ioc);
--
--              mptctl_timeout_expired(ioc->ioctl);
--              rc = -ENODATA;
-+      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, HZ*timeout);
-+      if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              rc = -ETIME;
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "%s: TIMED OUT!\n",
-+                  ioc->name, __FUNCTION__));
-+              if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
-+                      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
-+                      goto done_free_mem;
-+              }
-+              if (!timeleft) {
-+                      mptctl_timeout_expired(ioc, mf);
-+                      mf = NULL;
-+              }
-               goto done_free_mem;
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -ENODEV;
        }
  
-+      if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
-+              mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+
-       mf = NULL;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
+       if (pKarg->Information.uChangeCount != 0 &&
+-          pKarg->Information.uChangeCount != ioc->csmi_change_count ) {
++          pKarg->Information.uChangeCount != ioc->csmi_change_count) {
+               pKarg->IoctlHeader.ReturnCode =
+                   CSMI_SAS_STATUS_INVALID_PARAMETER;
+               pKarg->Information.uFailureCode =
+@@ -4218,12 +4235,12 @@ csmisas_get_raid_features(unsigned long 
+           sizeof(CSMI_SAS_RAID_FEATURES_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+               "Unable to write out csmi_sas_get_raid_features @ %p\n",
+-              __FILE__, __LINE__, __FUNCTION__, uarg);
++              __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -EFAULT;
+       }
  
-       /* If a valid reply frame, copy to the user.
-        * Offset 2: reply length in U32's
-        */
--      if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID) {
-+      if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
-               if (karg.maxReplyBytes < ioc->reply_sz) {
--                       sz = min(karg.maxReplyBytes, 4*ioc->ioctl->ReplyFrame[2]);
-+                       sz = min(karg.maxReplyBytes, 4*ioc->ioctl_cmds.reply[2]);
-               } else {
--                       sz = min(ioc->reply_sz, 4*ioc->ioctl->ReplyFrame[2]);
-+                       sz = min(ioc->reply_sz, 4*ioc->ioctl_cmds.reply[2]);
-               }
--
-               if (sz > 0) {
-                       if (copy_to_user(karg.replyFrameBufPtr,
--                               &ioc->ioctl->ReplyFrame, sz)){
-+                               ioc->ioctl_cmds.reply, sz)){
-                                printk(MYIOC_s_ERR_FMT
-                                    "%s@%d::mptctl_do_mpt_command - "
-                                "Unable to write out reply frame %p\n",
-@@ -2257,10 +2427,10 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-       /* If valid sense data, copy to user.
-        */
--      if (ioc->ioctl->status & MPT_IOCTL_STATUS_SENSE_VALID) {
-+      if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_SENSE_VALID) {
-               sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
-               if (sz > 0) {
--                      if (copy_to_user(karg.senseDataPtr, ioc->ioctl->sense, sz)) {
-+                      if (copy_to_user(karg.senseDataPtr, ioc->ioctl_cmds.sense, sz)) {
-                               printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
-                               "Unable to write sense data to user %p\n",
-                               ioc->name, __FILE__, __LINE__,
-@@ -2274,9 +2444,8 @@ mptctl_do_mpt_command (struct mpt_ioctl_
-       /* If the overall status is _GOOD and data in, copy data
-        * to user.
-        */
--      if ((ioc->ioctl->status & MPT_IOCTL_STATUS_COMMAND_GOOD) &&
--                              (karg.dataInSize > 0) && (bufIn.kptr)) {
--
-+      if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD) &&
-+              (karg.dataInSize > 0) && (bufIn.kptr)) {
-               if (copy_to_user(karg.dataInBufPtr,
-                                bufIn.kptr, karg.dataInSize)) {
-                       printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
-@@ -2289,9 +2458,8 @@ mptctl_do_mpt_command (struct mpt_ioctl_
- done_free_mem:
--      ioc->ioctl->status &= ~(MPT_IOCTL_STATUS_COMMAND_GOOD |
--              MPT_IOCTL_STATUS_SENSE_VALID |
--              MPT_IOCTL_STATUS_RF_VALID );
-+      CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
-       /* Free the allocated memory.
-        */
-@@ -2320,7 +2488,7 @@ done_free_mem:
-  * Outputs:   None.
-  * Return:    0 if successful
-  *            -EFAULT if data unavailable
-- *            -EBUSY  if previous command timeout and IOC reset is not complete.
-+ *            -EBUSY  if previous command timout and IOC reset is not complete.
-  *            -ENODEV if no such device/adapter
-  *            -ETIME  if timer expires
-  *            -ENOMEM if memory allocation error
-@@ -2331,16 +2499,17 @@ mptctl_hp_hostinfo(unsigned long arg, un
-       hp_host_info_t  __user *uarg = (void __user *) arg;
-       MPT_ADAPTER             *ioc;
-       struct pci_dev          *pdev;
--      char                    *pbuf=NULL;
-+      char                    *pbuf=NULL;
-       dma_addr_t              buf_dma;
-       hp_host_info_t          karg;
--      CONFIGPARMS             cfg;
--      ConfigPageHeader_t      hdr;
-       int                     iocnum;
--      int                     rc, cim_rev;
-+      int                     cim_rev;
-       ToolboxIstwiReadWriteRequest_t  *IstwiRWRequest;
-       MPT_FRAME_HDR           *mf = NULL;
-       MPIHeader_t             *mpi_hdr;
-+      unsigned long           timeleft;
-+      int                     retval;
-+      u32                     MsgContext;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       free_pages((unsigned long)pKarg, memory_pages);
+       return 0;
+ }
+@@ -4240,7 +4257,7 @@ static int
+ csmisas_set_raid_control(unsigned long arg)
+ {
+       CSMI_SAS_RAID_CONTROL_BUFFER __user *uarg = (void __user *) arg;
+-      CSMI_SAS_RAID_CONTROL_BUFFER karg, *pKarg=NULL;
++      CSMI_SAS_RAID_CONTROL_BUFFER karg, *pKarg = NULL;
+       int csmi_sas_raid_control_buffer_sz, iocnum;
+       int                             memory_pages;
+       MPT_ADAPTER     *ioc = NULL;
+@@ -4248,7 +4265,7 @@ csmisas_set_raid_control(unsigned long a
+       if (copy_from_user(&karg, uarg, sizeof(IOCTL_HEADER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_set_raid_control struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-       /* Reset long to int. Should affect IA64 and SPARC only
-        */
-@@ -2360,13 +2529,14 @@ mptctl_hp_hostinfo(unsigned long arg, un
+@@ -4256,11 +4273,11 @@ csmisas_set_raid_control(unsigned long a
+       memory_pages = get_order(csmi_sas_raid_control_buffer_sz);
+       pKarg = (CSMI_SAS_RAID_CONTROL_BUFFER *)__get_free_pages(
+               GFP_KERNEL, memory_pages);
+-      if (!pKarg){
++      if (!pKarg) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to malloc RAID_CONTROL_BUFFER "
+                       "csmi_sas_raid_control_buffer_sz=%d memory_pages=%d\n",
+-                      __FILE__, __LINE__, __FUNCTION__,
++                      __FILE__, __LINE__, __func__,
+                       csmi_sas_raid_control_buffer_sz, memory_pages);
+               return -ENOMEM;
+       }
+@@ -4269,7 +4286,7 @@ csmisas_set_raid_control(unsigned long a
+       if (copy_from_user(pKarg, uarg, csmi_sas_raid_control_buffer_sz)) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_set_raid_control struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -EFAULT;
+       }
+@@ -4277,22 +4294,22 @@ csmisas_set_raid_control(unsigned long a
+       if (((iocnum = mpt_verify_adapter(pKarg->IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -ENODEV;
+       }
  
-       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-           (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)pKarg, memory_pages);
                return -ENODEV;
        }
-+
-       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_hostinfo called.\n",
-           ioc->name));
--
-       /* Fill in the data and return the structure to the calling
-        * program
-        */
-@@ -2406,42 +2576,9 @@ mptctl_hp_hostinfo(unsigned long arg, un
-       karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0';
-       karg.fw_version[11] = '\0';
  
--      /* Issue a config request to get the device serial number
--       */
--      hdr.PageVersion = 0;
--      hdr.PageLength = 0;
--      hdr.PageNumber = 0;
--      hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
--      cfg.cfghdr.hdr = &hdr;
--      cfg.physAddr = -1;
--      cfg.pageAddr = 0;
--      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
--      cfg.dir = 0;    /* read */
--      cfg.timeout = 10;
-+      strncpy(karg.serial_number, ioc->board_tracer, 16);
--      strncpy(karg.serial_number, " ", 24);
--      if (mpt_config(ioc, &cfg) == 0) {
--              if (cfg.cfghdr.hdr->PageLength > 0) {
--                      /* Issue the second config page request */
--                      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
--
--                      pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
--                      if (pbuf) {
--                              cfg.physAddr = buf_dma;
--                              if (mpt_config(ioc, &cfg) == 0) {
--                                      ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf;
--                                      if (strlen(pdata->BoardTracerNumber) > 1) {
--                                              strncpy(karg.serial_number,                                                                         pdata->BoardTracerNumber, 24);
--                                              karg.serial_number[24-1]='\0';
--                                      }
--                              }
--                              pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
--                              pbuf = NULL;
--                      }
--              }
--      }
--      rc = mpt_GetIocState(ioc, 1);
--      switch (rc) {
-+      switch (mpt_GetIocState(ioc, 1)) {
-       case MPI_IOC_STATE_OPERATIONAL:
-               karg.ioc_status =  HP_STATUS_OK;
-               break;
-@@ -2468,12 +2605,12 @@ mptctl_hp_hostinfo(unsigned long arg, un
-       karg.soft_resets = 0;
-       karg.timeouts = 0;
-       if (ioc->sh != NULL) {
--              MPT_SCSI_HOST *hd =  shost_priv(ioc->sh);
-+              MPT_SCSI_HOST *hd =  (MPT_SCSI_HOST *)ioc->sh->hostdata;
-               if (hd && (cim_rev == 1)) {
--                      karg.hard_resets = hd->hard_resets;
--                      karg.soft_resets = hd->soft_resets;
--                      karg.timeouts = hd->timeouts;
-+                      karg.hard_resets = ioc->hard_resets;
-+                      karg.soft_resets = ioc->soft_resets;
-+                      karg.timeouts = ioc->timeouts;
-               }
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
+       if (pKarg->Information.uChangeCount != 0 &&
+-              pKarg->Information.uChangeCount != ioc->csmi_change_count ) {
++              pKarg->Information.uChangeCount != ioc->csmi_change_count) {
+               pKarg->IoctlHeader.ReturnCode =
+                   CSMI_SAS_STATUS_INVALID_PARAMETER;
+               pKarg->Information.uFailureCode =
+@@ -4329,8 +4346,8 @@ csmisas_set_raid_control(unsigned long a
+               goto cim_set_raid_control_exit;
+       }
+-      if( !strcmp(pKarg->Information.bClearConfiguration,
+-              CSMI_SAS_RAID_CLEAR_CONFIGURATION_SIGNATURE) ) {
++      if (!strcmp(pKarg->Information.bClearConfiguration,
++              CSMI_SAS_RAID_CLEAR_CONFIGURATION_SIGNATURE)) {
+               pKarg->IoctlHeader.ReturnCode =
+                       CSMI_SAS_STATUS_INVALID_PARAMETER;
+               pKarg->Information.uFailureCode =
+@@ -4349,12 +4366,12 @@ csmisas_set_raid_control(unsigned long a
+               sizeof(CSMI_SAS_RAID_CONTROL_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+               "Unable to write out csmi_sas_set_raid_control @ %p\n",
+-              __FILE__, __LINE__, __FUNCTION__, uarg);
++              __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)pKarg, memory_pages);
+               return -EFAULT;
        }
  
-@@ -2482,16 +2619,18 @@ mptctl_hp_hostinfo(unsigned long arg, un
-        */
-       if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
-               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
--                  ioc->name,__func__));
-+                  ioc->name,__FUNCTION__));
-+              retval = -ENOMEM;
-               goto out;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       free_pages((unsigned long)pKarg, memory_pages);
+       return 0;
+ }
+@@ -4378,42 +4395,39 @@ csmisas_get_raid_element(unsigned long a
+       if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_RAID_ELEMENT_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmisas_get_raid_element struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
  
-       IstwiRWRequest = (ToolboxIstwiReadWriteRequest_t *)mf;
-       mpi_hdr = (MPIHeader_t *) mf;
-+      MsgContext = mpi_hdr->MsgContext;
-       memset(IstwiRWRequest,0,sizeof(ToolboxIstwiReadWriteRequest_t));
-       IstwiRWRequest->Function = MPI_FUNCTION_TOOLBOX;
-       IstwiRWRequest->Tool = MPI_TOOLBOX_ISTWI_READ_WRITE_TOOL;
--      IstwiRWRequest->MsgContext = mpi_hdr->MsgContext;
-+      IstwiRWRequest->MsgContext = MsgContext;
-       IstwiRWRequest->Flags = MPI_TB_ISTWI_FLAGS_READ;
-       IstwiRWRequest->NumAddressBytes = 0x01;
-       IstwiRWRequest->DataLength = cpu_to_le16(0x04);
-@@ -2501,28 +2640,30 @@ mptctl_hp_hostinfo(unsigned long arg, un
-               IstwiRWRequest->DeviceAddr = 0xB0;
-       pbuf = pci_alloc_consistent(ioc->pcidev, 4, &buf_dma);
--      if (!pbuf)
-+      if (!pbuf) {
-+              retval = -ENOMEM;
-               goto out;
--      mpt_add_sge((char *)&IstwiRWRequest->SGL,
--          (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma);
-+      }
-+      ioc->add_sge((char *)&IstwiRWRequest->SGL, (MPT_SGE_FLAGS_SSIMPLE_READ|4),buf_dma);
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
--      ioc->ioctl->wait_done = 0;
-+      retval = 0;
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, IstwiRWRequest->MsgContext);
-+      INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
-       mpt_put_msg_frame(mptctl_id, ioc, mf);
--
--      rc = wait_event_timeout(mptctl_wait,
--           ioc->ioctl->wait_done == 1,
--           HZ*MPT_IOCTL_DEFAULT_TIMEOUT /* 10 sec */);
--
--      if(rc <=0 && (ioc->ioctl->wait_done != 1 )) {
--              /*
--               * Now we need to reset the board
--               */
--              mpt_free_msg_frame(ioc, mf);
--              mptctl_timeout_expired(ioc->ioctl);
-+      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, HZ*MPT_IOCTL_DEFAULT_TIMEOUT);
-+      if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              retval = -ETIME;
-+              printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name, __FUNCTION__);
-+              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
-+                      mpt_free_msg_frame(ioc, mf);
-+                      goto out;
-+              }
-+              if (!timeleft)
-+                      mptctl_timeout_expired(ioc, mf);
-               goto out;
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
        }
  
--      /*
-+      /*
-        *ISTWI Data Definition
-        * pbuf[0] = FW_VERSION = 0x4
-        * pbuf[1] = Bay Count = 6 or 4 or 2, depending on
-@@ -2531,10 +2672,13 @@ mptctl_hp_hostinfo(unsigned long arg, un
-        *   bays have drives in them
-        * pbuf[3] = Checksum (0x100 = (byte0 + byte2 + byte3)
-        */
--      if (ioc->ioctl->status & MPT_IOCTL_STATUS_RF_VALID)
-+      if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)
-               karg.rsvd = *(u32 *)pbuf;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
-  out:
-+      CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
-+
-       if (pbuf)
-               pci_free_consistent(ioc->pcidev, 4, pbuf, buf_dma);
+-/* TODO - implement IOCTL here */
+       karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_BAD_CNTL_CODE;
+       dcsmisasprintk(ioc, printk(KERN_DEBUG ": not implemented\n"));
  
-@@ -2547,7 +2691,7 @@ mptctl_hp_hostinfo(unsigned long arg, un
+-// csmisas_get_raid_element_exit:
+-
+       /* Copy the data from kernel memory to user memory
+        */
+       if (copy_to_user(uarg, &karg,
+                               sizeof(CSMI_SAS_RAID_ELEMENT_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to write out csmisas_get_raid_element @ %p\n",
+-                              __FILE__, __LINE__, __FUNCTION__, uarg);
++                              __FILE__, __LINE__, __func__, uarg);
                return -EFAULT;
        }
  
--      return 0;
-+      return retval;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
  
  }
+@@ -4434,45 +4448,43 @@ csmisas_set_raid_operation(unsigned long
+       MPT_ADAPTER                     *ioc = NULL;
+       int                             iocnum;
  
-@@ -2557,7 +2701,7 @@ mptctl_hp_hostinfo(unsigned long arg, un
-  * Outputs:   None.
-  * Return:    0 if successful
-  *            -EFAULT if data unavailable
-- *            -EBUSY  if previous command timeout and IOC reset is not complete.
-+ *            -EBUSY  if previous command timout and IOC reset is not complete.
-  *            -ENODEV if no such device/adapter
-  *            -ETIME  if timer expires
-  *            -ENOMEM if memory allocation error
-@@ -2587,13 +2731,14 @@ mptctl_hp_targetinfo(unsigned long arg)
+-      if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_RAID_SET_OPERATION_BUFFER))) {
++      if (copy_from_user(&karg, uarg,
++              sizeof(CSMI_SAS_RAID_SET_OPERATION_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_set_raid_operation struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-               (ioc == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
-                               __FILE__, __LINE__, iocnum);
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
                return -ENODEV;
        }
--      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_hp_targetinfo called.\n",
--          ioc->name));
  
-+      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_targetinfo called.\n",
-+          ioc->name));
-       /*  There is nothing to do for FCP parts.
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
+-/* TODO - implement IOCTL here */
+       karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_BAD_CNTL_CODE;
+       dcsmisasprintk(ioc, printk(KERN_DEBUG ": not implemented\n"));
+-// cim_set_raid_operation:
+-
+       /* Copy the data from kernel memory to user memory
         */
-       if ((ioc->bus_type == SAS) || (ioc->bus_type == FC))
-@@ -2685,7 +2830,7 @@ mptctl_hp_targetinfo(unsigned long arg)
-                       pci_free_consistent(ioc->pcidev, data_sz, (u8 *) pg3_alloc, page_dma);
-               }
+       if (copy_to_user(uarg, &karg,
+                               sizeof(CSMI_SAS_RAID_SET_OPERATION_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to write out csmi_set_raid_operation @ %p\n",
+-                              __FILE__, __LINE__, __FUNCTION__, uarg);
++                              __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
--      hd = shost_priv(ioc->sh);
-+      hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
-       if (hd != NULL)
-               karg.select_timeouts = hd->sel_timeout[karg.hdr.id];
  
-@@ -2703,7 +2848,7 @@ mptctl_hp_targetinfo(unsigned long arg)
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ }
+@@ -4512,24 +4524,24 @@ csmisas_task_managment(unsigned long arg
+       if (copy_from_user(&karg, uarg, sizeof(CSMI_SAS_SSP_TASK_IU_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_task_managment struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
--static const struct file_operations mptctl_fops = {
-+static struct file_operations mptctl_fops = {
-       .owner =        THIS_MODULE,
-       .llseek =       no_llseek,
-       .fasync =       mptctl_fasync,
-@@ -2743,8 +2888,9 @@ compat_mptfwxfer_ioctl(struct file *filp
-       iocnumX = kfw32.iocnum & 0xFF;
-       if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
-           (iocp == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
--                      __LINE__, iocnumX);
-+                              __LINE__, iocnumX);
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
                return -ENODEV;
        }
  
-@@ -2759,7 +2905,7 @@ compat_mptfwxfer_ioctl(struct file *filp
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
-       ret = mptctl_do_fw_download(kfw.iocnum, kfw.bufp, kfw.fwlen);
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
--      mutex_unlock(&iocp->ioctl->ioctl_mutex);
-+      mutex_unlock(&iocp->ioctl_cmds.mutex);
+       karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
  
-       return ret;
- }
-@@ -2783,8 +2929,9 @@ compat_mpt_command(struct file *filp, un
-       iocnumX = karg32.hdr.iocnum & 0xFF;
-       if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
-           (iocp == NULL)) {
-+              if (mpt_debug_level & MPT_DEBUG_IOCTL)
-               printk(KERN_DEBUG MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
--                      __LINE__, iocnumX);
-+                              __LINE__, iocnumX);
-               return -ENODEV;
+@@ -4575,18 +4587,22 @@ csmisas_task_managment(unsigned long arg
+               goto cim_get_task_managment_exit;
+       switch (karg.Parameters.uInformation) {
+-              case CSMI_SAS_SSP_TEST:
+-                      dcsmisasprintk(ioc, printk(KERN_DEBUG "TM request for test purposes\n"));
+-                      break;
+-              case CSMI_SAS_SSP_EXCEEDED:
+-                      dcsmisasprintk(ioc, printk(KERN_DEBUG "TM request due to timeout\n"));
+-                      break;
+-              case CSMI_SAS_SSP_DEMAND:
+-                      dcsmisasprintk(ioc, printk(KERN_DEBUG "TM request demanded by app\n"));
+-                      break;
+-              case CSMI_SAS_SSP_TRIGGER:
+-                      dcsmisasprintk(ioc, printk(KERN_DEBUG "TM request sent to trigger event\n"));
+-                      break;
++      case CSMI_SAS_SSP_TEST:
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "TM request for test purposes\n"));
++              break;
++      case CSMI_SAS_SSP_EXCEEDED:
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "TM request due to timeout\n"));
++              break;
++      case CSMI_SAS_SSP_DEMAND:
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "TM request demanded by app\n"));
++              break;
++      case CSMI_SAS_SSP_TRIGGER:
++              dcsmisasprintk(ioc, printk(KERN_DEBUG
++                      "TM request sent to trigger event\n"));
++              break;
        }
  
-@@ -2813,7 +2960,7 @@ compat_mpt_command(struct file *filp, un
-        */
-       ret = mptctl_do_mpt_command (karg, &uarg->MF);
+       switch (taskType) {
+@@ -4601,12 +4617,12 @@ csmisas_task_managment(unsigned long arg
+                               mf = MPT_INDEX_2_MFPTR(hd->ioc, i);
+                               TaskMsgContext =
+                                   mf->u.frame.hwhdr.msgctxu.MsgContext;
+-                              found_qtag=1;
++                              found_qtag = 1;
+                               break;
+                       }
+               }
  
--      mutex_unlock(&iocp->ioctl->ioctl_mutex);
-+      mutex_unlock(&iocp->ioctl_cmds.mutex);
+-              if(!found_qtag)
++              if (!found_qtag)
+                       goto cim_get_task_managment_exit;
  
-       return ret;
- }
-@@ -2833,6 +2980,31 @@ static long compat_mpctl_ioctl(struct fi
-       case MPTHARDRESET:
-       case HP_GETHOSTINFO:
-       case HP_GETTARGETINFO:
-+#if defined(CPQ_CIM)
-+      case CC_CSMI_SAS_GET_DRIVER_INFO:
-+      case CC_CSMI_SAS_GET_CNTLR_CONFIG:
-+      case CC_CSMI_SAS_GET_CNTLR_STATUS:
-+      case CC_CSMI_SAS_GET_SCSI_ADDRESS:
-+      case CC_CSMI_SAS_GET_DEVICE_ADDRESS:
-+      case CC_CSMI_SAS_GET_PHY_INFO:
-+      case CC_CSMI_SAS_GET_SATA_SIGNATURE:
-+      case CC_CSMI_SAS_GET_LINK_ERRORS:
-+      case CC_CSMI_SAS_SMP_PASSTHRU:
-+      case CC_CSMI_SAS_SSP_PASSTHRU:
-+      case CC_CSMI_SAS_FIRMWARE_DOWNLOAD:
-+      case CC_CSMI_SAS_GET_RAID_INFO:
-+      case CC_CSMI_SAS_GET_RAID_CONFIG:
-+      case CC_CSMI_SAS_GET_RAID_FEATURES:
-+      case CC_CSMI_SAS_SET_RAID_CONTROL:
-+      case CC_CSMI_SAS_GET_RAID_ELEMENT:
-+      case CC_CSMI_SAS_SET_RAID_OPERATION:
-+      case CC_CSMI_SAS_SET_PHY_INFO:
-+      case CC_CSMI_SAS_STP_PASSTHRU:
-+      case CC_CSMI_SAS_TASK_MANAGEMENT:
-+      case CC_CSMI_SAS_PHY_CONTROL:
-+      case CC_CSMI_SAS_GET_CONNECTOR_INFO:
-+      case CC_CSMI_SAS_GET_LOCATION:
-+#endif /* CPQ_CIM */
-       case MPTTEST:
-               ret = __mptctl_ioctl(f, cmd, arg);
+       case MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
+@@ -4618,7 +4634,6 @@ csmisas_task_managment(unsigned long arg
+               /* Single threading ....
+                */
+-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15))
+               mutex_lock(&ioc->taskmgmt_cmds.mutex);
+               if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
+                       mutex_unlock(&ioc->taskmgmt_cmds.mutex);
+@@ -4626,50 +4641,34 @@ csmisas_task_managment(unsigned long arg
+                           CSMI_SAS_STATUS_FAILED;
+                       goto cim_get_task_managment_exit;
+               }
+-#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0))
+-              if (mptctl_set_tm_flags(hd) != 0) {
+-                      karg.IoctlHeader.ReturnCode =
+-                          CSMI_SAS_STATUS_FAILED;
+-                      goto cim_get_task_managment_exit;
+-              }
+-#endif
+               /* Send request
+                */
+               if ((mf = mpt_get_msg_frame(mptctl_taskmgmt_id, ioc)) == NULL) {
+-                      dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
+-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15))
++                      dcsmisasprintk(ioc,
++                          printk(KERN_ERR ": no msg frames!\n"));
+                       mutex_unlock(&ioc->taskmgmt_cmds.mutex);
+                       mpt_clear_taskmgmt_in_progress_flag(ioc);
+-#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0))
+-                      mptctl_free_tm_flags(ioc);
+-#endif
+                       karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       goto cim_get_task_managment_exit;
+               }
+               mpi_hdr = (MPIHeader_t *) mf;
+               MsgContext = mpi_hdr->MsgContext;
+-              pScsiTm = (pSCSITaskMgmt_t ) mf;
++              pScsiTm = (pSCSITaskMgmt_t) mf;
+-              memset(pScsiTm,0,sizeof(SCSITaskMgmt_t));
++              memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
+               pScsiTm->TaskType = taskType;
+               pScsiTm->Bus = channel;
+               pScsiTm->TargetID = id;
+-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15))
+               int_to_scsilun(karg.Parameters.bLun,
+                   (struct scsi_lun *)pScsiTm->LUN);
+-#else
+-              pScsiTm->LUN[1] = karg.Parameters.bLun;
+-#endif
+               pScsiTm->MsgContext = MsgContext;
+               pScsiTm->TaskMsgContext = TaskMsgContext;
+               pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
+               if (csmisas_send_handshake_wait(ioc, mf,
+                   karg.IoctlHeader.Timeout) != 0)  {
+-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15))
+                       mutex_unlock(&ioc->taskmgmt_cmds.mutex);
+-#endif
+                       karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+                       goto cim_get_task_managment_exit;
+               }
+@@ -4677,25 +4676,26 @@ csmisas_task_managment(unsigned long arg
+               if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
+                       pScsiTmReply =
+-                          (pSCSITaskMgmtReply_t ) ioc->ioctl_cmds.reply;
++                          (pSCSITaskMgmtReply_t) ioc->ioctl_cmds.reply;
+                       ioc_status = le16_to_cpu(pScsiTmReply->IOCStatus)
+                           & MPI_IOCSTATUS_MASK;
+-                      memset(&karg.Status,0,
++                      memset(&karg.Status, 0,
+                           sizeof(CSMI_SAS_SSP_PASSTHRU_STATUS));
+-                      if(ioc_status == MPI_IOCSTATUS_SUCCESS) {
++                      if (ioc_status == MPI_IOCSTATUS_SUCCESS) {
+                               karg.IoctlHeader.ReturnCode =
+                                   CSMI_SAS_STATUS_SUCCESS;
+                               karg.Status.bSSPStatus =
+                                   CSMI_SAS_SSP_STATUS_COMPLETED;
+-                      }else if(ioc_status == MPI_IOCSTATUS_INSUFFICIENT_RESOURCES) {
++                      } else if (ioc_status
++                          == MPI_IOCSTATUS_INSUFFICIENT_RESOURCES) {
+                               karg.IoctlHeader.ReturnCode =
+                                   CSMI_SAS_STATUS_SUCCESS;
+                               karg.Status.bSSPStatus =
+                                   CSMI_SAS_SSP_STATUS_RETRY;
+-                      }else {
++                      } else {
+                               karg.IoctlHeader.ReturnCode =
+                                   CSMI_SAS_STATUS_FAILED;
+                               karg.Status.bSSPStatus =
+@@ -4711,9 +4711,7 @@ csmisas_task_managment(unsigned long arg
                break;
-@@ -2865,21 +3037,11 @@ static long compat_mpctl_ioctl(struct fi
- static int
- mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id)
- {
--      MPT_IOCTL *mem;
-       MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
--      /*
--       * Allocate and inite a MPT_IOCTL structure
--      */
--      mem = kzalloc(sizeof(MPT_IOCTL), GFP_KERNEL);
--      if (!mem) {
--              mptctl_remove(pdev);
--              return -ENOMEM;
--      }
-+      mutex_init(&ioc->ioctl_cmds.mutex);
-+      init_completion(&ioc->ioctl_cmds.done);
+       }
+-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15))
+       mutex_unlock(&ioc->taskmgmt_cmds.mutex);
+-#endif
+  cim_get_task_managment_exit:
+@@ -4723,11 +4721,11 @@ csmisas_task_managment(unsigned long arg
+                               sizeof(CSMI_SAS_SSP_TASK_IU_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to write out csmi_sas_task_managment @ %p\n",
+-                              __FILE__, __LINE__, __FUNCTION__, uarg);
++                              __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
--      ioc->ioctl = mem;
--      ioc->ioctl->ioc = ioc;
--      mutex_init(&ioc->ioctl->ioctl_mutex);
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
        return 0;
  }
  
-@@ -2893,9 +3055,22 @@ mptctl_probe(struct pci_dev *pdev, const
- static void
- mptctl_remove(struct pci_dev *pdev)
- {
-+#if defined(DIAG_BUFFER_SUPPORT)
-       MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
-+      int     i;
+@@ -4827,19 +4825,19 @@ csmisas_phy_reset(MPT_ADAPTER *ioc, u8 P
  
--      kfree ( ioc->ioctl );
-+      /*
-+       * Cleanup diag buffer allocated memory
-+       */
-+      for (i = 0; i < MPI_DIAG_BUF_TYPE_COUNT; i++) {
-+              if (ioc->DiagBuffer[i] == NULL)
-+                      continue;
-+              pci_free_consistent(ioc->pcidev, ioc->DiagBuffer_sz[i],
-+                  ioc->DiagBuffer[i], ioc->DiagBuffer_dma[i]);
-+              ioc->DiagBuffer[i] = NULL;
-+              ioc->DiagBuffer_Status[i] = 0;
+       if ((opcode != MPI_SAS_OP_PHY_LINK_RESET) &&
+           (opcode != MPI_SAS_OP_PHY_HARD_RESET))
+-          return -1;
++              return -1;
+       /* Get a MF for this command.
+        */
+       if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
+               dcsmisasprintk(ioc, printk(KERN_ERR ": no msg frames!\n"));
+               return -1;
+-        }
 +      }
-+#endif
- }
  
- static struct mpt_pci_driver mptctl_driver = {
-@@ -2935,6 +3110,7 @@ static int __init mptctl_init(void)
-               goto out_fail;
+       mpi_hdr = (MPIHeader_t *) mf;
+       MsgContext =  mpi_hdr->MsgContext;
+       sasIoUnitCntrReq = (SasIoUnitControlRequest_t *)mf;
+-      memset(sasIoUnitCntrReq,0,sizeof(SasIoUnitControlRequest_t));
++      memset(sasIoUnitCntrReq, 0, sizeof(SasIoUnitControlRequest_t));
+       sasIoUnitCntrReq->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
+       sasIoUnitCntrReq->MsgContext = MsgContext;
+       sasIoUnitCntrReq->Operation = opcode;
+@@ -4857,7 +4855,7 @@ csmisas_phy_reset(MPT_ADAPTER *ioc, u8 P
+           & MPI_IOCSTATUS_MASK;
+       if (ioc_status != MPI_IOCSTATUS_SUCCESS) {
+               printk(KERN_DEBUG "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
+-                  __FUNCTION__,
++                  __func__,
+                   sasIoUnitCntrReply->IOCStatus,
+                   sasIoUnitCntrReply->IOCLogInfo);
+               return -1;
+@@ -4878,12 +4876,12 @@ csmisas_phy_control(unsigned long arg)
+       CSMI_SAS_PHY_CONTROL_BUFFER __user *uarg = (void __user *) arg;
+       IOCTL_HEADER                    ioctl_header;
+       PCSMI_SAS_PHY_CONTROL_BUFFER    karg;
+-      SasIOUnitPage0_t                *sasIoUnitPg0=NULL;
++      SasIOUnitPage0_t                *sasIoUnitPg0 = NULL;
+       dma_addr_t                      sasIoUnitPg0_dma;
+-      int                             sasIoUnitPg0_data_sz=0;
+-      SasIOUnitPage1_t                *sasIoUnitPg1=NULL;
++      int                             sasIoUnitPg0_data_sz = 0;
++      SasIOUnitPage1_t                *sasIoUnitPg1 = NULL;
+       dma_addr_t                      sasIoUnitPg1_dma;
+-      int                             sasIoUnitPg1_data_sz=0;
++      int                             sasIoUnitPg1_data_sz = 0;
+       ConfigExtendedPageHeader_t      hdr;
+       CONFIGPARMS                     cfg;
+       MPT_ADAPTER                     *ioc = NULL;
+@@ -4894,7 +4892,7 @@ csmisas_phy_control(unsigned long arg)
+       if (copy_from_user(&ioctl_header, uarg, sizeof(IOCTL_HEADER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in IOCTL_HEADER"
+-                  "struct @ %p\n", __FILE__, __LINE__, __FUNCTION__, uarg);
++                  "struct @ %p\n", __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
  
-+      mptctl_taskmgmt_id = mpt_register(mptctl_taskmgmt_reply, MPTCTL_DRIVER);
-       mpt_reset_register(mptctl_id, mptctl_ioc_reset);
-       mpt_event_register(mptctl_id, mptctl_event_process);
+@@ -4902,11 +4900,11 @@ csmisas_phy_control(unsigned long arg)
+       memory_pages = get_order(csmi_sas_phy_control_buffer_sz);
+       karg = (PCSMI_SAS_PHY_CONTROL_BUFFER)__get_free_pages(
+               GFP_KERNEL, memory_pages);
+-      if (!karg){
++      if (!karg) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to malloc SAS_PHY_CONTROL_BUFFER "
+                       "csmi_sas_phy_control_buffer_sz=%d memory_pages=%d\n",
+-                      __FILE__, __LINE__, __FUNCTION__,
++                      __FILE__, __LINE__, __func__,
+                       csmi_sas_phy_control_buffer_sz, memory_pages);
+               return -ENOMEM;
+       }
+@@ -4915,7 +4913,7 @@ csmisas_phy_control(unsigned long arg)
+       if (copy_from_user(karg, uarg, csmi_sas_phy_control_buffer_sz)) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_phy_control_buffer "
+-                  "struct @ %p\n", __FILE__, __LINE__, __FUNCTION__, uarg);
++                  "struct @ %p\n", __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
+       }
+@@ -4923,19 +4921,19 @@ csmisas_phy_control(unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(ioctl_header.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)karg, memory_pages);
+               return -ENODEV;
+       }
  
-@@ -2956,15 +3132,23 @@ static void mptctl_exit(void)
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)karg, memory_pages);
+               return -ENODEV;
+       }
  
-       /* De-register reset handler from base module */
-       mpt_reset_deregister(mptctl_id);
-+      mpt_reset_deregister(mptctl_taskmgmt_id);
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
-       /* De-register callback handler from base module */
-       mpt_deregister(mptctl_id);
+       if (karg->bPhyIdentifier >= ioc->num_ports) {
+               karg->IoctlHeader.ReturnCode =
+@@ -4970,7 +4968,8 @@ csmisas_phy_control(unsigned long arg)
+       }
  
-         mpt_device_driver_deregister(MPTCTL_DRIVER);
--
- }
+       if (hdr.ExtPageLength == 0) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
++              dcsmisasprintk(ioc,
++                  printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sas_phy_control_exit;
+       }
+@@ -4980,7 +4979,8 @@ csmisas_phy_control(unsigned long arg)
+           sasIoUnitPg0_data_sz, &sasIoUnitPg0_dma);
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+       if (!sasIoUnitPg0) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++              dcsmisasprintk(ioc,
++                  printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sas_phy_control_exit;
+       }
+@@ -5023,7 +5023,8 @@ csmisas_phy_control(unsigned long arg)
+       }
  
-+#if defined(CPQ_CIM)
-+#include "csmi/csmisas.c"
-+#endif // CPQ_CIM
-+
-+#if defined(DIAG_BUFFER_SUPPORT)
-+#include "rejected_ioctls/diag_buffer.c"
-+#endif
-+
- module_init(mptctl_init);
- module_exit(mptctl_exit);
---- a/drivers/message/fusion/mptctl.h
-+++ b/drivers/message/fusion/mptctl.h
-@@ -1,5 +1,5 @@
- /*
-- *  linux/drivers/message/fusion/mptioctl.h
-+ *  linux/drivers/message/fusion/mptctl.h
-  *      Fusion MPT misc device (ioctl) driver.
-  *      For use with PCI chip/adapter(s):
-  *          LSIFC9xx/LSI409xx Fibre Channel
-@@ -460,8 +460,5 @@ typedef struct _hp_target_info {
+       if (hdr.ExtPageLength == 0) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
++              dcsmisasprintk(ioc,
++                  printk(KERN_ERR ": hdr.ExtPageLength == 0\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sas_phy_control_exit;
+       }
+@@ -5033,7 +5034,8 @@ csmisas_phy_control(unsigned long arg)
+           sasIoUnitPg1_data_sz, &sasIoUnitPg1_dma);
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+       if (!sasIoUnitPg1) {
+-              dcsmisasprintk(ioc, printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
++              dcsmisasprintk(ioc,
++                  printk(KERN_ERR ": pci_alloc_consistent: FAILED\n"));
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+               goto cim_sas_phy_control_exit;
+       }
+@@ -5054,19 +5056,18 @@ csmisas_phy_control(unsigned long arg)
+       case CSMI_SAS_PC_LINK_RESET:
+       case CSMI_SAS_PC_HARD_RESET:
+       {
+-              u8 opcode = (karg->uFunction==CSMI_SAS_PC_LINK_RESET) ?
++              u8 opcode = (karg->uFunction == CSMI_SAS_PC_LINK_RESET) ?
+                   MPI_SAS_OP_PHY_LINK_RESET : MPI_SAS_OP_PHY_HARD_RESET;
+-              if((karg->uLinkFlags & CSMI_SAS_PHY_ACTIVATE_CONTROL) &&
++              if ((karg->uLinkFlags & CSMI_SAS_PHY_ACTIVATE_CONTROL) &&
+                   (karg->usLengthOfControl >= sizeof(CSMI_SAS_PHY_CONTROL)) &&
+-                  (karg->bNumberOfControls > 0)){
+-                      if(karg->Control[0].bRate ==
++                  (karg->bNumberOfControls > 0)) {
++                      if (karg->Control[0].bRate ==
+                          CSMI_SAS_LINK_RATE_1_5_GBPS) {
+                               sasIoUnitPg1->PhyData[karg->bPhyIdentifier].MaxMinLinkRate =
+                               MPI_SAS_IOUNIT1_MAX_RATE_1_5 |
+                               MPI_SAS_IOUNIT1_MIN_RATE_1_5;
+-                      }
+-                      else if(karg->Control[0].bRate ==
++                      } else if (karg->Control[0].bRate ==
+                          CSMI_SAS_LINK_RATE_3_0_GBPS) {
+                               sasIoUnitPg1->PhyData[karg->bPhyIdentifier].MaxMinLinkRate =
+                               MPI_SAS_IOUNIT1_MAX_RATE_3_0 |
+@@ -5103,7 +5104,7 @@ csmisas_phy_control(unsigned long arg)
+       }
+       case CSMI_SAS_PC_PHY_DISABLE:
+-              if(karg->usLengthOfControl || karg->bNumberOfControls) {
++              if (karg->usLengthOfControl || karg->bNumberOfControls) {
+                       karg->IoctlHeader.ReturnCode =
+                           CSMI_SAS_STATUS_INVALID_PARAMETER;
+                       break;
+@@ -5135,14 +5136,14 @@ csmisas_phy_control(unsigned long arg)
+               break;
  
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--
- #endif
+       case CSMI_SAS_PC_GET_PHY_SETTINGS:
+-              if(karg->usLengthOfControl || karg->bNumberOfControls) {
++              if (karg->usLengthOfControl || karg->bNumberOfControls) {
+                       karg->IoctlHeader.ReturnCode =
+                           CSMI_SAS_STATUS_INVALID_PARAMETER;
+                       break;
+               }
+-              if(csmi_sas_phy_control_buffer_sz <
+-                  offsetof(CSMI_SAS_PHY_CONTROL_BUFFER,Control) +
+-                  (4* sizeof(CSMI_SAS_PHY_CONTROL))) {
++              if (csmi_sas_phy_control_buffer_sz <
++                  offsetof(CSMI_SAS_PHY_CONTROL_BUFFER, Control) +
++                  (4 * sizeof(CSMI_SAS_PHY_CONTROL))) {
+                       karg->IoctlHeader.ReturnCode =
+                           CSMI_SAS_STATUS_INVALID_PARAMETER;
+                       break;
+@@ -5175,15 +5176,15 @@ csmisas_phy_control(unsigned long arg)
  
---- a/drivers/message/fusion/mptdebug.h
-+++ b/drivers/message/fusion/mptdebug.h
-@@ -17,6 +17,10 @@
-  *
-  * Example:  (programming for MPT_DEBUG_EVENTS on host 5)
-  *
-+ * global setting:
-+ * echo 8 > /sys/module/mptbase/parameters/mpt_debug_level
-+ *
-+ * per host setting:
-  * echo 8 > /sys/class/scsi_host/host5/debug_level
-  *
-  * --------------------------------------------------------
-@@ -55,9 +59,11 @@
- #define MPT_DEBUG_RESET                       0x00008000
- #define MPT_DEBUG_SCSI                        0x00010000
- #define MPT_DEBUG_IOCTL                       0x00020000
-+#define MPT_DEBUG_CSMISAS             0x00040000
- #define MPT_DEBUG_FC                  0x00080000
- #define MPT_DEBUG_SAS                 0x00100000
- #define MPT_DEBUG_SAS_WIDE            0x00200000
-+#define MPT_DEBUG_36GB_MEM            0x00400000
+       /* Copy the data from kernel memory to user memory
+        */
+-      if (copy_to_user(uarg, karg,csmi_sas_phy_control_buffer_sz)) {
++      if (copy_to_user(uarg, karg, csmi_sas_phy_control_buffer_sz)) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to write out csmi_sas_phy_control_buffer @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
+       }
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       free_pages((unsigned long)karg, memory_pages);
+       return 0;
+ }
+@@ -5202,7 +5203,8 @@ csmisas_phy_control(unsigned long arg)
+  *            -EFAULT for non-successful reply or no reply (timeout)
+  **/
+ static int
+-csmisas_get_manuf_pg_7(MPT_ADAPTER *ioc, ManufacturingPage7_t *mfgpage7_buffer, int mfg_size)
++csmisas_get_manuf_pg_7(MPT_ADAPTER *ioc, ManufacturingPage7_t *mfgpage7_buffer,
++    int mfg_size)
+ {
+       ConfigPageHeader_t hdr;
+       CONFIGPARMS     cfg;
+@@ -5281,41 +5283,41 @@ csmisas_get_connector_info(unsigned long
+               printk(KERN_ERR "%s@%d::%s() - "
+                  "Unable to read in csmi_sas_connector_info_buffer"
+                  " struct @ %p\n",
+-                 __FILE__, __LINE__, __FUNCTION__, uarg);
++                 __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
- /*
-  * CONFIG_FUSION_LOGGING - enabled in Kconfig
-@@ -126,6 +132,9 @@
- #define dctlprintk(IOC, CMD)                  \
-       MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_IOCTL)
+       if (((iocnum = mpt_verify_adapter(karg.IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
-+#define dcsmisasprintk(IOC, CMD)              \
-+      MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_CSMISAS)
-+
- #define dfcprintk(IOC, CMD)                   \
-       MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_FC)
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
-@@ -135,7 +144,8 @@
- #define dsaswideprintk(IOC, CMD)              \
-       MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_SAS_WIDE)
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
--
-+#define d36memprintk(IOC, CMD)                \
-+      MPT_CHECK_LOGGING(IOC, CMD, MPT_DEBUG_36GB_MEM)
+       karg.IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
  
- /*
-  * Verbose logging
---- a/drivers/message/fusion/mptfc.c
-+++ b/drivers/message/fusion/mptfc.c
-@@ -43,6 +43,7 @@
-     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/init.h>
-@@ -52,8 +53,10 @@
- #include <linux/delay.h>      /* for mdelay */
- #include <linux/interrupt.h>  /* needed for in_interrupt() proto */
- #include <linux/reboot.h>     /* notifier code */
-+#include <linux/sched.h>
- #include <linux/workqueue.h>
- #include <linux/sort.h>
-+#include <linux/pci.h>
- #include <scsi/scsi.h>
- #include <scsi/scsi_cmnd.h>
-@@ -84,6 +87,14 @@ MODULE_PARM_DESC(mptfc_dev_loss_tmo, " I
-                                    " return following a device loss event."
-                                    "  Default=60.");
-+static int mpt_sdev_queue_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
-+static int mptfc_set_sdev_queue_depth(const char *val, struct kernel_param *kp);
-+module_param_call(mpt_sdev_queue_depth, mptfc_set_sdev_queue_depth,
-+    param_get_int,  &mpt_sdev_queue_depth, 0600);
-+MODULE_PARM_DESC(mpt_sdev_queue_depth,
-+    " Max Device Queue Depth (default="
-+    __MODULE_STRING(MPT_SCSI_CMD_PER_DEV_HIGH) ")");
-+
- /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
- #define MPTFC_MAX_LUN (16895)
- static int max_lun = MPTFC_MAX_LUN;
-@@ -183,6 +194,34 @@ static struct fc_function_template mptfc
-       .show_host_symbolic_name = 1,
- };
+       /* `32` is the sizeof MPI_MANPAGE7_CONNECTOR_INFO */
+       for (i = 0; i < 32; i++) {
+               karg.Reference[i].uPinout = CSMI_SAS_CON_UNKNOWN;
+-              strcpy(karg.Reference[i].bConnector,"");
++              strcpy(karg.Reference[i].bConnector, "");
+               karg.Reference[i].bLocation = CSMI_SAS_CON_UNKNOWN;
+       }
  
-+/**
-+ *    mptfc_set_sdev_queue_depth - global setting of the mpt_sdev_queue_depth
-+ *    found via /sys/module/mptfc/parameters/mpt_sdev_queue_depth
-+ *    @val:
-+ *    @kp:
-+ *
-+ *    Returns
-+ **/
-+static int
-+mptfc_set_sdev_queue_depth(const char *val, struct kernel_param *kp)
-+{
-+      int ret = param_set_int(val, kp);
-+      MPT_ADAPTER *ioc;
-+      struct scsi_device      *sdev;
-+
-+      if (ret)
-+              return ret;
-+
-+      list_for_each_entry(ioc, &ioc_list, list) {
-+              if (ioc->bus_type != FC)
-+                      continue;
-+              shost_for_each_device(sdev, ioc->sh)
-+                      mptscsih_change_queue_depth(sdev, mpt_sdev_queue_depth);
-+              ioc->sdev_queue_depth = mpt_sdev_queue_depth;
-+      }
-+      return 0;
-+}
-+
- static int
- mptfc_block_error_handler(struct scsi_cmnd *SCpnt,
-                         int (*func)(struct scsi_cmnd *SCpnt),
-@@ -194,7 +233,7 @@ mptfc_block_error_handler(struct scsi_cm
-       struct fc_rport         *rport = starget_to_rport(scsi_target(sdev));
-       unsigned long           flags;
-       int                     ready;
--      MPT_ADAPTER             *ioc;
-+      MPT_ADAPTER             *ioc;
+-      mfgPg7_sz = offsetof(CONFIG_PAGE_MANUFACTURING_7,ConnectorInfo) +
++      mfgPg7_sz = offsetof(CONFIG_PAGE_MANUFACTURING_7, ConnectorInfo) +
+           (ioc->num_ports * sizeof(MPI_MANPAGE7_CONNECTOR_INFO));
+       mfgPg7 = kmalloc(mfgPg7_sz, GFP_KERNEL);
+-      if (!mfgPg7){
++      if (!mfgPg7) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to malloc @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, mfgPg7);
++                  __FILE__, __LINE__, __func__, mfgPg7);
+               return -EFAULT;
+       }
+       memset(mfgPg7, 0, mfgPg7_sz);
+@@ -5339,13 +5341,12 @@ csmisas_get_connector_info(unsigned long
+       if (copy_to_user(uarg, &karg,
+               sizeof(CSMI_SAS_CONNECTOR_INFO_BUFFER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+-              "Unable to write out csmi_sas_connector_info_buffer @"
+-             "%p\n",
+-              __FILE__, __LINE__, __FUNCTION__, uarg);
++              "Unable to write out csmi_sas_connector_info_buffer @%p\n",
++              __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-       hd = shost_priv(SCpnt->device->host);
-       ioc = hd->ioc;
-@@ -231,28 +270,28 @@ static int
- mptfc_abort(struct scsi_cmnd *SCpnt)
- {
-       return
--          mptfc_block_error_handler(SCpnt, mptscsih_abort, __func__);
-+          mptfc_block_error_handler(SCpnt, mptscsih_abort, __FUNCTION__);
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       return 0;
  }
  
+@@ -5357,21 +5358,21 @@ csmisas_get_connector_info(unsigned long
+  **/
  static int
- mptfc_dev_reset(struct scsi_cmnd *SCpnt)
- {
-       return
--          mptfc_block_error_handler(SCpnt, mptscsih_dev_reset, __func__);
-+          mptfc_block_error_handler(SCpnt, mptscsih_dev_reset, __FUNCTION__);
- }
+ csmisas_fill_location_data(MPT_ADAPTER *ioc, u8 bus, u8 id, u8 opcode,
+-      CSMI_SAS_LOCATION_IDENTIFIER * location_ident)
++      CSMI_SAS_LOCATION_IDENTIFIER *location_ident)
+ {
+       ConfigExtendedPageHeader_t      hdr;
+       CONFIGPARMS                     cfg;
+       int                             rc;
+-      SasDevicePage0_t                *sasDevicePg0=NULL;
+-      SasEnclosurePage0_t             *sasEnclosurePg0=NULL;
+-      dma_addr_t                      sasDevicePg0_dma,sasEnclosurePg0_dma;
+-      int                             sasDevicePg0_data_sz=0;
+-      int                             sasEnclosurePg0_data_sz=0;
++      SasDevicePage0_t                *sasDevicePg0 = NULL;
++      SasEnclosurePage0_t             *sasEnclosurePg0 = NULL;
++      dma_addr_t                      sasDevicePg0_dma, sasEnclosurePg0_dma;
++      int                             sasDevicePg0_data_sz = 0;
++      int                             sasEnclosurePg0_data_sz = 0;
+       u64                             sas_address;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
+-      memset (location_ident, 0, sizeof(*location_ident));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
++      memset(location_ident, 0, sizeof(*location_ident));
+       /* SAS Device Page 0 */
+       hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
+@@ -5389,12 +5390,12 @@ csmisas_fill_location_data(MPT_ADAPTER *
+       cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
  
- static int
- mptfc_bus_reset(struct scsi_cmnd *SCpnt)
- {
-       return
--          mptfc_block_error_handler(SCpnt, mptscsih_bus_reset, __func__);
-+          mptfc_block_error_handler(SCpnt, mptscsih_bus_reset, __FUNCTION__);
- }
+       if ((rc = mpt_config(ioc, &cfg)) != 0) {
+-              rc=-1;
++              rc = -1;
+               goto fill_location_data_exit;
+       }
  
- static int
- mptfc_host_reset(struct scsi_cmnd *SCpnt)
- {
-       return
--          mptfc_block_error_handler(SCpnt, mptscsih_host_reset, __func__);
-+          mptfc_block_error_handler(SCpnt, mptscsih_host_reset, __FUNCTION__);
- }
+       if (hdr.ExtPageLength == 0) {
+-              rc=-1;
++              rc = -1;
+               goto fill_location_data_exit;
+       }
  
- static void
-@@ -476,6 +515,7 @@ mptfc_register_dev(MPT_ADAPTER *ioc, int
-                               if (vtarget) {
-                                       vtarget->id = pg0->CurrentTargetID;
-                                       vtarget->channel = pg0->CurrentBus;
-+                                      vtarget->deleted = 0;
-                               }
-                       }
-                       *((struct mptfc_rport_info **)rport->dd_data) = ri;
-@@ -513,6 +553,7 @@ mptfc_target_destroy(struct scsi_target 
-       struct fc_rport         *rport;
-       struct mptfc_rport_info *ri;
+@@ -5402,7 +5403,7 @@ csmisas_fill_location_data(MPT_ADAPTER *
+       sasDevicePg0 = (SasDevicePage0_t *) pci_alloc_consistent(
+           ioc->pcidev, sasDevicePg0_data_sz, &sasDevicePg0_dma);
+       if (!sasDevicePg0) {
+-              rc=-1;
++              rc = -1;
+               goto fill_location_data_exit;
+       }
  
-+      printk("%s - starget=%p\n", __FUNCTION__, starget);
-       rport = starget_to_rport(starget);
-       if (rport) {
-               ri = *((struct mptfc_rport_info **)rport->dd_data);
-@@ -560,6 +601,7 @@ mptfc_target_alloc(struct scsi_target *s
+@@ -5411,10 +5412,10 @@ csmisas_fill_location_data(MPT_ADAPTER *
+       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+       cfg.pageAddr = (bus << 8) + id
+           + (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
+-              MPI_SAS_DEVICE_PGAD_FORM_SHIFT);
++              MPI_SAS_DEVICE_PGAD_FORM_SHIFT);
  
-       return rc;
- }
-+
- /*
-  *    mptfc_dump_lun_info
-  *    @ioc
-@@ -589,7 +631,6 @@ mptfc_dump_lun_info(MPT_ADAPTER *ioc, st
-               (unsigned long long)nn));
- }
+       if ((rc = mpt_config(ioc, &cfg)) != 0) {
+-              rc=-1;
++              rc = -1;
+               goto fill_location_data_exit;
+       }
  
--
- /*
-  *    OS entry point to allow host driver to alloc memory
-  *    for each scsi device. Called once per device the bus scan.
-@@ -604,7 +645,7 @@ mptfc_slave_alloc(struct scsi_device *sd
-       VirtDevice              *vdevice;
-       struct scsi_target      *starget;
-       struct fc_rport         *rport;
--      MPT_ADAPTER             *ioc;
-+      MPT_ADAPTER             *ioc;
+@@ -5442,12 +5443,12 @@ csmisas_fill_location_data(MPT_ADAPTER *
+       cfg.timeout = MPT_IOCTL_DEFAULT_TIMEOUT;
  
-       starget = scsi_target(sdev);
-       rport = starget_to_rport(starget);
-@@ -614,11 +655,10 @@ mptfc_slave_alloc(struct scsi_device *sd
+       if ((rc = mpt_config(ioc, &cfg)) != 0) {
+-              rc=0;
++              rc = 0;
+               goto fill_location_data_exit;
+       }
  
-       hd = shost_priv(sdev->host);
-       ioc = hd->ioc;
--
-       vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
-       if (!vdevice) {
-               printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
--                              ioc->name, sizeof(VirtDevice));
-+                  ioc->name, sizeof(VirtDevice));
-               return -ENOMEM;
+       if (hdr.ExtPageLength == 0) {
+-              rc=0;
++              rc = 0;
+               goto fill_location_data_exit;
        }
  
-@@ -635,10 +675,7 @@ mptfc_slave_alloc(struct scsi_device *sd
-       vdevice->lun = sdev->lun;
+@@ -5455,36 +5456,34 @@ csmisas_fill_location_data(MPT_ADAPTER *
+       sasEnclosurePg0 = (SasEnclosurePage0_t *) pci_alloc_consistent(
+           ioc->pcidev, sasEnclosurePg0_data_sz, &sasEnclosurePg0_dma);
+       if (!sasEnclosurePg0) {
+-              rc=0;
++              rc = 0;
+               goto fill_location_data_exit;
+       }
+       cfg.physAddr = sasEnclosurePg0_dma;
+       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+       cfg.pageAddr = sasDevicePg0->EnclosureHandle
+-          + (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE << MPI_SAS_ENCLOS_PGAD_FORM_SHIFT);
++          + (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
++              MPI_SAS_ENCLOS_PGAD_FORM_SHIFT);
  
-       vtarget->num_luns++;
--
--
-       mptfc_dump_lun_info(ioc, rport, sdev, vtarget);
--
-       return 0;
- }
+       if ((rc = mpt_config(ioc, &cfg)) != 0) {
+-              rc=0;
++              rc = 0;
+               goto fill_location_data_exit;
+       }
  
-@@ -944,11 +981,12 @@ start_over:
+-      location_ident->bLocationFlags |= CSMI_SAS_LOCATE_ENCLOSURE_IDENTIFIER_VALID;
++      location_ident->bLocationFlags |=
++          CSMI_SAS_LOCATE_ENCLOSURE_IDENTIFIER_VALID;
+       memcpy(&sas_address, &sasEnclosurePg0->EnclosureLogicalID, sizeof(u64));
+       sas_address = reverse_byte_order64(sas_address);
+       if (sas_address)
+-              memcpy(location_ident->bEnclosureIdentifier, &sas_address, sizeof(u64));
++              memcpy(location_ident->bEnclosureIdentifier, &sas_address,
++                  sizeof(u64));
+       else
+-              strcpy(location_ident->bEnclosureIdentifier,"Internal");
++              strcpy(location_ident->bEnclosureIdentifier, "Internal");
+-// bBayPrefix - not supported
++/* bBayPrefix - not supported */
+-// TODO - We need to look at sasEnclosurePg0-.Flags , to determine
+-//    whether SEP BUS/TargetID is valid.  Ifs its a SES device, then
+-//    issue internal inquiry to (bus/id) to gather the Enclosure name.
+-//    If the device is SMP, then issue SMP_MANUFACTURING to get enclosure name
+-//    If its direct attached, there is no enclosure name
+       location_ident->bLocationFlags |= CSMI_SAS_LOCATE_ENCLOSURE_NAME_VALID;
+-      strcpy(location_ident->bEnclosureName,"Not Supported");
++      strcpy(location_ident->bEnclosureName, "Not Supported");
+       location_ident->bLocationFlags |= CSMI_SAS_LOCATE_LOCATION_STATE_VALID;
+       location_ident->bLocationState = CSMI_SAS_LOCATE_UNKNOWN;
+@@ -5493,11 +5492,6 @@ csmisas_fill_location_data(MPT_ADAPTER *
+       location_ident->bBayIdentifier = le16_to_cpu(sasDevicePg0->Slot);
+-// TODO - illuminating LEDs,
+-// karg->bIdentify = CSMI_SAS_LOCATE_FORCE_OFF, CSMI_SAS_LOCATE_FORCE_ON
+-// We can enable/disable LEDs by SCSI Enclosure Processor MPI request message
+-// printk("Flags=0x%x\n",sasEnclosurePg0->Flags);
+-
+ /* check sasEnclosurePg0->Flags -
+  * to validate whether we need to send the SEPRequest
+  * bit:5 should be set
+@@ -5527,13 +5521,13 @@ fill_location_data_exit:
+               pci_free_consistent(ioc->pcidev, sasEnclosurePg0_data_sz,
+                   sasEnclosurePg0, sasEnclosurePg0_dma);
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
        return rc;
  }
  
--static void
-+static int
- mptfc_SetFcPortPage1_defaults(MPT_ADAPTER *ioc)
- {
-       int             ii;
-       FCPortPage1_t   *pp1;
-+      int             rc;
+ static int
+-csmisas_fill_location_data_raid(MPT_ADAPTER *ioc, PCSMI_SAS_GET_LOCATION_BUFFER karg, u8 VolumeBus,
+-      u8 volumeID)
++csmisas_fill_location_data_raid(MPT_ADAPTER *ioc,
++    PCSMI_SAS_GET_LOCATION_BUFFER karg, u8 VolumeBus, u8 volumeID)
+ {
+       pRaidVolumePage0_t              pVolume0 = NULL;
+       pRaidPhysDiskPage0_t            pPhysDisk0 = NULL;
+@@ -5554,9 +5548,9 @@ csmisas_fill_location_data_raid(MPT_ADAP
+       csmi_sas_get_location_sz = karg->IoctlHeader.Length;
+       physDiskNumMax = (csmi_sas_get_location_sz -
+-          offsetof(CSMI_SAS_GET_LOCATION_BUFFER,Location))
++          offsetof(CSMI_SAS_GET_LOCATION_BUFFER, Location))
+           / sizeof(CSMI_SAS_LOCATION_IDENTIFIER);
+-      karg->bNumberOfLocationIdentifiers=0;
++      karg->bNumberOfLocationIdentifiers = 0;
  
-       #define MPTFC_FW_DEVICE_TIMEOUT (1)
-       #define MPTFC_FW_IO_PEND_TIMEOUT (1)
-@@ -956,8 +994,8 @@ mptfc_SetFcPortPage1_defaults(MPT_ADAPTE
-       #define OFF_FLAGS (MPI_FCPORTPAGE1_FLAGS_VERBOSE_RESCAN_EVENTS)
+       /*
+        * get RAID Volume Page 0
+@@ -5592,7 +5586,7 @@ csmisas_fill_location_data_raid(MPT_ADAP
  
-       for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
--              if (mptfc_GetFcPortPage1(ioc, ii) != 0)
--                      continue;
-+              if ((rc = mptfc_GetFcPortPage1(ioc, ii)) < 0)
-+                      return rc;
-               pp1 = ioc->fc_data.fc_port_page1[ii].data;
-               if ((pp1->InitiatorDeviceTimeout == MPTFC_FW_DEVICE_TIMEOUT)
-                && (pp1->InitiatorIoPendTimeout == MPTFC_FW_IO_PEND_TIMEOUT)
-@@ -968,8 +1006,10 @@ mptfc_SetFcPortPage1_defaults(MPT_ADAPTE
-               pp1->InitiatorIoPendTimeout = MPTFC_FW_IO_PEND_TIMEOUT;
-               pp1->Flags &= ~OFF_FLAGS;
-               pp1->Flags |= ON_FLAGS;
--              mptfc_WriteFcPortPage1(ioc, ii);
-+              if ((rc = mptfc_WriteFcPortPage1(ioc, ii)) < 0)
-+                      return rc;
+       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+       cfg.physAddr = volume0_dma;
+-      if (mpt_config(ioc, &cfg) != 0){
++      if (mpt_config(ioc, &cfg) != 0) {
+               rc = -1;
+               goto sas_fill_location_data_raid_exit;
        }
-+      return 0;
- }
+@@ -5632,17 +5626,17 @@ csmisas_fill_location_data_raid(MPT_ADAP
+       }
+       cfg.physAddr = physdisk0_dma;
  
+-      for (i=0; i < min(pVolume0->NumPhysDisks, physDiskNumMax); i++) {
++      for (i = 0; i < min(pVolume0->NumPhysDisks, physDiskNumMax); i++) {
  
-@@ -1082,10 +1122,13 @@ mptfc_link_status_change(struct work_str
- static void
- mptfc_setup_reset(struct work_struct *work)
- {
--      MPT_ADAPTER             *ioc =
-+      MPT_ADAPTER             *ioc =
-               container_of(work, MPT_ADAPTER, fc_setup_reset_work);
-       u64                     pn;
-       struct mptfc_rport_info *ri;
-+      struct scsi_target      *starget;
-+      VirtTarget              *vtarget;
-+
+               /* obtain a refresh of pPhysDisk0 */
+               cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+               cfg.pageAddr = pVolume0->PhysDisk[i].PhysDiskNum;
+-              if (mpt_config(ioc, &cfg) != 0){
++              if (mpt_config(ioc, &cfg) != 0) {
+                       rc = -1;
+                       goto sas_fill_location_data_raid_exit;
+               }
  
-       /* reset about to happen, delete (block) all rports */
-       list_for_each_entry(ri, &ioc->fc_rports, list) {
-@@ -1093,6 +1136,12 @@ mptfc_setup_reset(struct work_struct *wo
-                       ri->flags &= ~MPT_RPORT_INFO_FLAGS_REGISTERED;
-                       fc_remote_port_delete(ri->rport);       /* won't sleep */
-                       ri->rport = NULL;
-+                      starget = ri->starget;
-+                      if (starget) {
-+                              vtarget = starget->hostdata;
-+                              if (vtarget)
-+                                      vtarget->deleted = 1;
-+                      }
-                       pn = (u64)ri->pg0.WWPN.High << 32 |
-                            (u64)ri->pg0.WWPN.Low;
-@@ -1111,8 +1160,22 @@ mptfc_rescan_devices(struct work_struct 
-       MPT_ADAPTER             *ioc =
-               container_of(work, MPT_ADAPTER, fc_rescan_work);
-       int                     ii;
-+      int                     rc;
-       u64                     pn;
-       struct mptfc_rport_info *ri;
-+      struct scsi_target      *starget;
-+      VirtTarget              *vtarget;
-+
-+      /*
-+       * if cannot set defaults, something's really wrong, bail out
-+       */
-+
-+      if ((rc = mptfc_SetFcPortPage1_defaults(ioc)) < 0) {
-+              dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "mptfc_rescan.%d: unable to set PP1 defaults, rc %d.\n",
-+                  ioc->name, ioc->sh->host_no, rc));
-+              return;
-+      }
+-              if((csmisas_fill_location_data(ioc, pPhysDisk0->PhysDiskBus,
++              if ((csmisas_fill_location_data(ioc, pPhysDisk0->PhysDiskBus,
+                   pPhysDisk0->PhysDiskID, karg->bIdentify,
+                   &karg->Location[karg->bNumberOfLocationIdentifiers])) == 0)
+                       karg->bNumberOfLocationIdentifiers++;
+@@ -5679,7 +5673,7 @@ csmisas_fill_location_data_raid(MPT_ADAP
+               if (csmisas_get_ioc_pg5(ioc, iocPage5, sz) != 0)
+                       goto sas_fill_location_data_raid_exit;
+-              for(i = 0, idx = pVolume0->NumPhysDisks ; i < num_hotpares;
++              for (i = 0, idx = pVolume0->NumPhysDisks ; i < num_hotpares;
+                   i++, idx++) {
+                       if (idx >= physDiskNumMax)
+@@ -5728,11 +5722,11 @@ csmisas_fill_location_data_raid(MPT_ADAP
+                       if ((pVolume0->VolumeType ==
+                               MPI_RAID_VOL_TYPE_IME) &&
+                           ((tmpTotalMaxLBA * 2) +
+-                           (64*2*1024 ) /*metadata = 64MB*/ >
++                           (64*2*1024) /*metadata = 64MB*/ >
+                           le32_to_cpu(pPhysDisk0->MaxLBA)))
+                               continue;
  
-       /* start by tagging all ports as missing */
-       list_for_each_entry(ri, &ioc->fc_rports, list) {
-@@ -1140,6 +1203,12 @@ mptfc_rescan_devices(struct work_struct 
-                                      MPT_RPORT_INFO_FLAGS_MISSING);
-                       fc_remote_port_delete(ri->rport);       /* won't sleep */
-                       ri->rport = NULL;
-+                      starget = ri->starget;
-+                      if (starget) {
-+                              vtarget = starget->hostdata;
-+                              if (vtarget)
-+                                      vtarget->deleted = 1;
-+                      }
-                       pn = (u64)ri->pg0.WWPN.High << 32 |
-                            (u64)ri->pg0.WWPN.Low;
-@@ -1238,6 +1307,10 @@ mptfc_probe(struct pci_dev *pdev, const 
-       sh->max_id = ioc->pfacts->MaxDevices;
-       sh->max_lun = max_lun;
-+      sh->this_id = ioc->pfacts[0].PortSCSIID;
-+
-+      ioc->sdev_queue_depth = mpt_sdev_queue_depth;
-+
-       /* Required entry.
-        */
-       sh->unique_id = ioc->id;
-@@ -1251,17 +1324,15 @@ mptfc_probe(struct pci_dev *pdev, const 
-        * A slightly different algorithm is required for
-        * 64bit SGEs.
-        */
--      scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
--      if (sizeof(dma_addr_t) == sizeof(u64)) {
-+      scale = ioc->req_sz/ioc->SGE_size;
-+      if (ioc->sg_addr_size == sizeof(u64)) {
-               numSGE = (scale - 1) *
-                 (ioc->facts.MaxChainDepth-1) + scale +
--                (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
--                sizeof(u32));
-+                (ioc->req_sz - 60) / ioc->SGE_size;
-       } else {
-               numSGE = 1 + (scale - 1) *
-                 (ioc->facts.MaxChainDepth-1) + scale +
--                (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
--                sizeof(u32));
-+                (ioc->req_sz - 64) / ioc->SGE_size;
+-                      if((csmisas_fill_location_data(ioc,
++                      if ((csmisas_fill_location_data(ioc,
+                           pPhysDisk0->PhysDiskBus, pPhysDisk0->PhysDiskID,
+                           karg->bIdentify,
+                           &karg->Location[karg->bNumberOfLocationIdentifiers])) == 0)
+@@ -5749,7 +5743,7 @@ csmisas_fill_location_data_raid(MPT_ADAP
+               pci_free_consistent(ioc->pcidev, volumepage0sz, pVolume0,
+                   volume0_dma);
+-      if(pPhysDisk0)
++      if (pPhysDisk0)
+               pci_free_consistent(ioc->pcidev, physdiskpage0sz, pPhysDisk0,
+                   physdisk0_dma);
+@@ -5771,7 +5765,7 @@ csmisas_get_location(unsigned long arg)
+       PCSMI_SAS_GET_LOCATION_BUFFER   karg;
+       IOCTL_HEADER                    ioctl_header;
+       MPT_ADAPTER                     *ioc = NULL;
+-      int                             iocnum,i;
++      int                             iocnum, i;
+       int                             csmi_sas_get_location_sz;
+       int                             memory_pages;
+       struct sas_device_info          *sas_info;
+@@ -5779,7 +5773,7 @@ csmisas_get_location(unsigned long arg)
+       if (copy_from_user(&ioctl_header, uarg, sizeof(IOCTL_HEADER))) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in IOCTL_HEADER"
+-                  "struct @ %p\n", __FILE__, __LINE__, __FUNCTION__, uarg);
++                  "struct @ %p\n", __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
        }
  
-       if (numSGE < sh->sg_tablesize) {
-@@ -1290,30 +1361,6 @@ mptfc_probe(struct pci_dev *pdev, const 
-       dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
-                ioc->name, ioc->ScsiLookup));
--      /* Clear the TM flags
--       */
--      hd->tmPending = 0;
--      hd->tmState = TM_STATE_NONE;
--      hd->resetPending = 0;
--      hd->abortSCpnt = NULL;
--
--      /* Clear the pointer used to store
--       * single-threaded commands, i.e., those
--       * issued during a bus scan, dv and
--       * configuration pages.
--       */
--      hd->cmdPtr = NULL;
--
--      /* Initialize this SCSI Hosts' timers
--       * To use, set the timer expires field
--       * and add_timer
--       */
--      init_timer(&hd->timer);
--      hd->timer.data = (unsigned long) hd;
--      hd->timer.function = mptscsih_timer_expired;
--
--      init_waitqueue_head(&hd->scandv_waitq);
--      hd->scandv_wait_done = 0;
-       hd->last_queue_full = 0;
-       sh->transportt = mptfc_transport_template;
-@@ -1326,8 +1373,8 @@ mptfc_probe(struct pci_dev *pdev, const 
-       /* initialize workqueue */
+@@ -5787,11 +5781,11 @@ csmisas_get_location(unsigned long arg)
+       memory_pages = get_order(csmi_sas_get_location_sz);
+       karg = (PCSMI_SAS_GET_LOCATION_BUFFER)__get_free_pages(
+               GFP_KERNEL, memory_pages);
+-      if (!karg){
++      if (!karg) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                       "Unable to malloc GET_LOCATION_BUFFER "
+                       "csmi_sas_get_location_sz=%d memory_pages=%d\n",
+-                      __FILE__, __LINE__, __FUNCTION__,
++                      __FILE__, __LINE__, __func__,
+                       csmi_sas_get_location_sz, memory_pages);
+               return -ENOMEM;
+       }
+@@ -5800,7 +5794,7 @@ csmisas_get_location(unsigned long arg)
+       if (copy_from_user(karg, uarg, csmi_sas_get_location_sz)) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to read in csmi_sas_phy_control_buffer "
+-                  "struct @ %p\n", __FILE__, __LINE__, __FUNCTION__, uarg);
++                  "struct @ %p\n", __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
+       }
+@@ -5808,22 +5802,22 @@ csmisas_get_location(unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg->IoctlHeader.IOControllerNumber,
+           &ioc)) < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)karg, memory_pages);
+               return -ENODEV;
+       }
  
--      snprintf(ioc->fc_rescan_work_q_name, sizeof(ioc->fc_rescan_work_q_name),
--               "mptfc_wq_%d", sh->host_no);
-+      snprintf(ioc->fc_rescan_work_q_name, sizeof(ioc->fc_rescan_work_q_name), "mptfc_wq_%d",
-+              sh->host_no);
-       ioc->fc_rescan_work_q =
-               create_singlethread_workqueue(ioc->fc_rescan_work_q_name);
-       if (!ioc->fc_rescan_work_q)
-@@ -1340,7 +1387,6 @@ mptfc_probe(struct pci_dev *pdev, const 
-       for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
-               (void) mptfc_GetFcPortPage0(ioc, ii);
+       if (!csmisas_is_this_sas_cntr(ioc)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not SAS controller!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               free_pages((unsigned long)karg, memory_pages);
+               return -ENODEV;
        }
--      mptfc_SetFcPortPage1_defaults(ioc);
  
-       /*
-        * scan for rports -
-@@ -1378,9 +1424,6 @@ mptfc_event_process(MPT_ADAPTER *ioc, Ev
-       unsigned long flags;
-       int rc=1;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s enter.\n", __func__));
  
--      devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
--                      ioc->name, event));
--
-       if (ioc->sh == NULL ||
-               ((hd = shost_priv(ioc->sh)) == NULL))
-               return 1;
-@@ -1416,45 +1459,45 @@ mptfc_ioc_reset(MPT_ADAPTER *ioc, int re
-       unsigned long   flags;
+       karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_INVALID_PARAMETER;
+-      if(karg->bLengthOfLocationIdentifier !=
++      if (karg->bLengthOfLocationIdentifier !=
+           sizeof(CSMI_SAS_LOCATION_IDENTIFIER))
+               goto cim_sas_get_location_exit;
  
-       rc = mptscsih_ioc_reset(ioc,reset_phase);
--      if (rc == 0)
-+      if ((ioc->bus_type != FC) || (!rc))
-               return rc;
+@@ -5834,12 +5828,12 @@ csmisas_get_location(unsigned long arg)
  
--
--      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--              ": IOC %s_reset routed to FC host driver!\n",ioc->name,
--              reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
--              reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
--
--      if (reset_phase == MPT_IOC_SETUP_RESET) {
-+      switch(reset_phase) {
-+      case MPT_IOC_SETUP_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __FUNCTION__));
-               spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
-               if (ioc->fc_rescan_work_q) {
-                       queue_work(ioc->fc_rescan_work_q,
-                                  &ioc->fc_setup_reset_work);
-               }
-               spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
--      }
--
--      else if (reset_phase == MPT_IOC_PRE_RESET) {
--      }
--
--      else {  /* MPT_IOC_POST_RESET */
--              mptfc_SetFcPortPage1_defaults(ioc);
-+              break;
-+      case MPT_IOC_PRE_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __FUNCTION__));
-+              break;
-+      case MPT_IOC_POST_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_POST_RESET\n",  ioc->name, __FUNCTION__));
-               spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
-               if (ioc->fc_rescan_work_q) {
-                       queue_work(ioc->fc_rescan_work_q,
-                                  &ioc->fc_rescan_work);
-               }
-               spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
-+              break;
-+      default:
-+              break;
+       /* RAID SUPPORT */
+       if (ioc->raid_data.pIocPg2 && sas_info->is_logical_volume) {
+-              for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++){
++              for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
+                       if (sas_info->fw.id ==
+                           ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID &&
+                           sas_info->fw.channel ==
+                           ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus) {
+-                              if(csmisas_fill_location_data_raid(ioc, karg,
++                              if (csmisas_fill_location_data_raid(ioc, karg,
+                                   ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus,
+                                   ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID) == 0)
+                                       karg->IoctlHeader.ReturnCode =
+@@ -5858,13 +5852,13 @@ csmisas_get_location(unsigned long arg)
+       /* make sure there's enough room to populate the Location[] struct */
+       if ((csmi_sas_get_location_sz -
+-          offsetof(CSMI_SAS_GET_LOCATION_BUFFER,Location)) <
++          offsetof(CSMI_SAS_GET_LOCATION_BUFFER, Location)) <
+           sizeof(CSMI_SAS_LOCATION_IDENTIFIER))
+               goto cim_sas_get_location_exit;
+-      karg->bNumberOfLocationIdentifiers=1;
+-      karg->Location[0].bLocationFlags=0;
+-      if((csmisas_fill_location_data(ioc, sas_info->fw.channel,
++      karg->bNumberOfLocationIdentifiers = 1;
++      karg->Location[0].bLocationFlags = 0;
++      if ((csmisas_fill_location_data(ioc, sas_info->fw.channel,
+           sas_info->fw.id, karg->bIdentify, &karg->Location[0])) == 0)
+               karg->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
+       else
+@@ -5877,12 +5871,12 @@ csmisas_get_location(unsigned long arg)
+       if (copy_to_user(uarg, karg, csmi_sas_get_location_sz)) {
+               printk(KERN_ERR "%s@%d::%s() - "
+                   "Unable to write out csmi_sas_get_location_buffer "
+-                  "@ %p\n",__FILE__, __LINE__, __FUNCTION__, uarg);
++                  "@ %p\n", __FILE__, __LINE__, __func__, uarg);
+               free_pages((unsigned long)karg, memory_pages);
+               return -EFAULT;
        }
-       return 1;
- }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mptfc_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int __init
- mptfc_init(void)
- {
-@@ -1486,12 +1529,11 @@ mptfc_init(void)
-       return error;
+-      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n",__FUNCTION__));
++      dcsmisasprintk(ioc, printk(KERN_DEBUG "%s exit.\n", __func__));
+       free_pages((unsigned long)karg, memory_pages);
+       return 0;
  }
+Index: linux-2.6.27/drivers/message/fusion/csmi/csmisas.h
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/csmi/csmisas.h
++++ linux-2.6.27/drivers/message/fusion/csmi/csmisas.h
+@@ -87,10 +87,10 @@ Revision History:
+ #ifndef _CSMI_SAS_H_
+ #define _CSMI_SAS_H_
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mptfc_remove - Remove fc infrastructure for devices
-  *    @pdev: Pointer to pci_dev structure
-  *
-- */
-+ **/
- static void __devexit
- mptfc_remove(struct pci_dev *pdev)
- {
-@@ -1501,6 +1543,8 @@ mptfc_remove(struct pci_dev *pdev)
-       unsigned long           flags;
-       int                     ii;
+-// CSMI Specification Revision, the intent is that all versions of the
+-// specification will be backward compatible after the 1.00 release.
+-// Major revision number, corresponds to xxxx. of CSMI specification
+-// Minor revision number, corresponds to .xxxx of CSMI specification
++/* CSMI Specification Revision, the intent is that all versions of the
++ specification will be backward compatible after the 1.00 release.
++ Major revision number, corresponds to xxxx. of CSMI specification
++ Minor revision number, corresponds to .xxxx of CSMI specification */
+ #define CSMI_MAJOR_REVISION   0
+ #define CSMI_MINOR_REVISION   90
  
-+      printk("%s -pdev=%p\n", __FUNCTION__, pdev);
-+
-       /* destroy workqueue */
-       if ((work_q=ioc->fc_rescan_work_q)) {
-               spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
-@@ -1543,7 +1587,6 @@ mptfc_exit(void)
+@@ -104,60 +104,60 @@ Revision History:
+ /* TARGET OS LINUX SPECIFIC CODE                                         */
+ /*************************************************************************/
  
-       mpt_reset_deregister(mptfcDoneCtx);
-       mpt_event_deregister(mptfcDoneCtx);
--
-       mpt_deregister(mptfcInternalCtx);
-       mpt_deregister(mptfcTaskCtx);
-       mpt_deregister(mptfcDoneCtx);
---- a/drivers/message/fusion/mptlan.c
-+++ b/drivers/message/fusion/mptlan.c
-@@ -6,7 +6,6 @@
-  *
-  *  Copyright (c) 2000-2008 LSI Corporation
-  *  (mailto:DL-MPTFusionLinux@lsi.com)
-- *
-  */
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /*
-@@ -165,6 +164,11 @@ DEFINE_RWLOCK(bad_naa_lock);
- static u32 tx_max_out_p = 127 - 16;
+-// EDM #ifdef _linux
+ #ifdef __KERNEL__
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/*
-+ * Fusion MPT LAN external data
-+ */
-+
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    lan_reply - Handle all data sent from the hardware.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -190,8 +194,7 @@ lan_reply (MPT_ADAPTER *ioc, MPT_FRAME_H
-               u32 tmsg = CAST_PTR_TO_U32(reply);
+-// Linux base types
++/* Linux base types */
  
-               dioprintk((KERN_INFO MYNAM ": %s/%s: @lan_reply, tmsg %08x\n",
--                              IOC_AND_NETDEV_NAMES_s_s(dev),
--                              tmsg));
-+                  IOC_AND_NETDEV_NAMES_s_s(dev), tmsg));
+ #include <linux/types.h>
  
-               switch (GET_LAN_FORM(tmsg)) {
+ #define __i8    char
  
-@@ -440,6 +443,7 @@ mpt_lan_open(struct net_device *dev)
-       dlprintk((KERN_INFO MYNAM "/lo: Finished initializing RcvCtl\n"));
+-// pack definition
++/* pack definition */
  
-       mpt_lan_post_receive_buckets(priv);
-+
-       printk(KERN_INFO MYNAM ": %s/%s: interface up & active\n",
-                       IOC_AND_NETDEV_NAMES_s_s(dev));
+-// EDM #define CSMI_SAS_BEGIN_PACK(x)    pack(x)
+-// EDM #define CSMI_SAS_END_PACK         pack()
++#if 0
++ #define CSMI_SAS_BEGIN_PACK(x)    pack(x)
++ #define CSMI_SAS_END_PACK         pack()
+-// IOCTL Control Codes
+-// (IoctlHeader.ControlCode)
++ /* IOCTL Control Codes */
++ /* (IoctlHeader.ControlCode) */
+-// Control Codes prior to 0.77
++ /* Control Codes prior to 0.77 */
+-// Control Codes requiring CSMI_ALL_SIGNATURE
++ /* Control Codes requiring CSMI_ALL_SIGNATURE */
+-// #define CC_CSMI_SAS_GET_DRIVER_INFO    0x12345678
+-// #define CC_CSMI_SAS_GET_CNTLR_CONFIG   0x23456781
+-// #define CC_CSMI_SAS_GET_CNTLR_STATUS   0x34567812
+-// #define CC_CSMI_SAS_FIRMWARE_DOWNLOAD  0x92345678
++ #define CC_CSMI_SAS_GET_DRIVER_INFO    0x12345678
++ #define CC_CSMI_SAS_GET_CNTLR_CONFIG   0x23456781
++ #define CC_CSMI_SAS_GET_CNTLR_STATUS   0x34567812
++ #define CC_CSMI_SAS_FIRMWARE_DOWNLOAD  0x92345678
+-// Control Codes requiring CSMI_RAID_SIGNATURE
++ /* Control Codes requiring CSMI_RAID_SIGNATURE */
+-// #define CC_CSMI_SAS_GET_RAID_INFO      0x45678123
+-// #define CC_CSMI_SAS_GET_RAID_CONFIG    0x56781234
++ #define CC_CSMI_SAS_GET_RAID_INFO      0x45678123
++ #define CC_CSMI_SAS_GET_RAID_CONFIG    0x56781234
+-// Control Codes requiring CSMI_SAS_SIGNATURE
++ /* Control Codes requiring CSMI_SAS_SIGNATURE */
+-// #define CC_CSMI_SAS_GET_PHY_INFO       0x67812345
+-// #define CC_CSMI_SAS_SET_PHY_INFO       0x78123456
+-// #define CC_CSMI_SAS_GET_LINK_ERRORS    0x81234567
+-// #define CC_CSMI_SAS_SMP_PASSTHRU       0xA1234567
+-// #define CC_CSMI_SAS_SSP_PASSTHRU       0xB1234567
+-// #define CC_CSMI_SAS_STP_PASSTHRU       0xC1234567
+-// #define CC_CSMI_SAS_GET_SATA_SIGNATURE 0xD1234567
+-// #define CC_CSMI_SAS_GET_SCSI_ADDRESS   0xE1234567
+-// #define CC_CSMI_SAS_GET_DEVICE_ADDRESS 0xF1234567
+-// #define CC_CSMI_SAS_TASK_MANAGEMENT    0xA2345678
+-
+-// Control Codes for 0.77 and later
++ #define CC_CSMI_SAS_GET_PHY_INFO       0x67812345
++ #define CC_CSMI_SAS_SET_PHY_INFO       0x78123456
++ #define CC_CSMI_SAS_GET_LINK_ERRORS    0x81234567
++ #define CC_CSMI_SAS_SMP_PASSTHRU       0xA1234567
++ #define CC_CSMI_SAS_SSP_PASSTHRU       0xB1234567
++ #define CC_CSMI_SAS_STP_PASSTHRU       0xC1234567
++ #define CC_CSMI_SAS_GET_SATA_SIGNATURE 0xD1234567
++ #define CC_CSMI_SAS_GET_SCSI_ADDRESS   0xE1234567
++ #define CC_CSMI_SAS_GET_DEVICE_ADDRESS 0xF1234567
++ #define CC_CSMI_SAS_TASK_MANAGEMENT    0xA2345678
++#endif
++ /* Control Codes for 0.77 and later */
  
-@@ -610,7 +614,7 @@ mpt_lan_send_turbo(struct net_device *de
+-// Control Codes requiring CSMI_ALL_SIGNATURE
++ /* Control Codes requiring CSMI_ALL_SIGNATURE */
  
-       dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, skb %p sent.\n",
-                       IOC_AND_NETDEV_NAMES_s_s(dev),
--                      __func__, sent));
-+                      __FUNCTION__, sent));
+ #define CC_CSMI_SAS_GET_DRIVER_INFO    0xCC770001
+ #define CC_CSMI_SAS_GET_CNTLR_CONFIG   0xCC770002
+ #define CC_CSMI_SAS_GET_CNTLR_STATUS   0xCC770003
+ #define CC_CSMI_SAS_FIRMWARE_DOWNLOAD  0xCC770004
  
-       priv->SendCtl[ctx].skb = NULL;
-       pci_unmap_single(mpt_dev->pcidev, priv->SendCtl[ctx].dma,
-@@ -676,7 +680,7 @@ mpt_lan_send_reply(struct net_device *de
+-// Control Codes requiring CSMI_RAID_SIGNATURE
++/* Control Codes requiring CSMI_RAID_SIGNATURE */
  
-               dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, skb %p sent.\n",
-                               IOC_AND_NETDEV_NAMES_s_s(dev),
--                              __func__, sent));
-+                              __FUNCTION__, sent));
+ #define CC_CSMI_SAS_GET_RAID_INFO      0xCC77000A
+ #define CC_CSMI_SAS_GET_RAID_CONFIG    0xCC77000B
+@@ -166,7 +166,7 @@ Revision History:
+ #define CC_CSMI_SAS_GET_RAID_ELEMENT   0xCC77000E
+ #define CC_CSMI_SAS_SET_RAID_OPERATION 0xCC77000F
  
-               priv->SendCtl[ctx].skb = NULL;
-               pci_unmap_single(mpt_dev->pcidev, priv->SendCtl[ctx].dma,
-@@ -715,7 +719,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, s
-       u16 cur_naa = 0x1000;
+-// Control Codes requiring CSMI_SAS_SIGNATURE
++/* Control Codes requiring CSMI_SAS_SIGNATURE */
  
-       dioprintk((KERN_INFO MYNAM ": %s called, skb_addr = %p\n",
--                      __func__, skb));
-+                      __FUNCTION__, skb));
+ #define CC_CSMI_SAS_GET_PHY_INFO       0xCC770014
+ #define CC_CSMI_SAS_SET_PHY_INFO       0xCC770015
+@@ -182,14 +182,14 @@ Revision History:
+ #define CC_CSMI_SAS_GET_LOCATION       0xCC770025
  
-       spin_lock_irqsave(&priv->txfidx_lock, flags);
-       if (priv->mpt_txfidx_tail < 0) {
-@@ -723,7 +727,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, s
-               spin_unlock_irqrestore(&priv->txfidx_lock, flags);
  
-               printk (KERN_ERR "%s: no tx context available: %u\n",
--                      __func__, priv->mpt_txfidx_tail);
-+                      __FUNCTION__, priv->mpt_txfidx_tail);
-               return 1;
-       }
+-// Control Codes requiring CSMI_PHY_SIGNATURE
++/* Control Codes requiring CSMI_PHY_SIGNATURE */
  
-@@ -733,7 +737,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, s
-               spin_unlock_irqrestore(&priv->txfidx_lock, flags);
+ #define CC_CSMI_SAS_PHY_CONTROL        0xCC77003C
  
-               printk (KERN_ERR "%s: Unable to alloc request frame\n",
--                      __func__);
-+                      __FUNCTION__);
-               return 1;
-       }
+-// EDM #pragma CSMI_SAS_BEGIN_PACK(8)
++/* #pragma CSMI_SAS_BEGIN_PACK(8) */
+ #pragma pack(8)
  
-@@ -828,7 +834,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, s
-                         MPI_SGE_FLAGS_END_OF_LIST) << MPI_SGE_FLAGS_SHIFT) |
-                       skb->len);
-       pSimple->Address.Low = cpu_to_le32((u32) dma);
--      if (sizeof(dma_addr_t) > sizeof(u32))
-+      if (mpt_dev->sg_addr_size > sizeof(u32))
-               pSimple->Address.High = cpu_to_le32((u32) ((u64) dma >> 32));
-       else
-               pSimple->Address.High = 0;
-@@ -1117,7 +1123,6 @@ mpt_lan_receive_post_reply(struct net_de
-                                           PCI_DMA_FROMDEVICE);
+-// IOCTL_HEADER
++/* IOCTL_HEADER */
+ typedef struct _IOCTL_HEADER {
+     __u32 IOControllerNumber;
+     __u32 Length;
+@@ -199,189 +199,18 @@ typedef struct _IOCTL_HEADER {
+ } IOCTL_HEADER,
+   *PIOCTL_HEADER;
+-// EDM #pragma CSMI_SAS_END_PACK
+-#pragma pack()
+-
+-#endif
+-
+-/*************************************************************************/
+-/* TARGET OS WINDOWS SPECIFIC CODE                                       */
+-/*************************************************************************/
+-
+-#ifdef _WIN32
+-
+-// windows IOCTL definitions
+-
+-#ifndef _NTDDSCSIH_
+-#include <ntddscsi.h>
+-#endif
+-
+-// pack definition
+-
+-#if defined _MSC_VER
+-   #define CSMI_SAS_BEGIN_PACK(x)    pack(push,x)
+-   #define CSMI_SAS_END_PACK         pack(pop)
+-#elif defined __BORLANDC__
+-   #define CSMI_SAS_BEGIN_PACK(x)    option -a##x
+-   #define CSMI_SAS_END_PACK         option -a.
+-#else
+-   #error "CSMISAS.H - Must externally define a pack compiler designator."
+-#endif
+-
+-// base types
+-
+-#define __u8    unsigned char
+-#define __u16   unsigned short
+-#define __u32   unsigned long
+-#define __u64   unsigned __int64
+-
+-#define __i8    char
+-
+-// IOCTL Control Codes
+-// (IoctlHeader.ControlCode)
+-
+-// Control Codes requiring CSMI_ALL_SIGNATURE
+-
+-#define CC_CSMI_SAS_GET_DRIVER_INFO    1
+-#define CC_CSMI_SAS_GET_CNTLR_CONFIG   2
+-#define CC_CSMI_SAS_GET_CNTLR_STATUS   3
+-#define CC_CSMI_SAS_FIRMWARE_DOWNLOAD  4
+-
+-// Control Codes requiring CSMI_RAID_SIGNATURE
+-
+-#define CC_CSMI_SAS_GET_RAID_INFO      10
+-#define CC_CSMI_SAS_GET_RAID_CONFIG    11
+-#define CC_CSMI_SAS_GET_RAID_FEATURES  12
+-#define CC_CSMI_SAS_SET_RAID_CONTROL   13
+-#define CC_CSMI_SAS_GET_RAID_ELEMENT   14
+-#define CC_CSMI_SAS_SET_RAID_OPERATION 15
+-
+-// Control Codes requiring CSMI_SAS_SIGNATURE
+-
+-#define CC_CSMI_SAS_GET_PHY_INFO       20
+-#define CC_CSMI_SAS_SET_PHY_INFO       21
+-#define CC_CSMI_SAS_GET_LINK_ERRORS    22
+-#define CC_CSMI_SAS_SMP_PASSTHRU       23
+-#define CC_CSMI_SAS_SSP_PASSTHRU       24
+-#define CC_CSMI_SAS_STP_PASSTHRU       25
+-#define CC_CSMI_SAS_GET_SATA_SIGNATURE 26
+-#define CC_CSMI_SAS_GET_SCSI_ADDRESS   27
+-#define CC_CSMI_SAS_GET_DEVICE_ADDRESS 28
+-#define CC_CSMI_SAS_TASK_MANAGEMENT    29
+-#define CC_CSMI_SAS_GET_CONNECTOR_INFO 30
+-#define CC_CSMI_SAS_GET_LOCATION       31
+-
+-// Control Codes requiring CSMI_PHY_SIGNATURE
+-
+-#define CC_CSMI_SAS_PHY_CONTROL        60
+-
+-#define IOCTL_HEADER SRB_IO_CONTROL
+-#define PIOCTL_HEADER PSRB_IO_CONTROL
+-
+-#endif
+-
+-/*************************************************************************/
+-/* TARGET OS NETWARE SPECIFIC CODE                                       */
+-/*************************************************************************/
+-
+-#ifdef _NETWARE
+-
+-// NetWare IOCTL definitions
+-
+-#define CSMI_SAS_BEGIN_PACK(x)    pack(x)
+-#define CSMI_SAS_END_PACK         pack()
+-
+-#ifndef LONG
+-typedef unsigned long LONG;
+-#endif
+-
+-#ifndef WORD
+-typedef unsigned short WORD;
+-#endif
+-
+-#ifndef BYTE
+-typedef unsigned char BYTE;
+-#endif
+-
+-/* Need to have these definitions for Netware */
+-#define __u8    unsigned char
+-#define __u16   unsigned short
+-#define __u32   unsigned long
+-#define __u64   unsigned __int64
+-
+-#define __i8    char
+-
+-
+-// EDM #pragma CSMI_SAS_BEGIN_PACK(8)
+-#pragma pack(8)
+-
+-// IOCTL_HEADER
+-typedef struct _IOCTL_HEADER {
+-    __u32 Length;
+-    __u32 ReturnCode;
+-} IOCTL_HEADER,
+-  *PIOCTL_HEADER;
+-
+-// EDM #pragma CSMI_SAS_END_PACK
+ #pragma pack()
  
-               skb_copy_from_linear_data(old_skb, skb_put(skb, len), len);
+-// IOCTL Control Codes
+-// (IoctlHeader.ControlCode)
+-
+-// Control Codes requiring CSMI_ALL_SIGNATURE
+-
+-#define CC_CSMI_SAS_GET_DRIVER_INFO    0x01FF0001
+-#define CC_CSMI_SAS_GET_CNTLR_CONFIG   0x01FF0002
+-#define CC_CSMI_SAS_GET_CNTLR_STATUS   0x01FF0003
+-#define CC_CSMI_SAS_FIRMWARE_DOWNLOAD  0x01FF0004
+-
+-// Control Codes requiring CSMI_RAID_SIGNATURE
+-
+-#define CC_CSMI_SAS_GET_RAID_INFO      0x01FF000A
+-#define CC_CSMI_SAS_GET_RAID_CONFIG    0x01FF000B
+-#define CC_CSMI_SAS_GET_RAID_FEATURES  0x01FF000C
+-#define CC_CSMI_SAS_SET_RAID_CONTROL   0x01FF000D
+-#define CC_CSMI_SAS_GET_RAID_ELEMENT   0x01FF000E
+-#define CC_CSMI_SAS_SET_RAID_OPERATION 0x01FF000F
+-
+-// Control Codes requiring CSMI_SAS_SIGNATURE
 -
-               pci_dma_sync_single_for_device(mpt_dev->pcidev,
-                                              priv->RcvCtl[ctx].dma,
-                                              priv->RcvCtl[ctx].len,
-@@ -1208,7 +1213,7 @@ mpt_lan_post_receive_buckets(struct mpt_
+-#define CC_CSMI_SAS_GET_PHY_INFO       0x01FF0014
+-#define CC_CSMI_SAS_SET_PHY_INFO       0x01FF0015
+-#define CC_CSMI_SAS_GET_LINK_ERRORS    0x01FF0016
+-#define CC_CSMI_SAS_SMP_PASSTHRU       0x01FF0017
+-#define CC_CSMI_SAS_SSP_PASSTHRU       0x01FF0018
+-#define CC_CSMI_SAS_STP_PASSTHRU       0x01FF0019
+-#define CC_CSMI_SAS_GET_SATA_SIGNATURE 0x01FF001A
+-#define CC_CSMI_SAS_GET_SCSI_ADDRESS   0x01FF001B
+-#define CC_CSMI_SAS_GET_DEVICE_ADDRESS 0x01FF001C
+-#define CC_CSMI_SAS_TASK_MANAGEMENT    0x01FF001D
+-#define CC_CSMI_SAS_GET_CONNECTOR_INFO 0x01FF001E
+-#define CC_CSMI_SAS_GET_LOCATION       0x01FF001F
+-
+-// Control Codes requiring CSMI_PHY_SIGNATURE
+-
+-#define CC_CSMI_SAS_PHY_CONTROL        60
+-
+ #endif
  
-       dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, Start_buckets = %u, buckets_out = %u\n",
-                       IOC_AND_NETDEV_NAMES_s_s(dev),
--                      __func__, buckets, curr));
-+                      __FUNCTION__, buckets, curr));
+ /*************************************************************************/
+-/* TARGET OS NOT DEFINED ERROR                                           */
+-/*************************************************************************/
+-
+-// EDM
+-//#if (!_WIN32 && !_linux && !_NETWARE)
+-//   #error "Unknown target OS."
+-//#endif
+-
+-/*************************************************************************/
+ /* OS INDEPENDENT CODE                                                   */
+ /*************************************************************************/
+ /* * * * * * * * * * Class Independent IOCTL Constants * * * * * * * * * */
+-// Return codes for all IOCTL's regardless of class
+-// (IoctlHeader.ReturnCode)
++/* Return codes for all IOCTL's regardless of class*/
++/* (IoctlHeader.ReturnCode) */
+ #define CSMI_SAS_STATUS_SUCCESS              0
+ #define CSMI_SAS_STATUS_FAILED               1
+@@ -389,51 +218,51 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_STATUS_INVALID_PARAMETER    3
+ #define CSMI_SAS_STATUS_WRITE_ATTEMPTED      4
+-// Signature value
+-// (IoctlHeader.Signature)
++/* Signature value
++ (IoctlHeader.Signature) */
+ #define CSMI_ALL_SIGNATURE    "CSMIALL"
+-// Timeout value default of 60 seconds
+-// (IoctlHeader.Timeout)
++/* Timeout value default of 60 seconds
++ (IoctlHeader.Timeout) */
+ #define CSMI_ALL_TIMEOUT      60
+-//  Direction values for data flow on this IOCTL
+-// (IoctlHeader.Direction, Linux only)
++/*  Direction values for data flow on this IOCTL
++ (IoctlHeader.Direction, Linux only) */
+ #define CSMI_SAS_DATA_READ    0
+ #define CSMI_SAS_DATA_WRITE   1
+-// I/O Bus Types
+-// ISA and EISA bus types are not supported
+-// (bIoBusType)
++/* I/O Bus Types
++ ISA and EISA bus types are not supported
++ (bIoBusType) */
+ #define CSMI_SAS_BUS_TYPE_PCI       3
+ #define CSMI_SAS_BUS_TYPE_PCMCIA    4
+-// Controller Status
+-// (uStatus)
++/* Controller Status
++ (uStatus) */
+ #define CSMI_SAS_CNTLR_STATUS_GOOD     1
+ #define CSMI_SAS_CNTLR_STATUS_FAILED   2
+ #define CSMI_SAS_CNTLR_STATUS_OFFLINE  3
+ #define CSMI_SAS_CNTLR_STATUS_POWEROFF 4
+-// Offline Status Reason
+-// (uOfflineReason)
++/* Offline Status Reason
++ (uOfflineReason) */
+ #define CSMI_SAS_OFFLINE_REASON_NO_REASON             0
+ #define CSMI_SAS_OFFLINE_REASON_INITIALIZING          1
+ #define CSMI_SAS_OFFLINE_REASON_BACKSIDE_BUS_DEGRADED 2
+ #define CSMI_SAS_OFFLINE_REASON_BACKSIDE_BUS_FAILURE  3
+-// Controller Class
+-// (bControllerClass)
++/* Controller Class
++ (bControllerClass) */
+ #define CSMI_SAS_CNTLR_CLASS_HBA    5
+-// Controller Flag bits
+-// (uControllerFlags)
++/* Controller Flag bits
++ (uControllerFlags) */
+ #define CSMI_SAS_CNTLR_SAS_HBA          0x00000001
+ #define CSMI_SAS_CNTLR_SAS_RAID         0x00000002
+@@ -441,32 +270,29 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_CNTLR_SATA_RAID        0x00000008
+ #define CSMI_SAS_CNTLR_SMART_ARRAY      0x00000010
+-// for firmware download
++/* for firmware download */
+ #define CSMI_SAS_CNTLR_FWD_SUPPORT      0x00010000
+ #define CSMI_SAS_CNTLR_FWD_ONLINE       0x00020000
+ #define CSMI_SAS_CNTLR_FWD_SRESET       0x00040000
+ #define CSMI_SAS_CNTLR_FWD_HRESET       0x00080000
+ #define CSMI_SAS_CNTLR_FWD_RROM         0x00100000
+-// for RAID configuration supported
++/* for RAID configuration supported */
+ #define CSMI_SAS_CNTLR_RAID_CFG_SUPPORT 0x01000000
+-// Download Flag bits
+-// (uDownloadFlags)
++/* Download Flag bits (uDownloadFlags) */
+ #define CSMI_SAS_FWD_VALIDATE       0x00000001
+ #define CSMI_SAS_FWD_SOFT_RESET     0x00000002
+ #define CSMI_SAS_FWD_HARD_RESET     0x00000004
+-// Firmware Download Status
+-// (usStatus)
++/* Firmware Download Status (usStatus) */
+ #define CSMI_SAS_FWD_SUCCESS        0
+ #define CSMI_SAS_FWD_FAILED         1
+ #define CSMI_SAS_FWD_USING_RROM     2
+ #define CSMI_SAS_FWD_REJECT         3
+ #define CSMI_SAS_FWD_DOWNREV        4
+-// Firmware Download Severity
+-// (usSeverity>
++/* Firmware Download Severity (usSeverity) */
+ #define CSMI_SAS_FWD_INFORMATION    0
+ #define CSMI_SAS_FWD_WARNING        1
+ #define CSMI_SAS_FWD_ERROR          2
+@@ -474,25 +300,22 @@ typedef struct _IOCTL_HEADER {
+ /* * * * * * * * * * SAS RAID Class IOCTL Constants  * * * * * * * * */
+-// Return codes for the RAID IOCTL's regardless of class
+-// (IoctlHeader.ReturnCode)
++/* Return codes for the RAID IOCTL's regardless of class */
++/* (IoctlHeader.ReturnCode) */
+ #define CSMI_SAS_RAID_SET_OUT_OF_RANGE       1000
+ #define CSMI_SAS_RAID_SET_BUFFER_TOO_SMALL   1001
+ #define CSMI_SAS_RAID_SET_DATA_CHANGED       1002
+-// Signature value
+-// (IoctlHeader.Signature)
++/* Signature value (IoctlHeader.Signature) */
+ #define CSMI_RAID_SIGNATURE    "CSMIARY"
+-// Timeout value default of 60 seconds
+-// (IoctlHeader.Timeout)
++/* Timeout value default of 60 seconds  (IoctlHeader.Timeout) */
+ #define CSMI_RAID_TIMEOUT      60
+-// RAID Types
+-// (bRaidType)
++/* RAID Types  (bRaidType) */
+ #define CSMI_SAS_RAID_TYPE_NONE     0
+ #define CSMI_SAS_RAID_TYPE_0        1
+ #define CSMI_SAS_RAID_TYPE_1        2
+@@ -504,12 +327,11 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_RAID_TYPE_VOLUME   8
+ #define CSMI_SAS_RAID_TYPE_1E       9
+ #define CSMI_SAS_RAID_TYPE_OTHER    255
+-// the last value 255 was already defined for other
+-// so end is defined as 254
++/* the last value 255 was already defined for other  so end is defined as 254 */
+ #define CSMI_SAS_RAID_TYPE_END      254
+-// RAID Status
+-// (bStatus)
++/* RAID Status  (bStatus) */
++
+ #define CSMI_SAS_RAID_SET_STATUS_OK             0
+ #define CSMI_SAS_RAID_SET_STATUS_DEGRADED       1
+ #define CSMI_SAS_RAID_SET_STATUS_REBUILDING     2
+@@ -519,19 +341,16 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_RAID_SET_STATUS_QUEUED_FOR_REBUILD         6
+ #define CSMI_SAS_RAID_SET_STATUS_QUEUED_FOR_TRANSFORMATION  7
+-// RAID Drive Count
+-// (bDriveCount, 0xF1 to 0xFF are reserved)
++/* RAID Drive Count  (bDriveCount, 0xF1 to 0xFF are reserved) */
+ #define CSMI_SAS_RAID_DRIVE_COUNT_TOO_BIG   0xF1
+ #define CSMI_SAS_RAID_DRIVE_COUNT_SUPRESSED 0xF2
+-// RAID Data Type
+-// (bDataType)
++/* RAID Data Type  (bDataType) */
+ #define CSMI_SAS_RAID_DATA_DRIVES           0
+ #define CSMI_SAS_RAID_DATA_DEVICE_ID        1
+ #define CSMI_SAS_RAID_DATA_ADDITIONAL_DATA  2
+-// RAID Drive Status
+-// (bDriveStatus)
++/* RAID Drive Status  (bDriveStatus) */
+ #define CSMI_SAS_DRIVE_STATUS_OK          0
+ #define CSMI_SAS_DRIVE_STATUS_REBUILDING  1
+ #define CSMI_SAS_DRIVE_STATUS_FAILED      2
+@@ -539,15 +358,13 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_DRIVE_STATUS_OFFLINE     4
+ #define CSMI_SAS_DRIVE_STATUS_QUEUED_FOR_REBUILD 5
+-// RAID Drive Usage
+-// (bDriveUsage)
++/* RAID Drive Usage  (bDriveUsage) */
+ #define CSMI_SAS_DRIVE_CONFIG_NOT_USED      0
+ #define CSMI_SAS_DRIVE_CONFIG_MEMBER        1
+ #define CSMI_SAS_DRIVE_CONFIG_SPARE         2
+ #define CSMI_SAS_DRIVE_CONFIG_SPARE_ACTIVE  3
+-// RAID Drive Type
+-// (bDriveType)
++/* RAID Drive Type  (bDriveType) */
+ #define CSMI_SAS_DRIVE_TYPE_UNKNOWN         0
+ #define CSMI_SAS_DRIVE_TYPE_SINGLE_PORT_SAS 1
+ #define CSMI_SAS_DRIVE_TYPE_DUAL_PORT_SAS   2
+@@ -555,23 +372,20 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_DRIVE_TYPE_SATA_PS         4
+ #define CSMI_SAS_DRIVE_TYPE_OTHER           255
+-// RAID Write Protect
+-// (bWriteProtect)
++/* RAID Write Protect  (bWriteProtect) */
+ #define CSMI_SAS_RAID_SET_WRITE_PROTECT_UNKNOWN     0
+ #define CSMI_SAS_RAID_SET_WRITE_PROTECT_UNCHANGED   0
+ #define CSMI_SAS_RAID_SET_WRITE_PROTECT_ENABLED     1
+ #define CSMI_SAS_RAID_SET_WRITE_PROTECT_DISABLED    2
+-// RAID Cache Setting
+-// (bCacheSetting)
++/* RAID Cache Setting (bCacheSetting) */
+ #define CSMI_SAS_RAID_SET_CACHE_UNKNOWN             0
+ #define CSMI_SAS_RAID_SET_CACHE_UNCHANGED           0
+ #define CSMI_SAS_RAID_SET_CACHE_ENABLED             1
+ #define CSMI_SAS_RAID_SET_CACHE_DISABLED            2
+ #define CSMI_SAS_RAID_SET_CACHE_CORRUPT             3
+-// RAID Features
+-// (uFeatures)
++/* RAID Features  (uFeatures) */
+ #define CSMI_SAS_RAID_FEATURE_TRANSFORMATION    0x00000001
+ #define CSMI_SAS_RAID_FEATURE_REBUILD           0x00000002
+ #define CSMI_SAS_RAID_FEATURE_SPLIT_MIRROR      0x00000004
+@@ -580,8 +394,7 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_RAID_FEATURE_SURFACE_SCAN      0x00000020
+ #define CSMI_SAS_RAID_FEATURE_SPARES_SHARED     0x00000040
+-// RAID Priority
+-// (bDefaultTransformPriority, etc.)
++/* RAID Priority  (bDefaultTransformPriority, etc.) */
+ #define CSMI_SAS_PRIORITY_UNKNOWN   0
+ #define CSMI_SAS_PRIORITY_UNCHANGED 0
+ #define CSMI_SAS_PRIORITY_AUTO      1
+@@ -590,30 +403,25 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_PRIORITY_MEDIUM    4
+ #define CSMI_SAS_PRIORITY_HIGH      5
+-// RAID Transformation Rules
+-// (uRaidSetTransformationRules)
++/* RAID Transformation Rules  (uRaidSetTransformationRules) */
+ #define CSMI_SAS_RAID_RULE_AVAILABLE_MEMORY     0x00000001
+ #define CSMI_SAS_RAID_RULE_OVERLAPPED_EXTENTS   0x00000002
+-// RAID Cache Ratios Supported
+-// (bCacheRatiosSupported)
+-// from 0 to 100 defines the write to read ratio, 0 is 100% write
++/* RAID Cache Ratios Supported  (bCacheRatiosSupported) */
++/*  from 0 to 100 defines the write to read ratio, 0 is 100% write */
+ #define CSMI_SAS_RAID_CACHE_RATIO_RANGE     101
+ #define CSMI_SAS_RAID_CACHE_RATIO_FIXED     102
+ #define CSMI_SAS_RAID_CACHE_RATIO_AUTO      103
+ #define CSMI_SAS_RAID_CACHE_RATIO_END       255
+-// RAID Cache Ratio Flag
+-// (bCacheRatioFlag)
++/* RAID Cache Ratio Flag  (bCacheRatioFlag) */
+ #define CSMI_SAS_RAID_CACHE_RATIO_DISABLE   0
+ #define CSMI_SAS_RAID_CACHE_RATIO_ENABLE    1
+-// RAID Clear Configuration Signature
+-// (bClearConfiguration)
++/* RAID Clear Configuration Signature  (bClearConfiguration) */
+ #define CSMI_SAS_RAID_CLEAR_CONFIGURATION_SIGNATURE "RAIDCLR"
+-// RAID Failure Codes
+-// (uFailureCode)
++/* RAID Failure Codes  (uFailureCode) */
+ #define CSMI_SAS_FAIL_CODE_OK                           0
+ #define CSMI_SAS_FAIL_CODE_PARAMETER_INVALID            1000
+ #define CSMI_SAS_FAIL_CODE_TRANSFORM_PRIORITY_INVALID   1001
+@@ -638,22 +446,19 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_FAIL_CODE_WAIT_FOR_OPERATION           3000
+-// RAID Enumeration Types
+-// (uEnumerationType)
++/* RAID Enumeration Types  (uEnumerationType) */
+ #define CSMI_SAS_RAID_ELEMENT_TYPE_DRIVE                0
+ #define CSMI_SAS_RAID_ELEMENT_TYPE_MODULE               1
+ #define CSMI_SAS_RAID_ELEMENT_TYPE_DRIVE_RAID_SET       2
+ #define CSMI_SAS_RAID_ELEMENT_TYPE_EXTENT_DRIVE         3
+-// RAID Extent Types
+-// (bExtentType)
++/* RAID Extent Types  (bExtentType) */
+ #define CSMI_SAS_RAID_EXTENT_RESERVED       0
+ #define CSMI_SAS_RAID_EXTENT_METADATA       1
+ #define CSMI_SAS_RAID_EXTENT_ALLOCATED      2
+ #define CSMI_SAS_RAID_EXTENT_UNALLOCATED    3
+-// RAID Operation Types
+-// (uOperationType)
++/* RAID Operation Types  (uOperationType) */
+ #define CSMI_SAS_RAID_SET_CREATE            0
+ #define CSMI_SAS_RAID_SET_LABEL             1
+ #define CSMI_SAS_RAID_SET_TRANSFORM         2
+@@ -663,23 +468,20 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_RAID_SET_ONLINE_STATE      6
+ #define CSMI_SAS_RAID_SET_SPARE             7
+-// RAID Transform Types
+-// (bTransformType)
++/* RAID Transform Types  (bTransformType) */
+ #define CSMI_SAS_RAID_SET_TRANSFORM_SPLIT_MIRROR    0
+ #define CSMI_SAS_RAID_SET_TRANSFORM_MERGE_RAID_0    1
+ #define CSMI_SAS_RAID_SET_TRANSFORM_LUN_RENUMBER    2
+ #define CSMI_SAS_RAID_SET_TRANSFORM_RAID_SET        3
+-// RAID Online State
+-// (bOnlineState)
++/* RAID Online State  (bOnlineState) */
+ #define CSMI_SAS_RAID_SET_STATE_UNKNOWN     0
+ #define CSMI_SAS_RAID_SET_STATE_ONLINE      1
+ #define CSMI_SAS_RAID_SET_STATE_OFFLINE     2
+ /* * * * * * * * * * SAS HBA Class IOCTL Constants * * * * * * * * * */
+-// Return codes for SAS IOCTL's
+-// (IoctlHeader.ReturnCode)
++/* Return codes for SAS IOCTL's (IoctlHeader.ReturnCode) */
+ #define CSMI_SAS_PHY_INFO_CHANGED            CSMI_SAS_STATUS_SUCCESS
+ #define CSMI_SAS_PHY_INFO_NOT_CHANGEABLE     2000
+@@ -700,18 +502,15 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_NO_SCSI_ADDRESS             2013
+ #define CSMI_SAS_NO_DEVICE_ADDRESS           2014
+-// Signature value
+-// (IoctlHeader.Signature)
++/* Signature value  (IoctlHeader.Signature) */
+ #define CSMI_SAS_SIGNATURE    "CSMISAS"
+-// Timeout value default of 60 seconds
+-// (IoctlHeader.Timeout)
++/* Timeout value default of 60 seconds (IoctlHeader.Timeout) */
+ #define CSMI_SAS_TIMEOUT      60
+-// Device types
+-// (bDeviceType)
++/* Device types (bDeviceType) */
+ #define CSMI_SAS_PHY_UNUSED               0x00
+ #define CSMI_SAS_NO_DEVICE_ATTACHED       0x00
+@@ -719,16 +518,15 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_EDGE_EXPANDER_DEVICE     0x20
+ #define CSMI_SAS_FANOUT_EXPANDER_DEVICE   0x30
+-// Protocol options
+-// (bInitiatorPortProtocol, bTargetPortProtocol)
++/* Protocol options  (bInitiatorPortProtocol, bTargetPortProtocol) */
+ #define CSMI_SAS_PROTOCOL_SATA   0x01
+ #define CSMI_SAS_PROTOCOL_SMP    0x02
+ #define CSMI_SAS_PROTOCOL_STP    0x04
+ #define CSMI_SAS_PROTOCOL_SSP    0x08
+-// Negotiated and hardware link rates
+-// (bNegotiatedLinkRate, bMinimumLinkRate, bMaximumLinkRate)
++/* Negotiated and hardware link rates */
++/* (bNegotiatedLinkRate, bMinimumLinkRate, bMaximumLinkRate) */
+ #define CSMI_SAS_LINK_RATE_UNKNOWN  0x00
+ #define CSMI_SAS_PHY_DISABLED       0x01
+@@ -739,8 +537,7 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_LINK_RATE_3_0_GBPS 0x09
+ #define CSMI_SAS_LINK_VIRTUAL       0x10
+-// Discover state
+-// (bAutoDiscover)
++/* Discover state  (bAutoDiscover) */
+ #define CSMI_SAS_DISCOVER_NOT_SUPPORTED   0x00
+ #define CSMI_SAS_DISCOVER_NOT_STARTED     0x01
+@@ -748,57 +545,49 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_DISCOVER_COMPLETE        0x03
+ #define CSMI_SAS_DISCOVER_ERROR           0x04
+-// Phy features
++/*  Phy features */
+ #define CSMI_SAS_PHY_VIRTUAL_SMP          0x01
+-// Programmed link rates
+-// (bMinimumLinkRate, bMaximumLinkRate)
+-// (bProgrammedMinimumLinkRate, bProgrammedMaximumLinkRate)
++/* Programmed link rates  (bMinimumLinkRate, bMaximumLinkRate) */
++/* (bProgrammedMinimumLinkRate, bProgrammedMaximumLinkRate) */
+ #define CSMI_SAS_PROGRAMMED_LINK_RATE_UNCHANGED 0x00
+ #define CSMI_SAS_PROGRAMMED_LINK_RATE_1_5_GBPS  0x08
+ #define CSMI_SAS_PROGRAMMED_LINK_RATE_3_0_GBPS  0x09
+-// Link rate
+-// (bNegotiatedLinkRate in CSMI_SAS_SET_PHY_INFO)
++/* Link rate  (bNegotiatedLinkRate in CSMI_SAS_SET_PHY_INFO) */
+ #define CSMI_SAS_LINK_RATE_NEGOTIATE      0x00
+ #define CSMI_SAS_LINK_RATE_PHY_DISABLED   0x01
+-// Signal class
+-// (bSignalClass in CSMI_SAS_SET_PHY_INFO)
++/* Signal class  (bSignalClass in CSMI_SAS_SET_PHY_INFO) */
+ #define CSMI_SAS_SIGNAL_CLASS_UNKNOWN     0x00
+ #define CSMI_SAS_SIGNAL_CLASS_DIRECT      0x01
+ #define CSMI_SAS_SIGNAL_CLASS_SERVER      0x02
+ #define CSMI_SAS_SIGNAL_CLASS_ENCLOSURE   0x03
+-// Link error reset
+-// (bResetCounts)
++/* Link error reset  (bResetCounts) */
+ #define CSMI_SAS_LINK_ERROR_DONT_RESET_COUNTS   0x00
+ #define CSMI_SAS_LINK_ERROR_RESET_COUNTS        0x01
+-// Phy identifier
+-// (bPhyIdentifier)
++/* Phy identifier  (bPhyIdentifier) */
+ #define CSMI_SAS_USE_PORT_IDENTIFIER   0xFF
+-// Port identifier
+-// (bPortIdentifier)
++/* Port identifier  (bPortIdentifier) */
+ #define CSMI_SAS_IGNORE_PORT           0xFF
+-// Programmed link rates
+-// (bConnectionRate)
++/* Programmed link rates  (bConnectionRate) */
+ #define CSMI_SAS_LINK_RATE_NEGOTIATED  0x00
+ #define CSMI_SAS_LINK_RATE_1_5_GBPS    0x08
+ #define CSMI_SAS_LINK_RATE_3_0_GBPS    0x09
+-// Connection status
+-// (bConnectionStatus)
++/* Connection status  (bConnectionStatus) */
+ #define CSMI_SAS_OPEN_ACCEPT                          0
+ #define CSMI_SAS_OPEN_REJECT_BAD_DESTINATION          1
+@@ -814,8 +603,7 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_OPEN_REJECT_STP_RESOURCES_BUSY       11
+ #define CSMI_SAS_OPEN_REJECT_WRONG_DESTINATION        12
+-// SSP Status
+-// (bSSPStatus)
++/* SSP Status  (bSSPStatus)*/
+ #define CSMI_SAS_SSP_STATUS_UNKNOWN     0x00
+ #define CSMI_SAS_SSP_STATUS_WAITING     0x01
+@@ -824,8 +612,7 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_SSP_STATUS_RETRY       0x04
+ #define CSMI_SAS_SSP_STATUS_NO_TAG      0x05
+-// SSP Flags
+-// (uFlags)
++/* SSP Flags  (uFlags) */
+ #define CSMI_SAS_SSP_READ           0x00000001
+ #define CSMI_SAS_SSP_WRITE          0x00000002
+@@ -836,15 +623,13 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_SSP_TASK_ATTRIBUTE_ORDERED        0x00000020
+ #define CSMI_SAS_SSP_TASK_ATTRIBUTE_ACA            0x00000040
+-// SSP Data present
+-// (bDataPresent)
++/* SSP Data present  (bDataPresent) */
+ #define CSMI_SAS_SSP_NO_DATA_PRESENT         0x00
+ #define CSMI_SAS_SSP_RESPONSE_DATA_PRESENT   0x01
+ #define CSMI_SAS_SSP_SENSE_DATA_PRESENT      0x02
+-// STP Flags
+-// (uFlags)
++/* STP Flags  (uFlags) */
+ #define CSMI_SAS_STP_READ           0x00000001
+ #define CSMI_SAS_STP_WRITE          0x00000002
+@@ -856,15 +641,13 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_STP_EXECUTE_DIAG   0x00000100
+ #define CSMI_SAS_STP_RESET_DEVICE   0x00000200
+-// Task Management Flags
+-// (uFlags)
++/* Task Management Flags  (uFlags) */
+ #define CSMI_SAS_TASK_IU               0x00000001
+ #define CSMI_SAS_HARD_RESET_SEQUENCE   0x00000002
+ #define CSMI_SAS_SUPPRESS_RESULT       0x00000004
+-// Task Management Functions
+-// (bTaskManagement)
++/* Task Management Functions  (bTaskManagement) */
+ #define CSMI_SAS_SSP_ABORT_TASK           0x01
+ #define CSMI_SAS_SSP_ABORT_TASK_SET       0x02
+@@ -873,16 +656,14 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_SSP_CLEAR_ACA            0x40
+ #define CSMI_SAS_SSP_QUERY_TASK           0x80
+-// Task Management Information
+-// (uInformation)
++/* Task Management Information  (uInformation) */
+ #define CSMI_SAS_SSP_TEST           1
+ #define CSMI_SAS_SSP_EXCEEDED       2
+ #define CSMI_SAS_SSP_DEMAND         3
+ #define CSMI_SAS_SSP_TRIGGER        4
+-// Connector Pinout Information
+-// (uPinout)
++/* Connector Pinout Information  (uPinout) */
+ #define CSMI_SAS_CON_UNKNOWN              0x00000001
+ #define CSMI_SAS_CON_SFF_8482             0x00000002
+@@ -895,10 +676,9 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_CON_SFF_8484_LANE_3      0x00040000
+ #define CSMI_SAS_CON_SFF_8484_LANE_4      0x00080000
+-// Connector Location Information
+-// (bLocation)
++/* Connector Location Information  (bLocation) */
+-// same as uPinout above...
++/* same as uPinout above... */
+ // #define CSMI_SAS_CON_UNKNOWN              0x01
+ #define CSMI_SAS_CON_INTERNAL             0x02
+ #define CSMI_SAS_CON_EXTERNAL             0x04
+@@ -907,15 +687,13 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_CON_NOT_PRESENT          0x20
+ #define CSMI_SAS_CON_NOT_CONNECTED        0x80
+-// Device location identification
+-// (bIdentify)
++/* Device location identification  (bIdentify) */
+ #define CSMI_SAS_LOCATE_UNKNOWN           0x00
+ #define CSMI_SAS_LOCATE_FORCE_OFF         0x01
+ #define CSMI_SAS_LOCATE_FORCE_ON          0x02
+-// Location Valid flags
+-// (uLocationFlags)
++/* Location Valid flags  (uLocationFlags) */
+ #define CSMI_SAS_LOCATE_SAS_ADDRESS_VALID           0x00000001
+ #define CSMI_SAS_LOCATE_SAS_LUN_VALID               0x00000002
+@@ -927,48 +705,41 @@ typedef struct _IOCTL_HEADER {
+ /* * * * * * * * SAS Phy Control Class IOCTL Constants * * * * * * * * */
+-// Return codes for SAS Phy Control IOCTL's
+-// (IoctlHeader.ReturnCode)
++/* Return codes for SAS Phy Control IOCTL's  (IoctlHeader.ReturnCode) */
+-// Signature value
+-// (IoctlHeader.Signature)
++/* Signature value  (IoctlHeader.Signature) */
+ #define CSMI_PHY_SIGNATURE    "CSMIPHY"
+-// Phy Control Functions
+-// (bFunction)
++/* Phy Control Functions  (bFunction) */
+-// values 0x00 to 0xFF are consistent in definition with the SMP PHY CONTROL
+-// function defined in the SAS spec
++/* values 0x00 to 0xFF are consistent in definition with the SMP PHY CONTROL
++  function defined in the SAS spec */
+ #define CSMI_SAS_PC_NOP                   0x00000000
+ #define CSMI_SAS_PC_LINK_RESET            0x00000001
+ #define CSMI_SAS_PC_HARD_RESET            0x00000002
+ #define CSMI_SAS_PC_PHY_DISABLE           0x00000003
+-// 0x04 to 0xFF reserved...
++/* 0x04 to 0xFF reserved... */
+ #define CSMI_SAS_PC_GET_PHY_SETTINGS      0x00000100
+-// Link Flags
++/* Link Flags */
+ #define CSMI_SAS_PHY_ACTIVATE_CONTROL     0x00000001
+ #define CSMI_SAS_PHY_UPDATE_SPINUP_RATE   0x00000002
+ #define CSMI_SAS_PHY_AUTO_COMWAKE         0x00000004
+-// Device Types for Phy Settings
+-// (bType)
++/* Device Types for Phy Settings  (bType) */
+ #define CSMI_SAS_UNDEFINED 0x00
+ #define CSMI_SAS_SATA      0x01
+ #define CSMI_SAS_SAS       0x02
+-// Transmitter Flags
+-// (uTransmitterFlags)
++/* Transmitter Flags  (uTransmitterFlags) */
+ #define CSMI_SAS_PHY_PREEMPHASIS_DISABLED    0x00000001
+-// Receiver Flags
+-// (uReceiverFlags)
++/* Receiver Flags  (uReceiverFlags) */
+ #define CSMI_SAS_PHY_EQUALIZATION_DISABLED   0x00000001
+-// Pattern Flags
+-// (uPatternFlags)
+-// #define CSMI_SAS_PHY_ACTIVATE_CONTROL     0x00000001
++/* Pattern Flags  (uPatternFlags) */
++#define CSMI_SAS_PHY_ACTIVATE_CONTROL        0x00000001
+ #define CSMI_SAS_PHY_DISABLE_SCRAMBLING      0x00000002
+ #define CSMI_SAS_PHY_DISABLE_ALIGN           0x00000004
+ #define CSMI_SAS_PHY_DISABLE_SSC             0x00000008
+@@ -976,18 +747,16 @@ typedef struct _IOCTL_HEADER {
+ #define CSMI_SAS_PHY_FIXED_PATTERN           0x00000010
+ #define CSMI_SAS_PHY_USER_PATTERN            0x00000020
+-// Fixed Patterns
+-// (bFixedPattern)
++/* Fixed Patterns  (bFixedPattern) */
+ #define CSMI_SAS_PHY_CJPAT                   0x00000001
+ #define CSMI_SAS_PHY_ALIGN                   0x00000002
+-// Type Flags
+-// (bTypeFlags)
++/* Type Flags  (bTypeFlags) */
+ #define CSMI_SAS_PHY_POSITIVE_DISPARITY      0x01
+ #define CSMI_SAS_PHY_NEGATIVE_DISPARITY      0x02
+ #define CSMI_SAS_PHY_CONTROL_CHARACTER       0x04
+-// Miscellaneous
++/* Miscellaneous */
+ #define SLOT_NUMBER_UNKNOWN   0xFFFF
+ /*************************************************************************/
+@@ -996,10 +765,9 @@ typedef struct _IOCTL_HEADER {
+ /* * * * * * * * * * Class Independent Structures * * * * * * * * * */
+-// EDM #pragma CSMI_SAS_BEGIN_PACK(8)
+ #pragma pack(8)
+-// CC_CSMI_SAS_DRIVER_INFO
++/* CC_CSMI_SAS_DRIVER_INFO */
+ typedef struct _CSMI_SAS_DRIVER_INFO {
+    __u8  szName[81];
+@@ -1019,7 +787,7 @@ typedef struct _CSMI_SAS_DRIVER_INFO_BUF
+ } CSMI_SAS_DRIVER_INFO_BUFFER,
+   *PCSMI_SAS_DRIVER_INFO_BUFFER;
+-// CC_CSMI_SAS_CNTLR_CONFIGURATION
++/* CC_CSMI_SAS_CNTLR_CONFIGURATION */
+ typedef struct _CSMI_SAS_PCI_BUS_ADDRESS {
+    __u8  bBusNumber;
+@@ -1074,7 +842,7 @@ typedef struct _CSMI_SAS_CNTLR_CONFIG_BU
+ } CSMI_SAS_CNTLR_CONFIG_BUFFER,
+   *PCSMI_SAS_CNTLR_CONFIG_BUFFER;
+-// CC_CSMI_SAS_CNTLR_STATUS
++/* CC_CSMI_SAS_CNTLR_STATUS */
+ typedef struct _CSMI_SAS_CNTLR_STATUS {
+    __u32 uStatus;
+@@ -1089,7 +857,7 @@ typedef struct _CSMI_SAS_CNTLR_STATUS_BU
+ } CSMI_SAS_CNTLR_STATUS_BUFFER,
+   *PCSMI_SAS_CNTLR_STATUS_BUFFER;
+-// CC_CSMI_SAS_FIRMWARE_DOWNLOAD
++/* CC_CSMI_SAS_FIRMWARE_DOWNLOAD  */
+ typedef struct _CSMI_SAS_FIRMWARE_DOWNLOAD {
+    __u32 uBufferLength;
+@@ -1107,7 +875,7 @@ typedef struct _CSMI_SAS_FIRMWARE_DOWNLO
+ } CSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER,
+   *PCSMI_SAS_FIRMWARE_DOWNLOAD_BUFFER;
+-// CC_CSMI_SAS_RAID_INFO
++/* CC_CSMI_SAS_RAID_INFO */
+ typedef struct _CSMI_SAS_RAID_INFO {
+    __u32 uNumRaidSets;
+@@ -1140,7 +908,7 @@ typedef struct _CSMI_SAS_RAID_INFO_BUFFE
+ } CSMI_SAS_RAID_INFO_BUFFER,
+   *PCSMI_SAS_RAID_INFO_BUFFER;
+-// CC_CSMI_SAS_GET_RAID_CONFIG
++/* CC_CSMI_SAS_GET_RAID_CONFIG */
+ typedef struct _CSMI_SAS_RAID_DRIVES {
+    __u8  bModel[40];
+@@ -1220,7 +988,7 @@ typedef struct _CSMI_SAS_RAID_CONFIG_BUF
+ } CSMI_SAS_RAID_CONFIG_BUFFER,
+   *PCSMI_SAS_RAID_CONFIG_BUFFER;
+-// CC_CSMI_SAS_GET_RAID_FEATURES
++/* CC_CSMI_SAS_GET_RAID_FEATURES */
+ typedef struct _CSMI_SAS_RAID_TYPE_DESCRIPTION {
+   __u8  bRaidType;
+@@ -1256,7 +1024,7 @@ typedef struct _CSMI_SAS_RAID_FEATURES_B
+ } CSMI_SAS_RAID_FEATURES_BUFFER,
+   *PCSMI_SAS_RAID_FEATURES_BUFFER;
+-// CC_CSMI_SAS_SET_RAID_CONTROL
++/* CC_CSMI_SAS_SET_RAID_CONTROL */
+ typedef struct _CSMI_SAS_RAID_CONTROL {
+    __u8  bTransformPriority;
+@@ -1279,7 +1047,7 @@ typedef struct _CSMI_SAS_RAID_CONTROL_BU
+ } CSMI_SAS_RAID_CONTROL_BUFFER,
+   *PCSMI_SAS_RAID_CONTROL_BUFFER;
+-// CC_CSMI_SAS_GET_RAID_ELEMENT
++/* CC_CSMI_SAS_GET_RAID_ELEMENT */
+ typedef struct _CSMI_SAS_DRIVE_EXTENT_INFO {
+    __u32 uDriveIndex;
+@@ -1353,7 +1121,7 @@ typedef struct _CSMI_SAS_RAID_ELEMENT_BU
+ } CSMI_SAS_RAID_ELEMENT_BUFFER,
+   *PCSMI_SAS_RAID_ELEMENT_BUFFER;
+-// CC_CSMI_SAS_SET_RAID_OPERATION
++/* CC_CSMI_SAS_SET_RAID_OPERATION */
+ typedef struct _CSMI_SAS_RAID_SET_LIST {
+    __u32 uRaidSetIndex;
+@@ -1503,7 +1271,7 @@ typedef struct _CSMI_SAS_RAID_SET_OPERAT
+ /* * * * * * * * * * SAS HBA Class Structures * * * * * * * * * */
+-// CC_CSMI_SAS_GET_PHY_INFO
++/* CC_CSMI_SAS_GET_PHY_INFO */
+ typedef struct _CSMI_SAS_IDENTIFY {
+    __u8  bDeviceType;
+@@ -1545,7 +1313,7 @@ typedef struct _CSMI_SAS_PHY_INFO_BUFFER
+ } CSMI_SAS_PHY_INFO_BUFFER,
+   *PCSMI_SAS_PHY_INFO_BUFFER;
+-// CC_CSMI_SAS_SET_PHY_INFO
++/* CC_CSMI_SAS_SET_PHY_INFO */
+ typedef struct _CSMI_SAS_SET_PHY_INFO {
+    __u8  bPhyIdentifier;
+@@ -1563,7 +1331,7 @@ typedef struct _CSMI_SAS_SET_PHY_INFO_BU
+ } CSMI_SAS_SET_PHY_INFO_BUFFER,
+   *PCSMI_SAS_SET_PHY_INFO_BUFFER;
+-// CC_CSMI_SAS_GET_LINK_ERRORS
++/* CC_CSMI_SAS_GET_LINK_ERRORS */
+ typedef struct _CSMI_SAS_LINK_ERRORS {
+    __u8  bPhyIdentifier;
+@@ -1582,7 +1350,7 @@ typedef struct _CSMI_SAS_LINK_ERRORS_BUF
+ } CSMI_SAS_LINK_ERRORS_BUFFER,
+   *PCSMI_SAS_LINK_ERRORS_BUFFER;
+-// CC_CSMI_SAS_SMP_PASSTHRU
++/* CC_CSMI_SAS_SMP_PASSTHRU */
+ typedef struct _CSMI_SAS_SMP_REQUEST {
+    __u8  bFrameType;
+@@ -1622,7 +1390,7 @@ typedef struct _CSMI_SAS_SMP_PASSTHRU_BU
+ } CSMI_SAS_SMP_PASSTHRU_BUFFER,
+   *PCSMI_SAS_SMP_PASSTHRU_BUFFER;
+-// CC_CSMI_SAS_SSP_PASSTHRU
++/* CC_CSMI_SAS_SSP_PASSTHRU */
+ typedef struct _CSMI_SAS_SSP_PASSTHRU {
+    __u8  bPhyIdentifier;
+@@ -1661,7 +1429,7 @@ typedef struct _CSMI_SAS_SSP_PASSTHRU_BU
+ } CSMI_SAS_SSP_PASSTHRU_BUFFER,
+   *PCSMI_SAS_SSP_PASSTHRU_BUFFER;
+-// CC_CSMI_SAS_STP_PASSTHRU
++/* CC_CSMI_SAS_STP_PASSTHRU */
+ typedef struct _CSMI_SAS_STP_PASSTHRU {
+    __u8  bPhyIdentifier;
+@@ -1693,7 +1461,7 @@ typedef struct _CSMI_SAS_STP_PASSTHRU_BU
+ } CSMI_SAS_STP_PASSTHRU_BUFFER,
+   *PCSMI_SAS_STP_PASSTHRU_BUFFER;
+-// CC_CSMI_SAS_GET_SATA_SIGNATURE
++/* CC_CSMI_SAS_GET_SATA_SIGNATURE */
+ typedef struct _CSMI_SAS_SATA_SIGNATURE {
+    __u8  bPhyIdentifier;
+@@ -1708,7 +1476,7 @@ typedef struct _CSMI_SAS_SATA_SIGNATURE_
+ } CSMI_SAS_SATA_SIGNATURE_BUFFER,
+   *PCSMI_SAS_SATA_SIGNATURE_BUFFER;
+-// CC_CSMI_SAS_GET_SCSI_ADDRESS
++/* CC_CSMI_SAS_GET_SCSI_ADDRESS */
+ typedef struct _CSMI_SAS_GET_SCSI_ADDRESS_BUFFER {
+    IOCTL_HEADER IoctlHeader;
+@@ -1721,7 +1489,7 @@ typedef struct _CSMI_SAS_GET_SCSI_ADDRES
+ } CSMI_SAS_GET_SCSI_ADDRESS_BUFFER,
+    *PCSMI_SAS_GET_SCSI_ADDRESS_BUFFER;
+-// CC_CSMI_SAS_GET_DEVICE_ADDRESS
++/* CC_CSMI_SAS_GET_DEVICE_ADDRESS */
+ typedef struct _CSMI_SAS_GET_DEVICE_ADDRESS_BUFFER {
+    IOCTL_HEADER IoctlHeader;
+@@ -1734,7 +1502,7 @@ typedef struct _CSMI_SAS_GET_DEVICE_ADDR
+ } CSMI_SAS_GET_DEVICE_ADDRESS_BUFFER,
+   *PCSMI_SAS_GET_DEVICE_ADDRESS_BUFFER;
+-// CC_CSMI_SAS_TASK_MANAGEMENT
++/* CC_CSMI_SAS_TASK_MANAGEMENT */
+ typedef struct _CSMI_SAS_SSP_TASK_IU {
+    __u8  bHostIndex;
+@@ -1757,7 +1525,7 @@ typedef struct _CSMI_SAS_SSP_TASK_IU_BUF
+ } CSMI_SAS_SSP_TASK_IU_BUFFER,
+   *PCSMI_SAS_SSP_TASK_IU_BUFFER;
+-// CC_CSMI_SAS_GET_CONNECTOR_INFO
++/* CC_CSMI_SAS_GET_CONNECTOR_INFO */
+ typedef struct _CSMI_SAS_GET_CONNECTOR_INFO {
+    __u32 uPinout;
+@@ -1773,7 +1541,7 @@ typedef struct _CSMI_SAS_CONNECTOR_INFO_
+ } CSMI_SAS_CONNECTOR_INFO_BUFFER,
+   *PCSMI_SAS_CONNECTOR_INFO_BUFFER;
+-// CC_CSMI_SAS_GET_LOCATION
++/* CC_CSMI_SAS_GET_LOCATION */
+ typedef struct _CSMI_SAS_LOCATION_IDENTIFIER {
+    __u32 bLocationFlags;
+@@ -1801,7 +1569,7 @@ typedef struct _CSMI_SAS_GET_LOCATION_BU
+ } CSMI_SAS_GET_LOCATION_BUFFER,
+   *PCSMI_SAS_GET_LOCATION_BUFFER;
+-// CC_CSMI_SAS_PHY_CONTROL
++/* CC_CSMI_SAS_PHY_CONTROL */
+ typedef struct _CSMI_SAS_CHARACTER {
+    __u8  bTypeFlags;
+@@ -1848,7 +1616,6 @@ typedef struct _CSMI_SAS_PHY_CONTROL_BUF
+ } CSMI_SAS_PHY_CONTROL_BUFFER,
+   *PCSMI_SAS_PHY_CONTROL_BUFFER;
+-//EDM #pragma CSMI_SAS_END_PACK
+ #pragma pack()
+ #endif // _CSMI_SAS_H_
+Index: linux-2.6.27/drivers/message/fusion/lsi/mpi_cnfg.h
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/lsi/mpi_cnfg.h
++++ linux-2.6.27/drivers/message/fusion/lsi/mpi_cnfg.h
+@@ -1452,8 +1452,7 @@ typedef struct _CONFIG_PAGE_BIOS_2
+ #define MPI_BIOSPAGE2_FORM_SAS_WWN                      (0x05)
+ #define MPI_BIOSPAGE2_FORM_ENCLOSURE_SLOT               (0x06)
+-typedef struct _CONFIG_PAGE_BIOS_4
+-{
++typedef struct _CONFIG_PAGE_BIOS_4 {
+     CONFIG_PAGE_HEADER      Header;                     /* 00h */
+     U64                     ReassignmentBaseWWID;       /* 04h */
+ } CONFIG_PAGE_BIOS_4, MPI_POINTER PTR_CONFIG_PAGE_BIOS_4,
+Index: linux-2.6.27/drivers/message/fusion/lsi/mpi_log_sas.h
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/lsi/mpi_log_sas.h
++++ linux-2.6.27/drivers/message/fusion/lsi/mpi_log_sas.h
+@@ -160,11 +160,12 @@
+ #define PL_LOGINFO_SUB_CODE_INVALID_SGL                      (0x00000200)
++
+ #define PL_LOGINFO_SUB_CODE_WRONG_REL_OFF_OR_FRAME_LENGTH    (0x00000300)
+-#define PL_LOGINFO_SUB_CODE_FRAME_XFER_ERROR                 (0x00000400) /* Bits 0-3 encode Transport Status Register (offset 0x08) */
+-                                                                          /* Bit 0 is Status Bit 0: FrameXferErr */
+-                                                                          /* Bit 1 & 2 are Status Bits 16 and 17: FrameXmitErrStatus */
+-                                                                          /* Bit 3 is Status Bit 18 WriteDataLenghtGTDataLengthErr */
++/* Bits 0-3 encode Transport Status Register (offset 0x08) */
++/* Bit 0 is Status Bit 0: FrameXferErr */
++/* Bit 1 & 2 are Status Bits 16 and 17: FrameXmitErrStatus */
++/* Bit 3 is Status Bit 18 WriteDataLenghtGTDataLengthErr */
+ #define PL_LOGINFO_SUB_CODE_TX_FM_CONNECTED_LOW              (0x00000500)
+ #define PL_LOGINFO_SUB_CODE_SATA_NON_NCQ_RW_ERR_BIT_SET      (0x00000600)
+@@ -179,7 +180,7 @@
+ #define PL_LOGINFO_SUB_CODE_DISCOVERY_REMOTE_SEP_RESET       (0x00000E01)
+ #define PL_LOGINFO_SUB_CODE_SECOND_OPEN                      (0x00000F00)
+ #define PL_LOGINFO_SUB_CODE_DSCVRY_SATA_INIT_TIMEOUT         (0x00001000)
+-#define PL_LOGINFO_SUB_CODE_BREAK_ON_SATA_CONNECTION                   (0x00002000) /* not currently used in mainline */
++#define PL_LOGINFO_SUB_CODE_BREAK_ON_SATA_CONNECTION                   (0x00002000)
+ #define PL_LOGINFO_SUB_CODE_BREAK_ON_STUCK_LINK              (0x00003000)
+ #define PL_LOGINFO_SUB_CODE_BREAK_ON_STUCK_LINK_AIP          (0x00004000)
+ #define PL_LOGINFO_SUB_CODE_BREAK_ON_INCOMPLETE_BREAK_RCVD   (0x00005000)
+@@ -308,7 +309,6 @@
+ /* Device Firmware Update: Unable to allocate memory for page */
+ #define IR_LOGINFO_DEV_FW_UPDATE_ERR_ALLOC_CFG_PAGE             (0x00010056)
+ /* Device Firmware Update:  */
+-//#define IR_LOGINFO_DEV_FW_UPDATE_ERR_                         (0x00010054)
+ /****************************************************************************/
+Index: linux-2.6.27/drivers/message/fusion/lsi/mpi_type.h
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/lsi/mpi_type.h
++++ linux-2.6.27/drivers/message/fusion/lsi/mpi_type.h
+@@ -50,18 +50,8 @@ typedef signed   short  S16;
+ typedef unsigned short  U16;
+-#if defined(unix) || defined(__arm) || defined(ALPHA) || defined(__PPC__) || defined(__ppc)
+-
+-    typedef signed   int   S32;
+-    typedef unsigned int   U32;
+-
+-#else
+-
+-    typedef signed   long  S32;
+-    typedef unsigned long  U32;
+-
+-#endif
+-
++typedef int32_t   S32;
++typedef u_int32_t U32;
  
-       max = (mpt_dev->req_sz - MPT_LAN_RECEIVE_POST_REQUEST_SIZE) /
-                       (MPT_LAN_TRANSACTION32_SIZE + sizeof(SGESimple64_t));
-@@ -1217,9 +1222,9 @@ mpt_lan_post_receive_buckets(struct mpt_
-               mf = mpt_get_msg_frame(LanCtx, mpt_dev);
-               if (mf == NULL) {
-                       printk (KERN_ERR "%s: Unable to alloc request frame\n",
--                              __func__);
-+                              __FUNCTION__);
-                       dioprintk((KERN_ERR "%s: %u buckets remaining\n",
--                               __func__, buckets));
-+                               __FUNCTION__, buckets));
-                       goto out;
-               }
-               pRecvReq = (LANReceivePostRequest_t *) mf;
-@@ -1244,7 +1249,7 @@ mpt_lan_post_receive_buckets(struct mpt_
-                       spin_lock_irqsave(&priv->rxfidx_lock, flags);
-                       if (priv->mpt_rxfidx_tail < 0) {
-                               printk (KERN_ERR "%s: Can't alloc context\n",
--                                      __func__);
-+                                      __FUNCTION__);
-                               spin_unlock_irqrestore(&priv->rxfidx_lock,
-                                                      flags);
-                               break;
-@@ -1267,7 +1272,7 @@ mpt_lan_post_receive_buckets(struct mpt_
-                               if (skb == NULL) {
-                                       printk (KERN_WARNING
-                                               MYNAM "/%s: Can't alloc skb\n",
--                                              __func__);
-+                                              __FUNCTION__);
-                                       priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
-                                       spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
-                                       break;
-@@ -1295,7 +1300,7 @@ mpt_lan_post_receive_buckets(struct mpt_
-                                 MPI_SGE_FLAGS_SIMPLE_ELEMENT |
-                                 MPI_SGE_FLAGS_64_BIT_ADDRESSING) << MPI_SGE_FLAGS_SHIFT) | len);
-                       pSimple->Address.Low = cpu_to_le32((u32) priv->RcvCtl[ctx].dma);
--                      if (sizeof(dma_addr_t) > sizeof(u32))
-+                      if (mpt_dev->sg_addr_size > sizeof(u32))
-                               pSimple->Address.High = cpu_to_le32((u32) ((u64) priv->RcvCtl[ctx].dma >> 32));
-                       else
-                               pSimple->Address.High = 0;
-@@ -1305,7 +1310,7 @@ mpt_lan_post_receive_buckets(struct mpt_
+ typedef struct _S64
+ {
+Index: linux-2.6.27/drivers/message/fusion/mptbase.c
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/mptbase.c
++++ linux-2.6.27/drivers/message/fusion/mptbase.c
+@@ -83,15 +83,18 @@ MODULE_VERSION(my_VERSION);
  
-               if (pSimple == NULL) {
- /**/                  printk (KERN_WARNING MYNAM "/%s: No buckets posted\n",
--/**/                          __func__);
-+/**/                          __FUNCTION__);
-                       mpt_free_msg_frame(mpt_dev, mf);
-                       goto out;
-               }
-@@ -1329,9 +1334,9 @@ mpt_lan_post_receive_buckets(struct mpt_
+ static int mpt_msi_enable_spi;
+ module_param(mpt_msi_enable_spi, int, 0);
+-MODULE_PARM_DESC(mpt_msi_enable_spi, " Enable MSI Support for SPI controllers (default=0)");
++MODULE_PARM_DESC(mpt_msi_enable_spi,
++    " Enable MSI Support for SPI controllers (default=0)");
  
- out:
-       dioprintk((KERN_INFO MYNAM "/%s: End_buckets = %u, priv->buckets_out = %u\n",
--                __func__, buckets, atomic_read(&priv->buckets_out)));
-+                __FUNCTION__, buckets, atomic_read(&priv->buckets_out)));
-       dioprintk((KERN_INFO MYNAM "/%s: Posted %u buckets and received %u back\n",
--      __func__, priv->total_posted, priv->total_received));
-+      __FUNCTION__, priv->total_posted, priv->total_received));
+ static int mpt_msi_enable_fc;
+ module_param(mpt_msi_enable_fc, int, 0);
+-MODULE_PARM_DESC(mpt_msi_enable_fc, " Enable MSI Support for FC controllers (default=0)");
++MODULE_PARM_DESC(mpt_msi_enable_fc,
++    " Enable MSI Support for FC controllers (default=0)");
  
-       clear_bit(0, &priv->post_buckets_active);
- }
-@@ -1340,26 +1345,25 @@ static void
- mpt_lan_post_receive_buckets_work(struct work_struct *work)
- {
-       mpt_lan_post_receive_buckets(container_of(work, struct mpt_lan_priv,
--                                                post_buckets_task.work));
-+              post_buckets_task.work));
- }
+ static int mpt_msi_enable_sas = 1;
+ module_param(mpt_msi_enable_sas, int, 0);
+-MODULE_PARM_DESC(mpt_msi_enable_sas, " Enable MSI Support for SAS controllers (default=1)");
++MODULE_PARM_DESC(mpt_msi_enable_sas,
++    " Enable MSI Support for SAS controllers (default=1)");
  
- static const struct net_device_ops mpt_netdev_ops = {
-       .ndo_open       = mpt_lan_open,
-       .ndo_stop       = mpt_lan_close,
-       .ndo_start_xmit = mpt_lan_sdu_send,
-       .ndo_change_mtu = mpt_lan_change_mtu,
-       .ndo_tx_timeout = mpt_lan_tx_timeout,
- };
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- static struct net_device *
- mpt_register_lan_device (MPT_ADAPTER *mpt_dev, int pnum)
- {
--      struct net_device *dev;
--      struct mpt_lan_priv *priv;
-+      struct net_device *dev = alloc_fcdev(sizeof(struct mpt_lan_priv));
-+      struct mpt_lan_priv *priv = NULL;
-       u8 HWaddr[FC_ALEN], *a;
--      dev = alloc_fcdev(sizeof(struct mpt_lan_priv));
-       if (!dev)
-               return NULL;
+ static int mpt_channel_mapping;
+@@ -99,18 +102,20 @@ module_param(mpt_channel_mapping, int, 0
+ MODULE_PARM_DESC(mpt_channel_mapping, " Mapping id's to channels (default=0)");
  
-@@ -1363,8 +1367,9 @@ mpt_register_lan_device (MPT_ADAPTER *mp
-       priv->mpt_dev = mpt_dev;
-       priv->pnum = pnum;
+ int mpt_debug_level;
++EXPORT_SYMBOL(mpt_debug_level);
++
+ static int mpt_set_debug_level(const char *val, struct kernel_param *kp);
+ module_param_call(mpt_debug_level, mpt_set_debug_level, param_get_int,
+                 &mpt_debug_level, 0600);
+-MODULE_PARM_DESC(mpt_debug_level, " debug level - refer to mptdebug.h - (default=0)");
+-EXPORT_SYMBOL(mpt_debug_level);
++MODULE_PARM_DESC(mpt_debug_level,
++    " debug level - refer to mptdebug.h - (default=0)");
  
-+      memset(&priv->post_buckets_task, 0, sizeof(priv->post_buckets_task));
-       INIT_DELAYED_WORK(&priv->post_buckets_task,
--                        mpt_lan_post_receive_buckets_work);
-+              mpt_lan_post_receive_buckets_work);
-       priv->post_buckets_active = 0;
+ int mpt_fwfault_debug;
++EXPORT_SYMBOL(mpt_fwfault_debug);
+ module_param_call(mpt_fwfault_debug, param_set_int, param_get_int,
+                 &mpt_fwfault_debug, 0600);
+ MODULE_PARM_DESC(mpt_fwfault_debug, "Enable detection of Firmware fault"
+               " and halt Firmware on fault - (default=0)");
+-EXPORT_SYMBOL(mpt_fwfault_debug);
  
-       dlprintk((KERN_INFO MYNAM "@%d: bucketlen = %d\n",
-@@ -1421,6 +1428,7 @@ mpt_register_lan_device (MPT_ADAPTER *mp
-       dlprintk((KERN_INFO MYNAM ": Finished registering dev "
-               "and setting initial values\n"));
  
-+
-       if (register_netdev(dev) != 0) {
-               free_netdev(dev);
-               dev = NULL;
---- a/drivers/message/fusion/mptlan.h
-+++ b/drivers/message/fusion/mptlan.h
-@@ -6,7 +6,6 @@
-  *
-  *  Copyright (c) 2000-2008 LSI Corporation
-  *  (mailto:DL-MPTFusionLinux@lsi.com)
-- *
-  */
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ #ifdef MFCNT
+@@ -122,7 +127,7 @@ static int mfcounter = 0;
  /*
-@@ -55,6 +54,7 @@
- #include <linux/module.h>
- #endif
+  *  Public data...
+  */
+-struct proc_dir_entry *mpt_proc_root_dir;
++static struct proc_dir_entry *mpt_proc_root_dir;
  
-+#include <linux/version.h>
- #include <linux/netdevice.h>
- #include <linux/errno.h>
- // #include <linux/etherdevice.h>
-@@ -73,6 +73,7 @@
- #include <asm/uaccess.h>
- #include <asm/io.h>
-+#include <linux/pci.h>
-     /* Override mptbase.h by pre-defining these! */
- #define MODULEAUTHOR  "LSI Corporation"
---- a/drivers/message/fusion/mptsas.c
-+++ b/drivers/message/fusion/mptsas.c
-@@ -47,9 +47,11 @@
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/errno.h>
--#include <linux/jiffies.h>
-+#include <linux/sched.h>
- #include <linux/workqueue.h>
-+#include <linux/interrupt.h>
- #include <linux/delay.h>      /* for mdelay */
-+#include <linux/pci.h>
- #include <scsi/scsi.h>
- #include <scsi/scsi_cmnd.h>
-@@ -62,7 +64,6 @@
- #include "mptscsih.h"
- #include "mptsas.h"
+ #define WHOINIT_UNKNOWN               0xAA
  
--
- #define my_NAME               "Fusion MPT SAS Host driver"
- #define my_VERSION    MPT_LINUX_VERSION_COMMON
- #define MYNAM         "mptsas"
-@@ -72,6 +73,8 @@
+@@ -156,7 +161,8 @@ static u8 last_drv_idx;
+ /*
+  *  Forward protos...
   */
- #define MPTSAS_RAID_CHANNEL   1
+-static int    mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
++static int    mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
++    MPT_FRAME_HDR *reply);
+ static int    mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
+                       u32 *req, int replyBytes, u16 *u16reply, int maxwait,
+                       int sleepFlag);
+@@ -188,7 +194,8 @@ static int mpt_readScsiDevicePageHeaders
+ static void   mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
+ static void   mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
+ static void   mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc);
+-static int    SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch, int sleepFlag);
++static int    SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch,
++    int sleepFlag);
+ static int    SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
+ static int    mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag);
+ static int    mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
+@@ -353,10 +360,10 @@ mpt_fault_reset_work(struct work_struct 
+               printk(MYIOC_s_WARN_FMT "IOC is in FAULT state (%04xh)!!!\n",
+                   ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
+               printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
+-                  ioc->name, __FUNCTION__);
++                  ioc->name, __func__);
+               rc = mpt_HardResetHandler(ioc, CAN_SLEEP);
+               printk(MYIOC_s_WARN_FMT "%s: HardReset: %s\n", ioc->name,
+-                  __FUNCTION__, (rc == 0) ? "success" : "failed");
++                  __func__, (rc == 0) ? "success" : "failed");
+               ioc_raw_state = mpt_GetIocState(ioc, 0);
+               if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT)
+                       printk(MYIOC_s_WARN_FMT "IOC is in FAULT state after "
+@@ -378,11 +385,11 @@ mpt_fault_reset_work(struct work_struct 
+               ioc = ioc->alt_ioc;
  
-+#define SAS_CONFIG_PAGE_TIMEOUT               30
-+
- MODULE_AUTHOR(MODULEAUTHOR);
- MODULE_DESCRIPTION(my_NAME);
- MODULE_LICENSE("GPL");
-@@ -83,6 +86,25 @@ MODULE_PARM_DESC(mpt_pt_clear,
-               " Clear persistency table: enable=1  "
-               "(default=MPTSCSIH_PT_CLEAR=0)");
-+static int mpt_cmd_retry_count = 144;
-+module_param(mpt_cmd_retry_count, int, 0);
-+MODULE_PARM_DESC(mpt_cmd_retry_count,
-+              " Device discovery TUR command retry count: default=144");
-+
-+static int mpt_disable_hotplug_remove = 0;
-+module_param(mpt_disable_hotplug_remove, int, 0);
-+MODULE_PARM_DESC(mpt_disable_hotplug_remove,
-+              " Disable hotpug remove events: default=0");
-+
-+static int mpt_sdev_queue_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
-+static int mptsas_set_sdev_queue_depth(const char *val,
-+    struct kernel_param *kp);
-+module_param_call(mpt_sdev_queue_depth, mptsas_set_sdev_queue_depth,
-+    param_get_int, &mpt_sdev_queue_depth, 0600);
-+MODULE_PARM_DESC(mpt_sdev_queue_depth,
-+    " Max Device Queue Depth (default="
-+    __MODULE_STRING(MPT_SCSI_CMD_PER_DEV_HIGH) ")");
-+
- /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
- #define MPTSAS_MAX_LUN (16895)
- static int max_lun = MPTSAS_MAX_LUN;
-@@ -93,8 +115,53 @@ static u8  mptsasDoneCtx = MPT_MAX_PROTOC
- static u8     mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
- static u8     mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
- static u8     mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS;
-+static u8     mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS;
-+
-+static inline void mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
-+static struct mptsas_phyinfo * mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc,
-+      u64 sas_address);
-+static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
-+      u32 form, u32 form_specific);
-+static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
-+              u32 form, u32 form_specific);
-+
-+static int mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info);
-+static void mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info);
-+static void mptsas_expander_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info);
-+static int mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
-+              u32 form, u32 form_specific);
-+static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc);
-+static void mptsas_not_responding_devices(MPT_ADAPTER *ioc);
-+
-+static void mptsas_firmware_event_work(struct work_struct *work);
-+
-+/**
-+ *    mptsas_set_sdev_queue_depth - global setting of the mpt_sdev_queue_depth
-+ *    found via /sys/module/mptsas/parameters/mpt_sdev_queue_depth
-+ *    @val:
-+ *    @kp:
-+ *
-+ *    Returns
-+ **/
-+static int
-+mptsas_set_sdev_queue_depth(const char *val, struct kernel_param *kp)
-+{
-+      int ret = param_set_int(val, kp);
-+      MPT_ADAPTER *ioc;
-+      struct scsi_device      *sdev;
+       /* rearm the timer */
+-      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
++      spin_lock_irqsave(&ioc->fault_reset_work_lock, flags);
+       if (ioc->reset_work_q)
+               queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
+                       msecs_to_jiffies(MPT_POLLING_INTERVAL));
+-      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
++      spin_unlock_irqrestore(&ioc->fault_reset_work_lock, flags);
+ }
  
--static void mptsas_hotplug_work(struct work_struct *work);
-+      if (ret)
-+              return ret;
-+
-+      list_for_each_entry(ioc, &ioc_list, list) {
-+              if (ioc->bus_type != SAS)
-+                      continue;
-+              shost_for_each_device(sdev, ioc->sh)
-+                      mptscsih_change_queue_depth(sdev, mpt_sdev_queue_depth);
-+              ioc->sdev_queue_depth = mpt_sdev_queue_depth;
-+      }
-+      return 0;
-+}
+ /*
+@@ -439,7 +446,7 @@ mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa
+       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
+           MptCallbacks[cb_idx] == NULL) {
+               printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
+-                              __FUNCTION__, ioc->name, cb_idx);
++                              __func__, ioc->name, cb_idx);
+               goto out;
+       }
+@@ -497,9 +504,6 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
+                       mpt_sas_log_info(ioc, log_info);
+       }
+-      /* TODO - add shost_attrs, or command line option, and
+-       * extend this to SAS/FC
+-       */
+       if (ioc_stat & MPI_IOCSTATUS_MASK)
+               mpt_iocstatus_info(ioc, (u32)ioc_stat, mf);
  
- static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
-                                       MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
-@@ -218,37 +285,183 @@ static void mptsas_print_expander_pg1(MP
-           le16_to_cpu(pg1->AttachedDevHandle)));
+@@ -507,7 +511,7 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
+       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
+           MptCallbacks[cb_idx] == NULL) {
+               printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
+-                              __FUNCTION__, ioc->name, cb_idx);
++                              __func__, ioc->name, cb_idx);
+               freeme = 0;
+               goto out;
+       }
+@@ -523,11 +527,11 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
+       mb();
  }
  
--static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
-+/* inhibit sas firmware event handling */
-+static void
-+mptsas_fw_event_off(MPT_ADAPTER *ioc)
-+{
-+      unsigned long flags;
-+
-+      spin_lock_irqsave(&ioc->fw_event_lock, flags);
-+      ioc->fw_events_off = 1;
-+      spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
-+
-+}
-+
-+/* enable sas firmware event handling */
-+static void
-+mptsas_fw_event_on(MPT_ADAPTER *ioc)
-+{
-+      unsigned long flags;
-+
-+      spin_lock_irqsave(&ioc->fw_event_lock, flags);
-+      ioc->fw_events_off = 0;
-+      spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
-+}
-+
-+/* queue a sas firmware event */
-+static void
-+mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
-+    unsigned long delay)
-+{
-+      unsigned long flags;
-+
-+#if defined(CPQ_CIM)
-+      ioc->csmi_change_count++;
-+#endif
-+
-+      spin_lock_irqsave(&ioc->fw_event_lock, flags);
-+      list_add_tail(&fw_event->list, &ioc->fw_event_list);
-+      INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
-+      devtprintk(ioc, printk(MYIOC_s_INFO_FMT "%s: add (fw_event=0x%p)\n",
-+          ioc->name,__FUNCTION__, fw_event));
-+      queue_delayed_work(ioc->fw_event_q, &fw_event->work,
-+          msecs_to_jiffies(delay));
-+      spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
-+}
-+
-+/* requeue a sas firmware event */
-+static void
-+mptsas_requeue_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
-+    unsigned long delay)
-+{
-+      unsigned long flags;
-+      spin_lock_irqsave(&ioc->fw_event_lock, flags);
-+      devtprintk(ioc, printk(MYIOC_s_INFO_FMT "%s: reschedule task "
-+          "(fw_event=0x%p)\n", ioc->name,__FUNCTION__, fw_event));
-+      fw_event->retries++;
-+      queue_delayed_work(ioc->fw_event_q, &fw_event->work,
-+          msecs_to_jiffies(delay));
-+      spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
-+}
-+
-+/* free memory assoicated to a sas firmware event */
-+static void
-+mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event)
-+{
-+      unsigned long flags;
-+
-+      spin_lock_irqsave(&ioc->fw_event_lock, flags);
-+      devtprintk(ioc, printk(MYIOC_s_INFO_FMT "%s: kfree (fw_event=0x%p)\n",
-+          ioc->name,__FUNCTION__, fw_event));
-+      list_del(&fw_event->list);
-+      kfree(fw_event);
-+      spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
-+}
-+
-+/* walk the firmware event queue, and either stop or wait for outstanding events to complete */
-+static void
-+mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
-+{
-+      struct fw_event_work *fw_event, *next;
-+      struct mptsas_target_reset_event *target_reset_list, *n;
-+      u8      flush_q;
-+      MPT_SCSI_HOST   *hd = shost_priv(ioc->sh);
-+
-+      /* flush the target_reset_list */
-+      if (!list_empty(&hd->target_reset_list)) {
-+              list_for_each_entry_safe(target_reset_list, n,
-+                  &hd->target_reset_list, list) {
-+                      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                          "%s: removing target reset for id=%d\n",
-+                          ioc->name, __FUNCTION__,
-+                         target_reset_list->sas_event_data.TargetID));
-+                      list_del(&target_reset_list->list);
-+                      kfree(target_reset_list);
-+              }
-+      }
-+
-+      if (list_empty(&ioc->fw_event_list) ||
-+           !ioc->fw_event_q || in_interrupt())
-+              return;
-+
-+      flush_q = 0;
-+      list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
-+              if (cancel_delayed_work(&fw_event->work))
-+                      mptsas_free_fw_event(ioc, fw_event);
-+              else
-+                      flush_q = 1;
-+      }
-+      if (flush_q)
-+              flush_workqueue(ioc->fw_event_q);
-+}
-+
-+
-+/**
-+ *    phy_to_ioc -
-+ *    @phy:
-+ *
-+ *
-+ **/
-+static inline MPT_ADAPTER *
-+phy_to_ioc(struct sas_phy *phy)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
+  *    @irq: irq number (not used)
+  *    @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
+- *    @r: pt_regs pointer (not used)
+  *
+  *    This routine is registered via the request_irq() kernel API call,
+  *    and handles all interrupts generated from a specific MPT adapter
+@@ -539,7 +543,7 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
+  *    This routine handles register-level access of the adapter but
+  *    dispatches (calls) a protocol-specific callback routine to handle
+  *    the protocol-specific details of the MPT request completion.
+- **/
++ */
+ static irqreturn_t
+ mpt_interrupt(int irq, void *bus_id)
  {
-       struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
-       return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
+@@ -630,6 +634,7 @@ mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAM
+       return freereq;
  }
  
--static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
-+/**
-+ *    rphy_to_ioc -
-+ *    @rphy:
-+ *
-+ *
-+ **/
-+static inline MPT_ADAPTER *
-+rphy_to_ioc(struct sas_rphy *rphy)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_register - Register protocol-specific main callback handler.
+  *    @cbfunc: callback function pointer
+@@ -648,7 +653,7 @@ mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAM
+  *    {N,...,7,6,5,...,1} if successful.
+  *    A return value of MPT_MAX_PROTOCOL_DRIVERS (including zero!) should be
+  *    considered an error by the caller.
+- **/
++ */
+ u8
+ mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
  {
-       struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
-       return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
+@@ -672,13 +677,14 @@ mpt_register(MPT_CALLBACK cbfunc, MPT_DR
+       return last_drv_idx;
  }
  
-+/**
-+ *    mptsas_find_portinfo_by_sas_address -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @handle:
-+ *
-+ *    This function should be called with the sas_topology_mutex already held
-+ *
-+ **/
- static struct mptsas_portinfo *
--mptsas_get_hba_portinfo(MPT_ADAPTER *ioc)
-+mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_deregister - Deregister a protocol drivers resources.
+  *    @cb_idx: previously registered callback handle
+  *
+  *    Each protocol-specific driver should call this routine when its
+  *    module is unloaded.
+- **/
++ */
+ void
+ mpt_deregister(u8 cb_idx)
  {
--      struct list_head        *head = &ioc->sas_topology;
--      struct mptsas_portinfo  *pi = NULL;
--
--      /* always the first entry on sas_topology list */
--
--      if (!list_empty(head))
--              pi = list_entry(head->next, struct mptsas_portinfo, list);
-+      struct mptsas_portinfo *port_info, *rc=NULL;
-+      int i;
-+
-+      if (sas_address >= ioc->hba_port_sas_addr &&
-+          sas_address < (ioc->hba_port_sas_addr +
-+          ioc->hba_port_num_phy))
-+              return ioc->hba_port_info;
--      return pi;
-+      mutex_lock(&ioc->sas_topology_mutex);
-+      list_for_each_entry(port_info, &ioc->sas_topology, list)
-+              for (i = 0; i < port_info->num_phys; i++)
-+                      if (port_info->phy_info[i].identify.sas_address ==
-+                          sas_address) {
-+                              rc = port_info;
-+                              goto out;
-+                      }
-+ out:
-+      mutex_unlock(&ioc->sas_topology_mutex);
-+      return rc;
+@@ -691,9 +697,9 @@ mpt_deregister(u8 cb_idx)
+       }
  }
  
--/*
-- * mptsas_find_portinfo_by_handle
-+/**
-+ *    mptsas_find_portinfo_by_handle -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @handle:
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+- *    mpt_event_register - Register protocol-specific event callback
+- *    handler.
++ *    mpt_event_register - Register protocol-specific event callback handler.
+  *    @cb_idx: previously registered (via mpt_register) callback handle
+  *    @ev_cbfunc: callback function
   *
-- * This function should be called with the sas_topology_mutex already held
-- */
-+ *    This function should be called with the sas_topology_mutex already held
-+ *
-+ **/
- static struct mptsas_portinfo *
- mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
+@@ -701,7 +707,7 @@ mpt_deregister(u8 cb_idx)
+  *    if/when they choose to be notified of MPT events.
+  *
+  *    Returns 0 for success.
+- **/
++ */
+ int
+ mpt_event_register(u8 cb_idx, MPT_EVHANDLER ev_cbfunc)
  {
-@@ -265,9 +478,12 @@ mptsas_find_portinfo_by_handle(MPT_ADAPT
-       return rc;
+@@ -712,15 +718,15 @@ mpt_event_register(u8 cb_idx, MPT_EVHAND
+       return 0;
  }
  
--/*
-- * Returns true if there is a scsi end device
-- */
-+/**
-+ *    mptsas_is_end_device -
-+ *    @attached:
-+ *
-+ *    Returns true if there is a scsi end device
-+ **/
- static inline int
- mptsas_is_end_device(struct mptsas_devinfo * attached)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+- *    mpt_event_deregister - Deregister protocol-specific event callback
+- *    handler.
++ *    mpt_event_deregister - Deregister protocol-specific event callback handler.
+  *    @cb_idx: previously registered callback handle
+  *
+  *    Each protocol-specific driver should call this routine
+  *    when it does not (or can no longer) handle events,
+  *    or when its module is unloaded.
+- **/
++ */
+ void
+ mpt_event_deregister(u8 cb_idx)
  {
-@@ -285,7 +501,14 @@ mptsas_is_end_device(struct mptsas_devin
-               return 0;
+@@ -730,6 +736,7 @@ mpt_event_deregister(u8 cb_idx)
+       MptEvHandlers[cb_idx] = NULL;
  }
  
--/* no mutex */
-+/**
-+ *    mptsas_port_delete -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @port_details:
-+ *
-+ *    (no mutex)
-+ *
-+ **/
- static void
- mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_reset_register - Register protocol-specific IOC reset handler.
+  *    @cb_idx: previously registered (via mpt_register) callback handle
+@@ -739,7 +746,7 @@ mpt_event_deregister(u8 cb_idx)
+  *    if/when they choose to be notified of IOC resets.
+  *
+  *    Returns 0 for success.
+- **/
++ */
+ int
+ mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func)
  {
-@@ -300,7 +523,7 @@ mptsas_port_delete(MPT_ADAPTER *ioc, str
-       phy_info = port_info->phy_info;
-       dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
--          "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
-+          "bitmask=0x%016llX\n", ioc->name, __FUNCTION__, port_details,
-           port_details->num_phys, (unsigned long long)
-           port_details->phy_bitmask));
-@@ -308,11 +531,17 @@ mptsas_port_delete(MPT_ADAPTER *ioc, str
-               if(phy_info->port_details != port_details)
-                       continue;
-               memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
-+              mptsas_set_rphy(ioc, phy_info, NULL);
-               phy_info->port_details = NULL;
-       }
-       kfree(port_details);
+@@ -750,6 +757,7 @@ mpt_reset_register(u8 cb_idx, MPT_RESETH
+       return 0;
  }
  
-+/**
-+ *    mptsas_get_rphy -
-+ *    @phy_info:
-+ *
-+ **/
- static inline struct sas_rphy *
- mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
+  *    @cb_idx: previously registered callback handle
+@@ -757,7 +765,7 @@ mpt_reset_register(u8 cb_idx, MPT_RESETH
+  *    Each protocol-specific driver should call this routine
+  *    when it does not (or can no longer) handle IOC reset handling,
+  *    or when its module is unloaded.
+- **/
++ */
+ void
+ mpt_reset_deregister(u8 cb_idx)
  {
-@@ -322,13 +551,20 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
-               return NULL;
+@@ -767,11 +775,12 @@ mpt_reset_deregister(u8 cb_idx)
+       MptResetHandlers[cb_idx] = NULL;
  }
  
-+/**
-+ *    mptsas_set_rphy -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @phy_info:
-+ *    @rphy:
-+ *
-+ **/
- static inline void
- mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_device_driver_register - Register device driver hooks
+  *    @dd_cbfunc: driver callbacks struct
+  *    @cb_idx: MPT protocol driver index
+- **/
++ */
+ int
+ mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
  {
-       if (phy_info->port_details) {
-               phy_info->port_details->rphy = rphy;
--              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
--                  ioc->name, rphy));
-+              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "sas_rphy_add: rphy=%p\n", ioc->name, rphy));
-       }
+@@ -785,8 +794,6 @@ mpt_device_driver_register(struct mpt_pc
  
-       if (rphy) {
-@@ -339,6 +575,11 @@ mptsas_set_rphy(MPT_ADAPTER *ioc, struct
-       }
+       /* call per pci device probe entry point */
+       list_for_each_entry(ioc, &ioc_list, list) {
+-              if (!pci_get_drvdata(ioc->pcidev))
+-                      continue;
+               id = ioc->pcidev->driver ?
+                   ioc->pcidev->driver->id_table : NULL;
+               if (dd_cbfunc->probe)
+@@ -796,10 +803,11 @@ mpt_device_driver_register(struct mpt_pc
+       return 0;
  }
  
-+/**
-+ *    mptsas_get_port -
-+ *    @phy_info:
-+ *
-+ **/
- static inline struct sas_port *
- mptsas_get_port(struct mptsas_phyinfo *phy_info)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_device_driver_deregister - DeRegister device driver hooks
+  *    @cb_idx: MPT protocol driver index
+- **/
++ */
+ void
+ mpt_device_driver_deregister(u8 cb_idx)
  {
-@@ -348,6 +589,13 @@ mptsas_get_port(struct mptsas_phyinfo *p
-               return NULL;
+@@ -819,15 +827,18 @@ mpt_device_driver_deregister(u8 cb_idx)
+       MptDeviceDriverHandlers[cb_idx] = NULL;
  }
  
-+/**
-+ *    mptsas_set_port -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @phy_info:
-+ *    @port:
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+- *    mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
+- *    allocated per MPT adapter.
++ *    mpt_get_msg_frame - Obtain an MPT request frame from the pool
+  *    @cb_idx: Handle of registered MPT protocol driver
+  *    @ioc: Pointer to MPT adapter structure
+  *
++ *    Obtain an MPT request frame from the pool (of 1024) that are
++ *    allocated per MPT adapter.
 + *
-+ **/
- static inline void
- mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
+  *    Returns pointer to a MPT request frame or %NULL if none are available
+  *    or IOC is not active.
+- **/
++ */
+ MPT_FRAME_HDR*
+ mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc)
  {
-@@ -362,6 +610,11 @@ mptsas_set_port(MPT_ADAPTER *ioc, struct
-       }
+@@ -886,16 +897,16 @@ mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER
+       return mf;
  }
  
-+/**
-+ *    mptsas_get_starget -
-+ *    @phy_info:
-+ *
-+ **/
- static inline struct scsi_target *
- mptsas_get_starget(struct mptsas_phyinfo *phy_info)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+- *    mpt_put_msg_frame - Send a protocol specific MPT request frame
+- *    to a IOC.
++ *    mpt_put_msg_frame - Send a protocol-specific MPT request frame to an IOC
+  *    @cb_idx: Handle of registered MPT protocol driver
+  *    @ioc: Pointer to MPT adapter structure
+  *    @mf: Pointer to MPT request frame
+  *
+- *    This routine posts a MPT request frame to the request post FIFO of a
++ *    This routine posts an MPT request frame to the request post FIFO of a
+  *    specific MPT adapter.
+- **/
++ */
+ void
+ mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  {
-@@ -371,6 +624,12 @@ mptsas_get_starget(struct mptsas_phyinfo
-               return NULL;
+@@ -921,13 +932,15 @@ mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER
  }
  
-+/**
-+ *    mptsas_set_starget -
-+ *    @phy_info:
-+ *    @starget:
+ /**
+- *    mpt_put_msg_frame_hi_pri - Send a protocol specific MPT request frame
+- *    to a IOC using hi priority request queue.
++ *    mpt_put_msg_frame_hi_pri - Send a hi-pri protocol-specific MPT request frame
+  *    @cb_idx: Handle of registered MPT protocol driver
+  *    @ioc: Pointer to MPT adapter structure
+  *    @mf: Pointer to MPT request frame
+  *
+- *    This routine posts a MPT request frame to the request post FIFO of a
++ *    Send a protocol-specific MPT request frame to an IOC using
++ *    hi-priority request queue.
 + *
-+ **/
- static inline void
- mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
- starget)
-@@ -379,714 +638,787 @@ starget)
-               phy_info->port_details->starget = starget;
++ *    This routine posts an MPT request frame to the request post FIFO of a
+  *    specific MPT adapter.
+  **/
+ void
+@@ -952,6 +965,7 @@ mpt_put_msg_frame_hi_pri(u8 cb_idx, MPT_
+       CHIPREG_WRITE32(&ioc->chip->RequestHiPriFifo, mf_dma_addr);
  }
  
--
--/*
-- * mptsas_setup_wide_ports
-+/**
-+ *    mptsas_add_device_component -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @channel: fw mapped id's
-+ *    @id:
-+ *    @sas_address:
-+ *    @device_info:
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_free_msg_frame - Place MPT request frame back on FreeQ.
+  *    @handle: Handle of registered MPT protocol driver
+@@ -960,7 +974,7 @@ mpt_put_msg_frame_hi_pri(u8 cb_idx, MPT_
   *
-- * Updates for new and existing narrow/wide port configuration
-- * in the sas_topology
-- */
-+ **/
- static void
--mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
-+mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id,
-+      u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id)
+  *    This routine places a MPT request frame back on the MPT adapter's
+  *    FreeQ.
+- **/
++ */
+ void
+ mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  {
--      struct mptsas_portinfo_details * port_details;
--      struct mptsas_phyinfo *phy_info, *phy_info_cmp;
--      u64     sas_address;
--      int     i, j;
--
--      mutex_lock(&ioc->sas_topology_mutex);
--
--      phy_info = port_info->phy_info;
--      for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
--              if (phy_info->attached.handle)
--                      continue;
--              port_details = phy_info->port_details;
--              if (!port_details)
--                      continue;
--              if (port_details->num_phys < 2)
--                      continue;
--              /*
--               * Removing a phy from a port, letting the last
--               * phy be removed by firmware events.
--               */
--              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                  "%s: [%p]: deleting phy = %d\n",
--                  ioc->name, __func__, port_details, i));
--              port_details->num_phys--;
--              port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
--              memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
--              sas_port_delete_phy(port_details->port, phy_info->phy);
--              phy_info->port_details = NULL;
-+      struct sas_device_info  *sas_info, *next;
-+      struct scsi_device      *sdev;
-+      struct scsi_target      *starget;
-+      struct sas_rphy         *rphy;
-+
-+      /*
-+       * Delete all matching devices out of the list
-+       */
-+      down(&ioc->sas_device_info_mutex);
-+      list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
-+          list) {
-+              if (!sas_info->is_logical_volume &&
-+                  (sas_info->sas_address == sas_address ||
-+                  (sas_info->fw.channel == channel &&
-+                   sas_info->fw.id == id))) {
-+                      list_del(&sas_info->list);
-+                      kfree(sas_info);
-+              }
-       }
-+      if (!(sas_info = kzalloc(sizeof(struct sas_device_info), GFP_KERNEL)))
-+              goto out;
-+
-       /*
--       * Populate and refresh the tree
-+       * Set Firmware mapping
-        */
--      phy_info = port_info->phy_info;
--      for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
--              sas_address = phy_info->attached.sas_address;
--              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
--                  ioc->name, i, (unsigned long long)sas_address));
--              if (!sas_address)
--                      continue;
--              port_details = phy_info->port_details;
--              /*
--               * Forming a port
--               */
--              if (!port_details) {
--                      port_details = kzalloc(sizeof(*port_details),
--                              GFP_KERNEL);
--                      if (!port_details)
--                              goto out;
--                      port_details->num_phys = 1;
--                      port_details->port_info = port_info;
--                      if (phy_info->phy_id < 64 )
--                              port_details->phy_bitmask |=
--                                  (1 << phy_info->phy_id);
--                      phy_info->sas_port_add_phy=1;
--                      dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
--                          "phy_id=%d sas_address=0x%018llX\n",
--                          ioc->name, i, (unsigned long long)sas_address));
--                      phy_info->port_details = port_details;
--              }
-+      sas_info->fw.id = id;
-+      sas_info->fw.channel = channel;
--              if (i == port_info->num_phys - 1)
--                      continue;
--              phy_info_cmp = &port_info->phy_info[i + 1];
--              for (j = i + 1 ; j < port_info->num_phys ; j++,
--                  phy_info_cmp++) {
--                      if (!phy_info_cmp->attached.sas_address)
--                              continue;
--                      if (sas_address != phy_info_cmp->attached.sas_address)
--                              continue;
--                      if (phy_info_cmp->port_details == port_details )
--                              continue;
--                      dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                          "\t\tphy_id=%d sas_address=0x%018llX\n",
--                          ioc->name, j, (unsigned long long)
--                          phy_info_cmp->attached.sas_address));
--                      if (phy_info_cmp->port_details) {
--                              port_details->rphy =
--                                  mptsas_get_rphy(phy_info_cmp);
--                              port_details->port =
--                                  mptsas_get_port(phy_info_cmp);
--                              port_details->starget =
--                                  mptsas_get_starget(phy_info_cmp);
--                              port_details->num_phys =
--                                      phy_info_cmp->port_details->num_phys;
--                              if (!phy_info_cmp->port_details->num_phys)
--                                      kfree(phy_info_cmp->port_details);
--                      } else
--                              phy_info_cmp->sas_port_add_phy=1;
--                      /*
--                       * Adding a phy to a port
--                       */
--                      phy_info_cmp->port_details = port_details;
--                      if (phy_info_cmp->phy_id < 64 )
--                              port_details->phy_bitmask |=
--                              (1 << phy_info_cmp->phy_id);
--                      port_details->num_phys++;
-+      sas_info->sas_address = sas_address;
-+      sas_info->device_info = device_info;
-+      sas_info->slot = slot;
-+      sas_info->enclosure_logical_id = enclosure_logical_id;
-+      INIT_LIST_HEAD(&sas_info->list);
-+      list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
-+
-+      /*
-+       * Set OS mapping
-+       */
-+      shost_for_each_device(sdev, ioc->sh) {
-+              starget = scsi_target(sdev);
-+              rphy = dev_to_rphy(starget->dev.parent);
-+              if (rphy->identify.sas_address == sas_address) {
-+                      sas_info->os.id = starget->id;
-+                      sas_info->os.channel = starget->channel;
-               }
-       }
-  out:
--
--      for (i = 0; i < port_info->num_phys; i++) {
--              port_details = port_info->phy_info[i].port_details;
--              if (!port_details)
--                      continue;
--              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                  "%s: [%p]: phy_id=%02d num_phys=%02d "
--                  "bitmask=0x%016llX\n", ioc->name, __func__,
--                  port_details, i, port_details->num_phys,
--                  (unsigned long long)port_details->phy_bitmask));
--              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
--                  ioc->name, port_details->port, port_details->rphy));
--      }
--      dsaswideprintk(ioc, printk("\n"));
--      mutex_unlock(&ioc->sas_topology_mutex);
-+      up(&ioc->sas_device_info_mutex);
-+      return;
+@@ -970,7 +984,8 @@ mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT
+       spin_lock_irqsave(&ioc->FreeQlock, flags);
+       if (cpu_to_le32(mf->u.frame.linkage.arg1) == 0xdeadbeaf)
+               goto out;
+-      mf->u.frame.linkage.arg1 = cpu_to_le32(0xdeadbeaf); /* signature to know if this mf is freed */
++      /* signature to know if this mf is freed */
++      mf->u.frame.linkage.arg1 = cpu_to_le32(0xdeadbeaf);
+       list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
+ #ifdef MFCNT
+       ioc->mfcnt--;
+@@ -1122,7 +1137,7 @@ mpt_add_chain_64bit(char *pAddr, u8 next
+  *    request which are greater than 1 byte in size.
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
+ int
+ mpt_send_handshake_request(u8 cb_idx, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
+ {
+@@ -1199,6 +1214,7 @@ mpt_send_handshake_request(u8 cb_idx, MP
+       return r;
  }
  
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  /**
-- * csmisas_find_vtarget
-- *
-- * @ioc
-- * @volume_id
-- * @volume_bus
-+ *    mptsas_add_device_component_by_fw -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @channel:  fw mapped id's
-+ *    @id:
+  * mpt_host_page_access_control - control the IOC's Host Page Buffer access
+  * @ioc: Pointer to MPT adapter structure
+@@ -1215,7 +1231,7 @@ mpt_send_handshake_request(u8 cb_idx, MP
+  * 3h Free Buffer { MPI_DB_HPBAC_FREE_BUFFER }
   *
-  **/
--static VirtTarget *
--mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
-+static void
-+mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id)
+  * Returns 0 for success, non-zero for failure.
+- **/
++ */
+ static int
+ mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag)
  {
--      struct scsi_device              *sdev;
--      VirtDevice                      *vdevice;
--      VirtTarget                      *vtarget = NULL;
-+      struct mptsas_devinfo sas_device;
-+      struct mptsas_enclosure enclosure_info;
-+      int rc;
--      shost_for_each_device(sdev, ioc->sh) {
--              if ((vdevice = sdev->hostdata) == NULL)
--                      continue;
--              if (vdevice->vtarget->id == id &&
--                  vdevice->vtarget->channel == channel)
--                      vtarget = vdevice->vtarget;
--      }
--      return vtarget;
-+      rc = mptsas_sas_device_pg0(ioc, &sas_device,
-+          (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
-+           MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+          (channel << 8) + id);
-+      if (rc)
-+              return;
-+
-+      memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
-+      mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
-+          (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
-+           MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
-+           sas_device.handle_enclosure);
-+
-+      mptsas_add_device_component(ioc, sas_device.channel,
-+          sas_device.id, sas_device.sas_address, sas_device.device_info,
-+          sas_device.slot, enclosure_info.enclosure_logical_id);
+@@ -1240,6 +1256,7 @@ mpt_host_page_access_control(MPT_ADAPTER
+               return 0;
  }
  
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  /**
-- * mptsas_target_reset
-- *
-- * Issues TARGET_RESET to end device using handshaking method
-- *
-- * @ioc
-- * @channel
-- * @id
-- *
-- * Returns (1) success
-- *         (0) failure
-- *
-- **/
--static int
--mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
--{
--      MPT_FRAME_HDR   *mf;
--      SCSITaskMgmt_t  *pScsiTm;
--
--      if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
--              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames @%d!!\n",
--                  ioc->name,__func__, __LINE__));
--              return 0;
--      }
--
--      /* Format the Request
--       */
--      pScsiTm = (SCSITaskMgmt_t *) mf;
--      memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
--      pScsiTm->TargetID = id;
--      pScsiTm->Bus = channel;
--      pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
--      pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
--      pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
--
--      DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
--
--      mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);
--
--      return 1;
--}
--
--/**
-- * mptsas_target_reset_queue
-- *
-- * Receive request for TARGET_RESET after recieving an firmware
-- * event NOT_RESPONDING_EVENT, then put command in link list
-- * and queue if task_queue already in use.
-- *
-- * @ioc
-- * @sas_event_data
-+ *    mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding
-+ *    each individual device to list
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @channel: fw mapped id's
-+ *    @id:
+  *    mpt_host_page_alloc - allocate system memory for the fw
+  *    @ioc: Pointer to pointer to IOC adapter
+@@ -1247,7 +1264,7 @@ mpt_host_page_access_control(MPT_ADAPTER
   *
-  **/
- static void
--mptsas_target_reset_queue(MPT_ADAPTER *ioc,
--    EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
-+mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc, struct scsi_target *starget)
- {
--      MPT_SCSI_HOST   *hd = shost_priv(ioc->sh);
--      VirtTarget *vtarget = NULL;
--      struct mptsas_target_reset_event *target_reset_list;
--      u8              id, channel;
-+      CONFIGPARMS                     cfg;
-+      ConfigPageHeader_t              hdr;
-+      dma_addr_t                      dma_handle;
-+      pRaidVolumePage0_t              buffer = NULL;
-+      int                             i;
-+      RaidPhysDiskPage0_t             phys_disk;
-+      struct sas_device_info          *sas_info, *next;
--      id = sas_event_data->TargetID;
--      channel = sas_event_data->Bus;
-+      memset(&cfg, 0 , sizeof(CONFIGPARMS));
-+      memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
-+      /* assumption that all volumes on channel = 0 */
-+      cfg.pageAddr = starget->id;
-+      cfg.cfghdr.hdr = &hdr;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
--      if (!(vtarget = mptsas_find_vtarget(ioc, channel, id)))
--              return;
-+      if (mpt_config(ioc, &cfg) != 0)
-+              goto out;
--      vtarget->deleted = 1; /* block IO */
-+      if (!hdr.PageLength)
-+              goto out;
--      target_reset_list = kzalloc(sizeof(*target_reset_list),
--          GFP_ATOMIC);
--      if (!target_reset_list) {
--              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n",
--                  ioc->name,__func__, __LINE__));
--              return;
--      }
-+      buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
-+          &dma_handle);
--      memcpy(&target_reset_list->sas_event_data, sas_event_data,
--              sizeof(*sas_event_data));
--      list_add_tail(&target_reset_list->list, &hd->target_reset_list);
-+      if (!buffer)
-+              goto out;
--      if (hd->resetPending)
--              return;
-+      cfg.physAddr = dma_handle;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
--      if (mptsas_target_reset(ioc, channel, id)) {
--              target_reset_list->target_reset_issued = 1;
--              hd->resetPending = 1;
--      }
--}
-+      if (mpt_config(ioc, &cfg) != 0)
-+              goto out;
--/**
-- * mptsas_dev_reset_complete
-- *
-- * Completion for TARGET_RESET after NOT_RESPONDING_EVENT,
-- * enable work queue to finish off removing device from upper layers.
-- * then send next TARGET_RESET in the queue.
-- *
-- * @ioc
-- *
+  *    If we already allocated memory in past, then resend the same pointer.
+  *    Returns 0 for success, non-zero for failure.
 - **/
--static void
--mptsas_dev_reset_complete(MPT_ADAPTER *ioc)
--{
--      MPT_SCSI_HOST   *hd = shost_priv(ioc->sh);
--        struct list_head *head = &hd->target_reset_list;
--      struct mptsas_target_reset_event *target_reset_list;
--      struct mptsas_hotplug_event *ev;
--      EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
--      u8              id, channel;
--      __le64          sas_address;
-+      if (!buffer->NumPhysDisks)
-+              goto out;
--      if (list_empty(head))
--              return;
-+      /*
-+       * Adding entry for hidden components
-+       */
-+      for (i = 0; i < buffer->NumPhysDisks; i++) {
--      target_reset_list = list_entry(head->next, struct mptsas_target_reset_event, list);
-+              if(mpt_raid_phys_disk_pg0(ioc,
-+                  buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
-+                      continue;
--      sas_event_data = &target_reset_list->sas_event_data;
--      id = sas_event_data->TargetID;
--      channel = sas_event_data->Bus;
--      hd->resetPending = 0;
-+              mptsas_add_device_component_by_fw(ioc, phys_disk.PhysDiskBus,
-+                  phys_disk.PhysDiskID);
--      /*
--       * retry target reset
--       */
--      if (!target_reset_list->target_reset_issued) {
--              if (mptsas_target_reset(ioc, channel, id)) {
--                      target_reset_list->target_reset_issued = 1;
--                      hd->resetPending = 1;
-+              down(&ioc->sas_device_info_mutex);
-+              list_for_each_entry(sas_info, &ioc->sas_device_info_list,
-+                  list) {
-+                      if (!sas_info->is_logical_volume &&
-+                          (sas_info->fw.channel == phys_disk.PhysDiskBus &&
-+                          sas_info->fw.id == phys_disk.PhysDiskID)) {
-+                              sas_info->is_hidden_raid_component = 1;
-+                              sas_info->volume_id = starget->id;
-+                      }
-               }
--              return;
-+              up(&ioc->sas_device_info_mutex);
-       }
-       /*
--       * enable work queue to remove device from upper layers
-+       * Delete all matching devices out of the list
-        */
--      list_del(&target_reset_list->list);
-+      down(&ioc->sas_device_info_mutex);
-+      list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
-+          list) {
-+              if (sas_info->is_logical_volume && sas_info->fw.id ==
-+                  starget->id) {
-+                      list_del(&sas_info->list);
-+                      kfree(sas_info);
-+              }
-+      }
--      ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
--      if (!ev) {
--              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n",
--                  ioc->name,__func__, __LINE__));
--              return;
-+      sas_info = kzalloc(sizeof(struct sas_device_info), GFP_KERNEL);
-+      if (sas_info) {
-+              sas_info->fw.id = starget->id;
-+              sas_info->os.id = starget->id;
-+              sas_info->os.channel = starget->channel;
-+              sas_info->is_logical_volume = 1;
-+              INIT_LIST_HEAD(&sas_info->list);
-+              list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
-       }
-+      up(&ioc->sas_device_info_mutex);
--      INIT_WORK(&ev->work, mptsas_hotplug_work);
--      ev->ioc = ioc;
--      ev->handle = le16_to_cpu(sas_event_data->DevHandle);
--      ev->parent_handle =
--          le16_to_cpu(sas_event_data->ParentDevHandle);
--      ev->channel = channel;
--      ev->id =id;
--      ev->phy_id = sas_event_data->PhyNum;
--      memcpy(&sas_address, &sas_event_data->SASAddress,
--          sizeof(__le64));
--      ev->sas_address = le64_to_cpu(sas_address);
--      ev->device_info = le32_to_cpu(sas_event_data->DeviceInfo);
--      ev->event_type = MPTSAS_DEL_DEVICE;
--      schedule_work(&ev->work);
--      kfree(target_reset_list);
-+ out:
-+      if (buffer)
-+              pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
-+                  dma_handle);
-+}
--      /*
--       * issue target reset to next device in the queue
--       */
-+/**
-+ *    mptsas_add_device_component_starget -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @starget:
-+ *
-+ **/
-+static void
-+mptsas_add_device_component_starget(MPT_ADAPTER *ioc, struct scsi_target *starget)
-+{
-+      VirtTarget              *vtarget;
-+      struct sas_rphy         *rphy;
-+      struct mptsas_phyinfo *phy_info = NULL;
-+      struct mptsas_enclosure enclosure_info;
--      head = &hd->target_reset_list;
--      if (list_empty(head))
-+      rphy = dev_to_rphy(starget->dev.parent);
-+      vtarget = starget->hostdata;
-+      phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
-+                  rphy->identify.sas_address);
-+      if (!phy_info)
-               return;
--      target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
--          list);
--
--      sas_event_data = &target_reset_list->sas_event_data;
--      id = sas_event_data->TargetID;
--      channel = sas_event_data->Bus;
--
--      if (mptsas_target_reset(ioc, channel, id)) {
--              target_reset_list->target_reset_issued = 1;
--              hd->resetPending = 1;
--      }
-+      memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
-+      mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
-+          (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
-+           MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
-+           phy_info->attached.handle_enclosure);
-+
-+      mptsas_add_device_component(ioc, phy_info->attached.channel,
-+          phy_info->attached.id, phy_info->attached.sas_address,
-+          phy_info->attached.device_info,
-+          phy_info->attached.slot, enclosure_info.enclosure_logical_id);
++ */
+ static int
+ mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
+ {
+@@ -1305,6 +1322,7 @@ mpt_host_page_alloc(MPT_ADAPTER *ioc, pI
+ return 0;
  }
  
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  /**
-- * mptsas_taskmgmt_complete
-- *
-- * @ioc
-- * @mf
-- * @mr
-+ *    mptsas_del_device_component_by_os - Once a device has been removed, we
-+ *    mark the entry in the list as being cached
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @channel: os mapped id's
-+ *    @id:
+  *    mpt_verify_adapter - Given IOC identifier, set pointer to its adapter structure.
+  *    @iocid: IOC unique identifier (integer)
+@@ -1315,7 +1333,7 @@ return 0;
   *
-  **/
--static int
--mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
-+static void
-+mptsas_del_device_component_by_os(MPT_ADAPTER *ioc, u8 channel, u8 id)
+  *    Returns iocid and sets iocpp if iocid is found.
+  *    Returns -1 if iocid is not found.
+- **/
++ */
+ int
+ mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
  {
--      mptsas_dev_reset_complete(ioc);
--      return mptscsih_taskmgmt_complete(ioc, mf, mr);
-+      struct sas_device_info  *sas_info, *next;
-+
-+      /*
-+       * Set is_cached flag
-+       */
-+      list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
-+              list) {
-+              if (sas_info->os.channel == channel && sas_info->os.id == id)
-+                      sas_info->is_cached = 1;
-+      }
+@@ -1604,7 +1622,8 @@ mpt_mapresources(MPT_ADAPTER *ioc)
+               return r;
+       }
+       if (sizeof(dma_addr_t) > 4) {
+-              const uint64_t required_mask = dma_get_required_mask(&pdev->dev);
++              uint64_t required_mask;
++              required_mask = dma_get_required_mask(&pdev->dev);
+               if (required_mask > DMA_32BIT_MASK
+                   && !pci_set_dma_mask(pdev, DMA_64BIT_MASK)
+                   && !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
+@@ -1674,15 +1693,13 @@ mpt_mapresources(MPT_ADAPTER *ioc)
+       ioc->chip = (SYSIF_REGS __iomem *)mem;
+       /* Save Port IO values in case we need to do downloadboot */
+-      {
+-              u8 *pmem = (u8*)port;
+-              ioc->pio_mem_phys = port;
+-              ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
+-      }
++      ioc->pio_mem_phys = port;
++      ioc->pio_chip = (SYSIF_REGS __iomem *)port;
+       return 0;
  }
  
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  /**
-- * mptscsih_ioc_reset
-- *
-- * @ioc
-- * @reset_phase
-+ *    mptsas_del_device_components - Cleaning the list
-+ *    @ioc: Pointer to MPT_ADAPTER structure
+  *    mpt_attach - Install a PCI intelligent MPT adapter.
+  *    @pdev: Pointer to pci_dev structure
+@@ -1698,8 +1715,7 @@ mpt_mapresources(MPT_ADAPTER *ioc)
   *
-  **/
--static int
--mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
-+static void
-+mptsas_del_device_components(MPT_ADAPTER *ioc)
+  *    Returns 0 for success, non-zero for failure.
+  *
+- *    TODO: Add support for polled controllers
+- **/
++ */
+ int
+ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
  {
--      MPT_SCSI_HOST   *hd;
--      struct mptsas_target_reset_event *target_reset_list, *n;
--      int rc;
--
--      rc = mptscsih_ioc_reset(ioc, reset_phase);
--
--      if (ioc->bus_type != SAS)
--              goto out;
--
--      if (reset_phase != MPT_IOC_POST_RESET)
--              goto out;
-+      struct sas_device_info  *sas_info, *next;
--      if (!ioc->sh || !ioc->sh->hostdata)
--              goto out;
--      hd = shost_priv(ioc->sh);
--      if (!hd->ioc)
--              goto out;
--
--      if (list_empty(&hd->target_reset_list))
--              goto out;
--
--      /* flush the target_reset_list */
--      list_for_each_entry_safe(target_reset_list, n,
--          &hd->target_reset_list, list) {
--              list_del(&target_reset_list->list);
--              kfree(target_reset_list);
-+      down(&ioc->sas_device_info_mutex);
-+      list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
-+              list) {
-+              list_del(&sas_info->list);
-+              kfree(sas_info);
+@@ -1795,6 +1811,7 @@ mpt_attach(struct pci_dev *pdev, const s
+       /* Initialize work */
+       INIT_DELAYED_WORK(&ioc->fault_reset_work, mpt_fault_reset_work);
++      spin_lock_init(&ioc->fault_reset_work_lock);
+       /* Initialize workqueue */
+       snprintf(ioc->reset_work_q_name, sizeof(ioc->reset_work_q_name),
+@@ -1809,7 +1826,8 @@ mpt_attach(struct pci_dev *pdev, const s
+               return -ENOMEM;
        }
--
-- out:
--      return rc;
-+      up(&ioc->sas_device_info_mutex);
- }
  
--static int
--mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
--              u32 form, u32 form_specific)
-+/**
-+ *    mptsas_setup_wide_ports - Updates for new and existing narrow/wide port
-+ *    configuration
-+ *    in the sas_topology
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @port_info:
-+ *
-+ */
-+static void
-+mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
- {
--      ConfigExtendedPageHeader_t hdr;
--      CONFIGPARMS cfg;
--      SasEnclosurePage0_t *buffer;
--      dma_addr_t dma_handle;
--      int error;
--      __le64 le_identifier;
--
--      memset(&hdr, 0, sizeof(hdr));
--      hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
--      hdr.PageNumber = 0;
--      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
--      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
-+      struct mptsas_portinfo_details * port_details;
-+      struct mptsas_phyinfo *phy_info, *phy_info_cmp;
-+      u64     sas_address;
-+      int     i, j;
--      cfg.cfghdr.ehdr = &hdr;
--      cfg.physAddr = -1;
--      cfg.pageAddr = form + form_specific;
--      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
--      cfg.dir = 0;    /* read */
--      cfg.timeout = 10;
-+      mutex_lock(&ioc->sas_topology_mutex);
--      error = mpt_config(ioc, &cfg);
--      if (error)
--              goto out;
--      if (!hdr.ExtPageLength) {
--              error = -ENXIO;
--              goto out;
--      }
-+      phy_info = port_info->phy_info;
-+      for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
-+              if (phy_info->attached.handle)
-+                      continue;
-+              port_details = phy_info->port_details;
-+              if (!port_details)
-+                      continue;
-+              if (port_details->num_phys < 2)
-+                      continue;
--      buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
--                      &dma_handle);
--      if (!buffer) {
--              error = -ENOMEM;
--              goto out;
-+              /*
-+               * Removing a phy from a port, letting the last
-+               * phy be removed by firmware events.
-+               */
-+              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                      "%s: [%p]: deleting phy = %d\n",
-+                      ioc->name, __FUNCTION__, port_details, i));
-+              port_details->num_phys--;
-+              port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
-+              memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
-+              devtprintk(ioc, dev_printk(KERN_DEBUG, &phy_info->phy->dev,
-+                  MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name,
-+                   phy_info->phy_id, phy_info->phy));
-+              sas_port_delete_phy(port_details->port, phy_info->phy);
-+              phy_info->port_details = NULL;
-       }
--      cfg.physAddr = dma_handle;
--      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
--
--      error = mpt_config(ioc, &cfg);
--      if (error)
--              goto out_free_consistent;
--
--      /* save config data */
--      memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
--      enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
--      enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
--      enclosure->flags = le16_to_cpu(buffer->Flags);
--      enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
--      enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
--      enclosure->start_id = buffer->StartTargetID;
--      enclosure->start_channel = buffer->StartBus;
--      enclosure->sep_id = buffer->SEPTargetID;
--      enclosure->sep_channel = buffer->SEPBus;
-+      /*
-+       * Populate and refresh the tree
-+       */
-+      phy_info = port_info->phy_info;
-+      for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
-+              sas_address = phy_info->attached.sas_address;
-+              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
-+                  ioc->name, i, (unsigned long long)sas_address));
-+              if (!sas_address)
-+                      continue;
-+              port_details = phy_info->port_details;
-+              /*
-+               * Forming a port
-+               */
-+              if (!port_details) {
-+                      port_details = kzalloc(sizeof(struct mptsas_portinfo_details),
-+                              GFP_KERNEL);
-+                      if (!port_details)
-+                              goto out;
-+                      port_details->num_phys = 1;
-+                      port_details->port_info = port_info;
-+                      if (phy_info->phy_id < 64 )
-+                              port_details->phy_bitmask |=
-+                                  (1 << phy_info->phy_id);
-+                      phy_info->sas_port_add_phy=1;
-+                      dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
-+                          "phy_id=%d sas_address=0x%018llX\n", ioc->name, i,
-+                          (unsigned long long) sas_address));
-+                      phy_info->port_details = port_details;
-+              }
-+
-+              if (i == port_info->num_phys - 1)
-+                      continue;
-+              phy_info_cmp = &port_info->phy_info[i + 1];
-+              for (j = i + 1 ; j < port_info->num_phys ; j++,
-+                  phy_info_cmp++) {
-+                      if (!phy_info_cmp->attached.sas_address)
-+                              continue;
-+                      if (sas_address != phy_info_cmp->attached.sas_address)
-+                              continue;
-+                      if (phy_info_cmp->port_details == port_details )
-+                              continue;
-+                      dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                          "\t\tphy_id=%d sas_address=0x%018llX\n",
-+                          ioc->name, j, (unsigned long long)
-+                          phy_info_cmp->attached.sas_address));
-+                      if (phy_info_cmp->port_details) {
-+                              port_details->rphy =
-+                                  mptsas_get_rphy(phy_info_cmp);
-+                              port_details->port =
-+                                  mptsas_get_port(phy_info_cmp);
-+                              port_details->starget =
-+                                  mptsas_get_starget(phy_info_cmp);
-+                              port_details->num_phys =
-+                                      phy_info_cmp->port_details->num_phys;
-+                              if (!phy_info_cmp->port_details->num_phys)
-+                                      kfree(phy_info_cmp->port_details);
-+                      } else
-+                              phy_info_cmp->sas_port_add_phy=1;
-+                      /*
-+                       * Adding a phy to a port
-+                       */
-+                      phy_info_cmp->port_details = port_details;
-+                      if (phy_info_cmp->phy_id < 64 )
-+                              port_details->phy_bitmask |=
-+                              (1 << phy_info_cmp->phy_id);
-+                      port_details->num_phys++;
-+              }
-+      }
+-      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "facts @ %p, pfacts[0] @ %p\n",
++      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "facts @ %p,"
++              " pfacts[0] @ %p\n",
+               ioc->name, &ioc->facts, &ioc->pfacts[0]));
  
-- out_free_consistent:
--      pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
--                          buffer, dma_handle);
-  out:
--      return error;
-+
-+      for (i = 0; i < port_info->num_phys; i++) {
-+              port_details = port_info->phy_info[i].port_details;
-+              if (!port_details)
-+                      continue;
-+              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: [%p]: phy_id=%02d num_phys=%02d "
-+                  "bitmask=0x%016llX\n", ioc->name, __FUNCTION__,
-+                  port_details, i, port_details->num_phys,
-+                  (unsigned long long)port_details->phy_bitmask));
-+              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
-+                  ioc->name, port_details->port, port_details->rphy));
-+      }
-+      dsaswideprintk(ioc, printk("\n"));
-+      mutex_unlock(&ioc->sas_topology_mutex);
- }
+       pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
+@@ -1911,6 +1929,9 @@ mpt_attach(struct pci_dev *pdev, const s
+       ioc->active = 0;
+       CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  
--static int
--mptsas_slave_configure(struct scsi_device *sdev)
-+/**
-+ *    mptsas_find_vtarget - obtain vtarget object for non-raid devices
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @channel:
-+ *    @id:
-+ *
-+ **/
-+static VirtTarget *
-+mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
-+{
-+      struct scsi_device              *sdev;
-+      VirtDevice                      *vdevice;
-+      VirtTarget                      *vtarget = NULL;
-+
-+      shost_for_each_device(sdev, ioc->sh) {
-+              if ((vdevice = sdev->hostdata) == NULL ||
-+                      (vdevice->vtarget == NULL))
-+                      continue;
-+              if ((vdevice->vtarget->tflags &
-+                  MPT_TARGET_FLAGS_RAID_COMPONENT ||
-+                  vdevice->vtarget->raidVolume))
-+                      continue;
-+              if (vdevice->vtarget->id == id &&
-+                  vdevice->vtarget->channel == channel)
-+                      vtarget = vdevice->vtarget;
-+      }
-+      return vtarget;
-+}
++      /* Set IOC ptr in the pcidev's driver data. */
++      pci_set_drvdata(ioc->pcidev, ioc);
 +
-+static void
-+mptsas_queue_device_delete(MPT_ADAPTER *ioc,
-+    MpiEventDataSasDeviceStatusChange_t *sas_event_data)
- {
-+      struct fw_event_work *fw_event;
-+      int sz;
--      if (sdev->channel == MPTSAS_RAID_CHANNEL)
--              goto out;
-+      sz = offsetof(struct fw_event_work, event_data) +
-+          sizeof(MpiEventDataSasDeviceStatusChange_t);
-+      fw_event = kzalloc(sz, GFP_ATOMIC);
-+      if (!fw_event) {
-+              printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
-+                  ioc->name, __FUNCTION__, __LINE__);
-+              return;
-+      }
-+      memcpy(fw_event->event_data, sas_event_data,
-+          sizeof(MpiEventDataSasDeviceStatusChange_t));
-+      fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE;
-+      fw_event->ioc = ioc;
-+      mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
-+}
+       /* Set lookup ptr. */
+       list_add_tail(&ioc->list, &ioc_list);
  
--      sas_read_port_mode_page(sdev);
-+static void
-+mptsas_queue_rescan(MPT_ADAPTER *ioc)
-+{
-+      struct fw_event_work *fw_event;
-+      int sz;
-- out:
--      return mptscsih_slave_configure(sdev);
-+      sz = offsetof(struct fw_event_work, event_data);
-+      fw_event = kzalloc(sz, GFP_ATOMIC);
-+      if (!fw_event) {
-+              printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
-+                  ioc->name, __FUNCTION__, __LINE__);
-+              return;
-+      }
-+      fw_event->event = -1;
-+      fw_event->ioc = ioc;
-+      mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
+@@ -1979,10 +2000,11 @@ mpt_attach(struct pci_dev *pdev, const s
+       return 0;
  }
  
-+
-+/**
-+ *    mptsas_target_reset - Issues TARGET_RESET to end device using
-+ *    handshaking method
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @channel:
-+ *    @id:
-+ *
-+ *    Returns (1) success
-+ *            (0) failure
-+ *
-+ **/
- static int
--mptsas_target_alloc(struct scsi_target *starget)
-+mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_detach - Remove a PCI intelligent MPT adapter.
+  *    @pdev: Pointer to pci_dev structure
+- **/
++ */
+ void
+ mpt_detach(struct pci_dev *pdev)
  {
--      struct Scsi_Host *host = dev_to_shost(&starget->dev);
--      MPT_SCSI_HOST           *hd = shost_priv(host);
--      VirtTarget              *vtarget;
--      u8                      id, channel;
--      struct sas_rphy         *rphy;
--      struct mptsas_portinfo  *p;
--      int                      i;
--      MPT_ADAPTER             *ioc = hd->ioc;
-+      MPT_FRAME_HDR   *mf;
-+      SCSITaskMgmt_t  *pScsiTm;
--      vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
--      if (!vtarget)
--              return -ENOMEM;
-+      if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0)
-+              return 0;
--      vtarget->starget = starget;
--      vtarget->ioc_id = ioc->id;
--      vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
--      id = starget->id;
--      channel = 0;
-+      if ((mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc)) == NULL) {
-+              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames @%d!!\n",
-+                  ioc->name,__FUNCTION__, __LINE__));
-+              goto out_fail;
-+      }
--      /*
--       * RAID volumes placed beyond the last expected port.
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
-+              ioc->name, mf));
-+
-+      /* Format the Request
+@@ -1995,10 +2017,10 @@ mpt_detach(struct pci_dev *pdev)
+       /*
+        * Stop polling ioc for fault condition
         */
--      if (starget->channel == MPTSAS_RAID_CHANNEL) {
--              for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
--                      if (id == ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID)
--                              channel = ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus;
--              goto out;
--      }
-+      pScsiTm = (SCSITaskMgmt_t *) mf;
-+      memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
-+      pScsiTm->TargetID = id;
-+      pScsiTm->Bus = channel;
-+      pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
-+      pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
-+      pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
--      rphy = dev_to_rphy(starget->dev.parent);
--      mutex_lock(&ioc->sas_topology_mutex);
--      list_for_each_entry(p, &ioc->sas_topology, list) {
--              for (i = 0; i < p->num_phys; i++) {
--                      if (p->phy_info[i].attached.sas_address !=
--                                      rphy->identify.sas_address)
--                              continue;
--                      id = p->phy_info[i].attached.id;
--                      channel = p->phy_info[i].attached.channel;
--                      mptsas_set_starget(&p->phy_info[i], starget);
-+      DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
--                      /*
--                       * Exposing hidden raid components
--                       */
--                      if (mptscsih_is_phys_disk(ioc, channel, id)) {
--                              id = mptscsih_raid_id_to_num(ioc,
--                                              channel, id);
--                              vtarget->tflags |=
--                                  MPT_TARGET_FLAGS_RAID_COMPONENT;
--                              p->phy_info[i].attached.phys_disk_num = id;
--                      }
--                      mutex_unlock(&ioc->sas_topology_mutex);
--                      goto out;
--              }
--      }
--      mutex_unlock(&ioc->sas_topology_mutex);
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+         "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
-+         ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
--      kfree(vtarget);
--      return -ENXIO;
-+      mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
-- out:
--      vtarget->id = id;
--      vtarget->channel = channel;
--      starget->hostdata = vtarget;
-+      return 1;
-+
-+ out_fail:
-+
-+      mpt_clear_taskmgmt_in_progress_flag(ioc);
+-      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
++      spin_lock_irqsave(&ioc->fault_reset_work_lock, flags);
+       wq = ioc->reset_work_q;
+       ioc->reset_work_q = NULL;
+-      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
++      spin_unlock_irqrestore(&ioc->fault_reset_work_lock, flags);
+       cancel_delayed_work(&ioc->fault_reset_work);
+       destroy_workqueue(wq);
+@@ -2030,11 +2052,12 @@ mpt_detach(struct pci_dev *pdev)
+  * Power Management
+  */
+ #ifdef CONFIG_PM
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_suspend - Fusion MPT base driver suspend routine.
+  *    @pdev: Pointer to pci_dev structure
+  *    @state: new state to enter
+- **/
++ */
+ int
+ mpt_suspend(struct pci_dev *pdev, pm_message_t state)
+ {
+@@ -2069,10 +2092,11 @@ mpt_suspend(struct pci_dev *pdev, pm_mes
        return 0;
  }
--
-+/**
-+ * mptsas_target_reset_queue -
-+ * @ioc: Pointer to MPT_ADAPTER structure
-+ * @sas_event_data:
-+ *
-+ * Receive request for TARGET_RESET after
-+ * recieving an firmware event NOT_RESPONDING_EVENT, then put command in
-+ * link list and queue if task_queue already in use.
-+ **/
- static void
--mptsas_target_destroy(struct scsi_target *starget)
-+mptsas_target_reset_queue(MPT_ADAPTER *ioc,
-+    EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
- {
--      struct Scsi_Host *host = dev_to_shost(&starget->dev);
--      MPT_SCSI_HOST           *hd = shost_priv(host);
--      struct sas_rphy         *rphy;
--      struct mptsas_portinfo  *p;
--      int                      i;
--      MPT_ADAPTER *ioc = hd->ioc;
-+      MPT_SCSI_HOST   *hd = shost_priv(ioc->sh);
-+      VirtTarget *vtarget = NULL;
-+      struct mptsas_target_reset_event        *target_reset_list;
-+      u8              id, channel;
--      if (!starget->hostdata)
--              return;
-+      id = sas_event_data->TargetID;
-+      channel = sas_event_data->Bus;
--      if (starget->channel == MPTSAS_RAID_CHANNEL)
--              goto out;
-+      if ((vtarget = mptsas_find_vtarget(ioc, channel, id))) {
-+              if (!ioc->disable_hotplug_remove)
-+                      vtarget->deleted = 1; /* block IO */
-+      }
  
--      rphy = dev_to_rphy(starget->dev.parent);
--      list_for_each_entry(p, &ioc->sas_topology, list) {
--              for (i = 0; i < p->num_phys; i++) {
--                      if (p->phy_info[i].attached.sas_address !=
--                                      rphy->identify.sas_address)
--                              continue;
--                      mptsas_set_starget(&p->phy_info[i], NULL);
--                      goto out;
--              }
-+      target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event),
-+          GFP_ATOMIC);
-+      if (!target_reset_list) {
-+              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n",
-+                  ioc->name,__FUNCTION__, __LINE__));
-+              return;
-       }
-- out:
--      kfree(starget->hostdata);
--      starget->hostdata = NULL;
--}
-+      memcpy(&target_reset_list->sas_event_data, sas_event_data,
-+              sizeof(*sas_event_data));
-+      list_add_tail(&target_reset_list->list, &hd->target_reset_list);
-+
-+      target_reset_list->time_count = jiffies;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_resume - Fusion MPT base driver resume routine.
+  *    @pdev: Pointer to pci_dev structure
+- **/
++ */
+ int
+ mpt_resume(struct pci_dev *pdev)
+ {
+@@ -2132,7 +2156,9 @@ mpt_resume(struct pci_dev *pdev)
  
-+      if (mptsas_target_reset(ioc, channel, id))
-+              target_reset_list->target_reset_issued = 1;
-+}
+       /* bring ioc to operational state */
+       printk(MYIOC_s_INFO_FMT "Sending mpt_do_ioc_recovery\n", ioc->name);
+-      if ((recovery_state = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP, CAN_SLEEP)) != 0)
++      recovery_state = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
++                                              CAN_SLEEP);
++      if (recovery_state != 0)
+               printk(MYIOC_s_WARN_FMT "pci-resume: Cannot recover, "
+                   "error:[%x]\n", ioc->name, recovery_state);
+       else
+@@ -2158,6 +2184,7 @@ mpt_signal_reset(u8 index, MPT_ADAPTER *
+       return (MptResetHandlers[index])(ioc, reset_phase);
+ }
  
-+/**
-+ *    mptsas_taskmgmt_complete - Completion for TARGET_RESET after
-+ *    NOT_RESPONDING_EVENT, enable work queue to finish off removing device
-+ *    from upper layers. then send next TARGET_RESET in the queue.
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *
-+ **/
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_do_ioc_recovery - Initialize or recover MPT adapter.
+  *    @ioc: Pointer to MPT adapter structure
+@@ -2176,7 +2203,9 @@ mpt_signal_reset(u8 index, MPT_ADAPTER *
+  *            -2 if READY but IOCFacts Failed
+  *            -3 if READY but PrimeIOCFifos Failed
+  *            -4 if READY but IOCInit Failed
+- **/
++ *            -5 if failed to enable_device and/or request_selected_regions
++ *            -6 if failed to upload firmware
++ */
  static int
--mptsas_slave_alloc(struct scsi_device *sdev)
-+mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
+ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
  {
--      struct Scsi_Host        *host = sdev->host;
--      MPT_SCSI_HOST           *hd = shost_priv(host);
--      struct sas_rphy         *rphy;
--      struct mptsas_portinfo  *p;
--      VirtDevice              *vdevice;
--      struct scsi_target      *starget;
--      int                     i;
--      MPT_ADAPTER *ioc = hd->ioc;
-+      MPT_SCSI_HOST   *hd = shost_priv(ioc->sh);
-+        struct list_head *head = &hd->target_reset_list;
-+      struct mptsas_target_reset_event        *target_reset_list;
-+      u8              id, channel;
-+      SCSITaskMgmtReply_t *pScsiTmReply;
--      vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
--      if (!vdevice) {
--              printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
--                              ioc->name, sizeof(VirtDevice));
--              return -ENOMEM;
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
-+          "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
-+
-+      pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
-+      if (pScsiTmReply) {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
-+                  "\ttask_type = 0x%02X, iocstatus = 0x%04X "
-+                  "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
-+                  "term_cmnds = %d\n", ioc->name,
-+                  pScsiTmReply->Bus, pScsiTmReply->TargetID,
-+                  pScsiTmReply->TaskType,
-+                  le16_to_cpu(pScsiTmReply->IOCStatus),
-+                  le32_to_cpu(pScsiTmReply->IOCLogInfo),
-+                  pScsiTmReply->ResponseCode,
-+                  le32_to_cpu(pScsiTmReply->TerminationCount)));
-+
-+              if (pScsiTmReply->ResponseCode)
-+                      mptscsih_taskmgmt_response_code(ioc,
-+                      pScsiTmReply->ResponseCode);
-+      }
-+
-+      if (pScsiTmReply && (pScsiTmReply->TaskType ==
-+          MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
-+           MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) {
-+              ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
-+              ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
-+              memcpy(ioc->taskmgmt_cmds.reply, mr,
-+                  min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
-+              if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
-+                      ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
-+                      complete(&ioc->taskmgmt_cmds.done);
-+                      return 1;
-+              }
-+              return 0;
-       }
--      starget = scsi_target(sdev);
--      vdevice->vtarget = starget->hostdata;
--      if (sdev->channel == MPTSAS_RAID_CHANNEL)
--              goto out;
-+      mpt_clear_taskmgmt_in_progress_flag(ioc);
--      rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
--      mutex_lock(&ioc->sas_topology_mutex);
--      list_for_each_entry(p, &ioc->sas_topology, list) {
--              for (i = 0; i < p->num_phys; i++) {
--                      if (p->phy_info[i].attached.sas_address !=
--                                      rphy->identify.sas_address)
--                              continue;
--                      vdevice->lun = sdev->lun;
--                      /*
--                       * Exposing hidden raid components
--                       */
--                      if (mptscsih_is_phys_disk(ioc,
--                          p->phy_info[i].attached.channel,
--                          p->phy_info[i].attached.id))
--                              sdev->no_uld_attach = 1;
--                      mutex_unlock(&ioc->sas_topology_mutex);
--                      goto out;
--              }
-+      if (list_empty(head))
-+              return 1;
-+
-+      target_reset_list = list_entry(head->next,
-+          struct mptsas_target_reset_event, list);
-+
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "TaskMgmt: completed (%d seconds)\n",
-+          ioc->name, jiffies_to_msecs(jiffies -
-+          target_reset_list->time_count)/1000));
-+
-+      id = pScsiTmReply->TargetID;
-+      channel = pScsiTmReply->Bus;
-+      target_reset_list->time_count = jiffies;
-+
-+      /*
-+       * retry target reset
-+       */
-+      if (!target_reset_list->target_reset_issued) {
-+              if (mptsas_target_reset(ioc, channel, id))
-+                      target_reset_list->target_reset_issued = 1;
-+              return 1;
+@@ -2217,14 +2246,16 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
+                       if (reset_alt_ioc_active && ioc->alt_ioc) {
+                               /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
+-                              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": alt-ioc reply irq re-enabled\n",
++                              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                                      ": alt-ioc reply irq re-enabled\n",
+                                   ioc->alt_ioc->name));
+                               CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
+                               ioc->alt_ioc->active = 1;
+                       }
+               } else {
+-                      printk(MYIOC_s_WARN_FMT "NOT READY WARNING!\n", ioc->name);
++                      printk(MYIOC_s_WARN_FMT "NOT READY WARNING!\n",
++                          ioc->name);
+               }
+               ret = -1;
+               goto out;
+@@ -2238,7 +2269,8 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
+                       alt_ioc_ready = 1;
+               else
+                       printk(MYIOC_s_WARN_FMT
+-                          ": alt-ioc Not ready WARNING!\n", ioc->alt_ioc->name);
++                          ": alt-ioc Not ready WARNING!\n",
++                          ioc->alt_ioc->name);
        }
--      mutex_unlock(&ioc->sas_topology_mutex);
  
--      kfree(vdevice);
--      return -ENXIO;
-+      /*
-+       * enable work queue to remove device from upper layers
-+       */
-+      list_del(&target_reset_list->list);
-+      if ((mptsas_find_vtarget(ioc, channel, id)) && !ioc->fw_events_off)
-+              mptsas_queue_device_delete(ioc, &target_reset_list->sas_event_data);
-- out:
--      vdevice->vtarget->num_luns++;
--      sdev->hostdata = vdevice;
--      return 0;
-+
-+      /*
-+       * issue target reset to next device in the queue
-+       */
-+
-+      head = &hd->target_reset_list;
-+      if (list_empty(head))
-+              return 1;
-+
-+      target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
-+          list);
-+
-+      id = target_reset_list->sas_event_data.TargetID;
-+      channel = target_reset_list->sas_event_data.Bus;
-+      target_reset_list->time_count = jiffies;
-+
-+      if (mptsas_target_reset(ioc, channel, id))
-+              target_reset_list->target_reset_issued = 1;
-+
-+      return 1;
+       for (ii=0; ii<5; ii++) {
+@@ -2340,8 +2372,9 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
+               ret = -4;
+ // NEW!
+       if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
+-              printk(MYIOC_s_WARN_FMT ": alt-ioc (%d) FIFO mgmt alloc WARNING!\n",
+-                              ioc->alt_ioc->name, rc);
++              printk(MYIOC_s_WARN_FMT
++                  ": alt-ioc (%d) FIFO mgmt alloc WARNING!\n",
++                  ioc->alt_ioc->name, rc);
+               alt_ioc_ready = 0;
+               reset_alt_ioc_active = 0;
+       }
+@@ -2382,7 +2415,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
+                               } else {
+                                       printk(MYIOC_s_WARN_FMT
+                                           "firmware upload failure!\n", ioc->name);
+-                                      ret = -5;
++                                      ret = -6;
+                               }
+                       }
+               }
+@@ -2392,8 +2425,8 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
+        *  and EventAck handling.
+        */
+       if ((ret == 0) && (!ioc->facts.EventState)) {
+-              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "SendEventNotification\n",
+-                  ioc->name));
++              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
++                      "SendEventNotification\n", ioc->name));
+               ret = SendEventNotification(ioc, 1, sleepFlag); /* 1=Enable */
+       }
+@@ -2408,9 +2441,11 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
+       if (rc == 0) {  /* alt ioc */
+               if (reset_alt_ioc_active && ioc->alt_ioc) {
+                       /* (re)Enable alt-IOC! (reply interrupt) */
+-                      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "alt-ioc reply irq re-enabled\n",
++                      dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                              "alt-ioc reply irq re-enabled\n",
+                               ioc->alt_ioc->name));
+-                      CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
++                      CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask,
++                          MPI_HIM_DIM);
+                       ioc->alt_ioc->active = 1;
+               }
+       }
+@@ -2427,7 +2462,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
+               /*
+                * Initalize link list for inactive raid volumes.
+                */
+-              init_MUTEX(&ioc->raid_data.inactive_list_mutex);
++              mutex_init(&ioc->raid_data.inactive_list_mutex);
+               INIT_LIST_HEAD(&ioc->raid_data.inactive_list);
+               switch (ioc->bus_type) {
+@@ -2461,7 +2496,8 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
+                                *  (LANPage1_t stuff)
+                                */
+                               (void) GetLanConfigPages(ioc);
+-                              a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
++                              a = (u8 *)
++                                  &ioc->lan_cnfg_page1.HardwareAddressLow;
+                               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                                       "LanAddr = %02X:%02X:%02X"
+                                       ":%02X:%02X:%02X\n",
+@@ -2507,6 +2543,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
+       return ret;
  }
  
-+/**
-+ *    mptsas_ioc_reset -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @reset_phase:
-+ *
-+ **/
- static int
--mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
-+mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_detect_bound_ports - Search for matching PCI bus/dev_function
+  *    @ioc: Pointer to MPT adapter structure
+@@ -2518,7 +2555,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u3
+  *
+  *    If match on PCI dev_function +/-1 is found, bind the two MPT adapters
+  *    using alt_ioc pointer fields in their %MPT_ADAPTER structures.
+- **/
++ */
+ static void
+ mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
+ {
+@@ -2544,15 +2581,19 @@ mpt_detect_bound_ports(MPT_ADAPTER *ioc,
+               if (_pcidev == peer) {
+                       /* Paranoia checks */
+                       if (ioc->alt_ioc != NULL) {
+-                              printk(MYIOC_s_WARN_FMT "Oops, already bound (%s <==> %s)!\n",
+-                                      ioc->name, ioc->name, ioc->alt_ioc->name);
++                              printk(MYIOC_s_WARN_FMT
++                                  "Oops, already bound (%s <==> %s)!\n",
++                                  ioc->name, ioc->name, ioc->alt_ioc->name);
+                               break;
+                       } else if (ioc_srch->alt_ioc != NULL) {
+-                              printk(MYIOC_s_WARN_FMT "Oops, already bound (%s <==> %s)!\n",
+-                                      ioc_srch->name, ioc_srch->name, ioc_srch->alt_ioc->name);
++                              printk(MYIOC_s_WARN_FMT
++                                  "Oops, already bound (%s <==> %s)!\n",
++                                  ioc_srch->name, ioc_srch->name,
++                                  ioc_srch->alt_ioc->name);
+                               break;
+                       }
+-                      dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FOUND! binding %s <==> %s\n",
++                      dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                              "FOUND! binding %s <==> %s\n",
+                               ioc->name, ioc->name, ioc_srch->name));
+                       ioc_srch->alt_ioc = ioc;
+                       ioc->alt_ioc = ioc_srch;
+@@ -2561,10 +2602,11 @@ mpt_detect_bound_ports(MPT_ADAPTER *ioc,
+       pci_dev_put(peer);
+ }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_adapter_disable - Disable misbehaving MPT adapter.
+  *    @ioc: Pointer to MPT adapter structure
+- **/
++ */
+ static void
+ mpt_adapter_disable(MPT_ADAPTER *ioc)
  {
--      VirtDevice      *vdevice = SCpnt->device->hostdata;
--
--      if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
--              SCpnt->result = DID_NO_CONNECT << 16;
--              done(SCpnt);
--              return 0;
--      }
-+      MPT_SCSI_HOST   *hd;
-+      int rc;
--//    scsi_print_command(SCpnt);
-+      rc = mptscsih_ioc_reset(ioc, reset_phase);
-+      if ((ioc->bus_type != SAS) || (!rc))
-+              return rc;
+@@ -2577,7 +2619,8 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
+               if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)
+                   ioc->cached_fw, CAN_SLEEP)) < 0) {
+                       printk(MYIOC_s_WARN_FMT
+-                          ": firmware downloadboot failure (%d)!\n", ioc->name, ret);
++                          ": firmware downloadboot failure (%d)!\n",
++                          ioc->name, ret);
+               }
+       }
  
--      return mptscsih_qcmd(SCpnt,done);
--}
-+      hd = shost_priv(ioc->sh);
-+      if (!hd->ioc)
-+              goto out;
+@@ -2585,15 +2628,15 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
+        * Put the controller into ready state (if its not already)
+        */
+       if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY) {
+-              if(!SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET,
++              if (!SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET,
+                   CAN_SLEEP)) {
+                       if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY)
+                               printk(MYIOC_s_ERR_FMT "%s:  IOC msg unit "
+                                   "reset failed to put ioc in ready state!\n",
+-                                  ioc->name, __FUNCTION__);
++                                  ioc->name, __func__);
+               } else
+                       printk(MYIOC_s_ERR_FMT "%s:  IOC msg unit reset "
+-                          "failed!\n", ioc->name, __FUNCTION__);
++                          "failed!\n", ioc->name, __func__);
+       }
  
-+      switch(reset_phase) {
-+      case MPT_IOC_SETUP_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __FUNCTION__));
-+              mptsas_fw_event_off(ioc);
-+              break;
-+      case MPT_IOC_PRE_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __FUNCTION__));
-+              break;
-+      case MPT_IOC_POST_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_POST_RESET\n", ioc->name, __FUNCTION__));
-+              if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
-+                      ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
-+                      complete(&ioc->sas_mgmt.done);
-+              }
-+              mptsas_cleanup_fw_event_q(ioc);
-+              mptsas_queue_rescan(ioc);
-+              mptsas_fw_event_on(ioc);
-+              break;
-+      default:
-+              break;
-+      }
+       /* Disable adapter interrupts! */
+@@ -2607,8 +2650,9 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
  
--static struct scsi_host_template mptsas_driver_template = {
--      .module                         = THIS_MODULE,
--      .proc_name                      = "mptsas",
--      .proc_info                      = mptscsih_proc_info,
--      .name                           = "MPT SPI Host",
--      .info                           = mptscsih_info,
--      .queuecommand                   = mptsas_qcmd,
--      .target_alloc                   = mptsas_target_alloc,
--      .slave_alloc                    = mptsas_slave_alloc,
--      .slave_configure                = mptsas_slave_configure,
--      .target_destroy                 = mptsas_target_destroy,
--      .slave_destroy                  = mptscsih_slave_destroy,
--      .change_queue_depth             = mptscsih_change_queue_depth,
--      .eh_abort_handler               = mptscsih_abort,
--      .eh_device_reset_handler        = mptscsih_dev_reset,
--      .eh_bus_reset_handler           = mptscsih_bus_reset,
--      .eh_host_reset_handler          = mptscsih_host_reset,
--      .bios_param                     = mptscsih_bios_param,
--      .can_queue                      = MPT_FC_CAN_QUEUE,
--      .this_id                        = -1,
--      .sg_tablesize                   = MPT_SCSI_SG_DEPTH,
--      .max_sectors                    = 8192,
--      .cmd_per_lun                    = 7,
--      .use_clustering                 = ENABLE_CLUSTERING,
--      .shost_attrs                    = mptscsih_host_attrs,
--};
-+ out:
-+      return rc;
-+}
+       if (ioc->alloc != NULL) {
+               sz = ioc->alloc_sz;
+-              dexitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "free  @ %p, sz=%d bytes\n",
+-                      ioc->name, ioc->alloc, ioc->alloc_sz));
++              dexitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "free  @ %p, sz=%d bytes\n", ioc->name,
++                      ioc->alloc, ioc->alloc_sz));
+               pci_free_consistent(ioc->pcidev, sz,
+                               ioc->alloc, ioc->alloc_dma);
+               ioc->reply_frames = NULL;
+@@ -2666,10 +2710,11 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
+                   MPI_DB_HPBAC_FREE_BUFFER, NO_SLEEP)) != 0) {
+                       printk(MYIOC_s_ERR_FMT
+                          ": %s: host page buffers free failed (%d)!\n",
+-                          ioc->name, __FUNCTION__, ret);
++                          ioc->name, __func__, ret);
+               }
+-              dexitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HostPageBuffer free  @ %p, sz=%d bytes\n",
+-                      ioc->name, ioc->HostPageBuffer, ioc->HostPageBuffer_sz));
++              dexitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "HostPageBuffer free  @ %p, sz=%d bytes\n", ioc->name,
++                      ioc->HostPageBuffer, ioc->HostPageBuffer_sz));
+               pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
+                               ioc->HostPageBuffer,
+                               ioc->HostPageBuffer_dma);
+@@ -2681,13 +2726,14 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
+       pci_set_drvdata(ioc->pcidev, NULL);
+ }
  
--static int mptsas_get_linkerrors(struct sas_phy *phy)
-+/**
-+ *    mptsas_sas_enclosure_pg0 -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @enclosure:
-+ *    @form:
-+ *    @form_specific:
-+ *
-+ **/
-+static int
-+mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
-+              u32 form, u32 form_specific)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_adapter_dispose - Free all resources associated with an MPT adapter
+  *    @ioc: Pointer to MPT adapter structure
+  *
+  *    This routine unregisters h/w resources and frees all alloc'd memory
+  *    associated with a MPT adapter structure.
+- **/
++ */
+ static void
+ mpt_adapter_dispose(MPT_ADAPTER *ioc)
  {
--      MPT_ADAPTER *ioc = phy_to_ioc(phy);
-       ConfigExtendedPageHeader_t hdr;
-       CONFIGPARMS cfg;
--      SasPhyPage1_t *buffer;
-+      SasEnclosurePage0_t *buffer;
-       dma_addr_t dma_handle;
-       int error;
-+      __le64 le_identifier;
--      /* FIXME: only have link errors on local phys */
--      if (!scsi_is_sas_phy_local(phy))
--              return -EINVAL;
--
--      hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
--      hdr.ExtPageLength = 0;
--      hdr.PageNumber = 1 /* page number 1*/;
--      hdr.Reserved1 = 0;
--      hdr.Reserved2 = 0;
-+      memset(&hdr, 0, sizeof(hdr));
-+      hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
-+      hdr.PageNumber = 0;
-       hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
--      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
-       cfg.cfghdr.ehdr = &hdr;
-       cfg.physAddr = -1;
--      cfg.pageAddr = phy->identify.phy_identifier;
-+      cfg.pageAddr = form + form_specific;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
--      cfg.dir = 0;    /* read */
--      cfg.timeout = 10;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
-       error = mpt_config(ioc, &cfg);
-       if (error)
--              return error;
--      if (!hdr.ExtPageLength)
--              return -ENXIO;
-+              goto out;
-+      if (!hdr.ExtPageLength) {
-+              error = -ENXIO;
-+              goto out;
-+      }
+@@ -2718,7 +2764,8 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)
+ #if defined(CONFIG_MTRR) && 0
+       if (ioc->mtrr_reg > 0) {
+               mtrr_del(ioc->mtrr_reg, 0, 0);
+-              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MTRR region de-registered\n", ioc->name));
++              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "MTRR region de-registered\n", ioc->name));
+       }
+ #endif
  
-       buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
--                                    &dma_handle);
--      if (!buffer)
--              return -ENOMEM;
-+                      &dma_handle);
-+      if (!buffer) {
-+              error = -ENOMEM;
-+              goto out;
-+      }
+@@ -2727,7 +2774,8 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)
  
-       cfg.physAddr = dma_handle;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-@@ -1095,289 +1427,852 @@ static int mptsas_get_linkerrors(struct 
-       if (error)
-               goto out_free_consistent;
+       sz_last = ioc->alloc_total;
+       dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "free'd %d of %d bytes\n",
+-                      ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
++                      ioc->name, sz_first-sz_last+(int)sizeof(*ioc),
++                      sz_first));
  
--      mptsas_print_phy_pg1(ioc, buffer);
--
--      phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
--      phy->running_disparity_error_count =
--              le32_to_cpu(buffer->RunningDisparityErrorCount);
--      phy->loss_of_dword_sync_count =
--              le32_to_cpu(buffer->LossDwordSynchCount);
--      phy->phy_reset_problem_count =
--              le32_to_cpu(buffer->PhyResetProblemCount);
-+      /* save config data */
-+      memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
-+      enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
-+      enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
-+      enclosure->flags = le16_to_cpu(buffer->Flags);
-+      enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
-+      enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
-+      enclosure->start_id = buffer->StartTargetID;
-+      enclosure->start_channel = buffer->StartBus;
-+      enclosure->sep_id = buffer->SEPTargetID;
-+      enclosure->sep_channel = buffer->SEPBus;
-  out_free_consistent:
-       pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-                           buffer, dma_handle);
-+ out:
-       return error;
+       if (ioc->alt_ioc)
+               ioc->alt_ioc->alt_ioc = NULL;
+@@ -2735,10 +2783,11 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)
+       kfree(ioc);
  }
  
--static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
--              MPT_FRAME_HDR *reply)
-+/**
-+ *    mptsas_get_lun_number - returns the first entry in report_luns table
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @channel:
-+ *    @id:
-+ *    @lun:
-+ *
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    MptDisplayIocCapabilities - Disply IOC's capabilities.
+  *    @ioc: Pointer to MPT adapter structure
+- **/
 + */
-+static int
-+mptsas_get_lun_number(MPT_ADAPTER *ioc, u8 channel, u8 id, int *lun)
+ static void
+ MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
  {
--      ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_COMMAND_GOOD;
--      if (reply != NULL) {
--              ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_RF_VALID;
--              memcpy(ioc->sas_mgmt.reply, reply,
--                  min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
--      }
--      complete(&ioc->sas_mgmt.done);
--      return 1;
--}
-+      INTERNAL_CMD    *iocmd;
-+      struct scsi_lun *lun_data;
-+      dma_addr_t      lun_data_dma;
-+      u32             lun_data_len;
-+      u8              *data;
-+      MPT_SCSI_HOST   *hd;
-+      int             rc;
-+      u32             length, num_luns;
--static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
--{
--      MPT_ADAPTER *ioc = phy_to_ioc(phy);
--      SasIoUnitControlRequest_t *req;
--      SasIoUnitControlReply_t *reply;
--      MPT_FRAME_HDR *mf;
--      MPIHeader_t *hdr;
--      unsigned long timeleft;
--      int error = -ERESTARTSYS;
-+      iocmd = NULL;
-+      hd = shost_priv(ioc->sh);
-+      lun_data_len = (255 * sizeof(struct scsi_lun));
-+      lun_data = pci_alloc_consistent(ioc->pcidev, lun_data_len,
-+          &lun_data_dma);
-+      if (!lun_data) {
-+              printk(MYIOC_s_ERR_FMT "%s: pci_alloc_consistent(%d) FAILED!\n",
-+                  ioc->name, __FUNCTION__, lun_data_len);
-+              rc = -ENOMEM;
-+              goto out;
-+      }
+@@ -2777,6 +2826,7 @@ MptDisplayIocCapabilities(MPT_ADAPTER *i
+       printk("}\n");
+ }
  
--      /* FIXME: fusion doesn't allow non-local phy reset */
--      if (!scsi_is_sas_phy_local(phy))
--              return -EINVAL;
-+      iocmd = kzalloc(sizeof(INTERNAL_CMD), GFP_KERNEL);
-+      if (!iocmd) {
-+              printk(MYIOC_s_ERR_FMT "%s: kzalloc(%zd) FAILED!\n",
-+                  ioc->name, __FUNCTION__, sizeof(INTERNAL_CMD));
-+              rc = -ENOMEM;
-+              goto out;
-+      }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    MakeIocReady - Get IOC to a READY state, using KickStart if needed.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -2790,7 +2840,7 @@ MptDisplayIocCapabilities(MPT_ADAPTER *i
+  *            -2 - Msg Unit Reset Failed
+  *            -3 - IO Unit Reset Failed
+  *            -4 - IOC owned by a PEER
+- **/
++ */
+ static int
+ MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
+ {
+@@ -2804,7 +2854,8 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
  
--      /* not implemented for expanders */
--      if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
--              return -ENXIO;
-+      /*
-+       * Report Luns
-+       */
-+      iocmd->cmd = REPORT_LUNS;
-+      iocmd->data_dma = lun_data_dma;
-+      iocmd->data = (u8 *)lun_data;
-+      iocmd->size = lun_data_len;
-+      iocmd->channel = channel;
-+      iocmd->id = id;
--      if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
-+      if ((rc = mptscsih_do_cmd(hd, iocmd)) < 0) {
-+              printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d: "
-+                  "report_luns failed due to rc=0x%x\n", ioc->name,
-+                  __FUNCTION__, channel, id, rc);
-               goto out;
-+      }
+       /* Get current [raw] IOC state  */
+       ioc_state = mpt_GetIocState(ioc, 0);
+-      dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MakeIocReady, [raw] state=%08x\n", ioc->name, ioc_state));
++      dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++              "MakeIocReady, [raw] state=%08x\n", ioc->name, ioc_state));
  
--      mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
--      if (!mf) {
--              error = -ENOMEM;
--              goto out_unlock;
-+      if (rc != MPT_SCANDV_GOOD) {
-+              printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d: "
-+                  "report_luns failed due to rc=0x%x\n", ioc->name,
-+                  __FUNCTION__, channel, id, rc);
-+              rc = -rc;
-+              goto out;
+       /*
+        *      Check to see if IOC got left/stuck in doorbell handshake
+@@ -2817,8 +2868,10 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
        }
  
--      hdr = (MPIHeader_t *) mf;
--      req = (SasIoUnitControlRequest_t *)mf;
--      memset(req, 0, sizeof(SasIoUnitControlRequest_t));
--      req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
--      req->MsgContext = hdr->MsgContext;
--      req->Operation = hard_reset ?
--              MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
--      req->PhyNum = phy->identify.phy_identifier;
-+      data = (u8 *)lun_data;
-+      length = ((data[0] << 24) | (data[1] << 16) |
-+          (data[2] << 8) | (data[3] << 0));
--      mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
-+      num_luns = (length / sizeof(struct scsi_lun));
-+      if (!num_luns)
-+              goto out;
-+      /* return 1st lun in the list */
-+      *lun = scsilun_to_int(&lun_data[1]);
--      timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
--                      10 * HZ);
--      if (!timeleft) {
--              /* On timeout reset the board */
--              mpt_free_msg_frame(ioc, mf);
--              mpt_HardResetHandler(ioc, CAN_SLEEP);
--              error = -ETIMEDOUT;
--              goto out_unlock;
-+#if 0
-+      /* some debugging, left commented out */
-+      {
-+              struct scsi_lun *lunp;
-+              for (lunp = &lun_data[1]; lunp <= &lun_data[num_luns]; lunp++)
-+                      printk("%x\n", scsilun_to_int(lunp));
+       /* Is it already READY? */
+-      if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY) {
+-              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "IOC is in READY state\n",
++      if (!statefault &&
++          (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY) {
++              dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
++                      "IOC is in READY state\n",
+                   ioc->name));
+               return 0;
        }
-+#endif
--      /* a reply frame is expected */
--      if ((ioc->sas_mgmt.status &
--          MPT_IOCTL_STATUS_RF_VALID) == 0) {
--              error = -ENXIO;
--              goto out_unlock;
--      }
-+ out:
-+      if (lun_data)
-+              pci_free_consistent(ioc->pcidev, lun_data_len, lun_data,
-+                  lun_data_dma);
-+      kfree(iocmd);
-+      return rc;
-+}
+@@ -2894,8 +2947,9 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
  
--      /* process the completed Reply Message Frame */
--      reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
--      if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
--              printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
--                  ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
--              error = -ENXIO;
--              goto out_unlock;
-+/**
-+ * enum device_state -
-+ * @DEVICE_RETRY: need to retry the TUR
-+ * @DEVICE_ERROR: TUR return error, don't add device
-+ * @DEVICE_READY: device can be added
-+ *
-+ */
-+enum device_state{
-+      DEVICE_RETRY,
-+      DEVICE_ERROR,
-+      DEVICE_READY,
-+};
-+
-+/**
-+ * mptsas_test_unit_ready -
-+ * @ioc: Pointer to MPT_ADAPTER structure
-+ * @channel:
-+ * @id:
-+ * @count: retry count
-+ *
-+ */
-+enum device_state
-+mptsas_test_unit_ready(MPT_ADAPTER *ioc, u8 channel, u8 id, u16 count)
-+{
-+      INTERNAL_CMD    *iocmd;
-+      MPT_SCSI_HOST   *hd = shost_priv(ioc->sh);
-+      enum device_state       state;
-+      int                     rc;
-+      u8              skey, asc, ascq;
-+      u8              retry_ua;
-+
-+      if (count >= mpt_cmd_retry_count)
-+              return DEVICE_ERROR;
-+
-+      retry_ua = 0;
-+      iocmd = kzalloc(sizeof(INTERNAL_CMD), GFP_KERNEL);
-+      if (!iocmd) {
-+              printk(MYIOC_s_ERR_FMT "%s: kzalloc(%zd) FAILED!\n",
-+              __FUNCTION__, ioc->name, sizeof(INTERNAL_CMD));
-+              return DEVICE_ERROR;
-+      }
-+
-+      state = DEVICE_ERROR;
-+      iocmd->cmd = TEST_UNIT_READY;
-+      iocmd->data_dma = -1;
-+      iocmd->data = NULL;
-+
-+      if (mptscsih_is_phys_disk(ioc, channel, id)) {
-+              iocmd->flags |= MPT_ICFLAG_PHYS_DISK;
-+              iocmd->physDiskNum = mptscsih_raid_id_to_num(ioc, channel, id);
-+              iocmd->id = id;
-+      }
-+      iocmd->channel = channel;
-+      iocmd->id = id;
-+
-+ retry:
-+      devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_channel=%d "
-+          "fw_id=%d retry=%d\n", ioc->name, __FUNCTION__, channel, id, count));
-+      rc = mptscsih_do_cmd(hd, iocmd);
-+      devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rc=0x%02x\n",
-+          ioc->name, __FUNCTION__, rc));
-+      if (rc < 0) {
-+              printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d: "
-+                  "tur failed due to timeout\n", ioc->name,
-+                  __FUNCTION__, channel, id);
-+              goto tur_done;
-+      }
-+
-+      switch(rc) {
-+      case MPT_SCANDV_GOOD:
-+              state = DEVICE_READY;
-+              goto tur_done;
-+      case MPT_SCANDV_BUSY:
-+              devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: "
-+                  "fw_channel=%d fw_id=%d : device busy\n",
-+                  ioc->name, __FUNCTION__, channel, id));
-+              state = DEVICE_RETRY;
-+              break;
-+      case MPT_SCANDV_DID_RESET:
-+              devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: "
-+                  "fw_channel=%d fw_id=%d : did reset\n",
-+                  ioc->name, __FUNCTION__, channel, id));
-+              state = DEVICE_RETRY;
-+              break;
-+      case MPT_SCANDV_SENSE:
-+              skey = ioc->internal_cmds.sense[2] & 0x0F;
-+              asc = ioc->internal_cmds.sense[12];
-+              ascq = ioc->internal_cmds.sense[13];
-+
-+              devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: "
-+                  "fw_channel=%d fw_id=%d : [sense_key,asc,"
-+                  "ascq]: [0x%02x,0x%02x,0x%02x]\n", ioc->name,
-+                   __FUNCTION__, channel, id, skey, asc, ascq));
-+
-+              if (skey == UNIT_ATTENTION) {
-+                      if (!retry_ua) {
-+                              retry_ua++;
-+                              goto retry;
-+                      }
-+              } else if (skey == NOT_READY) {
-+                      /*
-+                       * medium isn't present
-+                       */
-+                      if (asc == 0x3a) {
-+                              state = DEVICE_READY;
-+                              goto tur_done;
-+                      }
-+                      /*
-+                       * LU becoming ready, or
-+                       * LU hasn't self-configured yet
-+                       */
-+                      if ((asc == 0x04 && ascq == 0x01) ||
-+                          (asc == 0x04 && ascq == 0x11) ||
-+                          asc == 0x3e) {
-+                              state = DEVICE_RETRY;
-+                              break;
-+                      }
-+              } else if (skey == ILLEGAL_REQUEST) {
-+              /* try sending a tur to a non-zero lun number */
-+                      if (!iocmd->lun && !mptsas_get_lun_number(ioc,
-+                          channel, id, &iocmd->lun) && iocmd->lun)
-+                              goto retry;
-+              }
-+              printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d : "
-+                  "tur failed due to [sense_key,asc,ascq]: "
-+                  "[0x%02x,0x%02x,0x%02x]\n", ioc->name,
-+                  __FUNCTION__, channel, id, skey, asc, ascq);
-+              goto tur_done;
-+      case MPT_SCANDV_SELECTION_TIMEOUT:
-+              printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d: "
-+                  "tur failed due to no device\n", ioc->name,
-+                  __FUNCTION__, channel,
-+                  id);
-+              goto tur_done;
-+      case MPT_SCANDV_SOME_ERROR:
-+              printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d: "
-+                  "tur failed due to some error\n", ioc->name,
-+                  __FUNCTION__,
-+                  channel, id);
-+              goto tur_done;
-+      default:
-+              printk(MYIOC_s_ERR_FMT
-+                  "%s: fw_channel=%d fw_id=%d: tur failed due to "
-+                  "unknown rc=0x%02x\n", ioc->name, __FUNCTION__,
-+                  channel, id, rc );
-+              goto tur_done;
-+      }
-+ tur_done:
-+      kfree(iocmd);
-+      return state;
-+}
-+
-+/**
-+ *    mptsas_issue_tlr - Enabling Transport Layer Retries
-+ *    @hd:
-+ *    @sdev:
-+ *
-+ **/
-+static void
-+mptsas_issue_tlr(MPT_SCSI_HOST *hd, struct scsi_device *sdev)
-+{
-+      INTERNAL_CMD    *iocmd;
-+      VirtDevice      *vdevice = sdev->hostdata;
-+      u8              retries;
-+      u8              rc;
-+      MPT_ADAPTER *ioc = hd->ioc;
-+
-+      if ( sdev->inquiry[8]  == 'H' &&
-+           sdev->inquiry[9]  == 'P' &&
-+           sdev->inquiry[10] == ' ' &&
-+           sdev->inquiry[11] == ' ' &&
-+           sdev->inquiry[12] == ' ' &&
-+           sdev->inquiry[13] == ' ' &&
-+           sdev->inquiry[14] == ' ' &&
-+           sdev->inquiry[15] == ' ' ) {
-+
-+              iocmd = kzalloc(sizeof(INTERNAL_CMD), GFP_KERNEL);
-+              if (!iocmd) {
-+                      printk(MYIOC_s_ERR_FMT "%s: kzalloc(%zd) FAILED!\n",
-+                      __FUNCTION__, ioc->name, sizeof(INTERNAL_CMD));
-+                      return;
-+              }
-+              iocmd->id = vdevice->vtarget->id;
-+              iocmd->channel = vdevice->vtarget->channel;
-+              iocmd->lun = vdevice->lun;
-+              iocmd->physDiskNum = -1;
-+              iocmd->cmd = TRANSPORT_LAYER_RETRIES;
-+              iocmd->data_dma = -1;
-+              for (retries = 0, rc = -1; retries < 3; retries++) {
-+                      rc = mptscsih_do_cmd(hd, iocmd);
-+                      if (!rc)
-+                              break;
-+              }
-+              if (rc != 0)
-+                      printk(MYIOC_s_DEBUG_FMT "unable to enable TLR on"
-+                         " fw_channel %d, fw_id %d, lun=%d\n",
-+                         ioc->name, vdevice->vtarget->channel,
-+                         vdevice->vtarget->id, sdev->lun);
-+              kfree(iocmd);
-       }
-+}
+               ii++; cntdn--;
+               if (!cntdn) {
+-                      printk(MYIOC_s_ERR_FMT "Wait IOC_READY state (0x%x) timeout(%d)!\n",
+-                                      ioc->name, ioc_state, (int)((ii+5)/HZ));
++                      printk(MYIOC_s_ERR_FMT
++                          "Wait IOC_READY state (0x%x) timeout(%d)!\n",
++                          ioc->name, ioc_state, (int)((ii+5)/HZ));
+                       return -ETIME;
+               }
  
--      error = 0;
-+/**
-+ *    mptsas_slave_configure -
-+ *    @sdev:
-+ *
-+ **/
-+static int
-+mptsas_slave_configure(struct scsi_device *sdev)
-+{
-+      struct Scsi_Host        *host = sdev->host;
-+      MPT_SCSI_HOST           *hd = shost_priv(host);
-+      MPT_ADAPTER             *ioc = hd->ioc;
-+      VirtDevice              *vdevice = sdev->hostdata;
-+
-+
-+      if (vdevice->vtarget->deleted) {
-+              sdev_printk(KERN_INFO, sdev, "clearing deleted flag\n");
-+              vdevice->vtarget->deleted = 0;
-+      }
+@@ -2916,6 +2970,7 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
+       return hard_reset_done;
+ }
  
-- out_unlock:
--      mutex_unlock(&ioc->sas_mgmt.mutex);
-+      /*
-+       * RAID volumes placed beyond the last expected port.
-+       * Ignore sending sas mode pages in that case..
-+       */
-+      if (sdev->channel == MPTSAS_RAID_CHANNEL) {
-+              mptsas_add_device_component_starget_ir(ioc, scsi_target(sdev));
-+              goto out;
-+      }
-+
-+      sas_read_port_mode_page(sdev);
-+
-+      mptsas_add_device_component_starget(ioc, scsi_target(sdev));
-+
-+      if (sdev->type == TYPE_TAPE &&
-+          (ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_TLR ))
-+              mptsas_issue_tlr(hd, sdev);
-  out:
--      return error;
-+
-+      return mptscsih_slave_configure(sdev);
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_GetIocState - Get the current state of a MPT adapter.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -2923,7 +2978,7 @@ MakeIocReady(MPT_ADAPTER *ioc, int force
+  *
+  *    Returns all IOC Doorbell register bits if cooked==0, else just the
+  *    Doorbell bits in MPI_IOC_STATE_MASK.
+- **/
++ */
+ u32
+ mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
+ {
+@@ -2939,6 +2994,7 @@ mpt_GetIocState(MPT_ADAPTER *ioc, int co
+       return cooked ? sc : s;
  }
  
-+/**
-+ *    mptsas_target_alloc -
-+ *    @starget:
-+ *
-+ **/
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    GetIocFacts - Send IOCFacts request to MPT adapter.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -2946,7 +3002,7 @@ mpt_GetIocState(MPT_ADAPTER *ioc, int co
+  *    @reason: If recovery, only update facts.
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
  static int
--mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
-+mptsas_target_alloc(struct scsi_target *starget)
+ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
  {
--      MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
--      int i, error;
--      struct mptsas_portinfo *p;
--      struct mptsas_enclosure enclosure_info;
--      u64 enclosure_handle;
-+      struct Scsi_Host *host = dev_to_shost(&starget->dev);
-+      MPT_SCSI_HOST           *hd = shost_priv(host);
-+      VirtTarget              *vtarget;
-+      u8                      id, channel;
-+      struct sas_rphy         *rphy;
-+      struct mptsas_portinfo  *p;
-+      int                      i;
-+      MPT_ADAPTER             *ioc = hd->ioc;
-+
-+      vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
-+      if (!vtarget)
-+              return -ENOMEM;
-+
-+      vtarget->starget = starget;
-+      vtarget->ioc_id = ioc->id;
-+      vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
-+      id = starget->id;
-+      channel = 0;
-+
-+      /*
-+       * RAID volumes placed beyond the last expected port.
-+       */
-+      if (starget->channel == MPTSAS_RAID_CHANNEL) {
-+              if (!ioc->raid_data.pIocPg2) {
-+                      kfree(vtarget);
-+                      return -ENXIO;
-+              }
-+              for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
-+                      if (id == ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID)
-+                              channel = ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus;
-+              vtarget->raidVolume = 1;
-+              goto out;
-+      }
+@@ -2961,9 +3017,9 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
  
-+      rphy = dev_to_rphy(starget->dev.parent);
-       mutex_lock(&ioc->sas_topology_mutex);
-       list_for_each_entry(p, &ioc->sas_topology, list) {
-               for (i = 0; i < p->num_phys; i++) {
--                      if (p->phy_info[i].attached.sas_address ==
--                          rphy->identify.sas_address) {
--                              enclosure_handle = p->phy_info[i].
--                                      attached.handle_enclosure;
--                              goto found_info;
-+                      if (p->phy_info[i].attached.sas_address !=
-+                          rphy->identify.sas_address)
-+                              continue;
-+                      id = p->phy_info[i].attached.id;
-+                      channel = p->phy_info[i].attached.channel;
-+                      mptsas_set_starget(&p->phy_info[i], starget);
-+
-+                      starget_printk(KERN_INFO, starget, MYIOC_s_FMT
-+                      "add device: fw_channel %d, fw_id %d, phy %d, sas_addr 0x%llx\n",
-+                      ioc->name, p->phy_info[i].attached.channel,
-+                      p->phy_info[i].attached.id, p->phy_info[i].attached.phy_id,
-+                      (unsigned long long)p->phy_info[i].attached.sas_address);
-+
-+                      /*
-+                       * Exposing hidden raid components
-+                       */
-+                      if (mptscsih_is_phys_disk(ioc, channel, id)) {
-+                              id = mptscsih_raid_id_to_num(ioc,
-+                                  channel, id);
-+                              vtarget->tflags |=
-+                                  MPT_TARGET_FLAGS_RAID_COMPONENT;
-+                              p->phy_info[i].attached.phys_disk_num = id;
-                       }
-+                      mutex_unlock(&ioc->sas_topology_mutex);
-+                      goto out;
-               }
+       /* IOC *must* NOT be in RESET state! */
+       if (ioc->last_state == MPI_IOC_STATE_RESET) {
+-              printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
+-                              ioc->name,
+-                              ioc->last_state );
++              printk(KERN_ERR MYNAM
++                  ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
++                  ioc->name, ioc->last_state);
+               return -44;
        }
-       mutex_unlock(&ioc->sas_topology_mutex);
-+
-+      kfree(vtarget);
-       return -ENXIO;
-- found_info:
--      mutex_unlock(&ioc->sas_topology_mutex);
--      memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
--      error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
--                      (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
--                       MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
--      if (!error)
--              *identifier = enclosure_info.enclosure_logical_id;
--      return error;
-+ out:
-+      vtarget->id = id;
-+      vtarget->channel = channel;
-+      starget->hostdata = vtarget;
-+      return 0;
- }
  
--static int
--mptsas_get_bay_identifier(struct sas_rphy *rphy)
-+/**
-+ *    mptsas_target_destroy -
-+ *    @starget:
-+ *
-+ **/
-+static void
-+mptsas_target_destroy(struct scsi_target *starget)
- {
--      MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
--      struct mptsas_portinfo *p;
--      int i, rc;
-+      struct Scsi_Host *host = dev_to_shost(&starget->dev);
-+      MPT_SCSI_HOST           *hd = shost_priv(host);
-+      struct sas_rphy         *rphy;
-+      struct mptsas_portinfo  *p;
-+      int                      i;
-+      MPT_ADAPTER             *ioc = hd->ioc;
--      mutex_lock(&ioc->sas_topology_mutex);
-+      if (!starget->hostdata)
-+              return;
-+
-+      mptsas_del_device_component_by_os(ioc, starget->channel,
-+          starget->id);
-+
-+      if (starget->channel == MPTSAS_RAID_CHANNEL)
-+              goto out;
-+
-+      rphy = dev_to_rphy(starget->dev.parent);
-       list_for_each_entry(p, &ioc->sas_topology, list) {
-               for (i = 0; i < p->num_phys; i++) {
--                      if (p->phy_info[i].attached.sas_address ==
--                          rphy->identify.sas_address) {
--                              rc = p->phy_info[i].attached.slot;
--                              goto out;
--                      }
-+                      if (p->phy_info[i].attached.sas_address !=
-+                                      rphy->identify.sas_address)
-+                              continue;
-+
-+                      starget_printk(KERN_INFO, starget, MYIOC_s_FMT
-+                      "delete device: fw_channel %d, fw_id %d, phy %d, "
-+                      "sas_addr 0x%llx\n", ioc->name,
-+                      p->phy_info[i].attached.channel,
-+                      p->phy_info[i].attached.id,
-+                      p->phy_info[i].attached.phy_id, (unsigned long long)
-+                      p->phy_info[i].attached.sas_address);
-+
-+                      mptsas_port_delete(ioc, p->phy_info[i].port_details);
-               }
-       }
--      rc = -ENXIO;
-+
-  out:
--      mutex_unlock(&ioc->sas_topology_mutex);
--      return rc;
-+      kfree(starget->hostdata);
-+      starget->hostdata = NULL;
- }
+@@ -3011,7 +3067,8 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
  
--static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
--                            struct request *req)
-+/**
-+ *    mptsas_slave_alloc -
-+ *    @sdev:
-+ *
-+ **/
-+static int
-+mptsas_slave_alloc(struct scsi_device *sdev)
- {
--      MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
--      MPT_FRAME_HDR *mf;
--      SmpPassthroughRequest_t *smpreq;
--      struct request *rsp = req->next_rq;
--      int ret;
--      int flagsLength;
--      unsigned long timeleft;
--      char *psge;
--      dma_addr_t dma_addr_in = 0;
--      dma_addr_t dma_addr_out = 0;
--      u64 sas_address = 0;
--
--      if (!rsp) {
--              printk(MYIOC_s_ERR_FMT "%s: the smp response space is missing\n",
--                  ioc->name, __func__);
--              return -EINVAL;
--      }
-+      struct Scsi_Host        *host = sdev->host;
-+      MPT_SCSI_HOST           *hd = shost_priv(host);
-+      struct sas_rphy         *rphy;
-+      struct mptsas_portinfo  *p;
-+      VirtDevice              *vdevice;
-+      struct scsi_target      *starget;
-+      int                     i;
-+      MPT_ADAPTER             *ioc = hd->ioc;
--      /* do we need to support multiple segments? */
--      if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
--              printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
--                  ioc->name, __func__, req->bio->bi_vcnt, req->data_len,
--                  rsp->bio->bi_vcnt, rsp->data_len);
--              return -EINVAL;
-+      vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
-+      if (!vdevice) {
-+              printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
-+                  ioc->name, sizeof(VirtDevice));
-+              return -ENOMEM;
-       }
-+      starget = scsi_target(sdev);
-+      vdevice->vtarget = starget->hostdata;
--      ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
--      if (ret)
-+      /*
-+       * RAID volumes placed beyond the last expected port.
-+       */
-+      if (sdev->channel == MPTSAS_RAID_CHANNEL)
-               goto out;
+               facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
+               if (facts->MsgVersion == MPI_VERSION_01_05)
+-                      facts->HeaderVersion = le16_to_cpu(facts->HeaderVersion);
++                      facts->HeaderVersion =
++                          le16_to_cpu(facts->HeaderVersion);
+               facts->MsgContext = le32_to_cpu(facts->MsgContext);
+               facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
+               facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
+@@ -3120,6 +3177,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
+       return 0;
+ }
  
--      mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
--      if (!mf) {
--              ret = -ENOMEM;
--              goto out_unlock;
-+      rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
-+      mutex_lock(&ioc->sas_topology_mutex);
-+      list_for_each_entry(p, &ioc->sas_topology, list) {
-+              for (i = 0; i < p->num_phys; i++) {
-+                      if (p->phy_info[i].attached.sas_address !=
-+                                      rphy->identify.sas_address)
-+                              continue;
-+                      vdevice->lun = sdev->lun;
-+                      /*
-+                       * Exposing hidden raid components
-+                       */
-+                      if (mptscsih_is_phys_disk(ioc,
-+                          p->phy_info[i].attached.channel,
-+                          p->phy_info[i].attached.id))
-+                              sdev->no_uld_attach = 1;
-+                      mutex_unlock(&ioc->sas_topology_mutex);
-+                      goto out;
-+              }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    GetPortFacts - Send PortFacts request to MPT adapter.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -3127,7 +3185,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepF
+  *    @sleepFlag: Specifies whether the process can sleep
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
+ static int
+ GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
+ {
+@@ -3141,7 +3199,7 @@ GetPortFacts(MPT_ADAPTER *ioc, int portn
+       /* IOC *must* NOT be in RESET state! */
+       if (ioc->last_state == MPI_IOC_STATE_RESET) {
+               printk(MYIOC_s_ERR_FMT "Can't get PortFacts, "
+-                 " NOT READY! (%08x)\n", ioc->name, ioc->last_state );
++                 " NOT READY! (%08x)\n", ioc->name, ioc->last_state);
+               return -4;
        }
-+      mutex_unlock(&ioc->sas_topology_mutex);
  
--      smpreq = (SmpPassthroughRequest_t *)mf;
--      memset(smpreq, 0, sizeof(*smpreq));
-+      kfree(vdevice);
-+      return -ENXIO;
--      smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4);
--      smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
-+ out:
-+      vdevice->vtarget->num_luns++;
-+      sdev->hostdata = vdevice;
-+      return 0;
-+}
+@@ -3159,14 +3217,14 @@ GetPortFacts(MPT_ADAPTER *ioc, int portn
+       get_pfacts.PortNumber = portnum;
+       /* Assert: All other get_pfacts fields are zero! */
  
--      if (rphy)
--              sas_address = rphy->identify.sas_address;
--      else {
--              struct mptsas_portinfo *port_info;
-+/**
-+ *    mptsas_qcmd -
-+ *    @SCpnt:
-+ *    @done:
-+ *
-+ **/
-+static int
-+mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
-+{
-+      MPT_SCSI_HOST   *hd;
-+      MPT_ADAPTER     *ioc;
-+      VirtDevice      *vdevice = SCpnt->device->hostdata;
--              mutex_lock(&ioc->sas_topology_mutex);
--              port_info = mptsas_get_hba_portinfo(ioc);
--              if (port_info && port_info->phy_info)
--                      sas_address =
--                              port_info->phy_info[0].phy->identify.sas_address;
--              mutex_unlock(&ioc->sas_topology_mutex);
-+      if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
-+              SCpnt->result = DID_NO_CONNECT << 16;
-+              done(SCpnt);
-+              return 0;
-       }
--      *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
-+      hd = shost_priv(SCpnt->device->host);
-+      ioc = hd->ioc;
--      psge = (char *)
--              (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
-+      if (ioc->sas_discovery_quiesce_io)
-+              return SCSI_MLQUEUE_HOST_BUSY;
--      /* request */
--      flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
--                     MPI_SGE_FLAGS_END_OF_BUFFER |
--                     MPI_SGE_FLAGS_DIRECTION |
--                     mpt_addr_size()) << MPI_SGE_FLAGS_SHIFT;
--      flagsLength |= (req->data_len - 4);
--
--      dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
--                                    req->data_len, PCI_DMA_BIDIRECTIONAL);
--      if (!dma_addr_out)
--              goto put_mf;
--      mpt_add_sge(psge, flagsLength, dma_addr_out);
--      psge += (sizeof(u32) + sizeof(dma_addr_t));
--
--      /* response */
--      flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
--      flagsLength |= rsp->data_len + 4;
--      dma_addr_in =  pci_map_single(ioc->pcidev, bio_data(rsp->bio),
--                                    rsp->data_len, PCI_DMA_BIDIRECTIONAL);
--      if (!dma_addr_in)
--              goto unmap;
--      mpt_add_sge(psge, flagsLength, dma_addr_in);
-+//    scsi_print_command(SCpnt);
-+      return mptscsih_qcmd(SCpnt,done);
-+}
+-      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
+-              ioc->name, portnum));
++      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
++              "Sending get PortFacts(%d) request\n", ioc->name, portnum));
  
--      mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
+       /* No non-zero fields in the get_pfacts request are greater than
+        * 1 byte in size, so we can just fire it off as is.
+        */
+       ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
+-              reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
++              reply_sz, (u16 *)pfacts, 5 /*seconds*/, sleepFlag);
+       if (ii != 0)
+               return ii;
  
--      timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
--      if (!timeleft) {
--              printk(MYIOC_s_ERR_FMT "%s: smp timeout!\n", ioc->name, __func__);
--              /* On timeout reset the board */
--              mpt_HardResetHandler(ioc, CAN_SLEEP);
--              ret = -ETIMEDOUT;
--              goto unmap;
--      }
--      mf = NULL;
--
--      if (ioc->sas_mgmt.status & MPT_IOCTL_STATUS_RF_VALID) {
--              SmpPassthroughReply_t *smprep;
--
--              smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
--              memcpy(req->sense, smprep, sizeof(*smprep));
--              req->sense_len = sizeof(*smprep);
--              req->data_len = 0;
--              rsp->data_len -= smprep->ResponseDataLength;
--      } else {
--              printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
--                  ioc->name, __func__);
--              ret = -ENXIO;
--      }
--unmap:
--      if (dma_addr_out)
--              pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len,
--                               PCI_DMA_BIDIRECTIONAL);
--      if (dma_addr_in)
--              pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len,
--                               PCI_DMA_BIDIRECTIONAL);
--put_mf:
--      if (mf)
-+static struct scsi_host_template mptsas_driver_template = {
-+      .module                         = THIS_MODULE,
-+      .proc_name                      = "mptsas",
-+      .proc_info                      = mptscsih_proc_info,
-+      .name                           = "MPT SPI Host",
-+      .info                           = mptscsih_info,
-+      .queuecommand                   = mptsas_qcmd,
-+      .target_alloc                   = mptsas_target_alloc,
-+      .slave_alloc                    = mptsas_slave_alloc,
-+      .slave_configure                = mptsas_slave_configure,
-+      .target_destroy                 = mptsas_target_destroy,
-+      .slave_destroy                  = mptscsih_slave_destroy,
-+      .change_queue_depth             = mptscsih_change_queue_depth,
-+      .eh_abort_handler               = mptscsih_abort,
-+      .eh_device_reset_handler        = mptscsih_dev_reset,
-+      .eh_bus_reset_handler           = mptscsih_bus_reset,
-+      .eh_host_reset_handler          = mptscsih_host_reset,
-+      .bios_param                     = mptscsih_bios_param,
-+      .can_queue                      = MPT_FC_CAN_QUEUE,
-+      .this_id                        = -1,
-+      .sg_tablesize                   = MPT_SCSI_SG_DEPTH,
-+      .max_sectors                    = 8192,
-+      .cmd_per_lun                    = 7,
-+      .use_clustering                 = ENABLE_CLUSTERING,
-+      .shost_attrs                    = mptscsih_host_attrs,
-+};
-+
-+/**
-+ *    mptsas_get_linkerrors -
-+ *    @phy:
-+ *
-+ **/
-+static int mptsas_get_linkerrors(struct sas_phy *phy)
-+{
-+      MPT_ADAPTER *ioc = phy_to_ioc(phy);
-+      ConfigExtendedPageHeader_t hdr;
-+      CONFIGPARMS cfg;
-+      SasPhyPage1_t *buffer;
-+      dma_addr_t dma_handle;
-+      int error;
-+
-+      /* FIXME: only have link errors on local phys */
-+      if (!scsi_is_sas_phy_local(phy))
-+              return -EINVAL;
-+
-+      hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
-+      hdr.ExtPageLength = 0;
-+      hdr.PageNumber = 1 /* page number 1*/;
-+      hdr.Reserved1 = 0;
-+      hdr.Reserved2 = 0;
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-+      hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
-+
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = phy->identify.phy_identifier;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
-+
-+      error = mpt_config(ioc, &cfg);
-+      if (error)
-+              return error;
-+      if (!hdr.ExtPageLength)
-+              return -ENXIO;
-+
-+      buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-+                                    &dma_handle);
-+      if (!buffer)
-+              return -ENOMEM;
-+
-+      cfg.physAddr = dma_handle;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      error = mpt_config(ioc, &cfg);
-+      if (error)
-+              goto out_free_consistent;
-+
-+      mptsas_print_phy_pg1(ioc, buffer);
-+
-+      phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
-+      phy->running_disparity_error_count =
-+              le32_to_cpu(buffer->RunningDisparityErrorCount);
-+      phy->loss_of_dword_sync_count =
-+              le32_to_cpu(buffer->LossDwordSynchCount);
-+      phy->phy_reset_problem_count =
-+              le32_to_cpu(buffer->PhyResetProblemCount);
-+
-+ out_free_consistent:
-+      pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-+                          buffer, dma_handle);
-+      return error;
-+}
-+
-+/**
-+ *    mptsas_mgmt_done -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @req:
-+ *    @reply:
-+ *
-+ **/
-+static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
-+              MPT_FRAME_HDR *reply)
-+{
-+      ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
-+      if (reply != NULL) {
-+              ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
-+              memcpy(ioc->sas_mgmt.reply, reply,
-+                  min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
-+      }
-+
-+      if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
-+              ioc->sas_mgmt.status &= ~MPT_MGMT_STATUS_PENDING;
-+              complete(&ioc->sas_mgmt.done);
-+              return 1;
-+      }
-+      return 0;
-+}
-+
-+/**
-+ *    mptsas_phy_reset -
-+ *    @phy:
-+ *    @hard_reset:
-+ *
-+ **/
-+static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
-+{
-+      MPT_ADAPTER *ioc = phy_to_ioc(phy);
-+      SasIoUnitControlRequest_t *req;
-+      SasIoUnitControlReply_t *reply;
-+      MPT_FRAME_HDR *mf;
-+      MPIHeader_t *hdr;
-+      unsigned long timeleft;
-+      int error = -ERESTARTSYS;
-+
-+      /* FIXME: fusion doesn't allow non-local phy reset */
-+      if (!scsi_is_sas_phy_local(phy))
-+              return -EINVAL;
-+
-+      /* not implemented for expanders */
-+      if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
-+              return -ENXIO;
-+
-+      if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
-+              goto out;
-+
-+      mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
-+      if (!mf) {
-+              error = -ENOMEM;
-+              goto out_unlock;
-+      }
-+
-+      hdr = (MPIHeader_t *) mf;
-+      req = (SasIoUnitControlRequest_t *)mf;
-+      memset(req, 0, sizeof(SasIoUnitControlRequest_t));
-+      req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
-+      req->MsgContext = hdr->MsgContext;
-+      req->Operation = hard_reset ?
-+              MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
-+      req->PhyNum = phy->identify.phy_identifier;
-+
-+      INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
-+      mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
-+      timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10*HZ);
-+      if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              error = -ETIME;
-               mpt_free_msg_frame(ioc, mf);
--out_unlock:
-+              if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
-+                      goto out;
-+              if (!timeleft) {
-+                      if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
-+                              mpt_HardResetHandler(ioc, CAN_SLEEP);
-+              }
-+              goto out_unlock;
-+      }
-+
-+      /* a reply frame is expected */
-+      if ((ioc->sas_mgmt.status &
-+          MPT_MGMT_STATUS_RF_VALID) == 0) {
-+              error = -ENXIO;
-+              goto out_unlock;
-+      }
-+
-+      /* process the completed Reply Message Frame */
-+      reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
-+      if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
-+              printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
-+                  ioc->name, __FUNCTION__, reply->IOCStatus, reply->IOCLogInfo);
-+              error = -ENXIO;
-+              goto out_unlock;
-+      }
-+
-+      error = 0;
-+
-+ out_unlock:
-+      CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
-       mutex_unlock(&ioc->sas_mgmt.mutex);
--out:
--      return ret;
-+ out:
-+      return error;
-+}
-+
-+/**
-+ *    mptsas_get_enclosure_identifier -
-+ *    @rphy:
-+ *    @identifier:
-+ *
-+ **/
-+static int
-+mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
-+{
-+      MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
-+      int i, error;
-+      struct mptsas_portinfo *p;
-+      struct mptsas_enclosure enclosure_info;
-+      u64 enclosure_handle;
-+
-+      mutex_lock(&ioc->sas_topology_mutex);
-+      list_for_each_entry(p, &ioc->sas_topology, list) {
-+              for (i = 0; i < p->num_phys; i++) {
-+                      if (p->phy_info[i].attached.sas_address ==
-+                          rphy->identify.sas_address) {
-+                              enclosure_handle = p->phy_info[i].
-+                                      attached.handle_enclosure;
-+                              goto found_info;
-+                      }
-+              }
-+      }
-+      mutex_unlock(&ioc->sas_topology_mutex);
-+      return -ENXIO;
-+
-+ found_info:
-+      mutex_unlock(&ioc->sas_topology_mutex);
-+      memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
-+      error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
-+                      (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
-+                       MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
-+                       enclosure_handle);
-+      if (!error)
-+              *identifier = enclosure_info.enclosure_logical_id;
-+      return error;
-+}
-+
-+/**
-+ *    mptsas_get_bay_identifier -
-+ *    @rphy:
-+ *
-+ **/
-+static int
-+mptsas_get_bay_identifier(struct sas_rphy *rphy)
-+{
-+      MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
-+      struct mptsas_portinfo *p;
-+      int i, rc;
-+
-+      mutex_lock(&ioc->sas_topology_mutex);
-+      list_for_each_entry(p, &ioc->sas_topology, list) {
-+              for (i = 0; i < p->num_phys; i++) {
-+                      if (p->phy_info[i].attached.sas_address ==
-+                          rphy->identify.sas_address) {
-+                              rc = p->phy_info[i].attached.slot;
-+                              goto out;
-+                      }
-+              }
-+      }
-+      rc = -ENXIO;
-+ out:
-+      mutex_unlock(&ioc->sas_topology_mutex);
-+      return rc;
+@@ -3201,6 +3259,7 @@ GetPortFacts(MPT_ADAPTER *ioc, int portn
+       return 0;
  }
  
- static struct sas_function_template mptsas_transport_functions = {
-@@ -1385,11 +2280,16 @@ static struct sas_function_template mpts
-       .get_enclosure_identifier = mptsas_get_enclosure_identifier,
-       .get_bay_identifier     = mptsas_get_bay_identifier,
-       .phy_reset              = mptsas_phy_reset,
--      .smp_handler            = mptsas_smp_handler,
- };
- static struct scsi_transport_template *mptsas_transport_template;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    SendIocInit - Send IOCInit request to MPT adapter.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -3209,7 +3268,7 @@ GetPortFacts(MPT_ADAPTER *ioc, int portn
+  *    Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
+ static int
+ SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
+ {
+@@ -3323,6 +3382,7 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepF
+       return r;
+ }
  
-+/**
-+ *    mptsas_sas_io_unit_pg0 -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @port_info:
-+ *
-+ **/
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    SendPortEnable - Send PortEnable request to MPT adapter port.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -3332,7 +3392,7 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepF
+  *    Send PortEnable to bring IOC to OPERATIONAL state.
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
  static int
mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  {
-@@ -1412,7 +2312,7 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc,
-       cfg.pageAddr = 0;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-       cfg.dir = 0;    /* read */
--      cfg.timeout = 10;
-+      cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
+@@ -3355,18 +3415,19 @@ SendPortEnable(MPT_ADAPTER *ioc, int por
+ /*    port_enable.MsgFlags = 0;               */
+ /*    port_enable.MsgContext = 0;             */
  
-       error = mpt_config(ioc, &cfg);
-       if (error)
-@@ -1438,7 +2338,7 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc,
+-      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
+-                      ioc->name, portnum, &port_enable));
++      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
++              "Sending Port(%d)Enable (req @ %p)\n", ioc->name,
++              portnum, &port_enable));
  
-       port_info->num_phys = buffer->NumPhys;
-       port_info->phy_info = kcalloc(port_info->num_phys,
--              sizeof(*port_info->phy_info),GFP_KERNEL);
-+              sizeof(struct mptsas_phyinfo),GFP_KERNEL);
-       if (!port_info->phy_info) {
-               error = -ENOMEM;
-               goto out_free_consistent;
-@@ -1459,6 +2359,8 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc,
-               port_info->phy_info[i].portinfo = port_info;
-               port_info->phy_info[i].handle =
-                   le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
-+              port_info->phy_info[i].port_flags =
-+                  buffer->PhyData[i].PortFlags;
+       /* RAID FW may take a long time to enable
+        */
+       if (ioc->ir_firmware || ioc->bus_type == SAS) {
+               rc = mpt_handshake_req_reply_wait(ioc, req_sz,
+-              (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
++              (u32 *)&port_enable, reply_sz, (u16 *)&reply_buf,
+               300 /*seconds*/, sleepFlag);
+       } else {
+               rc = mpt_handshake_req_reply_wait(ioc, req_sz,
+-              (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
++              (u32 *)&port_enable, reply_sz, (u16 *)&reply_buf,
+               30 /*seconds*/, sleepFlag);
        }
+       return rc;
+@@ -3435,6 +3496,7 @@ mpt_free_fw_memory(MPT_ADAPTER *ioc)
+       ioc->cached_fw = NULL;
+ }
  
-  out_free_consistent:
-@@ -1468,6 +2370,11 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc,
-       return error;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -3447,7 +3509,7 @@ mpt_free_fw_memory(MPT_ADAPTER *ioc)
+  *    on the bound IOC, the second image is discarded
+  *    and memory is free'd. Both channels must upload to prevent
+  *    IOC from running in degraded mode.
+- **/
++ */
+ static int
+ mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
+ {
+@@ -3499,8 +3561,8 @@ mpt_do_upload(MPT_ADAPTER *ioc, int slee
+           ioc->facts.FWImageSize, request_size));
+       DBG_DUMP_FW_REQUEST_FRAME(ioc, (u32 *)prequest);
+-      ii = mpt_handshake_req_reply_wait(ioc, request_size, (u32*)prequest,
+-          reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
++      ii = mpt_handshake_req_reply_wait(ioc, request_size, (u32 *)prequest,
++          reply_sz, (u16 *)preply, 65 /*seconds*/, sleepFlag);
+       dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FW Upload completed "
+           "rc=%x \n", ioc->name, ii));
+@@ -3512,10 +3574,10 @@ mpt_do_upload(MPT_ADAPTER *ioc, int slee
+                */
+               int status;
+               status = le16_to_cpu(preply->IOCStatus) &
+-                  MPI_IOCSTATUS_MASK;
++                  MPI_IOCSTATUS_MASK;
+               if (status == MPI_IOCSTATUS_SUCCESS &&
+                   ioc->facts.FWImageSize ==
+-                  le32_to_cpu(preply->ActualImageSize));
++                  le32_to_cpu(preply->ActualImageSize))
+                       cmdStatus = 0;
+       }
+       dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "do_upload cmdStatus=%d \n",
+@@ -3532,6 +3594,7 @@ mpt_do_upload(MPT_ADAPTER *ioc, int slee
+       return cmdStatus;
  }
  
-+/**
-+ *    mptsas_sas_io_unit_pg1 -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *
-+ **/
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_downloadboot - DownloadBoot code
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -3544,7 +3607,7 @@ mpt_do_upload(MPT_ADAPTER *ioc, int slee
+  *            -1 FW Image size is 0
+  *            -2 No valid cached_fw Pointer
+  *            <0 for fw upload failure.
+- **/
++ */
  static int
- mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
+ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag)
  {
-@@ -1483,11 +2390,11 @@ mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
+@@ -3648,13 +3711,15 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
+       }
  
-       cfg.cfghdr.ehdr = &hdr;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
--      cfg.timeout = 10;
-       cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-       cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
-       cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
-       cfg.cfghdr.ehdr->PageNumber = 1;
-+      cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
-       error = mpt_config(ioc, &cfg);
-       if (error)
-@@ -1525,6 +2432,14 @@ mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
-       return error;
+       /* Write the IopResetVectorRegAddr */
+-      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Addr=%x! \n",
+-          ioc->name, pFwHeader->IopResetRegAddr));
++      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++              "Write IopResetVector Addr=%x!\n", ioc->name,
++              pFwHeader->IopResetRegAddr));
+       CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
+       /* Write the IopResetVectorValue */
+-      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Value=%x! \n",
+-          ioc->name, pFwHeader->IopResetVectorValue));
++      ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++              "Write IopResetVector Value=%x!\n", ioc->name,
++              pFwHeader->IopResetVectorValue));
+       CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
+       /* Clear the internal flash bad bit - autoincrementing register,
+@@ -3684,7 +3749,7 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
+           ioc->name, diag0val));
+       CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
+-      if (ioc->bus_type == SAS ) {
++      if (ioc->bus_type == SAS) {
+               /* wait 1 sec */
+               if (sleepFlag == CAN_SLEEP)
+                       msleep(1000);
+@@ -3692,7 +3757,7 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
+                       mdelay(1000);
+               diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
+-              ddlprintk(ioc, printk (MYIOC_s_DEBUG_FMT
++              ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "diag0val=%x, turning off RW_ENABLE\n", ioc->name,
+                   diag0val));
+               diag0val &= ~(MPI_DIAG_RW_ENABLE);
+@@ -3715,8 +3780,9 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
+       /* Write 0xFF to reset the sequencer */
+       CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
+-      for (count = 0; count < 30; count ++) {
+-              doorbell = CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_IOC_STATE_MASK;
++      for (count = 0; count < 30; count++) {
++              doorbell = CHIPREG_READ32(&ioc->chip->Doorbell)
++                  & MPI_IOC_STATE_MASK;
+               if (doorbell == MPI_IOC_STATE_READY) {
+                       if (ioc->bus_type == SAS)
+                               return 0;
+@@ -3729,17 +3795,20 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
+                           "SendIocInit successful\n", ioc->name));
+                       return 0;
+               }
+-              ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "looking for READY STATE:"
+-                  " doorbell=%x count=%d\n", ioc->name, doorbell, count));
++              ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "looking for READY STATE: doorbell=%x count=%d\n",
++                      ioc->name, doorbell, count));
+               if (sleepFlag == CAN_SLEEP)
+                       msleep(1000);
+               else
+                       mdelay(1000);
+       }
+-      ddlprintk(ioc, printk(MYIOC_s_WARN_FMT "downloadboot failed! count=%d\n", ioc->name, count));
++      ddlprintk(ioc, printk(MYIOC_s_WARN_FMT
++              "downloadboot failed! count=%d\n", ioc->name, count));
+       return -EFAULT;
  }
  
-+/**
-+ *    mptsas_sas_phy_pg0 -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @phy_info:
-+ *    @form:
-+ *    @form_specific:
-+ *
-+ **/
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    KickStart - Perform hard reset of MPT adapter.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -3764,7 +3833,7 @@ mpt_downloadboot(MPT_ADAPTER *ioc, MpiFw
+  *                 OR reset but failed to come READY
+  *            -2 - no reset, could not enter DIAG mode
+  *            -3 - reset but bad FW bit
+- **/
++ */
  static int
- mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
-               u32 form, u32 form_specific)
-@@ -1545,12 +2460,12 @@ mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, str
+ KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
+ {
+@@ -3790,16 +3859,20 @@ KickStart(MPT_ADAPTER *ioc, int force, i
+       if (hard_reset_done < 0)
+               return hard_reset_done;
  
-       cfg.cfghdr.ehdr = &hdr;
-       cfg.dir = 0;    /* read */
--      cfg.timeout = 10;
+-      /* may not have worked but hard_reset_done doesn't always signal failure */
+-      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "Diagnostic reset completed!\n",
+-                      ioc->name));
++      /* may not have worked but hard_reset_done
++       * doesn't always signal failure
++       */
++      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
++              "Diagnostic reset completed!\n", ioc->name));
  
-       /* Get Phy Pg 0 for each Phy. */
-       cfg.physAddr = -1;
-       cfg.pageAddr = form + form_specific;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
-       error = mpt_config(ioc, &cfg);
-       if (error)
-@@ -1581,6 +2496,8 @@ mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, str
-       phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
-       phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
-       phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
-+      phy_info->change_count = buffer->ChangeCount;
-+      phy_info->phy_info = le32_to_cpu(buffer->PhyInfo);
-  out_free_consistent:
-       pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-@@ -1589,6 +2506,14 @@ mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, str
-       return error;
+       cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2;     /* 2 seconds */
+       for (cnt=0; cnt<cntdn; cnt++) {
+               ioc_state = mpt_GetIocState(ioc, 1);
+-              if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
+-                      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "KickStart successful! (cnt=%d)\n",
+-                                      ioc->name, cnt));
++              if ((ioc_state == MPI_IOC_STATE_READY) ||
++                  (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
++                      dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
++                              "KickStart successful! (cnt=%d)\n", ioc->name,
++                              cnt));
+                       return hard_reset_done;
+               }
+               if (sleepFlag == CAN_SLEEP) {
+@@ -3814,6 +3887,7 @@ KickStart(MPT_ADAPTER *ioc, int force, i
+       return -1;
  }
  
-+/**
-+ *    mptsas_sas_device_pg0 -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @device_info:
-+ *    @form:
-+ *    @form_specific:
-+ *
-+ **/
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_diag_reset - Perform hard reset of the adapter.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -3831,7 +3905,7 @@ KickStart(MPT_ADAPTER *ioc, int force, i
+  *              0  no reset performed because reset history bit set
+  *             -2  enabling diagnostic mode failed
+  *             -3  diagnostic reset failed
+- **/
++ */
  static int
- mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
-               u32 form, u32 form_specific)
-@@ -1600,10 +2525,6 @@ mptsas_sas_device_pg0(MPT_ADAPTER *ioc, 
-       __le64 sas_address;
-       int error=0;
+ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
+ {
+@@ -3852,7 +3926,7 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
+                       return 0;
  
--      if (ioc->sas_discovery_runtime &&
--              mptsas_is_end_device(device_info))
--                      goto out;
--
-       hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
-       hdr.ExtPageLength = 0;
-       hdr.PageNumber = 0;
-@@ -1617,9 +2538,8 @@ mptsas_sas_device_pg0(MPT_ADAPTER *ioc, 
-       cfg.physAddr = -1;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-       cfg.dir = 0;    /* read */
--      cfg.timeout = 10;
-+      cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
+               drsprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset "
+-                  "address=%p\n",  ioc->name, __FUNCTION__, &ioc->chip->Doorbell,
++                  "address=%p\n",  ioc->name, __func__, &ioc->chip->Doorbell,
+                   &ioc->chip->Reset_1078));
+               CHIPREG_WRITE32(&ioc->chip->Reset_1078, 0x07);
+               if (sleepFlag == CAN_SLEEP)
+@@ -3868,7 +3942,8 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
+                */
+               for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+                       if (MptResetHandlers[cb_idx])
+-                              (*(MptResetHandlers[cb_idx]))(ioc, MPT_IOC_PRE_RESET);
++                              (*(MptResetHandlers[cb_idx]))
++                                  (ioc, MPT_IOC_PRE_RESET);
+               }
  
--      memset(device_info, 0, sizeof(struct mptsas_devinfo));
-       error = mpt_config(ioc, &cfg);
-       if (error)
-               goto out;
-@@ -1639,11 +2559,18 @@ mptsas_sas_device_pg0(MPT_ADAPTER *ioc, 
-       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+               for (count = 0; count < 60; count ++) {
+@@ -3907,8 +3982,10 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
+       if (ioc->debug_level & MPT_DEBUG_RESET) {
+               if (ioc->alt_ioc)
+-                      diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
+-              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG1: diag0=%08x, diag1=%08x\n",
++                      diag1val =
++                          CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
++              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "DbG1: diag0=%08x, diag1=%08x\n",
+                       ioc->name, diag0val, diag1val));
+       }
  
-       error = mpt_config(ioc, &cfg);
-+
-+      if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
-+              error = -ENODEV;
-+              goto out_free_consistent;
-+      }
-+
-       if (error)
-               goto out_free_consistent;
+@@ -3943,14 +4020,16 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
  
-       mptsas_print_device_pg0(ioc, buffer);
+                       diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  
-+      memset(device_info, 0, sizeof(struct mptsas_devinfo));
-       device_info->handle = le16_to_cpu(buffer->DevHandle);
-       device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
-       device_info->handle_enclosure =
-@@ -1666,6 +2593,14 @@ mptsas_sas_device_pg0(MPT_ADAPTER *ioc, 
-       return error;
- }
+-                      drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
+-                                      ioc->name, diag0val));
++                      drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                              "Wrote magic DiagWriteEn sequence (%x)\n",
++                              ioc->name, diag0val));
+               }
  
-+/**
-+ *    mptsas_sas_expander_pg0 -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @port_info:
-+ *    @form:
-+ *    @form_specific:
-+ *
-+ **/
- static int
- mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
-               u32 form, u32 form_specific)
-@@ -1675,7 +2610,9 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc
-       SasExpanderPage0_t *buffer;
-       dma_addr_t dma_handle;
-       int i, error;
-+      __le64 sas_address;
-+      memset(port_info, 0, sizeof(struct mptsas_portinfo));
-       hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
-       hdr.ExtPageLength = 0;
-       hdr.PageNumber = 0;
-@@ -1689,9 +2626,8 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc
-       cfg.pageAddr = form + form_specific;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-       cfg.dir = 0;    /* read */
--      cfg.timeout = 10;
-+      cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
+               if (ioc->debug_level & MPT_DEBUG_RESET) {
+                       if (ioc->alt_ioc)
+                               diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
+-                      drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG2: diag0=%08x, diag1=%08x\n",
++                      drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                              "DbG2: diag0=%08x, diag1=%08x\n",
+                               ioc->name, diag0val, diag1val));
+               }
+               /*
+@@ -3966,8 +4045,8 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
+                */
+               CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
+               hard_reset_done = 1;
+-              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset performed\n",
+-                              ioc->name));
++              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "Diagnostic reset performed\n", ioc->name));
  
--      memset(port_info, 0, sizeof(struct mptsas_portinfo));
-       error = mpt_config(ioc, &cfg);
-       if (error)
-               goto out;
-@@ -1712,27 +2648,32 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc
-       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+               /*
+                * Call each currently registered protocol IOC reset handler
+@@ -3977,10 +4056,11 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
+                */
+               for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+                       if (MptResetHandlers[cb_idx]) {
+-                              mpt_signal_reset(cb_idx, ioc, MPT_IOC_PRE_RESET);
+-                              if (ioc->alt_ioc) {
+-                                      mpt_signal_reset(cb_idx, ioc->alt_ioc, MPT_IOC_PRE_RESET);
+-                              }
++                              mpt_signal_reset(cb_idx, ioc,
++                                  MPT_IOC_PRE_RESET);
++                              if (ioc->alt_ioc)
++                                      mpt_signal_reset(cb_idx,
++                                          ioc->alt_ioc, MPT_IOC_PRE_RESET);
+                       }
+               }
  
-       error = mpt_config(ioc, &cfg);
--      if (error)
--              goto out_free_consistent;
--
--      if (!buffer->NumPhys) {
-+      if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
-               error = -ENODEV;
-               goto out_free_consistent;
-       }
+@@ -4001,7 +4081,8 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
+                                       break;
+                               }
  
-+      if (error)
-+              goto out_free_consistent;
-+
-       /* save config data */
--      port_info->num_phys = buffer->NumPhys;
-+      port_info->num_phys = (buffer->NumPhys) ? buffer->NumPhys : 1;
-       port_info->phy_info = kcalloc(port_info->num_phys,
--              sizeof(*port_info->phy_info),GFP_KERNEL);
-+              sizeof(struct mptsas_phyinfo),GFP_KERNEL);
-       if (!port_info->phy_info) {
-               error = -ENOMEM;
-               goto out_free_consistent;
+-                              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "cached_fw: diag0val=%x count=%d\n",
++                              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                                      "cached_fw: diag0val=%x count=%d\n",
+                                       ioc->name, diag0val, count));
+                               /* wait 1 sec */
+                               if (sleepFlag == CAN_SLEEP)
+@@ -4055,7 +4136,8 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
+       if (ioc->debug_level & MPT_DEBUG_RESET) {
+               if (ioc->alt_ioc)
+                       diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
+-              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG3: diag0=%08x, diag1=%08x\n",
++              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "DbG3: diag0=%08x, diag1=%08x\n",
+                       ioc->name, diag0val, diag1val));
        }
  
-+      memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
-       for (i = 0; i < port_info->num_phys; i++) {
-               port_info->phy_info[i].portinfo = port_info;
-               port_info->phy_info[i].handle =
-                   le16_to_cpu(buffer->DevHandle);
-+              port_info->phy_info[i].identify.sas_address =
-+                  le64_to_cpu(sas_address);
-+              port_info->phy_info[i].identify.handle_parent =
-+                  le16_to_cpu(buffer->ParentDevHandle);
+@@ -4113,8 +4195,9 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
+       if (ioc->debug_level & MPT_DEBUG_RESET) {
+               if (ioc->alt_ioc)
+                       diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
+-              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG4: diag0=%08x, diag1=%08x\n",
+-                              ioc->name, diag0val, diag1val));
++              drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "DbG4: diag0=%08x, diag1=%08x\n",
++                      ioc->name, diag0val, diag1val));
        }
  
-  out_free_consistent:
-@@ -1742,6 +2683,14 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc
-       return error;
+       /*
+@@ -4128,6 +4211,7 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
+       return hard_reset_done;
  }
  
-+/**
-+ *    mptsas_sas_expander_pg1 -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @phy_info:
-+ *    @form:
-+ *    @form_specific:
-+ *
-+ **/
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    SendIocReset - Send IOCReset request to MPT adapter.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -4138,7 +4222,7 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ign
+  *    Send IOCReset request to the MPT adapter.
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
  static int
- mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
-               u32 form, u32 form_specific)
-@@ -1752,11 +2701,7 @@ mptsas_sas_expander_pg1(MPT_ADAPTER *ioc
-       dma_addr_t dma_handle;
-       int error=0;
+ SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
+ {
+@@ -4164,8 +4248,9 @@ SendIocReset(MPT_ADAPTER *ioc, u8 reset_
+                       if (sleepFlag != CAN_SLEEP)
+                               count *= 10;
  
--      if (ioc->sas_discovery_runtime &&
--              mptsas_is_end_device(&phy_info->attached))
--                      goto out;
--
--      hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
-+      hdr.PageVersion = MPI_SASEXPANDER1_PAGEVERSION;
-       hdr.ExtPageLength = 0;
-       hdr.PageNumber = 1;
-       hdr.Reserved1 = 0;
-@@ -1764,1352 +2709,2349 @@ mptsas_sas_expander_pg1(MPT_ADAPTER *ioc
-       hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
-       hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
--      cfg.cfghdr.ehdr = &hdr;
--      cfg.physAddr = -1;
--      cfg.pageAddr = form + form_specific;
-+      cfg.cfghdr.ehdr = &hdr;
-+      cfg.physAddr = -1;
-+      cfg.pageAddr = form + form_specific;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      cfg.dir = 0;    /* read */
-+      cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
-+
-+      error = mpt_config(ioc, &cfg);
-+      if (error)
-+              goto out;
-+
-+      if (!hdr.ExtPageLength) {
-+              error = -ENXIO;
-+              goto out;
-+      }
-+
-+      buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-+                                    &dma_handle);
-+      if (!buffer) {
-+              error = -ENOMEM;
-+              goto out;
-+      }
-+
-+      cfg.physAddr = dma_handle;
-+      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+
-+      error = mpt_config(ioc, &cfg);
-+      if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
-+              error = -ENODEV;
-+              goto out;
-+      }
-+
-+      if (error)
-+              goto out_free_consistent;
-+
-+
-+      mptsas_print_expander_pg1(ioc, buffer);
-+
-+      /* save config data */
-+      phy_info->phy_id = buffer->PhyIdentifier;
-+      phy_info->port_id = buffer->PhysicalPort;
-+      phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
-+      phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
-+      phy_info->hw_link_rate = buffer->HwLinkRate;
-+      phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
-+      phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
-+      phy_info->change_count = buffer->ChangeCount;
-+      phy_info->phy_info = le32_to_cpu(buffer->PhyInfo);
-+
-+ out_free_consistent:
-+      pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
-+                          buffer, dma_handle);
-+ out:
-+      return error;
-+}
-+
-+/**
-+ *    mptsas_parse_device_info -
-+ *    @identify:
-+ *    @device_info:
-+ *
-+ **/
-+static void
-+mptsas_parse_device_info(struct sas_identify *identify,
-+              struct mptsas_devinfo *device_info)
-+{
-+      u16 protocols;
-+
-+      identify->sas_address = device_info->sas_address;
-+      identify->phy_identifier = device_info->phy_id;
-+
-+      /*
-+       * Fill in Phy Initiator Port Protocol.
-+       * Bits 6:3, more than one bit can be set, fall through cases.
-+       */
-+      protocols = device_info->device_info & 0x78;
-+      identify->initiator_port_protocols = 0;
-+      if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
-+              identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
-+      if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
-+              identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
-+      if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
-+              identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
-+      if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
-+              identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
-+
-+      /*
-+       * Fill in Phy Target Port Protocol.
-+       * Bits 10:7, more than one bit can be set, fall through cases.
-+       */
-+      protocols = device_info->device_info & 0x780;
-+      identify->target_port_protocols = 0;
-+      if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
-+              identify->target_port_protocols |= SAS_PROTOCOL_SSP;
-+      if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
-+              identify->target_port_protocols |= SAS_PROTOCOL_STP;
-+      if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
-+              identify->target_port_protocols |= SAS_PROTOCOL_SMP;
-+      if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
-+              identify->target_port_protocols |= SAS_PROTOCOL_SATA;
-+
-+      /*
-+       * Fill in Attached device type.
-+       */
-+      switch (device_info->device_info &
-+                      MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
-+      case MPI_SAS_DEVICE_INFO_NO_DEVICE:
-+              identify->device_type = SAS_PHY_UNUSED;
-+              break;
-+      case MPI_SAS_DEVICE_INFO_END_DEVICE:
-+              identify->device_type = SAS_END_DEVICE;
-+              break;
-+      case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
-+              identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
-+              break;
-+      case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
-+              identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
-+              break;
-+      }
-+}
-+
-+/**
-+ *    mptsas_probe_one_phy -
-+ *    @dev:
-+ *    @phy_info:
-+ *    @local:
-+ *
-+ **/
-+static int mptsas_probe_one_phy(struct device *dev,
-+              struct mptsas_phyinfo *phy_info, int index, int local)
-+{
-+      MPT_ADAPTER *ioc;
-+      struct sas_phy *phy;
-+      struct sas_port *port;
-+      int error = 0;
-+
-+      if (!dev) {
-+              error = -ENODEV;
-+              goto out;
-+      }
-+
-+      if (!phy_info->phy) {
-+              phy = sas_phy_alloc(dev, index);
-+              if (!phy) {
-+                      error = -ENOMEM;
-+                      goto out;
-+              }
-+      } else
-+              phy = phy_info->phy;
-+
-+      mptsas_parse_device_info(&phy->identify, &phy_info->identify);
-+
-+      /*
-+       * Set Negotiated link rate.
-+       */
-+      switch (phy_info->negotiated_link_rate) {
-+      case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
-+              phy->negotiated_linkrate = SAS_PHY_DISABLED;
-+              break;
-+      case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
-+              phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
-+              break;
-+      case MPI_SAS_IOUNIT0_RATE_1_5:
-+              phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
-+              break;
-+      case MPI_SAS_IOUNIT0_RATE_3_0:
-+              phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
-+              break;
-+      case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
-+      case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
-+      default:
-+              phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
-+              break;
-+      }
-+
-+      /*
-+       * Set Max hardware link rate.
-+       */
-+      switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
-+      case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
-+              phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
-+              break;
-+      case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
-+              phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
-+              break;
-+      default:
-+              break;
-+      }
-+
-+      /*
-+       * Set Max programmed link rate.
-+       */
-+      switch (phy_info->programmed_link_rate &
-+                      MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
-+      case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
-+              phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
-+              break;
-+      case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
-+              phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
-+              break;
-+      default:
-+              break;
-+      }
-+
-+      /*
-+       * Set Min hardware link rate.
-+       */
-+      switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
-+      case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
-+              phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
-+              break;
-+      case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
-+              phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
-+              break;
-+      default:
-+              break;
-+      }
-+
-+      /*
-+       * Set Min programmed link rate.
-+       */
-+      switch (phy_info->programmed_link_rate &
-+                      MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
-+      case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
-+              phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
-+              break;
-+      case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
-+              phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
-+              break;
-+      default:
-+              break;
-+      }
-+
-+      if (!phy_info->phy) {
-+
-+              error = sas_phy_add(phy);
-+              if (error) {
-+                      sas_phy_free(phy);
-+                      goto out;
-+              }
-+              phy_info->phy = phy;
-+      }
-+
-+      if (!phy_info->attached.handle ||
-+                      !phy_info->port_details)
-+              goto out;
-+
-+      port = mptsas_get_port(phy_info);
-+      ioc = phy_to_ioc(phy_info->phy);
-+
-+      if (phy_info->sas_port_add_phy) {
-+              if (!port) {
-+                      port = sas_port_alloc_num(dev);
-+                      if (!port) {
-+                              error = -ENOMEM;
-+                              goto out;
-+                      }
-+                      error = sas_port_add(port);
-+                      if (error) {
-+                              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                                      "%s: exit at line=%d\n", ioc->name,
-+                                      __FUNCTION__, __LINE__));
-+                              goto out;
-+                      }
-+                      mptsas_set_port(ioc, phy_info, port);
-+                      devtprintk(ioc, dev_printk(KERN_DEBUG, &port->dev,
-+                          MYIOC_s_FMT "add port %d, sas_addr (0x%llx)\n",
-+                          ioc->name, port->port_identifier,
-+                          (unsigned long long)phy_info->attached.sas_address));
-+              }
-+              sas_port_add_phy(port, phy_info->phy);
-+              phy_info->sas_port_add_phy = 0;
-+              devtprintk(ioc, dev_printk(KERN_DEBUG, &phy_info->phy->dev,
-+                  MYIOC_s_FMT "add phy %d, phy-obj (0x%p)\n", ioc->name,
-+                   phy_info->phy_id, phy_info->phy));
-+      }
-+
-+      if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
-+
-+              struct sas_rphy *rphy;
-+              struct device *parent;
-+              struct sas_identify identify;
-+
-+              parent = dev->parent->parent;
-+
-+              if (mptsas_is_end_device(&phy_info->attached) &&
-+                  phy_info->attached.handle_parent) {
-+                      goto out;
-+              }
-+
-+              mptsas_parse_device_info(&identify, &phy_info->attached);
-+              if (scsi_is_host_device(parent)) {
-+                      struct mptsas_portinfo *port_info;
-+                      int i;
-+
-+                      port_info = ioc->hba_port_info;
-+                      for (i = 0; i < port_info->num_phys; i++)
-+                              if (port_info->phy_info[i].identify.sas_address ==
-+                                  identify.sas_address) {
-+                                      sas_port_mark_backlink(port);
-+                                      goto out;
-+                      }
-+
-+              } else if (scsi_is_sas_rphy(parent)) {
-+                      struct sas_rphy *parent_rphy = dev_to_rphy(parent);
-+                      if (identify.sas_address ==
-+                          parent_rphy->identify.sas_address) {
-+                              sas_port_mark_backlink(port);
-+                              goto out;
-+                      }
-+              }
-+
-+              switch (identify.device_type) {
-+              case SAS_END_DEVICE:
-+                      rphy = sas_end_device_alloc(port);
-+                      break;
-+              case SAS_EDGE_EXPANDER_DEVICE:
-+              case SAS_FANOUT_EXPANDER_DEVICE:
-+                      rphy = sas_expander_alloc(port, identify.device_type);
-+                      break;
-+              default:
-+                      rphy = NULL;
-+                      break;
-+              }
-+              if (!rphy) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                              "%s: exit at line=%d\n", ioc->name,
-+                              __FUNCTION__, __LINE__));
-+                      goto out;
-+              }
-+
-+              rphy->identify = identify;
-+              error = sas_rphy_add(rphy);
-+              if (error) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                              "%s: exit at line=%d\n", ioc->name,
-+                              __FUNCTION__, __LINE__));
-+                      sas_rphy_free(rphy);
-+                      goto out;
-+              }
-+              mptsas_set_rphy(ioc, phy_info, rphy);
-+      }
-+
-+ out:
-+      return error;
-+}
-+
-+/**
-+ *    mptsas_probe_hba_phys -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @handle:
-+ *
-+ **/
-+static int
-+mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
-+{
-+      struct mptsas_portinfo *port_info, *hba;
-+      int error = -ENOMEM, i;
-+
-+      hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
-+      if (! hba)
-+              goto out;
-+
-+      error = mptsas_sas_io_unit_pg0(ioc, hba);
-+      if (error)
-+              goto out_free_port_info;
-+
-+      mptsas_sas_io_unit_pg1(ioc);
-+      mutex_lock(&ioc->sas_topology_mutex);
-+      port_info = ioc->hba_port_info;
-+      if (!port_info) {
-+              ioc->hba_port_info = port_info = hba;
-+              ioc->hba_port_num_phy = port_info->num_phys;
-+              list_add_tail(&port_info->list, &ioc->sas_topology);
-+      } else {
-+              for (i = 0; i < hba->num_phys; i++) {
-+                      port_info->phy_info[i].negotiated_link_rate =
-+                              hba->phy_info[i].negotiated_link_rate;
-+                      port_info->phy_info[i].handle =
-+                              hba->phy_info[i].handle;
-+                      port_info->phy_info[i].port_id =
-+                              hba->phy_info[i].port_id;
-+                      port_info->phy_info[i].port_flags =
-+                          hba->phy_info[i].port_flags;
-+              }
-+              kfree(hba->phy_info);
-+              kfree(hba);
-+              hba = NULL;
-+      }
-+      mutex_unlock(&ioc->sas_topology_mutex);
-+#if defined(CPQ_CIM)
-+      ioc->num_ports = port_info->num_phys;
-+#endif
-+      for (i = 0; i < port_info->num_phys; i++) {
-+              mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
-+                      (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
-+                       MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
-+              port_info->phy_info[i].identify.handle =
-+                  port_info->phy_info[i].handle;
-+              mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
-+                      (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
-+                       MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+                       port_info->phy_info[i].identify.handle);
-+              if (!ioc->hba_port_sas_addr)
-+                      ioc->hba_port_sas_addr =
-+                          port_info->phy_info[i].identify.sas_address;
-+              port_info->phy_info[i].identify.phy_id =
-+                  port_info->phy_info[i].phy_id = i;
-+              if (port_info->phy_info[i].attached.handle)
-+                      mptsas_sas_device_pg0(ioc,
-+                              &port_info->phy_info[i].attached,
-+                              (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
-+                               MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+                              port_info->phy_info[i].attached.handle);
-+      }
-+
-+      mptsas_setup_wide_ports(ioc, port_info);
-+
-+      for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
-+              mptsas_probe_one_phy(&ioc->sh->shost_gendev,
-+                  &port_info->phy_info[i], ioc->sas_index, 1);
-+
-+      return 0;
-+
-+ out_free_port_info:
-+      kfree(hba);
-+ out:
-+      return error;
-+}
-+
-+/**
-+ *    mptsas_find_phyinfo_by_sas_address -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @sas_address:
-+ *
-+ **/
-+static struct mptsas_phyinfo *
-+mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
-+{
-+      struct mptsas_portinfo *port_info;
-+      struct mptsas_phyinfo *phy_info = NULL;
-+      int i;
-+
-+      mutex_lock(&ioc->sas_topology_mutex);
-+      list_for_each_entry(port_info, &ioc->sas_topology, list) {
-+              for (i = 0; i < port_info->num_phys; i++) {
-+                      if (!mptsas_is_end_device(
-+                              &port_info->phy_info[i].attached))
-+                              continue;
-+                      if (port_info->phy_info[i].attached.sas_address
-+                          != sas_address)
-+                              continue;
-+                      phy_info = &port_info->phy_info[i];
-+                      break;
-+              }
-+      }
-+      mutex_unlock(&ioc->sas_topology_mutex);
-+      return phy_info;
-+}
-+
-+/**
-+ *    mptsas_find_phyinfo_by_phys_disk_num -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @phys_disk_num:
-+ *    @channel:
-+ *    @id:
-+ *
-+ **/
-+static struct mptsas_phyinfo *
-+mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num,
-+      u8 channel, u8 id)
-+{
-+      struct mptsas_phyinfo *phy_info;
-+      struct mptsas_portinfo *port_info;
-+      RaidPhysDiskPage1_t *phys_disk = NULL;
-+      int num_paths;
-+      u64 sas_address = 0;
-+      int i;
-+
-+      phy_info = NULL;
-+      if (!ioc->raid_data.pIocPg3)
-+              return NULL;
-+      /* dual port support */
-+      num_paths = mpt_raid_phys_disk_get_num_paths(ioc, phys_disk_num);
-+      if (!num_paths)
-+              goto out;
-+      phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t,Path) +
-+         (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
-+      if (!phys_disk)
-+              goto out;
-+      mpt_raid_phys_disk_pg1(ioc, phys_disk_num, phys_disk);
-+      for (i = 0; i < num_paths; i++) {
-+              if ((phys_disk->Path[i].Flags & 1) != 0)
-+                      /* entry no longer valid */
-+                      continue;
-+              if ((id == phys_disk->Path[i].PhysDiskID) &&
-+                  (channel == phys_disk->Path[i].PhysDiskBus)) {
-+                      memcpy(&sas_address, &phys_disk->Path[i].WWID,
-+                              sizeof(u64));
-+                      phy_info = mptsas_find_phyinfo_by_sas_address(ioc, sas_address);
-+                      goto out;
-+              }
-+      }
-+
-+ out:
-+      kfree(phys_disk);
-+      if (phy_info)
-+              return phy_info;
-+
-+      /*
-+       * Extra code to handle RAID0 case, where the sas_address is not updated
-+       * in phys_disk_page_1 when hotswapped
-+       */
-+      mutex_lock(&ioc->sas_topology_mutex);
-+      list_for_each_entry(port_info, &ioc->sas_topology, list) {
-+              for (i = 0; i < port_info->num_phys && !phy_info; i++) {
-+                      if (!mptsas_is_end_device(
-+                              &port_info->phy_info[i].attached))
-+                              continue;
-+                      if (port_info->phy_info[i].attached.phys_disk_num == ~0)
-+                              continue;
-+                      if (port_info->phy_info[i].attached.phys_disk_num == phys_disk_num &&
-+                          port_info->phy_info[i].attached.id == id &&
-+                          port_info->phy_info[i].attached.channel == channel)
-+                              phy_info = &port_info->phy_info[i];
-+              }
-+      }
-+      mutex_unlock(&ioc->sas_topology_mutex);
-+      return phy_info;
-+}
-+
-+/**
-+ *    mptsas_reprobe_lun -
-+ *    @sdev:
-+ *    @data:
-+ *
-+ **/
-+static void
-+mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
-+{
-+      int rc;
-+
-+      sdev->no_uld_attach = data ? 1 : 0;
-+      rc = scsi_device_reprobe(sdev);
-+}
-+
-+/**
-+ *    mptsas_reprobe_target -
-+ *    @starget:
-+ *    @uld_attach:
-+ *
-+ **/
-+static void
-+mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
-+{
-+      starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
-+                      mptsas_reprobe_lun);
-+}
-+
-+/**
-+ *    mptsas_adding_inactive_raid_components -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @channel:
-+ *    @id:
-+ *
-+ *
-+ *     TODO: check for hotspares
-+ **/
-+static void
-+mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
-+{
-+      CONFIGPARMS                     cfg;
-+      ConfigPageHeader_t              hdr;
-+      dma_addr_t                      dma_handle;
-+      pRaidVolumePage0_t              buffer = NULL;
-+      RaidPhysDiskPage0_t             phys_disk;
-+      int                             i;
-+      struct mptsas_phyinfo           *phy_info;
-+      struct mptsas_devinfo           sas_device;
-+
-+      memset(&cfg, 0 , sizeof(CONFIGPARMS));
-+      memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
-+      hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
-+      cfg.pageAddr = (channel << 8) + id;
-+      cfg.cfghdr.hdr = &hdr;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
--      cfg.dir = 0;    /* read */
--      cfg.timeout = 10;
-+      cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
+-                      printk(MYIOC_s_ERR_FMT "Wait IOC_READY state (0x%x) timeout(%d)!\n",
+-                                      ioc->name, state, (int)((count+5)/HZ));
++                      printk(MYIOC_s_ERR_FMT
++                          "Wait IOC_READY state (0x%x) timeout(%d)!\n",
++                          ioc->name, state, (int)((count+5)/HZ));
+                       return -ETIME;
+               }
  
--      error = mpt_config(ioc, &cfg);
--      if (error)
-+      if (mpt_config(ioc, &cfg) != 0)
-               goto out;
+@@ -4176,23 +4261,20 @@ SendIocReset(MPT_ADAPTER *ioc, u8 reset_
+               }
+       }
+-      /* TODO!
+-       *  Cleanup all event stuff for this IOC; re-issue EventNotification
+-       *  request if needed.
+-       */
+       if (ioc->facts.Function)
+               ioc->facts.EventState = 0;
+       return 0;
+ }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    initChainBuffers - Allocate memory for and initialize chain buffers
+  *    @ioc: Pointer to MPT_ADAPTER structure
+  *
+  *    Allocates memory for and initializes chain buffers,
+  *    chain buffer control arrays and spinlock.
+- **/
++ */
+ static int
+ initChainBuffers(MPT_ADAPTER *ioc)
+ {
+@@ -4234,11 +4316,11 @@ initChainBuffers(MPT_ADAPTER *ioc)
+        * num_sge = num sge in request frame + last chain buffer
+        * scale = num sge per chain buffer if no chain element
+        */
+-      scale = ioc->req_sz/ ioc->SGE_size;
++      scale = ioc->req_sz / ioc->SGE_size;
+       if (ioc->sg_addr_size == sizeof(u64))
+               num_sge =  scale + (ioc->req_sz - 60) / ioc->SGE_size;
+       else
+-              num_sge =  1+ scale + (ioc->req_sz - 64) / ioc->SGE_size;
++              num_sge =  1 + scale + (ioc->req_sz - 64) / ioc->SGE_size;
  
--      if (!hdr.ExtPageLength) {
--              error = -ENXIO;
-+      if (!hdr.PageLength)
-               goto out;
+       if (ioc->sg_addr_size == sizeof(u64)) {
+               numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
+@@ -4253,8 +4335,7 @@ initChainBuffers(MPT_ADAPTER *ioc)
+       if (ioc->bus_type == FC) {
+               if (numSGE > MPT_SCSI_FC_SG_DEPTH)
+                       numSGE = MPT_SCSI_FC_SG_DEPTH;
 -      }
+-      else {
++      } else {
+               if (numSGE > MPT_SCSI_SG_DEPTH)
+                       numSGE = MPT_SCSI_SG_DEPTH;
+       }
+@@ -4292,6 +4373,7 @@ initChainBuffers(MPT_ADAPTER *ioc)
+       return num_chain;
+ }
  
--      buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
--                                    &dma_handle);
--      if (!buffer) {
--              error = -ENOMEM;
-+      buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
-+          &dma_handle);
-+
-+      if (!buffer)
-               goto out;
--      }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    PrimeIocFifos - Initialize IOC request and reply FIFOs.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -4301,7 +4383,7 @@ initChainBuffers(MPT_ADAPTER *ioc)
+  *    reply frames.
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
+ static int
+ PrimeIocFifos(MPT_ADAPTER *ioc)
+ {
+@@ -4513,6 +4595,7 @@ out_fail:
+       return -1;
+ }
  
-       cfg.physAddr = dma_handle;
-       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_handshake_req_reply_wait - Send MPT request to and receive reply
+  *    from IOC via doorbell handshake method.
+@@ -4530,7 +4613,7 @@ out_fail:
+  *    greater than 1 byte in size.
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
+ static int
+ mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
+               int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
+@@ -4624,6 +4707,7 @@ mpt_handshake_req_reply_wait(MPT_ADAPTER
+       return -failcnt;
+ }
  
--      error = mpt_config(ioc, &cfg);
--      if (error)
--              goto out_free_consistent;
--
--
--      mptsas_print_expander_pg1(ioc, buffer);
--
--      /* save config data */
--      phy_info->phy_id = buffer->PhyIdentifier;
--      phy_info->port_id = buffer->PhysicalPort;
--      phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
--      phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
--      phy_info->hw_link_rate = buffer->HwLinkRate;
--      phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
--      phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
-+      if (mpt_config(ioc, &cfg) != 0)
-+              goto out;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    WaitForDoorbellAck - Wait for IOC doorbell handshake acknowledge
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -4635,7 +4719,7 @@ mpt_handshake_req_reply_wait(MPT_ADAPTER
+  *    bit in its IntStatus register being clear.
+  *
+  *    Returns a negative value on failure, else wait loop count.
+- **/
++ */
+ static int
+ WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
+ {
+@@ -4674,6 +4758,7 @@ WaitForDoorbellAck(MPT_ADAPTER *ioc, int
+       return -1;
+ }
  
-- out_free_consistent:
--      pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
--                          buffer, dma_handle);
-- out:
--      return error;
--}
-+      if (!(buffer->VolumeStatus.Flags &
-+          MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
-+              goto out;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    WaitForDoorbellInt - Wait for IOC to set its doorbell interrupt bit
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -4684,7 +4769,7 @@ WaitForDoorbellAck(MPT_ADAPTER *ioc, int
+  *    (MPI_HIS_DOORBELL_INTERRUPT) to be set in the IntStatus register.
+  *
+  *    Returns a negative value on failure, else wait loop count.
+- **/
++ */
+ static int
+ WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
+ {
+@@ -4703,7 +4788,7 @@ WaitForDoorbellInt(MPT_ADAPTER *ioc, int
+               }
+       } else {
+               while (--cntdn) {
+-                      udelay (1000);
++                      udelay(1000);
+                       intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
+                       if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
+                               break;
+@@ -4722,6 +4807,7 @@ WaitForDoorbellInt(MPT_ADAPTER *ioc, int
+       return -1;
+ }
  
--static void
--mptsas_parse_device_info(struct sas_identify *identify,
--              struct mptsas_devinfo *device_info)
--{
--      u16 protocols;
-+      if (!buffer->NumPhysDisks)
-+              goto out;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    WaitForDoorbellReply - Wait for and capture an IOC handshake reply.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -4733,7 +4819,7 @@ WaitForDoorbellInt(MPT_ADAPTER *ioc, int
+  *    of 128 bytes of reply data.
+  *
+  *    Returns a negative value on failure, else size of reply in WORDS.
+- **/
++ */
+ static int
+ WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
+ {
+@@ -4807,6 +4893,7 @@ WaitForDoorbellReply(MPT_ADAPTER *ioc, i
+       return u16cnt/2;
+ }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    GetLanConfigPages - Fetch LANConfig pages.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -4816,7 +4903,7 @@ WaitForDoorbellReply(MPT_ADAPTER *ioc, i
+  *            -EPERM if not allowed due to ISR context
+  *            -EAGAIN if no msg frames currently available
+  *            -EFAULT for non-successful reply or no reply (timeout)
+- **/
++ */
+ static int
+ GetLanConfigPages(MPT_ADAPTER *ioc)
+ {
+@@ -4863,10 +4950,6 @@ GetLanConfigPages(MPT_ADAPTER *ioc)
  
--      identify->sas_address = device_info->sas_address;
--      identify->phy_identifier = device_info->phy_id;
-+      for (i = 0; i < buffer->NumPhysDisks; i++) {
+                       pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
  
--      /*
--       * Fill in Phy Initiator Port Protocol.
--       * Bits 6:3, more than one bit can be set, fall through cases.
--       */
--      protocols = device_info->device_info & 0x78;
--      identify->initiator_port_protocols = 0;
--      if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
--              identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
--      if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
--              identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
--      if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
--              identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
--      if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
--              identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
-+              if (mpt_raid_phys_disk_pg0(ioc,
-+                  buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
-+                      continue;
+-                      /* FIXME!
+-                       *      Normalize endianness of structure data,
+-                       *      by byte-swapping all > 1 byte fields!
+-                       */
  
--      /*
--       * Fill in Phy Target Port Protocol.
--       * Bits 10:7, more than one bit can be set, fall through cases.
--       */
--      protocols = device_info->device_info & 0x780;
--      identify->target_port_protocols = 0;
--      if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
--              identify->target_port_protocols |= SAS_PROTOCOL_SSP;
--      if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
--              identify->target_port_protocols |= SAS_PROTOCOL_STP;
--      if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
--              identify->target_port_protocols |= SAS_PROTOCOL_SMP;
--      if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
--              identify->target_port_protocols |= SAS_PROTOCOL_SATA;
-+              if (mptsas_sas_device_pg0(ioc, &sas_device,
-+                  (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
-+                   MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+                      (phys_disk.PhysDiskBus << 8) +
-+                      phys_disk.PhysDiskID))
-+                      continue;
--      /*
--       * Fill in Attached device type.
--       */
--      switch (device_info->device_info &
--                      MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
--      case MPI_SAS_DEVICE_INFO_NO_DEVICE:
--              identify->device_type = SAS_PHY_UNUSED;
--              break;
--      case MPI_SAS_DEVICE_INFO_END_DEVICE:
--              identify->device_type = SAS_END_DEVICE;
--              break;
--      case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
--              identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
--              break;
--      case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
--              identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
--              break;
-+              phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
-+                  sas_device.sas_address);
-+              mptsas_add_end_device(ioc, phy_info);
+               }
+@@ -4907,16 +4990,12 @@ GetLanConfigPages(MPT_ADAPTER *ioc)
+               pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
+-              /* FIXME!
+-               *      Normalize endianness of structure data,
+-               *      by byte-swapping all > 1 byte fields!
+-               */
+-
        }
-+
-+ out:
-+      if (buffer)
-+              pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
-+                  dma_handle);
+       return rc;
  }
  
--static int mptsas_probe_one_phy(struct device *dev,
--              struct mptsas_phyinfo *phy_info, int index, int local)
-+/**
-+ *    mptsas_add_end_device - report a new end device to sas transport layer
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @phy_info: decribes attached device
-+ *
-+ *    return (0) success (1) failure
-+ *
-+ **/
-+static int
-+mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mptbase_sas_persist_operation - Perform operation on SAS Persistent Table
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -4929,7 +5008,7 @@ GetLanConfigPages(MPT_ADAPTER *ioc)
+  *    NOTE: Don't use not this function during interrupt time.
+  *
+  *    Returns 0 for success, non-zero error
+- **/
++ */
+ int
+ mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode)
  {
--      MPT_ADAPTER *ioc;
--      struct sas_phy *phy;
-+      struct sas_rphy *rphy;
-       struct sas_port *port;
--      int error = 0;
-+      struct sas_identify identify;
-+      char *ds = NULL;
-+      u8 fw_id;
--      if (!dev) {
--              error = -ENODEV;
--              goto out;
-+      if (!phy_info){
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                      "%s: exit at line=%d\n", ioc->name,
-+                      __FUNCTION__, __LINE__));
-+              return 1;
+@@ -4958,12 +5037,12 @@ mptbase_sas_persist_operation(MPT_ADAPTE
+               goto out;
        }
  
--      if (!phy_info->phy) {
--              phy = sas_phy_alloc(dev, index);
--              if (!phy) {
--                      error = -ENOMEM;
--                      goto out;
--              }
--      } else
--              phy = phy_info->phy;
--
--      mptsas_parse_device_info(&phy->identify, &phy_info->identify);
--
--      /*
--       * Set Negotiated link rate.
--       */
--      switch (phy_info->negotiated_link_rate) {
--      case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
--              phy->negotiated_linkrate = SAS_PHY_DISABLED;
--              break;
--      case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
--              phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
--              break;
--      case MPI_SAS_IOUNIT0_RATE_1_5:
--              phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
--              break;
--      case MPI_SAS_IOUNIT0_RATE_3_0:
--              phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
--              break;
--      case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
--      case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
--      default:
--              phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
--              break;
--      }
-+      fw_id = phy_info->attached.id;
+-      printk("%s: persist_opcode=%x\n",__FUNCTION__, persist_opcode);
++      printk("%s: persist_opcode=%x\n",__func__, persist_opcode);
  
--      /*
--       * Set Max hardware link rate.
--       */
--      switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
--      case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
--              phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
--              break;
--      case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
--              phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
--              break;
--      default:
--              break;
-+      if (mptsas_get_rphy(phy_info)) {
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                      "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                      __FUNCTION__, fw_id, __LINE__));
-+              return 2;
-       }
+       /* Get a MF for this command.
+        */
+       if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
+-              printk("%s: no msg frames!\n",__FUNCTION__);
++              printk("%s: no msg frames!\n",__func__);
+               ret = -1;
+               goto out;
+         }
+@@ -4979,12 +5058,12 @@ mptbase_sas_persist_operation(MPT_ADAPTE
+       timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done, 10*HZ);
+       if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               ret = -ETIME;
+-              printk("%s: failed\n", __FUNCTION__);
++              printk(KERN_WARNING "%s: failed\n", __func__);
+               if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
+                       goto out;
+               if (!timeleft) {
+                       printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
+-                          ioc->name, __FUNCTION__);
++                          ioc->name, __func__);
+                       if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
+                               mpt_HardResetHandler(ioc, CAN_SLEEP);
+                       mpt_free_msg_frame(ioc, mf);
+@@ -5000,12 +5079,13 @@ mptbase_sas_persist_operation(MPT_ADAPTE
+       sasIoUnitCntrReply =
+           (SasIoUnitControlReply_t *)ioc->mptbase_cmds.reply;
+       if (le16_to_cpu(sasIoUnitCntrReply->IOCStatus) != MPI_IOCSTATUS_SUCCESS) {
+-              printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n", __FUNCTION__,
+-                  sasIoUnitCntrReply->IOCStatus, sasIoUnitCntrReply->IOCLogInfo);
+-              printk("%s: failed\n",__FUNCTION__);
++              printk(KERN_WARNING "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
++                  __func__, sasIoUnitCntrReply->IOCStatus,
++                  sasIoUnitCntrReply->IOCLogInfo);
++              printk(KERN_WARNING "%s: failed\n", __func__);
+               ret = -1;
+       } else
+-              printk("%s: success\n",__FUNCTION__);
++              printk(KERN_INFO "%s: success\n", __func__);
+  out:
  
--      /*
--       * Set Max programmed link rate.
--       */
--      switch (phy_info->programmed_link_rate &
--                      MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
--      case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
--              phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
--              break;
--      case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
--              phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
--              break;
--      default:
--              break;
-+      port = mptsas_get_port(phy_info);
-+      if (!port) {
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                      "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                      __FUNCTION__, fw_id, __LINE__));
-+              return 3;
-+      }
-+
-+      if (phy_info->attached.device_info &
-+          MPI_SAS_DEVICE_INFO_SSP_TARGET)
-+              ds = "ssp";
-+      if (phy_info->attached.device_info &
-+          MPI_SAS_DEVICE_INFO_STP_TARGET)
-+              ds = "stp";
-+      if (phy_info->attached.device_info &
-+          MPI_SAS_DEVICE_INFO_SATA_DEVICE)
-+              ds = "sata";
-+
-+      printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d,"
-+          " phy %d, sas_addr 0x%llx\n", ioc->name, ds,
-+          phy_info->attached.channel, phy_info->attached.id,
-+          phy_info->attached.phy_id, (unsigned long long)
-+          phy_info->attached.sas_address);
-+
-+      mptsas_parse_device_info(&identify, &phy_info->attached);
-+      rphy = sas_end_device_alloc(port);
-+      if (!rphy) {
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                      "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                      __FUNCTION__, fw_id, __LINE__));
-+              return 5; /* non-fatal: an rphy can be added later */
-+      }
+       CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
+@@ -5013,6 +5093,8 @@ mptbase_sas_persist_operation(MPT_ADAPTE
+       return ret;
+ }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 +
-+      rphy->identify = identify;
-+      if (sas_rphy_add(rphy)) {
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                      "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                      __FUNCTION__, fw_id, __LINE__));
-+              sas_rphy_free(rphy);
-+              return 6;
+ static void
+ mptbase_raid_process_event_data(MPT_ADAPTER *ioc,
+     MpiEventDataRaid_t * pRaidEventData)
+@@ -5143,6 +5225,7 @@ mptbase_raid_process_event_data(MPT_ADAP
        }
-+      mptsas_set_rphy(ioc, phy_info, rphy);
-+      return 0;
-+}
+ }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    GetIoUnitPage2 - Retrieve BIOS version and boot order information.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -5152,7 +5235,7 @@ mptbase_raid_process_event_data(MPT_ADAP
+  *            -EPERM if not allowed due to ISR context
+  *            -EAGAIN if no msg frames currently available
+  *            -EFAULT for non-successful reply or no reply (timeout)
+- **/
++ */
+ static int
+ GetIoUnitPage2(MPT_ADAPTER *ioc)
+ {
+@@ -5200,6 +5283,7 @@ GetIoUnitPage2(MPT_ADAPTER *ioc)
+       return rc;
+ }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
+  *    @ioc: Pointer to a Adapter Strucutre
+@@ -5219,7 +5303,7 @@ GetIoUnitPage2(MPT_ADAPTER *ioc)
+  *            Both valid
+  *            Return 0
+  *    CHECK - what type of locking mechanisms should be used????
+- **/
++ */
+ static int
+ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
+ {
+@@ -5290,7 +5374,8 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
+                               if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
+                                       ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
+-                                      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "noQas due to Capabilities=%x\n",
++                                      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                                              "noQas due to Capabilities=%x\n",
+                                               ioc->name, pPP0->Capabilities));
+                               }
+                               ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
+@@ -5299,7 +5384,8 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
+                                       ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
+                                       data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
+                                       ioc->spi_data.minSyncFactor = (u8) (data >> 8);
+-                                      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PortPage0 minSyncFactor=%x\n",
++                                      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                                              "PortPage0 minSyncFactor=%x\n",
+                                               ioc->name, ioc->spi_data.minSyncFactor));
+                               } else {
+                                       ioc->spi_data.maxSyncOffset = 0;
+@@ -5315,7 +5401,8 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
+                                       if (ioc->spi_data.minSyncFactor < MPT_ULTRA) {
+                                               ioc->spi_data.minSyncFactor = MPT_ULTRA;
+-                                              ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HVD or SE detected, minSyncFactor=%x\n",
++                                              ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                                                      "HVD or SE detected, minSyncFactor=%x\n",
+                                                       ioc->name, ioc->spi_data.minSyncFactor));
+                                       }
+                               }
+@@ -5420,6 +5507,7 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
+       return rc;
+ }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_readScsiDevicePageHeaders - save version and length of SDP1
+  *    @ioc: Pointer to a Adapter Strucutre
+@@ -5427,7 +5515,7 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc
+  *
+  *    Return: -EFAULT if read of config page header fails
+  *            or 0 if success.
+- **/
++ */
+ static int
+ mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
+ {
+@@ -5475,7 +5563,7 @@ mpt_read_ioc_pg_6(MPT_ADAPTER *ioc)
+ {
+       CONFIGPARMS              cfg;
+       ConfigPageHeader_t       header;
+-      IOCPage6_t              *pIoc6=NULL;
++      IOCPage6_t              *pIoc6 = NULL;
+       dma_addr_t               ioc6_dma;
+       int                      iocpage6sz;
+       void                    *mem;
+@@ -5546,13 +5634,13 @@ mpt_inactive_raid_list_free(MPT_ADAPTER 
+       if (list_empty(&ioc->raid_data.inactive_list))
+               return;
+-      down(&ioc->raid_data.inactive_list_mutex);
++      mutex_lock(&ioc->raid_data.inactive_list_mutex);
+       list_for_each_entry_safe(component_info, pNext,
+           &ioc->raid_data.inactive_list, list) {
+               list_del(&component_info->list);
+               kfree(component_info);
+       }
+-      up(&ioc->raid_data.inactive_list_mutex);
++      mutex_unlock(&ioc->raid_data.inactive_list_mutex);
+ }
  
--      /*
--       * Set Min hardware link rate.
--       */
--      switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
--      case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
--              phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
--              break;
--      case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
--              phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
--              break;
--      default:
--              break;
--      }
-+/**
-+ *    mptsas_del_end_device - report a deleted end device to sas transport
-+ *    layer
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @phy_info: decribes attached device
-+ *
-+ **/
-+static void
-+mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
-+{
-+      struct sas_rphy *rphy;
-+      struct sas_port *port;
-+      struct mptsas_portinfo *port_info;
-+      struct mptsas_phyinfo *phy_info_parent;
-+      int i;
-+      struct scsi_target * starget;
-+      char *ds = NULL;
-+      u8 fw_id;
-+      u64 sas_address;
--      /*
--       * Set Min programmed link rate.
--       */
--      switch (phy_info->programmed_link_rate &
--                      MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
--      case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
--              phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
--              break;
--      case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
--              phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
--              break;
--      default:
--              break;
--      }
-+      if (!phy_info)
-+              return;
+ /**
+@@ -5615,7 +5703,7 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *i
+       if (!handle_inactive_volumes)
+               goto out;
  
--      if (!phy_info->phy) {
-+      fw_id = phy_info->attached.id;
-+      sas_address = phy_info->attached.sas_address;
+-      down(&ioc->raid_data.inactive_list_mutex);
++      mutex_lock(&ioc->raid_data.inactive_list_mutex);
+       for (i = 0; i < buffer->NumPhysDisks; i++) {
+               if(mpt_raid_phys_disk_pg0(ioc,
+                   buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
+@@ -5631,7 +5719,7 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *i
+                   buffer->PhysDisk[i].PhysDiskNum);
+               if (num_paths < 2)
+                       continue;
+-              phys_disk_1 = kzalloc(offsetof(RaidPhysDiskPage1_t,Path) +
++              phys_disk_1 = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
+                  (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
+               if (!phys_disk_1)
+                       continue;
+@@ -5658,7 +5746,7 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *i
+               list_add_tail(&component_info->list,
+                   &ioc->raid_data.inactive_list);
+       }
+-      up(&ioc->raid_data.inactive_list_mutex);
++      mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  
--              error = sas_phy_add(phy);
--              if (error) {
--                      sas_phy_free(phy);
--                      goto out;
--              }
--              phy_info->phy = phy;
-+      if (!phy_info->port_details) {
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                      "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                      __FUNCTION__, fw_id, __LINE__));
-+              return;
+  out:
+       if (buffer)
+@@ -5678,7 +5766,8 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *i
+  *    -ENOMEM if pci_alloc failed
+  **/
+ int
+-mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, RaidPhysDiskPage0_t *phys_disk)
++mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num,
++    RaidPhysDiskPage0_t *phys_disk)
+ {
+       CONFIGPARMS                     cfg;
+       ConfigPageHeader_t              hdr;
+@@ -5812,7 +5901,8 @@ mpt_raid_phys_disk_get_num_paths(MPT_ADA
+  *    -ENOMEM if pci_alloc failed
+  **/
+ int
+-mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc, u8 phys_disk_num, RaidPhysDiskPage1_t *phys_disk)
++mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc, u8 phys_disk_num,
++    RaidPhysDiskPage1_t *phys_disk)
+ {
+       CONFIGPARMS                     cfg;
+       ConfigPageHeader_t              hdr;
+@@ -5865,14 +5955,20 @@ mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc,
+       for (i = 0; i < phys_disk->NumPhysDiskPaths; i++) {
+               phys_disk->Path[i].PhysDiskID = buffer->Path[i].PhysDiskID;
+               phys_disk->Path[i].PhysDiskBus = buffer->Path[i].PhysDiskBus;
+-              phys_disk->Path[i].OwnerIdentifier = buffer->Path[i].OwnerIdentifier;
+-              phys_disk->Path[i].Flags = le16_to_cpu(buffer->Path[i].Flags);
+-              memcpy(&sas_address, &buffer->Path[i].WWID, sizeof(__le64));
++              phys_disk->Path[i].OwnerIdentifier =
++                  buffer->Path[i].OwnerIdentifier;
++              phys_disk->Path[i].Flags =
++                  le16_to_cpu(buffer->Path[i].Flags);
++              memcpy(&sas_address, &buffer->Path[i].WWID,
++                  sizeof(__le64));
+               sas_address = le64_to_cpu(sas_address);
+-              memcpy(&phys_disk->Path[i].WWID, &sas_address, sizeof(__le64));
+-              memcpy(&sas_address, &buffer->Path[i].OwnerWWID, sizeof(__le64));
++              memcpy(&phys_disk->Path[i].WWID, &sas_address,
++                  sizeof(__le64));
++              memcpy(&sas_address, &buffer->Path[i].OwnerWWID,
++                  sizeof(__le64));
+               sas_address = le64_to_cpu(sas_address);
+-              memcpy(&phys_disk->Path[i].OwnerWWID, &sas_address, sizeof(__le64));
++              memcpy(&phys_disk->Path[i].OwnerWWID, &sas_address,
++                  sizeof(__le64));
        }
--
--      if (!phy_info->attached.handle ||
--                      !phy_info->port_details)
--              goto out;
-+      rphy = mptsas_get_rphy(phy_info);
-+      if (!rphy) {
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                      "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                      __FUNCTION__, fw_id, __LINE__));
-+              return;
-+      }
-+      if (phy_info->attached.device_info &
-+          MPI_SAS_DEVICE_INFO_SSP_TARGET)
-+              ds = "ssp";
-+      if (phy_info->attached.device_info &
-+          MPI_SAS_DEVICE_INFO_STP_TARGET)
-+              ds = "stp";
-+      if (phy_info->attached.device_info &
-+          MPI_SAS_DEVICE_INFO_SATA_DEVICE)
-+              ds = "sata";
-+
-+      starget = mptsas_get_starget(phy_info);
-+
-+      printk(MYIOC_s_INFO_FMT "removing %s device: fw_channel %d,"
-+          " fw_id %d, phy %d, sas_addr 0x%llx\n", ioc->name, ds,
-+          phy_info->attached.channel, phy_info->attached.id,
-+          phy_info->attached.phy_id, (unsigned long long)
-+          sas_address);
-       port = mptsas_get_port(phy_info);
--      ioc = phy_to_ioc(phy_info->phy);
-+      if (!port) {
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                      "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                      __FUNCTION__, fw_id, __LINE__));
-+              return;
-+      }
-+      port_info = phy_info->portinfo;
-+      phy_info_parent = port_info->phy_info;
-+      for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) {
-+              if(!phy_info_parent->phy)
-+                      continue;
-+              if (phy_info_parent->attached.sas_address !=
-+                  sas_address)
-+                      continue;
-+              dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev,
-+                  MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n",
-+                  ioc->name, phy_info_parent->phy_id,
-+                  phy_info_parent->phy);
-+              sas_port_delete_phy(port, phy_info_parent->phy);
-+      }
-+
-+      dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
-+          "delete port %d, sas_addr (0x%llx)\n", ioc->name,
-+           port->port_identifier, (unsigned long long)sas_address);
-+      sas_port_delete(port);
-+//    mptsas_port_delete(ioc, phy_info->port_details);
-+}
  
--      if (phy_info->sas_port_add_phy) {
-+struct mptsas_phyinfo *
-+mptsas_refreshing_device_handles(MPT_ADAPTER *ioc, struct mptsas_devinfo *sas_device)
-+{
-+      struct mptsas_phyinfo *phy_info;
-+      struct mptsas_portinfo *port_info;
-+      int i;
--              if (!port) {
--                      port = sas_port_alloc_num(dev);
--                      if (!port) {
--                              error = -ENOMEM;
--                              goto out;
--                      }
--                      error = sas_port_add(port);
--                      if (error) {
--                              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                                      "%s: exit at line=%d\n", ioc->name,
--                                      __func__, __LINE__));
--                              goto out;
--                      }
--                      mptsas_set_port(ioc, phy_info, port);
--                      dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                          "sas_port_alloc: port=%p dev=%p port_id=%d\n",
--                          ioc->name, port, dev, port->port_identifier));
--              }
--              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_port_add_phy: phy_id=%d\n",
--                  ioc->name, phy_info->phy_id));
--              sas_port_add_phy(port, phy_info->phy);
--              phy_info->sas_port_add_phy = 0;
-+      phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
-+          sas_device->sas_address);
-+      if (!phy_info)
-+              goto out;
-+      port_info = phy_info->portinfo;
-+      if (!port_info)
-+              goto out;
-+      mutex_lock(&ioc->sas_topology_mutex);
-+      for (i = 0; i < port_info->num_phys; i++) {
-+              if(port_info->phy_info[i].attached.sas_address !=
-+                  sas_device->sas_address)
-+                      continue;
-+              port_info->phy_info[i].attached.channel = sas_device->channel;
-+              port_info->phy_info[i].attached.id = sas_device->id;
-+              port_info->phy_info[i].attached.sas_address =
-+                  sas_device->sas_address;
-+              port_info->phy_info[i].attached.handle = sas_device->handle;
-+              port_info->phy_info[i].attached.handle_parent =
-+                  sas_device->handle_parent;
-+              port_info->phy_info[i].attached.handle_enclosure =
-+                  sas_device->handle_enclosure;
-       }
-+      mutex_unlock(&ioc->sas_topology_mutex);
-+ out:
-+      return phy_info;
-+}
+  out:
+@@ -5896,8 +5992,8 @@ mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc,
+ static int
+ mpt_sort_ioc_pg2(const void *a, const void *b)
+ {
+-      ConfigPageIoc2RaidVol_t * volume_a = (ConfigPageIoc2RaidVol_t *)a;
+-      ConfigPageIoc2RaidVol_t * volume_b = (ConfigPageIoc2RaidVol_t *)b;
++      ConfigPageIoc2RaidVol_t *volume_a = (ConfigPageIoc2RaidVol_t *)a;
++      ConfigPageIoc2RaidVol_t *volume_b = (ConfigPageIoc2RaidVol_t *)b;
  
--      if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
--
--              struct sas_rphy *rphy;
--              struct device *parent;
--              struct sas_identify identify;
--              parent = dev->parent->parent;
--              /*
--               * Let the hotplug_work thread handle processing
--               * the adding/removing of devices that occur
--               * after start of day.
--               */
--              if (ioc->sas_discovery_runtime &&
--                      mptsas_is_end_device(&phy_info->attached))
--                              goto out;
-+/**
-+ *    mptsas_hotplug_work - Work queue thread to handle SAS hotplug events
-+ *
-+ *
-+ **/
-+static void
-+mptsas_hotplug_work(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
-+    struct mptsas_hotplug_event *hot_plug_info)
-+{
-+      struct mptsas_phyinfo *phy_info;
-+      struct scsi_target * starget;
-+      struct mptsas_devinfo sas_device;
-+      VirtTarget *vtarget;
-+      enum device_state state;
-+      int i;
--              mptsas_parse_device_info(&identify, &phy_info->attached);
--              if (scsi_is_host_device(parent)) {
--                      struct mptsas_portinfo *port_info;
--                      int i;
-+      switch (hot_plug_info->event_type) {
--                      mutex_lock(&ioc->sas_topology_mutex);
--                      port_info = mptsas_get_hba_portinfo(ioc);
--                      mutex_unlock(&ioc->sas_topology_mutex);
-+      case MPTSAS_ADD_PHYSDISK:
--                      for (i = 0; i < port_info->num_phys; i++)
--                              if (port_info->phy_info[i].identify.sas_address ==
--                                  identify.sas_address) {
--                                      sas_port_mark_backlink(port);
--                                      goto out;
--                              }
-+              if (!ioc->raid_data.pIocPg2)
-+                      break;
--              } else if (scsi_is_sas_rphy(parent)) {
--                      struct sas_rphy *parent_rphy = dev_to_rphy(parent);
--                      if (identify.sas_address ==
--                          parent_rphy->identify.sas_address) {
--                              sas_port_mark_backlink(port);
--                              goto out;
-+              for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
-+                      if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID ==
-+                          hot_plug_info->id) {
-+                              printk(MYIOC_s_WARN_FMT "firmware bug: unable "
-+                                  "to add hidden disk - target_id matchs "
-+                                  "volume_id\n", ioc->name);
-+                              mptsas_free_fw_event(ioc, fw_event);
-+                              return;
+       if (volume_a->VolumeBus == volume_b->VolumeBus) {
+               if (volume_a->VolumeID == volume_b->VolumeID)
+@@ -6186,7 +6282,8 @@ mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
                        }
-               }
--              switch (identify.device_type) {
--              case SAS_END_DEVICE:
--                      rphy = sas_end_device_alloc(port);
--                      break;
--              case SAS_EDGE_EXPANDER_DEVICE:
--              case SAS_FANOUT_EXPANDER_DEVICE:
--                      rphy = sas_expander_alloc(port, identify.device_type);
-+      case MPTSAS_ADD_DEVICE:
-+              memset(&sas_device, 0, sizeof(struct mptsas_devinfo));
-+              mptsas_sas_device_pg0(ioc, &sas_device,
-+                  (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
-+                  MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+                  (hot_plug_info->channel << 8) +
-+                  hot_plug_info->id);
-+
-+              if (!sas_device.handle)
-+                      return;
-+
-+              phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
-+              if (!phy_info)
-                       break;
--              default:
--                      rphy = NULL;
-+
-+              if (mptsas_get_rphy(phy_info))
-                       break;
--              }
--              if (!rphy) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      goto out;
--              }
  
--              rphy->identify = identify;
--              error = sas_rphy_add(rphy);
--              if (error) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      sas_rphy_free(rphy);
--                      goto out;
-+              state = mptsas_test_unit_ready(ioc, phy_info->attached.channel,
-+                  phy_info->attached.id, fw_event->retries);
-+
-+              if (state == DEVICE_RETRY && !ioc->fw_events_off) {
-+                      mptsas_requeue_fw_event(ioc, fw_event, 1000);
-+                      return;
+               } else {
+-                      dprintk(ioc, printk(MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
++                      dprintk(ioc, printk(MYIOC_s_WARN_FMT
++                              "Coalescing Disabled\n", ioc->name));
                }
--              mptsas_set_rphy(ioc, phy_info, rphy);
--      }
-- out:
--      return error;
--}
-+              if (state == DEVICE_READY)
-+                      mptsas_add_end_device(ioc, phy_info);
-+              break;
--static int
--mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
--{
--      struct mptsas_portinfo *port_info, *hba;
--      int error = -ENOMEM, i;
-+      case MPTSAS_DEL_DEVICE:
--      hba = kzalloc(sizeof(*port_info), GFP_KERNEL);
--      if (! hba)
--              goto out;
-+              if (!ioc->disable_hotplug_remove) {
-+                      phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
-+                          hot_plug_info->sas_address);
-+                      mptsas_del_end_device(ioc, phy_info);
-+              }
-+              break;
--      error = mptsas_sas_io_unit_pg0(ioc, hba);
--      if (error)
--              goto out_free_port_info;
-+      case MPTSAS_DEL_PHYSDISK:
--      mptsas_sas_io_unit_pg1(ioc);
--      mutex_lock(&ioc->sas_topology_mutex);
--      port_info = mptsas_get_hba_portinfo(ioc);
--      if (!port_info) {
--              port_info = hba;
--              list_add_tail(&port_info->list, &ioc->sas_topology);
--      } else {
--              for (i = 0; i < hba->num_phys; i++) {
--                      port_info->phy_info[i].negotiated_link_rate =
--                              hba->phy_info[i].negotiated_link_rate;
--                      port_info->phy_info[i].handle =
--                              hba->phy_info[i].handle;
--                      port_info->phy_info[i].port_id =
--                              hba->phy_info[i].port_id;
--              }
--              kfree(hba->phy_info);
--              kfree(hba);
--              hba = NULL;
--      }
--      mutex_unlock(&ioc->sas_topology_mutex);
--      for (i = 0; i < port_info->num_phys; i++) {
--              mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
--                      (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
--                       MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
-+              mpt_findImVolumes(ioc);
--              mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
--                      (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
--                       MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
--                       port_info->phy_info[i].handle);
--              port_info->phy_info[i].identify.phy_id =
--                  port_info->phy_info[i].phy_id = i;
--              if (port_info->phy_info[i].attached.handle)
--                      mptsas_sas_device_pg0(ioc,
--                              &port_info->phy_info[i].attached,
--                              (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
--                               MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
--                              port_info->phy_info[i].attached.handle);
--      }
-+              phy_info = mptsas_find_phyinfo_by_phys_disk_num(
-+                  ioc, hot_plug_info->phys_disk_num, hot_plug_info->channel,
-+                  hot_plug_info->id);
-+              mptsas_del_end_device(ioc, phy_info);
-+              break;
+       }
  
--      mptsas_setup_wide_ports(ioc, port_info);
-+      case MPTSAS_ADD_PHYSDISK_REPROBE:
+@@ -6238,12 +6335,13 @@ mpt_get_manufacturing_pg_0(MPT_ADAPTER *
+               pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
+ }
  
--      for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
--              mptsas_probe_one_phy(&ioc->sh->shost_gendev,
--                  &port_info->phy_info[i], ioc->sas_index, 1);
-+              if (mptsas_sas_device_pg0(ioc, &sas_device,
-+                  (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
-+                   MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+                  (hot_plug_info->channel << 8) + hot_plug_info->id)) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                      "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                              __FUNCTION__, hot_plug_info->id, __LINE__));
-+                      break;
-+              }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    SendEventNotification - Send EventNotification (on or off) request to adapter
+  *    @ioc: Pointer to MPT_ADAPTER structure
+  *    @EvSwitch: Event switch flags
+  *    @sleepFlag: Specifies whether the process can sleep
+- **/
++ */
+ static int
+ SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch, int sleepFlag)
+ {
+@@ -6262,15 +6360,16 @@ SendEventNotification(MPT_ADAPTER *ioc, 
+           ioc->name, EvSwitch, &evn));
  
--      return 0;
-+              phy_info = mptsas_find_phyinfo_by_sas_address(
-+                  ioc, sas_device.sas_address);
+       return mpt_handshake_req_reply_wait(ioc, sizeof(EventNotification_t),
+-          (u32*)&evn, sizeof(MPIDefaultReply_t), (u16*)&reply_buf, 30,
++          (u32 *)&evn, sizeof(MPIDefaultReply_t), (u16 *)&reply_buf, 30,
+           sleepFlag);
+ }
  
-- out_free_port_info:
--      kfree(hba);
-- out:
--      return error;
--}
-+              if (!phy_info){
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                              "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                              __FUNCTION__, hot_plug_info->id, __LINE__));
-+                      break;
-+              }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    SendEventAck - Send EventAck request to MPT adapter.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+  *    @evnp: Pointer to original EventNotification request
+- **/
++ */
+ static int
+ SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
+ {
+@@ -6278,7 +6377,7 @@ SendEventAck(MPT_ADAPTER *ioc, EventNoti
  
--static int
--mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
--{
--      struct mptsas_portinfo *port_info, *p, *ex;
--      struct device *parent;
--      struct sas_rphy *rphy;
--      int error = -ENOMEM, i, j;
-+              starget = mptsas_get_starget(phy_info);
-+              if (!starget) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                              "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                              __FUNCTION__, hot_plug_info->id, __LINE__));
-+                      break;
-+              }
+       if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
+               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
+-                  ioc->name,__FUNCTION__));
++                  ioc->name,__func__));
+               return -1;
+       }
  
--      ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
--      if (!ex)
--              goto out;
-+              vtarget = starget->hostdata;
-+              if (!vtarget) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                              "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                              __FUNCTION__, hot_plug_info->id, __LINE__));
-+                      break;
-+              }
+@@ -6297,6 +6396,7 @@ SendEventAck(MPT_ADAPTER *ioc, EventNoti
+       return 0;
+ }
  
--      error = mptsas_sas_expander_pg0(ioc, ex,
--          (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
--           MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle);
--      if (error)
--              goto out_free_port_info;
-+              mpt_findImVolumes(ioc);
--      *handle = ex->phy_info[0].handle;
-+              starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Hidding: "
-+                  "fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
-+                  ioc->name, hot_plug_info->channel, hot_plug_info->id,
-+                  hot_plug_info->phys_disk_num, (unsigned long long)
-+                  sas_device.sas_address);
-+
-+              vtarget->id = hot_plug_info->phys_disk_num;
-+              vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
-+              phy_info->attached.phys_disk_num = hot_plug_info->phys_disk_num;
-+              mptsas_reprobe_target(starget, 1);
-+              break;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_config - Generic function to issue config message
+  *    @ioc:   Pointer to an adapter structure
+@@ -6309,7 +6409,7 @@ SendEventAck(MPT_ADAPTER *ioc, EventNoti
+  *    -EPERM if not allowed due to ISR context
+  *    -EAGAIN if no msg frames currently available
+  *    -EFAULT for non-successful reply or no reply (timeout)
+- **/
++ */
+ int
+ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
+ {
+@@ -6334,7 +6434,7 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       if (ioc->ioc_reset_in_progress) {
+               dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: busy with host reset\n", ioc->name, __FUNCTION__));
++                  "%s: busy with host reset\n", ioc->name, __func__));
+               spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+               return -EBUSY;
+       }
+@@ -6345,7 +6445,7 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS
+           mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_OPERATIONAL) {
+               dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "%s: ioc not operational, %d, %xh\n",
+-                  ioc->name, __FUNCTION__, ioc->active,
++                  ioc->name, __func__, ioc->active,
+                   mpt_GetIocState(ioc, 0)));
+               return -EFAULT;
+       }
+@@ -6423,7 +6523,8 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS
+       ioc->add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
+       timeout = (pCfg->timeout < 15) ? HZ*15 : HZ*pCfg->timeout;
+       mpt_put_msg_frame(mpt_base_index, ioc, mf);
+-      timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done, timeout);
++      timeleft =
++          wait_for_completion_timeout(&ioc->mptbase_cmds.done, timeout);
+       if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               ret = -ETIME;
+               dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+@@ -6459,7 +6560,8 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS
+       }
+       if (retry_count)
+-              printk(MYIOC_s_INFO_FMT "Retry completed ret=0x%x timeleft=%ld\n",
++              printk(MYIOC_s_INFO_FMT
++                  "Retry completed ret=0x%x timeleft=%ld\n",
+                   ioc->name, ret, timeleft);
+       dcprintk(ioc, printk(KERN_DEBUG "IOCStatus=%04xh, IOCLogInfo=%08xh\n",
+@@ -6472,15 +6574,15 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS
+       if (issue_hard_reset) {
+               issue_hard_reset = 0;
+               printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
+-                  ioc->name, __FUNCTION__);
++                  ioc->name, __func__);
+               if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
+                       mpt_HardResetHandler(ioc, CAN_SLEEP);
+               mpt_free_msg_frame(ioc, mf);
+               /* attempt one retry for a timed out command */
+               if (!retry_count) {
+                       printk(MYIOC_s_INFO_FMT
+-                          "Attempting Retry Config request type 0x%x, page 0x%x,"
+-                          " action %d\n", ioc->name, page_type,
++                          "Attempting Retry Config request type 0x%x,"
++                          " page 0x%x, action %d\n", ioc->name, page_type,
+                           pCfg->cfghdr.hdr->PageNumber, pCfg->action);
+                       retry_count++;
+                       goto retry_config;
+@@ -6489,37 +6591,40 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS
+       return ret;
+ }
  
--      mutex_lock(&ioc->sas_topology_mutex);
--      port_info = mptsas_find_portinfo_by_handle(ioc, *handle);
--      if (!port_info) {
--              port_info = ex;
--              list_add_tail(&port_info->list, &ioc->sas_topology);
--      } else {
--              for (i = 0; i < ex->num_phys; i++) {
--                      port_info->phy_info[i].handle =
--                              ex->phy_info[i].handle;
--                      port_info->phy_info[i].port_id =
--                              ex->phy_info[i].port_id;
-+      case MPTSAS_DEL_PHYSDISK_REPROBE:
-+
-+              if (mptsas_sas_device_pg0(ioc, &sas_device,
-+                  (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
-+                   MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+                      (hot_plug_info->channel << 8) + hot_plug_info->id)) {
-+                              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                                  "%s: fw_id=%d exit at line=%d\n",
-+                                  ioc->name, __FUNCTION__,
-+                                  hot_plug_info->id, __LINE__));
-+                      break;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_ioc_reset - Base cleanup for hard reset
+  *    @ioc: Pointer to the adapter structure
+  *    @reset_phase: Indicates pre- or post-reset functionality
+  *
+  *    Remark: Frees resources with internally generated commands.
+- **/
++ */
+ static int
+ mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
+ {
+-      switch(reset_phase) {
++      switch (reset_phase) {
+       case MPT_IOC_SETUP_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
+               ioc->taskmgmt_quiesce_io = 1;
+               break;
+       case MPT_IOC_PRE_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
+               break;
+       case MPT_IOC_POST_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_POST_RESET\n",  ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_POST_RESET\n",  ioc->name, __func__));
+ /* wake up mptbase_cmds */
+               if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
+-                      ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
++                      ioc->mptbase_cmds.status
++                          |= MPT_MGMT_STATUS_DID_IOCRESET;
+                       complete(&ioc->mptbase_cmds.done);
                }
--              kfree(ex->phy_info);
--              kfree(ex);
--              ex = NULL;
--      }
--      mutex_unlock(&ioc->sas_topology_mutex);
--      for (i = 0; i < port_info->num_phys; i++) {
--              mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
--                      (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
--                       MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
-+              phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
-+                              sas_device.sas_address);
-+              if (!phy_info) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                          "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                          __FUNCTION__, hot_plug_info->id, __LINE__));
-+                      break;
-+              }
--              if (port_info->phy_info[i].identify.handle) {
--                      mptsas_sas_device_pg0(ioc,
--                              &port_info->phy_info[i].identify,
--                              (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
--                               MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
--                              port_info->phy_info[i].identify.handle);
--                      port_info->phy_info[i].identify.phy_id =
--                          port_info->phy_info[i].phy_id;
-+              starget = mptsas_get_starget(phy_info);
-+              if (!starget) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                          "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                          __FUNCTION__, hot_plug_info->id, __LINE__));
-+                      break;
+ /* wake up taskmgmt_cmds */
+               if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
+-                      ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
++                      ioc->taskmgmt_cmds.status
++                          |= MPT_MGMT_STATUS_DID_IOCRESET;
+                       complete(&ioc->taskmgmt_cmds.done);
                }
+               break;
+@@ -6532,11 +6637,12 @@ mpt_ioc_reset(MPT_ADAPTER *ioc, int rese
  
--              if (port_info->phy_info[i].attached.handle) {
--                      mptsas_sas_device_pg0(ioc,
--                              &port_info->phy_info[i].attached,
--                              (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
--                               MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
--                              port_info->phy_info[i].attached.handle);
--                      port_info->phy_info[i].attached.phy_id =
--                          port_info->phy_info[i].phy_id;
-+              vtarget = starget->hostdata;
-+              if (!vtarget) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                          "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                          __FUNCTION__, hot_plug_info->id, __LINE__));
-+                      break;
-               }
--      }
  
--      parent = &ioc->sh->shost_gendev;
--      for (i = 0; i < port_info->num_phys; i++) {
--              mutex_lock(&ioc->sas_topology_mutex);
--              list_for_each_entry(p, &ioc->sas_topology, list) {
--                      for (j = 0; j < p->num_phys; j++) {
--                              if (port_info->phy_info[i].identify.handle !=
--                                              p->phy_info[j].attached.handle)
--                                      continue;
--                              rphy = mptsas_get_rphy(&p->phy_info[j]);
--                              parent = &rphy->dev;
--                      }
-+              if (!(vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                          "%s: fw_id=%d exit at line=%d\n", ioc->name,
-+                          __FUNCTION__, hot_plug_info->id, __LINE__));
-+                      break;
-               }
--              mutex_unlock(&ioc->sas_topology_mutex);
--      }
+ #ifdef CONFIG_PROC_FS         /* { */
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
+ static int
+ procmpt_create(void)
+ {
+@@ -6557,11 +6663,12 @@ procmpt_create(void)
+       return 0;
+ }
  
--      mptsas_setup_wide_ports(ioc, port_info);
-+              mpt_findImVolumes(ioc);
-+
-+              starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Exposing:"
-+                  " fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
-+                  ioc->name, hot_plug_info->channel, hot_plug_info->id,
-+                  hot_plug_info->phys_disk_num, (unsigned long long)
-+                  sas_device.sas_address);
-+
-+              vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
-+              vtarget->id = hot_plug_info->id;
-+              phy_info->attached.phys_disk_num = ~0;
-+              mptsas_reprobe_target(starget, 0);
-+              mptsas_add_device_component_by_fw(ioc,
-+                  hot_plug_info->channel, hot_plug_info->id);
-+              break;
-+
-+      case MPTSAS_ADD_RAID:
-+
-+              mpt_findImVolumes(ioc);
-+              printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
-+                  "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
-+                  hot_plug_info->id);
-+              scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
-+                  hot_plug_info->id, 0);
-+              break;
-+
-+      case MPTSAS_DEL_RAID:
-+
-+              mpt_findImVolumes(ioc);
-+              printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
-+                  "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
-+                  hot_plug_info->id);
-+              scsi_remove_device(hot_plug_info->sdev);
-+              scsi_device_put(hot_plug_info->sdev);
-+              break;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
+ static void
+ procmpt_destroy(void)
+ {
+@@ -6570,6 +6677,7 @@ procmpt_destroy(void)
+       remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
+ }
  
--      for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
--              mptsas_probe_one_phy(parent, &port_info->phy_info[i],
--                  ioc->sas_index, 0);
-+      case MPTSAS_ADD_INACTIVE_VOLUME:
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    procmpt_summary_read - Handle read request of a summary file
+  *    @buf: Pointer to area to write information
+@@ -6581,7 +6689,7 @@ procmpt_destroy(void)
+  *
+  *    Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary.
+  *    Returns number of characters written to process performing the read.
+- **/
++ */
+ static int
+ procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
+ {
+@@ -6613,6 +6721,7 @@ procmpt_summary_read(char *buf, char **s
+       MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
+ }
  
--      return 0;
-+              mpt_findImVolumes(ioc);
-+              mptsas_adding_inactive_raid_components(ioc,
-+                  hot_plug_info->channel, hot_plug_info->id);
-+              break;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    procmpt_version_read - Handle read request from /proc/mpt/version.
+  *    @buf: Pointer to area to write information
+@@ -6623,7 +6732,7 @@ procmpt_summary_read(char *buf, char **s
+  *    @data: Pointer
+  *
+  *    Returns number of characters written to process performing the read.
+- **/
++ */
+ static int
+ procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
+ {
+@@ -6668,6 +6777,7 @@ procmpt_version_read(char *buf, char **s
+       MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
+ }
  
-- out_free_port_info:
--      if (ex) {
--              kfree(ex->phy_info);
--              kfree(ex);
-+      default:
-+              break;
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
+  *    @buf: Pointer to area to write information
+@@ -6678,7 +6788,7 @@ procmpt_version_read(char *buf, char **s
+  *    @data: Pointer
+  *
+  *    Returns number of characters written to process performing the read.
+- **/
++ */
+ static int
+ procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
+ {
+@@ -6779,6 +6889,7 @@ mpt_get_fw_exp_ver(char *buf, MPT_ADAPTE
        }
-- out:
--      return error;
-+
-+      mptsas_free_fw_event(ioc, fw_event);
  }
  
--/*
-- * mptsas_delete_expander_phys
-+/**
-+ * mptsas_send_sas_event
-  *
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -6789,7 +6900,7 @@ mpt_get_fw_exp_ver(char *buf, MPT_ADAPTE
   *
-- * This will traverse topology, and remove expanders
-- * that are no longer present
-- */
-+ * @ioc
-+ * @sas_event_data
-+ *
-+ **/
- static void
--mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
-+mptsas_send_sas_event(struct fw_event_work *fw_event)
+  *    This routine writes (english readable) ASCII text, which represents
+  *    a summary of IOC information, to a buffer.
+- **/
++ */
+ void
+ mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
  {
--      struct mptsas_portinfo buffer;
--      struct mptsas_portinfo *port_info, *n, *parent;
--      struct mptsas_phyinfo *phy_info;
--      struct sas_port * port;
--      int i;
--      u64     expander_sas_address;
-+      MPT_ADAPTER *ioc;
-+      struct mptsas_hotplug_event hot_plug_info;
-+      EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
-+      u32 device_info;
-+      u64 sas_address;
--      mutex_lock(&ioc->sas_topology_mutex);
--      list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
-+      ioc = fw_event->ioc;
-+      sas_event_data = (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)
-+          fw_event->event_data;
-+      device_info = le32_to_cpu(sas_event_data->DeviceInfo);
--              if (port_info->phy_info &&
--                  (!(port_info->phy_info[0].identify.device_info &
--                  MPI_SAS_DEVICE_INFO_SMP_TARGET)))
--                      continue;
-+      if ((device_info &
-+           (MPI_SAS_DEVICE_INFO_SSP_TARGET |
-+            MPI_SAS_DEVICE_INFO_STP_TARGET |
-+            MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0) {
-+              mptsas_free_fw_event(ioc, fw_event);
-+              return;
-+      }
--              if (mptsas_sas_expander_pg0(ioc, &buffer,
--                   (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
--                   MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
--                   port_info->phy_info[0].handle)) {
-+      if (sas_event_data->ReasonCode ==
-+              MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED) {
-+              mptbase_sas_persist_operation(ioc,
-+                  MPI_SAS_OP_CLEAR_NOT_PRESENT);
-+              mptsas_free_fw_event(ioc, fw_event);
-+              return;
-+      }
+@@ -6901,19 +7012,19 @@ mpt_halt_firmware(MPT_ADAPTER *ioc)
+       if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
+               printk(MYIOC_s_ERR_FMT "IOC is in FAULT state (%04xh)!!!\n",
+                       ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
+-              if(mpt_fwfault_debug == 2)
+-                      for(;;);
++              if (mpt_fwfault_debug == 2)
++                      for (;;);
+               else
+-                      panic("%s: IOC Fault (%04xh)!!!\n",ioc->name,
++                      panic("%s: IOC Fault (%04xh)!!!\n", ioc->name,
+                               ioc_raw_state & MPI_DOORBELL_DATA_MASK);
+       } else {
+               CHIPREG_WRITE32(&ioc->chip->Doorbell, 0xC0FFEE00);
+-              if(mpt_fwfault_debug == 2) {
+-                      printk("%s: Firmware is halted due to command timeout\n"
+-                                      ,ioc->name);
+-                      for(;;);
+-              }
+-              else
++              if (mpt_fwfault_debug == 2) {
++                      printk(KERN_ERR
++                          "%s: Firmware is halted due to command timeout\n",
++                          ioc->name);
++                      for (;;);
++              } else
+                       panic("%s: Firmware is halted due to command timeout\n",
+                                       ioc->name);
+       }
+@@ -6943,14 +7054,16 @@ mpt_SoftResetHandler(MPT_ADAPTER *ioc, i
+       u32              ioc_state;
+       unsigned long    time_count;
  
--                      /*
--                       * Obtain the port_info instance to the parent port
--                       */
--                      parent = mptsas_find_portinfo_by_handle(ioc,
--                          port_info->phy_info[0].identify.handle_parent);
-+      switch (sas_event_data->ReasonCode) {
-+      case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
-+      case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
-+              memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
-+              hot_plug_info.handle = le16_to_cpu(sas_event_data->DevHandle);
-+              hot_plug_info.channel = sas_event_data->Bus;
-+              hot_plug_info.id = sas_event_data->TargetID;
-+              hot_plug_info.phy_id = sas_event_data->PhyNum;
-+              memcpy(&sas_address, &sas_event_data->SASAddress,
-+                  sizeof(u64));
-+              hot_plug_info.sas_address = le64_to_cpu(sas_address);
-+              hot_plug_info.device_info = device_info;
-+              if (sas_event_data->ReasonCode &
-+                  MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
-+                      hot_plug_info.event_type = MPTSAS_ADD_DEVICE;
-+              else
-+                      hot_plug_info.event_type = MPTSAS_DEL_DEVICE;
-+              mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
-+              break;
-+
-+      case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
-+              mptbase_sas_persist_operation(ioc,
-+                  MPI_SAS_OP_CLEAR_NOT_PRESENT);
-+              mptsas_free_fw_event(ioc, fw_event);
-+              break;
+-      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SoftResetHandler Entered!\n", ioc->name));
++      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++              "SoftResetHandler Entered!\n", ioc->name));
  
--                      if (!parent)
--                              goto next_port;
-+      case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
-+      /* TODO */
-+      case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
-+      /* TODO */
-+      default:
-+              mptsas_free_fw_event(ioc, fw_event);
-+              break;
-+      }
-+}
+       ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
  
--                      expander_sas_address =
--                              port_info->phy_info[0].identify.sas_address;
+-      if(mpt_fwfault_debug)
++      if (mpt_fwfault_debug)
+               mpt_halt_firmware(ioc);
  
--                      /*
--                       * Delete rphys in the parent that point
--                       * to this expander.  The transport layer will
--                       * cleanup all the children.
--                       */
--                      phy_info = parent->phy_info;
--                      for (i = 0; i < parent->num_phys; i++, phy_info++) {
--                              port = mptsas_get_port(phy_info);
--                              if (!port)
--                                      continue;
--                              if (phy_info->attached.sas_address !=
--                                      expander_sas_address)
--                                      continue;
--                              dsaswideprintk(ioc,
--                                  dev_printk(KERN_DEBUG, &port->dev,
--                                  MYIOC_s_FMT "delete port (%d)\n", ioc->name,
--                                  port->port_identifier));
--                              sas_port_delete(port);
--                              mptsas_port_delete(ioc, phy_info->port_details);
--                      }
-- next_port:
--
--                      phy_info = port_info->phy_info;
--                      for (i = 0; i < port_info->num_phys; i++, phy_info++)
--                              mptsas_port_delete(ioc, phy_info->port_details);
--
--                      list_del(&port_info->list);
--                      kfree(port_info->phy_info);
--                      kfree(port_info);
-+/**
-+ * mptsas_send_raid_event
-+ *
-+ *
-+ * @ioc
-+ * @raid_event_data
-+ *
-+ **/
-+static void
-+mptsas_send_raid_event(struct fw_event_work *fw_event)
-+{
-+      MPT_ADAPTER *ioc;
-+      EVENT_DATA_RAID *raid_event_data;
-+      struct mptsas_hotplug_event hot_plug_info;
-+      int status;
-+      int state;
-+      struct scsi_device *sdev = NULL;
-+      VirtDevice *vdevice = NULL;
-+      RaidPhysDiskPage0_t phys_disk;
-+
-+      ioc = fw_event->ioc;
-+      raid_event_data = (EVENT_DATA_RAID *)fw_event->event_data;
-+      status = le32_to_cpu(raid_event_data->SettingsStatus);
-+      state = (status >> 8) & 0xff;
-+
-+      memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
-+      hot_plug_info.id = raid_event_data->VolumeID;
-+      hot_plug_info.channel = raid_event_data->VolumeBus;
-+      hot_plug_info.phys_disk_num = raid_event_data->PhysDiskNum;
-+
-+      if (raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_DELETED ||
-+          raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_CREATED ||
-+          raid_event_data->ReasonCode ==
-+          MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED) {
-+              sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
-+                  hot_plug_info.id, 0);
-+              hot_plug_info.sdev = sdev;
-+              if (sdev)
-+                      vdevice = sdev->hostdata;
-+      }
-+
-+      devtprintk(ioc, printk(MYIOC_s_INFO_FMT "Entering %s: "
-+          "ReasonCode=%02x\n", ioc->name, __FUNCTION__,
-+          raid_event_data->ReasonCode));
-+
-+      switch (raid_event_data->ReasonCode) {
-+      case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
-+              hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK_REPROBE;
-+              break;
-+      case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
-+              hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK_REPROBE;
-+              break;
-+      case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
-+              switch (state) {
-+              case MPI_PD_STATE_ONLINE:
-+              case MPI_PD_STATE_NOT_COMPATIBLE:
-+                      mpt_raid_phys_disk_pg0(ioc,
-+                          raid_event_data->PhysDiskNum, &phys_disk);
-+                      hot_plug_info.id = phys_disk.PhysDiskID;
-+                      hot_plug_info.channel = phys_disk.PhysDiskBus;
-+                      hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
-+                      break;
-+              case MPI_PD_STATE_FAILED:
-+              case MPI_PD_STATE_MISSING:
-+              case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
-+              case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
-+              case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
-+                      hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
-+                      break;
-+              default:
-+                      break;
-               }
--              /*
--              * Free this memory allocated from inside
--              * mptsas_sas_expander_pg0
--              */
--              kfree(buffer.phy_info);
-+              break;
-+      case MPI_EVENT_RAID_RC_VOLUME_DELETED:
-+              if (!sdev)
-+                      break;
-+              vdevice->vtarget->deleted = 1; /* block IO */
-+              hot_plug_info.event_type = MPTSAS_DEL_RAID;
-+              break;
-+      case MPI_EVENT_RAID_RC_VOLUME_CREATED:
-+              if (sdev) {
-+                      scsi_device_put(sdev);
-+                      break;
-+              }
-+              hot_plug_info.event_type = MPTSAS_ADD_RAID;
-+              break;
-+      case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
-+              if (!(status & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)) {
-+                      if (!sdev)
-+                              break;
-+                      vdevice->vtarget->deleted = 1; /* block IO */
-+                      hot_plug_info.event_type = MPTSAS_DEL_RAID;
-+                      break;
-+              }
-+              switch (state) {
-+              case MPI_RAIDVOL0_STATUS_STATE_FAILED:
-+              case MPI_RAIDVOL0_STATUS_STATE_MISSING:
-+                      if (!sdev)
-+                              break;
-+                      vdevice->vtarget->deleted = 1; /* block IO */
-+                      hot_plug_info.event_type = MPTSAS_DEL_RAID;
-+                      break;
-+              case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
-+              case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
-+                      if (sdev) {
-+                              scsi_device_put(sdev);
-+                              break;
-+                      }
-+                      hot_plug_info.event_type = MPTSAS_ADD_RAID;
-+                      break;
-+              default:
-+                      break;
-+              }
-+              break;
-+      default:
-+              break;
+-      if (ioc_state == MPI_IOC_STATE_FAULT || ioc_state == MPI_IOC_STATE_RESET) {
++      if (ioc_state == MPI_IOC_STATE_FAULT
++          || ioc_state == MPI_IOC_STATE_RESET) {
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "skipping, either in FAULT or RESET state!\n", ioc->name));
+               return -1;
+@@ -6995,11 +7108,10 @@ mpt_SoftResetHandler(MPT_ADAPTER *ioc, i
+               if ((rc = GetIocFacts(ioc, sleepFlag,
+                           MPT_HOSTEVENT_IOC_RECOVER)) == 0)
+                       break;
+-              if (sleepFlag == CAN_SLEEP) {
++              if (sleepFlag == CAN_SLEEP)
+                       msleep(100);
+-              } else {
++              else
+                       mdelay(100);
+-              }
        }
--      mutex_unlock(&ioc->sas_topology_mutex);
-+
-+      if (hot_plug_info.event_type != MPTSAS_IGNORE_EVENT)
-+              mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
-+      else
-+              mptsas_free_fw_event(ioc, fw_event);
- }
--/*
-- * Start of day discovery
-- */
--static void
--mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
-+/**
-+ *    mptsas_issue_tm - send mptsas internal tm request
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @type
-+ *    @channel
-+ *    @id
-+ *    @lun
-+ *    @task_context
-+ *    @timeout
-+ *
-+ *    return:
-+ *
-+ **/
-+static int
-+mptsas_issue_tm(MPT_ADAPTER *ioc, u8 type, u8 channel, u8 id, u64 lun, int task_context, ulong timeout,
-+      u8 *issue_reset)
- {
--      u32 handle = 0xFFFF;
--      int i;
-+      MPT_FRAME_HDR   *mf;
-+      SCSITaskMgmt_t  *pScsiTm;
-+      int              retval;
-+      unsigned long    timeleft;
--      mutex_lock(&ioc->sas_discovery_mutex);
--      mptsas_probe_hba_phys(ioc);
--      while (!mptsas_probe_expander_phys(ioc, &handle))
--              ;
--      /*
--        Reporting RAID volumes.
--      */
--      if (!ioc->ir_firmware)
-+      *issue_reset = 0;
-+      if ((mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc)) == NULL) {
-+              retval = -1; /* return failure */
-+              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt request: no "
-+                  "msg frames!!\n", ioc->name));
-               goto out;
--      if (!ioc->raid_data.pIocPg2)
-+      }
-+
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request: mr = %p, "
-+          "task_type = 0x%02X,\n\t timeout = %ld, fw_channel = %d, "
-+          "fw_id = %d, lun = %lld,\n\t task_context = 0x%x\n", ioc->name, mf,
-+           type, timeout, channel, id, (unsigned long long)lun,
-+           task_context));
-+
-+      pScsiTm = (SCSITaskMgmt_t *) mf;
-+      memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
-+      pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
-+      pScsiTm->TaskType = type;
-+      pScsiTm->MsgFlags = 0;
-+      pScsiTm->TargetID = id;
-+      pScsiTm->Bus = channel;
-+      pScsiTm->ChainOffset = 0;
-+      pScsiTm->Reserved = 0;
-+      pScsiTm->Reserved1 = 0;
-+      pScsiTm->TaskMsgContext = task_context;
-+      int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
-+
-+      INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+      CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
-+      retval = 0;
-+      mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
-+
-+      /* Now wait for the command to complete */
-+      timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,
-+          timeout*HZ);
-+      if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              retval = -1; /* return failure */
-+              dtmprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                  "TaskMgmt request: TIMED OUT!(mr=%p)\n", ioc->name, mf));
-+              mpt_free_msg_frame(ioc, mf);
-+              if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
-+                      goto out;
-+              *issue_reset = 1;
+       if (ii == 5)
                goto out;
--      if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
-+      }
-+
-+      if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
-+              retval = -1; /* return failure */
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "TaskMgmt request: failed with no reply\n", ioc->name));
-               goto out;
--      for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
--              scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
--                  ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
+@@ -7033,13 +7145,15 @@ mpt_SoftResetHandler(MPT_ADAPTER *ioc, i
+       if (ioc->active) {      /* otherwise, hard reset coming */
+               for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+                       if (MptResetHandlers[cb_idx])
+-                              mpt_signal_reset(cb_idx, ioc, MPT_IOC_POST_RESET);
++                              mpt_signal_reset(cb_idx,
++                                  ioc, MPT_IOC_POST_RESET);
+               }
        }
-+
-  out:
--      mutex_unlock(&ioc->sas_discovery_mutex);
-+      CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+      return retval;
- }
  
--/*
-- * Work queue thread to handle Runtime discovery
-- * Mere purpose is the hot add/delete of expanders
-- *(Mutex UNLOCKED)
-- */
-+/**
-+ *    mptsas_broadcast_primative_work - Work queue thread to handle
-+ *    broadcast primitive events
-+ *    @work: work queue payload containing info describing the event
-+ *
-+ **/
- static void
--__mptsas_discovery_work(MPT_ADAPTER *ioc)
-+mptsas_broadcast_primative_work(struct fw_event_work *fw_event)
- {
--      u32 handle = 0xFFFF;
-+      MPT_ADAPTER *ioc = fw_event->ioc;
-+      MPT_FRAME_HDR           *mf;
-+      VirtDevice              *vdevice;
-+      int                     ii;
-+      struct scsi_cmnd        *sc;
-+      SCSITaskMgmtReply_t *   pScsiTmReply;
-+      u8                      issue_reset;
-+      int                     task_context;
-+      u8                      channel, id;
-+      int                      lun;
-+      u32                      termination_count;
-+      u32                      query_count;
-+
+-      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SoftResetHandler: completed (%d seconds): %s\n",
+-          ioc->name, jiffies_to_msecs(jiffies - time_count)/1000,
+-          ((rc == 0) ? "SUCCESS" : "FAILED")));
 +      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "%s - enter\n", ioc->name, __FUNCTION__));
-+
-+      mutex_lock(&ioc->taskmgmt_cmds.mutex);
-+      if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
-+              mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+              mptsas_requeue_fw_event(ioc, fw_event, 1000);
-+              return;
-+      }
++              "SoftResetHandler: completed (%d seconds): %s\n",
++              ioc->name, jiffies_to_msecs(jiffies - time_count)/1000,
++              ((rc == 0) ? "SUCCESS" : "FAILED")));
  
--      ioc->sas_discovery_runtime=1;
--      mptsas_delete_expander_phys(ioc);
--      mptsas_probe_hba_phys(ioc);
--      while (!mptsas_probe_expander_phys(ioc, &handle))
--              ;
--      ioc->sas_discovery_runtime=0;
-+      issue_reset = 0;
-+      termination_count = 0;
-+      query_count = 0;
-+      mpt_findImVolumes(ioc);
-+      pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply;
-+
-+      for (ii = 0; ii < ioc->req_depth; ii++) {
-+              sc = mptscsih_get_scsi_lookup(ioc, ii);
-+              if (!sc)
-+                      continue;
-+              mf = MPT_INDEX_2_MFPTR(ioc, ii);
-+              if (!mf)
-+                      continue;
-+              task_context = mf->u.frame.hwhdr.msgctxu.MsgContext;
-+              vdevice = sc->device->hostdata;
-+              if (!vdevice || !vdevice->vtarget)
-+                      continue;
-+              if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
-+                      continue; /* skip hidden raid components */
-+              if (vdevice->vtarget->raidVolume)
-+                      continue; /* skip hidden raid components */
-+              channel = vdevice->vtarget->channel;
-+              id = vdevice->vtarget->id;
-+              lun = vdevice->lun;
-+              if (mptsas_issue_tm(ioc, MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK,
-+                  channel, id, (u64)lun, task_context, 30, &issue_reset))
-+                      goto out;
-+              query_count++;
-+              termination_count +=
-+                  le32_to_cpu(pScsiTmReply->TerminationCount);
-+              if ((pScsiTmReply->IOCStatus == MPI_IOCSTATUS_SUCCESS) &&
-+                  (pScsiTmReply->ResponseCode ==
-+                  MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
-+                  pScsiTmReply->ResponseCode ==
-+                  MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
-+                      continue;
-+              if (mptsas_issue_tm(ioc,
-+                  MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET,
-+                  channel, id, (u64)lun, 0, 30, &issue_reset))
-+                      goto out;
-+              termination_count +=
-+                  le32_to_cpu(pScsiTmReply->TerminationCount);
-+      }
-+
-+ out:
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "%s - exit, query_count = %d termination_count = %d\n",
-+          ioc->name, __FUNCTION__, query_count, termination_count));
-+
-+      ioc->broadcast_aen_busy = 0;
-+      mpt_clear_taskmgmt_in_progress_flag(ioc);
-+      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+
-+      if (issue_reset) {
-+              printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
-+                  ioc->name, __FUNCTION__);
-+              if (mpt_SoftResetHandler(ioc, CAN_SLEEP))
-+                      mpt_HardResetHandler(ioc, CAN_SLEEP);
-+      }
-+      mptsas_free_fw_event(ioc, fw_event);
+       return rc;
  }
--/*
-- * Work queue thread to handle Runtime discovery
-- * Mere purpose is the hot add/delete of expanders
-- *(Mutex LOCKED)
-- */
-+/**
-+ *    mptsas_send_ir2_event - handle exposing hidden disk when an inactive raid volume is added
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @ir2_data:
-+ *
-+ **/
- static void
--mptsas_discovery_work(struct work_struct *work)
-+mptsas_send_ir2_event(struct fw_event_work *fw_event)
+@@ -7060,7 +7174,7 @@ mpt_SoftResetHandler(MPT_ADAPTER *ioc, i
+  *    FW reload/initialization failed.
+  *
+  *    Returns 0 for SUCCESS or -1 if FAILED.
+- **/
++ */
+ int
+ mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
  {
--      struct mptsas_discovery_event *ev =
--              container_of(work, struct mptsas_discovery_event, work);
--      MPT_ADAPTER *ioc = ev->ioc;
--
--      mutex_lock(&ioc->sas_discovery_mutex);
--      __mptsas_discovery_work(ioc);
--      mutex_unlock(&ioc->sas_discovery_mutex);
--      kfree(ev);
-+      MPT_ADAPTER *ioc;
-+      struct mptsas_hotplug_event hot_plug_info;
-+      MPI_EVENT_DATA_IR2 * ir2_data;
-+      u8 reasonCode;
-+      RaidPhysDiskPage0_t phys_disk;
-+
-+      ioc = fw_event->ioc;
-+      ir2_data = (MPI_EVENT_DATA_IR2 *)fw_event->event_data;
-+      reasonCode = ir2_data->ReasonCode;
-+
-+      devtprintk(ioc, printk(MYIOC_s_INFO_FMT "Entering %s: "
-+          "ReasonCode=%02x\n", ioc->name,__FUNCTION__, reasonCode));
-+
-+      memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
-+      hot_plug_info.id = ir2_data->TargetID;
-+      hot_plug_info.channel = ir2_data->Bus;
-+      switch (reasonCode) {
-+      case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
-+              hot_plug_info.event_type = MPTSAS_ADD_INACTIVE_VOLUME;
-+              break;
-+      case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED:
-+              hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum;
-+              hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
-+              break;
-+      case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED:
-+              hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum;
-+              mpt_raid_phys_disk_pg0(ioc,
-+                  ir2_data->PhysDiskNum, &phys_disk);
-+              hot_plug_info.id = phys_disk.PhysDiskID;
-+              hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
-+              break;
-+      default:
-+              mptsas_free_fw_event(ioc, fw_event);
-+              return;
-+      }
-+      mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
- }
+@@ -7075,7 +7189,7 @@ mpt_HardResetHandler(MPT_ADAPTER *ioc, i
+       printk("MF count 0x%x !\n", ioc->mfcnt);
+ #endif
  
--static struct mptsas_phyinfo *
--mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
-+static void
-+mptsas_expander_refresh(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
- {
--      struct mptsas_portinfo *port_info;
--      struct mptsas_phyinfo *phy_info = NULL;
--      int i;
-+      struct mptsas_portinfo *parent;
-+      struct device *parent_dev;
-+      struct sas_rphy *rphy;
-+      int             i;
-+      u64             sas_address; /* expander sas address */
-+      u32             handle;
--      mutex_lock(&ioc->sas_topology_mutex);
--      list_for_each_entry(port_info, &ioc->sas_topology, list) {
--              for (i = 0; i < port_info->num_phys; i++) {
--                      if (!mptsas_is_end_device(
--                              &port_info->phy_info[i].attached))
--                              continue;
--                      if (port_info->phy_info[i].attached.sas_address
--                          != sas_address)
--                              continue;
--                      phy_info = &port_info->phy_info[i];
--                      break;
--              }
--      }
--      mutex_unlock(&ioc->sas_topology_mutex);
--      return phy_info;
--}
-+      handle = port_info->phy_info[0].handle;
-+      sas_address = port_info->phy_info[0].identify.sas_address;
-+      for (i = 0; i < port_info->num_phys; i++) {
-+              mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
-+                  (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
-+                  MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + handle);
--static struct mptsas_phyinfo *
--mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u8 channel, u8 id)
--{
--      struct mptsas_portinfo *port_info;
--      struct mptsas_phyinfo *phy_info = NULL;
--      int i;
-+              mptsas_sas_device_pg0(ioc,
-+                  &port_info->phy_info[i].identify,
-+                  (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
-+                  MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+                  port_info->phy_info[i].identify.handle);
-+              port_info->phy_info[i].identify.phy_id =
-+                  port_info->phy_info[i].phy_id;
--      mutex_lock(&ioc->sas_topology_mutex);
--      list_for_each_entry(port_info, &ioc->sas_topology, list) {
--              for (i = 0; i < port_info->num_phys; i++) {
--                      if (!mptsas_is_end_device(
--                              &port_info->phy_info[i].attached))
--                              continue;
--                      if (port_info->phy_info[i].attached.id != id)
--                              continue;
--                      if (port_info->phy_info[i].attached.channel != channel)
--                              continue;
--                      phy_info = &port_info->phy_info[i];
--                      break;
-+              if (port_info->phy_info[i].attached.handle) {
-+                      mptsas_sas_device_pg0(ioc,
-+                          &port_info->phy_info[i].attached,
-+                          (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
-+                           MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+                          port_info->phy_info[i].attached.handle);
-+                      port_info->phy_info[i].attached.phy_id =
-+                          port_info->phy_info[i].phy_id;
+-      if(mpt_fwfault_debug)
++      if (mpt_fwfault_debug)
+               mpt_halt_firmware(ioc);
+       /* Reset the adapter. Prevent more than 1 call to
+@@ -7101,14 +7215,15 @@ mpt_HardResetHandler(MPT_ADAPTER *ioc, i
+               if (MptResetHandlers[cb_idx]) {
+                       mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
+                       if (ioc->alt_ioc)
+-                              mpt_signal_reset(cb_idx, ioc->alt_ioc, MPT_IOC_SETUP_RESET);
++                              mpt_signal_reset(cb_idx,
++                                  ioc->alt_ioc, MPT_IOC_SETUP_RESET);
                }
        }
--      mutex_unlock(&ioc->sas_topology_mutex);
--      return phy_info;
--}
--
--static struct mptsas_phyinfo *
--mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
--{
--      struct mptsas_portinfo *port_info;
--      struct mptsas_phyinfo *phy_info = NULL;
--      int i;
  
-       mutex_lock(&ioc->sas_topology_mutex);
--      list_for_each_entry(port_info, &ioc->sas_topology, list) {
--              for (i = 0; i < port_info->num_phys; i++) {
--                      if (!mptsas_is_end_device(
--                              &port_info->phy_info[i].attached))
--                              continue;
--                      if (port_info->phy_info[i].attached.phys_disk_num == ~0)
--                              continue;
--                      if (port_info->phy_info[i].attached.phys_disk_num != id)
--                              continue;
--                      if (port_info->phy_info[i].attached.channel != channel)
--                              continue;
--                      phy_info = &port_info->phy_info[i];
--                      break;
-+      parent = mptsas_find_portinfo_by_handle(ioc,
-+          port_info->phy_info[0].identify.handle_parent);
-+      if (!parent) {
-+              mutex_unlock(&ioc->sas_topology_mutex);
-+              return;
-+      }
-+      for (i = 0, parent_dev = NULL; i < parent->num_phys && !parent_dev;
-+          i++) {
-+              if (parent->phy_info[i].attached.sas_address == sas_address) {
-+                      rphy = mptsas_get_rphy(&parent->phy_info[i]);
-+                      parent_dev = &rphy->dev;
+       time_count = jiffies;
+       if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
+-              printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
+-                      rc, ioc->name);
++              printk(KERN_WARNING MYNAM
++                  ": WARNING - (%d) Cannot recover %s\n", rc, ioc->name);
+       } else {
+               if (ioc->hard_resets < -1)
+                       ioc->hard_resets++;
+@@ -7129,13 +7244,15 @@ mpt_HardResetHandler(MPT_ADAPTER *ioc, i
+               if (MptResetHandlers[cb_idx]) {
+                       mpt_signal_reset(cb_idx, ioc, MPT_IOC_POST_RESET);
+                       if (ioc->alt_ioc)
+-                              mpt_signal_reset(cb_idx, ioc->alt_ioc, MPT_IOC_POST_RESET);
++                              mpt_signal_reset(cb_idx,
++                                  ioc->alt_ioc, MPT_IOC_POST_RESET);
                }
        }
-       mutex_unlock(&ioc->sas_topology_mutex);
--      return phy_info;
-+
-+      mptsas_setup_wide_ports(ioc, port_info);
-+      for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
-+              mptsas_probe_one_phy(parent_dev, &port_info->phy_info[i],
-+                  ioc->sas_index, 0);
+-      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HardResetHandler: completed (%d seconds): %s\n",
+-          ioc->name, jiffies_to_msecs(jiffies - time_count)/1000,
+-          ((rc == 0) ? "SUCCESS" : "FAILED")));
++      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++              "HardResetHandler: completed (%d seconds): %s\n",
++              ioc->name, jiffies_to_msecs(jiffies - time_count)/1000,
++              ((rc == 0) ? "SUCCESS" : "FAILED")));
+       return rc;
  }
  
--/*
-- * Work queue thread to clear the persitency table
-- */
- static void
--mptsas_persist_clear_table(struct work_struct *work)
-+mptsas_expander_event_add(MPT_ADAPTER *ioc,
-+    MpiEventDataSasExpanderStatusChange_t* expander_data)
+@@ -7607,6 +7724,7 @@ mpt_display_event_info(MPT_ADAPTER *ioc,
+ }
+ #endif
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    ProcessEventNotification - Route EventNotificationReply to all event handlers
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -7616,7 +7734,7 @@ mpt_display_event_info(MPT_ADAPTER *ioc,
+  *    Routes a received EventNotificationReply to all currently registered
+  *    event handlers.
+  *    Returns sum of event handlers return values.
+- **/
++ */
+ static int
+ ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
  {
--      MPT_ADAPTER *ioc = container_of(work, MPT_ADAPTER, sas_persist_task);
-+      struct mptsas_portinfo *port_info;
-+      int i;
-+      __le64 sas_address;
--      mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
--}
-+      port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
-+      if (!port_info)
-+              BUG();
-+      port_info->num_phys = (expander_data->NumPhys) ?
-+          expander_data->NumPhys : 1;
-+      port_info->phy_info = kcalloc(port_info->num_phys,
-+          sizeof(struct mptsas_phyinfo),GFP_KERNEL);
-+      if (!port_info->phy_info)
-+              BUG();
-+      memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
-+      for (i = 0; i < port_info->num_phys; i++) {
-+              port_info->phy_info[i].portinfo = port_info;
-+              port_info->phy_info[i].handle =
-+                  le16_to_cpu(expander_data->DevHandle);
-+              port_info->phy_info[i].identify.sas_address =
-+                  le64_to_cpu(sas_address);
-+              port_info->phy_info[i].identify.handle_parent =
-+                  le16_to_cpu(expander_data->ParentDevHandle);
-+      }
+@@ -7695,12 +7813,12 @@ ProcessEventNotification(MPT_ADAPTER *io
+       for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+               if (MptEvHandlers[cb_idx]) {
+                       devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                          "Routing Event to event handler #%d\n", ioc->name, cb_idx));
++                          "Routing Event to event handler #%d\n",
++                          ioc->name, cb_idx));
+                       r += (*(MptEvHandlers[cb_idx]))(ioc, pEventReply);
+                       handlers++;
+               }
+       }
+-      /* FIXME?  Examine results here? */
  
--static void
--mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
--{
--      int rc;
-+      mutex_lock(&ioc->sas_topology_mutex);
-+      list_add_tail(&port_info->list, &ioc->sas_topology);
-+      mutex_unlock(&ioc->sas_topology_mutex);
--      sdev->no_uld_attach = data ? 1 : 0;
--      rc = scsi_device_reprobe(sdev);
--}
-+      printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
-+          "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
-+          (unsigned long long)sas_address);
--static void
--mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
--{
--      starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
--                      mptsas_reprobe_lun);
-+      mptsas_expander_refresh(ioc, port_info);
+       /*
+        *  If needed, send (a single) EventAck.
+@@ -7762,6 +7880,7 @@ mpt_fc_log_info(MPT_ADAPTER *ioc, u32 lo
+                       ioc->name, log_info, desc, (log_info & 0xFFFFFF));
  }
  
-+/**
-+ * mptsas_delete_expander_siblings - remove siblings attached to expander
-+ * @ioc: Pointer to MPT_ADAPTER structure
-+ * @parent: the parent port_info object
-+ * @expander: the expander port_info object
-+ **/
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mpt_spi_log_info - Log information returned from SCSI Parallel IOC.
+  *    @ioc: Pointer to MPT_ADAPTER structure
+@@ -7769,7 +7888,7 @@ mpt_fc_log_info(MPT_ADAPTER *ioc, u32 lo
+  *    @log_info: U32 LogInfo word from the IOC
+  *
+  *    Refer to lsi/sp_log.h.
+- **/
++ */
  static void
--mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
-+mptsas_delete_expander_siblings(MPT_ADAPTER *ioc, struct mptsas_portinfo
-+    *parent, struct mptsas_portinfo *expander)
+ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
  {
--      CONFIGPARMS                     cfg;
--      ConfigPageHeader_t              hdr;
--      dma_addr_t                      dma_handle;
--      pRaidVolumePage0_t              buffer = NULL;
--      RaidPhysDiskPage0_t             phys_disk;
--      int                             i;
--      struct mptsas_hotplug_event     *ev;
-+      struct mptsas_phyinfo *phy_info;
-+      struct mptsas_portinfo *port_info;
-+      struct sas_rphy *rphy;
-+      int i;
--      memset(&cfg, 0 , sizeof(CONFIGPARMS));
--      memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
--      hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
--      cfg.pageAddr = (channel << 8) + id;
--      cfg.cfghdr.hdr = &hdr;
--      cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
-+      phy_info = expander->phy_info;
-+      for (i = 0; i < expander->num_phys; i++, phy_info++) {
-+              if (!(rphy = mptsas_get_rphy(phy_info)))
-+                      continue;
-+              if (rphy->identify.device_type == SAS_END_DEVICE)
-+                      mptsas_del_end_device(ioc, phy_info);
-+      }
--      if (mpt_config(ioc, &cfg) != 0)
--              goto out;
-+      phy_info = expander->phy_info;
-+      for (i = 0; i < expander->num_phys; i++, phy_info++) {
-+              if (!(rphy = mptsas_get_rphy(phy_info)))
-+                      continue;
-+              if (rphy->identify.device_type ==
-+                  MPI_SAS_DEVICE_INFO_EDGE_EXPANDER ||
-+                  rphy->identify.device_type ==
-+                  MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
-+                      port_info = mptsas_find_portinfo_by_sas_address(ioc,
-+                          rphy->identify.sas_address);
-+                      if (!port_info)
-+                              continue;
-+                      if (port_info == parent) /* backlink rphy */
-+                              continue;
-+                      mptsas_expander_delete(ioc, port_info);
-+              }
-+      }
-+}
--      if (!hdr.PageLength)
--              goto out;
--      buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
--          &dma_handle);
-+/**
-+ *    mptsas_expander_delete - remove this expander
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @port_info: expander port_info struct
-+ *
-+ **/
--      if (!buffer)
--              goto out;
-+static void
-+mptsas_expander_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
-+{
--      cfg.physAddr = dma_handle;
--      cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-+      struct mptsas_portinfo *parent;
-+      int             i;
-+      u64             expander_sas_address;
-+      struct mptsas_phyinfo *phy_info;
-+      struct mptsas_portinfo buffer;
-+      struct mptsas_portinfo_details * port_details;
-+      struct sas_port * port;
--      if (mpt_config(ioc, &cfg) != 0)
--              goto out;
-+      if (!port_info)
-+              return;
--      if (!(buffer->VolumeStatus.Flags &
--          MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
--              goto out;
-+      /* see if expander is still there before deleting */
-+      mptsas_sas_expander_pg0(ioc, &buffer,
-+          (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
-+          MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
-+          port_info->phy_info[0].identify.handle);
--      if (!buffer->NumPhysDisks)
--              goto out;
-+      if (buffer.num_phys) {
-+              kfree(buffer.phy_info);
-+              return;
-+      }
+@@ -8353,7 +8472,8 @@ mpt_iocstatus_info(MPT_ADAPTER *ioc, u32
+       if (!desc)
+               return;
  
--      for (i = 0; i < buffer->NumPhysDisks; i++) {
+-      dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s\n", ioc->name, status, desc));
++      dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++              "IOCStatus(0x%04X): %s\n", ioc->name, status, desc));
+ }
  
--              if (mpt_raid_phys_disk_pg0(ioc,
--                  buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
--                      continue;
-+      /*
-+       * Obtain the port_info instance to the parent port
-+       */
-+      port_details = NULL;
-+      expander_sas_address =
-+          port_info->phy_info[0].identify.sas_address;
-+      parent = mptsas_find_portinfo_by_handle(ioc,
-+          port_info->phy_info[0].identify.handle_parent);
-+      mptsas_delete_expander_siblings(ioc, parent, port_info);
-+      if (!parent)
-+              goto out;
+ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+@@ -8364,7 +8484,6 @@ EXPORT_SYMBOL(mpt_resume);
+ EXPORT_SYMBOL(mpt_suspend);
+ #endif
+ EXPORT_SYMBOL(ioc_list);
+-EXPORT_SYMBOL(mpt_proc_root_dir);
+ EXPORT_SYMBOL(mpt_register);
+ EXPORT_SYMBOL(mpt_deregister);
+ EXPORT_SYMBOL(mpt_event_register);
+@@ -8395,11 +8514,12 @@ EXPORT_SYMBOL(mpt_set_taskmgmt_in_progre
+ EXPORT_SYMBOL(mpt_clear_taskmgmt_in_progress_flag);
+ EXPORT_SYMBOL(mpt_halt_firmware);
  
--              ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
--              if (!ev) {
--                      printk(MYIOC_s_WARN_FMT "mptsas: lost hotplug event\n", ioc->name);
--                      goto out;
-+      /*
-+       * Delete rphys in the parent that point
-+       * to this expander.
-+       */
-+      phy_info = parent->phy_info;
-+      port = NULL;
-+      for (i = 0; i < parent->num_phys; i++, phy_info++) {
-+              if(!phy_info->phy)
-+                      continue;
-+              if (phy_info->attached.sas_address !=
-+                  expander_sas_address)
-+                      continue;
-+              if (!port) {
-+                      port = mptsas_get_port(phy_info);
-+                      port_details = phy_info->port_details;
-               }
--
--              INIT_WORK(&ev->work, mptsas_hotplug_work);
--              ev->ioc = ioc;
--              ev->id = phys_disk.PhysDiskID;
--              ev->channel = phys_disk.PhysDiskBus;
--              ev->phys_disk_num_valid = 1;
--              ev->phys_disk_num = phys_disk.PhysDiskNum;
--              ev->event_type = MPTSAS_ADD_DEVICE;
--              schedule_work(&ev->work);
-+              dev_printk(KERN_DEBUG, &phy_info->phy->dev,
-+                  MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name,
-+                  phy_info->phy_id, phy_info->phy);
-+              sas_port_delete_phy(port, phy_info->phy);
-+      }
-+      if (port) {
-+              dev_printk(KERN_DEBUG, &port->dev,
-+                  MYIOC_s_FMT "delete port %d, sas_addr (0x%llx)\n",
-+                  ioc->name, port->port_identifier,
-+                  (unsigned long long)expander_sas_address);
-+              sas_port_delete(port);
-+              mptsas_port_delete(ioc, port_details);
-       }
--
-  out:
--      if (buffer)
--              pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
--                  dma_handle);
-+
-+      printk(MYIOC_s_INFO_FMT "delete expander: num_phys %d, "
-+          "sas_addr (0x%llx)\n",  ioc->name, port_info->num_phys,
-+          (unsigned long long)expander_sas_address);
-+
-+      /*
-+       * free link
-+       */
-+      list_del(&port_info->list);
-+      kfree(port_info->phy_info);
-+      kfree(port_info);
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    fusion_init - Fusion MPT base driver initialization routine.
+  *
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
+ static int __init
+ fusion_init(void)
+ {
+@@ -8430,12 +8550,13 @@ fusion_init(void)
+       return 0;
  }
--/*
-- * Work queue thread to handle SAS hotplug events
-+
-+
-+/**
-+ * mptsas_send_expander_event - expanders events
-+ * @ioc: Pointer to MPT_ADAPTER structure
-+ * @expander_data: event data
-+ *
-+ *
-+ * This function handles adding, removing, and refreshing
-+ * device handles within the expander objects.
-  */
- static void
--mptsas_hotplug_work(struct work_struct *work)
-+mptsas_send_expander_event(struct fw_event_work *fw_event)
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    fusion_exit - Perform driver unload cleanup.
+  *
+  *    This routine frees all resources associated with each MPT adapter
+  *    and removes all %MPT_PROCFS_MPTBASEDIR entries.
+- **/
++ */
+ static void __exit
+ fusion_exit(void)
  {
--      struct mptsas_hotplug_event *ev =
--              container_of(work, struct mptsas_hotplug_event, work);
-+      MPT_ADAPTER *ioc;
-+      MpiEventDataSasExpanderStatusChange_t* expander_data;
-+      struct mptsas_portinfo *port_info;
-+      __le64 sas_address;
-+      int i;
--      MPT_ADAPTER *ioc = ev->ioc;
--      struct mptsas_phyinfo *phy_info;
--      struct sas_rphy *rphy;
--      struct sas_port *port;
--      struct scsi_device *sdev;
--      struct scsi_target * starget;
--      struct sas_identify identify;
--      char *ds = NULL;
--      struct mptsas_devinfo sas_device;
--      VirtTarget *vtarget;
--      VirtDevice *vdevice;
-+      ioc = fw_event->ioc;
-+      expander_data = (MpiEventDataSasExpanderStatusChange_t *)
-+          fw_event->event_data;
-+      memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
-+      port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
-+
-+      if (expander_data->ReasonCode == MPI_EVENT_SAS_EXP_RC_ADDED) {
-+              if (port_info) {
-+                      for (i = 0; i < port_info->num_phys; i++) {
-+                              port_info->phy_info[i].portinfo = port_info;
-+                              port_info->phy_info[i].handle =
-+                                  le16_to_cpu(expander_data->DevHandle);
-+                              port_info->phy_info[i].identify.sas_address =
-+                                  le64_to_cpu(sas_address);
-+                              port_info->phy_info[i].identify.handle_parent =
-+                                  le16_to_cpu(expander_data->ParentDevHandle);
-+                      }
-+                      mptsas_expander_refresh(ioc, port_info);
-+              } else if (!port_info && expander_data->NumPhys)
-+                      mptsas_expander_event_add(ioc, expander_data);
-+      } else if (expander_data->ReasonCode ==
-+          MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING)
-+              mptsas_expander_delete(ioc, port_info);
--      mutex_lock(&ioc->sas_discovery_mutex);
--      switch (ev->event_type) {
--      case MPTSAS_DEL_DEVICE:
-+      mptsas_free_fw_event(ioc, fw_event);
-+}
+Index: linux-2.6.27/drivers/message/fusion/mptbase.h
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/mptbase.h
++++ linux-2.6.27/drivers/message/fusion/mptbase.h
+@@ -72,8 +72,8 @@
+ #define COPYRIGHT     "Copyright (c) 1999-2008 " MODULEAUTHOR
+ #endif
  
--              phy_info = NULL;
--              if (ev->phys_disk_num_valid) {
--                      if (ev->hidden_raid_component){
--                              if (mptsas_sas_device_pg0(ioc, &sas_device,
--                                  (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
--                                   MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
--                                  (ev->channel << 8) + ev->id)) {
--                                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                                      "%s: exit at line=%d\n", ioc->name,
--                                              __func__, __LINE__));
--                                      break;
--                              }
--                              phy_info = mptsas_find_phyinfo_by_sas_address(
--                                  ioc, sas_device.sas_address);
--                      }else
--                              phy_info = mptsas_find_phyinfo_by_phys_disk_num(
--                                  ioc, ev->channel, ev->phys_disk_num);
--              }
+-#define MPT_LINUX_VERSION_COMMON      "4.00.43.00"
+-#define MPT_LINUX_PACKAGE_NAME                "@(#)mptlinux-4.00.43.00"
++#define MPT_LINUX_VERSION_COMMON      "4.00.43.00suse"
++#define MPT_LINUX_PACKAGE_NAME                "@(#)mptlinux-4.00.43.00suse"
+ #define WHAT_MAGIC_STRING             "@" "(" "#" ")"
+ #define MPT_LINUX_MAJOR_VERSION               4
+ #define MPT_LINUX_MINOR_VERSION               00
+@@ -177,10 +177,10 @@
+ #define MPT_SCSI_SG_DEPTH     40
+ #endif
  
--              if (!phy_info)
--                      phy_info = mptsas_find_phyinfo_by_target(ioc,
--                          ev->channel, ev->id);
-+/**
-+ * mptsas_expander_add -
-+ * @ioc: Pointer to MPT_ADAPTER structure
-+ * @handle:
-+ *
-+ */
-+struct mptsas_portinfo *
-+mptsas_expander_add(MPT_ADAPTER *ioc, u16 handle)
-+{
-+      struct mptsas_portinfo buffer, *port_info;
-+      int i;
+-#ifdef  CONFIG_FUSION_MAX_FC_SGE
+-#if     CONFIG_FUSION_MAX_FC_SGE  < 16
++#ifdef        CONFIG_FUSION_MAX_FC_SGE
++#if   CONFIG_FUSION_MAX_FC_SGE  < 16
+ #define MPT_SCSI_FC_SG_DEPTH  16
+-#elif   CONFIG_FUSION_MAX_FC_SGE  > 256
++#elif CONFIG_FUSION_MAX_FC_SGE  > 256
+ #define MPT_SCSI_FC_SG_DEPTH  256
+ #else
+ #define MPT_SCSI_FC_SG_DEPTH  CONFIG_FUSION_MAX_FC_SGE
+@@ -444,10 +444,10 @@ do { \
+ #define MPT_MGMT_STATUS_RF_VALID      0x01    /* The Reply Frame is VALID */
+ #define MPT_MGMT_STATUS_COMMAND_GOOD  0x02    /* Command Status GOOD */
+ #define MPT_MGMT_STATUS_PENDING               0x04    /* command is pending */
+-#define MPT_MGMT_STATUS_DID_IOCRESET  0x08    /* IOC Reset occurred on the current*/
++#define MPT_MGMT_STATUS_DID_IOCRESET  0x08    /* IOC Reset occurred */
+ #define MPT_MGMT_STATUS_SENSE_VALID   0x10    /* valid sense info */
+ #define MPT_MGMT_STATUS_TIMER_ACTIVE  0x20    /* obsolete */
+-#define MPT_MGMT_STATUS_FREE_MF               0x40    /* free the mf from complete routine */
++#define MPT_MGMT_STATUS_FREE_MF               0x40    /* free the mf */
+ #define INITIALIZE_MGMT_STATUS(status) \
+@@ -467,7 +467,7 @@ typedef struct _MPT_MGMT {
+       u8                       status;        /* current command status */
+       int                      completion_code;
+       u32                      msg_context;
+-}MPT_MGMT;
++} MPT_MGMT;
  
--              /*
--               * Sanity checks, for non-existing phys and remote rphys.
--               */
--              if (!phy_info){
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      break;
--              }
--              if (!phy_info->port_details) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      break;
--              }
--              rphy = mptsas_get_rphy(phy_info);
--              if (!rphy) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      break;
--              }
-+      if ((mptsas_sas_expander_pg0(ioc, &buffer,
-+          (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
-+          MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)))
-+              return NULL;
--              port = mptsas_get_port(phy_info);
--              if (!port) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      break;
--              }
-+      port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_ATOMIC);
-+      if (!port_info) {
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+              "%s: exit at line=%d\n", ioc->name,
-+              __FUNCTION__, __LINE__));
-+              return NULL;
-+      }
-+      port_info->num_phys = buffer.num_phys;
-+      port_info->phy_info = buffer.phy_info;
-+      for (i = 0; i < port_info->num_phys; i++)
-+              port_info->phy_info[i].portinfo = port_info;
-+      mutex_lock(&ioc->sas_topology_mutex);
-+      list_add_tail(&port_info->list, &ioc->sas_topology);
-+      mutex_unlock(&ioc->sas_topology_mutex);
-+      printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
-+          "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
-+          (unsigned long long)buffer.phy_info[0].identify.sas_address);
-+      mptsas_expander_refresh(ioc, port_info);
-+      return port_info;
-+}
+ /*
+  *  Event Structure and define
+@@ -540,7 +540,7 @@ typedef    struct _RaidCfgData {
+       IOCPage2_t      *pIocPg2;               /* table of Raid Volumes */
+       IOCPage3_t      *pIocPg3;               /* table of physical disks */
+       IOCPage6_t      *pIocPg6;               /* table of IR static data */
+-      struct semaphore        inactive_list_mutex;
++      struct mutex    inactive_list_mutex;
+       struct list_head        inactive_list; /* link list for physical
+                                               disk that belong in
+                                               inactive volumes */
+@@ -571,7 +571,8 @@ struct mptfc_rport_info
+ };
  
--              starget = mptsas_get_starget(phy_info);
--              if (starget) {
--                      vtarget = starget->hostdata;
-+static void
-+mptsas_send_link_status_event(struct fw_event_work *fw_event)
-+{
-+      MPT_ADAPTER *ioc;
-+      MpiEventDataSasPhyLinkStatus_t *link_data;
-+      struct mptsas_portinfo *port_info;
-+      struct mptsas_phyinfo *phy_info = NULL;
-+      __le64 sas_address;
-+      u8 phy_num;
-+      u8 link_rate;
--                      if (!vtarget) {
--                              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                                      "%s: exit at line=%d\n", ioc->name,
--                                      __func__, __LINE__));
--                              break;
--                      }
-+      ioc = fw_event->ioc;
-+      link_data = (MpiEventDataSasPhyLinkStatus_t *)fw_event->event_data;
+ typedef void (*MPT_ADD_SGE)(char *pAddr, u32 flagslength, dma_addr_t dma_addr);
+-typedef void (*MPT_ADD_CHAIN)(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr);
++typedef void (*MPT_ADD_CHAIN)
++      (char *pAddr, u8 next, u16 length, dma_addr_t dma_addr);
  
--                      /*
--                       * Handling  RAID components
--                       */
--                      if (ev->phys_disk_num_valid &&
--                          ev->hidden_raid_component) {
--                              printk(MYIOC_s_INFO_FMT
--                                  "RAID Hidding: channel=%d, id=%d, "
--                                  "physdsk %d \n", ioc->name, ev->channel,
--                                  ev->id, ev->phys_disk_num);
--                              vtarget->id = ev->phys_disk_num;
--                              vtarget->tflags |=
--                                  MPT_TARGET_FLAGS_RAID_COMPONENT;
--                              mptsas_reprobe_target(starget, 1);
--                              phy_info->attached.phys_disk_num =
--                                  ev->phys_disk_num;
--                      break;
-+      memcpy(&sas_address, &link_data->SASAddress, sizeof(__le64));
-+      sas_address = le64_to_cpu(sas_address);
-+      link_rate = link_data->LinkRates >> 4;
-+      phy_num = link_data->PhyNum;
-+
-+      port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
-+      if (port_info) {
-+              phy_info = &port_info->phy_info[phy_num];
-+              if (phy_info)
-+                      phy_info->negotiated_link_rate = link_rate;
-+      }
-+
-+      if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 ||
-+          link_rate == MPI_SAS_IOUNIT0_RATE_3_0) {
-+
-+              if (!port_info) {
-+                      if (ioc->old_sas_discovery_protocal) {
-+                              port_info = mptsas_expander_add(ioc,
-+                                  le16_to_cpu(link_data->DevHandle));
-+                              if (port_info)
-+                                      goto out;
-                       }
-+                      goto out;
-               }
-+              if (port_info == ioc->hba_port_info)
-+                      mptsas_probe_hba_phys(ioc);
-+              else
-+                      mptsas_expander_refresh(ioc, port_info);
-+      } else if (phy_info && phy_info->phy) {
-+              if (link_rate ==  MPI_SAS_IOUNIT0_RATE_PHY_DISABLED)
-+                      phy_info->phy->negotiated_linkrate =
-+                          SAS_PHY_DISABLED;
-+              else if (link_rate ==
-+                  MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION)
-+                      phy_info->phy->negotiated_linkrate =
-+                          SAS_LINK_RATE_FAILED;
-+              else
-+                      phy_info->phy->negotiated_linkrate =
-+                          SAS_LINK_RATE_UNKNOWN;
-+      }
-+ out:
-+      mptsas_free_fw_event(ioc, fw_event);
-+}
+ /*
+  *  Adapter Structure - pci_dev specific. Maximum: MPT_MAX_ADAPTERS
+@@ -583,7 +584,8 @@ typedef struct _MPT_ADAPTER
+       char                     name[MPT_NAME_LENGTH]; /* "iocN"             */
+       char                     prod_name[MPT_NAME_LENGTH];    /* "LSIFC9x9"         */
+ #ifdef CONFIG_FUSION_LOGGING
+-      char                     evStr[EVENT_DESCR_STR_SZ]; /* used in mpt_display_event_info */
++      /* used in mpt_display_event_info */
++      char                     evStr[EVENT_DESCR_STR_SZ];
+ #endif
+       char                     board_name[16];
+       char                     board_assembly[16];
+@@ -597,7 +599,8 @@ typedef struct _MPT_ADAPTER
+       SYSIF_REGS __iomem      *pio_chip;      /* Programmed IO (downloadboot) */
+       u8                       bus_type;
+       unsigned long            mem_phys;      /* == f4020000 (mmap) */
+-      unsigned long            pio_mem_phys;  /* Programmed IO (downloadboot) */
++      /* Programmed IO (downloadboot) */
++      unsigned long            pio_mem_phys;
+       int                      mem_size;      /* mmap memory size */
+       int                      number_of_buses;
+       int                      devices_per_bus;
+@@ -612,8 +615,10 @@ typedef struct _MPT_ADAPTER
+       int                      reply_depth;   /* Num Allocated reply frames */
+       int                      reply_sz;      /* Reply frame size */
+       int                      num_chain;     /* Number of chain buffers */
+-      MPT_ADD_SGE              add_sge;       /* Pointer to add_sge function */
+-      MPT_ADD_CHAIN            add_chain;     /* Pointer to add_chain function */
++      /* Pointer to add_sge function */
++      MPT_ADD_SGE              add_sge;
++      /* Pointer to add_chain function */
++      MPT_ADD_CHAIN            add_chain;
+               /* Pool of buffers for chaining. ReqToChain
+                * and ChainToChain track index of chain buffers.
+                * ChainBuffer (DMA) virt/phys addresses.
+@@ -646,7 +651,8 @@ typedef struct _MPT_ADAPTER
+       dma_addr_t               HostPageBuffer_dma;
+       int                      mtrr_reg;
+       struct pci_dev          *pcidev;        /* struct pci_dev pointer */
+-      int                     bars;   /* bitmask of BAR's that must be configured */
++      /* bitmask of BAR's that must be configured */
++      int                     bars;
+       int                      msi_enable;
+       u8                      __iomem *memmap;        /* mmap address */
+       struct Scsi_Host        *sh;            /* Scsi Host pointer */
+@@ -680,7 +686,8 @@ typedef struct _MPT_ADAPTER
+ #if defined(CPQ_CIM)
+       u32                      csmi_change_count;     /* count to track all IR
+                                       events for CSMI */
+-      u8                       pci_slot_number; /* ioc page 1 - pci slot number */
++      /* ioc page 1 - pci slot number */
++      u8                       pci_slot_number;
+ #endif
  
--              if (phy_info->attached.device_info &
--                  MPI_SAS_DEVICE_INFO_SSP_TARGET)
--                      ds = "ssp";
--              if (phy_info->attached.device_info &
--                  MPI_SAS_DEVICE_INFO_STP_TARGET)
--                      ds = "stp";
--              if (phy_info->attached.device_info &
--                  MPI_SAS_DEVICE_INFO_SATA_DEVICE)
--                      ds = "sata";
--
--              printk(MYIOC_s_INFO_FMT
--                     "removing %s device, channel %d, id %d, phy %d\n",
--                     ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
--              dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
--                  "delete port (%d)\n", ioc->name, port->port_identifier);
--              sas_port_delete(port);
--              mptsas_port_delete(ioc, phy_info->port_details);
--              break;
--      case MPTSAS_ADD_DEVICE:
--
--              if (ev->phys_disk_num_valid)
--                      mpt_findImVolumes(ioc);
+       u8                       ir_firmware; /* =1 if IR firmware detected */
+@@ -711,11 +718,12 @@ typedef struct _MPT_ADAPTER
+       u8                       fw_events_off; /* if '1', then ignore events */
+       char fw_event_q_name[20];
+-      struct mptsas_portinfo  *hba_port_info; /* port_info object for the host */
++      /* port_info object for the host */
++      struct mptsas_portinfo  *hba_port_info;
+       u64                      hba_port_sas_addr;
+       u16                      hba_port_num_phy;
+       struct list_head         sas_device_info_list;
+-      struct semaphore         sas_device_info_mutex;
++      struct mutex             sas_device_info_mutex;
+       u8                       old_sas_discovery_protocal;
+       u8                       sas_discovery_quiesce_io;
+       int                      sas_index; /* index refrencing */
+@@ -735,6 +743,7 @@ typedef struct _MPT_ADAPTER
+       char                     reset_work_q_name[20];
+       struct workqueue_struct *reset_work_q;
+       struct delayed_work      fault_reset_work;
++      spinlock_t               fault_reset_work_lock;
+       struct work_struct       fc_setup_reset_work;
+       struct list_head         fc_rports;
+       struct work_struct       fc_lsc_work;
+@@ -743,9 +752,12 @@ typedef struct _MPT_ADAPTER
+       struct work_struct       fc_rescan_work;
+       char                     fc_rescan_work_q_name[20];
+       struct workqueue_struct *fc_rescan_work_q;
+-      unsigned long             hard_resets;          /* driver forced bus resets count */
+-      unsigned long             soft_resets;          /* fw/external bus resets count */
+-      unsigned long             timeouts;             /* cmd timeouts */
++      /* driver forced bus resets count */
++      unsigned long             hard_resets;
++      /* fw/external bus resets count */
++      unsigned long             soft_resets;
++      /* cmd timeouts */
++      unsigned long             timeouts;
+       struct scsi_cmnd        **ScsiLookup;
+       spinlock_t                scsi_lookup_lock;
+       int                       sdev_queue_depth;     /* sdev queue depth */
+@@ -907,10 +919,14 @@ extern int        mpt_config(MPT_ADAPTER *ioc,
+ extern int     mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size);
+ extern void    mpt_free_fw_memory(MPT_ADAPTER *ioc);
+ extern int     mpt_findImVolumes(MPT_ADAPTER *ioc);
+-extern int     mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
+-extern int     mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage0_t phys_disk);
+-extern int     mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage1_t phys_disk);
+-extern int     mpt_raid_phys_disk_get_num_paths(MPT_ADAPTER *ioc, u8 phys_disk_num);
++extern int     mptbase_sas_persist_operation(MPT_ADAPTER *ioc,
++    u8 persist_opcode);
++extern int     mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num,
++    pRaidPhysDiskPage0_t phys_disk);
++extern int     mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc, u8 phys_disk_num,
++    pRaidPhysDiskPage1_t phys_disk);
++extern int     mpt_raid_phys_disk_get_num_paths(MPT_ADAPTER *ioc,
++    u8 phys_disk_num);
+ extern int     mpt_set_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc);
+ extern void    mpt_clear_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc);
+@@ -920,7 +936,6 @@ extern void         mpt_halt_firmware(MPT_ADAPT
+  *  Public data decl's...
+  */
+ extern struct list_head         ioc_list;
+-extern struct proc_dir_entry  *mpt_proc_root_dir;
+ extern int mpt_debug_level;
+ extern int mpt_fwfault_debug;
  
--              /*
--               * Refresh sas device pg0 data
--               */
--              if (mptsas_sas_device_pg0(ioc, &sas_device,
--                  (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
--                   MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
--                      (ev->channel << 8) + ev->id)) {
--                              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                                      "%s: exit at line=%d\n", ioc->name,
--                                      __func__, __LINE__));
--                      break;
-+static void
-+mptsas_handle_queue_full_event(struct fw_event_work *fw_event)
-+{
-+      MPT_ADAPTER *ioc;
-+      EventDataQueueFull_t *qfull_data;
-+      struct sas_device_info *sas_info;
-+      struct scsi_device      *sdev;
-+      int depth;
-+      int id = -1;
-+      int channel = -1;
-+      int fw_id, fw_channel;
-+      u16 current_depth;
-+
-+
-+      ioc = fw_event->ioc;
-+      qfull_data = (EventDataQueueFull_t *)fw_event->event_data;
-+      fw_id = qfull_data->TargetID;
-+      fw_channel = qfull_data->Bus;
-+      current_depth = le16_to_cpu(qfull_data->CurrentDepth);
-+
-+      /* if hidden raid component, look for the volume id */
-+      down(&ioc->sas_device_info_mutex);
-+      if (mptscsih_is_phys_disk(ioc, fw_channel, fw_id)) {
-+              list_for_each_entry(sas_info, &ioc->sas_device_info_list,
-+                  list) {
-+                      if (sas_info->is_cached ||
-+                          sas_info->is_logical_volume)
-+                              continue;
-+                      if (sas_info->is_hidden_raid_component &&
-+                          (sas_info->fw.channel == fw_channel &&
-+                          sas_info->fw.id == fw_id)) {
-+                              id = sas_info->volume_id;
-+                              channel = MPTSAS_RAID_CHANNEL;
-+                              goto out;
-+                      }
-               }
--
--              __mptsas_discovery_work(ioc);
--
--              phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
--                              sas_device.sas_address);
--
--              if (!phy_info || !phy_info->port_details) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      break;
-+      } else {
-+              list_for_each_entry(sas_info, &ioc->sas_device_info_list,
-+                  list) {
-+                      if (sas_info->is_cached ||
-+                          sas_info->is_hidden_raid_component ||
-+                          sas_info->is_logical_volume)
-+                              continue;
-+                      if (sas_info->fw.channel == fw_channel &&
-+                          sas_info->fw.id == fw_id) {
-+                              id = sas_info->os.id;
-+                              channel = sas_info->os.channel;
-+                              goto out;
-+                      }
-               }
+Index: linux-2.6.27/drivers/message/fusion/mptctl.c
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/mptctl.c
++++ linux-2.6.27/drivers/message/fusion/mptctl.c
+@@ -75,7 +75,7 @@
+ #if defined(CPQ_CIM)
+ #include "mptsas.h"
+ #include "csmi/csmisas.h"
+-#endif // CPQ_CIM
++#endif
  
--              starget = mptsas_get_starget(phy_info);
--              if (starget && (!ev->hidden_raid_component)){
--
--                      vtarget = starget->hostdata;
-+      }
+ #if defined(DIAG_BUFFER_SUPPORT)
+ #include "rejected_ioctls/diag_buffer.h"
+@@ -148,7 +148,7 @@ static int csmisas_task_managment(unsign
+ static int csmisas_phy_control(unsigned long arg);
+ static int csmisas_get_connector_info(unsigned long arg);
+ static int csmisas_get_location(unsigned long arg);
+-#endif // CPQ_CIM
++#endif
  
--                      if (!vtarget) {
--                              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                                  "%s: exit at line=%d\n", ioc->name,
--                                  __func__, __LINE__));
--                              break;
--                      }
--                      /*
--                       * Handling  RAID components
--                       */
--                      if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
--                              printk(MYIOC_s_INFO_FMT
--                                  "RAID Exposing: channel=%d, id=%d, "
--                                  "physdsk %d \n", ioc->name, ev->channel,
--                                  ev->id, ev->phys_disk_num);
--                              vtarget->tflags &=
--                                  ~MPT_TARGET_FLAGS_RAID_COMPONENT;
--                              vtarget->id = ev->id;
--                              mptsas_reprobe_target(starget, 0);
--                              phy_info->attached.phys_disk_num = ~0;
-+ out:
-+      up(&ioc->sas_device_info_mutex);
-+
-+      if (id != -1) {
-+              shost_for_each_device(sdev, ioc->sh) {
-+                      if (sdev->id == id && sdev->channel == channel) {
-+                              if (current_depth > sdev->queue_depth) {
-+                                      sdev_printk(KERN_INFO, sdev,
-+                                          "strange observation, the queue "
-+                                          "depth is (%d) meanwhile fw queue "
-+                                          "depth (%d)\n", sdev->queue_depth,
-+                                          current_depth);
-+                                      continue;
-+                              }
-+                              depth = scsi_track_queue_full(sdev,
-+                                  current_depth - 1);
-+                              if (depth > 0)
-+                                      sdev_printk(KERN_INFO, sdev,
-+                                      "Queue depth reduced to (%d)\n",
-+                                         depth);
-+                              else if (depth < 0)
-+                                      sdev_printk(KERN_INFO, sdev,
-+                                      "Tagged Command Queueing is being "
-+                                      "disabled\n");
-+                              else if (depth == 0)
-+                                      sdev_printk(KERN_INFO, sdev,
-+                                      "Queue depth not changed yet\n");
-                       }
--                      break;
-               }
-+      }
+ #if defined(DIAG_BUFFER_SUPPORT)
+ /* diag_buffer proto's */
+@@ -157,7 +157,7 @@ static int mptctl_release_diag_buffer(un
+ static int mptctl_unregister_diag_buffer(unsigned long arg);
+ static int mptctl_query_diag_buffer(unsigned long arg);
+ static int mptctl_read_diag_buffer(unsigned long arg);
+-#endif // DIAG_BUFFER_SUPPORT
++#endif
  
--              if (mptsas_get_rphy(phy_info)) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      if (ev->channel) printk("%d\n", __LINE__);
--                      break;
--              }
-+      mptsas_free_fw_event(ioc, fw_event);
-+}
+ static int  mptctl_probe(struct pci_dev *, const struct pci_device_id *);
+ static void mptctl_remove(struct pci_dev *);
+@@ -279,7 +279,8 @@ mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME
+                   le32_to_cpu(reply->u.reply.IOCLogInfo)));
+       if ((req->u.hdr.Function == MPI_FUNCTION_SCSI_IO_REQUEST) ||
+-              (req->u.hdr.Function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
++              (req->u.hdr.Function
++                       == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
+               if (reply->u.sreply.SCSIStatus || reply->u.sreply.SCSIState)
+                       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+@@ -290,7 +291,8 @@ mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME
+                       le16_to_cpu(reply->u.sreply.TaskTag),
+                       le32_to_cpu(reply->u.sreply.TransferCount)));
+-              if (reply->u.sreply.SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
++              if (reply->u.sreply.SCSIState
++                  & MPI_SCSI_STATE_AUTOSENSE_VALID) {
+                       sz = req->u.scsireq.SenseBufferLength;
+                       req_index =
+                           le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
+@@ -324,7 +326,8 @@ mptctl_taskmgmt_reply(MPT_ADAPTER *ioc, 
+       if (!mf)
+               return 0;
  
--              port = mptsas_get_port(phy_info);
--              if (!port) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      break;
--              }
--              memcpy(&phy_info->attached, &sas_device,
--                  sizeof(struct mptsas_devinfo));
-+/**
-+ * mptsas_firmware_event_work - work thread for processing fw events
-+ * @work: work queue payload containing info describing the event
-+ * Context: user
-+ *
-+ */
-+static void
-+mptsas_firmware_event_work(struct work_struct *work)
-+{
-+      struct fw_event_work *fw_event =
-+              container_of(work, struct fw_event_work, work.work);
-+      MPT_ADAPTER *ioc = fw_event->ioc;
-+
-+      /* special rescan topology handling */
-+      if (fw_event->event == -1) {
-+              devtprintk(ioc, printk(MYIOC_s_INFO_FMT "%s: rescan after "
-+                  "reset\n", ioc->name,__FUNCTION__));
-+              mptsas_not_responding_devices(ioc);
-+              mptsas_scan_sas_topology(ioc);
-+              mptsas_free_fw_event(ioc, fw_event);
-+              return;
-+      }
+-      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed (mf=%p, mr=%p)\n",
++      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++             "TaskMgmt completed (mf=%p, mr=%p)\n",
+           ioc->name, mf, mr));
+       ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
+@@ -365,8 +368,8 @@ mptctl_bus_reset(MPT_ADAPTER *ioc, u8 fu
+       /* bus reset is only good for SCSI IO, RAID PASSTHRU */
+       if (!(function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) ||
+           (function == MPI_FUNCTION_SCSI_IO_REQUEST)) {
+-              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt, not SCSI_IO!!\n",
+-                              ioc->name));
++              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
++                      "TaskMgmt, not SCSI_IO!!\n", ioc->name));
+               return -EPERM;
+       }
  
--              if (phy_info->attached.device_info &
--                  MPI_SAS_DEVICE_INFO_SSP_TARGET)
--                      ds = "ssp";
--              if (phy_info->attached.device_info &
--                  MPI_SAS_DEVICE_INFO_STP_TARGET)
--                      ds = "stp";
--              if (phy_info->attached.device_info &
--                  MPI_SAS_DEVICE_INFO_SATA_DEVICE)
--                      ds = "sata";
--
--              printk(MYIOC_s_INFO_FMT
--                     "attaching %s device, channel %d, id %d, phy %d\n",
--                     ioc->name, ds, ev->channel, ev->id, ev->phy_id);
-+      /* events handling turned off during host reset */
-+      if (ioc->fw_events_off) {
-+              mptsas_free_fw_event(ioc, fw_event);
-+              return;
-+      }
+@@ -381,8 +384,8 @@ mptctl_bus_reset(MPT_ADAPTER *ioc, u8 fu
+       /* Send request
+        */
+       if ((mf = mpt_get_msg_frame(mptctl_taskmgmt_id, ioc)) == NULL) {
+-              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt, no msg frames!!\n",
+-                              ioc->name));
++              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
++                      "TaskMgmt, no msg frames!!\n", ioc->name));
+               mpt_clear_taskmgmt_in_progress_flag(ioc);
+               retval = -ENOMEM;
+               goto mptctl_bus_reset_done;
+@@ -408,20 +411,21 @@ mptctl_bus_reset(MPT_ADAPTER *ioc, u8 fu
+               pScsiTm->Reserved2[ii] = 0;
  
--              mptsas_parse_device_info(&identify, &phy_info->attached);
--              rphy = sas_end_device_alloc(port);
--              if (!rphy) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      break; /* non-fatal: an rphy can be added later */
--              }
-+      devtprintk(ioc, printk(MYIOC_s_INFO_FMT "%s: fw_event=(0x%p), "
-+          "event = (0x%02x)\n", ioc->name,__FUNCTION__, fw_event,
-+          (fw_event->event & 0xFF)));
--              rphy->identify = identify;
--              if (sas_rphy_add(rphy)) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
--                              "%s: exit at line=%d\n", ioc->name,
--                              __func__, __LINE__));
--                      sas_rphy_free(rphy);
+       switch (ioc->bus_type) {
+-              case FC:
+-                      timeout = 40;
 -                      break;
--              }
--              mptsas_set_rphy(ioc, phy_info, rphy);
-+      switch (fw_event->event) {
-+      case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
-+              mptsas_send_sas_event(fw_event);
-               break;
--      case MPTSAS_ADD_RAID:
--              sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
--                  ev->id, 0);
--              if (sdev) {
--                      scsi_device_put(sdev);
+-              case SAS:
+-                      timeout = 30;
 -                      break;
--              }
--              printk(MYIOC_s_INFO_FMT
--                     "attaching raid volume, channel %d, id %d\n",
--                     ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
--              scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, ev->id, 0);
--              mpt_findImVolumes(ioc);
-+      case MPI_EVENT_INTEGRATED_RAID:
-+              mptsas_send_raid_event(fw_event);
-               break;
--      case MPTSAS_DEL_RAID:
--              sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
--                  ev->id, 0);
--              if (!sdev)
+-              case SPI:
+-              default:
+-                      timeout = 2;
 -                      break;
--              printk(MYIOC_s_INFO_FMT
--                     "removing raid volume, channel %d, id %d\n",
--                     ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
--              vdevice = sdev->hostdata;
--              scsi_remove_device(sdev);
--              scsi_device_put(sdev);
--              mpt_findImVolumes(ioc);
-+      case MPI_EVENT_IR2:
-+              mptsas_send_ir2_event(fw_event);
-               break;
--      case MPTSAS_ADD_INACTIVE_VOLUME:
--              mptsas_adding_inactive_raid_components(ioc,
--                  ev->channel, ev->id);
-+      case MPI_EVENT_PERSISTENT_TABLE_FULL:
-+              mptbase_sas_persist_operation(ioc,
-+                  MPI_SAS_OP_CLEAR_NOT_PRESENT);
-+              mptsas_free_fw_event(ioc, fw_event);
-               break;
--      case MPTSAS_IGNORE_EVENT:
--      default:
-+      case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
-+              mptsas_broadcast_primative_work(fw_event);
++      case FC:
++              timeout = 40;
 +              break;
-+      case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
-+              mptsas_send_expander_event(fw_event);
++      case SAS:
++              timeout = 30;
 +              break;
-+      case MPI_EVENT_SAS_PHY_LINK_STATUS:
-+              mptsas_send_link_status_event(fw_event);
++      case SPI:
++      default:
++              timeout = 10;
 +              break;
-+      case MPI_EVENT_QUEUE_FULL:
-+              mptsas_handle_queue_full_event(fw_event);
-               break;
        }
--
--      mutex_unlock(&ioc->sas_discovery_mutex);
--      kfree(ev);
- }
  
--static void
--mptsas_send_sas_event(MPT_ADAPTER *ioc,
--              EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
--{
--      struct mptsas_hotplug_event *ev;
--      u32 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
--      __le64 sas_address;
--      if ((device_info &
--           (MPI_SAS_DEVICE_INFO_SSP_TARGET |
--            MPI_SAS_DEVICE_INFO_STP_TARGET |
--            MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0)
--              return;
-+/**
-+ *    mptsas_event_process -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @reply:
-+ *
-+ **/
-+static int
-+mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
-+{
-+      u32 event = le32_to_cpu(reply->Event);
-+      int sz, event_data_sz;
-+      struct fw_event_work *fw_event;
-+      unsigned long delay;
--      switch (sas_event_data->ReasonCode) {
--      case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
-+      /* events turned off due to host reset or driver unloading */
-+      if (ioc->fw_events_off)
-+              return 0;
--              mptsas_target_reset_queue(ioc, sas_event_data);
-+      delay = msecs_to_jiffies(1);
-+      switch (event) {
-+      case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
-+      {
-+              EVENT_DATA_SAS_BROADCAST_PRIMITIVE *broadcast_event_data =
-+                  (EVENT_DATA_SAS_BROADCAST_PRIMITIVE *)reply->Data;
-+              if (broadcast_event_data->Primitive !=
-+                  MPI_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
-+                      return 0;
-+              if (ioc->broadcast_aen_busy)
-+                      return 0;
-+              ioc->broadcast_aen_busy = 1;
-               break;
-+      }
-+      case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
-+      {
-+              EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data =
-+                  (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data;
--      case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
--              ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
--              if (!ev) {
--                      printk(MYIOC_s_WARN_FMT "lost hotplug event\n", ioc->name);
--                      break;
-+              if (sas_event_data->ReasonCode ==
-+                  MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING) {
-+                      mptsas_target_reset_queue(ioc, sas_event_data);
-+                      return 0;
-               }
-+              break;
-+      }
-+      case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
-+      {
-+              MpiEventDataSasExpanderStatusChange_t *expander_data =
-+                  (MpiEventDataSasExpanderStatusChange_t *)reply->Data;
--              INIT_WORK(&ev->work, mptsas_hotplug_work);
--              ev->ioc = ioc;
--              ev->handle = le16_to_cpu(sas_event_data->DevHandle);
--              ev->parent_handle =
--                  le16_to_cpu(sas_event_data->ParentDevHandle);
--              ev->channel = sas_event_data->Bus;
--              ev->id = sas_event_data->TargetID;
--              ev->phy_id = sas_event_data->PhyNum;
--              memcpy(&sas_address, &sas_event_data->SASAddress,
--                  sizeof(__le64));
--              ev->sas_address = le64_to_cpu(sas_address);
--              ev->device_info = device_info;
-+              if (ioc->old_sas_discovery_protocal)
-+                      return 0;
--              if (sas_event_data->ReasonCode &
--                  MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
--                      ev->event_type = MPTSAS_ADD_DEVICE;
--              else
--                      ev->event_type = MPTSAS_DEL_DEVICE;
--              schedule_work(&ev->work);
-+              if (expander_data->ReasonCode ==
-+                  MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING &&
-+                  ioc->device_missing_delay)
-+                      delay = HZ * ioc->device_missing_delay;
+-      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt type=%d timeout=%ld\n",
+-          ioc->name, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, timeout));
++      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++              "TaskMgmt type=%d timeout=%ld\n", ioc->name,
++              MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, timeout));
+       INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
+       CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
+@@ -431,9 +435,10 @@ mptctl_bus_reset(MPT_ADAPTER *ioc, u8 fu
+               mpt_put_msg_frame_hi_pri(mptctl_taskmgmt_id, ioc, mf);
+       else {
+               retval = mpt_send_handshake_request(mptctl_taskmgmt_id, ioc,
+-                  sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
++                  sizeof(SCSITaskMgmt_t), (u32 *)pScsiTm, CAN_SLEEP);
+               if (retval != 0) {
+-                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "TaskMgmt send_handshake FAILED!"
++                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
++                              "TaskMgmt send_handshake FAILED!"
+                               " (ioc %p, mf %p, rc=%d) \n", ioc->name,
+                               ioc, mf, retval));
+                       mpt_clear_taskmgmt_in_progress_flag(ioc);
+@@ -498,11 +503,10 @@ mptctl_timeout_expired(MPT_ADAPTER *ioc,
+       unsigned long flags;
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": %s\n",
+-              ioc->name, __FUNCTION__));
++              ioc->name, __func__));
+-      if(mpt_fwfault_debug)
++      if (mpt_fwfault_debug)
+               mpt_halt_firmware(ioc);
+-
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       if (ioc->ioc_reset_in_progress) {
+               spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+@@ -540,15 +544,15 @@ mptctl_ioc_reset(MPT_ADAPTER *ioc, int r
+       switch(reset_phase) {
+       case MPT_IOC_SETUP_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
                break;
--      case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
--      /*
--       * Persistent table is full.
--       */
--              INIT_WORK(&ioc->sas_persist_task,
--                  mptsas_persist_clear_table);
--              schedule_work(&ioc->sas_persist_task);
-+      }
-+      case MPI_EVENT_SAS_DISCOVERY:
-+      {
-+              u32 discovery_status;
-+              EventDataSasDiscovery_t *discovery_data =
-+                  (EventDataSasDiscovery_t *)reply->Data;
-+
-+              discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus);
-+              ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0;
-+              if (ioc->old_sas_discovery_protocal && !discovery_status)
-+                      mptsas_queue_rescan(ioc);
-+              return 0;
-+      }
-+      case MPI_EVENT_INTEGRATED_RAID:
-+      case MPI_EVENT_PERSISTENT_TABLE_FULL:
-+      case MPI_EVENT_IR2:
-+      case MPI_EVENT_SAS_PHY_LINK_STATUS:
-+      case MPI_EVENT_QUEUE_FULL:
+       case MPT_IOC_PRE_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
                break;
--      /*
--       * TODO, handle other events
--       */
--      case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
--      case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
--      case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
--      case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
--      case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
--      case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
--      case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
-       default:
--              break;
-+              return 0;
-       }
-+
-+      event_data_sz = ((reply->MsgLength * 4) -
-+          offsetof(EventNotificationReply_t, Data));
-+      sz = offsetof(struct fw_event_work, event_data) + event_data_sz;
-+      fw_event = kzalloc(sz, GFP_ATOMIC);
-+      if (!fw_event) {
-+              printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name,
-+                  __FUNCTION__, __LINE__);
-+              return 0;
-+      }
-+      memcpy(fw_event->event_data, reply->Data, event_data_sz);
-+      fw_event->event = event;
-+      fw_event->ioc = ioc;
-+      mptsas_add_fw_event(ioc, fw_event, delay);
-+      return 0;
- }
--static void
--mptsas_send_raid_event(MPT_ADAPTER *ioc,
--              EVENT_DATA_RAID *raid_event_data)
-+
-+
-+/* Delete a volume when no longer listed in ioc pg2
-+ */
-+static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id)
- {
--      struct mptsas_hotplug_event *ev;
--      int status = le32_to_cpu(raid_event_data->SettingsStatus);
--      int state = (status >> 8) & 0xff;
-+      struct scsi_device *sdev;
-+      int i;
--      if (ioc->bus_type != SAS)
-+      sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, id, 0);
-+      if (!sdev)
-               return;
-+      if (!ioc->raid_data.pIocPg2)
-+              goto out;
-+      if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
-+              goto out;
-+      for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
-+              if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id)
-+                      goto release_sdev;
-+ out:
-+      printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
-+          "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,id);
-+      scsi_remove_device(sdev);
-+ release_sdev:
-+      scsi_device_put(sdev);
-+}
-+
-+static void
-+mptsas_not_responding_devices(MPT_ADAPTER *ioc)
-+{
-+      struct mptsas_portinfo buffer, *port_info;
-+      struct sas_device_info  *sas_info;
-+      struct mptsas_devinfo sas_device;
-+      u32     handle;
-+      VirtTarget *vtarget = NULL;
-+      struct mptsas_phyinfo *phy_info;
-+      u8 found_expander;
--      ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
--      if (!ev) {
--              printk(MYIOC_s_WARN_FMT "lost hotplug event\n", ioc->name);
-+      if (ioc->disable_hotplug_remove)
-               return;
-+
-+      mpt_findImVolumes(ioc);
-+
-+      /* devices, logical volumes */
-+ redo_device_scan:
-+      list_for_each_entry(sas_info, &ioc->sas_device_info_list, list) {
-+              if (sas_info->is_cached)
-+                      continue;
-+              if (!sas_info->is_logical_volume) {
-+                      sas_device.handle = 0;
-+                      mptsas_sas_device_pg0(ioc, &sas_device,
-+                          (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
-+                           MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
-+                              (sas_info->fw.channel << 8) +
-+                              sas_info->fw.id);
-+                      if (sas_device.handle)
-+                              continue;
-+                      /* delete device */
-+                      if ((vtarget = mptsas_find_vtarget(ioc,
-+                                  sas_info->fw.channel,
-+                          sas_info->fw.id)))
-+                              vtarget->deleted = 1;
-+                      phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
-+                          sas_info->sas_address);
-+                      if (phy_info) {
-+                              mptsas_del_end_device(ioc, phy_info);
-+                              goto redo_device_scan;
-+                      }
-+              } else
-+                      mptsas_volume_delete(ioc, sas_info->fw.id);
-       }
--      INIT_WORK(&ev->work, mptsas_hotplug_work);
--      ev->ioc = ioc;
--      ev->id = raid_event_data->VolumeID;
--      ev->channel = raid_event_data->VolumeBus;
--      ev->event_type = MPTSAS_IGNORE_EVENT;
-+      /* expanders */
-+ redo_expander_scan:
-+      list_for_each_entry(port_info, &ioc->sas_topology, list) {
--      switch (raid_event_data->ReasonCode) {
--      case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
--              ev->phys_disk_num_valid = 1;
--              ev->phys_disk_num = raid_event_data->PhysDiskNum;
--              ev->event_type = MPTSAS_ADD_DEVICE;
--              break;
--      case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
--              ev->phys_disk_num_valid = 1;
--              ev->phys_disk_num = raid_event_data->PhysDiskNum;
--              ev->hidden_raid_component = 1;
--              ev->event_type = MPTSAS_DEL_DEVICE;
--              break;
--      case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
--              switch (state) {
--              case MPI_PD_STATE_ONLINE:
--              case MPI_PD_STATE_NOT_COMPATIBLE:
--                      ev->phys_disk_num_valid = 1;
--                      ev->phys_disk_num = raid_event_data->PhysDiskNum;
--                      ev->hidden_raid_component = 1;
--                      ev->event_type = MPTSAS_ADD_DEVICE;
--                      break;
--              case MPI_PD_STATE_MISSING:
--              case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
--              case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
--              case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
--                      ev->phys_disk_num_valid = 1;
--                      ev->phys_disk_num = raid_event_data->PhysDiskNum;
--                      ev->event_type = MPTSAS_DEL_DEVICE;
--                      break;
--              default:
--                      break;
-+              if (port_info->phy_info &&
-+                  (!(port_info->phy_info[0].identify.device_info &
-+                  MPI_SAS_DEVICE_INFO_SMP_TARGET)))
-+                      continue;
-+              found_expander = 0;
-+              handle = 0xFFFF;
-+              while (!mptsas_sas_expander_pg0(ioc, &buffer,
-+                  (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
-+                   MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle) &&
-+                  !found_expander) {
-+
-+                      handle = buffer.phy_info[0].handle;
-+                      if (buffer.phy_info[0].identify.sas_address ==
-+                          port_info->phy_info[0].identify.sas_address) {
-+                              found_expander = 1;
-+                      }
-+                      kfree(buffer.phy_info);
-               }
--              break;
--      case MPI_EVENT_RAID_RC_VOLUME_DELETED:
--              ev->event_type = MPTSAS_DEL_RAID;
--              break;
--      case MPI_EVENT_RAID_RC_VOLUME_CREATED:
--              ev->event_type = MPTSAS_ADD_RAID;
--              break;
--      case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
--              switch (state) {
--              case MPI_RAIDVOL0_STATUS_STATE_FAILED:
--              case MPI_RAIDVOL0_STATUS_STATE_MISSING:
--                      ev->event_type = MPTSAS_DEL_RAID;
--                      break;
--              case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
--              case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
--                      ev->event_type = MPTSAS_ADD_RAID;
--                      break;
--              default:
--                      break;
-+
-+              if (!found_expander) {
-+                      mptsas_expander_delete(ioc, port_info);
-+                      goto redo_expander_scan;
-               }
--              break;
--      default:
--              break;
-       }
--      schedule_work(&ev->work);
- }
+       case MPT_IOC_POST_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_POST_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
+               if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_PENDING) {
+                       ioc->ioctl_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
+                       complete(&ioc->ioctl_cmds.done);
+@@ -571,13 +575,11 @@ mptctl_event_process(MPT_ADAPTER *ioc, E
+       event = le32_to_cpu(pEvReply->Event) & 0xFF;
  
-+/**
-+ *    mptsas_probe_expanders - adding expanders
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *
-+ **/
- static void
--mptsas_send_discovery_event(MPT_ADAPTER *ioc,
--      EVENT_DATA_SAS_DISCOVERY *discovery_data)
-+mptsas_probe_expanders(MPT_ADAPTER *ioc)
- {
--      struct mptsas_discovery_event *ev;
-+      struct mptsas_portinfo buffer, *port_info;
-+      u32                     handle;
-+      int i;
--      /*
--       * DiscoveryStatus
--       *
--       * This flag will be non-zero when firmware
--       * kicks off discovery, and return to zero
--       * once its completed.
--       */
--      if (discovery_data->DiscoveryStatus)
--              return;
-+      handle = 0xFFFF;
-+      while (!mptsas_sas_expander_pg0(ioc, &buffer,
-+          (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
-+           MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)) {
--      ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
--      if (!ev)
--              return;
--      INIT_WORK(&ev->work, mptsas_discovery_work);
--      ev->ioc = ioc;
--      schedule_work(&ev->work);
--};
-+              handle = buffer.phy_info[0].handle;
-+              port_info = mptsas_find_portinfo_by_sas_address(ioc,
-+                  buffer.phy_info[0].identify.sas_address);
-+
-+              if (port_info) {
-+                      /* refreshing handles */
-+                      for (i = 0; i < buffer.num_phys; i++) {
-+                              port_info->phy_info[i].handle = handle;
-+                              port_info->phy_info[i].identify.handle_parent =
-+                                  buffer.phy_info[0].identify.handle_parent;
-+                      }
-+                      mptsas_expander_refresh(ioc, port_info);
-+                      kfree(buffer.phy_info);
-+                      continue;
-+              }
-+
-+              port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
-+              if (!port_info) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                      "%s: exit at line=%d\n", ioc->name,
-+                      __FUNCTION__, __LINE__));
-+                      return;
-+              }
-+              port_info->num_phys = buffer.num_phys;
-+              port_info->phy_info = buffer.phy_info;
-+              for (i = 0; i < port_info->num_phys; i++)
-+                      port_info->phy_info[i].portinfo = port_info;
-+              mutex_lock(&ioc->sas_topology_mutex);
-+              list_add_tail(&port_info->list, &ioc->sas_topology);
-+              mutex_unlock(&ioc->sas_topology_mutex);
-+              printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
-+                  "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
-+          (unsigned long long)buffer.phy_info[0].identify.sas_address);
-+              mptsas_expander_refresh(ioc, port_info);
-+      }
-+}
+       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s() called\n",
+-          ioc->name, __FUNCTION__));
++          ioc->name, __func__));
+       if(async_queue == NULL)
+               return 1;
  
--/*
-- * mptsas_send_ir2_event - handle exposing hidden disk when
-- * an inactive raid volume is added
-- *
-- * @ioc: Pointer to MPT_ADAPTER structure
-- * @ir2_data
-- *
-- */
- static void
--mptsas_send_ir2_event(MPT_ADAPTER *ioc, PTR_MPI_EVENT_DATA_IR2 ir2_data)
-+mptsas_probe_devices(MPT_ADAPTER *ioc)
- {
--      struct mptsas_hotplug_event *ev;
-+      u16 retry_count;
-+      u16 handle;
-+      struct mptsas_devinfo sas_device;
-+      struct mptsas_phyinfo *phy_info;
-+      enum device_state state;
--      if (ir2_data->ReasonCode !=
--          MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED)
--              return;
-+      handle = 0xFFFF;
-+      while (!(mptsas_sas_device_pg0(ioc, &sas_device,
-+          MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
-+
-+              handle = sas_device.handle;
-+
-+              if ((sas_device.device_info &
-+                   (MPI_SAS_DEVICE_INFO_SSP_TARGET |
-+                    MPI_SAS_DEVICE_INFO_STP_TARGET |
-+                    MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0)
-+                      continue;
--      ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
--      if (!ev)
--              return;
-+              phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
-+              if (!phy_info)
-+                      continue;
--      INIT_WORK(&ev->work, mptsas_hotplug_work);
--      ev->ioc = ioc;
--      ev->id = ir2_data->TargetID;
--      ev->channel = ir2_data->Bus;
--      ev->event_type = MPTSAS_ADD_INACTIVE_VOLUME;
-+              if (mptsas_get_rphy(phy_info))
-+                      continue;
--      schedule_work(&ev->work);
--};
-+              state = DEVICE_RETRY;
-+              retry_count = 0;
-+              while(state == DEVICE_RETRY) {
-+                      state = mptsas_test_unit_ready(ioc, sas_device.channel,
-+                          sas_device.id, retry_count++);
-+                      ssleep(1);
-+              }
-+              if (state == DEVICE_READY)
-+                      mptsas_add_end_device(ioc, phy_info);
-+      }
-+}
+       /* Raise SIGIO for persistent events.
+-       * TODO - this define is not in MPI spec yet,
+-       * but they plan to set it to 0x21
+        */
+        if (event == 0x21 ) {
+               ioc->aen_event_read_flag=1;
+@@ -660,8 +662,9 @@ __mptctl_ioctl(struct file *file, unsign
+       if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
+           (iocp == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_ioctl() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnumX);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                          __FILE__, __func__,  __LINE__, iocnumX);
+               return -ENODEV;
+       }
  
--static int
--mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
-+/**
-+ *    mptsas_scan_sas_topology -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @sas_address:
-+ *
-+ **/
-+static void
-+mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
- {
--      int rc=1;
--      u8 event = le32_to_cpu(reply->Event) & 0xFF;
-+      struct scsi_device *sdev;
-+      int i;
+@@ -700,9 +703,9 @@ __mptctl_ioctl(struct file *file, unsign
+               return csmisas_get_cntlr_status(arg);
+       } else if (cmd == CC_CSMI_SAS_GET_SCSI_ADDRESS) {
+               return csmisas_get_scsi_address(arg);
+-      } else if (cmd == CC_CSMI_SAS_GET_DEVICE_ADDRESS){
++      } else if (cmd == CC_CSMI_SAS_GET_DEVICE_ADDRESS) {
+               return csmisas_get_device_address(arg);
+-#endif // CPQ_CIM
++#endif
+       }
  
--      if (!ioc->sh)
--              goto out;
-+      mptsas_probe_hba_phys(ioc);
-+      mptsas_probe_expanders(ioc);
-+      mptsas_probe_devices(ioc);
+       /* All of these commands require an interrupt or
+@@ -711,8 +714,6 @@ __mptctl_ioctl(struct file *file, unsign
+       if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)
+               return ret;
  
-       /*
--       * sas_discovery_ignore_events
--       *
--       * This flag is to prevent anymore processing of
--       * sas events once mptsas_remove function is called.
--       */
--      if (ioc->sas_discovery_ignore_events) {
--              rc = mptscsih_event_process(ioc, reply);
--              goto out;
--      }
--
--      switch (event) {
--      case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
--              mptsas_send_sas_event(ioc,
--                      (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
--              break;
--      case MPI_EVENT_INTEGRATED_RAID:
--              mptsas_send_raid_event(ioc,
--                      (EVENT_DATA_RAID *)reply->Data);
--              break;
--      case MPI_EVENT_PERSISTENT_TABLE_FULL:
--              INIT_WORK(&ioc->sas_persist_task,
--                  mptsas_persist_clear_table);
--              schedule_work(&ioc->sas_persist_task);
--              break;
--       case MPI_EVENT_SAS_DISCOVERY:
--              mptsas_send_discovery_event(ioc,
--                      (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
--              break;
--      case MPI_EVENT_IR2:
--              mptsas_send_ir2_event(ioc,
--                  (PTR_MPI_EVENT_DATA_IR2)reply->Data);
--              break;
--      default:
--              rc = mptscsih_event_process(ioc, reply);
--              break;
-+        Reporting RAID volumes.
-+      */
-+      if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 ||
-+          !ioc->raid_data.pIocPg2->NumActiveVolumes)
-+              return;
-+      for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
-+              if ((sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
-+                  ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0))) {
-+                      scsi_device_put(sdev);
-+                      continue;
-+              }
-+              printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
-+                  "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
-+                  ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID);
-+              scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
-+                  ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
-       }
-- out:
+-//    dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT ": mptctl_ioctl()\n", iocp->name));
 -
--      return rc;
- }
+       if (cmd == MPTFWDOWNLOAD)
+               ret = mptctl_fw_download(arg);
+       else if (cmd == MPTCOMMAND)
+@@ -763,7 +764,7 @@ __mptctl_ioctl(struct file *file, unsign
+               ret = csmisas_get_connector_info(arg);
+       else if (cmd == CC_CSMI_SAS_GET_LOCATION)
+               ret = csmisas_get_location(arg);
+-#endif // CPQ_CIM
++#endif
  
-+/**
-+ *    mptsas_probe -
-+ *    @pdev:
-+ *    @id:
-+ *
-+ **/
- static int
- mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
- {
-@@ -3129,6 +5071,7 @@ mptsas_probe(struct pci_dev *pdev, const
-               return r;
+ #if defined(DIAG_BUFFER_SUPPORT)
+ /* diag_buffer requiring fw calls*/
+@@ -773,7 +774,7 @@ __mptctl_ioctl(struct file *file, unsign
+               ret = mptctl_release_diag_buffer(arg);
+       else if (cmd == MPTDIAGREADBUFFER)
+               ret = mptctl_read_diag_buffer(arg);
+-#endif // DIAG_BUFFER_SUPPORT
++#endif
+       else
+               ret = -EINVAL;
  
-       ioc = pci_get_drvdata(pdev);
-+      mptsas_fw_event_off(ioc);
-       ioc->DoneCtx = mptsasDoneCtx;
-       ioc->TaskCtx = mptsasTaskCtx;
-       ioc->InternalCtx = mptsasInternalCtx;
-@@ -3173,7 +5116,7 @@ mptsas_probe(struct pci_dev *pdev, const
-                       ioc->name);
-               error = -1;
-               goto out_mptsas_probe;
--        }
-+      }
+@@ -807,8 +808,9 @@ static int mptctl_do_reset(unsigned long
  
-       spin_lock_irqsave(&ioc->FreeQlock, flags);
+       if (mpt_verify_adapter(krinfo.hdr.iocnum, &iocp) < 0) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s@%d::mptctl_do_reset - ioc%d not found!\n",
+-                              __FILE__, __LINE__, krinfo.hdr.iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s@%d::%s - ioc%d not found!\n",
++                          __FILE__, __LINE__, __func__,  krinfo.hdr.iocnum);
+               return -ENODEV; /* (-6) No such device or address */
+       }
  
-@@ -3187,10 +5130,9 @@ mptsas_probe(struct pci_dev *pdev, const
+@@ -898,7 +900,8 @@ mptctl_do_fw_download(int ioc, char __us
  
-       /* set 16 byte cdb's */
-       sh->max_cmd_len = 16;
--
-+      sh->can_queue = min_t(int, ioc->req_depth - 10, sh->can_queue);
-       sh->max_id = ioc->pfacts[0].PortSCSIID;
-       sh->max_lun = max_lun;
--
-       sh->transportt = mptsas_transport_template;
+       if (mpt_verify_adapter(ioc, &iocp) < 0) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "ioctl_fwdl - ioc%d not found!\n", ioc);
++                      printk(KERN_DEBUG MYNAM
++                          "ioctl_fwdl - ioc%d not found!\n", ioc);
+               return -ENODEV; /* (-6) No such device or address */
+       } else {
  
-       /* Required entry.
-@@ -3199,10 +5141,10 @@ mptsas_probe(struct pci_dev *pdev, const
+@@ -982,7 +985,7 @@ mptctl_do_fw_download(int ioc, char __us
+                       / iocp->SGE_size;
+       if (numfrags > maxfrags) {
+               ret = -EMLINK;
+-              goto fwdl_out;
++              goto fwdl_out;
+       }
  
-       INIT_LIST_HEAD(&ioc->sas_topology);
-       mutex_init(&ioc->sas_topology_mutex);
--      mutex_init(&ioc->sas_discovery_mutex);
-       mutex_init(&ioc->sas_mgmt.mutex);
-       init_completion(&ioc->sas_mgmt.done);
+       dctlprintk(iocp, printk(MYIOC_s_DEBUG_FMT "DbG: sgl buffer = %p, sgfrags = %d\n",
+@@ -1036,7 +1039,7 @@ mptctl_do_fw_download(int ioc, char __us
+       timeleft = wait_for_completion_timeout(&iocp->ioctl_cmds.done, HZ*60);
+       if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               ret = -ETIME;
+-              printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __FUNCTION__);
++              printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__);
+               if (iocp->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
+                       mpt_free_msg_frame(iocp, mf);
+                       goto fwdl_out;
+@@ -1047,7 +1050,7 @@ mptctl_do_fw_download(int ioc, char __us
+       }
+       if (!(iocp->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
+-              printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __FUNCTION__);
++              printk(MYIOC_s_WARN_FMT "%s: failed\n", iocp->name, __func__);
+               mpt_free_msg_frame(iocp, mf);
+               ret = -ENODATA;
+               goto fwdl_out;
+@@ -1059,10 +1062,12 @@ mptctl_do_fw_download(int ioc, char __us
+       ReplyMsg = (pFWDownloadReply_t)iocp->ioctl_cmds.reply;
+       iocstat = le16_to_cpu(ReplyMsg->IOCStatus) & MPI_IOCSTATUS_MASK;
+       if (iocstat == MPI_IOCSTATUS_SUCCESS) {
+-              printk(MYIOC_s_INFO_FMT ": F/W update successfully sent!\n", iocp->name);
++              printk(MYIOC_s_INFO_FMT
++                  ": F/W update successfully sent!\n", iocp->name);
+               return 0;
+       } else if (iocstat == MPI_IOCSTATUS_INVALID_FUNCTION) {
+-              printk(MYIOC_s_WARN_FMT "Hmmm...  doesn't support F/W download?\n",
++              printk(MYIOC_s_WARN_FMT
++                  "Hmmm...  doesn't support F/W download?\n",
+                   iocp->name);
+               printk(MYIOC_s_WARN_FMT "(time to go bang on somebodies door)\n",
+                   iocp->name);
+@@ -1177,7 +1182,8 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, i
+                       bytes_allocd += this_alloc;
+                       sgl->FlagsLength = (0x10000000|sgdir|this_alloc);
+                       if (ioc->sg_addr_size == sizeof(u64))
+-                              sgl->FlagsLength |= MPT_SGE_FLAGS_64_BIT_ADDRESSING;
++                              sgl->FlagsLength
++                                  |= MPT_SGE_FLAGS_64_BIT_ADDRESSING;
+                       dma_addr = pci_map_single(ioc->pcidev, buflist[buflist_ent].kptr, this_alloc, dir);
+                       sgl->Address = dma_addr;
  
-+
-       /* Verify that we won't exceed the maximum
-        * number of chain buffers
-        * We can optimize:  ZZ = req_sz/sizeof(SGE)
-@@ -3212,17 +5154,16 @@ mptsas_probe(struct pci_dev *pdev, const
-        * A slightly different algorithm is required for
-        * 64bit SGEs.
-        */
--      scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
--      if (sizeof(dma_addr_t) == sizeof(u64)) {
-+
-+      scale = ioc->req_sz/ioc->SGE_size;
-+      if (ioc->sg_addr_size == sizeof(u64)) {
-               numSGE = (scale - 1) *
-                 (ioc->facts.MaxChainDepth-1) + scale +
--                (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
--                sizeof(u32));
-+                (ioc->req_sz - 60) / ioc->SGE_size;
-       } else {
-               numSGE = 1 + (scale - 1) *
-                 (ioc->facts.MaxChainDepth-1) + scale +
--                (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
--                sizeof(u32));
-+                (ioc->req_sz - 64) / ioc->SGE_size;
+@@ -1362,8 +1368,9 @@ mptctl_getiocinfo (unsigned long arg, un
+       if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
+           (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_getiocinfo() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                         "%s::%s @%d - ioc%d not found!\n",
++                         __FILE__, __func__,  __LINE__, iocnum);
+               kfree(karg);
+               return -ENODEV;
+       }
+@@ -1498,8 +1505,9 @@ mptctl_gettargetinfo (unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+           (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_gettargetinfo() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                              __FILE__, __func__,  __LINE__, iocnum);
+               return -ENODEV;
        }
  
-       if (numSGE < sh->sg_tablesize) {
-@@ -3250,34 +5191,17 @@ mptsas_probe(struct pci_dev *pdev, const
-       dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
-                ioc->name, ioc->ScsiLookup));
+@@ -1514,7 +1522,8 @@ mptctl_gettargetinfo (unsigned long arg)
+       port = karg.hdr.port;
  
--      /* Clear the TM flags
--       */
--      hd->tmPending = 0;
--      hd->tmState = TM_STATE_NONE;
--      hd->resetPending = 0;
--      hd->abortSCpnt = NULL;
--
--      /* Clear the pointer used to store
--       * single-threaded commands, i.e., those
--       * issued during a bus scan, dv and
--       * configuration pages.
--       */
--      hd->cmdPtr = NULL;
--
--      /* Initialize this SCSI Hosts' timers
--       * To use, set the timer expires field
--       * and add_timer
--       */
--      init_timer(&hd->timer);
--      hd->timer.data = (unsigned long) hd;
--      hd->timer.function = mptscsih_timer_expired;
--
-+      ioc->sdev_queue_depth = mpt_sdev_queue_depth;
-       ioc->sas_data.ptClear = mpt_pt_clear;
--
--      init_waitqueue_head(&hd->scandv_waitq);
--      hd->scandv_wait_done = 0;
-       hd->last_queue_full = 0;
-+      ioc->disable_hotplug_remove = mpt_disable_hotplug_remove;
-+      if (ioc->disable_hotplug_remove)
-+              printk(MYIOC_s_INFO_FMT "disabling hotplug remove\n", ioc->name);
-+
-       INIT_LIST_HEAD(&hd->target_reset_list);
-+      INIT_LIST_HEAD(&ioc->sas_device_info_list);
-+      init_MUTEX(&ioc->sas_device_info_mutex);
-+
-       spin_unlock_irqrestore(&ioc->FreeQlock, flags);
+       if (maxWordsLeft <= 0) {
+-              printk(MYIOC_s_ERR_FMT "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
++              printk(MYIOC_s_ERR_FMT
++                  "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
+                   ioc->name, __FILE__, __LINE__);
+               return -ENOMEM;
+       }
+@@ -1535,7 +1544,8 @@ mptctl_gettargetinfo (unsigned long arg)
+        */
+       pmem = kzalloc(numBytes, GFP_KERNEL);
+       if (!pmem) {
+-              printk(MYIOC_s_ERR_FMT "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
++              printk(MYIOC_s_ERR_FMT
++                  "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
+                   ioc->name, __FILE__, __LINE__);
+               return -ENOMEM;
+       }
+@@ -1615,8 +1625,9 @@ mptctl_readtest (unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+           (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_readtest() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                          __FILE__, __func__,  __LINE__, iocnum);
+               return -ENODEV;
+       }
  
-       if (ioc->sas_data.ptClear==1) {
-@@ -3292,8 +5216,11 @@ mptsas_probe(struct pci_dev *pdev, const
-               goto out_mptsas_probe;
+@@ -1677,8 +1688,9 @@ mptctl_eventquery (unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+           (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_eventquery() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                          __FILE__, __func__,  __LINE__, iocnum);
+               return -ENODEV;
        }
  
-+      /* older firmware doesn't support expander events */
-+      if ((ioc->facts.HeaderVersion >> 8) < 0xE)
-+              ioc->old_sas_discovery_protocal = 1;
-       mptsas_scan_sas_topology(ioc);
--
-+      mptsas_fw_event_on(ioc);
-       return 0;
+@@ -1717,8 +1729,9 @@ mptctl_eventenable (unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+           (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_eventenable() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                          __FILE__, __func__,  __LINE__, iocnum);
+               return -ENODEV;
+       }
  
-  out_mptsas_probe:
-@@ -3302,13 +5229,23 @@ mptsas_probe(struct pci_dev *pdev, const
-       return error;
- }
+@@ -1730,7 +1743,8 @@ mptctl_eventenable (unsigned long arg)
+               int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
+               ioc->events = kzalloc(sz, GFP_KERNEL);
+               if (!ioc->events) {
+-                      printk(MYIOC_s_ERR_FMT "Insufficient memory to add adapter!\n",
++                      printk(MYIOC_s_ERR_FMT
++                          "Insufficient memory to add adapter!\n",
+                           ioc->name);
+                       return -ENOMEM;
+               }
+@@ -1766,8 +1780,9 @@ mptctl_eventreport (unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+           (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_eventreport() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                          __FILE__, __func__,  __LINE__, iocnum);
+               return -ENODEV;
+       }
  
--static void __devexit mptsas_remove(struct pci_dev *pdev)
-+/**
-+ *    mptsas_remove -
-+ *    @pdev:
-+ *
-+ **/
-+static void __devexit
-+mptsas_remove(struct pci_dev *pdev)
- {
-       MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
-       struct mptsas_portinfo *p, *n;
-       int i;
+@@ -1821,8 +1836,9 @@ mptctl_replace_fw (unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+           (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_replace_fw() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                          __FILE__, __func__,  __LINE__, iocnum);
+               return -ENODEV;
+       }
  
--      ioc->sas_discovery_ignore_events = 1;
-+      mptsas_fw_event_off(ioc);
-+      mptsas_cleanup_fw_event_q(ioc);
-+
-+      mptsas_del_device_components(ioc);
-+
-       sas_remove_host(ioc->sh);
+@@ -1870,7 +1886,8 @@ mptctl_replace_fw (unsigned long arg)
+  *
+  * Outputs:   None.
+  * Return:    0 if successful
+- *            -EBUSY  if previous command timout and IOC reset is not complete.
++ *            -EBUSY  if previous command timout and IOC reset is
++ *            not complete.
+  *            -EFAULT if data unavailable
+  *            -ENODEV if no such device/adapter
+  *            -ETIME  if timer expires
+@@ -1896,8 +1913,9 @@ mptctl_mpt_command (unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+           (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_mpt_command() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                          __FILE__, __func__,  __LINE__, iocnum);
+               return -ENODEV;
+       }
  
-       mutex_lock(&ioc->sas_topology_mutex);
-@@ -3316,11 +5253,12 @@ static void __devexit mptsas_remove(stru
-               list_del(&p->list);
-               for (i = 0 ; i < p->num_phys ; i++)
-                       mptsas_port_delete(ioc, p->phy_info[i].port_details);
-+
-               kfree(p->phy_info);
-               kfree(p);
+@@ -1911,7 +1929,8 @@ mptctl_mpt_command (unsigned long arg)
+  *
+  * Outputs:   None.
+  * Return:    0 if successful
+- *            -EBUSY  if previous command timout and IOC reset is not complete.
++ *            -EBUSY  if previous command timout and IOC reset is
++ *            not complete.
+  *            -EFAULT if data unavailable
+  *            -ENODEV if no such device/adapter
+  *            -ETIME  if timer expires
+@@ -1948,8 +1967,9 @@ mptctl_do_mpt_command (struct mpt_ioctl_
+       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+           (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_do_mpt_command() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                          __FILE__, __func__,  __LINE__, iocnum);
+               return -ENODEV;
        }
-       mutex_unlock(&ioc->sas_topology_mutex);
--
-+      ioc->hba_port_info = NULL;
-       mptscsih_remove(pdev);
- }
  
-@@ -3352,6 +5290,10 @@ static struct pci_driver mptsas_driver =
- #endif
- };
+@@ -2194,10 +2214,12 @@ mptctl_do_mpt_command (struct mpt_ioctl_
+       {
+               SCSITaskMgmt_t  *pScsiTm;
+               pScsiTm = (SCSITaskMgmt_t *)mf;
+-              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\tTaskType=0x%x MsgFlags=0x%x "
+-                  "TaskMsgContext=0x%x id=%d channel=%d\n", ioc->name, pScsiTm->TaskType,
+-                  le32_to_cpu(pScsiTm->TaskMsgContext), pScsiTm->MsgFlags,
+-                  pScsiTm->TargetID, pScsiTm->Bus));
++              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "\tTaskType=0x%x MsgFlags=0x%x "
++                      "TaskMsgContext=0x%x id=%d channel=%d\n",
++                      ioc->name, pScsiTm->TaskType,
++                      le32_to_cpu(pScsiTm->TaskMsgContext),
++                      pScsiTm->MsgFlags, pScsiTm->TargetID, pScsiTm->Bus));
+               break;
+       }
  
-+/**
-+ *    mptsas_init -
-+ *
-+ **/
- static int __init
- mptsas_init(void)
- {
-@@ -3365,10 +5307,12 @@ mptsas_init(void)
+@@ -2286,9 +2308,9 @@ mptctl_do_mpt_command (struct mpt_ioctl_
+               /* Set up the dataOut memory allocation */
+               if (karg.dataOutSize > 0) {
+                       if (karg.dataInSize > 0) {
+-                              flagsLength = ( MPI_SGE_FLAGS_SIMPLE_ELEMENT |
++                              flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
+                                               MPI_SGE_FLAGS_END_OF_BUFFER |
+-                                              MPI_SGE_FLAGS_DIRECTION )
++                                              MPI_SGE_FLAGS_DIRECTION)
+                                               << MPI_SGE_FLAGS_SHIFT;
+                       } else {
+                               flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
+@@ -2365,7 +2387,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_
+                       mpt_put_msg_frame_hi_pri(mptctl_id, ioc, mf);
+               else {
+                       rc = mpt_send_handshake_request(mptctl_id, ioc,
+-                          sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
++                          sizeof(SCSITaskMgmt_t), (u32 *)mf, CAN_SLEEP);
+                       if (rc != 0) {
+                               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                                   "send_handshake FAILED! (ioc %p, mf %p)\n",
+@@ -2381,16 +2403,16 @@ mptctl_do_mpt_command (struct mpt_ioctl_
+       /* Now wait for the command to complete */
+       timeout = (karg.timeout > 0) ? karg.timeout : MPT_IOCTL_DEFAULT_TIMEOUT;
+-      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, HZ*timeout);
++      timeleft =
++          wait_for_completion_timeout(&ioc->ioctl_cmds.done, HZ*timeout);
+       if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               rc = -ETIME;
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "%s: TIMED OUT!\n",
+-                  ioc->name, __FUNCTION__));
++                  ioc->name, __func__));
+               if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
+                       mutex_unlock(&ioc->taskmgmt_cmds.mutex);
+-              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
++              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
+                       goto done_free_mem;
+-              }
+               if (!timeleft) {
+                       mptctl_timeout_expired(ioc, mf);
+                       mf = NULL;
+@@ -2408,7 +2430,8 @@ mptctl_do_mpt_command (struct mpt_ioctl_
+        */
+       if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) {
+               if (karg.maxReplyBytes < ioc->reply_sz) {
+-                       sz = min(karg.maxReplyBytes, 4*ioc->ioctl_cmds.reply[2]);
++                       sz = min(karg.maxReplyBytes,
++                           4*ioc->ioctl_cmds.reply[2]);
+               } else {
+                        sz = min(ioc->reply_sz, 4*ioc->ioctl_cmds.reply[2]);
+               }
+@@ -2430,7 +2453,8 @@ mptctl_do_mpt_command (struct mpt_ioctl_
+       if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_SENSE_VALID) {
+               sz = min(karg.maxSenseBytes, MPT_SENSE_BUFFER_SIZE);
+               if (sz > 0) {
+-                      if (copy_to_user(karg.senseDataPtr, ioc->ioctl_cmds.sense, sz)) {
++                      if (copy_to_user(karg.senseDataPtr,
++                              ioc->ioctl_cmds.sense, sz)) {
+                               printk(MYIOC_s_ERR_FMT "%s@%d::mptctl_do_mpt_command - "
+                               "Unable to write sense data to user %p\n",
+                               ioc->name, __FILE__, __LINE__,
+@@ -2488,7 +2512,8 @@ done_free_mem:
+  * Outputs:   None.
+  * Return:    0 if successful
+  *            -EFAULT if data unavailable
+- *            -EBUSY  if previous command timout and IOC reset is not complete.
++ *            -EBUSY  if previous command timout and IOC reset is
++ *             not complete.
+  *            -ENODEV if no such device/adapter
+  *            -ETIME  if timer expires
+  *            -ENOMEM if memory allocation error
+@@ -2499,7 +2524,7 @@ mptctl_hp_hostinfo(unsigned long arg, un
+       hp_host_info_t  __user *uarg = (void __user *) arg;
+       MPT_ADAPTER             *ioc;
+       struct pci_dev          *pdev;
+-      char                    *pbuf=NULL;
++      char                    *pbuf = NULL;
+       dma_addr_t              buf_dma;
+       hp_host_info_t          karg;
+       int                     iocnum;
+@@ -2530,8 +2555,9 @@ mptctl_hp_hostinfo(unsigned long arg, un
+       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+           (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_hp_hostinfo() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                          __FILE__, __func__,  __LINE__, iocnum);
                return -ENODEV;
+       }
  
-       mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
--      mptsasTaskCtx = mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER);
-+      mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
-       mptsasInternalCtx =
-               mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
-       mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
-+      mptsasDeviceResetCtx =
-+              mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER);
-       mpt_event_register(mptsasDoneCtx, mptsas_event_process);
-       mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset);
-@@ -3380,6 +5324,10 @@ mptsas_init(void)
-       return error;
- }
+@@ -2619,7 +2645,7 @@ mptctl_hp_hostinfo(unsigned long arg, un
+        */
+       if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL) {
+               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
+-                  ioc->name,__FUNCTION__));
++                  ioc->name,__func__));
+               retval = -ENOMEM;
+               goto out;
+       }
+@@ -2644,16 +2670,19 @@ mptctl_hp_hostinfo(unsigned long arg, un
+               retval = -ENOMEM;
+               goto out;
+       }
+-      ioc->add_sge((char *)&IstwiRWRequest->SGL, (MPT_SGE_FLAGS_SSIMPLE_READ|4),buf_dma);
++      ioc->add_sge((char *)&IstwiRWRequest->SGL,
++          (MPT_SGE_FLAGS_SSIMPLE_READ|4), buf_dma);
  
-+/**
-+ *    mptsas_exit -
-+ *
-+ **/
- static void __exit
- mptsas_exit(void)
- {
-@@ -3393,6 +5341,7 @@ mptsas_exit(void)
-       mpt_deregister(mptsasInternalCtx);
-       mpt_deregister(mptsasTaskCtx);
-       mpt_deregister(mptsasDoneCtx);
-+      mpt_deregister(mptsasDeviceResetCtx);
- }
+       retval = 0;
+-      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, IstwiRWRequest->MsgContext);
++      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
++          IstwiRWRequest->MsgContext);
+       INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
+       mpt_put_msg_frame(mptctl_id, ioc, mf);
+-      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done, HZ*MPT_IOCTL_DEFAULT_TIMEOUT);
++      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
++          HZ*MPT_IOCTL_DEFAULT_TIMEOUT);
+       if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               retval = -ETIME;
+-              printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name, __FUNCTION__);
++              printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name, __func__);
+               if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
+                       mpt_free_msg_frame(ioc, mf);
+                       goto out;
+@@ -2701,7 +2730,8 @@ mptctl_hp_hostinfo(unsigned long arg, un
+  * Outputs:   None.
+  * Return:    0 if successful
+  *            -EFAULT if data unavailable
+- *            -EBUSY  if previous command timout and IOC reset is not complete.
++ *            -EBUSY  if previous command timout and IOC reset is
++ *            not complete.
+  *            -ENODEV if no such device/adapter
+  *            -ETIME  if timer expires
+  *            -ENOMEM if memory allocation error
+@@ -2732,12 +2762,14 @@ mptctl_hp_targetinfo(unsigned long arg)
+       if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+               (ioc == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "%s::mptctl_hp_targetinfo() @%d - ioc%d not found!\n",
+-                              __FILE__, __LINE__, iocnum);
++                      printk(KERN_DEBUG MYNAM
++                          "%s::%s @%d - ioc%d not found!\n",
++                          __FILE__, __func__,  __LINE__, iocnum);
+               return -ENODEV;
+       }
  
- module_init(mptsas_init);
---- a/drivers/message/fusion/mptsas.h
-+++ b/drivers/message/fusion/mptsas.h
-@@ -50,9 +50,10 @@
- /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- struct mptsas_target_reset_event {
--      struct list_head        list;
--      EVENT_DATA_SAS_DEVICE_STATUS_CHANGE sas_event_data;
-+      struct list_head        list;
-+      MpiEventDataSasDeviceStatusChange_t sas_event_data;
-       u8      target_reset_issued;
-+      unsigned long    time_count;
- };
+-      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": mptctl_hp_targetinfo called.\n",
++      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++              ": mptctl_hp_targetinfo called.\n",
+           ioc->name));
+       /*  There is nothing to do for FCP parts.
+        */
+@@ -2889,8 +2921,9 @@ compat_mptfwxfer_ioctl(struct file *filp
+       if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
+           (iocp == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n",
+-                              __LINE__, iocnumX);
++                      printk(KERN_DEBUG MYNAM
++                          "::%s @%d - ioc%d not found!\n", __func__,
++                          __LINE__, iocnumX);
+               return -ENODEV;
+       }
  
- enum mptsas_hotplug_action {
-@@ -61,11 +62,34 @@ enum mptsas_hotplug_action {
-       MPTSAS_ADD_RAID,
-       MPTSAS_DEL_RAID,
-       MPTSAS_ADD_INACTIVE_VOLUME,
-+      MPTSAS_ADD_PHYSDISK,
-+      MPTSAS_ADD_PHYSDISK_REPROBE,
-+      MPTSAS_DEL_PHYSDISK,
-+      MPTSAS_DEL_PHYSDISK_REPROBE,
-+      MPTSAS_REQUEUE_EVENT,
-       MPTSAS_IGNORE_EVENT,
- };
+@@ -2930,8 +2963,9 @@ compat_mpt_command(struct file *filp, un
+       if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||
+           (iocp == NULL)) {
+               if (mpt_debug_level & MPT_DEBUG_IOCTL)
+-              printk(KERN_DEBUG MYNAM "::compat_mpt_command @%d - ioc%d not found!\n",
+-                              __LINE__, iocnumX);
++                      printk(KERN_DEBUG MYNAM
++                          "::%s @%d - ioc%d not found!\n",
++                          __func__, __LINE__, iocnumX);
+               return -ENODEV;
+       }
  
-+struct sas_mapping{
-+      u8                      id;
-+      u8                      channel;
-+};
-+
-+struct sas_device_info {
-+      struct list_head        list;
-+      struct sas_mapping      os;     /* operating system mapping*/
-+      struct sas_mapping      fw;     /* firmware mapping */
-+      u64                     sas_address;
-+      u32                     device_info; /* specific bits for devices */
-+      u16                     slot;           /* enclosure slot id */
-+      u64                     enclosure_logical_id; /*enclosure address */
-+      u8                      is_logical_volume; /* is this logical volume */
-+      u8                      is_hidden_raid_component; /* this belongs to volume */
-+      u8                      volume_id; /* this valid when is_hidden_raid_component set */
-+      u8                      is_cached;      /* cached data for a removed device */
-+};
-+
- struct mptsas_hotplug_event {
--      struct work_struct      work;
-       MPT_ADAPTER             *ioc;
-       enum mptsas_hotplug_action event_type;
-       u64                     sas_address;
-@@ -73,17 +97,28 @@ struct mptsas_hotplug_event {
-       u8                      id;
-       u32                     device_info;
-       u16                     handle;
--      u16                     parent_handle;
-       u8                      phy_id;
--      u8                      phys_disk_num_valid;    /* hrc (hidden raid component) */
-       u8                      phys_disk_num;          /* hrc - unique index*/
--      u8                      hidden_raid_component;  /* hrc - don't expose*/
-+      struct scsi_device      *sdev;
- };
+@@ -3144,7 +3178,7 @@ static void mptctl_exit(void)
  
--struct mptsas_discovery_event {
-+
-+struct fw_event_work {
-+      struct list_head        list;
-+      struct delayed_work      work;
-+      MPT_ADAPTER             *ioc;
-+      u32                     event;
-+      u8                      retries;
-+      u8                      event_data[1];
-+};
-+
-+#if 0
-+struct mptsas_link_status_event {
-       struct work_struct      work;
-+      MpiEventDataSasPhyLinkStatus_t link_data;
-       MPT_ADAPTER             *ioc;
- };
+ #if defined(CPQ_CIM)
+ #include "csmi/csmisas.c"
+-#endif // CPQ_CIM
 +#endif
  
- /*
-  * SAS topology structures
-@@ -113,32 +148,35 @@ struct mptsas_devinfo {
-  * Specific details on ports, wide/narrow
-  */
- struct mptsas_portinfo_details{
--      u16     num_phys;       /* number of phys belong to this port */
--      u64     phy_bitmask;    /* TODO, extend support for 255 phys */
--      struct sas_rphy *rphy;  /* transport layer rphy object */
-+      u16     num_phys;       /* number of phys beloing to this port */
-+      u64     phy_bitmask;    /* this needs extending to support 128 phys */
-+      struct sas_rphy *rphy; /* rphy for end devices */
-       struct sas_port *port;  /* transport layer port object */
-       struct scsi_target *starget;
-       struct mptsas_portinfo *port_info;
- };
+ #if defined(DIAG_BUFFER_SUPPORT)
+ #include "rejected_ioctls/diag_buffer.c"
+Index: linux-2.6.27/drivers/message/fusion/mptfc.c
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/mptfc.c
++++ linux-2.6.27/drivers/message/fusion/mptfc.c
+@@ -270,28 +270,28 @@ static int
+ mptfc_abort(struct scsi_cmnd *SCpnt)
+ {
+       return
+-          mptfc_block_error_handler(SCpnt, mptscsih_abort, __FUNCTION__);
++          mptfc_block_error_handler(SCpnt, mptscsih_abort, __func__);
+ }
+ static int
+ mptfc_dev_reset(struct scsi_cmnd *SCpnt)
+ {
+       return
+-          mptfc_block_error_handler(SCpnt, mptscsih_dev_reset, __FUNCTION__);
++          mptfc_block_error_handler(SCpnt, mptscsih_dev_reset, __func__);
+ }
  
- struct mptsas_phyinfo {
--      u16     handle;                 /* unique id to address this */
--      u8      phy_id;                 /* phy index */
--      u8      port_id;                /* firmware port identifier */
-+      u16     handle;                 /* handle for this phy */
-+      u8      phy_id;                 /* phy index */
-+      u8      port_id;                /* port number this phy is part of */
-       u8      negotiated_link_rate;   /* nego'd link rate for this phy */
--      u8      hw_link_rate;           /* hardware max/min phys link rate */
-+      u8      hw_link_rate;           /* hardware max/min phys link rate */
-       u8      programmed_link_rate;   /* programmed max/min phy link rate */
-       u8      sas_port_add_phy;       /* flag to request sas_port_add_phy*/
-+      u8      change_count;           /* change count of the phy */
-+      u8      port_flags;             /* info wrt host sas ports */
-+      u32     phy_info;               /* various info wrt the phy */
-       struct mptsas_devinfo identify; /* point to phy device info */
-       struct mptsas_devinfo attached; /* point to attached device info */
--      struct sas_phy *phy;            /* transport layer phy object */
-+      struct sas_phy *phy;
-       struct mptsas_portinfo *portinfo;
-       struct mptsas_portinfo_details * port_details;
- };
+ static int
+ mptfc_bus_reset(struct scsi_cmnd *SCpnt)
+ {
+       return
+-          mptfc_block_error_handler(SCpnt, mptscsih_bus_reset, __FUNCTION__);
++          mptfc_block_error_handler(SCpnt, mptscsih_bus_reset, __func__);
+ }
  
- struct mptsas_portinfo {
-       struct list_head list;
--      u16             num_phys;       /* number of phys */
-+      u16     num_phys;               /* number of phys */
-       struct mptsas_phyinfo *phy_info;
- };
+ static int
+ mptfc_host_reset(struct scsi_cmnd *SCpnt)
+ {
+       return
+-          mptfc_block_error_handler(SCpnt, mptscsih_host_reset, __FUNCTION__);
++          mptfc_block_error_handler(SCpnt, mptscsih_host_reset, __func__);
+ }
  
-@@ -156,3 +194,4 @@ struct mptsas_enclosure {
+ static void
+@@ -553,7 +553,6 @@ mptfc_target_destroy(struct scsi_target 
+       struct fc_rport         *rport;
+       struct mptfc_rport_info *ri;
  
- /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- #endif
-+
---- a/drivers/message/fusion/mptscsih.c
-+++ b/drivers/message/fusion/mptscsih.c
-@@ -53,7 +53,9 @@
- #include <linux/delay.h>      /* for mdelay */
- #include <linux/interrupt.h>  /* needed for in_interrupt() proto */
- #include <linux/reboot.h>     /* notifier code */
-+#include <linux/sched.h>
- #include <linux/workqueue.h>
-+#include <linux/pci.h>
- #include <scsi/scsi.h>
- #include <scsi/scsi_cmnd.h>
-@@ -77,10 +79,15 @@ MODULE_LICENSE("GPL");
- MODULE_VERSION(my_VERSION);
+-      printk("%s - starget=%p\n", __FUNCTION__, starget);
+       rport = starget_to_rport(starget);
+       if (rport) {
+               ri = *((struct mptfc_rport_info **)rport->dd_data);
+@@ -994,7 +993,8 @@ mptfc_SetFcPortPage1_defaults(MPT_ADAPTE
+       #define OFF_FLAGS (MPI_FCPORTPAGE1_FLAGS_VERBOSE_RESCAN_EVENTS)
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+typedef struct _BIG_SENSE_BUF {
-+      u8              data[MPT_SENSE_BUFFER_ALLOC];
-+} BIG_SENSE_BUF;
-+
-+
- /*
-  *  Other private/forward protos...
-  */
--static struct scsi_cmnd * mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
-+struct scsi_cmnd * mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
- static struct scsi_cmnd * mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i);
- static void   mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd);
- static int    SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *scmd);
-@@ -92,17 +99,10 @@ static int mptscsih_AddSGE(MPT_ADAPTER *
-                                SCSIIORequest_t *pReq, int req_idx);
- static void   mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);
- static void   mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);
--static int    mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd);
--static int    mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout );
--
--static int    mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout);
+       for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
+-              if ((rc = mptfc_GetFcPortPage1(ioc, ii)) < 0)
++              rc = mptfc_GetFcPortPage1(ioc, ii);
++              if (rc < 0)
+                       return rc;
+               pp1 = ioc->fc_data.fc_port_page1[ii].data;
+               if ((pp1->InitiatorDeviceTimeout == MPTFC_FW_DEVICE_TIMEOUT)
+@@ -1006,7 +1006,8 @@ mptfc_SetFcPortPage1_defaults(MPT_ADAPTE
+               pp1->InitiatorIoPendTimeout = MPTFC_FW_IO_PEND_TIMEOUT;
+               pp1->Flags &= ~OFF_FLAGS;
+               pp1->Flags |= ON_FLAGS;
+-              if ((rc = mptfc_WriteFcPortPage1(ioc, ii)) < 0)
++              rc = mptfc_WriteFcPortPage1(ioc, ii);
++              if (rc < 0)
+                       return rc;
+       }
+       return 0;
+@@ -1170,8 +1171,9 @@ mptfc_rescan_devices(struct work_struct 
+        * if cannot set defaults, something's really wrong, bail out
+        */
  
- int           mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
- int           mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
--
--int           mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
--static int    mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
--static void   mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice);
-+static void   mptscsih_synchronize_cache(struct scsi_device *sdev, MPT_SCSI_HOST *hd, VirtDevice *vdevice);
+-      if ((rc = mptfc_SetFcPortPage1_defaults(ioc)) < 0) {
+-              dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
++      rc = mptfc_SetFcPortPage1_defaults(ioc);
++      if (rc < 0) {
++              dfcprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "mptfc_rescan.%d: unable to set PP1 defaults, rc %d.\n",
+                   ioc->name, ioc->sh->host_no, rc));
+               return;
+@@ -1373,8 +1375,9 @@ mptfc_probe(struct pci_dev *pdev, const 
  
- void          mptscsih_remove(struct pci_dev *);
- void          mptscsih_shutdown(struct pci_dev *);
-@@ -111,81 +111,17 @@ int              mptscsih_suspend(struct pci_dev *p
- int           mptscsih_resume(struct pci_dev *pdev);
- #endif
+       /* initialize workqueue */
  
--#define SNS_LEN(scp)  SCSI_SENSE_BUFFERSIZE
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/**
-- *    mptscsih_add_sge - Place a simple SGE at address pAddr.
-- *    @pAddr: virtual address for SGE
-- *    @flagslength: SGE flags and data transfer length
-- *    @dma_addr: Physical address
-- *
-- *    This routine places a MPT request frame back on the MPT adapter's
-- *    FreeQ.
-- */
--static inline void
--mptscsih_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
--{
--      if (sizeof(dma_addr_t) == sizeof(u64)) {
--              SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
--              u32 tmp = dma_addr & 0xFFFFFFFF;
--
--              pSge->FlagsLength = cpu_to_le32(flagslength);
--              pSge->Address.Low = cpu_to_le32(tmp);
--              tmp = (u32) ((u64)dma_addr >> 32);
--              pSge->Address.High = cpu_to_le32(tmp);
--
--      } else {
--              SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
--              pSge->FlagsLength = cpu_to_le32(flagslength);
--              pSge->Address = cpu_to_le32(dma_addr);
--      }
--} /* mptscsih_add_sge() */
-+#define SNS_LEN(scp)  sizeof((scp)->sense_buffer)
+-      snprintf(ioc->fc_rescan_work_q_name, sizeof(ioc->fc_rescan_work_q_name), "mptfc_wq_%d",
+-              sh->host_no);
++      snprintf(ioc->fc_rescan_work_q_name,
++          sizeof(ioc->fc_rescan_work_q_name), "mptfc_wq_%d",
++          sh->host_no);
+       ioc->fc_rescan_work_q =
+               create_singlethread_workqueue(ioc->fc_rescan_work_q_name);
+       if (!ioc->fc_rescan_work_q)
+@@ -1462,10 +1465,10 @@ mptfc_ioc_reset(MPT_ADAPTER *ioc, int re
+       if ((ioc->bus_type != FC) || (!rc))
+               return rc;
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+-      switch(reset_phase) {
++      switch (reset_phase) {
+       case MPT_IOC_SETUP_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
+               spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
+               if (ioc->fc_rescan_work_q) {
+                       queue_work(ioc->fc_rescan_work_q,
+@@ -1475,11 +1478,11 @@ mptfc_ioc_reset(MPT_ADAPTER *ioc, int re
+               break;
+       case MPT_IOC_PRE_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
+               break;
+       case MPT_IOC_POST_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_POST_RESET\n",  ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_POST_RESET\n",  ioc->name, __func__));
+               spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
+               if (ioc->fc_rescan_work_q) {
+                       queue_work(ioc->fc_rescan_work_q,
+@@ -1493,11 +1496,12 @@ mptfc_ioc_reset(MPT_ADAPTER *ioc, int re
+       return 1;
+ }
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  /**
-- *    mptscsih_add_chain - Place a chain SGE at address pAddr.
-- *    @pAddr: virtual address for SGE
-- *    @next: nextChainOffset value (u32's)
-- *    @length: length of next SGL segment
-- *    @dma_addr: Physical address
-- *
-- *    This routine places a MPT request frame back on the MPT adapter's
-- *    FreeQ.
-- */
--static inline void
--mptscsih_add_chain(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
--{
--      if (sizeof(dma_addr_t) == sizeof(u64)) {
--              SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
--              u32 tmp = dma_addr & 0xFFFFFFFF;
--
--              pChain->Length = cpu_to_le16(length);
--              pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
--
--              pChain->NextChainOffset = next;
--
--              pChain->Address.Low = cpu_to_le32(tmp);
--              tmp = (u32) ((u64)dma_addr >> 32);
--              pChain->Address.High = cpu_to_le32(tmp);
--      } else {
--              SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
--              pChain->Length = cpu_to_le16(length);
--              pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
--              pChain->NextChainOffset = next;
--              pChain->Address = cpu_to_le32(dma_addr);
--      }
--} /* mptscsih_add_chain() */
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-  *    mptscsih_getFreeChainBuffer - Function to get a free chain
-  *    from the MPT_SCSI_HOST FreeChainQ.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-  *    @req_idx: Index of the SCSI IO request frame. (output)
+  *    mptfc_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer.
   *
-  *    return SUCCESS or FAILED
-- */
-+ **/
- static inline int
- mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
+  *    Returns 0 for success, non-zero for failure.
+- **/
++ */
+ static int __init
+ mptfc_init(void)
  {
-@@ -195,7 +131,7 @@ mptscsih_getFreeChainBuffer(MPT_ADAPTER 
-       int chain_idx;
+@@ -1529,11 +1533,12 @@ mptfc_init(void)
+       return error;
+ }
  
-       dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "getFreeChainBuffer called\n",
--          ioc->name));
-+                      ioc->name));
-       spin_lock_irqsave(&ioc->FreeQlock, flags);
-       if (!list_empty(&ioc->FreeChainQ)) {
-               int offset;
-@@ -206,14 +142,13 @@ mptscsih_getFreeChainBuffer(MPT_ADAPTER 
-               offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
-               chain_idx = offset / ioc->req_sz;
-               rc = SUCCESS;
--              dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                  "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
--                  ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
-+              dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
-+                      ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
-       } else {
-               rc = FAILED;
-               chain_idx = MPT_HOST_NO_CHAIN;
-               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n",
--                  ioc->name));
-+                      ioc->name));
-       }
-       spin_unlock_irqrestore(&ioc->FreeQlock, flags);
++/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+ /**
+  *    mptfc_remove - Remove fc infrastructure for devices
+  *    @pdev: Pointer to pci_dev structure
+  *
+- **/
++ */
+ static void __devexit
+ mptfc_remove(struct pci_dev *pdev)
+ {
+@@ -1543,8 +1548,6 @@ mptfc_remove(struct pci_dev *pdev)
+       unsigned long           flags;
+       int                     ii;
  
-@@ -222,7 +157,7 @@ mptscsih_getFreeChainBuffer(MPT_ADAPTER 
- } /* mptscsih_getFreeChainBuffer() */
+-      printk("%s -pdev=%p\n", __FUNCTION__, pdev);
+-
+       /* destroy workqueue */
+       if ((work_q=ioc->fc_rescan_work_q)) {
+               spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
+Index: linux-2.6.27/drivers/message/fusion/mptlan.c
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/mptlan.c
++++ linux-2.6.27/drivers/message/fusion/mptlan.c
+@@ -614,7 +614,7 @@ mpt_lan_send_turbo(struct net_device *de
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-+/**
-  *    mptscsih_AddSGE - Add a SGE (plus chain buffers) to the
-  *    SCSIIORequest_t Message Frame.
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -230,7 +165,7 @@ mptscsih_getFreeChainBuffer(MPT_ADAPTER 
-  *    @pReq: Pointer to SCSIIORequest_t structure
-  *
-  *    Returns ...
-- */
-+ **/
- static int
- mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
-               SCSIIORequest_t *pReq, int req_idx)
-@@ -281,10 +216,10 @@ mptscsih_AddSGE(MPT_ADAPTER *ioc, struct
-        */
+       dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, skb %p sent.\n",
+                       IOC_AND_NETDEV_NAMES_s_s(dev),
+-                      __FUNCTION__, sent));
++                      __func__, sent));
  
- nextSGEset:
--      numSgeSlots = ((frm_sz - sgeOffset) / (sizeof(u32) + sizeof(dma_addr_t)) );
-+      numSgeSlots = ((frm_sz - sgeOffset) / ioc->SGE_size );
-       numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;
+       priv->SendCtl[ctx].skb = NULL;
+       pci_unmap_single(mpt_dev->pcidev, priv->SendCtl[ctx].dma,
+@@ -680,7 +680,7 @@ mpt_lan_send_reply(struct net_device *de
  
--      sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | MPT_SGE_FLAGS_ADDRESSING | sgdir;
-+      sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | sgdir;
+               dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, skb %p sent.\n",
+                               IOC_AND_NETDEV_NAMES_s_s(dev),
+-                              __FUNCTION__, sent));
++                              __func__, sent));
  
-       /* Get first (num - 1) SG elements
-        * Skip any SG entries with a length of 0
-@@ -299,11 +234,11 @@ nextSGEset:
-               }
+               priv->SendCtl[ctx].skb = NULL;
+               pci_unmap_single(mpt_dev->pcidev, priv->SendCtl[ctx].dma,
+@@ -719,7 +719,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, s
+       u16 cur_naa = 0x1000;
  
-               v2 = sg_dma_address(sg);
--              mptscsih_add_sge(psge, sgflags | thisxfer, v2);
-+              ioc->add_sge(psge, sgflags | thisxfer, v2);
-               sg = sg_next(sg);       /* Get next SG element from the OS */
--              psge += (sizeof(u32) + sizeof(dma_addr_t));
--              sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
-+              psge += ioc->SGE_size;
-+              sgeOffset += ioc->SGE_size;
-               sg_done++;
-       }
-@@ -320,12 +255,8 @@ nextSGEset:
-               thisxfer = sg_dma_len(sg);
-               v2 = sg_dma_address(sg);
--              mptscsih_add_sge(psge, sgflags | thisxfer, v2);
--              /*
--              sg = sg_next(sg);
--              psge += (sizeof(u32) + sizeof(dma_addr_t));
--              */
--              sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
-+              ioc->add_sge(psge, sgflags | thisxfer, v2);
-+              sgeOffset += ioc->SGE_size;
-               sg_done++;
-               if (chainSge) {
-@@ -334,7 +265,7 @@ nextSGEset:
-                        * Update the chain element
-                        * Offset and Length fields.
-                        */
--                      mptscsih_add_chain((char *)chainSge, 0, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
-+                      ioc->add_chain((char *)chainSge, 0, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
-               } else {
-                       /* The current buffer is the original MF
-                        * and there is no Chain buffer.
-@@ -367,7 +298,7 @@ nextSGEset:
-                * set properly).
-                */
-               if (sg_done) {
--                      u32 *ptmp = (u32 *) (psge - (sizeof(u32) + sizeof(dma_addr_t)));
-+                      u32 *ptmp = (u32 *) (psge - ioc->SGE_size);
-                       sgflags = le32_to_cpu(*ptmp);
-                       sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT;
-                       *ptmp = cpu_to_le32(sgflags);
-@@ -381,8 +312,8 @@ nextSGEset:
-                        * Old chain element is now complete.
-                        */
-                       u8 nextChain = (u8) (sgeOffset >> 2);
--                      sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
--                      mptscsih_add_chain((char *)chainSge, nextChain, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
-+                      sgeOffset += ioc->SGE_size;
-+                      ioc->add_chain((char *)chainSge, nextChain, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
-               } else {
-                       /* The original MF buffer requires a chain buffer -
-                        * set the offset.
-@@ -461,7 +392,7 @@ mptscsih_issue_sep_command(MPT_ADAPTER *
+       dioprintk((KERN_INFO MYNAM ": %s called, skb_addr = %p\n",
+-                      __FUNCTION__, skb));
++                      __func__, skb));
  
-       if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
-               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: no msg frames!!\n",
--                  ioc->name,__func__));
-+                  ioc->name,__FUNCTION__));
-               return;
-       }
+       spin_lock_irqsave(&priv->txfidx_lock, flags);
+       if (priv->mpt_txfidx_tail < 0) {
+@@ -727,7 +727,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, s
+               spin_unlock_irqrestore(&priv->txfidx_lock, flags);
  
-@@ -592,14 +523,14 @@ mptscsih_info_scsiio(MPT_ADAPTER *ioc, s
+               printk (KERN_ERR "%s: no tx context available: %u\n",
+-                      __FUNCTION__, priv->mpt_txfidx_tail);
++                      __func__, priv->mpt_txfidx_tail);
+               return 1;
        }
  
-       scsi_print_command(sc);
--      printk(MYIOC_s_DEBUG_FMT "\tfw_channel = %d, fw_id = %d\n",
--          ioc->name, pScsiReply->Bus, pScsiReply->TargetID);
--      printk(MYIOC_s_DEBUG_FMT "\trequest_len = %d, underflow = %d, "
--          "resid = %d\n", ioc->name, scsi_bufflen(sc), sc->underflow,
--          scsi_get_resid(sc));
--      printk(MYIOC_s_DEBUG_FMT "\ttag = %d, transfer_count = %d, "
--          "sc->result = %08X\n", ioc->name, le16_to_cpu(pScsiReply->TaskTag),
-+      printk(MYIOC_s_DEBUG_FMT "\tfw_channel = %d, fw_id = %d, lun = %d\n",
-+          ioc->name, pScsiReply->Bus, pScsiReply->TargetID, sc->device->lun);
-+      printk(MYIOC_s_DEBUG_FMT "\trequest_len = %d, underflow = %d, resid = %d\n",
-+             ioc->name, scsi_bufflen(sc), sc->underflow, scsi_get_resid(sc));
-+      printk(MYIOC_s_DEBUG_FMT "\ttag = %d, transfer_count = %d, sc->result = %08X\n",
-+          ioc->name, le16_to_cpu(pScsiReply->TaskTag),
-           le32_to_cpu(pScsiReply->TransferCount), sc->result);
-+
-       printk(MYIOC_s_DEBUG_FMT "\tiocstatus = %s (0x%04x), "
-           "scsi_status = %s (0x%02x), scsi_state = (0x%02x)\n",
-           ioc->name, desc, ioc_status, desc1, pScsiReply->SCSIStatus,
-@@ -625,7 +556,7 @@ mptscsih_info_scsiio(MPT_ADAPTER *ioc, s
- #endif
+@@ -737,7 +737,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, s
+               spin_unlock_irqrestore(&priv->txfidx_lock, flags);
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-+/**
-  *    mptscsih_io_done - Main SCSI IO callback routine registered to
-  *    Fusion MPT (base) driver
-  *    @ioc: Pointer to MPT_ADAPTER structure
-@@ -638,7 +569,7 @@ mptscsih_info_scsiio(MPT_ADAPTER *ioc, s
-  *    load/init time via the mpt_register() API call.
-  *
-  *    Returns 1 indicating alloc'd request frame ptr should be freed.
-- */
-+ **/
- int
- mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
- {
-@@ -651,14 +582,15 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-       VirtTarget       *vtarget;
+               printk (KERN_ERR "%s: Unable to alloc request frame\n",
+-                      __FUNCTION__);
++                      __func__);
+               return 1;
+       }
  
-       hd = shost_priv(ioc->sh);
-+
-       req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
-       req_idx_MR = (mr != NULL) ?
-           le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx) : req_idx;
-       if ((req_idx != req_idx_MR) ||
--          (mf->u.frame.linkage.arg1 == 0xdeadbeaf)) {
--              printk(MYIOC_s_ERR_FMT "Received a mf that was already freed\n",
--                  ioc->name);
--              printk (MYIOC_s_ERR_FMT
-+          (le32_to_cpu(mf->u.frame.linkage.arg1) == 0xdeadbeaf)) {
-+              printk(MYIOC_s_WARN_FMT
-+                  "Received a mf that was already freed\n", ioc->name);
-+              printk (MYIOC_s_WARN_FMT
-                   "req_idx=%x req_idx_MR=%x mf=%p mr=%p sc=%p\n",
-                   ioc->name, req_idx, req_idx_MR, mf, mr,
-                   mptscsih_get_scsi_lookup(ioc, req_idx_MR));
-@@ -693,7 +625,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-       if((ioc->facts.MsgVersion >= MPI_VERSION_01_05) && pScsiReply){
-               dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                      "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n",
-+                      "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task_tag=%d)\n",
-                       ioc->name, mf, mr, sc, req_idx, pScsiReply->TaskTag));
-       }else{
-               dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-@@ -706,6 +638,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-               ;
-       } else {
-               u32      xfer_cnt;
-+              u32      difftransfer;
-               u16      status;
-               u8       scsi_state, scsi_status;
-               u32      log_info;
-@@ -716,6 +649,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-               xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);
-               scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
-               log_info = le32_to_cpu(pScsiReply->IOCLogInfo);
-+              vdevice = sc->device->hostdata;
+@@ -1213,7 +1213,7 @@ mpt_lan_post_receive_buckets(struct mpt_
  
-               /*
-                *  if we get a data underrun indication, yet no data was
-@@ -733,20 +667,9 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-               if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)
-                       mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);
+       dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, Start_buckets = %u, buckets_out = %u\n",
+                       IOC_AND_NETDEV_NAMES_s_s(dev),
+-                      __FUNCTION__, buckets, curr));
++                      __func__, buckets, curr));
  
--              /*
--               *  Look for + dump FCP ResponseInfo[]!
--               */
--              if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
--                  pScsiReply->ResponseInfo) {
--                      printk(MYIOC_s_NOTE_FMT "[%d:%d:%d:%d] "
--                      "FCP_ResponseInfo=%08xh\n", ioc->name,
--                      sc->device->host->host_no, sc->device->channel,
--                      sc->device->id, sc->device->lun,
--                      le32_to_cpu(pScsiReply->ResponseInfo));
--              }
--
-               switch(status) {
-               case MPI_IOCSTATUS_BUSY:                        /* 0x0002 */
-+              case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:      /* 0x0006 */
-                       /* CHECKME!
-                        * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)
-                        * But not: DID_BUS_BUSY lest one risk
-@@ -771,7 +694,6 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-                       if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)
-                               hd->sel_timeout[pScsiReq->TargetID]++;
--                      vdevice = sc->device->hostdata;
-                       if (!vdevice)
-                               break;
-                       vtarget = vdevice->vtarget;
-@@ -793,14 +715,11 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-                                       }
-                               }
-                       } else if (ioc->bus_type == FC) {
--                              /*
--                               * The FC IOC may kill a request for variety of
--                               * reasons, some of which may be recovered by a
--                               * retry, some which are unlikely to be
--                               * recovered. Return DID_ERROR instead of
--                               * DID_RESET to permit retry of the command,
--                               * just not an infinite number of them
--                               */
-+                              /* The FC IOC may kill a request for variety of reasons,
-+                              some of which may be recovered by a retry, some which
-+                              are unlikely to be recovered. Return DID_ERROR instead
-+                              of DID_RESET to permit retry of the command, just not
-+                              an infinite number of them */
-                               sc->result = DID_ERROR << 16;
+       max = (mpt_dev->req_sz - MPT_LAN_RECEIVE_POST_REQUEST_SIZE) /
+                       (MPT_LAN_TRANSACTION32_SIZE + sizeof(SGESimple64_t));
+@@ -1222,9 +1222,9 @@ mpt_lan_post_receive_buckets(struct mpt_
+               mf = mpt_get_msg_frame(LanCtx, mpt_dev);
+               if (mf == NULL) {
+                       printk (KERN_ERR "%s: Unable to alloc request frame\n",
+-                              __FUNCTION__);
++                              __func__);
+                       dioprintk((KERN_ERR "%s: %u buckets remaining\n",
+-                               __FUNCTION__, buckets));
++                               __func__, buckets));
+                       goto out;
+               }
+               pRecvReq = (LANReceivePostRequest_t *) mf;
+@@ -1249,7 +1249,7 @@ mpt_lan_post_receive_buckets(struct mpt_
+                       spin_lock_irqsave(&priv->rxfidx_lock, flags);
+                       if (priv->mpt_rxfidx_tail < 0) {
+                               printk (KERN_ERR "%s: Can't alloc context\n",
+-                                      __FUNCTION__);
++                                      __func__);
+                               spin_unlock_irqrestore(&priv->rxfidx_lock,
+                                                      flags);
                                break;
-                       }
-@@ -810,12 +729,16 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-                        */
-               case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:        /* 0x0048 */
--              case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:         /* 0x004C */
-                       /* Linux handles an unsolicited DID_RESET better
-                        * than an unsolicited DID_ABORT.
-                        */
-                       sc->result = DID_RESET << 16;
-+              case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:         /* 0x004C */
-+                      if ( ioc->bus_type == FC )
-+                              sc->result = DID_ERROR << 16;
-+                      else
-+                              sc->result = DID_RESET << 16;
-                       break;
-               case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:      /* 0x0049 */
-@@ -824,9 +747,6 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-                               sc->result=DID_SOFT_ERROR << 16;
-                       else /* Sufficient data transfer occurred */
-                               sc->result = (DID_OK << 16) | scsi_status;
--                      dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                          "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
--                          ioc->name, sc->result, sc->device->channel, sc->device->id));
-                       break;
+@@ -1272,7 +1272,7 @@ mpt_lan_post_receive_buckets(struct mpt_
+                               if (skb == NULL) {
+                                       printk (KERN_WARNING
+                                               MYNAM "/%s: Can't alloc skb\n",
+-                                              __FUNCTION__);
++                                              __func__);
+                                       priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
+                                       spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
+                                       break;
+@@ -1310,7 +1310,7 @@ mpt_lan_post_receive_buckets(struct mpt_
  
-               case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:          /* 0x0045 */
-@@ -835,11 +755,34 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-                        *  precedence!
-                        */
-                       sc->result = (DID_OK << 16) | scsi_status;
--                      if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
--                              /* Have already saved the status and sense data
-+
-+                      if (!(scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
-+
-+                              /*
-+                               * For an Errata on LSI53C1030
-+                               * When the length of request data
-+                               * and transfer data are different
-+                               * with result of command (READ or VERIFY),
-+                               * DID_SOFT_ERROR is set.
-                                */
--                              ;
--                      } else {
-+                              if (ioc->bus_type == SPI && vdevice &&
-+                                  vdevice->vtarget->type == TYPE_DISK) {
-+                                      if (pScsiReq->CDB[0] == READ_6  ||
-+                                          pScsiReq->CDB[0] == READ_10 ||
-+                                          pScsiReq->CDB[0] == READ_12 ||
-+                                          pScsiReq->CDB[0] == READ_16 ||
-+                                          pScsiReq->CDB[0] == VERIFY  ||
-+                                          pScsiReq->CDB[0] == VERIFY_16) {
-+                                              if (scsi_bufflen(sc) !=
-+                                                  xfer_cnt) {
-+                                                      sc->result = DID_SOFT_ERROR << 16;
-+                                                      printk(MYIOC_s_WARN_FMT "Errata"
-+                                                             "on LSI53C1030 occurred. sc->request_bufflen=0x%02x, "
-+                                                             "xfer_cnt=0x%02x\n", ioc->name, scsi_bufflen(sc), xfer_cnt);
-+                                              }
-+                                      }
-+                              }
-+
-                               if (xfer_cnt < sc->underflow) {
-                                       if (scsi_status == SAM_STAT_BUSY)
-                                               sc->result = SAM_STAT_BUSY;
-@@ -848,7 +791,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-                               }
-                               if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {
-                                       /* What to do?
--                                      */
-+                                      */
-                                       sc->result = DID_SOFT_ERROR << 16;
-                               }
-                               else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
-@@ -857,13 +800,6 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-                               }
-                       }
+               if (pSimple == NULL) {
+ /**/                  printk (KERN_WARNING MYNAM "/%s: No buckets posted\n",
+-/**/                          __FUNCTION__);
++/**/                          __func__);
+                       mpt_free_msg_frame(mpt_dev, mf);
+                       goto out;
+               }
+@@ -1334,9 +1334,9 @@ mpt_lan_post_receive_buckets(struct mpt_
  
--
--                      dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                          "  sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
--                          ioc->name, sc->underflow));
--                      dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                          "  ActBytesXferd=%02xh\n", ioc->name, xfer_cnt));
--
-                       /* Report Queue Full
-                        */
-                       if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
-@@ -879,6 +815,44 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-                       if (scsi_state == 0) {
-                               ;
-                       } else if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
-+
-+                              /*
-+                               * For potential trouble on LSI53C1030. (date:2007.xx.)
-+                               * It is checked whether the length of request data is equal to
-+                               * the length of transfer and residual.
-+                               * MEDIUM_ERROR is set by incorrect data.
-+                               */
-+                              if (ioc->bus_type == SPI && vdevice &&
-+                                  vdevice->vtarget->type == TYPE_DISK) {
-+                                      if (sc->sense_buffer[2] & 0x20) {
-+                                              difftransfer =
-+                                                      sc->sense_buffer[3] << 24 |
-+                                                      sc->sense_buffer[4] << 16 |
-+                                                      sc->sense_buffer[5] << 8 |
-+                                                      sc->sense_buffer[6];
-+                                              if ((sc->sense_buffer[3] & 0x80) == 0x80) {
-+                                                      if (scsi_bufflen(sc) != xfer_cnt) {
-+                                                              sc->sense_buffer[2] = MEDIUM_ERROR;
-+                                                              sc->sense_buffer[12] = 0xff;
-+                                                              sc->sense_buffer[13] = 0xff;
-+                                                              printk(MYIOC_s_WARN_FMT "Errata on "
-+                                                                     "LSI53C1030 occurred. sc->request_bufflen=0x%02x,"
-+                                                                     "xfer_cnt=0x%02x\n", ioc->name, scsi_bufflen(sc), xfer_cnt);
-+                                                      }
-+                                              } else {
-+                                                      if (scsi_bufflen(sc) != xfer_cnt + difftransfer) {
-+                                                              sc->sense_buffer[2] = MEDIUM_ERROR;
-+                                                              sc->sense_buffer[12] = 0xff;
-+                                                              sc->sense_buffer[13] = 0xff;
-+                                                              printk(MYIOC_s_WARN_FMT "Errata on "
-+                                                                     "LSI53C1030 occurred. sc->request_bufflen=0x%02x,"
-+                                                                     " xfer_cnt=0x%02x, difftransfer=0x%02x\n",
-+                                                                     ioc->name, scsi_bufflen(sc) , xfer_cnt, difftransfer);
-+                                                      }
-+                                              }
-+                                      }
-+                              }
-+
-                               /*
-                                * If running against circa 200003dd 909 MPT f/w,
-                                * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL
-@@ -890,7 +864,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
+ out:
+       dioprintk((KERN_INFO MYNAM "/%s: End_buckets = %u, priv->buckets_out = %u\n",
+-                __FUNCTION__, buckets, atomic_read(&priv->buckets_out)));
++                __func__, buckets, atomic_read(&priv->buckets_out)));
+       dioprintk((KERN_INFO MYNAM "/%s: Posted %u buckets and received %u back\n",
+-      __FUNCTION__, priv->total_posted, priv->total_received));
++      __func__, priv->total_posted, priv->total_received));
  
-                       }
-                       else if (scsi_state &
--                               (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
-+                               (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
-                          ) {
-                               /*
-                                * What to do?
-@@ -926,7 +900,6 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-               case MPI_IOCSTATUS_INVALID_SGL:                 /* 0x0003 */
-               case MPI_IOCSTATUS_INTERNAL_ERROR:              /* 0x0004 */
-               case MPI_IOCSTATUS_RESERVED:                    /* 0x0005 */
--              case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:      /* 0x0006 */
-               case MPI_IOCSTATUS_INVALID_FIELD:               /* 0x0007 */
-               case MPI_IOCSTATUS_INVALID_STATE:               /* 0x0008 */
-               case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR:          /* 0x0046 */
-@@ -957,7 +930,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-       return 1;
+       clear_bit(0, &priv->post_buckets_active);
  }
--/*
-+/**
-  *    mptscsih_flush_running_cmds - For each command found, search
-  *            Scsi_Host instance taskQ and reply to OS.
-  *            Called only if recovering from a FW reload.
-@@ -966,7 +939,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
-  *    Returns: None.
-  *
-  *    Must be called while new I/Os are being queued.
-- */
-+ **/
+Index: linux-2.6.27/drivers/message/fusion/mptsas.c
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/mptsas.c
++++ linux-2.6.27/drivers/message/fusion/mptsas.c
+@@ -117,19 +117,23 @@ static u8        mptsasInternalCtx = MPT_MAX_PR
+ static u8     mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS;
+ static u8     mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS;
+-static inline void mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
+-static struct mptsas_phyinfo * mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc,
+-      u64 sas_address);
+-static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
+-      u32 form, u32 form_specific);
+-static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
+-              u32 form, u32 form_specific);
+-
+-static int mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info);
+-static void mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info);
+-static void mptsas_expander_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info);
+-static int mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
+-              u32 form, u32 form_specific);
++static inline void mptsas_set_rphy(MPT_ADAPTER *ioc,
++    struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
++static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address(
++    MPT_ADAPTER *ioc, u64 sas_address);
++static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc,
++    struct mptsas_devinfo *device_info, u32 form, u32 form_specific);
++static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc,
++    struct mptsas_enclosure *enclosure,       u32 form, u32 form_specific);
++
++static int mptsas_add_end_device(MPT_ADAPTER *ioc,
++    struct mptsas_phyinfo *phy_info);
++static void mptsas_del_end_device(MPT_ADAPTER *ioc,
++    struct mptsas_phyinfo *phy_info);
++static void mptsas_expander_delete(MPT_ADAPTER *ioc,
++    struct mptsas_portinfo *port_info);
++static int mptsas_sas_expander_pg0(MPT_ADAPTER *ioc,
++    struct mptsas_portinfo *port_info, u32 form, u32 form_specific);
+ static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc);
+ static void mptsas_not_responding_devices(MPT_ADAPTER *ioc);
+@@ -323,7 +327,7 @@ mptsas_add_fw_event(MPT_ADAPTER *ioc, st
+       list_add_tail(&fw_event->list, &ioc->fw_event_list);
+       INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
+       devtprintk(ioc, printk(MYIOC_s_INFO_FMT "%s: add (fw_event=0x%p)\n",
+-          ioc->name,__FUNCTION__, fw_event));
++          ioc->name, __func__, fw_event));
+       queue_delayed_work(ioc->fw_event_q, &fw_event->work,
+           msecs_to_jiffies(delay));
+       spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
+@@ -337,7 +341,7 @@ mptsas_requeue_fw_event(MPT_ADAPTER *ioc
+       unsigned long flags;
+       spin_lock_irqsave(&ioc->fw_event_lock, flags);
+       devtprintk(ioc, printk(MYIOC_s_INFO_FMT "%s: reschedule task "
+-          "(fw_event=0x%p)\n", ioc->name,__FUNCTION__, fw_event));
++          "(fw_event=0x%p)\n", ioc->name, __func__, fw_event));
+       fw_event->retries++;
+       queue_delayed_work(ioc->fw_event_q, &fw_event->work,
+           msecs_to_jiffies(delay));
+@@ -352,13 +356,14 @@ mptsas_free_fw_event(MPT_ADAPTER *ioc, s
+       spin_lock_irqsave(&ioc->fw_event_lock, flags);
+       devtprintk(ioc, printk(MYIOC_s_INFO_FMT "%s: kfree (fw_event=0x%p)\n",
+-          ioc->name,__FUNCTION__, fw_event));
++          ioc->name, __func__, fw_event));
+       list_del(&fw_event->list);
+       kfree(fw_event);
+       spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
+ }
+-/* walk the firmware event queue, and either stop or wait for outstanding events to complete */
++/* walk the firmware event queue, and either stop or wait for
++ * outstanding events to complete */
  static void
- mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
+ mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
+ {
+@@ -373,7 +378,7 @@ mptsas_cleanup_fw_event_q(MPT_ADAPTER *i
+                   &hd->target_reset_list, list) {
+                       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                           "%s: removing target reset for id=%d\n",
+-                          ioc->name, __FUNCTION__,
++                          ioc->name, __func__,
+                          target_reset_list->sas_event_data.TargetID));
+                       list_del(&target_reset_list->list);
+                       kfree(target_reset_list);
+@@ -433,7 +438,7 @@ rphy_to_ioc(struct sas_rphy *rphy)
+ static struct mptsas_portinfo *
+ mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
  {
-@@ -992,14 +965,14 @@ mptscsih_flush_running_cmds(MPT_SCSI_HOS
-               scsi_dma_unmap(sc);
-               sc->result = DID_RESET << 16;
-               sc->host_scribble = NULL;
--              sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT
--                  "completing cmds: fw_channel %d, fw_id %d, sc=%p,"
--                  " mf = %p, idx=%x\n", ioc->name, channel, id, sc, mf, ii);
-+              dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT
-+                  "completing cmds: fw_channel %d, fw_id %d, sc=%p, mf = %p, "
-+                  "idx=%x\n", ioc->name, channel, id, sc, mf, ii));
-               sc->scsi_done(sc);
+-      struct mptsas_portinfo *port_info, *rc=NULL;
++      struct mptsas_portinfo *port_info, *rc = NULL;
+       int i;
+       if (sas_address >= ioc->hba_port_sas_addr &&
+@@ -523,7 +528,7 @@ mptsas_port_delete(MPT_ADAPTER *ioc, str
+       phy_info = port_info->phy_info;
+       dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
+-          "bitmask=0x%016llX\n", ioc->name, __FUNCTION__, port_details,
++          "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
+           port_details->num_phys, (unsigned long long)
+           port_details->phy_bitmask));
+@@ -659,7 +664,7 @@ mptsas_add_device_component(MPT_ADAPTER 
+       /*
+        * Delete all matching devices out of the list
+        */
+-      down(&ioc->sas_device_info_mutex);
++      mutex_lock(&ioc->sas_device_info_mutex);
+       list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
+           list) {
+               if (!sas_info->is_logical_volume &&
+@@ -700,7 +705,7 @@ mptsas_add_device_component(MPT_ADAPTER 
        }
+  out:
+-      up(&ioc->sas_device_info_mutex);
++      mutex_unlock(&ioc->sas_device_info_mutex);
+       return;
  }
  
--/*
-+/**
-  *    mptscsih_search_running_cmds - Delete any commands associated
-  *            with the specified target and lun. Function called only
-  *            when a lun is disable by mid-layer.
-@@ -1012,15 +985,15 @@ mptscsih_flush_running_cmds(MPT_SCSI_HOS
-  *    Returns: None.
+@@ -745,7 +750,8 @@ mptsas_add_device_component_by_fw(MPT_AD
   *
-  *    Called from slave_destroy.
-- */
-+ **/
+  **/
  static void
- mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
+-mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc, struct scsi_target *starget)
++mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc,
++    struct scsi_target *starget)
  {
-       SCSIIORequest_t *mf = NULL;
-       int              ii;
-       struct scsi_cmnd *sc;
--      struct scsi_lun  lun;
--      MPT_ADAPTER *ioc = hd->ioc;
-+      struct scsi_lun lun;
-+      MPT_ADAPTER     *ioc = hd->ioc;
-       unsigned long   flags;
-       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-@@ -1030,8 +1003,11 @@ mptscsih_search_running_cmds(MPT_SCSI_HO
-                       mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
-                       if (mf == NULL)
-                               continue;
--                      /* If the device is a hidden raid component, then its
--                       * expected that the mf->function will be RAID_SCSI_IO
-+
-+                      /*
-+                       * If the device is a hidden raid component,
-+                       * then its expected that
-+                       * the function would be raid scsi io
-                        */
-                       if (vdevice->vtarget->tflags &
-                           MPT_TARGET_FLAGS_RAID_COMPONENT && mf->Function !=
-@@ -1053,9 +1029,11 @@ mptscsih_search_running_cmds(MPT_SCSI_HO
-                       scsi_dma_unmap(sc);
-                       sc->host_scribble = NULL;
-                       sc->result = DID_NO_CONNECT << 16;
--                      sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT "completing cmds: fw_channel %d,"
--                         "fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name, vdevice->vtarget->channel,
--                         vdevice->vtarget->id, sc, mf, ii);
-+                      dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device,
-+                         MYIOC_s_FMT "completing cmds: fw_channel %d, "
-+                         "fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name,
-+                         vdevice->vtarget->channel, vdevice->vtarget->id,
-+                         sc, mf, ii));
-                       sc->scsi_done(sc);
-                       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
-               }
-@@ -1067,7 +1045,7 @@ mptscsih_search_running_cmds(MPT_SCSI_HO
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+       CONFIGPARMS                     cfg;
+       ConfigPageHeader_t              hdr;
+@@ -790,14 +796,14 @@ mptsas_add_device_component_starget_ir(M
+        */
+       for (i = 0; i < buffer->NumPhysDisks; i++) {
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-+/**
-  *    mptscsih_report_queue_full - Report QUEUE_FULL status returned
-  *    from a SCSI target device.
-  *    @sc: Pointer to scsi_cmnd structure
-@@ -1077,12 +1055,12 @@ mptscsih_search_running_cmds(MPT_SCSI_HO
-  *    This routine periodically reports QUEUE_FULL status returned from a
-  *    SCSI target device.  It reports this to the console via kernel
-  *    printk() API call, not more than once every 10 seconds.
-- */
-+ **/
- static void
- mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)
- {
-       long time = jiffies;
--      MPT_SCSI_HOST           *hd;
-+      MPT_SCSI_HOST   *hd;
-       MPT_ADAPTER     *ioc;
+-              if(mpt_raid_phys_disk_pg0(ioc,
++              if (mpt_raid_phys_disk_pg0(ioc,
+                   buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
+                       continue;
  
-       if (sc->device == NULL)
-@@ -1100,12 +1078,12 @@ mptscsih_report_queue_full(struct scsi_c
- }
+               mptsas_add_device_component_by_fw(ioc, phys_disk.PhysDiskBus,
+                   phys_disk.PhysDiskID);
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-+/**
-  *    mptscsih_remove - Removed scsi devices
-  *    @pdev: Pointer to pci_dev structure
-  *
-  *
-- */
-+ **/
- void
- mptscsih_remove(struct pci_dev *pdev)
- {
-@@ -1151,10 +1129,10 @@ mptscsih_remove(struct pci_dev *pdev)
- }
+-              down(&ioc->sas_device_info_mutex);
++              mutex_lock(&ioc->sas_device_info_mutex);
+               list_for_each_entry(sas_info, &ioc->sas_device_info_list,
+                   list) {
+                       if (!sas_info->is_logical_volume &&
+@@ -807,13 +813,13 @@ mptsas_add_device_component_starget_ir(M
+                               sas_info->volume_id = starget->id;
+                       }
+               }
+-              up(&ioc->sas_device_info_mutex);
++              mutex_unlock(&ioc->sas_device_info_mutex);
+       }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-+/**
-  *    mptscsih_shutdown - reboot notifier
-  *
-- */
-+ **/
- void
- mptscsih_shutdown(struct pci_dev *pdev)
- {
-@@ -1162,11 +1140,11 @@ mptscsih_shutdown(struct pci_dev *pdev)
+       /*
+        * Delete all matching devices out of the list
+        */
+-      down(&ioc->sas_device_info_mutex);
++      mutex_lock(&ioc->sas_device_info_mutex);
+       list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
+           list) {
+               if (sas_info->is_logical_volume && sas_info->fw.id ==
+@@ -832,7 +838,7 @@ mptsas_add_device_component_starget_ir(M
+               INIT_LIST_HEAD(&sas_info->list);
+               list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
+       }
+-      up(&ioc->sas_device_info_mutex);
++      mutex_unlock(&ioc->sas_device_info_mutex);
  
- #ifdef CONFIG_PM
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-+/**
-  *    mptscsih_suspend - Fusion MPT scsi driver suspend routine.
-  *
+  out:
+       if (buffer)
+@@ -847,7 +853,8 @@ mptsas_add_device_component_starget_ir(M
   *
-- */
-+ **/
- int
- mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
+  **/
+ static void
+-mptsas_add_device_component_starget(MPT_ADAPTER *ioc, struct scsi_target *starget)
++mptsas_add_device_component_starget(MPT_ADAPTER *ioc,
++    struct scsi_target *starget)
  {
-@@ -1179,11 +1157,11 @@ mptscsih_suspend(struct pci_dev *pdev, p
+       VirtTarget              *vtarget;
+       struct sas_rphy         *rphy;
+@@ -906,13 +913,13 @@ mptsas_del_device_components(MPT_ADAPTER
+ {
+       struct sas_device_info  *sas_info, *next;
+-      down(&ioc->sas_device_info_mutex);
++      mutex_lock(&ioc->sas_device_info_mutex);
+       list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
+               list) {
+               list_del(&sas_info->list);
+               kfree(sas_info);
+       }
+-      up(&ioc->sas_device_info_mutex);
++      mutex_unlock(&ioc->sas_device_info_mutex);
  }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-+/**
-  *    mptscsih_resume - Fusion MPT scsi driver resume routine.
-  *
-  *
-- */
-+ **/
- int
- mptscsih_resume(struct pci_dev *pdev)
- {
-@@ -1205,7 +1183,7 @@ mptscsih_resume(struct pci_dev *pdev)
-  *    (linux scsi_host_template.info routine)
-  *
-  *    Returns pointer to buffer where information was written.
-- */
-+ **/
- const char *
- mptscsih_info(struct Scsi_Host *SChost)
- {
-@@ -1338,7 +1316,7 @@ mptscsih_proc_info(struct Scsi_Host *hos
-  *    from a linux scsi_cmnd request and send it to the IOC.
-  *
-  *    Returns 0. (rtn value discarded by linux scsi mid-layer)
-- */
-+ **/
- int
- mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
+ /**
+@@ -926,7 +933,7 @@ mptsas_del_device_components(MPT_ADAPTER
+ static void
+ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
  {
-@@ -1346,7 +1324,6 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, v
-       MPT_FRAME_HDR           *mf;
-       SCSIIORequest_t         *pScsiReq;
-       VirtDevice              *vdevice = SCpnt->device->hostdata;
--      int      lun;
-       u32      datalen;
-       u32      scsictl;
-       u32      scsidir;
-@@ -1357,24 +1334,20 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, v
-       hd = shost_priv(SCpnt->device->host);
-       ioc = hd->ioc;
--      lun = SCpnt->device->lun;
-       SCpnt->scsi_done = done;
-       dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "qcmd: SCpnt=%p, done()=%p\n",
-               ioc->name, SCpnt, done));
--      if (hd->resetPending) {
--              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "qcmd: SCpnt=%p timeout + 60HZ\n",
--                      ioc->name, SCpnt));
-+      if (ioc->taskmgmt_quiesce_io)
-               return SCSI_MLQUEUE_HOST_BUSY;
--      }
+-      struct mptsas_portinfo_details * port_details;
++      struct mptsas_portinfo_details *port_details;
+       struct mptsas_phyinfo *phy_info, *phy_info_cmp;
+       u64     sas_address;
+       int     i, j;
+@@ -949,9 +956,9 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc
+                */
+               dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                       "%s: [%p]: deleting phy = %d\n",
+-                      ioc->name, __FUNCTION__, port_details, i));
++                      ioc->name, __func__, port_details, i));
+               port_details->num_phys--;
+-              port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
++              port_details->phy_bitmask &= ~(1 << phy_info->phy_id);
+               memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
+               devtprintk(ioc, dev_printk(KERN_DEBUG, &phy_info->phy->dev,
+                   MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name,
+@@ -966,8 +973,9 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc
+       phy_info = port_info->phy_info;
+       for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
+               sas_address = phy_info->attached.sas_address;
+-              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
+-                  ioc->name, i, (unsigned long long)sas_address));
++              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "phy_id=%d sas_address=0x%018llX\n",
++                      ioc->name, i, (unsigned long long)sas_address));
+               if (!sas_address)
+                       continue;
+               port_details = phy_info->port_details;
+@@ -981,13 +989,14 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc
+                               goto out;
+                       port_details->num_phys = 1;
+                       port_details->port_info = port_info;
+-                      if (phy_info->phy_id < 64 )
++                      if (phy_info->phy_id < 64)
+                               port_details->phy_bitmask |=
+                                   (1 << phy_info->phy_id);
+-                      phy_info->sas_port_add_phy=1;
+-                      dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
+-                          "phy_id=%d sas_address=0x%018llX\n", ioc->name, i,
+-                          (unsigned long long) sas_address));
++                      phy_info->sas_port_add_phy = 1;
++                      dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                              "\t\tForming port\n\t\t"
++                              "phy_id=%d sas_address=0x%018llX\n", ioc->name,
++                              i, (unsigned long long) sas_address));
+                       phy_info->port_details = port_details;
+               }
  
-       /*
-        *  Put together a MPT SCSI request...
-        */
-       if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
-               dprintk(ioc, printk(MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
--                              ioc->name));
-+                      ioc->name));
-               return SCSI_MLQUEUE_HOST_BUSY;
+@@ -1000,7 +1009,7 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc
+                               continue;
+                       if (sas_address != phy_info_cmp->attached.sas_address)
+                               continue;
+-                      if (phy_info_cmp->port_details == port_details )
++                      if (phy_info_cmp->port_details == port_details)
+                               continue;
+                       dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                           "\t\tphy_id=%d sas_address=0x%018llX\n",
+@@ -1018,12 +1027,12 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc
+                               if (!phy_info_cmp->port_details->num_phys)
+                                       kfree(phy_info_cmp->port_details);
+                       } else
+-                              phy_info_cmp->sas_port_add_phy=1;
++                              phy_info_cmp->sas_port_add_phy = 1;
+                       /*
+                        * Adding a phy to a port
+                        */
+                       phy_info_cmp->port_details = port_details;
+-                      if (phy_info_cmp->phy_id < 64 )
++                      if (phy_info_cmp->phy_id < 64)
+                               port_details->phy_bitmask |=
+                               (1 << phy_info_cmp->phy_id);
+                       port_details->num_phys++;
+@@ -1038,11 +1047,12 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc
+                       continue;
+               dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "%s: [%p]: phy_id=%02d num_phys=%02d "
+-                  "bitmask=0x%016llX\n", ioc->name, __FUNCTION__,
++                  "bitmask=0x%016llX\n", ioc->name, __func__,
+                   port_details, i, port_details->num_phys,
+                   (unsigned long long)port_details->phy_bitmask));
+-              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
+-                  ioc->name, port_details->port, port_details->rphy));
++              dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "\t\tport = %p rphy=%p\n",
++                      ioc->name, port_details->port, port_details->rphy));
+       }
+       dsaswideprintk(ioc, printk("\n"));
+       mutex_unlock(&ioc->sas_topology_mutex);
+@@ -1089,7 +1099,7 @@ mptsas_queue_device_delete(MPT_ADAPTER *
+       fw_event = kzalloc(sz, GFP_ATOMIC);
+       if (!fw_event) {
+               printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
+-                  ioc->name, __FUNCTION__, __LINE__);
++                  ioc->name, __func__, __LINE__);
+               return;
        }
+       memcpy(fw_event->event_data, sas_event_data,
+@@ -1109,7 +1119,7 @@ mptsas_queue_rescan(MPT_ADAPTER *ioc)
+       fw_event = kzalloc(sz, GFP_ATOMIC);
+       if (!fw_event) {
+               printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
+-                  ioc->name, __FUNCTION__, __LINE__);
++                  ioc->name, __func__, __LINE__);
+               return;
+       }
+       fw_event->event = -1;
+@@ -1139,8 +1149,9 @@ mptsas_target_reset(MPT_ADAPTER *ioc, u8
+               return 0;
  
-@@ -1422,7 +1395,7 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, v
-       pScsiReq->CDBLength = SCpnt->cmd_len;
-       pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
-       pScsiReq->Reserved = 0;
--      pScsiReq->MsgFlags = mpt_msg_flags();
-+      pScsiReq->MsgFlags = mpt_msg_flags(ioc);
-       int_to_scsilun(SCpnt->device->lun, (struct scsi_lun *)pScsiReq->LUN);
-       pScsiReq->Control = cpu_to_le32(scsictl);
+       if ((mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc)) == NULL) {
+-              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames @%d!!\n",
+-                  ioc->name,__FUNCTION__, __LINE__));
++              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
++                      "%s, no msg frames @%d!!\n",
++                      ioc->name, __func__, __LINE__));
+               goto out_fail;
+       }
  
-@@ -1448,7 +1421,7 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, v
+@@ -1150,7 +1161,7 @@ mptsas_target_reset(MPT_ADAPTER *ioc, u8
+       /* Format the Request
         */
-       if (datalen == 0) {
-               /* Add a NULL SGE */
--              mptscsih_add_sge((char *)&pScsiReq->SGL, MPT_SGE_FLAGS_SSIMPLE_READ | 0,
-+              ioc->add_sge((char *)&pScsiReq->SGL, MPT_SGE_FLAGS_SSIMPLE_READ | 0,
-                       (dma_addr_t) -1);
-       } else {
-               /* Add a 32 or 64 bit SGE */
-@@ -1527,239 +1500,454 @@ mptscsih_freeChainBuffers(MPT_ADAPTER *i
-  */
+       pScsiTm = (SCSITaskMgmt_t *) mf;
+-      memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
++      memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
+       pScsiTm->TargetID = id;
+       pScsiTm->Bus = channel;
+       pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
+@@ -1201,8 +1212,9 @@ mptsas_target_reset_queue(MPT_ADAPTER *i
+       target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event),
+           GFP_ATOMIC);
+       if (!target_reset_list) {
+-              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n",
+-                  ioc->name,__FUNCTION__, __LINE__));
++              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
++                      "%s, failed to allocate mem @%d..!!\n",
++                      ioc->name, __func__, __LINE__));
+               return;
+       }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/**
-- *    mptscsih_TMHandler - Generic handler for SCSI Task Management.
-- *    @hd: Pointer to MPT SCSI HOST structure
-- *    @type: Task Management type
-- *    @channel: channel number for task management
-- *    @id: Logical Target ID for reset (if appropriate)
-- *    @lun: Logical Unit for reset (if appropriate)
-- *    @ctx2abort: Context for the task to be aborted (if appropriate)
-- *    @timeout: timeout for task management control
-- *
-- *    Fall through to mpt_HardResetHandler if: not operational, too many
-- *    failed TM requests or handshake failure.
-- *
-- *    Remark: Currently invoked from a non-interrupt thread (_bh).
-- *
-- *    Note: With old EH code, at most 1 SCSI TaskMgmt function per IOC
-- *    will be active.
-- *
-- *    Returns 0 for SUCCESS, or %FAILED.
-- **/
--int
--mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout)
--{
--      MPT_ADAPTER     *ioc;
--      int              rc = -1;
--      u32              ioc_raw_state;
--      unsigned long    flags;
--
--      ioc = hd->ioc;
--      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler Entered!\n", ioc->name));
--
--      // SJR - CHECKME - Can we avoid this here?
--      // (mpt_HardResetHandler has this check...)
--      spin_lock_irqsave(&ioc->diagLock, flags);
--      if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)) {
--              spin_unlock_irqrestore(&ioc->diagLock, flags);
--              return FAILED;
--      }
--      spin_unlock_irqrestore(&ioc->diagLock, flags);
--
--      /*  Wait a fixed amount of time for the TM pending flag to be cleared.
--       *  If we time out and not bus reset, then we return a FAILED status
--       *  to the caller.
--       *  The call to mptscsih_tm_pending_wait() will set the pending flag
--       *  if we are
--       *  successful. Otherwise, reload the FW.
--       */
--      if (mptscsih_tm_pending_wait(hd) == FAILED) {
--              if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
--                      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler abort: "
--                         "Timed out waiting for last TM (%d) to complete! \n",
--                         ioc->name, hd->tmPending));
--                      return FAILED;
--              } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) {
--                      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler target "
--                              "reset: Timed out waiting for last TM (%d) "
--                              "to complete! \n", ioc->name,
--                              hd->tmPending));
--                      return FAILED;
--              } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
--                      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler bus reset: "
--                         "Timed out waiting for last TM (%d) to complete! \n",
--                        ioc->name, hd->tmPending));
--                      return FAILED;
--              }
--      } else {
--              spin_lock_irqsave(&ioc->FreeQlock, flags);
--              hd->tmPending |=  (1 << type);
--              spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--      }
--
--      ioc_raw_state = mpt_GetIocState(ioc, 0);
--
--      if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
--              printk(MYIOC_s_WARN_FMT
--                      "TM Handler for type=%x: IOC Not operational (0x%x)!\n",
--                      ioc->name, type, ioc_raw_state);
--              printk(MYIOC_s_WARN_FMT " Issuing HardReset!!\n", ioc->name);
--              if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
--                      printk(MYIOC_s_WARN_FMT "TMHandler: HardReset "
--                          "FAILED!!\n", ioc->name);
--              return FAILED;
--      }
--
--      if (ioc_raw_state & MPI_DOORBELL_ACTIVE) {
--              printk(MYIOC_s_WARN_FMT
--                      "TM Handler for type=%x: ioc_state: "
--                      "DOORBELL_ACTIVE (0x%x)!\n",
--                      ioc->name, type, ioc_raw_state);
--              return FAILED;
--      }
--
--      /* Isse the Task Mgmt request.
--       */
--      if (hd->hard_resets < -1)
--              hd->hard_resets++;
--
--      rc = mptscsih_IssueTaskMgmt(hd, type, channel, id, lun,
--          ctx2abort, timeout);
--      if (rc)
--              printk(MYIOC_s_INFO_FMT "Issue of TaskMgmt failed!\n",
--                     ioc->name);
--      else
--              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issue of TaskMgmt Successful!\n",
--                         ioc->name));
--
--      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                      "TMHandler rc = %d!\n", ioc->name, rc));
--
--      return rc;
--}
--
--
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/**
-- *    mptscsih_IssueTaskMgmt - Generic send Task Management function.
-- *    @hd: Pointer to MPT_SCSI_HOST structure
-- *    @type: Task Management type
-- *    @channel: channel number for task management
-- *    @id: Logical Target ID for reset (if appropriate)
-- *    @lun: Logical Unit for reset (if appropriate)
-- *    @ctx2abort: Context for the task to be aborted (if appropriate)
-- *    @timeout: timeout for task management control
-- *
-- *    Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
-- *    or a non-interrupt thread.  In the former, must not call schedule().
-- *
-- *    Not all fields are meaningfull for all task types.
-- *
-- *    Returns 0 for SUCCESS, or FAILED.
-- *
-- **/
-+
- static int
--mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout)
-+mptscsih_scandv_bus_reset(MPT_ADAPTER *ioc)
+@@ -1227,7 +1239,7 @@ static int
+ mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  {
-       MPT_FRAME_HDR   *mf;
-       SCSITaskMgmt_t  *pScsiTm;
-+      SCSITaskMgmtReply_t *pScsiTmReply;
-       int              ii;
-       int              retval;
--      MPT_ADAPTER     *ioc = hd->ioc;
-+      unsigned long    timeout;
-+      unsigned long    time_count;
-+      u16              iocstatus;
-+
-+      mutex_lock(&ioc->taskmgmt_cmds.mutex);
-+      if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
-+              mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+              return -EPERM;
-+      }
--      /* Return Fail to calling function if no message frames available.
-+      /* Send request
+       MPT_SCSI_HOST   *hd = shost_priv(ioc->sh);
+-        struct list_head *head = &hd->target_reset_list;
++      struct list_head *head = &hd->target_reset_list;
+       struct mptsas_target_reset_event        *target_reset_list;
+       u8              id, channel;
+       SCSITaskMgmtReply_t *pScsiTmReply;
+@@ -1300,7 +1312,8 @@ mptsas_taskmgmt_complete(MPT_ADAPTER *io
         */
-       if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
--              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n",
-+              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt, no msg frames!!\n",
-                               ioc->name));
--              return FAILED;
-+              mpt_clear_taskmgmt_in_progress_flag(ioc);
-+              retval = -ENOMEM;
-+              goto out;
-       }
--      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt request @ %p\n",
--                      ioc->name, mf));
+       list_del(&target_reset_list->list);
+       if ((mptsas_find_vtarget(ioc, channel, id)) && !ioc->fw_events_off)
+-              mptsas_queue_device_delete(ioc, &target_reset_list->sas_event_data);
++              mptsas_queue_device_delete(ioc,
++                  &target_reset_list->sas_event_data);
  
--      /* Format the Request
--       */
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
-+              ioc->name, mf));
-+
-       pScsiTm = (SCSITaskMgmt_t *) mf;
--      pScsiTm->TargetID = id;
--      pScsiTm->Bus = channel;
--      pScsiTm->ChainOffset = 0;
-+      memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
-       pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
--
-+      pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS;
-+      pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
-+      pScsiTm->TargetID = 0;
-+      pScsiTm->Bus = 0;
-+      pScsiTm->ChainOffset = 0;
-       pScsiTm->Reserved = 0;
--      pScsiTm->TaskType = type;
-       pScsiTm->Reserved1 = 0;
--      pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
--                    ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
--
--      int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
--
-+      pScsiTm->TaskMsgContext = 0;
-+      for (ii= 0; ii < 8; ii++)
-+              pScsiTm->LUN[ii] = 0;
-       for (ii=0; ii < 7; ii++)
-               pScsiTm->Reserved2[ii] = 0;
  
--      pScsiTm->TaskMsgContext = ctx2abort;
--
--      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt: ctx2abort (0x%08x) "
--              "type=%d\n", ioc->name, ctx2abort, type));
-+      switch (ioc->bus_type) {
-+              case FC:
-+                      timeout = 40;
-+                      break;
-+              case SAS:
-+                      timeout = 30;
-+                      break;
-+              case SPI:
-+              default:
-+                      timeout = 2;
-+                      break;
-+      }
+       /*
+@@ -1311,8 +1324,8 @@ mptsas_taskmgmt_complete(MPT_ADAPTER *io
+       if (list_empty(head))
+               return 1;
  
--      DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)pScsiTm);
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt type=%d timeout=%ld\n",
-+          ioc->name, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, timeout));
+-      target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
+-          list);
++      target_reset_list = list_entry(head->next,
++          struct mptsas_target_reset_event, list);
  
-+      INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+      CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
-+      retval = 0;
-+      time_count = jiffies;
-       if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
-           (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
-               mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);
-       else {
-               retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,
--                      sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
--              if (retval) {
--                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "send_handshake FAILED!"
--                      " (hd %p, ioc %p, mf %p, rc=%d) \n", ioc->name, hd,
--                      ioc, mf, retval));
--                      goto fail_out;
-+                  sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
-+              if (retval != 0) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "TaskMgmt send_handshake FAILED!"
-+                              " (ioc %p, mf %p, rc=%d) \n", ioc->name,
-+                              ioc, mf, retval));
-+                      mpt_clear_taskmgmt_in_progress_flag(ioc);
-+                      goto out;
-               }
+       id = target_reset_list->sas_event_data.TargetID;
+       channel = target_reset_list->sas_event_data.Bus;
+@@ -1344,19 +1357,19 @@ mptsas_ioc_reset(MPT_ADAPTER *ioc, int r
+       if (!hd->ioc)
+               goto out;
+-      switch(reset_phase) {
++      switch (reset_phase) {
+       case MPT_IOC_SETUP_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
+               mptsas_fw_event_off(ioc);
+               break;
+       case MPT_IOC_PRE_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
+               break;
+       case MPT_IOC_POST_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_POST_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
+               if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
+                       ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
+                       complete(&ioc->sas_mgmt.done);
+@@ -1473,7 +1486,7 @@ mptsas_get_lun_number(MPT_ADAPTER *ioc, 
+           &lun_data_dma);
+       if (!lun_data) {
+               printk(MYIOC_s_ERR_FMT "%s: pci_alloc_consistent(%d) FAILED!\n",
+-                  ioc->name, __FUNCTION__, lun_data_len);
++                  ioc->name, __func__, lun_data_len);
+               rc = -ENOMEM;
+               goto out;
+       }
+@@ -1481,7 +1494,7 @@ mptsas_get_lun_number(MPT_ADAPTER *ioc, 
+       iocmd = kzalloc(sizeof(INTERNAL_CMD), GFP_KERNEL);
+       if (!iocmd) {
+               printk(MYIOC_s_ERR_FMT "%s: kzalloc(%zd) FAILED!\n",
+-                  ioc->name, __FUNCTION__, sizeof(INTERNAL_CMD));
++                  ioc->name, __func__, sizeof(INTERNAL_CMD));
+               rc = -ENOMEM;
+               goto out;
+       }
+@@ -1499,14 +1512,14 @@ mptsas_get_lun_number(MPT_ADAPTER *ioc, 
+       if ((rc = mptscsih_do_cmd(hd, iocmd)) < 0) {
+               printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d: "
+                   "report_luns failed due to rc=0x%x\n", ioc->name,
+-                  __FUNCTION__, channel, id, rc);
++                  __func__, channel, id, rc);
+               goto out;
        }
  
--      if(mptscsih_tm_wait_for_completion(hd, timeout) == FAILED) {
--              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "task management request TIMED OUT!"
--                      " (hd %p, ioc %p, mf %p) \n", ioc->name, hd,
--                      ioc, mf));
--              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling HardReset! \n",
--                       ioc->name));
--              retval = mpt_HardResetHandler(ioc, CAN_SLEEP);
--              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rc=%d \n",
--                       ioc->name, retval));
--              goto fail_out;
-+      /* Now wait for the command to complete */
-+      ii = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ);
-+      if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "TaskMgmt failed\n", ioc->name));
-+              mpt_free_msg_frame(ioc, mf);
-+              mpt_clear_taskmgmt_in_progress_flag(ioc);
-+              retval = -1; /* return failure */
-+              goto out;
+       if (rc != MPT_SCANDV_GOOD) {
+               printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d: "
+                   "report_luns failed due to rc=0x%x\n", ioc->name,
+-                  __FUNCTION__, channel, id, rc);
++                  __func__, channel, id, rc);
+               rc = -rc;
+               goto out;
        }
+@@ -1576,7 +1589,7 @@ mptsas_test_unit_ready(MPT_ADAPTER *ioc,
+       iocmd = kzalloc(sizeof(INTERNAL_CMD), GFP_KERNEL);
+       if (!iocmd) {
+               printk(MYIOC_s_ERR_FMT "%s: kzalloc(%zd) FAILED!\n",
+-              __FUNCTION__, ioc->name, sizeof(INTERNAL_CMD));
++              __func__, ioc->name, sizeof(INTERNAL_CMD));
+               return DEVICE_ERROR;
+       }
+@@ -1595,31 +1608,31 @@ mptsas_test_unit_ready(MPT_ADAPTER *ioc,
+  retry:
+       devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_channel=%d "
+-          "fw_id=%d retry=%d\n", ioc->name, __FUNCTION__, channel, id, count));
++          "fw_id=%d retry=%d\n", ioc->name, __func__, channel, id, count));
+       rc = mptscsih_do_cmd(hd, iocmd);
+       devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rc=0x%02x\n",
+-          ioc->name, __FUNCTION__, rc));
++          ioc->name, __func__, rc));
+       if (rc < 0) {
+               printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d: "
+                   "tur failed due to timeout\n", ioc->name,
+-                  __FUNCTION__, channel, id);
++                  __func__, channel, id);
+               goto tur_done;
+       }
+-      switch(rc) {
++      switch (rc) {
+       case MPT_SCANDV_GOOD:
+               state = DEVICE_READY;
+               goto tur_done;
+       case MPT_SCANDV_BUSY:
+               devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: "
+                   "fw_channel=%d fw_id=%d : device busy\n",
+-                  ioc->name, __FUNCTION__, channel, id));
++                  ioc->name, __func__, channel, id));
+               state = DEVICE_RETRY;
+               break;
+       case MPT_SCANDV_DID_RESET:
+               devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: "
+                   "fw_channel=%d fw_id=%d : did reset\n",
+-                  ioc->name, __FUNCTION__, channel, id));
++                  ioc->name, __func__, channel, id));
+               state = DEVICE_RETRY;
+               break;
+       case MPT_SCANDV_SENSE:
+@@ -1630,7 +1643,7 @@ mptsas_test_unit_ready(MPT_ADAPTER *ioc,
+               devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: "
+                   "fw_channel=%d fw_id=%d : [sense_key,asc,"
+                   "ascq]: [0x%02x,0x%02x,0x%02x]\n", ioc->name,
+-                   __FUNCTION__, channel, id, skey, asc, ascq));
++                   __func__, channel, id, skey, asc, ascq));
+               if (skey == UNIT_ATTENTION) {
+                       if (!retry_ua) {
+@@ -1656,7 +1669,7 @@ mptsas_test_unit_ready(MPT_ADAPTER *ioc,
+                               break;
+                       }
+               } else if (skey == ILLEGAL_REQUEST) {
+-              /* try sending a tur to a non-zero lun number */
++                      /* try sending a tur to a non-zero lun number */
+                       if (!iocmd->lun && !mptsas_get_lun_number(ioc,
+                           channel, id, &iocmd->lun) && iocmd->lun)
+                               goto retry;
+@@ -1664,25 +1677,25 @@ mptsas_test_unit_ready(MPT_ADAPTER *ioc,
+               printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d : "
+                   "tur failed due to [sense_key,asc,ascq]: "
+                   "[0x%02x,0x%02x,0x%02x]\n", ioc->name,
+-                  __FUNCTION__, channel, id, skey, asc, ascq);
++                  __func__, channel, id, skey, asc, ascq);
+               goto tur_done;
+       case MPT_SCANDV_SELECTION_TIMEOUT:
+               printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d: "
+                   "tur failed due to no device\n", ioc->name,
+-                  __FUNCTION__, channel,
++                  __func__, channel,
+                   id);
+               goto tur_done;
+       case MPT_SCANDV_SOME_ERROR:
+               printk(MYIOC_s_ERR_FMT "%s: fw_channel=%d fw_id=%d: "
+                   "tur failed due to some error\n", ioc->name,
+-                  __FUNCTION__,
++                  __func__,
+                   channel, id);
+               goto tur_done;
+       default:
+               printk(MYIOC_s_ERR_FMT
+                   "%s: fw_channel=%d fw_id=%d: tur failed due to "
+-                  "unknown rc=0x%02x\n", ioc->name, __FUNCTION__,
+-                  channel, id, rc );
++                  "unknown rc=0x%02x\n", ioc->name, __func__,
++                  channel, id, rc);
+               goto tur_done;
+       }
+  tur_done:
+@@ -1705,19 +1718,19 @@ mptsas_issue_tlr(MPT_SCSI_HOST *hd, stru
+       u8              rc;
+       MPT_ADAPTER *ioc = hd->ioc;
  
--      /*
--       * Handle success case, see if theres a non-zero ioc_status.
--       */
--      if (hd->tm_iocstatus == MPI_IOCSTATUS_SUCCESS ||
--         hd->tm_iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
--         hd->tm_iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED)
--              retval = 0;
--      else
--              retval = FAILED;
-+      if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "TaskMgmt failed\n", ioc->name));
-+              retval = -1; /* return failure */
-+              goto out;
-+      }
+-      if ( sdev->inquiry[8]  == 'H' &&
++      if (sdev->inquiry[8]  == 'H' &&
+            sdev->inquiry[9]  == 'P' &&
+            sdev->inquiry[10] == ' ' &&
+            sdev->inquiry[11] == ' ' &&
+            sdev->inquiry[12] == ' ' &&
+            sdev->inquiry[13] == ' ' &&
+            sdev->inquiry[14] == ' ' &&
+-           sdev->inquiry[15] == ' ' ) {
++           sdev->inquiry[15] == ' ') {
+               iocmd = kzalloc(sizeof(INTERNAL_CMD), GFP_KERNEL);
+               if (!iocmd) {
+                       printk(MYIOC_s_ERR_FMT "%s: kzalloc(%zd) FAILED!\n",
+-                      __FUNCTION__, ioc->name, sizeof(INTERNAL_CMD));
++                      __func__, ioc->name, sizeof(INTERNAL_CMD));
+                       return;
+               }
+               iocmd->id = vdevice->vtarget->id;
+@@ -1773,7 +1786,7 @@ mptsas_slave_configure(struct scsi_devic
+       mptsas_add_device_component_starget(ioc, scsi_target(sdev));
+       if (sdev->type == TYPE_TAPE &&
+-          (ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_TLR ))
++          (ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_TLR))
+               mptsas_issue_tlr(hd, sdev);
+  out:
  
--      return retval;
-+      pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply;
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "TaskMgmt fw_channel = %d, fw_id = %d, task_type = 0x%02X,\n"
-+          "\tiocstatus = 0x%04X, loginfo = 0x%08X, response_code = 0x%02X,\n"
-+          "\tterm_cmnds = %d\n", ioc->name, pScsiTmReply->Bus,
-+          pScsiTmReply->TargetID, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
-+          le16_to_cpu(pScsiTmReply->IOCStatus),
-+          le32_to_cpu(pScsiTmReply->IOCLogInfo),
-+          pScsiTmReply->ResponseCode,
-+          le32_to_cpu(pScsiTmReply->TerminationCount)));
-- fail_out:
-+      iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
--      /*
--       * Free task management mf, and corresponding tm flags
--       */
--      mpt_free_msg_frame(ioc, mf);
--      hd->tmPending = 0;
--      hd->tmState = TM_STATE_NONE;
--      return FAILED;
-+      if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
-+         iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED ||
-+         iocstatus == MPI_IOCSTATUS_SUCCESS)
-+              retval = 0;
-+      else {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "TaskMgmt failed\n", ioc->name));
-+              retval = -1; /* return failure */
-+      }
-+
-+ out:
-+      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+      CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+      return retval;
+@@ -1815,7 +1828,7 @@ mptsas_target_alloc(struct scsi_target *
+                       kfree(vtarget);
+                       return -ENXIO;
+               }
+-              for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
++              for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
+                       if (id == ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID)
+                               channel = ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus;
+               vtarget->raidVolume = 1;
+@@ -1834,9 +1847,11 @@ mptsas_target_alloc(struct scsi_target *
+                       mptsas_set_starget(&p->phy_info[i], starget);
+                       starget_printk(KERN_INFO, starget, MYIOC_s_FMT
+-                      "add device: fw_channel %d, fw_id %d, phy %d, sas_addr 0x%llx\n",
++                      "add device: fw_channel %d, fw_id %d, phy %d,"
++                      " sas_addr 0x%llx\n",
+                       ioc->name, p->phy_info[i].attached.channel,
+-                      p->phy_info[i].attached.id, p->phy_info[i].attached.phy_id,
++                      p->phy_info[i].attached.id,
++                      p->phy_info[i].attached.phy_id,
+                       (unsigned long long)p->phy_info[i].attached.sas_address);
+                       /*
+@@ -1899,9 +1914,9 @@ mptsas_target_destroy(struct scsi_target
+                       starget_printk(KERN_INFO, starget, MYIOC_s_FMT
+                       "delete device: fw_channel %d, fw_id %d, phy %d, "
+                       "sas_addr 0x%llx\n", ioc->name,
+-                      p->phy_info[i].attached.channel,
++                      p->phy_info[i].attached.channel,
+                       p->phy_info[i].attached.id,
+-                      p->phy_info[i].attached.phy_id, (unsigned long long)
++                      p->phy_info[i].attached.phy_id, (unsigned long long)
+                       p->phy_info[i].attached.sas_address);
+                       mptsas_port_delete(ioc, p->phy_info[i].port_details);
+@@ -2000,8 +2015,7 @@ mptsas_qcmd(struct scsi_cmnd *SCpnt, voi
+       if (ioc->sas_discovery_quiesce_io)
+               return SCSI_MLQUEUE_HOST_BUSY;
+-//    scsi_print_command(SCpnt);
+-      return mptscsih_qcmd(SCpnt,done);
++      return mptscsih_qcmd(SCpnt, done);
  }
  
--static int
--mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)
-+int
-+mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
- {
--      switch (ioc->bus_type) {
--      case FC:
--              return 40;
--      case SAS:
-+      MPT_SCSI_HOST   *hd;
-+
-+      if ((ioc->sh == NULL) || (ioc->sh->hostdata == NULL))
-+              return 0;
-+
-+      switch (reset_phase) {
-+      case MPT_IOC_SETUP_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __FUNCTION__));
-+              break;
-+      case MPT_IOC_PRE_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __FUNCTION__));
-+              hd = shost_priv(ioc->sh);
-+              mptscsih_flush_running_cmds(hd);
-+              break;
-+      case MPT_IOC_POST_RESET:
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: MPT_IOC_POST_RESET\n", ioc->name, __FUNCTION__));
-+              if (ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING) {
-+                      ioc->internal_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
-+                      complete(&ioc->internal_cmds.done);
-+              }
-+              break;
-+      default:
-+              break;
-+      }
-+      return 1;               /* currently means nothing really */
-+}
-+
-+void
-+mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code)
-+{
-+      char *desc;
-+
-+      switch (response_code) {
-+      case MPI_SCSITASKMGMT_RSP_TM_COMPLETE:
-+              desc = "The task completed.";
-+              break;
-+      case MPI_SCSITASKMGMT_RSP_INVALID_FRAME:
-+              desc = "The IOC received an invalid frame status.";
-+              break;
-+      case MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
-+              desc = "The task type is not supported.";
-+              break;
-+      case MPI_SCSITASKMGMT_RSP_TM_FAILED:
-+              desc = "The requested task failed.";
-+              break;
-+      case MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED:
-+              desc = "The task completed successfully.";
-+              break;
-+      case MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN:
-+              desc = "The LUN request is invalid.";
-+              break;
-+      case MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
-+              desc = "The task is in the IOC queue and has not been sent to target.";
-+              break;
-+      default:
-+              desc = "unknown";
-+              break;
-+      }
-+      printk(MYIOC_s_DEBUG_FMT "Response Code(0x%08x): F/W: %s\n",
-+              ioc->name, response_code, desc);
-+}
-+
-+static int
-+mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type, SCSITaskMgmtReply_t *pScsiTmReply)
+@@ -2046,7 +2060,6 @@ static int mptsas_get_linkerrors(struct 
+       dma_addr_t dma_handle;
+       int error;
+-      /* FIXME: only have link errors on local phys */
+       if (!scsi_is_sas_phy_local(phy))
+               return -EINVAL;
+@@ -2140,7 +2153,6 @@ static int mptsas_phy_reset(struct sas_p
+       unsigned long timeleft;
+       int error = -ERESTARTSYS;
+-      /* FIXME: fusion doesn't allow non-local phy reset */
+       if (!scsi_is_sas_phy_local(phy))
+               return -EINVAL;
+@@ -2192,7 +2204,7 @@ static int mptsas_phy_reset(struct sas_p
+       reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
+       if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
+               printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
+-                  ioc->name, __FUNCTION__, reply->IOCStatus, reply->IOCLogInfo);
++                  ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
+               error = -ENXIO;
+               goto out_unlock;
+       }
+@@ -2275,11 +2287,160 @@ mptsas_get_bay_identifier(struct sas_rph
+       return rc;
+ }
++static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
++                            struct request *req)
 +{
-+      u16                      iocstatus;
-+      u32                      termination_count;
-+      int                      retval;
-+
-+      if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
-+              retval = FAILED;
-+              goto out;
-+      }
-+
-+      DBG_DUMP_TM_REPLY_FRAME(ioc, (u32 *)pScsiTmReply);
-+
-+      iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
-+      termination_count = le32_to_cpu(pScsiTmReply->TerminationCount);
-+
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "TaskMgmt fw_channel = %d, fw_id = %d, task_type = 0x%02X,\n"
-+          "\tiocstatus = 0x%04X, loginfo = 0x%08X, response_code = 0x%02X,\n"
-+          "\tterm_cmnds = %d\n", ioc->name, pScsiTmReply->Bus,
-+          pScsiTmReply->TargetID, type, le16_to_cpu(pScsiTmReply->IOCStatus),
-+          le32_to_cpu(pScsiTmReply->IOCLogInfo), pScsiTmReply->ResponseCode,
-+          termination_count));
-+
-+      if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 &&
-+          pScsiTmReply->ResponseCode)
-+              mptscsih_taskmgmt_response_code(ioc,
-+                  pScsiTmReply->ResponseCode);
++      MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
++      MPT_FRAME_HDR *mf;
++      SmpPassthroughRequest_t *smpreq;
++      struct request *rsp = req->next_rq;
++      int ret;
++      int flagsLength;
++      unsigned long timeleft;
++      char *psge;
++      dma_addr_t dma_addr_in = 0;
++      dma_addr_t dma_addr_out = 0;
++      u64 sas_address = 0;
 +
-+      if (iocstatus == MPI_IOCSTATUS_SUCCESS) {
-+              retval = 0;
-+              goto out;
++      if (!rsp) {
++              printk(MYIOC_s_ERR_FMT
++                  "%s: the smp response space is missing\n",
++                  ioc->name, __func__);
++              return -EINVAL;
 +      }
 +
-+      retval = FAILED;
-+      if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
-+              if (termination_count == 1)
-+                      retval = 0;
-+              goto out;
++      /* do we need to support multiple segments? */
++      if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
++              printk(MYIOC_s_ERR_FMT
++                  "%s: multiple segments req %u %u, rsp %u %u\n",
++                  ioc->name, __func__, req->bio->bi_vcnt, req->data_len,
++                  rsp->bio->bi_vcnt, rsp->data_len);
++              return -EINVAL;
 +      }
 +
-+      if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
-+         iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED)
-+              retval = 0;
-+
-+ out:
-+      return retval;
-+}
-+
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/**
-+ *    mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @mf: Pointer to SCSI task mgmt request frame
-+ *    @mr: Pointer to SCSI task mgmt reply frame
-+ *
-+ *    This routine is called from mptbase.c::mpt_interrupt() at the completion
-+ *    of any SCSI task management request.
-+ *    This routine is registered with the MPT (base) driver at driver
-+ *    load/init time via the mpt_register() API call.
-+ *
-+ *    Returns 1 indicating alloc'd request frame ptr should be freed.
-+ **/
-+int
-+mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
-+{
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed (mf=%p, mr=%p)\n",
-+          ioc->name, mf, mr));
-+
-+      ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
-+
-+      if (!mr)
++      ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
++      if (ret)
 +              goto out;
 +
-+      ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
-+      memcpy(ioc->taskmgmt_cmds.reply, mr,
-+          min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
-+ out:
-+      if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
-+              mpt_clear_taskmgmt_in_progress_flag(ioc);
-+              ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
-+              complete(&ioc->taskmgmt_cmds.done);
-+              return 1;
++      mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
++      if (!mf) {
++              ret = -ENOMEM;
++              goto out_unlock;
 +      }
-+      return 0;
-+}
-+
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/**
-+ *    mptscsih_IssueTaskMgmt - Generic send Task Management function.
-+ *    @hd: Pointer to MPT_SCSI_HOST structure
-+ *    @type: Task Management type
-+ *    @channel: channel number for task management
-+ *    @id: Logical Target ID for reset (if appropriate)
-+ *    @lun: Logical Unit for reset (if appropriate)
-+ *    @ctx2abort: Context for the task to be aborted (if appropriate)
-+ *    @timeout: timeout for task management control
-+ *
-+ *    Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
-+ *    or a non-interrupt thread.  In the former, must not call schedule().
-+ *
-+ *    Not all fields are meaningfull for all task types.
-+ *
-+ *    Returns 0 for SUCCESS, or FAILED.
-+ *
-+ **/
-+int
-+mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout)
-+{
-+      MPT_FRAME_HDR   *mf = NULL;
-+      SCSITaskMgmt_t  *pScsiTm;
-+      int              ii;
-+      int              retval;
-+      MPT_ADAPTER     *ioc = hd->ioc;
-+      unsigned long    timeleft;
-+      u8               issue_hard_reset;
-+      u32              ioc_raw_state;
-+      unsigned long    time_count;
-+
-+      issue_hard_reset = 0;
-+      ioc_raw_state = mpt_GetIocState(ioc, 0);
 +
-+      if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
-+              printk(MYIOC_s_WARN_FMT
-+                      "TaskMgmt type=%x: IOC Not operational (0x%x)!\n",
-+                      ioc->name, type, ioc_raw_state);
-+              printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
-+                  ioc->name, __FUNCTION__);
-+              if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
-+                      printk(MYIOC_s_WARN_FMT "TaskMgmt HardReset "
-+                          "FAILED!!\n", ioc->name);
-+              return 0;
-+      }
++      smpreq = (SmpPassthroughRequest_t *)mf;
++      memset(smpreq, 0, sizeof(*smpreq));
 +
-+      if (ioc_raw_state & MPI_DOORBELL_ACTIVE) {
-+              printk(MYIOC_s_WARN_FMT
-+                      "TaskMgmt type=%x: ioc_state: "
-+                      "DOORBELL_ACTIVE (0x%x)!\n",
-+                      ioc->name, type, ioc_raw_state);
-+              return FAILED;
-+      }
++      smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4);
++      smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
 +
-+      mutex_lock(&ioc->taskmgmt_cmds.mutex);
-+      if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
-+      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+              retval = FAILED;
-+              goto out;
-+      }
++      if (rphy)
++              sas_address = rphy->identify.sas_address;
++      else {
++              struct mptsas_portinfo *port_info;
 +
-+      /* Return Fail to calling function if no message frames available.
-+       */
-+      if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
-+              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "TaskMgmt no msg frames!!\n",
-+                              ioc->name));
-+              retval = FAILED;
-+              mpt_clear_taskmgmt_in_progress_flag(ioc);
-+              goto out;
++              mutex_lock(&ioc->sas_topology_mutex);
++              port_info = ioc->hba_port_info;
++              if (port_info && port_info->phy_info)
++                      sas_address =
++                              port_info->phy_info[0].phy->identify.sas_address;
++              mutex_unlock(&ioc->sas_topology_mutex);
 +      }
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
-+                      ioc->name, mf));
-+
-+      /* Format the Request
-+       */
-+      pScsiTm = (SCSITaskMgmt_t *) mf;
-+      pScsiTm->TargetID = id;
-+      pScsiTm->Bus = channel;
-+      pScsiTm->ChainOffset = 0;
-+      pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
 +
-+      pScsiTm->Reserved = 0;
-+      pScsiTm->TaskType = type;
-+      pScsiTm->Reserved1 = 0;
-+      pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
-+                    ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
++      *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
 +
-+      int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
++      psge = (char *)
++              (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
 +
-+      for (ii=0; ii < 7; ii++)
-+              pScsiTm->Reserved2[ii] = 0;
++      /* request */
 +
-+      pScsiTm->TaskMsgContext = ctx2abort;
++      flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
++              MPI_SGE_FLAGS_SYSTEM_ADDRESS |
++              MPI_SGE_FLAGS_HOST_TO_IOC |
++              MPI_SGE_FLAGS_END_OF_BUFFER;
 +
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt: ctx2abort (0x%08x) "
-+          "task_type = 0x%02X, timeout = %ld\n", ioc->name, ctx2abort,
-+          type, timeout));
++      flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
 +
-+      DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)pScsiTm);
++      flagsLength |= (req->data_len - 4);
 +
-+      INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+      time_count = jiffies;
-+      if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
-+          (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
-+              mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);
-+      else {
-+              retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,
-+                      sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
-+              if (retval) {
-+                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "TaskMgmt handshake FAILED!"
-+                          " (mf=%p, rc=%d) \n", ioc->name, mf, retval));
-+                      mpt_free_msg_frame(ioc, mf);
-+                      mpt_clear_taskmgmt_in_progress_flag(ioc);
-+                      goto out;
-+              }
-+      }
++      dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
++                                    req->data_len, PCI_DMA_BIDIRECTIONAL);
++      if (!dma_addr_out)
++              goto put_mf;
++      ioc->add_sge(psge, flagsLength, dma_addr_out);
++      psge += ioc->SGE_size;
 +
-+      timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ);
-+      if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              retval = FAILED;
-+              dtmprintk(ioc, printk(MYIOC_s_ERR_FMT
-+                  "TaskMgmt TIMED OUT!(mf=%p)\n", ioc->name, mf));
-+              mpt_clear_taskmgmt_in_progress_flag(ioc);
-+              if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
-+                      goto out;
-+              issue_hard_reset = 1;
-+              goto out;
-+      }
++      /* response */
++      flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
++              MPI_SGE_FLAGS_SYSTEM_ADDRESS |
++              MPI_SGE_FLAGS_IOC_TO_HOST |
++              MPI_SGE_FLAGS_END_OF_BUFFER;
 +
-+      retval = mptscsih_taskmgmt_reply(ioc, type,
-+          (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply);
++      flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
++      flagsLength |= rsp->data_len + 4;
++      dma_addr_in =  pci_map_single(ioc->pcidev, bio_data(rsp->bio),
++                                    rsp->data_len, PCI_DMA_BIDIRECTIONAL);
++      if (!dma_addr_in)
++              goto out_unmap;
 +
-+      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "TaskMgmt completed (%d seconds)\n",
-+          ioc->name, jiffies_to_msecs(jiffies - time_count)/1000));
++      ioc->add_sge(psge, flagsLength, dma_addr_in);
 +
-+ out:
++      INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
++      mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
 +
-+      CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
-+      if(issue_hard_reset) {
-+              printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
-+                  ioc->name, __FUNCTION__);
-+              if ((retval = mpt_SoftResetHandler(ioc, CAN_SLEEP)) != 0)
-+                      retval = mpt_HardResetHandler(ioc, CAN_SLEEP);
++      timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
++      if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
++              ret = -ETIME;
 +              mpt_free_msg_frame(ioc, mf);
++              mf = NULL;
++              if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
++                      goto out_unmap;
++              if (!timeleft) {
++                      if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
++                              mpt_HardResetHandler(ioc, CAN_SLEEP);
++              }
++              goto out_unmap;
 +      }
 +
-+      retval = (retval == 0) ? 0 : FAILED;
-+      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
-+      return retval;
-+}
++      mf = NULL;
 +
-+static int
-+mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)
-+{
-+      switch (ioc->bus_type) {
-+      case FC:
-+              return 40;
-+      case SAS:
-+              return 30;
-       case SPI:
-       default:
-               return 10;
-@@ -1786,7 +1973,7 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
-       int              retval;
-       VirtDevice       *vdevice;
-       ulong            sn = SCpnt->serial_number;
--      MPT_ADAPTER     *ioc;
-+      MPT_ADAPTER     *ioc;
-       /* If we can't locate our host adapter structure, return FAILED status.
-        */
-@@ -1810,7 +1997,21 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
-                   ioc->name, SCpnt));
-               SCpnt->result = DID_NO_CONNECT << 16;
-               SCpnt->scsi_done(SCpnt);
--              retval = 0;
-+              retval = SUCCESS;
-+              goto out;
-+      }
++      if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
++              SmpPassthroughReply_t *smprep;
 +
-+      /* Find this command
-+       */
-+      if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) {
-+              /* Cmd not found in ScsiLookup.
-+               * Do OS callback.
-+               */
-+              SCpnt->result = DID_RESET << 16;
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "task abort: command not in the active list! (sc=%p)\n",
-+                  ioc->name, SCpnt));
-+              retval = SUCCESS;
-               goto out;
-       }
-@@ -1825,27 +2026,19 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
-               goto out;
-       }
--      /* Find this command
-+      /* Task aborts are not supported for volumes.
-        */
--      if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) {
--              /* Cmd not found in ScsiLookup.
--               * Do OS callback.
--               */
-+      if (vdevice->vtarget->raidVolume) {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "task abort: raid volume (sc=%p)\n",
-+                  ioc->name, SCpnt));
-               SCpnt->result = DID_RESET << 16;
--              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "task abort: "
--                 "Command not in the active list! (sc=%p)\n", ioc->name,
--                 SCpnt));
--              retval = 0;
--              goto out;
--      }
--
--      if (hd->resetPending) {
-               retval = FAILED;
-               goto out;
-       }
-
--      if (hd->timeouts < -1)
--              hd->timeouts++;
-+      if (ioc->timeouts < -1)
-+              ioc->timeouts++;
-
-       if (mpt_fwfault_debug)
-               mpt_halt_firmware(ioc);
-@@ -1856,25 +2053,31 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
-        */
-       mf = MPT_INDEX_2_MFPTR(ioc, scpnt_idx);
-       ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
--
--      hd->abortSCpnt = SCpnt;
--
--      retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
-+      mptscsih_IssueTaskMgmt(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
-           vdevice->vtarget->channel, vdevice->vtarget->id, vdevice->lun,
-           ctx2abort, mptscsih_get_tm_timeout(ioc));
-+      /* check to see whether command actually completed and/or
-+       * terminated
-+       */
-       if (SCPNT_TO_LOOKUP_IDX(ioc, SCpnt) == scpnt_idx &&
--          SCpnt->serial_number == sn)
-+          SCpnt->serial_number == sn) {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "task abort: command still in active list! (sc=%p)\n",
-+                  ioc->name, SCpnt));
-               retval = FAILED;
++              smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
++              memcpy(req->sense, smprep, sizeof(*smprep));
++              req->sense_len = sizeof(*smprep);
++              req->data_len = 0;
++              rsp->data_len -= smprep->ResponseDataLength;
 +      } else {
-+              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "task abort: command cleared from active list! (sc=%p)\n",
-+                  ioc->name, SCpnt));
-+              retval = SUCCESS;
-+      }
-  out:
-       printk(MYIOC_s_INFO_FMT "task abort: %s (sc=%p)\n",
--          ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
-+          ioc->name, ((retval == SUCCESS) ? "SUCCESS" : "FAILED" ), SCpnt);
--      if (retval == 0)
--              return SUCCESS;
--      else
--              return FAILED;
-+      return retval;
- }
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-@@ -1907,14 +2110,9 @@ mptscsih_dev_reset(struct scsi_cmnd * SC
-              ioc->name, SCpnt);
-       scsi_print_command(SCpnt);
--      if (hd->resetPending) {
--              retval = FAILED;
--              goto out;
--      }
--
-       vdevice = SCpnt->device->hostdata;
-       if (!vdevice || !vdevice->vtarget) {
--              retval = 0;
-+              retval = SUCCESS;
-               goto out;
-       }
-@@ -1925,12 +2123,12 @@ mptscsih_dev_reset(struct scsi_cmnd * SC
-               goto out;
-       }
--      retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
--          vdevice->vtarget->channel, vdevice->vtarget->id, 0, 0,
--          mptscsih_get_tm_timeout(ioc));
-+      retval = mptscsih_IssueTaskMgmt(hd,
-+          MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, vdevice->vtarget->channel,
-+          vdevice->vtarget->id, 0, 0, mptscsih_get_tm_timeout(ioc));
-  out:
--      printk (MYIOC_s_INFO_FMT "target reset: %s (sc=%p)\n",
-+      printk(MYIOC_s_INFO_FMT "target reset: %s (sc=%p)\n",
-           ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
-       if (retval == 0)
-@@ -1955,12 +2153,12 @@ mptscsih_bus_reset(struct scsi_cmnd * SC
-       MPT_SCSI_HOST   *hd;
-       int              retval;
-       VirtDevice       *vdevice;
--      MPT_ADAPTER     *ioc;
-+      MPT_ADAPTER *ioc;
-       /* If we can't locate our host adapter structure, return FAILED status.
-        */
-       if ((hd = shost_priv(SCpnt->device->host)) == NULL){
--              printk(KERN_ERR MYNAM ": bus reset: "
-+              printk(KERN_ERR MYNAM ": bus_reset: "
-                  "Can't locate host! (sc=%p)\n", SCpnt);
-               return FAILED;
-       }
-@@ -1970,11 +2168,13 @@ mptscsih_bus_reset(struct scsi_cmnd * SC
-              ioc->name, SCpnt);
-       scsi_print_command(SCpnt);
--      if (hd->timeouts < -1)
--              hd->timeouts++;
-+      if (ioc->timeouts < -1)
-+              ioc->timeouts++;
-       vdevice = SCpnt->device->hostdata;
--      retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
-+      if (!vdevice || !vdevice->vtarget)
-+              return SUCCESS;
-+      retval = mptscsih_IssueTaskMgmt(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
-           vdevice->vtarget->channel, 0, 0, 0, mptscsih_get_tm_timeout(ioc));
-       printk(MYIOC_s_INFO_FMT "bus reset: %s (sc=%p)\n",
-@@ -1999,8 +2199,9 @@ int
- mptscsih_host_reset(struct scsi_cmnd *SCpnt)
- {
-       MPT_SCSI_HOST *  hd;
--      int              retval;
--      MPT_ADAPTER     *ioc;
-+      int              status = SUCCESS;
-+      MPT_ADAPTER     *ioc;
-+      int             retval;
-       /*  If we can't locate the host to reset, then we failed. */
-       if ((hd = shost_priv(SCpnt->device->host)) == NULL){
-@@ -2011,237 +2212,29 @@ mptscsih_host_reset(struct scsi_cmnd *SC
-       ioc = hd->ioc;
-       printk(MYIOC_s_INFO_FMT "attempting host reset! (sc=%p)\n",
--          ioc->name, SCpnt);
-+             ioc->name, SCpnt);
-       /*  If our attempts to reset the host failed, then return a failed
-        *  status.  The host will be taken off line by the SCSI mid-layer.
-        */
--      if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0) {
--              retval = FAILED;
--      } else {
--              /*  Make sure TM pending is cleared and TM state is set to
--               *  NONE.
--               */
--              retval = 0;
--              hd->tmPending = 0;
--              hd->tmState = TM_STATE_NONE;
--      }
-+      if ((retval = mpt_SoftResetHandler(ioc, CAN_SLEEP)) != 0)
-+              retval = mpt_HardResetHandler(ioc, CAN_SLEEP);
++              printk(MYIOC_s_ERR_FMT
++                  "%s: smp passthru reply failed to be returned\n",
++                  ioc->name, __func__);
++              ret = -ENXIO;
++      }
++out_unmap:
++      if (dma_addr_out)
++              pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len,
++                               PCI_DMA_BIDIRECTIONAL);
++      if (dma_addr_in)
++              pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len,
++                               PCI_DMA_BIDIRECTIONAL);
++put_mf:
++      if (mf)
++              mpt_free_msg_frame(ioc, mf);
++out_unlock:
++      CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
++      mutex_unlock(&ioc->sas_mgmt.mutex);
++out:
++      return ret;
++}
 +
-+      if (retval < 0)
-+              status = FAILED;
-+      else
-+              status = SUCCESS;
-       printk(MYIOC_s_INFO_FMT "host reset: %s (sc=%p)\n",
-           ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
--      return retval;
--}
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/**
-- *    mptscsih_tm_pending_wait - wait for pending task management request to complete
-- *    @hd: Pointer to MPT host structure.
-- *
-- *    Returns {SUCCESS,FAILED}.
-- */
--static int
--mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd)
--{
--      unsigned long  flags;
--      int            loop_count = 4 * 10;  /* Wait 10 seconds */
--      int            status = FAILED;
--      MPT_ADAPTER     *ioc = hd->ioc;
--
--      do {
--              spin_lock_irqsave(&ioc->FreeQlock, flags);
--              if (hd->tmState == TM_STATE_NONE) {
--                      hd->tmState = TM_STATE_IN_PROGRESS;
--                      hd->tmPending = 1;
--                      spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--                      status = SUCCESS;
--                      break;
--              }
--              spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--              msleep(250);
--      } while (--loop_count);
--
-       return status;
- }
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-- *    mptscsih_tm_wait_for_completion - wait for completion of TM task
-- *    @hd: Pointer to MPT host structure.
-- *    @timeout: timeout value
-- *
-- *    Returns {SUCCESS,FAILED}.
-- */
--static int
--mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout )
--{
--      unsigned long  flags;
--      int            loop_count = 4 * timeout;
--      int            status = FAILED;
--      MPT_ADAPTER     *ioc = hd->ioc;
--
--      do {
--              spin_lock_irqsave(&ioc->FreeQlock, flags);
--              if(hd->tmPending == 0) {
--                      status = SUCCESS;
--                      spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--                      break;
--              }
--              spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--              msleep(250);
--      } while (--loop_count);
--
--      return status;
--}
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--static void
--mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code)
--{
--      char *desc;
--
--      switch (response_code) {
--      case MPI_SCSITASKMGMT_RSP_TM_COMPLETE:
--              desc = "The task completed.";
--              break;
--      case MPI_SCSITASKMGMT_RSP_INVALID_FRAME:
--              desc = "The IOC received an invalid frame status.";
--              break;
--      case MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
--              desc = "The task type is not supported.";
--              break;
--      case MPI_SCSITASKMGMT_RSP_TM_FAILED:
--              desc = "The requested task failed.";
--              break;
--      case MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED:
--              desc = "The task completed successfully.";
--              break;
--      case MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN:
--              desc = "The LUN request is invalid.";
--              break;
--      case MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
--              desc = "The task is in the IOC queue and has not been sent to target.";
--              break;
--      default:
--              desc = "unknown";
--              break;
--      }
--      printk(MYIOC_s_INFO_FMT "Response Code(0x%08x): F/W: %s\n",
--              ioc->name, response_code, desc);
--}
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/**
-- *    mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
-- *    @ioc: Pointer to MPT_ADAPTER structure
-- *    @mf: Pointer to SCSI task mgmt request frame
-- *    @mr: Pointer to SCSI task mgmt reply frame
-- *
-- *    This routine is called from mptbase.c::mpt_interrupt() at the completion
-- *    of any SCSI task management request.
-- *    This routine is registered with the MPT (base) driver at driver
-- *    load/init time via the mpt_register() API call.
-- *
-- *    Returns 1 indicating alloc'd request frame ptr should be freed.
-- **/
--int
--mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
--{
--      SCSITaskMgmtReply_t     *pScsiTmReply;
--      SCSITaskMgmt_t          *pScsiTmReq;
--      MPT_SCSI_HOST           *hd;
--      unsigned long            flags;
--      u16                      iocstatus;
--      u8                       tmType;
--      u32                      termination_count;
--
--      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed (mf=%p,mr=%p)\n",
--          ioc->name, mf, mr));
--      if (!ioc->sh) {
--              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
--                  "TaskMgmt Complete: NULL Scsi Host Ptr\n", ioc->name));
--              return 1;
--      }
--
--      if (mr == NULL) {
--              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
--                  "ERROR! TaskMgmt Reply: NULL Request %p\n", ioc->name, mf));
--              return 1;
--      }
--
--      hd = shost_priv(ioc->sh);
--      pScsiTmReply = (SCSITaskMgmtReply_t*)mr;
--      pScsiTmReq = (SCSITaskMgmt_t*)mf;
--      tmType = pScsiTmReq->TaskType;
--      iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
--      termination_count = le32_to_cpu(pScsiTmReply->TerminationCount);
--
--      if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 &&
--          pScsiTmReply->ResponseCode)
--              mptscsih_taskmgmt_response_code(ioc,
--                  pScsiTmReply->ResponseCode);
--      DBG_DUMP_TM_REPLY_FRAME(ioc, (u32 *)pScsiTmReply);
--
--#ifdef CONFIG_FUSION_LOGGING
--      if ((ioc->debug_level & MPT_DEBUG_REPLY) ||
--                              (ioc->debug_level & MPT_DEBUG_TM ))
--              printk("%s: ha=%d [%d:%d:0] task_type=0x%02X "
--                      "iocstatus=0x%04X\n\tloginfo=0x%08X response_code=0x%02X "
--                      "term_cmnds=%d\n", __func__, ioc->id, pScsiTmReply->Bus,
--                       pScsiTmReply->TargetID, pScsiTmReq->TaskType,
--                      le16_to_cpu(pScsiTmReply->IOCStatus),
--                      le32_to_cpu(pScsiTmReply->IOCLogInfo),pScsiTmReply->ResponseCode,
--                      le32_to_cpu(pScsiTmReply->TerminationCount));
--#endif
--      if (!iocstatus) {
--              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT " TaskMgmt SUCCESS\n", ioc->name));
--                      hd->abortSCpnt = NULL;
--              goto out;
--      }
--
--      /* Error?  (anything non-zero?) */
--
--      /* clear flags and continue.
--       */
--      switch (tmType) {
--
--      case MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
--              if (termination_count == 1)
--                      iocstatus = MPI_IOCSTATUS_SCSI_TASK_TERMINATED;
--              hd->abortSCpnt = NULL;
--              break;
--
--      case MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS:
--
--              /* If an internal command is present
--               * or the TM failed - reload the FW.
--               * FC FW may respond FAILED to an ABORT
--               */
--              if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED ||
--                  hd->cmdPtr)
--                      if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
--                              printk(MYIOC_s_WARN_FMT " Firmware Reload FAILED!!\n", ioc->name);
--              break;
--
--      case MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
--      default:
--              break;
--      }
--
-- out:
--      spin_lock_irqsave(&ioc->FreeQlock, flags);
--      hd->tmPending = 0;
--      hd->tmState = TM_STATE_NONE;
--      hd->tm_iocstatus = iocstatus;
--      spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--
--      return 1;
--}
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-  *    This is anyones guess quite frankly.
-- */
-+ **/
- int
- mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
-               sector_t capacity, int geom[])
-@@ -2278,40 +2271,82 @@ mptscsih_bios_param(struct scsi_device *
-       return 0;
- }
+ static struct sas_function_template mptsas_transport_functions = {
+       .get_linkerrors         = mptsas_get_linkerrors,
+       .get_enclosure_identifier = mptsas_get_enclosure_identifier,
+       .get_bay_identifier     = mptsas_get_bay_identifier,
+       .phy_reset              = mptsas_phy_reset,
++      .smp_handler            = mptsas_smp_handler,
+ };
  
--/* Search IOC page 3 to determine if this is hidden physical disk
-+/**
-+ * Search IOC page 3 to determine if this is hidden physical disk
-  *
-- */
-+ **/
- int
- mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id)
- {
-       struct inactive_raid_component_info *component_info;
--      int i;
-+      u8 i, j;
-+      RaidPhysDiskPage1_t *phys_disk;
-       int rc = 0;
-+      int num_paths;
+ static struct scsi_transport_template *mptsas_transport_template;
+@@ -2338,7 +2499,7 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc,
  
-       if (!ioc->raid_data.pIocPg3)
-               goto out;
-       for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
-               if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
--                  (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
-+                  (channel ==
-+                   ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
-                       rc = 1;
+       port_info->num_phys = buffer->NumPhys;
+       port_info->phy_info = kcalloc(port_info->num_phys,
+-              sizeof(struct mptsas_phyinfo),GFP_KERNEL);
++              sizeof(struct mptsas_phyinfo), GFP_KERNEL);
+       if (!port_info->phy_info) {
+               error = -ENOMEM;
+               goto out_free_consistent;
+@@ -2659,7 +2820,7 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc
+       /* save config data */
+       port_info->num_phys = (buffer->NumPhys) ? buffer->NumPhys : 1;
+       port_info->phy_info = kcalloc(port_info->num_phys,
+-              sizeof(struct mptsas_phyinfo),GFP_KERNEL);
++              sizeof(struct mptsas_phyinfo), GFP_KERNEL);
+       if (!port_info->phy_info) {
+               error = -ENOMEM;
+               goto out_free_consistent;
+@@ -2970,7 +3131,7 @@ static int mptsas_probe_one_phy(struct d
+                       if (error) {
+                               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                                       "%s: exit at line=%d\n", ioc->name,
+-                                      __FUNCTION__, __LINE__));
++                                      __func__, __LINE__));
+                               goto out;
+                       }
+                       mptsas_set_port(ioc, phy_info, port);
+@@ -3036,7 +3197,7 @@ static int mptsas_probe_one_phy(struct d
+               if (!rphy) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                               "%s: exit at line=%d\n", ioc->name,
+-                              __FUNCTION__, __LINE__));
++                              __func__, __LINE__));
                        goto out;
                }
-       }
-+      if (ioc->bus_type != SAS)
-+              goto out;
-+
-+      /*
-+       * Check if dual path
-+       */
-+      for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
-+              num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
-+                  ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
-+              if (num_paths < 2)
-+                      continue;
-+              phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t,Path) +
-+                 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
-+              if (!phys_disk)
-+                      continue;
-+              if ((mpt_raid_phys_disk_pg1(ioc,
-+                  ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
-+                  phys_disk))) {
-+                      kfree(phys_disk);
-+                      continue;
-+              }
-+              for (j = 0; j < num_paths; j++) {
-+                      if ((phys_disk->Path[j].Flags &
-+                          MPI_RAID_PHYSDISK1_FLAG_INVALID))
-+                              continue;
-+                      if ((phys_disk->Path[j].Flags &
-+                          MPI_RAID_PHYSDISK1_FLAG_BROKEN))
-+                              continue;
-+                      if ((id == phys_disk->Path[j].PhysDiskID) &&
-+                          (channel == phys_disk->Path[j].PhysDiskBus)) {
-+                              rc = 1;
-+                              kfree(phys_disk);
-+                              goto out;
-+                      }
-+              }
-+              kfree(phys_disk);
-+      }
-+
-       /*
-        * Check inactive list for matching phys disks
-        */
-       if (list_empty(&ioc->raid_data.inactive_list))
-               goto out;
--      mutex_lock(&ioc->raid_data.inactive_list_mutex);
-+      down(&ioc->raid_data.inactive_list_mutex);
-       list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
-           list) {
-               if ((component_info->d.PhysDiskID == id) &&
-                   (component_info->d.PhysDiskBus == channel))
-                       rc = 1;
-       }
--      mutex_unlock(&ioc->raid_data.inactive_list_mutex);
-+      up(&ioc->raid_data.inactive_list_mutex);
  
-  out:
-       return rc;
-@@ -2322,43 +2357,84 @@ u8
- mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
- {
-       struct inactive_raid_component_info *component_info;
--      int i;
-+      int i,j;
-+      RaidPhysDiskPage1_t *phys_disk;
-       int rc = -ENXIO;
-+      u8 num_paths;
+@@ -3045,7 +3206,7 @@ static int mptsas_probe_one_phy(struct d
+               if (error) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                               "%s: exit at line=%d\n", ioc->name,
+-                              __FUNCTION__, __LINE__));
++                              __func__, __LINE__));
+                       sas_rphy_free(rphy);
+                       goto out;
+               }
+@@ -3069,7 +3230,7 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
+       int error = -ENOMEM, i;
  
-       if (!ioc->raid_data.pIocPg3)
-               goto out;
-       for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
-               if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
--                  (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
-+                  (channel ==
-+                   ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
-                       rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
+       hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
+-      if (! hba)
++      if (!hba)
+               goto out;
+       error = mptsas_sas_io_unit_pg0(ioc, hba);
+@@ -3195,7 +3356,7 @@ mptsas_find_phyinfo_by_phys_disk_num(MPT
+       num_paths = mpt_raid_phys_disk_get_num_paths(ioc, phys_disk_num);
+       if (!num_paths)
+               goto out;
+-      phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t,Path) +
++      phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
+          (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
+       if (!phys_disk)
+               goto out;
+@@ -3208,7 +3369,8 @@ mptsas_find_phyinfo_by_phys_disk_num(MPT
+                   (channel == phys_disk->Path[i].PhysDiskBus)) {
+                       memcpy(&sas_address, &phys_disk->Path[i].WWID,
+                               sizeof(u64));
+-                      phy_info = mptsas_find_phyinfo_by_sas_address(ioc, sas_address);
++                      phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
++                          sas_address);
                        goto out;
                }
        }
+@@ -3230,7 +3392,8 @@ mptsas_find_phyinfo_by_phys_disk_num(MPT
+                               continue;
+                       if (port_info->phy_info[i].attached.phys_disk_num == ~0)
+                               continue;
+-                      if (port_info->phy_info[i].attached.phys_disk_num == phys_disk_num &&
++                      if (port_info->phy_info[i].attached.phys_disk_num ==
++                          phys_disk_num &&
+                           port_info->phy_info[i].attached.id == id &&
+                           port_info->phy_info[i].attached.channel == channel)
+                               phy_info = &port_info->phy_info[i];
+@@ -3275,7 +3438,6 @@ mptsas_reprobe_target(struct scsi_target
+  *    @id:
+  *
+  *
+- *     TODO: check for hotspares
+  **/
+ static void
+ mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
+@@ -3363,10 +3525,10 @@ mptsas_add_end_device(MPT_ADAPTER *ioc, 
+       char *ds = NULL;
+       u8 fw_id;
+-      if (!phy_info){
++      if (!phy_info) {
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                       "%s: exit at line=%d\n", ioc->name,
+-                      __FUNCTION__, __LINE__));
++                      __func__, __LINE__));
+               return 1;
+       }
  
-+      if (ioc->bus_type != SAS)
-+              goto out;
-+
-+      /*
-+       * Check if dual path
-+       */
-+      for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
-+              num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
-+                  ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
-+              if (num_paths < 2)
-+                      continue;
-+              phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t,Path) +
-+                 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
-+              if (!phys_disk)
-+                      continue;
-+              if ((mpt_raid_phys_disk_pg1(ioc,
-+                  ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
-+                  phys_disk))) {
-+                      kfree(phys_disk);
-+                      continue;
-+              }
-+              for (j = 0; j < num_paths; j++) {
-+                      if ((phys_disk->Path[j].Flags &
-+                          MPI_RAID_PHYSDISK1_FLAG_INVALID))
-+                              continue;
-+                      if ((phys_disk->Path[j].Flags &
-+                          MPI_RAID_PHYSDISK1_FLAG_BROKEN))
-+                              continue;
-+                      if ((id == phys_disk->Path[j].PhysDiskID) &&
-+                          (channel == phys_disk->Path[j].PhysDiskBus)) {
-+                              rc = phys_disk->PhysDiskNum;
-+                              kfree(phys_disk);
-+                              goto out;
-+                      }
-+              }
-+              kfree(phys_disk);
-+      }
-+
-       /*
-        * Check inactive list for matching phys disks
-        */
-       if (list_empty(&ioc->raid_data.inactive_list))
-               goto out;
+@@ -3375,7 +3537,7 @@ mptsas_add_end_device(MPT_ADAPTER *ioc, 
+       if (mptsas_get_rphy(phy_info)) {
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                       "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                      __FUNCTION__, fw_id, __LINE__));
++                      __func__, fw_id, __LINE__));
+               return 2;
+       }
  
--      mutex_lock(&ioc->raid_data.inactive_list_mutex);
-+      down(&ioc->raid_data.inactive_list_mutex);
-       list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
-           list) {
-               if ((component_info->d.PhysDiskID == id) &&
-                   (component_info->d.PhysDiskBus == channel))
-                       rc = component_info->d.PhysDiskNum;
+@@ -3383,7 +3545,7 @@ mptsas_add_end_device(MPT_ADAPTER *ioc, 
+       if (!port) {
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                       "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                      __FUNCTION__, fw_id, __LINE__));
++                      __func__, fw_id, __LINE__));
+               return 3;
        }
--      mutex_unlock(&ioc->raid_data.inactive_list_mutex);
-+      up(&ioc->raid_data.inactive_list_mutex);
  
-  out:
-       return rc;
- }
- EXPORT_SYMBOL(mptscsih_raid_id_to_num);
--/*
-+/**
-  *    OS entry point to allow for host driver to free allocated memory
-  *    Called if no device present or device being unloaded
-- */
-+ **/
- void
- mptscsih_slave_destroy(struct scsi_device *sdev)
- {
-@@ -2370,23 +2446,25 @@ mptscsih_slave_destroy(struct scsi_devic
-       starget = scsi_target(sdev);
-       vtarget = starget->hostdata;
-+      vtarget->num_luns--;
-       vdevice = sdev->hostdata;
-+      if (!vdevice)
-+              return;
-       mptscsih_search_running_cmds(hd, vdevice);
--      vtarget->num_luns--;
--      mptscsih_synchronize_cache(hd, vdevice);
-+      mptscsih_synchronize_cache(sdev, hd, vdevice);
-       kfree(vdevice);
-       sdev->hostdata = NULL;
+@@ -3408,7 +3570,7 @@ mptsas_add_end_device(MPT_ADAPTER *ioc, 
+       if (!rphy) {
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                       "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                      __FUNCTION__, fw_id, __LINE__));
++                      __func__, fw_id, __LINE__));
+               return 5; /* non-fatal: an rphy can be added later */
+       }
+@@ -3416,7 +3578,7 @@ mptsas_add_end_device(MPT_ADAPTER *ioc, 
+       if (sas_rphy_add(rphy)) {
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                       "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                      __FUNCTION__, fw_id, __LINE__));
++                      __func__, fw_id, __LINE__));
+               sas_rphy_free(rphy);
+               return 6;
+       }
+@@ -3439,7 +3601,7 @@ mptsas_del_end_device(MPT_ADAPTER *ioc, 
+       struct mptsas_portinfo *port_info;
+       struct mptsas_phyinfo *phy_info_parent;
+       int i;
+-      struct scsi_target * starget;
++      struct scsi_target *starget;
+       char *ds = NULL;
+       u8 fw_id;
+       u64 sas_address;
+@@ -3453,14 +3615,14 @@ mptsas_del_end_device(MPT_ADAPTER *ioc, 
+       if (!phy_info->port_details) {
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                       "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                      __FUNCTION__, fw_id, __LINE__));
++                      __func__, fw_id, __LINE__));
+               return;
+       }
+       rphy = mptsas_get_rphy(phy_info);
+       if (!rphy) {
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                       "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                      __FUNCTION__, fw_id, __LINE__));
++                      __func__, fw_id, __LINE__));
+               return;
+       }
+       if (phy_info->attached.device_info &
+@@ -3485,13 +3647,13 @@ mptsas_del_end_device(MPT_ADAPTER *ioc, 
+       if (!port) {
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                       "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                      __FUNCTION__, fw_id, __LINE__));
++                      __func__, fw_id, __LINE__));
+               return;
+       }
+       port_info = phy_info->portinfo;
+       phy_info_parent = port_info->phy_info;
+       for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) {
+-              if(!phy_info_parent->phy)
++              if (!phy_info_parent->phy)
+                       continue;
+               if (phy_info_parent->attached.sas_address !=
+                   sas_address)
+@@ -3507,11 +3669,11 @@ mptsas_del_end_device(MPT_ADAPTER *ioc, 
+           "delete port %d, sas_addr (0x%llx)\n", ioc->name,
+            port->port_identifier, (unsigned long long)sas_address);
+       sas_port_delete(port);
+-//    mptsas_port_delete(ioc, phy_info->port_details);
  }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-+/**
-  *    mptscsih_change_queue_depth - This function will set a devices queue depth
-  *    @sdev: per scsi_device pointer
-  *    @qdepth: requested queue depth
-  *
-  *    Adding support for new 'change_queue_depth' api.
--*/
-+ **/
- int
- mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
+ struct mptsas_phyinfo *
+-mptsas_refreshing_device_handles(MPT_ADAPTER *ioc, struct mptsas_devinfo *sas_device)
++mptsas_refreshing_device_handles(MPT_ADAPTER *ioc,
++    struct mptsas_devinfo *sas_device)
  {
-@@ -2401,15 +2479,16 @@ mptscsih_change_queue_depth(struct scsi_
-       vtarget = starget->hostdata;
-       if (ioc->bus_type == SPI) {
--              if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
--                      max_depth = 1;
--              else if (sdev->type == TYPE_DISK &&
--                       vtarget->minSyncFactor <= MPT_ULTRA160)
-+              if (sdev->type == TYPE_DISK &&
-+                  vtarget->minSyncFactor <= MPT_ULTRA160)
-                       max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
-               else
-                       max_depth = MPT_SCSI_CMD_PER_DEV_LOW;
-       } else
--              max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
-+              max_depth = ioc->sh->can_queue;
-+
-+      if (!sdev->tagged_supported)
-+              max_depth = 1;
-       if (qdepth > max_depth)
-               qdepth = max_depth;
-@@ -2419,15 +2498,24 @@ mptscsih_change_queue_depth(struct scsi_
-               tagged = MSG_SIMPLE_TAG;
+       struct mptsas_phyinfo *phy_info;
+       struct mptsas_portinfo *port_info;
+@@ -3526,7 +3688,7 @@ mptsas_refreshing_device_handles(MPT_ADA
+               goto out;
+       mutex_lock(&ioc->sas_topology_mutex);
+       for (i = 0; i < port_info->num_phys; i++) {
+-              if(port_info->phy_info[i].attached.sas_address !=
++              if (port_info->phy_info[i].attached.sas_address !=
+                   sas_device->sas_address)
+                       continue;
+               port_info->phy_info[i].attached.channel = sas_device->channel;
+@@ -3555,7 +3717,7 @@ mptsas_hotplug_work(MPT_ADAPTER *ioc, st
+     struct mptsas_hotplug_event *hot_plug_info)
+ {
+       struct mptsas_phyinfo *phy_info;
+-      struct scsi_target * starget;
++      struct scsi_target *starget;
+       struct mptsas_devinfo sas_device;
+       VirtTarget *vtarget;
+       enum device_state state;
+@@ -3636,17 +3798,17 @@ mptsas_hotplug_work(MPT_ADAPTER *ioc, st
+                   (hot_plug_info->channel << 8) + hot_plug_info->id)) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                       "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                              __FUNCTION__, hot_plug_info->id, __LINE__));
++                      __func__, hot_plug_info->id, __LINE__));
+                       break;
+               }
  
-       scsi_adjust_queue_depth(sdev, tagged, qdepth);
-+
-+      if (sdev->inquiry_len > 7)
-+              sdev_printk(KERN_INFO, sdev, MYIOC_s_FMT "qdepth=%d, "
-+                  "tagged=%d, simple=%d, ordered=%d, scsi_level=%d, "
-+                  "cmd_que=%d\n", ioc->name, sdev->queue_depth,
-+                  sdev->tagged_supported, sdev->simple_tags,
-+                  sdev->ordered_tags, sdev->scsi_level,
-+                  (sdev->inquiry[7] & 2) >> 1);
-+
-       return sdev->queue_depth;
- }
+               phy_info = mptsas_find_phyinfo_by_sas_address(
+                   ioc, sas_device.sas_address);
  
--/*
-+/**
-  *    OS entry point to adjust the queue_depths on a per-device basis.
-  *    Called once per device the bus scan. Use it to force the queue_depth
-  *    member to 1 if a device does not support Q tags.
-  *    Return non-zero if fails.
-- */
-+ **/
- int
- mptscsih_slave_configure(struct scsi_device *sdev)
- {
-@@ -2436,52 +2524,37 @@ mptscsih_slave_configure(struct scsi_dev
-       VirtDevice              *vdevice;
-       struct scsi_target      *starget;
-       MPT_SCSI_HOST           *hd = shost_priv(sh);
--      MPT_ADAPTER             *ioc = hd->ioc;
-+      MPT_ADAPTER             *ioc = hd->ioc;
-       starget = scsi_target(sdev);
-       vtarget = starget->hostdata;
-       vdevice = sdev->hostdata;
-+      vdevice->configured_lun = 1;
--      dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--              "device @ %p, channel=%d, id=%d, lun=%d\n",
--              ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));
--      if (ioc->bus_type == SPI)
--              dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                  "sdtr %d wdtr %d ppr %d inq length=%d\n",
--                  ioc->name, sdev->sdtr, sdev->wdtr,
--                  sdev->ppr, sdev->inquiry_len));
-+      if ((ioc->bus_type != SAS) && (sdev->id > sh->max_id)) {
-+              /* error case, should never happen */
-+              scsi_adjust_queue_depth(sdev, 0, 1);
-+              goto slave_configure_exit;
-+      }
+-              if (!phy_info){
++              if (!phy_info) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                               "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                              __FUNCTION__, hot_plug_info->id, __LINE__));
++                              __func__, hot_plug_info->id, __LINE__));
+                       break;
+               }
  
--      vdevice->configured_lun = 1;
--      mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH);
-+      mptscsih_change_queue_depth(sdev, ioc->sdev_queue_depth);
+@@ -3654,7 +3816,7 @@ mptsas_hotplug_work(MPT_ADAPTER *ioc, st
+               if (!starget) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                               "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                              __FUNCTION__, hot_plug_info->id, __LINE__));
++                              __func__, hot_plug_info->id, __LINE__));
+                       break;
+               }
  
--      dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--              "Queue depth=%d, tflags=%x\n",
--              ioc->name, sdev->queue_depth, vtarget->tflags));
--
--      if (ioc->bus_type == SPI)
--              dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                  "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
--                  ioc->name, vtarget->negoFlags, vtarget->maxOffset,
--                  vtarget->minSyncFactor));
--
--      dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--              "tagged %d, simple %d, ordered %d\n",
--              ioc->name,sdev->tagged_supported, sdev->simple_tags,
--              sdev->ordered_tags));
-+slave_configure_exit:
+@@ -3662,7 +3824,7 @@ mptsas_hotplug_work(MPT_ADAPTER *ioc, st
+               if (!vtarget) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                               "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                              __FUNCTION__, hot_plug_info->id, __LINE__));
++                              __func__, hot_plug_info->id, __LINE__));
+                       break;
+               }
  
-       return 0;
- }
+@@ -3688,7 +3850,7 @@ mptsas_hotplug_work(MPT_ADAPTER *ioc, st
+                       (hot_plug_info->channel << 8) + hot_plug_info->id)) {
+                               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                                   "%s: fw_id=%d exit at line=%d\n",
+-                                  ioc->name, __FUNCTION__,
++                                  ioc->name, __func__,
+                                   hot_plug_info->id, __LINE__));
+                       break;
+               }
+@@ -3698,7 +3860,7 @@ mptsas_hotplug_work(MPT_ADAPTER *ioc, st
+               if (!phy_info) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                           "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                          __FUNCTION__, hot_plug_info->id, __LINE__));
++                          __func__, hot_plug_info->id, __LINE__));
+                       break;
+               }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-+/**
-  *  Private routines...
-  */
+@@ -3706,7 +3868,7 @@ mptsas_hotplug_work(MPT_ADAPTER *ioc, st
+               if (!starget) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                           "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                          __FUNCTION__, hot_plug_info->id, __LINE__));
++                          __func__, hot_plug_info->id, __LINE__));
+                       break;
+               }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/* Utility function to copy sense data from the scsi_cmnd buffer
-+/**
-+ * Utility function to copy sense data from the scsi_cmnd buffer
-  * to the FC and SCSI target structures.
-  *
-- */
-+ **/
- static void
- mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)
- {
-@@ -2521,31 +2594,31 @@ mptscsih_copy_sense_data(struct scsi_cmn
-                               ioc->events[idx].data[1] = (sense_data[13] << 8) | sense_data[12];
+@@ -3714,14 +3876,14 @@ mptsas_hotplug_work(MPT_ADAPTER *ioc, st
+               if (!vtarget) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                           "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                          __FUNCTION__, hot_plug_info->id, __LINE__));
++                          __func__, hot_plug_info->id, __LINE__));
+                       break;
+               }
  
-                               ioc->eventContext++;
--                              if (ioc->pcidev->vendor ==
--                                  PCI_VENDOR_ID_IBM) {
--                                      mptscsih_issue_sep_command(ioc,
--                                          vdevice->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
--                                      vdevice->vtarget->tflags |=
--                                          MPT_TARGET_FLAGS_LED_ON;
-+                              if (ioc->pcidev->vendor == PCI_VENDOR_ID_IBM) {
-+                                      mptscsih_issue_sep_command(ioc, vdevice->vtarget,
-+                                          MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
-+                                      vdevice->vtarget->tflags |= MPT_TARGET_FLAGS_LED_ON;
-                               }
-                       }
+               if (!(vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                           "%s: fw_id=%d exit at line=%d\n", ioc->name,
+-                          __FUNCTION__, hot_plug_info->id, __LINE__));
++                          __func__, hot_plug_info->id, __LINE__));
+                       break;
                }
-       } else {
-               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hmmm... SenseData len=0! (?)\n",
--                              ioc->name));
-+                  ioc->name));
+@@ -3800,7 +3962,7 @@ mptsas_send_sas_event(struct fw_event_wo
+       if ((device_info &
+            (MPI_SAS_DEVICE_INFO_SSP_TARGET |
+             MPI_SAS_DEVICE_INFO_STP_TARGET |
+-            MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0) {
++            MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) {
+               mptsas_free_fw_event(ioc, fw_event);
+               return;
        }
- }
+@@ -3840,9 +4002,7 @@ mptsas_send_sas_event(struct fw_event_wo
+               break;
  
- /**
-  * mptscsih_get_scsi_lookup
-- * @ioc: Pointer to MPT_ADAPTER structure
-- * @i: index into the array
-  *
-  * retrieves scmd entry from ScsiLookup[] array list
-  *
-+ * @ioc: Pointer to MPT_ADAPTER structure
-+ * @i: index into the array
-+ *
-  * Returns the scsi_cmd pointer
-+ *
-  **/
--static struct scsi_cmnd *
-+struct scsi_cmnd *
- mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i)
- {
-       unsigned long   flags;
-@@ -2560,12 +2633,14 @@ mptscsih_get_scsi_lookup(MPT_ADAPTER *io
+       case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
+-      /* TODO */
+       case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
+-      /* TODO */
+       default:
+               mptsas_free_fw_event(ioc, fw_event);
+               break;
+@@ -3892,7 +4052,7 @@ mptsas_send_raid_event(struct fw_event_w
+       }
  
- /**
-  * mptscsih_getclear_scsi_lookup
-- * @ioc: Pointer to MPT_ADAPTER structure
-- * @i: index into the array
-  *
-  * retrieves and clears scmd entry from ScsiLookup[] array list
+       devtprintk(ioc, printk(MYIOC_s_INFO_FMT "Entering %s: "
+-          "ReasonCode=%02x\n", ioc->name, __FUNCTION__,
++          "ReasonCode=%02x\n", ioc->name, __func__,
+           raid_event_data->ReasonCode));
+       switch (raid_event_data->ReasonCode) {
+@@ -3988,8 +4148,8 @@ mptsas_send_raid_event(struct fw_event_w
   *
-+ * @ioc: Pointer to MPT_ADAPTER structure
-+ * @i: index into the array
-+ *
-  * Returns the scsi_cmd pointer
-+ *
   **/
- static struct scsi_cmnd *
- mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i)
-@@ -2602,10 +2677,14 @@ mptscsih_set_scsi_lookup(MPT_ADAPTER *io
- }
- /**
-- * SCPNT_TO_LOOKUP_IDX - searches for a given scmd in the ScsiLookup[] array list
-+ * SCPNT_TO_LOOKUP_IDX
-+ *
-+ * search's for a given scmd in the ScsiLookup[] array list
-+ *
-  * @ioc: Pointer to MPT_ADAPTER structure
-- * @sc: scsi_cmnd pointer
-- */
-+ * @scmd: scsi_cmnd pointer
-+ *
-+ **/
  static int
- SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *sc)
+-mptsas_issue_tm(MPT_ADAPTER *ioc, u8 type, u8 channel, u8 id, u64 lun, int task_context, ulong timeout,
+-      u8 *issue_reset)
++mptsas_issue_tm(MPT_ADAPTER *ioc, u8 type, u8 channel, u8 id, u64 lun,
++    int task_context, ulong timeout, u8 *issue_reset)
  {
-@@ -2627,380 +2706,226 @@ SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, st
+       MPT_FRAME_HDR   *mf;
+       SCSITaskMgmt_t  *pScsiTm;
+@@ -4068,7 +4228,7 @@ mptsas_broadcast_primative_work(struct f
+       VirtDevice              *vdevice;
+       int                     ii;
+       struct scsi_cmnd        *sc;
+-      SCSITaskMgmtReply_t *   pScsiTmReply;
++      SCSITaskMgmtReply_t     *pScsiTmReply;
+       u8                      issue_reset;
+       int                     task_context;
+       u8                      channel, id;
+@@ -4077,7 +4237,7 @@ mptsas_broadcast_primative_work(struct f
+       u32                      query_count;
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-          "%s - enter\n", ioc->name, __FUNCTION__));
++          "%s - enter\n", ioc->name, __func__));
+       mutex_lock(&ioc->taskmgmt_cmds.mutex);
+       if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
+@@ -4133,7 +4293,7 @@ mptsas_broadcast_primative_work(struct f
+  out:
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+           "%s - exit, query_count = %d termination_count = %d\n",
+-          ioc->name, __FUNCTION__, query_count, termination_count));
++          ioc->name, __func__, query_count, termination_count));
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- int
--mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
-+mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
+       ioc->broadcast_aen_busy = 0;
+       mpt_clear_taskmgmt_in_progress_flag(ioc);
+@@ -4141,7 +4301,7 @@ mptsas_broadcast_primative_work(struct f
+       if (issue_reset) {
+               printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
+-                  ioc->name, __FUNCTION__);
++                  ioc->name, __func__);
+               if (mpt_SoftResetHandler(ioc, CAN_SLEEP))
+                       mpt_HardResetHandler(ioc, CAN_SLEEP);
+       }
+@@ -4159,7 +4319,7 @@ mptsas_send_ir2_event(struct fw_event_wo
  {
--      MPT_SCSI_HOST   *hd;
--      unsigned long    flags;
--
--      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--          ": IOC %s_reset routed to SCSI host driver!\n",
--          ioc->name, reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
--          reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
--
--      /* If a FW reload request arrives after base installed but
--       * before all scsi hosts have been attached, then an alt_ioc
--       * may have a NULL sh pointer.
--       */
--      if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL)
--              return 0;
--      else
--              hd = shost_priv(ioc->sh);
--
--      if (reset_phase == MPT_IOC_SETUP_RESET) {
--              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Setup-Diag Reset\n", ioc->name));
--
--              /* Clean Up:
--               * 1. Set Hard Reset Pending Flag
--               * All new commands go to doneQ
--               */
--              hd->resetPending = 1;
--
--      } else if (reset_phase == MPT_IOC_PRE_RESET) {
--              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Pre-Diag Reset\n", ioc->name));
--
--              /* 2. Flush running commands
--               *      Clean ScsiLookup (and associated memory)
--               *      AND clean mytaskQ
--               */
-+      u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
+       MPT_ADAPTER *ioc;
+       struct mptsas_hotplug_event hot_plug_info;
+-      MPI_EVENT_DATA_IR2 * ir2_data;
++      MPI_EVENT_DATA_IR2 *ir2_data;
+       u8 reasonCode;
+       RaidPhysDiskPage0_t phys_disk;
  
--              /* 2b. Reply to OS all known outstanding I/O commands.
--               */
--              mptscsih_flush_running_cmds(hd);
-+      devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "MPT event (=%02Xh) routed to SCSI host driver!\n",
-+          ioc->name, event));
--              /* 2c. If there was an internal command that
--               * has not completed, configuration or io request,
--               * free these resources.
--               */
--              if (hd->cmdPtr) {
--                      del_timer(&hd->timer);
--                      mpt_free_msg_frame(ioc, hd->cmdPtr);
--              }
-+      if ((event == MPI_EVENT_IOC_BUS_RESET ||
-+          event == MPI_EVENT_EXT_BUS_RESET) &&
-+          (ioc->bus_type == SPI) && (ioc->soft_resets < -1))
-+                      ioc->soft_resets++;
+@@ -4168,7 +4328,7 @@ mptsas_send_ir2_event(struct fw_event_wo
+       reasonCode = ir2_data->ReasonCode;
  
--              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Pre-Reset complete.\n", ioc->name));
-+      return 1;               /* currently means nothing really */
-+}
+       devtprintk(ioc, printk(MYIOC_s_INFO_FMT "Entering %s: "
+-          "ReasonCode=%02x\n", ioc->name,__FUNCTION__, reasonCode));
++          "ReasonCode=%02x\n", ioc->name, __func__, reasonCode));
  
--      } else {
--              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Post-Diag Reset\n", ioc->name));
-+int
-+mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id)
-+{
-+      MPT_ADAPTER             *ioc = hd->ioc;
-+      MpiRaidActionRequest_t  *pReq;
-+      MPT_FRAME_HDR           *mf;
-+      int                     ret;
-+      unsigned long           timeleft;
--              /* Once a FW reload begins, all new OS commands are
--               * redirected to the doneQ w/ a reset status.
--               * Init all control structures.
--               */
-+      mutex_lock(&ioc->internal_cmds.mutex);
+       memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
+       hot_plug_info.id = ir2_data->TargetID;
+@@ -4255,7 +4415,7 @@ mptsas_expander_refresh(MPT_ADAPTER *ioc
  
--              /* 2. Chain Buffer initialization
--               */
-+      /* Get and Populate a free Frame
-+       */
-+      if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
-+              dfailprintk(hd->ioc, printk(MYIOC_s_WARN_FMT "%s: no msg frames!\n",
-+                      ioc->name, __FUNCTION__));
-+              ret = -EAGAIN;
-+              goto out;
-+      }
-+      pReq = (MpiRaidActionRequest_t *)mf;
-+      if (quiesce)
-+              pReq->Action = MPI_RAID_ACTION_QUIESCE_PHYS_IO;
-+      else
-+              pReq->Action = MPI_RAID_ACTION_ENABLE_PHYS_IO;
-+      pReq->Reserved1 = 0;
-+      pReq->ChainOffset = 0;
-+      pReq->Function = MPI_FUNCTION_RAID_ACTION;
-+      pReq->VolumeID = id;
-+      pReq->VolumeBus = channel;
-+      pReq->PhysDiskNum = 0;
-+      pReq->MsgFlags = 0;
-+      pReq->Reserved2 = 0;
-+      pReq->ActionDataWord = 0; /* Reserved for this action */
--              /* 4. Renegotiate to all devices, if SPI
--               */
-+      ioc->add_sge((char *)&pReq->ActionDataSGE,
-+              MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
+ static void
+ mptsas_expander_event_add(MPT_ADAPTER *ioc,
+-    MpiEventDataSasExpanderStatusChange_t* expander_data)
++    MpiEventDataSasExpanderStatusChange_t *expander_data)
+ {
+       struct mptsas_portinfo *port_info;
+       int i;
+@@ -4267,7 +4427,7 @@ mptsas_expander_event_add(MPT_ADAPTER *i
+       port_info->num_phys = (expander_data->NumPhys) ?
+           expander_data->NumPhys : 1;
+       port_info->phy_info = kcalloc(port_info->num_phys,
+-          sizeof(struct mptsas_phyinfo),GFP_KERNEL);
++          sizeof(struct mptsas_phyinfo), GFP_KERNEL);
+       if (!port_info->phy_info)
+               BUG();
+       memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
+@@ -4351,8 +4511,8 @@ mptsas_expander_delete(MPT_ADAPTER *ioc,
+       u64             expander_sas_address;
+       struct mptsas_phyinfo *phy_info;
+       struct mptsas_portinfo buffer;
+-      struct mptsas_portinfo_details * port_details;
+-      struct sas_port * port;
++      struct mptsas_portinfo_details *port_details;
++      struct sas_port *port;
  
--              /* 5. Enable new commands to be posted
--               */
--              spin_lock_irqsave(&ioc->FreeQlock, flags);
--              hd->tmPending = 0;
--              spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--              hd->resetPending = 0;
--              hd->tmState = TM_STATE_NONE;
-+      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RAID Volume action=%x channel=%d id=%d\n",
-+                      ioc->name, pReq->Action, channel, id));
--              /* 6. If there was an internal command,
--               * wake this process up.
--               */
--              if (hd->cmdPtr) {
--                      /*
--                       * Wake up the original calling thread
--                       */
--                      hd->pLocal = &hd->localReply;
--                      hd->pLocal->completion = MPT_SCANDV_DID_RESET;
--                      hd->scandv_wait_done = 1;
--                      wake_up(&hd->scandv_waitq);
--                      hd->cmdPtr = NULL;
-+      INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)
-+      mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
-+      timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done, 10*HZ);
-+      if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              ret = -ETIME;
-+              dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: TIMED OUT!\n",
-+                  ioc->name, __FUNCTION__));
-+              if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
-+                      goto out;
-+              if (!timeleft) {
-+                      printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
-+                          ioc->name, __FUNCTION__);
-+                      if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
-+                              mpt_HardResetHandler(ioc, CAN_SLEEP);
-+                      mpt_free_msg_frame(ioc, mf);
-               }
--
--              dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Post-Reset complete.\n", ioc->name));
--
-+              goto out;
+       if (!port_info)
+               return;
+@@ -4388,7 +4548,7 @@ mptsas_expander_delete(MPT_ADAPTER *ioc,
+       phy_info = parent->phy_info;
+       port = NULL;
+       for (i = 0; i < parent->num_phys; i++, phy_info++) {
+-              if(!phy_info->phy)
++              if (!phy_info->phy)
+                       continue;
+               if (phy_info->attached.sas_address !=
+                   expander_sas_address)
+@@ -4438,7 +4598,7 @@ static void
+ mptsas_send_expander_event(struct fw_event_work *fw_event)
+ {
+       MPT_ADAPTER *ioc;
+-      MpiEventDataSasExpanderStatusChange_t* expander_data;
++      MpiEventDataSasExpanderStatusChange_t *expander_data;
+       struct mptsas_portinfo *port_info;
+       __le64 sas_address;
+       int i;
+@@ -4492,7 +4652,7 @@ mptsas_expander_add(MPT_ADAPTER *ioc, u1
+       if (!port_info) {
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+               "%s: exit at line=%d\n", ioc->name,
+-              __FUNCTION__, __LINE__));
++              __func__, __LINE__));
+               return NULL;
        }
+       port_info->num_phys = buffer.num_phys;
+@@ -4589,7 +4749,7 @@ mptsas_handle_queue_full_event(struct fw
+       current_depth = le16_to_cpu(qfull_data->CurrentDepth);
  
--      return 1;               /* currently means nothing really */
-+      ret = ioc->internal_cmds.completion_code;
-+
-+ out:
-+      CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
-+      mutex_unlock(&ioc->internal_cmds.mutex);
-+      return ret;
- }
+       /* if hidden raid component, look for the volume id */
+-      down(&ioc->sas_device_info_mutex);
++      mutex_lock(&ioc->sas_device_info_mutex);
+       if (mptscsih_is_phys_disk(ioc, fw_channel, fw_id)) {
+               list_for_each_entry(sas_info, &ioc->sas_device_info_list,
+                   list) {
+@@ -4622,7 +4782,7 @@ mptsas_handle_queue_full_event(struct fw
      }
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--int
--mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
-+/**
-+ *    mptscsih_get_completion_code -
-+ *    @ioc: Pointer to MPT_ADAPTER structure
-+ *    @reply:
-+ *    @cmd:
-+ *
-+ **/
-+static int
-+mptscsih_get_completion_code(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
- {
--      MPT_SCSI_HOST *hd;
--      u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
-+      SCSIIOReply_t   *pReply;
-+      MpiRaidActionReply_t *pr;
-+      u8               scsi_status;
-+      u16              status;
-+      int              completion_code;
--      devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
--                      ioc->name, event));
-+      pReply = (SCSIIOReply_t *)reply;
-+      status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
-+      scsi_status = pReply->SCSIStatus;
--      if (ioc->sh == NULL ||
--              ((hd = shost_priv(ioc->sh)) == NULL))
--              return 1;
-+      devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh, IOCLogInfo=%08xh\n",
-+           ioc->name, status, pReply->SCSIState, scsi_status, le32_to_cpu(pReply->IOCLogInfo)));
--      switch (event) {
--      case MPI_EVENT_UNIT_ATTENTION:                  /* 03 */
--              /* FIXME! */
--              break;
--      case MPI_EVENT_IOC_BUS_RESET:                   /* 04 */
--      case MPI_EVENT_EXT_BUS_RESET:                   /* 05 */
--              if (hd && (ioc->bus_type == SPI) && (hd->soft_resets < -1))
--                      hd->soft_resets++;
--              break;
--      case MPI_EVENT_LOGOUT:                          /* 09 */
--              /* FIXME! */
-+      switch(status) {
-+
-+      case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:       /* 0x0043 */
-+              completion_code = MPT_SCANDV_SELECTION_TIMEOUT;
-               break;
+  out:
+-      up(&ioc->sas_device_info_mutex);
++      mutex_unlock(&ioc->sas_device_info_mutex);
  
--      case MPI_EVENT_RESCAN:                          /* 06 */
-+      case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR:          /* 0x0046 */
-+      case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:        /* 0x0048 */
-+      case MPI_IOCSTATUS_SCSI_IOC_TERMINATED:         /* 0x004B */
-+      case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:         /* 0x004C */
-+              completion_code = MPT_SCANDV_DID_RESET;
-               break;
+       if (id != -1) {
+               shost_for_each_device(sdev, ioc->sh) {
+@@ -4643,8 +4803,8 @@ mptsas_handle_queue_full_event(struct fw
+                                          depth);
+                               else if (depth < 0)
+                                       sdev_printk(KERN_INFO, sdev,
+-                                      "Tagged Command Queueing is being "
+-                                      "disabled\n");
++                                          "Tagged Command Queueing is being "
++                                          "disabled\n");
+                               else if (depth == 0)
+                                       sdev_printk(KERN_INFO, sdev,
+                                       "Queue depth not changed yet\n");
+@@ -4671,7 +4831,7 @@ mptsas_firmware_event_work(struct work_s
+       /* special rescan topology handling */
+       if (fw_event->event == -1) {
+               devtprintk(ioc, printk(MYIOC_s_INFO_FMT "%s: rescan after "
+-                  "reset\n", ioc->name,__FUNCTION__));
++                  "reset\n", ioc->name, __func__));
+               mptsas_not_responding_devices(ioc);
+               mptsas_scan_sas_topology(ioc);
+               mptsas_free_fw_event(ioc, fw_event);
+@@ -4685,7 +4845,7 @@ mptsas_firmware_event_work(struct work_s
+       }
+       devtprintk(ioc, printk(MYIOC_s_INFO_FMT "%s: fw_event=(0x%p), "
+-          "event = (0x%02x)\n", ioc->name,__FUNCTION__, fw_event,
++          "event = (0x%02x)\n", ioc->name, __func__, fw_event,
+           (fw_event->event & 0xFF)));
+       switch (fw_event->event) {
+@@ -4805,7 +4965,7 @@ mptsas_event_process(MPT_ADAPTER *ioc, E
+       fw_event = kzalloc(sz, GFP_ATOMIC);
+       if (!fw_event) {
+               printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name,
+-                  __FUNCTION__, __LINE__);
++                  __func__, __LINE__);
+               return 0;
+       }
+       memcpy(fw_event->event_data, reply->Data, event_data_sz);
+@@ -4835,7 +4995,7 @@ static void mptsas_volume_delete(MPT_ADA
+                       goto release_sdev;
+  out:
+       printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
+-          "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,id);
++          "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, id);
+       scsi_remove_device(sdev);
+  release_sdev:
+       scsi_device_put(sdev);
+@@ -4953,7 +5113,7 @@ mptsas_probe_expanders(MPT_ADAPTER *ioc)
+               if (!port_info) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                       "%s: exit at line=%d\n", ioc->name,
+-                      __FUNCTION__, __LINE__));
++                      __func__, __LINE__));
+                       return;
+               }
+               port_info->num_phys = buffer.num_phys;
+@@ -5000,7 +5160,7 @@ mptsas_probe_devices(MPT_ADAPTER *ioc)
+               state = DEVICE_RETRY;
+               retry_count = 0;
+-              while(state == DEVICE_RETRY) {
++              while (state == DEVICE_RETRY) {
+                       state = mptsas_test_unit_ready(ioc, sas_device.channel,
+                           sas_device.id, retry_count++);
+                       ssleep(1);
+@@ -5032,7 +5192,7 @@ mptsas_scan_sas_topology(MPT_ADAPTER *io
+       if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 ||
+           !ioc->raid_data.pIocPg2->NumActiveVolumes)
+               return;
+-      for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
++      for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
+               if ((sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
+                   ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0))) {
+                       scsi_device_put(sdev);
+@@ -5196,11 +5356,12 @@ mptsas_probe(struct pci_dev *pdev, const
+       hd->last_queue_full = 0;
+       ioc->disable_hotplug_remove = mpt_disable_hotplug_remove;
+       if (ioc->disable_hotplug_remove)
+-              printk(MYIOC_s_INFO_FMT "disabling hotplug remove\n", ioc->name);
++              printk(MYIOC_s_INFO_FMT
++                  "disabling hotplug remove\n", ioc->name);
  
--              /*
--               *  CHECKME! Don't think we need to do
--               *  anything for these, but...
--               */
--      case MPI_EVENT_LINK_STATUS_CHANGE:              /* 07 */
--      case MPI_EVENT_LOOP_STATE_CHANGE:               /* 08 */
--              /*
--               *  CHECKME!  Falling thru...
--               */
-+      case MPI_IOCSTATUS_BUSY:
-+      case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:
-+              completion_code = MPT_SCANDV_BUSY;
-               break;
+       INIT_LIST_HEAD(&hd->target_reset_list);
+       INIT_LIST_HEAD(&ioc->sas_device_info_list);
+-      init_MUTEX(&ioc->sas_device_info_mutex);
++      mutex_init(&ioc->sas_device_info_mutex);
  
--      case MPI_EVENT_INTEGRATED_RAID:                 /* 0B */
-+      case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:          /* 0x0045 */
-+      case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR:        /* 0x0040 */
-+      case MPI_IOCSTATUS_SUCCESS:                     /* 0x0000 */
-+              if (pReply->Function == MPI_FUNCTION_CONFIG) {
-+                      completion_code = MPT_SCANDV_GOOD;
-+              } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
-+                      pr = (MpiRaidActionReply_t *)reply;
-+                      if (le16_to_cpu(pr->ActionStatus) == MPI_RAID_ACTION_ASTATUS_SUCCESS)
-+                              completion_code = MPT_SCANDV_GOOD;
-+                      else
-+                              completion_code = MPT_SCANDV_SOME_ERROR;
-+              } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)
-+                      completion_code = MPT_SCANDV_SENSE;
-+              else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
-+                      if (req->u.scsireq.CDB[0] == INQUIRY)
-+                              completion_code = MPT_SCANDV_ISSUE_SENSE;
-+                      else
-+                              completion_code = MPT_SCANDV_DID_RESET;
-+              }
-+              else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
-+                      completion_code = MPT_SCANDV_DID_RESET;
-+              else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
-+                      completion_code = MPT_SCANDV_DID_RESET;
-+              else if (scsi_status == MPI_SCSI_STATUS_BUSY)
-+                      completion_code = MPT_SCANDV_BUSY;
-+              else
-+                      completion_code = MPT_SCANDV_GOOD;
-               break;
+       spin_unlock_irqrestore(&ioc->FreeQlock, flags);
+Index: linux-2.6.27/drivers/message/fusion/mptsas.h
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/mptsas.h
++++ linux-2.6.27/drivers/message/fusion/mptsas.h
+@@ -84,9 +84,12 @@ struct sas_device_info {
+       u16                     slot;           /* enclosure slot id */
+       u64                     enclosure_logical_id; /*enclosure address */
+       u8                      is_logical_volume; /* is this logical volume */
+-      u8                      is_hidden_raid_component; /* this belongs to volume */
+-      u8                      volume_id; /* this valid when is_hidden_raid_component set */
+-      u8                      is_cached;      /* cached data for a removed device */
++      /* this belongs to volume */
++      u8                      is_hidden_raid_component;
++      /* this valid when is_hidden_raid_component set */
++      u8                      volume_id;
++      /* cached data for a removed device */
++      u8                      is_cached;
+ };
+ struct mptsas_hotplug_event {
+Index: linux-2.6.27/drivers/message/fusion/mptscsih.c
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/mptscsih.c
++++ linux-2.6.27/drivers/message/fusion/mptscsih.c
+@@ -102,7 +102,8 @@ static void        mptscsih_copy_sense_data(str
+ int           mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
+ int           mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
+-static void   mptscsih_synchronize_cache(struct scsi_device *sdev, MPT_SCSI_HOST *hd, VirtDevice *vdevice);
++static void   mptscsih_synchronize_cache(struct scsi_device *sdev,
++    MPT_SCSI_HOST *hd, VirtDevice *vdevice);
+ void          mptscsih_remove(struct pci_dev *);
+ void          mptscsih_shutdown(struct pci_dev *);
+@@ -142,12 +143,16 @@ mptscsih_getFreeChainBuffer(MPT_ADAPTER 
+               offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
+               chain_idx = offset / ioc->req_sz;
+               rc = SUCCESS;
+-              dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
+-                      ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
++              dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++                      "getFreeChainBuffer chainBuf=%p ChainBuffer=%p"
++                      " offset=%d chain_idx=%d\n",
++                      ioc->name, chainBuf, ioc->ChainBuffer, offset,
++                      chain_idx));
+       } else {
+               rc = FAILED;
+               chain_idx = MPT_HOST_NO_CHAIN;
+-              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n",
++              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
++                      "getFreeChainBuffer failed\n",
+                       ioc->name));
+       }
+       spin_unlock_irqrestore(&ioc->FreeQlock, flags);
+@@ -216,7 +221,7 @@ mptscsih_AddSGE(MPT_ADAPTER *ioc, struct
+        */
+ nextSGEset:
+-      numSgeSlots = ((frm_sz - sgeOffset) / ioc->SGE_size );
++      numSgeSlots = ((frm_sz - sgeOffset) / ioc->SGE_size);
+       numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;
+       sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | sgdir;
+@@ -265,7 +270,8 @@ nextSGEset:
+                        * Update the chain element
+                        * Offset and Length fields.
+                        */
+-                      ioc->add_chain((char *)chainSge, 0, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
++                      ioc->add_chain((char *)chainSge, 0, sgeOffset,
++                          ioc->ChainBufferDMA + chain_dma_off);
+               } else {
+                       /* The current buffer is the original MF
+                        * and there is no Chain buffer.
+@@ -313,7 +319,8 @@ nextSGEset:
+                        */
+                       u8 nextChain = (u8) (sgeOffset >> 2);
+                       sgeOffset += ioc->SGE_size;
+-                      ioc->add_chain((char *)chainSge, nextChain, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
++                      ioc->add_chain((char *)chainSge, nextChain, sgeOffset,
++                         ioc->ChainBufferDMA + chain_dma_off);
+               } else {
+                       /* The original MF buffer requires a chain buffer -
+                        * set the offset.
+@@ -392,7 +399,7 @@ mptscsih_issue_sep_command(MPT_ADAPTER *
+       if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
+               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: no msg frames!!\n",
+-                  ioc->name,__FUNCTION__));
++                  ioc->name,__func__));
+               return;
+       }
  
--      case MPI_EVENT_NONE:                            /* 00 */
--      case MPI_EVENT_LOG_DATA:                        /* 01 */
--      case MPI_EVENT_STATE_CHANGE:                    /* 02 */
--      case MPI_EVENT_EVENT_CHANGE:                    /* 0A */
-+      case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR:         /* 0x0047 */
-+              if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
-+                      completion_code = MPT_SCANDV_DID_RESET;
-+              else
-+                      completion_code = MPT_SCANDV_SOME_ERROR;
-+              break;
-       default:
--              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": Ignoring event (=%02Xh)\n",
--                  ioc->name, event));
-+              completion_code = MPT_SCANDV_SOME_ERROR;
-               break;
--      }
+@@ -525,9 +532,11 @@ mptscsih_info_scsiio(MPT_ADAPTER *ioc, s
+       scsi_print_command(sc);
+       printk(MYIOC_s_DEBUG_FMT "\tfw_channel = %d, fw_id = %d, lun = %d\n",
+           ioc->name, pScsiReply->Bus, pScsiReply->TargetID, sc->device->lun);
+-      printk(MYIOC_s_DEBUG_FMT "\trequest_len = %d, underflow = %d, resid = %d\n",
++      printk(MYIOC_s_DEBUG_FMT
++          "\trequest_len = %d, underflow = %d, resid = %d\n",
+              ioc->name, scsi_bufflen(sc), sc->underflow, scsi_get_resid(sc));
+-      printk(MYIOC_s_DEBUG_FMT "\ttag = %d, transfer_count = %d, sc->result = %08X\n",
++      printk(MYIOC_s_DEBUG_FMT
++          "\ttag = %d, transfer_count = %d, sc->result = %08X\n",
+           ioc->name, le16_to_cpu(pScsiReply->TaskTag),
+           le32_to_cpu(pScsiReply->TransferCount), sc->result);
  
--      return 1;               /* currently means nothing really */
--}
-+      }       /* switch(status) */
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-- *  Bus Scan and Domain Validation functionality ...
-- */
-+      devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "  completionCode set to %08xh\n", ioc->name, completion_code));
-+      return completion_code;
-+}
+@@ -590,7 +599,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
+           (le32_to_cpu(mf->u.frame.linkage.arg1) == 0xdeadbeaf)) {
+               printk(MYIOC_s_WARN_FMT
+                   "Received a mf that was already freed\n", ioc->name);
+-              printk (MYIOC_s_WARN_FMT
++              printk(MYIOC_s_WARN_FMT
+                   "req_idx=%x req_idx_MR=%x mf=%p mr=%p sc=%p\n",
+                   ioc->name, req_idx, req_idx_MR, mf, mr,
+                   mptscsih_get_scsi_lookup(ioc, req_idx_MR));
+@@ -715,11 +724,12 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
+                                       }
+                               }
+                       } else if (ioc->bus_type == FC) {
+-                              /* The FC IOC may kill a request for variety of reasons,
+-                              some of which may be recovered by a retry, some which
+-                              are unlikely to be recovered. Return DID_ERROR instead
+-                              of DID_RESET to permit retry of the command, just not
+-                              an infinite number of them */
++                              /* The FC IOC may kill a request for variety
++                               * of reasons, some of which may be recovered
++                               *  by a retry, some which are unlikely to be
++                               *  recovered. Return DID_ERROR instead of
++                               *  DID_RESET to permit retry of the command,
++                               *  just not an infinite number of them */
+                               sc->result = DID_ERROR << 16;
+                               break;
+                       }
+@@ -735,7 +745,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_F
+                       sc->result = DID_RESET << 16;
  
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-- *    mptscsih_scandv_complete - Scan and DV callback routine registered
-- *    to Fustion MPT (base) driver.
-- *
-+/**
-+ *    mptscsih_scandv_complete -
-  *    @ioc: Pointer to MPT_ADAPTER structure
-- *    @mf: Pointer to original MPT request frame
-- *    @mr: Pointer to MPT reply frame (NULL if TurboReply)
-+ *    @req:
-+ *    @reply:
-  *
-- *    This routine is called from mpt.c::mpt_interrupt() at the completion
-- *    of any SCSI IO request.
-- *    This routine is registered with the Fusion MPT (base) driver at driver
-- *    load/init time via the mpt_register() API call.
-- *
-- *    Returns 1 indicating alloc'd request frame ptr should be freed.
-- *
-- *    Remark: Sets a completion code and (possibly) saves sense data
-- *    in the IOC member localReply structure.
-- *    Used ONLY for DV and other internal commands.
-- */
-+ **/
- int
--mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
-+mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
- {
--      MPT_SCSI_HOST   *hd;
-       SCSIIORequest_t *pReq;
--      int              completionCode;
-+      SCSIIOReply_t   *pReply;
-+      u8               cmd;
-       u16              req_idx;
-+      u8              *sense_data;
-+      int              sz;
--      hd = shost_priv(ioc->sh);
--
--      if ((mf == NULL) ||
--          (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
--              printk(MYIOC_s_ERR_FMT
--                      "ScanDvComplete, %s req frame ptr! (=%p)\n",
--                              ioc->name, mf?"BAD":"NULL", (void *) mf);
--              goto wakeup;
--      }
--
--      del_timer(&hd->timer);
--      req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
--      mptscsih_set_scsi_lookup(ioc, req_idx, NULL);
--      pReq = (SCSIIORequest_t *) mf;
-+      ioc->internal_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
-+      ioc->internal_cmds.completion_code = MPT_SCANDV_GOOD;
-+      if (!reply)
-+              goto out;
+               case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:         /* 0x004C */
+-                      if ( ioc->bus_type == FC )
++                      if (ioc->bus_type == FC)
+                               sc->result = DID_ERROR << 16;
+                       else
+                               sc->result = DID_RESET << 16;
+@@ -1421,8 +1431,8 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, v
+        */
+       if (datalen == 0) {
+               /* Add a NULL SGE */
+-              ioc->add_sge((char *)&pScsiReq->SGL, MPT_SGE_FLAGS_SSIMPLE_READ | 0,
+-                      (dma_addr_t) -1);
++              ioc->add_sge((char *)&pScsiReq->SGL,
++                  MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
+       } else {
+               /* Add a 32 or 64 bit SGE */
+               if (mptscsih_AddSGE(ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
+@@ -1523,8 +1533,8 @@ mptscsih_scandv_bus_reset(MPT_ADAPTER *i
+       /* Send request
+        */
+       if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
+-              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt, no msg frames!!\n",
+-                              ioc->name));
++              dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
++                      "TaskMgmt, no msg frames!!\n", ioc->name));
+               mpt_clear_taskmgmt_in_progress_flag(ioc);
+               retval = -ENOMEM;
+               goto out;
+@@ -1544,26 +1554,27 @@ mptscsih_scandv_bus_reset(MPT_ADAPTER *i
+       pScsiTm->Reserved = 0;
+       pScsiTm->Reserved1 = 0;
+       pScsiTm->TaskMsgContext = 0;
+-      for (ii= 0; ii < 8; ii++)
++      for (ii = 0; ii < 8; ii++)
+               pScsiTm->LUN[ii] = 0;
+-      for (ii=0; ii < 7; ii++)
++      for (ii = 0; ii < 7; ii++)
+               pScsiTm->Reserved2[ii] = 0;
  
--      if (mf != hd->cmdPtr) {
--              printk(MYIOC_s_WARN_FMT "ScanDvComplete (mf=%p, cmdPtr=%p, idx=%d)\n",
--                              ioc->name, (void *)mf, (void *) hd->cmdPtr, req_idx);
-+      pReply = (SCSIIOReply_t *) reply;
-+      pReq = (SCSIIORequest_t *) req;
-+      ioc->internal_cmds.completion_code =
-+          mptscsih_get_completion_code(ioc, req, reply);
-+      ioc->internal_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
-+      memcpy(ioc->internal_cmds.reply, reply,
-+          min(MPT_DEFAULT_FRAME_SIZE, 4 * reply->u.reply.MsgLength));
-+      cmd = reply->u.hdr.Function;
-+      if (((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
-+          (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) &&
-+          (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
-+              req_idx = le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
-+              sense_data = ((u8 *)ioc->sense_buf_pool +
-+                  (req_idx * MPT_SENSE_BUFFER_ALLOC));
-+              sz = min_t(int, pReq->SenseBufferLength,
-+                  MPT_SENSE_BUFFER_ALLOC);
-+              memcpy(ioc->internal_cmds.sense, sense_data, sz);
-       }
--      hd->cmdPtr = NULL;
--
--      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScanDvComplete (mf=%p,mr=%p,idx=%d)\n",
--                      ioc->name, mf, mr, req_idx));
--
--      hd->pLocal = &hd->localReply;
--      hd->pLocal->scsiStatus = 0;
--
--      /* If target struct exists, clear sense valid flag.
--       */
--      if (mr == NULL) {
--              completionCode = MPT_SCANDV_GOOD;
--      } else {
--              SCSIIOReply_t   *pReply;
--              u16              status;
--              u8               scsi_status;
--
--              pReply = (SCSIIOReply_t *) mr;
--
--              status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
--              scsi_status = pReply->SCSIStatus;
--
--
--              switch(status) {
--
--              case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:       /* 0x0043 */
--                      completionCode = MPT_SCANDV_SELECTION_TIMEOUT;
--                      break;
--
--              case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR:          /* 0x0046 */
--              case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:        /* 0x0048 */
--              case MPI_IOCSTATUS_SCSI_IOC_TERMINATED:         /* 0x004B */
--              case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:         /* 0x004C */
--                      completionCode = MPT_SCANDV_DID_RESET;
--                      break;
--
--              case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:          /* 0x0045 */
--              case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR:        /* 0x0040 */
--              case MPI_IOCSTATUS_SUCCESS:                     /* 0x0000 */
--                      if (pReply->Function == MPI_FUNCTION_CONFIG) {
--                              ConfigReply_t *pr = (ConfigReply_t *)mr;
--                              completionCode = MPT_SCANDV_GOOD;
--                              hd->pLocal->header.PageVersion = pr->Header.PageVersion;
--                              hd->pLocal->header.PageLength = pr->Header.PageLength;
--                              hd->pLocal->header.PageNumber = pr->Header.PageNumber;
--                              hd->pLocal->header.PageType = pr->Header.PageType;
--
--                      } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
--                              /* If the RAID Volume request is successful,
--                               * return GOOD, else indicate that
--                               * some type of error occurred.
--                               */
--                              MpiRaidActionReply_t    *pr = (MpiRaidActionReply_t *)mr;
--                              if (le16_to_cpu(pr->ActionStatus) == MPI_RAID_ACTION_ASTATUS_SUCCESS)
--                                      completionCode = MPT_SCANDV_GOOD;
--                              else
--                                      completionCode = MPT_SCANDV_SOME_ERROR;
--                              memcpy(hd->pLocal->sense, pr, sizeof(hd->pLocal->sense));
--
--                      } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
--                              u8              *sense_data;
--                              int              sz;
--
--                              /* save sense data in global structure
--                               */
--                              completionCode = MPT_SCANDV_SENSE;
--                              hd->pLocal->scsiStatus = scsi_status;
--                              sense_data = ((u8 *)ioc->sense_buf_pool +
--                                      (req_idx * MPT_SENSE_BUFFER_ALLOC));
--
--                              sz = min_t(int, pReq->SenseBufferLength,
--                                                      SCSI_STD_SENSE_BYTES);
--                              memcpy(hd->pLocal->sense, sense_data, sz);
--
--                              ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "  Check Condition, sense ptr %p\n",
--                                  ioc->name, sense_data));
--                      } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
--                              if (pReq->CDB[0] == INQUIRY)
--                                      completionCode = MPT_SCANDV_ISSUE_SENSE;
--                              else
--                                      completionCode = MPT_SCANDV_DID_RESET;
--                      }
--                      else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
--                              completionCode = MPT_SCANDV_DID_RESET;
--                      else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
--                              completionCode = MPT_SCANDV_DID_RESET;
--                      else {
--                              completionCode = MPT_SCANDV_GOOD;
--                              hd->pLocal->scsiStatus = scsi_status;
--                      }
+       switch (ioc->bus_type) {
+-              case FC:
+-                      timeout = 40;
 -                      break;
--
--              case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR:         /* 0x0047 */
--                      if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
--                              completionCode = MPT_SCANDV_DID_RESET;
--                      else
--                              completionCode = MPT_SCANDV_SOME_ERROR;
+-              case SAS:
+-                      timeout = 30;
 -                      break;
--
+-              case SPI:
 -              default:
--                      completionCode = MPT_SCANDV_SOME_ERROR;
+-                      timeout = 2;
 -                      break;
--
--              }       /* switch(status) */
--
--      } /* end of address reply case */
--
--      hd->pLocal->completion = completionCode;
--
--      /* MF and RF are freed in mpt_interrupt
--       */
--wakeup:
--      /* Free Chain buffers (will never chain) in scan or dv */
--      //mptscsih_freeChainBuffers(ioc, req_idx);
--
--      /*
--       * Wake up the original calling thread
--       */
--      hd->scandv_wait_done = 1;
--      wake_up(&hd->scandv_waitq);
--
-+ out:
-+      if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING))
-+              return 0;
-+      ioc->internal_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
-+      complete(&ioc->internal_cmds.done);
-       return 1;
++      case FC:
++              timeout = 40;
++              break;
++      case SAS:
++              timeout = 30;
++              break;
++      case SPI:
++      default:
++              timeout = 10;
++              break;
+       }
+-      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt type=%d timeout=%ld\n",
+-          ioc->name, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, timeout));
++      dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++              "TaskMgmt type=%d timeout=%ld\n", ioc->name,
++              MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, timeout));
+       INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
+       CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
+@@ -1576,7 +1587,8 @@ mptscsih_scandv_bus_reset(MPT_ADAPTER *i
+               retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,
+                   sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
+               if (retval != 0) {
+-                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "TaskMgmt send_handshake FAILED!"
++                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
++                              "TaskMgmt send_handshake FAILED!"
+                               " (ioc %p, mf %p, rc=%d) \n", ioc->name,
+                               ioc, mf, retval));
+                       mpt_clear_taskmgmt_in_progress_flag(ioc);
+@@ -1642,19 +1654,20 @@ mptscsih_ioc_reset(MPT_ADAPTER *ioc, int
+       switch (reset_phase) {
+       case MPT_IOC_SETUP_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
+               break;
+       case MPT_IOC_PRE_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
+               hd = shost_priv(ioc->sh);
+               mptscsih_flush_running_cmds(hd);
+               break;
+       case MPT_IOC_POST_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: MPT_IOC_POST_RESET\n", ioc->name, __FUNCTION__));
++                  "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
+               if (ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING) {
+-                      ioc->internal_cmds.status |= MPT_MGMT_STATUS_DID_IOCRESET;
++                      ioc->internal_cmds.status
++                          |= MPT_MGMT_STATUS_DID_IOCRESET;
+                       complete(&ioc->internal_cmds.done);
+               }
+               break;
+@@ -1700,7 +1713,8 @@ mptscsih_taskmgmt_response_code(MPT_ADAP
  }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*    mptscsih_timer_expired - Call back for timer process.
-- *    Used only for dv functionality.
-- *    @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
-- *
-- */
--void
--mptscsih_timer_expired(unsigned long data)
--{
--      MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) data;
--      MPT_ADAPTER     *ioc = hd->ioc;
--
--      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Timer Expired! Cmd %p\n", ioc->name, hd->cmdPtr));
--
--      if (hd->cmdPtr) {
--              MPIHeader_t *cmd = (MPIHeader_t *)hd->cmdPtr;
--
--              if (cmd->Function == MPI_FUNCTION_SCSI_IO_REQUEST) {
--                      /* Desire to issue a task management request here.
--                       * TM requests MUST be single threaded.
--                       * If old eh code and no TM current, issue request.
--                       * If new eh code, do nothing. Wait for OS cmd timeout
--                       *      for bus reset.
--                       */
--              } else {
--                      /* Perform a FW reload */
--                      if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0) {
--                              printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
--                      }
--              }
--      } else {
--              /* This should NEVER happen */
--              printk(MYIOC_s_WARN_FMT "Null cmdPtr!!!!\n", ioc->name);
--      }
--
--      /* No more processing.
--       * TM call will generate an interrupt for SCSI TM Management.
--       * The FW will reply to all outstanding commands, callback will finish cleanup.
--       * Hard reset clean-up will free all resources.
--       */
--      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Timer Expired Complete!\n", ioc->name));
--
--      return;
--}
--
--
--/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mptscsih_do_cmd - Do internal command.
-  *    @hd: MPT_SCSI_HOST pointer
-@@ -3019,28 +2944,33 @@ mptscsih_timer_expired(unsigned long dat
-  *               0 if good
+ static int
+-mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type, SCSITaskMgmtReply_t *pScsiTmReply)
++mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type,
++    SCSITaskMgmtReply_t *pScsiTmReply)
+ {
+       u16                      iocstatus;
+       u32                      termination_count;
+@@ -1764,7 +1778,8 @@ mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc
+  *    Returns 1 indicating alloc'd request frame ptr should be freed.
+  **/
+ int
+-mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
++mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf,
++    MPT_FRAME_HDR *mr)
+ {
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed (mf=%p, mr=%p)\n",
+           ioc->name, mf, mr));
+@@ -1807,7 +1822,8 @@ mptscsih_taskmgmt_complete(MPT_ADAPTER *
   *
-  *             > 0 if command complete but some type of completion error.
-- */
--static int
-+ **/
-+int
- mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
+  **/
+ int
+-mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout)
++mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun,
++    int ctx2abort, ulong timeout)
  {
-       MPT_FRAME_HDR   *mf;
-       SCSIIORequest_t *pScsiReq;
--      SCSIIORequest_t  ReqCopy;
-       int              my_idx, ii, dir;
--      int              rc, cmdTimeout;
--      int             in_isr;
-+      int              timeout;
-       char             cmdLen;
-       char             CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
--      char             cmd = io->cmd;
--      MPT_ADAPTER     *ioc = hd->ioc;
-+      u8               cmd = io->cmd;
-+      MPT_ADAPTER *ioc = hd->ioc;
-+      int              ret = 0;
-+      unsigned long    timeleft;
-+      unsigned long    flags;
--      in_isr = in_interrupt();
--      if (in_isr) {
--              dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Internal SCSI IO request not allowed in ISR context!\n",
--                                      ioc->name));
--              return -EPERM;
-+      /* don't send internal command during diag reset */
-+      spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
-+      if (ioc->ioc_reset_in_progress) {
-+              spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+              dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: busy with host reset\n", ioc->name, __FUNCTION__));
-+              return MPT_SCANDV_BUSY;
-       }
-+      spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
-+      mutex_lock(&ioc->internal_cmds.mutex);
-       /* Set command specific information
+       MPT_FRAME_HDR   *mf = NULL;
+       SCSITaskMgmt_t  *pScsiTm;
+@@ -1827,7 +1843,7 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd
+                       "TaskMgmt type=%x: IOC Not operational (0x%x)!\n",
+                       ioc->name, type, ioc_raw_state);
+               printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
+-                  ioc->name, __FUNCTION__);
++                  ioc->name, __func__);
+               if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
+                       printk(MYIOC_s_WARN_FMT "TaskMgmt HardReset "
+                           "FAILED!!\n", ioc->name);
+@@ -1844,7 +1860,7 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd
+       mutex_lock(&ioc->taskmgmt_cmds.mutex);
+       if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
+-      mutex_unlock(&ioc->taskmgmt_cmds.mutex);
++              mutex_unlock(&ioc->taskmgmt_cmds.mutex);
+               retval = FAILED;
+               goto out;
+       }
+@@ -1852,8 +1868,9 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd
+       /* Return Fail to calling function if no message frames available.
         */
-@@ -3050,13 +2980,13 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
-               dir = MPI_SCSIIO_CONTROL_READ;
-               CDB[0] = cmd;
-               CDB[4] = io->size;
--              cmdTimeout = 10;
-+              timeout = 10;
-               break;
+       if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
+-              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "TaskMgmt no msg frames!!\n",
+-                              ioc->name));
++              dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
++                      "TaskMgmt no msg frames!!\n",
++                      ioc->name));
+               retval = FAILED;
+               mpt_clear_taskmgmt_in_progress_flag(ioc);
+               goto out;
+@@ -1873,11 +1890,11 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd
+       pScsiTm->TaskType = type;
+       pScsiTm->Reserved1 = 0;
+       pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
+-                    ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
++              ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
  
-       case TEST_UNIT_READY:
-               cmdLen = 6;
-               dir = MPI_SCSIIO_CONTROL_READ;
--              cmdTimeout = 10;
-+              timeout = 10;
-               break;
+       int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
  
-       case START_STOP:
-@@ -3064,7 +2994,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
-               dir = MPI_SCSIIO_CONTROL_READ;
-               CDB[0] = cmd;
-               CDB[4] = 1;     /*Spin up the disk */
--              cmdTimeout = 15;
-+              timeout = 15;
-               break;
+-      for (ii=0; ii < 7; ii++)
++      for (ii = 0; ii < 7; ii++)
+               pScsiTm->Reserved2[ii] = 0;
  
-       case REQUEST_SENSE:
-@@ -3072,7 +3002,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
-               CDB[0] = cmd;
-               CDB[4] = io->size;
-               dir = MPI_SCSIIO_CONTROL_READ;
--              cmdTimeout = 10;
-+              timeout = 10;
-               break;
+       pScsiTm->TaskMsgContext = ctx2abort;
+@@ -1895,17 +1912,19 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd
+               mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);
+       else {
+               retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,
+-                      sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
++                      sizeof(SCSITaskMgmt_t), (u32 *)pScsiTm, CAN_SLEEP);
+               if (retval) {
+-                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "TaskMgmt handshake FAILED!"
+-                          " (mf=%p, rc=%d) \n", ioc->name, mf, retval));
++                      dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
++                              "TaskMgmt handshake FAILED!"
++                              " (mf=%p, rc=%d) \n", ioc->name, mf, retval));
+                       mpt_free_msg_frame(ioc, mf);
+                       mpt_clear_taskmgmt_in_progress_flag(ioc);
+                       goto out;
+               }
+       }
  
-       case READ_BUFFER:
-@@ -3091,7 +3021,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
-               CDB[6] = (io->size >> 16) & 0xFF;
-               CDB[7] = (io->size >>  8) & 0xFF;
-               CDB[8] = io->size & 0xFF;
--              cmdTimeout = 10;
-+              timeout = 10;
-               break;
+-      timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, timeout*HZ);
++      timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,
++          timeout*HZ);
+       if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               retval = FAILED;
+               dtmprintk(ioc, printk(MYIOC_s_ERR_FMT
+@@ -1927,9 +1946,9 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd
+  out:
  
-       case WRITE_BUFFER:
-@@ -3106,21 +3036,21 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
-               CDB[6] = (io->size >> 16) & 0xFF;
-               CDB[7] = (io->size >>  8) & 0xFF;
-               CDB[8] = io->size & 0xFF;
--              cmdTimeout = 10;
-+              timeout = 10;
-               break;
+       CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
+-      if(issue_hard_reset) {
++      if (issue_hard_reset) {
+               printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
+-                  ioc->name, __FUNCTION__);
++                  ioc->name, __func__);
+               if ((retval = mpt_SoftResetHandler(ioc, CAN_SLEEP)) != 0)
+                       retval = mpt_HardResetHandler(ioc, CAN_SLEEP);
+               mpt_free_msg_frame(ioc, mf);
+@@ -2037,7 +2056,7 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
+               goto out;
+       }
  
-       case RESERVE:
-               cmdLen = 6;
-               dir = MPI_SCSIIO_CONTROL_READ;
-               CDB[0] = cmd;
--              cmdTimeout = 10;
-+              timeout = 10;
-               break;
+-      if(mpt_fwfault_debug)
++      if (mpt_fwfault_debug)
+               mpt_halt_firmware(ioc);
  
-       case RELEASE:
-               cmdLen = 6;
-               dir = MPI_SCSIIO_CONTROL_READ;
-               CDB[0] = cmd;
--              cmdTimeout = 10;
-+              timeout = 10;
-               break;
+       if (ioc->timeouts < -1)
+@@ -2075,7 +2094,7 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
  
-       case SYNCHRONIZE_CACHE:
-@@ -3128,20 +3058,42 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
-               dir = MPI_SCSIIO_CONTROL_READ;
-               CDB[0] = cmd;
- //            CDB[1] = 0x02;  /* set immediate bit */
--              cmdTimeout = 10;
-+              timeout = 10;
-+              break;
-+
-+      case REPORT_LUNS:
-+              cmdLen = 12;
-+              dir = MPI_SCSIIO_CONTROL_READ;
-+              CDB[0] = cmd;
-+              CDB[6] = (io->size >> 24) & 0xFF;
-+              CDB[7] = (io->size >> 16) & 0xFF;
-+              CDB[8] = (io->size >>  8) & 0xFF;
-+              CDB[9] = io->size & 0xFF;
-+              timeout = 10;
-+              break;
-+
-+      case TRANSPORT_LAYER_RETRIES:
-+              CDB[0] = cmd;
-+              CDB[1] = 0x01;
-+              cmdLen = 6;
-+              dir = MPI_SCSIIO_CONTROL_READ;
-+              timeout = 10;
-               break;
+  out:
+       printk(MYIOC_s_INFO_FMT "task abort: %s (sc=%p)\n",
+-          ioc->name, ((retval == SUCCESS) ? "SUCCESS" : "FAILED" ), SCpnt);
++          ioc->name, ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), SCpnt);
  
-       default:
-               /* Error Case */
--              return -EFAULT;
-+              ret = -EFAULT;
-+              goto out;
-       }
+       return retval;
+ }
+@@ -2306,7 +2325,7 @@ mptscsih_is_phys_disk(MPT_ADAPTER *ioc, 
+                   ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
+               if (num_paths < 2)
+                       continue;
+-              phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t,Path) +
++              phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
+                  (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
+               if (!phys_disk)
+                       continue;
+@@ -2339,14 +2358,14 @@ mptscsih_is_phys_disk(MPT_ADAPTER *ioc, 
+       if (list_empty(&ioc->raid_data.inactive_list))
+               goto out;
  
-       /* Get and Populate a free Frame
-+       * MsgContext set in mpt_get_msg_frame call
-        */
-       if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
--              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "No msg frames!\n",
--                  ioc->name));
--              return -EBUSY;
-+              dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: No msg frames!\n",
-+                  ioc->name, __FUNCTION__));
-+              ret = MPT_SCANDV_BUSY;
-+              goto out;
+-      down(&ioc->raid_data.inactive_list_mutex);
++      mutex_lock(&ioc->raid_data.inactive_list_mutex);
+       list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
+           list) {
+               if ((component_info->d.PhysDiskID == id) &&
+                   (component_info->d.PhysDiskBus == channel))
+                       rc = 1;
        }
+-      up(&ioc->raid_data.inactive_list_mutex);
++      mutex_lock(&ioc->raid_data.inactive_list_mutex);
  
-       pScsiReq = (SCSIIORequest_t *) mf;
-@@ -3164,14 +3116,10 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
+  out:
+       return rc;
+@@ -2357,7 +2376,7 @@ u8
+ mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
+ {
+       struct inactive_raid_component_info *component_info;
+-      int i,j;
++      int i, j;
+       RaidPhysDiskPage1_t *phys_disk;
+       int rc = -ENXIO;
+       u8 num_paths;
+@@ -2384,7 +2403,7 @@ mptscsih_raid_id_to_num(MPT_ADAPTER *ioc
+                   ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
+               if (num_paths < 2)
+                       continue;
+-              phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t,Path) +
++              phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
+                  (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
+               if (!phys_disk)
+                       continue;
+@@ -2417,14 +2436,14 @@ mptscsih_raid_id_to_num(MPT_ADAPTER *ioc
+       if (list_empty(&ioc->raid_data.inactive_list))
+               goto out;
  
-       pScsiReq->CDBLength = cmdLen;
-       pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
--
-       pScsiReq->Reserved = 0;
--
--      pScsiReq->MsgFlags = mpt_msg_flags();
--      /* MsgContext set in mpt_get_msg_fram call  */
-+      pScsiReq->MsgFlags = mpt_msg_flags(ioc);
+-      down(&ioc->raid_data.inactive_list_mutex);
++      mutex_lock(&ioc->raid_data.inactive_list_mutex);
+       list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
+           list) {
+               if ((component_info->d.PhysDiskID == id) &&
+                   (component_info->d.PhysDiskBus == channel))
+                       rc = component_info->d.PhysDiskNum;
+       }
+-      up(&ioc->raid_data.inactive_list_mutex);
++      mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  
-       int_to_scsilun(io->lun, (struct scsi_lun *)pScsiReq->LUN);
--
-       if (io->flags & MPT_ICFLAG_TAGGED_CMD)
-               pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
-       else
-@@ -3179,74 +3127,61 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
+  out:
+       return rc;
+@@ -2595,9 +2614,11 @@ mptscsih_copy_sense_data(struct scsi_cmn
  
-       if (cmd == REQUEST_SENSE) {
-               pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
--              ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Untagged! 0x%2x\n",
--                      ioc->name, cmd));
-+              devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: Untagged! 0x%02x\n", ioc->name, __FUNCTION__, cmd));
+                               ioc->eventContext++;
+                               if (ioc->pcidev->vendor == PCI_VENDOR_ID_IBM) {
+-                                      mptscsih_issue_sep_command(ioc, vdevice->vtarget,
++                                      mptscsih_issue_sep_command(ioc,
++                                          vdevice->vtarget,
+                                           MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
+-                                      vdevice->vtarget->tflags |= MPT_TARGET_FLAGS_LED_ON;
++                                      vdevice->vtarget->tflags |=
++                                          MPT_TARGET_FLAGS_LED_ON;
+                               }
+                       }
+               }
+@@ -2736,8 +2757,9 @@ mptscsih_quiesce_raid(MPT_SCSI_HOST *hd,
+       /* Get and Populate a free Frame
+        */
+       if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
+-              dfailprintk(hd->ioc, printk(MYIOC_s_WARN_FMT "%s: no msg frames!\n",
+-                      ioc->name, __FUNCTION__));
++              dfailprintk(hd->ioc, printk(MYIOC_s_WARN_FMT
++                      "%s: no msg frames!\n",
++                      ioc->name, __func__));
+               ret = -EAGAIN;
+               goto out;
        }
+@@ -2759,8 +2781,9 @@ mptscsih_quiesce_raid(MPT_SCSI_HOST *hd,
+       ioc->add_sge((char *)&pReq->ActionDataSGE,
+               MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
  
--      for (ii=0; ii < 16; ii++)
--              pScsiReq->CDB[ii] = CDB[ii];
-+      for (ii = 0; ii < 16; ii++)
-+          pScsiReq->CDB[ii] = CDB[ii];
-       pScsiReq->DataLength = cpu_to_le32(io->size);
-       pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
-                                          + (my_idx * MPT_SENSE_BUFFER_ALLOC));
+-      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RAID Volume action=%x channel=%d id=%d\n",
+-                      ioc->name, pReq->Action, channel, id));
++      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
++              "RAID Volume action=%x channel=%d id=%d\n",
++              ioc->name, pReq->Action, channel, id));
  
--      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Command 0x%x for (%d:%d:%d)\n",
--                      ioc->name, cmd, io->channel, io->id, io->lun));
--
--      if (dir == MPI_SCSIIO_CONTROL_READ) {
--              mpt_add_sge((char *) &pScsiReq->SGL,
--                      MPT_SGE_FLAGS_SSIMPLE_READ | io->size,
--                      io->data_dma);
--      } else {
--              mpt_add_sge((char *) &pScsiReq->SGL,
--                      MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size,
--                      io->data_dma);
--      }
--
--      /* The ISR will free the request frame, but we need
--       * the information to initialize the target. Duplicate.
--       */
--      memcpy(&ReqCopy, pScsiReq, sizeof(SCSIIORequest_t));
--
--      /* Issue this command after:
--       *      finish init
--       *      add timer
--       * Wait until the reply has been received
--       *  ScsiScanDvCtx callback function will
--       *      set hd->pLocal;
--       *      set scandv_wait_done and call wake_up
--       */
--      hd->pLocal = NULL;
--      hd->timer.expires = jiffies + HZ*cmdTimeout;
--      hd->scandv_wait_done = 0;
--
--      /* Save cmd pointer, for resource free if timeout or
--       * FW reload occurs
--       */
--      hd->cmdPtr = mf;
-+      devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+          "%s: Sending Command 0x%02x for fw_channel=%d fw_id=%d lun=%d\n",
-+          ioc->name, __FUNCTION__, cmd, io->channel, io->id, io->lun));
-+
-+      if (dir == MPI_SCSIIO_CONTROL_READ)
-+              ioc->add_sge((char *) &pScsiReq->SGL,
-+                  MPT_SGE_FLAGS_SSIMPLE_READ | io->size, io->data_dma);
-+      else
-+              ioc->add_sge((char *) &pScsiReq->SGL,
-+                  MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size, io->data_dma);
--      add_timer(&hd->timer);
-+      INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)
+       INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)
        mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
--      wait_event(hd->scandv_waitq, hd->scandv_wait_done);
--
--      if (hd->pLocal) {
--              rc = hd->pLocal->completion;
--              hd->pLocal->skip = 0;
--
--              /* Always set fatal error codes in some cases.
--               */
--              if (rc == MPT_SCANDV_SELECTION_TIMEOUT)
--                      rc = -ENXIO;
--              else if (rc == MPT_SCANDV_SOME_ERROR)
--                      rc =  -rc;
--      } else {
--              rc = -EFAULT;
--              /* This should never happen. */
--              ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "_do_cmd: Null pLocal!!!\n",
--                              ioc->name));
-+      timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done,
-+          timeout*HZ);
-+      if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              ret = MPT_SCANDV_DID_RESET;
-+              dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-+                  "%s: TIMED OUT for cmd=0x%02x\n", ioc->name, __FUNCTION__,
-+                  cmd));
-+              if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
-+                      mpt_free_msg_frame(ioc, mf);
-+                      goto out;
-+              }
-+              if (!timeleft) {
-+                      if (!mptscsih_scandv_bus_reset(ioc))
-+                              goto out;
-+                      printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
-+                          ioc->name, __FUNCTION__);
-+                      if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
-+                              mpt_HardResetHandler(ioc, CAN_SLEEP);
-+                      mpt_free_msg_frame(ioc, mf);
-+              }
-+              goto out;
+@@ -2768,12 +2791,12 @@ mptscsih_quiesce_raid(MPT_SCSI_HOST *hd,
+       if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               ret = -ETIME;
+               dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: TIMED OUT!\n",
+-                  ioc->name, __FUNCTION__));
++                  ioc->name, __func__));
+               if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
+                       goto out;
+               if (!timeleft) {
+                       printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
+-                          ioc->name, __FUNCTION__);
++                          ioc->name, __func__);
+                       if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
+                               mpt_HardResetHandler(ioc, CAN_SLEEP);
+                       mpt_free_msg_frame(ioc, mf);
+@@ -2797,7 +2820,8 @@ mptscsih_quiesce_raid(MPT_SCSI_HOST *hd,
+  *
+  **/
+ static int
+-mptscsih_get_completion_code(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
++mptscsih_get_completion_code(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
++    MPT_FRAME_HDR *reply)
+ {
+       SCSIIOReply_t   *pReply;
+       MpiRaidActionReply_t *pr;
+@@ -2810,10 +2834,12 @@ mptscsih_get_completion_code(MPT_ADAPTER
+       scsi_status = pReply->SCSIStatus;
+       devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-          "IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh, IOCLogInfo=%08xh\n",
+-           ioc->name, status, pReply->SCSIState, scsi_status, le32_to_cpu(pReply->IOCLogInfo)));
++          "IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh,"
++          " IOCLogInfo=%08xh\n",
++           ioc->name, status, pReply->SCSIState, scsi_status,
++           le32_to_cpu(pReply->IOCLogInfo)));
+-      switch(status) {
++      switch (status) {
+       case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:       /* 0x0043 */
+               completion_code = MPT_SCANDV_SELECTION_TIMEOUT;
+@@ -2836,9 +2862,11 @@ mptscsih_get_completion_code(MPT_ADAPTER
+       case MPI_IOCSTATUS_SUCCESS:                     /* 0x0000 */
+               if (pReply->Function == MPI_FUNCTION_CONFIG) {
+                       completion_code = MPT_SCANDV_GOOD;
+-              } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
++              } else if (pReply->Function ==
++                  MPI_FUNCTION_RAID_ACTION) {
+                       pr = (MpiRaidActionReply_t *)reply;
+-                      if (le16_to_cpu(pr->ActionStatus) == MPI_RAID_ACTION_ASTATUS_SUCCESS)
++                      if (le16_to_cpu(pr->ActionStatus) ==
++                          MPI_RAID_ACTION_ASTATUS_SUCCESS)
+                               completion_code = MPT_SCANDV_GOOD;
+                       else
+                               completion_code = MPT_SCANDV_SOME_ERROR;
+@@ -2849,8 +2877,7 @@ mptscsih_get_completion_code(MPT_ADAPTER
+                               completion_code = MPT_SCANDV_ISSUE_SENSE;
+                       else
+                               completion_code = MPT_SCANDV_DID_RESET;
+-              }
+-              else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
++              } else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
+                       completion_code = MPT_SCANDV_DID_RESET;
+               else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
+                       completion_code = MPT_SCANDV_DID_RESET;
+@@ -2885,7 +2912,8 @@ mptscsih_get_completion_code(MPT_ADAPTER
+  *
+  **/
+ int
+-mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
++mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
++    MPT_FRAME_HDR *reply)
+ {
+       SCSIIORequest_t *pReq;
+       SCSIIOReply_t   *pReply;
+@@ -2965,7 +2993,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
+       if (ioc->ioc_reset_in_progress) {
+               spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+               dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: busy with host reset\n", ioc->name, __FUNCTION__));
++                  "%s: busy with host reset\n", ioc->name, __func__));
+               return MPT_SCANDV_BUSY;
+       }
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+@@ -3091,7 +3119,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
+        */
+       if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
+               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: No msg frames!\n",
+-                  ioc->name, __FUNCTION__));
++                  ioc->name, __func__));
+               ret = MPT_SCANDV_BUSY;
+               goto out;
+       }
+@@ -3128,11 +3156,11 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
+       if (cmd == REQUEST_SENSE) {
+               pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
+               devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: Untagged! 0x%02x\n", ioc->name, __FUNCTION__, cmd));
++                  "%s: Untagged! 0x%02x\n", ioc->name, __func__, cmd));
        }
  
--      return rc;
-+      ret = ioc->internal_cmds.completion_code;
-+      devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: success, rc=0x%02x\n",
-+                      ioc->name, __FUNCTION__, ret));
-+
-+ out:
-+      CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
-+      mutex_unlock(&ioc->internal_cmds.mutex);
-+      return ret;
- }
+       for (ii = 0; ii < 16; ii++)
+-          pScsiReq->CDB[ii] = CDB[ii];
++              pScsiReq->CDB[ii] = CDB[ii];
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-@@ -3260,9 +3195,10 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
+       pScsiReq->DataLength = cpu_to_le32(io->size);
+       pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
+@@ -3140,7 +3168,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
+       devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+           "%s: Sending Command 0x%02x for fw_channel=%d fw_id=%d lun=%d\n",
+-          ioc->name, __FUNCTION__, cmd, io->channel, io->id, io->lun));
++          ioc->name, __func__, cmd, io->channel, io->id, io->lun));
+       if (dir == MPI_SCSIIO_CONTROL_READ)
+               ioc->add_sge((char *) &pScsiReq->SGL,
+@@ -3156,7 +3184,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
+       if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               ret = MPT_SCANDV_DID_RESET;
+               dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+-                  "%s: TIMED OUT for cmd=0x%02x\n", ioc->name, __FUNCTION__,
++                  "%s: TIMED OUT for cmd=0x%02x\n", ioc->name, __func__,
+                   cmd));
+               if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
+                       mpt_free_msg_frame(ioc, mf);
+@@ -3166,7 +3194,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
+                       if (!mptscsih_scandv_bus_reset(ioc))
+                               goto out;
+                       printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
+-                          ioc->name, __FUNCTION__);
++                          ioc->name, __func__);
+                       if (mpt_SoftResetHandler(ioc, CAN_SLEEP) != 0)
+                               mpt_HardResetHandler(ioc, CAN_SLEEP);
+                       mpt_free_msg_frame(ioc, mf);
+@@ -3176,7 +3204,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
+       ret = ioc->internal_cmds.completion_code;
+       devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: success, rc=0x%02x\n",
+-                      ioc->name, __FUNCTION__, ret));
++                      ioc->name, __func__, ret));
+  out:
+       CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
+@@ -3195,7 +3223,8 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTER
   *
   */
  static void
--mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
-+mptscsih_synchronize_cache(struct scsi_device *sdev, MPT_SCSI_HOST *hd, VirtDevice *vdevice)
+-mptscsih_synchronize_cache(struct scsi_device *sdev, MPT_SCSI_HOST *hd, VirtDevice *vdevice)
++mptscsih_synchronize_cache(struct scsi_device *sdev, MPT_SCSI_HOST *hd,
++    VirtDevice *vdevice)
  {
        INTERNAL_CMD             iocmd;
-+      MPT_ADAPTER *ioc = hd->ioc;
-       /* Ignore hidden raid components, this is handled when the command
-        * is sent to the volume
-@@ -3274,23 +3210,23 @@ mptscsih_synchronize_cache(MPT_SCSI_HOST
-           !vdevice->configured_lun)
-               return;
--      /* Following parameters will not change
--       * in this routine.
--       */
-+      memset(&iocmd, 0, sizeof(INTERNAL_CMD));
-       iocmd.cmd = SYNCHRONIZE_CACHE;
--      iocmd.flags = 0;
-       iocmd.physDiskNum = -1;
-       iocmd.data = NULL;
-       iocmd.data_dma = -1;
--      iocmd.size = 0;
--      iocmd.rsvd = iocmd.rsvd2 = 0;
-       iocmd.channel = vdevice->vtarget->channel;
+       MPT_ADAPTER *ioc = hd->ioc;
+@@ -3219,8 +3248,9 @@ mptscsih_synchronize_cache(struct scsi_d
        iocmd.id = vdevice->vtarget->id;
        iocmd.lun = vdevice->lun;
  
-+      sdev_printk(KERN_INFO, sdev, MYIOC_s_FMT "SYNCHRONIZE_CACHE: fw_channel %d,"
-+          " fw_id %d\n", ioc->name, vdevice->vtarget->channel, vdevice->vtarget->id);
+-      sdev_printk(KERN_INFO, sdev, MYIOC_s_FMT "SYNCHRONIZE_CACHE: fw_channel %d,"
+-          " fw_id %d\n", ioc->name, vdevice->vtarget->channel, vdevice->vtarget->id);
++      sdev_printk(KERN_INFO, sdev, MYIOC_s_FMT
++          "SYNCHRONIZE_CACHE: fw_channel %d, fw_id %d\n",
++          ioc->name, vdevice->vtarget->channel, vdevice->vtarget->id);
        mptscsih_do_cmd(hd, &iocmd);
  }
  
-+/*
-+ * shost attributes
-+ */
- static ssize_t
- mptscsih_version_fw_show(struct device *dev, struct device_attribute *attr,
-                        char *buf)
-@@ -3464,13 +3400,44 @@ mptscsih_debug_level_store(struct device
-               return -EINVAL;
+@@ -3408,7 +3438,8 @@ static DEVICE_ATTR(debug_level, S_IRUGO 
+       mptscsih_debug_level_show, mptscsih_debug_level_store);
  
-       ioc->debug_level = val;
--      printk(MYIOC_s_INFO_FMT "debug_level=%08xh\n",
--                              ioc->name, ioc->debug_level);
-+      printk(MYIOC_s_INFO_FMT "debug_level=%08xh\n", ioc->name,
-+          ioc->debug_level);
+ static ssize_t
+-mptscsih_disable_hotplug_remove_show(struct device *dev, struct device_attribute *attr, char *buf)
++mptscsih_disable_hotplug_remove_show(struct device *dev,
++    struct device_attribute *attr, char *buf)
+ {
+       struct Scsi_Host *host = class_to_shost(dev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+@@ -3417,7 +3448,8 @@ mptscsih_disable_hotplug_remove_show(str
+       return snprintf(buf, PAGE_SIZE, "%02xh\n", ioc->disable_hotplug_remove);
+ }
+ static ssize_t
+-mptscsih_disable_hotplug_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
++mptscsih_disable_hotplug_remove_store(struct device *dev,
++    struct device_attribute *attr, const char *buf, size_t count)
+ {
+       struct Scsi_Host *host = class_to_shost(dev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+@@ -3436,7 +3468,8 @@ mptscsih_disable_hotplug_remove_store(st
        return strlen(buf);
  }
- static DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR,
-       mptscsih_debug_level_show, mptscsih_debug_level_store);
+ static DEVICE_ATTR(disable_hotplug_remove, S_IRUGO | S_IWUSR,
+-      mptscsih_disable_hotplug_remove_show, mptscsih_disable_hotplug_remove_store);
++      mptscsih_disable_hotplug_remove_show,
++      mptscsih_disable_hotplug_remove_store);
  
-+static ssize_t
-+mptscsih_disable_hotplug_remove_show(struct device *dev, struct device_attribute *attr, char *buf)
-+{
-+      struct Scsi_Host *host = class_to_shost(dev);
-+      MPT_SCSI_HOST   *hd = shost_priv(host);
-+      MPT_ADAPTER *ioc = hd->ioc;
-+
-+      return snprintf(buf, PAGE_SIZE, "%02xh\n", ioc->disable_hotplug_remove);
-+}
-+static ssize_t
-+mptscsih_disable_hotplug_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
-+{
-+      struct Scsi_Host *host = class_to_shost(dev);
-+      MPT_SCSI_HOST   *hd = shost_priv(host);
-+      MPT_ADAPTER *ioc = hd->ioc;
-+      int val = 0;
-+
-+      if (sscanf(buf, "%x", &val) != 1)
-+              return -EINVAL;
-+
-+      ioc->disable_hotplug_remove = val;
-+      if (ioc->disable_hotplug_remove)
-+              printk(MYIOC_s_INFO_FMT "disabling hotplug remove\n",
-+                  ioc->name);
-+      else
-+              printk(MYIOC_s_INFO_FMT "eanbling hotplug remove\n", ioc->name);
-+      return strlen(buf);
-+}
-+static DEVICE_ATTR(disable_hotplug_remove, S_IRUGO | S_IWUSR,
-+      mptscsih_disable_hotplug_remove_show, mptscsih_disable_hotplug_remove_store);
-+
  struct device_attribute *mptscsih_host_attrs[] = {
        &dev_attr_version_fw,
-       &dev_attr_version_bios,
-@@ -3484,6 +3451,7 @@ struct device_attribute *mptscsih_host_a
-       &dev_attr_io_delay,
-       &dev_attr_device_delay,
-       &dev_attr_debug_level,
-+      &dev_attr_disable_hotplug_remove,
-       NULL,
- };
- EXPORT_SYMBOL(mptscsih_host_attrs);
-@@ -3510,7 +3478,9 @@ EXPORT_SYMBOL(mptscsih_scandv_complete);
- EXPORT_SYMBOL(mptscsih_event_process);
- EXPORT_SYMBOL(mptscsih_ioc_reset);
- EXPORT_SYMBOL(mptscsih_change_queue_depth);
--EXPORT_SYMBOL(mptscsih_timer_expired);
--EXPORT_SYMBOL(mptscsih_TMHandler);
--
-+EXPORT_SYMBOL(mptscsih_IssueTaskMgmt);
-+EXPORT_SYMBOL(mptscsih_do_cmd);
-+EXPORT_SYMBOL(mptscsih_quiesce_raid);
-+EXPORT_SYMBOL(mptscsih_get_scsi_lookup);
-+EXPORT_SYMBOL(mptscsih_taskmgmt_response_code);
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
---- a/drivers/message/fusion/mptscsih.h
-+++ b/drivers/message/fusion/mptscsih.h
-@@ -60,6 +60,7 @@
- #define MPT_SCANDV_SELECTION_TIMEOUT  (0x00000008)
- #define MPT_SCANDV_ISSUE_SENSE                (0x00000010)
- #define MPT_SCANDV_FALLBACK           (0x00000020)
-+#define MPT_SCANDV_BUSY                       (0x00000040)
- #define MPT_SCANDV_MAX_RETRIES                (10)
-@@ -71,6 +72,7 @@
- #define MPT_ICFLAG_DID_RESET  0x20    /* Bus Reset occurred with this command */
- #define MPT_ICFLAG_RESERVED   0x40    /* Reserved has been issued */
-+
- #define MPT_SCSI_CMD_PER_DEV_HIGH     64
- #define MPT_SCSI_CMD_PER_DEV_LOW      32
-@@ -84,9 +86,11 @@
- #define MPTSCSIH_DOMAIN_VALIDATION      1
- #define MPTSCSIH_MAX_WIDTH              1
- #define MPTSCSIH_MIN_SYNC               0x08
-+#define MPTSCSIH_QAS                    1
- #define MPTSCSIH_SAF_TE                 0
- #define MPTSCSIH_PT_CLEAR               0
-+#define TRANSPORT_LAYER_RETRIES               0xC2
- #endif
- typedef struct _internal_cmd {
-@@ -112,7 +116,7 @@ extern int mptscsih_resume(struct pci_de
- extern int mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int func);
- extern const char * mptscsih_info(struct Scsi_Host *SChost);
- extern int mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *));
--extern void mptscsih_slave_destroy(struct scsi_device *device);
-+extern void mptscsih_slave_destroy(struct scsi_device *sdev);
- extern int mptscsih_slave_configure(struct scsi_device *device);
- extern int mptscsih_abort(struct scsi_cmnd * SCpnt);
- extern int mptscsih_dev_reset(struct scsi_cmnd * SCpnt);
-@@ -125,8 +129,11 @@ extern int mptscsih_scandv_complete(MPT_
+Index: linux-2.6.27/drivers/message/fusion/mptscsih.h
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/mptscsih.h
++++ linux-2.6.27/drivers/message/fusion/mptscsih.h
+@@ -129,11 +129,13 @@ extern int mptscsih_scandv_complete(MPT_
  extern int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
  extern int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
  extern int mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth);
--extern void mptscsih_timer_expired(unsigned long data);
--extern int mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout);
-+extern int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout);
+-extern int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout);
++extern int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel,
++    u8 id, int lun, int ctx2abort, ulong timeout);
  extern u8 mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id);
  extern int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id);
-+extern int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
+ extern int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
  extern struct device_attribute *mptscsih_host_attrs[];
-+extern int mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id);
-+extern struct scsi_cmnd * mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
-+extern void mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code);
---- a/drivers/message/fusion/mptspi.c
-+++ b/drivers/message/fusion/mptspi.c
-@@ -53,8 +53,10 @@
- #include <linux/delay.h>      /* for mdelay */
- #include <linux/interrupt.h>  /* needed for in_interrupt() proto */
- #include <linux/reboot.h>     /* notifier code */
-+#include <linux/sched.h>
- #include <linux/workqueue.h>
- #include <linux/raid_class.h>
-+#include <linux/pci.h>
- #include <scsi/scsi.h>
- #include <scsi/scsi_cmnd.h>
-@@ -83,6 +85,10 @@ static int mpt_saf_te = MPTSCSIH_SAF_TE;
- module_param(mpt_saf_te, int, 0);
- MODULE_PARM_DESC(mpt_saf_te, " Force enabling SEP Processor: enable=1  (default=MPTSCSIH_SAF_TE=0)");
-+static int mpt_qas = MPTSCSIH_QAS;
-+module_param(mpt_qas, int, 1);
-+MODULE_PARM_DESC(mpt_qas, " Quick Arbitration and Selection (QAS) enabled=1, disabled=0 (default=MPTSCSIH_QAS=1)");
-+
+-extern int mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id);
++extern int mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel,
++    u8 id);
+ extern struct scsi_cmnd * mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
+ extern void mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code);
+Index: linux-2.6.27/drivers/message/fusion/mptspi.c
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/mptspi.c
++++ linux-2.6.27/drivers/message/fusion/mptspi.c
+@@ -87,7 +87,8 @@ MODULE_PARM_DESC(mpt_saf_te, " Force ena
+ static int mpt_qas = MPTSCSIH_QAS;
+ module_param(mpt_qas, int, 1);
+-MODULE_PARM_DESC(mpt_qas, " Quick Arbitration and Selection (QAS) enabled=1, disabled=0 (default=MPTSCSIH_QAS=1)");
++MODULE_PARM_DESC(mpt_qas, " Quick Arbitration and Selection (QAS) enabled=1,"
++   " disabled= (default=MPTSCSIH_QAS=1)");
  static void mptspi_write_offset(struct scsi_target *, int);
  static void mptspi_write_width(struct scsi_target *, int);
- static int mptspi_write_spi_device_pg1(struct scsi_target *,
-@@ -95,12 +101,12 @@ static u8 mptspiTaskCtx = MPT_MAX_PROTOC
- static u8     mptspiInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
- /**
-- *    mptspi_setTargetNegoParms  - Update the target negotiation parameters
-+ *    mptspi_setTargetNegoParms  - Update the target negotiation parameters
-  *    @hd: Pointer to a SCSI Host Structure
-  *    @target: per target private data
-  *    @sdev: SCSI device
-  *
-- *    Update the target negotiation parameters based on the the Inquiry
-+ *    Update the target negotiation parameters based on the the Inquiry
-  *    data, adapter capabilities, and NVRAM settings.
-  **/
- static void
-@@ -131,7 +137,7 @@ mptspi_setTargetNegoParms(MPT_SCSI_HOST 
-               if (scsi_device_sync(sdev)) {
-                       factor = pspi_data->minSyncFactor;
-                       if (!scsi_device_dt(sdev))
--                                      factor = MPT_ULTRA2;
-+                              factor = MPT_ULTRA2;
-                       else {
-                               if (!scsi_device_ius(sdev) &&
-                                   !scsi_device_qas(sdev))
-@@ -209,6 +215,10 @@ mptspi_setTargetNegoParms(MPT_SCSI_HOST 
-       target->maxOffset = offset;
-       target->maxWidth = width;
-+      spi_min_period(scsi_target(sdev)) = factor;
-+      spi_max_offset(scsi_target(sdev)) = offset;
-+      spi_max_width(scsi_target(sdev)) = width;
-+
-       target->tflags |= MPT_TARGET_FLAGS_VALID_NEGO;
-       /* Disable unused features.
-@@ -230,7 +240,7 @@ mptspi_setTargetNegoParms(MPT_SCSI_HOST 
+@@ -240,7 +241,7 @@ mptspi_setTargetNegoParms(MPT_SCSI_HOST 
                 */
  
                ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--                      "Disabling QAS due to noQas=%02x on id=%d!\n", ioc->name, noQas, id));
-+              "Disabling QAS due to noQas=%02x on id=%d!\n", ioc->name, noQas, id));
+-              "Disabling QAS due to noQas=%02x on id=%d!\n", ioc->name, noQas, id));
++                      "Disabling QAS due to noQas=%02x on id=%d!\n", ioc->name, noQas, id));
        }
  }
  
-@@ -262,7 +272,7 @@ mptspi_writeIOCPage4(MPT_SCSI_HOST *hd, 
-        */
-       if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
-               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
--                              "writeIOCPage4 : no msg frames!\n",ioc->name));
-+                  "writeIOCPage4 : no msg frames!\n", ioc->name));
-               return -EAGAIN;
-       }
-@@ -300,11 +310,11 @@ mptspi_writeIOCPage4(MPT_SCSI_HOST *hd, 
-       flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE |
-               (IOCPage4Ptr->Header.PageLength + ii) * 4;
--      mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
-+      ioc->add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
+@@ -314,7 +315,7 @@ mptspi_writeIOCPage4(MPT_SCSI_HOST *hd, 
  
        ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n",
--              ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, id, channel));
-+                      ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, id, channel));
+-                      ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, id, channel));
++              ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, id, channel));
  
        mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
  
-@@ -371,7 +381,7 @@ mptspi_initTarget(MPT_SCSI_HOST *hd, Vir
-  *            non-zero = true
-  *            zero = false
-  *
-- */
-+ **/
- static int
- mptspi_is_raid(struct _MPT_SCSI_HOST *hd, u32 id)
- {
-@@ -399,12 +409,11 @@ static int mptspi_target_alloc(struct sc
-       struct Scsi_Host *shost = dev_to_shost(&starget->dev);
-       struct _MPT_SCSI_HOST *hd = shost_priv(shost);
-       VirtTarget              *vtarget;
--      MPT_ADAPTER *ioc;
-+      MPT_ADAPTER *ioc = hd->ioc;
-       if (hd == NULL)
-               return -ENODEV;
--      ioc = hd->ioc;
-       vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
-       if (!vtarget)
-               return -ENOMEM;
-@@ -471,9 +480,12 @@ mptspi_target_destroy(struct scsi_target
- static void
- mptspi_print_write_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii)
- {
--      ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d Requested = 0x%08x"
-+      if (!(hd->ioc->debug_level & MPT_DEBUG_DV))
-+              return;
-+
-+      starget_printk(KERN_DEBUG, starget, MYIOC_s_FMT "Wrote = 0x%08x"
-           " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n",
--          hd->ioc->name, starget->id, ii,
-+          hd->ioc->name, ii,
-           ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "",
-           ((ii >> 8) & 0xFF), ((ii >> 16) & 0xFF),
-           ii & MPI_SCSIDEVPAGE0_NP_IU ? "IU ": "",
-@@ -483,7 +495,7 @@ mptspi_print_write_nego(struct _MPT_SCSI
+@@ -495,7 +496,7 @@ mptspi_print_write_nego(struct _MPT_SCSI
            ii & MPI_SCSIDEVPAGE0_NP_WR_FLOW ? "WRFLOW ": "",
            ii & MPI_SCSIDEVPAGE0_NP_RD_STRM ? "RDSTRM ": "",
            ii & MPI_SCSIDEVPAGE0_NP_RTI ? "RTI ": "",
--          ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": ""));
-+          ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": "");
+-          ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": "");
++          ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP " : "");
  }
  
  /**
-@@ -496,9 +508,12 @@ mptspi_print_write_nego(struct _MPT_SCSI
- static void
- mptspi_print_read_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii)
- {
--      ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d Read = 0x%08x"
-+      if (!(hd->ioc->debug_level & MPT_DEBUG_DV))
-+              return;
-+
-+      starget_printk(KERN_DEBUG, starget, MYIOC_s_FMT "Read = 0x%08x"
-           " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n",
--          hd->ioc->name, starget->id, ii,
-+          hd->ioc->name, ii,
-           ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "",
-           ((ii >> 8) & 0xFF), ((ii >> 16) & 0xFF),
-           ii & MPI_SCSIDEVPAGE0_NP_IU ? "IU ": "",
-@@ -508,7 +523,7 @@ mptspi_print_read_nego(struct _MPT_SCSI_
+@@ -523,7 +524,7 @@ mptspi_print_read_nego(struct _MPT_SCSI_
            ii & MPI_SCSIDEVPAGE0_NP_WR_FLOW ? "WRFLOW ": "",
            ii & MPI_SCSIDEVPAGE0_NP_RD_STRM ? "RDSTRM ": "",
            ii & MPI_SCSIDEVPAGE0_NP_RTI ? "RTI ": "",
--          ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": ""));
-+          ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": "");
+-          ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": "");
++          ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP " : "");
  }
  
  static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
-@@ -557,9 +572,11 @@ static int mptspi_read_spi_device_pg0(st
-       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
-       cfg.dir = 0;
-       cfg.pageAddr = starget->id;
-+      cfg.timeout = 60;
-       if (mpt_config(ioc, &cfg)) {
--              starget_printk(KERN_ERR, starget, MYIOC_s_FMT "mpt_config failed\n", ioc->name);
-+              starget_printk(KERN_ERR, starget,
-+                  MYIOC_s_FMT "mpt_config failed\n", ioc->name);
-               goto out_free;
-       }
-       err = 0;
-@@ -614,64 +631,11 @@ static void mptspi_read_parameters(struc
-       spi_width(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WIDE) ? 1 : 0;
+@@ -822,8 +823,8 @@ static int mptspi_write_spi_device_pg1(s
+       pg1 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg1_dma, GFP_KERNEL);
+       if (pg1 == NULL) {
+-              starget_printk(KERN_ERR, starget,
+-                  MYIOC_s_FMT "dma_alloc_coherent for parameters failed\n", ioc->name);
++              starget_printk(KERN_ERR, starget, MYIOC_s_FMT
++                  "dma_alloc_coherent for parameters failed\n", ioc->name);
+               return -EINVAL;
+       }
+@@ -1071,12 +1072,12 @@ mpt_work_wrapper(struct work_struct *wor
+               if(vtarget->id != disk)
+                       continue;
+-              starget_printk(KERN_INFO, vtarget->starget,
+-                  MYIOC_s_FMT "Integrated RAID requests DV of new device\n", ioc->name);
++              starget_printk(KERN_INFO, vtarget->starget, MYIOC_s_FMT
++                  "Integrated RAID requests DV of new device\n", ioc->name);
+               mptspi_dv_device(hd, sdev);
+       }
+-      shost_printk(KERN_INFO, shost,
+-          MYIOC_s_FMT "Integrated RAID detects new device %d\n", ioc->name, disk);
++      shost_printk(KERN_INFO, shost, MYIOC_s_FMT
++          "Integrated RAID detects new device %d\n", ioc->name, disk);
+       scsi_scan_target(&ioc->sh->shost_gendev, 1, disk, 0, 1);
  }
  
--static int
--mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id)
--{
--      MpiRaidActionRequest_t  *pReq;
--      MPT_FRAME_HDR           *mf;
--      MPT_ADAPTER *ioc = hd->ioc;
--
--      /* Get and Populate a free Frame
--       */
--      if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
--              ddvprintk(ioc, printk(MYIOC_s_WARN_FMT "_do_raid: no msg frames!\n",
--                                      ioc->name));
--              return -EAGAIN;
--      }
--      pReq = (MpiRaidActionRequest_t *)mf;
--      if (quiesce)
--              pReq->Action = MPI_RAID_ACTION_QUIESCE_PHYS_IO;
--      else
--              pReq->Action = MPI_RAID_ACTION_ENABLE_PHYS_IO;
--      pReq->Reserved1 = 0;
--      pReq->ChainOffset = 0;
--      pReq->Function = MPI_FUNCTION_RAID_ACTION;
--      pReq->VolumeID = id;
--      pReq->VolumeBus = channel;
--      pReq->PhysDiskNum = 0;
--      pReq->MsgFlags = 0;
--      pReq->Reserved2 = 0;
--      pReq->ActionDataWord = 0; /* Reserved for this action */
--
--      mpt_add_sge((char *)&pReq->ActionDataSGE,
--              MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
--
--      ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RAID Volume action=%x channel=%d id=%d\n",
--                      ioc->name, pReq->Action, channel, id));
--
--      hd->pLocal = NULL;
--      hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */
--      hd->scandv_wait_done = 0;
--
--      /* Save cmd pointer, for resource free if timeout or
--       * FW reload occurs
--       */
--      hd->cmdPtr = mf;
--
--      add_timer(&hd->timer);
--      mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
--      wait_event(hd->scandv_waitq, hd->scandv_wait_done);
--
--      if ((hd->pLocal == NULL) || (hd->pLocal->completion != 0))
--              return -1;
--
--      return 0;
--}
--
- static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
-                            struct scsi_device *sdev)
- {
-       VirtTarget *vtarget = scsi_target(sdev)->hostdata;
-+      struct scsi_target *starget = scsi_target(sdev);
+@@ -1087,8 +1088,8 @@ static void mpt_dv_raid(struct _MPT_SCSI
        MPT_ADAPTER *ioc = hd->ioc;
  
-       /* no DV on RAID devices */
-@@ -679,11 +643,20 @@ static void mptspi_dv_device(struct _MPT
-           mptspi_is_raid(hd, sdev->id))
+       if (!wqw) {
+-              shost_printk(KERN_ERR, ioc->sh,
+-                  MYIOC_s_FMT "Failed to act on RAID event for physical disk %d\n",
++              shost_printk(KERN_ERR, ioc->sh, MYIOC_s_FMT
++                  "Failed to act on RAID event for physical disk %d\n",
+                   ioc->name, disk);
                return;
+       }
+Index: linux-2.6.27/drivers/message/fusion/rejected_ioctls/diag_buffer.c
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/rejected_ioctls/diag_buffer.c
++++ linux-2.6.27/drivers/message/fusion/rejected_ioctls/diag_buffer.c
+@@ -4,19 +4,20 @@
+  * Outputs:   None.
+  * Return:    0 if successful
+  *            -EFAULT if data unavailable
+- *            -EBUSY  if previous command timout and IOC reset is not complete.
++ *            -EBUSY  if previous command timout and IOC reset is not
++ *            complete.
+  *            -ENODEV if no such device/adapter
+  *            -ETIME  if timer expires
+  *            -ENOMEM if memory allocation error
+  */
+ static int
+-mptctl_register_diag_buffer (unsigned long arg)
++mptctl_register_diag_buffer(unsigned long arg)
+ {
+       mpt_diag_register_t     __user *uarg = (void __user *) arg;
+       mpt_diag_register_t     karg;
+       MPT_ADAPTER             *ioc;
+       int                     iocnum, rc, ii;
+-      void *                  request_data;
++      void                    *request_data;
+       dma_addr_t              request_data_dma;
+       u32                     request_data_sz;
+       MPT_FRAME_HDR           *mf;
+@@ -30,37 +31,39 @@ mptctl_register_diag_buffer (unsigned lo
+       if (copy_from_user(&karg, uarg, sizeof(mpt_diag_register_t))) {
+               printk(KERN_ERR "%s@%d::%s - "
+               "Unable to read in mpt_diag_register_t struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-+      if (ioc->debug_level & MPT_DEBUG_DV)
-+              starget_printk(KERN_DEBUG, starget, MYIOC_s_FMT
-+                  "sdtr=%d, wdtr=%d, ppr=%d, min_period=0x%02x, "
-+                  "max_offset=0x%02x, max_width=%d, nego_flags=0x%02x, "
-+                  "tflags=0x%02x\n", ioc->name, sdev->sdtr, sdev->wdtr,
-+                  sdev->ppr, spi_min_period(starget),
-+                  spi_max_offset(starget), spi_max_width(starget),
-+                  vtarget->negoFlags, vtarget->tflags);
+-      if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+-              (ioc == NULL)) {
++      iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc);
 +
-       /* If this is a piece of a RAID, then quiesce first */
-       if (sdev->channel == 1 &&
-           mptscsih_quiesce_raid(hd, 1, vtarget->channel, vtarget->id) < 0) {
--              starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT
--                  "Integrated RAID quiesce failed\n", ioc->name);
-+              starget_printk(KERN_ERR, scsi_target(sdev),
-+                  MYIOC_s_FMT "Integrated RAID quiesce failed\n", ioc->name);
-               return;
++      if ((iocnum < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
        }
  
-@@ -693,8 +666,8 @@ static void mptspi_dv_device(struct _MPT
-       if (sdev->channel == 1 &&
-           mptscsih_quiesce_raid(hd, 0, vtarget->channel, vtarget->id) < 0)
--              starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT
--                  "Integrated RAID resume failed\n", ioc->name);
-+              starget_printk(KERN_ERR, scsi_target(sdev),
-+                  MYIOC_s_FMT "Integrated RAID resume failed\n", ioc->name);
-       mptspi_read_parameters(sdev->sdev_target);
-       spi_display_xfer_agreement(sdev->sdev_target);
-@@ -716,7 +689,7 @@ static int mptspi_slave_alloc(struct scs
-       vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
-       if (!vdevice) {
-               printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
--                              ioc->name, sizeof(VirtDevice));
-+                  ioc->name, sizeof(VirtDevice));
-               return -ENOMEM;
+       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s enter.\n", ioc->name,
+-              __FUNCTION__));
++              __func__));
+       buffer_type = karg.data.BufferType;
+       if (!(ioc->facts.IOCCapabilities & MPT_DIAG_CAPABILITY(buffer_type))) {
+               printk(MYIOC_s_DEBUG_FMT "%s: doesn't have Capability for "
+-                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
++                  "buffer_type=%x\n", ioc->name, __func__, buffer_type);
+               return -ENODEV;
        }
  
-@@ -738,21 +711,13 @@ static int mptspi_slave_configure(struct
- {
-       struct _MPT_SCSI_HOST *hd = shost_priv(sdev->host);
-       VirtTarget *vtarget = scsi_target(sdev)->hostdata;
--      int ret;
-+      int     ret;
-       mptspi_initTarget(hd, vtarget, sdev);
--
-       ret = mptscsih_slave_configure(sdev);
--
-       if (ret)
-               return ret;
+       if (ioc->DiagBuffer_Status[buffer_type] &
+           MPT_DIAG_BUFFER_IS_REGISTERED) {
+               printk(MYIOC_s_DEBUG_FMT "%s: already has a Registered "
+-                  "buffer for buffer_type=%x\n", ioc->name, __FUNCTION__,
++                  "buffer for buffer_type=%x\n", ioc->name, __func__,
+                   buffer_type);
+               return -EFAULT;
+       }
  
--      ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d min_period=0x%02x"
--              " max_offset=0x%02x max_width=%d\n", hd->ioc->name,
--              sdev->id, spi_min_period(scsi_target(sdev)),
--              spi_max_offset(scsi_target(sdev)),
--              spi_max_width(scsi_target(sdev))));
--
-       if ((sdev->channel == 1 ||
-            !(mptspi_is_raid(hd, sdev->id))) &&
-           !spi_initial_dv(sdev->sdev_target))
-@@ -857,8 +822,8 @@ static int mptspi_write_spi_device_pg1(s
+       /* Get a free request frame and save the message context.
+        */
+-      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
++      mf = mpt_get_msg_frame(mptctl_id, ioc);
++      if (mf  == NULL)
+               return -EAGAIN;
  
-       pg1 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg1_dma, GFP_KERNEL);
-       if (pg1 == NULL) {
--              starget_printk(KERN_ERR, starget, MYIOC_s_FMT
--                  "dma_alloc_coherent for parameters failed\n", ioc->name);
-+              starget_printk(KERN_ERR, starget,
-+                  MYIOC_s_FMT "dma_alloc_coherent for parameters failed\n", ioc->name);
-               return -EINVAL;
+       request_data = ioc->DiagBuffer[buffer_type];
+@@ -85,9 +88,9 @@ mptctl_register_diag_buffer (unsigned lo
+               if (request_data == NULL) {
+                       printk(MYIOC_s_DEBUG_FMT "%s: pci_alloc_consistent"
+                           " FAILED, (request_sz=%d)\n", ioc->name,
+-                          __FUNCTION__, request_data_sz);
++                          __func__, request_data_sz);
+                       mpt_free_msg_frame(ioc, mf);
+-                      return -EAGAIN;
++                      return -EAGAIN;
+               }
+               ioc->DiagBuffer[buffer_type] = request_data;
+               ioc->DiagBuffer_sz[buffer_type] = request_data_sz;
+@@ -95,7 +98,7 @@ mptctl_register_diag_buffer (unsigned lo
        }
  
-@@ -887,8 +852,8 @@ static int mptspi_write_spi_device_pg1(s
-       mptspi_print_write_nego(hd, starget, le32_to_cpu(pg1->RequestedParameters));
+       ioc->DiagBuffer_Status[buffer_type] = 0;
+-      diag_buffer_post_request = (DiagBufferPostRequest_t *)mf;
++      diag_buffer_post_request = (DiagBufferPostRequest_t *)mf;
+       diag_buffer_post_request->Function = MPI_FUNCTION_DIAG_BUFFER_POST;
+       diag_buffer_post_request->ChainOffset = 0;
+       diag_buffer_post_request->BufferType = karg.data.BufferType;
+@@ -137,7 +140,7 @@ mptctl_register_diag_buffer (unsigned lo
+       if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               rc = -ETIME;
+               printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name,
+-                  __FUNCTION__);
++                  __func__);
+               if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
+                       mpt_free_msg_frame(ioc, mf);
+                       goto out;
+@@ -150,7 +153,7 @@ mptctl_register_diag_buffer (unsigned lo
+       /* process the completed Reply Message Frame */
+       if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0) {
+               dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: status=%x\n",
+-                  ioc->name, __FUNCTION__, ioc->ioctl_cmds.status));
++                  ioc->name, __func__, ioc->ioctl_cmds.status));
+               rc = -EFAULT;
+               goto out;
+       }
+@@ -160,12 +163,13 @@ mptctl_register_diag_buffer (unsigned lo
+           MPI_IOCSTATUS_SUCCESS) {
+               if (diag_buffer_post_reply->MsgLength > 5)
+                       ioc->DataSize[buffer_type] =
+-                           le32_to_cpu(diag_buffer_post_reply->TransferLength);
++                          le32_to_cpu
++                          (diag_buffer_post_reply->TransferLength);
+               ioc->DiagBuffer_Status[buffer_type] |=
+                       MPT_DIAG_BUFFER_IS_REGISTERED;
+       } else {
+               dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: IOCStatus=%x "
+-                  "IOCLogInfo=%x\n", ioc->name, __FUNCTION__,
++                  "IOCLogInfo=%x\n", ioc->name, __func__,
+                   diag_buffer_post_reply->IOCStatus,
+                   diag_buffer_post_reply->IOCLogInfo));
+               rc = -EFAULT;
+@@ -187,18 +191,19 @@ mptctl_register_diag_buffer (unsigned lo
+  * Outputs:   None.
+  * Return:    0 if successful
+  *            -EFAULT if data unavailable
+- *            -EBUSY  if previous command timout and IOC reset is not complete.
++ *            -EBUSY  if previous command timout and IOC reset is
++ *            not complete.
+  *            -ENODEV if no such device/adapter
+  *            -ETIME  if timer expires
+  *            -ENOMEM if memory allocation error
+  */
+ static int
+-mptctl_release_diag_buffer (unsigned long arg)
++mptctl_release_diag_buffer(unsigned long arg)
+ {
+       mpt_diag_release_t      __user *uarg = (void __user *) arg;
+       mpt_diag_release_t      karg;
+       MPT_ADAPTER             *ioc;
+-      void *                  request_data;
++      void                    *request_data;
+       int                     iocnum, rc;
+       MPT_FRAME_HDR           *mf;
+       DiagReleaseRequest_t    *diag_release;
+@@ -210,42 +215,42 @@ mptctl_release_diag_buffer (unsigned lon
+       if (copy_from_user(&karg, uarg, sizeof(mpt_diag_release_t))) {
+               printk(KERN_ERR "%s@%d::%s - "
+               "Unable to read in mpt_diag_release_t struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-       if (mpt_config(ioc, &cfg)) {
--              starget_printk(KERN_ERR, starget, MYIOC_s_FMT
--                  "mpt_config failed\n", ioc->name);
-+              starget_printk(KERN_ERR, starget,
-+                  MYIOC_s_FMT "mpt_config failed\n", ioc->name);
-               goto out_free;
+-      if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+-              (ioc == NULL)) {
++      iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc);
++      if ((iocnum < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
        }
-       err = 0;
-@@ -963,14 +928,15 @@ static void mptspi_write_dt(struct scsi_
-       if (spi_period(starget) == -1)
-               mptspi_read_parameters(starget);
  
--      if (!dt && spi_period(starget) < 10)
--              spi_period(starget) = 10;
-+      if (!dt) {
-+              spi_qas(starget) = 0;
-+              spi_iu(starget) = 0;
-+      }
+       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s enter.\n", ioc->name,
+-              __FUNCTION__));
++              __func__));
+       buffer_type = karg.data.UniqueId & 0x000000ff;
+       if (!(ioc->facts.IOCCapabilities & MPT_DIAG_CAPABILITY(buffer_type))) {
+               printk(MYIOC_s_DEBUG_FMT "%s: doesn't have Capability for "
+-                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
++                  "buffer_type=%x\n", ioc->name, __func__, buffer_type);
+               return -ENODEV;
+       }
  
-       spi_dt(starget) = dt;
+       if ((ioc->DiagBuffer_Status[buffer_type] &
+-              MPT_DIAG_BUFFER_IS_REGISTERED) == 0 ) {
++              MPT_DIAG_BUFFER_IS_REGISTERED) == 0) {
+               printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x is not "
+-                  "registered\n", ioc->name, __FUNCTION__, buffer_type);
++                  "registered\n", ioc->name, __func__, buffer_type);
+               return -EFAULT;
+       }
  
-       nego = mptspi_getRP(starget);
+       if (karg.data.UniqueId != ioc->UniqueId[buffer_type]) {
+               printk(MYIOC_s_DEBUG_FMT "%s: unique_id=%x is not registered\n",
+-                  ioc->name, __FUNCTION__, karg.data.UniqueId);
++                  ioc->name, __func__, karg.data.UniqueId);
+               return -EFAULT;
+       }
  
--
-       pg1.RequestedParameters = cpu_to_le32(nego);
-       pg1.Reserved = 0;
-       pg1.Configuration = 0;
-@@ -986,9 +952,6 @@ static void mptspi_write_iu(struct scsi_
-       if (spi_period(starget) == -1)
-               mptspi_read_parameters(starget);
--      if (!iu && spi_period(starget) < 9)
--              spi_period(starget) = 9;
--
-       spi_iu(starget) = iu;
-       nego = mptspi_getRP(starget);
-@@ -1030,9 +993,11 @@ static void mptspi_write_qas(struct scsi
-       struct _MPT_SCSI_HOST *hd = shost_priv(shost);
-       VirtTarget *vtarget = starget->hostdata;
-       u32 nego;
-+      MPT_ADAPTER *ioc = hd->ioc;
--      if ((vtarget->negoFlags & MPT_TARGET_NO_NEGO_QAS) ||
--          hd->ioc->spi_data.noQas)
-+      if (!mpt_qas ||
-+          (vtarget->negoFlags & MPT_TARGET_NO_NEGO_QAS) ||
-+          ioc->spi_data.noQas)
-               spi_qas(starget) = 0;
-       else
-               spi_qas(starget) = qas;
-@@ -1053,8 +1018,8 @@ static void mptspi_write_width(struct sc
+       if (ioc->DiagBuffer_Status[buffer_type] & MPT_DIAG_BUFFER_IS_RELEASED) {
+               dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x "
+-                  "is already released\n", ioc->name, __FUNCTION__,
++                  "is already released\n", ioc->name, __func__,
+                   buffer_type));
+               return rc;
+       }
+@@ -254,13 +259,14 @@ mptctl_release_diag_buffer (unsigned lon
  
-       if (!width) {
-               spi_dt(starget) = 0;
--              if (spi_period(starget) < 10)
--                      spi_period(starget) = 10;
-+              spi_qas(starget) = 0;
-+              spi_iu(starget) = 0;
+       if (request_data == NULL) {
+               printk(MYIOC_s_DEBUG_FMT "%s: doesn't have buffer for "
+-                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
++                  "buffer_type=%x\n", ioc->name, __func__, buffer_type);
+               return -ENODEV;
        }
  
-       spi_width(starget) = width;
-@@ -1074,7 +1039,8 @@ struct work_queue_wrapper {
-       int                     disk;
- };
+       /* Get a free request frame and save the message context.
+        */
+-      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
++      mf = mpt_get_msg_frame(mptctl_id, ioc);
++      if (mf == NULL)
+               return -EAGAIN;
  
--static void mpt_work_wrapper(struct work_struct *work)
-+static void
-+mpt_work_wrapper(struct work_struct *work)
+       diag_release = (DiagReleaseRequest_t *)mf;
+@@ -281,7 +287,7 @@ mptctl_release_diag_buffer (unsigned lon
+       if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               rc = -ETIME;
+               printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name,
+-                  __FUNCTION__);
++                  __func__);
+               if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
+                       mpt_free_msg_frame(ioc, mf);
+                       goto out;
+@@ -294,7 +300,7 @@ mptctl_release_diag_buffer (unsigned lon
+       /* process the completed Reply Message Frame */
+       if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0) {
+               dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: status=%x\n",
+-                  ioc->name, __FUNCTION__, ioc->ioctl_cmds.status));
++                  ioc->name, __func__, ioc->ioctl_cmds.status));
+               rc = -EFAULT;
+               goto out;
+       }
+@@ -304,7 +310,7 @@ mptctl_release_diag_buffer (unsigned lon
+           MPI_IOCSTATUS_SUCCESS) {
+               dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: IOCStatus=%x "
+                       "IOCLogInfo=%x\n",
+-                  ioc->name, __FUNCTION__, diag_release_reply->IOCStatus,
++                  ioc->name, __func__, diag_release_reply->IOCStatus,
+                   diag_release_reply->IOCLogInfo));
+               rc = -EFAULT;
+       } else
+@@ -324,19 +330,20 @@ mptctl_release_diag_buffer (unsigned lon
+  * Outputs:   None.
+  * Return:    0 if successful
+  *            -EFAULT if data unavailable
+- *            -EBUSY  if previous command timout and IOC reset is not complete.
++ *            -EBUSY  if previous command timout and IOC reset is
++ *            not complete.
+  *            -ENODEV if no such device/adapter
+  *            -ETIME  if timer expires
+  *            -ENOMEM if memory allocation error
+  */
+ static int
+-mptctl_unregister_diag_buffer (unsigned long arg)
++mptctl_unregister_diag_buffer(unsigned long arg)
  {
-       struct work_queue_wrapper *wqw =
-               container_of(work, struct work_queue_wrapper, work);
-@@ -1105,12 +1071,12 @@ static void mpt_work_wrapper(struct work
-               if(vtarget->id != disk)
-                       continue;
--              starget_printk(KERN_INFO, vtarget->starget, MYIOC_s_FMT
--                  "Integrated RAID requests DV of new device\n", ioc->name);
-+              starget_printk(KERN_INFO, vtarget->starget,
-+                  MYIOC_s_FMT "Integrated RAID requests DV of new device\n", ioc->name);
-               mptspi_dv_device(hd, sdev);
+       mpt_diag_unregister_t   __user *uarg = (void __user *) arg;
+       mpt_diag_unregister_t   karg;
+       MPT_ADAPTER             *ioc;
+       int                     iocnum;
+-      void *                  request_data;
++      void                    *request_data;
+       dma_addr_t              request_data_dma;
+       u32                     request_data_sz;
+       u8                      buffer_type;
+@@ -344,49 +351,48 @@ mptctl_unregister_diag_buffer (unsigned 
+       if (copy_from_user(&karg, uarg, sizeof(mpt_diag_unregister_t))) {
+               printk(KERN_ERR "%s@%d::%s - "
+               "Unable to read in mpt_diag_unregister_t struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
+-
+-      if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+-              (ioc == NULL)) {
++      iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc);
++      if ((iocnum < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
        }
--      shost_printk(KERN_INFO, shost, MYIOC_s_FMT
--          "Integrated RAID detects new device %d\n", ioc->name, disk);
-+      shost_printk(KERN_INFO, shost,
-+          MYIOC_s_FMT "Integrated RAID detects new device %d\n", ioc->name, disk);
-       scsi_scan_target(&ioc->sh->shost_gendev, 1, disk, 0, 1);
- }
  
-@@ -1121,8 +1087,8 @@ static void mpt_dv_raid(struct _MPT_SCSI
-       MPT_ADAPTER *ioc = hd->ioc;
+       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s enter.\n", ioc->name,
+-              __FUNCTION__));
++              __func__));
+       buffer_type = karg.data.UniqueId & 0x000000ff;
+       if (!(ioc->facts.IOCCapabilities & MPT_DIAG_CAPABILITY(buffer_type))) {
+               printk(MYIOC_s_DEBUG_FMT "%s: doesn't have Capability for "
+-                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
++                  "buffer_type=%x\n", ioc->name, __func__, buffer_type);
+               return -ENODEV;
+       }
  
-       if (!wqw) {
--              shost_printk(KERN_ERR, ioc->sh, MYIOC_s_FMT
--                  "Failed to act on RAID event for physical disk %d\n",
-+              shost_printk(KERN_ERR, ioc->sh,
-+                  MYIOC_s_FMT "Failed to act on RAID event for physical disk %d\n",
-                   ioc->name, disk);
-               return;
+       if ((ioc->DiagBuffer_Status[buffer_type] &
+               MPT_DIAG_BUFFER_IS_REGISTERED) == 0) {
+               printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x is not "
+-                  "registered\n", ioc->name, __FUNCTION__, buffer_type);
++                  "registered\n", ioc->name, __func__, buffer_type);
+               return -EFAULT;
+       }
+       if ((ioc->DiagBuffer_Status[buffer_type] &
+               MPT_DIAG_BUFFER_IS_RELEASED) == 0) {
+               printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x has not been "
+-                  "released\n", ioc->name, __FUNCTION__, buffer_type);
++                  "released\n", ioc->name, __func__, buffer_type);
+               return -EFAULT;
        }
-@@ -1213,9 +1179,9 @@ static struct pci_device_id mptspi_pci_t
- MODULE_DEVICE_TABLE(pci, mptspi_pci_table);
  
+       if (karg.data.UniqueId != ioc->UniqueId[buffer_type]) {
+               printk(MYIOC_s_DEBUG_FMT "%s: unique_id=%x is not registered\n",
+-                  ioc->name, __FUNCTION__, karg.data.UniqueId);
++                  ioc->name, __func__, karg.data.UniqueId);
+               return -EFAULT;
+       }
  
--/*
-+/**
-  * renegotiate for a given target
-- */
-+ **/
- static void
- mptspi_dv_renegotiate_work(struct work_struct *work)
- {
-@@ -1261,32 +1227,33 @@ mptspi_dv_renegotiate(struct _MPT_SCSI_H
-       schedule_work(&wqw->work);
- }
+       request_data = ioc->DiagBuffer[buffer_type];
+       if (!request_data) {
+               printk(MYIOC_s_DEBUG_FMT "%s: doesn't have buffer for "
+-                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
++                  "buffer_type=%x\n", ioc->name, __func__, buffer_type);
+               return -ENODEV;
+       }
  
--/*
-+/**
-  * spi module reset handler
-- */
-+ **/
+@@ -405,18 +411,19 @@ mptctl_unregister_diag_buffer (unsigned 
+  * Outputs:   None.
+  * Return:    0 if successful
+  *            -EFAULT if data unavailable
+- *            -EBUSY  if previous command timout and IOC reset is not complete.
++ *            -EBUSY  if previous command timout and IOC reset
++ *            is not complete.
+  *            -ENODEV if no such device/adapter
+  *            -ETIME  if timer expires
+  *            -ENOMEM if memory allocation error
+  */
  static int
- mptspi_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
+-mptctl_query_diag_buffer (unsigned long arg)
++mptctl_query_diag_buffer(unsigned long arg)
  {
-+      struct _MPT_SCSI_HOST *hd = NULL;
-       int rc;
+       mpt_diag_query_t        __user *uarg = (void __user *)arg;
+       mpt_diag_query_t        karg;
+       MPT_ADAPTER             *ioc;
+-      void *                  request_data;
++      void                    *request_data;
+       int                     iocnum, ii, rc;
+       u8                      buffer_type;
+@@ -424,38 +431,38 @@ mptctl_query_diag_buffer (unsigned long 
+       if (copy_from_user(&karg, uarg, sizeof(mpt_diag_query_t))) {
+               printk(KERN_ERR "%s@%d::%s - "
+               "Unable to read in mpt_diag_query_t struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
  
-       rc = mptscsih_ioc_reset(ioc, reset_phase);
-+      if ((ioc->bus_type != SPI) || (!rc))
-+              goto out;
+       karg.data.Flags = 0;
+-      if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+-              (ioc == NULL)) {
++      iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc);
++      if ((iocnum < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               goto out;
+       }
  
--      /* only try to do a renegotiation if we're properly set up
--       * if we get an ioc fault on bringup, ioc->sh will be NULL */
--      if (reset_phase == MPT_IOC_POST_RESET &&
--          ioc->sh) {
--              struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
-+      hd = shost_priv(ioc->sh);
-+      if (!hd->ioc)
-+              goto out;
+       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s enter.\n", ioc->name,
+-              __FUNCTION__));
++              __func__));
+       buffer_type = karg.data.BufferType;
+       if (!(ioc->facts.IOCCapabilities & MPT_DIAG_CAPABILITY(buffer_type))) {
+               printk(MYIOC_s_DEBUG_FMT "%s: doesn't have Capability for "
+-                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
++                  "buffer_type=%x\n", ioc->name, __func__, buffer_type);
+               goto out;
+       }
+       if ((ioc->DiagBuffer_Status[buffer_type] &
+-              MPT_DIAG_BUFFER_IS_REGISTERED) == 0) {
++              MPT_DIAG_BUFFER_IS_REGISTERED) == 0) {
+               printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x is not "
+-                  "registered\n", ioc->name, __FUNCTION__, buffer_type);
++                  "registered\n", ioc->name, __func__, buffer_type);
+               goto out;
+       }
+       if (karg.data.UniqueId & 0xffffff00) {
+               if (karg.data.UniqueId != ioc->UniqueId[buffer_type]) {
+                       printk(MYIOC_s_DEBUG_FMT "%s: unique_id=%x is not "
+-                          "registered\n", ioc->name, __FUNCTION__,
++                          "registered\n", ioc->name, __func__,
+                           karg.data.UniqueId);
+                       goto out;
+               }
+@@ -464,7 +471,7 @@ mptctl_query_diag_buffer (unsigned long 
+       request_data = ioc->DiagBuffer[buffer_type];
+       if (!request_data) {
+               printk(MYIOC_s_DEBUG_FMT "%s: doesn't have buffer for "
+-                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
++                  "buffer_type=%x\n", ioc->name, __func__, buffer_type);
+               goto out;
+       }
  
-+      if (ioc->active && reset_phase == MPT_IOC_POST_RESET)
-               mptspi_dv_renegotiate(hd);
--      }
--
-+ out:
+@@ -490,7 +497,7 @@ mptctl_query_diag_buffer (unsigned long 
+  out:
+       if (copy_to_user(uarg, &karg, sizeof(mpt_diag_query_t))) {
+               printk(MYIOC_s_ERR_FMT "%s Unable to write mpt_diag_query_t "
+-                  "data @ %p\n", ioc->name, __FUNCTION__, uarg);
++                  "data @ %p\n", ioc->name, __func__, uarg);
+               return -EFAULT;
+       }
        return rc;
- }
- #ifdef CONFIG_PM
--/*
-+/**
-  * spi module resume handler
-- */
-+ **/
+@@ -502,13 +509,14 @@ mptctl_query_diag_buffer (unsigned long 
+  * Outputs:   None.
+  * Return:    0 if successful
+  *            -EFAULT if data unavailable
+- *            -EBUSY  if previous command timout and IOC reset is not complete.
++ *            -EBUSY  if previous command timout and IOC reset
++ *            is not complete.
+  *            -ENODEV if no such device/adapter
+  *            -ETIME  if timer expires
+  *            -ENOMEM if memory allocation error
+  */
  static int
- mptspi_resume(struct pci_dev *pdev)
- {
-@@ -1303,13 +1270,13 @@ mptspi_resume(struct pci_dev *pdev)
+-mptctl_read_diag_buffer (unsigned long arg)
++mptctl_read_diag_buffer(unsigned long arg)
+ {
+       mpt_diag_read_buffer_t  __user *uarg = (void __user *) arg;
+       mpt_diag_read_buffer_t  karg;
+@@ -527,50 +535,49 @@ mptctl_read_diag_buffer (unsigned long a
+       if (copy_from_user(&karg, uarg, sizeof(mpt_diag_read_buffer_t))) {
+               printk(KERN_ERR "%s@%d::%s - "
+               "Unable to read in mpt_diag_read_buffer_t struct @ %p\n",
+-                  __FILE__, __LINE__, __FUNCTION__, uarg);
++                  __FILE__, __LINE__, __func__, uarg);
+               return -EFAULT;
+       }
+-
+-      if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
+-              (ioc == NULL)) {
++      iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc);
++      if ((iocnum < 0) || (ioc == NULL)) {
+               printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
+-                  __FILE__, __FUNCTION__, __LINE__, iocnum);
++                  __FILE__, __func__, __LINE__, iocnum);
+               return -ENODEV;
+       }
  
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
--/*
-+/**
-  *    mptspi_probe - Installs scsi devices per bus.
-  *    @pdev: Pointer to pci_dev structure
-  *
-  *    Returns 0 for success, non-zero for failure.
-  *
-- */
-+ **/
- static int
- mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
- {
-@@ -1423,19 +1390,18 @@ mptspi_probe(struct pci_dev *pdev, const
-        * A slightly different algorithm is required for
-        * 64bit SGEs.
-        */
--      scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
--      if (sizeof(dma_addr_t) == sizeof(u64)) {
-+      scale = ioc->req_sz/ioc->SGE_size;
-+      if (ioc->sg_addr_size == sizeof(u64)) {
-               numSGE = (scale - 1) *
-                 (ioc->facts.MaxChainDepth-1) + scale +
--                (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
--                sizeof(u32));
-+                (ioc->req_sz - 60) / ioc->SGE_size;
-       } else {
-               numSGE = 1 + (scale - 1) *
-                 (ioc->facts.MaxChainDepth-1) + scale +
--                (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
--                sizeof(u32));
-+                (ioc->req_sz - 64) / ioc->SGE_size;
+       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s enter.\n", ioc->name,
+-          __FUNCTION__));
++              __func__));
+       buffer_type = karg.data.UniqueId & 0x000000ff;
+       if (!(ioc->facts.IOCCapabilities & MPT_DIAG_CAPABILITY(buffer_type))) {
+               printk(MYIOC_s_DEBUG_FMT "%s: doesn't have Capability "
+-                  "for buffer_type=%x\n", ioc->name, __FUNCTION__,
++                  "for buffer_type=%x\n", ioc->name, __func__,
+                   buffer_type);
+               return -EFAULT;
        }
  
-+
-       if (numSGE < sh->sg_tablesize) {
-               /* Reset this value */
-               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-@@ -1444,11 +1410,11 @@ mptspi_probe(struct pci_dev *pdev, const
-               sh->sg_tablesize = numSGE;
+       if (karg.data.UniqueId != ioc->UniqueId[buffer_type]) {
+               printk(MYIOC_s_DEBUG_FMT "%s: unique_id=%x is not registered\n",
+-                  ioc->name, __FUNCTION__, karg.data.UniqueId);
++                  ioc->name, __func__, karg.data.UniqueId);
+               return -EFAULT;
        }
  
--      spin_unlock_irqrestore(&ioc->FreeQlock, flags);
--
-       hd = shost_priv(sh);
-       hd->ioc = ioc;
+       request_data = ioc->DiagBuffer[buffer_type];
+       if (!request_data) {
+               printk(MYIOC_s_DEBUG_FMT "%s: doesn't have buffer for "
+-                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
++                  "buffer_type=%x\n", ioc->name, __func__, buffer_type);
+               return -EFAULT;
+       }
  
-+      spin_unlock_irqrestore(&ioc->FreeQlock, flags);
-+
-       /* SCSI needs scsi_cmnd lookup table!
-        * (with size equal to req_depth*PtrSz!)
-        */
-@@ -1462,39 +1428,12 @@ mptspi_probe(struct pci_dev *pdev, const
-       dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
-                ioc->name, ioc->ScsiLookup));
+       diagData = (void *)(request_data + karg.data.StartingOffset);
+       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: diagData=%p "
+-          "request_data=%p StartingOffset=%x\n", ioc->name, __FUNCTION__,
++          "request_data=%p StartingOffset=%x\n", ioc->name, __func__,
+           diagData, request_data, karg.data.StartingOffset));
  
--      /* Clear the TM flags
--       */
--      hd->tmPending = 0;
--      hd->tmState = TM_STATE_NONE;
--      hd->resetPending = 0;
--      hd->abortSCpnt = NULL;
--
--      /* Clear the pointer used to store
--       * single-threaded commands, i.e., those
--       * issued during a bus scan, dv and
--       * configuration pages.
--       */
--      hd->cmdPtr = NULL;
--
--      /* Initialize this SCSI Hosts' timers
--       * To use, set the timer expires field
--       * and add_timer
--       */
--      init_timer(&hd->timer);
--      hd->timer.data = (unsigned long) hd;
--      hd->timer.function = mptscsih_timer_expired;
--
-+      ioc->sdev_queue_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
-       ioc->spi_data.Saf_Te = mpt_saf_te;
--
--      hd->negoNvram = MPT_SCSICFG_USE_NVRAM;
-       ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
--              "saf_te %x\n",
--              ioc->name,
--              mpt_saf_te));
--      ioc->spi_data.noQas = 0;
-+          "saf_te %x\n", ioc->name, mpt_saf_te));
-+      ioc->spi_data.noQas = mpt_qas ? 0 : MPT_TARGET_NO_NEGO_QAS;
--      init_waitqueue_head(&hd->scandv_waitq);
--      hd->scandv_wait_done = 0;
-       hd->last_queue_full = 0;
-       hd->spi_pending = 0;
+       if (copy_to_user((void __user *)&uarg->data.DiagnosticData[0],
+           diagData, karg.data.BytesToRead)) {
+               printk(MYIOC_s_ERR_FMT "%s: Unable to write "
+                   "mpt_diag_read_buffer_t data @ %p\n", ioc->name,
+-                  __FUNCTION__, diagData);
++                  __func__, diagData);
+               return -EFAULT;
+       }
  
-@@ -1514,7 +1453,7 @@ mptspi_probe(struct pci_dev *pdev, const
-        * issue internal bus reset
-        */
-       if (ioc->spi_data.bus_reset)
--              mptscsih_TMHandler(hd,
-+              mptscsih_IssueTaskMgmt(hd,
-                   MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
-                   0, 0, 0, 0, 5);
-@@ -1544,7 +1483,7 @@ static struct pci_driver mptspi_driver =
-  *    mptspi_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer.
-  *
-  *    Returns 0 for success, non-zero for failure.
-- */
-+ **/
- static int __init
- mptspi_init(void)
- {
-@@ -1574,7 +1513,8 @@ mptspi_init(void)
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- /**
-  *    mptspi_exit - Unregisters MPT adapter(s)
-- */
-+ *
-+ **/
- static void __exit
- mptspi_exit(void)
- {
-@@ -1582,7 +1522,6 @@ mptspi_exit(void)
+@@ -578,17 +585,18 @@ mptctl_read_diag_buffer (unsigned long a
+               goto out;
  
-       mpt_reset_deregister(mptspiDoneCtx);
-       mpt_event_deregister(mptspiDoneCtx);
--
-       mpt_deregister(mptspiInternalCtx);
-       mpt_deregister(mptspiTaskCtx);
-       mpt_deregister(mptspiDoneCtx);
---- /dev/null
-+++ b/drivers/message/fusion/rejected_ioctls/diag_buffer.c
-@@ -0,0 +1,667 @@
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/* REGISTER DIAG BUFFER Routine.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -EBUSY  if previous command timout and IOC reset is not complete.
-+ *            -ENODEV if no such device/adapter
-+ *            -ETIME  if timer expires
-+ *            -ENOMEM if memory allocation error
-+ */
-+static int
-+mptctl_register_diag_buffer (unsigned long arg)
-+{
-+      mpt_diag_register_t     __user *uarg = (void __user *) arg;
-+      mpt_diag_register_t     karg;
-+      MPT_ADAPTER             *ioc;
-+      int                     iocnum, rc, ii;
-+      void *                  request_data;
-+      dma_addr_t              request_data_dma;
-+      u32                     request_data_sz;
-+      MPT_FRAME_HDR           *mf;
-+      DiagBufferPostRequest_t *diag_buffer_post_request;
-+      DiagBufferPostReply_t   *diag_buffer_post_reply;
-+      u32                     tmp;
-+      u8                      buffer_type;
-+      unsigned long           timeleft;
-+
-+      rc = 0;
-+      if (copy_from_user(&karg, uarg, sizeof(mpt_diag_register_t))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+              "Unable to read in mpt_diag_register_t struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-+              (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s enter.\n", ioc->name,
-+              __FUNCTION__));
-+      buffer_type = karg.data.BufferType;
-+      if (!(ioc->facts.IOCCapabilities & MPT_DIAG_CAPABILITY(buffer_type))) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: doesn't have Capability for "
-+                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
-+              return -ENODEV;
-+      }
-+
-+      if (ioc->DiagBuffer_Status[buffer_type] &
-+          MPT_DIAG_BUFFER_IS_REGISTERED) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: already has a Registered "
-+                  "buffer for buffer_type=%x\n", ioc->name, __FUNCTION__,
-+                  buffer_type);
-+              return -EFAULT;
-+      }
-+
-+      /* Get a free request frame and save the message context.
-+       */
-+      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
-+              return -EAGAIN;
-+
-+      request_data = ioc->DiagBuffer[buffer_type];
-+      request_data_sz = karg.data.RequestedBufferSize;
-+
-+      if (request_data) {
-+              request_data_dma = ioc->DiagBuffer_dma[buffer_type];
-+              if (request_data_sz != ioc->DiagBuffer_sz[buffer_type]) {
-+                      pci_free_consistent(ioc->pcidev,
-+                          ioc->DiagBuffer_sz[buffer_type],
-+                          request_data, request_data_dma);
-+                      request_data = NULL;
-+              }
-+      }
-+
-+      if (request_data == NULL) {
-+              ioc->DiagBuffer_sz[buffer_type] = 0;
-+              ioc->DiagBuffer_dma[buffer_type] = 0;
-+              ioc->DataSize[buffer_type] = 0;
-+              request_data = pci_alloc_consistent(
-+                      ioc->pcidev, request_data_sz, &request_data_dma);
-+              if (request_data == NULL) {
-+                      printk(MYIOC_s_DEBUG_FMT "%s: pci_alloc_consistent"
-+                          " FAILED, (request_sz=%d)\n", ioc->name,
-+                          __FUNCTION__, request_data_sz);
-+                      mpt_free_msg_frame(ioc, mf);
-+                      return -EAGAIN;
-+              }
-+              ioc->DiagBuffer[buffer_type] = request_data;
-+              ioc->DiagBuffer_sz[buffer_type] = request_data_sz;
-+              ioc->DiagBuffer_dma[buffer_type] = request_data_dma;
-+      }
-+
-+      ioc->DiagBuffer_Status[buffer_type] = 0;
-+      diag_buffer_post_request = (DiagBufferPostRequest_t *)mf;
-+      diag_buffer_post_request->Function = MPI_FUNCTION_DIAG_BUFFER_POST;
-+      diag_buffer_post_request->ChainOffset = 0;
-+      diag_buffer_post_request->BufferType = karg.data.BufferType;
-+      diag_buffer_post_request->TraceLevel = ioc->TraceLevel[buffer_type] =
-+          karg.data.TraceLevel;
-+      diag_buffer_post_request->MsgFlags = 0;
-+      diag_buffer_post_request->Reserved1 = 0;
-+      diag_buffer_post_request->Reserved2 = 0;
-+      diag_buffer_post_request->Reserved3 = 0;
-+      diag_buffer_post_request->BufferAddress.High = 0;
-+      if (buffer_type == MPI_DIAG_BUF_TYPE_EXTENDED)
-+              ioc->ExtendedType[buffer_type] = karg.data.ExtendedType;
-+      else
-+              ioc->ExtendedType[buffer_type] = 0;
-+      diag_buffer_post_request->ExtendedType =
-+          cpu_to_le32(ioc->ExtendedType[buffer_type]);
-+      ioc->UniqueId[buffer_type] = karg.data.UniqueId;
-+      diag_buffer_post_request->BufferLength = cpu_to_le32(request_data_sz);
-+      for (ii = 0; ii < 4; ii++) {
-+              ioc->ProductSpecific[buffer_type][ii] =
-+                      karg.data.ProductSpecific[ii];
-+              diag_buffer_post_request->ProductSpecific[ii] =
-+                      cpu_to_le32(ioc->ProductSpecific[buffer_type][ii]);
-+      }
-+
-+      tmp = request_data_dma & 0xFFFFFFFF;
-+      diag_buffer_post_request->BufferAddress.Low = cpu_to_le32(tmp);
-+      if (ioc->sg_addr_size == sizeof(u64)) {
-+              tmp = (u32)((u64)request_data_dma >> 32);
-+              diag_buffer_post_request->BufferAddress.High = cpu_to_le32(tmp);
-+      }
-+
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
-+          diag_buffer_post_request->MsgContext);
-+      INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
-+      mpt_put_msg_frame(mptctl_id, ioc, mf);
-+      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
-+          MPT_IOCTL_DEFAULT_TIMEOUT*HZ);
-+      if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              rc = -ETIME;
-+              printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name,
-+                  __FUNCTION__);
-+              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
-+                      mpt_free_msg_frame(ioc, mf);
-+                      goto out;
-+              }
-+              if (!timeleft)
-+                      mptctl_timeout_expired(ioc, mf);
-+              goto out;
-+      }
-+
-+      /* process the completed Reply Message Frame */
-+      if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0) {
-+              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: status=%x\n",
-+                  ioc->name, __FUNCTION__, ioc->ioctl_cmds.status));
-+              rc = -EFAULT;
-+              goto out;
-+      }
-+
-+      diag_buffer_post_reply = (DiagBufferPostReply_t *)ioc->ioctl_cmds.reply;
-+      if (le16_to_cpu(diag_buffer_post_reply->IOCStatus) ==
-+          MPI_IOCSTATUS_SUCCESS) {
-+              if (diag_buffer_post_reply->MsgLength > 5)
-+                      ioc->DataSize[buffer_type] =
-+                           le32_to_cpu(diag_buffer_post_reply->TransferLength);
-+              ioc->DiagBuffer_Status[buffer_type] |=
-+                      MPT_DIAG_BUFFER_IS_REGISTERED;
-+      } else {
-+              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: IOCStatus=%x "
-+                  "IOCLogInfo=%x\n", ioc->name, __FUNCTION__,
-+                  diag_buffer_post_reply->IOCStatus,
-+                  diag_buffer_post_reply->IOCLogInfo));
-+              rc = -EFAULT;
-+      }
-+
-+ out:
-+
-+      CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
-+      if (rc)
-+              pci_free_consistent(ioc->pcidev, request_data_sz,
-+                  request_data, request_data_dma);
-+      return rc;
-+}
-+
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/* RELEASE DIAG BUFFER Routine.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -EBUSY  if previous command timout and IOC reset is not complete.
-+ *            -ENODEV if no such device/adapter
-+ *            -ETIME  if timer expires
-+ *            -ENOMEM if memory allocation error
-+ */
-+static int
-+mptctl_release_diag_buffer (unsigned long arg)
-+{
-+      mpt_diag_release_t      __user *uarg = (void __user *) arg;
-+      mpt_diag_release_t      karg;
-+      MPT_ADAPTER             *ioc;
-+      void *                  request_data;
-+      int                     iocnum, rc;
-+      MPT_FRAME_HDR           *mf;
-+      DiagReleaseRequest_t    *diag_release;
-+      DiagReleaseReply_t      *diag_release_reply;
-+      u8                      buffer_type;
-+      unsigned long           timeleft;
-+
-+      rc = 0;
-+      if (copy_from_user(&karg, uarg, sizeof(mpt_diag_release_t))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+              "Unable to read in mpt_diag_release_t struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-+              (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s enter.\n", ioc->name,
-+              __FUNCTION__));
-+      buffer_type = karg.data.UniqueId & 0x000000ff;
-+      if (!(ioc->facts.IOCCapabilities & MPT_DIAG_CAPABILITY(buffer_type))) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: doesn't have Capability for "
-+                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
-+              return -ENODEV;
-+      }
-+
-+      if ((ioc->DiagBuffer_Status[buffer_type] &
-+              MPT_DIAG_BUFFER_IS_REGISTERED) == 0 ) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x is not "
-+                  "registered\n", ioc->name, __FUNCTION__, buffer_type);
-+              return -EFAULT;
-+      }
-+
-+      if (karg.data.UniqueId != ioc->UniqueId[buffer_type]) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: unique_id=%x is not registered\n",
-+                  ioc->name, __FUNCTION__, karg.data.UniqueId);
-+              return -EFAULT;
-+      }
-+
-+      if (ioc->DiagBuffer_Status[buffer_type] & MPT_DIAG_BUFFER_IS_RELEASED) {
-+              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x "
-+                  "is already released\n", ioc->name, __FUNCTION__,
-+                  buffer_type));
-+              return rc;
-+      }
-+
-+      request_data = ioc->DiagBuffer[buffer_type];
-+
-+      if (request_data == NULL) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: doesn't have buffer for "
-+                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
-+              return -ENODEV;
-+      }
-+
-+      /* Get a free request frame and save the message context.
-+       */
-+      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
-+              return -EAGAIN;
-+
-+      diag_release = (DiagReleaseRequest_t *)mf;
-+      diag_release->Function = MPI_FUNCTION_DIAG_RELEASE;
-+      diag_release->BufferType = buffer_type;
-+      diag_release->ChainOffset = 0;
-+      diag_release->Reserved1 = 0;
-+      diag_release->Reserved2 = 0;
-+      diag_release->Reserved3 = 0;
-+      diag_release->MsgFlags = 0;
-+
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
-+          diag_release->MsgContext);
-+      INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
-+      mpt_put_msg_frame(mptctl_id, ioc, mf);
-+      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
-+          MPT_IOCTL_DEFAULT_TIMEOUT*HZ);
-+      if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              rc = -ETIME;
-+              printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name,
-+                  __FUNCTION__);
-+              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
-+                      mpt_free_msg_frame(ioc, mf);
-+                      goto out;
-+              }
-+              if (!timeleft)
-+                      mptctl_timeout_expired(ioc, mf);
-+              goto out;
-+      }
-+
-+      /* process the completed Reply Message Frame */
-+      if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0) {
-+              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: status=%x\n",
-+                  ioc->name, __FUNCTION__, ioc->ioctl_cmds.status));
-+              rc = -EFAULT;
-+              goto out;
-+      }
-+
-+      diag_release_reply = (DiagReleaseReply_t *)ioc->ioctl_cmds.reply;
-+      if (le16_to_cpu(diag_release_reply->IOCStatus) !=
-+          MPI_IOCSTATUS_SUCCESS) {
-+              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: IOCStatus=%x "
-+                      "IOCLogInfo=%x\n",
-+                  ioc->name, __FUNCTION__, diag_release_reply->IOCStatus,
-+                  diag_release_reply->IOCLogInfo));
-+              rc = -EFAULT;
-+      } else
-+              ioc->DiagBuffer_Status[buffer_type] |=
-+                  MPT_DIAG_BUFFER_IS_RELEASED;
-+
-+ out:
-+
-+      CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
-+      return rc;
-+}
-+
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/* UNREGISTER DIAG BUFFER Routine.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -EBUSY  if previous command timout and IOC reset is not complete.
-+ *            -ENODEV if no such device/adapter
-+ *            -ETIME  if timer expires
-+ *            -ENOMEM if memory allocation error
-+ */
-+static int
-+mptctl_unregister_diag_buffer (unsigned long arg)
-+{
-+      mpt_diag_unregister_t   __user *uarg = (void __user *) arg;
-+      mpt_diag_unregister_t   karg;
-+      MPT_ADAPTER             *ioc;
-+      int                     iocnum;
-+      void *                  request_data;
-+      dma_addr_t              request_data_dma;
-+      u32                     request_data_sz;
-+      u8                      buffer_type;
-+
-+      if (copy_from_user(&karg, uarg, sizeof(mpt_diag_unregister_t))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+              "Unable to read in mpt_diag_unregister_t struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-+              (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s enter.\n", ioc->name,
-+              __FUNCTION__));
-+      buffer_type = karg.data.UniqueId & 0x000000ff;
-+      if (!(ioc->facts.IOCCapabilities & MPT_DIAG_CAPABILITY(buffer_type))) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: doesn't have Capability for "
-+                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
-+              return -ENODEV;
-+      }
-+
-+      if ((ioc->DiagBuffer_Status[buffer_type] &
-+              MPT_DIAG_BUFFER_IS_REGISTERED) == 0) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x is not "
-+                  "registered\n", ioc->name, __FUNCTION__, buffer_type);
-+              return -EFAULT;
-+      }
-+      if ((ioc->DiagBuffer_Status[buffer_type] &
+       dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: Reregister "
+-              "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type));
++              "buffer_type=%x\n", ioc->name, __func__, buffer_type));
+       if ((ioc->DiagBuffer_Status[buffer_type] &
+-          MPT_DIAG_BUFFER_IS_RELEASED) == 0) {
 +              MPT_DIAG_BUFFER_IS_RELEASED) == 0) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x has not been "
-+                  "released\n", ioc->name, __FUNCTION__, buffer_type);
-+              return -EFAULT;
-+      }
-+
-+      if (karg.data.UniqueId != ioc->UniqueId[buffer_type]) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: unique_id=%x is not registered\n",
-+                  ioc->name, __FUNCTION__, karg.data.UniqueId);
-+              return -EFAULT;
-+      }
-+
-+      request_data = ioc->DiagBuffer[buffer_type];
-+      if (!request_data) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: doesn't have buffer for "
-+                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
-+              return -ENODEV;
-+      }
-+
-+      request_data_sz = ioc->DiagBuffer_sz[buffer_type];
-+      request_data_dma = ioc->DiagBuffer_dma[buffer_type];
-+      pci_free_consistent(ioc->pcidev, request_data_sz,
-+          request_data, request_data_dma);
-+      ioc->DiagBuffer[buffer_type] = NULL;
-+      ioc->DiagBuffer_Status[buffer_type] = 0;
-+      return 0;
-+}
-+
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/* QUERY DIAG BUFFER Routine.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -EBUSY  if previous command timout and IOC reset is not complete.
-+ *            -ENODEV if no such device/adapter
-+ *            -ETIME  if timer expires
-+ *            -ENOMEM if memory allocation error
-+ */
-+static int
-+mptctl_query_diag_buffer (unsigned long arg)
-+{
-+      mpt_diag_query_t        __user *uarg = (void __user *)arg;
-+      mpt_diag_query_t        karg;
-+      MPT_ADAPTER             *ioc;
-+      void *                  request_data;
-+      int                     iocnum, ii, rc;
-+      u8                      buffer_type;
-+
-+      rc = -EFAULT;
-+      if (copy_from_user(&karg, uarg, sizeof(mpt_diag_query_t))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+              "Unable to read in mpt_diag_query_t struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      karg.data.Flags = 0;
-+      if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-+              (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              goto out;
-+      }
-+
-+      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s enter.\n", ioc->name,
-+              __FUNCTION__));
-+      buffer_type = karg.data.BufferType;
-+      if (!(ioc->facts.IOCCapabilities & MPT_DIAG_CAPABILITY(buffer_type))) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: doesn't have Capability for "
-+                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
-+              goto out;
-+      }
-+
-+      if ((ioc->DiagBuffer_Status[buffer_type] &
-+              MPT_DIAG_BUFFER_IS_REGISTERED) == 0) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x is not "
-+                  "registered\n", ioc->name, __FUNCTION__, buffer_type);
-+              goto out;
-+      }
-+
-+      if (karg.data.UniqueId & 0xffffff00) {
-+              if (karg.data.UniqueId != ioc->UniqueId[buffer_type]) {
-+                      printk(MYIOC_s_DEBUG_FMT "%s: unique_id=%x is not "
-+                          "registered\n", ioc->name, __FUNCTION__,
-+                          karg.data.UniqueId);
-+                      goto out;
-+              }
-+      }
-+
-+      request_data = ioc->DiagBuffer[buffer_type];
-+      if (!request_data) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: doesn't have buffer for "
-+                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
-+              goto out;
-+      }
-+
-+      rc = 0;
-+      if (buffer_type == MPI_DIAG_BUF_TYPE_EXTENDED) {
-+              if (karg.data.ExtendedType != ioc->ExtendedType[buffer_type])
-+                      goto out;
-+      } else
-+              karg.data.ExtendedType = 0;
-+
-+      if (ioc->DiagBuffer_Status[buffer_type] & MPT_DIAG_BUFFER_IS_RELEASED)
-+              karg.data.Flags = 3;
-+      else
-+              karg.data.Flags = 7;
-+      karg.data.TraceLevel = ioc->TraceLevel[buffer_type];
-+      for (ii = 0; ii < 4; ii++)
-+              karg.data.ProductSpecific[ii] =
-+                  ioc->ProductSpecific[buffer_type][ii];
-+      karg.data.DataSize = ioc->DiagBuffer_sz[buffer_type];
-+      karg.data.DriverAddedBufferSize = 0;
-+      karg.data.UniqueId = ioc->UniqueId[buffer_type];
-+
-+ out:
-+      if (copy_to_user(uarg, &karg, sizeof(mpt_diag_query_t))) {
-+              printk(MYIOC_s_ERR_FMT "%s Unable to write mpt_diag_query_t "
-+                  "data @ %p\n", ioc->name, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+      return rc;
-+}
-+
-+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-+/* READ DIAG BUFFER Routine.
-+ *
-+ * Outputs:   None.
-+ * Return:    0 if successful
-+ *            -EFAULT if data unavailable
-+ *            -EBUSY  if previous command timout and IOC reset is not complete.
-+ *            -ENODEV if no such device/adapter
-+ *            -ETIME  if timer expires
-+ *            -ENOMEM if memory allocation error
-+ */
-+static int
-+mptctl_read_diag_buffer (unsigned long arg)
-+{
-+      mpt_diag_read_buffer_t  __user *uarg = (void __user *) arg;
-+      mpt_diag_read_buffer_t  karg;
-+      MPT_ADAPTER             *ioc;
-+      void                    *request_data, *diagData;
-+      dma_addr_t              request_data_dma;
-+      DiagBufferPostRequest_t *diag_buffer_post_request;
-+      DiagBufferPostReply_t   *diag_buffer_post_reply;
-+      MPT_FRAME_HDR           *mf;
-+      int                     iocnum, rc, ii;
-+      u8                      buffer_type;
-+      u32                     tmp;
-+      unsigned long           timeleft;
-+
-+      rc = 0;
-+      if (copy_from_user(&karg, uarg, sizeof(mpt_diag_read_buffer_t))) {
-+              printk(KERN_ERR "%s@%d::%s - "
-+              "Unable to read in mpt_diag_read_buffer_t struct @ %p\n",
-+                  __FILE__, __LINE__, __FUNCTION__, uarg);
-+              return -EFAULT;
-+      }
-+
-+      if (((iocnum = mpt_verify_adapter(karg.hdr.iocnum, &ioc)) < 0) ||
-+              (ioc == NULL)) {
-+              printk(KERN_ERR "%s::%s() @%d - ioc%d not found!\n",
-+                  __FILE__, __FUNCTION__, __LINE__, iocnum);
-+              return -ENODEV;
-+      }
-+
-+      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s enter.\n", ioc->name,
-+          __FUNCTION__));
-+      buffer_type = karg.data.UniqueId & 0x000000ff;
-+      if (!(ioc->facts.IOCCapabilities & MPT_DIAG_CAPABILITY(buffer_type))) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: doesn't have Capability "
-+                  "for buffer_type=%x\n", ioc->name, __FUNCTION__,
-+                  buffer_type);
-+              return -EFAULT;
-+      }
-+
-+      if (karg.data.UniqueId != ioc->UniqueId[buffer_type]) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: unique_id=%x is not registered\n",
-+                  ioc->name, __FUNCTION__, karg.data.UniqueId);
-+              return -EFAULT;
-+      }
-+
-+      request_data = ioc->DiagBuffer[buffer_type];
-+      if (!request_data) {
-+              printk(MYIOC_s_DEBUG_FMT "%s: doesn't have buffer for "
-+                  "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type);
-+              return -EFAULT;
-+      }
-+
-+      diagData = (void *)(request_data + karg.data.StartingOffset);
-+      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: diagData=%p "
-+          "request_data=%p StartingOffset=%x\n", ioc->name, __FUNCTION__,
-+          diagData, request_data, karg.data.StartingOffset));
-+
-+      if (copy_to_user((void __user *)&uarg->data.DiagnosticData[0],
-+          diagData, karg.data.BytesToRead)) {
-+              printk(MYIOC_s_ERR_FMT "%s: Unable to write "
-+                  "mpt_diag_read_buffer_t data @ %p\n", ioc->name,
-+                  __FUNCTION__, diagData);
-+              return -EFAULT;
-+      }
-+
-+      if ((karg.data.Flags & MPI_FW_DIAG_FLAG_REREGISTER) == 0)
-+              goto out;
-+
-+      dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: Reregister "
-+              "buffer_type=%x\n", ioc->name, __FUNCTION__, buffer_type));
-+      if ((ioc->DiagBuffer_Status[buffer_type] &
-+          MPT_DIAG_BUFFER_IS_RELEASED) == 0) {
-+              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x "
-+                  "is still registered\n", ioc->name, __FUNCTION__,
-+                  buffer_type));
-+              return rc;
-+      }
-+      /* Get a free request frame and save the message context.
-+      */
-+      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
-+              return -EAGAIN;
-+
-+      diag_buffer_post_request = (DiagBufferPostRequest_t *)mf;
-+      diag_buffer_post_request->Function = MPI_FUNCTION_DIAG_BUFFER_POST;
-+      diag_buffer_post_request->ChainOffset = 0;
-+      diag_buffer_post_request->BufferType = buffer_type;
-+      diag_buffer_post_request->TraceLevel =
-+              ioc->TraceLevel[buffer_type];
-+      diag_buffer_post_request->MsgFlags = 0;
-+      diag_buffer_post_request->Reserved1 = 0;
-+      diag_buffer_post_request->Reserved2 = 0;
-+      diag_buffer_post_request->Reserved3 = 0;
-+      diag_buffer_post_request->BufferAddress.High = 0;
-+      if ( buffer_type == MPI_DIAG_BUF_TYPE_EXTENDED )
-+              diag_buffer_post_request->ExtendedType =
-+                      cpu_to_le32(ioc->ExtendedType[buffer_type]);
-+      diag_buffer_post_request->BufferLength =
-+          cpu_to_le32(ioc->DiagBuffer_sz[buffer_type]);
-+      for (ii = 0; ii < 4; ii++)
-+              diag_buffer_post_request->ProductSpecific[ii] =
-+                  cpu_to_le32(ioc->ProductSpecific[buffer_type][ii]);
-+      request_data_dma = ioc->DiagBuffer_dma[buffer_type];
-+      tmp = request_data_dma & 0xFFFFFFFF;
-+      diag_buffer_post_request->BufferAddress.Low = cpu_to_le32(tmp);
-+      if (ioc->sg_addr_size == sizeof(u64)) {
-+              tmp = (u32)((u64)request_data_dma >> 32);
-+              diag_buffer_post_request->BufferAddress.High = cpu_to_le32(tmp);
-+      }
-+
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context,
-+          diag_buffer_post_request->MsgContext);
-+      INITIALIZE_MGMT_STATUS(ioc->ioctl_cmds.status)
-+      mpt_put_msg_frame(mptctl_id, ioc, mf);
-+      timeleft = wait_for_completion_timeout(&ioc->ioctl_cmds.done,
-+          MPT_IOCTL_DEFAULT_TIMEOUT*HZ);
-+      if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
-+              rc = -ETIME;
-+              printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name,
-+                  __FUNCTION__);
-+              if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
-+                      mpt_free_msg_frame(ioc, mf);
-+                      goto out;
-+              }
-+              if (!timeleft)
-+                      mptctl_timeout_expired(ioc, mf);
-+              goto out;
-+      }
-+
-+      /* process the completed Reply Message Frame */
-+      if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0) {
-+              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: status=%x\n",
-+                  ioc->name, __FUNCTION__, ioc->ioctl_cmds.status));
-+              rc = -EFAULT;
-+      }
-+
-+      diag_buffer_post_reply = (DiagBufferPostReply_t *)ioc->ioctl_cmds.reply;
-+      if (le16_to_cpu(diag_buffer_post_reply->IOCStatus) ==
-+          MPI_IOCSTATUS_SUCCESS) {
-+              if (diag_buffer_post_reply->MsgLength > 5)
-+                      ioc->DataSize[buffer_type] =
-+                          le32_to_cpu(diag_buffer_post_reply->TransferLength);
-+              ioc->DiagBuffer_Status[buffer_type] |=
-+                  MPT_DIAG_BUFFER_IS_REGISTERED;
-+      } else {
-+              dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: IOCStatus=%x "
-+                  "IOCLogInfo=%x\n", ioc->name, __FUNCTION__,
-+                  diag_buffer_post_reply->IOCStatus,
-+                  diag_buffer_post_reply->IOCLogInfo));
-+              rc = -EFAULT;
-+      }
-+
-+ out:
-+      CLEAR_MGMT_STATUS(ioc->ioctl_cmds.status)
-+      SET_MGMT_MSG_CONTEXT(ioc->ioctl_cmds.msg_context, 0);
-+      return rc;
-+}
---- /dev/null
-+++ b/drivers/message/fusion/rejected_ioctls/diag_buffer.h
-@@ -0,0 +1,101 @@
-+#define MPTDIAGREGISTER                               _IOWR(MPT_MAGIC_NUMBER,26,mpt_diag_register_t)
-+#define MPTDIAGRELEASE                                _IOWR(MPT_MAGIC_NUMBER,27,mpt_diag_release_t)
-+#define MPTDIAGUNREGISTER                     _IOWR(MPT_MAGIC_NUMBER,28,mpt_diag_unregister_t)
-+#define MPTDIAGQUERY                          _IOWR(MPT_MAGIC_NUMBER,29,mpt_diag_query_t)
-+#define MPTDIAGREADBUFFER                     _IOWR(MPT_MAGIC_NUMBER,30,mpt_diag_read_buffer_t)
-+
-+#define MPI_FW_DIAG_IOCTL                     (0x80646961)
-+#define MPI_FW_DIAG_TYPE_REGISTER             (0x00000001)
-+#define MPI_FW_DIAG_TYPE_UNREGISTER           (0x00000002)
-+#define MPI_FW_DIAG_TYPE_QUERY                        (0x00000003)
-+#define MPI_FW_DIAG_TYPE_READ_BUFFER          (0x00000004)
-+#define MPI_FW_DIAG_TYPE_RELEASE              (0x00000005)
-+
-+#define MPI_FW_DIAG_INVALID_UID                       (0x00000000)
-+#define FW_DIAGNOSTIC_BUFFER_COUNT            (3)
-+#define FW_DIAGNOSTIC_UID_NOT_FOUND           (0xFF)
-+
-+#define MPI_FW_DIAG_ERROR_SUCCESS             (0x00000000)
-+#define MPI_FW_DIAG_ERROR_FAILURE             (0x00000001)
-+#define MPI_FW_DIAG_ERROR_INVALID_PARAMETER   (0x00000002)
-+#define MPI_FW_DIAG_ERROR_POST_FAILED         (0x00000010)
-+#define MPI_FW_DIAG_ERROR_INVALID_UID         (0x00000011)
-+
-+#define MPI_FW_DIAG_ERROR_RELEASE_FAILED      (0x00000012)
-+#define MPI_FW_DIAG_ERROR_NO_BUFFER           (0x00000013)
-+#define MPI_FW_DIAG_ERROR_ALREADY_RELEASED    (0x00000014)
-+
-+#define MPT_DIAG_CAPABILITY(bufftype) (MPI_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER << bufftype)
-+
-+#define MPT_DIAG_BUFFER_IS_REGISTERED                 1
-+#define MPT_DIAG_BUFFER_IS_RELEASED           2
-+
-+typedef struct _MPI_FW_DIAG_REGISTER {
-+      u8                      TraceLevel;
-+      u8                      BufferType;
-+      u16                     Flags;
-+      u32                     ExtendedType;
-+      u32                     ProductSpecific[4];
-+      u32                     RequestedBufferSize;
-+      u32                     UniqueId;
-+} MPI_FW_DIAG_REGISTER, *PTR_MPI_FW_DIAG_REGISTER;
-+
-+typedef struct _mpt_diag_register {
-+      mpt_ioctl_header        hdr;
-+      MPI_FW_DIAG_REGISTER    data;
-+} mpt_diag_register_t;
-+
-+typedef struct _MPI_FW_DIAG_UNREGISTER {
-+      u32                     UniqueId;
-+} MPI_FW_DIAG_UNREGISTER, *PTR_MPI_FW_DIAG_UNREGISTER;
-+
-+typedef struct _mpt_diag_unregister {
-+      mpt_ioctl_header         hdr;
-+      MPI_FW_DIAG_UNREGISTER  data;
-+} mpt_diag_unregister_t;
-+
-+#define MPI_FW_DIAG_FLAG_APP_OWNED          (0x0001)
-+#define MPI_FW_DIAG_FLAG_BUFFER_VALID       (0x0002)
-+#define MPI_FW_DIAG_FLAG_FW_BUFFER_ACCESS   (0x0004)
-+
-+typedef struct _MPI_FW_DIAG_QUERY {
-+      u8                      TraceLevel;
-+      u8                      BufferType;
-+      u16                     Flags;
-+      u32                     ExtendedType;
-+      u32                     ProductSpecific[4];
-+      u32                     DataSize;
-+      u32                     DriverAddedBufferSize;
-+      u32                     UniqueId;
-+} MPI_FW_DIAG_QUERY, *PTR_MPI_FW_DIAG_QUERY;
-+
-+typedef struct _mpt_diag_query {
-+      mpt_ioctl_header        hdr;
-+      MPI_FW_DIAG_QUERY       data;
-+} mpt_diag_query_t;
-+
-+typedef struct _MPI_FW_DIAG_RELEASE {
-+      u32                     UniqueId;
-+} MPI_FW_DIAG_RELEASE, *PTR_MPI_FW_DIAG_RELEASE;
-+
-+typedef struct _mpt_diag_release {
-+      mpt_ioctl_header        hdr;
-+      MPI_FW_DIAG_RELEASE     data;
-+} mpt_diag_release_t;
-+
-+#define MPI_FW_DIAG_FLAG_REREGISTER         (0x0001)
-+
-+typedef struct _MPI_FW_DIAG_READ_BUFFER {
-+      u8                      Status;
-+      u8                      Reserved;
-+      u16                     Flags;
-+      u32                     StartingOffset;
-+      u32                     BytesToRead;
-+      u32                     UniqueId;
-+      u32                     DiagnosticData[1];
-+} MPI_FW_DIAG_READ_BUFFER, *PTR_MPI_FW_DIAG_READ_BUFFER;
-+
-+typedef struct _mpt_diag_read_buffer {
-+      mpt_ioctl_header        hdr;
-+      MPI_FW_DIAG_READ_BUFFER data;
-+} mpt_diag_read_buffer_t;
+               dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: buffer_type=%x "
+-                  "is still registered\n", ioc->name, __FUNCTION__,
++                  "is still registered\n", ioc->name, __func__,
+                   buffer_type));
+               return rc;
+       }
+       /* Get a free request frame and save the message context.
+       */
+-      if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)
++      mf = mpt_get_msg_frame(mptctl_id, ioc);
++      if (mf == NULL)
+               return -EAGAIN;
+       diag_buffer_post_request = (DiagBufferPostRequest_t *)mf;
+@@ -602,7 +610,7 @@ mptctl_read_diag_buffer (unsigned long a
+       diag_buffer_post_request->Reserved2 = 0;
+       diag_buffer_post_request->Reserved3 = 0;
+       diag_buffer_post_request->BufferAddress.High = 0;
+-      if ( buffer_type == MPI_DIAG_BUF_TYPE_EXTENDED )
++      if (buffer_type == MPI_DIAG_BUF_TYPE_EXTENDED)
+               diag_buffer_post_request->ExtendedType =
+                       cpu_to_le32(ioc->ExtendedType[buffer_type]);
+       diag_buffer_post_request->BufferLength =
+@@ -627,7 +635,7 @@ mptctl_read_diag_buffer (unsigned long a
+       if (!(ioc->ioctl_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               rc = -ETIME;
+               printk(MYIOC_s_WARN_FMT "%s: failed\n", ioc->name,
+-                  __FUNCTION__);
++                  __func__);
+               if (ioc->ioctl_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
+                       mpt_free_msg_frame(ioc, mf);
+                       goto out;
+@@ -640,7 +648,7 @@ mptctl_read_diag_buffer (unsigned long a
+       /* process the completed Reply Message Frame */
+       if ((ioc->ioctl_cmds.status & MPT_MGMT_STATUS_RF_VALID) == 0) {
+               dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: status=%x\n",
+-                  ioc->name, __FUNCTION__, ioc->ioctl_cmds.status));
++                  ioc->name, __func__, ioc->ioctl_cmds.status));
+               rc = -EFAULT;
+       }
+@@ -654,7 +662,7 @@ mptctl_read_diag_buffer (unsigned long a
+                   MPT_DIAG_BUFFER_IS_REGISTERED;
+       } else {
+               dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: IOCStatus=%x "
+-                  "IOCLogInfo=%x\n", ioc->name, __FUNCTION__,
++                  "IOCLogInfo=%x\n", ioc->name, __func__,
+                   diag_buffer_post_reply->IOCStatus,
+                   diag_buffer_post_reply->IOCLogInfo));
+               rc = -EFAULT;
+Index: linux-2.6.27/drivers/message/fusion/rejected_ioctls/diag_buffer.h
+===================================================================
+--- linux-2.6.27.orig/drivers/message/fusion/rejected_ioctls/diag_buffer.h
++++ linux-2.6.27/drivers/message/fusion/rejected_ioctls/diag_buffer.h
+@@ -1,8 +1,13 @@
+-#define MPTDIAGREGISTER                               _IOWR(MPT_MAGIC_NUMBER,26,mpt_diag_register_t)
+-#define MPTDIAGRELEASE                                _IOWR(MPT_MAGIC_NUMBER,27,mpt_diag_release_t)
+-#define MPTDIAGUNREGISTER                     _IOWR(MPT_MAGIC_NUMBER,28,mpt_diag_unregister_t)
+-#define MPTDIAGQUERY                          _IOWR(MPT_MAGIC_NUMBER,29,mpt_diag_query_t)
+-#define MPTDIAGREADBUFFER                     _IOWR(MPT_MAGIC_NUMBER,30,mpt_diag_read_buffer_t)
++#define MPTDIAGREGISTER       \
++      _IOWR(MPT_MAGIC_NUMBER, 26, mpt_diag_register_t)
++#define MPTDIAGRELEASE \
++      _IOWR(MPT_MAGIC_NUMBER, 27, mpt_diag_release_t)
++#define MPTDIAGUNREGISTER \
++      _IOWR(MPT_MAGIC_NUMBER, 28, mpt_diag_unregister_t)
++#define MPTDIAGQUERY \
++      _IOWR(MPT_MAGIC_NUMBER, 29, mpt_diag_query_t)
++#define MPTDIAGREADBUFFER \
++      _IOWR(MPT_MAGIC_NUMBER, 30, mpt_diag_read_buffer_t)
+ #define MPI_FW_DIAG_IOCTL                     (0x80646961)
+ #define MPI_FW_DIAG_TYPE_REGISTER             (0x00000001)
+@@ -25,7 +30,8 @@
+ #define MPI_FW_DIAG_ERROR_NO_BUFFER           (0x00000013)
+ #define MPI_FW_DIAG_ERROR_ALREADY_RELEASED    (0x00000014)
+-#define MPT_DIAG_CAPABILITY(bufftype) (MPI_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER << bufftype)
++#define MPT_DIAG_CAPABILITY(bufftype) \
++    (MPI_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER << bufftype)
+ #define MPT_DIAG_BUFFER_IS_REGISTERED                 1
+ #define MPT_DIAG_BUFFER_IS_RELEASED           2
index d2c27dc03f939148321275380c22b35218e150f1..047497034bb086ffc2c9eb126bb61095bb72a70f 100644 (file)
@@ -10,11 +10,11 @@ diff -upr linux-2.6.25/include/linux/netfilter/xt_owner.h linux-2.6.25-owner-xid
  };
  
  struct xt_owner_match_info {
-       u_int32_t uid_min, uid_max;
-       u_int32_t gid_min, gid_max;
-       u_int8_t match, invert;
-+      u_int32_t nid;
-+      u_int32_t xid;
+       __u32 uid_min, uid_max;
+       __u32 gid_min, gid_max;
+       __u8 match, invert;
++      __u32 nid;
++      __u32 xid;
  };
  
  #endif /* _XT_OWNER_MATCH_H */
index e539edac9d0d67fb9497669c44fc2bf677cf3250..3033271a900bd1f324887d4893af987d5e6a5052 100644 (file)
@@ -153,7 +153,7 @@ diff -urp v2.6.28/linux/net/ipv4/fib_frontend.c linux/net/ipv4/fib_frontend.c
        fib_res_put(&res);
        if (no_addr)
                goto last_resort;
--      if (rpf)
+-      if (rpf == 1)
 -              goto e_inval;
        fl.oif = dev->ifindex;
  
index 973c0edb9c6462c4fdaa12b9b4378e38de06d417..99c75921d52d820e3e1c6b698954c1c2e92d78c8 100644 (file)
@@ -8,39 +8,45 @@
  #include <linux/bootmem.h>
  #include <linux/syscalls.h>
 -#include <linux/suspend.h>
+ #include <linux/kexec.h>
  
  #include <asm/uaccess.h>
---- a/kernel/timer.c.org       2008-01-20 11:46:53.931178999 +0100
-+++ b/kernel/timer.c   2008-01-20 11:47:09.758637482 +0100
-@@ -32,13 +32,13 @@
- #include <linux/time.h>
- #include <linux/jiffies.h>
- #include <linux/posix-timers.h>
-+#include <linux/notifier.h>
-+#include <linux/suspend.h>
- #include <linux/cpu.h>
- #include <linux/syscalls.h>
- #include <linux/delay.h>
- #include <linux/tick.h>
- #include <linux/kallsyms.h>
--#include <linux/notifier.h>
--#include <linux/suspend.h>
- #include <asm/uaccess.h>
- #include <asm/unistd.h>
-
 --- e/include/linux/fs.h       2008-05-07 11:39:56.000000000 +0000
 +++ e/include/linux/fs.h       2008-05-07 11:43:49.907309587 +0000
-@@ -127,10 +127,10 @@
- #define MS_RELATIME   (1<<21) /* Update atime relative to mtime/ctime. */
+@@ -207,10 +207,13 @@
  #define MS_KERNMOUNT  (1<<22) /* this is a kern_mount call */
  #define MS_I_VERSION  (1<<23) /* Update inode I_version field */
--#define MS_FROZEN     (1<<24) /* Frozen by freeze_filesystems() */
+ #define MS_STRICTATIME        (1<<24) /* Always perform atime updates */
+-#define MS_FROZEN     (1<<25) /* Frozen by freeze_filesystems() */
  #define MS_ACTIVE     (1<<30)
  #define MS_NOUSER     (1<<31)
  
-+#define MS_FROZEN     (1<<29) /* Frozen by freeze_filesystems() */
++
++
++#define MS_FROZEN     (1<<29) /* Frozen by freeze_filesystems() */
++
  /*
   * Superblock flags that can be altered by MS_REMOUNT
   */
+
+--- e/include/linux/fs.h.orig  2009-07-20 14:35:32.000000000 +0200
++++ e/include/linux/fs.h       2009-07-20 14:37:27.086666353 +0200
+@@ -230,6 +230,8 @@
+ /* Inode flags - they have nothing to superblock flags now */
++#define S_ATOMIC_COPY 2048    /* Pages mapped with this inode need to be
++                                atomically copied (gem) */
+ #define S_SYNC                1       /* Writes are synced at once */
+ #define S_NOATIME     2       /* Do not update access times */
+ #define S_APPEND      4       /* Append-only file */
+@@ -240,8 +242,6 @@
+ #define S_NOCMTIME    128     /* Do not update file c/mtime */
+ #define S_SWAPFILE    256     /* Do not truncate: swapon got its bmaps */
+ #define S_PRIVATE     512     /* Inode is fs-internal */
+-#define S_ATOMIC_COPY 1024    /* Pages mapped with this inode need to be
+-                                 atomically copied (gem) */
+ /*
+  * Note that nosuid etc flags are inode-specific: setting some file-system
+
index f7741d179f088fd7d679864cd38912dddc9fa331..197df477702a0b8aaa2c5cc5060ee9ec00fdfcdd 100644 (file)
@@ -483,10 +483,10 @@ index 0000000..7a96186
 +
 diff --git a/Documentation/power/tuxonice.txt b/Documentation/power/tuxonice.txt
 new file mode 100644
-index 0000000..49199ff
+index 0000000..8900b45
 --- /dev/null
 +++ b/Documentation/power/tuxonice.txt
-@@ -0,0 +1,750 @@
+@@ -0,0 +1,948 @@
 +      --- TuxOnIce, version 3.0 ---
 +
 +1.  What is it?
@@ -560,11 +560,10 @@ index 0000000..49199ff
 +
 +   Compression support is implemented via the cryptoapi. You will therefore want
 +   to select any Cryptoapi transforms that you want to use on your image from
-+   the Cryptoapi menu while configuring your kernel. Part of the TuxOnIce patch
-+   adds a new cryptoapi compression called LZF. We recommend the use of this
-+   compression method - it is very fast and still achieves good compression.
++   the Cryptoapi menu while configuring your kernel. We recommend the use of the
++   LZO compression method - it is very fast and still achieves good compression.
 +
-+   You can also tell TuxOnIce to write it's image to an encrypted and/or
++   You can also tell TuxOnIce to write its image to an encrypted and/or
 +   compressed filesystem/swap partition. In that case, you don't need to do
 +   anything special for TuxOnIce when it comes to kernel configuration.
 +
@@ -822,6 +821,39 @@ index 0000000..49199ff
 +   configure sudo to allow you to invoke your hibernate script as an ordinary
 +   user.
 +
++   - alloc/failure_test
++
++   This debugging option provides a way of testing TuxOnIce's handling of
++   memory allocation failures. Each allocation type that TuxOnIce makes has
++   been given a unique number (see the source code). Echo the appropriate
++   number into this entry, and when TuxOnIce attempts to do that allocation,
++   it will pretend there was a failure and act accordingly.
++
++   - alloc/find_max_mem_allocated
++
++   This debugging option will cause TuxOnIce to find the maximum amount of
++   memory it used during a cycle, and report that information in debugging
++   information at the end of the cycle.
++
++   - alt_resume_param
++
++   Instead of powering down after writing a hibernation image, TuxOnIce
++   supports resuming from a different image. This entry lets you set the
++   location of the signature for that image (the resume= value you'd use
++   for it). Using an alternate image and keep_image mode, you can do things
++   like using an alternate image to power down an uninterruptible power
++   supply.
++
++   - block_io/target_outstanding_io
++
++   This value controls the amount of memory that the block I/O code says it
++   needs when the core code is calculating how much memory is needed for
++   hibernating and for resuming. It doesn't directly control the amount of
++   I/O that is submitted at any one time - that depends on the amount of
++   available memory (we may have more available than we asked for), the
++   throughput that is being achieved and the ability of the CPU to keep up
++   with disk throughput (particularly where we're compressing pages).
++
 +   - checksum/enabled
 +
 +   Use cryptoapi hashing routines to verify that Pageset2 pages don't change
@@ -849,6 +881,16 @@ index 0000000..49199ff
 +   This file returns information about your configuration that may be helpful
 +   in diagnosing problems with hibernating.
 +
++   - did_suspend_to_both:
++
++   This file can be used when you hibernate with powerdown method 3 (ie suspend
++   to ram after writing the image). There can be two outcomes in this case. We
++   can resume from the suspend-to-ram before the battery runs out, or we can run
++   out of juice and and up resuming like normal. This entry lets you find out,
++   post resume, which way we went. If the value is 1, we resumed from suspend
++   to ram. This can be useful when actions need to be run post suspend-to-ram
++   that don't need to be run if we did the normal resume from power off.
++
 +   - do_hibernate:
 +
 +   When anything is written to this file, the kernel side of TuxOnIce will
@@ -889,6 +931,37 @@ index 0000000..49199ff
 +   an image without actually doing a hibernation cycle. It is useful for
 +   diagnosing freezing and image preparation issues.
 +
++   - full_pageset2
++
++   TuxOnIce divides the pages that are stored in an image into two sets. The
++   difference between the two sets is that pages in pageset 1 are atomically
++   copied, and pages in pageset 2 are written to disk without being copied
++   first. A page CAN be written to disk without being copied first if and only
++   if its contents will not be modified or used at any time after userspace
++   processes are frozen. A page MUST be in pageset 1 if its contents are
++   modified or used at any time after userspace processes have been frozen.
++
++   Normally (ie if this option is enabled), TuxOnIce will put all pages on the
++   per-zone LRUs in pageset2, then remove those pages used by any userspace
++   user interface helper and TuxOnIce storage manager that are running,
++   together with pages used by the GEM memory manager introduced around 2.6.28
++   kernels.
++
++   If this option is disabled, a much more conservative approach will be taken.
++   The only pages in pageset2 will be those belonging to userspace processes,
++   with the exclusion of those belonging to the TuxOnIce userspace helpers
++   mentioned above. This will result in a much smaller pageset2, and will
++   therefore result in smaller images than are possible with this option
++   enabled.
++
++   - ignore_rootfs
++
++   TuxOnIce records which device is mounted as the root filesystem when
++   writing the hibernation image. It will normally check at resume time that
++   this device isn't already mounted - that would be a cause of filesystem
++   corruption. In some particular cases (RAM based root filesystems), you
++   might want to disable this check. This option allows you to do that.
++
 +   - image_exists:
 +
 +   Can be used in a script to determine whether a valid image exists at the
@@ -908,6 +981,23 @@ index 0000000..49199ff
 +   include/linux/suspend-debug.h with the values SUSPEND_ABORTED to
 +   SUSPEND_KEPT_IMAGE. This is a bitmask.
 +
++   - late_cpu_hotplug:
++
++   This sysfs entry controls whether cpu hotplugging is done - as normal - just
++   before (unplug) and after (replug) the atomic copy/restore (so that all
++   CPUs/cores are available for multithreaded I/O). The alternative is to
++   unplug all secondary CPUs/cores at the start of hibernating/resuming, and
++   replug them at the end of resuming. No multithreaded I/O will be possible in
++   this configuration, but the odd machine has been reported to require it.
++
++   - lid_file:
++
++   This determines which ACPI button file we look in to determine whether the
++   lid is open or closed after resuming from suspend to disk or power off.
++   If the entry is set to "lid/LID", we'll open /proc/acpi/button/lid/LID/state
++   and check its contents at the appropriate moment. See post_wake_state below
++   for more details on how this entry is used.
++
 +   - log_everything (CONFIG_PM_DEBUG):
 +
 +   Setting this option results in all messages printed being logged. Normally,
@@ -915,11 +1005,62 @@ index 0000000..49199ff
 +   logs. Useful for debugging. It can be toggled during a cycle by pressing
 +   'L'.
 +
++   - no_load_direct:
++
++   This is a debugging option. If, when loading the atomically copied pages of
++   an image, TuxOnIce finds that the destination address for a page is free,
++   it will normally allocate the image, load the data directly into that
++   address and skip it in the atomic restore. If this option is disabled, the
++   page will be loaded somewhere else and atomically restored like other pages.
++
++   - no_flusher_thread:
++
++   When doing multithreaded I/O (see below), the first online CPU can be used
++   to _just_ submit compressed pages when writing the image, rather than
++   compressing and submitting data. This option is normally disabled, but has
++   been included because Nigel would like to see whether it will be more useful
++   as the number of cores/cpus in computers increases.
++
++   - no_multithreaded_io:
++
++   TuxOnIce will normally create one thread per cpu/core on your computer,
++   each of which will then perform I/O. This will generally result in
++   throughput that's the maximum the storage medium can handle. There
++   shouldn't be any reason to disable multithreaded I/O now, but this option
++   has been retained for debugging purposes.
++
++   - no_pageset2
++
++   See the entry for full_pageset2 above for an explanation of pagesets.
++   Enabling this option causes TuxOnIce to do an atomic copy of all pages,
++   thereby limiting the maximum image size to 1/2 of memory, as swsusp does.
++
++   - no_pageset2_if_unneeded
++
++   See the entry for full_pageset2 above for an explanation of pagesets.
++   Enabling this option causes TuxOnIce to act like no_pageset2 was enabled
++   if and only it isn't needed anyway. This option may still make TuxOnIce
++   less reliable because pageset2 pages are normally used to store the
++   atomic copy - drivers that want to do allocations of larger amounts of
++   memory in one shot will be more likely to find that those amounts aren't
++   available if this option is enabled.
++
 +   - pause_between_steps (CONFIG_PM_DEBUG):
 +
 +   This option is used during debugging, to make TuxOnIce pause between
 +   each step of the process. It is ignored when the nice display is on.
 +
++   - post_wake_state:
++
++   TuxOnIce provides support for automatically waking after a user-selected
++   delay, and using a different powerdown method if the lid is still closed.
++   (Yes, we're assuming a laptop).  This entry lets you choose what state
++   should be entered next. The values are those described under
++   powerdown_method, below. It can be used to suspend to RAM after hibernating,
++   then powerdown properly (say) 20 minutes. It can also be used to power down
++   properly, then wake at (say) 6.30am and suspend to RAM until you're ready
++   to use the machine.
++
 +   - powerdown_method:
 +
 +   Used to select a method by which TuxOnIce should powerdown after writing the
@@ -966,6 +1107,28 @@ index 0000000..49199ff
 +   at the end of saving an image. It can be toggled during a cycle by pressing
 +   'R'.
 +
++   - resume:
++
++   This sysfs entry can be used to read and set the location in which TuxOnIce
++   will look for the signature of an image - the value set using resume= at
++   boot time or CONFIG_PM_STD_PARTITION ("Default resume partition"). By
++   writing to this file as well as modifying your bootloader's configuration
++   file (eg menu.lst), you can set or reset the location of your image or the
++   method of storing the image without rebooting.
++
++   - replace_swsusp (CONFIG_TOI_REPLACE_SWSUSP):
++
++   This option makes
++
++     echo disk > /sys/power/state
++
++   activate TuxOnIce instead of swsusp. Regardless of whether this option is
++   enabled, any invocation of swsusp's resume time trigger will cause TuxOnIce
++   to check for an image too. This is due to the fact that at resume time, we
++   can't know whether this option was enabled until we see if an image is there
++   for us to resume from. (And when an image exists, we don't care whether we
++   did replace swsusp anyway - we just want to resume).
++
 +   - resume_commandline:
 +
 +   This entry can be read after resuming to see the commandline that was used
@@ -1000,12 +1163,23 @@ index 0000000..49199ff
 +   currently have activated. It is particularly useful when you only want to
 +   use a swap file to store your image. See above for further details.
 +
-+   - userui_program
++   - test_bio
 +
-+   This entry is used to tell TuxOnice what userspace program to use for
-+   providing a user interface while hibernating. The program uses a netlink
-+   socket to pass messages back and forward to the kernel, allowing all of the
-+   functions formerly implemented in the kernel user interface components.
++   This is a debugging option. When enabled, TuxOnIce will not hibernate.
++   Instead, when asked to write an image, it will skip the atomic copy,
++   just doing the writing of the image and then returning control to the
++   user at the point where it would have powered off. This is useful for
++   testing throughput in different configurations.
++
++   - test_filter_speed
++
++   This is a debugging option. When enabled, TuxOnIce will not hibernate.
++   Instead, when asked to write an image, it will not write anything or do
++   an atomic copy, but will only run any enabled compression algorithm on the
++   data that would have been written (the source pages of the atomic copy in
++   the case of pageset 1). This is useful for comparing the performance of
++   compression algorithms and for determining the extent to which an upgrade
++   to your storage method would improve hibernation speed.
 +
 +   - user_interface/debug_sections (CONFIG_PM_DEBUG):
 +
@@ -1035,17 +1209,41 @@ index 0000000..49199ff
 +   Setting this to "1" will enable you abort a hibernation cycle or resuming by
 +   pressing escape, "0" (default) disables this feature. Note that enabling
 +   this option means that you cannot initiate a hibernation cycle and then walk
-+away
-+   from your computer, expecting it to be secure. With feature disabled,
++   away from your computer, expecting it to be secure. With feature disabled,
 +   you can validly have this expectation once TuxOnice begins to write the
 +   image to disk. (Prior to this point, it is possible that TuxOnice might
 +   about because of failure to freeze all processes or because constraints
 +   on its ability to save the image are not met).
 +
++   - user_interface/program
++
++   This entry is used to tell TuxOnice what userspace program to use for
++   providing a user interface while hibernating. The program uses a netlink
++   socket to pass messages back and forward to the kernel, allowing all of the
++   functions formerly implemented in the kernel user interface components.
++
 +   - version:
 +
 +   The version of TuxOnIce you have compiled into the currently running kernel.
 +
++   - wake_alarm_dir:
++
++   As mentioned above (post_wake_state), TuxOnIce supports automatically waking
++   after some delay. This entry allows you to select which wake alarm to use.
++   It should contain the value "rtc0" if you're wanting to use
++   /sys/class/rtc/rtc0.
++
++   - wake_delay:
++
++   This value determines the delay from the end of writing the image until the
++   wake alarm is triggered. You can set an absolute time by writing the desired
++   time into /sys/class/rtc/<wake_alarm_dir>/wakealarm and leaving these values
++   empty.
++
++   Note that for the wakeup to actually occur, you may need to modify entries
++   in /proc/acpi/wakeup. This is done by echoing the name of the button in the
++   first column (eg PBTN) into the file.
++
 +7. How do you get support?
 +
 +   Glad you asked. TuxOnIce is being actively maintained and supported
@@ -1238,12 +1436,12 @@ index 0000000..49199ff
 +   testing. His efforts have contributed as much to TuxOnIce as any of the
 +   names above.
 diff --git a/MAINTAINERS b/MAINTAINERS
-index 5d460c9..a39a4fb 100644
+index cf4abdd..979b923 100644
 --- a/MAINTAINERS
 +++ b/MAINTAINERS
-@@ -4343,6 +4343,13 @@ P:      Maciej W. Rozycki
- M:    macro@linux-mips.org
- S:    Maintained
+@@ -5655,6 +5655,13 @@ S:      Maintained
+ F:    drivers/tc/
+ F:    include/linux/tc.h
  
 +TUXONICE (ENHANCED HIBERNATION)
 +P:    Nigel Cunningham
@@ -1256,10 +1454,10 @@ index 5d460c9..a39a4fb 100644
  P:    Dario Ballabio
  M:    ballabio_dario@emc.com
 diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
-index 58bcaeb..f5e16a4 100644
+index 5422169..33be4fa 100644
 --- a/arch/powerpc/mm/pgtable_32.c
 +++ b/arch/powerpc/mm/pgtable_32.c
-@@ -388,6 +388,7 @@ void kernel_map_pages(struct page *page, int numpages, int enable)
+@@ -396,6 +396,7 @@ void kernel_map_pages(struct page *page, int numpages, int enable)
  
        change_page_attr(page, numpages, enable ? PAGE_KERNEL : __pgprot(0));
  }
@@ -1268,10 +1466,10 @@ index 58bcaeb..f5e16a4 100644
  
  static int fixmaps;
 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
-index 4526b3a..6851f01 100644
+index 667188e..8113e78 100644
 --- a/arch/x86/kernel/reboot.c
 +++ b/arch/x86/kernel/reboot.c
-@@ -605,6 +605,7 @@ void machine_restart(char *cmd)
+@@ -620,6 +620,7 @@ void machine_restart(char *cmd)
  {
        machine_ops.restart(cmd);
  }
@@ -1280,10 +1478,10 @@ index 4526b3a..6851f01 100644
  void machine_halt(void)
  {
 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
-index 7233bd7..0079a2c 100644
+index e17efed..5d0b4d2 100644
 --- a/arch/x86/mm/pageattr.c
 +++ b/arch/x86/mm/pageattr.c
-@@ -1154,6 +1154,7 @@ void kernel_map_pages(struct page *page, int numpages, int enable)
+@@ -1268,6 +1268,7 @@ void kernel_map_pages(struct page *page, int numpages, int enable)
         */
        __flush_tlb_all();
  }
@@ -1291,7 +1489,7 @@ index 7233bd7..0079a2c 100644
  
  #ifdef CONFIG_HIBERNATION
  
-@@ -1168,7 +1169,7 @@ bool kernel_page_present(struct page *page)
+@@ -1282,7 +1283,7 @@ bool kernel_page_present(struct page *page)
        pte = lookup_address((unsigned long)page_address(page), &level);
        return (pte_val(*pte) & _PAGE_PRESENT);
  }
@@ -1301,7 +1499,7 @@ index 7233bd7..0079a2c 100644
  
  #endif /* CONFIG_DEBUG_PAGEALLOC */
 diff --git a/arch/x86/power/cpu_64.c b/arch/x86/power/cpu_64.c
-index e3b6cf7..bdd74a8 100644
+index 5343540..d2d55bd 100644
 --- a/arch/x86/power/cpu_64.c
 +++ b/arch/x86/power/cpu_64.c
 @@ -10,6 +10,7 @@
@@ -1312,7 +1510,7 @@ index e3b6cf7..bdd74a8 100644
  #include <asm/proto.h>
  #include <asm/page.h>
  #include <asm/pgtable.h>
-@@ -76,6 +77,7 @@ void save_processor_state(void)
+@@ -77,6 +78,7 @@ void save_processor_state(void)
  {
        __save_processor_state(&saved_context);
  }
@@ -1341,7 +1539,7 @@ index 81197c6..ff7e534 100644
  /*
   *    pfn_is_nosave - check if given pfn is in the 'nosave' section
 diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c
-index 6dd000d..b42e72a 100644
+index 65fdc86..e5c31f6 100644
 --- a/arch/x86/power/hibernate_64.c
 +++ b/arch/x86/power/hibernate_64.c
 @@ -10,6 +10,7 @@
@@ -1352,7 +1550,7 @@ index 6dd000d..b42e72a 100644
  #include <asm/proto.h>
  #include <asm/page.h>
  #include <asm/pgtable.h>
-@@ -117,6 +118,7 @@ int swsusp_arch_resume(void)
+@@ -118,6 +119,7 @@ int swsusp_arch_resume(void)
        restore_image();
        return 0;
  }
@@ -1360,28 +1558,16 @@ index 6dd000d..b42e72a 100644
  
  /*
   *    pfn_is_nosave - check if given pfn is in the 'nosave' section
-@@ -167,3 +169,4 @@ int arch_hibernation_header_restore(void *addr)
+@@ -168,3 +170,4 @@ int arch_hibernation_header_restore(void *addr)
        restore_cr3 = rdr->cr3;
        return (rdr->magic == RESTORE_MAGIC) ? 0 : -EINVAL;
  }
 +EXPORT_SYMBOL_GPL(arch_hibernation_header_restore);
-diff --git a/drivers/base/dd.c b/drivers/base/dd.c
-index 1352312..f705dce 100644
---- a/drivers/base/dd.c
-+++ b/drivers/base/dd.c
-@@ -183,6 +183,7 @@ int wait_for_device_probe(void)
-       async_synchronize_full();
-       return 0;
- }
-+EXPORT_SYMBOL_GPL(wait_for_device_probe);
- /**
-  * driver_probe_device - attempt to bind device & driver together
 diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
-index 2d14f4a..dc9ef3b 100644
+index 3e4bc69..80612e3 100644
 --- a/drivers/base/power/main.c
 +++ b/drivers/base/power/main.c
-@@ -54,6 +54,7 @@ void device_pm_lock(void)
+@@ -55,6 +55,7 @@ void device_pm_lock(void)
  {
        mutex_lock(&dpm_list_mtx);
  }
@@ -1389,7 +1575,7 @@ index 2d14f4a..dc9ef3b 100644
  
  /**
   *    device_pm_unlock - unlock the list of active devices used by the PM core
-@@ -62,6 +63,7 @@ void device_pm_unlock(void)
+@@ -63,6 +64,7 @@ void device_pm_unlock(void)
  {
        mutex_unlock(&dpm_list_mtx);
  }
@@ -1398,7 +1584,7 @@ index 2d14f4a..dc9ef3b 100644
  /**
   *    device_pm_add - add a device to the list of active devices
 diff --git a/drivers/char/vt.c b/drivers/char/vt.c
-index 7900bd6..a5a8717 100644
+index 08151d4..7377d98 100644
 --- a/drivers/char/vt.c
 +++ b/drivers/char/vt.c
 @@ -187,6 +187,7 @@ int fg_console;
@@ -1410,7 +1596,7 @@ index 7900bd6..a5a8717 100644
  /*
   * For each existing display, we have a pointer to console currently visible
 diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
-index 88d3368..5817513 100644
+index 4984aa8..c69b548 100644
 --- a/drivers/gpu/drm/drm_gem.c
 +++ b/drivers/gpu/drm/drm_gem.c
 @@ -136,7 +136,8 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
@@ -1424,18 +1610,10 @@ index 88d3368..5817513 100644
                kfree(obj);
                return NULL;
 diff --git a/drivers/md/md.c b/drivers/md/md.c
-index a307f87..6eb04ea 100644
+index 641b211..73ccc45 100644
 --- a/drivers/md/md.c
 +++ b/drivers/md/md.c
-@@ -5778,7 +5778,6 @@ void md_done_sync(mddev_t *mddev, int blocks, int ok)
-       }
- }
--
- /* md_write_start(mddev, bi)
-  * If we need to update some array metadata (e.g. 'active' flag
-  * in superblock) before writing, schedule a superblock update
-@@ -5922,6 +5921,9 @@ void md_do_sync(mddev_t *mddev)
+@@ -6251,6 +6251,9 @@ void md_do_sync(mddev_t *mddev)
                mddev->curr_resync = 2;
  
        try_again:
@@ -1445,7 +1623,7 @@ index a307f87..6eb04ea 100644
                if (kthread_should_stop()) {
                        set_bit(MD_RECOVERY_INTR, &mddev->recovery);
                        goto skip;
-@@ -5943,6 +5945,10 @@ void md_do_sync(mddev_t *mddev)
+@@ -6272,6 +6275,10 @@ void md_do_sync(mddev_t *mddev)
                                         * time 'round when curr_resync == 2
                                         */
                                        continue;
@@ -1456,7 +1634,7 @@ index a307f87..6eb04ea 100644
                                /* We need to wait 'interruptible' so as not to
                                 * contribute to the load average, and not to
                                 * be caught by 'softlockup'
-@@ -5955,6 +5961,7 @@ void md_do_sync(mddev_t *mddev)
+@@ -6284,6 +6291,7 @@ void md_do_sync(mddev_t *mddev)
                                               " share one or more physical units)\n",
                                               desc, mdname(mddev), mdname(mddev2));
                                        mddev_put(mddev2);
@@ -1464,18 +1642,17 @@ index a307f87..6eb04ea 100644
                                        if (signal_pending(current))
                                                flush_signals(current);
                                        schedule();
-@@ -6038,6 +6045,10 @@ void md_do_sync(mddev_t *mddev)
+@@ -6384,6 +6392,9 @@ void md_do_sync(mddev_t *mddev)
                                   mddev->resync_max > j
                                   || kthread_should_stop());
-               }
-+
 +              while (freezer_is_on())
 +                      yield();
 +
                if (kthread_should_stop())
                        goto interrupted;
-               sectors = mddev->pers->sync_request(mddev, j, &skipped,
-@@ -6081,6 +6092,9 @@ void md_do_sync(mddev_t *mddev)
+@@ -6428,6 +6439,9 @@ void md_do_sync(mddev_t *mddev)
                        last_mark = next;
                }
  
@@ -1485,11 +1662,11 @@ index a307f87..6eb04ea 100644
  
                if (kthread_should_stop())
                        goto interrupted;
-diff --git a/fs/buffer.c b/fs/buffer.c
-index 891e1c7..cb8c84a 100644
---- a/fs/buffer.c
-+++ b/fs/buffer.c
-@@ -310,6 +310,93 @@ int thaw_bdev(struct block_device *bdev, struct super_block *sb)
+diff --git a/fs/block_dev.c b/fs/block_dev.c
+index f45dbc1..52a7869 100644
+--- a/fs/block_dev.c
++++ b/fs/block_dev.c
+@@ -321,6 +321,93 @@ int thaw_bdev(struct block_device *bdev, struct super_block *sb)
  }
  EXPORT_SYMBOL(thaw_bdev);
  
@@ -1580,11 +1757,11 @@ index 891e1c7..cb8c84a 100644
 +      lockdep_on();
 +}
 +
- /*
-  * Various filesystems appear to want __find_get_block to be non-blocking.
-  * But it's the page lock which protects the buffers.  To get around this,
+ static int blkdev_writepage(struct page *page, struct writeback_control *wbc)
+ {
+       return block_write_full_page(page, blkdev_get_block, wbc);
 diff --git a/fs/drop_caches.c b/fs/drop_caches.c
-index 3e5637f..f3c5cd6 100644
+index b6a719a..30ef3f3 100644
 --- a/fs/drop_caches.c
 +++ b/fs/drop_caches.c
 @@ -8,6 +8,7 @@
@@ -1664,7 +1841,7 @@ index ba76b68..e9942d4 100644
        if (nbytes < sizeof(struct fuse_out_header))
                return -EINVAL;
 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
-index fdff346..1fd3cd1 100644
+index 8b8eebc..31cda20 100644
 --- a/fs/fuse/dir.c
 +++ b/fs/fuse/dir.c
 @@ -7,12 +7,14 @@
@@ -1781,7 +1958,7 @@ index fdff346..1fd3cd1 100644
                return PTR_ERR(req);
  
 diff --git a/fs/fuse/file.c b/fs/fuse/file.c
-index 821d10f..4b8b86f 100644
+index 06f30e9..80ad032 100644
 --- a/fs/fuse/file.c
 +++ b/fs/fuse/file.c
 @@ -7,11 +7,13 @@
@@ -1825,7 +2002,7 @@ index 821d10f..4b8b86f 100644
        /*
         * Start writeback against all dirty pages of the inode, then
         * wait for all outstanding writes, before sending the FSYNC
-@@ -438,6 +446,8 @@ static int fuse_readpage(struct file *file, struct page *page)
+@@ -437,6 +445,8 @@ static int fuse_readpage(struct file *file, struct page *page)
        if (is_bad_inode(inode))
                goto out;
  
@@ -1834,7 +2011,7 @@ index 821d10f..4b8b86f 100644
        /*
         * Page writeback can extend beyond the liftime of the
         * page-cache page, so make sure we read a properly synced
-@@ -538,6 +548,9 @@ static int fuse_readpages_fill(void *_data, struct page *page)
+@@ -540,6 +550,9 @@ static int fuse_readpages_fill(void *_data, struct page *page)
        struct inode *inode = data->inode;
        struct fuse_conn *fc = get_fuse_conn(inode);
  
@@ -1844,7 +2021,7 @@ index 821d10f..4b8b86f 100644
        fuse_wait_on_page_writeback(inode, page->index);
  
        if (req->num_pages &&
-@@ -568,6 +581,8 @@ static int fuse_readpages(struct file *file, struct address_space *mapping,
+@@ -570,6 +583,8 @@ static int fuse_readpages(struct file *file, struct address_space *mapping,
        if (is_bad_inode(inode))
                goto out;
  
@@ -1853,7 +2030,7 @@ index 821d10f..4b8b86f 100644
        data.file = file;
        data.inode = inode;
        data.req = fuse_get_req(fc);
-@@ -685,6 +700,8 @@ static int fuse_buffered_write(struct file *file, struct inode *inode,
+@@ -686,6 +701,8 @@ static int fuse_buffered_write(struct file *file, struct inode *inode,
        if (is_bad_inode(inode))
                return -EIO;
  
@@ -1862,7 +2039,7 @@ index 821d10f..4b8b86f 100644
        /*
         * Make sure writepages on the same page are not mixed up with
         * plain writes.
-@@ -839,6 +856,8 @@ static ssize_t fuse_perform_write(struct file *file,
+@@ -842,6 +859,8 @@ static ssize_t fuse_perform_write(struct file *file,
                struct fuse_req *req;
                ssize_t count;
  
@@ -1871,7 +2048,7 @@ index 821d10f..4b8b86f 100644
                req = fuse_get_req(fc);
                if (IS_ERR(req)) {
                        err = PTR_ERR(req);
-@@ -973,6 +992,8 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
+@@ -992,6 +1011,8 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
        if (is_bad_inode(inode))
                return -EIO;
  
@@ -1880,7 +2057,7 @@ index 821d10f..4b8b86f 100644
        req = fuse_get_req(fc);
        if (IS_ERR(req))
                return PTR_ERR(req);
-@@ -1330,6 +1351,8 @@ static int fuse_getlk(struct file *file, struct file_lock *fl)
+@@ -1360,6 +1381,8 @@ static int fuse_getlk(struct file *file, struct file_lock *fl)
        struct fuse_lk_out outarg;
        int err;
  
@@ -1889,7 +2066,7 @@ index 821d10f..4b8b86f 100644
        req = fuse_get_req(fc);
        if (IS_ERR(req))
                return PTR_ERR(req);
-@@ -1365,6 +1388,8 @@ static int fuse_setlk(struct file *file, struct file_lock *fl, int flock)
+@@ -1395,6 +1418,8 @@ static int fuse_setlk(struct file *file, struct file_lock *fl, int flock)
        if (fl->fl_flags & FL_CLOSE)
                return 0;
  
@@ -1898,7 +2075,7 @@ index 821d10f..4b8b86f 100644
        req = fuse_get_req(fc);
        if (IS_ERR(req))
                return PTR_ERR(req);
-@@ -1431,6 +1456,8 @@ static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
+@@ -1461,6 +1486,8 @@ static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
        if (!inode->i_sb->s_bdev || fc->no_bmap)
                return 0;
  
@@ -1927,10 +2104,10 @@ index 0000000..170e49a
 +      } \
 +} while (0)
 diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
-index 459b73d..f4dfbf5 100644
+index 91f7c85..cb18b16 100644
 --- a/fs/fuse/inode.c
 +++ b/fs/fuse/inode.c
-@@ -925,7 +925,7 @@ static int fuse_get_sb(struct file_system_type *fs_type,
+@@ -929,7 +929,7 @@ static int fuse_get_sb(struct file_system_type *fs_type,
  static struct file_system_type fuse_fs_type = {
        .owner          = THIS_MODULE,
        .name           = "fuse",
@@ -1939,7 +2116,7 @@ index 459b73d..f4dfbf5 100644
        .get_sb         = fuse_get_sb,
        .kill_sb        = kill_anon_super,
  };
-@@ -944,7 +944,7 @@ static struct file_system_type fuseblk_fs_type = {
+@@ -948,7 +948,7 @@ static struct file_system_type fuseblk_fs_type = {
        .name           = "fuseblk",
        .get_sb         = fuse_get_sb_blk,
        .kill_sb        = kill_block_super,
@@ -1949,20 +2126,20 @@ index 459b73d..f4dfbf5 100644
  
  static inline int register_fuseblk(void)
 diff --git a/fs/namei.c b/fs/namei.c
-index bbc15c2..11271b2 100644
+index 967c3db..bffeb61 100644
 --- a/fs/namei.c
 +++ b/fs/namei.c
-@@ -2210,6 +2210,8 @@ int vfs_unlink(struct inode *dir, struct dentry *dentry)
+@@ -2220,6 +2220,8 @@ int vfs_unlink(struct inode *dir, struct dentry *dentry)
        if (!dir->i_op->unlink)
                return -EPERM;
  
 +      vfs_check_frozen(dir->i_sb, SB_FREEZE_WRITE);
 +
-       DQUOT_INIT(dir);
+       vfs_dq_init(dir);
  
        mutex_lock(&dentry->d_inode->i_mutex);
 diff --git a/fs/super.c b/fs/super.c
-index 6ce5014..5030f0f 100644
+index 1943fdf..0ad40de 100644
 --- a/fs/super.c
 +++ b/fs/super.c
 @@ -44,6 +44,8 @@
@@ -1975,10 +2152,10 @@ index 6ce5014..5030f0f 100644
  
  /**
 diff --git a/include/linux/Kbuild b/include/linux/Kbuild
-index 106c3ba..17a95d2 100644
+index 3f0eaa3..40e2a83 100644
 --- a/include/linux/Kbuild
 +++ b/include/linux/Kbuild
-@@ -208,6 +208,7 @@ unifdef-y += filter.h
+@@ -209,6 +209,7 @@ unifdef-y += filter.h
  unifdef-y += flat.h
  unifdef-y += futex.h
  unifdef-y += fs.h
@@ -1986,22 +2163,6 @@ index 106c3ba..17a95d2 100644
  unifdef-y += gameport.h
  unifdef-y += generic_serial.h
  unifdef-y += hayesesp.h
-diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
-index bd7ac79..09044e6 100644
---- a/include/linux/buffer_head.h
-+++ b/include/linux/buffer_head.h
-@@ -172,6 +172,11 @@ wait_queue_head_t *bh_waitq_head(struct buffer_head *bh);
- int fsync_bdev(struct block_device *);
- struct super_block *freeze_bdev(struct block_device *);
- int thaw_bdev(struct block_device *, struct super_block *);
-+#define FS_FREEZER_FUSE 1
-+#define FS_FREEZER_NORMAL 2
-+#define FS_FREEZER_ALL (FS_FREEZER_FUSE | FS_FREEZER_NORMAL)
-+void freeze_filesystems(int which);
-+void thaw_filesystems(int which);
- int fsync_super(struct super_block *);
- int fsync_no_super(struct block_device *);
- struct buffer_head *__find_get_block(struct block_device *bdev, sector_t block,
 diff --git a/include/linux/freezer.h b/include/linux/freezer.h
 index 5a361f8..c775cd1 100644
 --- a/include/linux/freezer.h
@@ -2040,7 +2201,7 @@ index 5a361f8..c775cd1 100644
  static inline void freezer_do_not_count(void) {}
  static inline void freezer_count(void) {}
 diff --git a/include/linux/fs.h b/include/linux/fs.h
-index 92734c0..249df0f 100644
+index 3b534e5..46dc165 100644
 --- a/include/linux/fs.h
 +++ b/include/linux/fs.h
 @@ -8,6 +8,7 @@
@@ -2051,7 +2212,7 @@ index 92734c0..249df0f 100644
  
  /*
   * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
-@@ -109,6 +110,7 @@ struct inodes_stat_t {
+@@ -172,6 +173,7 @@ struct inodes_stat_t {
  #define FS_REQUIRES_DEV 1 
  #define FS_BINARY_MOUNTDATA 2
  #define FS_HAS_SUBTYPE 4
@@ -2059,15 +2220,15 @@ index 92734c0..249df0f 100644
  #define FS_REVAL_DOT  16384   /* Check the paths ".", ".." for staleness */
  #define FS_RENAME_DOES_D_MOVE 32768   /* FS will handle d_move()
                                         * during rename() internally.
-@@ -141,6 +143,7 @@ struct inodes_stat_t {
- #define MS_RELATIME   (1<<21) /* Update atime relative to mtime/ctime. */
+@@ -205,6 +207,7 @@ struct inodes_stat_t {
  #define MS_KERNMOUNT  (1<<22) /* this is a kern_mount call */
  #define MS_I_VERSION  (1<<23) /* Update inode I_version field */
-+#define MS_FROZEN     (1<<24) /* Frozen by freeze_filesystems() */
+ #define MS_STRICTATIME        (1<<24) /* Always perform atime updates */
++#define MS_FROZEN     (1<<25) /* Frozen by freeze_filesystems() */
  #define MS_ACTIVE     (1<<30)
  #define MS_NOUSER     (1<<31)
  
-@@ -167,6 +170,8 @@ struct inodes_stat_t {
+@@ -231,6 +234,8 @@ struct inodes_stat_t {
  #define S_NOCMTIME    128     /* Do not update file c/mtime */
  #define S_SWAPFILE    256     /* Do not truncate: swapon got its bmaps */
  #define S_PRIVATE     512     /* Inode is fs-internal */
@@ -2076,7 +2237,7 @@ index 92734c0..249df0f 100644
  
  /*
   * Note that nosuid etc flags are inode-specific: setting some file-system
-@@ -1216,8 +1221,11 @@ enum {
+@@ -1390,8 +1395,11 @@ enum {
        SB_FREEZE_TRANS = 2,
  };
  
@@ -2090,19 +2251,31 @@ index 92734c0..249df0f 100644
  
  #define get_fs_excl() atomic_inc(&current->fs_excl)
  #define put_fs_excl() atomic_dec(&current->fs_excl)
+@@ -1949,6 +1957,11 @@ extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
+ extern int fsync_bdev(struct block_device *);
+ extern int fsync_super(struct super_block *);
+ extern int fsync_no_super(struct block_device *);
++#define FS_FREEZER_FUSE 1
++#define FS_FREEZER_NORMAL 2
++#define FS_FREEZER_ALL (FS_FREEZER_FUSE | FS_FREEZER_NORMAL)
++void freeze_filesystems(int which);
++void thaw_filesystems(int which);
+ #else
+ static inline void bd_forget(struct inode *inode) {}
+ static inline int sync_blockdev(struct block_device *bdev) { return 0; }
 diff --git a/include/linux/mm.h b/include/linux/mm.h
-index 3daa05f..8497a33 100644
+index bff1f0d..c4199cd 100644
 --- a/include/linux/mm.h
 +++ b/include/linux/mm.h
-@@ -104,6 +104,7 @@ extern unsigned int kobjsize(const void *objp);
- #define VM_CAN_NONLINEAR 0x08000000   /* Has ->fault & does nonlinear pages */
+@@ -105,6 +105,7 @@ extern unsigned int kobjsize(const void *objp);
  #define VM_MIXEDMAP   0x10000000      /* Can contain "struct page" and pure PFN pages */
  #define VM_SAO                0x20000000      /* Strong Access Ordering (powerpc) */
-+#define VM_ATOMIC_COPY        0x40000000      /* This VM should be atomically copied by TuxOnIce */
+ #define VM_PFN_AT_MMAP        0x40000000      /* PFNMAP vma that is fully mapped at mmap time */
++#define VM_ATOMIC_COPY        0x80000000      /* TuxOnIce should atomically copy */
  
  #ifndef VM_STACK_DEFAULT_FLAGS                /* arch can override this */
  #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
-@@ -1305,6 +1306,7 @@ int drop_caches_sysctl_handler(struct ctl_table *, int, struct file *,
+@@ -1297,6 +1298,7 @@ int drop_caches_sysctl_handler(struct ctl_table *, int, struct file *,
                                        void __user *, size_t *, loff_t *);
  unsigned long shrink_slab(unsigned long scanned, gfp_t gfp_mask,
                        unsigned long lru_pages);
@@ -2111,7 +2284,7 @@ index 3daa05f..8497a33 100644
  #ifndef CONFIG_MMU
  #define randomize_va_space 0
 diff --git a/include/linux/netlink.h b/include/linux/netlink.h
-index 51b09a1..a35eb65 100644
+index 5ba398e..f220828 100644
 --- a/include/linux/netlink.h
 +++ b/include/linux/netlink.h
 @@ -24,6 +24,8 @@
@@ -2124,10 +2297,10 @@ index 51b09a1..a35eb65 100644
  #define MAX_LINKS 32          
  
 diff --git a/include/linux/suspend.h b/include/linux/suspend.h
-index c7d9bb1..8e7de98 100644
+index 795032e..1f52617 100644
 --- a/include/linux/suspend.h
 +++ b/include/linux/suspend.h
-@@ -295,4 +295,70 @@ static inline void register_nosave_region_late(unsigned long b, unsigned long e)
+@@ -308,4 +308,70 @@ static inline void register_nosave_region_late(unsigned long b, unsigned long e)
  
  extern struct mutex pm_mutex;
  
@@ -2161,7 +2334,7 @@ index c7d9bb1..8e7de98 100644
 +extern int toi_running;
 +
 +#define test_action_state(bit) (test_bit(bit, &toi_bkd.toi_action))
-+extern int toi_try_hibernate(void);
++extern int try_tuxonice_hibernate(void);
 +
 +#else /* !CONFIG_TOI */
 +
@@ -2171,16 +2344,16 @@ index c7d9bb1..8e7de98 100644
 +#define test_toi_state(bit) (0)
 +#define toi_running (0)
 +
-+static inline int toi_try_hibernate(void) { return 0; }
++static inline int try_tuxonice_hibernate(void) { return 0; }
 +#define test_action_state(bit) (0)
 +
 +#endif /* CONFIG_TOI */
 +
 +#ifdef CONFIG_HIBERNATION
 +#ifdef CONFIG_TOI
-+extern void toi_try_resume(void);
++extern void try_tuxonice_resume(void);
 +#else
-+#define toi_try_resume() do { } while (0)
++#define try_tuxonice_resume() do { } while (0)
 +#endif
 +
 +extern int resume_attempted;
@@ -2199,7 +2372,7 @@ index c7d9bb1..8e7de98 100644
 +#endif
  #endif /* _LINUX_SUSPEND_H */
 diff --git a/include/linux/swap.h b/include/linux/swap.h
-index d302155..8ef7de2 100644
+index d476aad..b522e83 100644
 --- a/include/linux/swap.h
 +++ b/include/linux/swap.h
 @@ -168,6 +168,7 @@ struct swap_list_t {
@@ -2211,10 +2384,10 @@ index d302155..8ef7de2 100644
  
  /* Definition of global_page_state not available yet */
 diff --git a/init/do_mounts.c b/init/do_mounts.c
-index 8d4ff5a..df19830 100644
+index dd7ee5f..5ecae29 100644
 --- a/init/do_mounts.c
 +++ b/init/do_mounts.c
-@@ -142,6 +142,7 @@ fail:
+@@ -143,6 +143,7 @@ fail:
  done:
        return res;
  }
@@ -2222,7 +2395,7 @@ index 8d4ff5a..df19830 100644
  
  static int __init root_dev_setup(char *line)
  {
-@@ -411,6 +412,8 @@ void __init prepare_namespace(void)
+@@ -412,6 +413,8 @@ void __init prepare_namespace(void)
        if (is_floppy && rd_doload && rd_load_disk(0))
                ROOT_DEV = Root_RAM0;
  
@@ -2256,10 +2429,10 @@ index 614241b..f3ea292 100644
        sys_fchdir(old_fd);
        sys_mount("/", ".", NULL, MS_MOVE, NULL);
 diff --git a/init/main.c b/init/main.c
-index 83697e1..3485b50 100644
+index d721dad..1c0b018 100644
 --- a/init/main.c
 +++ b/init/main.c
-@@ -115,6 +115,7 @@ extern void softirq_init(void);
+@@ -117,6 +117,7 @@ extern void softirq_init(void);
  char __initdata boot_command_line[COMMAND_LINE_SIZE];
  /* Untouched saved command line (eg. for /proc) */
  char *saved_command_line;
@@ -2268,7 +2441,7 @@ index 83697e1..3485b50 100644
  static char *static_command_line;
  
 diff --git a/kernel/cpu.c b/kernel/cpu.c
-index 79e40f0..eb36db0 100644
+index 395b697..fe274d1 100644
 --- a/kernel/cpu.c
 +++ b/kernel/cpu.c
 @@ -415,6 +415,7 @@ int disable_nonboot_cpus(void)
@@ -2288,10 +2461,10 @@ index 79e40f0..eb36db0 100644
  static int alloc_frozen_cpus(void)
  {
 diff --git a/kernel/fork.c b/kernel/fork.c
-index 4854c2c..3bfddab 100644
+index 875ffbd..c9df3fe 100644
 --- a/kernel/fork.c
 +++ b/kernel/fork.c
-@@ -80,6 +80,7 @@ int max_threads;             /* tunable limit on nr_threads */
+@@ -82,6 +82,7 @@ int max_threads;             /* tunable limit on nr_threads */
  DEFINE_PER_CPU(unsigned long, process_counts) = 0;
  
  __cacheline_aligned DEFINE_RWLOCK(tasklist_lock);  /* outer */
@@ -2300,10 +2473,10 @@ index 4854c2c..3bfddab 100644
  DEFINE_TRACE(sched_process_fork);
  
 diff --git a/kernel/kmod.c b/kernel/kmod.c
-index a27a5f6..8ed006a 100644
+index 7e95bed..41e5186 100644
 --- a/kernel/kmod.c
 +++ b/kernel/kmod.c
-@@ -317,6 +317,7 @@ int usermodehelper_disable(void)
+@@ -319,6 +319,7 @@ int usermodehelper_disable(void)
        usermodehelper_disabled = 0;
        return -EAGAIN;
  }
@@ -2311,7 +2484,7 @@ index a27a5f6..8ed006a 100644
  
  /**
   * usermodehelper_enable - allow new helpers to be started again
-@@ -325,6 +326,7 @@ void usermodehelper_enable(void)
+@@ -327,6 +328,7 @@ void usermodehelper_enable(void)
  {
        usermodehelper_disabled = 0;
  }
@@ -2320,7 +2493,7 @@ index a27a5f6..8ed006a 100644
  static void helper_lock(void)
  {
 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
-index 23bd4da..2520b0e 100644
+index 23bd4da..7638270 100644
 --- a/kernel/power/Kconfig
 +++ b/kernel/power/Kconfig
 @@ -38,6 +38,13 @@ config CAN_PM_TRACE
@@ -2337,7 +2510,7 @@ index 23bd4da..2520b0e 100644
  config PM_TRACE
        bool
        help
-@@ -179,6 +186,256 @@ config PM_STD_PARTITION
+@@ -179,6 +186,237 @@ config PM_STD_PARTITION
          suspended image to. It will simply pick the first available swap 
          device.
  
@@ -2374,34 +2547,15 @@ index 23bd4da..2520b0e 100644
 +      comment "General Options"
 +              depends on TOI_CORE
 +
-+      config TOI_DEFAULT_PRE_HIBERNATE
-+              string "Default pre-hibernate command"
-+              depends on TOI_CORE
-+              ---help---
-+                This entry allows you to specify a command to be run prior
-+                to starting a hibernation cycle. If this command returns
-+                a non-zero result code, hibernating will be aborted. If
-+                you're starting hibernation via the hibernate script,
-+                this value should probably be blank.
-+
-+      config TOI_DEFAULT_POST_HIBERNATE
-+              string "Default post-resume command"
-+              depends on TOI_CORE
-+              ---help---
-+                This entry allows you to specify a command to be run after
-+                completing a hibernation cycle. The return code of this
-+                command is ignored. If you're starting hibernation via the
-+                hibernate script, this value should probably be blank.
-+
 +      config TOI_CRYPTO
 +              tristate "Compression support"
 +              depends on TOI_CORE && CRYPTO
 +              default y
 +              ---help---
 +                This option adds support for using cryptoapi compression
-+                algorithms. Compression is particularly useful as
-+                the LZF support that comes with the TuxOnIce patch can double
-+                your suspend and resume speed.
++                algorithms. Compression is particularly useful as it can
++                more than double your suspend and resume speed (depending
++                upon how well your image compresses).
 +
 +                You probably want this, so say Y here.
 +
@@ -2595,15 +2749,13 @@ index 23bd4da..2520b0e 100644
        tristate "Advanced Power Management Emulation"
        depends on PM && SYS_SUPPORTS_APM_EMULATION
 diff --git a/kernel/power/Makefile b/kernel/power/Makefile
-index 720ea4f..c1681d0 100644
+index 720ea4f..e797c0d 100644
 --- a/kernel/power/Makefile
 +++ b/kernel/power/Makefile
-@@ -3,6 +3,36 @@ ifeq ($(CONFIG_PM_DEBUG),y)
+@@ -3,6 +3,34 @@ ifeq ($(CONFIG_PM_DEBUG),y)
  EXTRA_CFLAGS  +=      -DDEBUG
  endif
  
-+obj-y                         := main.o
-+
 +tuxonice_core-objs := tuxonice_modules.o tuxonice_sysfs.o tuxonice_highlevel.o \
 +              tuxonice_io.o tuxonice_pagedir.o tuxonice_prepare_image.o \
 +              tuxonice_extent.o tuxonice_pageflags.o tuxonice_ui.o \
@@ -2636,13 +2788,14 @@ index 720ea4f..c1681d0 100644
  obj-$(CONFIG_PM_SLEEP)                += console.o
  obj-$(CONFIG_FREEZER)         += process.o
 diff --git a/kernel/power/disk.c b/kernel/power/disk.c
-index 4a4a206..4b8067e 100644
+index 5cb080e..4f82ed5 100644
 --- a/kernel/power/disk.c
 +++ b/kernel/power/disk.c
-@@ -24,10 +24,12 @@
- #include <linux/freezer.h>
+@@ -25,11 +25,12 @@
+ #include <scsi/scsi_scan.h>
+ #include <asm/suspend.h>
  
- #include "power.h"
+-#include "power.h"
 -
 +#include "tuxonice.h"
  
@@ -2654,7 +2807,7 @@ index 4a4a206..4b8067e 100644
  dev_t swsusp_resume_device;
  sector_t swsusp_resume_block;
  
-@@ -113,55 +115,60 @@ static int hibernation_test(int level) { return 0; }
+@@ -115,55 +116,60 @@ static int hibernation_test(int level) { return 0; }
   *    hibernation
   */
  
@@ -2720,7 +2873,7 @@ index 4a4a206..4b8067e 100644
  
  /**
   *    platform_pre_restore - prepare the platform for the restoration from a
-@@ -169,11 +176,12 @@ static void platform_finish(int platform_mode)
+@@ -171,11 +177,12 @@ static void platform_finish(int platform_mode)
   *    called, platform_restore_cleanup() must be called.
   */
  
@@ -2734,7 +2887,7 @@ index 4a4a206..4b8067e 100644
  
  /**
   *    platform_restore_cleanup - switch the platform to the normal mode of
-@@ -182,22 +190,24 @@ static int platform_pre_restore(int platform_mode)
+@@ -184,22 +191,24 @@ static int platform_pre_restore(int platform_mode)
   *    regardless of the result of platform_pre_restore().
   */
  
@@ -2761,7 +2914,7 @@ index 4a4a206..4b8067e 100644
  
  /**
   *    create_image - freeze devices that need to be frozen with interrupts
-@@ -407,6 +417,7 @@ int hibernation_restore(int platform_mode)
+@@ -423,6 +432,7 @@ int hibernation_restore(int platform_mode)
        pm_restore_console();
        return error;
  }
@@ -2769,17 +2922,17 @@ index 4a4a206..4b8067e 100644
  
  /**
   *    hibernation_platform_enter - enter the hibernation state using the
-@@ -523,6 +534,9 @@ int hibernate(void)
+@@ -542,6 +552,9 @@ int hibernate(void)
  {
        int error;
  
 +      if (test_action_state(TOI_REPLACE_SWSUSP))
-+              return toi_try_hibernate();
++              return try_tuxonice_hibernate();
 +
        mutex_lock(&pm_mutex);
        /* The snapshot device should not be opened while we're running */
        if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
-@@ -600,10 +614,19 @@ int hibernate(void)
+@@ -619,10 +632,17 @@ int hibernate(void)
   *
   */
  
@@ -2794,13 +2947,11 @@ index 4a4a206..4b8067e 100644
 +       * We can't know (until an image header - if any - is loaded), whether
 +       * we did override swsusp. We therefore ensure that both are tried.
 +       */
-+      if (test_action_state(TOI_REPLACE_SWSUSP))
-+              printk(KERN_INFO "Replacing swsusp.\n");
-+              toi_try_resume();
++      try_tuxonice_resume();
  
        /*
         * If the user said "noresume".. bail out early.
-@@ -918,6 +941,7 @@ static int __init resume_offset_setup(char *str)
+@@ -947,6 +967,7 @@ static int __init resume_offset_setup(char *str)
  static int __init noresume_setup(char *str)
  {
        noresume = 1;
@@ -2809,7 +2960,7 @@ index 4a4a206..4b8067e 100644
  }
  
 diff --git a/kernel/power/main.c b/kernel/power/main.c
-index c9632f8..91aa900 100644
+index 8680282..ea50274 100644
 --- a/kernel/power/main.c
 +++ b/kernel/power/main.c
 @@ -26,6 +26,7 @@
@@ -2838,7 +2989,7 @@ index c9632f8..91aa900 100644
  
  /**
   * suspend_valid_only_mem - generic memory-only valid callback
-@@ -449,6 +452,7 @@ static int enter_state(suspend_state_t state)
+@@ -465,6 +468,7 @@ static int enter_state(suspend_state_t state)
        mutex_unlock(&pm_mutex);
        return error;
  }
@@ -2846,7 +2997,7 @@ index c9632f8..91aa900 100644
  
  
  /**
-@@ -471,6 +475,7 @@ EXPORT_SYMBOL(pm_suspend);
+@@ -487,6 +491,7 @@ EXPORT_SYMBOL(pm_suspend);
  #endif /* CONFIG_SUSPEND */
  
  struct kobject *power_kobj;
@@ -2855,21 +3006,10 @@ index c9632f8..91aa900 100644
  /**
   *    state - control system power state.
 diff --git a/kernel/power/power.h b/kernel/power/power.h
-index 46b5ec7..f946b3b 100644
+index 46b5ec7..4cc59d5 100644
 --- a/kernel/power/power.h
 +++ b/kernel/power/power.h
-@@ -1,3 +1,10 @@
-+/*
-+ * Copyright (C) 2004-2008 Nigel Cunningham (nigel at tuxonice net)
-+ */
-+
-+#ifndef KERNEL_POWER_POWER_H
-+#define KERNEL_POWER_POWER_H
-+
- #include <linux/suspend.h>
- #include <linux/suspend_ioctls.h>
- #include <linux/utsname.h>
-@@ -31,8 +38,12 @@ static inline char *check_image_kernel(struct swsusp_info *info)
+@@ -31,8 +31,12 @@ static inline char *check_image_kernel(struct swsusp_info *info)
        return arch_hibernation_header_restore(info) ?
                        "architecture specific data" : NULL;
  }
@@ -2882,7 +3022,7 @@ index 46b5ec7..f946b3b 100644
  /*
   * Keep some memory free so that I/O operations can succeed without paging
   * [Might this be more than 4 MB?]
-@@ -49,6 +60,7 @@ static inline char *check_image_kernel(struct swsusp_info *info)
+@@ -49,6 +53,7 @@ static inline char *check_image_kernel(struct swsusp_info *info)
  extern int hibernation_snapshot(int platform_mode);
  extern int hibernation_restore(int platform_mode);
  extern int hibernation_platform_enter(void);
@@ -2890,7 +3030,7 @@ index 46b5ec7..f946b3b 100644
  #endif
  
  extern int pfn_is_nosave(unsigned long);
-@@ -63,6 +75,8 @@ static struct kobj_attribute _name##_attr = {        \
+@@ -63,6 +68,8 @@ static struct kobj_attribute _name##_attr = {        \
        .store  = _name##_store,                \
  }
  
@@ -2899,7 +3039,7 @@ index 46b5ec7..f946b3b 100644
  /* Preferred image size in bytes (default 500 MB) */
  extern unsigned long image_size;
  extern int in_suspend;
-@@ -223,3 +237,89 @@ static inline void suspend_thaw_processes(void)
+@@ -223,3 +230,86 @@ static inline void suspend_thaw_processes(void)
  {
  }
  #endif
@@ -2965,7 +3105,6 @@ index 46b5ec7..f946b3b 100644
 +                                       */
 +};
 +
-+
 +extern int memory_bm_create(struct memory_bitmap *bm, gfp_t gfp_mask,
 +              int safe_needed);
 +extern void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free);
@@ -2987,10 +3126,8 @@ index 46b5ec7..f946b3b 100644
 +extern int memory_bm_write(struct memory_bitmap *bm, int (*rw_chunk)
 +      (int rw, struct toi_module_ops *owner, char *buffer, int buffer_size));
 +#endif
-+
-+#endif
 diff --git a/kernel/power/process.c b/kernel/power/process.c
-index ca63401..ac19ff7 100644
+index ca63401..10ba50f 100644
 --- a/kernel/power/process.c
 +++ b/kernel/power/process.c
 @@ -13,6 +13,10 @@
@@ -3026,8 +3163,7 @@ index ca63401..ac19ff7 100644
        error = try_to_freeze_tasks(true);
        if (error)
                goto Exit;
--      printk("done.\n");
-+      printk(KERN_INFO "done.\n");
+       printk("done.\n");
  
 -      printk("Freezing remaining freezable tasks ... ");
 +      sys_sync();
@@ -3049,7 +3185,7 @@ index ca63401..ac19ff7 100644
  
  static void thaw_tasks(bool nosig_only)
  {
-@@ -145,10 +159,40 @@ static void thaw_tasks(bool nosig_only)
+@@ -145,10 +159,35 @@ static void thaw_tasks(bool nosig_only)
  
  void thaw_processes(void)
  {
@@ -3060,17 +3196,12 @@ index ca63401..ac19ff7 100644
 +      if (old_state == FREEZER_OFF)
 +              return;
 +
-+      /*
-+       * Change state beforehand because thawed tasks might submit I/O
-+       * immediately.
-+       */
 +      freezer_state = FREEZER_OFF;
 +
 +      printk(KERN_INFO "Restarting all filesystems ...\n");
 +      thaw_filesystems(FS_FREEZER_ALL);
 +
 +      printk(KERN_INFO "Restarting tasks ... ");
-+
 +      if (old_state == FREEZER_FULLY_ON)
 +              thaw_tasks(true);
        thaw_tasks(false);
@@ -3093,7 +3224,7 @@ index ca63401..ac19ff7 100644
 + */
 +EXPORT_SYMBOL_GPL(thaw_kernel_threads);
 diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
-index f5fc2d7..63959e7 100644
+index 33e2e4a..a78b7ef 100644
 --- a/kernel/power/snapshot.c
 +++ b/kernel/power/snapshot.c
 @@ -34,6 +34,8 @@
@@ -3126,7 +3257,7 @@ index f5fc2d7..63959e7 100644
        return (unsigned long)get_image_page(gfp_mask, PG_SAFE);
  }
  
-@@ -223,47 +232,24 @@ static void *chain_alloc(struct chain_allocator *ca, unsigned int size)
+@@ -223,47 +232,22 @@ static void *chain_alloc(struct chain_allocator *ca, unsigned int size)
   *    the represented memory area.
   */
  
@@ -3169,18 +3300,17 @@ index f5fc2d7..63959e7 100644
  {
        bm->cur.block = list_entry(bm->blocks.next, struct bm_block, hook);
        bm->cur.bit = 0;
-+
+-}
+-static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free);
 +      bm->iter.block = list_entry(bm->blocks.next, struct bm_block, hook);
 +      bm->iter.bit = 0;
- }
++}
 +EXPORT_SYMBOL_GPL(memory_bm_position_reset);
  
--static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free);
-+void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free);
  /**
   *    create_bm_block_list - create a list of block bitmap objects
-@@ -374,7 +360,7 @@ static int create_mem_extents(struct list_head *list, gfp_t gfp_mask)
+@@ -371,7 +355,7 @@ static int create_mem_extents(struct list_head *list, gfp_t gfp_mask)
  /**
    *   memory_bm_create - allocate memory for a memory bitmap
    */
@@ -3189,7 +3319,7 @@ index f5fc2d7..63959e7 100644
  memory_bm_create(struct memory_bitmap *bm, gfp_t gfp_mask, int safe_needed)
  {
        struct chain_allocator ca;
-@@ -430,11 +416,12 @@ memory_bm_create(struct memory_bitmap *bm, gfp_t gfp_mask, int safe_needed)
+@@ -427,11 +411,12 @@ memory_bm_create(struct memory_bitmap *bm, gfp_t gfp_mask, int safe_needed)
        memory_bm_free(bm, PG_UNSAFE_CLEAR);
        goto Exit;
  }
@@ -3203,7 +3333,7 @@ index f5fc2d7..63959e7 100644
  {
        struct bm_block *bb;
  
-@@ -446,6 +433,7 @@ static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free)
+@@ -443,6 +428,7 @@ static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free)
  
        INIT_LIST_HEAD(&bm->blocks);
  }
@@ -3211,7 +3341,7 @@ index f5fc2d7..63959e7 100644
  
  /**
   *    memory_bm_find_bit - find the bit in the bitmap @bm that corresponds
-@@ -484,7 +472,7 @@ static int memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn,
+@@ -481,7 +467,7 @@ static int memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn,
        return 0;
  }
  
@@ -3220,18 +3350,15 @@ index f5fc2d7..63959e7 100644
  {
        void *addr;
        unsigned int bit;
-@@ -494,8 +482,9 @@ static void memory_bm_set_bit(struct memory_bitmap *bm, unsigned long pfn)
+@@ -491,6 +477,7 @@ static void memory_bm_set_bit(struct memory_bitmap *bm, unsigned long pfn)
        BUG_ON(error);
        set_bit(bit, addr);
  }
 +EXPORT_SYMBOL_GPL(memory_bm_set_bit);
  
--static int mem_bm_set_bit_check(struct memory_bitmap *bm, unsigned long pfn)
-+int mem_bm_set_bit_check(struct memory_bitmap *bm, unsigned long pfn)
+ static int mem_bm_set_bit_check(struct memory_bitmap *bm, unsigned long pfn)
  {
-       void *addr;
-       unsigned int bit;
-@@ -507,7 +496,7 @@ static int mem_bm_set_bit_check(struct memory_bitmap *bm, unsigned long pfn)
+@@ -504,7 +491,7 @@ static int mem_bm_set_bit_check(struct memory_bitmap *bm, unsigned long pfn)
        return error;
  }
  
@@ -3240,7 +3367,7 @@ index f5fc2d7..63959e7 100644
  {
        void *addr;
        unsigned int bit;
-@@ -517,8 +506,9 @@ static void memory_bm_clear_bit(struct memory_bitmap *bm, unsigned long pfn)
+@@ -514,8 +501,9 @@ static void memory_bm_clear_bit(struct memory_bitmap *bm, unsigned long pfn)
        BUG_ON(error);
        clear_bit(bit, addr);
  }
@@ -3251,7 +3378,7 @@ index f5fc2d7..63959e7 100644
  {
        void *addr;
        unsigned int bit;
-@@ -528,6 +518,7 @@ static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
+@@ -525,6 +513,7 @@ static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
        BUG_ON(error);
        return test_bit(bit, addr);
  }
@@ -3259,7 +3386,7 @@ index f5fc2d7..63959e7 100644
  
  static bool memory_bm_pfn_present(struct memory_bitmap *bm, unsigned long pfn)
  {
-@@ -546,43 +537,178 @@ static bool memory_bm_pfn_present(struct memory_bitmap *bm, unsigned long pfn)
+@@ -543,43 +532,178 @@ static bool memory_bm_pfn_present(struct memory_bitmap *bm, unsigned long pfn)
   *    this function.
   */
  
@@ -3349,8 +3476,7 @@ index f5fc2d7..63959e7 100644
 +DEFINE_MEMORY_BITMAP(io_map);
 +DEFINE_MEMORY_BITMAP(nosave_map);
 +DEFINE_MEMORY_BITMAP(free_map);
--static LIST_HEAD(nosave_regions);
++
 +int memory_bm_write(struct memory_bitmap *bm, int (*rw_chunk)
 +      (int rw, struct toi_module_ops *owner, char *buffer, int buffer_size))
 +{
@@ -3360,7 +3486,8 @@ index f5fc2d7..63959e7 100644
 +
 +      if (!bm)
 +              return result;
-+
+-static LIST_HEAD(nosave_regions);
 +      list_for_each_entry(bb, &bm->blocks, hook)
 +              nr++;
 +
@@ -3454,7 +3581,7 @@ index f5fc2d7..63959e7 100644
  
  /**
   *    register_nosave_region - register a range of page frames the contents
-@@ -818,7 +944,7 @@ static unsigned int count_free_highmem_pages(void)
+@@ -815,7 +939,7 @@ static unsigned int count_free_highmem_pages(void)
   *    We should save the page if it isn't Nosave or NosaveFree, or Reserved,
   *    and it isn't a part of a free chunk of pages.
   */
@@ -3463,7 +3590,7 @@ index f5fc2d7..63959e7 100644
  {
        struct page *page;
  
-@@ -837,6 +963,7 @@ static struct page *saveable_highmem_page(struct zone *zone, unsigned long pfn)
+@@ -834,6 +958,7 @@ static struct page *saveable_highmem_page(struct zone *zone, unsigned long pfn)
  
        return page;
  }
@@ -3471,7 +3598,7 @@ index f5fc2d7..63959e7 100644
  
  /**
   *    count_highmem_pages - compute the total number of saveable highmem
-@@ -862,11 +989,6 @@ unsigned int count_highmem_pages(void)
+@@ -859,11 +984,6 @@ unsigned int count_highmem_pages(void)
        }
        return n;
  }
@@ -3483,7 +3610,7 @@ index f5fc2d7..63959e7 100644
  #endif /* CONFIG_HIGHMEM */
  
  /**
-@@ -877,7 +999,7 @@ static inline void *saveable_highmem_page(struct zone *z, unsigned long p)
+@@ -874,7 +994,7 @@ static inline void *saveable_highmem_page(struct zone *z, unsigned long p)
   *    of pages statically defined as 'unsaveable', and it isn't a part of
   *    a free chunk of pages.
   */
@@ -3492,7 +3619,7 @@ index f5fc2d7..63959e7 100644
  {
        struct page *page;
  
-@@ -899,6 +1021,7 @@ static struct page *saveable_page(struct zone *zone, unsigned long pfn)
+@@ -896,6 +1016,7 @@ static struct page *saveable_page(struct zone *zone, unsigned long pfn)
  
        return page;
  }
@@ -3500,7 +3627,7 @@ index f5fc2d7..63959e7 100644
  
  /**
   *    count_data_pages - compute the total number of saveable non-highmem
-@@ -1213,6 +1336,9 @@ asmlinkage int swsusp_save(void)
+@@ -1210,6 +1331,9 @@ asmlinkage int swsusp_save(void)
  {
        unsigned int nr_pages, nr_highmem;
  
@@ -3510,7 +3637,7 @@ index f5fc2d7..63959e7 100644
        printk(KERN_INFO "PM: Creating hibernation image: \n");
  
        drain_local_pages(NULL);
-@@ -1253,14 +1379,14 @@ asmlinkage int swsusp_save(void)
+@@ -1250,14 +1374,14 @@ asmlinkage int swsusp_save(void)
  }
  
  #ifndef CONFIG_ARCH_HIBERNATION_HEADER
@@ -3527,7 +3654,7 @@ index f5fc2d7..63959e7 100644
  {
        if (info->version_code != LINUX_VERSION_CODE)
                return "kernel version";
-@@ -1274,6 +1400,7 @@ static char *check_image_kernel(struct swsusp_info *info)
+@@ -1271,6 +1395,7 @@ static char *check_image_kernel(struct swsusp_info *info)
                return "machine";
        return NULL;
  }
@@ -3535,7 +3662,7 @@ index f5fc2d7..63959e7 100644
  #endif /* CONFIG_ARCH_HIBERNATION_HEADER */
  
  unsigned long snapshot_get_image_size(void)
-@@ -1281,7 +1408,7 @@ unsigned long snapshot_get_image_size(void)
+@@ -1278,7 +1403,7 @@ unsigned long snapshot_get_image_size(void)
        return nr_copy_pages + nr_meta_pages + 1;
  }
  
@@ -3544,7 +3671,7 @@ index f5fc2d7..63959e7 100644
  {
        memset(info, 0, sizeof(struct swsusp_info));
        info->num_physpages = num_physpages;
-@@ -1291,6 +1418,7 @@ static int init_header(struct swsusp_info *info)
+@@ -1288,6 +1413,7 @@ static int init_header(struct swsusp_info *info)
        info->size <<= PAGE_SHIFT;
        return init_header_complete(info);
  }
@@ -3554,10 +3681,10 @@ index f5fc2d7..63959e7 100644
   *    pack_pfns - pfns corresponding to the set bits found in the bitmap @bm
 diff --git a/kernel/power/tuxonice.h b/kernel/power/tuxonice.h
 new file mode 100644
-index 0000000..267368d
+index 0000000..1d6349d
 --- /dev/null
 +++ b/kernel/power/tuxonice.h
-@@ -0,0 +1,212 @@
+@@ -0,0 +1,213 @@
 +/*
 + * kernel/power/tuxonice.h
 + *
@@ -3579,6 +3706,7 @@ index 0000000..267368d
 +#include <linux/kmod.h>
 +#include <asm/setup.h>
 +#include "tuxonice_pageflags.h"
++#include "power.h"
 +
 +#define TOI_CORE_VERSION "3.0.1"
 +
@@ -3740,8 +3868,8 @@ index 0000000..267368d
 +extern int save_image_part1(void);
 +extern int toi_atomic_restore(void);
 +
-+extern int _toi_try_hibernate(void);
-+extern void __toi_try_resume(void);
++extern int toi_try_hibernate(void);
++extern void toi_try_resume(void);
 +
 +extern int __toi_post_context_save(void);
 +
@@ -3772,10 +3900,10 @@ index 0000000..267368d
 +#endif
 diff --git a/kernel/power/tuxonice_alloc.c b/kernel/power/tuxonice_alloc.c
 new file mode 100644
-index 0000000..5e3aae8
+index 0000000..0089ab8
 --- /dev/null
 +++ b/kernel/power/tuxonice_alloc.c
-@@ -0,0 +1,287 @@
+@@ -0,0 +1,288 @@
 +/*
 + * kernel/power/tuxonice_alloc.c
 + *
@@ -3860,7 +3988,7 @@ index 0000000..5e3aae8
 +              } \
 +      } while (0)
 +
-+static void alloc_update_stats(int fail_num, void *result)
++static void alloc_update_stats(int fail_num, void *result, int size)
 +{
 +      if (!result) {
 +              atomic_inc(&toi_fail_count[fail_num]);
@@ -3871,7 +3999,7 @@ index 0000000..5e3aae8
 +      if (unlikely(test_action_state(TOI_GET_MAX_MEM_ALLOCD))) {
 +              mutex_lock(&toi_alloc_mutex);
 +              toi_cur_allocd[fail_num]++;
-+              cur_allocd++;
++              cur_allocd+= size;
 +              if (unlikely(cur_allocd > max_allocd)) {
 +                      int i;
 +
@@ -3883,13 +4011,13 @@ index 0000000..5e3aae8
 +      }
 +}
 +
-+static void free_update_stats(int fail_num)
++static void free_update_stats(int fail_num, int size)
 +{
 +      BUG_ON(fail_num >= TOI_ALLOC_PATHS);
 +      atomic_inc(&toi_free_count[fail_num]);
 +      if (unlikely(test_action_state(TOI_GET_MAX_MEM_ALLOCD))) {
 +              mutex_lock(&toi_alloc_mutex);
-+              cur_allocd--;
++              cur_allocd-= size;
 +              toi_cur_allocd[fail_num]--;
 +              mutex_unlock(&toi_alloc_mutex);
 +      }
@@ -3903,7 +4031,7 @@ index 0000000..5e3aae8
 +              MIGHT_FAIL(fail_num, NULL);
 +      result = kzalloc(size, flags);
 +      if (toi_alloc_ops.enabled)
-+              alloc_update_stats(fail_num, result);
++              alloc_update_stats(fail_num, result, size);
 +      return result;
 +}
 +EXPORT_SYMBOL_GPL(toi_kzalloc);
@@ -3917,7 +4045,8 @@ index 0000000..5e3aae8
 +              MIGHT_FAIL(fail_num, 0);
 +      result = __get_free_pages(mask, order);
 +      if (toi_alloc_ops.enabled)
-+              alloc_update_stats(fail_num, (void *) result);
++              alloc_update_stats(fail_num, (void *) result,
++                              PAGE_SIZE << order);
 +      return result;
 +}
 +EXPORT_SYMBOL_GPL(toi_get_free_pages);
@@ -3930,7 +4059,7 @@ index 0000000..5e3aae8
 +              MIGHT_FAIL(fail_num, NULL);
 +      result = alloc_page(mask);
 +      if (toi_alloc_ops.enabled)
-+              alloc_update_stats(fail_num, (void *) result);
++              alloc_update_stats(fail_num, (void *) result, PAGE_SIZE);
 +      return result;
 +}
 +EXPORT_SYMBOL_GPL(toi_alloc_page);
@@ -3943,15 +4072,15 @@ index 0000000..5e3aae8
 +              MIGHT_FAIL(fail_num, 0);
 +      result = get_zeroed_page(mask);
 +      if (toi_alloc_ops.enabled)
-+              alloc_update_stats(fail_num, (void *) result);
++              alloc_update_stats(fail_num, (void *) result, PAGE_SIZE);
 +      return result;
 +}
 +EXPORT_SYMBOL_GPL(toi_get_zeroed_page);
 +
-+void toi_kfree(int fail_num, const void *arg)
++void toi_kfree(int fail_num, const void *arg, int size)
 +{
 +      if (arg && toi_alloc_ops.enabled)
-+              free_update_stats(fail_num);
++              free_update_stats(fail_num, size);
 +
 +      kfree(arg);
 +}
@@ -3960,7 +4089,7 @@ index 0000000..5e3aae8
 +void toi_free_page(int fail_num, unsigned long virt)
 +{
 +      if (virt && toi_alloc_ops.enabled)
-+              free_update_stats(fail_num);
++              free_update_stats(fail_num, PAGE_SIZE);
 +
 +      free_page(virt);
 +}
@@ -3969,7 +4098,7 @@ index 0000000..5e3aae8
 +void toi__free_page(int fail_num, struct page *page)
 +{
 +      if (page && toi_alloc_ops.enabled)
-+              free_update_stats(fail_num);
++              free_update_stats(fail_num, PAGE_SIZE);
 +
 +      __free_page(page);
 +}
@@ -3978,7 +4107,7 @@ index 0000000..5e3aae8
 +void toi_free_pages(int fail_num, struct page *page, int order)
 +{
 +      if (page && toi_alloc_ops.enabled)
-+              free_update_stats(fail_num);
++              free_update_stats(fail_num, PAGE_SIZE << order);
 +
 +      __free_pages(page, order);
 +}
@@ -4065,7 +4194,7 @@ index 0000000..5e3aae8
 +#endif
 diff --git a/kernel/power/tuxonice_alloc.h b/kernel/power/tuxonice_alloc.h
 new file mode 100644
-index 0000000..a1dd8ff
+index 0000000..6069dfa
 --- /dev/null
 +++ b/kernel/power/tuxonice_alloc.h
 @@ -0,0 +1,51 @@
@@ -4083,7 +4212,7 @@ index 0000000..a1dd8ff
 +
 +#ifdef CONFIG_PM_DEBUG
 +extern void *toi_kzalloc(int fail_num, size_t size, gfp_t flags);
-+extern void toi_kfree(int fail_num, const void *arg);
++extern void toi_kfree(int fail_num, const void *arg, int size);
 +
 +extern unsigned long toi_get_free_pages(int fail_num, gfp_t mask,
 +              unsigned int order);
@@ -4101,7 +4230,7 @@ index 0000000..a1dd8ff
 +#else /* CONFIG_PM_DEBUG */
 +
 +#define toi_kzalloc(FAIL, SIZE, FLAGS) (kzalloc(SIZE, FLAGS))
-+#define toi_kfree(FAIL, ALLOCN) (kfree(ALLOCN))
++#define toi_kfree(FAIL, ALLOCN, SIZE) (kfree(ALLOCN))
 +
 +#define toi_get_free_pages(FAIL, FLAGS, ORDER) __get_free_pages(FLAGS, ORDER)
 +#define toi_get_free_page(FAIL, FLAGS) __get_free_page(FLAGS)
@@ -4122,10 +4251,10 @@ index 0000000..a1dd8ff
 +#endif
 diff --git a/kernel/power/tuxonice_atomic_copy.c b/kernel/power/tuxonice_atomic_copy.c
 new file mode 100644
-index 0000000..aff8177
+index 0000000..d6ef2b0
 --- /dev/null
 +++ b/kernel/power/tuxonice_atomic_copy.c
-@@ -0,0 +1,420 @@
+@@ -0,0 +1,415 @@
 +/*
 + * kernel/power/tuxonice_atomic_copy.c
 + *
@@ -4142,11 +4271,11 @@ index 0000000..aff8177
 +#include <linux/cpu.h>
 +#include <linux/freezer.h>
 +#include <linux/console.h>
++#include <asm/suspend.h>
 +#include "tuxonice.h"
 +#include "tuxonice_storage.h"
 +#include "tuxonice_power_off.h"
 +#include "tuxonice_ui.h"
-+#include "power.h"
 +#include "tuxonice_io.h"
 +#include "tuxonice_prepare_image.h"
 +#include "tuxonice_pageflags.h"
@@ -4444,7 +4573,6 @@ index 0000000..aff8177
 +{
 +      if (suspend_time && platform_begin(1)) {
 +              set_abort_result(TOI_PLATFORM_PREP_FAILED);
-+              toi_end_atomic(ATOMIC_STEP_PLATFORM_END, suspend_time, 0);
 +              return 1;
 +      }
 +
@@ -4456,15 +4584,34 @@ index 0000000..aff8177
 +              return 1;
 +      }
 +
++      if (suspend_time && arch_prepare_suspend()) {
++              set_abort_result(TOI_ARCH_PREPARE_FAILED);
++              toi_end_atomic(ATOMIC_STEP_DEVICE_RESUME, suspend_time, 1);
++              return 1;
++      }
++
++      /* At this point, device_suspend() has been called, but *not*
++       * device_power_down(). We *must* device_power_down() now.
++       * Otherwise, drivers for some devices (e.g. interrupt controllers)
++       * become desynchronized with the actual state of the hardware
++       * at resume time, and evil weirdness ensues.
++       */
++
++      if (device_power_down(state)) {
++              set_abort_result(TOI_DEVICE_REFUSED);
++              toi_end_atomic(ATOMIC_STEP_DEVICE_RESUME, suspend_time, 1);
++              return 1;
++      }
++
 +      if (suspend_time && platform_pre_snapshot(1)) {
 +              set_abort_result(TOI_PRE_SNAPSHOT_FAILED);
-+              toi_end_atomic(ATOMIC_STEP_PLATFORM_FINISH, suspend_time, 0);
++              toi_end_atomic(ATOMIC_STEP_PLATFORM_FINISH, suspend_time, 1);
 +              return 1;
 +      }
 +
 +      if (!suspend_time && platform_pre_restore(1)) {
 +              set_abort_result(TOI_PRE_RESTORE_FAILED);
-+              toi_end_atomic(ATOMIC_STEP_DEVICE_RESUME, suspend_time, 0);
++              toi_end_atomic(ATOMIC_STEP_PLATFORM_FINISH, suspend_time, 1);
 +              return 1;
 +      }
 +
@@ -4472,36 +4619,16 @@ index 0000000..aff8177
 +              if (disable_nonboot_cpus()) {
 +                      set_abort_result(TOI_CPU_HOTPLUG_FAILED);
 +                      toi_end_atomic(ATOMIC_STEP_CPU_HOTPLUG,
-+                                      suspend_time, 0);
++                                      suspend_time, 1);
 +                      return 1;
 +              }
 +      }
 +
-+      if (suspend_time && arch_prepare_suspend()) {
-+              set_abort_result(TOI_ARCH_PREPARE_FAILED);
-+              toi_end_atomic(ATOMIC_STEP_CPU_HOTPLUG, suspend_time, 0);
-+              return 1;
-+      }
-+
-+      device_pm_lock();
 +      local_irq_disable();
 +
-+      /* At this point, device_suspend() has been called, but *not*
-+       * device_power_down(). We *must* device_power_down() now.
-+       * Otherwise, drivers for some devices (e.g. interrupt controllers)
-+       * become desynchronized with the actual state of the hardware
-+       * at resume time, and evil weirdness ensues.
-+       */
-+
-+      if (device_power_down(state)) {
-+              set_abort_result(TOI_DEVICE_REFUSED);
-+              toi_end_atomic(ATOMIC_STEP_IRQS, suspend_time, 0);
-+              return 1;
-+      }
-+
 +      if (sysdev_suspend(state)) {
 +              set_abort_result(TOI_SYSDEV_REFUSED);
-+              toi_end_atomic(ATOMIC_STEP_POWER_UP, suspend_time, 0);
++              toi_end_atomic(ATOMIC_STEP_IRQS, suspend_time, 1);
 +              return 1;
 +      }
 +
@@ -4521,26 +4648,23 @@ index 0000000..aff8177
 +              if (!suspend_time)
 +                      platform_leave(1);
 +              sysdev_resume();
-+      case ATOMIC_STEP_POWER_UP:
-+              device_power_up(suspend_time ?
-+                      (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
 +      case ATOMIC_STEP_IRQS:
 +              local_irq_enable();
-+              device_pm_unlock();
 +      case ATOMIC_STEP_CPU_HOTPLUG:
 +              if (test_action_state(TOI_LATE_CPU_HOTPLUG))
 +                      enable_nonboot_cpus();
++              platform_restore_cleanup(1);
 +      case ATOMIC_STEP_PLATFORM_FINISH:
 +              platform_finish(1);
++              device_power_up(suspend_time ?
++                      (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
 +      case ATOMIC_STEP_DEVICE_RESUME:
 +              if (suspend_time && (error & 2))
 +                      platform_recover(1);
 +              device_resume(suspend_time ?
 +                      ((error & 1) ? PMSG_RECOVER : PMSG_THAW) :
 +                      PMSG_RESTORE);
-+      case ATOMIC_STEP_RESUME_CONSOLE:
 +              resume_console();
-+      case ATOMIC_STEP_PLATFORM_END:
 +              platform_end(1);
 +
 +              toi_prepare_status(DONT_CLEAR_BAR, "Post atomic.");
@@ -4548,10 +4672,10 @@ index 0000000..aff8177
 +}
 diff --git a/kernel/power/tuxonice_atomic_copy.h b/kernel/power/tuxonice_atomic_copy.h
 new file mode 100644
-index 0000000..e907f50
+index 0000000..a428f4c
 --- /dev/null
 +++ b/kernel/power/tuxonice_atomic_copy.h
-@@ -0,0 +1,23 @@
+@@ -0,0 +1,20 @@
 +/*
 + * kernel/power/tuxonice_atomic_copy.h
 + *
@@ -4564,23 +4688,20 @@ index 0000000..e907f50
 +
 +enum {
 +      ATOMIC_ALL_STEPS,
-+      ATOMIC_STEP_POWER_UP,
 +      ATOMIC_STEP_IRQS,
 +      ATOMIC_STEP_CPU_HOTPLUG,
 +      ATOMIC_STEP_PLATFORM_FINISH,
 +      ATOMIC_STEP_DEVICE_RESUME,
-+      ATOMIC_STEP_RESUME_CONSOLE,
-+      ATOMIC_STEP_PLATFORM_END,
 +};
 +
 +int toi_go_atomic(pm_message_t state, int toi_time);
 +void toi_end_atomic(int stage, int toi_time, int error);
 diff --git a/kernel/power/tuxonice_block_io.c b/kernel/power/tuxonice_block_io.c
 new file mode 100644
-index 0000000..7100da0
+index 0000000..12fa249
 --- /dev/null
 +++ b/kernel/power/tuxonice_block_io.c
-@@ -0,0 +1,1336 @@
+@@ -0,0 +1,1338 @@
 +/*
 + * kernel/power/tuxonice_block_io.c
 + *
@@ -5101,7 +5222,8 @@ index 0000000..7100da0
 +      printk(KERN_DEBUG "Total unowned : %d.\n", unowned);
 +      printk(KERN_DEBUG "Total used : %d (%ld pages).\n", total_header_bytes,
 +                      DIV_ROUND_UP(total_header_bytes, PAGE_SIZE));
-+      printk(KERN_DEBUG "Space needed now : %ld.\n", get_header_storage_needed());
++      printk(KERN_DEBUG "Space needed now : %ld.\n",
++                      get_header_storage_needed());
 +      dump_block_chains();
 +      abort_hibernate(TOI_HEADER_TOO_BIG, "Header reservation too small.");
 +      return -EIO;
@@ -5117,9 +5239,9 @@ index 0000000..7100da0
 + **/
 +static int go_next_page(int writing, int section_barrier)
 +{
-+      int i, max = (toi_writer_posn.current_chain == -1) ? 1 :
-+        toi_devinfo[toi_writer_posn.current_chain].blocks_per_page,
-+              compare_to = 0;
++      int i, chain_num = toi_writer_posn.current_chain,
++        max = (chain_num == -1) ? 1 : toi_devinfo[chain_num].blocks_per_page,
++        compare_to = 0, compare_chain, compare_offset;
 +
 +      /* Have we already used the last page of the stream? */
 +      switch (current_stream) {
@@ -5134,13 +5256,14 @@ index 0000000..7100da0
 +              break;
 +      }
 +
-+      if (section_barrier && toi_writer_posn.current_chain ==
-+                      toi_writer_posn_save[compare_to].chain_num &&
-+          toi_writer_posn.current_offset ==
-+                      toi_writer_posn_save[compare_to].offset) {
++      compare_chain = toi_writer_posn_save[compare_to].chain_num;
++      compare_offset = toi_writer_posn_save[compare_to].offset;
++
++      if (section_barrier && chain_num == compare_chain &&
++          toi_writer_posn.current_offset == compare_offset) {
 +              if (writing) {
-+                     if (!current_stream)
-+                             return debug_broken_header();
++                      if (!current_stream)
++                              return debug_broken_header();
 +              } else {
 +                      more_readahead = 0;
 +                      return -ENODATA;
@@ -5984,16 +6107,15 @@ index 0000000..b18298c
 +extern struct toi_extent_iterate_state toi_writer_posn;
 diff --git a/kernel/power/tuxonice_builtin.c b/kernel/power/tuxonice_builtin.c
 new file mode 100644
-index 0000000..635e602
+index 0000000..97472d5
 --- /dev/null
 +++ b/kernel/power/tuxonice_builtin.c
-@@ -0,0 +1,314 @@
+@@ -0,0 +1,313 @@
 +/*
 + * Copyright (C) 2004-2008 Nigel Cunningham (nigel at tuxonice net)
 + *
 + * This file is released under the GPLv2.
 + */
-+#include <linux/module.h>
 +#include <linux/resume-trace.h>
 +#include <linux/kernel.h>
 +#include <linux/swap.h>
@@ -6197,7 +6319,7 @@ index 0000000..635e602
 +      return toi_core_fns->post_context_save();
 +}
 +
-+int toi_try_hibernate(void)
++int try_tuxonice_hibernate(void)
 +{
 +      if (!toi_core_fns)
 +              return -ENODEV;
@@ -6212,7 +6334,7 @@ index 0000000..635e602
 +static int ignore_late_initcall;
 +#endif
 +
-+void toi_try_resume(void)
++void try_tuxonice_resume(void)
 +{
 +      /* Don't let it wrap around eventually */
 +      if (num_resume_calls < 2)
@@ -6756,7 +6878,7 @@ index 0000000..84a9174
 +
 diff --git a/kernel/power/tuxonice_cluster.c b/kernel/power/tuxonice_cluster.c
 new file mode 100644
-index 0000000..0fad533
+index 0000000..671006d
 --- /dev/null
 +++ b/kernel/power/tuxonice_cluster.c
 @@ -0,0 +1,1069 @@
@@ -7122,7 +7244,7 @@ index 0000000..0fad533
 +
 +      if (this) {
 +              list_del_init(&this->list);
-+              toi_kfree(36, this);
++              toi_kfree(36, this, sizeof(*this));
 +              node_array[index].peer_count--;
 +      }
 +
@@ -7856,10 +7978,10 @@ index 0000000..b0f8918
 +
 diff --git a/kernel/power/tuxonice_compress.c b/kernel/power/tuxonice_compress.c
 new file mode 100644
-index 0000000..febb783
+index 0000000..8acdf65
 --- /dev/null
 +++ b/kernel/power/tuxonice_compress.c
-@@ -0,0 +1,448 @@
+@@ -0,0 +1,447 @@
 +/*
 + * kernel/power/compression.c
 + *
@@ -7871,7 +7993,6 @@ index 0000000..febb783
 + * using cryptoapi.
 + */
 +
-+#include <linux/module.h>
 +#include <linux/suspend.h>
 +#include <linux/highmem.h>
 +#include <linux/vmalloc.h>
@@ -8310,10 +8431,10 @@ index 0000000..febb783
 +#endif
 diff --git a/kernel/power/tuxonice_extent.c b/kernel/power/tuxonice_extent.c
 new file mode 100644
-index 0000000..76877c6
+index 0000000..28c421b
 --- /dev/null
 +++ b/kernel/power/tuxonice_extent.c
-@@ -0,0 +1,314 @@
+@@ -0,0 +1,313 @@
 +/*
 + * kernel/power/tuxonice_extent.c
 + *
@@ -8324,7 +8445,6 @@ index 0000000..76877c6
 + * These functions encapsulate the manipulation of storage metadata.
 + */
 +
-+#include <linux/module.h>
 +#include <linux/suspend.h>
 +#include "tuxonice_modules.h"
 +#include "tuxonice_extent.h"
@@ -8355,7 +8475,7 @@ index 0000000..76877c6
 +
 +      while (this) {
 +              struct hibernate_extent *next = this->next;
-+              toi_kfree(2, this);
++              toi_kfree(2, this, sizeof(*this));
 +              chain->num_extents--;
 +              this = next;
 +      }
@@ -8397,7 +8517,7 @@ index 0000000..76877c6
 +                      if (next_ext && cur_ext->end + 1 == next_ext->start) {
 +                              cur_ext->end = next_ext->end;
 +                              cur_ext->next = next_ext->next;
-+                              toi_kfree(2, next_ext);
++                              toi_kfree(2, next_ext, sizeof(*next_ext));
 +                              chain->num_extents--;
 +                      }
 +
@@ -8708,10 +8828,10 @@ index 0000000..22ffb9b
 +#endif
 diff --git a/kernel/power/tuxonice_file.c b/kernel/power/tuxonice_file.c
 new file mode 100644
-index 0000000..4181c47
+index 0000000..0458a0c
 --- /dev/null
 +++ b/kernel/power/tuxonice_file.c
-@@ -0,0 +1,1241 @@
+@@ -0,0 +1,1248 @@
 +/*
 + * kernel/power/tuxonice_file.c
 + *
@@ -8744,7 +8864,6 @@ index 0000000..4181c47
 + */
 +
 +#include <linux/suspend.h>
-+#include <linux/module.h>
 +#include <linux/blkdev.h>
 +#include <linux/file.h>
 +#include <linux/stat.h>
@@ -9783,13 +9902,21 @@ index 0000000..4181c47
 +      if (!setting_toi_file_target) /* Concurrent write via /sys? */
 +              __test_toi_file_target(toi_file_target, 1, 0);
 +
-+      if (colon)
-+              target_firstblock = (int) simple_strtoul(colon + 1, NULL, 0);
-+      else
++      if (colon) {
++              unsigned long block;
++              result = strict_strtoul(colon + 1, 0, &block);
++              if (result)
++                      goto out;
++              target_firstblock = (int) block;
++      } else
 +              target_firstblock = 0;
 +
 +      if (at_symbol) {
-+              target_blocksize = (int) simple_strtoul(at_symbol + 1, NULL, 0);
++              unsigned long block_size;
++              result = strict_strtoul(at_symbol + 1, 0, &block_size);
++              if (result)
++                      goto out;
++              target_blocksize = (int) block_size;
 +              if (target_blocksize & (SECTOR_SIZE - 1)) {
 +                      printk(KERN_INFO "FileAllocator: Blocksizes are "
 +                                       "multiples of %d.\n", SECTOR_SIZE);
@@ -9955,10 +10082,10 @@ index 0000000..4181c47
 +#endif
 diff --git a/kernel/power/tuxonice_highlevel.c b/kernel/power/tuxonice_highlevel.c
 new file mode 100644
-index 0000000..e56dbed
+index 0000000..c1e99fd
 --- /dev/null
 +++ b/kernel/power/tuxonice_highlevel.c
-@@ -0,0 +1,1335 @@
+@@ -0,0 +1,1305 @@
 +/*
 + * kernel/power/tuxonice_highlevel.c
 + */
@@ -10029,7 +10156,6 @@ index 0000000..e56dbed
 + */
 +
 +#include <linux/suspend.h>
-+#include <linux/module.h>
 +#include <linux/freezer.h>
 +#include <linux/utsrelease.h>
 +#include <linux/cpu.h>
@@ -10058,15 +10184,11 @@ index 0000000..e56dbed
 +static mm_segment_t oldfs;
 +static DEFINE_MUTEX(tuxonice_in_use);
 +static int block_dump_save;
-+static char pre_hibernate_command[256];
-+static char post_hibernate_command[256];
 +
 +/* Binary signature if an image is present */
 +char *tuxonice_signature = "\xed\xc3\x02\xe9\x98\x56\xe5\x0c";
 +EXPORT_SYMBOL_GPL(tuxonice_signature);
 +
-+int do_toi_step(int step);
-+
 +unsigned long boot_kernel_data_buffer;
 +
 +static char *result_strings[] = {
@@ -10120,11 +10242,6 @@ index 0000000..e56dbed
 +              block_dump = block_dump_save;
 +              set_cpus_allowed(current, CPU_MASK_ALL);
 +              toi_alloc_print_debug_stats();
-+
-+              if (hibernate_or_resume == SYSFS_HIBERNATE &&
-+                              strlen(post_hibernate_command))
-+                      toi_launch_userspace_program(post_hibernate_command,
-+                                      0, UMH_WAIT_PROC, 0);
 +              atomic_inc(&snapshot_device_available);
 +              mutex_unlock(&pm_mutex);
 +      }
@@ -10143,8 +10260,6 @@ index 0000000..e56dbed
 + **/
 +int toi_start_anything(int hibernate_or_resume)
 +{
-+      int starting_cycle = (hibernate_or_resume == SYSFS_HIBERNATE);
-+
 +      mutex_lock(&tuxonice_in_use);
 +
 +      oldfs = get_fs();
@@ -10157,17 +10272,6 @@ index 0000000..e56dbed
 +                      goto snapshotdevice_unavailable;
 +      }
 +
-+      if (starting_cycle && strlen(pre_hibernate_command)) {
-+              int result = toi_launch_userspace_program(pre_hibernate_command,
-+                              0, UMH_WAIT_PROC, 0);
-+              if (result) {
-+                      printk(KERN_INFO "Pre-hibernate command '%s' returned"
-+                                      " %d. Aborting.\n",
-+                                      pre_hibernate_command, result);
-+                      goto prehibernate_err;
-+              }
-+      }
-+
 +      if (hibernate_or_resume == SYSFS_HIBERNATE)
 +              toi_print_modules();
 +
@@ -10448,7 +10552,7 @@ index 0000000..e56dbed
 +              /* Printk can only handle 1023 bytes, including
 +               * its level mangling. */
 +              for (i = 0; i < 3; i++)
-+                      printk("%s", buffer + (1023 * i));
++                      printk(KERN_ERR "%s", buffer + (1023 * i));
 +              toi_free_page(20, (unsigned long) buffer);
 +      }
 +
@@ -10954,12 +11058,12 @@ index 0000000..e56dbed
 +/* -- Functions for kickstarting a hibernate or resume --- */
 +
 +/**
-+ * __toi_try_resume - try to do the steps in resuming
++ * toi_try_resume - try to do the steps in resuming
 + *
 + * Check if we have an image and if so try to resume. Clear the status
 + * flags too.
 + **/
-+void __toi_try_resume(void)
++void toi_try_resume(void)
 +{
 +      set_toi_state(TOI_TRYING_TO_RESUME);
 +      resume_attempted = 1;
@@ -10980,12 +11084,12 @@ index 0000000..e56dbed
 +}
 +
 +/**
-+ * _toi_try_resume - wrapper calling __toi_try_resume from do_mounts
++ * toi_sys_power_disk_try_resume - wrapper calling toi_try_resume
 + *
-+ * Wrapper for when __toi_try_resume is called from init/do_mounts.c,
++ * Wrapper for when __toi_try_resume is called from swsusp resume path,
 + * rather than from echo > /sys/power/tuxonice/do_resume.
 + **/
-+static void _toi_try_resume(void)
++static void toi_sys_power_disk_try_resume(void)
 +{
 +      resume_attempted = 1;
 +
@@ -11000,7 +11104,7 @@ index 0000000..e56dbed
 +      if (toi_start_anything(SYSFS_RESUMING))
 +              goto out;
 +
-+      __toi_try_resume();
++      toi_try_resume();
 +
 +      /*
 +       * For initramfs, we have to clear the boot time
@@ -11014,8 +11118,7 @@ index 0000000..e56dbed
 +}
 +
 +/**
-+ * _toi_try_hibernate - try to start a hibernation cycle
-+ * @have_pmsem:       Whether the pm_sem is already taken.
++ * toi_try_hibernate - try to start a hibernation cycle
 + *
 + * Start a hibernation cycle, coming in from either
 + * echo > /sys/power/tuxonice/do_suspend
@@ -11027,7 +11130,7 @@ index 0000000..e56dbed
 + * In the later case, we come in without pm_sem taken; in the
 + * former, it has been taken.
 + **/
-+int _toi_try_hibernate(void)
++int toi_try_hibernate(void)
 +{
 +      int result = 0, sys_power_disk = 0, retries = 0;
 +
@@ -11151,10 +11254,10 @@ index 0000000..e56dbed
 +              int i;
 +              for (i = 0; i < arg; i++)
 +                      if (argv[i] && argv[i] != channel)
-+                              toi_kfree(5, argv[i]);
++                              toi_kfree(5, argv[i], sizeof (*argv[i]));
 +      }
 +
-+      toi_kfree(4, channel);
++      toi_kfree(4, channel, sizeof(*channel));
 +
 +      return retval;
 +}
@@ -11207,10 +11310,6 @@ index 0000000..e56dbed
 +                      TOI_NO_PS2_IF_UNNEEDED, 0),
 +      SYSFS_BIT("late_cpu_hotplug", SYSFS_RW, &toi_bkd.toi_action,
 +                      TOI_LATE_CPU_HOTPLUG, 0),
-+      SYSFS_STRING("pre_hibernate_command", SYSFS_RW, pre_hibernate_command,
-+                      0, 255, NULL),
-+      SYSFS_STRING("post_hibernate_command", SYSFS_RW, post_hibernate_command,
-+                      0, 255, NULL),
 +#ifdef CONFIG_TOI_KEEP_IMAGE
 +      SYSFS_BIT("keep_image", SYSFS_RW , &toi_bkd.toi_action, TOI_KEEP_IMAGE,
 +                      0),
@@ -11220,8 +11319,8 @@ index 0000000..e56dbed
 +static struct toi_core_fns my_fns = {
 +      .get_nonconflicting_page = __toi_get_nonconflicting_page,
 +      .post_context_save = __toi_post_context_save,
-+      .try_hibernate = _toi_try_hibernate,
-+      .try_resume = _toi_try_resume,
++      .try_hibernate = toi_try_hibernate,
++      .try_resume = toi_sys_power_disk_try_resume,
 +};
 +
 +/**
@@ -11238,8 +11337,6 @@ index 0000000..e56dbed
 +
 +      printk(KERN_INFO "TuxOnIce " TOI_CORE_VERSION
 +                      " (http://tuxonice.net)\n");
-+      strncpy(pre_hibernate_command, CONFIG_TOI_DEFAULT_PRE_HIBERNATE, 255);
-+      strncpy(post_hibernate_command, CONFIG_TOI_DEFAULT_POST_HIBERNATE, 255);
 +
 +      if (toi_sysfs_init())
 +              return 1;
@@ -11296,10 +11393,10 @@ index 0000000..e56dbed
 +#endif
 diff --git a/kernel/power/tuxonice_io.c b/kernel/power/tuxonice_io.c
 new file mode 100644
-index 0000000..1207ad3
+index 0000000..ca21958
 --- /dev/null
 +++ b/kernel/power/tuxonice_io.c
-@@ -0,0 +1,1499 @@
+@@ -0,0 +1,1536 @@
 +/*
 + * kernel/power/tuxonice_io.c
 + *
@@ -11319,9 +11416,9 @@ index 0000000..1207ad3
 +#include <linux/utsname.h>
 +#include <linux/mount.h>
 +#include <linux/highmem.h>
-+#include <linux/module.h>
 +#include <linux/kthread.h>
 +#include <linux/cpu.h>
++#include <linux/fs_struct.h>
 +#include <asm/tlbflush.h>
 +
 +#include "tuxonice.h"
@@ -11681,6 +11778,144 @@ index 0000000..1207ad3
 +}
 +
 +/**
++ * write_next_page - write the next page in a pageset
++ * @data_pfn: The pfn where the next data to write is located.
++ * @my_io_index: The index of the page in the pageset.
++ * @write_pfn: The pfn number to write in the image (where the data belongs).
++ * @first_filter: Where to send the page (optimisation).
++ *
++ * Get the pfn of the next page to write, map the page if necessary and do the
++ * write.
++ **/
++static int write_next_page(unsigned long *data_pfn, int *my_io_index,
++              unsigned long *write_pfn, struct toi_module_ops *first_filter)
++{
++      struct page *page;
++      char **my_checksum_locn = &__get_cpu_var(checksum_locn);
++      int result = 0, was_present;
++
++      *data_pfn = memory_bm_next_pfn(io_map);
++
++      /* Another thread could have beaten us to it. */
++      if (*data_pfn == BM_END_OF_MAP) {
++              if (atomic_read(&io_count)) {
++                      printk(KERN_INFO "Ran out of pfns but io_count is "
++                                      "still %d.\n", atomic_read(&io_count));
++                      BUG();
++              }
++              return -ENODATA;
++      }
++
++      *my_io_index = io_finish_at - atomic_sub_return(1, &io_count);
++
++      memory_bm_clear_bit(io_map, *data_pfn);
++      page = pfn_to_page(*data_pfn);
++
++      was_present = kernel_page_present(page);
++      if (!was_present)
++              kernel_map_pages(page, 1, 1);
++
++      if (io_pageset == 1)
++              *write_pfn = memory_bm_next_pfn(pageset1_map);
++      else {
++              *write_pfn = *data_pfn;
++              *my_checksum_locn = tuxonice_get_next_checksum();
++      }
++
++      mutex_unlock(&io_mutex);
++
++      if (io_pageset == 2 && tuxonice_calc_checksum(page, *my_checksum_locn))
++              return 1;
++
++      result = first_filter->write_page(*write_pfn, page, PAGE_SIZE);
++
++      if (!was_present)
++              kernel_map_pages(page, 1, 0);
++
++      return result;
++}
++
++/**
++ * read_next_page - read the next page in a pageset
++ * @my_io_index: The index of the page in the pageset.
++ * @write_pfn: The pfn in which the data belongs.
++ *
++ * Read a page of the image into our buffer.
++ **/
++
++static int read_next_page(int *my_io_index, unsigned long *write_pfn,
++              struct page *buffer, struct toi_module_ops *first_filter)
++{
++      unsigned int buf_size;
++      int result;
++
++      *my_io_index = io_finish_at - atomic_sub_return(1, &io_count);
++      mutex_unlock(&io_mutex);
++
++      /*
++       * Are we aborting? If so, don't submit any more I/O as
++       * resetting the resume_attempted flag (from ui.c) will
++       * clear the bdev flags, making this thread oops.
++       */
++      if (unlikely(test_toi_state(TOI_STOP_RESUME))) {
++              atomic_dec(&toi_io_workers);
++              if (!atomic_read(&toi_io_workers))
++                      set_toi_state(TOI_IO_STOPPED);
++              while (1)
++                      schedule();
++      }
++
++      /* See toi_bio_read_page in tuxonice_block_io.c:
++       * read the next page in the image.
++       */
++      result = first_filter->read_page(write_pfn, buffer, &buf_size);
++      if (buf_size != PAGE_SIZE) {
++              abort_hibernate(TOI_FAILED_IO,
++                      "I/O pipeline returned %d bytes instead"
++                      " of %ud.\n", buf_size, PAGE_SIZE);
++              mutex_lock(&io_mutex);
++              return -ENODATA;
++      }
++
++      return result;
++}
++
++/**
++ * 
++ **/
++static void use_read_page(unsigned long write_pfn, struct page *buffer)
++{
++      struct page *final_page = pfn_to_page(write_pfn),
++                  *copy_page = final_page;
++      char *virt, *buffer_virt;
++
++      if (io_pageset == 1 && !load_direct(final_page)) {
++              copy_page = copy_page_from_orig_page(final_page);
++              BUG_ON(!copy_page);
++      }
++
++      if (memory_bm_test_bit(io_map, write_pfn)) {
++              int was_present;
++
++              virt = kmap(copy_page);
++              buffer_virt = kmap(buffer);
++              was_present = kernel_page_present(copy_page);
++              if (!was_present)
++                      kernel_map_pages(copy_page, 1, 1);
++              memcpy(virt, buffer_virt, PAGE_SIZE);
++              if (!was_present)
++                      kernel_map_pages(copy_page, 1, 0);
++              kunmap(copy_page);
++              kunmap(buffer);
++              memory_bm_clear_bit(io_map, write_pfn);
++      } else {
++              mutex_lock(&io_mutex);
++              atomic_inc(&io_count);
++              mutex_unlock(&io_mutex);
++      }
++}
++
++/**
 + * worker_rw_loop - main loop to read/write pages
 + *
 + * The main I/O loop for reading or writing pages. The io_map bitmap is used to
@@ -11701,9 +11936,6 @@ index 0000000..1207ad3
 +      mutex_lock(&io_mutex);
 +
 +      do {
-+              unsigned int buf_size;
-+              int was_present = 1;
-+
 +              if (data && jiffies > next_jiffies) {
 +                      next_jiffies += HZ / 2;
 +                      if (toiActiveAllocator->update_throughput_throttle)
@@ -11718,83 +11950,15 @@ index 0000000..1207ad3
 +               * use the copy (Pageset1) or original page (Pageset2), but
 +               * always write the pfn of the original page.
 +               */
-+              if (io_write) {
-+                      struct page *page;
-+                      char **my_checksum_locn = &__get_cpu_var(checksum_locn);
-+
-+                      data_pfn = memory_bm_next_pfn(io_map);
-+
-+                      /* Another thread could have beaten us to it. */
-+                      if (data_pfn == BM_END_OF_MAP) {
-+                              if (atomic_read(&io_count)) {
-+                                      printk(KERN_INFO "Ran out of pfns but "
-+                                              "io_count is still %d.\n",
-+                                              atomic_read(&io_count));
-+                                      BUG();
-+                              }
-+                              break;
-+                      }
-+
-+                      my_io_index = io_finish_at -
-+                              atomic_sub_return(1, &io_count);
-+
-+                      memory_bm_clear_bit(io_map, data_pfn);
-+                      page = pfn_to_page(data_pfn);
-+
-+                      was_present = kernel_page_present(page);
-+                      if (!was_present)
-+                              kernel_map_pages(page, 1, 1);
-+
-+                      if (io_pageset == 1)
-+                              write_pfn = memory_bm_next_pfn(pageset1_map);
-+                      else {
-+                              write_pfn = data_pfn;
-+                              *my_checksum_locn =
-+                                      tuxonice_get_next_checksum();
-+                      }
-+
-+                      mutex_unlock(&io_mutex);
-+
-+                      if (io_pageset == 2 &&
-+                          tuxonice_calc_checksum(page, *my_checksum_locn))
-+                                      return 1;
-+
-+                      result = first_filter->write_page(write_pfn, page,
-+                                      PAGE_SIZE);
-+
-+                      if (!was_present)
-+                              kernel_map_pages(page, 1, 0);
-+              } else { /* Reading */
-+                      my_io_index = io_finish_at -
-+                              atomic_sub_return(1, &io_count);
-+                      mutex_unlock(&io_mutex);
-+
-+                      /*
-+                       * Are we aborting? If so, don't submit any more I/O as
-+                       * resetting the resume_attempted flag (from ui.c) will
-+                       * clear the bdev flags, making this thread oops.
-+                       */
-+                      if (unlikely(test_toi_state(TOI_STOP_RESUME))) {
-+                              atomic_dec(&toi_io_workers);
-+                              if (!atomic_read(&toi_io_workers))
-+                                      set_toi_state(TOI_IO_STOPPED);
-+                              while (1)
-+                                      schedule();
-+                      }
-+
-+                      /* See toi_bio_read_page in tuxonice_block_io.c:
-+                       * read the next page in the image.
-+                       */
-+                      result = first_filter->read_page(&write_pfn, buffer,
-+                                      &buf_size);
-+                      if (buf_size != PAGE_SIZE) {
-+                              abort_hibernate(TOI_FAILED_IO,
-+                                      "I/O pipeline returned %d bytes instead"
-+                                      " of %ud.\n", buf_size, PAGE_SIZE);
-+                              mutex_lock(&io_mutex);
-+                              break;
-+                      }
-+              }
++              if (io_write)
++                      result = write_next_page(&data_pfn, &my_io_index,
++                                      &write_pfn, first_filter);
++              else /* Reading */
++                      result = read_next_page(&my_io_index, &write_pfn,
++                                      buffer, first_filter);
++
++              if (result == -ENODATA)
++                      break;
 +
 +              if (result) {
 +                      io_result = result;
@@ -11814,35 +11978,8 @@ index 0000000..1207ad3
 +               * Discard reads of resaved pages while reading ps2
 +               * and unwanted pages while rereading ps2 when aborting.
 +               */
-+              if (!io_write && !PageResave(pfn_to_page(write_pfn))) {
-+                      struct page *final_page = pfn_to_page(write_pfn),
-+                                  *copy_page = final_page;
-+                      char *virt, *buffer_virt;
-+
-+                      if (io_pageset == 1 && !load_direct(final_page)) {
-+                              copy_page =
-+                                      copy_page_from_orig_page(final_page);
-+                              BUG_ON(!copy_page);
-+                      }
-+
-+                      if (memory_bm_test_bit(io_map, write_pfn)) {
-+                              virt = kmap(copy_page);
-+                              buffer_virt = kmap(buffer);
-+                              was_present = kernel_page_present(copy_page);
-+                              if (!was_present)
-+                                      kernel_map_pages(copy_page, 1, 1);
-+                              memcpy(virt, buffer_virt, PAGE_SIZE);
-+                              if (!was_present)
-+                                      kernel_map_pages(copy_page, 1, 0);
-+                              kunmap(copy_page);
-+                              kunmap(buffer);
-+                              memory_bm_clear_bit(io_map, write_pfn);
-+                      } else {
-+                              mutex_lock(&io_mutex);
-+                              atomic_inc(&io_count);
-+                              mutex_unlock(&io_mutex);
-+                      }
-+              }
++              if (!io_write && !PageResave(pfn_to_page(write_pfn)))
++                      use_read_page(write_pfn, buffer);
 +
 +              if (my_io_index + io_base == io_nextupdate)
 +                      io_nextupdate = toi_update_status(my_io_index +
@@ -11850,8 +11987,7 @@ index 0000000..1207ad3
 +                              MB(io_base+my_io_index+1), MB(io_barmax));
 +
 +              if (my_io_index == io_pc) {
-+                      printk("%s%d%%...", io_pc_step == 1 ? KERN_ERR : "",
-+                                      20 * io_pc_step);
++                      printk(KERN_ERR "...%d%%.\n", 20 * io_pc_step);
 +                      io_pc_step++;
 +                      io_pc = io_finish_at * io_pc_step / 5;
 +              }
@@ -11987,8 +12123,6 @@ index 0000000..1207ad3
 +      if (!io_result && !result && !test_result_state(TOI_ABORTED)) {
 +              unsigned long next;
 +
-+              printk("done.\n");
-+
 +              toi_update_status(io_base + io_finish_at, io_barmax,
 +                              " %d/%d MB ",
 +                              MB(io_base + io_finish_at), MB(io_barmax));
@@ -12801,10 +12935,10 @@ index 0000000..1207ad3
 +}
 diff --git a/kernel/power/tuxonice_io.h b/kernel/power/tuxonice_io.h
 new file mode 100644
-index 0000000..86e8996
+index 0000000..01b3db6
 --- /dev/null
 +++ b/kernel/power/tuxonice_io.h
-@@ -0,0 +1,71 @@
+@@ -0,0 +1,70 @@
 +/*
 + * kernel/power/tuxonice_io.h
 + *
@@ -12818,7 +12952,6 @@ index 0000000..86e8996
 +
 +#include <linux/utsname.h>
 +#include "tuxonice_pagedir.h"
-+#include "power.h"
 +
 +/* Non-module data saved in our image header */
 +struct toi_header {
@@ -12878,7 +13011,7 @@ index 0000000..86e8996
 +extern int toi_bio_queue_flusher_should_finish;
 diff --git a/kernel/power/tuxonice_modules.c b/kernel/power/tuxonice_modules.c
 new file mode 100644
-index 0000000..a0cd9eb
+index 0000000..c650f5c
 --- /dev/null
 +++ b/kernel/power/tuxonice_modules.c
 @@ -0,0 +1,494 @@
@@ -12890,7 +13023,6 @@ index 0000000..a0cd9eb
 + */
 +
 +#include <linux/suspend.h>
-+#include <linux/module.h>
 +#include "tuxonice.h"
 +#include "tuxonice_modules.h"
 +#include "tuxonice_sysfs.h"
@@ -12966,6 +13098,7 @@ index 0000000..a0cd9eb
 +      printk(KERN_DEBUG "                     %ld\n",
 +                      bytes + sizeof(struct toi_module_header));
 +}
++EXPORT_SYMBOL_GPL(print_toi_header_storage_for_modules);
 +
 +/*
 + * toi_memory_for_modules
@@ -13982,10 +14115,10 @@ index 0000000..37e174b
 +#endif
 diff --git a/kernel/power/tuxonice_pagedir.c b/kernel/power/tuxonice_pagedir.c
 new file mode 100644
-index 0000000..0c2f7fc
+index 0000000..92c1e5e
 --- /dev/null
 +++ b/kernel/power/tuxonice_pagedir.c
-@@ -0,0 +1,381 @@
+@@ -0,0 +1,380 @@
 +/*
 + * kernel/power/tuxonice_pagedir.c
 + *
@@ -14014,7 +14147,6 @@ index 0000000..0c2f7fc
 +#include "tuxonice_pagedir.h"
 +#include "tuxonice_prepare_image.h"
 +#include "tuxonice.h"
-+#include "power.h"
 +#include "tuxonice_builtin.h"
 +#include "tuxonice_alloc.h"
 +
@@ -14142,7 +14274,7 @@ index 0000000..0c2f7fc
 +      int low_direct = 0, high_direct = 0;
 +      int high_to_free, low_to_free, result = 0;
 +
-+      /* 
++      /*
 +       * We are about to allocate all available memory, and processes
 +       * might not have finished freezing yet. To avoid potential OOMs,
 +       * disable non boot cpus and do this with IRQs disabled
@@ -14347,7 +14479,7 @@ index 0000000..0c2f7fc
 +
 +      local_irq_enable();
 +      enable_nonboot_cpus();
-+      
++
 +      return result;
 +}
 +
@@ -14425,10 +14557,10 @@ index 0000000..9d0d929
 +#endif
 diff --git a/kernel/power/tuxonice_pageflags.c b/kernel/power/tuxonice_pageflags.c
 new file mode 100644
-index 0000000..5310faa
+index 0000000..626e5df
 --- /dev/null
 +++ b/kernel/power/tuxonice_pageflags.c
-@@ -0,0 +1,27 @@
+@@ -0,0 +1,28 @@
 +/*
 + * kernel/power/tuxonice_pageflags.c
 + *
@@ -14456,12 +14588,13 @@ index 0000000..5310faa
 +
 +      return total;
 +}
++EXPORT_SYMBOL_GPL(toi_pageflags_space_needed);
 diff --git a/kernel/power/tuxonice_pageflags.h b/kernel/power/tuxonice_pageflags.h
 new file mode 100644
-index 0000000..14dc7c5
+index 0000000..610625d
 --- /dev/null
 +++ b/kernel/power/tuxonice_pageflags.h
-@@ -0,0 +1,74 @@
+@@ -0,0 +1,72 @@
 +/*
 + * kernel/power/tuxonice_pageflags.h
 + *
@@ -14473,8 +14606,6 @@ index 0000000..14dc7c5
 +#ifndef KERNEL_POWER_TUXONICE_PAGEFLAGS_H
 +#define KERNEL_POWER_TUXONICE_PAGEFLAGS_H
 +
-+#include "power.h"
-+
 +extern struct memory_bitmap *pageset1_map;
 +extern struct memory_bitmap *pageset1_copy_map;
 +extern struct memory_bitmap *pageset2_map;
@@ -14538,7 +14669,7 @@ index 0000000..14dc7c5
 +#endif
 diff --git a/kernel/power/tuxonice_power_off.c b/kernel/power/tuxonice_power_off.c
 new file mode 100644
-index 0000000..2edd7fc
+index 0000000..9cdb489
 --- /dev/null
 +++ b/kernel/power/tuxonice_power_off.c
 @@ -0,0 +1,282 @@
@@ -14773,14 +14904,14 @@ index 0000000..2edd7fc
 +                      printk(KERN_INFO "Failed to read epoch file (%d).\n",
 +                                      (int) size);
 +              else {
-+                      unsigned long since_epoch =
-+                              simple_strtol(array, NULL, 0);
-+
-+                      /* Clear any wakeup time. */
-+                      write_alarm_file(0);
++                      unsigned long since_epoch;
++                      if (!strict_strtoul(array, 0, &since_epoch)) {
++                              /* Clear any wakeup time. */
++                              write_alarm_file(0);
 +
-+                      /* Set new wakeup time. */
-+                      write_alarm_file(since_epoch + wake_delay);
++                              /* Set new wakeup time. */
++                              write_alarm_file(since_epoch + wake_delay);
++                      }
 +              }
 +      }
 +
@@ -14856,10 +14987,10 @@ index 0000000..a85633a
 +extern void platform_restore_cleanup(int platform_mode);
 diff --git a/kernel/power/tuxonice_prepare_image.c b/kernel/power/tuxonice_prepare_image.c
 new file mode 100644
-index 0000000..1ee506a
+index 0000000..a675de0
 --- /dev/null
 +++ b/kernel/power/tuxonice_prepare_image.c
-@@ -0,0 +1,1056 @@
+@@ -0,0 +1,1045 @@
 +/*
 + * kernel/power/tuxonice_prepare_image.c
 + *
@@ -14882,7 +15013,6 @@ index 0000000..1ee506a
 + *
 + */
 +
-+#include <linux/module.h>
 +#include <linux/highmem.h>
 +#include <linux/freezer.h>
 +#include <linux/hardirq.h>
@@ -14895,7 +15025,6 @@ index 0000000..1ee506a
 +#include "tuxonice_ui.h"
 +#include "tuxonice_extent.h"
 +#include "tuxonice_prepare_image.h"
-+#include "tuxonice_block_io.h"
 +#include "tuxonice.h"
 +#include "tuxonice_checksum.h"
 +#include "tuxonice_sysfs.h"
@@ -14925,7 +15054,7 @@ index 0000000..1ee506a
 +      while (attention_list) {
 +              last = attention_list;
 +              attention_list = attention_list->next;
-+              toi_kfree(6, last);
++              toi_kfree(6, last, sizeof(*last));
 +      }
 +}
 +
@@ -15138,7 +15267,7 @@ index 0000000..1ee506a
 +                      ClearPageNosave(this->page + i);
 +
 +              toi_free_pages(9, this->page, this->order);
-+              toi_kfree(7, this);
++              toi_kfree(7, this, sizeof(*this));
 +      }
 +
 +      extra_pages_allocated = 0;
@@ -15184,7 +15313,7 @@ index 0000000..1ee506a
 +              }
 +
 +              if (!virt) {
-+                      toi_kfree(7, extras_entry);
++                      toi_kfree(7, extras_entry, sizeof(*extras_entry));
 +                      return extra_pages_allocated;
 +              }
 +
@@ -15221,10 +15350,7 @@ index 0000000..1ee506a
 +      int result = 0, cpu;
 +
 +      /* PCP lists */
-+      for_each_zone(zone) {
-+              if (!populated_zone(zone))
-+                      continue;
-+
++      for_each_populated_zone(zone) {
 +              if (!(zone_idx_mask & (1 << zone_idx(zone))))
 +                      continue;
 +
@@ -15285,6 +15411,7 @@ index 0000000..1ee506a
 +
 +      return DIV_ROUND_UP(bytes, PAGE_SIZE);
 +}
++EXPORT_SYMBOL_GPL(get_header_storage_needed);
 +
 +/*
 + * When freeing memory, pages from either pageset might be freed.
@@ -15496,10 +15623,7 @@ index 0000000..1ee506a
 +      struct zone *zone;
 +      struct list_head *curr;
 +
-+      for_each_zone(zone) {
-+              if (!populated_zone(zone))
-+                      continue;
-+
++      for_each_populated_zone(zone) {
 +              spin_lock_irqsave(&zone->lock, flags);
 +
 +              for (i = 0; i < zone->spanned_pages; i++)
@@ -15576,12 +15700,9 @@ index 0000000..1ee506a
 +       * Pages not to be saved are marked Nosave irrespective of being
 +       * reserved.
 +       */
-+      for_each_zone(zone) {
++      for_each_populated_zone(zone) {
 +              int highmem = is_highmem(zone);
 +
-+              if (!populated_zone(zone))
-+                      continue;
-+
 +              for (loop = 0; loop < zone->spanned_pages; loop++) {
 +                      unsigned long pfn = ZONE_START(zone) + loop;
 +                      struct page *page;
@@ -15672,8 +15793,6 @@ index 0000000..1ee506a
 +      int wanted, got, old_header_req;
 +      long seek;
 +
-+      toi_recalculate_image_contents(0);
-+
 +      /* Include allowance for growth in pagedir1 while writing pagedir 2 */
 +      wanted = pagedir1.size +  extra_pd1_pages_allowance -
 +              get_lowmem_size(pagedir2);
@@ -15778,7 +15897,6 @@ index 0000000..1ee506a
 +       * to freeze fail, we give up and abort.
 +       */
 +
-+      toi_recalculate_image_contents(0);
 +      amount_wanted = amount_needed(1);
 +
 +      switch (image_size_limit) {
@@ -15792,7 +15910,6 @@ index 0000000..1ee506a
 +              drop_pagecache();
 +              toi_recalculate_image_contents(0);
 +              amount_wanted = amount_needed(1);
-+              did_eat_memory = 1;
 +              break;
 +      default:
 +              break;
@@ -15800,7 +15917,7 @@ index 0000000..1ee506a
 +
 +      if (amount_wanted > 0 && !test_result_state(TOI_ABORTED) &&
 +                      image_size_limit != -1) {
-+              long request = amount_wanted;
++              long request = amount_wanted + 50;
 +
 +              toi_prepare_status(CLEAR_BAR,
 +                              "Seeking to free %ldMB of memory.",
@@ -15812,7 +15929,7 @@ index 0000000..1ee506a
 +               * Ask for too many because shrink_all_memory doesn't
 +               * currently return enough most of the time.
 +               */
-+              shrink_all_memory(amount_wanted + 50);
++              shrink_all_memory(request);
 +
 +              did_eat_memory = 1;
 +
@@ -15878,6 +15995,8 @@ index 0000000..1ee506a
 +              return 1;
 +      }
 +
++      toi_recalculate_image_contents(0);
++
 +      do {
 +              toi_prepare_status(CLEAR_BAR,
 +                              "Preparing Image. Try %d.", tries);
@@ -15907,6 +16026,7 @@ index 0000000..1ee506a
 +                      if (!need_pageset2() &&
 +                                test_action_state(TOI_NO_PS2_IF_UNNEEDED)) {
 +                              no_ps2_needed = 1;
++                              toi_recalculate_image_contents(0);
 +                              update_image(1);
 +                      }
 +
@@ -16299,10 +16419,10 @@ index 0000000..24f8e8a
 +};
 diff --git a/kernel/power/tuxonice_swap.c b/kernel/power/tuxonice_swap.c
 new file mode 100644
-index 0000000..7c0effe
+index 0000000..3753f5b
 --- /dev/null
 +++ b/kernel/power/tuxonice_swap.c
-@@ -0,0 +1,1313 @@
+@@ -0,0 +1,1334 @@
 +/*
 + * kernel/power/tuxonice_swap.c
 + *
@@ -16315,7 +16435,6 @@ index 0000000..7c0effe
 + */
 +
 +#include <linux/suspend.h>
-+#include <linux/module.h>
 +#include <linux/blkdev.h>
 +#include <linux/swapops.h>
 +#include <linux/swap.h>
@@ -16430,7 +16549,7 @@ index 0000000..7c0effe
 +              return;
 +
 +      blkdev_put(this->bdev, FMODE_READ | FMODE_NDELAY);
-+      toi_kfree(8, this);
++      toi_kfree(8, this, sizeof(*this));
 +      bdevs_opened[i] = NULL;
 +}
 +
@@ -16817,7 +16936,8 @@ index 0000000..7c0effe
 +
 +              if (extent_min > -1 && add_blocks_to_extent_chain(last_chain,
 +                                      extent_min, extent_max)) {
-+                      printk("Out of memory while making block chains.\n");
++                      printk(KERN_ERR "Out of memory while making block "
++                                      "chains.\n");
 +                      return -ENOMEM;
 +              }
 +
@@ -16828,8 +16948,8 @@ index 0000000..7c0effe
 +
 +      if (extent_min > -1 && add_blocks_to_extent_chain(last_chain,
 +                              extent_min, extent_max)) {
-+                      printk("Out of memory while making block chains.\n");
-+                      return -ENOMEM;
++              printk(KERN_ERR "Out of memory while making block chains.\n");
++              return -ENOMEM;
 +      }
 +
 +      return apply_header_reservation();
@@ -16866,7 +16986,7 @@ index 0000000..7c0effe
 +
 +      for (i = 0; i < MAX_SWAPFILES; i++) {
 +              struct swap_info_struct *si = get_swap_info_struct(i);
-+              if ((si->flags & SWP_USED) &&
++              if ((si->flags & SWP_USED) && si->swap_map &&
 +                  (si->flags & SWP_WRITEOK) &&
 +                  (strncmp(si->bdev->bd_disk->disk_name, "ram", 3))) {
 +                      val->totalswap += si->inuse_pages;
@@ -16965,7 +17085,8 @@ index 0000000..7c0effe
 +      for (i = 0; i < MAX_SWAPFILES; i++) {
 +              struct swap_info_struct *si = get_swap_info_struct(i);
 +              to_add[i] = 0;
-+              if (!si->bdev)
++              if (!(si->flags & SWP_USED) || !si->swap_map ||
++                  !(si->flags & SWP_WRITEOK))
 +                      continue;
 +              if (!strncmp(si->bdev->bd_disk->disk_name, "ram", 3)) {
 +                      devinfo[i].ignored = 1;
@@ -17030,14 +17151,28 @@ index 0000000..7c0effe
 +      }
 +
 +      for (i = 0; i < MAX_SWAPFILES; i++) {
-+              if (!to_add[i] || !toi_add_to_extent_chain(&swapextents,
-+                                      extent_min[i], extent_max[i]))
++              int this_result;
++
++              /* Anything to do for this swap entry? */
++              if (!to_add[i])
++                      continue;
++
++              this_result = toi_add_to_extent_chain(&swapextents,
++                              extent_min[i], extent_max[i]);
++
++              /* Added okay? */
++              if (!this_result)
 +                      continue;
 +
++              /* 
++               * Nope. Remember an error occured, free the swap and subtract
++               * from the amount of swap allocated.
++               */
++              result = this_result;
++
 +              free_swap_range(extent_min[i], extent_max[i]);
 +              if (!devinfo[i].ignored)
 +                      gotten -= (extent_max[i] - extent_min[i] + 1);
-+              break;
 +      }
 +
 +      if (gotten < pages_to_get) {
@@ -17081,7 +17216,8 @@ index 0000000..7c0effe
 +      /* Forward one page will be done prior to the read */
 +      for (i = 0; i < MAX_SWAPFILES; i++) {
 +              si = get_swap_info_struct(i);
-+              if (si->swap_file)
++              if (si->flags & SWP_USED && si->swap_map &&
++                  si->flags & SWP_WRITEOK)
 +                      devinfo[i].dev_t = si->bdev->bd_dev;
 +              else
 +                      devinfo[i].dev_t = (dev_t) 0;
@@ -17316,14 +17452,14 @@ index 0000000..7c0effe
 +      }
 +
 +      if (!resume_block_device) {
-+          resume_block_device = open_bdev(MAX_SWAPFILES, resume_swap_dev_t,
-+                          1);
-+          if (IS_ERR(resume_block_device)) {
-+              if (!quiet)
-+                      printk(KERN_INFO "Failed to open resume dev_t (%x).\n",
-+                              resume_swap_dev_t);
-+              return -1;
-+          }
++              resume_block_device = open_bdev(MAX_SWAPFILES,
++                              resume_swap_dev_t, 1);
++              if (IS_ERR(resume_block_device)) {
++                      if (!quiet)
++                              printk(KERN_INFO "Failed to open resume dev_t"
++                                              " (%x).\n", resume_swap_dev_t);
++                      return -1;
++              }
 +      }
 +
 +      signature_found = parse_signature();
@@ -17424,7 +17560,7 @@ index 0000000..7c0effe
 +              int only_allocator, int quiet)
 +{
 +      char *thischar, *devstart, *colon = NULL;
-+      int signature_found, result = -EINVAL, temp_result;
++      int signature_found, result = -EINVAL, temp_result = 0;
 +
 +      if (strncmp(commandline, "swap:", 5)) {
 +              /*
@@ -17452,15 +17588,19 @@ index 0000000..7c0effe
 +      while ((thischar - commandline) < 250 && *thischar)
 +              thischar++;
 +
-+      if (colon)
-+              resume_firstblock = (int) simple_strtoul(colon + 1, NULL, 0);
-+      else
++      if (colon) {
++              unsigned long block;
++              temp_result = strict_strtoul(colon + 1, 0, &block);
++              if (!temp_result)
++                      resume_firstblock = (int) block;
++      } else
 +              resume_firstblock = 0;
 +
 +      clear_toi_state(TOI_CAN_HIBERNATE);
 +      clear_toi_state(TOI_CAN_RESUME);
 +
-+      temp_result = try_to_parse_resume_device(devstart, quiet);
++      if (!temp_result)
++              temp_result = try_to_parse_resume_device(devstart, quiet);
 +
 +      if (colon)
 +              *colon = ':';
@@ -17500,7 +17640,8 @@ index 0000000..7c0effe
 +      for (i = 0; i < MAX_SWAPFILES; i++) {
 +              struct swap_info_struct *si =  get_swap_info_struct(i);
 +
-+              if (!si->swap_file)
++              if ((!si->flags & SWP_USED) || si->swap_map ||
++                  !(si->flags & SWP_WRITEOK))
 +                      continue;
 +
 +              if (S_ISBLK(si->swap_file->f_mapping->host->i_mode)) {
@@ -17618,10 +17759,10 @@ index 0000000..7c0effe
 +#endif
 diff --git a/kernel/power/tuxonice_sysfs.c b/kernel/power/tuxonice_sysfs.c
 new file mode 100644
-index 0000000..4f64dc7
+index 0000000..3b815ab
 --- /dev/null
 +++ b/kernel/power/tuxonice_sysfs.c
-@@ -0,0 +1,324 @@
+@@ -0,0 +1,335 @@
 +/*
 + * kernel/power/tuxonice_sysfs.c
 + *
@@ -17636,7 +17777,6 @@ index 0000000..4f64dc7
 + */
 +
 +#include <linux/suspend.h>
-+#include <linux/module.h>
 +
 +#include "tuxonice_sysfs.h"
 +#include "tuxonice.h"
@@ -17653,7 +17793,7 @@ index 0000000..4f64dc7
 +
 +static void toi_main_wrapper(void)
 +{
-+      _toi_try_hibernate();
++      toi_try_hibernate();
 +}
 +
 +static ssize_t toi_attr_show(struct kobject *kobj, struct attribute *attr,
@@ -17736,7 +17876,10 @@ index 0000000..4f64dc7
 +              break;
 +      case TOI_SYSFS_DATA_BIT:
 +              {
-+              int value = simple_strtoul(my_buf, NULL, 0);
++              unsigned long value;
++              result = strict_strtoul(my_buf, 0, &value);
++              if (result)
++                      break;
 +              if (value)
 +                      set_bit(sysfs_data->data.bit.bit,
 +                              (sysfs_data->data.bit.bit_vector));
@@ -17747,17 +17890,21 @@ index 0000000..4f64dc7
 +              break;
 +      case TOI_SYSFS_DATA_INTEGER:
 +              {
-+                      int *variable =
-+                              sysfs_data->data.integer.variable;
-+                      *variable = simple_strtol(my_buf, NULL, 0);
-+                      BOUND(variable, integer);
++                      long temp;
++                      result = strict_strtol(my_buf, 0, &temp);
++                      if (result)
++                              break;
++                      *(sysfs_data->data.integer.variable) = (int) temp;
++                      BOUND(sysfs_data->data.integer.variable, integer);
 +                      break;
 +              }
 +      case TOI_SYSFS_DATA_LONG:
 +              {
 +                      long *variable =
 +                              sysfs_data->data.a_long.variable;
-+                      *variable = simple_strtol(my_buf, NULL, 0);
++                      result = strict_strtol(my_buf, 0, variable);
++                      if (result)
++                              break;
 +                      BOUND(variable, a_long);
 +                      break;
 +              }
@@ -17765,7 +17912,9 @@ index 0000000..4f64dc7
 +              {
 +                      unsigned long *variable =
 +                              sysfs_data->data.ul.variable;
-+                      *variable = simple_strtoul(my_buf, NULL, 0);
++                      result = strict_strtoul(my_buf, 0, variable);
++                      if (result)
++                              break;
 +                      BOUND(variable, ul);
 +                      break;
 +              }
@@ -17794,8 +17943,11 @@ index 0000000..4f64dc7
 +              break;
 +      }
 +
++      if (!result)
++              result = count;
++
 +      /* Side effect routine? */
-+      if (sysfs_data->write_side_effect)
++      if (result == count && sysfs_data->write_side_effect)
 +              sysfs_data->write_side_effect();
 +
 +      /* Free temporary buffers */
@@ -17834,7 +17986,7 @@ index 0000000..4f64dc7
 +      SYSFS_CUSTOM("do_hibernate", SYSFS_WRITEONLY, NULL, NULL,
 +              SYSFS_HIBERNATING, toi_main_wrapper),
 +      SYSFS_CUSTOM("do_resume", SYSFS_WRITEONLY, NULL, NULL,
-+              SYSFS_RESUMING, __toi_try_resume)
++              SYSFS_RESUMING, toi_try_resume)
 +};
 +
 +void remove_toi_sysdir(struct kobject *kobj)
@@ -17948,10 +18100,10 @@ index 0000000..4f64dc7
 +}
 diff --git a/kernel/power/tuxonice_sysfs.h b/kernel/power/tuxonice_sysfs.h
 new file mode 100644
-index 0000000..2fea1cc
+index 0000000..2020ac7
 --- /dev/null
 +++ b/kernel/power/tuxonice_sysfs.h
-@@ -0,0 +1,138 @@
+@@ -0,0 +1,137 @@
 +/*
 + * kernel/power/tuxonice_sysfs.h
 + *
@@ -17961,7 +18113,6 @@ index 0000000..2fea1cc
 + */
 +
 +#include <linux/sysfs.h>
-+#include "power.h"
 +
 +struct toi_sysfs_data {
 +      struct attribute attr;
@@ -18457,10 +18608,10 @@ index 0000000..dc45741
 +extern void toi_remove_ui_ops(struct ui_ops *this_ui);
 diff --git a/kernel/power/tuxonice_userui.c b/kernel/power/tuxonice_userui.c
 new file mode 100644
-index 0000000..de685b6
+index 0000000..c7b1053
 --- /dev/null
 +++ b/kernel/power/tuxonice_userui.c
-@@ -0,0 +1,663 @@
+@@ -0,0 +1,662 @@
 +/*
 + * kernel/power/user_ui.c
 + *
@@ -18491,7 +18642,6 @@ index 0000000..de685b6
 +#include <linux/ctype.h>
 +#include <linux/tty.h>
 +#include <linux/vt_kern.h>
-+#include <linux/module.h>
 +#include <linux/reboot.h>
 +#include <linux/kmod.h>
 +#include <linux/security.h>
@@ -19125,10 +19275,10 @@ index 0000000..de685b6
 +late_initcall(toi_user_ui_init);
 +#endif
 diff --git a/kernel/power/user.c b/kernel/power/user.c
-index 6c85359..5249c79 100644
+index ed97375..3519246 100644
 --- a/kernel/power/user.c
 +++ b/kernel/power/user.c
-@@ -64,6 +64,7 @@ static struct snapshot_data {
+@@ -65,6 +65,7 @@ static struct snapshot_data {
  } snapshot_state;
  
  atomic_t snapshot_device_available = ATOMIC_INIT(1);
@@ -19137,7 +19287,7 @@ index 6c85359..5249c79 100644
  static int snapshot_open(struct inode *inode, struct file *filp)
  {
 diff --git a/kernel/printk.c b/kernel/printk.c
-index e3602d0..a239499 100644
+index 5052b54..0215fc3 100644
 --- a/kernel/printk.c
 +++ b/kernel/printk.c
 @@ -32,6 +32,7 @@
@@ -19145,10 +19295,10 @@ index e3602d0..a239499 100644
  #include <linux/bootmem.h>
  #include <linux/syscalls.h>
 +#include <linux/suspend.h>
+ #include <linux/kexec.h>
  
  #include <asm/uaccess.h>
-@@ -59,6 +60,7 @@ int console_printk[4] = {
+@@ -60,6 +61,7 @@ int console_printk[4] = {
        MINIMUM_CONSOLE_LOGLEVEL,       /* minimum_console_loglevel */
        DEFAULT_CONSOLE_LOGLEVEL,       /* default_console_loglevel */
  };
@@ -19156,7 +19306,7 @@ index e3602d0..a239499 100644
  
  /*
   * Low level drivers may need that to know if they can schedule in
-@@ -892,6 +894,7 @@ void suspend_console(void)
+@@ -911,6 +913,7 @@ void suspend_console(void)
        console_suspended = 1;
        up(&console_sem);
  }
@@ -19164,7 +19314,7 @@ index e3602d0..a239499 100644
  
  void resume_console(void)
  {
-@@ -901,6 +904,7 @@ void resume_console(void)
+@@ -920,6 +923,7 @@ void resume_console(void)
        console_suspended = 0;
        release_console_sem();
  }
@@ -19172,89 +19322,8 @@ index e3602d0..a239499 100644
  
  /**
   * acquire_console_sem - lock the console system for exclusive use.
-diff --git a/kernel/timer.c b/kernel/timer.c
-index 13dd64f..7075c2d 100644
---- a/kernel/timer.c
-+++ b/kernel/timer.c
-@@ -37,6 +37,8 @@
- #include <linux/delay.h>
- #include <linux/tick.h>
- #include <linux/kallsyms.h>
-+#include <linux/notifier.h>
-+#include <linux/suspend.h>
- #include <asm/uaccess.h>
- #include <asm/unistd.h>
-@@ -1057,6 +1059,59 @@ unsigned long avenrun[3];
- EXPORT_SYMBOL(avenrun);
-+#ifdef CONFIG_PM
-+static unsigned long avenrun_save[3];
-+/*
-+ * save_avenrun - Record the values prior to starting a hibernation cycle.
-+ * We do this to make the work done in hibernation invisible to userspace
-+ * post-suspend. Some programs, including some MTAs, watch the load average
-+ * and stop work until it lowers. Without this, they would stop working for
-+ * a while post-resume, unnecessarily.
-+ */
-+
-+static void save_avenrun(void)
-+{
-+      avenrun_save[0] = avenrun[0];
-+      avenrun_save[1] = avenrun[1];
-+      avenrun_save[2] = avenrun[2];
-+}
-+
-+static void restore_avenrun(void)
-+{
-+      if (!avenrun_save[0])
-+              return;
-+
-+      avenrun[0] = avenrun_save[0];
-+      avenrun[1] = avenrun_save[1];
-+      avenrun[2] = avenrun_save[2];
-+
-+      avenrun_save[0] = 0;
-+}
-+
-+static int avenrun_pm_callback(struct notifier_block *nfb,
-+                                      unsigned long action,
-+                                      void *ignored)
-+{
-+      switch (action) {
-+      case PM_HIBERNATION_PREPARE:
-+              save_avenrun();
-+              return NOTIFY_OK;
-+      case PM_POST_HIBERNATION:
-+              restore_avenrun();
-+              return NOTIFY_OK;
-+      }
-+
-+      return NOTIFY_DONE;
-+}
-+
-+static void register_pm_notifier_callback(void)
-+{
-+      pm_notifier(avenrun_pm_callback, 0);
-+}
-+#else
-+static inline void register_pm_notifier_callback(void) { }
-+#endif
-+
- /*
-  * calc_load - given tick count, update the avenrun load estimates.
-  * This is called while holding a write_lock on xtime_lock.
-@@ -1551,6 +1606,7 @@ void __init init_timers(void)
-       BUG_ON(err == NOTIFY_BAD);
-       register_cpu_notifier(&timers_nb);
-       open_softirq(TIMER_SOFTIRQ, run_timer_softirq);
-+      register_pm_notifier_callback();
- }
- /**
 diff --git a/mm/bootmem.c b/mm/bootmem.c
-index 51a0ccf..48374aa 100644
+index daf9271..fb468a7 100644
 --- a/mm/bootmem.c
 +++ b/mm/bootmem.c
 @@ -22,6 +22,7 @@
@@ -19266,7 +19335,7 @@ index 51a0ccf..48374aa 100644
  #ifdef CONFIG_CRASH_DUMP
  /*
 diff --git a/mm/highmem.c b/mm/highmem.c
-index b36b83b..c46ede9 100644
+index 68eb1d9..800c7a9 100644
 --- a/mm/highmem.c
 +++ b/mm/highmem.c
 @@ -58,6 +58,7 @@ unsigned int nr_free_highpages (void)
@@ -19278,10 +19347,10 @@ index b36b83b..c46ede9 100644
  static int pkmap_count[LAST_PKMAP];
  static unsigned int last_pkmap_nr;
 diff --git a/mm/memory.c b/mm/memory.c
-index d7df5ba..ef53e66 100644
+index 4126dd1..878eff1 100644
 --- a/mm/memory.c
 +++ b/mm/memory.c
-@@ -1180,6 +1180,7 @@ no_page_table:
+@@ -1185,6 +1185,7 @@ no_page_table:
        }
        return page;
  }
@@ -19290,10 +19359,10 @@ index d7df5ba..ef53e66 100644
  /* Can we do the FOLL_ANON optimization? */
  static inline int use_zero_page(struct vm_area_struct *vma)
 diff --git a/mm/mmzone.c b/mm/mmzone.c
-index 16ce8b9..8dd207b 100644
+index f5b7d17..72a6770 100644
 --- a/mm/mmzone.c
 +++ b/mm/mmzone.c
-@@ -13,6 +13,7 @@ struct pglist_data *first_online_pgdat(void)
+@@ -14,6 +14,7 @@ struct pglist_data *first_online_pgdat(void)
  {
        return NODE_DATA(first_online_node);
  }
@@ -19301,7 +19370,7 @@ index 16ce8b9..8dd207b 100644
  
  struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
  {
-@@ -22,6 +23,7 @@ struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
+@@ -23,6 +24,7 @@ struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
                return NULL;
        return NODE_DATA(nid);
  }
@@ -19309,7 +19378,7 @@ index 16ce8b9..8dd207b 100644
  
  /*
   * next_zone - helper magic for for_each_zone()
-@@ -41,6 +43,7 @@ struct zone *next_zone(struct zone *zone)
+@@ -42,6 +44,7 @@ struct zone *next_zone(struct zone *zone)
        }
        return zone;
  }
@@ -19318,10 +19387,10 @@ index 16ce8b9..8dd207b 100644
  static inline int zref_in_nodemask(struct zoneref *zref, nodemask_t *nodes)
  {
 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
-index 74dc57c..16df11b 100644
+index bb553c3..fb606e5 100644
 --- a/mm/page-writeback.c
 +++ b/mm/page-writeback.c
-@@ -105,6 +105,7 @@ int dirty_expire_interval = 30 * HZ;
+@@ -105,6 +105,7 @@ unsigned int dirty_expire_interval = 30 * 100; /* centiseconds */
   * Flag that makes the machine dump writes/reads and block dirtyings.
   */
  int block_dump;
@@ -19330,10 +19399,10 @@ index 74dc57c..16df11b 100644
  /*
   * Flag that puts the machine in "laptop mode". Doubles as a timeout in jiffies:
 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
-index 5c44ed4..e9cddc3 100644
+index fe753ec..c2f026b 100644
 --- a/mm/page_alloc.c
 +++ b/mm/page_alloc.c
-@@ -1807,6 +1807,26 @@ static unsigned int nr_free_zone_pages(int offset)
+@@ -1810,6 +1810,26 @@ static unsigned int nr_free_zone_pages(int offset)
        return sum;
  }
  
@@ -19360,7 +19429,7 @@ index 5c44ed4..e9cddc3 100644
  /*
   * Amount of free RAM allocatable within ZONE_DMA and ZONE_NORMAL
   */
-@@ -1817,6 +1837,15 @@ unsigned int nr_free_buffer_pages(void)
+@@ -1820,6 +1840,15 @@ unsigned int nr_free_buffer_pages(void)
  EXPORT_SYMBOL_GPL(nr_free_buffer_pages);
  
  /*
@@ -19377,10 +19446,10 @@ index 5c44ed4..e9cddc3 100644
   */
  unsigned int nr_free_pagecache_pages(void)
 diff --git a/mm/shmem.c b/mm/shmem.c
-index 4103a23..caeba07 100644
+index b25f95c..4908d20 100644
 --- a/mm/shmem.c
 +++ b/mm/shmem.c
-@@ -1538,6 +1538,8 @@ static struct inode *shmem_get_inode(struct super_block *sb, int mode,
+@@ -1557,6 +1557,8 @@ static struct inode *shmem_get_inode(struct super_block *sb, int mode,
                memset(info, 0, (char *)inode - (char *)info);
                spin_lock_init(&info->lock);
                info->flags = flags & VM_NORESERVE;
@@ -19390,7 +19459,7 @@ index 4103a23..caeba07 100644
  
                switch (mode & S_IFMT) {
 diff --git a/mm/swap_state.c b/mm/swap_state.c
-index 3ecea98..be135e6 100644
+index 1416e7e..4f75ac3 100644
 --- a/mm/swap_state.c
 +++ b/mm/swap_state.c
 @@ -45,6 +45,7 @@ struct address_space swapper_space = {
@@ -19462,10 +19531,10 @@ index 312fafe..894fcb5 100644
  /*
   * swap_lock prevents swap_map being freed. Don't grab an extra
 diff --git a/mm/vmscan.c b/mm/vmscan.c
-index 56ddf41..f8df64a 100644
+index d254306..e20daf5 100644
 --- a/mm/vmscan.c
 +++ b/mm/vmscan.c
-@@ -2025,6 +2025,9 @@ void wakeup_kswapd(struct zone *zone, int order)
+@@ -2036,6 +2036,9 @@ void wakeup_kswapd(struct zone *zone, int order)
        if (!populated_zone(zone))
                return;
  
@@ -19475,51 +19544,11 @@ index 56ddf41..f8df64a 100644
        pgdat = zone->zone_pgdat;
        if (zone_watermark_ok(zone, order, zone->pages_low, 0, 0))
                return;
-@@ -2184,6 +2187,7 @@ out:
+@@ -2196,6 +2199,7 @@ out:
  
-       return ret;
+       return sc.nr_reclaimed;
  }
 +EXPORT_SYMBOL_GPL(shrink_all_memory);
  #endif
  
  /* It's optimal to keep kswapds on the same CPUs as their memory, but
-diff -ruNp 950-modular-compilation.patch-old/kernel/power/tuxonice_modules.c 950-modular-compilation.patch-new/kernel/power/tuxonice_modules.c
---- 950-modular-compilation.patch-old/kernel/power/tuxonice_modules.c  2009-04-11 08:31:27.000000000 +1000
-+++ 950-modular-compilation.patch-new/kernel/power/tuxonice_modules.c  2009-04-11 08:31:07.000000000 +1000
-@@ -80,6 +80,7 @@ void print_toi_header_storage_for_module
-       printk(KERN_DEBUG "                     %ld\n",
-              bytes + sizeof(struct toi_module_header));
- }
-+EXPORT_SYMBOL_GPL(print_toi_header_storage_for_modules);
- /*
-  * toi_memory_for_modules
-diff -ruNp 950-modular-compilation.patch-old/kernel/power/tuxonice_prepare_image.c 950-modular-compilation.patch-new/kernel/power/tuxonice_prepare_image.c
---- 950-modular-compilation.patch-old/kernel/power/tuxonice_prepare_image.c    2009-04-11 08:31:27.000000000 +1000
-+++ 950-modular-compilation.patch-new/kernel/power/tuxonice_prepare_image.c    2009-04-11 08:30:31.000000000 +1000
-@@ -424,6 +424,7 @@ long get_header_storage_needed(void)
-       return DIV_ROUND_UP(bytes, PAGE_SIZE);
- }
-+EXPORT_SYMBOL_GPL(get_header_storage_needed);
- /*
-  * When freeing memory, pages from either pageset might be freed.
-diff -ruNp 910.patch-old/kernel/power/tuxonice_pageflags.c 910.patch-new/kernel/power/tuxonice_pageflags.c
---- 910.patch-old/kernel/power/tuxonice_pageflags.c    2009-04-11 09:39:17.000000000 +1000
-+++ 910.patch-new/kernel/power/tuxonice_pageflags.c    2009-04-11 09:39:07.000000000 +1000
-@@ -25,3 +25,4 @@ int toi_pageflags_space_needed(void)
-       return total;
- }
-+EXPORT_SYMBOL_GPL(toi_pageflags_space_needed);
-diff -u linux-2.6.27/kernel/power/tuxonice_pageflags.h{~,}
---- linux-2.6.27/kernel/power/tuxonice_pageflags.h~     2009-04-11 10:14:55.000000000 +0200
-+++ linux-2.6.27/kernel/power/tuxonice_pageflags.h      2009-04-11 14:08:04.000000000 +0200
-@@ -70,5 +70,5 @@
-
- extern void save_pageflags(struct memory_bitmap *pagemap);
- extern int load_pageflags(struct memory_bitmap *pagemap);
--extern int toi_pageflags_space_needed(void);
-+int toi_pageflags_space_needed(void);
- #endif
index d8b47245e75aa50296c41baf12ffa98fcbd24e89..e017089a46caa35c3283539925ee4be61ee96e8b 100644 (file)
@@ -643,10 +643,10 @@ diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
 index 789cf2e..7f82ed3 100644
 --- a/fs/ecryptfs/main.c
 +++ b/fs/ecryptfs/main.c
-@@ -194,7 +194,7 @@ int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
-               d_add(dentry, inode);
-       else
-               d_instantiate(dentry, inode);
+@@ -190,7 +190,7 @@ int ecryptfs_interpose(struct dentry *lo
+               init_special_inode(inode, lower_inode->i_mode,
+                                  lower_inode->i_rdev);
+       dentry->d_op = &ecryptfs_dops;
 -      fsstack_copy_attr_all(inode, lower_inode, NULL);
 +      fsstack_copy_attr_all(inode, lower_inode);
        /* This size will be overwritten for real files w/ headers and
index ea3178f3225a0ef81d1464ffeb3c8b1050549015..1214f19389a6b39aaeb11d981719d7a5b98e34e5 100644 (file)
@@ -1,6 +1,6 @@
-diff -NurpP --minimal linux-2.6.29.4/arch/alpha/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/Kconfig
---- linux-2.6.29.4/arch/alpha/Kconfig  2009-03-24 14:18:07.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/Kconfig    2009-03-24 14:48:16.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/alpha/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/Kconfig
+--- linux-2.6.30.1/arch/alpha/Kconfig  2009-03-24 14:18:07.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/Kconfig       2009-07-04 01:11:38.000000000 +0200
 @@ -666,6 +666,8 @@ config DUMMY_CONSOLE
        depends on VGA_HOSE
        default y
@@ -10,9 +10,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/alpha/Kconfig linux-2.6.29.4-vs2.3.0.3
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/entry.S linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/entry.S
---- linux-2.6.29.4/arch/alpha/kernel/entry.S   2009-03-24 14:18:07.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/entry.S     2009-03-24 14:48:16.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/alpha/kernel/entry.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/kernel/entry.S
+--- linux-2.6.30.1/arch/alpha/kernel/entry.S   2009-06-11 17:11:46.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/kernel/entry.S        2009-07-04 01:11:38.000000000 +0200
 @@ -874,24 +874,15 @@ sys_getxgid:
        .globl  sys_getxpid
        .ent    sys_getxpid
@@ -45,10 +45,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/entry.S linux-2.6.29.4-vs
        ret
  .end sys_getxpid
  
-diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/osf_sys.c linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/osf_sys.c
---- linux-2.6.29.4/arch/alpha/kernel/osf_sys.c 2009-03-24 14:18:07.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/osf_sys.c   2009-03-24 14:48:16.000000000 +0100
-@@ -877,7 +877,7 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct
+diff -NurpP --minimal linux-2.6.30.1/arch/alpha/kernel/osf_sys.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/kernel/osf_sys.c
+--- linux-2.6.30.1/arch/alpha/kernel/osf_sys.c 2009-06-11 17:11:46.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/kernel/osf_sys.c      2009-07-04 01:11:38.000000000 +0200
+@@ -875,7 +875,7 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct
  {
        if (tv) {
                struct timeval ktv;
@@ -57,9 +57,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/osf_sys.c linux-2.6.29.4-
                if (put_tv32(tv, &ktv))
                        return -EFAULT;
        }
-diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/ptrace.c
---- linux-2.6.29.4/arch/alpha/kernel/ptrace.c  2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/ptrace.c    2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/alpha/kernel/ptrace.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/kernel/ptrace.c
+--- linux-2.6.30.1/arch/alpha/kernel/ptrace.c  2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/kernel/ptrace.c       2009-07-04 01:11:38.000000000 +0200
 @@ -15,6 +15,7 @@
  #include <linux/slab.h>
  #include <linux/security.h>
@@ -68,9 +68,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/ptrace.c linux-2.6.29.4-v
  
  #include <asm/uaccess.h>
  #include <asm/pgtable.h>
-diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/systbls.S linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/systbls.S
---- linux-2.6.29.4/arch/alpha/kernel/systbls.S 2009-03-24 14:18:08.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/systbls.S   2009-03-24 14:48:16.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/alpha/kernel/systbls.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/kernel/systbls.S
+--- linux-2.6.30.1/arch/alpha/kernel/systbls.S 2009-03-24 14:18:08.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/kernel/systbls.S      2009-07-04 01:11:38.000000000 +0200
 @@ -446,7 +446,7 @@ sys_call_table:
        .quad sys_stat64                        /* 425 */
        .quad sys_lstat64
@@ -80,9 +80,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/systbls.S linux-2.6.29.4-
        .quad sys_ni_syscall                    /* sys_mbind */
        .quad sys_ni_syscall                    /* sys_get_mempolicy */
        .quad sys_ni_syscall                    /* sys_set_mempolicy */
-diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/traps.c
---- linux-2.6.29.4/arch/alpha/kernel/traps.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/traps.c     2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/alpha/kernel/traps.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/kernel/traps.c
+--- linux-2.6.30.1/arch/alpha/kernel/traps.c   2009-06-11 17:11:46.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/kernel/traps.c        2009-07-04 01:11:38.000000000 +0200
 @@ -183,7 +183,8 @@ die_if_kernel(char * str, struct pt_regs
  #ifdef CONFIG_SMP
        printk("CPU %d ", hard_smp_processor_id());
@@ -93,9 +93,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/traps.c linux-2.6.29.4-vs
        dik_show_regs(regs, r9_15);
        add_taint(TAINT_DIE);
        dik_show_trace((unsigned long *)(regs+1));
-diff -NurpP --minimal linux-2.6.29.4/arch/alpha/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/mm/fault.c
---- linux-2.6.29.4/arch/alpha/mm/fault.c       2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/mm/fault.c 2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/alpha/mm/fault.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/mm/fault.c
+--- linux-2.6.30.1/arch/alpha/mm/fault.c       2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/alpha/mm/fault.c    2009-07-04 01:11:38.000000000 +0200
 @@ -193,8 +193,8 @@ do_page_fault(unsigned long address, uns
                down_read(&mm->mmap_sem);
                goto survive;
@@ -107,10 +107,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/alpha/mm/fault.c linux-2.6.29.4-vs2.3.
        if (!user_mode(regs))
                goto no_context;
        do_group_exit(SIGKILL);
-diff -NurpP --minimal linux-2.6.29.4/arch/arm/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/arm/Kconfig
---- linux-2.6.29.4/arch/arm/Kconfig    2009-03-24 14:18:08.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/arm/Kconfig      2009-03-24 14:48:16.000000000 +0100
-@@ -1333,6 +1333,8 @@ source "fs/Kconfig"
+diff -NurpP --minimal linux-2.6.30.1/arch/arm/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/arm/Kconfig
+--- linux-2.6.30.1/arch/arm/Kconfig    2009-06-11 17:11:46.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/arm/Kconfig 2009-07-04 01:11:38.000000000 +0200
+@@ -1429,6 +1429,8 @@ source "fs/Kconfig"
  
  source "arch/arm/Kconfig.debug"
  
@@ -119,9 +119,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/arm/Kconfig linux-2.6.29.4-vs2.3.0.36.
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/arm/kernel/calls.S linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/calls.S
---- linux-2.6.29.4/arch/arm/kernel/calls.S     2009-03-24 14:18:09.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/calls.S       2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/arm/kernel/calls.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/arm/kernel/calls.S
+--- linux-2.6.30.1/arch/arm/kernel/calls.S     2009-06-11 17:11:48.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/arm/kernel/calls.S  2009-07-04 01:11:38.000000000 +0200
 @@ -322,7 +322,7 @@
  /* 310 */     CALL(sys_request_key)
                CALL(sys_keyctl)
@@ -131,10 +131,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/arm/kernel/calls.S linux-2.6.29.4-vs2.
                CALL(sys_ioprio_set)
  /* 315 */     CALL(sys_ioprio_get)
                CALL(sys_inotify_init)
-diff -NurpP --minimal linux-2.6.29.4/arch/arm/kernel/process.c linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/process.c
---- linux-2.6.29.4/arch/arm/kernel/process.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/process.c     2009-02-22 22:54:24.000000000 +0100
-@@ -262,7 +262,8 @@ void __show_regs(struct pt_regs *regs)
+diff -NurpP --minimal linux-2.6.30.1/arch/arm/kernel/process.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/arm/kernel/process.c
+--- linux-2.6.30.1/arch/arm/kernel/process.c   2009-06-11 17:11:49.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/arm/kernel/process.c        2009-07-04 01:11:38.000000000 +0200
+@@ -263,7 +263,8 @@ void __show_regs(struct pt_regs *regs)
  void show_regs(struct pt_regs * regs)
  {
        printk("\n");
@@ -144,10 +144,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/arm/kernel/process.c linux-2.6.29.4-vs
        __show_regs(regs);
        __backtrace();
  }
-diff -NurpP --minimal linux-2.6.29.4/arch/arm/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/traps.c
---- linux-2.6.29.4/arch/arm/kernel/traps.c     2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/traps.c       2009-02-22 22:54:24.000000000 +0100
-@@ -214,8 +214,8 @@ static void __die(const char *str, int e
+diff -NurpP --minimal linux-2.6.30.1/arch/arm/kernel/traps.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/arm/kernel/traps.c
+--- linux-2.6.30.1/arch/arm/kernel/traps.c     2009-06-11 17:11:49.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/arm/kernel/traps.c  2009-07-04 01:11:38.000000000 +0200
+@@ -228,8 +228,8 @@ static void __die(const char *str, int e
               str, err, ++die_counter);
        print_modules();
        __show_regs(regs);
@@ -158,9 +158,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/arm/kernel/traps.c linux-2.6.29.4-vs2.
  
        if (!user_mode(regs) || in_interrupt()) {
                dump_mem("Stack: ", regs->ARM_sp,
-diff -NurpP --minimal linux-2.6.29.4/arch/arm/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/arm/mm/fault.c
---- linux-2.6.29.4/arch/arm/mm/fault.c 2009-03-24 14:18:17.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/arm/mm/fault.c   2009-03-24 14:48:17.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/arm/mm/fault.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/arm/mm/fault.c
+--- linux-2.6.30.1/arch/arm/mm/fault.c 2009-03-24 14:18:17.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/arm/mm/fault.c      2009-07-04 01:11:38.000000000 +0200
 @@ -294,7 +294,8 @@ do_page_fault(unsigned long addr, unsign
                 * happened to us that made us unable to handle
                 * the page fault gracefully.
@@ -171,9 +171,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/arm/mm/fault.c linux-2.6.29.4-vs2.3.0.
                do_group_exit(SIGKILL);
                return 0;
        }
-diff -NurpP --minimal linux-2.6.29.4/arch/cris/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/cris/Kconfig
---- linux-2.6.29.4/arch/cris/Kconfig   2009-03-24 14:18:23.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/cris/Kconfig     2009-03-24 14:48:19.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/cris/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/cris/Kconfig
+--- linux-2.6.30.1/arch/cris/Kconfig   2009-06-11 17:11:56.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/cris/Kconfig        2009-07-04 01:11:38.000000000 +0200
 @@ -685,6 +685,8 @@ source "drivers/staging/Kconfig"
  
  source "arch/cris/Kconfig.debug"
@@ -183,9 +183,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/cris/Kconfig linux-2.6.29.4-vs2.3.0.36
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/frv/kernel/kernel_thread.S linux-2.6.29.4-vs2.3.0.36.14/arch/frv/kernel/kernel_thread.S
---- linux-2.6.29.4/arch/frv/kernel/kernel_thread.S     2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/frv/kernel/kernel_thread.S       2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/frv/kernel/kernel_thread.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/frv/kernel/kernel_thread.S
+--- linux-2.6.30.1/arch/frv/kernel/kernel_thread.S     2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/frv/kernel/kernel_thread.S  2009-07-04 01:11:38.000000000 +0200
 @@ -37,7 +37,7 @@ kernel_thread:
  
        # start by forking the current process, but with shared VM
@@ -195,9 +195,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/frv/kernel/kernel_thread.S linux-2.6.2
        sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
        setlo           #0xe4e4,gr9
        setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
-diff -NurpP --minimal linux-2.6.29.4/arch/h8300/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/h8300/Kconfig
---- linux-2.6.29.4/arch/h8300/Kconfig  2009-03-24 14:18:24.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/h8300/Kconfig    2009-03-24 14:48:19.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/h8300/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/h8300/Kconfig
+--- linux-2.6.30.1/arch/h8300/Kconfig  2009-03-24 14:18:24.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/h8300/Kconfig       2009-07-04 01:11:38.000000000 +0200
 @@ -226,6 +226,8 @@ source "fs/Kconfig"
  
  source "arch/h8300/Kconfig.debug"
@@ -207,9 +207,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/h8300/Kconfig linux-2.6.29.4-vs2.3.0.3
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/ia64/ia32/ia32_entry.S linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/ia32/ia32_entry.S
---- linux-2.6.29.4/arch/ia64/ia32/ia32_entry.S 2009-03-24 14:18:24.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/ia32/ia32_entry.S   2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/ia64/ia32/ia32_entry.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/ia32/ia32_entry.S
+--- linux-2.6.30.1/arch/ia64/ia32/ia32_entry.S 2009-06-11 17:11:57.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/ia32/ia32_entry.S      2009-07-04 01:11:38.000000000 +0200
 @@ -451,7 +451,7 @@ ia32_syscall_table:
        data8 sys_tgkill        /* 270 */
        data8 compat_sys_utimes
@@ -219,10 +219,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/ia64/ia32/ia32_entry.S linux-2.6.29.4-
        data8 sys_ni_syscall
        data8 sys_ni_syscall    /* 275 */
        data8 sys_ni_syscall
-diff -NurpP --minimal linux-2.6.29.4/arch/ia64/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/Kconfig
---- linux-2.6.29.4/arch/ia64/Kconfig   2009-03-24 14:18:24.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/Kconfig     2009-03-24 14:48:19.000000000 +0100
-@@ -672,6 +672,8 @@ source "fs/Kconfig"
+diff -NurpP --minimal linux-2.6.30.1/arch/ia64/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/Kconfig
+--- linux-2.6.30.1/arch/ia64/Kconfig   2009-06-11 17:11:57.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/Kconfig        2009-07-04 01:11:38.000000000 +0200
+@@ -675,6 +675,8 @@ source "fs/Kconfig"
  
  source "arch/ia64/Kconfig.debug"
  
@@ -231,10 +231,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/ia64/Kconfig linux-2.6.29.4-vs2.3.0.36
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/entry.S linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/entry.S
---- linux-2.6.29.4/arch/ia64/kernel/entry.S    2009-03-24 14:18:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/entry.S      2009-02-22 22:54:24.000000000 +0100
-@@ -1653,7 +1653,7 @@ sys_call_table:
+diff -NurpP --minimal linux-2.6.30.1/arch/ia64/kernel/entry.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/kernel/entry.S
+--- linux-2.6.30.1/arch/ia64/kernel/entry.S    2009-06-11 17:11:57.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/kernel/entry.S 2009-07-04 01:11:38.000000000 +0200
+@@ -1753,7 +1753,7 @@ sys_call_table:
        data8 sys_mq_notify
        data8 sys_mq_getsetattr
        data8 sys_kexec_load
@@ -243,9 +243,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/entry.S linux-2.6.29.4-vs2
        data8 sys_waitid                        // 1270
        data8 sys_add_key
        data8 sys_request_key
-diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/perfmon.c linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/perfmon.c
---- linux-2.6.29.4/arch/ia64/kernel/perfmon.c  2009-03-24 14:18:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/perfmon.c    2009-03-24 14:48:19.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/ia64/kernel/perfmon.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/kernel/perfmon.c
+--- linux-2.6.30.1/arch/ia64/kernel/perfmon.c  2009-06-11 17:11:57.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/kernel/perfmon.c       2009-07-04 01:11:38.000000000 +0200
 @@ -41,6 +41,7 @@
  #include <linux/rcupdate.h>
  #include <linux/completion.h>
@@ -263,9 +263,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/perfmon.c linux-2.6.29.4-v
        vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
                                                        vma_pages(vma));
        up_write(&task->mm->mmap_sem);
-diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/process.c linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/process.c
---- linux-2.6.29.4/arch/ia64/kernel/process.c  2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/process.c    2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/ia64/kernel/process.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/kernel/process.c
+--- linux-2.6.30.1/arch/ia64/kernel/process.c  2009-06-11 17:11:57.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/kernel/process.c       2009-07-04 01:11:38.000000000 +0200
 @@ -110,8 +110,8 @@ show_regs (struct pt_regs *regs)
        unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
  
@@ -277,9 +277,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/process.c linux-2.6.29.4-v
        printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
               regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
               init_utsname()->release);
-diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/ptrace.c
---- linux-2.6.29.4/arch/ia64/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/ptrace.c     2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/ia64/kernel/ptrace.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/kernel/ptrace.c
+--- linux-2.6.30.1/arch/ia64/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/kernel/ptrace.c        2009-07-04 01:11:38.000000000 +0200
 @@ -23,6 +23,7 @@
  #include <linux/regset.h>
  #include <linux/elf.h>
@@ -288,9 +288,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/ptrace.c linux-2.6.29.4-vs
  
  #include <asm/pgtable.h>
  #include <asm/processor.h>
-diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/traps.c
---- linux-2.6.29.4/arch/ia64/kernel/traps.c    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/traps.c      2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/ia64/kernel/traps.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/kernel/traps.c
+--- linux-2.6.30.1/arch/ia64/kernel/traps.c    2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/kernel/traps.c 2009-07-04 01:11:38.000000000 +0200
 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
        put_cpu();
  
@@ -315,9 +315,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/traps.c linux-2.6.29.4-vs2
                        }
                }
        }
-diff -NurpP --minimal linux-2.6.29.4/arch/ia64/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/mm/fault.c
---- linux-2.6.29.4/arch/ia64/mm/fault.c        2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/mm/fault.c  2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/ia64/mm/fault.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/mm/fault.c
+--- linux-2.6.30.1/arch/ia64/mm/fault.c        2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/ia64/mm/fault.c     2009-07-04 01:11:38.000000000 +0200
 @@ -10,6 +10,7 @@
  #include <linux/interrupt.h>
  #include <linux/kprobes.h>
@@ -326,9 +326,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/ia64/mm/fault.c linux-2.6.29.4-vs2.3.0
  
  #include <asm/pgtable.h>
  #include <asm/processor.h>
-diff -NurpP --minimal linux-2.6.29.4/arch/m32r/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/m32r/kernel/traps.c
---- linux-2.6.29.4/arch/m32r/kernel/traps.c    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/m32r/kernel/traps.c      2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/m32r/kernel/traps.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m32r/kernel/traps.c
+--- linux-2.6.30.1/arch/m32r/kernel/traps.c    2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m32r/kernel/traps.c 2009-07-04 01:11:38.000000000 +0200
 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
        } else {
                printk("SPI: %08lx\n", sp);
@@ -341,9 +341,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/m32r/kernel/traps.c linux-2.6.29.4-vs2
  
        /*
         * When in-kernel, we also print out the stack and code at the
-diff -NurpP --minimal linux-2.6.29.4/arch/m68k/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/Kconfig
---- linux-2.6.29.4/arch/m68k/Kconfig   2009-03-24 14:18:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/Kconfig     2009-03-24 14:48:20.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/m68k/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m68k/Kconfig
+--- linux-2.6.30.1/arch/m68k/Kconfig   2009-03-24 14:18:26.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m68k/Kconfig        2009-07-04 01:11:38.000000000 +0200
 @@ -616,6 +616,8 @@ source "fs/Kconfig"
  
  source "arch/m68k/Kconfig.debug"
@@ -353,9 +353,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/m68k/Kconfig linux-2.6.29.4-vs2.3.0.36
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/m68k/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/kernel/ptrace.c
---- linux-2.6.29.4/arch/m68k/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/kernel/ptrace.c     2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/m68k/kernel/ptrace.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m68k/kernel/ptrace.c
+--- linux-2.6.30.1/arch/m68k/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m68k/kernel/ptrace.c        2009-07-04 01:11:38.000000000 +0200
 @@ -18,6 +18,7 @@
  #include <linux/ptrace.h>
  #include <linux/user.h>
@@ -373,9 +373,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/m68k/kernel/ptrace.c linux-2.6.29.4-vs
  
        return ret;
  out_eio:
-diff -NurpP --minimal linux-2.6.29.4/arch/m68k/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/kernel/traps.c
---- linux-2.6.29.4/arch/m68k/kernel/traps.c    2009-03-24 14:18:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/kernel/traps.c      2009-03-24 14:48:20.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/m68k/kernel/traps.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m68k/kernel/traps.c
+--- linux-2.6.30.1/arch/m68k/kernel/traps.c    2009-03-24 14:18:26.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m68k/kernel/traps.c 2009-07-04 01:11:38.000000000 +0200
 @@ -906,8 +906,8 @@ void show_registers(struct pt_regs *regs
        printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
               regs->d4, regs->d5, regs->a0, regs->a1);
@@ -387,10 +387,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/m68k/kernel/traps.c linux-2.6.29.4-vs2
        addr = (unsigned long)&fp->un;
        printk("Frame format=%X ", regs->format);
        switch (regs->format) {
-diff -NurpP --minimal linux-2.6.29.4/arch/m68knommu/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/m68knommu/Kconfig
---- linux-2.6.29.4/arch/m68knommu/Kconfig      2009-03-24 14:18:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/m68knommu/Kconfig        2009-03-24 14:48:20.000000000 +0100
-@@ -720,6 +720,8 @@ source "fs/Kconfig"
+diff -NurpP --minimal linux-2.6.30.1/arch/m68knommu/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m68knommu/Kconfig
+--- linux-2.6.30.1/arch/m68knommu/Kconfig      2009-06-11 17:11:59.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m68knommu/Kconfig   2009-07-04 01:11:38.000000000 +0200
+@@ -721,6 +721,8 @@ source "fs/Kconfig"
  
  source "arch/m68knommu/Kconfig.debug"
  
@@ -399,9 +399,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/m68knommu/Kconfig linux-2.6.29.4-vs2.3
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/m68knommu/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/m68knommu/kernel/traps.c
---- linux-2.6.29.4/arch/m68knommu/kernel/traps.c       2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/m68knommu/kernel/traps.c 2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/m68knommu/kernel/traps.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m68knommu/kernel/traps.c
+--- linux-2.6.30.1/arch/m68knommu/kernel/traps.c       2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/m68knommu/kernel/traps.c    2009-07-04 01:11:38.000000000 +0200
 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
        printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
               fp->d4, fp->d5, fp->a0, fp->a1);
@@ -414,10 +414,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/m68knommu/kernel/traps.c linux-2.6.29.
        show_stack(NULL, (unsigned long *)(fp + 1));
        add_taint(TAINT_DIE);
        do_exit(SIGSEGV);
-diff -NurpP --minimal linux-2.6.29.4/arch/mips/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/mips/Kconfig
---- linux-2.6.29.4/arch/mips/Kconfig   2009-03-24 14:18:29.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/Kconfig     2009-03-24 14:48:21.000000000 +0100
-@@ -2142,6 +2142,8 @@ source "fs/Kconfig"
+diff -NurpP --minimal linux-2.6.30.1/arch/mips/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/Kconfig
+--- linux-2.6.30.1/arch/mips/Kconfig   2009-06-11 17:12:00.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/Kconfig        2009-07-04 01:11:38.000000000 +0200
+@@ -2137,6 +2137,8 @@ source "fs/Kconfig"
  
  source "arch/mips/Kconfig.debug"
  
@@ -426,9 +426,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/mips/Kconfig linux-2.6.29.4-vs2.3.0.36
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/ptrace.c
---- linux-2.6.29.4/arch/mips/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/ptrace.c     2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/mips/kernel/ptrace.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/ptrace.c
+--- linux-2.6.30.1/arch/mips/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/ptrace.c        2009-07-04 01:11:38.000000000 +0200
 @@ -25,6 +25,7 @@
  #include <linux/security.h>
  #include <linux/audit.h>
@@ -447,9 +447,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/ptrace.c linux-2.6.29.4-vs
        switch (request) {
        /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT: /* read word at location addr. */
-diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall32-o32.S linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall32-o32.S
---- linux-2.6.29.4/arch/mips/kernel/scall32-o32.S      2009-03-24 14:18:31.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall32-o32.S        2009-03-24 14:48:21.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/mips/kernel/scall32-o32.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/scall32-o32.S
+--- linux-2.6.30.1/arch/mips/kernel/scall32-o32.S      2009-06-11 17:12:01.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/scall32-o32.S   2009-07-04 01:11:38.000000000 +0200
 @@ -597,7 +597,7 @@ einval:    li      v0, -ENOSYS
        sys     sys_mq_timedreceive     5
        sys     sys_mq_notify           2       /* 4275 */
@@ -459,9 +459,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall32-o32.S linux-2.6.29
        sys     sys_waitid              5
        sys     sys_ni_syscall          0       /* available, was setaltroot */
        sys     sys_add_key             5       /* 4280 */
-diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall64-64.S linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-64.S
---- linux-2.6.29.4/arch/mips/kernel/scall64-64.S       2009-03-24 14:18:31.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-64.S 2009-03-24 14:48:21.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/mips/kernel/scall64-64.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/scall64-64.S
+--- linux-2.6.30.1/arch/mips/kernel/scall64-64.S       2009-06-11 17:12:01.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/scall64-64.S    2009-07-04 01:11:38.000000000 +0200
 @@ -434,7 +434,7 @@ sys_call_table:
        PTR     sys_mq_timedreceive
        PTR     sys_mq_notify
@@ -471,9 +471,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall64-64.S linux-2.6.29.
        PTR     sys_waitid
        PTR     sys_ni_syscall                  /* available, was setaltroot */
        PTR     sys_add_key
-diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall64-n32.S linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-n32.S
---- linux-2.6.29.4/arch/mips/kernel/scall64-n32.S      2009-03-24 14:18:31.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-n32.S        2009-03-24 14:48:21.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/mips/kernel/scall64-n32.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/scall64-n32.S
+--- linux-2.6.30.1/arch/mips/kernel/scall64-n32.S      2009-06-11 17:12:01.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/scall64-n32.S   2009-07-04 01:11:38.000000000 +0200
 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
        PTR     compat_sys_mq_timedreceive
        PTR     compat_sys_mq_notify
@@ -483,9 +483,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall64-n32.S linux-2.6.29
        PTR     compat_sys_waitid
        PTR     sys_ni_syscall                  /* available, was setaltroot */
        PTR     sys_add_key
-diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall64-o32.S linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-o32.S
---- linux-2.6.29.4/arch/mips/kernel/scall64-o32.S      2009-03-24 14:18:31.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-o32.S        2009-03-24 14:59:48.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/mips/kernel/scall64-o32.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/scall64-o32.S
+--- linux-2.6.30.1/arch/mips/kernel/scall64-o32.S      2009-06-11 17:12:01.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/scall64-o32.S   2009-07-04 01:11:38.000000000 +0200
 @@ -480,7 +480,7 @@ sys_call_table:
        PTR     compat_sys_mq_timedreceive
        PTR     compat_sys_mq_notify            /* 4275 */
@@ -495,9 +495,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall64-o32.S linux-2.6.29
        PTR     sys_32_waitid
        PTR     sys_ni_syscall                  /* available, was setaltroot */
        PTR     sys_add_key                     /* 4280 */
-diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/traps.c
---- linux-2.6.29.4/arch/mips/kernel/traps.c    2009-03-24 14:18:31.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/traps.c      2009-03-24 14:48:21.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/mips/kernel/traps.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/traps.c
+--- linux-2.6.30.1/arch/mips/kernel/traps.c    2009-06-11 17:12:01.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/mips/kernel/traps.c 2009-07-04 01:11:38.000000000 +0200
 @@ -335,9 +335,10 @@ void show_registers(const struct pt_regs
  
        __show_regs(regs);
@@ -512,10 +512,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/traps.c linux-2.6.29.4-vs2
        if (cpu_has_userlocal) {
                unsigned long tls;
  
-diff -NurpP --minimal linux-2.6.29.4/arch/parisc/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/Kconfig
---- linux-2.6.29.4/arch/parisc/Kconfig 2009-03-24 14:18:32.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/Kconfig   2009-03-24 14:48:21.000000000 +0100
-@@ -281,6 +281,8 @@ source "fs/Kconfig"
+diff -NurpP --minimal linux-2.6.30.1/arch/parisc/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/parisc/Kconfig
+--- linux-2.6.30.1/arch/parisc/Kconfig 2009-06-11 17:12:02.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/parisc/Kconfig      2009-07-04 01:11:38.000000000 +0200
+@@ -291,6 +291,8 @@ source "fs/Kconfig"
  
  source "arch/parisc/Kconfig.debug"
  
@@ -524,9 +524,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/parisc/Kconfig linux-2.6.29.4-vs2.3.0.
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/parisc/kernel/syscall_table.S linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/kernel/syscall_table.S
---- linux-2.6.29.4/arch/parisc/kernel/syscall_table.S  2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/kernel/syscall_table.S    2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/parisc/kernel/syscall_table.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/parisc/kernel/syscall_table.S
+--- linux-2.6.30.1/arch/parisc/kernel/syscall_table.S  2009-06-11 17:12:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/parisc/kernel/syscall_table.S       2009-07-04 01:11:38.000000000 +0200
 @@ -361,7 +361,7 @@
        ENTRY_COMP(mbind)               /* 260 */
        ENTRY_COMP(get_mempolicy)
@@ -536,9 +536,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/parisc/kernel/syscall_table.S linux-2.
        ENTRY_SAME(add_key)
        ENTRY_SAME(request_key)         /* 265 */
        ENTRY_SAME(keyctl)
-diff -NurpP --minimal linux-2.6.29.4/arch/parisc/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/kernel/traps.c
---- linux-2.6.29.4/arch/parisc/kernel/traps.c  2009-03-24 14:18:32.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/kernel/traps.c    2009-03-24 14:48:21.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/parisc/kernel/traps.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/parisc/kernel/traps.c
+--- linux-2.6.30.1/arch/parisc/kernel/traps.c  2009-06-11 17:12:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/parisc/kernel/traps.c       2009-07-04 01:11:38.000000000 +0200
 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
                if (err == 0)
                        return; /* STFU */
@@ -551,7 +551,7 @@ diff -NurpP --minimal linux-2.6.29.4/arch/parisc/kernel/traps.c linux-2.6.29.4-v
  #ifdef PRINT_USER_FAULTS
                /* XXX for debugging only */
                show_regs(regs);
-@@ -269,8 +270,8 @@ KERN_CRIT "                     ||     |
+@@ -271,8 +272,8 @@ KERN_CRIT "                     ||     |
                pdc_console_restart();
        
        if (err)
@@ -562,9 +562,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/parisc/kernel/traps.c linux-2.6.29.4-v
  
        /* Wot's wrong wif bein' racy? */
        if (current->thread.flags & PARISC_KERNEL_DEATH) {
-diff -NurpP --minimal linux-2.6.29.4/arch/parisc/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/mm/fault.c
---- linux-2.6.29.4/arch/parisc/mm/fault.c      2009-03-24 14:18:33.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/mm/fault.c        2009-03-24 14:48:21.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/parisc/mm/fault.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/parisc/mm/fault.c
+--- linux-2.6.30.1/arch/parisc/mm/fault.c      2009-03-24 14:18:33.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/parisc/mm/fault.c   2009-07-04 01:11:38.000000000 +0200
 @@ -238,8 +238,9 @@ bad_area:
  
  #ifdef PRINT_USER_FAULTS
@@ -587,10 +587,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/parisc/mm/fault.c linux-2.6.29.4-vs2.3
        if (user_mode(regs))
                do_group_exit(SIGKILL);
        goto no_context;
-diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/Kconfig
---- linux-2.6.29.4/arch/powerpc/Kconfig        2009-03-24 14:18:33.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/Kconfig  2009-03-24 14:48:22.000000000 +0100
-@@ -882,6 +882,8 @@ source "lib/Kconfig"
+diff -NurpP --minimal linux-2.6.30.1/arch/powerpc/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/Kconfig
+--- linux-2.6.30.1/arch/powerpc/Kconfig        2009-06-11 17:12:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/Kconfig     2009-07-04 01:11:38.000000000 +0200
+@@ -922,6 +922,8 @@ source "lib/Kconfig"
  
  source "arch/powerpc/Kconfig.debug"
  
@@ -599,9 +599,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/Kconfig linux-2.6.29.4-vs2.3.0
  source "security/Kconfig"
  
  config KEYS_COMPAT
-diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/irq.c linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/irq.c
---- linux-2.6.29.4/arch/powerpc/kernel/irq.c   2009-03-24 14:18:35.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/irq.c     2009-03-24 14:48:22.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/powerpc/kernel/irq.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/kernel/irq.c
+--- linux-2.6.30.1/arch/powerpc/kernel/irq.c   2009-06-11 17:12:14.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/kernel/irq.c        2009-07-04 01:11:38.000000000 +0200
 @@ -53,6 +53,7 @@
  #include <linux/bootmem.h>
  #include <linux/pci.h>
@@ -610,10 +610,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/irq.c linux-2.6.29.4-vs
  
  #include <asm/uaccess.h>
  #include <asm/system.h>
-diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/process.c linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/process.c
---- linux-2.6.29.4/arch/powerpc/kernel/process.c       2009-03-24 14:18:35.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/process.c 2009-03-24 14:48:22.000000000 +0100
-@@ -516,8 +516,9 @@ void show_regs(struct pt_regs * regs)
+diff -NurpP --minimal linux-2.6.30.1/arch/powerpc/kernel/process.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/kernel/process.c
+--- linux-2.6.30.1/arch/powerpc/kernel/process.c       2009-06-11 17:12:14.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/kernel/process.c    2009-07-04 01:11:38.000000000 +0200
+@@ -519,8 +519,9 @@ void show_regs(struct pt_regs * regs)
  #else
                printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
  #endif
@@ -625,10 +625,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/process.c linux-2.6.29.
  
  #ifdef CONFIG_SMP
        printk(" CPU: %d", raw_smp_processor_id());
-diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/traps.c
---- linux-2.6.29.4/arch/powerpc/kernel/traps.c 2009-03-24 14:18:35.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/traps.c   2009-03-24 14:48:22.000000000 +0100
-@@ -940,8 +940,9 @@ void nonrecoverable_exception(struct pt_
+diff -NurpP --minimal linux-2.6.30.1/arch/powerpc/kernel/traps.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/kernel/traps.c
+--- linux-2.6.30.1/arch/powerpc/kernel/traps.c 2009-06-11 17:12:14.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/kernel/traps.c      2009-07-04 01:11:38.000000000 +0200
+@@ -921,8 +921,9 @@ void nonrecoverable_exception(struct pt_
  
  void trace_syscall(struct pt_regs *regs)
  {
@@ -640,9 +640,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/traps.c linux-2.6.29.4-
               regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
  }
  
-diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/vdso.c linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/vdso.c
---- linux-2.6.29.4/arch/powerpc/kernel/vdso.c  2009-03-24 14:18:35.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/vdso.c    2009-03-24 14:48:22.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/powerpc/kernel/vdso.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/kernel/vdso.c
+--- linux-2.6.30.1/arch/powerpc/kernel/vdso.c  2009-03-24 14:18:35.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/kernel/vdso.c       2009-07-04 01:11:38.000000000 +0200
 @@ -22,6 +22,7 @@
  #include <linux/security.h>
  #include <linux/bootmem.h>
@@ -651,10 +651,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/vdso.c linux-2.6.29.4-v
  
  #include <asm/pgtable.h>
  #include <asm/system.h>
-diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/mm/fault.c
---- linux-2.6.29.4/arch/powerpc/mm/fault.c     2009-03-24 14:18:36.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/mm/fault.c       2009-03-24 14:48:22.000000000 +0100
-@@ -362,7 +362,8 @@ out_of_memory:
+diff -NurpP --minimal linux-2.6.30.1/arch/powerpc/mm/fault.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/mm/fault.c
+--- linux-2.6.30.1/arch/powerpc/mm/fault.c     2009-06-11 17:12:14.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/powerpc/mm/fault.c  2009-07-04 01:11:38.000000000 +0200
+@@ -350,7 +350,8 @@ out_of_memory:
                down_read(&mm->mmap_sem);
                goto survive;
        }
@@ -664,10 +664,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/mm/fault.c linux-2.6.29.4-vs2.
        if (user_mode(regs))
                do_group_exit(SIGKILL);
        return SIGKILL;
-diff -NurpP --minimal linux-2.6.29.4/arch/s390/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/s390/Kconfig
---- linux-2.6.29.4/arch/s390/Kconfig   2009-03-24 14:18:38.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/s390/Kconfig     2009-03-24 14:48:22.000000000 +0100
-@@ -586,6 +586,8 @@ source "fs/Kconfig"
+diff -NurpP --minimal linux-2.6.30.1/arch/s390/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/s390/Kconfig
+--- linux-2.6.30.1/arch/s390/Kconfig   2009-06-11 17:12:16.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/s390/Kconfig        2009-07-04 01:11:38.000000000 +0200
+@@ -583,6 +583,8 @@ source "fs/Kconfig"
  
  source "arch/s390/Kconfig.debug"
  
@@ -676,9 +676,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/s390/Kconfig linux-2.6.29.4-vs2.3.0.36
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/s390/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/arch/s390/kernel/ptrace.c
---- linux-2.6.29.4/arch/s390/kernel/ptrace.c   2009-03-24 14:18:40.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/s390/kernel/ptrace.c     2009-03-24 14:48:22.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/s390/kernel/ptrace.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/s390/kernel/ptrace.c
+--- linux-2.6.30.1/arch/s390/kernel/ptrace.c   2009-03-24 14:18:40.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/s390/kernel/ptrace.c        2009-07-04 01:11:38.000000000 +0200
 @@ -36,6 +36,7 @@
  #include <linux/elf.h>
  #include <linux/regset.h>
@@ -687,9 +687,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/s390/kernel/ptrace.c linux-2.6.29.4-vs
  
  #include <asm/segment.h>
  #include <asm/page.h>
-diff -NurpP --minimal linux-2.6.29.4/arch/s390/kernel/syscalls.S linux-2.6.29.4-vs2.3.0.36.14/arch/s390/kernel/syscalls.S
---- linux-2.6.29.4/arch/s390/kernel/syscalls.S 2009-03-24 14:18:40.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/s390/kernel/syscalls.S   2009-03-24 14:48:22.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/s390/kernel/syscalls.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/s390/kernel/syscalls.S
+--- linux-2.6.30.1/arch/s390/kernel/syscalls.S 2009-06-11 17:12:16.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/s390/kernel/syscalls.S      2009-07-04 01:11:38.000000000 +0200
 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)      /* 260 */
  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
@@ -699,23 +699,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/s390/kernel/syscalls.S linux-2.6.29.4-
  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
-diff -NurpP --minimal linux-2.6.29.4/arch/s390/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/s390/mm/fault.c
---- linux-2.6.29.4/arch/s390/mm/fault.c        2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/s390/mm/fault.c  2009-02-22 22:54:24.000000000 +0100
-@@ -216,7 +216,8 @@ static int do_out_of_memory(struct pt_re
-               down_read(&mm->mmap_sem);
-               return 1;
-       }
--      printk("VM: killing process %s\n", tsk->comm);
-+      printk("VM: killing process %s(%d:#%u)\n",
-+              tsk->comm, tsk->pid, tsk->xid);
-       if (regs->psw.mask & PSW_MASK_PSTATE)
-               do_group_exit(SIGKILL);
-       do_no_context(regs, error_code, address);
-diff -NurpP --minimal linux-2.6.29.4/arch/sh/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/sh/Kconfig
---- linux-2.6.29.4/arch/sh/Kconfig     2009-03-24 14:18:40.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/sh/Kconfig       2009-03-24 14:48:22.000000000 +0100
-@@ -694,6 +694,8 @@ source "fs/Kconfig"
+diff -NurpP --minimal linux-2.6.30.1/arch/sh/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sh/Kconfig
+--- linux-2.6.30.1/arch/sh/Kconfig     2009-06-11 17:12:16.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sh/Kconfig  2009-07-04 01:11:38.000000000 +0200
+@@ -757,6 +757,8 @@ source "fs/Kconfig"
  
  source "arch/sh/Kconfig.debug"
  
@@ -724,9 +711,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/sh/Kconfig linux-2.6.29.4-vs2.3.0.36.1
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/sh/kernel/irq.c linux-2.6.29.4-vs2.3.0.36.14/arch/sh/kernel/irq.c
---- linux-2.6.29.4/arch/sh/kernel/irq.c        2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/sh/kernel/irq.c  2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/sh/kernel/irq.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sh/kernel/irq.c
+--- linux-2.6.30.1/arch/sh/kernel/irq.c        2009-06-11 17:12:18.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sh/kernel/irq.c     2009-07-04 01:11:38.000000000 +0200
 @@ -11,6 +11,7 @@
  #include <linux/module.h>
  #include <linux/kernel_stat.h>
@@ -735,9 +722,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/sh/kernel/irq.c linux-2.6.29.4-vs2.3.0
  #include <asm/processor.h>
  #include <asm/machvec.h>
  #include <asm/uaccess.h>
-diff -NurpP --minimal linux-2.6.29.4/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.29.4-vs2.3.0.36.14/arch/sh/kernel/vsyscall/vsyscall.c
---- linux-2.6.29.4/arch/sh/kernel/vsyscall/vsyscall.c  2009-03-24 14:18:42.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/sh/kernel/vsyscall/vsyscall.c    2009-03-24 14:48:22.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sh/kernel/vsyscall/vsyscall.c
+--- linux-2.6.30.1/arch/sh/kernel/vsyscall/vsyscall.c  2009-03-24 14:18:42.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sh/kernel/vsyscall/vsyscall.c       2009-07-04 01:11:38.000000000 +0200
 @@ -19,6 +19,7 @@
  #include <linux/elf.h>
  #include <linux/sched.h>
@@ -746,9 +733,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/sh/kernel/vsyscall/vsyscall.c linux-2.
  
  /*
   * Should the kernel map a VDSO page into processes and pass its
-diff -NurpP --minimal linux-2.6.29.4/arch/sparc/include/asm/tlb_64.h linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/include/asm/tlb_64.h
---- linux-2.6.29.4/arch/sparc/include/asm/tlb_64.h     2009-05-23 23:16:50.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/include/asm/tlb_64.h       2009-04-30 12:14:53.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/arch/sparc/include/asm/tlb_64.h linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sparc/include/asm/tlb_64.h
+--- linux-2.6.30.1/arch/sparc/include/asm/tlb_64.h     2009-06-11 17:12:18.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sparc/include/asm/tlb_64.h  2009-07-04 01:11:38.000000000 +0200
 @@ -3,6 +3,7 @@
  
  #include <linux/swap.h>
@@ -757,9 +744,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/sparc/include/asm/tlb_64.h linux-2.6.2
  #include <asm/pgalloc.h>
  #include <asm/tlbflush.h>
  #include <asm/mmu_context.h>
-diff -NurpP --minimal linux-2.6.29.4/arch/sparc/include/asm/unistd.h linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/include/asm/unistd.h
---- linux-2.6.29.4/arch/sparc/include/asm/unistd.h     2009-03-24 14:18:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/include/asm/unistd.h       2009-04-08 15:52:53.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/arch/sparc/include/asm/unistd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sparc/include/asm/unistd.h
+--- linux-2.6.30.1/arch/sparc/include/asm/unistd.h     2009-06-11 17:12:18.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sparc/include/asm/unistd.h  2009-07-04 01:11:38.000000000 +0200
 @@ -335,7 +335,7 @@
  #define __NR_timer_getoverrun 264
  #define __NR_timer_delete     265
@@ -769,10 +756,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/sparc/include/asm/unistd.h linux-2.6.2
  #define __NR_io_setup         268
  #define __NR_io_destroy               269
  #define __NR_io_submit                270
-diff -NurpP --minimal linux-2.6.29.4/arch/sparc/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/Kconfig
---- linux-2.6.29.4/arch/sparc/Kconfig  2009-03-24 14:18:43.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/Kconfig    2009-03-24 14:48:22.000000000 +0100
-@@ -522,6 +522,8 @@ source "fs/Kconfig"
+diff -NurpP --minimal linux-2.6.30.1/arch/sparc/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sparc/Kconfig
+--- linux-2.6.30.1/arch/sparc/Kconfig  2009-06-11 17:12:18.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sparc/Kconfig       2009-07-04 01:11:38.000000000 +0200
+@@ -525,6 +525,8 @@ source "fs/Kconfig"
  
  source "arch/sparc/Kconfig.debug"
  
@@ -781,9 +768,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/sparc/Kconfig linux-2.6.29.4-vs2.3.0.3
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/sparc/kernel/systbls_32.S linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/kernel/systbls_32.S
---- linux-2.6.29.4/arch/sparc/kernel/systbls_32.S      2009-03-24 14:18:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/kernel/systbls_32.S        2009-04-08 15:57:59.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/arch/sparc/kernel/systbls_32.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sparc/kernel/systbls_32.S
+--- linux-2.6.30.1/arch/sparc/kernel/systbls_32.S      2009-06-11 17:12:19.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sparc/kernel/systbls_32.S   2009-07-04 01:11:38.000000000 +0200
 @@ -70,7 +70,7 @@ sys_call_table:
  /*250*/       .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
  /*255*/       .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
@@ -793,9 +780,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/sparc/kernel/systbls_32.S linux-2.6.29
  /*270*/       .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
  /*275*/       .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
  /*280*/       .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
-diff -NurpP --minimal linux-2.6.29.4/arch/sparc/kernel/systbls_64.S linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/kernel/systbls_64.S
---- linux-2.6.29.4/arch/sparc/kernel/systbls_64.S      2009-03-24 14:18:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/kernel/systbls_64.S        2009-04-08 15:56:23.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/arch/sparc/kernel/systbls_64.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sparc/kernel/systbls_64.S
+--- linux-2.6.30.1/arch/sparc/kernel/systbls_64.S      2009-06-11 17:12:19.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/sparc/kernel/systbls_64.S   2009-07-04 01:11:38.000000000 +0200
 @@ -71,7 +71,7 @@ sys_call_table32:
  /*250*/       .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
        .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
@@ -814,9 +801,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/sparc/kernel/systbls_64.S linux-2.6.29
  /*270*/       .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
        .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
  /*280*/       .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
-diff -NurpP --minimal linux-2.6.29.4/arch/x86/ia32/ia32entry.S linux-2.6.29.4-vs2.3.0.36.14/arch/x86/ia32/ia32entry.S
---- linux-2.6.29.4/arch/x86/ia32/ia32entry.S   2009-03-24 14:18:48.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/x86/ia32/ia32entry.S     2009-03-22 23:29:11.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/x86/ia32/ia32entry.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/x86/ia32/ia32entry.S
+--- linux-2.6.30.1/arch/x86/ia32/ia32entry.S   2009-06-11 17:12:20.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/x86/ia32/ia32entry.S        2009-07-04 01:11:38.000000000 +0200
 @@ -768,7 +768,7 @@ ia32_sys_call_table:
        .quad sys_tgkill                /* 270 */
        .quad compat_sys_utimes
@@ -826,9 +813,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/x86/ia32/ia32entry.S linux-2.6.29.4-vs
        .quad sys_mbind
        .quad compat_sys_get_mempolicy  /* 275 */
        .quad sys_set_mempolicy
-diff -NurpP --minimal linux-2.6.29.4/arch/x86/include/asm/unistd_64.h linux-2.6.29.4-vs2.3.0.36.14/arch/x86/include/asm/unistd_64.h
---- linux-2.6.29.4/arch/x86/include/asm/unistd_64.h    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/x86/include/asm/unistd_64.h      2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/x86/include/asm/unistd_64.h linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/x86/include/asm/unistd_64.h
+--- linux-2.6.30.1/arch/x86/include/asm/unistd_64.h    2009-06-11 17:12:21.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/x86/include/asm/unistd_64.h 2009-07-04 01:11:38.000000000 +0200
 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
  #define __NR_utimes                           235
  __SYSCALL(__NR_utimes, sys_utimes)
@@ -838,10 +825,10 @@ diff -NurpP --minimal linux-2.6.29.4/arch/x86/include/asm/unistd_64.h linux-2.6.
  #define __NR_mbind                            237
  __SYSCALL(__NR_mbind, sys_mbind)
  #define __NR_set_mempolicy                    238
-diff -NurpP --minimal linux-2.6.29.4/arch/x86/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/x86/Kconfig
---- linux-2.6.29.4/arch/x86/Kconfig    2009-03-24 14:18:47.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/x86/Kconfig      2009-03-24 14:48:23.000000000 +0100
-@@ -1990,6 +1990,8 @@ source "fs/Kconfig"
+diff -NurpP --minimal linux-2.6.30.1/arch/x86/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/x86/Kconfig
+--- linux-2.6.30.1/arch/x86/Kconfig    2009-06-11 17:12:19.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/x86/Kconfig 2009-07-04 01:11:38.000000000 +0200
+@@ -2045,6 +2045,8 @@ source "fs/Kconfig"
  
  source "arch/x86/Kconfig.debug"
  
@@ -850,9 +837,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/x86/Kconfig linux-2.6.29.4-vs2.3.0.36.
  source "security/Kconfig"
  
  source "crypto/Kconfig"
-diff -NurpP --minimal linux-2.6.29.4/arch/x86/kernel/syscall_table_32.S linux-2.6.29.4-vs2.3.0.36.14/arch/x86/kernel/syscall_table_32.S
---- linux-2.6.29.4/arch/x86/kernel/syscall_table_32.S  2009-03-24 14:18:51.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/arch/x86/kernel/syscall_table_32.S    2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/arch/x86/kernel/syscall_table_32.S linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/x86/kernel/syscall_table_32.S
+--- linux-2.6.30.1/arch/x86/kernel/syscall_table_32.S  2009-06-11 17:12:23.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/arch/x86/kernel/syscall_table_32.S       2009-07-04 01:11:38.000000000 +0200
 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
        .long sys_tgkill        /* 270 */
        .long sys_utimes
@@ -862,9 +849,9 @@ diff -NurpP --minimal linux-2.6.29.4/arch/x86/kernel/syscall_table_32.S linux-2.
        .long sys_mbind
        .long sys_get_mempolicy
        .long sys_set_mempolicy
-diff -NurpP --minimal linux-2.6.29.4/Documentation/vserver/debug.txt linux-2.6.29.4-vs2.3.0.36.14/Documentation/vserver/debug.txt
---- linux-2.6.29.4/Documentation/vserver/debug.txt     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/Documentation/vserver/debug.txt       2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/Documentation/vserver/debug.txt linux-2.6.30.1-vs2.3.0.36.14-pre4/Documentation/vserver/debug.txt
+--- linux-2.6.30.1/Documentation/vserver/debug.txt     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/Documentation/vserver/debug.txt  2009-07-04 01:11:38.000000000 +0200
 @@ -0,0 +1,154 @@
 +
 +debug_cvirt:
@@ -1020,10 +1007,10 @@ diff -NurpP --minimal linux-2.6.29.4/Documentation/vserver/debug.txt linux-2.6.2
 + m 2^m        "vx_acc_page[%5d,%s,%2d]: %5d%s"
 +      "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
 +      "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
-diff -NurpP --minimal linux-2.6.29.4/drivers/block/Kconfig linux-2.6.29.4-vs2.3.0.36.14/drivers/block/Kconfig
---- linux-2.6.29.4/drivers/block/Kconfig       2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/block/Kconfig 2009-02-22 22:54:24.000000000 +0100
-@@ -264,6 +264,13 @@ config BLK_DEV_CRYPTOLOOP
+diff -NurpP --minimal linux-2.6.30.1/drivers/block/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/block/Kconfig
+--- linux-2.6.30.1/drivers/block/Kconfig       2009-06-11 17:12:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/block/Kconfig    2009-07-04 01:11:39.000000000 +0200
+@@ -271,6 +271,13 @@ config BLK_DEV_CRYPTOLOOP
          instead, which can be configured to be on-disk compatible with the
          cryptoloop device.
  
@@ -1037,9 +1024,9 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/block/Kconfig linux-2.6.29.4-vs2.3.
  config BLK_DEV_NBD
        tristate "Network block device support"
        depends on NET
-diff -NurpP --minimal linux-2.6.29.4/drivers/block/loop.c linux-2.6.29.4-vs2.3.0.36.14/drivers/block/loop.c
---- linux-2.6.29.4/drivers/block/loop.c        2009-03-24 14:18:56.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/block/loop.c  2009-03-24 15:09:29.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/drivers/block/loop.c linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/block/loop.c
+--- linux-2.6.30.1/drivers/block/loop.c        2009-06-11 17:12:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/block/loop.c     2009-07-04 01:11:39.000000000 +0200
 @@ -75,6 +75,7 @@
  #include <linux/gfp.h>
  #include <linux/kthread.h>
@@ -1048,7 +1035,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/block/loop.c linux-2.6.29.4-vs2.3.0
  
  #include <asm/uaccess.h>
  
-@@ -809,6 +810,7 @@ static int loop_set_fd(struct loop_devic
+@@ -834,6 +835,7 @@ static int loop_set_fd(struct loop_devic
        lo->lo_blocksize = lo_blocksize;
        lo->lo_device = bdev;
        lo->lo_flags = lo_flags;
@@ -1056,7 +1043,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/block/loop.c linux-2.6.29.4-vs2.3.0
        lo->lo_backing_file = file;
        lo->transfer = transfer_none;
        lo->ioctl = NULL;
-@@ -931,6 +933,7 @@ static int loop_clr_fd(struct loop_devic
+@@ -959,6 +961,7 @@ static int loop_clr_fd(struct loop_devic
        lo->lo_encrypt_key_size = 0;
        lo->lo_flags = 0;
        lo->lo_thread = NULL;
@@ -1064,7 +1051,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/block/loop.c linux-2.6.29.4-vs2.3.0
        memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
        memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
        memset(lo->lo_file_name, 0, LO_NAME_SIZE);
-@@ -958,7 +961,7 @@ loop_set_status(struct loop_device *lo, 
+@@ -993,7 +996,7 @@ loop_set_status(struct loop_device *lo, 
  
        if (lo->lo_encrypt_key_size &&
            lo->lo_key_owner != uid &&
@@ -1073,7 +1060,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/block/loop.c linux-2.6.29.4-vs2.3.0
                return -EPERM;
        if (lo->lo_state != Lo_bound)
                return -ENXIO;
-@@ -1042,7 +1045,8 @@ loop_get_status(struct loop_device *lo, 
+@@ -1077,7 +1080,8 @@ loop_get_status(struct loop_device *lo, 
        memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
        info->lo_encrypt_type =
                lo->lo_encryption ? lo->lo_encryption->number : 0;
@@ -1083,7 +1070,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/block/loop.c linux-2.6.29.4-vs2.3.0
                info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
                memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
                       lo->lo_encrypt_key_size);
-@@ -1351,6 +1355,9 @@ static int lo_open(struct block_device *
+@@ -1421,6 +1425,9 @@ static int lo_open(struct block_device *
  {
        struct loop_device *lo = bdev->bd_disk->private_data;
  
@@ -1093,19 +1080,20 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/block/loop.c linux-2.6.29.4-vs2.3.0
        mutex_lock(&lo->lo_ctl_mutex);
        lo->lo_refcnt++;
        mutex_unlock(&lo->lo_ctl_mutex);
-diff -NurpP --minimal linux-2.6.29.4/drivers/block/Makefile linux-2.6.29.4-vs2.3.0.36.14/drivers/block/Makefile
---- linux-2.6.29.4/drivers/block/Makefile      2009-03-24 14:18:55.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/block/Makefile        2009-03-24 14:48:25.000000000 +0100
-@@ -31,5 +31,6 @@ obj-$(CONFIG_VIODASD)                += viodasd.o
+diff -NurpP --minimal linux-2.6.30.1/drivers/block/Makefile linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/block/Makefile
+--- linux-2.6.30.1/drivers/block/Makefile      2009-06-11 17:12:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/block/Makefile   2009-07-04 01:11:39.000000000 +0200
+@@ -33,6 +33,7 @@ obj-$(CONFIG_VIODASD)                += viodasd.o
  obj-$(CONFIG_BLK_DEV_SX8)     += sx8.o
  obj-$(CONFIG_BLK_DEV_UB)      += ub.o
  obj-$(CONFIG_BLK_DEV_HD)      += hd.o
 +obj-$(CONFIG_BLK_DEV_VROOT)   += vroot.o
  
  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)     += xen-blkfront.o
-diff -NurpP --minimal linux-2.6.29.4/drivers/block/vroot.c linux-2.6.29.4-vs2.3.0.36.14/drivers/block/vroot.c
---- linux-2.6.29.4/drivers/block/vroot.c       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/block/vroot.c 2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/drivers/block/vroot.c linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/block/vroot.c
+--- linux-2.6.30.1/drivers/block/vroot.c       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/block/vroot.c    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,281 @@
 +/*
 + *  linux/drivers/block/vroot.c
@@ -1388,18 +1376,18 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/block/vroot.c linux-2.6.29.4-vs2.3.
 +
 +#endif
 +
-diff -NurpP --minimal linux-2.6.29.4/drivers/char/sysrq.c linux-2.6.29.4-vs2.3.0.36.14/drivers/char/sysrq.c
---- linux-2.6.29.4/drivers/char/sysrq.c        2009-03-24 14:18:57.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/char/sysrq.c  2009-03-24 15:15:27.000000000 +0100
-@@ -38,6 +38,7 @@
- #include <linux/irq.h>
+diff -NurpP --minimal linux-2.6.30.1/drivers/char/sysrq.c linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/char/sysrq.c
+--- linux-2.6.30.1/drivers/char/sysrq.c        2009-06-11 17:12:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/char/sysrq.c     2009-07-04 01:11:39.000000000 +0200
+@@ -37,6 +37,7 @@
+ #include <linux/kexec.h>
  #include <linux/hrtimer.h>
  #include <linux/oom.h>
 +#include <linux/vserver/debug.h>
  
  #include <asm/ptrace.h>
  #include <asm/irq_regs.h>
-@@ -369,6 +370,21 @@ static struct sysrq_key_op sysrq_unrt_op
+@@ -381,6 +382,21 @@ static struct sysrq_key_op sysrq_unrt_op
        .enable_mask    = SYSRQ_ENABLE_RTNICE,
  };
  
@@ -1421,7 +1409,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/char/sysrq.c linux-2.6.29.4-vs2.3.0
  /* Key Operations table and lock */
  static DEFINE_SPINLOCK(sysrq_key_table_lock);
  
-@@ -419,7 +435,11 @@ static struct sysrq_key_op *sysrq_key_ta
+@@ -435,7 +451,11 @@ static struct sysrq_key_op *sysrq_key_ta
        NULL,                           /* v */
        &sysrq_showstate_blocked_op,    /* w */
        /* x: May be registered on ppc/powerpc for xmon */
@@ -1433,7 +1421,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/char/sysrq.c linux-2.6.29.4-vs2.3.0
        /* y: May be registered on sparc64 for global register dump */
        NULL,                           /* y */
        &sysrq_ftrace_dump_op,          /* z */
-@@ -434,6 +454,8 @@ static int sysrq_key_table_key2index(int
+@@ -450,6 +470,8 @@ static int sysrq_key_table_key2index(int
                retval = key - '0';
        else if ((key >= 'a') && (key <= 'z'))
                retval = key + 10 - 'a';
@@ -1442,9 +1430,9 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/char/sysrq.c linux-2.6.29.4-vs2.3.0
        else
                retval = -1;
        return retval;
-diff -NurpP --minimal linux-2.6.29.4/drivers/char/tty_io.c linux-2.6.29.4-vs2.3.0.36.14/drivers/char/tty_io.c
---- linux-2.6.29.4/drivers/char/tty_io.c       2009-03-24 14:18:57.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/char/tty_io.c 2009-03-24 14:48:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/drivers/char/tty_io.c linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/char/tty_io.c
+--- linux-2.6.30.1/drivers/char/tty_io.c       2009-06-11 17:12:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/char/tty_io.c    2009-07-04 01:11:39.000000000 +0200
 @@ -106,6 +106,7 @@
  
  #include <linux/kmod.h>
@@ -1453,7 +1441,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/char/tty_io.c linux-2.6.29.4-vs2.3.
  
  #undef TTY_DEBUG_HANGUP
  
-@@ -2303,6 +2304,7 @@ static int tiocspgrp(struct tty_struct *
+@@ -2302,6 +2303,7 @@ static int tiocspgrp(struct tty_struct *
                return -ENOTTY;
        if (get_user(pgrp_nr, p))
                return -EFAULT;
@@ -1461,9 +1449,9 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/char/tty_io.c linux-2.6.29.4-vs2.3.
        if (pgrp_nr < 0)
                return -EINVAL;
        rcu_read_lock();
-diff -NurpP --minimal linux-2.6.29.4/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.29.4-vs2.3.0.36.14/drivers/infiniband/hw/ipath/ipath_user_pages.c
---- linux-2.6.29.4/drivers/infiniband/hw/ipath/ipath_user_pages.c      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/infiniband/hw/ipath/ipath_user_pages.c        2009-02-22 22:54:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/infiniband/hw/ipath/ipath_user_pages.c
+--- linux-2.6.30.1/drivers/infiniband/hw/ipath/ipath_user_pages.c      2009-06-11 17:12:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/infiniband/hw/ipath/ipath_user_pages.c   2009-07-04 01:11:39.000000000 +0200
 @@ -33,6 +33,7 @@
  
  #include <linux/mm.h>
@@ -1509,10 +1497,10 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/infiniband/hw/ipath/ipath_user_page
        up_write(&work->mm->mmap_sem);
        mmput(work->mm);
        kfree(work);
-diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm.c linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm.c
---- linux-2.6.29.4/drivers/md/dm.c     2009-03-24 14:19:05.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm.c       2009-03-24 15:15:57.000000000 +0100
-@@ -22,6 +22,7 @@
+diff -NurpP --minimal linux-2.6.30.1/drivers/md/dm.c linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/md/dm.c
+--- linux-2.6.30.1/drivers/md/dm.c     2009-07-03 20:12:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/md/dm.c  2009-07-04 01:11:39.000000000 +0200
+@@ -21,6 +21,7 @@
  #include <linux/hdreg.h>
  #include <linux/blktrace_api.h>
  #include <trace/block.h>
@@ -1520,7 +1508,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm.c linux-2.6.29.4-vs2.3.0.36.1
  
  #define DM_MSG_PREFIX "core"
  
-@@ -115,6 +116,7 @@ struct mapped_device {
+@@ -105,6 +106,7 @@ struct mapped_device {
        rwlock_t map_lock;
        atomic_t holders;
        atomic_t open_count;
@@ -1528,7 +1516,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm.c linux-2.6.29.4-vs2.3.0.36.1
  
        unsigned long flags;
  
-@@ -295,6 +297,7 @@ static void __exit dm_exit(void)
+@@ -291,6 +293,7 @@ static void __exit dm_exit(void)
  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
  {
        struct mapped_device *md;
@@ -1536,7 +1524,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm.c linux-2.6.29.4-vs2.3.0.36.1
  
        spin_lock(&_minor_lock);
  
-@@ -303,18 +306,19 @@ static int dm_blk_open(struct block_devi
+@@ -299,18 +302,19 @@ static int dm_blk_open(struct block_devi
                goto out;
  
        if (test_bit(DMF_FREEING, &md->flags) ||
@@ -1562,7 +1550,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm.c linux-2.6.29.4-vs2.3.0.36.1
  }
  
  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
-@@ -504,6 +508,14 @@ int dm_set_geometry(struct mapped_device
+@@ -503,6 +507,14 @@ int dm_set_geometry(struct mapped_device
        return 0;
  }
  
@@ -1577,7 +1565,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm.c linux-2.6.29.4-vs2.3.0.36.1
  /*-----------------------------------------------------------------
   * CRUD START:
   *   A more elegant soln is in the works that uses the queue
-@@ -1110,6 +1122,7 @@ static struct mapped_device *alloc_dev(i
+@@ -1126,6 +1138,7 @@ static struct mapped_device *alloc_dev(i
        INIT_LIST_HEAD(&md->uevent_list);
        spin_lock_init(&md->uevent_lock);
  
@@ -1585,21 +1573,21 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm.c linux-2.6.29.4-vs2.3.0.36.1
        md->queue = blk_alloc_queue(GFP_KERNEL);
        if (!md->queue)
                goto bad_queue;
-diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm.h linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm.h
---- linux-2.6.29.4/drivers/md/dm.h     2009-03-24 14:19:05.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm.h       2009-03-24 14:48:26.000000000 +0100
-@@ -54,6 +54,8 @@ int dm_table_any_congested(struct dm_tab
+diff -NurpP --minimal linux-2.6.30.1/drivers/md/dm.h linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/md/dm.h
+--- linux-2.6.30.1/drivers/md/dm.h     2009-06-11 17:12:31.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/md/dm.h  2009-07-04 01:11:39.000000000 +0200
+@@ -53,6 +53,8 @@ int dm_table_any_congested(struct dm_tab
+  */
  #define dm_target_is_valid(t) ((t)->table)
- int dm_table_barrier_ok(struct dm_table *t);
  
 +xid_t dm_get_xid(struct mapped_device *md);
 +
  /*-----------------------------------------------------------------
   * A registry of target types.
   *---------------------------------------------------------------*/
-diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm-ioctl.c linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm-ioctl.c
---- linux-2.6.29.4/drivers/md/dm-ioctl.c       2009-03-24 14:19:05.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm-ioctl.c 2009-03-24 14:48:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/drivers/md/dm-ioctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/md/dm-ioctl.c
+--- linux-2.6.30.1/drivers/md/dm-ioctl.c       2009-06-11 17:12:31.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/md/dm-ioctl.c    2009-07-04 01:11:39.000000000 +0200
 @@ -16,6 +16,7 @@
  #include <linux/dm-ioctl.h>
  #include <linux/hdreg.h>
@@ -1670,7 +1658,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm-ioctl.c linux-2.6.29.4-vs2.3.
  out:
        return mdptr;
  }
-@@ -1405,8 +1416,8 @@ static int ctl_ioctl(uint command, struc
+@@ -1426,8 +1437,8 @@ static int ctl_ioctl(uint command, struc
        ioctl_fn fn = NULL;
        size_t param_size;
  
@@ -1681,9 +1669,9 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm-ioctl.c linux-2.6.29.4-vs2.3.
                return -EACCES;
  
        if (_IOC_TYPE(command) != DM_IOCTL)
-diff -NurpP --minimal linux-2.6.29.4/drivers/net/tun.c linux-2.6.29.4-vs2.3.0.36.14/drivers/net/tun.c
---- linux-2.6.29.4/drivers/net/tun.c   2009-03-24 14:19:23.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/drivers/net/tun.c     2009-03-25 01:51:59.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/drivers/net/tun.c linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/net/tun.c
+--- linux-2.6.30.1/drivers/net/tun.c   2009-07-03 20:12:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/drivers/net/tun.c        2009-07-04 01:24:45.000000000 +0200
 @@ -61,6 +61,7 @@
  #include <linux/crc32.h>
  #include <linux/nsproxy.h>
@@ -1691,43 +1679,43 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/net/tun.c linux-2.6.29.4-vs2.3.0.36
 +#include <linux/vs_network.h>
  #include <net/net_namespace.h>
  #include <net/netns/generic.h>
-@@ -93,6 +94,7 @@ struct tun_struct {
-       int                     attached;
+ #include <net/rtnetlink.h>
+@@ -102,6 +103,7 @@ struct tun_struct {
+       unsigned int            flags;
        uid_t                   owner;
        gid_t                   group;
 +      nid_t                   nid;
  
-       wait_queue_head_t       read_wait;
        struct sk_buff_head     readq;
-@@ -697,6 +699,7 @@ static void tun_setup(struct net_device 
+@@ -138,7 +140,7 @@ static int tun_attach(struct tun_struct 
+       /* Check permissions */
+       if (((tun->owner != -1 && cred->euid != tun->owner) ||
+            (tun->group != -1 && !in_egroup_p(tun->group))) &&
+-              !capable(CAP_NET_ADMIN))
++              !cap_raised(current_cap(), CAP_NET_ADMIN))
+               return -EPERM;
+       netif_tx_lock_bh(tun->dev);
+@@ -813,6 +815,7 @@ static void tun_setup(struct net_device 
  
        tun->owner = -1;
        tun->group = -1;
 +      tun->nid = current->nid;
  
        dev->ethtool_ops = &tun_ethtool_ops;
-       dev->destructor = free_netdev;
-@@ -727,6 +730,9 @@ static int tun_set_iff(struct net *net, 
-       tn = net_generic(net, tun_net_id);
-       tun = tun_get_by_name(tn, ifr->ifr_name);
-       if (tun) {
+       dev->destructor = tun_free_netdev;
+@@ -877,6 +880,9 @@ static int tun_set_iff(struct net *net, 
+               else
+                       return -EINVAL;
 +              if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
 +                      return -EPERM;
 +
-               if (tun->attached)
-                       return -EBUSY;
-@@ -735,7 +741,7 @@ static int tun_set_iff(struct net *net, 
-                     cred->euid != tun->owner) ||
-                    (tun->group != -1 &&
-                     cred->egid != tun->group)) &&
--                  !capable(CAP_NET_ADMIN)) {
-+                   !cap_raised(current_cap(), CAP_NET_ADMIN)) {
-                       return -EPERM;
-               }
-       }
-@@ -747,7 +753,7 @@ static int tun_set_iff(struct net *net, 
+               err = tun_attach(tun, file);
+               if (err < 0)
+                       return err;
+@@ -887,7 +893,7 @@ static int tun_set_iff(struct net *net, 
  
                err = -EINVAL;
  
@@ -1736,7 +1724,7 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/net/tun.c linux-2.6.29.4-vs2.3.0.36
                        return -EPERM;
  
                /* Set dev type */
-@@ -987,6 +993,16 @@ static int tun_chr_ioctl(struct inode *i
+@@ -1150,6 +1156,16 @@ static int tun_chr_ioctl(struct inode *i
                DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
                break;
  
@@ -1753,9 +1741,9 @@ diff -NurpP --minimal linux-2.6.29.4/drivers/net/tun.c linux-2.6.29.4-vs2.3.0.36
        case TUNSETLINK:
                /* Only allow setting the type when the interface is down */
                rtnl_lock();
-diff -NurpP --minimal linux-2.6.29.4/fs/attr.c linux-2.6.29.4-vs2.3.0.36.14/fs/attr.c
---- linux-2.6.29.4/fs/attr.c   2009-03-24 14:22:24.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/attr.c     2009-03-24 14:48:34.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/attr.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/attr.c
+--- linux-2.6.30.1/fs/attr.c   2009-06-11 17:13:01.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/attr.c        2009-07-04 02:19:40.000000000 +0200
 @@ -14,6 +14,9 @@
  #include <linux/fcntl.h>
  #include <linux/quotaops.h>
@@ -1793,12 +1781,12 @@ diff -NurpP --minimal linux-2.6.29.4/fs/attr.c linux-2.6.29.4-vs2.3.0.36.14/fs/a
 -                          (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
 +                          (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
 +                          (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
-                               error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
+                               error = vfs_dq_transfer(inode, attr) ?
+                                       -EDQUOT : 0;
                        if (!error)
-                               error = inode_setattr(inode, attr);
-diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_aout.c linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_aout.c
---- linux-2.6.29.4/fs/binfmt_aout.c    2009-03-24 14:22:24.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_aout.c      2009-03-24 14:48:34.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/binfmt_aout.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/binfmt_aout.c
+--- linux-2.6.30.1/fs/binfmt_aout.c    2009-03-24 14:22:24.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/binfmt_aout.c 2009-07-04 01:11:39.000000000 +0200
 @@ -24,6 +24,7 @@
  #include <linux/binfmts.h>
  #include <linux/personality.h>
@@ -1807,10 +1795,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_aout.c linux-2.6.29.4-vs2.3.0.36.
  
  #include <asm/system.h>
  #include <asm/uaccess.h>
-diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_elf.c linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_elf.c
---- linux-2.6.29.4/fs/binfmt_elf.c     2009-03-24 14:22:24.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_elf.c       2009-03-24 14:48:34.000000000 +0100
-@@ -38,6 +38,7 @@
+diff -NurpP --minimal linux-2.6.30.1/fs/binfmt_elf.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/binfmt_elf.c
+--- linux-2.6.30.1/fs/binfmt_elf.c     2009-06-11 17:13:02.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/binfmt_elf.c  2009-07-04 01:11:39.000000000 +0200
+@@ -31,6 +31,7 @@
  #include <linux/random.h>
  #include <linux/elf.h>
  #include <linux/utsname.h>
@@ -1818,9 +1806,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_elf.c linux-2.6.29.4-vs2.3.0.36.1
  #include <asm/uaccess.h>
  #include <asm/param.h>
  #include <asm/page.h>
-diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_flat.c linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_flat.c
---- linux-2.6.29.4/fs/binfmt_flat.c    2009-03-24 14:22:24.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_flat.c      2009-03-24 14:48:34.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/binfmt_flat.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/binfmt_flat.c
+--- linux-2.6.30.1/fs/binfmt_flat.c    2009-06-11 17:13:02.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/binfmt_flat.c 2009-07-04 01:11:39.000000000 +0200
 @@ -35,6 +35,7 @@
  #include <linux/init.h>
  #include <linux/flat.h>
@@ -1829,9 +1817,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_flat.c linux-2.6.29.4-vs2.3.0.36.
  
  #include <asm/byteorder.h>
  #include <asm/system.h>
-diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_som.c linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_som.c
---- linux-2.6.29.4/fs/binfmt_som.c     2009-03-24 14:22:24.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_som.c       2009-03-24 14:48:34.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/binfmt_som.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/binfmt_som.c
+--- linux-2.6.30.1/fs/binfmt_som.c     2009-06-11 17:13:02.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/binfmt_som.c  2009-07-04 01:11:39.000000000 +0200
 @@ -28,6 +28,7 @@
  #include <linux/shm.h>
  #include <linux/personality.h>
@@ -1840,10 +1828,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_som.c linux-2.6.29.4-vs2.3.0.36.1
  
  #include <asm/uaccess.h>
  #include <asm/pgtable.h>
-diff -NurpP --minimal linux-2.6.29.4/fs/block_dev.c linux-2.6.29.4-vs2.3.0.36.14/fs/block_dev.c
---- linux-2.6.29.4/fs/block_dev.c      2009-03-24 14:22:24.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/block_dev.c        2009-03-24 14:48:34.000000000 +0100
-@@ -24,6 +24,7 @@
+diff -NurpP --minimal linux-2.6.30.1/fs/block_dev.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/block_dev.c
+--- linux-2.6.30.1/fs/block_dev.c      2009-06-11 17:13:02.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/block_dev.c   2009-07-04 01:11:39.000000000 +0200
+@@ -25,6 +25,7 @@
  #include <linux/uio.h>
  #include <linux/namei.h>
  #include <linux/log2.h>
@@ -1851,7 +1839,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/block_dev.c linux-2.6.29.4-vs2.3.0.36.14
  #include <asm/uaccess.h>
  #include "internal.h"
  
-@@ -392,6 +393,7 @@ struct block_device *bdget(dev_t dev)
+@@ -539,6 +540,7 @@ struct block_device *bdget(dev_t dev)
                bdev->bd_invalidated = 0;
                inode->i_mode = S_IFBLK;
                inode->i_rdev = dev;
@@ -1859,7 +1847,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/block_dev.c linux-2.6.29.4-vs2.3.0.36.14
                inode->i_bdev = bdev;
                inode->i_data.a_ops = &def_blk_aops;
                mapping_set_gfp_mask(&inode->i_data, GFP_USER);
-@@ -428,6 +430,11 @@ EXPORT_SYMBOL(bdput);
+@@ -575,6 +577,11 @@ EXPORT_SYMBOL(bdput);
  static struct block_device *bd_acquire(struct inode *inode)
  {
        struct block_device *bdev;
@@ -1871,7 +1859,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/block_dev.c linux-2.6.29.4-vs2.3.0.36.14
  
        spin_lock(&bdev_lock);
        bdev = inode->i_bdev;
-@@ -438,7 +445,7 @@ static struct block_device *bd_acquire(s
+@@ -585,7 +592,7 @@ static struct block_device *bd_acquire(s
        }
        spin_unlock(&bdev_lock);
  
@@ -1880,9 +1868,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/block_dev.c linux-2.6.29.4-vs2.3.0.36.14
        if (bdev) {
                spin_lock(&bdev_lock);
                if (!inode->i_bdev) {
-diff -NurpP --minimal linux-2.6.29.4/fs/char_dev.c linux-2.6.29.4-vs2.3.0.36.14/fs/char_dev.c
---- linux-2.6.29.4/fs/char_dev.c       2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/char_dev.c 2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/char_dev.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/char_dev.c
+--- linux-2.6.30.1/fs/char_dev.c       2009-03-24 14:22:25.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/char_dev.c    2009-07-04 01:11:39.000000000 +0200
 @@ -21,6 +21,8 @@
  #include <linux/cdev.h>
  #include <linux/mutex.h>
@@ -1915,13 +1903,13 @@ diff -NurpP --minimal linux-2.6.29.4/fs/char_dev.c linux-2.6.29.4-vs2.3.0.36.14/
                if (!kobj)
                        return -ENXIO;
                new = container_of(kobj, struct cdev, kobj);
-diff -NurpP --minimal linux-2.6.29.4/fs/dcache.c linux-2.6.29.4-vs2.3.0.36.14/fs/dcache.c
---- linux-2.6.29.4/fs/dcache.c 2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/dcache.c   2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/dcache.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/dcache.c
+--- linux-2.6.30.1/fs/dcache.c 2009-06-11 17:13:02.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/dcache.c      2009-07-04 02:18:36.000000000 +0200
 @@ -32,6 +32,7 @@
- #include <linux/seqlock.h>
  #include <linux/swap.h>
  #include <linux/bootmem.h>
+ #include <linux/fs_struct.h>
 +#include <linux/vs_limit.h>
  #include "internal.h"
  
@@ -1961,7 +1949,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/dcache.c linux-2.6.29.4-vs2.3.0.36.14/fs
        spin_unlock(&dcache_lock);
  
        return dentry;
-@@ -1418,6 +1426,7 @@ struct dentry * __d_lookup(struct dentry
+@@ -1406,6 +1414,7 @@ struct dentry * __d_lookup(struct dentry
                }
  
                atomic_inc(&dentry->d_count);
@@ -1969,9 +1957,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/dcache.c linux-2.6.29.4-vs2.3.0.36.14/fs
                found = dentry;
                spin_unlock(&dentry->d_lock);
                break;
-diff -NurpP --minimal linux-2.6.29.4/fs/devpts/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/devpts/inode.c
---- linux-2.6.29.4/fs/devpts/inode.c   2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/devpts/inode.c     2009-03-24 15:32:47.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/devpts/inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/devpts/inode.c
+--- linux-2.6.30.1/fs/devpts/inode.c   2009-06-11 17:13:02.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/devpts/inode.c        2009-07-04 01:11:39.000000000 +0200
 @@ -19,12 +19,12 @@
  #include <linux/tty.h>
  #include <linux/mutex.h>
@@ -2008,7 +1996,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/devpts/inode.c linux-2.6.29.4-vs2.3.0.36
  extern int pty_limit;                 /* Config limit on Unix98 ptys */
  static DEFINE_MUTEX(allocated_ptys_lock);
  
-@@ -254,6 +268,25 @@ static int devpts_show_options(struct se
+@@ -263,6 +277,25 @@ static int devpts_show_options(struct se
        return 0;
  }
  
@@ -2034,7 +2022,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/devpts/inode.c linux-2.6.29.4-vs2.3.0.36
  static const struct super_operations devpts_sops = {
        .statfs         = simple_statfs,
        .remount_fs     = devpts_remount,
-@@ -293,12 +326,15 @@ devpts_fill_super(struct super_block *s,
+@@ -302,12 +335,15 @@ devpts_fill_super(struct super_block *s,
        inode = new_inode(s);
        if (!inode)
                goto free_fsi;
@@ -2051,15 +2039,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/devpts/inode.c linux-2.6.29.4-vs2.3.0.36
  
        s->s_root = d_alloc_root(inode);
        if (s->s_root)
-@@ -479,6 +515,7 @@ static int init_pts_mount(struct file_sy
-       return err;
- }
-+
- static int devpts_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *data, struct vfsmount *mnt)
- {
-@@ -590,6 +627,9 @@ int devpts_pty_new(struct inode *ptmx_in
+@@ -499,6 +535,9 @@ int devpts_pty_new(struct inode *ptmx_in
        inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
        inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
        init_special_inode(inode, S_IFCHR|opts->mode, device);
@@ -2069,10 +2049,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/devpts/inode.c linux-2.6.29.4-vs2.3.0.36
        inode->i_private = tty;
        tty->driver_data = inode;
  
-diff -NurpP --minimal linux-2.6.29.4/fs/exec.c linux-2.6.29.4-vs2.3.0.36.14/fs/exec.c
---- linux-2.6.29.4/fs/exec.c   2009-05-23 23:16:52.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/exec.c     2009-05-10 23:42:01.000000000 +0200
-@@ -257,7 +257,9 @@ static int __bprm_mm_init(struct linux_b
+diff -NurpP --minimal linux-2.6.30.1/fs/exec.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/exec.c
+--- linux-2.6.30.1/fs/exec.c   2009-06-11 17:13:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/exec.c        2009-07-04 01:11:39.000000000 +0200
+@@ -248,7 +248,9 @@ static int __bprm_mm_init(struct linux_b
        if (err)
                goto err;
  
@@ -2083,7 +2063,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/exec.c linux-2.6.29.4-vs2.3.0.36.14/fs/e
        up_write(&mm->mmap_sem);
        bprm->p = vma->vm_end - sizeof(void *);
        return 0;
-@@ -1463,7 +1465,7 @@ static int format_corename(char *corenam
+@@ -1449,7 +1451,7 @@ static int format_corename(char *corenam
                        /* UNIX time of coredump */
                        case 't': {
                                struct timeval tv;
@@ -2092,27 +2072,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/exec.c linux-2.6.29.4-vs2.3.0.36.14/fs/e
                                rc = snprintf(out_ptr, out_end - out_ptr,
                                              "%lu", tv.tv_sec);
                                if (rc > out_end - out_ptr)
-diff -NurpP --minimal linux-2.6.29.4/fs/ext2/balloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/balloc.c
---- linux-2.6.29.4/fs/ext2/balloc.c    2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/balloc.c      2009-03-24 14:48:35.000000000 +0100
-@@ -16,6 +16,8 @@
- #include <linux/sched.h>
- #include <linux/buffer_head.h>
- #include <linux/capability.h>
-+#include <linux/vs_dlimit.h>
-+#include <linux/vs_tag.h>
- /*
-  * balloc.c contains the blocks allocation and deallocation routines
-@@ -569,6 +571,7 @@ do_more:
-       }
- error_return:
-       brelse(bitmap_bh);
-+      DLIMIT_FREE_BLOCK(inode, freed);
-       release_blocks(sb, freed);
-       DQUOT_FREE_BLOCK(inode, freed);
- }
-@@ -701,7 +704,6 @@ ext2_try_to_allocate(struct super_block 
+diff -NurpP --minimal linux-2.6.30.1/fs/ext2/balloc.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/balloc.c
+--- linux-2.6.30.1/fs/ext2/balloc.c    2009-06-11 17:13:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/balloc.c 2009-07-04 01:11:38.000000000 +0200
+@@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
                        start = 0;
                end = EXT2_BLOCKS_PER_GROUP(sb);
        }
@@ -2120,41 +2083,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/balloc.c linux-2.6.29.4-vs2.3.0.36.
        BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
  
  repeat:
-@@ -1251,6 +1253,11 @@ ext2_fsblk_t ext2_new_blocks(struct inod
-               *errp = -EDQUOT;
-               return 0;
-       }
-+      if (DLIMIT_ALLOC_BLOCK(inode, num)) {
-+              *errp = -ENOSPC;
-+              DQUOT_FREE_BLOCK(inode, num);
-+              return 0;
-+      }
-       sbi = EXT2_SB(sb);
-       es = EXT2_SB(sb)->s_es;
-@@ -1409,6 +1416,7 @@ allocated:
-       *errp = 0;
-       brelse(bitmap_bh);
-+      DLIMIT_FREE_BLOCK(inode, *count-num);
-       DQUOT_FREE_BLOCK(inode, *count-num);
-       *count = num;
-       return ret_block;
-@@ -1419,8 +1427,10 @@ out:
-       /*
-        * Undo the block allocation
-        */
--      if (!performed_allocation)
-+      if (!performed_allocation) {
-+              DLIMIT_FREE_BLOCK(inode, *count);
-               DQUOT_FREE_BLOCK(inode, *count);
-+      }
-       brelse(bitmap_bh);
-       return 0;
- }
-diff -NurpP --minimal linux-2.6.29.4/fs/ext2/ext2.h linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ext2.h
---- linux-2.6.29.4/fs/ext2/ext2.h      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ext2.h        2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext2/ext2.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/ext2.h
+--- linux-2.6.30.1/fs/ext2/ext2.h      2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/ext2.h   2009-07-04 01:11:39.000000000 +0200
 @@ -170,6 +170,7 @@ extern const struct file_operations ext2
  extern const struct address_space_operations ext2_aops;
  extern const struct address_space_operations ext2_aops_xip;
@@ -2163,67 +2094,18 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/ext2.h linux-2.6.29.4-vs2.3.0.36.14
  
  /* namei.c */
  extern const struct inode_operations ext2_dir_inode_operations;
-diff -NurpP --minimal linux-2.6.29.4/fs/ext2/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/file.c
---- linux-2.6.29.4/fs/ext2/file.c      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/file.c        2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext2/file.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/file.c
+--- linux-2.6.30.1/fs/ext2/file.c      2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/file.c   2009-07-04 01:11:39.000000000 +0200
 @@ -87,4 +87,5 @@ const struct inode_operations ext2_file_
        .setattr        = ext2_setattr,
        .permission     = ext2_permission,
        .fiemap         = ext2_fiemap,
 +      .sync_flags     = ext2_sync_flags,
  };
-diff -NurpP --minimal linux-2.6.29.4/fs/ext2/ialloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ialloc.c
---- linux-2.6.29.4/fs/ext2/ialloc.c    2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ialloc.c      2009-03-24 15:36:12.000000000 +0100
-@@ -17,6 +17,8 @@
- #include <linux/backing-dev.h>
- #include <linux/buffer_head.h>
- #include <linux/random.h>
-+#include <linux/vs_dlimit.h>
-+#include <linux/vs_tag.h>
- #include "ext2.h"
- #include "xattr.h"
- #include "acl.h"
-@@ -123,6 +125,7 @@ void ext2_free_inode (struct inode * ino
-               ext2_xattr_delete_inode(inode);
-               DQUOT_FREE_INODE(inode);
-               DQUOT_DROP(inode);
-+              DLIMIT_FREE_INODE(inode);
-       }
-       es = EXT2_SB(sb)->s_es;
-@@ -454,6 +457,11 @@ struct inode *ext2_new_inode(struct inod
-       if (!inode)
-               return ERR_PTR(-ENOMEM);
-+      inode->i_tag = dx_current_fstag(sb);
-+      if (DLIMIT_ALLOC_INODE(inode)) {
-+              err = -ENOSPC;
-+              goto fail_dlim;
-+      }
-       ei = EXT2_I(inode);
-       sbi = EXT2_SB(sb);
-       es = sbi->s_es;
-@@ -609,6 +617,7 @@ fail_free_drop:
- fail_drop:
-       DQUOT_DROP(inode);
-+      DLIMIT_FREE_INODE(inode);
-       inode->i_flags |= S_NOQUOTA;
-       inode->i_nlink = 0;
-       unlock_new_inode(inode);
-@@ -616,6 +625,8 @@ fail_drop:
-       return ERR_PTR(err);
- fail:
-+      DLIMIT_FREE_INODE(inode);
-+fail_dlim:
-       make_bad_inode(inode);
-       iput(inode);
-       return ERR_PTR(err);
-diff -NurpP --minimal linux-2.6.29.4/fs/ext2/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/inode.c
---- linux-2.6.29.4/fs/ext2/inode.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/inode.c       2009-03-24 15:41:38.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext2/inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/inode.c
+--- linux-2.6.30.1/fs/ext2/inode.c     2009-06-11 17:13:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/inode.c  2009-07-04 02:26:09.000000000 +0200
 @@ -33,6 +33,7 @@
  #include <linux/mpage.h>
  #include <linux/fiemap.h>
@@ -2232,7 +2114,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/inode.c linux-2.6.29.4-vs2.3.0.36.1
  #include "ext2.h"
  #include "acl.h"
  #include "xip.h"
-@@ -1018,7 +1019,7 @@ void ext2_truncate(struct inode *inode)
+@@ -1040,7 +1041,7 @@ void ext2_truncate(struct inode *inode)
                return;
        if (ext2_inode_is_fast_symlink(inode))
                return;
@@ -2241,7 +2123,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/inode.c linux-2.6.29.4-vs2.3.0.36.1
                return;
  
        blocksize = inode->i_sb->s_blocksize;
-@@ -1156,38 +1157,72 @@ void ext2_set_inode_flags(struct inode *
+@@ -1178,38 +1179,72 @@ void ext2_set_inode_flags(struct inode *
  {
        unsigned int flags = EXT2_I(inode)->i_flags;
  
@@ -2321,7 +2203,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/inode.c linux-2.6.29.4-vs2.3.0.36.1
  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
  {
        struct ext2_inode_info *ei;
-@@ -1195,6 +1230,8 @@ struct inode *ext2_iget (struct super_bl
+@@ -1217,6 +1252,8 @@ struct inode *ext2_iget (struct super_bl
        struct ext2_inode *raw_inode;
        struct inode *inode;
        long ret = -EIO;
@@ -2330,7 +2212,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/inode.c linux-2.6.29.4-vs2.3.0.36.1
        int n;
  
        inode = iget_locked(sb, ino);
-@@ -1217,12 +1254,17 @@ struct inode *ext2_iget (struct super_bl
+@@ -1239,12 +1276,17 @@ struct inode *ext2_iget (struct super_bl
        }
  
        inode->i_mode = le16_to_cpu(raw_inode->i_mode);
@@ -2352,7 +2234,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/inode.c linux-2.6.29.4-vs2.3.0.36.1
        inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
        inode->i_size = le32_to_cpu(raw_inode->i_size);
        inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
-@@ -1320,8 +1362,8 @@ static int ext2_update_inode(struct inod
+@@ -1342,8 +1384,8 @@ static int ext2_update_inode(struct inod
        struct ext2_inode_info *ei = EXT2_I(inode);
        struct super_block *sb = inode->i_sb;
        ino_t ino = inode->i_ino;
@@ -2363,7 +2245,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/inode.c linux-2.6.29.4-vs2.3.0.36.1
        struct buffer_head * bh;
        struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
        int n;
-@@ -1357,6 +1399,9 @@ static int ext2_update_inode(struct inod
+@@ -1379,6 +1421,9 @@ static int ext2_update_inode(struct inod
                raw_inode->i_uid_high = 0;
                raw_inode->i_gid_high = 0;
        }
@@ -2373,19 +2255,19 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/inode.c linux-2.6.29.4-vs2.3.0.36.1
        raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
        raw_inode->i_size = cpu_to_le32(inode->i_size);
        raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
-@@ -1443,7 +1488,8 @@ int ext2_setattr(struct dentry *dentry, 
+@@ -1465,7 +1510,8 @@ int ext2_setattr(struct dentry *dentry, 
        if (error)
                return error;
        if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
 -          (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
 +          (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
 +          (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
-               error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
+               error = vfs_dq_transfer(inode, iattr) ? -EDQUOT : 0;
                if (error)
                        return error;
-diff -NurpP --minimal linux-2.6.29.4/fs/ext2/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ioctl.c
---- linux-2.6.29.4/fs/ext2/ioctl.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ioctl.c       2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext2/ioctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/ioctl.c
+--- linux-2.6.30.1/fs/ext2/ioctl.c     2009-03-24 14:22:25.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/ioctl.c  2009-07-04 01:11:39.000000000 +0200
 @@ -14,6 +14,7 @@
  #include <linux/compat.h>
  #include <linux/mount.h>
@@ -2417,9 +2299,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/ioctl.c linux-2.6.29.4-vs2.3.0.36.1
                        if (!capable(CAP_LINUX_IMMUTABLE)) {
                                mutex_unlock(&inode->i_mutex);
                                ret = -EPERM;
-diff -NurpP --minimal linux-2.6.29.4/fs/ext2/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/namei.c
---- linux-2.6.29.4/fs/ext2/namei.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/namei.c       2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext2/namei.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/namei.c
+--- linux-2.6.30.1/fs/ext2/namei.c     2009-03-24 14:22:25.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/namei.c  2009-07-04 01:11:39.000000000 +0200
 @@ -31,6 +31,7 @@
   */
  
@@ -2450,9 +2332,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/namei.c linux-2.6.29.4-vs2.3.0.36.1
        .permission     = ext2_permission,
 +      .sync_flags     = ext2_sync_flags,
  };
-diff -NurpP --minimal linux-2.6.29.4/fs/ext2/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/super.c
---- linux-2.6.29.4/fs/ext2/super.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/super.c       2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext2/super.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/super.c
+--- linux-2.6.30.1/fs/ext2/super.c     2009-06-11 17:13:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/super.c  2009-07-04 01:11:39.000000000 +0200
 @@ -391,7 +391,8 @@ enum {
        Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
        Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
@@ -2517,9 +2399,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/super.c linux-2.6.29.4-vs2.3.0.36.1
        sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
                ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  
-diff -NurpP --minimal linux-2.6.29.4/fs/ext2/symlink.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/symlink.c
---- linux-2.6.29.4/fs/ext2/symlink.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/symlink.c     2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext2/symlink.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/symlink.c
+--- linux-2.6.30.1/fs/ext2/symlink.c   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext2/symlink.c        2009-07-04 01:11:39.000000000 +0200
 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
        .listxattr      = ext2_listxattr,
        .removexattr    = generic_removexattr,
@@ -2534,218 +2416,19 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext2/symlink.c linux-2.6.29.4-vs2.3.0.36
  #endif
 +      .sync_flags     = ext2_sync_flags,
  };
-diff -NurpP --minimal linux-2.6.29.4/fs/ext2/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/xattr.c
---- linux-2.6.29.4/fs/ext2/xattr.c     2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/xattr.c       2009-02-22 22:54:25.000000000 +0100
-@@ -60,6 +60,7 @@
- #include <linux/mbcache.h>
- #include <linux/quotaops.h>
- #include <linux/rwsem.h>
-+#include <linux/vs_dlimit.h>
- #include "ext2.h"
- #include "xattr.h"
- #include "acl.h"
-@@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
-                                  the inode.  */
-                               ea_bdebug(new_bh, "reusing block");
-+                              error = -ENOSPC;
-+                              if (DLIMIT_ALLOC_BLOCK(inode, 1))
-+                                      goto cleanup;
-                               error = -EDQUOT;
-                               if (DQUOT_ALLOC_BLOCK(inode, 1)) {
-+                                      DLIMIT_FREE_BLOCK(inode, 1);
-                                       unlock_buffer(new_bh);
-                                       goto cleanup;
-                               }
-@@ -731,6 +736,7 @@ ext2_xattr_set2(struct inode *inode, str
-                       le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
-                       if (ce)
-                               mb_cache_entry_release(ce);
-+                      DLIMIT_FREE_BLOCK(inode, 1);
-                       DQUOT_FREE_BLOCK(inode, 1);
-                       mark_buffer_dirty(old_bh);
-                       ea_bdebug(old_bh, "refcount now=%d",
-@@ -794,6 +800,7 @@ ext2_xattr_delete_inode(struct inode *in
-               mark_buffer_dirty(bh);
-               if (IS_SYNC(inode))
-                       sync_dirty_buffer(bh);
-+              DLIMIT_FREE_BLOCK(inode, 1);
-               DQUOT_FREE_BLOCK(inode, 1);
-       }
-       EXT2_I(inode)->i_file_acl = 0;
-diff -NurpP --minimal linux-2.6.29.4/fs/ext3/balloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/balloc.c
---- linux-2.6.29.4/fs/ext3/balloc.c    2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/balloc.c      2009-03-25 00:53:20.000000000 +0100
-@@ -19,6 +19,8 @@
- #include <linux/ext3_jbd.h>
- #include <linux/quotaops.h>
- #include <linux/buffer_head.h>
-+#include <linux/vs_dlimit.h>
-+#include <linux/vs_tag.h>
- /*
-  * balloc.c contains the blocks allocation and deallocation routines
-@@ -675,8 +677,10 @@ void ext3_free_blocks(handle_t *handle, 
-               return;
-       }
-       ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
--      if (dquot_freed_blocks)
-+      if (dquot_freed_blocks) {
-+              DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
-               DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
-+      }
-       return;
- }
-@@ -1415,18 +1419,33 @@ out:
-  *
-  * Check if filesystem has at least 1 free block available for allocation.
-  */
--static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
-+static int ext3_has_free_blocks(struct super_block *sb)
- {
--      ext3_fsblk_t free_blocks, root_blocks;
-+      struct ext3_sb_info *sbi = EXT3_SB(sb);
-+      unsigned long long free_blocks, root_blocks;
-+      int cond;
-       free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
-       root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
--      if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
-+
-+      vxdprintk(VXD_CBIT(dlim, 3),
-+              "ext3_has_free_blocks(%p): free=%llu, root=%llu",
-+              sb, free_blocks, root_blocks);
-+
-+      DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
-+
-+      cond = (free_blocks < root_blocks + 1 &&
-+              !capable(CAP_SYS_RESOURCE) &&
-               sbi->s_resuid != current_fsuid() &&
--              (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
--              return 0;
--      }
--      return 1;
-+              (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
-+
-+      vxdprintk(VXD_CBIT(dlim, 3),
-+              "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
-+              sb, free_blocks, root_blocks,
-+              !capable(CAP_SYS_RESOURCE)?'1':'0',
-+              sbi->s_resuid, current_fsuid(), cond?0:1);
-+
-+      return (cond ? 0 : 1);
- }
- /**
-@@ -1443,7 +1462,7 @@ static int ext3_has_free_blocks(struct e
-  */
- int ext3_should_retry_alloc(struct super_block *sb, int *retries)
- {
--      if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
-+      if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
-               return 0;
-       jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
-@@ -1506,6 +1525,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
-               *errp = -EDQUOT;
-               return 0;
-       }
-+      if (DLIMIT_ALLOC_BLOCK(inode, num))
-+          goto out_dlimit;
-       sbi = EXT3_SB(sb);
-       es = EXT3_SB(sb)->s_es;
-@@ -1522,7 +1543,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
-       if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
-               my_rsv = &block_i->rsv_window_node;
--      if (!ext3_has_free_blocks(sbi)) {
-+      if (!ext3_has_free_blocks(sb)) {
-               *errp = -ENOSPC;
-               goto out;
-       }
-@@ -1715,12 +1736,16 @@ allocated:
-       *errp = 0;
-       brelse(bitmap_bh);
-       DQUOT_FREE_BLOCK(inode, *count-num);
-+      DLIMIT_FREE_BLOCK(inode, *count-num);
-       *count = num;
-       return ret_block;
- io_error:
-       *errp = -EIO;
- out:
-+      if (!performed_allocation)
-+              DLIMIT_FREE_BLOCK(inode, *count);
-+out_dlimit:
-       if (fatal) {
-               *errp = fatal;
-               ext3_std_error(sb, fatal);
-diff -NurpP --minimal linux-2.6.29.4/fs/ext3/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/file.c
---- linux-2.6.29.4/fs/ext3/file.c      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/file.c        2009-02-22 22:54:25.000000000 +0100
-@@ -135,5 +135,6 @@ const struct inode_operations ext3_file_
+diff -NurpP --minimal linux-2.6.30.1/fs/ext3/file.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/file.c
+--- linux-2.6.30.1/fs/ext3/file.c      2009-06-11 17:13:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/file.c   2009-07-04 01:11:39.000000000 +0200
+@@ -139,5 +139,6 @@ const struct inode_operations ext3_file_
  #endif
        .permission     = ext3_permission,
        .fiemap         = ext3_fiemap,
 +      .sync_flags     = ext3_sync_flags,
  };
  
-diff -NurpP --minimal linux-2.6.29.4/fs/ext3/ialloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/ialloc.c
---- linux-2.6.29.4/fs/ext3/ialloc.c    2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/ialloc.c      2009-03-24 15:44:06.000000000 +0100
-@@ -23,6 +23,8 @@
- #include <linux/buffer_head.h>
- #include <linux/random.h>
- #include <linux/bitops.h>
-+#include <linux/vs_dlimit.h>
-+#include <linux/vs_tag.h>
- #include <asm/byteorder.h>
-@@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
-       ext3_xattr_delete_inode(handle, inode);
-       DQUOT_FREE_INODE(inode);
-       DQUOT_DROP(inode);
-+      DLIMIT_FREE_INODE(inode);
-       is_directory = S_ISDIR(inode->i_mode);
-@@ -440,6 +443,12 @@ struct inode *ext3_new_inode(handle_t *h
-       inode = new_inode(sb);
-       if (!inode)
-               return ERR_PTR(-ENOMEM);
-+
-+      inode->i_tag = dx_current_fstag(sb);
-+      if (DLIMIT_ALLOC_INODE(inode)) {
-+              err = -ENOSPC;
-+              goto out_dlimit;
-+      }
-       ei = EXT3_I(inode);
-       sbi = EXT3_SB(sb);
-@@ -613,6 +622,8 @@ got:
- fail:
-       ext3_std_error(sb, err);
- out:
-+      DLIMIT_FREE_INODE(inode);
-+out_dlimit:
-       iput(inode);
-       ret = ERR_PTR(err);
- really_out:
-@@ -624,6 +635,7 @@ fail_free_drop:
- fail_drop:
-       DQUOT_DROP(inode);
-+      DLIMIT_FREE_INODE(inode);
-       inode->i_flags |= S_NOQUOTA;
-       inode->i_nlink = 0;
-       unlock_new_inode(inode);
-diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/inode.c
---- linux-2.6.29.4/fs/ext3/inode.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/inode.c       2009-03-24 15:44:29.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext3/inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/inode.c
+--- linux-2.6.30.1/fs/ext3/inode.c     2009-06-11 17:13:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/inode.c  2009-07-04 01:11:39.000000000 +0200
 @@ -38,6 +38,7 @@
  #include <linux/bio.h>
  #include <linux/fiemap.h>
@@ -2754,7 +2437,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.1
  #include "xattr.h"
  #include "acl.h"
  
-@@ -2288,7 +2289,7 @@ static void ext3_free_branches(handle_t 
+@@ -2318,7 +2319,7 @@ static void ext3_free_branches(handle_t 
  
  int ext3_can_truncate(struct inode *inode)
  {
@@ -2763,7 +2446,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.1
                return 0;
        if (S_ISREG(inode->i_mode))
                return 1;
-@@ -2662,36 +2663,84 @@ void ext3_set_inode_flags(struct inode *
+@@ -2695,36 +2696,84 @@ void ext3_set_inode_flags(struct inode *
  {
        unsigned int flags = EXT3_I(inode)->i_flags;
  
@@ -2855,7 +2538,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.1
  }
  
  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
-@@ -2703,6 +2752,8 @@ struct inode *ext3_iget(struct super_blo
+@@ -2736,6 +2785,8 @@ struct inode *ext3_iget(struct super_blo
        struct inode *inode;
        long ret;
        int block;
@@ -2864,7 +2547,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.1
  
        inode = iget_locked(sb, ino);
        if (!inode)
-@@ -2723,12 +2774,17 @@ struct inode *ext3_iget(struct super_blo
+@@ -2756,12 +2807,17 @@ struct inode *ext3_iget(struct super_blo
        bh = iloc.bh;
        raw_inode = ext3_raw_inode(&iloc);
        inode->i_mode = le16_to_cpu(raw_inode->i_mode);
@@ -2886,7 +2569,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.1
        inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
        inode->i_size = le32_to_cpu(raw_inode->i_size);
        inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
-@@ -2859,6 +2915,8 @@ static int ext3_do_update_inode(handle_t
+@@ -2892,6 +2948,8 @@ static int ext3_do_update_inode(handle_t
        struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
        struct ext3_inode_info *ei = EXT3_I(inode);
        struct buffer_head *bh = iloc->bh;
@@ -2895,7 +2578,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.1
        int err = 0, rc, block;
  
        /* For fields not not tracking in the in-memory inode,
-@@ -2869,29 +2927,32 @@ static int ext3_do_update_inode(handle_t
+@@ -2902,29 +2960,32 @@ static int ext3_do_update_inode(handle_t
        ext3_get_inode_flags(ei);
        raw_inode->i_mode = cpu_to_le16(inode->i_mode);
        if(!(test_opt(inode->i_sb, NO_UID32))) {
@@ -2934,7 +2617,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.1
        raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
        raw_inode->i_size = cpu_to_le32(ei->i_disksize);
        raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
-@@ -3044,7 +3105,8 @@ int ext3_setattr(struct dentry *dentry, 
+@@ -3077,7 +3138,8 @@ int ext3_setattr(struct dentry *dentry, 
                return error;
  
        if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
@@ -2944,7 +2627,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.1
                handle_t *handle;
  
                /* (user+group)*(old+new) structure, inode write (sb,
-@@ -3066,6 +3128,8 @@ int ext3_setattr(struct dentry *dentry, 
+@@ -3099,6 +3161,8 @@ int ext3_setattr(struct dentry *dentry, 
                        inode->i_uid = attr->ia_uid;
                if (attr->ia_valid & ATTR_GID)
                        inode->i_gid = attr->ia_gid;
@@ -2953,9 +2636,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.1
                error = ext3_mark_inode_dirty(handle, inode);
                ext3_journal_stop(handle);
        }
-diff -NurpP --minimal linux-2.6.29.4/fs/ext3/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/ioctl.c
---- linux-2.6.29.4/fs/ext3/ioctl.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/ioctl.c       2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext3/ioctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/ioctl.c
+--- linux-2.6.30.1/fs/ext3/ioctl.c     2009-06-11 17:13:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/ioctl.c  2009-07-04 02:23:27.000000000 +0200
 @@ -8,6 +8,7 @@
   */
  
@@ -2964,15 +2647,15 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/ioctl.c linux-2.6.29.4-vs2.3.0.36.1
  #include <linux/jbd.h>
  #include <linux/capability.h>
  #include <linux/ext3_fs.h>
-@@ -16,6 +17,7 @@
+@@ -15,6 +16,7 @@
+ #include <linux/mount.h>
  #include <linux/time.h>
  #include <linux/compat.h>
- #include <linux/smp_lock.h>
 +#include <linux/vs_tag.h>
  #include <asm/uaccess.h>
  
- int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
-@@ -55,6 +57,11 @@ int ext3_ioctl (struct inode * inode, st
+ long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+@@ -50,6 +52,11 @@ long ext3_ioctl(struct file *filp, unsig
  
                flags = ext3_mask_flags(inode->i_mode, flags);
  
@@ -2982,9 +2665,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/ioctl.c linux-2.6.29.4-vs2.3.0.36.1
 +              }
 +
                mutex_lock(&inode->i_mutex);
                /* Is it quota file? Do not allow user to mess with it */
-               if (IS_NOQUOTA(inode)) {
-@@ -73,7 +80,9 @@ int ext3_ioctl (struct inode * inode, st
+@@ -68,7 +75,9 @@ long ext3_ioctl(struct file *filp, unsig
                 *
                 * This test looks nicer. Thanks to Pauline Middelink
                 */
@@ -2992,12 +2675,12 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/ioctl.c linux-2.6.29.4-vs2.3.0.36.1
 +              if ((oldflags & EXT3_IMMUTABLE_FL) ||
 +                      ((flags ^ oldflags) & (EXT3_APPEND_FL |
 +                      EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
-                       if (!capable(CAP_LINUX_IMMUTABLE)) {
-                               mutex_unlock(&inode->i_mutex);
-                               err = -EPERM;
-diff -NurpP --minimal linux-2.6.29.4/fs/ext3/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/namei.c
---- linux-2.6.29.4/fs/ext3/namei.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/namei.c       2009-03-24 14:48:35.000000000 +0100
+                       if (!capable(CAP_LINUX_IMMUTABLE))
+                               goto flags_out;
+               }
+diff -NurpP --minimal linux-2.6.30.1/fs/ext3/namei.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/namei.c
+--- linux-2.6.30.1/fs/ext3/namei.c     2009-06-11 17:13:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/namei.c  2009-07-04 01:11:39.000000000 +0200
 @@ -36,6 +36,7 @@
  #include <linux/quotaops.h>
  #include <linux/buffer_head.h>
@@ -3014,7 +2697,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/namei.c linux-2.6.29.4-vs2.3.0.36.1
                }
                if ((bh = bh_use[ra_ptr++]) == NULL)
                        goto next;
-@@ -2433,6 +2435,7 @@ const struct inode_operations ext3_dir_i
+@@ -2446,6 +2448,7 @@ const struct inode_operations ext3_dir_i
        .removexattr    = generic_removexattr,
  #endif
        .permission     = ext3_permission,
@@ -3022,16 +2705,16 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/namei.c linux-2.6.29.4-vs2.3.0.36.1
  };
  
  const struct inode_operations ext3_special_inode_operations = {
-@@ -2444,4 +2447,5 @@ const struct inode_operations ext3_speci
+@@ -2457,4 +2460,5 @@ const struct inode_operations ext3_speci
        .removexattr    = generic_removexattr,
  #endif
        .permission     = ext3_permission,
 +      .sync_flags     = ext3_sync_flags,
  };
-diff -NurpP --minimal linux-2.6.29.4/fs/ext3/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/super.c
---- linux-2.6.29.4/fs/ext3/super.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/super.c       2009-03-24 14:48:35.000000000 +0100
-@@ -790,7 +790,7 @@ enum {
+diff -NurpP --minimal linux-2.6.30.1/fs/ext3/super.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/super.c
+--- linux-2.6.30.1/fs/ext3/super.c     2009-06-11 17:13:03.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/super.c  2009-07-04 01:11:39.000000000 +0200
+@@ -794,7 +794,7 @@ enum {
        Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
        Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
        Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
@@ -3040,7 +2723,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/super.c linux-2.6.29.4-vs2.3.0.36.1
  };
  
  static const match_table_t tokens = {
-@@ -843,6 +843,9 @@ static const match_table_t tokens = {
+@@ -847,6 +847,9 @@ static const match_table_t tokens = {
        {Opt_usrquota, "usrquota"},
        {Opt_barrier, "barrier=%u"},
        {Opt_resize, "resize"},
@@ -3050,7 +2733,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/super.c linux-2.6.29.4-vs2.3.0.36.1
        {Opt_err, NULL},
  };
  
-@@ -935,6 +938,20 @@ static int parse_options (char *options,
+@@ -939,6 +942,20 @@ static int parse_options (char *options,
                case Opt_nouid32:
                        set_opt (sbi->s_mount_opt, NO_UID32);
                        break;
@@ -3071,7 +2754,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/super.c linux-2.6.29.4-vs2.3.0.36.1
                case Opt_nocheck:
                        clear_opt (sbi->s_mount_opt, CHECK);
                        break;
-@@ -1653,6 +1670,9 @@ static int ext3_fill_super (struct super
+@@ -1657,6 +1674,9 @@ static int ext3_fill_super (struct super
                            NULL, 0))
                goto failed_mount;
  
@@ -3081,7 +2764,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/super.c linux-2.6.29.4-vs2.3.0.36.1
        sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
                ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  
-@@ -2527,6 +2547,13 @@ static int ext3_remount (struct super_bl
+@@ -2531,6 +2551,13 @@ static int ext3_remount (struct super_bl
        if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
                ext3_abort(sb, __func__, "Abort forced by user");
  
@@ -3095,9 +2778,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/super.c linux-2.6.29.4-vs2.3.0.36.1
        sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
                ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  
-diff -NurpP --minimal linux-2.6.29.4/fs/ext3/symlink.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/symlink.c
---- linux-2.6.29.4/fs/ext3/symlink.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/symlink.c     2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext3/symlink.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/symlink.c
+--- linux-2.6.30.1/fs/ext3/symlink.c   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext3/symlink.c        2009-07-04 01:11:39.000000000 +0200
 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
        .listxattr      = ext3_listxattr,
        .removexattr    = generic_removexattr,
@@ -3112,78 +2795,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext3/symlink.c linux-2.6.29.4-vs2.3.0.36
  #endif
 +      .sync_flags     = ext3_sync_flags,
  };
-diff -NurpP --minimal linux-2.6.29.4/fs/ext3/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/xattr.c
---- linux-2.6.29.4/fs/ext3/xattr.c     2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/xattr.c       2009-02-22 22:54:25.000000000 +0100
-@@ -58,6 +58,7 @@
- #include <linux/mbcache.h>
- #include <linux/quotaops.h>
- #include <linux/rwsem.h>
-+#include <linux/vs_dlimit.h>
- #include "xattr.h"
- #include "acl.h"
-@@ -498,6 +499,7 @@ ext3_xattr_release_block(handle_t *handl
-               error = ext3_journal_dirty_metadata(handle, bh);
-               if (IS_SYNC(inode))
-                       handle->h_sync = 1;
-+                      DLIMIT_FREE_BLOCK(inode, 1);
-               DQUOT_FREE_BLOCK(inode, 1);
-               ea_bdebug(bh, "refcount now=%d; releasing",
-                         le32_to_cpu(BHDR(bh)->h_refcount));
-@@ -771,11 +773,14 @@ inserted:
-                       if (new_bh == bs->bh)
-                               ea_bdebug(new_bh, "keeping");
-                       else {
-+                              error = -ENOSPC;
-+                              if (DLIMIT_ALLOC_BLOCK(inode, 1))
-+                                      goto cleanup;
-                               /* The old block is released after updating
-                                  the inode. */
-                               error = -EDQUOT;
-                               if (DQUOT_ALLOC_BLOCK(inode, 1))
--                                      goto cleanup;
-+                                      goto cleanup_dlimit;
-                               error = ext3_journal_get_write_access(handle,
-                                                                     new_bh);
-                               if (error)
-@@ -849,6 +854,8 @@ cleanup:
- cleanup_dquot:
-       DQUOT_FREE_BLOCK(inode, 1);
-+cleanup_dlimit:
-+      DLIMIT_FREE_BLOCK(inode, 1);
-       goto cleanup;
- bad_block:
-diff -NurpP --minimal linux-2.6.29.4/fs/ext4/balloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/balloc.c
---- linux-2.6.29.4/fs/ext4/balloc.c    2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/balloc.c      2009-03-24 14:48:35.000000000 +0100
-@@ -17,6 +17,8 @@
- #include <linux/jbd2.h>
- #include <linux/quotaops.h>
- #include <linux/buffer_head.h>
-+#include <linux/vs_dlimit.h>
-+#include <linux/vs_tag.h>
- #include "ext4.h"
- #include "ext4_jbd2.h"
- #include "group.h"
-@@ -535,8 +537,10 @@ void ext4_free_blocks(handle_t *handle, 
-       ext4_mb_free_blocks(handle, inode, block, count,
-                           metadata, &dquot_freed_blocks);
--      if (dquot_freed_blocks)
-+      if (dquot_freed_blocks) {
-+              DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
-               DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
-+      }
-       return;
- }
-diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ext4.h linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ext4.h
---- linux-2.6.29.4/fs/ext4/ext4.h      2009-05-23 23:16:52.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ext4.h        2009-05-23 23:19:11.000000000 +0200
-@@ -243,8 +243,12 @@ struct flex_groups {
+diff -NurpP --minimal linux-2.6.30.1/fs/ext4/ext4.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/ext4.h
+--- linux-2.6.30.1/fs/ext4/ext4.h      2009-06-11 17:13:04.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/ext4.h   2009-07-04 15:54:50.000000000 +0200
+@@ -235,8 +235,12 @@ struct flex_groups {
  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
  #define EXT4_EXTENTS_FL                       0x00080000 /* Inode uses extents */
  #define EXT4_EXT_MIGRATE              0x00100000 /* Inode is migrating */
@@ -3196,15 +2811,15 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ext4.h linux-2.6.29.4-vs2.3.0.36.14
  #define EXT4_FL_USER_VISIBLE          0x000BDFFF /* User visible flags */
  #define EXT4_FL_USER_MODIFIABLE               0x000B80FF /* User modifiable flags */
  
-@@ -541,6 +545,7 @@ do {                                                                              \
+@@ -560,6 +564,7 @@ do {                                                                              \
  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
  #define EXT4_MOUNT_DELALLOC           0x8000000 /* Delalloc support */
  #define EXT4_MOUNT_DATA_ERR_ABORT     0x10000000 /* Abort on file data write */
-+#define EXT4_MOUNT_TAGGED             (1<<24) /* Enable Context Tags */
++#define EXT4_MOUNT_TAGGED             (1<<30) /* Enable Context Tags */
  
  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
  #ifndef _LINUX_EXT2_FS_H
-@@ -1076,6 +1081,7 @@ struct buffer_head *ext4_bread(handle_t 
+@@ -1068,6 +1073,7 @@ struct buffer_head *ext4_bread(handle_t 
                                                ext4_lblk_t, int, int *);
  int ext4_get_block(struct inode *inode, sector_t iblock,
                                struct buffer_head *bh_result, int create);
@@ -3212,79 +2827,19 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ext4.h linux-2.6.29.4-vs2.3.0.36.14
  
  extern struct inode *ext4_iget(struct super_block *, unsigned long);
  extern int  ext4_write_inode(struct inode *, int);
-diff -NurpP --minimal linux-2.6.29.4/fs/ext4/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/file.c
---- linux-2.6.29.4/fs/ext4/file.c      2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/file.c        2009-03-24 14:48:35.000000000 +0100
-@@ -171,5 +171,6 @@ const struct inode_operations ext4_file_
+diff -NurpP --minimal linux-2.6.30.1/fs/ext4/file.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/file.c
+--- linux-2.6.30.1/fs/ext4/file.c      2009-06-11 17:13:04.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/file.c   2009-07-04 01:11:39.000000000 +0200
+@@ -176,5 +176,6 @@ const struct inode_operations ext4_file_
        .permission     = ext4_permission,
        .fallocate      = ext4_fallocate,
        .fiemap         = ext4_fiemap,
 +      .sync_flags     = ext4_sync_flags,
  };
  
-diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ialloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ialloc.c
---- linux-2.6.29.4/fs/ext4/ialloc.c    2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ialloc.c      2009-03-24 14:48:35.000000000 +0100
-@@ -22,6 +22,8 @@
- #include <linux/random.h>
- #include <linux/bitops.h>
- #include <linux/blkdev.h>
-+#include <linux/vs_dlimit.h>
-+#include <linux/vs_tag.h>
- #include <asm/byteorder.h>
- #include "ext4.h"
- #include "ext4_jbd2.h"
-@@ -224,6 +226,7 @@ void ext4_free_inode(handle_t *handle, s
-       ext4_xattr_delete_inode(handle, inode);
-       DQUOT_FREE_INODE(inode);
-       DQUOT_DROP(inode);
-+      DLIMIT_FREE_INODE(inode);
-       is_directory = S_ISDIR(inode->i_mode);
-@@ -711,6 +714,12 @@ struct inode *ext4_new_inode(handle_t *h
-       inode = new_inode(sb);
-       if (!inode)
-               return ERR_PTR(-ENOMEM);
-+
-+      inode->i_tag = dx_current_fstag(sb);
-+      if (DLIMIT_ALLOC_INODE(inode)) {
-+              err = -ENOSPC;
-+              goto out_dlimit;
-+      }
-       ei = EXT4_I(inode);
-       sbi = EXT4_SB(sb);
-@@ -889,7 +898,8 @@ got:
-        * newly created directory and file only if -o extent mount option is
-        * specified
-        */
--      ei->i_flags = EXT4_I(dir)->i_flags & ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL);
-+      ei->i_flags = EXT4_I(dir)->i_flags &
-+              ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL|EXT4_IXUNLINK_FL|EXT4_BARRIER_FL);
-       if (S_ISLNK(mode))
-               ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
-       /* dirsync only applies to directories */
-@@ -949,6 +959,8 @@ got:
- fail:
-       ext4_std_error(sb, err);
- out:
-+      DLIMIT_FREE_INODE(inode);
-+out_dlimit:
-       iput(inode);
-       ret = ERR_PTR(err);
- really_out:
-@@ -960,6 +972,7 @@ fail_free_drop:
- fail_drop:
-       DQUOT_DROP(inode);
-+      DLIMIT_FREE_INODE(inode);
-       inode->i_flags |= S_NOQUOTA;
-       inode->i_nlink = 0;
-       unlock_new_inode(inode);
-diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/inode.c
---- linux-2.6.29.4/fs/ext4/inode.c     2009-05-23 23:16:52.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/inode.c       2009-05-23 23:19:11.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/fs/ext4/inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/inode.c
+--- linux-2.6.30.1/fs/ext4/inode.c     2009-06-11 17:13:04.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/inode.c  2009-07-04 01:11:39.000000000 +0200
 @@ -37,6 +37,7 @@
  #include <linux/namei.h>
  #include <linux/uio.h>
@@ -3293,7 +2848,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.1
  #include "ext4_jbd2.h"
  #include "xattr.h"
  #include "acl.h"
-@@ -3781,7 +3782,7 @@ static void ext4_free_branches(handle_t 
+@@ -3916,7 +3917,7 @@ static void ext4_free_branches(handle_t 
  
  int ext4_can_truncate(struct inode *inode)
  {
@@ -3302,7 +2857,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.1
                return 0;
        if (S_ISREG(inode->i_mode))
                return 1;
-@@ -4134,37 +4135,86 @@ void ext4_set_inode_flags(struct inode *
+@@ -4267,37 +4268,86 @@ void ext4_set_inode_flags(struct inode *
  {
        unsigned int flags = EXT4_I(inode)->i_flags;
  
@@ -3396,7 +2951,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.1
  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
                                        struct ext4_inode_info *ei)
  {
-@@ -4197,6 +4247,8 @@ struct inode *ext4_iget(struct super_blo
+@@ -4330,6 +4380,8 @@ struct inode *ext4_iget(struct super_blo
        struct inode *inode;
        long ret;
        int block;
@@ -3405,7 +2960,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.1
  
        inode = iget_locked(sb, ino);
        if (!inode)
-@@ -4216,12 +4268,16 @@ struct inode *ext4_iget(struct super_blo
+@@ -4349,12 +4401,16 @@ struct inode *ext4_iget(struct super_blo
        bh = iloc.bh;
        raw_inode = ext4_raw_inode(&iloc);
        inode->i_mode = le16_to_cpu(raw_inode->i_mode);
@@ -3426,7 +2981,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.1
        inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
  
        ei->i_state = 0;
-@@ -4387,6 +4443,8 @@ static int ext4_do_update_inode(handle_t
+@@ -4555,6 +4611,8 @@ static int ext4_do_update_inode(handle_t
        struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
        struct ext4_inode_info *ei = EXT4_I(inode);
        struct buffer_head *bh = iloc->bh;
@@ -3435,7 +2990,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.1
        int err = 0, rc, block;
  
        /* For fields not not tracking in the in-memory inode,
-@@ -4397,29 +4455,32 @@ static int ext4_do_update_inode(handle_t
+@@ -4565,29 +4623,32 @@ static int ext4_do_update_inode(handle_t
        ext4_get_inode_flags(ei);
        raw_inode->i_mode = cpu_to_le16(inode->i_mode);
        if (!(test_opt(inode->i_sb, NO_UID32))) {
@@ -3474,7 +3029,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.1
        raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
  
        EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
-@@ -4601,7 +4662,8 @@ int ext4_setattr(struct dentry *dentry, 
+@@ -4769,7 +4830,8 @@ int ext4_setattr(struct dentry *dentry, 
                return error;
  
        if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
@@ -3484,7 +3039,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.1
                handle_t *handle;
  
                /* (user+group)*(old+new) structure, inode write (sb,
-@@ -4623,6 +4685,8 @@ int ext4_setattr(struct dentry *dentry, 
+@@ -4791,6 +4853,8 @@ int ext4_setattr(struct dentry *dentry, 
                        inode->i_uid = attr->ia_uid;
                if (attr->ia_valid & ATTR_GID)
                        inode->i_gid = attr->ia_gid;
@@ -3493,9 +3048,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.1
                error = ext4_mark_inode_dirty(handle, inode);
                ext4_journal_stop(handle);
        }
-diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ioctl.c
---- linux-2.6.29.4/fs/ext4/ioctl.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ioctl.c       2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext4/ioctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/ioctl.c
+--- linux-2.6.30.1/fs/ext4/ioctl.c     2009-06-11 17:13:04.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/ioctl.c  2009-07-04 01:11:39.000000000 +0200
 @@ -8,12 +8,14 @@
   */
  
@@ -3511,9 +3066,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ioctl.c linux-2.6.29.4-vs2.3.0.36.1
  #include <asm/uaccess.h>
  #include "ext4_jbd2.h"
  #include "ext4.h"
-@@ -51,6 +53,11 @@ long ext4_ioctl(struct file *filp, unsig
-               if (!S_ISDIR(inode->i_mode))
-                       flags &= ~EXT4_DIRSYNC_FL;
+@@ -50,6 +52,11 @@ long ext4_ioctl(struct file *filp, unsig
+               flags = ext4_mask_flags(inode->i_mode, flags);
  
 +              if (IS_BARRIER(inode)) {
 +                      vxwprintk_task(1, "messing with the barrier.");
@@ -3523,7 +3078,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ioctl.c linux-2.6.29.4-vs2.3.0.36.1
                err = -EPERM;
                mutex_lock(&inode->i_mutex);
                /* Is it quota file? Do not allow user to mess with it */
-@@ -68,7 +75,9 @@ long ext4_ioctl(struct file *filp, unsig
+@@ -67,7 +74,9 @@ long ext4_ioctl(struct file *filp, unsig
                 *
                 * This test looks nicer. Thanks to Pauline Middelink
                 */
@@ -3534,9 +3089,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ioctl.c linux-2.6.29.4-vs2.3.0.36.1
                        if (!capable(CAP_LINUX_IMMUTABLE))
                                goto flags_out;
                }
-diff -NurpP --minimal linux-2.6.29.4/fs/ext4/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/namei.c
---- linux-2.6.29.4/fs/ext4/namei.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/namei.c       2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext4/namei.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/namei.c
+--- linux-2.6.30.1/fs/ext4/namei.c     2009-06-11 17:13:04.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/namei.c  2009-07-04 01:11:39.000000000 +0200
 @@ -34,6 +34,7 @@
  #include <linux/quotaops.h>
  #include <linux/buffer_head.h>
@@ -3545,7 +3100,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/namei.c linux-2.6.29.4-vs2.3.0.36.1
  #include "ext4.h"
  #include "ext4_jbd2.h"
  
-@@ -917,6 +918,7 @@ restart:
+@@ -942,6 +943,7 @@ restart:
                                if (bh)
                                        ll_rw_block(READ_META, 1, &bh);
                        }
@@ -3553,7 +3108,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/namei.c linux-2.6.29.4-vs2.3.0.36.1
                }
                if ((bh = bh_use[ra_ptr++]) == NULL)
                        goto next;
-@@ -2481,6 +2483,7 @@ const struct inode_operations ext4_dir_i
+@@ -2533,6 +2535,7 @@ const struct inode_operations ext4_dir_i
        .removexattr    = generic_removexattr,
  #endif
        .permission     = ext4_permission,
@@ -3561,18 +3116,18 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/namei.c linux-2.6.29.4-vs2.3.0.36.1
  };
  
  const struct inode_operations ext4_special_inode_operations = {
-@@ -2492,4 +2495,5 @@ const struct inode_operations ext4_speci
+@@ -2544,4 +2547,5 @@ const struct inode_operations ext4_speci
        .removexattr    = generic_removexattr,
  #endif
        .permission     = ext4_permission,
 +      .sync_flags     = ext4_sync_flags,
  };
-diff -NurpP --minimal linux-2.6.29.4/fs/ext4/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/super.c
---- linux-2.6.29.4/fs/ext4/super.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/super.c       2009-03-24 15:46:48.000000000 +0100
-@@ -1013,7 +1013,8 @@ enum {
-       Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
-       Opt_grpquota, Opt_i_version,
+diff -NurpP --minimal linux-2.6.30.1/fs/ext4/super.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/super.c
+--- linux-2.6.30.1/fs/ext4/super.c     2009-06-11 17:13:04.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/super.c  2009-07-04 02:21:38.000000000 +0200
+@@ -1029,7 +1029,8 @@ enum {
+       Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize,
+       Opt_usrquota, Opt_grpquota, Opt_i_version,
        Opt_stripe, Opt_delalloc, Opt_nodelalloc,
 -      Opt_inode_readahead_blks, Opt_journal_ioprio
 +      Opt_inode_readahead_blks, Opt_journal_ioprio,
@@ -3580,17 +3135,17 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/super.c linux-2.6.29.4-vs2.3.0.36.1
  };
  
  static const match_table_t tokens = {
-@@ -1073,6 +1074,9 @@ static const match_table_t tokens = {
-       {Opt_nodelalloc, "nodelalloc"},
-       {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
-       {Opt_journal_ioprio, "journal_ioprio=%u"},
+@@ -1092,6 +1093,9 @@ static const match_table_t tokens = {
+       {Opt_auto_da_alloc, "auto_da_alloc=%u"},
+       {Opt_auto_da_alloc, "auto_da_alloc"},
+       {Opt_noauto_da_alloc, "noauto_da_alloc"},
 +      {Opt_tag, "tag"},
 +      {Opt_notag, "notag"},
 +      {Opt_tagid, "tagid=%u"},
        {Opt_err, NULL},
  };
  
-@@ -1168,6 +1172,20 @@ static int parse_options(char *options, 
+@@ -1187,6 +1191,20 @@ static int parse_options(char *options, 
                case Opt_nouid32:
                        set_opt(sbi->s_mount_opt, NO_UID32);
                        break;
@@ -3611,7 +3166,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/super.c linux-2.6.29.4-vs2.3.0.36.1
                case Opt_debug:
                        set_opt(sbi->s_mount_opt, DEBUG);
                        break;
-@@ -2113,6 +2131,9 @@ static int ext4_fill_super(struct super_
+@@ -2335,6 +2353,9 @@ static int ext4_fill_super(struct super_
                           &journal_ioprio, NULL, 0))
                goto failed_mount;
  
@@ -3621,7 +3176,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/super.c linux-2.6.29.4-vs2.3.0.36.1
        sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
                ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  
-@@ -3160,6 +3181,13 @@ static int ext4_remount(struct super_blo
+@@ -3399,6 +3420,13 @@ static int ext4_remount(struct super_blo
        if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
                ext4_abort(sb, __func__, "Abort forced by user");
  
@@ -3635,9 +3190,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/super.c linux-2.6.29.4-vs2.3.0.36.1
        sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
                ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  
-diff -NurpP --minimal linux-2.6.29.4/fs/ext4/symlink.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/symlink.c
---- linux-2.6.29.4/fs/ext4/symlink.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/symlink.c     2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ext4/symlink.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/symlink.c
+--- linux-2.6.30.1/fs/ext4/symlink.c   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ext4/symlink.c        2009-07-04 01:11:39.000000000 +0200
 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
        .listxattr      = ext4_listxattr,
        .removexattr    = generic_removexattr,
@@ -3652,53 +3207,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ext4/symlink.c linux-2.6.29.4-vs2.3.0.36
  #endif
 +      .sync_flags     = ext4_sync_flags,
  };
-diff -NurpP --minimal linux-2.6.29.4/fs/ext4/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/xattr.c
---- linux-2.6.29.4/fs/ext4/xattr.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/xattr.c       2009-03-24 15:47:44.000000000 +0100
-@@ -56,6 +56,7 @@
- #include <linux/mbcache.h>
- #include <linux/quotaops.h>
- #include <linux/rwsem.h>
-+#include <linux/vs_dlimit.h>
- #include "ext4_jbd2.h"
- #include "ext4.h"
- #include "xattr.h"
-@@ -490,6 +491,7 @@ ext4_xattr_release_block(handle_t *handl
-               error = ext4_handle_dirty_metadata(handle, inode, bh);
-               if (IS_SYNC(inode))
-                       ext4_handle_sync(handle);
-+              DLIMIT_FREE_BLOCK(inode, 1);
-               DQUOT_FREE_BLOCK(inode, 1);
-               ea_bdebug(bh, "refcount now=%d; releasing",
-                         le32_to_cpu(BHDR(bh)->h_refcount));
-@@ -781,11 +783,14 @@ inserted:
-                       if (new_bh == bs->bh)
-                               ea_bdebug(new_bh, "keeping");
-                       else {
-+                              error = -ENOSPC;
-+                              if (DLIMIT_ALLOC_BLOCK(inode, 1))
-+                                      goto cleanup;
-                               /* The old block is released after updating
-                                  the inode. */
-                               error = -EDQUOT;
-                               if (DQUOT_ALLOC_BLOCK(inode, 1))
--                                      goto cleanup;
-+                                      goto cleanup_dlimit;
-                               error = ext4_journal_get_write_access(handle,
-                                                                     new_bh);
-                               if (error)
-@@ -861,6 +866,8 @@ cleanup:
- cleanup_dquot:
-       DQUOT_FREE_BLOCK(inode, 1);
-+cleanup_dlimit:
-+      DLIMIT_FREE_BLOCK(inode, 1);
-       goto cleanup;
- bad_block:
-diff -NurpP --minimal linux-2.6.29.4/fs/fcntl.c linux-2.6.29.4-vs2.3.0.36.14/fs/fcntl.c
---- linux-2.6.29.4/fs/fcntl.c  2009-05-23 23:16:52.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/fcntl.c    2009-05-23 23:19:11.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/fs/fcntl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/fcntl.c
+--- linux-2.6.30.1/fs/fcntl.c  2009-06-11 17:13:04.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/fcntl.c       2009-07-04 01:11:39.000000000 +0200
 @@ -20,6 +20,7 @@
  #include <linux/rcupdate.h>
  #include <linux/pid_namespace.h>
@@ -3725,9 +3236,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/fcntl.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  
        err = security_file_fcntl(filp, cmd, arg);
        if (err) {
-diff -NurpP --minimal linux-2.6.29.4/fs/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/file.c
---- linux-2.6.29.4/fs/file.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/file.c     2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/file.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/file.c
+--- linux-2.6.30.1/fs/file.c   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/file.c        2009-07-04 01:11:39.000000000 +0200
 @@ -19,6 +19,7 @@
  #include <linux/spinlock.h>
  #include <linux/rcupdate.h>
@@ -3753,10 +3264,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/f
  #if 1
        /* Sanity check */
        if (rcu_dereference(fdt->fd[fd]) != NULL) {
-diff -NurpP --minimal linux-2.6.29.4/fs/file_table.c linux-2.6.29.4-vs2.3.0.36.14/fs/file_table.c
---- linux-2.6.29.4/fs/file_table.c     2009-03-24 14:22:25.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/file_table.c       2009-03-24 14:48:35.000000000 +0100
-@@ -21,6 +21,8 @@
+diff -NurpP --minimal linux-2.6.30.1/fs/file_table.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/file_table.c
+--- linux-2.6.30.1/fs/file_table.c     2009-06-11 17:13:04.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/file_table.c  2009-07-04 01:11:39.000000000 +0200
+@@ -22,6 +22,8 @@
  #include <linux/fsnotify.h>
  #include <linux/sysctl.h>
  #include <linux/percpu_counter.h>
@@ -3765,8 +3276,8 @@ diff -NurpP --minimal linux-2.6.29.4/fs/file_table.c linux-2.6.29.4-vs2.3.0.36.1
  
  #include <asm/atomic.h>
  
-@@ -129,6 +131,8 @@ struct file *get_empty_filp(void)
-       f->f_cred = get_cred(cred);
+@@ -131,6 +133,8 @@ struct file *get_empty_filp(void)
+       spin_lock_init(&f->f_lock);
        eventpoll_init_file(f);
        /* f->f_version: 0 */
 +      f->f_xid = vx_current_xid();
@@ -3774,7 +3285,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/file_table.c linux-2.6.29.4-vs2.3.0.36.1
        return f;
  
  over:
-@@ -283,6 +287,8 @@ void __fput(struct file *file)
+@@ -285,6 +289,8 @@ void __fput(struct file *file)
                cdev_put(inode->i_cdev);
        fops_put(file->f_op);
        put_pid(file->f_owner.pid);
@@ -3783,7 +3294,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/file_table.c linux-2.6.29.4-vs2.3.0.36.1
        file_kill(file);
        if (file->f_mode & FMODE_WRITE)
                drop_file_write_access(file);
-@@ -350,6 +356,8 @@ void put_filp(struct file *file)
+@@ -352,6 +358,8 @@ void put_filp(struct file *file)
  {
        if (atomic_long_dec_and_test(&file->f_count)) {
                security_file_free(file);
@@ -3792,18 +3303,18 @@ diff -NurpP --minimal linux-2.6.29.4/fs/file_table.c linux-2.6.29.4-vs2.3.0.36.1
                file_kill(file);
                file_free(file);
        }
-diff -NurpP --minimal linux-2.6.29.4/fs/fs_struct.c linux-2.6.29.4-vs2.3.0.36.14/fs/fs_struct.c
---- linux-2.6.29.4/fs/fs_struct.c      2009-05-23 23:16:52.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/fs_struct.c        2009-05-20 01:29:56.000000000 +0200
-@@ -3,6 +3,7 @@
- #include <linux/fs.h>
+diff -NurpP --minimal linux-2.6.30.1/fs/fs_struct.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/fs_struct.c
+--- linux-2.6.30.1/fs/fs_struct.c      2009-06-11 17:13:04.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/fs_struct.c   2009-07-04 02:03:16.000000000 +0200
+@@ -4,6 +4,7 @@
  #include <linux/path.h>
  #include <linux/slab.h>
+ #include <linux/fs_struct.h>
 +#include <linux/vserver/global.h>
  
  /*
   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
-@@ -76,6 +77,7 @@ void free_fs_struct(struct fs_struct *fs
+@@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
  {
        path_put(&fs->root);
        path_put(&fs->pwd);
@@ -3811,7 +3322,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/fs_struct.c linux-2.6.29.4-vs2.3.0.36.14
        kmem_cache_free(fs_cachep, fs);
  }
  
-@@ -111,6 +113,7 @@ struct fs_struct *copy_fs_struct(struct 
+@@ -112,6 +114,7 @@ struct fs_struct *copy_fs_struct(struct 
                fs->pwd = old->pwd;
                path_get(&old->pwd);
                read_unlock(&old->lock);
@@ -3819,9 +3330,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/fs_struct.c linux-2.6.29.4-vs2.3.0.36.14
        }
        return fs;
  }
-diff -NurpP --minimal linux-2.6.29.4/fs/hfsplus/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/hfsplus/ioctl.c
---- linux-2.6.29.4/fs/hfsplus/ioctl.c  2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/hfsplus/ioctl.c    2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/hfsplus/ioctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/hfsplus/ioctl.c
+--- linux-2.6.30.1/fs/hfsplus/ioctl.c  2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/hfsplus/ioctl.c       2009-07-04 01:11:39.000000000 +0200
 @@ -17,6 +17,7 @@
  #include <linux/mount.h>
  #include <linux/sched.h>
@@ -3830,11 +3341,11 @@ diff -NurpP --minimal linux-2.6.29.4/fs/hfsplus/ioctl.c linux-2.6.29.4-vs2.3.0.3
  #include <asm/uaccess.h>
  #include "hfsplus_fs.h"
  
-diff -NurpP --minimal linux-2.6.29.4/fs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/inode.c
---- linux-2.6.29.4/fs/inode.c  2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/inode.c    2009-03-25 00:51:55.000000000 +0100
-@@ -126,6 +126,9 @@ struct inode *inode_init_always(struct s
-       struct address_space * const mapping = &inode->i_data;
+diff -NurpP --minimal linux-2.6.30.1/fs/inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/inode.c
+--- linux-2.6.30.1/fs/inode.c  2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/inode.c       2009-07-04 01:11:39.000000000 +0200
+@@ -127,6 +127,9 @@ struct inode *inode_init_always(struct s
+       struct address_space *const mapping = &inode->i_data;
  
        inode->i_sb = sb;
 +
@@ -3843,15 +3354,15 @@ diff -NurpP --minimal linux-2.6.29.4/fs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/
        inode->i_blkbits = sb->s_blocksize_bits;
        inode->i_flags = 0;
        atomic_set(&inode->i_count, 1);
-@@ -146,6 +149,7 @@ struct inode *inode_init_always(struct s
+@@ -147,6 +150,7 @@ struct inode *inode_init_always(struct s
        inode->i_bdev = NULL;
        inode->i_cdev = NULL;
        inode->i_rdev = 0;
 +      inode->i_mdev = 0;
        inode->dirtied_when = 0;
-       if (security_inode_alloc(inode)) {
-               if (inode->i_sb->s_op->destroy_inode)
-@@ -267,6 +271,8 @@ void __iget(struct inode * inode)
+       if (security_inode_alloc(inode))
+@@ -277,6 +281,8 @@ void __iget(struct inode *inode)
        inodes_stat.nr_unused--;
  }
  
@@ -3860,7 +3371,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  /**
   * clear_inode - clear an inode
   * @inode: inode to clear
-@@ -1539,9 +1545,11 @@ void init_special_inode(struct inode *in
+@@ -1553,9 +1559,11 @@ void init_special_inode(struct inode *in
        if (S_ISCHR(mode)) {
                inode->i_fop = &def_chr_fops;
                inode->i_rdev = rdev;
@@ -3872,9 +3383,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/
        } else if (S_ISFIFO(mode))
                inode->i_fop = &def_fifo_fops;
        else if (S_ISSOCK(mode))
-diff -NurpP --minimal linux-2.6.29.4/fs/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/ioctl.c
---- linux-2.6.29.4/fs/ioctl.c  2009-05-23 23:16:52.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ioctl.c    2009-05-23 23:19:11.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/fs/ioctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ioctl.c
+--- linux-2.6.30.1/fs/ioctl.c  2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ioctl.c       2009-07-04 01:11:39.000000000 +0200
 @@ -15,6 +15,9 @@
  #include <linux/uaccess.h>
  #include <linux/writeback.h>
@@ -3885,9 +3396,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  
  #include <asm/ioctls.h>
  
-diff -NurpP --minimal linux-2.6.29.4/fs/ioprio.c linux-2.6.29.4-vs2.3.0.36.14/fs/ioprio.c
---- linux-2.6.29.4/fs/ioprio.c 2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ioprio.c   2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ioprio.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ioprio.c
+--- linux-2.6.30.1/fs/ioprio.c 2009-03-24 14:22:26.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ioprio.c      2009-07-04 01:11:39.000000000 +0200
 @@ -26,6 +26,7 @@
  #include <linux/syscalls.h>
  #include <linux/security.h>
@@ -3914,9 +3425,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ioprio.c linux-2.6.29.4-vs2.3.0.36.14/fs
                                tmpio = get_task_ioprio(p);
                                if (tmpio < 0)
                                        continue;
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/acl.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/acl.c
---- linux-2.6.29.4/fs/jfs/acl.c        2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/acl.c  2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/jfs/acl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/acl.c
+--- linux-2.6.30.1/fs/jfs/acl.c        2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/acl.c     2009-07-04 02:22:31.000000000 +0200
 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
                return rc;
  
@@ -3924,12 +3435,12 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/acl.c linux-2.6.29.4-vs2.3.0.36.14/f
 -          (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
 +          (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
 +          (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
-               if (DQUOT_TRANSFER(inode, iattr))
+               if (vfs_dq_transfer(inode, iattr))
                        return -EDQUOT;
        }
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/file.c
---- linux-2.6.29.4/fs/jfs/file.c       2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/file.c 2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/jfs/file.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/file.c
+--- linux-2.6.30.1/fs/jfs/file.c       2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/file.c    2009-07-04 01:11:39.000000000 +0200
 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
        .setattr        = jfs_setattr,
        .permission     = jfs_permission,
@@ -3938,28 +3449,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/file.c linux-2.6.29.4-vs2.3.0.36.14/
  };
  
  const struct file_operations jfs_file_operations = {
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/inode.c
---- linux-2.6.29.4/fs/jfs/inode.c      2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/inode.c        2009-03-24 14:48:35.000000000 +0100
-@@ -22,6 +22,7 @@
- #include <linux/buffer_head.h>
- #include <linux/pagemap.h>
- #include <linux/quotaops.h>
-+#include <linux/vs_dlimit.h>
- #include "jfs_incore.h"
- #include "jfs_inode.h"
- #include "jfs_filsys.h"
-@@ -161,6 +162,7 @@ void jfs_delete_inode(struct inode *inod
-               DQUOT_INIT(inode);
-               DQUOT_FREE_INODE(inode);
-               DQUOT_DROP(inode);
-+              DLIMIT_FREE_INODE(inode);
-       }
-       clear_inode(inode);
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/ioctl.c
---- linux-2.6.29.4/fs/jfs/ioctl.c      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/ioctl.c        2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/jfs/ioctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/ioctl.c
+--- linux-2.6.30.1/fs/jfs/ioctl.c      2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/ioctl.c   2009-07-04 01:11:39.000000000 +0200
 @@ -11,6 +11,7 @@
  #include <linux/mount.h>
  #include <linux/time.h>
@@ -3991,9 +3483,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/ioctl.c linux-2.6.29.4-vs2.3.0.36.14
                        if (!capable(CAP_LINUX_IMMUTABLE)) {
                                mutex_unlock(&inode->i_mutex);
                                err = -EPERM;
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_dinode.h linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_dinode.h
---- linux-2.6.29.4/fs/jfs/jfs_dinode.h 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_dinode.h   2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/jfs/jfs_dinode.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/jfs_dinode.h
+--- linux-2.6.30.1/fs/jfs/jfs_dinode.h 2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/jfs_dinode.h      2009-07-04 01:11:39.000000000 +0200
 @@ -161,9 +161,13 @@ struct dinode {
  
  #define JFS_APPEND_FL         0x01000000 /* writes to file may only append */
@@ -4010,187 +3502,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_dinode.h linux-2.6.29.4-vs2.3.0.
  #define JFS_FL_INHERIT                0x03C80000
  
  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_dtree.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_dtree.c
---- linux-2.6.29.4/fs/jfs/jfs_dtree.c  2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_dtree.c    2009-02-22 22:54:25.000000000 +0100
-@@ -102,6 +102,7 @@
- #include <linux/fs.h>
- #include <linux/quotaops.h>
-+#include <linux/vs_dlimit.h>
- #include "jfs_incore.h"
- #include "jfs_superblock.h"
- #include "jfs_filsys.h"
-@@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
-                */
-               if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
-                       goto clean_up;
--              if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
--                      DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
--                      goto clean_up;
--              }
-+              if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
-+                      goto clean_up_dquot;
-+              if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
-+                      goto clean_up_dlimit;
-               /*
-                * Save the table, we're going to overwrite it with the
-@@ -480,6 +481,12 @@ static u32 add_index(tid_t tid, struct i
-       return index;
-+      clean_up_dlimit:
-+      DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
-+
-+      clean_up_dquot:
-+      DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
-+
-       clean_up:
-       jfs_ip->next_index--;
-@@ -951,6 +958,7 @@ static int dtSplitUp(tid_t tid,
-       struct tlock *tlck;
-       struct lv *lv;
-       int quota_allocation = 0;
-+      int dlimit_allocation = 0;
-       /* get split page */
-       smp = split->mp;
-@@ -1033,6 +1041,12 @@ static int dtSplitUp(tid_t tid,
-               }
-               quota_allocation += n;
-+              if (DLIMIT_ALLOC_BLOCK(ip, n)) {
-+                      rc = -ENOSPC;
-+                      goto extendOut;
-+              }
-+              dlimit_allocation += n;
-+
-               if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
-                                   (s64) n, &nxaddr)))
-                       goto extendOut;
-@@ -1306,6 +1320,9 @@ static int dtSplitUp(tid_t tid,
-       freeKeyName:
-       kfree(key.name);
-+      /* Rollback dlimit allocation */
-+      if (rc && dlimit_allocation)
-+              DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
-       /* Rollback quota allocation */
-       if (rc && quota_allocation)
-               DQUOT_FREE_BLOCK(ip, quota_allocation);
-@@ -1373,6 +1390,12 @@ static int dtSplitPage(tid_t tid, struct
-               release_metapage(rmp);
-               return -EDQUOT;
-       }
-+      /* Allocate blocks to dlimit. */
-+      if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
-+              DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
-+              release_metapage(rmp);
-+              return -ENOSPC;
-+      }
-       jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
-@@ -1920,6 +1943,12 @@ static int dtSplitRoot(tid_t tid,
-               release_metapage(rmp);
-               return -EDQUOT;
-       }
-+      /* Allocate blocks to dlimit. */
-+      if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
-+              DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
-+              release_metapage(rmp);
-+              return -ENOSPC;
-+      }
-       BT_MARK_DIRTY(rmp, ip);
-       /*
-@@ -2286,6 +2315,8 @@ static int dtDeleteUp(tid_t tid, struct 
-       xlen = lengthPXD(&fp->header.self);
-+      /* Free dlimit allocation. */
-+      DLIMIT_FREE_BLOCK(ip, xlen);
-       /* Free quota allocation. */
-       DQUOT_FREE_BLOCK(ip, xlen);
-@@ -2362,6 +2393,8 @@ static int dtDeleteUp(tid_t tid, struct 
-                               xlen = lengthPXD(&p->header.self);
-+                              /* Free dlimit allocation */
-+                              DLIMIT_FREE_BLOCK(ip, xlen);
-                               /* Free quota allocation */
-                               DQUOT_FREE_BLOCK(ip, xlen);
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_extent.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_extent.c
---- linux-2.6.29.4/fs/jfs/jfs_extent.c 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_extent.c   2009-02-22 22:54:25.000000000 +0100
-@@ -18,6 +18,7 @@
- #include <linux/fs.h>
- #include <linux/quotaops.h>
-+#include <linux/vs_dlimit.h>
- #include "jfs_incore.h"
- #include "jfs_inode.h"
- #include "jfs_superblock.h"
-@@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
-               return -EDQUOT;
-       }
-+      /* Allocate blocks to dlimit. */
-+      if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
-+              DQUOT_FREE_BLOCK(ip, nxlen);
-+              dbFree(ip, nxaddr, (s64) nxlen);
-+              mutex_unlock(&JFS_IP(ip)->commit_mutex);
-+              return -ENOSPC;
-+      }
-+
-       /* determine the value of the extent flag */
-       xflag = abnr ? XAD_NOTRECORDED : 0;
-@@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
-        */
-       if (rc) {
-               dbFree(ip, nxaddr, nxlen);
-+              DLIMIT_FREE_BLOCK(ip, nxlen);
-               DQUOT_FREE_BLOCK(ip, nxlen);
-               mutex_unlock(&JFS_IP(ip)->commit_mutex);
-               return (rc);
-@@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
-               mutex_unlock(&JFS_IP(ip)->commit_mutex);
-               return -EDQUOT;
-       }
-+      /* Allocate blocks to dlimit. */
-+      if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
-+              DQUOT_FREE_BLOCK(ip, nxlen);
-+              dbFree(ip, nxaddr, (s64) nxlen);
-+              up(&JFS_IP(ip)->commit_sem);
-+              return -ENOSPC;
-+      }
-       delta = nxlen - xlen;
-@@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
-               /* extend the extent */
-               if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
-                       dbFree(ip, xaddr + xlen, delta);
-+                      DLIMIT_FREE_BLOCK(ip, nxlen);
-                       DQUOT_FREE_BLOCK(ip, nxlen);
-                       goto exit;
-               }
-@@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
-                */
-               if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
-                       dbFree(ip, nxaddr, nxlen);
-+                      DLIMIT_FREE_BLOCK(ip, nxlen);
-                       DQUOT_FREE_BLOCK(ip, nxlen);
-                       goto exit;
-               }
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_filsys.h linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_filsys.h
---- linux-2.6.29.4/fs/jfs/jfs_filsys.h 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_filsys.h   2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/jfs/jfs_filsys.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/jfs_filsys.h
+--- linux-2.6.30.1/fs/jfs/jfs_filsys.h 2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/jfs_filsys.h      2009-07-04 01:11:39.000000000 +0200
 @@ -263,6 +263,7 @@
  #define JFS_NAME_MAX  255
  #define JFS_PATH_MAX  BPSIZE
@@ -4199,9 +3513,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_filsys.h linux-2.6.29.4-vs2.3.0.
  
  /*
   *    file system state (superblock state)
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_imap.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_imap.c
---- linux-2.6.29.4/fs/jfs/jfs_imap.c   2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_imap.c     2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/jfs/jfs_imap.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/jfs_imap.c
+--- linux-2.6.30.1/fs/jfs/jfs_imap.c   2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/jfs_imap.c        2009-07-04 01:11:39.000000000 +0200
 @@ -45,6 +45,7 @@
  #include <linux/buffer_head.h>
  #include <linux/pagemap.h>
@@ -4210,7 +3524,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_imap.c linux-2.6.29.4-vs2.3.0.36
  
  #include "jfs_incore.h"
  #include "jfs_inode.h"
-@@ -3062,6 +3063,8 @@ static int copy_from_dinode(struct dinod
+@@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
  {
        struct jfs_inode_info *jfs_ip = JFS_IP(ip);
        struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
@@ -4219,7 +3533,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_imap.c linux-2.6.29.4-vs2.3.0.36
  
        jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
        jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
-@@ -3082,14 +3085,18 @@ static int copy_from_dinode(struct dinod
+@@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
        }
        ip->i_nlink = le32_to_cpu(dip->di_nlink);
  
@@ -4240,7 +3554,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_imap.c linux-2.6.29.4-vs2.3.0.36
        if (sbi->gid == -1)
                ip->i_gid = jfs_ip->saved_gid;
        else {
-@@ -3154,14 +3161,12 @@ static void copy_to_dinode(struct dinode
+@@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
        dip->di_size = cpu_to_le64(ip->i_size);
        dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
        dip->di_nlink = cpu_to_le32(ip->i_nlink);
@@ -4261,19 +3575,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_imap.c linux-2.6.29.4-vs2.3.0.36
        jfs_get_inode_flags(jfs_ip);
        /*
         * mode2 is only needed for storing the higher order bits.
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_inode.c
---- linux-2.6.29.4/fs/jfs/jfs_inode.c  2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_inode.c    2009-03-24 15:58:01.000000000 +0100
-@@ -18,6 +18,8 @@
- #include <linux/fs.h>
- #include <linux/quotaops.h>
-+#include <linux/vs_dlimit.h>
-+#include <linux/vs_tag.h>
- #include "jfs_incore.h"
- #include "jfs_inode.h"
- #include "jfs_filsys.h"
-@@ -30,29 +32,46 @@ void jfs_set_inode_flags(struct inode *i
+diff -NurpP --minimal linux-2.6.30.1/fs/jfs/jfs_inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/jfs_inode.c
+--- linux-2.6.30.1/fs/jfs/jfs_inode.c  2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/jfs_inode.c       2009-07-04 01:11:38.000000000 +0200
+@@ -30,29 +30,46 @@ void jfs_set_inode_flags(struct inode *i
  {
        unsigned int flags = JFS_IP(inode)->mode2;
  
@@ -4326,7 +3631,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_inode.c linux-2.6.29.4-vs2.3.0.3
        if (flags & S_APPEND)
                jfs_ip->mode2 |= JFS_APPEND_FL;
        if (flags & S_NOATIME)
-@@ -61,6 +80,19 @@ void jfs_get_inode_flags(struct jfs_inod
+@@ -61,6 +78,19 @@ void jfs_get_inode_flags(struct jfs_inod
                jfs_ip->mode2 |= JFS_DIRSYNC_FL;
        if (flags & S_SYNC)
                jfs_ip->mode2 |= JFS_SYNC_FL;
@@ -4346,31 +3651,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_inode.c linux-2.6.29.4-vs2.3.0.3
  }
  
  /*
-@@ -113,6 +145,12 @@ struct inode *ialloc(struct inode *paren
-       jfs_inode->saved_uid = inode->i_uid;
-       jfs_inode->saved_gid = inode->i_gid;
-+      inode->i_tag = dx_current_fstag(sb);
-+      if (DLIMIT_ALLOC_INODE(inode)) {
-+              rc = -ENOSPC;
-+              goto fail_drop2;
-+      }
-+
-       /*
-        * Allocate inode to quota.
-        */
-@@ -162,6 +200,8 @@ struct inode *ialloc(struct inode *paren
-       return inode;
- fail_drop:
-+      DLIMIT_FREE_INODE(inode);
-+fail_drop2:
-       DQUOT_DROP(inode);
-       inode->i_flags |= S_NOQUOTA;
- fail_unlock:
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_inode.h linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_inode.h
---- linux-2.6.29.4/fs/jfs/jfs_inode.h  2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_inode.h    2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/jfs/jfs_inode.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/jfs_inode.h
+--- linux-2.6.30.1/fs/jfs/jfs_inode.h  2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/jfs_inode.h       2009-07-04 01:11:39.000000000 +0200
 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
        int fh_len, int fh_type);
@@ -4379,95 +3662,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_inode.h linux-2.6.29.4-vs2.3.0.3
  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
  
  extern const struct address_space_operations jfs_aops;
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_xtree.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_xtree.c
---- linux-2.6.29.4/fs/jfs/jfs_xtree.c  2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_xtree.c    2009-02-22 22:54:25.000000000 +0100
-@@ -23,6 +23,7 @@
- #include <linux/module.h>
- #include <linux/quotaops.h>
- #include <linux/seq_file.h>
-+#include <linux/vs_dlimit.h>
- #include "jfs_incore.h"
- #include "jfs_filsys.h"
- #include "jfs_metapage.h"
-@@ -848,7 +849,12 @@ int xtInsert(tid_t tid,           /* transaction 
-                       hint = 0;
-               if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
-                       goto out;
-+              if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
-+                      DQUOT_FREE_BLOCK(ip, xlen);
-+                      goto out;
-+              }
-               if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
-+                      DLIMIT_FREE_BLOCK(ip, xlen);
-                       DQUOT_FREE_BLOCK(ip, xlen);
-                       goto out;
-               }
-@@ -878,6 +884,7 @@ int xtInsert(tid_t tid,            /* transaction 
-                       /* undo data extent allocation */
-                       if (*xaddrp == 0) {
-                               dbFree(ip, xaddr, (s64) xlen);
-+                              DLIMIT_FREE_BLOCK(ip, xlen);
-                               DQUOT_FREE_BLOCK(ip, xlen);
-                       }
-                       return rc;
-@@ -1234,6 +1241,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
-       struct tlock *tlck;
-       struct xtlock *sxtlck = NULL, *rxtlck = NULL;
-       int quota_allocation = 0;
-+      int dlimit_allocation = 0;
-       smp = split->mp;
-       sp = XT_PAGE(ip, smp);
-@@ -1253,6 +1261,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
-       quota_allocation += lengthPXD(pxd);
-+      /* Allocate blocks to dlimit. */
-+      if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
-+             rc = -ENOSPC;
-+             goto clean_up;
-+      }
-+      dlimit_allocation += lengthPXD(pxd);
-+
-       /*
-        * allocate the new right page for the split
-        */
-@@ -1454,6 +1469,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
-       clean_up:
-+      /* Rollback dlimit allocation. */
-+      if (dlimit_allocation)
-+              DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
-       /* Rollback quota allocation. */
-       if (quota_allocation)
-               DQUOT_FREE_BLOCK(ip, quota_allocation);
-@@ -1517,6 +1535,12 @@ xtSplitRoot(tid_t tid,
-               release_metapage(rmp);
-               return -EDQUOT;
-       }
-+      /* Allocate blocks to dlimit. */
-+      if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
-+              DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
-+              release_metapage(rmp);
-+              return -ENOSPC;
-+      }
-       jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
-@@ -3940,6 +3964,8 @@ s64 xtTruncate(tid_t tid, struct inode *
-       else
-               ip->i_size = newsize;
-+      /* update dlimit allocation to reflect freed blocks */
-+      DLIMIT_FREE_BLOCK(ip, nfreed);
-       /* update quota allocation to reflect freed blocks */
-       DQUOT_FREE_BLOCK(ip, nfreed);
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/namei.c
---- linux-2.6.29.4/fs/jfs/namei.c      2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/namei.c        2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/jfs/namei.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/namei.c
+--- linux-2.6.30.1/fs/jfs/namei.c      2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/namei.c   2009-07-04 01:11:39.000000000 +0200
 @@ -21,6 +21,7 @@
  #include <linux/ctype.h>
  #include <linux/quotaops.h>
@@ -4492,10 +3689,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/namei.c linux-2.6.29.4-vs2.3.0.36.14
  };
  
  const struct file_operations jfs_dir_operations = {
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/super.c
---- linux-2.6.29.4/fs/jfs/super.c      2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/super.c        2009-03-24 14:48:35.000000000 +0100
-@@ -196,7 +196,8 @@ static void jfs_put_super(struct super_b
+diff -NurpP --minimal linux-2.6.30.1/fs/jfs/super.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/super.c
+--- linux-2.6.30.1/fs/jfs/super.c      2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/jfs/super.c   2009-07-04 01:11:39.000000000 +0200
+@@ -200,7 +200,8 @@ static void jfs_put_super(struct super_b
  enum {
        Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
        Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
@@ -4505,7 +3702,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/super.c linux-2.6.29.4-vs2.3.0.36.14
  };
  
  static const match_table_t tokens = {
-@@ -206,6 +207,10 @@ static const match_table_t tokens = {
+@@ -210,6 +211,10 @@ static const match_table_t tokens = {
        {Opt_resize, "resize=%u"},
        {Opt_resize_nosize, "resize"},
        {Opt_errors, "errors=%s"},
@@ -4516,7 +3713,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/super.c linux-2.6.29.4-vs2.3.0.36.14
        {Opt_ignore, "noquota"},
        {Opt_ignore, "quota"},
        {Opt_usrquota, "usrquota"},
-@@ -340,6 +345,20 @@ static int parse_options(char *options, 
+@@ -344,6 +349,20 @@ static int parse_options(char *options, 
                        }
                        break;
                }
@@ -4537,7 +3734,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/super.c linux-2.6.29.4-vs2.3.0.36.14
                default:
                        printk("jfs: Unrecognized mount option \"%s\" "
                                        " or missing value\n", p);
-@@ -370,6 +389,13 @@ static int jfs_remount(struct super_bloc
+@@ -374,6 +393,13 @@ static int jfs_remount(struct super_bloc
        if (!parse_options(data, sb, &newLVSize, &flag)) {
                return -EINVAL;
        }
@@ -4551,7 +3748,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/super.c linux-2.6.29.4-vs2.3.0.36.14
        if (newLVSize) {
                if (sb->s_flags & MS_RDONLY) {
                        printk(KERN_ERR
-@@ -441,6 +467,9 @@ static int jfs_fill_super(struct super_b
+@@ -445,6 +471,9 @@ static int jfs_fill_super(struct super_b
  #ifdef CONFIG_JFS_POSIX_ACL
        sb->s_flags |= MS_POSIXACL;
  #endif
@@ -4561,89 +3758,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/jfs/super.c linux-2.6.29.4-vs2.3.0.36.14
  
        if (newLVSize) {
                printk(KERN_ERR "resize option for remount only\n");
-diff -NurpP --minimal linux-2.6.29.4/fs/jfs/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/xattr.c
---- linux-2.6.29.4/fs/jfs/xattr.c      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/xattr.c        2009-02-22 22:54:25.000000000 +0100
-@@ -23,6 +23,7 @@
- #include <linux/posix_acl_xattr.h>
- #include <linux/quotaops.h>
- #include <linux/security.h>
-+#include <linux/vs_dlimit.h>
- #include "jfs_incore.h"
- #include "jfs_superblock.h"
- #include "jfs_dmap.h"
-@@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
-       if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
-               return -EDQUOT;
-       }
-+      /* Allocate new blocks to dlimit. */
-+      if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
-+              DQUOT_FREE_BLOCK(ip, nblocks);
-+              return -ENOSPC;
-+      }
-       rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
-       if (rc) {
-+              /*Rollback dlimit allocation. */
-+              DLIMIT_FREE_BLOCK(ip, nblocks);
-               /*Rollback quota allocation. */
-               DQUOT_FREE_BLOCK(ip, nblocks);
-               return rc;
-@@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
-       failed:
-       /* Rollback quota allocation. */
-+      DLIMIT_FREE_BLOCK(ip, nblocks);
-+      /* Rollback quota allocation. */
-       DQUOT_FREE_BLOCK(ip, nblocks);
-       dbFree(ip, blkno, nblocks);
-@@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
-       s64 blkno;
-       int rc;
-       int quota_allocation = 0;
-+      int dlimit_allocation = 0;
-       /* When fsck.jfs clears a bad ea, it doesn't clear the size */
-       if (ji->ea.flag == 0)
-@@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
-               quota_allocation = blocks_needed;
-+              /* Allocate new blocks to dlimit. */
-+              rc = -ENOSPC;
-+              if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
-+                      goto clean_up;
-+              dlimit_allocation = blocks_needed;
-+
-               rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
-                            &blkno);
-               if (rc)
-@@ -600,6 +617,9 @@ static int ea_get(struct inode *inode, s
-       return ea_size;
-       clean_up:
-+      /* Rollback dlimit allocation */
-+      if (dlimit_allocation)
-+              DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
-       /* Rollback quota allocation */
-       if (quota_allocation)
-               DQUOT_FREE_BLOCK(inode, quota_allocation);
-@@ -676,8 +696,10 @@ static int ea_put(tid_t tid, struct inod
-       }
-       /* If old blocks exist, they must be removed from quota allocation. */
--      if (old_blocks)
-+      if (old_blocks) {
-+              DLIMIT_FREE_BLOCK(inode, old_blocks);
-               DQUOT_FREE_BLOCK(inode, old_blocks);
-+      }
-       inode->i_ctime = CURRENT_TIME;
-diff -NurpP --minimal linux-2.6.29.4/fs/libfs.c linux-2.6.29.4-vs2.3.0.36.14/fs/libfs.c
---- linux-2.6.29.4/fs/libfs.c  2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/libfs.c    2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/libfs.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/libfs.c
+--- linux-2.6.30.1/fs/libfs.c  2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/libfs.c       2009-07-04 01:11:39.000000000 +0200
 @@ -125,7 +125,8 @@ static inline unsigned char dt_type(stru
   * both impossible due to the lock on directory.
   */
@@ -4682,7 +3799,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/libfs.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
  {
        return -EISDIR;
-@@ -796,6 +811,7 @@ EXPORT_SYMBOL(dcache_dir_close);
+@@ -811,6 +826,7 @@ EXPORT_SYMBOL(dcache_dir_close);
  EXPORT_SYMBOL(dcache_dir_lseek);
  EXPORT_SYMBOL(dcache_dir_open);
  EXPORT_SYMBOL(dcache_readdir);
@@ -4690,9 +3807,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/libfs.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  EXPORT_SYMBOL(generic_read_dir);
  EXPORT_SYMBOL(get_sb_pseudo);
  EXPORT_SYMBOL(simple_write_begin);
-diff -NurpP --minimal linux-2.6.29.4/fs/locks.c linux-2.6.29.4-vs2.3.0.36.14/fs/locks.c
---- linux-2.6.29.4/fs/locks.c  2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/locks.c    2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/locks.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/locks.c
+--- linux-2.6.30.1/fs/locks.c  2009-03-24 14:22:26.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/locks.c       2009-07-04 01:11:39.000000000 +0200
 @@ -127,6 +127,8 @@
  #include <linux/time.h>
  #include <linux/rcupdate.h>
@@ -4878,13 +3995,13 @@ diff -NurpP --minimal linux-2.6.29.4/fs/locks.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  
        f->private++;
        return 0;
-diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/namei.c
---- linux-2.6.29.4/fs/namei.c  2009-05-23 23:16:52.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/namei.c    2009-05-23 22:57:27.000000000 +0200
-@@ -31,6 +31,14 @@
- #include <linux/file.h>
+diff -NurpP --minimal linux-2.6.30.1/fs/namei.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/namei.c
+--- linux-2.6.30.1/fs/namei.c  2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/namei.c       2009-07-04 02:25:19.000000000 +0200
+@@ -33,6 +33,14 @@
  #include <linux/fcntl.h>
  #include <linux/device_cgroup.h>
+ #include <linux/fs_struct.h>
 +#include <linux/proc_fs.h>
 +#include <linux/vserver/inode.h>
 +#include <linux/vs_base.h>
@@ -4896,7 +4013,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  #include <asm/uaccess.h>
  
  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
-@@ -167,6 +175,77 @@ void putname(const char *name)
+@@ -169,6 +177,77 @@ void putname(const char *name)
  EXPORT_SYMBOL(putname);
  #endif
  
@@ -4974,7 +4091,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  
  /**
   * generic_permission  -  check for access rights on a Posix-like filesystem
-@@ -253,10 +332,14 @@ int inode_permission(struct inode *inode
+@@ -255,10 +334,14 @@ int inode_permission(struct inode *inode
                /*
                 * Nobody gets write access to an immutable file.
                 */
@@ -4990,7 +4107,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
        if (inode->i_op->permission)
                retval = inode->i_op->permission(inode, mask);
        else
-@@ -432,6 +515,8 @@ static int exec_permission_lite(struct i
+@@ -434,6 +517,8 @@ static int exec_permission_lite(struct i
  {
        umode_t mode = inode->i_mode;
  
@@ -4999,7 +4116,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
        if (inode->i_op->permission)
                return -EAGAIN;
  
-@@ -749,7 +834,8 @@ static __always_inline void follow_dotdo
+@@ -751,7 +836,8 @@ static __always_inline void follow_dotdo
                if (nd->path.dentry == fs->root.dentry &&
                    nd->path.mnt == fs->root.mnt) {
                          read_unlock(&fs->lock);
@@ -5009,7 +4126,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
                }
                  read_unlock(&fs->lock);
                spin_lock(&dcache_lock);
-@@ -786,16 +872,30 @@ static int do_lookup(struct nameidata *n
+@@ -788,16 +874,30 @@ static int do_lookup(struct nameidata *n
  {
        struct vfsmount *mnt = nd->path.mnt;
        struct dentry *dentry = __d_lookup(nd->path.dentry, name);
@@ -5040,7 +4157,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  
  need_lookup:
        dentry = real_lookup(nd->path.dentry, name, nd);
-@@ -1364,7 +1464,7 @@ static int may_delete(struct inode *dir,
+@@ -1370,7 +1470,7 @@ static int may_delete(struct inode *dir,
        if (IS_APPEND(dir))
                return -EPERM;
        if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
@@ -5049,8 +4166,8 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
                return -EPERM;
        if (isdir) {
                if (!S_ISDIR(victim->d_inode->i_mode))
-@@ -1506,6 +1606,14 @@ int may_open(struct path *path, int acc_
-               flag &= ~O_TRUNC;
+@@ -1510,6 +1610,14 @@ int may_open(struct path *path, int acc_
+               break;
        }
  
 +#ifdef        CONFIG_VSERVER_COWBL
@@ -5064,19 +4181,20 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
        error = inode_permission(inode, acc_mode);
        if (error)
                return error;
-@@ -1639,6 +1747,11 @@ struct file *do_filp_open(int dfd, const
+@@ -1647,7 +1755,11 @@ struct file *do_filp_open(int dfd, const
+       int count = 0;
        int will_write;
        int flag = open_to_namei_flags(open_flag);
+-
 +#ifdef        CONFIG_VSERVER_COWBL
 +      int rflag = flag;
 +      int rmode = mode;
 +restart:
 +#endif
-       acc_mode = MAY_OPEN | ACC_MODE(flag);
+       if (!acc_mode)
+               acc_mode = MAY_OPEN | ACC_MODE(flag);
  
-       /* O_TRUNC implies we need access checks for write permissions */
-@@ -1771,6 +1884,25 @@ ok:
+@@ -1781,6 +1893,25 @@ ok:
                        goto exit;
        }
        error = may_open(&nd.path, acc_mode, flag);
@@ -5102,7 +4220,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
        if (error) {
                if (will_write)
                        mnt_drop_write(nd.path.mnt);
-@@ -1924,9 +2056,17 @@ int vfs_mknod(struct inode *dir, struct 
+@@ -1934,9 +2065,17 @@ int vfs_mknod(struct inode *dir, struct 
        if (error)
                return error;
  
@@ -5121,7 +4239,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
        if (!dir->i_op->mknod)
                return -EPERM;
  
-@@ -2393,7 +2533,7 @@ int vfs_link(struct dentry *old_dentry, 
+@@ -2403,7 +2542,7 @@ int vfs_link(struct dentry *old_dentry, 
        /*
         * A link to an append-only or immutable file cannot be created.
         */
@@ -5130,7 +4248,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
                return -EPERM;
        if (!dir->i_op->link)
                return -EPERM;
-@@ -2766,6 +2906,219 @@ int vfs_follow_link(struct nameidata *nd
+@@ -2776,6 +2915,219 @@ int vfs_follow_link(struct nameidata *nd
        return __vfs_follow_link(nd, link);
  }
  
@@ -5350,13 +4468,13 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  /* get the link contents into pagecache */
  static char *page_getlink(struct dentry * dentry, struct page **ppage)
  {
-diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14/fs/namespace.c
---- linux-2.6.29.4/fs/namespace.c      2009-05-23 23:16:52.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/namespace.c        2009-05-10 23:42:01.000000000 +0200
-@@ -27,6 +27,11 @@
- #include <linux/ramfs.h>
+diff -NurpP --minimal linux-2.6.30.1/fs/namespace.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/namespace.c
+--- linux-2.6.30.1/fs/namespace.c      2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/namespace.c   2009-07-04 02:20:45.000000000 +0200
+@@ -28,6 +28,11 @@
  #include <linux/log2.h>
  #include <linux/idr.h>
+ #include <linux/fs_struct.h>
 +#include <linux/vs_base.h>
 +#include <linux/vs_context.h>
 +#include <linux/vs_tag.h>
@@ -5405,7 +4523,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
  /*
   * Simple .show_options callback for filesystems which don't want to
   * implement more complex mount option showing.
-@@ -759,6 +790,8 @@ static int show_sb_opts(struct seq_file 
+@@ -774,6 +805,8 @@ static int show_sb_opts(struct seq_file 
                { MS_SYNCHRONOUS, ",sync" },
                { MS_DIRSYNC, ",dirsync" },
                { MS_MANDLOCK, ",mand" },
@@ -5414,7 +4532,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
                { 0, NULL }
        };
        const struct proc_fs_info *fs_infop;
-@@ -805,10 +838,20 @@ static int show_vfsmnt(struct seq_file *
+@@ -821,10 +854,20 @@ static int show_vfsmnt(struct seq_file *
        int err = 0;
        struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
  
@@ -5439,7 +4557,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
        show_type(m, mnt->mnt_sb);
        seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
        err = show_sb_opts(m, mnt->mnt_sb);
-@@ -838,6 +881,11 @@ static int show_mountinfo(struct seq_fil
+@@ -854,6 +897,11 @@ static int show_mountinfo(struct seq_fil
        struct path root = p->root;
        int err = 0;
  
@@ -5451,7 +4569,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
        seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
                   MAJOR(sb->s_dev), MINOR(sb->s_dev));
        seq_dentry(m, mnt->mnt_root, " \t\n\\");
-@@ -896,17 +944,27 @@ static int show_vfsstat(struct seq_file 
+@@ -912,17 +960,27 @@ static int show_vfsstat(struct seq_file 
        struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
        int err = 0;
  
@@ -5489,7 +4607,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
  
        /* file system type */
        seq_puts(m, "with fstype ");
-@@ -1145,7 +1203,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
+@@ -1159,7 +1217,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
                goto dput_and_out;
  
        retval = -EPERM;
@@ -5498,7 +4616,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
                goto dput_and_out;
  
        retval = do_umount(path.mnt, flags);
-@@ -1171,7 +1229,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
+@@ -1185,7 +1243,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
  
  static int mount_is_safe(struct path *path)
  {
@@ -5507,7 +4625,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
                return 0;
        return -EPERM;
  #ifdef notyet
-@@ -1462,11 +1520,13 @@ static int do_change_type(struct path *p
+@@ -1476,11 +1534,13 @@ static int do_change_type(struct path *p
   * do loopback mount.
   */
  static int do_loopback(struct path *path, char *old_name,
@@ -5522,7 +4640,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
        if (err)
                return err;
        if (!old_name || !*old_name)
-@@ -1500,6 +1560,7 @@ static int do_loopback(struct path *path
+@@ -1514,6 +1574,7 @@ static int do_loopback(struct path *path
                spin_unlock(&vfsmount_lock);
                release_mounts(&umount_list);
        }
@@ -5530,7 +4648,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
  
  out:
        up_write(&namespace_sem);
-@@ -1530,12 +1591,12 @@ static int change_mount_flags(struct vfs
+@@ -1544,12 +1605,12 @@ static int change_mount_flags(struct vfs
   * on it - tough luck.
   */
  static int do_remount(struct path *path, int flags, int mnt_flags,
@@ -5545,7 +4663,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
                return -EPERM;
  
        if (!check_mnt(path->mnt))
-@@ -1577,7 +1638,7 @@ static int do_move_mount(struct path *pa
+@@ -1591,7 +1652,7 @@ static int do_move_mount(struct path *pa
        struct path old_path, parent_path;
        struct vfsmount *p;
        int err = 0;
@@ -5554,7 +4672,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
                return -EPERM;
        if (!old_name || !*old_name)
                return -EINVAL;
-@@ -1659,7 +1720,7 @@ static int do_new_mount(struct path *pat
+@@ -1673,7 +1734,7 @@ static int do_new_mount(struct path *pat
                return -EINVAL;
  
        /* we need capabilities... */
@@ -5563,7 +4681,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
                return -EPERM;
  
        mnt = do_kern_mount(type, flags, name, data);
-@@ -1904,6 +1965,7 @@ long do_mount(char *dev_name, char *dir_
+@@ -1918,6 +1979,7 @@ long do_mount(char *dev_name, char *dir_
        struct path path;
        int retval = 0;
        int mnt_flags = 0;
@@ -5571,9 +4689,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
  
        /* Discard magic */
        if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
-@@ -1919,6 +1981,12 @@ long do_mount(char *dev_name, char *dir_
-       if (data_page)
-               ((char *)data_page)[PAGE_SIZE - 1] = 0;
+@@ -1937,6 +1999,12 @@ long do_mount(char *dev_name, char *dir_
+       if (!(flags & MS_NOATIME))
+               mnt_flags |= MNT_RELATIME;
  
 +      if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
 +              /* FIXME: bind and re-mounts get the tag flag? */
@@ -5584,16 +4702,16 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
        /* Separate the per-mountpoint flags */
        if (flags & MS_NOSUID)
                mnt_flags |= MNT_NOSUID;
-@@ -1935,6 +2003,8 @@ long do_mount(char *dev_name, char *dir_
+@@ -1953,6 +2021,8 @@ long do_mount(char *dev_name, char *dir_
        if (flags & MS_RDONLY)
                mnt_flags |= MNT_READONLY;
  
 +      if (!capable(CAP_SYS_ADMIN))
 +              mnt_flags |= MNT_NODEV;
        flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
-                  MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
-@@ -1950,9 +2020,9 @@ long do_mount(char *dev_name, char *dir_
+                  MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
+                  MS_STRICTATIME);
+@@ -1969,9 +2039,9 @@ long do_mount(char *dev_name, char *dir_
  
        if (flags & MS_REMOUNT)
                retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
@@ -5605,7 +4723,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
        else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
                retval = do_change_type(&path, flags);
        else if (flags & MS_MOVE)
-@@ -2021,6 +2091,7 @@ static struct mnt_namespace *dup_mnt_ns(
+@@ -2040,6 +2110,7 @@ static struct mnt_namespace *dup_mnt_ns(
                q = next_mnt(q, new_ns->root);
        }
        up_write(&namespace_sem);
@@ -5613,7 +4731,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
  
        if (rootmnt)
                mntput(rootmnt);
-@@ -2147,9 +2218,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
+@@ -2166,9 +2237,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
        down_write(&namespace_sem);
        mutex_lock(&old.dentry->d_inode->i_mutex);
        error = -EINVAL;
@@ -5626,17 +4744,17 @@ diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14
                goto out2;
        if (!check_mnt(root.mnt))
                goto out2;
-@@ -2288,5 +2360,6 @@ void __put_mnt_ns(struct mnt_namespace *
+@@ -2307,5 +2379,6 @@ void __put_mnt_ns(struct mnt_namespace *
        spin_unlock(&vfsmount_lock);
        up_write(&namespace_sem);
        release_mounts(&umount_list);
 +      atomic_dec(&vs_global_mnt_ns);
        kfree(ns);
  }
-diff -NurpP --minimal linux-2.6.29.4/fs/nfs/client.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/client.c
---- linux-2.6.29.4/fs/nfs/client.c     2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/client.c       2009-03-24 14:48:35.000000000 +0100
-@@ -696,6 +696,9 @@ static int nfs_init_server_rpcclient(str
+diff -NurpP --minimal linux-2.6.30.1/fs/nfs/client.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/client.c
+--- linux-2.6.30.1/fs/nfs/client.c     2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/client.c  2009-07-04 01:11:39.000000000 +0200
+@@ -689,6 +689,9 @@ static int nfs_init_server_rpcclient(str
        if (server->flags & NFS_MOUNT_SOFT)
                server->client->cl_softrtry = 1;
  
@@ -5646,7 +4764,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/client.c linux-2.6.29.4-vs2.3.0.36.1
        return 0;
  }
  
-@@ -862,6 +865,10 @@ static void nfs_server_set_fsinfo(struct
+@@ -856,6 +859,10 @@ static void nfs_server_set_fsinfo(struct
                server->acdirmin = server->acdirmax = 0;
        }
  
@@ -5657,9 +4775,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/client.c linux-2.6.29.4-vs2.3.0.36.1
        server->maxfilesize = fsinfo->maxfilesize;
  
        /* We're airborne Set socket buffersize */
-diff -NurpP --minimal linux-2.6.29.4/fs/nfs/dir.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/dir.c
---- linux-2.6.29.4/fs/nfs/dir.c        2009-05-23 23:16:52.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/dir.c  2009-05-23 23:19:11.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/fs/nfs/dir.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/dir.c
+--- linux-2.6.30.1/fs/nfs/dir.c        2009-06-11 17:13:05.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/dir.c     2009-07-04 01:11:39.000000000 +0200
 @@ -34,6 +34,7 @@
  #include <linux/namei.h>
  #include <linux/mount.h>
@@ -5676,9 +4794,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/dir.c linux-2.6.29.4-vs2.3.0.36.14/f
  no_entry:
        res = d_materialise_unique(dentry, inode);
        if (res != NULL) {
-diff -NurpP --minimal linux-2.6.29.4/fs/nfs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/inode.c
---- linux-2.6.29.4/fs/nfs/inode.c      2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/inode.c        2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/nfs/inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/inode.c
+--- linux-2.6.30.1/fs/nfs/inode.c      2009-06-11 17:13:06.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/inode.c   2009-07-04 02:07:17.000000000 +0200
 @@ -37,6 +37,7 @@
  #include <linux/vfs.h>
  #include <linux/inet.h>
@@ -5687,20 +4805,51 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/inode.c linux-2.6.29.4-vs2.3.0.36.14
  
  #include <asm/system.h>
  #include <asm/uaccess.h>
-@@ -313,8 +314,10 @@ nfs_fhget(struct super_block *sb, struct
-                       nfsi->change_attr = fattr->change_attr;
-               inode->i_size = nfs_size_to_loff_t(fattr->size);
-               inode->i_nlink = fattr->nlink;
--              inode->i_uid = fattr->uid;
--              inode->i_gid = fattr->gid;
-+              inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
-+              inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
-+              inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
-+                                       /* maybe fattr->xid someday */
-               if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
-                       /*
-                        * report the blocks in 512byte units
-@@ -462,6 +465,8 @@ void nfs_setattr_update_inode(struct ino
+@@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
+       if (inode->i_state & I_NEW) {
+               struct nfs_inode *nfsi = NFS_I(inode);
+               unsigned long now = jiffies;
++              uid_t uid;
++              gid_t gid;
+               /* We set i_ino for the few things that still rely on it,
+                * such as stat(2) */
+@@ -322,8 +325,8 @@ nfs_fhget(struct super_block *sb, struct
+               nfsi->change_attr = 0;
+               inode->i_size = 0;
+               inode->i_nlink = 0;
+-              inode->i_uid = -2;
+-              inode->i_gid = -2;
++              uid = -2;
++              gid = -2;
+               inode->i_blocks = 0;
+               memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
+@@ -342,9 +345,9 @@ nfs_fhget(struct super_block *sb, struct
+               if (fattr->valid & NFS_ATTR_FATTR_NLINK)
+                       inode->i_nlink = fattr->nlink;
+               if (fattr->valid & NFS_ATTR_FATTR_OWNER)
+-                      inode->i_uid = fattr->uid;
++                      uid = fattr->uid;
+               if (fattr->valid & NFS_ATTR_FATTR_GROUP)
+-                      inode->i_gid = fattr->gid;
++                      gid = fattr->gid;
+               if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
+                       inode->i_blocks = fattr->du.nfs2.blocks;
+               if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
+@@ -353,6 +356,11 @@ nfs_fhget(struct super_block *sb, struct
+                        */
+                       inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
+               }
++              inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
++              inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
++              inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
++                              /* maybe fattr->xid someday */
++
+               nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
+               nfsi->attrtimeo_timestamp = now;
+               nfsi->access_cache = RB_ROOT;
+@@ -493,6 +501,8 @@ void nfs_setattr_update_inode(struct ino
                        inode->i_uid = attr->ia_uid;
                if ((attr->ia_valid & ATTR_GID) != 0)
                        inode->i_gid = attr->ia_gid;
@@ -5709,7 +4858,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/inode.c linux-2.6.29.4-vs2.3.0.36.14
                NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
                spin_unlock(&inode->i_lock);
        }
-@@ -850,6 +855,9 @@ static int nfs_check_inode_attributes(st
+@@ -903,6 +913,9 @@ static int nfs_check_inode_attributes(st
        struct nfs_inode *nfsi = NFS_I(inode);
        loff_t cur_size, new_isize;
        unsigned long invalid = 0;
@@ -5719,25 +4868,28 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/inode.c linux-2.6.29.4-vs2.3.0.36.14
  
  
        /* Has the inode gone and changed behind our back? */
-@@ -871,10 +879,15 @@ static int nfs_check_inode_attributes(st
-       if (cur_size != new_isize && nfsi->npages == 0)
-               invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
+@@ -926,13 +939,18 @@ static int nfs_check_inode_attributes(st
+                       invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
+       }
  
 +      uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
 +      gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
 +      tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
 +
        /* Have any file permissions changed? */
-       if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
--                      || inode->i_uid != fattr->uid
--                      || inode->i_gid != fattr->gid)
-+                      || inode->i_uid != uid
-+                      || inode->i_gid != gid
-+                      || inode->i_tag != tag)
+       if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
+               invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
+-      if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
++      if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
+               invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
+-      if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
++      if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
                invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
++              /* maybe check for tag too? */
  
        /* Has the link count changed? */
-@@ -1073,6 +1086,9 @@ static int nfs_update_inode(struct inode
+       if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
+@@ -1146,6 +1164,9 @@ static int nfs_update_inode(struct inode
        loff_t cur_isize, new_isize;
        unsigned long invalid = 0;
        unsigned long now = jiffies;
@@ -5747,38 +4899,46 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/inode.c linux-2.6.29.4-vs2.3.0.36.14
  
        dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
                        __func__, inode->i_sb->s_id, inode->i_ino,
-@@ -1146,9 +1162,14 @@ static int nfs_update_inode(struct inode
-       memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
-       nfsi->change_attr = fattr->change_attr;
+@@ -1234,6 +1255,9 @@ static int nfs_update_inode(struct inode
+               }
+       }
  
 +      uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
 +      gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
 +      tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
-+
-       if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
--          inode->i_uid != fattr->uid ||
--          inode->i_gid != fattr->gid)
-+          inode->i_uid != uid ||
-+          inode->i_gid != gid ||
-+          inode->i_tag != tag)
-               invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
-       if (inode->i_nlink != fattr->nlink)
-@@ -1156,8 +1177,9 @@ static int nfs_update_inode(struct inode
-       inode->i_mode = fattr->mode;
-       inode->i_nlink = fattr->nlink;
--      inode->i_uid = fattr->uid;
--      inode->i_gid = fattr->gid;
+       if (fattr->valid & NFS_ATTR_FATTR_ATIME)
+               memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
+@@ -1245,18 +1269,22 @@ static int nfs_update_inode(struct inode
+               }
+       }
+       if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
+-              if (inode->i_uid != fattr->uid) {
++              if (uid != fattr->uid) {
+                       invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
+-                      inode->i_uid = fattr->uid;
++                      uid = fattr->uid;
+               }
+       }
+       if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
+-              if (inode->i_gid != fattr->gid) {
++              if (gid != fattr->gid) {
+                       invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
+-                      inode->i_gid = fattr->gid;
++                      gid = fattr->gid;
+               }
+       }
 +      inode->i_uid = uid;
 +      inode->i_gid = gid;
 +      inode->i_tag = tag;
-       if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
-               /*
-diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/nfs3xdr.c
---- linux-2.6.29.4/fs/nfs/nfs3xdr.c    2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/nfs3xdr.c      2009-04-30 12:14:53.000000000 +0200
++
+       if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
+               if (inode->i_nlink != fattr->nlink) {
+                       invalid |= NFS_INO_INVALID_ATTR;
+diff -NurpP --minimal linux-2.6.30.1/fs/nfs/nfs3xdr.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/nfs3xdr.c
+--- linux-2.6.30.1/fs/nfs/nfs3xdr.c    2009-06-11 17:13:06.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/nfs3xdr.c 2009-07-04 01:11:39.000000000 +0200
 @@ -22,6 +22,7 @@
  #include <linux/nfs3.h>
  #include <linux/nfs_fs.h>
@@ -5787,7 +4947,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.
  #include "internal.h"
  
  #define NFSDBG_FACILITY               NFSDBG_XDR
-@@ -182,7 +183,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
+@@ -177,7 +178,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
  }
  
  static inline __be32 *
@@ -5796,7 +4956,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.
  {
        if (attr->ia_valid & ATTR_MODE) {
                *p++ = xdr_one;
-@@ -190,15 +191,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
+@@ -185,15 +186,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
        } else {
                *p++ = xdr_zero;
        }
@@ -5818,7 +4978,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.
        } else {
                *p++ = xdr_zero;
        }
-@@ -283,7 +286,8 @@ static int
+@@ -280,7 +283,8 @@ static int
  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
  {
        p = xdr_encode_fhandle(p, args->fh);
@@ -5828,7 +4988,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.
        *p++ = htonl(args->guard);
        if (args->guard)
                p = xdr_encode_time3(p, &args->guardtime);
-@@ -388,7 +392,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
+@@ -385,7 +389,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
                *p++ = args->verifier[0];
                *p++ = args->verifier[1];
        } else
@@ -5838,7 +4998,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.
  
        req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
        return 0;
-@@ -402,7 +407,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
+@@ -399,7 +404,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
  {
        p = xdr_encode_fhandle(p, args->fh);
        p = xdr_encode_array(p, args->name, args->len);
@@ -5848,7 +5008,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.
        req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
        return 0;
  }
-@@ -415,7 +421,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
+@@ -412,7 +418,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
  {
        p = xdr_encode_fhandle(p, args->fromfh);
        p = xdr_encode_array(p, args->fromname, args->fromlen);
@@ -5858,7 +5018,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.
        *p++ = htonl(args->pathlen);
        req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  
-@@ -433,7 +440,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
+@@ -430,7 +437,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
        p = xdr_encode_fhandle(p, args->fh);
        p = xdr_encode_array(p, args->name, args->len);
        *p++ = htonl(args->type);
@@ -5868,9 +5028,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.
        if (args->type == NF3CHR || args->type == NF3BLK) {
                *p++ = htonl(MAJOR(args->rdev));
                *p++ = htonl(MINOR(args->rdev));
-diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfsroot.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/nfsroot.c
---- linux-2.6.29.4/fs/nfs/nfsroot.c    2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/nfsroot.c      2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/nfs/nfsroot.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/nfsroot.c
+--- linux-2.6.30.1/fs/nfs/nfsroot.c    2009-06-11 17:13:06.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/nfsroot.c 2009-07-04 01:11:39.000000000 +0200
 @@ -119,12 +119,12 @@ static int mount_port __initdata = 0;            /
  enum {
        /* Options that take integer arguments */
@@ -5886,7 +5046,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfsroot.c linux-2.6.29.4-vs2.3.0.36.
        /* Error token */
        Opt_err
  };
-@@ -161,6 +161,9 @@ static match_table_t __initconst tokens 
+@@ -161,6 +161,9 @@ static const match_table_t tokens __init
        {Opt_tcp, "tcp"},
        {Opt_acl, "acl"},
        {Opt_noacl, "noacl"},
@@ -5917,9 +5077,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfsroot.c linux-2.6.29.4-vs2.3.0.36.
                        default:
                                printk(KERN_WARNING "Root-NFS: unknown "
                                        "option: %s\n", p);
-diff -NurpP --minimal linux-2.6.29.4/fs/nfs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/super.c
---- linux-2.6.29.4/fs/nfs/super.c      2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/super.c        2009-03-24 16:02:06.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/nfs/super.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/super.c
+--- linux-2.6.30.1/fs/nfs/super.c      2009-06-11 17:13:06.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfs/super.c   2009-07-04 01:11:39.000000000 +0200
 @@ -51,6 +51,7 @@
  #include <linux/nfs_xdr.h>
  #include <linux/magic.h>
@@ -5928,7 +5088,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/super.c linux-2.6.29.4-vs2.3.0.36.14
  
  #include <asm/system.h>
  #include <asm/uaccess.h>
-@@ -517,6 +518,7 @@ static void nfs_show_mount_options(struc
+@@ -523,6 +524,7 @@ static void nfs_show_mount_options(struc
                { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
                { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
                { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
@@ -5936,9 +5096,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfs/super.c linux-2.6.29.4-vs2.3.0.36.14
                { 0, NULL, NULL }
        };
        const struct proc_nfs_info *nfs_infop;
-diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/auth.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/auth.c
---- linux-2.6.29.4/fs/nfsd/auth.c      2009-03-24 14:22:26.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/auth.c        2009-03-24 16:09:39.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/nfsd/auth.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfsd/auth.c
+--- linux-2.6.30.1/fs/nfsd/auth.c      2009-03-24 14:22:26.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfsd/auth.c   2009-07-04 01:11:39.000000000 +0200
 @@ -10,6 +10,7 @@
  #include <linux/sunrpc/svcauth.h>
  #include <linux/nfsd/nfsd.h>
@@ -5957,26 +5117,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/auth.c linux-2.6.29.4-vs2.3.0.36.14
  
        rqgi = rqstp->rq_cred.cr_group_info;
  
-@@ -69,7 +73,7 @@ int nfsd_setuser(struct svc_rqst *rqstp,
-               }
-       } else {
-               gi = get_group_info(rqgi);
--      }
-+      }
-       if (new->fsuid == (uid_t) -1)
-               new->fsuid = exp->ex_anon_uid;
-@@ -94,6 +98,6 @@ oom:
-       ret = -ENOMEM;
- error:
-       abort_creds(new);
--      return ret;
-+      return ret;
- }
-diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfs3xdr.c
---- linux-2.6.29.4/fs/nfsd/nfs3xdr.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfs3xdr.c     2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/nfsd/nfs3xdr.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfsd/nfs3xdr.c
+--- linux-2.6.30.1/fs/nfsd/nfs3xdr.c   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfsd/nfs3xdr.c        2009-07-04 01:11:39.000000000 +0200
 @@ -21,6 +21,7 @@
  #include <linux/sunrpc/svc.h>
  #include <linux/nfsd/nfsd.h>
@@ -6027,10 +5170,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36
        if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
                p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
        } else {
-diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/nfs4xdr.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfs4xdr.c
---- linux-2.6.29.4/fs/nfsd/nfs4xdr.c   2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfs4xdr.c     2009-05-23 23:19:11.000000000 +0200
-@@ -56,6 +56,7 @@
+diff -NurpP --minimal linux-2.6.30.1/fs/nfsd/nfs4xdr.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfsd/nfs4xdr.c
+--- linux-2.6.30.1/fs/nfsd/nfs4xdr.c   2009-06-11 17:13:06.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfsd/nfs4xdr.c        2009-07-04 01:11:39.000000000 +0200
+@@ -57,6 +57,7 @@
  #include <linux/nfs4_acl.h>
  #include <linux/sunrpc/gss_api.h>
  #include <linux/sunrpc/svcauth_gss.h>
@@ -6038,7 +5181,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/nfs4xdr.c linux-2.6.29.4-vs2.3.0.36
  
  #define NFSDDBG_FACILITY              NFSDDBG_XDR
  
-@@ -1714,14 +1715,18 @@ out_acl:
+@@ -2078,14 +2079,18 @@ out_acl:
                WRITE32(stat.nlink);
        }
        if (bmval1 & FATTR4_WORD1_OWNER) {
@@ -6059,9 +5202,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/nfs4xdr.c linux-2.6.29.4-vs2.3.0.36
                if (status == nfserr_resource)
                        goto out_resource;
                if (status)
-diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/nfsxdr.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfsxdr.c
---- linux-2.6.29.4/fs/nfsd/nfsxdr.c    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfsxdr.c      2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/nfsd/nfsxdr.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfsd/nfsxdr.c
+--- linux-2.6.30.1/fs/nfsd/nfsxdr.c    2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/nfsd/nfsxdr.c 2009-07-04 01:11:39.000000000 +0200
 @@ -15,6 +15,7 @@
  #include <linux/nfsd/nfsd.h>
  #include <linux/nfsd/xdr.h>
@@ -6110,9 +5253,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/nfsxdr.c linux-2.6.29.4-vs2.3.0.36.
  
        if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
                *p++ = htonl(NFS_MAXPATHLEN);
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/dlm/dlmfs.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlm/dlmfs.c
---- linux-2.6.29.4/fs/ocfs2/dlm/dlmfs.c        2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlm/dlmfs.c  2009-03-24 16:10:48.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/dlm/dlmfs.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/dlm/dlmfs.c
+--- linux-2.6.30.1/fs/ocfs2/dlm/dlmfs.c        2009-03-24 14:22:27.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/dlm/dlmfs.c     2009-07-04 01:11:39.000000000 +0200
 @@ -43,6 +43,7 @@
  #include <linux/init.h>
  #include <linux/string.h>
@@ -6137,10 +5280,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/dlm/dlmfs.c linux-2.6.29.4-vs2.3.0
        inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
        inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/dlmglue.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlmglue.c
---- linux-2.6.29.4/fs/ocfs2/dlmglue.c  2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlmglue.c    2009-03-24 14:48:35.000000000 +0100
-@@ -1885,6 +1885,7 @@ static void __ocfs2_stuff_meta_lvb(struc
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/dlmglue.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/dlmglue.c
+--- linux-2.6.30.1/fs/ocfs2/dlmglue.c  2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/dlmglue.c       2009-07-04 01:11:39.000000000 +0200
+@@ -1900,6 +1900,7 @@ static void __ocfs2_stuff_meta_lvb(struc
        lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
        lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
        lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
@@ -6148,7 +5291,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/dlmglue.c linux-2.6.29.4-vs2.3.0.3
        lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
        lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
        lvb->lvb_iatime_packed  =
-@@ -1939,6 +1940,7 @@ static void ocfs2_refresh_inode_from_lvb
+@@ -1954,6 +1955,7 @@ static void ocfs2_refresh_inode_from_lvb
  
        inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
        inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
@@ -6156,9 +5299,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/dlmglue.c linux-2.6.29.4-vs2.3.0.3
        inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
        inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
        ocfs2_unpack_timespec(&inode->i_atime,
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/dlmglue.h linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlmglue.h
---- linux-2.6.29.4/fs/ocfs2/dlmglue.h  2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlmglue.h    2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/dlmglue.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/dlmglue.h
+--- linux-2.6.30.1/fs/ocfs2/dlmglue.h  2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/dlmglue.h       2009-07-04 01:11:39.000000000 +0200
 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
        __be16       lvb_inlink;
        __be32       lvb_iattr;
@@ -6169,9 +5312,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/dlmglue.h linux-2.6.29.4-vs2.3.0.3
  };
  
  #define OCFS2_QINFO_LVB_VERSION 1
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/file.c
---- linux-2.6.29.4/fs/ocfs2/file.c     2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/file.c       2009-05-23 23:19:11.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/file.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/file.c
+--- linux-2.6.30.1/fs/ocfs2/file.c     2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/file.c  2009-07-04 01:11:39.000000000 +0200
 @@ -911,13 +911,15 @@ int ocfs2_setattr(struct dentry *dentry,
                mlog(0, "uid change: %d\n", attr->ia_uid);
        if (attr->ia_valid & ATTR_GID)
@@ -6197,9 +5340,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/file.c linux-2.6.29.4-vs2.3.0.36.1
  };
  
  const struct inode_operations ocfs2_special_file_iops = {
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/inode.c
---- linux-2.6.29.4/fs/ocfs2/inode.c    2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/inode.c      2009-03-24 16:11:11.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/inode.c
+--- linux-2.6.30.1/fs/ocfs2/inode.c    2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/inode.c 2009-07-04 01:11:39.000000000 +0200
 @@ -29,6 +29,7 @@
  #include <linux/highmem.h>
  #include <linux/pagemap.h>
@@ -6208,7 +5351,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.c linux-2.6.29.4-vs2.3.0.36.
  
  #include <asm/byteorder.h>
  
-@@ -44,6 +45,7 @@
+@@ -45,6 +46,7 @@
  #include "file.h"
  #include "heartbeat.h"
  #include "inode.h"
@@ -6216,7 +5359,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.c linux-2.6.29.4-vs2.3.0.36.
  #include "journal.h"
  #include "namei.h"
  #include "suballoc.h"
-@@ -77,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
+@@ -78,11 +80,13 @@ void ocfs2_set_inode_flags(struct inode 
  {
        unsigned int flags = OCFS2_I(inode)->ip_attr;
  
@@ -6231,7 +5374,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.c linux-2.6.29.4-vs2.3.0.36.
  
        if (flags & OCFS2_SYNC_FL)
                inode->i_flags |= S_SYNC;
-@@ -91,25 +95,85 @@ void ocfs2_set_inode_flags(struct inode 
+@@ -92,25 +96,85 @@ void ocfs2_set_inode_flags(struct inode 
                inode->i_flags |= S_NOATIME;
        if (flags & OCFS2_DIRSYNC_FL)
                inode->i_flags |= S_DIRSYNC;
@@ -6320,8 +5463,8 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.c linux-2.6.29.4-vs2.3.0.36.
 +      return status;
  }
  
- struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
-@@ -222,6 +286,8 @@ void ocfs2_populate_inode(struct inode *
+ struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
+@@ -234,6 +298,8 @@ void ocfs2_populate_inode(struct inode *
        struct super_block *sb;
        struct ocfs2_super *osb;
        int use_plocks = 1;
@@ -6330,7 +5473,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.c linux-2.6.29.4-vs2.3.0.36.
  
        mlog_entry("(0x%p, size:%llu)\n", inode,
                   (unsigned long long)le64_to_cpu(fe->i_size));
-@@ -253,8 +319,12 @@ void ocfs2_populate_inode(struct inode *
+@@ -265,8 +331,12 @@ void ocfs2_populate_inode(struct inode *
        inode->i_generation = le32_to_cpu(fe->i_generation);
        inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
        inode->i_mode = le16_to_cpu(fe->i_mode);
@@ -6345,52 +5488,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.c linux-2.6.29.4-vs2.3.0.36.
  
        /* Fast symlinks will have i_size but no allocated clusters. */
        if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
-@@ -1206,8 +1276,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
-       fe->i_size = cpu_to_le64(i_size_read(inode));
-       fe->i_links_count = cpu_to_le16(inode->i_nlink);
--      fe->i_uid = cpu_to_le32(inode->i_uid);
--      fe->i_gid = cpu_to_le32(inode->i_gid);
-+      fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
-+              inode->i_uid, inode->i_tag));
-+      fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
-+              inode->i_gid, inode->i_tag));
-+      /* i_tag = = cpu_to_le16(inode->i_tag); */
-       fe->i_mode = cpu_to_le16(inode->i_mode);
-       fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
-       fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
-@@ -1235,16 +1308,25 @@ leave:
- void ocfs2_refresh_inode(struct inode *inode,
-                        struct ocfs2_dinode *fe)
- {
-+      uid_t uid;
-+      gid_t gid;
-+
-       spin_lock(&OCFS2_I(inode)->ip_lock);
-       OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
-       OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
-+      /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
-+         OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
-       OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features);
-       ocfs2_set_inode_flags(inode);
-       i_size_write(inode, le64_to_cpu(fe->i_size));
-       inode->i_nlink = le16_to_cpu(fe->i_links_count);
--      inode->i_uid = le32_to_cpu(fe->i_uid);
--      inode->i_gid = le32_to_cpu(fe->i_gid);
-+      uid = le32_to_cpu(fe->i_uid);
-+      gid = le32_to_cpu(fe->i_gid);
-+      inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
-+      inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
-+      inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
-+              /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
-       inode->i_mode = le16_to_cpu(fe->i_mode);
-       if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
-               inode->i_blocks = 0;
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.h linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/inode.h
---- linux-2.6.29.4/fs/ocfs2/inode.h    2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/inode.h      2009-03-24 14:48:35.000000000 +0100
-@@ -147,6 +147,7 @@ struct buffer_head *ocfs2_bread(struct i
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/inode.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/inode.h
+--- linux-2.6.30.1/fs/ocfs2/inode.h    2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/inode.h 2009-07-04 01:11:39.000000000 +0200
+@@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
  
  void ocfs2_set_inode_flags(struct inode *inode);
  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
@@ -6398,9 +5499,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.h linux-2.6.29.4-vs2.3.0.36.
  
  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
  {
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ioctl.c
---- linux-2.6.29.4/fs/ocfs2/ioctl.c    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ioctl.c      2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/ioctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/ioctl.c
+--- linux-2.6.30.1/fs/ocfs2/ioctl.c    2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/ioctl.c 2009-07-04 01:11:39.000000000 +0200
 @@ -42,7 +42,7 @@ static int ocfs2_get_inode_attr(struct i
        return status;
  }
@@ -6422,9 +5523,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ioctl.c linux-2.6.29.4-vs2.3.0.36.
        handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ioctl.h linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ioctl.h
---- linux-2.6.29.4/fs/ocfs2/ioctl.h    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ioctl.h      2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/ioctl.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/ioctl.h
+--- linux-2.6.30.1/fs/ocfs2/ioctl.h    2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/ioctl.h 2009-07-04 01:11:39.000000000 +0200
 @@ -10,6 +10,9 @@
  #ifndef OCFS2_IOCTL_H
  #define OCFS2_IOCTL_H
@@ -6435,9 +5536,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ioctl.h linux-2.6.29.4-vs2.3.0.36.
  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
  
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/namei.c
---- linux-2.6.29.4/fs/ocfs2/namei.c    2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/namei.c      2009-03-25 01:04:31.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/namei.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/namei.c
+--- linux-2.6.30.1/fs/ocfs2/namei.c    2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/namei.c 2009-07-06 17:33:52.000000000 +0200
 @@ -41,6 +41,7 @@
  #include <linux/slab.h>
  #include <linux/highmem.h>
@@ -6446,15 +5547,15 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/namei.c linux-2.6.29.4-vs2.3.0.36.
  
  #define MLOG_MASK_PREFIX ML_NAMEI
  #include <cluster/masklog.h>
-@@ -462,6 +463,7 @@ static int ocfs2_mknod_locked(struct ocf
-       struct ocfs2_extent_list *fel;
+@@ -478,6 +479,7 @@ static int ocfs2_mknod_locked(struct ocf
        u64 fe_blkno = 0;
        u16 suballoc_bit;
+       u16 feat;
 +      tag_t tag;
  
        mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry,
                   inode->i_mode, (unsigned long)dev, dentry->d_name.len,
-@@ -508,8 +510,11 @@ static int ocfs2_mknod_locked(struct ocf
+@@ -524,8 +526,11 @@ static int ocfs2_mknod_locked(struct ocf
        fe->i_blkno = cpu_to_le64(fe_blkno);
        fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
        fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
@@ -6468,7 +5569,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/namei.c linux-2.6.29.4-vs2.3.0.36.
        fe->i_mode = cpu_to_le16(inode->i_mode);
        if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
                fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
-@@ -2025,6 +2030,7 @@ const struct inode_operations ocfs2_dir_
+@@ -2037,6 +2042,7 @@ const struct inode_operations ocfs2_dir_
        .rename         = ocfs2_rename,
        .setattr        = ocfs2_setattr,
        .getattr        = ocfs2_getattr,
@@ -6476,10 +5577,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/namei.c linux-2.6.29.4-vs2.3.0.36.
        .permission     = ocfs2_permission,
        .setxattr       = generic_setxattr,
        .getxattr       = generic_getxattr,
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ocfs2_fs.h linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ocfs2_fs.h
---- linux-2.6.29.4/fs/ocfs2/ocfs2_fs.h 2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ocfs2_fs.h   2009-03-24 14:48:35.000000000 +0100
-@@ -219,18 +219,23 @@
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/ocfs2_fs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/ocfs2_fs.h
+--- linux-2.6.30.1/fs/ocfs2/ocfs2_fs.h 2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/ocfs2_fs.h      2009-07-04 01:11:39.000000000 +0200
+@@ -225,18 +225,23 @@
  #define OCFS2_INDEXED_DIR_FL  (0x0008)
  
  /* Inode attributes, keep in sync with EXT2 */
@@ -6514,9 +5615,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ocfs2_fs.h linux-2.6.29.4-vs2.3.0.
  
  /*
   * Extent record flags (e_node.leaf.flags)
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ocfs2.h linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ocfs2.h
---- linux-2.6.29.4/fs/ocfs2/ocfs2.h    2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ocfs2.h      2009-03-24 16:18:22.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/ocfs2.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/ocfs2.h
+--- linux-2.6.30.1/fs/ocfs2/ocfs2.h    2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/ocfs2.h 2009-07-04 01:11:39.000000000 +0200
 @@ -199,6 +199,7 @@ enum ocfs2_mount_options
        OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */
        OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */
@@ -6525,9 +5626,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ocfs2.h linux-2.6.29.4-vs2.3.0.36.
  };
  
  #define OCFS2_OSB_SOFT_RO     0x0001
-diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/super.c
---- linux-2.6.29.4/fs/ocfs2/super.c    2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/super.c      2009-03-24 16:19:44.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/ocfs2/super.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/super.c
+--- linux-2.6.30.1/fs/ocfs2/super.c    2009-07-03 20:12:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/ocfs2/super.c 2009-07-04 01:11:39.000000000 +0200
 @@ -172,6 +172,7 @@ enum {
        Opt_noacl,
        Opt_usrquota,
@@ -6546,7 +5647,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/super.c linux-2.6.29.4-vs2.3.0.36.
        {Opt_err, NULL}
  };
  
-@@ -436,6 +440,13 @@ static int ocfs2_remount(struct super_bl
+@@ -604,6 +608,13 @@ static int ocfs2_remount(struct super_bl
                goto out;
        }
  
@@ -6560,7 +5661,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/super.c linux-2.6.29.4-vs2.3.0.36.
        if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
            (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
                ret = -EINVAL;
-@@ -950,6 +961,9 @@ static int ocfs2_fill_super(struct super
+@@ -1128,6 +1139,9 @@ static int ocfs2_fill_super(struct super
  
        ocfs2_complete_mount_recovery(osb);
  
@@ -6570,7 +5671,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/super.c linux-2.6.29.4-vs2.3.0.36.
        if (ocfs2_mount_local(osb))
                snprintf(nodestr, sizeof(nodestr), "local");
        else
-@@ -1208,6 +1222,20 @@ static int ocfs2_parse_options(struct su
+@@ -1386,6 +1400,20 @@ static int ocfs2_parse_options(struct su
                        printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
                        break;
  #endif
@@ -6591,13 +5692,13 @@ diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/super.c linux-2.6.29.4-vs2.3.0.36.
                default:
                        mlog(ML_ERROR,
                             "Unrecognized mount option \"%s\" "
-diff -NurpP --minimal linux-2.6.29.4/fs/open.c linux-2.6.29.4-vs2.3.0.36.14/fs/open.c
---- linux-2.6.29.4/fs/open.c   2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/open.c     2009-03-24 14:48:35.000000000 +0100
-@@ -29,22 +29,31 @@
- #include <linux/rcupdate.h>
+diff -NurpP --minimal linux-2.6.30.1/fs/open.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/open.c
+--- linux-2.6.30.1/fs/open.c   2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/open.c        2009-07-04 02:02:28.000000000 +0200
+@@ -30,22 +30,31 @@
  #include <linux/audit.h>
  #include <linux/falloc.h>
+ #include <linux/fs_struct.h>
 +#include <linux/vs_base.h>
 +#include <linux/vs_limit.h>
 +#include <linux/vs_dlimit.h>
@@ -6628,7 +5729,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/open.c linux-2.6.29.4-vs2.3.0.36.14/fs/o
        }
        return retval;
  }
-@@ -638,6 +647,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
+@@ -639,6 +648,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
        error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
        if (error)
                goto out;
@@ -6639,7 +5740,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/open.c linux-2.6.29.4-vs2.3.0.36.14/fs/o
        inode = path.dentry->d_inode;
  
        error = mnt_want_write(path.mnt);
-@@ -671,11 +684,11 @@ static int chown_common(struct dentry * 
+@@ -672,11 +685,11 @@ static int chown_common(struct dentry * 
        newattrs.ia_valid =  ATTR_CTIME;
        if (user != (uid_t) -1) {
                newattrs.ia_valid |= ATTR_UID;
@@ -6653,7 +5754,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/open.c linux-2.6.29.4-vs2.3.0.36.14/fs/o
        }
        if (!S_ISDIR(inode->i_mode))
                newattrs.ia_valid |=
-@@ -698,7 +711,11 @@ SYSCALL_DEFINE3(chown, const char __user
+@@ -699,7 +712,11 @@ SYSCALL_DEFINE3(chown, const char __user
        error = mnt_want_write(path.mnt);
        if (error)
                goto out_release;
@@ -6666,7 +5767,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/open.c linux-2.6.29.4-vs2.3.0.36.14/fs/o
        mnt_drop_write(path.mnt);
  out_release:
        path_put(&path);
-@@ -723,7 +740,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
+@@ -724,7 +741,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
        error = mnt_want_write(path.mnt);
        if (error)
                goto out_release;
@@ -6679,7 +5780,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/open.c linux-2.6.29.4-vs2.3.0.36.14/fs/o
        mnt_drop_write(path.mnt);
  out_release:
        path_put(&path);
-@@ -742,7 +763,11 @@ SYSCALL_DEFINE3(lchown, const char __use
+@@ -743,7 +764,11 @@ SYSCALL_DEFINE3(lchown, const char __use
        error = mnt_want_write(path.mnt);
        if (error)
                goto out_release;
@@ -6692,7 +5793,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/open.c linux-2.6.29.4-vs2.3.0.36.14/fs/o
        mnt_drop_write(path.mnt);
  out_release:
        path_put(&path);
-@@ -986,6 +1011,7 @@ static void __put_unused_fd(struct files
+@@ -987,6 +1012,7 @@ static void __put_unused_fd(struct files
        __FD_CLR(fd, fdt->open_fds);
        if (fd < files->next_fd)
                files->next_fd = fd;
@@ -6700,9 +5801,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/open.c linux-2.6.29.4-vs2.3.0.36.14/fs/o
  }
  
  void put_unused_fd(unsigned int fd)
-diff -NurpP --minimal linux-2.6.29.4/fs/proc/array.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/array.c
---- linux-2.6.29.4/fs/proc/array.c     2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/array.c       2009-05-10 23:42:01.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/fs/proc/array.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/array.c
+--- linux-2.6.30.1/fs/proc/array.c     2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/array.c  2009-07-04 01:11:39.000000000 +0200
 @@ -82,6 +82,8 @@
  #include <linux/pid_namespace.h>
  #include <linux/ptrace.h>
@@ -6828,19 +5929,19 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/array.c linux-2.6.29.4-vs2.3.0.36.1
        seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
-diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/base.c
---- linux-2.6.29.4/fs/proc/base.c      2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/base.c        2009-05-10 23:42:01.000000000 +0200
-@@ -80,6 +80,8 @@
- #include <linux/oom.h>
+diff -NurpP --minimal linux-2.6.30.1/fs/proc/base.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/base.c
+--- linux-2.6.30.1/fs/proc/base.c      2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/base.c   2009-07-04 02:07:58.000000000 +0200
+@@ -81,6 +81,8 @@
  #include <linux/elf.h>
  #include <linux/pid_namespace.h>
+ #include <linux/fs_struct.h>
 +#include <linux/vs_context.h>
 +#include <linux/vs_network.h>
  #include "internal.h"
  
  /* NOTE:
-@@ -1443,6 +1445,8 @@ static struct inode *proc_pid_make_inode
+@@ -1444,6 +1446,8 @@ static struct inode *proc_pid_make_inode
                inode->i_gid = cred->egid;
                rcu_read_unlock();
        }
@@ -6849,7 +5950,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
        security_task_to_inode(task, inode);
  
  out:
-@@ -1993,6 +1997,13 @@ static struct dentry *proc_pident_lookup
+@@ -1994,6 +1998,13 @@ static struct dentry *proc_pident_lookup
        if (!task)
                goto out_no_task;
  
@@ -6863,7 +5964,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
        /*
         * Yes, it does not scale. And it should not. Don't add
         * new entries into /proc/<tgid>/ without very good reasons.
-@@ -2378,7 +2389,7 @@ out_iput:
+@@ -2379,7 +2390,7 @@ out_iput:
  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
  {
        struct dentry *error;
@@ -6872,7 +5973,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
        const struct pid_entry *p, *last;
  
        error = ERR_PTR(-ENOENT);
-@@ -2468,6 +2479,9 @@ static int proc_pid_personality(struct s
+@@ -2469,6 +2480,9 @@ static int proc_pid_personality(struct s
  static const struct file_operations proc_task_operations;
  static const struct inode_operations proc_task_inode_operations;
  
@@ -6882,7 +5983,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
  static const struct pid_entry tgid_base_stuff[] = {
        DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
        DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
-@@ -2526,6 +2540,8 @@ static const struct pid_entry tgid_base_
+@@ -2527,6 +2541,8 @@ static const struct pid_entry tgid_base_
  #ifdef CONFIG_CGROUPS
        REG("cgroup",  S_IRUGO, proc_cgroup_operations),
  #endif
@@ -6891,7 +5992,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
        INF("oom_score",  S_IRUGO, proc_oom_score),
        REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
  #ifdef CONFIG_AUDITSYSCALL
-@@ -2541,6 +2557,7 @@ static const struct pid_entry tgid_base_
+@@ -2542,6 +2558,7 @@ static const struct pid_entry tgid_base_
  #ifdef CONFIG_TASK_IO_ACCOUNTING
        INF("io",       S_IRUGO, proc_tgid_io_accounting),
  #endif
@@ -6899,7 +6000,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
  };
  
  static int proc_tgid_base_readdir(struct file * filp,
-@@ -2737,7 +2754,7 @@ retry:
+@@ -2738,7 +2755,7 @@ retry:
        iter.task = NULL;
        pid = find_ge_pid(iter.tgid, ns);
        if (pid) {
@@ -6908,7 +6009,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
                iter.task = pid_task(pid, PIDTYPE_PID);
                /* What we to know is if the pid we have find is the
                 * pid of a thread_group_leader.  Testing for task
-@@ -2767,7 +2784,7 @@ static int proc_pid_fill_cache(struct fi
+@@ -2768,7 +2785,7 @@ static int proc_pid_fill_cache(struct fi
        struct tgid_iter iter)
  {
        char name[PROC_NUMBUF];
@@ -6917,7 +6018,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
        return proc_fill_cache(filp, dirent, filldir, name, len,
                                proc_pid_instantiate, iter.task, NULL);
  }
-@@ -2776,7 +2793,7 @@ static int proc_pid_fill_cache(struct fi
+@@ -2777,7 +2794,7 @@ static int proc_pid_fill_cache(struct fi
  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
  {
        unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
@@ -6926,7 +6027,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
        struct tgid_iter iter;
        struct pid_namespace *ns;
  
-@@ -2796,6 +2813,8 @@ int proc_pid_readdir(struct file * filp,
+@@ -2797,6 +2814,8 @@ int proc_pid_readdir(struct file * filp,
             iter.task;
             iter.tgid += 1, iter = next_tgid(ns, iter)) {
                filp->f_pos = iter.tgid + TGID_OFFSET;
@@ -6935,7 +6036,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
                if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
                        put_task_struct(iter.task);
                        goto out;
-@@ -2942,6 +2961,8 @@ static struct dentry *proc_task_lookup(s
+@@ -2943,6 +2962,8 @@ static struct dentry *proc_task_lookup(s
        tid = name_to_int(dentry);
        if (tid == ~0U)
                goto out;
@@ -6944,9 +6045,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14
  
        ns = dentry->d_sb->s_fs_info;
        rcu_read_lock();
-diff -NurpP --minimal linux-2.6.29.4/fs/proc/generic.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/generic.c
---- linux-2.6.29.4/fs/proc/generic.c   2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/generic.c     2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/proc/generic.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/generic.c
+--- linux-2.6.30.1/fs/proc/generic.c   2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/generic.c        2009-07-04 01:11:39.000000000 +0200
 @@ -20,6 +20,7 @@
  #include <linux/bitops.h>
  #include <linux/spinlock.h>
@@ -6955,7 +6056,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/generic.c linux-2.6.29.4-vs2.3.0.36
  #include <asm/uaccess.h>
  
  #include "internal.h"
-@@ -382,6 +383,8 @@ struct dentry *proc_lookup_de(struct pro
+@@ -425,6 +426,8 @@ struct dentry *proc_lookup_de(struct pro
        for (de = de->subdir; de ; de = de->next) {
                if (de->namelen != dentry->d_name.len)
                        continue;
@@ -6964,7 +6065,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/generic.c linux-2.6.29.4-vs2.3.0.36
                if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
                        unsigned int ino;
  
-@@ -390,6 +393,8 @@ struct dentry *proc_lookup_de(struct pro
+@@ -433,6 +436,8 @@ struct dentry *proc_lookup_de(struct pro
                        spin_unlock(&proc_subdir_lock);
                        error = -EINVAL;
                        inode = proc_get_inode(dir->i_sb, ino, de);
@@ -6973,7 +6074,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/generic.c linux-2.6.29.4-vs2.3.0.36
                        goto out_unlock;
                }
        }
-@@ -467,6 +472,8 @@ int proc_readdir_de(struct proc_dir_entr
+@@ -510,6 +515,8 @@ int proc_readdir_de(struct proc_dir_entr
  
                                /* filldir passes info to user space */
                                de_get(de);
@@ -6982,7 +6083,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/generic.c linux-2.6.29.4-vs2.3.0.36
                                spin_unlock(&proc_subdir_lock);
                                if (filldir(dirent, de->name, de->namelen, filp->f_pos,
                                            de->low_ino, de->mode >> 12) < 0) {
-@@ -474,6 +481,7 @@ int proc_readdir_de(struct proc_dir_entr
+@@ -517,6 +524,7 @@ int proc_readdir_de(struct proc_dir_entr
                                        goto out;
                                }
                                spin_lock(&proc_subdir_lock);
@@ -6990,7 +6091,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/generic.c linux-2.6.29.4-vs2.3.0.36
                                filp->f_pos++;
                                next = de->next;
                                de_put(de);
-@@ -588,6 +596,7 @@ static struct proc_dir_entry *__proc_cre
+@@ -631,6 +639,7 @@ static struct proc_dir_entry *__proc_cre
        ent->nlink = nlink;
        atomic_set(&ent->count, 1);
        ent->pde_users = 0;
@@ -6998,7 +6099,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/generic.c linux-2.6.29.4-vs2.3.0.36
        spin_lock_init(&ent->pde_unload_lock);
        ent->pde_unload_completion = NULL;
        INIT_LIST_HEAD(&ent->pde_openers);
-@@ -611,7 +620,8 @@ struct proc_dir_entry *proc_symlink(cons
+@@ -654,7 +663,8 @@ struct proc_dir_entry *proc_symlink(cons
                                kfree(ent->data);
                                kfree(ent);
                                ent = NULL;
@@ -7008,10 +6109,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/generic.c linux-2.6.29.4-vs2.3.0.36
                } else {
                        kfree(ent);
                        ent = NULL;
-diff -NurpP --minimal linux-2.6.29.4/fs/proc/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/inode.c
---- linux-2.6.29.4/fs/proc/inode.c     2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/inode.c       2009-03-24 14:48:35.000000000 +0100
-@@ -465,6 +465,8 @@ struct inode *proc_get_inode(struct supe
+diff -NurpP --minimal linux-2.6.30.1/fs/proc/inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/inode.c
+--- linux-2.6.30.1/fs/proc/inode.c     2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/inode.c  2009-07-04 01:11:39.000000000 +0200
+@@ -459,6 +459,8 @@ struct inode *proc_get_inode(struct supe
                        inode->i_uid = de->uid;
                        inode->i_gid = de->gid;
                }
@@ -7020,9 +6121,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/inode.c linux-2.6.29.4-vs2.3.0.36.1
                if (de->size)
                        inode->i_size = de->size;
                if (de->nlink)
-diff -NurpP --minimal linux-2.6.29.4/fs/proc/internal.h linux-2.6.29.4-vs2.3.0.36.14/fs/proc/internal.h
---- linux-2.6.29.4/fs/proc/internal.h  2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/internal.h    2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/proc/internal.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/internal.h
+--- linux-2.6.30.1/fs/proc/internal.h  2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/internal.h       2009-07-04 01:11:39.000000000 +0200
 @@ -10,6 +10,7 @@
   */
  
@@ -7059,9 +6160,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/internal.h linux-2.6.29.4-vs2.3.0.3
  static inline int proc_fd(struct inode *inode)
  {
        return PROC_I(inode)->fd;
-diff -NurpP --minimal linux-2.6.29.4/fs/proc/loadavg.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/loadavg.c
---- linux-2.6.29.4/fs/proc/loadavg.c   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/loadavg.c     2009-05-20 00:24:34.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/fs/proc/loadavg.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/loadavg.c
+--- linux-2.6.30.1/fs/proc/loadavg.c   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/loadavg.c        2009-07-04 01:11:39.000000000 +0200
 @@ -12,21 +12,37 @@
  
  static int loadavg_proc_show(struct seq_file *m, void *v)
@@ -7104,9 +6205,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/loadavg.c linux-2.6.29.4-vs2.3.0.36
                task_active_pid_ns(current)->last_pid);
        return 0;
  }
-diff -NurpP --minimal linux-2.6.29.4/fs/proc/meminfo.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/meminfo.c
---- linux-2.6.29.4/fs/proc/meminfo.c   2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/meminfo.c     2009-05-10 23:42:01.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/fs/proc/meminfo.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/meminfo.c
+--- linux-2.6.30.1/fs/proc/meminfo.c   2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/meminfo.c        2009-07-04 01:11:39.000000000 +0200
 @@ -41,7 +41,7 @@ static int meminfo_proc_show(struct seq_
  
        cached = global_page_state(NR_FILE_PAGES) -
@@ -7116,9 +6217,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/meminfo.c linux-2.6.29.4-vs2.3.0.36
                cached = 0;
  
        get_vmalloc_info(&vmi);
-diff -NurpP --minimal linux-2.6.29.4/fs/proc/root.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/root.c
---- linux-2.6.29.4/fs/proc/root.c      2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/root.c        2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/proc/root.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/root.c
+--- linux-2.6.30.1/fs/proc/root.c      2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/root.c   2009-07-04 01:11:39.000000000 +0200
 @@ -18,9 +18,14 @@
  #include <linux/bitops.h>
  #include <linux/mount.h>
@@ -7150,18 +6251,18 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/root.c linux-2.6.29.4-vs2.3.0.36.14
  };
  
  int pid_ns_prepare_proc(struct pid_namespace *ns)
-diff -NurpP --minimal linux-2.6.29.4/fs/proc/uptime.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/uptime.c
---- linux-2.6.29.4/fs/proc/uptime.c    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/uptime.c      2009-02-22 22:54:25.000000000 +0100
-@@ -2,6 +2,7 @@
- #include <linux/proc_fs.h>
+diff -NurpP --minimal linux-2.6.30.1/fs/proc/uptime.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/uptime.c
+--- linux-2.6.30.1/fs/proc/uptime.c    2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/proc/uptime.c 2009-07-04 02:10:28.000000000 +0200
+@@ -4,6 +4,7 @@
  #include <linux/sched.h>
+ #include <linux/seq_file.h>
  #include <linux/time.h>
 +#include <linux/vserver/cvirt.h>
  #include <asm/cputime.h>
  
- static int proc_calc_metrics(char *page, char **start, off_t off,
-@@ -29,6 +30,10 @@ static int uptime_read_proc(char *page, 
+ static int uptime_proc_show(struct seq_file *m, void *v)
+@@ -15,6 +16,10 @@ static int uptime_proc_show(struct seq_f
        do_posix_clock_monotonic_gettime(&uptime);
        monotonic_to_bootbased(&uptime);
        cputime_to_timespec(idletime, &idle);
@@ -7169,12 +6270,12 @@ diff -NurpP --minimal linux-2.6.29.4/fs/proc/uptime.c linux-2.6.29.4-vs2.3.0.36.
 +      if (vx_flags(VXF_VIRT_UPTIME, 0))
 +              vx_vsi_uptime(&uptime, &idle);
 +
-       len = sprintf(page, "%lu.%02lu %lu.%02lu\n",
+       seq_printf(m, "%lu.%02lu %lu.%02lu\n",
                        (unsigned long) uptime.tv_sec,
                        (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
-diff -NurpP --minimal linux-2.6.29.4/fs/quota.c linux-2.6.29.4-vs2.3.0.36.14/fs/quota.c
---- linux-2.6.29.4/fs/quota.c  2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/quota.c    2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/quota/quota.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/quota/quota.c
+--- linux-2.6.30.1/fs/quota/quota.c    2009-06-11 17:13:07.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/quota/quota.c 2009-07-14 15:05:36.000000000 +0200
 @@ -18,6 +18,7 @@
  #include <linux/capability.h>
  #include <linux/quotaops.h>
@@ -7182,8 +6283,8 @@ diff -NurpP --minimal linux-2.6.29.4/fs/quota.c linux-2.6.29.4-vs2.3.0.36.14/fs/
 +#include <linux/vs_context.h>
  
  /* Check validity of generic quotactl commands */
- static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
-@@ -81,11 +82,11 @@ static int generic_quotactl_valid(struct
+ static int generic_quotactl_valid(struct super_block *sb, int type, int cmd,
+@@ -83,11 +84,11 @@ static int generic_quotactl_valid(struct
        if (cmd == Q_GETQUOTA) {
                if (((type == USRQUOTA && current_euid() != id) ||
                     (type == GRPQUOTA && !in_egroup_p(id))) &&
@@ -7197,7 +6298,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/quota.c linux-2.6.29.4-vs2.3.0.36.14/fs/
                        return -EPERM;
  
        return 0;
-@@ -132,10 +133,10 @@ static int xqm_quotactl_valid(struct sup
+@@ -135,10 +136,10 @@ static int xqm_quotactl_valid(struct sup
        if (cmd == Q_XGETQUOTA) {
                if (((type == XQM_USRQUOTA && current_euid() != id) ||
                     (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
@@ -7210,7 +6311,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/quota.c linux-2.6.29.4-vs2.3.0.36.14/fs/
                        return -EPERM;
        }
  
-@@ -337,6 +338,46 @@ static int do_quotactl(struct super_bloc
+@@ -348,6 +349,46 @@ static int do_quotactl(struct super_bloc
        return 0;
  }
  
@@ -7257,7 +6358,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/quota.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  /*
   * look up a superblock on which quota ops will be performed
   * - use the name of a block device to find the superblock thereon
-@@ -354,6 +395,22 @@ static inline struct super_block *quotac
+@@ -365,6 +406,22 @@ static struct super_block *quotactl_bloc
        putname(tmp);
        if (IS_ERR(bdev))
                return ERR_CAST(bdev);
@@ -7280,131 +6381,27 @@ diff -NurpP --minimal linux-2.6.29.4/fs/quota.c linux-2.6.29.4-vs2.3.0.36.14/fs/
        sb = get_super(bdev);
        bdput(bdev);
        if (!sb)
-diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/bitmap.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/bitmap.c
---- linux-2.6.29.4/fs/reiserfs/bitmap.c        2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/bitmap.c  2009-02-22 22:54:25.000000000 +0100
-@@ -13,6 +13,7 @@
- #include <linux/reiserfs_fs_sb.h>
- #include <linux/reiserfs_fs_i.h>
- #include <linux/quotaops.h>
-+#include <linux/vs_dlimit.h>
- #define PREALLOCATION_SIZE 9
-@@ -429,8 +430,10 @@ static void _reiserfs_free_block(struct 
-       set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
-       journal_mark_dirty(th, s, sbh);
--      if (for_unformatted)
-+      if (for_unformatted) {
-+              DLIMIT_FREE_BLOCK(inode, 1);
-               DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
-+      }
- }
- void reiserfs_free_block(struct reiserfs_transaction_handle *th,
-@@ -1045,6 +1048,7 @@ static inline int blocknrs_and_prealloc_
-       b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
-       int passno = 0;
-       int nr_allocated = 0;
-+      int blocks;
-       determine_prealloc_size(hint);
-       if (!hint->formatted_node) {
-@@ -1054,19 +1058,30 @@ static inline int blocknrs_and_prealloc_
-                              "reiserquota: allocating %d blocks id=%u",
-                              amount_needed, hint->inode->i_uid);
- #endif
--              quota_ret =
--                  DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
--              if (quota_ret)  /* Quota exceeded? */
-+              quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
-+                      amount_needed);
-+              if (quota_ret)
-                       return QUOTA_EXCEEDED;
-+              if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
-+                      DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
-+                              amount_needed);
-+                      return NO_DISK_SPACE;
-+              }
-+
-               if (hint->preallocate && hint->prealloc_size) {
- #ifdef REISERQUOTA_DEBUG
-                       reiserfs_debug(s, REISERFS_DEBUG_CODE,
-                                      "reiserquota: allocating (prealloc) %d blocks id=%u",
-                                      hint->prealloc_size, hint->inode->i_uid);
- #endif
--                      quota_ret =
--                          DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
--                                                       hint->prealloc_size);
-+                      quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
-+                              hint->prealloc_size);
-+                      if (!quota_ret &&
-+                              DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
-+                              DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
-+                                      hint->prealloc_size);
-+                              quota_ret = 1;
-+                      }
-                       if (quota_ret)
-                               hint->preallocate = hint->prealloc_size = 0;
-               }
-@@ -1098,7 +1113,10 @@ static inline int blocknrs_and_prealloc_
-                                              nr_allocated,
-                                              hint->inode->i_uid);
- #endif
--                              DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
-+                              /* Free not allocated blocks */
-+                              blocks = amount_needed + hint->prealloc_size - nr_allocated;
-+                              DLIMIT_FREE_BLOCK(hint->inode, blocks);
-+                              DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
-                       }
-                       while (nr_allocated--)
-                               reiserfs_free_block(hint->th, hint->inode,
-@@ -1129,10 +1147,10 @@ static inline int blocknrs_and_prealloc_
-                              REISERFS_I(hint->inode)->i_prealloc_count,
-                              hint->inode->i_uid);
- #endif
--              DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
--                                       hint->prealloc_size - nr_allocated -
--                                       REISERFS_I(hint->inode)->
--                                       i_prealloc_count);
-+              blocks = amount_needed + hint->prealloc_size - nr_allocated -
-+                      REISERFS_I(hint->inode)->i_prealloc_count;
-+              DLIMIT_FREE_BLOCK(hint->inode, blocks);
-+              DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
-       }
-       return CARRY_ON;
-diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/file.c
---- linux-2.6.29.4/fs/reiserfs/file.c  2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/file.c    2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/reiserfs/file.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/file.c
+--- linux-2.6.30.1/fs/reiserfs/file.c  2009-06-11 17:13:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/file.c       2009-07-04 01:11:39.000000000 +0200
 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
        .listxattr = reiserfs_listxattr,
        .removexattr = reiserfs_removexattr,
        .permission = reiserfs_permission,
 +      .sync_flags = reiserfs_sync_flags,
  };
-diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/inode.c
---- linux-2.6.29.4/fs/reiserfs/inode.c 2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/inode.c   2009-03-24 14:48:35.000000000 +0100
-@@ -18,6 +18,8 @@
+diff -NurpP --minimal linux-2.6.30.1/fs/reiserfs/inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/inode.c
+--- linux-2.6.30.1/fs/reiserfs/inode.c 2009-06-11 17:13:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/inode.c      2009-07-04 02:52:58.000000000 +0200
+@@ -18,6 +18,7 @@
  #include <linux/writeback.h>
  #include <linux/quotaops.h>
  #include <linux/swap.h>
-+#include <linux/vs_dlimit.h>
 +#include <linux/vs_tag.h>
  
  int reiserfs_commit_write(struct file *f, struct page *page,
                          unsigned from, unsigned to);
-@@ -54,6 +56,7 @@ void reiserfs_delete_inode(struct inode 
-                * stat data deletion */
-               if (!err) 
-                       DQUOT_FREE_INODE(inode);
-+              DLIMIT_FREE_INODE(inode);
-               if (journal_end(&th, inode->i_sb, jbegin_count))
-                       goto out;
-@@ -1116,6 +1119,8 @@ static void init_inode(struct inode *ino
+@@ -1117,6 +1118,8 @@ static void init_inode(struct inode *ino
        struct buffer_head *bh;
        struct item_head *ih;
        __u32 rdev;
@@ -7413,7 +6410,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
        //int version = ITEM_VERSION_1;
  
        bh = PATH_PLAST_BUFFER(path);
-@@ -1139,12 +1144,13 @@ static void init_inode(struct inode *ino
+@@ -1140,12 +1143,13 @@ static void init_inode(struct inode *ino
                    (struct stat_data_v1 *)B_I_PITEM(bh, ih);
                unsigned long blocks;
  
@@ -7429,7 +6426,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
                inode->i_size = sd_v1_size(sd);
                inode->i_atime.tv_sec = sd_v1_atime(sd);
                inode->i_mtime.tv_sec = sd_v1_mtime(sd);
-@@ -1186,11 +1192,12 @@ static void init_inode(struct inode *ino
+@@ -1187,11 +1191,12 @@ static void init_inode(struct inode *ino
                // (directories and symlinks)
                struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
  
@@ -7444,7 +6441,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
                inode->i_mtime.tv_sec = sd_v2_mtime(sd);
                inode->i_atime.tv_sec = sd_v2_atime(sd);
                inode->i_ctime.tv_sec = sd_v2_ctime(sd);
-@@ -1220,6 +1227,10 @@ static void init_inode(struct inode *ino
+@@ -1221,6 +1226,10 @@ static void init_inode(struct inode *ino
                sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
        }
  
@@ -7455,7 +6452,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
        pathrelse(path);
        if (S_ISREG(inode->i_mode)) {
                inode->i_op = &reiserfs_file_inode_operations;
-@@ -1242,13 +1253,15 @@ static void init_inode(struct inode *ino
+@@ -1243,13 +1252,15 @@ static void init_inode(struct inode *ino
  static void inode2sd(void *sd, struct inode *inode, loff_t size)
  {
        struct stat_data *sd_v2 = (struct stat_data *)sd;
@@ -7473,28 +6470,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
        set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
        set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
        set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
-@@ -1763,6 +1776,10 @@ int reiserfs_new_inode(struct reiserfs_t
-       BUG_ON(!th->t_trans_id);
-+      if (DLIMIT_ALLOC_INODE(inode)) {
-+              err = -ENOSPC;
-+              goto out_bad_dlimit;
-+      }
-       if (DQUOT_ALLOC_INODE(inode)) {
-               err = -EDQUOT;
-               goto out_end_trans;
-@@ -1950,6 +1967,9 @@ int reiserfs_new_inode(struct reiserfs_t
-       DQUOT_FREE_INODE(inode);
-       out_end_trans:
-+      DLIMIT_FREE_INODE(inode);
-+
-+      out_bad_dlimit:
-       journal_end(th, th->t_super, th->t_blocks_allocated);
-       /* Drop can be outside and it needs more credits so it's better to have it outside */
-       DQUOT_DROP(inode);
-@@ -2837,14 +2857,19 @@ int reiserfs_commit_write(struct file *f
+@@ -2832,14 +2843,19 @@ int reiserfs_commit_write(struct file *f
  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
  {
        if (reiserfs_attrs(inode->i_sb)) {
@@ -7518,7 +6494,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
                if (sd_attrs & REISERFS_APPEND_FL)
                        inode->i_flags |= S_APPEND;
                else
-@@ -2857,6 +2882,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
+@@ -2852,6 +2868,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
                        REISERFS_I(inode)->i_flags |= i_nopack_mask;
                else
                        REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
@@ -7534,7 +6510,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
        }
  }
  
-@@ -2867,6 +2901,11 @@ void i_attrs_to_sd_attrs(struct inode *i
+@@ -2862,6 +2887,11 @@ void i_attrs_to_sd_attrs(struct inode *i
                        *sd_attrs |= REISERFS_IMMUTABLE_FL;
                else
                        *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
@@ -7546,7 +6522,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
                if (inode->i_flags & S_SYNC)
                        *sd_attrs |= REISERFS_SYNC_FL;
                else
-@@ -2879,6 +2918,15 @@ void i_attrs_to_sd_attrs(struct inode *i
+@@ -2874,6 +2904,15 @@ void i_attrs_to_sd_attrs(struct inode *i
                        *sd_attrs |= REISERFS_NOTAIL_FL;
                else
                        *sd_attrs &= ~REISERFS_NOTAIL_FL;
@@ -7562,7 +6538,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
        }
  }
  
-@@ -3046,6 +3094,22 @@ static ssize_t reiserfs_direct_IO(int rw
+@@ -3041,6 +3080,22 @@ static ssize_t reiserfs_direct_IO(int rw
                                  reiserfs_get_blocks_direct_io, NULL);
  }
  
@@ -7585,7 +6561,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
  {
        struct inode *inode = dentry->d_inode;
-@@ -3099,9 +3163,11 @@ int reiserfs_setattr(struct dentry *dent
+@@ -3094,9 +3149,11 @@ int reiserfs_setattr(struct dentry *dent
        }
  
        error = inode_change_ok(inode, attr);
@@ -7598,7 +6574,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
                        error = reiserfs_chown_xattrs(inode, attr);
  
                        if (!error) {
-@@ -3131,6 +3197,9 @@ int reiserfs_setattr(struct dentry *dent
+@@ -3126,6 +3183,9 @@ int reiserfs_setattr(struct dentry *dent
                                        inode->i_uid = attr->ia_uid;
                                if (attr->ia_valid & ATTR_GID)
                                        inode->i_gid = attr->ia_gid;
@@ -7608,9 +6584,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.
                                mark_inode_dirty(inode);
                                error =
                                    journal_end(&th, inode->i_sb, jbegin_count);
-diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/ioctl.c
---- linux-2.6.29.4/fs/reiserfs/ioctl.c 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/ioctl.c   2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/reiserfs/ioctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/ioctl.c
+--- linux-2.6.30.1/fs/reiserfs/ioctl.c 2009-06-11 17:13:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/ioctl.c      2009-07-04 01:11:39.000000000 +0200
 @@ -7,6 +7,7 @@
  #include <linux/mount.h>
  #include <linux/reiserfs_fs.h>
@@ -7658,9 +6634,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/ioctl.c linux-2.6.29.4-vs2.3.0.
                        sd_attrs_to_i_attrs(flags, inode);
                        REISERFS_I(inode)->i_attrs = flags;
                        inode->i_ctime = CURRENT_TIME_SEC;
-diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/namei.c
---- linux-2.6.29.4/fs/reiserfs/namei.c 2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/namei.c   2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/reiserfs/namei.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/namei.c
+--- linux-2.6.30.1/fs/reiserfs/namei.c 2009-06-11 17:13:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/namei.c      2009-07-04 02:11:56.000000000 +0200
 @@ -17,6 +17,7 @@
  #include <linux/reiserfs_acl.h>
  #include <linux/reiserfs_xattr.h>
@@ -7669,23 +6645,23 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/namei.c linux-2.6.29.4-vs2.3.0.
  
  #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) i->i_nlink=1; }
  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
-@@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
-                       reiserfs_write_unlock(dir->i_sb);
-                       return ERR_PTR(-EACCES);
-               }
+@@ -354,6 +355,7 @@ static struct dentry *reiserfs_lookup(st
+       if (retval == IO_ERROR) {
+               return ERR_PTR(-EIO);
+       }
 +              dx_propagate_tag(nd, inode);
  
-               /* Propogate the priv_object flag so we know we're in the priv tree */
-               if (is_reiserfs_priv_object(dir))
-@@ -586,6 +588,7 @@ static int new_inode_init(struct inode *
+       return d_splice_alias(inode, dentry);
+ }
+@@ -570,6 +572,7 @@ static int new_inode_init(struct inode *
        } else {
                inode->i_gid = current_fsgid();
        }
 +      inode->i_tag = dx_current_fstag(inode->i_sb);
-       DQUOT_INIT(inode);
+       vfs_dq_init(inode);
        return 0;
  }
-@@ -1540,6 +1543,7 @@ const struct inode_operations reiserfs_d
+@@ -1515,6 +1518,7 @@ const struct inode_operations reiserfs_d
        .listxattr = reiserfs_listxattr,
        .removexattr = reiserfs_removexattr,
        .permission = reiserfs_permission,
@@ -7693,7 +6669,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/namei.c linux-2.6.29.4-vs2.3.0.
  };
  
  /*
-@@ -1556,6 +1560,7 @@ const struct inode_operations reiserfs_s
+@@ -1531,6 +1535,7 @@ const struct inode_operations reiserfs_s
        .listxattr = reiserfs_listxattr,
        .removexattr = reiserfs_removexattr,
        .permission = reiserfs_permission,
@@ -7701,95 +6677,17 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/namei.c linux-2.6.29.4-vs2.3.0.
  
  };
  
-@@ -1569,5 +1574,6 @@ const struct inode_operations reiserfs_s
+@@ -1544,5 +1549,6 @@ const struct inode_operations reiserfs_s
        .listxattr = reiserfs_listxattr,
        .removexattr = reiserfs_removexattr,
        .permission = reiserfs_permission,
 +      .sync_flags = reiserfs_sync_flags,
  
  };
-diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/stree.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/stree.c
---- linux-2.6.29.4/fs/reiserfs/stree.c 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/stree.c   2009-02-22 22:54:25.000000000 +0100
-@@ -55,6 +55,7 @@
- #include <linux/reiserfs_fs.h>
- #include <linux/buffer_head.h>
- #include <linux/quotaops.h>
-+#include <linux/vs_dlimit.h>
- /* Does the buffer contain a disk block which is in the tree. */
- inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
-@@ -1297,6 +1298,7 @@ int reiserfs_delete_item(struct reiserfs
-                      "reiserquota delete_item(): freeing %u, id=%u type=%c",
-                      quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
- #endif
-+      DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
-       DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
-       /* Return deleted body length */
-@@ -1385,6 +1387,7 @@ void reiserfs_delete_solid_item(struct r
- #endif
-                               DQUOT_FREE_SPACE_NODIRTY(inode,
-                                                        quota_cut_bytes);
-+                              DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
-                       }
-                       break;
-               }
-@@ -1734,6 +1737,7 @@ int reiserfs_cut_from_item(struct reiser
-                      "reiserquota cut_from_item(): freeing %u id=%u type=%c",
-                      quota_cut_bytes, p_s_inode->i_uid, '?');
- #endif
-+      DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
-       DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
-       return n_ret_value;
- }
-@@ -1975,6 +1979,11 @@ int reiserfs_paste_into_item(struct reis
-               pathrelse(p_s_search_path);
-               return -EDQUOT;
-       }
-+      if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
-+              DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
-+              pathrelse(p_s_search_path);
-+              return -ENOSPC;
-+      }
-       init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
-                      n_pasted_size);
- #ifdef DISPLACE_NEW_PACKING_LOCALITIES
-@@ -2027,6 +2036,7 @@ int reiserfs_paste_into_item(struct reis
-                      n_pasted_size, inode->i_uid,
-                      key2type(&(p_s_key->on_disk_key)));
- #endif
-+      DLIMIT_FREE_SPACE(inode, n_pasted_size);
-       DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
-       return retval;
- }
-@@ -2064,6 +2074,11 @@ int reiserfs_insert_item(struct reiserfs
-                       pathrelse(p_s_path);
-                       return -EDQUOT;
-               }
-+              if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
-+                      DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
-+                      pathrelse(p_s_path);
-+                      return -ENOSPC;
-+              }
-       }
-       init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
-                      IH_SIZE + ih_item_len(p_s_ih));
-@@ -2111,7 +2126,9 @@ int reiserfs_insert_item(struct reiserfs
-                      "reiserquota insert_item(): freeing %u id=%u type=%c",
-                      quota_bytes, inode->i_uid, head2type(p_s_ih));
- #endif
--      if (inode)
-+      if (inode) {
-+              DLIMIT_FREE_SPACE(inode, quota_bytes);
-               DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
-+      }
-       return retval;
- }
-diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/super.c
---- linux-2.6.29.4/fs/reiserfs/super.c 2009-03-24 14:22:27.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/super.c   2009-03-24 14:48:35.000000000 +0100
-@@ -902,6 +902,14 @@ static int reiserfs_parse_options(struct
+diff -NurpP --minimal linux-2.6.30.1/fs/reiserfs/super.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/super.c
+--- linux-2.6.30.1/fs/reiserfs/super.c 2009-06-11 17:13:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/super.c      2009-07-06 17:43:06.000000000 +0200
+@@ -905,6 +905,14 @@ static int reiserfs_parse_options(struct
                {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
                {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
  #endif
@@ -7804,20 +6702,21 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/super.c linux-2.6.29.4-vs2.3.0.
  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
                {"acl",.setmask = 1 << REISERFS_POSIXACL},
                {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
-@@ -1195,6 +1203,12 @@ static int reiserfs_remount(struct super
+@@ -1210,6 +1218,13 @@ static int reiserfs_remount(struct super
        handle_quota_files(s, qf_names, &qfmt);
  #endif
  
 +      if ((mount_options & (1 << REISERFS_TAGGED)) &&
 +              !(s->s_flags & MS_TAGGED)) {
-+              reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
++              reiserfs_warning(s, "super-vs01",
++                      "reiserfs: tagging not permitted on remount.");
 +              return -EINVAL;
 +      }
 +
        handle_attrs(s);
  
        /* Add options that are safe here */
-@@ -1659,6 +1673,10 @@ static int reiserfs_fill_super(struct su
+@@ -1670,6 +1685,10 @@ static int reiserfs_fill_super(struct su
                goto error;
        }
  
@@ -7828,10 +6727,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/super.c linux-2.6.29.4-vs2.3.0.
        rs = SB_DISK_SUPER_BLOCK(s);
        /* Let's do basic sanity check to verify that underlying device is not
           smaller than the filesystem. If the check fails then abort and scream,
-diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/xattr.c
---- linux-2.6.29.4/fs/reiserfs/xattr.c 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/xattr.c   2009-02-22 22:54:25.000000000 +0100
-@@ -35,6 +35,7 @@
+diff -NurpP --minimal linux-2.6.30.1/fs/reiserfs/xattr.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/xattr.c
+--- linux-2.6.30.1/fs/reiserfs/xattr.c 2009-06-11 17:13:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/reiserfs/xattr.c      2009-07-04 01:11:39.000000000 +0200
+@@ -39,6 +39,7 @@
  #include <linux/namei.h>
  #include <linux/errno.h>
  #include <linux/fs.h>
@@ -7839,9 +6738,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/xattr.c linux-2.6.29.4-vs2.3.0.
  #include <linux/file.h>
  #include <linux/pagemap.h>
  #include <linux/xattr.h>
-diff -NurpP --minimal linux-2.6.29.4/fs/stat.c linux-2.6.29.4-vs2.3.0.36.14/fs/stat.c
---- linux-2.6.29.4/fs/stat.c   2009-03-24 14:22:36.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/stat.c     2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/stat.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/stat.c
+--- linux-2.6.30.1/fs/stat.c   2009-06-11 17:13:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/stat.c        2009-07-04 01:11:39.000000000 +0200
 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
        stat->nlink = inode->i_nlink;
        stat->uid = inode->i_uid;
@@ -7850,9 +6749,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/stat.c linux-2.6.29.4-vs2.3.0.36.14/fs/s
        stat->rdev = inode->i_rdev;
        stat->atime = inode->i_atime;
        stat->mtime = inode->i_mtime;
-diff -NurpP --minimal linux-2.6.29.4/fs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/super.c
---- linux-2.6.29.4/fs/super.c  2009-03-24 14:22:36.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/super.c    2009-03-24 16:32:06.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/super.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/super.c
+--- linux-2.6.30.1/fs/super.c  2009-06-11 17:13:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/super.c       2009-07-04 01:11:39.000000000 +0200
 @@ -39,6 +39,9 @@
  #include <linux/mutex.h>
  #include <linux/file.h>
@@ -7863,7 +6762,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  #include <asm/uaccess.h>
  #include "internal.h"
  
-@@ -918,12 +921,18 @@ struct vfsmount *
+@@ -992,12 +995,18 @@ struct vfsmount *
  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
  {
        struct vfsmount *mnt;
@@ -7882,7 +6781,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/
        error = -ENOMEM;
        mnt = alloc_vfsmnt(name);
        if (!mnt)
-@@ -942,9 +951,17 @@ vfs_kern_mount(struct file_system_type *
+@@ -1016,9 +1025,17 @@ vfs_kern_mount(struct file_system_type *
        error = type->get_sb(type, flags, name, data, mnt);
        if (error < 0)
                goto out_free_secdata;
@@ -7902,19 +6801,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/
        if (error)
                goto out_sb;
  
-diff -NurpP --minimal linux-2.6.29.4/fs/sysfs/mount.c linux-2.6.29.4-vs2.3.0.36.14/fs/sysfs/mount.c
---- linux-2.6.29.4/fs/sysfs/mount.c    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/sysfs/mount.c      2009-02-22 22:54:25.000000000 +0100
-@@ -20,8 +20,6 @@
- #include "sysfs.h"
--/* Random magic number */
--#define SYSFS_MAGIC 0x62656572
- static struct vfsmount *sysfs_mount;
- struct super_block * sysfs_sb = NULL;
-@@ -47,7 +45,7 @@ static int sysfs_fill_super(struct super
+diff -NurpP --minimal linux-2.6.30.1/fs/sysfs/mount.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/sysfs/mount.c
+--- linux-2.6.30.1/fs/sysfs/mount.c    2009-06-11 17:13:08.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/sysfs/mount.c 2009-07-04 01:11:39.000000000 +0200
+@@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
  
        sb->s_blocksize = PAGE_CACHE_SIZE;
        sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
@@ -7923,9 +6813,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/sysfs/mount.c linux-2.6.29.4-vs2.3.0.36.
        sb->s_op = &sysfs_ops;
        sb->s_time_gran = 1;
        sysfs_sb = sb;
-diff -NurpP --minimal linux-2.6.29.4/fs/utimes.c linux-2.6.29.4-vs2.3.0.36.14/fs/utimes.c
---- linux-2.6.29.4/fs/utimes.c 2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/utimes.c   2009-02-22 22:54:25.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/utimes.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/utimes.c
+--- linux-2.6.30.1/fs/utimes.c 2009-03-24 14:22:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/utimes.c      2009-07-04 01:11:39.000000000 +0200
 @@ -8,6 +8,8 @@
  #include <linux/stat.h>
  #include <linux/utime.h>
@@ -7935,9 +6825,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/utimes.c linux-2.6.29.4-vs2.3.0.36.14/fs
  #include <asm/uaccess.h>
  #include <asm/unistd.h>
  
-diff -NurpP --minimal linux-2.6.29.4/fs/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/xattr.c
---- linux-2.6.29.4/fs/xattr.c  2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xattr.c    2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xattr.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xattr.c
+--- linux-2.6.30.1/fs/xattr.c  2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xattr.c       2009-07-04 01:11:39.000000000 +0200
 @@ -18,6 +18,7 @@
  #include <linux/module.h>
  #include <linux/fsnotify.h>
@@ -7946,10 +6836,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/
  #include <asm/uaccess.h>
  
  
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_ioctl.c
---- linux-2.6.29.4/fs/xfs/linux-2.6/xfs_ioctl.c        2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_ioctl.c  2009-03-24 14:48:35.000000000 +0100
-@@ -769,6 +769,10 @@ xfs_merge_ioc_xflags(
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/linux-2.6/xfs_ioctl.c
+--- linux-2.6.30.1/fs/xfs/linux-2.6/xfs_ioctl.c        2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/linux-2.6/xfs_ioctl.c     2009-07-04 01:11:39.000000000 +0200
+@@ -743,6 +743,10 @@ xfs_merge_ioc_xflags(
                xflags |= XFS_XFLAG_IMMUTABLE;
        else
                xflags &= ~XFS_XFLAG_IMMUTABLE;
@@ -7960,7 +6850,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.29.4
        if (flags & FS_APPEND_FL)
                xflags |= XFS_XFLAG_APPEND;
        else
-@@ -797,6 +801,8 @@ xfs_di2lxflags(
+@@ -771,6 +775,8 @@ xfs_di2lxflags(
  
        if (di_flags & XFS_DIFLAG_IMMUTABLE)
                flags |= FS_IMMUTABLE_FL;
@@ -7969,7 +6859,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.29.4
        if (di_flags & XFS_DIFLAG_APPEND)
                flags |= FS_APPEND_FL;
        if (di_flags & XFS_DIFLAG_SYNC)
-@@ -855,6 +861,8 @@ xfs_set_diflags(
+@@ -829,6 +835,8 @@ xfs_set_diflags(
        di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
        if (xflags & XFS_XFLAG_IMMUTABLE)
                di_flags |= XFS_DIFLAG_IMMUTABLE;
@@ -7978,7 +6868,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.29.4
        if (xflags & XFS_XFLAG_APPEND)
                di_flags |= XFS_DIFLAG_APPEND;
        if (xflags & XFS_XFLAG_SYNC)
-@@ -897,6 +905,10 @@ xfs_diflags_to_linux(
+@@ -871,6 +879,10 @@ xfs_diflags_to_linux(
                inode->i_flags |= S_IMMUTABLE;
        else
                inode->i_flags &= ~S_IMMUTABLE;
@@ -7989,7 +6879,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.29.4
        if (xflags & XFS_XFLAG_APPEND)
                inode->i_flags |= S_APPEND;
        else
-@@ -1371,10 +1383,18 @@ xfs_file_ioctl(
+@@ -1345,10 +1357,18 @@ xfs_file_ioctl(
        case XFS_IOC_FSGETXATTRA:
                return xfs_ioc_fsgetxattr(ip, 1, arg);
        case XFS_IOC_FSSETXATTR:
@@ -8008,9 +6898,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.29.4
                return xfs_ioc_setxflags(ip, filp, arg);
  
        case XFS_IOC_FSSETDM: {
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_iops.c
---- linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c 2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_iops.c   2009-03-24 16:33:10.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/linux-2.6/xfs_iops.c
+--- linux-2.6.30.1/fs/xfs/linux-2.6/xfs_iops.c 2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/linux-2.6/xfs_iops.c      2009-07-04 01:11:39.000000000 +0200
 @@ -54,6 +54,7 @@
  #include <linux/security.h>
  #include <linux/falloc.h>
@@ -8019,15 +6909,15 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.4-
  
  /*
   * Bring the atime in the XFS inode uptodate.
-@@ -552,6 +553,7 @@ xfs_vn_getattr(
+@@ -540,6 +541,7 @@ xfs_vn_getattr(
        stat->nlink = ip->i_d.di_nlink;
        stat->uid = ip->i_d.di_uid;
        stat->gid = ip->i_d.di_gid;
 +      stat->tag = ip->i_d.di_tag;
        stat->ino = ip->i_ino;
- #if XFS_BIG_INUMS
-       stat->ino += mp->m_inoadd;
-@@ -591,6 +593,12 @@ xfs_vn_getattr(
+       stat->atime = inode->i_atime;
+       stat->mtime.tv_sec = ip->i_d.di_mtime.t_sec;
+@@ -576,6 +578,12 @@ xfs_vn_getattr(
  }
  
  STATIC int
@@ -8040,7 +6930,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.4-
  xfs_vn_setattr(
        struct dentry   *dentry,
        struct iattr    *iattr)
-@@ -748,6 +756,7 @@ static const struct inode_operations xfs
+@@ -733,6 +741,7 @@ static const struct inode_operations xfs
        .listxattr              = xfs_vn_listxattr,
        .fallocate              = xfs_vn_fallocate,
        .fiemap                 = xfs_vn_fiemap,
@@ -8048,7 +6938,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.4-
  };
  
  static const struct inode_operations xfs_dir_inode_operations = {
-@@ -773,6 +782,7 @@ static const struct inode_operations xfs
+@@ -758,6 +767,7 @@ static const struct inode_operations xfs
        .getxattr               = generic_getxattr,
        .removexattr            = generic_removexattr,
        .listxattr              = xfs_vn_listxattr,
@@ -8056,7 +6946,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.4-
  };
  
  static const struct inode_operations xfs_dir_ci_inode_operations = {
-@@ -822,6 +832,10 @@ xfs_diflags_to_iflags(
+@@ -807,6 +817,10 @@ xfs_diflags_to_iflags(
                inode->i_flags |= S_IMMUTABLE;
        else
                inode->i_flags &= ~S_IMMUTABLE;
@@ -8067,7 +6957,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.4-
        if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
                inode->i_flags |= S_APPEND;
        else
-@@ -834,6 +848,15 @@ xfs_diflags_to_iflags(
+@@ -819,6 +833,15 @@ xfs_diflags_to_iflags(
                inode->i_flags |= S_NOATIME;
        else
                inode->i_flags &= ~S_NOATIME;
@@ -8083,7 +6973,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.4-
  }
  
  /*
-@@ -862,6 +885,7 @@ xfs_setup_inode(
+@@ -847,6 +870,7 @@ xfs_setup_inode(
        inode->i_nlink  = ip->i_d.di_nlink;
        inode->i_uid    = ip->i_d.di_uid;
        inode->i_gid    = ip->i_d.di_gid;
@@ -8091,9 +6981,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.4-
  
        switch (inode->i_mode & S_IFMT) {
        case S_IFBLK:
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_linux.h
---- linux-2.6.29.4/fs/xfs/linux-2.6/xfs_linux.h        2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_linux.h  2009-03-25 01:26:04.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/linux-2.6/xfs_linux.h
+--- linux-2.6.30.1/fs/xfs/linux-2.6/xfs_linux.h        2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/linux-2.6/xfs_linux.h     2009-07-04 01:11:39.000000000 +0200
 @@ -119,6 +119,7 @@
  
  #define current_cpu()         (raw_smp_processor_id())
@@ -8102,10 +6992,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.29.4
  #define current_test_flags(f) (current->flags & (f))
  #define current_set_flags_nested(sp, f)               \
                (*(sp) = current->flags, current->flags |= (f))
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_super.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_super.c
---- linux-2.6.29.4/fs/xfs/linux-2.6/xfs_super.c        2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_super.c  2009-03-25 01:48:51.000000000 +0100
-@@ -120,6 +120,9 @@ mempool_t *xfs_ioend_pool;
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/linux-2.6/xfs_super.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/linux-2.6/xfs_super.c
+--- linux-2.6.30.1/fs/xfs/linux-2.6/xfs_super.c        2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/linux-2.6/xfs_super.c     2009-07-04 01:11:39.000000000 +0200
+@@ -118,6 +118,9 @@ mempool_t *xfs_ioend_pool;
  #define MNTOPT_DMAPI  "dmapi"         /* DMI enabled (DMAPI / XDSM) */
  #define MNTOPT_XDSM   "xdsm"          /* DMI enabled (DMAPI / XDSM) */
  #define MNTOPT_DMI    "dmi"           /* DMI enabled (DMAPI / XDSM) */
@@ -8115,7 +7005,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_super.c linux-2.6.29.4
  
  /*
   * Table driven mount option parser.
-@@ -128,10 +131,14 @@ mempool_t *xfs_ioend_pool;
+@@ -126,10 +129,14 @@ mempool_t *xfs_ioend_pool;
   * in the future, too.
   */
  enum {
@@ -8130,7 +7020,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_super.c linux-2.6.29.4
        {Opt_barrier, "barrier"},
        {Opt_nobarrier, "nobarrier"},
        {Opt_err, NULL}
-@@ -395,6 +402,19 @@ xfs_parseargs(
+@@ -383,6 +390,19 @@ xfs_parseargs(
                } else if (!strcmp(this_char, "irixsgid")) {
                        cmn_err(CE_WARN,
        "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
@@ -8150,7 +7040,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_super.c linux-2.6.29.4
                } else {
                        cmn_err(CE_WARN,
                                "XFS: unknown mount option [%s].", this_char);
-@@ -1221,6 +1241,16 @@ xfs_fs_remount(
+@@ -1233,6 +1253,16 @@ xfs_fs_remount(
                case Opt_nobarrier:
                        mp->m_flags &= ~XFS_MOUNT_BARRIER;
                        break;
@@ -8167,7 +7057,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_super.c linux-2.6.29.4
                default:
                        /*
                         * Logically we would return an error here to prevent
-@@ -1480,6 +1510,9 @@ xfs_fs_fill_super(
+@@ -1443,6 +1473,9 @@ xfs_fs_fill_super(
  
        XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
  
@@ -8177,21 +7067,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_super.c linux-2.6.29.4
        sb->s_dirt = 1;
        sb->s_magic = XFS_SB_MAGIC;
        sb->s_blocksize = mp->m_sb.sb_blocksize;
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/quota/xfs_qm_syscalls.c
---- linux-2.6.29.4/fs/xfs/quota/xfs_qm_syscalls.c      2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/quota/xfs_qm_syscalls.c        2009-03-24 14:48:35.000000000 +0100
-@@ -426,7 +426,7 @@ xfs_qm_scall_quotaon(
-       uint            accflags;
-       __int64_t       sbflags;
--      if (!capable(CAP_SYS_ADMIN))
-+      if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
-               return XFS_ERROR(EPERM);
-       flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_dinode.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_dinode.h
---- linux-2.6.29.4/fs/xfs/xfs_dinode.h 2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_dinode.h   2009-03-24 16:38:27.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/xfs_dinode.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_dinode.h
+--- linux-2.6.30.1/fs/xfs/xfs_dinode.h 2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_dinode.h      2009-07-04 01:11:39.000000000 +0200
 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
        __be32          di_gid;         /* owner's group id */
        __be32          di_nlink;       /* number of links to file */
@@ -8203,7 +7081,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_dinode.h linux-2.6.29.4-vs2.3.0.
        __be16          di_flushiter;   /* incremented on flush */
        xfs_timestamp_t di_atime;       /* time last accessed */
        xfs_timestamp_t di_mtime;       /* time last modified */
-@@ -181,6 +183,8 @@ static inline void xfs_dinode_put_rdev(s
+@@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12        /* inherit inode extent size */
  #define XFS_DIFLAG_NODEFRAG_BIT     13        /* do not reorganize/defragment */
  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
@@ -8212,7 +7090,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_dinode.h linux-2.6.29.4-vs2.3.0.
  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
-@@ -196,6 +200,7 @@ static inline void xfs_dinode_put_rdev(s
+@@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
@@ -8220,7 +7098,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_dinode.h linux-2.6.29.4-vs2.3.0.
  
  #ifdef CONFIG_XFS_RT
  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
-@@ -208,6 +213,10 @@ static inline void xfs_dinode_put_rdev(s
+@@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
         XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
         XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
         XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
@@ -8232,9 +7110,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_dinode.h linux-2.6.29.4-vs2.3.0.
 +#define XFS_DIVFLAG_COW               0x02
  
  #endif        /* __XFS_DINODE_H__ */
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_fs.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_fs.h
---- linux-2.6.29.4/fs/xfs/xfs_fs.h     2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_fs.h       2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/xfs_fs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_fs.h
+--- linux-2.6.30.1/fs/xfs/xfs_fs.h     2009-03-24 14:22:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_fs.h  2009-07-04 01:11:39.000000000 +0200
 @@ -67,6 +67,9 @@ struct fsxattr {
  #define XFS_XFLAG_EXTSZINHERIT        0x00001000      /* inherit inode extent size */
  #define XFS_XFLAG_NODEFRAG    0x00002000      /* do not defragment */
@@ -8255,9 +7133,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_fs.h linux-2.6.29.4-vs2.3.0.36.1
        __u32           bs_dmevmask;    /* DMIG event mask              */
        __u16           bs_dmstate;     /* DMIG state info              */
        __u16           bs_aextents;    /* attribute number of extents  */
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_ialloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_ialloc.c
---- linux-2.6.29.4/fs/xfs/xfs_ialloc.c 2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_ialloc.c   2009-03-24 17:03:17.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/xfs_ialloc.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_ialloc.c
+--- linux-2.6.30.1/fs/xfs/xfs_ialloc.c 2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_ialloc.c      2009-07-04 01:11:39.000000000 +0200
 @@ -41,7 +41,6 @@
  #include "xfs_error.h"
  #include "xfs_bmap.h"
@@ -8266,9 +7144,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_ialloc.c linux-2.6.29.4-vs2.3.0.
  /*
   * Allocation group level functions.
   */
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_inode.c
---- linux-2.6.29.4/fs/xfs/xfs_inode.c  2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_inode.c    2009-03-25 01:42:50.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/xfs_inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_inode.c
+--- linux-2.6.30.1/fs/xfs/xfs_inode.c  2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_inode.c       2009-07-04 01:11:39.000000000 +0200
 @@ -250,6 +250,7 @@ xfs_inotobp(
        return 0;
  }
@@ -8425,7 +7303,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_inode.c linux-2.6.29.4-vs2.3.0.3
        flags = XFS_ILOG_CORE;
        switch (mode & S_IFMT) {
        case S_IFIFO:
-@@ -2161,6 +2188,7 @@ xfs_ifree(
+@@ -2163,6 +2190,7 @@ xfs_ifree(
        }
        ip->i_d.di_mode = 0;            /* mark incore inode as free */
        ip->i_d.di_flags = 0;
@@ -8433,7 +7311,7 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_inode.c linux-2.6.29.4-vs2.3.0.3
        ip->i_d.di_dmevmask = 0;
        ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
        ip->i_df.if_ext_max =
-@@ -3128,7 +3156,8 @@ xfs_iflush_int(
+@@ -3130,7 +3158,8 @@ xfs_iflush_int(
         * because if the inode is dirty at all the core must
         * be.
         */
@@ -8443,9 +7321,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_inode.c linux-2.6.29.4-vs2.3.0.3
  
        /* Wrap, we never let the log put out DI_MAX_FLUSH */
        if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_inode.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_inode.h
---- linux-2.6.29.4/fs/xfs/xfs_inode.h  2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_inode.h    2009-03-25 01:10:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/xfs_inode.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_inode.h
+--- linux-2.6.30.1/fs/xfs/xfs_inode.h  2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_inode.h       2009-07-04 01:11:39.000000000 +0200
 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
        __uint32_t      di_gid;         /* owner's group id */
        __uint32_t      di_nlink;       /* number of links to file */
@@ -8469,21 +7347,21 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_inode.h linux-2.6.29.4-vs2.3.0.3
  void          xfs_idestroy_fork(struct xfs_inode *, int);
  void          xfs_idata_realloc(struct xfs_inode *, int, int);
  void          xfs_iroot_realloc(struct xfs_inode *, int, int);
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_itable.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_itable.c
---- linux-2.6.29.4/fs/xfs/xfs_itable.c 2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_itable.c   2009-03-24 14:48:35.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/xfs_itable.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_itable.c
+--- linux-2.6.30.1/fs/xfs/xfs_itable.c 2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_itable.c      2009-07-04 01:11:39.000000000 +0200
 @@ -82,6 +82,7 @@ xfs_bulkstat_one_iget(
        buf->bs_mode = dic->di_mode;
        buf->bs_uid = dic->di_uid;
        buf->bs_gid = dic->di_gid;
 +      buf->bs_tag = dic->di_tag;
        buf->bs_size = dic->di_size;
-       vn_atime_to_bstime(VFS_I(ip), &buf->bs_atime);
-       buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_log_recover.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_log_recover.c
---- linux-2.6.29.4/fs/xfs/xfs_log_recover.c    2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_log_recover.c      2009-03-24 17:17:15.000000000 +0100
-@@ -2421,7 +2421,8 @@ xlog_recover_do_inode_trans(
+       /*
+        * We are reading the atime from the Linux inode because the
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/xfs_log_recover.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_log_recover.c
+--- linux-2.6.30.1/fs/xfs/xfs_log_recover.c    2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_log_recover.c 2009-07-04 01:11:39.000000000 +0200
+@@ -2453,7 +2453,8 @@ xlog_recover_do_inode_trans(
        }
  
        /* The core is in in-core format */
@@ -8493,10 +7371,10 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_log_recover.c linux-2.6.29.4-vs2
  
        /* the rest is in on-disk format */
        if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_mount.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_mount.h
---- linux-2.6.29.4/fs/xfs/xfs_mount.h  2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_mount.h    2009-03-24 14:48:35.000000000 +0100
-@@ -371,6 +371,7 @@ typedef struct xfs_mount {
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/xfs_mount.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_mount.h
+--- linux-2.6.30.1/fs/xfs/xfs_mount.h  2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_mount.h       2009-07-04 01:11:39.000000000 +0200
+@@ -361,6 +361,7 @@ typedef struct xfs_mount {
                                                   allocator */
  #define XFS_MOUNT_NOATTR2     (1ULL << 25)    /* disable use of attr2 format */
  
@@ -8504,9 +7382,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_mount.h linux-2.6.29.4-vs2.3.0.3
  
  /*
   * Default minimum read and write sizes.
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_vnodeops.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_vnodeops.c
---- linux-2.6.29.4/fs/xfs/xfs_vnodeops.c       2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_vnodeops.c 2009-03-24 17:18:40.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/xfs_vnodeops.c linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_vnodeops.c
+--- linux-2.6.30.1/fs/xfs/xfs_vnodeops.c       2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_vnodeops.c    2009-07-04 01:11:39.000000000 +0200
 @@ -53,6 +53,90 @@
  #include "xfs_filestream.h"
  #include "xfs_vnodeops.h"
@@ -8656,9 +7534,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_vnodeops.c linux-2.6.29.4-vs2.3.
                if (iuid != uid) {
                        if (XFS_IS_UQUOTA_ON(mp)) {
                                ASSERT(mask & ATTR_UID);
-diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_vnodeops.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_vnodeops.h
---- linux-2.6.29.4/fs/xfs/xfs_vnodeops.h       2009-03-24 14:22:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_vnodeops.h 2009-03-24 17:19:30.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/fs/xfs/xfs_vnodeops.h linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_vnodeops.h
+--- linux-2.6.30.1/fs/xfs/xfs_vnodeops.h       2009-06-11 17:13:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/fs/xfs/xfs_vnodeops.h    2009-07-04 01:11:39.000000000 +0200
 @@ -14,6 +14,7 @@ struct xfs_inode;
  struct xfs_iomap;
  
@@ -8667,9 +7545,9 @@ diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_vnodeops.h linux-2.6.29.4-vs2.3.
  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
  #define       XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
  #define       XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
-diff -NurpP --minimal linux-2.6.29.4/include/asm-generic/tlb.h linux-2.6.29.4-vs2.3.0.36.14/include/asm-generic/tlb.h
---- linux-2.6.29.4/include/asm-generic/tlb.h   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/asm-generic/tlb.h     2009-04-08 15:50:06.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/include/asm-generic/tlb.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/asm-generic/tlb.h
+--- linux-2.6.30.1/include/asm-generic/tlb.h   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/asm-generic/tlb.h        2009-07-04 01:11:39.000000000 +0200
 @@ -14,6 +14,7 @@
  #define _ASM_GENERIC__TLB_H
  
@@ -8678,9 +7556,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/asm-generic/tlb.h linux-2.6.29.4-vs
  #include <asm/pgalloc.h>
  #include <asm/tlbflush.h>
  
-diff -NurpP --minimal linux-2.6.29.4/include/linux/capability.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/capability.h
---- linux-2.6.29.4/include/linux/capability.h  2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/capability.h    2009-04-30 12:14:53.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/include/linux/capability.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/capability.h
+--- linux-2.6.30.1/include/linux/capability.h  2009-06-11 17:13:13.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/capability.h       2009-07-04 01:11:39.000000000 +0200
 @@ -285,6 +285,7 @@ struct cpu_vfs_cap_data {
     arbitrary SCSI commands */
  /* Allow setting encryption key on loopback filesystem */
@@ -8704,18 +7582,18 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/capability.h linux-2.6.29.4-v
  
  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
  
-diff -NurpP --minimal linux-2.6.29.4/include/linux/devpts_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/devpts_fs.h
---- linux-2.6.29.4/include/linux/devpts_fs.h   2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/devpts_fs.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/devpts_fs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/devpts_fs.h
+--- linux-2.6.30.1/include/linux/devpts_fs.h   2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/devpts_fs.h        2009-07-04 01:11:39.000000000 +0200
 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
  
  #endif
  
 -
  #endif /* _LINUX_DEVPTS_FS_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/ext2_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/ext2_fs.h
---- linux-2.6.29.4/include/linux/ext2_fs.h     2009-03-24 14:22:41.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/ext2_fs.h       2009-03-24 15:39:54.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/ext2_fs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/ext2_fs.h
+--- linux-2.6.30.1/include/linux/ext2_fs.h     2009-03-24 14:22:41.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/ext2_fs.h  2009-07-04 01:11:39.000000000 +0200
 @@ -189,8 +189,12 @@ struct ext2_group_desc
  #define EXT2_NOTAIL_FL                        FS_NOTAIL_FL    /* file tail should not be merged */
  #define EXT2_DIRSYNC_FL                       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
@@ -8754,9 +7632,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/ext2_fs.h linux-2.6.29.4-vs2.
  
  
  #define clear_opt(o, opt)             o &= ~EXT2_MOUNT_##opt
-diff -NurpP --minimal linux-2.6.29.4/include/linux/ext3_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/ext3_fs.h
---- linux-2.6.29.4/include/linux/ext3_fs.h     2009-03-24 14:22:41.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/ext3_fs.h       2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/ext3_fs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/ext3_fs.h
+--- linux-2.6.30.1/include/linux/ext3_fs.h     2009-06-11 17:13:14.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/ext3_fs.h  2009-07-04 01:11:39.000000000 +0200
 @@ -173,10 +173,14 @@ struct ext3_group_desc
  #define EXT3_NOTAIL_FL                        0x00008000 /* file tail should not be merged */
  #define EXT3_DIRSYNC_FL                       0x00010000 /* dirsync behaviour (directories only) */
@@ -8774,7 +7652,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/ext3_fs.h linux-2.6.29.4-vs2.
  
  /* Flags that should be inherited by new inodes from their parent. */
  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
-@@ -316,7 +320,7 @@ struct ext3_inode {
+@@ -317,7 +321,7 @@ struct ext3_inode {
                struct {
                        __u8    l_i_frag;       /* Fragment number */
                        __u8    l_i_fsize;      /* Fragment size */
@@ -8783,7 +7661,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/ext3_fs.h linux-2.6.29.4-vs2.
                        __le16  l_i_uid_high;   /* these 2 fields    */
                        __le16  l_i_gid_high;   /* were reserved2[0] */
                        __u32   l_i_reserved2;
-@@ -350,6 +354,7 @@ struct ext3_inode {
+@@ -351,6 +355,7 @@ struct ext3_inode {
  #define i_gid_low     i_gid
  #define i_uid_high    osd2.linux2.l_i_uid_high
  #define i_gid_high    osd2.linux2.l_i_gid_high
@@ -8791,7 +7669,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/ext3_fs.h linux-2.6.29.4-vs2.
  #define i_reserved2   osd2.linux2.l_i_reserved2
  
  #elif defined(__GNU__)
-@@ -413,6 +418,7 @@ struct ext3_inode {
+@@ -414,6 +419,7 @@ struct ext3_inode {
  #define EXT3_MOUNT_GRPQUOTA           0x200000 /* "old" group quota */
  #define EXT3_MOUNT_DATA_ERR_ABORT     0x400000 /* Abort on file data write
                                                  * error in ordered mode */
@@ -8799,7 +7677,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/ext3_fs.h linux-2.6.29.4-vs2.
  
  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
  #ifndef _LINUX_EXT2_FS_H
-@@ -874,6 +880,7 @@ struct buffer_head * ext3_bread (handle_
+@@ -875,6 +881,7 @@ struct buffer_head * ext3_bread (handle_
  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
        sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
        int create, int extend_disksize);
@@ -8807,24 +7685,24 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/ext3_fs.h linux-2.6.29.4-vs2.
  
  extern struct inode *ext3_iget(struct super_block *, unsigned long);
  extern int  ext3_write_inode (struct inode *, int);
-diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/fs.h
---- linux-2.6.29.4/include/linux/fs.h  2009-03-24 14:22:41.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/fs.h    2009-03-24 17:21:20.000000000 +0100
-@@ -141,6 +141,9 @@ struct inodes_stat_t {
- #define MS_RELATIME   (1<<21) /* Update atime relative to mtime/ctime. */
+diff -NurpP --minimal linux-2.6.30.1/include/linux/fs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/fs.h
+--- linux-2.6.30.1/include/linux/fs.h  2009-06-11 17:13:14.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/fs.h       2009-07-04 02:28:05.000000000 +0200
+@@ -205,6 +205,9 @@ struct inodes_stat_t {
  #define MS_KERNMOUNT  (1<<22) /* this is a kern_mount call */
  #define MS_I_VERSION  (1<<23) /* Update inode I_version field */
-+#define MS_TAGGED     (1<<24) /* use generic inode tagging */
-+#define MS_TAGID      (1<<25) /* use specific tag for this mount */
-+#define MS_NOTAGCHECK (1<<26) /* don't check tags */
+ #define MS_STRICTATIME        (1<<24) /* Always perform atime updates */
++#define MS_TAGGED     (1<<25) /* use generic inode tagging */
++#define MS_TAGID      (1<<26) /* use specific tag for this mount */
++#define MS_NOTAGCHECK (1<<27) /* don't check tags */
  #define MS_ACTIVE     (1<<30)
  #define MS_NOUSER     (1<<31)
  
-@@ -167,6 +170,14 @@ struct inodes_stat_t {
+@@ -231,6 +234,14 @@ struct inodes_stat_t {
+ #define S_NOCMTIME    128     /* Do not update file c/mtime */
+ #define S_SWAPFILE    256     /* Do not truncate: swapon got its bmaps */
  #define S_PRIVATE     512     /* Inode is fs-internal */
- #define S_ATOMIC_COPY 1024    /* Pages mapped with this inode need to be
-                                  atomically copied (gem) */
-+#define S_IXUNLINK    2048    /* Immutable Invert on unlink */
++#define S_IXUNLINK    1024    /* Immutable Invert on unlink */
 +
 +/* Linux-VServer related Inode flags */
 +
@@ -8835,7 +7713,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  
  /*
   * Note that nosuid etc flags are inode-specific: setting some file-system
-@@ -189,12 +200,15 @@ struct inodes_stat_t {
+@@ -253,12 +264,15 @@ struct inodes_stat_t {
  #define IS_DIRSYNC(inode)     (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
                                        ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
  #define IS_MANDLOCK(inode)    __IS_FLG(inode, MS_MANDLOCK)
@@ -8853,7 +7731,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  #define IS_POSIXACL(inode)    __IS_FLG(inode, MS_POSIXACL)
  
  #define IS_DEADDIR(inode)     ((inode)->i_flags & S_DEAD)
-@@ -202,6 +216,16 @@ struct inodes_stat_t {
+@@ -266,6 +280,16 @@ struct inodes_stat_t {
  #define IS_SWAPFILE(inode)    ((inode)->i_flags & S_SWAPFILE)
  #define IS_PRIVATE(inode)     ((inode)->i_flags & S_PRIVATE)
  
@@ -8870,7 +7748,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  /* the read-only stuff doesn't really belong here, but any other place is
     probably as bad and I don't want to create yet another include file. */
  
-@@ -279,11 +303,14 @@ struct inodes_stat_t {
+@@ -343,11 +367,14 @@ struct inodes_stat_t {
  #define FS_TOPDIR_FL                  0x00020000 /* Top of directory hierarchies*/
  #define FS_EXTENT_FL                  0x00080000 /* Extents */
  #define FS_DIRECTIO_FL                        0x00100000 /* Use direct i/o */
@@ -8887,7 +7765,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  
  #define SYNC_FILE_RANGE_WAIT_BEFORE   1
  #define SYNC_FILE_RANGE_WRITE         2
-@@ -365,6 +392,7 @@ typedef void (dio_iodone_t)(struct kiocb
+@@ -429,6 +456,7 @@ typedef void (dio_iodone_t)(struct kiocb
  #define ATTR_KILL_PRIV        (1 << 14)
  #define ATTR_OPEN     (1 << 15) /* Truncating from open(O_TRUNC) */
  #define ATTR_TIMES_SET        (1 << 16)
@@ -8895,7 +7773,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  
  /*
   * This is the Inode Attributes structure, used for notify_change().  It
-@@ -380,6 +408,7 @@ struct iattr {
+@@ -444,6 +472,7 @@ struct iattr {
        umode_t         ia_mode;
        uid_t           ia_uid;
        gid_t           ia_gid;
@@ -8903,7 +7781,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
        loff_t          ia_size;
        struct timespec ia_atime;
        struct timespec ia_mtime;
-@@ -393,6 +422,9 @@ struct iattr {
+@@ -457,6 +486,9 @@ struct iattr {
        struct file     *ia_file;
  };
  
@@ -8913,7 +7791,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  /*
   * Includes for diskquotas.
   */
-@@ -656,7 +688,9 @@ struct inode {
+@@ -720,7 +752,9 @@ struct inode {
        unsigned int            i_nlink;
        uid_t                   i_uid;
        gid_t                   i_gid;
@@ -8923,7 +7801,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
        u64                     i_version;
        loff_t                  i_size;
  #ifdef __NEED_I_SIZE_ORDERED
-@@ -704,7 +738,8 @@ struct inode {
+@@ -768,7 +802,8 @@ struct inode {
        unsigned long           i_state;
        unsigned long           dirtied_when;   /* jiffies of first dirtying */
  
@@ -8933,7 +7811,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  
        atomic_t                i_writecount;
  #ifdef CONFIG_SECURITY
-@@ -791,12 +826,12 @@ static inline void i_size_write(struct i
+@@ -852,12 +887,12 @@ static inline void i_size_write(struct i
  
  static inline unsigned iminor(const struct inode *inode)
  {
@@ -8948,7 +7826,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  }
  
  extern struct block_device *I_BDEV(struct inode *inode);
-@@ -854,6 +889,7 @@ struct file {
+@@ -916,6 +951,7 @@ struct file {
        loff_t                  f_pos;
        struct fown_struct      f_owner;
        const struct cred       *f_cred;
@@ -8956,7 +7834,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
        struct file_ra_state    f_ra;
  
        u64                     f_version;
-@@ -996,6 +1032,7 @@ struct file_lock {
+@@ -1057,6 +1093,7 @@ struct file_lock {
        struct file *fl_file;
        loff_t fl_start;
        loff_t fl_end;
@@ -8964,7 +7842,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  
        struct fasync_struct *  fl_fasync; /* for lease break notifications */
        unsigned long fl_break_time;    /* for nonblocking lease breaks */
-@@ -1363,6 +1400,7 @@ struct inode_operations {
+@@ -1537,6 +1574,7 @@ struct inode_operations {
                          loff_t len);
        int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
                      u64 len);
@@ -8972,7 +7850,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  };
  
  struct seq_file;
-@@ -1378,6 +1416,7 @@ extern ssize_t vfs_readv(struct file *, 
+@@ -1552,6 +1590,7 @@ extern ssize_t vfs_readv(struct file *, 
                unsigned long, loff_t *);
  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
                unsigned long, loff_t *);
@@ -8980,7 +7858,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  
  struct super_operations {
        struct inode *(*alloc_inode)(struct super_block *sb);
-@@ -2096,6 +2135,7 @@ extern int dcache_dir_open(struct inode 
+@@ -2323,6 +2362,7 @@ extern int dcache_dir_open(struct inode 
  extern int dcache_dir_close(struct inode *, struct file *);
  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
  extern int dcache_readdir(struct file *, void *, filldir_t);
@@ -8988,24 +7866,24 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.3
  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  extern int simple_statfs(struct dentry *, struct kstatfs *);
  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
-diff -NurpP --minimal linux-2.6.29.4/include/linux/if_tun.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/if_tun.h
---- linux-2.6.29.4/include/linux/if_tun.h      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/if_tun.h        2009-02-22 22:54:26.000000000 +0100
-@@ -46,6 +46,7 @@
- #define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
- #define TUNSETTXFILTER _IOW('T', 209, unsigned int)
+diff -NurpP --minimal linux-2.6.30.1/include/linux/if_tun.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/if_tun.h
+--- linux-2.6.30.1/include/linux/if_tun.h      2009-06-11 17:13:14.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/if_tun.h   2009-07-04 02:28:56.000000000 +0200
+@@ -48,6 +48,7 @@
  #define TUNGETIFF      _IOR('T', 210, unsigned int)
+ #define TUNGETSNDBUF   _IOR('T', 211, int)
+ #define TUNSETSNDBUF   _IOW('T', 212, int)
 +#define TUNSETNID     _IOW('T', 215, int)
  
  /* TUNSETIFF ifr flags */
  #define IFF_TUN               0x0001
-diff -NurpP --minimal linux-2.6.29.4/include/linux/init_task.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/init_task.h
---- linux-2.6.29.4/include/linux/init_task.h   2009-03-24 14:22:41.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/init_task.h     2009-03-24 14:48:36.000000000 +0100
-@@ -184,6 +184,10 @@ extern struct cred init_cred;
-       INIT_IDS                                                        \
+diff -NurpP --minimal linux-2.6.30.1/include/linux/init_task.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/init_task.h
+--- linux-2.6.30.1/include/linux/init_task.h   2009-06-11 17:13:14.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/init_task.h        2009-07-04 02:26:54.000000000 +0200
+@@ -174,6 +174,10 @@ extern struct cred init_cred;
        INIT_TRACE_IRQFLAGS                                             \
        INIT_LOCKDEP                                                    \
+       INIT_FTRACE_GRAPH                                               \
 +      .xid            = 0,                                            \
 +      .vx_info        = NULL,                                         \
 +      .nid            = 0,                                            \
@@ -9013,9 +7891,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/init_task.h linux-2.6.29.4-vs
  }
  
  
-diff -NurpP --minimal linux-2.6.29.4/include/linux/interrupt.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/interrupt.h
---- linux-2.6.29.4/include/linux/interrupt.h   2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/interrupt.h     2009-04-30 12:14:53.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/include/linux/interrupt.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/interrupt.h
+--- linux-2.6.30.1/include/linux/interrupt.h   2009-06-11 17:13:14.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/interrupt.h        2009-07-04 01:11:39.000000000 +0200
 @@ -9,8 +9,8 @@
  #include <linux/cpumask.h>
  #include <linux/irqreturn.h>
@@ -9026,9 +7904,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/interrupt.h linux-2.6.29.4-vs
  #include <linux/irqflags.h>
  #include <linux/smp.h>
  #include <linux/percpu.h>
-diff -NurpP --minimal linux-2.6.29.4/include/linux/ipc.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/ipc.h
---- linux-2.6.29.4/include/linux/ipc.h 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/ipc.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/ipc.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/ipc.h
+--- linux-2.6.30.1/include/linux/ipc.h 2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/ipc.h      2009-07-04 01:11:39.000000000 +0200
 @@ -93,6 +93,7 @@ struct kern_ipc_perm
        key_t           key;
        uid_t           uid;
@@ -9037,9 +7915,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/ipc.h linux-2.6.29.4-vs2.3.0.
        uid_t           cuid;
        gid_t           cgid;
        mode_t          mode; 
-diff -NurpP --minimal linux-2.6.29.4/include/linux/Kbuild linux-2.6.29.4-vs2.3.0.36.14/include/linux/Kbuild
---- linux-2.6.29.4/include/linux/Kbuild        2009-03-24 14:22:40.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/Kbuild  2009-03-24 17:22:07.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/Kbuild linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/Kbuild
+--- linux-2.6.30.1/include/linux/Kbuild        2009-06-11 17:13:13.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/Kbuild     2009-07-04 01:11:39.000000000 +0200
 @@ -373,5 +373,8 @@ unifdef-y += xattr.h
  unifdef-y += xfrm.h
  
@@ -9049,9 +7927,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/Kbuild linux-2.6.29.4-vs2.3.0
  header-y += wimax.h
  header-y += wimax/
 +
-diff -NurpP --minimal linux-2.6.29.4/include/linux/loop.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/loop.h
---- linux-2.6.29.4/include/linux/loop.h        2009-03-24 14:22:42.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/loop.h  2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/loop.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/loop.h
+--- linux-2.6.30.1/include/linux/loop.h        2009-06-11 17:13:15.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/loop.h     2009-07-04 01:11:39.000000000 +0200
 @@ -45,6 +45,7 @@ struct loop_device {
        struct loop_func_table *lo_encryption;
        __u32           lo_init[2];
@@ -9060,9 +7938,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/loop.h linux-2.6.29.4-vs2.3.0
        int             (*ioctl)(struct loop_device *, int cmd, 
                                 unsigned long arg); 
  
-diff -NurpP --minimal linux-2.6.29.4/include/linux/magic.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/magic.h
---- linux-2.6.29.4/include/linux/magic.h       2009-03-24 14:22:42.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/magic.h 2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/magic.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/magic.h
+--- linux-2.6.30.1/include/linux/magic.h       2009-06-11 17:13:15.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/magic.h    2009-07-04 01:11:39.000000000 +0200
 @@ -3,7 +3,7 @@
  
  #define ADFS_SUPER_MAGIC      0xadf5
@@ -9080,9 +7958,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/magic.h linux-2.6.29.4-vs2.3.
  #define QNX4_SUPER_MAGIC      0x002f          /* qnx4 fs detection */
  
  #define REISERFS_SUPER_MAGIC  0x52654973      /* used by gcc */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/major.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/major.h
---- linux-2.6.29.4/include/linux/major.h       2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/major.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/major.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/major.h
+--- linux-2.6.30.1/include/linux/major.h       2009-06-11 17:13:15.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/major.h    2009-07-04 01:11:39.000000000 +0200
 @@ -15,6 +15,7 @@
  #define HD_MAJOR              IDE0_MAJOR
  #define PTY_SLAVE_MAJOR               3
@@ -9091,10 +7969,10 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/major.h linux-2.6.29.4-vs2.3.
  #define TTYAUX_MAJOR          5
  #define LP_MAJOR              6
  #define VCS_MAJOR             7
-diff -NurpP --minimal linux-2.6.29.4/include/linux/mm_types.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/mm_types.h
---- linux-2.6.29.4/include/linux/mm_types.h    2009-03-24 14:22:42.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/mm_types.h      2009-03-24 14:48:36.000000000 +0100
-@@ -232,6 +232,7 @@ struct mm_struct {
+diff -NurpP --minimal linux-2.6.30.1/include/linux/mm_types.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/mm_types.h
+--- linux-2.6.30.1/include/linux/mm_types.h    2009-06-11 17:13:15.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/mm_types.h 2009-07-04 01:11:39.000000000 +0200
+@@ -236,6 +236,7 @@ struct mm_struct {
  
        /* Architecture-specific MM context */
        mm_context_t context;
@@ -9102,10 +7980,10 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/mm_types.h linux-2.6.29.4-vs2
  
        /* Swap token stuff */
        /*
-diff -NurpP --minimal linux-2.6.29.4/include/linux/mount.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/mount.h
---- linux-2.6.29.4/include/linux/mount.h       2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/mount.h 2009-02-22 22:54:26.000000000 +0100
-@@ -35,6 +35,9 @@ struct mnt_namespace;
+diff -NurpP --minimal linux-2.6.30.1/include/linux/mount.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/mount.h
+--- linux-2.6.30.1/include/linux/mount.h       2009-06-11 17:13:15.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/mount.h    2009-07-04 01:11:39.000000000 +0200
+@@ -36,6 +36,9 @@ struct mnt_namespace;
  #define MNT_UNBINDABLE        0x2000  /* if the vfsmount is a unbindable mount */
  #define MNT_PNODE_MASK        0x3000  /* propagation flag mask */
  
@@ -9115,7 +7993,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/mount.h linux-2.6.29.4-vs2.3.
  struct vfsmount {
        struct list_head mnt_hash;
        struct vfsmount *mnt_parent;    /* fs we are mounted on */
-@@ -69,6 +72,7 @@ struct vfsmount {
+@@ -70,6 +73,7 @@ struct vfsmount {
         * are held, and all mnt_writer[]s on this mount have 0 as their ->count
         */
        atomic_t __mnt_writers;
@@ -9123,9 +8001,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/mount.h linux-2.6.29.4-vs2.3.
  };
  
  static inline struct vfsmount *mntget(struct vfsmount *mnt)
-diff -NurpP --minimal linux-2.6.29.4/include/linux/net.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/net.h
---- linux-2.6.29.4/include/linux/net.h 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/net.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/net.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/net.h
+--- linux-2.6.30.1/include/linux/net.h 2009-06-11 17:13:15.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/net.h      2009-07-04 01:11:39.000000000 +0200
 @@ -68,6 +68,7 @@ struct net;
  #define SOCK_NOSPACE          2
  #define SOCK_PASSCRED         3
@@ -9134,9 +8012,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/net.h linux-2.6.29.4-vs2.3.0.
  
  #ifndef ARCH_HAS_SOCKET_TYPES
  /**
-diff -NurpP --minimal linux-2.6.29.4/include/linux/nfs_mount.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/nfs_mount.h
---- linux-2.6.29.4/include/linux/nfs_mount.h   2009-03-24 14:22:43.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/nfs_mount.h     2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/nfs_mount.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/nfs_mount.h
+--- linux-2.6.30.1/include/linux/nfs_mount.h   2009-03-24 14:22:43.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/nfs_mount.h        2009-07-04 01:11:39.000000000 +0200
 @@ -63,7 +63,8 @@ struct nfs_mount_data {
  #define NFS_MOUNT_SECFLAVOUR  0x2000  /* 5 */
  #define NFS_MOUNT_NORDIRPLUS  0x4000  /* 5 */
@@ -9147,9 +8025,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/nfs_mount.h linux-2.6.29.4-vs
  
  /* The following are for internal use only */
  #define NFS_MOUNT_LOOKUP_CACHE_NONEG  0x10000
-diff -NurpP --minimal linux-2.6.29.4/include/linux/nsproxy.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/nsproxy.h
---- linux-2.6.29.4/include/linux/nsproxy.h     2009-03-24 14:22:43.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/nsproxy.h       2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/nsproxy.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/nsproxy.h
+--- linux-2.6.30.1/include/linux/nsproxy.h     2009-06-11 17:13:17.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/nsproxy.h  2009-07-04 01:11:39.000000000 +0200
 @@ -3,6 +3,7 @@
  
  #include <linux/spinlock.h>
@@ -9158,7 +8036,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/nsproxy.h linux-2.6.29.4-vs2.
  
  struct mnt_namespace;
  struct uts_namespace;
-@@ -62,22 +63,33 @@ static inline struct nsproxy *task_nspro
+@@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
  }
  
  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
@@ -9198,9 +8076,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/nsproxy.h linux-2.6.29.4-vs2.
  }
  
  #ifdef CONFIG_CGROUP_NS
-diff -NurpP --minimal linux-2.6.29.4/include/linux/pid.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/pid.h
---- linux-2.6.29.4/include/linux/pid.h 2009-03-24 14:22:43.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/pid.h   2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/pid.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/pid.h
+--- linux-2.6.30.1/include/linux/pid.h 2009-03-24 14:22:43.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/pid.h      2009-07-04 01:11:39.000000000 +0200
 @@ -8,7 +8,8 @@ enum pid_type
        PIDTYPE_PID,
        PIDTYPE_PGID,
@@ -9219,10 +8097,10 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/pid.h linux-2.6.29.4-vs2.3.0.
  pid_t pid_vnr(struct pid *pid);
  
  #define do_each_pid_task(pid, type, task)                             \
-diff -NurpP --minimal linux-2.6.29.4/include/linux/proc_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/proc_fs.h
---- linux-2.6.29.4/include/linux/proc_fs.h     2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/proc_fs.h       2009-02-22 22:54:26.000000000 +0100
-@@ -59,6 +59,7 @@ struct proc_dir_entry {
+diff -NurpP --minimal linux-2.6.30.1/include/linux/proc_fs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/proc_fs.h
+--- linux-2.6.30.1/include/linux/proc_fs.h     2009-06-11 17:13:17.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/proc_fs.h  2009-07-04 01:11:39.000000000 +0200
+@@ -56,6 +56,7 @@ struct proc_dir_entry {
        nlink_t nlink;
        uid_t uid;
        gid_t gid;
@@ -9230,7 +8108,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/proc_fs.h linux-2.6.29.4-vs2.
        loff_t size;
        const struct inode_operations *proc_iops;
        /*
-@@ -268,12 +269,18 @@ static inline void kclist_add(struct kco
+@@ -264,12 +265,18 @@ static inline void kclist_add(struct kco
  extern void kclist_add(struct kcore_list *, void *, size_t);
  #endif
  
@@ -9249,7 +8127,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/proc_fs.h linux-2.6.29.4-vs2.
  };
  
  struct ctl_table_header;
-@@ -281,6 +288,7 @@ struct ctl_table;
+@@ -277,6 +284,7 @@ struct ctl_table;
  
  struct proc_inode {
        struct pid *pid;
@@ -9257,10 +8135,10 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/proc_fs.h linux-2.6.29.4-vs2.
        int fd;
        union proc_op op;
        struct proc_dir_entry *pde;
-diff -NurpP --minimal linux-2.6.29.4/include/linux/reiserfs_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/reiserfs_fs.h
---- linux-2.6.29.4/include/linux/reiserfs_fs.h 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/reiserfs_fs.h   2009-02-22 22:54:26.000000000 +0100
-@@ -837,6 +837,11 @@ struct stat_data_v1 {
+diff -NurpP --minimal linux-2.6.30.1/include/linux/reiserfs_fs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/reiserfs_fs.h
+--- linux-2.6.30.1/include/linux/reiserfs_fs.h 2009-06-11 17:13:17.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/reiserfs_fs.h      2009-07-04 01:11:39.000000000 +0200
+@@ -868,6 +868,11 @@ struct stat_data_v1 {
  #define REISERFS_COMPR_FL     FS_COMPR_FL
  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
  
@@ -9272,7 +8150,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/reiserfs_fs.h linux-2.6.29.4-
  /* persistent flags that file inherits from the parent directory */
  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |       \
                                REISERFS_SYNC_FL |      \
-@@ -846,6 +851,9 @@ struct stat_data_v1 {
+@@ -877,6 +882,9 @@ struct stat_data_v1 {
                                REISERFS_COMPR_FL |     \
                                REISERFS_NOTAIL_FL )
  
@@ -9282,7 +8160,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/reiserfs_fs.h linux-2.6.29.4-
  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
     address blocks) */
  struct stat_data {
-@@ -1911,6 +1919,7 @@ static inline void reiserfs_update_sd(st
+@@ -1958,6 +1966,7 @@ static inline void reiserfs_update_sd(st
  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
@@ -9290,10 +8168,10 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/reiserfs_fs.h linux-2.6.29.4-
  
  /* namei.c */
  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
-diff -NurpP --minimal linux-2.6.29.4/include/linux/reiserfs_fs_sb.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/reiserfs_fs_sb.h
---- linux-2.6.29.4/include/linux/reiserfs_fs_sb.h      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/reiserfs_fs_sb.h        2009-02-22 22:54:26.000000000 +0100
-@@ -456,6 +456,7 @@ enum reiserfs_mount_options {
+diff -NurpP --minimal linux-2.6.30.1/include/linux/reiserfs_fs_sb.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/reiserfs_fs_sb.h
+--- linux-2.6.30.1/include/linux/reiserfs_fs_sb.h      2009-06-11 17:13:17.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/reiserfs_fs_sb.h   2009-07-04 01:11:39.000000000 +0200
+@@ -455,6 +455,7 @@ enum reiserfs_mount_options {
        REISERFS_POSIXACL,
        REISERFS_BARRIER_NONE,
        REISERFS_BARRIER_FLUSH,
@@ -9301,11 +8179,11 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/reiserfs_fs_sb.h linux-2.6.29
  
        /* Actions on error */
        REISERFS_ERROR_PANIC,
-diff -NurpP --minimal linux-2.6.29.4/include/linux/sched.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/sched.h
---- linux-2.6.29.4/include/linux/sched.h       2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/sched.h 2009-04-30 12:14:53.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/include/linux/sched.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/sched.h
+--- linux-2.6.30.1/include/linux/sched.h       2009-06-11 17:13:17.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/sched.h    2009-07-04 02:31:28.000000000 +0200
 @@ -71,7 +71,6 @@ struct sched_param {
- #include <linux/fs_struct.h>
+ #include <linux/path.h>
  #include <linux/compiler.h>
  #include <linux/completion.h>
 -#include <linux/pid.h>
@@ -9320,7 +8198,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sched.h linux-2.6.29.4-vs2.3.
  
  #include <asm/processor.h>
  
-@@ -176,12 +176,13 @@ extern unsigned long long time_sync_thre
+@@ -179,12 +179,13 @@ extern unsigned long long time_sync_thre
  #define TASK_UNINTERRUPTIBLE  2
  #define __TASK_STOPPED                4
  #define __TASK_TRACED         8
@@ -9338,7 +8216,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sched.h linux-2.6.29.4-vs2.3.
  
  /* Convenience macros for the sake of set_task_state */
  #define TASK_KILLABLE         (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
-@@ -359,25 +360,28 @@ extern void arch_unmap_area_topdown(stru
+@@ -367,25 +368,28 @@ extern void arch_unmap_area_topdown(stru
   * The mm counters are not protected by its page_table_lock,
   * so must be incremented atomically.
   */
@@ -9376,7 +8254,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sched.h linux-2.6.29.4-vs2.3.
  #define get_mm_rss(mm)                                        \
        (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
  #define update_hiwater_rss(mm)        do {                    \
-@@ -1132,7 +1136,9 @@ struct task_struct {
+@@ -1134,7 +1138,9 @@ struct task_struct {
        const struct sched_class *sched_class;
        struct sched_entity se;
        struct sched_rt_entity rt;
@@ -9387,7 +8265,7 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sched.h linux-2.6.29.4-vs2.3.
  #ifdef CONFIG_PREEMPT_NOTIFIERS
        /* list of struct preempt_notifier: */
        struct hlist_head preempt_notifiers;
-@@ -1288,6 +1294,14 @@ struct task_struct {
+@@ -1291,6 +1297,14 @@ struct task_struct {
  #endif
        seccomp_t seccomp;
  
@@ -9402,9 +8280,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sched.h linux-2.6.29.4-vs2.3.
  /* Thread group tracking */
        u32 parent_exec_id;
        u32 self_exec_id;
-@@ -1500,6 +1514,11 @@ struct pid_namespace;
-  * see also pid_nr() etc in include/linux/pid.h
-  */
+@@ -1508,6 +1522,11 @@ struct pid_namespace;
+ pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
+                       struct pid_namespace *ns);
  
 +#include <linux/vserver/base.h>
 +#include <linux/vserver/context.h>
@@ -9414,16 +8292,17 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sched.h linux-2.6.29.4-vs2.3.
  static inline pid_t task_pid_nr(struct task_struct *tsk)
  {
        return tsk->pid;
-@@ -1509,7 +1528,7 @@ pid_t task_pid_nr_ns(struct task_struct 
+@@ -1521,7 +1540,8 @@ static inline pid_t task_pid_nr_ns(struc
  
  static inline pid_t task_pid_vnr(struct task_struct *tsk)
  {
--      return pid_vnr(task_pid(tsk));
-+      return vx_map_pid(pid_vnr(task_pid(tsk)));
+-      return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
++      // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
++      return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
  }
  
  
-@@ -1522,7 +1541,7 @@ pid_t task_tgid_nr_ns(struct task_struct
+@@ -1534,7 +1554,7 @@ pid_t task_tgid_nr_ns(struct task_struct
  
  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
  {
@@ -9432,9 +8311,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sched.h linux-2.6.29.4-vs2.3.
  }
  
  
-diff -NurpP --minimal linux-2.6.29.4/include/linux/shmem_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/shmem_fs.h
---- linux-2.6.29.4/include/linux/shmem_fs.h    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/shmem_fs.h      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/shmem_fs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/shmem_fs.h
+--- linux-2.6.30.1/include/linux/shmem_fs.h    2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/shmem_fs.h 2009-07-04 01:11:39.000000000 +0200
 @@ -8,6 +8,9 @@
  
  #define SHMEM_NR_DIRECT 16
@@ -9445,9 +8324,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/shmem_fs.h linux-2.6.29.4-vs2
  struct shmem_inode_info {
        spinlock_t              lock;
        unsigned long           flags;
-diff -NurpP --minimal linux-2.6.29.4/include/linux/stat.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/stat.h
---- linux-2.6.29.4/include/linux/stat.h        2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/stat.h  2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/stat.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/stat.h
+--- linux-2.6.30.1/include/linux/stat.h        2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/stat.h     2009-07-04 01:11:39.000000000 +0200
 @@ -66,6 +66,7 @@ struct kstat {
        unsigned int    nlink;
        uid_t           uid;
@@ -9456,9 +8335,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/stat.h linux-2.6.29.4-vs2.3.0
        dev_t           rdev;
        loff_t          size;
        struct timespec  atime;
-diff -NurpP --minimal linux-2.6.29.4/include/linux/sunrpc/auth.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/sunrpc/auth.h
---- linux-2.6.29.4/include/linux/sunrpc/auth.h 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/sunrpc/auth.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/sunrpc/auth.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/sunrpc/auth.h
+--- linux-2.6.30.1/include/linux/sunrpc/auth.h 2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/sunrpc/auth.h      2009-07-04 01:11:39.000000000 +0200
 @@ -25,6 +25,7 @@
  struct auth_cred {
        uid_t   uid;
@@ -9467,9 +8346,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sunrpc/auth.h linux-2.6.29.4-
        struct group_info *group_info;
        unsigned char machine_cred : 1;
  };
-diff -NurpP --minimal linux-2.6.29.4/include/linux/sunrpc/clnt.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/sunrpc/clnt.h
---- linux-2.6.29.4/include/linux/sunrpc/clnt.h 2009-03-24 14:22:43.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/sunrpc/clnt.h   2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/sunrpc/clnt.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/sunrpc/clnt.h
+--- linux-2.6.30.1/include/linux/sunrpc/clnt.h 2009-03-24 14:22:43.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/sunrpc/clnt.h      2009-07-04 01:11:39.000000000 +0200
 @@ -43,7 +43,8 @@ struct rpc_clnt {
        unsigned int            cl_softrtry : 1,/* soft timeouts */
                                cl_discrtry : 1,/* disconnect before retry */
@@ -9480,10 +8359,10 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sunrpc/clnt.h linux-2.6.29.4-
  
        struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
        const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/syscalls.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/syscalls.h
---- linux-2.6.29.4/include/linux/syscalls.h    2009-03-24 14:22:43.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/syscalls.h      2009-03-24 14:48:36.000000000 +0100
-@@ -369,6 +369,8 @@ asmlinkage long sys_symlink(const char _
+diff -NurpP --minimal linux-2.6.30.1/include/linux/syscalls.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/syscalls.h
+--- linux-2.6.30.1/include/linux/syscalls.h    2009-06-11 17:13:18.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/syscalls.h 2009-07-04 01:11:39.000000000 +0200
+@@ -425,6 +425,8 @@ asmlinkage long sys_symlink(const char _
  asmlinkage long sys_unlink(const char __user *pathname);
  asmlinkage long sys_rename(const char __user *oldname,
                                const char __user *newname);
@@ -9492,9 +8371,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/syscalls.h linux-2.6.29.4-vs2
  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
  
-diff -NurpP --minimal linux-2.6.29.4/include/linux/sysctl.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/sysctl.h
---- linux-2.6.29.4/include/linux/sysctl.h      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/sysctl.h        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/sysctl.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/sysctl.h
+--- linux-2.6.30.1/include/linux/sysctl.h      2009-06-11 17:13:18.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/sysctl.h   2009-07-04 01:11:39.000000000 +0200
 @@ -70,6 +70,7 @@ enum
        CTL_ABI=9,              /* Binary emulation */
        CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
@@ -9511,9 +8390,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sysctl.h linux-2.6.29.4-vs2.3
  
        KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
        KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/sysfs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/sysfs.h
---- linux-2.6.29.4/include/linux/sysfs.h       2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/sysfs.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/sysfs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/sysfs.h
+--- linux-2.6.30.1/include/linux/sysfs.h       2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/sysfs.h    2009-07-04 01:11:39.000000000 +0200
 @@ -17,6 +17,8 @@
  #include <linux/list.h>
  #include <asm/atomic.h>
@@ -9523,9 +8402,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/sysfs.h linux-2.6.29.4-vs2.3.
  struct kobject;
  struct module;
  
-diff -NurpP --minimal linux-2.6.29.4/include/linux/time.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/time.h
---- linux-2.6.29.4/include/linux/time.h        2009-03-24 14:22:43.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/time.h  2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/time.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/time.h
+--- linux-2.6.30.1/include/linux/time.h        2009-06-11 17:13:18.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/time.h     2009-07-04 01:11:39.000000000 +0200
 @@ -190,6 +190,9 @@ static __always_inline void timespec_add
        a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
        a->tv_nsec = ns;
@@ -9536,10 +8415,10 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/time.h linux-2.6.29.4-vs2.3.0
  #endif /* __KERNEL__ */
  
  #define NFDBITS                       __NFDBITS
-diff -NurpP --minimal linux-2.6.29.4/include/linux/types.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/types.h
---- linux-2.6.29.4/include/linux/types.h       2009-03-24 14:22:43.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/types.h 2009-03-24 14:48:36.000000000 +0100
-@@ -36,6 +36,9 @@ typedef __kernel_uid32_t     uid_t;
+diff -NurpP --minimal linux-2.6.30.1/include/linux/types.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/types.h
+--- linux-2.6.30.1/include/linux/types.h       2009-06-11 17:13:18.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/types.h    2009-07-04 01:11:39.000000000 +0200
+@@ -37,6 +37,9 @@ typedef __kernel_uid32_t     uid_t;
  typedef __kernel_gid32_t      gid_t;
  typedef __kernel_uid16_t        uid16_t;
  typedef __kernel_gid16_t        gid16_t;
@@ -9549,9 +8428,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/types.h linux-2.6.29.4-vs2.3.
  
  typedef unsigned long         uintptr_t;
  
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vroot.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vroot.h
---- linux-2.6.29.4/include/linux/vroot.h       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vroot.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vroot.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vroot.h
+--- linux-2.6.30.1/include/linux/vroot.h       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vroot.h    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,51 @@
 +
 +/*
@@ -9604,9 +8483,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vroot.h linux-2.6.29.4-vs2.3.
 +#define VROOT_CLR_DEV         0x5601
 +
 +#endif /* _LINUX_VROOT_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_base.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_base.h
---- linux-2.6.29.4/include/linux/vs_base.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_base.h       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_base.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_base.h
+--- linux-2.6.30.1/include/linux/vs_base.h     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_base.h  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,10 @@
 +#ifndef _VS_BASE_H
 +#define _VS_BASE_H
@@ -9618,9 +8497,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_base.h linux-2.6.29.4-vs2.
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_context.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_context.h
---- linux-2.6.29.4/include/linux/vs_context.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_context.h    2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_context.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_context.h
+--- linux-2.6.30.1/include/linux/vs_context.h  1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_context.h       2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,227 @@
 +#ifndef _VS_CONTEXT_H
 +#define _VS_CONTEXT_H
@@ -9849,9 +8728,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_context.h linux-2.6.29.4-v
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_cowbl.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_cowbl.h
---- linux-2.6.29.4/include/linux/vs_cowbl.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_cowbl.h      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_cowbl.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_cowbl.h
+--- linux-2.6.30.1/include/linux/vs_cowbl.h    1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_cowbl.h 2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,47 @@
 +#ifndef _VS_COWBL_H
 +#define _VS_COWBL_H
@@ -9900,9 +8779,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_cowbl.h linux-2.6.29.4-vs2
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_cvirt.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_cvirt.h
---- linux-2.6.29.4/include/linux/vs_cvirt.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_cvirt.h      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_cvirt.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_cvirt.h
+--- linux-2.6.30.1/include/linux/vs_cvirt.h    1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_cvirt.h 2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,50 @@
 +#ifndef _VS_CVIRT_H
 +#define _VS_CVIRT_H
@@ -9954,9 +8833,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_cvirt.h linux-2.6.29.4-vs2
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_device.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_device.h
---- linux-2.6.29.4/include/linux/vs_device.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_device.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_device.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_device.h
+--- linux-2.6.30.1/include/linux/vs_device.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_device.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,45 @@
 +#ifndef _VS_DEVICE_H
 +#define _VS_DEVICE_H
@@ -10003,9 +8882,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_device.h linux-2.6.29.4-vs
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_dlimit.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_dlimit.h
---- linux-2.6.29.4/include/linux/vs_dlimit.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_dlimit.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_dlimit.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_dlimit.h
+--- linux-2.6.30.1/include/linux/vs_dlimit.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_dlimit.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,211 @@
 +#ifndef _VS_DLIMIT_H
 +#define _VS_DLIMIT_H
@@ -10218,9 +9097,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_dlimit.h linux-2.6.29.4-vs
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/base.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/base.h
---- linux-2.6.29.4/include/linux/vserver/base.h        1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/base.h  2009-03-25 00:36:15.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/base.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/base.h
+--- linux-2.6.30.1/include/linux/vserver/base.h        1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/base.h     2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,157 @@
 +#ifndef _VX_BASE_H
 +#define _VX_BASE_H
@@ -10379,9 +9258,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/base.h linux-2.6.29.4
 +#define nx_info_state(n, m)   (__nx_state(n) & (m))
 +
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_cmd.h
---- linux-2.6.29.4/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_cmd.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/cacct_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cacct_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cacct_cmd.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,23 @@
 +#ifndef _VX_CACCT_CMD_H
 +#define _VX_CACCT_CMD_H
@@ -10406,9 +9285,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct_cmd.h linux-2.6
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_CACCT_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct_def.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_def.h
---- linux-2.6.29.4/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_def.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/cacct_def.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cacct_def.h
+--- linux-2.6.30.1/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cacct_def.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,43 @@
 +#ifndef _VX_CACCT_DEF_H
 +#define _VX_CACCT_DEF_H
@@ -10453,9 +9332,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct_def.h linux-2.6
 +#endif
 +
 +#endif        /* _VX_CACCT_DEF_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct.h
---- linux-2.6.29.4/include/linux/vserver/cacct.h       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/cacct.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cacct.h
+--- linux-2.6.30.1/include/linux/vserver/cacct.h       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cacct.h    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,15 @@
 +#ifndef _VX_CACCT_H
 +#define _VX_CACCT_H
@@ -10472,9 +9351,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct.h linux-2.6.29.
 +};
 +
 +#endif        /* _VX_CACCT_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct_int.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_int.h
---- linux-2.6.29.4/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_int.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/cacct_int.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cacct_int.h
+--- linux-2.6.30.1/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cacct_int.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,21 @@
 +#ifndef _VX_CACCT_INT_H
 +#define _VX_CACCT_INT_H
@@ -10497,9 +9376,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct_int.h linux-2.6
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_CACCT_INT_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/check.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/check.h
---- linux-2.6.29.4/include/linux/vserver/check.h       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/check.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/check.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/check.h
+--- linux-2.6.30.1/include/linux/vserver/check.h       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/check.h    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,89 @@
 +#ifndef _VS_CHECK_H
 +#define _VS_CHECK_H
@@ -10590,9 +9469,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/check.h linux-2.6.29.
 +#define nx_weak_check(c, m)   ((m) ? nx_check(c, m) : 1)
 +
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/context_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/context_cmd.h
---- linux-2.6.29.4/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/context_cmd.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/context_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/context_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/context_cmd.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,128 @@
 +#ifndef _VX_CONTEXT_CMD_H
 +#define _VX_CONTEXT_CMD_H
@@ -10722,9 +9601,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/context_cmd.h linux-2
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_CONTEXT_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/context.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/context.h
---- linux-2.6.29.4/include/linux/vserver/context.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/context.h       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/context.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/context.h
+--- linux-2.6.30.1/include/linux/vserver/context.h     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/context.h  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,179 @@
 +#ifndef _VX_CONTEXT_H
 +#define _VX_CONTEXT_H
@@ -10905,9 +9784,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/context.h linux-2.6.2
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_CONTEXT_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cvirt_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt_cmd.h
---- linux-2.6.29.4/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt_cmd.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/cvirt_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cvirt_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cvirt_cmd.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,53 @@
 +#ifndef _VX_CVIRT_CMD_H
 +#define _VX_CVIRT_CMD_H
@@ -10962,9 +9841,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cvirt_cmd.h linux-2.6
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_CVIRT_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cvirt_def.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt_def.h
---- linux-2.6.29.4/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt_def.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/cvirt_def.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cvirt_def.h
+--- linux-2.6.30.1/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cvirt_def.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,80 @@
 +#ifndef _VX_CVIRT_DEF_H
 +#define _VX_CVIRT_DEF_H
@@ -11046,9 +9925,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cvirt_def.h linux-2.6
 +#endif
 +
 +#endif        /* _VX_CVIRT_DEF_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cvirt.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt.h
---- linux-2.6.29.4/include/linux/vserver/cvirt.h       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/cvirt.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cvirt.h
+--- linux-2.6.30.1/include/linux/vserver/cvirt.h       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/cvirt.h    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,20 @@
 +#ifndef _VX_CVIRT_H
 +#define _VX_CVIRT_H
@@ -11070,9 +9949,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cvirt.h linux-2.6.29.
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_CVIRT_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/debug_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/debug_cmd.h
---- linux-2.6.29.4/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/debug_cmd.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/debug_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/debug_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/debug_cmd.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,58 @@
 +#ifndef _VX_DEBUG_CMD_H
 +#define _VX_DEBUG_CMD_H
@@ -11132,9 +10011,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/debug_cmd.h linux-2.6
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_DEBUG_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/debug.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/debug.h
---- linux-2.6.29.4/include/linux/vserver/debug.h       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/debug.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/debug.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/debug.h
+--- linux-2.6.30.1/include/linux/vserver/debug.h       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/debug.h    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,127 @@
 +#ifndef _VX_DEBUG_H
 +#define _VX_DEBUG_H
@@ -11263,9 +10142,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/debug.h linux-2.6.29.
 +
 +
 +#endif /* _VX_DEBUG_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/device_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device_cmd.h
---- linux-2.6.29.4/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device_cmd.h    2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/device_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/device_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/device_cmd.h       2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,44 @@
 +#ifndef _VX_DEVICE_CMD_H
 +#define _VX_DEVICE_CMD_H
@@ -11311,9 +10190,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/device_cmd.h linux-2.
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_DEVICE_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/device_def.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device_def.h
---- linux-2.6.29.4/include/linux/vserver/device_def.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device_def.h    2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/device_def.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/device_def.h
+--- linux-2.6.30.1/include/linux/vserver/device_def.h  1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/device_def.h       2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,17 @@
 +#ifndef _VX_DEVICE_DEF_H
 +#define _VX_DEVICE_DEF_H
@@ -11332,9 +10211,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/device_def.h linux-2.
 +};
 +
 +#endif        /* _VX_DEVICE_DEF_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/device.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device.h
---- linux-2.6.29.4/include/linux/vserver/device.h      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device.h        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/device.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/device.h
+--- linux-2.6.30.1/include/linux/vserver/device.h      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/device.h   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,15 @@
 +#ifndef _VX_DEVICE_H
 +#define _VX_DEVICE_H
@@ -11351,9 +10230,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/device.h linux-2.6.29
 +#else /* _VX_DEVICE_H */
 +#warning duplicate inclusion
 +#endif        /* _VX_DEVICE_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/dlimit_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/dlimit_cmd.h
---- linux-2.6.29.4/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/dlimit_cmd.h    2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/dlimit_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/dlimit_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/dlimit_cmd.h       2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,74 @@
 +#ifndef _VX_DLIMIT_CMD_H
 +#define _VX_DLIMIT_CMD_H
@@ -11429,9 +10308,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/dlimit_cmd.h linux-2.
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_DLIMIT_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/dlimit.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/dlimit.h
---- linux-2.6.29.4/include/linux/vserver/dlimit.h      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/dlimit.h        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/dlimit.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/dlimit.h
+--- linux-2.6.30.1/include/linux/vserver/dlimit.h      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/dlimit.h   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,54 @@
 +#ifndef _VX_DLIMIT_H
 +#define _VX_DLIMIT_H
@@ -11487,10 +10366,10 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/dlimit.h linux-2.6.29
 +#else /* _VX_DLIMIT_H */
 +#warning duplicate inclusion
 +#endif        /* _VX_DLIMIT_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/global.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/global.h
---- linux-2.6.29.4/include/linux/vserver/global.h      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/global.h        2009-02-22 22:54:26.000000000 +0100
-@@ -0,0 +1,20 @@
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/global.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/global.h
+--- linux-2.6.30.1/include/linux/vserver/global.h      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/global.h   2009-07-04 04:51:55.000000000 +0200
+@@ -0,0 +1,19 @@
 +#ifndef _VX_GLOBAL_H
 +#define _VX_GLOBAL_H
 +
@@ -11505,15 +10384,14 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/global.h linux-2.6.29
 +extern atomic_t vs_global_fs;
 +extern atomic_t vs_global_mnt_ns;
 +extern atomic_t vs_global_uts_ns;
-+extern atomic_t vs_global_ipc_ns;
 +extern atomic_t vs_global_user_ns;
 +extern atomic_t vs_global_pid_ns;
 +
 +
 +#endif /* _VX_GLOBAL_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/history.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/history.h
---- linux-2.6.29.4/include/linux/vserver/history.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/history.h       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/history.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/history.h
+--- linux-2.6.30.1/include/linux/vserver/history.h     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/history.h  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,197 @@
 +#ifndef _VX_HISTORY_H
 +#define _VX_HISTORY_H
@@ -11712,9 +10590,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/history.h linux-2.6.2
 +#endif /* CONFIG_VSERVER_HISTORY */
 +
 +#endif /* _VX_HISTORY_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/inode_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/inode_cmd.h
---- linux-2.6.29.4/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/inode_cmd.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/inode_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/inode_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/inode_cmd.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,59 @@
 +#ifndef _VX_INODE_CMD_H
 +#define _VX_INODE_CMD_H
@@ -11775,9 +10653,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/inode_cmd.h linux-2.6
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_INODE_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/inode.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/inode.h
---- linux-2.6.29.4/include/linux/vserver/inode.h       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/inode.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/inode.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/inode.h
+--- linux-2.6.30.1/include/linux/vserver/inode.h       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/inode.h    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,38 @@
 +#ifndef _VX_INODE_H
 +#define _VX_INODE_H
@@ -11817,9 +10695,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/inode.h linux-2.6.29.
 +#else /* _VX_INODE_H */
 +#warning duplicate inclusion
 +#endif        /* _VX_INODE_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/Kbuild linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/Kbuild
---- linux-2.6.29.4/include/linux/vserver/Kbuild        1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/Kbuild  2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/Kbuild linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/Kbuild
+--- linux-2.6.30.1/include/linux/vserver/Kbuild        1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/Kbuild     2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,8 @@
 +
 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
@@ -11829,9 +10707,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/Kbuild linux-2.6.29.4
 +
 +unifdef-y += switch.h network.h monitor.h inode.h device.h
 +
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_cmd.h
---- linux-2.6.29.4/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_cmd.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/limit_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/limit_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/limit_cmd.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,69 @@
 +#ifndef _VX_LIMIT_CMD_H
 +#define _VX_LIMIT_CMD_H
@@ -11902,9 +10780,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit_cmd.h linux-2.6
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_LIMIT_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit_def.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_def.h
---- linux-2.6.29.4/include/linux/vserver/limit_def.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_def.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/limit_def.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/limit_def.h
+--- linux-2.6.30.1/include/linux/vserver/limit_def.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/limit_def.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,47 @@
 +#ifndef _VX_LIMIT_DEF_H
 +#define _VX_LIMIT_DEF_H
@@ -11953,9 +10831,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit_def.h linux-2.6
 +#endif
 +
 +#endif        /* _VX_LIMIT_DEF_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit.h
---- linux-2.6.29.4/include/linux/vserver/limit.h       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/limit.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/limit.h
+--- linux-2.6.30.1/include/linux/vserver/limit.h       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/limit.h    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,70 @@
 +#ifndef _VX_LIMIT_H
 +#define _VX_LIMIT_H
@@ -12027,9 +10905,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit.h linux-2.6.29.
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_LIMIT_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit_int.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_int.h
---- linux-2.6.29.4/include/linux/vserver/limit_int.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_int.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/limit_int.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/limit_int.h
+--- linux-2.6.30.1/include/linux/vserver/limit_int.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/limit_int.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,198 @@
 +#ifndef _VX_LIMIT_INT_H
 +#define _VX_LIMIT_INT_H
@@ -12229,9 +11107,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit_int.h linux-2.6
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_LIMIT_INT_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/monitor.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/monitor.h
---- linux-2.6.29.4/include/linux/vserver/monitor.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/monitor.h       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/monitor.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/monitor.h
+--- linux-2.6.30.1/include/linux/vserver/monitor.h     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/monitor.h  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,96 @@
 +#ifndef _VX_MONITOR_H
 +#define _VX_MONITOR_H
@@ -12329,9 +11207,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/monitor.h linux-2.6.2
 +
 +
 +#endif /* _VX_MONITOR_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/network_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/network_cmd.h
---- linux-2.6.29.4/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/network_cmd.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/network_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/network_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/network_cmd.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,150 @@
 +#ifndef _VX_NETWORK_CMD_H
 +#define _VX_NETWORK_CMD_H
@@ -12483,9 +11361,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/network_cmd.h linux-2
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_CONTEXT_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/network.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/network.h
---- linux-2.6.29.4/include/linux/vserver/network.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/network.h       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/network.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/network.h
+--- linux-2.6.30.1/include/linux/vserver/network.h     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/network.h  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,146 @@
 +#ifndef _VX_NETWORK_H
 +#define _VX_NETWORK_H
@@ -12633,9 +11511,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/network.h linux-2.6.2
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_NETWORK_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/percpu.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/percpu.h
---- linux-2.6.29.4/include/linux/vserver/percpu.h      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/percpu.h        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/percpu.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/percpu.h
+--- linux-2.6.30.1/include/linux/vserver/percpu.h      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/percpu.h   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,14 @@
 +#ifndef _VX_PERCPU_H
 +#define _VX_PERCPU_H
@@ -12651,9 +11529,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/percpu.h linux-2.6.29
 +#define       PERCPU_PERCTX   (sizeof(struct _vx_percpu))
 +
 +#endif        /* _VX_PERCPU_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/pid.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/pid.h
---- linux-2.6.29.4/include/linux/vserver/pid.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/pid.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/pid.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/pid.h
+--- linux-2.6.30.1/include/linux/vserver/pid.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/pid.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,51 @@
 +#ifndef _VSERVER_PID_H
 +#define _VSERVER_PID_H
@@ -12706,9 +11584,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/pid.h linux-2.6.29.4-
 +}
 +
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/sched_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched_cmd.h
---- linux-2.6.29.4/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched_cmd.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/sched_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/sched_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/sched_cmd.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,108 @@
 +#ifndef _VX_SCHED_CMD_H
 +#define _VX_SCHED_CMD_H
@@ -12818,9 +11696,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/sched_cmd.h linux-2.6
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_SCHED_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/sched_def.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched_def.h
---- linux-2.6.29.4/include/linux/vserver/sched_def.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched_def.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/sched_def.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/sched_def.h
+--- linux-2.6.30.1/include/linux/vserver/sched_def.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/sched_def.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,68 @@
 +#ifndef _VX_SCHED_DEF_H
 +#define _VX_SCHED_DEF_H
@@ -12890,9 +11768,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/sched_def.h linux-2.6
 +#endif
 +
 +#endif        /* _VX_SCHED_DEF_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/sched.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched.h
---- linux-2.6.29.4/include/linux/vserver/sched.h       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/sched.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/sched.h
+--- linux-2.6.30.1/include/linux/vserver/sched.h       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/sched.h    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,26 @@
 +#ifndef _VX_SCHED_H
 +#define _VX_SCHED_H
@@ -12920,9 +11798,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/sched.h linux-2.6.29.
 +#else /* _VX_SCHED_H */
 +#warning duplicate inclusion
 +#endif        /* _VX_SCHED_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/signal_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/signal_cmd.h
---- linux-2.6.29.4/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/signal_cmd.h    2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/signal_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/signal_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/signal_cmd.h       2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,43 @@
 +#ifndef _VX_SIGNAL_CMD_H
 +#define _VX_SIGNAL_CMD_H
@@ -12967,9 +11845,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/signal_cmd.h linux-2.
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_SIGNAL_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/signal.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/signal.h
---- linux-2.6.29.4/include/linux/vserver/signal.h      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/signal.h        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/signal.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/signal.h
+--- linux-2.6.30.1/include/linux/vserver/signal.h      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/signal.h   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,14 @@
 +#ifndef _VX_SIGNAL_H
 +#define _VX_SIGNAL_H
@@ -12985,9 +11863,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/signal.h linux-2.6.29
 +#else /* _VX_SIGNAL_H */
 +#warning duplicate inclusion
 +#endif        /* _VX_SIGNAL_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/space_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/space_cmd.h
---- linux-2.6.29.4/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/space_cmd.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/space_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/space_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/space_cmd.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,38 @@
 +#ifndef _VX_SPACE_CMD_H
 +#define _VX_SPACE_CMD_H
@@ -13027,9 +11905,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/space_cmd.h linux-2.6
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_SPACE_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/space.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/space.h
---- linux-2.6.29.4/include/linux/vserver/space.h       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/space.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/space.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/space.h
+--- linux-2.6.30.1/include/linux/vserver/space.h       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/space.h    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,12 @@
 +#ifndef _VX_SPACE_H
 +#define _VX_SPACE_H
@@ -13043,9 +11921,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/space.h linux-2.6.29.
 +#else /* _VX_SPACE_H */
 +#warning duplicate inclusion
 +#endif        /* _VX_SPACE_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/switch.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/switch.h
---- linux-2.6.29.4/include/linux/vserver/switch.h      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/switch.h        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/switch.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/switch.h
+--- linux-2.6.30.1/include/linux/vserver/switch.h      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/switch.h   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,98 @@
 +#ifndef _VX_SWITCH_H
 +#define _VX_SWITCH_H
@@ -13145,9 +12023,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/switch.h linux-2.6.29
 +
 +#endif        /* _VX_SWITCH_H */
 +
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/tag_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/tag_cmd.h
---- linux-2.6.29.4/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/tag_cmd.h       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/tag_cmd.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/tag_cmd.h
+--- linux-2.6.30.1/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/tag_cmd.h  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,22 @@
 +#ifndef _VX_TAG_CMD_H
 +#define _VX_TAG_CMD_H
@@ -13171,9 +12049,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/tag_cmd.h linux-2.6.2
 +
 +#endif        /* __KERNEL__ */
 +#endif        /* _VX_TAG_CMD_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/tag.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/tag.h
---- linux-2.6.29.4/include/linux/vserver/tag.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/tag.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vserver/tag.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/tag.h
+--- linux-2.6.30.1/include/linux/vserver/tag.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vserver/tag.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,143 @@
 +#ifndef _DX_TAG_H
 +#define _DX_TAG_H
@@ -13318,9 +12196,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/tag.h linux-2.6.29.4-
 +#endif
 +
 +#endif /* _DX_TAG_H */
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_inet6.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_inet6.h
---- linux-2.6.29.4/include/linux/vs_inet6.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_inet6.h      2009-03-25 00:46:50.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_inet6.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_inet6.h
+--- linux-2.6.30.1/include/linux/vs_inet6.h    1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_inet6.h 2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,246 @@
 +#ifndef _VS_INET6_H
 +#define _VS_INET6_H
@@ -13568,9 +12446,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_inet6.h linux-2.6.29.4-vs2
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_inet.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_inet.h
---- linux-2.6.29.4/include/linux/vs_inet.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_inet.h       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_inet.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_inet.h
+--- linux-2.6.30.1/include/linux/vs_inet.h     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_inet.h  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,342 @@
 +#ifndef _VS_INET_H
 +#define _VS_INET_H
@@ -13914,9 +12792,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_inet.h linux-2.6.29.4-vs2.
 +#else
 +// #warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_limit.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_limit.h
---- linux-2.6.29.4/include/linux/vs_limit.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_limit.h      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_limit.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_limit.h
+--- linux-2.6.30.1/include/linux/vs_limit.h    1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_limit.h 2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,140 @@
 +#ifndef _VS_LIMIT_H
 +#define _VS_LIMIT_H
@@ -14058,9 +12936,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_limit.h linux-2.6.29.4-vs2
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_memory.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_memory.h
---- linux-2.6.29.4/include/linux/vs_memory.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_memory.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_memory.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_memory.h
+--- linux-2.6.30.1/include/linux/vs_memory.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_memory.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,159 @@
 +#ifndef _VS_MEMORY_H
 +#define _VS_MEMORY_H
@@ -14221,9 +13099,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_memory.h linux-2.6.29.4-vs
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_network.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_network.h
---- linux-2.6.29.4/include/linux/vs_network.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_network.h    2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_network.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_network.h
+--- linux-2.6.30.1/include/linux/vs_network.h  1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_network.h       2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,169 @@
 +#ifndef _NX_VS_NETWORK_H
 +#define _NX_VS_NETWORK_H
@@ -14394,9 +13272,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_network.h linux-2.6.29.4-v
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_pid.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_pid.h
---- linux-2.6.29.4/include/linux/vs_pid.h      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_pid.h        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_pid.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_pid.h
+--- linux-2.6.30.1/include/linux/vs_pid.h      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_pid.h   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,95 @@
 +#ifndef _VS_PID_H
 +#define _VS_PID_H
@@ -14493,9 +13371,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_pid.h linux-2.6.29.4-vs2.3
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_sched.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_sched.h
---- linux-2.6.29.4/include/linux/vs_sched.h    1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_sched.h      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_sched.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_sched.h
+--- linux-2.6.30.1/include/linux/vs_sched.h    1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_sched.h 2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,110 @@
 +#ifndef _VS_SCHED_H
 +#define _VS_SCHED_H
@@ -14607,9 +13485,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_sched.h linux-2.6.29.4-vs2
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_socket.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_socket.h
---- linux-2.6.29.4/include/linux/vs_socket.h   1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_socket.h     2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_socket.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_socket.h
+--- linux-2.6.30.1/include/linux/vs_socket.h   1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_socket.h        2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,67 @@
 +#ifndef _VS_SOCKET_H
 +#define _VS_SOCKET_H
@@ -14678,9 +13556,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_socket.h linux-2.6.29.4-vs
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_tag.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_tag.h
---- linux-2.6.29.4/include/linux/vs_tag.h      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_tag.h        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_tag.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_tag.h
+--- linux-2.6.30.1/include/linux/vs_tag.h      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_tag.h   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,47 @@
 +#ifndef _VS_TAG_H
 +#define _VS_TAG_H
@@ -14729,9 +13607,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_tag.h linux-2.6.29.4-vs2.3
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_time.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_time.h
---- linux-2.6.29.4/include/linux/vs_time.h     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_time.h       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/linux/vs_time.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_time.h
+--- linux-2.6.30.1/include/linux/vs_time.h     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/linux/vs_time.h  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,19 @@
 +#ifndef _VS_TIME_H
 +#define _VS_TIME_H
@@ -14752,9 +13630,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_time.h linux-2.6.29.4-vs2.
 +#else
 +#warning duplicate inclusion
 +#endif
-diff -NurpP --minimal linux-2.6.29.4/include/net/addrconf.h linux-2.6.29.4-vs2.3.0.36.14/include/net/addrconf.h
---- linux-2.6.29.4/include/net/addrconf.h      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/net/addrconf.h        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/net/addrconf.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/net/addrconf.h
+--- linux-2.6.30.1/include/net/addrconf.h      2009-06-11 17:13:18.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/net/addrconf.h   2009-07-04 01:11:39.000000000 +0200
 @@ -84,7 +84,8 @@ extern int                   ipv6_dev_get_saddr(struct n
                                               struct net_device *dev,
                                               const struct in6_addr *daddr,
@@ -14765,9 +13643,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/net/addrconf.h linux-2.6.29.4-vs2.3
  extern int                    ipv6_get_lladdr(struct net_device *dev,
                                                struct in6_addr *addr,
                                                unsigned char banned_flags);
-diff -NurpP --minimal linux-2.6.29.4/include/net/af_unix.h linux-2.6.29.4-vs2.3.0.36.14/include/net/af_unix.h
---- linux-2.6.29.4/include/net/af_unix.h       2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/net/af_unix.h 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/net/af_unix.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/net/af_unix.h
+--- linux-2.6.30.1/include/net/af_unix.h       2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/net/af_unix.h    2009-07-04 01:11:39.000000000 +0200
 @@ -4,6 +4,7 @@
  #include <linux/socket.h>
  #include <linux/un.h>
@@ -14776,9 +13654,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/net/af_unix.h linux-2.6.29.4-vs2.3.
  #include <net/sock.h>
  
  extern void unix_inflight(struct file *fp);
-diff -NurpP --minimal linux-2.6.29.4/include/net/inet_timewait_sock.h linux-2.6.29.4-vs2.3.0.36.14/include/net/inet_timewait_sock.h
---- linux-2.6.29.4/include/net/inet_timewait_sock.h    2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/net/inet_timewait_sock.h      2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/net/inet_timewait_sock.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/net/inet_timewait_sock.h
+--- linux-2.6.30.1/include/net/inet_timewait_sock.h    2009-03-24 14:22:44.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/net/inet_timewait_sock.h 2009-07-04 01:11:39.000000000 +0200
 @@ -15,15 +15,14 @@
  #ifndef _INET_TIMEWAIT_SOCK_
  #define _INET_TIMEWAIT_SOCK_
@@ -14808,9 +13686,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/net/inet_timewait_sock.h linux-2.6.
        int                     tw_timeout;
        volatile unsigned char  tw_substate;
        /* 3 bits hole, try to pack */
-diff -NurpP --minimal linux-2.6.29.4/include/net/route.h linux-2.6.29.4-vs2.3.0.36.14/include/net/route.h
---- linux-2.6.29.4/include/net/route.h 2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/net/route.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/net/route.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/net/route.h
+--- linux-2.6.30.1/include/net/route.h 2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/net/route.h      2009-07-04 01:11:39.000000000 +0200
 @@ -135,6 +135,9 @@ static inline void ip_rt_put(struct rtab
                dst_release(&rt->u.dst);
  }
@@ -14857,9 +13735,9 @@ diff -NurpP --minimal linux-2.6.29.4/include/net/route.h linux-2.6.29.4-vs2.3.0.
                err = __ip_route_output_key(net, rp, &fl);
                if (err)
                        return err;
-diff -NurpP --minimal linux-2.6.29.4/include/net/sock.h linux-2.6.29.4-vs2.3.0.36.14/include/net/sock.h
---- linux-2.6.29.4/include/net/sock.h  2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/include/net/sock.h    2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/include/net/sock.h linux-2.6.30.1-vs2.3.0.36.14-pre4/include/net/sock.h
+--- linux-2.6.30.1/include/net/sock.h  2009-06-11 17:13:23.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/include/net/sock.h       2009-07-04 01:11:39.000000000 +0200
 @@ -134,6 +134,10 @@ struct sock_common {
  #ifdef CONFIG_NET_NS
        struct net              *skc_net;
@@ -14882,10 +13760,10 @@ diff -NurpP --minimal linux-2.6.29.4/include/net/sock.h linux-2.6.29.4-vs2.3.0.3
        unsigned char           sk_shutdown : 2,
                                sk_no_check : 2,
                                sk_userlocks : 4;
-diff -NurpP --minimal linux-2.6.29.4/init/main.c linux-2.6.29.4-vs2.3.0.36.14/init/main.c
---- linux-2.6.29.4/init/main.c 2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/init/main.c   2009-03-24 17:22:37.000000000 +0100
-@@ -64,6 +64,7 @@
+diff -NurpP --minimal linux-2.6.30.1/init/main.c linux-2.6.30.1-vs2.3.0.36.14-pre4/init/main.c
+--- linux-2.6.30.1/init/main.c 2009-06-11 17:13:25.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/init/main.c      2009-07-04 01:11:39.000000000 +0200
+@@ -65,6 +65,7 @@
  #include <linux/ftrace.h>
  #include <linux/async.h>
  #include <trace/boot.h>
@@ -14893,7 +13771,7 @@ diff -NurpP --minimal linux-2.6.29.4/init/main.c linux-2.6.29.4-vs2.3.0.36.14/in
  
  #include <asm/io.h>
  #include <asm/bugs.h>
-@@ -381,12 +382,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
+@@ -383,12 +384,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
  
  static void __init setup_per_cpu_areas(void)
  {
@@ -14910,19 +13788,19 @@ diff -NurpP --minimal linux-2.6.29.4/init/main.c linux-2.6.29.4-vs2.3.0.36.14/in
        ptr = alloc_bootmem_pages(size * nr_possible_cpus);
  
        for_each_possible_cpu(i) {
-diff -NurpP --minimal linux-2.6.29.4/ipc/mqueue.c linux-2.6.29.4-vs2.3.0.36.14/ipc/mqueue.c
---- linux-2.6.29.4/ipc/mqueue.c        2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/ipc/mqueue.c  2009-03-24 17:24:19.000000000 +0100
-@@ -31,6 +31,8 @@
- #include <linux/mutex.h>
+diff -NurpP --minimal linux-2.6.30.1/ipc/mqueue.c linux-2.6.30.1-vs2.3.0.36.14-pre4/ipc/mqueue.c
+--- linux-2.6.30.1/ipc/mqueue.c        2009-06-11 17:13:25.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/ipc/mqueue.c     2009-07-04 01:40:51.000000000 +0200
+@@ -32,6 +32,8 @@
  #include <linux/nsproxy.h>
  #include <linux/pid.h>
+ #include <linux/ipc_namespace.h>
 +#include <linux/vs_context.h>
 +#include <linux/vs_limit.h>
  
  #include <net/sock.h>
  #include "util.h"
-@@ -79,6 +81,7 @@ struct mqueue_inode_info {
+@@ -65,6 +67,7 @@ struct mqueue_inode_info {
        struct sigevent notify;
        struct pid* notify_owner;
        struct user_struct *user;       /* user who created, for accounting */
@@ -14930,7 +13808,7 @@ diff -NurpP --minimal linux-2.6.29.4/ipc/mqueue.c linux-2.6.29.4-vs2.3.0.36.14/i
        struct sock *notify_sock;
        struct sk_buff *notify_cookie;
  
-@@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
+@@ -124,6 +127,7 @@ static struct inode *mqueue_get_inode(st
                if (S_ISREG(mode)) {
                        struct mqueue_inode_info *info;
                        struct task_struct *p = current;
@@ -14938,15 +13816,15 @@ diff -NurpP --minimal linux-2.6.29.4/ipc/mqueue.c linux-2.6.29.4-vs2.3.0.36.14/i
                        unsigned long mq_bytes, mq_msg_tblsz;
  
                        inode->i_fop = &mqueue_file_operations;
-@@ -140,6 +144,7 @@ static struct inode *mqueue_get_inode(st
+@@ -138,6 +142,7 @@ static struct inode *mqueue_get_inode(st
                        info->notify_owner = NULL;
                        info->qsize = 0;
                        info->user = NULL;      /* set when all is ok */
 +                      info->vxi = NULL;
                        memset(&info->attr, 0, sizeof(info->attr));
-                       info->attr.mq_maxmsg = msg_max;
-                       info->attr.mq_msgsize = msgsize_max;
-@@ -154,22 +159,26 @@ static struct inode *mqueue_get_inode(st
+                       info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
+                       info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
+@@ -152,22 +157,26 @@ static struct inode *mqueue_get_inode(st
                        spin_lock(&mq_lock);
                        if (u->mq_bytes + mq_bytes < u->mq_bytes ||
                            u->mq_bytes + mq_bytes >
@@ -14974,7 +13852,7 @@ diff -NurpP --minimal linux-2.6.29.4/ipc/mqueue.c linux-2.6.29.4-vs2.3.0.36.14/i
                } else if (S_ISDIR(mode)) {
                        inc_nlink(inode);
                        /* Some things misbehave if size == 0 on a directory */
-@@ -260,10 +269,14 @@ static void mqueue_delete_inode(struct i
+@@ -268,8 +277,11 @@ static void mqueue_delete_inode(struct i
                   (info->attr.mq_maxmsg * info->attr.mq_msgsize));
        user = info->user;
        if (user) {
@@ -14983,15 +13861,20 @@ diff -NurpP --minimal linux-2.6.29.4/ipc/mqueue.c linux-2.6.29.4-vs2.3.0.36.14/i
                spin_lock(&mq_lock);
                user->mq_bytes -= mq_bytes;
 +              vx_ipcmsg_sub(vxi, user, mq_bytes);
-               queues_count--;
+               /*
+                * get_ns_from_inode() ensures that the
+                * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
+@@ -279,6 +291,7 @@ static void mqueue_delete_inode(struct i
+               if (ipc_ns)
+                       ipc_ns->mq_queues_count--;
                spin_unlock(&mq_lock);
 +              put_vx_info(vxi);
                free_uid(user);
        }
- }
-diff -NurpP --minimal linux-2.6.29.4/ipc/msg.c linux-2.6.29.4-vs2.3.0.36.14/ipc/msg.c
---- linux-2.6.29.4/ipc/msg.c   2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/ipc/msg.c     2009-02-22 22:54:26.000000000 +0100
+       if (ipc_ns)
+diff -NurpP --minimal linux-2.6.30.1/ipc/msg.c linux-2.6.30.1-vs2.3.0.36.14-pre4/ipc/msg.c
+--- linux-2.6.30.1/ipc/msg.c   2009-03-24 14:22:44.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/ipc/msg.c        2009-07-04 01:11:39.000000000 +0200
 @@ -38,6 +38,7 @@
  #include <linux/rwsem.h>
  #include <linux/nsproxy.h>
@@ -15008,37 +13891,21 @@ diff -NurpP --minimal linux-2.6.29.4/ipc/msg.c linux-2.6.29.4-vs2.3.0.36.14/ipc/
  
        msq->q_perm.security = NULL;
        retval = security_msg_queue_alloc(msq);
-diff -NurpP --minimal linux-2.6.29.4/ipc/namespace.c linux-2.6.29.4-vs2.3.0.36.14/ipc/namespace.c
---- linux-2.6.29.4/ipc/namespace.c     2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/ipc/namespace.c       2009-02-22 22:54:26.000000000 +0100
-@@ -9,6 +9,8 @@
- #include <linux/rcupdate.h>
- #include <linux/nsproxy.h>
+diff -NurpP --minimal linux-2.6.30.1/ipc/namespace.c linux-2.6.30.1-vs2.3.0.36.14-pre4/ipc/namespace.c
+--- linux-2.6.30.1/ipc/namespace.c     2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/ipc/namespace.c  2009-07-04 04:52:12.000000000 +0200
+@@ -11,6 +11,8 @@
  #include <linux/slab.h>
+ #include <linux/fs.h>
+ #include <linux/mount.h>
 +#include <linux/vs_base.h>
 +#include <linux/vserver/global.h>
  
  #include "util.h"
  
-@@ -35,6 +37,7 @@ static struct ipc_namespace *clone_ipc_n
-       register_ipcns_notifier(ns);
-       kref_init(&ns->kref);
-+      atomic_inc(&vs_global_ipc_ns);
-       return ns;
- }
-@@ -101,6 +104,7 @@ void free_ipc_ns(struct kref *kref)
-       sem_exit_ns(ns);
-       msg_exit_ns(ns);
-       shm_exit_ns(ns);
-+      atomic_dec(&vs_global_ipc_ns);
-       kfree(ns);
-       atomic_dec(&nr_ipc_ns);
-diff -NurpP --minimal linux-2.6.29.4/ipc/sem.c linux-2.6.29.4-vs2.3.0.36.14/ipc/sem.c
---- linux-2.6.29.4/ipc/sem.c   2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/ipc/sem.c     2009-03-31 23:31:33.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/ipc/sem.c linux-2.6.30.1-vs2.3.0.36.14-pre4/ipc/sem.c
+--- linux-2.6.30.1/ipc/sem.c   2009-03-24 14:22:44.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/ipc/sem.c        2009-07-04 01:11:39.000000000 +0200
 @@ -83,6 +83,8 @@
  #include <linux/rwsem.h>
  #include <linux/nsproxy.h>
@@ -15076,19 +13943,19 @@ diff -NurpP --minimal linux-2.6.29.4/ipc/sem.c linux-2.6.29.4-vs2.3.0.36.14/ipc/
        security_sem_free(sma);
        ipc_rcu_putref(sma);
  }
-diff -NurpP --minimal linux-2.6.29.4/ipc/shm.c linux-2.6.29.4-vs2.3.0.36.14/ipc/shm.c
---- linux-2.6.29.4/ipc/shm.c   2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/ipc/shm.c     2009-03-24 14:48:36.000000000 +0100
-@@ -39,6 +39,8 @@
- #include <linux/nsproxy.h>
+diff -NurpP --minimal linux-2.6.30.1/ipc/shm.c linux-2.6.30.1-vs2.3.0.36.14-pre4/ipc/shm.c
+--- linux-2.6.30.1/ipc/shm.c   2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/ipc/shm.c        2009-07-04 01:48:00.000000000 +0200
+@@ -40,6 +40,8 @@
  #include <linux/mount.h>
  #include <linux/ipc_namespace.h>
+ #include <linux/ima.h>
 +#include <linux/vs_context.h>
 +#include <linux/vs_limit.h>
  
  #include <asm/uaccess.h>
  
-@@ -168,7 +170,12 @@ static void shm_open(struct vm_area_stru
+@@ -169,7 +171,12 @@ static void shm_open(struct vm_area_stru
   */
  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
  {
@@ -15102,7 +13969,7 @@ diff -NurpP --minimal linux-2.6.29.4/ipc/shm.c linux-2.6.29.4-vs2.3.0.36.14/ipc/
        shm_rmid(ns, shp);
        shm_unlock(shp);
        if (!is_file_hugepages(shp->shm_file))
-@@ -178,6 +185,7 @@ static void shm_destroy(struct ipc_names
+@@ -179,6 +186,7 @@ static void shm_destroy(struct ipc_names
                                                shp->mlock_user);
        fput (shp->shm_file);
        security_shm_free(shp);
@@ -15110,7 +13977,7 @@ diff -NurpP --minimal linux-2.6.29.4/ipc/shm.c linux-2.6.29.4-vs2.3.0.36.14/ipc/
        ipc_rcu_putref(shp);
  }
  
-@@ -348,11 +356,15 @@ static int newseg(struct ipc_namespace *
+@@ -349,11 +357,15 @@ static int newseg(struct ipc_namespace *
        if (ns->shm_tot + numpages > ns->shm_ctlall)
                return -ENOSPC;
  
@@ -15126,7 +13993,7 @@ diff -NurpP --minimal linux-2.6.29.4/ipc/shm.c linux-2.6.29.4-vs2.3.0.36.14/ipc/
        shp->shm_perm.mode = (shmflg & S_IRWXUGO);
        shp->mlock_user = NULL;
  
-@@ -406,6 +418,7 @@ static int newseg(struct ipc_namespace *
+@@ -408,6 +420,7 @@ static int newseg(struct ipc_namespace *
        ns->shm_tot += numpages;
        error = shp->shm_perm.id;
        shm_unlock(shp);
@@ -15134,9 +14001,9 @@ diff -NurpP --minimal linux-2.6.29.4/ipc/shm.c linux-2.6.29.4-vs2.3.0.36.14/ipc/
        return error;
  
  no_id:
-diff -NurpP --minimal linux-2.6.29.4/kernel/capability.c linux-2.6.29.4-vs2.3.0.36.14/kernel/capability.c
---- linux-2.6.29.4/kernel/capability.c 2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/capability.c   2009-03-24 17:27:28.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/capability.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/capability.c
+--- linux-2.6.30.1/kernel/capability.c 2009-03-24 14:22:44.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/capability.c      2009-07-04 01:11:39.000000000 +0200
 @@ -14,6 +14,7 @@
  #include <linux/security.h>
  #include <linux/syscalls.h>
@@ -15172,9 +14039,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/capability.c linux-2.6.29.4-vs2.3.0.
        if (unlikely(!cap_valid(cap))) {
                printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
                BUG();
-diff -NurpP --minimal linux-2.6.29.4/kernel/compat.c linux-2.6.29.4-vs2.3.0.36.14/kernel/compat.c
---- linux-2.6.29.4/kernel/compat.c     2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/compat.c       2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/compat.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/compat.c
+--- linux-2.6.30.1/kernel/compat.c     2009-03-24 14:22:44.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/compat.c  2009-07-04 01:11:39.000000000 +0200
 @@ -891,7 +891,7 @@ asmlinkage long compat_sys_time(compat_t
        compat_time_t i;
        struct timeval tv;
@@ -15193,12 +14060,12 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/compat.c linux-2.6.29.4-vs2.3.0.36.1
        return 0;
  }
  
-diff -NurpP --minimal linux-2.6.29.4/kernel/exit.c linux-2.6.29.4-vs2.3.0.36.14/kernel/exit.c
---- linux-2.6.29.4/kernel/exit.c       2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/exit.c 2009-05-10 23:58:02.000000000 +0200
-@@ -47,6 +47,10 @@
- #include <linux/task_io_accounting_ops.h>
+diff -NurpP --minimal linux-2.6.30.1/kernel/exit.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/exit.c
+--- linux-2.6.30.1/kernel/exit.c       2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/exit.c    2009-07-04 01:11:39.000000000 +0200
+@@ -48,6 +48,10 @@
  #include <linux/tracehook.h>
+ #include <linux/fs_struct.h>
  #include <linux/init_task.h>
 +#include <linux/vs_limit.h>
 +#include <linux/vs_context.h>
@@ -15207,7 +14074,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/exit.c linux-2.6.29.4-vs2.3.0.36.14/
  #include <trace/sched.h>
  
  #include <asm/uaccess.h>
-@@ -497,9 +501,11 @@ static void close_files(struct files_str
+@@ -489,9 +493,11 @@ static void close_files(struct files_str
                                        filp_close(file, files);
                                        cond_resched();
                                }
@@ -15219,7 +14086,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/exit.c linux-2.6.29.4-vs2.3.0.36.14/
                }
        }
  }
-@@ -1092,10 +1098,15 @@ NORET_TYPE void do_exit(long code)
+@@ -1007,10 +1013,15 @@ NORET_TYPE void do_exit(long code)
        if (tsk->splice_pipe)
                __free_pipe_info(tsk->splice_pipe);
  
@@ -15235,21 +14102,21 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/exit.c linux-2.6.29.4-vs2.3.0.36.14/
        BUG();
        /* Avoid "noreturn function does return".  */
        for (;;)
-diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/kernel/fork.c
---- linux-2.6.29.4/kernel/fork.c       2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/fork.c 2009-05-10 23:58:22.000000000 +0200
-@@ -60,6 +60,10 @@
- #include <linux/tty.h>
- #include <linux/proc_fs.h>
- #include <linux/blkdev.h>
+diff -NurpP --minimal linux-2.6.30.1/kernel/fork.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/fork.c
+--- linux-2.6.30.1/kernel/fork.c       2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/fork.c    2009-07-04 01:50:45.000000000 +0200
+@@ -63,6 +63,10 @@
+ #include <linux/fs_struct.h>
+ #include <trace/sched.h>
+ #include <linux/magic.h>
 +#include <linux/vs_context.h>
 +#include <linux/vs_network.h>
 +#include <linux/vs_limit.h>
 +#include <linux/vs_memory.h>
- #include <trace/sched.h>
  
  #include <asm/pgtable.h>
-@@ -140,6 +144,8 @@ void free_task(struct task_struct *tsk)
+ #include <asm/pgalloc.h>
+@@ -142,6 +146,8 @@ void free_task(struct task_struct *tsk)
        prop_local_destroy_single(&tsk->dirties);
        free_thread_info(tsk->stack);
        rt_mutex_debug_task_free(tsk);
@@ -15258,16 +14125,16 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
        ftrace_graph_exit_task(tsk);
        free_task_struct(tsk);
  }
-@@ -279,6 +285,8 @@ static int dup_mmap(struct mm_struct *mm
+@@ -285,6 +291,8 @@ static int dup_mmap(struct mm_struct *mm
        mm->free_area_cache = oldmm->mmap_base;
        mm->cached_hole_size = ~0UL;
        mm->map_count = 0;
 +      __set_mm_counter(mm, file_rss, 0);
 +      __set_mm_counter(mm, anon_rss, 0);
-       cpus_clear(mm->cpu_vm_mask);
+       cpumask_clear(mm_cpumask(mm));
        mm->mm_rb = RB_ROOT;
        rb_link = &mm->mm_rb.rb_node;
-@@ -290,7 +298,7 @@ static int dup_mmap(struct mm_struct *mm
+@@ -296,7 +304,7 @@ static int dup_mmap(struct mm_struct *mm
  
                if (mpnt->vm_flags & VM_DONTCOPY) {
                        long pages = vma_pages(mpnt);
@@ -15276,7 +14143,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
                        vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
                                                                -pages);
                        continue;
-@@ -423,8 +431,8 @@ static struct mm_struct * mm_init(struct
+@@ -429,8 +437,8 @@ static struct mm_struct * mm_init(struct
        mm->flags = (current->mm) ? current->mm->flags : default_dump_filter;
        mm->core_state = NULL;
        mm->nr_ptes = 0;
@@ -15287,7 +14154,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
        spin_lock_init(&mm->page_table_lock);
        spin_lock_init(&mm->ioctx_lock);
        INIT_HLIST_HEAD(&mm->ioctx_list);
-@@ -435,6 +443,7 @@ static struct mm_struct * mm_init(struct
+@@ -441,6 +449,7 @@ static struct mm_struct * mm_init(struct
        if (likely(!mm_alloc_pgd(mm))) {
                mm->def_flags = 0;
                mmu_notifier_mm_init(mm);
@@ -15295,7 +14162,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
                return mm;
        }
  
-@@ -468,6 +477,7 @@ void __mmdrop(struct mm_struct *mm)
+@@ -474,6 +483,7 @@ void __mmdrop(struct mm_struct *mm)
        mm_free_pgd(mm);
        destroy_context(mm);
        mmu_notifier_mm_destroy(mm);
@@ -15303,7 +14170,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
        free_mm(mm);
  }
  EXPORT_SYMBOL_GPL(__mmdrop);
-@@ -594,6 +604,7 @@ struct mm_struct *dup_mm(struct task_str
+@@ -600,6 +610,7 @@ struct mm_struct *dup_mm(struct task_str
                goto fail_nomem;
  
        memcpy(mm, oldmm, sizeof(*mm));
@@ -15311,7 +14178,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
  
        /* Initializing for Swap token stuff */
        mm->token_priority = 0;
-@@ -627,6 +638,7 @@ fail_nocontext:
+@@ -633,6 +644,7 @@ fail_nocontext:
         * If init_new_context() failed, we cannot use mmput() to free the mm
         * because it calls destroy_context()
         */
@@ -15319,7 +14186,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
        mm_free_pgd(mm);
        free_mm(mm);
        return NULL;
-@@ -943,6 +955,8 @@ static struct task_struct *copy_process(
+@@ -954,6 +966,8 @@ static struct task_struct *copy_process(
        int retval;
        struct task_struct *p;
        int cgroup_callbacks_done = 0;
@@ -15328,7 +14195,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
  
        if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
                return ERR_PTR(-EINVAL);
-@@ -977,12 +991,28 @@ static struct task_struct *copy_process(
+@@ -988,12 +1002,28 @@ static struct task_struct *copy_process(
        DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
        DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
  #endif
@@ -15358,7 +14225,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
        }
  
        retval = copy_creds(p, clone_flags);
-@@ -1259,6 +1289,18 @@ static struct task_struct *copy_process(
+@@ -1263,6 +1293,18 @@ static struct task_struct *copy_process(
  
        total_forks++;
        spin_unlock(&current->sighand->siglock);
@@ -15377,7 +14244,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
        write_unlock_irq(&tasklist_lock);
        proc_fork_connector(p);
        cgroup_post_fork(p);
-@@ -1303,6 +1345,9 @@ bad_fork_cleanup_count:
+@@ -1307,6 +1349,9 @@ bad_fork_cleanup_count:
        atomic_dec(&p->cred->user->processes);
        put_cred(p->real_cred);
        put_cred(p->cred);
@@ -15387,9 +14254,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/
  bad_fork_free:
        free_task(p);
  fork_out:
-diff -NurpP --minimal linux-2.6.29.4/kernel/kthread.c linux-2.6.29.4-vs2.3.0.36.14/kernel/kthread.c
---- linux-2.6.29.4/kernel/kthread.c    2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/kthread.c      2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/kthread.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/kthread.c
+--- linux-2.6.30.1/kernel/kthread.c    2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/kthread.c 2009-07-04 01:11:39.000000000 +0200
 @@ -13,6 +13,7 @@
  #include <linux/file.h>
  #include <linux/module.h>
@@ -15398,18 +14265,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/kthread.c linux-2.6.29.4-vs2.3.0.36.
  #include <trace/sched.h>
  
  #define KTHREAD_NICE_LEVEL (-5)
-@@ -102,7 +103,7 @@ static void create_kthread(struct kthrea
-               struct sched_param param = { .sched_priority = 0 };
-               wait_for_completion(&create->started);
-               read_lock(&tasklist_lock);
--              create->result = find_task_by_pid_ns(pid, &init_pid_ns);
-+              create->result = find_task_by_real_pid(pid);
-               read_unlock(&tasklist_lock);
-               /*
-                * root may have changed our (kthreadd's) priority or CPU mask.
-diff -NurpP --minimal linux-2.6.29.4/kernel/Makefile linux-2.6.29.4-vs2.3.0.36.14/kernel/Makefile
---- linux-2.6.29.4/kernel/Makefile     2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/Makefile       2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/Makefile linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/Makefile
+--- linux-2.6.30.1/kernel/Makefile     2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/Makefile  2009-07-04 01:11:39.000000000 +0200
 @@ -22,6 +22,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
  CFLAGS_REMOVE_sched_clock.o = -pg
  endif
@@ -15418,9 +14276,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/Makefile linux-2.6.29.4-vs2.3.0.36.1
  obj-$(CONFIG_FREEZER) += freezer.o
  obj-$(CONFIG_PROFILING) += profile.o
  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
-diff -NurpP --minimal linux-2.6.29.4/kernel/nsproxy.c linux-2.6.29.4-vs2.3.0.36.14/kernel/nsproxy.c
---- linux-2.6.29.4/kernel/nsproxy.c    2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/nsproxy.c      2009-03-25 00:39:02.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/nsproxy.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/nsproxy.c
+--- linux-2.6.30.1/kernel/nsproxy.c    2009-03-24 14:22:44.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/nsproxy.c 2009-07-04 01:11:39.000000000 +0200
 @@ -19,6 +19,8 @@
  #include <linux/mnt_namespace.h>
  #include <linux/utsname.h>
@@ -15583,9 +14441,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/nsproxy.c linux-2.6.29.4-vs2.3.0.36.
        if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
                               CLONE_NEWNET)))
                return 0;
-diff -NurpP --minimal linux-2.6.29.4/kernel/pid.c linux-2.6.29.4-vs2.3.0.36.14/kernel/pid.c
---- linux-2.6.29.4/kernel/pid.c        2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/pid.c  2009-05-10 23:59:04.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/kernel/pid.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/pid.c
+--- linux-2.6.30.1/kernel/pid.c        2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/pid.c     2009-07-04 01:11:39.000000000 +0200
 @@ -36,6 +36,7 @@
  #include <linux/pid_namespace.h>
  #include <linux/init_task.h>
@@ -15630,7 +14488,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/pid.c linux-2.6.29.4-vs2.3.0.36.14/k
  }
  EXPORT_SYMBOL(find_task_by_pid_ns);
  
-@@ -431,7 +435,7 @@ struct pid *find_get_pid(pid_t nr)
+@@ -433,7 +437,7 @@ struct pid *find_get_pid(pid_t nr)
  }
  EXPORT_SYMBOL_GPL(find_get_pid);
  
@@ -15639,7 +14497,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/pid.c linux-2.6.29.4-vs2.3.0.36.14/k
  {
        struct upid *upid;
        pid_t nr = 0;
-@@ -444,6 +448,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
+@@ -446,6 +450,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
        return nr;
  }
  
@@ -15651,9 +14509,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/pid.c linux-2.6.29.4-vs2.3.0.36.14/k
  pid_t pid_vnr(struct pid *pid)
  {
        return pid_nr_ns(pid, current->nsproxy->pid_ns);
-diff -NurpP --minimal linux-2.6.29.4/kernel/pid_namespace.c linux-2.6.29.4-vs2.3.0.36.14/kernel/pid_namespace.c
---- linux-2.6.29.4/kernel/pid_namespace.c      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/pid_namespace.c        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/pid_namespace.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/pid_namespace.c
+--- linux-2.6.30.1/kernel/pid_namespace.c      2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/pid_namespace.c   2009-07-04 01:11:39.000000000 +0200
 @@ -13,6 +13,7 @@
  #include <linux/syscalls.h>
  #include <linux/err.h>
@@ -15678,9 +14536,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/pid_namespace.c linux-2.6.29.4-vs2.3
        kmem_cache_free(pid_ns_cachep, ns);
  }
  
-diff -NurpP --minimal linux-2.6.29.4/kernel/posix-timers.c linux-2.6.29.4-vs2.3.0.36.14/kernel/posix-timers.c
---- linux-2.6.29.4/kernel/posix-timers.c       2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/posix-timers.c 2009-05-06 21:28:16.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/kernel/posix-timers.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/posix-timers.c
+--- linux-2.6.30.1/kernel/posix-timers.c       2009-03-24 14:22:44.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/posix-timers.c    2009-07-04 01:11:39.000000000 +0200
 @@ -46,6 +46,7 @@
  #include <linux/wait.h>
  #include <linux/workqueue.h>
@@ -15716,18 +14574,18 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/posix-timers.c linux-2.6.29.4-vs2.3.
        /* If we failed to send the signal the timer stops. */
        return ret > 0;
  }
-diff -NurpP --minimal linux-2.6.29.4/kernel/printk.c linux-2.6.29.4-vs2.3.0.36.14/kernel/printk.c
---- linux-2.6.29.4/kernel/printk.c     2009-03-24 14:22:44.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/printk.c       2009-03-24 14:48:36.000000000 +0100
-@@ -32,6 +32,7 @@
- #include <linux/security.h>
+diff -NurpP --minimal linux-2.6.30.1/kernel/printk.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/printk.c
+--- linux-2.6.30.1/kernel/printk.c     2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/printk.c  2009-07-04 01:56:52.000000000 +0200
+@@ -33,6 +33,7 @@
  #include <linux/bootmem.h>
  #include <linux/syscalls.h>
+ #include <linux/kexec.h>
 +#include <linux/vs_cvirt.h>
  
  #include <asm/uaccess.h>
  
-@@ -251,18 +252,13 @@ int do_syslog(int type, char __user *buf
+@@ -270,18 +271,13 @@ int do_syslog(int type, char __user *buf
        unsigned i, j, limit, count;
        int do_clear = 0;
        char c;
@@ -15748,7 +14606,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/printk.c linux-2.6.29.4-vs2.3.0.36.1
                error = -EINVAL;
                if (!buf || len < 0)
                        goto out;
-@@ -273,6 +269,16 @@ int do_syslog(int type, char __user *buf
+@@ -292,6 +288,16 @@ int do_syslog(int type, char __user *buf
                        error = -EFAULT;
                        goto out;
                }
@@ -15765,7 +14623,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/printk.c linux-2.6.29.4-vs2.3.0.36.1
                error = wait_event_interruptible(log_wait,
                                                        (log_start - log_end));
                if (error)
-@@ -297,16 +303,6 @@ int do_syslog(int type, char __user *buf
+@@ -316,16 +322,6 @@ int do_syslog(int type, char __user *buf
                do_clear = 1;
                /* FALL THRU */
        case 3:         /* Read last kernel messages */
@@ -15782,18 +14640,18 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/printk.c linux-2.6.29.4-vs2.3.0.36.1
                count = len;
                if (count > log_buf_len)
                        count = log_buf_len;
-diff -NurpP --minimal linux-2.6.29.4/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/kernel/ptrace.c
---- linux-2.6.29.4/kernel/ptrace.c     2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/ptrace.c       2009-05-10 23:42:01.000000000 +0200
-@@ -21,6 +21,7 @@
- #include <linux/audit.h>
+diff -NurpP --minimal linux-2.6.30.1/kernel/ptrace.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/ptrace.c
+--- linux-2.6.30.1/kernel/ptrace.c     2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/ptrace.c  2009-07-04 02:00:10.000000000 +0200
+@@ -22,6 +22,7 @@
  #include <linux/pid_namespace.h>
  #include <linux/syscalls.h>
+ #include <linux/uaccess.h>
 +#include <linux/vs_context.h>
  
- #include <asm/pgtable.h>
- #include <asm/uaccess.h>
-@@ -159,6 +160,11 @@ int __ptrace_may_access(struct task_stru
+ /*
+@@ -161,6 +162,11 @@ int __ptrace_may_access(struct task_stru
                dumpable = get_dumpable(task->mm);
        if (!dumpable && !capable(CAP_SYS_PTRACE))
                return -EPERM;
@@ -15805,7 +14663,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.1
  
        return security_ptrace_may_access(task, mode);
  }
-@@ -596,6 +602,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
+@@ -672,6 +678,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
                goto out;
        }
  
@@ -15816,9 +14674,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.1
        if (request == PTRACE_ATTACH) {
                ret = ptrace_attach(child);
                /*
-diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14/kernel/sched.c
---- linux-2.6.29.4/kernel/sched.c      2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sched.c        2009-05-10 23:42:01.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/kernel/sched.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sched.c
+--- linux-2.6.30.1/kernel/sched.c      2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sched.c   2009-07-04 01:59:40.000000000 +0200
 @@ -72,6 +72,8 @@
  #include <linux/debugfs.h>
  #include <linux/ctype.h>
@@ -15828,7 +14686,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
  #include <trace/sched.h>
  
  #include <asm/tlb.h>
-@@ -617,6 +619,16 @@ struct rq {
+@@ -637,6 +639,16 @@ struct rq {
  #endif
        struct hrtimer hrtick_timer;
  #endif
@@ -15845,15 +14703,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
  
  #ifdef CONFIG_SCHEDSTATS
        /* latency stats */
-@@ -1713,6 +1725,7 @@ static void update_avg(u64 *avg, u64 sam
- static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
- {
-+      // BUG_ON(p->state & TASK_ONHOLD);
-       sched_info_queued(p);
-       p->sched_class->enqueue_task(rq, p, wakeup);
-       p->se.on_rq = 1;
-@@ -1836,6 +1849,8 @@ static inline void check_class_changed(s
+@@ -1910,6 +1922,8 @@ static inline void check_class_changed(s
                p->sched_class->prio_changed(rq, p, oldprio, running);
  }
  
@@ -15862,7 +14712,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
  #ifdef CONFIG_SMP
  
  /* Used instead of source_load when we know the type == 0 */
-@@ -1923,6 +1938,7 @@ migrate_task(struct task_struct *p, int 
+@@ -1997,6 +2011,7 @@ migrate_task(struct task_struct *p, int 
  {
        struct rq *rq = task_rq(p);
  
@@ -15870,7 +14720,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
        /*
         * If the task is not on a runqueue (and not running), then
         * it is sufficient to simply update the task's cpu field.
-@@ -2250,6 +2266,8 @@ static int sched_balance_self(int cpu, i
+@@ -2324,6 +2339,8 @@ static int sched_balance_self(int cpu, i
  
  #endif /* CONFIG_SMP */
  
@@ -15879,7 +14729,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
  /***
   * try_to_wake_up - wake up a thread
   * @p: the to-be-woken-up thread
-@@ -2294,6 +2312,13 @@ static int try_to_wake_up(struct task_st
+@@ -2368,6 +2385,13 @@ static int try_to_wake_up(struct task_st
        rq = task_rq_lock(p, &flags);
        update_rq_clock(rq);
        old_state = p->state;
@@ -15893,7 +14743,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
        if (!(old_state & state))
                goto out;
  
-@@ -2315,6 +2340,12 @@ static int try_to_wake_up(struct task_st
+@@ -2389,6 +2413,12 @@ static int try_to_wake_up(struct task_st
                /* might preempt at this point */
                rq = task_rq_lock(p, &flags);
                old_state = p->state;
@@ -15906,7 +14756,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
                if (!(old_state & state))
                        goto out;
                if (p->se.on_rq)
-@@ -4226,16 +4257,19 @@ void account_user_time(struct task_struc
+@@ -4607,16 +4637,19 @@ void account_user_time(struct task_struc
                       cputime_t cputime_scaled)
  {
        struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
@@ -15927,7 +14777,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
                cpustat->nice = cputime64_add(cpustat->nice, tmp);
        else
                cpustat->user = cputime64_add(cpustat->user, tmp);
-@@ -4279,6 +4313,7 @@ void account_system_time(struct task_str
+@@ -4662,6 +4695,7 @@ void account_system_time(struct task_str
                         cputime_t cputime, cputime_t cputime_scaled)
  {
        struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
@@ -15935,7 +14785,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
        cputime64_t tmp;
  
        if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
-@@ -4289,6 +4324,7 @@ void account_system_time(struct task_str
+@@ -4672,6 +4706,7 @@ void account_system_time(struct task_str
        /* Add system time to process. */
        p->stime = cputime_add(p->stime, cputime);
        p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
@@ -15943,19 +14793,19 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
        account_group_system_time(p, cputime);
  
        /* Add system time to cpustat. */
-@@ -4644,6 +4680,11 @@ need_resched_nonpreemptible:
+@@ -5049,6 +5084,11 @@ need_resched_nonpreemptible:
                idle_balance(cpu, rq);
  
-       prev->sched_class->put_prev_task(rq, prev);
+       put_prev_task(rq, prev);
 +
 +      vx_set_rq_time(rq, jiffies);    /* update time */
 +      vx_schedule(prev, rq, cpu);     /* hold if over limit */
 +      vx_try_unhold(rq, cpu);         /* unhold if refilled */
 +
-       next = pick_next_task(rq, prev);
+       next = pick_next_task(rq);
  
        if (likely(prev != next)) {
-@@ -5209,7 +5250,7 @@ SYSCALL_DEFINE1(nice, int, increment)
+@@ -5696,7 +5736,7 @@ SYSCALL_DEFINE1(nice, int, increment)
                nice = 19;
  
        if (increment < 0 && !can_nice(current, nice))
@@ -15964,7 +14814,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
  
        retval = security_task_setnice(current, nice);
        if (retval)
-@@ -8485,7 +8526,10 @@ void __init sched_init(void)
+@@ -8985,7 +9025,10 @@ void __init sched_init(void)
  
  #endif
  #endif /* CONFIG_FAIR_GROUP_SCHED */
@@ -15976,9 +14826,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14
                rq->rt.rt_runtime = def_rt_bandwidth.rt_runtime;
  #ifdef CONFIG_RT_GROUP_SCHED
                INIT_LIST_HEAD(&rq->leaf_rt_rq_list);
-diff -NurpP --minimal linux-2.6.29.4/kernel/sched_fair.c linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_fair.c
---- linux-2.6.29.4/kernel/sched_fair.c 2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_fair.c   2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/sched_fair.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sched_fair.c
+--- linux-2.6.30.1/kernel/sched_fair.c 2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sched_fair.c      2009-07-04 01:11:39.000000000 +0200
 @@ -717,6 +717,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
        check_spread(cfs_rq, se);
        if (se != cfs_rq->curr)
@@ -15998,9 +14848,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched_fair.c linux-2.6.29.4-vs2.3.0.
        account_entity_dequeue(cfs_rq, se);
        update_min_vruntime(cfs_rq);
  }
-diff -NurpP --minimal linux-2.6.29.4/kernel/sched_hard.h linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_hard.h
---- linux-2.6.29.4/kernel/sched_hard.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_hard.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/sched_hard.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sched_hard.h
+--- linux-2.6.30.1/kernel/sched_hard.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sched_hard.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,353 @@
 +
 +#ifdef CONFIG_VSERVER_IDLELIMIT
@@ -16355,9 +15205,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched_hard.h linux-2.6.29.4-vs2.3.0.
 +
 +#endif /* CONFIG_VSERVER_HARDCPU */
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/sched_mon.h linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_mon.h
---- linux-2.6.29.4/kernel/sched_mon.h  1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_mon.h    2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/sched_mon.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sched_mon.h
+--- linux-2.6.30.1/kernel/sched_mon.h  1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sched_mon.h       2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,200 @@
 +
 +#include <linux/vserver/monitor.h>
@@ -16559,9 +15409,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sched_mon.h linux-2.6.29.4-vs2.3.0.3
 +
 +#endif /* CONFIG_VSERVER_MONITOR */
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/signal.c linux-2.6.29.4-vs2.3.0.36.14/kernel/signal.c
---- linux-2.6.29.4/kernel/signal.c     2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/signal.c       2009-04-20 23:37:12.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/kernel/signal.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/signal.c
+--- linux-2.6.30.1/kernel/signal.c     2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/signal.c  2009-07-04 01:11:39.000000000 +0200
 @@ -27,6 +27,8 @@
  #include <linux/freezer.h>
  #include <linux/pid_namespace.h>
@@ -16571,7 +15421,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/signal.c linux-2.6.29.4-vs2.3.0.36.1
  #include <trace/sched.h>
  
  #include <asm/param.h>
-@@ -584,6 +586,14 @@ static int check_kill_permission(int sig
+@@ -595,6 +597,14 @@ static int check_kill_permission(int sig
        if (!valid_signal(sig))
                return -EINVAL;
  
@@ -16586,7 +15436,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/signal.c linux-2.6.29.4-vs2.3.0.36.1
        if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
                return 0;
  
-@@ -611,6 +621,20 @@ static int check_kill_permission(int sig
+@@ -622,6 +632,20 @@ static int check_kill_permission(int sig
                }
        }
  
@@ -16607,7 +15457,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/signal.c linux-2.6.29.4-vs2.3.0.36.1
        return security_task_kill(t, info, sig, 0);
  }
  
-@@ -1076,7 +1100,7 @@ int kill_pid_info(int sig, struct siginf
+@@ -1104,7 +1128,7 @@ int kill_pid_info(int sig, struct siginf
        rcu_read_lock();
  retry:
        p = pid_task(pid, PIDTYPE_PID);
@@ -16616,7 +15466,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/signal.c linux-2.6.29.4-vs2.3.0.36.1
                error = group_send_sig_info(sig, info, p);
                if (unlikely(error == -ESRCH))
                        /*
-@@ -1115,7 +1139,7 @@ int kill_pid_info_as_uid(int sig, struct
+@@ -1143,7 +1167,7 @@ int kill_pid_info_as_uid(int sig, struct
  
        read_lock(&tasklist_lock);
        p = pid_task(pid, PIDTYPE_PID);
@@ -16625,7 +15475,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/signal.c linux-2.6.29.4-vs2.3.0.36.1
                ret = -ESRCH;
                goto out_unlock;
        }
-@@ -1169,8 +1193,10 @@ static int kill_something_info(int sig, 
+@@ -1197,8 +1221,10 @@ static int kill_something_info(int sig, 
                struct task_struct * p;
  
                for_each_process(p) {
@@ -16638,8 +15488,8 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/signal.c linux-2.6.29.4-vs2.3.0.36.1
                                int err = group_send_sig_info(sig, info, p);
                                ++count;
                                if (err != -EPERM)
-@@ -1849,6 +1875,11 @@ relock:
-                   !signal_group_exit(signal))
+@@ -1884,6 +1910,11 @@ relock:
+                               !sig_kernel_only(signr))
                        continue;
  
 +              /* virtual init is protected against user signals */
@@ -16650,21 +15500,21 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/signal.c linux-2.6.29.4-vs2.3.0.36.1
                if (sig_kernel_stop(signr)) {
                        /*
                         * The default action is to stop all threads in
-diff -NurpP --minimal linux-2.6.29.4/kernel/softirq.c linux-2.6.29.4-vs2.3.0.36.14/kernel/softirq.c
---- linux-2.6.29.4/kernel/softirq.c    2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/softirq.c      2009-04-30 12:14:53.000000000 +0200
-@@ -23,6 +23,7 @@
- #include <linux/rcupdate.h>
+diff -NurpP --minimal linux-2.6.30.1/kernel/softirq.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/softirq.c
+--- linux-2.6.30.1/kernel/softirq.c    2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/softirq.c 2009-07-04 01:48:28.000000000 +0200
+@@ -25,6 +25,7 @@
  #include <linux/smp.h>
  #include <linux/tick.h>
+ #include <trace/irq.h>
 +#include <linux/vs_context.h>
  
  #include <asm/irq.h>
  /*
-diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/kernel/sys.c
---- linux-2.6.29.4/kernel/sys.c        2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sys.c  2009-03-24 14:48:36.000000000 +0100
-@@ -39,6 +39,7 @@
+diff -NurpP --minimal linux-2.6.30.1/kernel/sys.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sys.c
+--- linux-2.6.30.1/kernel/sys.c        2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sys.c     2009-07-04 01:11:39.000000000 +0200
+@@ -40,6 +40,7 @@
  #include <linux/syscalls.h>
  #include <linux/kprobes.h>
  #include <linux/user_namespace.h>
@@ -16672,7 +15522,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/k
  
  #include <asm/uaccess.h>
  #include <asm/io.h>
-@@ -128,7 +129,10 @@ static int set_one_prio(struct task_stru
+@@ -129,7 +130,10 @@ static int set_one_prio(struct task_stru
                goto out;
        }
        if (niceval < task_nice(p) && !can_nice(p, niceval)) {
@@ -16684,7 +15534,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/k
                goto out;
        }
        no_nice = security_task_setnice(p, niceval);
-@@ -177,6 +181,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
+@@ -178,6 +182,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
                        else
                                pgrp = task_pgrp(current);
                        do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
@@ -16693,7 +15543,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/k
                                error = set_one_prio(p, niceval, error);
                        } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
                        break;
-@@ -238,6 +244,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
+@@ -239,6 +245,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
                        else
                                pgrp = task_pgrp(current);
                        do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
@@ -16702,7 +15552,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/k
                                niceval = 20 - task_nice(p);
                                if (niceval > retval)
                                        retval = niceval;
-@@ -347,6 +355,9 @@ void kernel_power_off(void)
+@@ -348,6 +356,9 @@ void kernel_power_off(void)
        machine_power_off();
  }
  EXPORT_SYMBOL_GPL(kernel_power_off);
@@ -16712,7 +15562,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/k
  /*
   * Reboot system call: for obvious reasons only root may call it,
   * and even root needs to set up some magic numbers in the registers
-@@ -378,6 +389,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
+@@ -380,6 +391,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
        if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
                cmd = LINUX_REBOOT_CMD_HALT;
  
@@ -16722,7 +15572,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/k
        lock_kernel();
        switch (cmd) {
        case LINUX_REBOOT_CMD_RESTART:
-@@ -1420,7 +1434,7 @@ SYSCALL_DEFINE2(sethostname, char __user
+@@ -1413,7 +1427,7 @@ SYSCALL_DEFINE2(sethostname, char __user
        int errno;
        char tmp[__NEW_UTS_LEN];
  
@@ -16731,7 +15581,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/k
                return -EPERM;
        if (len < 0 || len > __NEW_UTS_LEN)
                return -EINVAL;
-@@ -1469,7 +1483,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
+@@ -1462,7 +1476,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
        int errno;
        char tmp[__NEW_UTS_LEN];
  
@@ -16740,7 +15590,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/k
                return -EPERM;
        if (len < 0 || len > __NEW_UTS_LEN)
                return -EINVAL;
-@@ -1538,7 +1552,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
+@@ -1531,7 +1545,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
                return -EINVAL;
        old_rlim = current->signal->rlim + resource;
        if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
@@ -16749,10 +15599,10 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/k
                return -EPERM;
        if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
                return -EPERM;
-diff -NurpP --minimal linux-2.6.29.4/kernel/sysctl.c linux-2.6.29.4-vs2.3.0.36.14/kernel/sysctl.c
---- linux-2.6.29.4/kernel/sysctl.c     2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sysctl.c       2009-04-30 12:14:53.000000000 +0200
-@@ -111,6 +111,7 @@ static int ngroups_max = NGROUPS_MAX;
+diff -NurpP --minimal linux-2.6.30.1/kernel/sysctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sysctl.c
+--- linux-2.6.30.1/kernel/sysctl.c     2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sysctl.c  2009-07-04 01:11:39.000000000 +0200
+@@ -115,6 +115,7 @@ static int ngroups_max = NGROUPS_MAX;
  #ifdef CONFIG_MODULES
  extern char modprobe_path[];
  #endif
@@ -16760,7 +15610,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sysctl.c linux-2.6.29.4-vs2.3.0.36.1
  #ifdef CONFIG_CHR_DEV_SG
  extern int sg_big_buff;
  #endif
-@@ -542,6 +543,15 @@ static struct ctl_table kern_table[] = {
+@@ -546,6 +547,15 @@ static struct ctl_table kern_table[] = {
                .strategy       = &sysctl_string,
        },
  #endif
@@ -16776,9 +15626,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sysctl.c linux-2.6.29.4-vs2.3.0.36.1
  #ifdef CONFIG_CHR_DEV_SG
        {
                .ctl_name       = KERN_SG_BIG_BUFF,
-diff -NurpP --minimal linux-2.6.29.4/kernel/sysctl_check.c linux-2.6.29.4-vs2.3.0.36.14/kernel/sysctl_check.c
---- linux-2.6.29.4/kernel/sysctl_check.c       2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sysctl_check.c 2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/sysctl_check.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sysctl_check.c
+--- linux-2.6.30.1/kernel/sysctl_check.c       2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/sysctl_check.c    2009-07-04 01:11:39.000000000 +0200
 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
  
        { KERN_PANIC,                   "panic" },
@@ -16787,7 +15637,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sysctl_check.c linux-2.6.29.4-vs2.3.
  
        { KERN_SPARC_REBOOT,            "reboot-cmd" },
        { KERN_CTLALTDEL,               "ctrl-alt-del" },
-@@ -1216,6 +1217,22 @@ static const struct trans_ctl_table tran
+@@ -1217,6 +1218,22 @@ static const struct trans_ctl_table tran
        {}
  };
  
@@ -16810,7 +15660,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sysctl_check.c linux-2.6.29.4-vs2.3.
  static const struct trans_ctl_table trans_root_table[] = {
        { CTL_KERN,     "kernel",       trans_kern_table },
        { CTL_VM,       "vm",           trans_vm_table },
-@@ -1232,6 +1249,7 @@ static const struct trans_ctl_table tran
+@@ -1233,6 +1250,7 @@ static const struct trans_ctl_table tran
        { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
        { CTL_PM,       "pm",           trans_pm_table },
        { CTL_FRV,      "frv",          trans_frv_table },
@@ -16818,9 +15668,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/sysctl_check.c linux-2.6.29.4-vs2.3.
        {}
  };
  
-diff -NurpP --minimal linux-2.6.29.4/kernel/time.c linux-2.6.29.4-vs2.3.0.36.14/kernel/time.c
---- linux-2.6.29.4/kernel/time.c       2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/time.c 2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/time.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/time.c
+--- linux-2.6.30.1/kernel/time.c       2009-03-24 14:22:45.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/time.c    2009-07-04 01:11:39.000000000 +0200
 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
  SYSCALL_DEFINE1(time, time_t __user *, tloc)
  {
@@ -16865,9 +15715,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/time.c linux-2.6.29.4-vs2.3.0.36.14/
        tv->tv_sec = x.tv_sec;
        tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
  }
-diff -NurpP --minimal linux-2.6.29.4/kernel/timer.c linux-2.6.29.4-vs2.3.0.36.14/kernel/timer.c
---- linux-2.6.29.4/kernel/timer.c      2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/timer.c        2009-03-24 17:41:02.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/timer.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/timer.c
+--- linux-2.6.30.1/kernel/timer.c      2009-06-11 17:13:26.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/timer.c   2009-07-04 01:11:39.000000000 +0200
 @@ -37,6 +37,10 @@
  #include <linux/delay.h>
  #include <linux/tick.h>
@@ -16879,7 +15729,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/timer.c linux-2.6.29.4-vs2.3.0.36.14
  
  #include <asm/uaccess.h>
  #include <asm/unistd.h>
-@@ -1018,6 +1022,25 @@ unsigned long get_next_timer_interrupt(u
+@@ -1103,6 +1107,25 @@ unsigned long get_next_timer_interrupt(u
  }
  #endif
  
@@ -16905,7 +15755,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/timer.c linux-2.6.29.4-vs2.3.0.36.14
  /*
   * Called from the timer interrupt handler to charge one tick to the current
   * process.  user_tick is 1 if the tick is user time, 0 for system.
-@@ -1034,6 +1057,7 @@ void update_process_times(int user_tick)
+@@ -1119,6 +1142,7 @@ void update_process_times(int user_tick)
                rcu_check_callbacks(cpu, user_tick);
        printk_tick();
        scheduler_tick();
@@ -16913,7 +15763,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/timer.c linux-2.6.29.4-vs2.3.0.36.14
        run_posix_cpu_timers(p);
  }
  
-@@ -1136,12 +1160,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
+@@ -1221,12 +1245,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
  
  #endif
  
@@ -16926,7 +15776,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/timer.c linux-2.6.29.4-vs2.3.0.36.14
  
  /**
   * sys_getpid - return the thread group id of the current process
-@@ -1170,10 +1188,23 @@ SYSCALL_DEFINE0(getppid)
+@@ -1255,10 +1273,23 @@ SYSCALL_DEFINE0(getppid)
        rcu_read_lock();
        pid = task_tgid_vnr(current->real_parent);
        rcu_read_unlock();
@@ -16951,7 +15801,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/timer.c linux-2.6.29.4-vs2.3.0.36.14
  SYSCALL_DEFINE0(getuid)
  {
        /* Only we change this so SMP safe */
-@@ -1344,6 +1375,8 @@ int do_sysinfo(struct sysinfo *info)
+@@ -1429,6 +1460,8 @@ int do_sysinfo(struct sysinfo *info)
                        tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
                        tp.tv_sec++;
                }
@@ -16960,9 +15810,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/timer.c linux-2.6.29.4-vs2.3.0.36.14
                info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
  
                info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
-diff -NurpP --minimal linux-2.6.29.4/kernel/user.c linux-2.6.29.4-vs2.3.0.36.14/kernel/user.c
---- linux-2.6.29.4/kernel/user.c       2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/user.c 2009-03-24 17:47:32.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/user.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/user.c
+--- linux-2.6.30.1/kernel/user.c       2009-06-11 17:13:27.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/user.c    2009-07-04 01:11:39.000000000 +0200
 @@ -249,10 +249,10 @@ static struct kobj_type uids_ktype = {
   *
   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
@@ -17004,9 +15854,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/user.c linux-2.6.29.4-vs2.3.0.36.14/
                        goto out_destoy_sched;
  
                /*
-diff -NurpP --minimal linux-2.6.29.4/kernel/user_namespace.c linux-2.6.29.4-vs2.3.0.36.14/kernel/user_namespace.c
---- linux-2.6.29.4/kernel/user_namespace.c     2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/user_namespace.c       2009-03-24 18:05:19.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/user_namespace.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/user_namespace.c
+--- linux-2.6.30.1/kernel/user_namespace.c     2009-03-24 14:22:45.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/user_namespace.c  2009-07-04 01:11:39.000000000 +0200
 @@ -10,6 +10,7 @@
  #include <linux/slab.h>
  #include <linux/user_namespace.h>
@@ -17032,9 +15882,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/user_namespace.c linux-2.6.29.4-vs2.
        INIT_WORK(&ns->destroyer, free_user_ns_work);
        schedule_work(&ns->destroyer);
  }
-diff -NurpP --minimal linux-2.6.29.4/kernel/utsname.c linux-2.6.29.4-vs2.3.0.36.14/kernel/utsname.c
---- linux-2.6.29.4/kernel/utsname.c    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/utsname.c      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/utsname.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/utsname.c
+--- linux-2.6.30.1/kernel/utsname.c    2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/utsname.c 2009-07-04 01:11:39.000000000 +0200
 @@ -14,6 +14,7 @@
  #include <linux/utsname.h>
  #include <linux/err.h>
@@ -17058,9 +15908,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/utsname.c linux-2.6.29.4-vs2.3.0.36.
 +      atomic_dec(&vs_global_uts_ns);
        kfree(ns);
  }
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cacct.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct.c
---- linux-2.6.29.4/kernel/vserver/cacct.c      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct.c        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/cacct.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cacct.c
+--- linux-2.6.30.1/kernel/vserver/cacct.c      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cacct.c   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,42 @@
 +/*
 + *  linux/kernel/vserver/cacct.c
@@ -17104,9 +15954,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cacct.c linux-2.6.29.4-vs2.3
 +      return 0;
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cacct_init.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct_init.h
---- linux-2.6.29.4/kernel/vserver/cacct_init.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct_init.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/cacct_init.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cacct_init.h
+--- linux-2.6.30.1/kernel/vserver/cacct_init.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cacct_init.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,25 @@
 +
 +
@@ -17133,9 +15983,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cacct_init.h linux-2.6.29.4-
 +      return;
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cacct_proc.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct_proc.h
---- linux-2.6.29.4/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct_proc.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/cacct_proc.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cacct_proc.h
+--- linux-2.6.30.1/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cacct_proc.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,53 @@
 +#ifndef _VX_CACCT_PROC_H
 +#define _VX_CACCT_PROC_H
@@ -17190,10 +16040,10 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cacct_proc.h linux-2.6.29.4-
 +}
 +
 +#endif        /* _VX_CACCT_PROC_H */
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/context.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/context.c
---- linux-2.6.29.4/kernel/vserver/context.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/context.c      2009-05-23 22:56:58.000000000 +0200
-@@ -0,0 +1,1030 @@
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/context.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/context.c
+--- linux-2.6.30.1/kernel/vserver/context.c    1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/context.c 2009-07-04 02:46:55.000000000 +0200
+@@ -0,0 +1,1031 @@
 +/*
 + *  linux/kernel/vserver/context.c
 + *
@@ -17233,6 +16083,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/context.c linux-2.6.29.4-vs2
 +#include <linux/vserver/limit_int.h>
 +#include <linux/vserver/space.h>
 +#include <linux/init_task.h>
++#include <linux/fs_struct.h>
 +
 +#include <linux/vs_context.h>
 +#include <linux/vs_limit.h>
@@ -18224,9 +17075,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/context.c linux-2.6.29.4-vs2
 +
 +EXPORT_SYMBOL_GPL(free_vx_info);
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cvirt.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt.c
---- linux-2.6.29.4/kernel/vserver/cvirt.c      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt.c        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/cvirt.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cvirt.c
+--- linux-2.6.30.1/kernel/vserver/cvirt.c      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cvirt.c   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,300 @@
 +/*
 + *  linux/kernel/vserver/cvirt.c
@@ -18528,9 +17379,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cvirt.c linux-2.6.29.4-vs2.3
 +
 +#endif
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cvirt_init.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt_init.h
---- linux-2.6.29.4/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt_init.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/cvirt_init.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cvirt_init.h
+--- linux-2.6.30.1/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cvirt_init.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,69 @@
 +
 +
@@ -18601,9 +17452,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cvirt_init.h linux-2.6.29.4-
 +      return;
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cvirt_proc.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt_proc.h
---- linux-2.6.29.4/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt_proc.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/cvirt_proc.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cvirt_proc.h
+--- linux-2.6.30.1/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/cvirt_proc.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,135 @@
 +#ifndef _VX_CVIRT_PROC_H
 +#define _VX_CVIRT_PROC_H
@@ -18740,9 +17591,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cvirt_proc.h linux-2.6.29.4-
 +}
 +
 +#endif        /* _VX_CVIRT_PROC_H */
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/debug.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/debug.c
---- linux-2.6.29.4/kernel/vserver/debug.c      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/debug.c        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/debug.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/debug.c
+--- linux-2.6.30.1/kernel/vserver/debug.c      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/debug.c   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,32 @@
 +/*
 + *  kernel/vserver/debug.c
@@ -18776,9 +17627,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/debug.c linux-2.6.29.4-vs2.3
 +
 +EXPORT_SYMBOL_GPL(dump_vx_info);
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/device.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/device.c
---- linux-2.6.29.4/kernel/vserver/device.c     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/device.c       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/device.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/device.c
+--- linux-2.6.30.1/kernel/vserver/device.c     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/device.c  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,443 @@
 +/*
 + *  linux/kernel/vserver/device.c
@@ -19223,9 +18074,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/device.c linux-2.6.29.4-vs2.
 +#endif        /* CONFIG_COMPAT */
 +
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/dlimit.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/dlimit.c
---- linux-2.6.29.4/kernel/vserver/dlimit.c     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/dlimit.c       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/dlimit.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/dlimit.c
+--- linux-2.6.30.1/kernel/vserver/dlimit.c     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/dlimit.c  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,522 @@
 +/*
 + *  linux/kernel/vserver/dlimit.c
@@ -19749,9 +18600,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/dlimit.c linux-2.6.29.4-vs2.
 +EXPORT_SYMBOL_GPL(locate_dl_info);
 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/helper.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/helper.c
---- linux-2.6.29.4/kernel/vserver/helper.c     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/helper.c       2009-03-25 00:40:43.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/helper.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/helper.c
+--- linux-2.6.30.1/kernel/vserver/helper.c     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/helper.c  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,199 @@
 +/*
 + *  linux/kernel/vserver/helper.c
@@ -19952,9 +18803,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/helper.c linux-2.6.29.4-vs2.
 +      return do_vshelper(vshelper_path, argv, envp, 1);
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/history.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/history.c
---- linux-2.6.29.4/kernel/vserver/history.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/history.c      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/history.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/history.c
+--- linux-2.6.30.1/kernel/vserver/history.c    1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/history.c 2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,258 @@
 +/*
 + *  kernel/vserver/history.c
@@ -20214,9 +19065,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/history.c linux-2.6.29.4-vs2
 +
 +#endif        /* CONFIG_COMPAT */
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/inet.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/inet.c
---- linux-2.6.29.4/kernel/vserver/inet.c       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/inet.c 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/inet.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/inet.c
+--- linux-2.6.30.1/kernel/vserver/inet.c       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/inet.c    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,225 @@
 +
 +#include <linux/in.h>
@@ -20443,9 +19294,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/inet.c linux-2.6.29.4-vs2.3.
 +
 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/init.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/init.c
---- linux-2.6.29.4/kernel/vserver/init.c       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/init.c 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/init.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/init.c
+--- linux-2.6.30.1/kernel/vserver/init.c       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/init.c    2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,45 @@
 +/*
 + *  linux/kernel/init.c
@@ -20492,9 +19343,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/init.c linux-2.6.29.4-vs2.3.
 +module_init(init_vserver);
 +module_exit(exit_vserver);
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/inode.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/inode.c
---- linux-2.6.29.4/kernel/vserver/inode.c      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/inode.c        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/inode.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/inode.c
+--- linux-2.6.30.1/kernel/vserver/inode.c      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/inode.c   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,422 @@
 +/*
 + *  linux/kernel/vserver/inode.c
@@ -20918,9 +19769,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/inode.c linux-2.6.29.4-vs2.3
 +
 +#endif        /* CONFIG_PROPAGATE */
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/Kconfig linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/Kconfig
---- linux-2.6.29.4/kernel/vserver/Kconfig      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/Kconfig        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/Kconfig
+--- linux-2.6.30.1/kernel/vserver/Kconfig      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/Kconfig   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,251 @@
 +#
 +# Linux VServer configuration
@@ -21173,9 +20024,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/Kconfig linux-2.6.29.4-vs2.3
 +      default y
 +      select SECURITY_CAPABILITIES
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/limit.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit.c
---- linux-2.6.29.4/kernel/vserver/limit.c      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit.c        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/limit.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/limit.c
+--- linux-2.6.30.1/kernel/vserver/limit.c      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/limit.c   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,319 @@
 +/*
 + *  linux/kernel/vserver/limit.c
@@ -21496,9 +20347,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/limit.c linux-2.6.29.4-vs2.3
 +      return points;
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/limit_init.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit_init.h
---- linux-2.6.29.4/kernel/vserver/limit_init.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit_init.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/limit_init.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/limit_init.h
+--- linux-2.6.30.1/kernel/vserver/limit_init.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/limit_init.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,31 @@
 +
 +
@@ -21531,9 +20382,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/limit_init.h linux-2.6.29.4-
 +      }
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/limit_proc.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit_proc.h
---- linux-2.6.29.4/kernel/vserver/limit_proc.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit_proc.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/limit_proc.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/limit_proc.h
+--- linux-2.6.30.1/kernel/vserver/limit_proc.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/limit_proc.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,57 @@
 +#ifndef _VX_LIMIT_PROC_H
 +#define _VX_LIMIT_PROC_H
@@ -21592,9 +20443,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/limit_proc.h linux-2.6.29.4-
 +#endif        /* _VX_LIMIT_PROC_H */
 +
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/Makefile linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/Makefile
---- linux-2.6.29.4/kernel/vserver/Makefile     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/Makefile       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/Makefile linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/Makefile
+--- linux-2.6.30.1/kernel/vserver/Makefile     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/Makefile  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,18 @@
 +#
 +# Makefile for the Linux vserver routines.
@@ -21614,9 +20465,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/Makefile linux-2.6.29.4-vs2.
 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/monitor.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/monitor.c
---- linux-2.6.29.4/kernel/vserver/monitor.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/monitor.c      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/monitor.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/monitor.c
+--- linux-2.6.30.1/kernel/vserver/monitor.c    1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/monitor.c 2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,138 @@
 +/*
 + *  kernel/vserver/monitor.c
@@ -21756,9 +20607,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/monitor.c linux-2.6.29.4-vs2
 +
 +#endif        /* CONFIG_COMPAT */
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/network.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/network.c
---- linux-2.6.29.4/kernel/vserver/network.c    1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/network.c      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/network.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/network.c
+--- linux-2.6.30.1/kernel/vserver/network.c    1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/network.c 2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,864 @@
 +/*
 + *  linux/kernel/vserver/network.c
@@ -22624,10 +21475,10 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/network.c linux-2.6.29.4-vs2
 +EXPORT_SYMBOL_GPL(free_nx_info);
 +EXPORT_SYMBOL_GPL(unhash_nx_info);
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/proc.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/proc.c
---- linux-2.6.29.4/kernel/vserver/proc.c       1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/proc.c 2009-05-23 22:57:16.000000000 +0200
-@@ -0,0 +1,1096 @@
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/proc.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/proc.c
+--- linux-2.6.30.1/kernel/vserver/proc.c       1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/proc.c    2009-07-04 04:52:43.000000000 +0200
+@@ -0,0 +1,1097 @@
 +/*
 + *  linux/kernel/vserver/proc.c
 + *
@@ -22647,6 +21498,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/proc.c linux-2.6.29.4-vs2.3.
 + */
 +
 +#include <linux/proc_fs.h>
++#include <linux/fs_struct.h>
 +#include <asm/unistd.h>
 +
 +#include <linux/vs_context.h>
@@ -22717,7 +21569,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/proc.c linux-2.6.29.4-vs2.3.
 +              atomic_read(&vs_global_fs),
 +              atomic_read(&vs_global_mnt_ns),
 +              atomic_read(&vs_global_uts_ns),
-+              atomic_read(&vs_global_ipc_ns),
++              atomic_read(&nr_ipc_ns),
 +              atomic_read(&vs_global_user_ns),
 +              atomic_read(&vs_global_pid_ns),
 +              atomic_read(&init_task.usage),
@@ -23724,9 +22576,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/proc.c linux-2.6.29.4-vs2.3.
 +      return buffer - orig;
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sched.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched.c
---- linux-2.6.29.4/kernel/vserver/sched.c      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched.c        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/sched.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/sched.c
+--- linux-2.6.30.1/kernel/vserver/sched.c      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/sched.c   2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,414 @@
 +/*
 + *  linux/kernel/vserver/sched.c
@@ -24142,9 +22994,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sched.c linux-2.6.29.4-vs2.3
 +      return 0;
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sched_init.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched_init.h
---- linux-2.6.29.4/kernel/vserver/sched_init.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched_init.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/sched_init.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/sched_init.h
+--- linux-2.6.30.1/kernel/vserver/sched_init.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/sched_init.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,50 @@
 +
 +static inline void vx_info_init_sched(struct _vx_sched *sched)
@@ -24196,9 +23048,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sched_init.h linux-2.6.29.4-
 +{
 +      return;
 +}
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sched_proc.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched_proc.h
---- linux-2.6.29.4/kernel/vserver/sched_proc.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched_proc.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/sched_proc.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/sched_proc.h
+--- linux-2.6.30.1/kernel/vserver/sched_proc.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/sched_proc.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,57 @@
 +#ifndef _VX_SCHED_PROC_H
 +#define _VX_SCHED_PROC_H
@@ -24257,9 +23109,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sched_proc.h linux-2.6.29.4-
 +}
 +
 +#endif        /* _VX_SCHED_PROC_H */
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/signal.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/signal.c
---- linux-2.6.29.4/kernel/vserver/signal.c     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/signal.c       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/signal.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/signal.c
+--- linux-2.6.30.1/kernel/vserver/signal.c     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/signal.c  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,132 @@
 +/*
 + *  linux/kernel/vserver/signal.c
@@ -24393,9 +23245,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/signal.c linux-2.6.29.4-vs2.
 +      return ret;
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/space.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/space.c
---- linux-2.6.29.4/kernel/vserver/space.c      1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/space.c        2009-05-29 18:59:49.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/space.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/space.c
+--- linux-2.6.30.1/kernel/vserver/space.c      1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/space.c   2009-07-04 04:52:00.000000000 +0200
 @@ -0,0 +1,375 @@
 +/*
 + *  linux/kernel/vserver/space.c
@@ -24414,6 +23266,7 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/space.c linux-2.6.29.4-vs2.3
 +#include <linux/utsname.h>
 +#include <linux/nsproxy.h>
 +#include <linux/err.h>
++#include <linux/fs_struct.h>
 +#include <asm/uaccess.h>
 +
 +#include <linux/vs_context.h>
@@ -24424,7 +23277,6 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/space.c linux-2.6.29.4-vs2.3
 +atomic_t vs_global_fs         = ATOMIC_INIT(0);
 +atomic_t vs_global_mnt_ns     = ATOMIC_INIT(0);
 +atomic_t vs_global_uts_ns     = ATOMIC_INIT(0);
-+atomic_t vs_global_ipc_ns     = ATOMIC_INIT(0);
 +atomic_t vs_global_user_ns    = ATOMIC_INIT(0);
 +atomic_t vs_global_pid_ns     = ATOMIC_INIT(0);
 +
@@ -24772,9 +23624,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/space.c linux-2.6.29.4-vs2.3
 +      return 0;
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/switch.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/switch.c
---- linux-2.6.29.4/kernel/vserver/switch.c     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/switch.c       2009-03-24 14:59:18.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/switch.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/switch.c
+--- linux-2.6.30.1/kernel/vserver/switch.c     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/switch.c  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,543 @@
 +/*
 + *  linux/kernel/vserver/switch.c
@@ -25319,9 +24171,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/switch.c linux-2.6.29.4-vs2.
 +}
 +
 +#endif        /* CONFIG_COMPAT */
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sysctl.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sysctl.c
---- linux-2.6.29.4/kernel/vserver/sysctl.c     1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sysctl.c       2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/sysctl.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/sysctl.c
+--- linux-2.6.30.1/kernel/vserver/sysctl.c     1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/sysctl.c  2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,244 @@
 +/*
 + *  kernel/vserver/sysctl.c
@@ -25567,9 +24419,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sysctl.c linux-2.6.29.4-vs2.
 +EXPORT_SYMBOL_GPL(vx_debug_space);
 +EXPORT_SYMBOL_GPL(vx_debug_misc);
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/tag.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/tag.c
---- linux-2.6.29.4/kernel/vserver/tag.c        1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/tag.c  2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/tag.c linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/tag.c
+--- linux-2.6.30.1/kernel/vserver/tag.c        1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/tag.c     2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,63 @@
 +/*
 + *  linux/kernel/vserver/tag.c
@@ -25634,9 +24486,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/tag.c linux-2.6.29.4-vs2.3.0
 +}
 +
 +
-diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/vci_config.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/vci_config.h
---- linux-2.6.29.4/kernel/vserver/vci_config.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/vci_config.h   2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/kernel/vserver/vci_config.h linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/vci_config.h
+--- linux-2.6.30.1/kernel/vserver/vci_config.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/kernel/vserver/vci_config.h      2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,81 @@
 +
 +/*  interface version */
@@ -25719,9 +24571,9 @@ diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/vci_config.h linux-2.6.29.4-
 +      0;
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/mm/filemap_xip.c linux-2.6.29.4-vs2.3.0.36.14/mm/filemap_xip.c
---- linux-2.6.29.4/mm/filemap_xip.c    2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/filemap_xip.c      2009-04-30 12:14:53.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/mm/filemap_xip.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/filemap_xip.c
+--- linux-2.6.30.1/mm/filemap_xip.c    2009-06-11 17:13:27.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/filemap_xip.c 2009-07-04 01:11:39.000000000 +0200
 @@ -17,6 +17,7 @@
  #include <linux/sched.h>
  #include <linux/seqlock.h>
@@ -25730,9 +24582,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/filemap_xip.c linux-2.6.29.4-vs2.3.0.36.
  #include <asm/tlbflush.h>
  #include <asm/io.h>
  
-diff -NurpP --minimal linux-2.6.29.4/mm/fremap.c linux-2.6.29.4-vs2.3.0.36.14/mm/fremap.c
---- linux-2.6.29.4/mm/fremap.c 2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/fremap.c   2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/mm/fremap.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/fremap.c
+--- linux-2.6.30.1/mm/fremap.c 2009-03-24 14:22:45.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/fremap.c      2009-07-04 01:11:39.000000000 +0200
 @@ -16,6 +16,7 @@
  #include <linux/module.h>
  #include <linux/syscalls.h>
@@ -25741,9 +24593,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/fremap.c linux-2.6.29.4-vs2.3.0.36.14/mm
  
  #include <asm/mmu_context.h>
  #include <asm/cacheflush.h>
-diff -NurpP --minimal linux-2.6.29.4/mm/hugetlb.c linux-2.6.29.4-vs2.3.0.36.14/mm/hugetlb.c
---- linux-2.6.29.4/mm/hugetlb.c        2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/hugetlb.c  2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/mm/hugetlb.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/hugetlb.c
+--- linux-2.6.30.1/mm/hugetlb.c        2009-06-11 17:13:27.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/hugetlb.c     2009-07-04 01:11:39.000000000 +0200
 @@ -24,6 +24,7 @@
  #include <asm/io.h>
  
@@ -25752,9 +24604,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/hugetlb.c linux-2.6.29.4-vs2.3.0.36.14/m
  #include "internal.h"
  
  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
-diff -NurpP --minimal linux-2.6.29.4/mm/memory.c linux-2.6.29.4-vs2.3.0.36.14/mm/memory.c
---- linux-2.6.29.4/mm/memory.c 2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/memory.c   2009-05-23 23:19:11.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/mm/memory.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/memory.c
+--- linux-2.6.30.1/mm/memory.c 2009-06-11 17:13:27.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/memory.c      2009-07-04 01:11:39.000000000 +0200
 @@ -55,6 +55,7 @@
  #include <linux/kallsyms.h>
  #include <linux/swapops.h>
@@ -25773,19 +24625,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/memory.c linux-2.6.29.4-vs2.3.0.36.14/mm
  again:
        rss[1] = rss[0] = 0;
        dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
-@@ -2481,6 +2485,11 @@ static int do_swap_page(struct mm_struct
-               count_vm_event(PGMAJFAULT);
-       }
-+      if (!vx_rss_avail(mm, 1)) {
-+              ret = VM_FAULT_OOM;
-+              goto out;
-+      }
-+
-       mark_page_accessed(page);
-       lock_page(page);
-@@ -2572,6 +2581,8 @@ static int do_anonymous_page(struct mm_s
+@@ -2575,6 +2579,8 @@ static int do_anonymous_page(struct mm_s
        /* Allocate our own private page. */
        pte_unmap(page_table);
  
@@ -25794,7 +24634,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/memory.c linux-2.6.29.4-vs2.3.0.36.14/mm
        if (unlikely(anon_vma_prepare(vma)))
                goto oom;
        page = alloc_zeroed_user_highpage_movable(vma, address);
-@@ -2855,6 +2866,7 @@ static inline int handle_pte_fault(struc
+@@ -2858,6 +2864,7 @@ static inline int handle_pte_fault(struc
  {
        pte_t entry;
        spinlock_t *ptl;
@@ -25802,7 +24642,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/memory.c linux-2.6.29.4-vs2.3.0.36.14/mm
  
        entry = *pte;
        if (!pte_present(entry)) {
-@@ -2879,9 +2891,12 @@ static inline int handle_pte_fault(struc
+@@ -2882,9 +2889,12 @@ static inline int handle_pte_fault(struc
        if (unlikely(!pte_same(*pte, entry)))
                goto unlock;
        if (write_access) {
@@ -25817,7 +24657,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/memory.c linux-2.6.29.4-vs2.3.0.36.14/mm
                entry = pte_mkdirty(entry);
        }
        entry = pte_mkyoung(entry);
-@@ -2899,7 +2914,10 @@ static inline int handle_pte_fault(struc
+@@ -2902,7 +2912,10 @@ static inline int handle_pte_fault(struc
        }
  unlock:
        pte_unmap_unlock(pte, ptl);
@@ -25829,9 +24669,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/memory.c linux-2.6.29.4-vs2.3.0.36.14/mm
  }
  
  /*
-diff -NurpP --minimal linux-2.6.29.4/mm/mlock.c linux-2.6.29.4-vs2.3.0.36.14/mm/mlock.c
---- linux-2.6.29.4/mm/mlock.c  2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/mlock.c    2009-03-28 05:08:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/mm/mlock.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/mlock.c
+--- linux-2.6.30.1/mm/mlock.c  2009-03-24 14:22:45.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/mlock.c       2009-07-04 01:11:39.000000000 +0200
 @@ -18,6 +18,7 @@
  #include <linux/rmap.h>
  #include <linux/mmzone.h>
@@ -25914,10 +24754,10 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mlock.c linux-2.6.29.4-vs2.3.0.36.14/mm/
  
        up_write(&current->mm->mmap_sem);
  }
-diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/mmap.c
---- linux-2.6.29.4/mm/mmap.c   2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/mmap.c     2009-05-10 23:42:01.000000000 +0200
-@@ -1215,7 +1215,8 @@ munmap_back:
+diff -NurpP --minimal linux-2.6.30.1/mm/mmap.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/mmap.c
+--- linux-2.6.30.1/mm/mmap.c   2009-06-11 17:13:27.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/mmap.c        2009-07-04 01:11:39.000000000 +0200
+@@ -1219,7 +1219,8 @@ munmap_back:
        if (correct_wcount)
                atomic_inc(&inode->i_writecount);
  out:
@@ -25927,7 +24767,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
        vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
        if (vm_flags & VM_LOCKED) {
                /*
-@@ -1224,7 +1225,8 @@ out:
+@@ -1228,7 +1229,8 @@ out:
                long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
                if (nr_pages < 0)
                        return nr_pages;        /* vma gone! */
@@ -25937,7 +24777,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
        } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
                make_pages_present(addr, addr + len);
        return addr;
-@@ -1571,9 +1573,9 @@ static int acct_stack_growth(struct vm_a
+@@ -1575,9 +1577,9 @@ static int acct_stack_growth(struct vm_a
                return -ENOMEM;
  
        /* Ok, everything looks good - let it rip */
@@ -25949,7 +24789,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
        vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
        return 0;
  }
-@@ -1748,7 +1750,8 @@ static void remove_vma_list(struct mm_st
+@@ -1752,7 +1754,8 @@ static void remove_vma_list(struct mm_st
        do {
                long nrpages = vma_pages(vma);
  
@@ -25959,7 +24799,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
                vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
                vma = remove_vma(vma);
        } while (vma);
-@@ -1920,7 +1923,8 @@ int do_munmap(struct mm_struct *mm, unsi
+@@ -1924,7 +1927,8 @@ int do_munmap(struct mm_struct *mm, unsi
                struct vm_area_struct *tmp = vma;
                while (tmp && tmp->vm_start < end) {
                        if (tmp->vm_flags & VM_LOCKED) {
@@ -25969,7 +24809,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
                                munlock_vma_pages_all(tmp);
                        }
                        tmp = tmp->vm_next;
-@@ -2009,6 +2013,8 @@ unsigned long do_brk(unsigned long addr,
+@@ -2013,6 +2017,8 @@ unsigned long do_brk(unsigned long addr,
                lock_limit >>= PAGE_SHIFT;
                if (locked > lock_limit && !capable(CAP_IPC_LOCK))
                        return -EAGAIN;
@@ -25978,7 +24818,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
        }
  
        /*
-@@ -2035,7 +2041,8 @@ unsigned long do_brk(unsigned long addr,
+@@ -2039,7 +2045,8 @@ unsigned long do_brk(unsigned long addr,
        if (mm->map_count > sysctl_max_map_count)
                return -ENOMEM;
  
@@ -25988,7 +24828,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
                return -ENOMEM;
  
        /* Can we just expand an old private anonymous mapping? */
-@@ -2061,10 +2068,13 @@ unsigned long do_brk(unsigned long addr,
+@@ -2065,10 +2072,13 @@ unsigned long do_brk(unsigned long addr,
        vma->vm_page_prot = vm_get_page_prot(flags);
        vma_link(mm, vma, prev, rb_link, rb_parent);
  out:
@@ -26004,7 +24844,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
        }
        return addr;
  }
-@@ -2107,6 +2117,11 @@ void exit_mmap(struct mm_struct *mm)
+@@ -2111,6 +2121,11 @@ void exit_mmap(struct mm_struct *mm)
        free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
        tlb_finish_mmu(tlb, 0, end);
  
@@ -26016,7 +24856,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
        /*
         * Walk the list again, actually closing and freeing it,
         * with preemption enabled, without holding any MM locks.
-@@ -2146,7 +2161,8 @@ int insert_vm_struct(struct mm_struct * 
+@@ -2150,7 +2165,8 @@ int insert_vm_struct(struct mm_struct * 
        if (__vma && __vma->vm_start < vma->vm_end)
                return -ENOMEM;
        if ((vma->vm_flags & VM_ACCOUNT) &&
@@ -26026,7 +24866,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
                return -ENOMEM;
        vma_link(mm, vma, prev, rb_link, rb_parent);
        return 0;
-@@ -2222,6 +2238,8 @@ int may_expand_vm(struct mm_struct *mm, 
+@@ -2226,6 +2242,8 @@ int may_expand_vm(struct mm_struct *mm, 
  
        if (cur + npages > lim)
                return 0;
@@ -26035,7 +24875,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
        return 1;
  }
  
-@@ -2299,8 +2317,7 @@ int install_special_mapping(struct mm_st
+@@ -2303,8 +2321,7 @@ int install_special_mapping(struct mm_st
                return -ENOMEM;
        }
  
@@ -26045,9 +24885,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/m
        return 0;
  }
  
-diff -NurpP --minimal linux-2.6.29.4/mm/mremap.c linux-2.6.29.4-vs2.3.0.36.14/mm/mremap.c
---- linux-2.6.29.4/mm/mremap.c 2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/mremap.c   2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/mm/mremap.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/mremap.c
+--- linux-2.6.30.1/mm/mremap.c 2009-03-24 14:22:45.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/mremap.c      2009-07-04 01:11:39.000000000 +0200
 @@ -19,6 +19,7 @@
  #include <linux/security.h>
  #include <linux/syscalls.h>
@@ -26099,10 +24939,10 @@ diff -NurpP --minimal linux-2.6.29.4/mm/mremap.c linux-2.6.29.4-vs2.3.0.36.14/mm
                                mlock_vma_pages_range(vma, addr + old_len,
                                                   addr + new_len);
                        }
-diff -NurpP --minimal linux-2.6.29.4/mm/nommu.c linux-2.6.29.4-vs2.3.0.36.14/mm/nommu.c
---- linux-2.6.29.4/mm/nommu.c  2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/nommu.c    2009-05-10 23:42:01.000000000 +0200
-@@ -1352,7 +1352,7 @@ unsigned long do_mmap_pgoff(struct file 
+diff -NurpP --minimal linux-2.6.30.1/mm/nommu.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/nommu.c
+--- linux-2.6.30.1/mm/nommu.c  2009-06-11 17:13:27.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/nommu.c       2009-07-04 01:11:39.000000000 +0200
+@@ -1343,7 +1343,7 @@ unsigned long do_mmap_pgoff(struct file 
        /* okay... we have a mapping; now we have to register it */
        result = vma->vm_start;
  
@@ -26111,7 +24951,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/nommu.c linux-2.6.29.4-vs2.3.0.36.14/mm/
  
  share:
        add_vma_to_mm(current->mm, vma);
-@@ -1618,7 +1618,7 @@ void exit_mmap(struct mm_struct *mm)
+@@ -1614,7 +1614,7 @@ void exit_mmap(struct mm_struct *mm)
  
        kenter("");
  
@@ -26120,9 +24960,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/nommu.c linux-2.6.29.4-vs2.3.0.36.14/mm/
  
        while ((vma = mm->mmap)) {
                mm->mmap = vma->vm_next;
-diff -NurpP --minimal linux-2.6.29.4/mm/oom_kill.c linux-2.6.29.4-vs2.3.0.36.14/mm/oom_kill.c
---- linux-2.6.29.4/mm/oom_kill.c       2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/oom_kill.c 2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/mm/oom_kill.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/oom_kill.c
+--- linux-2.6.30.1/mm/oom_kill.c       2009-06-11 17:13:27.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/oom_kill.c    2009-07-04 01:11:39.000000000 +0200
 @@ -27,6 +27,7 @@
  #include <linux/notifier.h>
  #include <linux/memcontrol.h>
@@ -26144,7 +24984,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/oom_kill.c linux-2.6.29.4-vs2.3.0.36.14/
         * After this unlock we can no longer dereference local variable `mm'
         */
        task_unlock(p);
-@@ -162,8 +169,8 @@ unsigned long badness(struct task_struct
+@@ -160,8 +167,8 @@ unsigned long badness(struct task_struct
        }
  
  #ifdef DEBUG
@@ -26155,7 +24995,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/oom_kill.c linux-2.6.29.4-vs2.3.0.36.14/
  #endif
        return points;
  }
-@@ -326,8 +333,8 @@ static void __oom_kill_task(struct task_
+@@ -330,8 +337,8 @@ static void __oom_kill_task(struct task_
        }
  
        if (verbose)
@@ -26166,7 +25006,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/oom_kill.c linux-2.6.29.4-vs2.3.0.36.14/
  
        /*
         * We give our sacrificial lamb high priority and access to
-@@ -410,8 +417,8 @@ static int oom_kill_process(struct task_
+@@ -415,8 +422,8 @@ static int oom_kill_process(struct task_
                return 0;
        }
  
@@ -26177,9 +25017,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/oom_kill.c linux-2.6.29.4-vs2.3.0.36.14/
  
        /* Try to kill a child first */
        list_for_each_entry(c, &p->children, sibling) {
-diff -NurpP --minimal linux-2.6.29.4/mm/page_alloc.c linux-2.6.29.4-vs2.3.0.36.14/mm/page_alloc.c
---- linux-2.6.29.4/mm/page_alloc.c     2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/page_alloc.c       2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/mm/page_alloc.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/page_alloc.c
+--- linux-2.6.30.1/mm/page_alloc.c     2009-07-03 20:12:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/page_alloc.c  2009-07-04 01:11:39.000000000 +0200
 @@ -46,6 +46,8 @@
  #include <linux/page-isolation.h>
  #include <linux/page_cgroup.h>
@@ -26189,7 +25029,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/page_alloc.c linux-2.6.29.4-vs2.3.0.36.1
  
  #include <asm/tlbflush.h>
  #include <asm/div64.h>
-@@ -1839,6 +1841,9 @@ void si_meminfo(struct sysinfo *val)
+@@ -1842,6 +1844,9 @@ void si_meminfo(struct sysinfo *val)
        val->totalhigh = totalhigh_pages;
        val->freehigh = nr_free_highpages();
        val->mem_unit = PAGE_SIZE;
@@ -26199,7 +25039,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/page_alloc.c linux-2.6.29.4-vs2.3.0.36.1
  }
  
  EXPORT_SYMBOL(si_meminfo);
-@@ -1859,6 +1864,9 @@ void si_meminfo_node(struct sysinfo *val
+@@ -1862,6 +1867,9 @@ void si_meminfo_node(struct sysinfo *val
        val->freehigh = 0;
  #endif
        val->mem_unit = PAGE_SIZE;
@@ -26209,9 +25049,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/page_alloc.c linux-2.6.29.4-vs2.3.0.36.1
  }
  #endif
  
-diff -NurpP --minimal linux-2.6.29.4/mm/rmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/rmap.c
---- linux-2.6.29.4/mm/rmap.c   2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/rmap.c     2009-03-24 18:26:27.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/mm/rmap.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/rmap.c
+--- linux-2.6.30.1/mm/rmap.c   2009-06-11 17:13:27.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/rmap.c        2009-07-04 01:11:39.000000000 +0200
 @@ -50,6 +50,7 @@
  #include <linux/memcontrol.h>
  #include <linux/mmu_notifier.h>
@@ -26220,10 +25060,10 @@ diff -NurpP --minimal linux-2.6.29.4/mm/rmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/r
  
  #include <asm/tlbflush.h>
  
-diff -NurpP --minimal linux-2.6.29.4/mm/shmem.c linux-2.6.29.4-vs2.3.0.36.14/mm/shmem.c
---- linux-2.6.29.4/mm/shmem.c  2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/shmem.c    2009-03-24 14:48:36.000000000 +0100
-@@ -1757,7 +1757,7 @@ static int shmem_statfs(struct dentry *d
+diff -NurpP --minimal linux-2.6.30.1/mm/shmem.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/shmem.c
+--- linux-2.6.30.1/mm/shmem.c  2009-06-11 17:13:27.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/shmem.c       2009-07-04 01:11:39.000000000 +0200
+@@ -1776,7 +1776,7 @@ static int shmem_statfs(struct dentry *d
  {
        struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
  
@@ -26232,7 +25072,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/shmem.c linux-2.6.29.4-vs2.3.0.36.14/mm/
        buf->f_bsize = PAGE_CACHE_SIZE;
        buf->f_namelen = NAME_MAX;
        spin_lock(&sbinfo->stat_lock);
-@@ -2326,7 +2326,7 @@ static int shmem_fill_super(struct super
+@@ -2345,7 +2345,7 @@ static int shmem_fill_super(struct super
        sb->s_maxbytes = SHMEM_MAX_BYTES;
        sb->s_blocksize = PAGE_CACHE_SIZE;
        sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
@@ -26241,10 +25081,10 @@ diff -NurpP --minimal linux-2.6.29.4/mm/shmem.c linux-2.6.29.4-vs2.3.0.36.14/mm/
        sb->s_op = &shmem_ops;
        sb->s_time_gran = 1;
  #ifdef CONFIG_TMPFS_POSIX_ACL
-diff -NurpP --minimal linux-2.6.29.4/mm/slab.c linux-2.6.29.4-vs2.3.0.36.14/mm/slab.c
---- linux-2.6.29.4/mm/slab.c   2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/slab.c     2009-03-24 14:48:36.000000000 +0100
-@@ -509,6 +509,8 @@ struct kmem_cache {
+diff -NurpP --minimal linux-2.6.30.1/mm/slab.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/slab.c
+--- linux-2.6.30.1/mm/slab.c   2009-06-11 17:13:27.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/slab.c        2009-07-04 01:11:39.000000000 +0200
+@@ -510,6 +510,8 @@ struct kmem_cache {
  #define STATS_INC_FREEMISS(x) do { } while (0)
  #endif
  
@@ -26253,7 +25093,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/slab.c linux-2.6.29.4-vs2.3.0.36.14/mm/s
  #if DEBUG
  
  /*
-@@ -3275,6 +3277,7 @@ retry:
+@@ -3284,6 +3286,7 @@ retry:
  
        obj = slab_get_obj(cachep, slabp, nodeid);
        check_slabp(cachep, slabp);
@@ -26261,7 +25101,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/slab.c linux-2.6.29.4-vs2.3.0.36.14/mm/s
        l3->free_objects--;
        /* move slabp to correct slabp list: */
        list_del(&slabp->list);
-@@ -3347,6 +3350,7 @@ __cache_alloc_node(struct kmem_cache *ca
+@@ -3358,6 +3361,7 @@ __cache_alloc_node(struct kmem_cache *ca
        /* ___cache_alloc_node can fall back to other nodes */
        ptr = ____cache_alloc_node(cachep, flags, nodeid);
    out:
@@ -26269,7 +25109,7 @@ diff -NurpP --minimal linux-2.6.29.4/mm/slab.c linux-2.6.29.4-vs2.3.0.36.14/mm/s
        local_irq_restore(save_flags);
        ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
  
-@@ -3518,6 +3522,7 @@ static inline void __cache_free(struct k
+@@ -3531,6 +3535,7 @@ static inline void __cache_free(struct k
  
        check_irq_off();
        objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
@@ -26277,9 +25117,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/slab.c linux-2.6.29.4-vs2.3.0.36.14/mm/s
  
        /*
         * Skip calling cache_free_alien() when the platform is not numa.
-diff -NurpP --minimal linux-2.6.29.4/mm/slab_vs.h linux-2.6.29.4-vs2.3.0.36.14/mm/slab_vs.h
---- linux-2.6.29.4/mm/slab_vs.h        1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/slab_vs.h  2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/mm/slab_vs.h linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/slab_vs.h
+--- linux-2.6.30.1/mm/slab_vs.h        1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/slab_vs.h     2009-07-04 01:11:39.000000000 +0200
 @@ -0,0 +1,27 @@
 +
 +#include <linux/vserver/context.h>
@@ -26308,9 +25148,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/slab_vs.h linux-2.6.29.4-vs2.3.0.36.14/m
 +      atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
 +}
 +
-diff -NurpP --minimal linux-2.6.29.4/mm/swapfile.c linux-2.6.29.4-vs2.3.0.36.14/mm/swapfile.c
---- linux-2.6.29.4/mm/swapfile.c       2009-03-24 14:22:45.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/mm/swapfile.c 2009-03-24 18:27:15.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/mm/swapfile.c linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/swapfile.c
+--- linux-2.6.30.1/mm/swapfile.c       2009-03-24 14:22:45.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/mm/swapfile.c    2009-07-04 01:11:39.000000000 +0200
 @@ -34,6 +34,8 @@
  #include <asm/tlbflush.h>
  #include <linux/swapops.h>
@@ -26329,9 +25169,9 @@ diff -NurpP --minimal linux-2.6.29.4/mm/swapfile.c linux-2.6.29.4-vs2.3.0.36.14/
  }
  
  /*
-diff -NurpP --minimal linux-2.6.29.4/net/core/dev.c linux-2.6.29.4-vs2.3.0.36.14/net/core/dev.c
---- linux-2.6.29.4/net/core/dev.c      2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/core/dev.c        2009-04-15 22:58:30.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/net/core/dev.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/core/dev.c
+--- linux-2.6.30.1/net/core/dev.c      2009-06-11 17:13:28.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/core/dev.c   2009-07-04 01:11:39.000000000 +0200
 @@ -126,6 +126,7 @@
  #include <linux/in.h>
  #include <linux/jhash.h>
@@ -26340,7 +25180,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/dev.c linux-2.6.29.4-vs2.3.0.36.14
  
  #include "net-sysfs.h"
  
-@@ -2853,6 +2854,8 @@ static int dev_ifconf(struct net *net, c
+@@ -2904,6 +2905,8 @@ static int dev_ifconf(struct net *net, c
  
        total = 0;
        for_each_netdev(net, dev) {
@@ -26349,7 +25189,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/dev.c linux-2.6.29.4-vs2.3.0.36.14
                for (i = 0; i < NPROTO; i++) {
                        if (gifconf_list[i]) {
                                int done;
-@@ -2921,6 +2924,9 @@ static void dev_seq_printf_stats(struct 
+@@ -2972,6 +2975,9 @@ static void dev_seq_printf_stats(struct 
  {
        const struct net_device_stats *stats = dev_get_stats(dev);
  
@@ -26359,7 +25199,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/dev.c linux-2.6.29.4-vs2.3.0.36.14
        seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
                   "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
                   dev->name, stats->rx_bytes, stats->rx_packets,
-@@ -4862,6 +4868,15 @@ int dev_change_net_namespace(struct net_
+@@ -4915,6 +4921,15 @@ int dev_change_net_namespace(struct net_
                goto out;
  #endif
  
@@ -26375,7 +25215,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/dev.c linux-2.6.29.4-vs2.3.0.36.14
        /* Ensure the device has been registrered */
        err = -EINVAL;
        if (dev->reg_state != NETREG_REGISTERED)
-@@ -4921,6 +4936,8 @@ int dev_change_net_namespace(struct net_
+@@ -4974,6 +4989,8 @@ int dev_change_net_namespace(struct net_
  
        netdev_unregister_kobject(dev);
  
@@ -26384,9 +25224,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/dev.c linux-2.6.29.4-vs2.3.0.36.14
        /* Actually switch the network namespace */
        dev_net_set(dev, net);
  
-diff -NurpP --minimal linux-2.6.29.4/net/core/net-sysfs.c linux-2.6.29.4-vs2.3.0.36.14/net/core/net-sysfs.c
---- linux-2.6.29.4/net/core/net-sysfs.c        2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/core/net-sysfs.c  2009-03-24 18:30:01.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/core/net-sysfs.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/core/net-sysfs.c
+--- linux-2.6.30.1/net/core/net-sysfs.c        2009-06-11 17:13:29.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/core/net-sysfs.c     2009-07-04 01:11:39.000000000 +0200
 @@ -512,6 +512,9 @@ int netdev_register_kobject(struct net_d
        if (dev_net(net) != &init_net)
                return 0;
@@ -26397,9 +25237,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/net-sysfs.c linux-2.6.29.4-vs2.3.0
        return device_add(dev);
  }
  
-diff -NurpP --minimal linux-2.6.29.4/net/core/rtnetlink.c linux-2.6.29.4-vs2.3.0.36.14/net/core/rtnetlink.c
---- linux-2.6.29.4/net/core/rtnetlink.c        2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/core/rtnetlink.c  2009-03-24 14:48:36.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/core/rtnetlink.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/core/rtnetlink.c
+--- linux-2.6.30.1/net/core/rtnetlink.c        2009-06-11 17:13:29.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/core/rtnetlink.c     2009-07-04 01:11:39.000000000 +0200
 @@ -690,6 +690,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
  
        idx = 0;
@@ -26419,10 +25259,10 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/rtnetlink.c linux-2.6.29.4-vs2.3.0
        skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
        if (skb == NULL)
                goto errout;
-diff -NurpP --minimal linux-2.6.29.4/net/core/sock.c linux-2.6.29.4-vs2.3.0.36.14/net/core/sock.c
---- linux-2.6.29.4/net/core/sock.c     2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/core/sock.c       2009-03-24 14:48:36.000000000 +0100
-@@ -124,6 +124,10 @@
+diff -NurpP --minimal linux-2.6.30.1/net/core/sock.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/core/sock.c
+--- linux-2.6.30.1/net/core/sock.c     2009-06-11 17:13:29.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/core/sock.c  2009-07-04 01:11:39.000000000 +0200
+@@ -125,6 +125,10 @@
  #include <linux/ipsec.h>
  
  #include <linux/filter.h>
@@ -26433,7 +25273,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/sock.c linux-2.6.29.4-vs2.3.0.36.1
  
  #ifdef CONFIG_INET
  #include <net/tcp.h>
-@@ -900,6 +904,8 @@ static struct sock *sk_prot_alloc(struct
+@@ -947,6 +951,8 @@ static struct sock *sk_prot_alloc(struct
                if (!try_module_get(prot->owner))
                        goto out_free_sec;
        }
@@ -26442,7 +25282,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/sock.c linux-2.6.29.4-vs2.3.0.36.1
  
        return sk;
  
-@@ -976,6 +982,11 @@ void sk_free(struct sock *sk)
+@@ -1024,6 +1030,11 @@ void sk_free(struct sock *sk)
                       __func__, atomic_read(&sk->sk_omem_alloc));
  
        put_net(sock_net(sk));
@@ -26454,7 +25294,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/sock.c linux-2.6.29.4-vs2.3.0.36.1
        sk_prot_free(sk->sk_prot_creator, sk);
  }
  
-@@ -1011,6 +1022,8 @@ struct sock *sk_clone(const struct sock 
+@@ -1059,6 +1070,8 @@ struct sock *sk_clone(const struct sock 
  
                /* SANITY */
                get_net(sock_net(newsk));
@@ -26463,7 +25303,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/sock.c linux-2.6.29.4-vs2.3.0.36.1
                sk_node_init(&newsk->sk_node);
                sock_lock_init(newsk);
                bh_lock_sock(newsk);
-@@ -1057,6 +1070,12 @@ struct sock *sk_clone(const struct sock 
+@@ -1105,6 +1118,12 @@ struct sock *sk_clone(const struct sock 
                newsk->sk_priority = 0;
                atomic_set(&newsk->sk_refcnt, 2);
  
@@ -26476,7 +25316,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/sock.c linux-2.6.29.4-vs2.3.0.36.1
                /*
                 * Increment the counter in the same struct proto as the master
                 * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
-@@ -1744,6 +1763,11 @@ void sock_init_data(struct socket *sock,
+@@ -1794,6 +1813,11 @@ void sock_init_data(struct socket *sock,
  
        sk->sk_stamp = ktime_set(-1L, 0);
  
@@ -26488,9 +25328,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/core/sock.c linux-2.6.29.4-vs2.3.0.36.1
        atomic_set(&sk->sk_refcnt, 1);
        atomic_set(&sk->sk_drops, 0);
  }
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/af_inet.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/af_inet.c
---- linux-2.6.29.4/net/ipv4/af_inet.c  2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/af_inet.c    2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/af_inet.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/af_inet.c
+--- linux-2.6.30.1/net/ipv4/af_inet.c  2009-06-11 17:13:29.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/af_inet.c       2009-07-04 01:11:39.000000000 +0200
 @@ -115,6 +115,7 @@
  #ifdef CONFIG_IP_MROUTE
  #include <linux/mroute.h>
@@ -26513,7 +25353,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/af_inet.c linux-2.6.29.4-vs2.3.0.3
        err = -EAFNOSUPPORT;
        if (!inet_netns_ok(net, protocol))
                goto out_rcu_unlock;
-@@ -445,6 +449,7 @@ int inet_bind(struct socket *sock, struc
+@@ -444,6 +448,7 @@ int inet_bind(struct socket *sock, struc
        struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
        struct sock *sk = sock->sk;
        struct inet_sock *inet = inet_sk(sk);
@@ -26521,7 +25361,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/af_inet.c linux-2.6.29.4-vs2.3.0.3
        unsigned short snum;
        int chk_addr_ret;
        int err;
-@@ -458,7 +463,11 @@ int inet_bind(struct socket *sock, struc
+@@ -457,7 +462,11 @@ int inet_bind(struct socket *sock, struc
        if (addr_len < sizeof(struct sockaddr_in))
                goto out;
  
@@ -26534,7 +25374,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/af_inet.c linux-2.6.29.4-vs2.3.0.3
  
        /* Not specified by any standard per-se, however it breaks too
         * many applications when removed.  It is unfortunate since
-@@ -470,7 +479,7 @@ int inet_bind(struct socket *sock, struc
+@@ -469,7 +478,7 @@ int inet_bind(struct socket *sock, struc
        err = -EADDRNOTAVAIL;
        if (!sysctl_ip_nonlocal_bind &&
            !(inet->freebind || inet->transparent) &&
@@ -26543,7 +25383,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/af_inet.c linux-2.6.29.4-vs2.3.0.3
            chk_addr_ret != RTN_LOCAL &&
            chk_addr_ret != RTN_MULTICAST &&
            chk_addr_ret != RTN_BROADCAST)
-@@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
+@@ -494,7 +503,7 @@ int inet_bind(struct socket *sock, struc
        if (sk->sk_state != TCP_CLOSE || inet->num)
                goto out_release_sock;
  
@@ -26552,7 +25392,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/af_inet.c linux-2.6.29.4-vs2.3.0.3
        if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
                inet->saddr = 0;  /* Use device */
  
-@@ -688,11 +697,13 @@ int inet_getname(struct socket *sock, st
+@@ -687,11 +696,13 @@ int inet_getname(struct socket *sock, st
                     peer == 1))
                        return -ENOTCONN;
                sin->sin_port = inet->dport;
@@ -26567,9 +25407,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/af_inet.c linux-2.6.29.4-vs2.3.0.3
                sin->sin_port = inet->sport;
                sin->sin_addr.s_addr = addr;
        }
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/devinet.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/devinet.c
---- linux-2.6.29.4/net/ipv4/devinet.c  2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/devinet.c    2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/devinet.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/devinet.c
+--- linux-2.6.30.1/net/ipv4/devinet.c  2009-06-11 17:13:29.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/devinet.c       2009-07-04 01:11:39.000000000 +0200
 @@ -413,6 +413,7 @@ struct in_device *inetdev_by_index(struc
        return in_dev;
  }
@@ -26619,7 +25459,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/devinet.c linux-2.6.29.4-vs2.3.0.3
                if (!buf) {
                        done += sizeof(ifr);
                        continue;
-@@ -1156,6 +1166,7 @@ static int inet_dump_ifaddr(struct sk_bu
+@@ -1164,6 +1174,7 @@ static int inet_dump_ifaddr(struct sk_bu
        struct net_device *dev;
        struct in_device *in_dev;
        struct in_ifaddr *ifa;
@@ -26627,7 +25467,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/devinet.c linux-2.6.29.4-vs2.3.0.3
        int s_ip_idx, s_idx = cb->args[0];
  
        s_ip_idx = ip_idx = cb->args[1];
-@@ -1170,6 +1181,8 @@ static int inet_dump_ifaddr(struct sk_bu
+@@ -1178,6 +1189,8 @@ static int inet_dump_ifaddr(struct sk_bu
  
                for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
                     ifa = ifa->ifa_next, ip_idx++) {
@@ -26636,9 +25476,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/devinet.c linux-2.6.29.4-vs2.3.0.3
                        if (ip_idx < s_ip_idx)
                                continue;
                        if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/fib_hash.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/fib_hash.c
---- linux-2.6.29.4/net/ipv4/fib_hash.c 2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/fib_hash.c   2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/fib_hash.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/fib_hash.c
+--- linux-2.6.30.1/net/ipv4/fib_hash.c 2009-03-24 14:22:46.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/fib_hash.c      2009-07-04 01:11:39.000000000 +0200
 @@ -1022,7 +1022,7 @@ static int fib_seq_show(struct seq_file 
        prefix  = f->fn_key;
        mask    = FZ_MASK(iter->zone);
@@ -26648,9 +25488,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/fib_hash.c linux-2.6.29.4-vs2.3.0.
                seq_printf(seq,
                         "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
                         fi->fib_dev ? fi->fib_dev->name : "*", prefix,
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_connection_sock.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_connection_sock.c
---- linux-2.6.29.4/net/ipv4/inet_connection_sock.c     2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_connection_sock.c       2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/inet_connection_sock.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/inet_connection_sock.c
+--- linux-2.6.30.1/net/ipv4/inet_connection_sock.c     2009-06-11 17:13:29.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/inet_connection_sock.c  2009-07-04 01:11:39.000000000 +0200
 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
  }
  EXPORT_SYMBOL(inet_get_local_port_range);
@@ -26704,9 +25544,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_connection_sock.c linux-2.6.2
                                        break;
                        }
                }
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_diag.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_diag.c
---- linux-2.6.29.4/net/ipv4/inet_diag.c        2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_diag.c  2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/inet_diag.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/inet_diag.c
+--- linux-2.6.30.1/net/ipv4/inet_diag.c        2009-03-24 14:22:46.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/inet_diag.c     2009-07-04 01:11:39.000000000 +0200
 @@ -32,6 +32,8 @@
  #include <linux/stddef.h>
  
@@ -26808,9 +25648,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_diag.c linux-2.6.29.4-vs2.3.0
                                if (num < s_num)
                                        goto next_dying;
                                if (r->id.idiag_sport != tw->tw_sport &&
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_hashtables.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_hashtables.c
---- linux-2.6.29.4/net/ipv4/inet_hashtables.c  2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_hashtables.c    2009-04-17 15:35:48.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/inet_hashtables.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/inet_hashtables.c
+--- linux-2.6.30.1/net/ipv4/inet_hashtables.c  2009-06-11 17:13:29.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/inet_hashtables.c       2009-07-04 01:11:39.000000000 +0200
 @@ -21,6 +21,7 @@
  
  #include <net/inet_connection_sock.h>
@@ -26819,7 +25659,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_hashtables.c linux-2.6.29.4-v
  #include <net/ip.h>
  
  /*
-@@ -125,6 +126,11 @@ static inline int compute_score(struct s
+@@ -134,6 +135,11 @@ static inline int compute_score(struct s
                        if (rcv_saddr != daddr)
                                return -1;
                        score += 2;
@@ -26831,7 +25671,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_hashtables.c linux-2.6.29.4-v
                }
                if (sk->sk_bound_dev_if) {
                        if (sk->sk_bound_dev_if != dif)
-@@ -142,7 +148,6 @@ static inline int compute_score(struct s
+@@ -151,7 +157,6 @@ static inline int compute_score(struct s
   * wildcarded during the search since they can never be otherwise.
   */
  
@@ -26839,7 +25679,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_hashtables.c linux-2.6.29.4-v
  struct sock *__inet_lookup_listener(struct net *net,
                                    struct inet_hashinfo *hashinfo,
                                    const __be32 daddr, const unsigned short hnum,
-@@ -165,6 +170,7 @@ begin:
+@@ -174,6 +179,7 @@ begin:
                        hiscore = score;
                }
        }
@@ -26847,9 +25687,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_hashtables.c linux-2.6.29.4-v
        /*
         * if the nulls value we got at the end of this lookup is
         * not the expected one, we must restart lookup.
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/netfilter/nf_nat_helper.c
---- linux-2.6.29.4/net/ipv4/netfilter/nf_nat_helper.c  2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/netfilter/nf_nat_helper.c    2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/netfilter/nf_nat_helper.c
+--- linux-2.6.30.1/net/ipv4/netfilter/nf_nat_helper.c  2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/netfilter/nf_nat_helper.c       2009-07-04 01:11:39.000000000 +0200
 @@ -19,6 +19,7 @@
  #include <net/route.h>
  
@@ -26858,9 +25698,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/netfilter/nf_nat_helper.c linux-2.
  #include <net/netfilter/nf_conntrack.h>
  #include <net/netfilter/nf_conntrack_helper.h>
  #include <net/netfilter/nf_conntrack_ecache.h>
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/netfilter.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/netfilter.c
---- linux-2.6.29.4/net/ipv4/netfilter.c        2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/netfilter.c  2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/netfilter.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/netfilter.c
+--- linux-2.6.30.1/net/ipv4/netfilter.c        2009-03-24 14:22:46.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/netfilter.c     2009-07-04 01:11:39.000000000 +0200
 @@ -4,7 +4,7 @@
  #include <linux/netfilter_ipv4.h>
  #include <linux/ip.h>
@@ -26870,9 +25710,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/netfilter.c linux-2.6.29.4-vs2.3.0
  #include <net/xfrm.h>
  #include <net/ip.h>
  #include <net/netfilter/nf_queue.h>
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/raw.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/raw.c
---- linux-2.6.29.4/net/ipv4/raw.c      2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/raw.c        2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/raw.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/raw.c
+--- linux-2.6.30.1/net/ipv4/raw.c      2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/raw.c   2009-07-04 01:11:39.000000000 +0200
 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
  
                if (net_eq(sock_net(sk), net) && inet->num == num       &&
@@ -26903,7 +25743,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/raw.c linux-2.6.29.4-vs2.3.0.36.14
        kfree_skb(skb);
  error:
        IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
-@@ -550,6 +557,13 @@ static int raw_sendmsg(struct kiocb *ioc
+@@ -551,6 +558,13 @@ static int raw_sendmsg(struct kiocb *ioc
                }
  
                security_sk_classify_flow(sk, &fl);
@@ -26917,7 +25757,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/raw.c linux-2.6.29.4-vs2.3.0.36.14
                err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
        }
        if (err)
-@@ -619,17 +633,19 @@ static int raw_bind(struct sock *sk, str
+@@ -620,17 +634,19 @@ static int raw_bind(struct sock *sk, str
  {
        struct inet_sock *inet = inet_sk(sk);
        struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
@@ -26940,7 +25780,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/raw.c linux-2.6.29.4-vs2.3.0.36.14
        if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
                inet->saddr = 0;  /* Use device */
        sk_dst_reset(sk);
-@@ -681,7 +697,8 @@ static int raw_recvmsg(struct kiocb *ioc
+@@ -682,7 +698,8 @@ static int raw_recvmsg(struct kiocb *ioc
        /* Copy the address. */
        if (sin) {
                sin->sin_family = AF_INET;
@@ -26950,7 +25790,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/raw.c linux-2.6.29.4-vs2.3.0.36.14
                sin->sin_port = 0;
                memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
        }
-@@ -858,7 +875,8 @@ static struct sock *raw_get_first(struct
+@@ -859,7 +876,8 @@ static struct sock *raw_get_first(struct
                struct hlist_node *node;
  
                sk_for_each(sk, node, &state->h->ht[state->bucket])
@@ -26960,7 +25800,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/raw.c linux-2.6.29.4-vs2.3.0.36.14
                                goto found;
        }
        sk = NULL;
-@@ -874,7 +892,8 @@ static struct sock *raw_get_next(struct 
+@@ -875,7 +893,8 @@ static struct sock *raw_get_next(struct 
                sk = sk_next(sk);
  try_again:
                ;
@@ -26970,7 +25810,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/raw.c linux-2.6.29.4-vs2.3.0.36.14
  
        if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
                sk = sk_head(&state->h->ht[state->bucket]);
-@@ -933,7 +952,10 @@ static void raw_sock_seq_show(struct seq
+@@ -934,7 +953,10 @@ static void raw_sock_seq_show(struct seq
  
        seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
                " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
@@ -26982,9 +25822,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/raw.c linux-2.6.29.4-vs2.3.0.36.14
                atomic_read(&sp->sk_wmem_alloc),
                atomic_read(&sp->sk_rmem_alloc),
                0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp.c
---- linux-2.6.29.4/net/ipv4/tcp.c      2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp.c        2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/tcp.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/tcp.c
+--- linux-2.6.30.1/net/ipv4/tcp.c      2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/tcp.c   2009-07-04 01:11:39.000000000 +0200
 @@ -264,6 +264,7 @@
  #include <linux/cache.h>
  #include <linux/err.h>
@@ -26993,10 +25833,10 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp.c linux-2.6.29.4-vs2.3.0.36.14
  
  #include <net/icmp.h>
  #include <net/tcp.h>
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp_ipv4.c
---- linux-2.6.29.4/net/ipv4/tcp_ipv4.c 2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp_ipv4.c   2009-05-23 23:19:11.000000000 +0200
-@@ -1895,6 +1895,12 @@ static void *listening_get_next(struct s
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/tcp_ipv4.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/tcp_ipv4.c
+--- linux-2.6.30.1/net/ipv4/tcp_ipv4.c 2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/tcp_ipv4.c      2009-07-04 01:11:39.000000000 +0200
+@@ -1886,6 +1886,12 @@ static void *listening_get_next(struct s
                req = req->dl_next;
                while (1) {
                        while (req) {
@@ -27009,7 +25849,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.
                                if (req->rsk_ops->family == st->family) {
                                        cur = req;
                                        goto out;
-@@ -1919,6 +1925,10 @@ get_req:
+@@ -1910,6 +1916,10 @@ get_req:
        }
  get_sk:
        sk_nulls_for_each_from(sk, node) {
@@ -27020,7 +25860,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.
                if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
                        cur = sk;
                        goto out;
-@@ -1982,6 +1992,11 @@ static void *established_get_first(struc
+@@ -1973,6 +1983,11 @@ static void *established_get_first(struc
  
                spin_lock_bh(lock);
                sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
@@ -27032,7 +25872,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.
                        if (sk->sk_family != st->family ||
                            !net_eq(sock_net(sk), net)) {
                                continue;
-@@ -1992,6 +2007,11 @@ static void *established_get_first(struc
+@@ -1983,6 +1998,11 @@ static void *established_get_first(struc
                st->state = TCP_SEQ_STATE_TIME_WAIT;
                inet_twsk_for_each(tw, node,
                                   &tcp_hashinfo.ehash[st->bucket].twchain) {
@@ -27044,7 +25884,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.
                        if (tw->tw_family != st->family ||
                            !net_eq(twsk_net(tw), net)) {
                                continue;
-@@ -2020,7 +2040,9 @@ static void *established_get_next(struct
+@@ -2011,7 +2031,9 @@ static void *established_get_next(struct
                tw = cur;
                tw = tw_next(tw);
  get_tw:
@@ -27055,7 +25895,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.
                        tw = tw_next(tw);
                }
                if (tw) {
-@@ -2043,6 +2065,11 @@ get_tw:
+@@ -2034,6 +2056,11 @@ get_tw:
                sk = sk_nulls_next(sk);
  
        sk_nulls_for_each_from(sk, node) {
@@ -27067,7 +25907,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.
                if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
                        goto found;
        }
-@@ -2194,9 +2221,9 @@ static void get_openreq4(struct sock *sk
+@@ -2185,9 +2212,9 @@ static void get_openreq4(struct sock *sk
        seq_printf(f, "%4d: %08X:%04X %08X:%04X"
                " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
                i,
@@ -27079,7 +25919,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.
                ntohs(ireq->rmt_port),
                TCP_SYN_RECV,
                0, 0, /* could print option size, but that is af dependent. */
-@@ -2239,7 +2266,10 @@ static void get_tcp4_sock(struct sock *s
+@@ -2230,7 +2257,10 @@ static void get_tcp4_sock(struct sock *s
  
        seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
                        "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
@@ -27091,7 +25931,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.
                tp->write_seq - tp->snd_una,
                sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
                                             (tp->rcv_nxt - tp->copied_seq),
-@@ -2275,7 +2305,10 @@ static void get_timewait4_sock(struct in
+@@ -2266,7 +2296,10 @@ static void get_timewait4_sock(struct in
  
        seq_printf(f, "%4d: %08X:%04X %08X:%04X"
                " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
@@ -27103,9 +25943,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.
                3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
                atomic_read(&tw->tw_refcnt), tw, len);
  }
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_minisocks.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp_minisocks.c
---- linux-2.6.29.4/net/ipv4/tcp_minisocks.c    2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp_minisocks.c      2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/tcp_minisocks.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/tcp_minisocks.c
+--- linux-2.6.30.1/net/ipv4/tcp_minisocks.c    2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/tcp_minisocks.c 2009-07-04 01:11:39.000000000 +0200
 @@ -26,6 +26,10 @@
  #include <net/inet_common.h>
  #include <net/xfrm.h>
@@ -27129,9 +25969,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_minisocks.c linux-2.6.29.4-vs2
  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
                if (tw->tw_family == PF_INET6) {
                        struct ipv6_pinfo *np = inet6_sk(sk);
-diff -NurpP --minimal linux-2.6.29.4/net/ipv4/udp.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/udp.c
---- linux-2.6.29.4/net/ipv4/udp.c      2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/udp.c        2009-04-15 22:58:30.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/net/ipv4/udp.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/udp.c
+--- linux-2.6.30.1/net/ipv4/udp.c      2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv4/udp.c   2009-07-04 01:11:39.000000000 +0200
 @@ -222,14 +222,7 @@ fail:
        return error;
  }
@@ -27205,7 +26045,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/udp.c linux-2.6.29.4-vs2.3.0.36.14
                    ipv6_only_sock(s)                                   ||
                    (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
                        continue;
-@@ -694,8 +700,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
+@@ -698,8 +704,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
                                               { .sport = inet->sport,
                                                 .dport = dport } } };
                struct net *net = sock_net(sk);
@@ -27219,7 +26059,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/udp.c linux-2.6.29.4-vs2.3.0.36.14
                err = ip_route_output_flow(net, &rt, &fl, sk, 1);
                if (err) {
                        if (err == -ENETUNREACH)
-@@ -940,7 +951,8 @@ try_again:
+@@ -944,7 +955,8 @@ try_again:
        {
                sin->sin_family = AF_INET;
                sin->sin_port = udp_hdr(skb)->source;
@@ -27229,7 +26069,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/udp.c linux-2.6.29.4-vs2.3.0.36.14
                memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
        }
        if (inet->cmsg_flags)
-@@ -1594,6 +1606,8 @@ static struct sock *udp_get_first(struct
+@@ -1598,6 +1610,8 @@ static struct sock *udp_get_first(struct
                sk_nulls_for_each(sk, node, &hslot->head) {
                        if (!net_eq(sock_net(sk), net))
                                continue;
@@ -27238,7 +26078,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/udp.c linux-2.6.29.4-vs2.3.0.36.14
                        if (sk->sk_family == state->family)
                                goto found;
                }
-@@ -1611,7 +1625,9 @@ static struct sock *udp_get_next(struct 
+@@ -1615,7 +1629,9 @@ static struct sock *udp_get_next(struct 
  
        do {
                sk = sk_nulls_next(sk);
@@ -27249,7 +26089,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/udp.c linux-2.6.29.4-vs2.3.0.36.14
  
        if (!sk) {
                if (state->bucket < UDP_HTABLE_SIZE)
-@@ -1716,7 +1732,10 @@ static void udp4_format_sock(struct sock
+@@ -1720,7 +1736,10 @@ static void udp4_format_sock(struct sock
  
        seq_printf(f, "%4d: %08X:%04X %08X:%04X"
                " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
@@ -27261,10 +26101,10 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv4/udp.c linux-2.6.29.4-vs2.3.0.36.14
                atomic_read(&sp->sk_wmem_alloc),
                atomic_read(&sp->sk_rmem_alloc),
                0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/addrconf.c
---- linux-2.6.29.4/net/ipv6/addrconf.c 2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/addrconf.c   2009-03-24 20:39:23.000000000 +0100
-@@ -85,6 +85,8 @@
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/addrconf.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/addrconf.c
+--- linux-2.6.30.1/net/ipv6/addrconf.c 2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/addrconf.c      2009-07-04 01:11:39.000000000 +0200
+@@ -86,6 +86,8 @@
  
  #include <linux/proc_fs.h>
  #include <linux/seq_file.h>
@@ -27273,7 +26113,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.
  
  /* Set to 3 to get tracing... */
  #define ACONF_DEBUG 2
-@@ -1111,7 +1113,7 @@ out:
+@@ -1118,7 +1120,7 @@ out:
  
  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
                       const struct in6_addr *daddr, unsigned int prefs,
@@ -27282,7 +26122,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.
  {
        struct ipv6_saddr_score scores[2],
                                *score = &scores[0], *hiscore = &scores[1];
-@@ -1184,6 +1186,8 @@ int ipv6_dev_get_saddr(struct net *net, 
+@@ -1191,6 +1193,8 @@ int ipv6_dev_get_saddr(struct net *net, 
                                               dev->name);
                                continue;
                        }
@@ -27291,59 +26131,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.
  
                        score->rule = -1;
                        bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
-@@ -1367,35 +1371,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
-       return ifp;
- }
-+extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
-+
- int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
- {
-       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
-       const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
--      __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
-       __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
-       int sk_ipv6only = ipv6_only_sock(sk);
-       int sk2_ipv6only = inet_v6_ipv6only(sk2);
-       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
-       int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
--      if (!sk2_rcv_saddr && !sk_ipv6only)
-+      /* FIXME: needs handling for v4 ANY */
-+      if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
-               return 1;
-       if (addr_type2 == IPV6_ADDR_ANY &&
--          !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
-+          !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
-+          v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
-               return 1;
-       if (addr_type == IPV6_ADDR_ANY &&
--          !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
-+          !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
-+          (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
-+              return 1;
-+
-+      if (addr_type == IPV6_ADDR_ANY &&
-+          addr_type2 == IPV6_ADDR_ANY &&
-+          nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
-               return 1;
-       if (sk2_rcv_saddr6 &&
-+          addr_type != IPV6_ADDR_ANY &&
-+          addr_type != IPV6_ADDR_ANY &&
-           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
-               return 1;
-       if (addr_type == IPV6_ADDR_MAPPED &&
-           !sk2_ipv6only &&
--          (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
-+          ipv4_rcv_saddr_equal(sk, sk2))
-               return 1;
-       return 0;
-@@ -2993,7 +3008,10 @@ static void if6_seq_stop(struct seq_file
+@@ -2954,7 +2958,10 @@ static void if6_seq_stop(struct seq_file
  static int if6_seq_show(struct seq_file *seq, void *v)
  {
        struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
@@ -27355,7 +26143,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.
                   &ifp->addr,
                   ifp->idev->dev->ifindex,
                   ifp->prefix_len,
-@@ -3487,6 +3505,12 @@ static int inet6_dump_addr(struct sk_buf
+@@ -3448,6 +3455,12 @@ static int inet6_dump_addr(struct sk_buf
        struct ifmcaddr6 *ifmca;
        struct ifacaddr6 *ifaca;
        struct net *net = sock_net(skb->sk);
@@ -27368,7 +26156,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.
  
        s_idx = cb->args[0];
        s_ip_idx = ip_idx = cb->args[1];
-@@ -3508,6 +3532,8 @@ static int inet6_dump_addr(struct sk_buf
+@@ -3469,6 +3482,8 @@ static int inet6_dump_addr(struct sk_buf
                             ifa = ifa->if_next, ip_idx++) {
                                if (ip_idx < s_ip_idx)
                                        continue;
@@ -27377,7 +26165,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.
                                err = inet6_fill_ifaddr(skb, ifa,
                                                        NETLINK_CB(cb->skb).pid,
                                                        cb->nlh->nlmsg_seq,
-@@ -3521,6 +3547,8 @@ static int inet6_dump_addr(struct sk_buf
+@@ -3482,6 +3497,8 @@ static int inet6_dump_addr(struct sk_buf
                             ifmca = ifmca->next, ip_idx++) {
                                if (ip_idx < s_ip_idx)
                                        continue;
@@ -27386,7 +26174,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.
                                err = inet6_fill_ifmcaddr(skb, ifmca,
                                                          NETLINK_CB(cb->skb).pid,
                                                          cb->nlh->nlmsg_seq,
-@@ -3534,6 +3562,8 @@ static int inet6_dump_addr(struct sk_buf
+@@ -3495,6 +3512,8 @@ static int inet6_dump_addr(struct sk_buf
                             ifaca = ifaca->aca_next, ip_idx++) {
                                if (ip_idx < s_ip_idx)
                                        continue;
@@ -27395,7 +26183,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.
                                err = inet6_fill_ifacaddr(skb, ifaca,
                                                          NETLINK_CB(cb->skb).pid,
                                                          cb->nlh->nlmsg_seq,
-@@ -3819,12 +3849,19 @@ static int inet6_dump_ifinfo(struct sk_b
+@@ -3781,12 +3800,19 @@ static int inet6_dump_ifinfo(struct sk_b
        int s_idx = cb->args[0];
        struct net_device *dev;
        struct inet6_dev *idev;
@@ -27415,9 +26203,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.
                if ((idev = in6_dev_get(dev)) == NULL)
                        goto cont;
                err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/af_inet6.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/af_inet6.c
---- linux-2.6.29.4/net/ipv6/af_inet6.c 2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/af_inet6.c   2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/af_inet6.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/af_inet6.c
+--- linux-2.6.30.1/net/ipv6/af_inet6.c 2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/af_inet6.c      2009-07-04 01:11:39.000000000 +0200
 @@ -41,6 +41,8 @@
  #include <linux/netdevice.h>
  #include <linux/icmpv6.h>
@@ -27469,18 +26257,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/af_inet6.c linux-2.6.29.4-vs2.3.0.
        addr_type = ipv6_addr_type(&addr->sin6_addr);
        if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
                return -EINVAL;
-@@ -281,6 +293,10 @@ int inet6_bind(struct socket *sock, stru
-                       err = -EADDRNOTAVAIL;
-                       goto out;
-               }
-+              if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
-+                      err = -EADDRNOTAVAIL;
-+                      goto out;
-+              }
-       } else {
-               if (addr_type != IPV6_ADDR_ANY) {
-                       struct net_device *dev = NULL;
-@@ -306,6 +322,11 @@ int inet6_bind(struct socket *sock, stru
+@@ -321,6 +333,11 @@ int inet6_bind(struct socket *sock, stru
                                }
                        }
  
@@ -27492,7 +26269,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/af_inet6.c linux-2.6.29.4-vs2.3.0.
                        /* ipv4 addr of the socket is invalid.  Only the
                         * unspecified and mapped address have a v4 equivalent.
                         */
-@@ -324,6 +345,8 @@ int inet6_bind(struct socket *sock, stru
+@@ -339,6 +356,8 @@ int inet6_bind(struct socket *sock, stru
                }
        }
  
@@ -27501,7 +26278,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/af_inet6.c linux-2.6.29.4-vs2.3.0.
        inet->rcv_saddr = v4addr;
        inet->saddr = v4addr;
  
-@@ -416,9 +439,11 @@ int inet6_getname(struct socket *sock, s
+@@ -434,9 +453,11 @@ int inet6_getname(struct socket *sock, s
                        return -ENOTCONN;
                sin->sin6_port = inet->dport;
                ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
@@ -27513,9 +26290,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/af_inet6.c linux-2.6.29.4-vs2.3.0.
                if (ipv6_addr_any(&np->rcv_saddr))
                        ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
                else
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/fib6_rules.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/fib6_rules.c
---- linux-2.6.29.4/net/ipv6/fib6_rules.c       2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/fib6_rules.c 2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/fib6_rules.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/fib6_rules.c
+--- linux-2.6.30.1/net/ipv6/fib6_rules.c       2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/fib6_rules.c    2009-07-04 01:11:39.000000000 +0200
 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
                        if (ipv6_dev_get_saddr(net,
                                               ip6_dst_idev(&rt->u.dst)->dev,
@@ -27525,9 +26302,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/fib6_rules.c linux-2.6.29.4-vs2.3.
                                goto again;
                        if (!ipv6_prefix_equal(&saddr, &r->src.addr,
                                               r->src.plen))
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/inet6_hashtables.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/inet6_hashtables.c
---- linux-2.6.29.4/net/ipv6/inet6_hashtables.c 2009-03-24 14:22:46.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/inet6_hashtables.c   2009-03-24 20:50:24.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/inet6_hashtables.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/inet6_hashtables.c
+--- linux-2.6.30.1/net/ipv6/inet6_hashtables.c 2009-03-24 14:22:46.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/inet6_hashtables.c      2009-07-04 01:11:39.000000000 +0200
 @@ -16,6 +16,7 @@
  
  #include <linux/module.h>
@@ -27563,9 +26340,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/inet6_hashtables.c linux-2.6.29.4-
                }
                if (sk->sk_bound_dev_if) {
                        if (sk->sk_bound_dev_if != dif)
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/ip6_output.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/ip6_output.c
---- linux-2.6.29.4/net/ipv6/ip6_output.c       2009-03-24 14:22:47.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/ip6_output.c 2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/ip6_output.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/ip6_output.c
+--- linux-2.6.30.1/net/ipv6/ip6_output.c       2009-03-24 14:22:47.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/ip6_output.c    2009-07-04 01:11:39.000000000 +0200
 @@ -951,7 +951,7 @@ static int ip6_dst_lookup_tail(struct so
                err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
                                         &fl->fl6_dst,
@@ -27575,9 +26352,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/ip6_output.c linux-2.6.29.4-vs2.3.
                if (err)
                        goto out_err_release;
        }
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/Kconfig linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/Kconfig
---- linux-2.6.29.4/net/ipv6/Kconfig    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/Kconfig      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/Kconfig linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/Kconfig
+--- linux-2.6.30.1/net/ipv6/Kconfig    2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/Kconfig 2009-07-04 01:11:39.000000000 +0200
 @@ -4,8 +4,8 @@
  
  #   IPv6 as module will cause a CRASH if you try to unload it
@@ -27589,9 +26366,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/Kconfig linux-2.6.29.4-vs2.3.0.36.
        ---help---
          This is complemental support for the IP version 6.
          You will still be able to do traditional IPv4 networking as well.
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/ndisc.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/ndisc.c
---- linux-2.6.29.4/net/ipv6/ndisc.c    2009-03-24 14:22:47.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/ndisc.c      2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/ndisc.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/ndisc.c
+--- linux-2.6.30.1/net/ipv6/ndisc.c    2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/ndisc.c 2009-07-04 01:11:39.000000000 +0200
 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
        } else {
                if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
@@ -27601,9 +26378,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/ndisc.c linux-2.6.29.4-vs2.3.0.36.
                        return;
                src_addr = &tmpaddr;
        }
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/raw.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/raw.c
---- linux-2.6.29.4/net/ipv6/raw.c      2009-03-24 14:22:47.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/raw.c        2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/raw.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/raw.c
+--- linux-2.6.30.1/net/ipv6/raw.c      2009-03-24 14:22:47.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/raw.c   2009-07-04 01:11:39.000000000 +0200
 @@ -29,6 +29,7 @@
  #include <linux/icmpv6.h>
  #include <linux/netfilter.h>
@@ -27626,10 +26403,10 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/raw.c linux-2.6.29.4-vs2.3.0.36.14
                /* ipv4 addr of the socket is invalid.  Only the
                 * unspecified and mapped address have a v4 equivalent.
                 */
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/route.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/route.c
---- linux-2.6.29.4/net/ipv6/route.c    2009-03-24 14:22:47.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/route.c      2009-03-24 14:48:37.000000000 +0100
-@@ -2254,7 +2254,8 @@ static int rt6_fill_node(struct net *net
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/route.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/route.c
+--- linux-2.6.30.1/net/ipv6/route.c    2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/route.c 2009-07-04 01:11:39.000000000 +0200
+@@ -2257,7 +2257,8 @@ static int rt6_fill_node(struct net *net
                struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
                struct in6_addr saddr_buf;
                if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
@@ -27639,9 +26416,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/route.c linux-2.6.29.4-vs2.3.0.36.
                        NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
        }
  
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/tcp_ipv6.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/tcp_ipv6.c
---- linux-2.6.29.4/net/ipv6/tcp_ipv6.c 2009-03-24 14:22:47.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/tcp_ipv6.c   2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/tcp_ipv6.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/tcp_ipv6.c
+--- linux-2.6.30.1/net/ipv6/tcp_ipv6.c 2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/tcp_ipv6.c      2009-07-04 01:11:39.000000000 +0200
 @@ -68,6 +68,7 @@
  
  #include <linux/crypto.h>
@@ -27668,9 +26445,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/tcp_ipv6.c linux-2.6.29.4-vs2.3.0.
  
        addr_type = ipv6_addr_type(&usin->sin6_addr);
  
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/udp.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/udp.c
---- linux-2.6.29.4/net/ipv6/udp.c      2009-03-24 14:22:47.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/udp.c        2009-03-24 20:56:49.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/udp.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/udp.c
+--- linux-2.6.30.1/net/ipv6/udp.c      2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/udp.c   2009-07-04 01:11:39.000000000 +0200
 @@ -47,6 +47,7 @@
  
  #include <linux/proc_fs.h>
@@ -27678,8 +26455,8 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/udp.c linux-2.6.29.4-vs2.3.0.36.14
 +#include <linux/vs_inet6.h>
  #include "udp_impl.h"
  
- int udp_v6_get_port(struct sock *sk, unsigned short snum)
-@@ -77,6 +78,10 @@ static inline int compute_score(struct s
+ int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
+@@ -109,6 +110,10 @@ static inline int compute_score(struct s
                        if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
                                return -1;
                        score++;
@@ -27690,9 +26467,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/udp.c linux-2.6.29.4-vs2.3.0.36.14
                }
                if (!ipv6_addr_any(&np->daddr)) {
                        if (!ipv6_addr_equal(&np->daddr, saddr))
-diff -NurpP --minimal linux-2.6.29.4/net/ipv6/xfrm6_policy.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/xfrm6_policy.c
---- linux-2.6.29.4/net/ipv6/xfrm6_policy.c     2009-03-24 14:22:47.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/xfrm6_policy.c       2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/ipv6/xfrm6_policy.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/xfrm6_policy.c
+--- linux-2.6.30.1/net/ipv6/xfrm6_policy.c     2009-06-11 17:13:30.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/ipv6/xfrm6_policy.c  2009-07-04 01:11:39.000000000 +0200
 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
        dev = ip6_dst_idev(dst)->dev;
        ipv6_dev_get_saddr(dev_net(dev), dev,
@@ -27702,9 +26479,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/ipv6/xfrm6_policy.c linux-2.6.29.4-vs2.
        dst_release(dst);
        return 0;
  }
-diff -NurpP --minimal linux-2.6.29.4/net/netlink/af_netlink.c linux-2.6.29.4-vs2.3.0.36.14/net/netlink/af_netlink.c
---- linux-2.6.29.4/net/netlink/af_netlink.c    2009-03-24 14:22:47.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/netlink/af_netlink.c      2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/netlink/af_netlink.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/netlink/af_netlink.c
+--- linux-2.6.30.1/net/netlink/af_netlink.c    2009-06-11 17:13:31.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/netlink/af_netlink.c 2009-07-04 01:11:39.000000000 +0200
 @@ -55,6 +55,9 @@
  #include <linux/types.h>
  #include <linux/audit.h>
@@ -27715,7 +26492,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/netlink/af_netlink.c linux-2.6.29.4-vs2
  
  #include <net/net_namespace.h>
  #include <net/sock.h>
-@@ -1776,6 +1779,8 @@ static struct sock *netlink_seq_socket_i
+@@ -1831,6 +1834,8 @@ static struct sock *netlink_seq_socket_i
                        sk_for_each(s, node, &hash->table[j]) {
                                if (sock_net(s) != seq_file_net(seq))
                                        continue;
@@ -27724,7 +26501,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/netlink/af_netlink.c linux-2.6.29.4-vs2
                                if (off == pos) {
                                        iter->link = i;
                                        iter->hash_idx = j;
-@@ -1810,7 +1815,8 @@ static void *netlink_seq_next(struct seq
+@@ -1865,7 +1870,8 @@ static void *netlink_seq_next(struct seq
        s = v;
        do {
                s = sk_next(s);
@@ -27734,7 +26511,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/netlink/af_netlink.c linux-2.6.29.4-vs2
        if (s)
                return s;
  
-@@ -1822,7 +1828,8 @@ static void *netlink_seq_next(struct seq
+@@ -1877,7 +1883,8 @@ static void *netlink_seq_next(struct seq
  
                for (; j <= hash->mask; j++) {
                        s = sk_head(&hash->table[j]);
@@ -27744,10 +26521,10 @@ diff -NurpP --minimal linux-2.6.29.4/net/netlink/af_netlink.c linux-2.6.29.4-vs2
                                s = sk_next(s);
                        if (s) {
                                iter->link = i;
-diff -NurpP --minimal linux-2.6.29.4/net/sctp/ipv6.c linux-2.6.29.4-vs2.3.0.36.14/net/sctp/ipv6.c
---- linux-2.6.29.4/net/sctp/ipv6.c     2009-03-24 14:22:48.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/sctp/ipv6.c       2009-03-24 20:58:14.000000000 +0100
-@@ -317,7 +317,8 @@ static void sctp_v6_get_saddr(struct sct
+diff -NurpP --minimal linux-2.6.30.1/net/sctp/ipv6.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/sctp/ipv6.c
+--- linux-2.6.30.1/net/sctp/ipv6.c     2009-06-11 17:13:32.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/sctp/ipv6.c  2009-07-04 01:11:39.000000000 +0200
+@@ -316,7 +316,8 @@ static void sctp_v6_get_saddr(struct sct
                                   dst ? ip6_dst_idev(dst)->dev : NULL,
                                   &daddr->v6.sin6_addr,
                                   inet6_sk(&sk->inet.sk)->srcprefs,
@@ -27757,9 +26534,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/sctp/ipv6.c linux-2.6.29.4-vs2.3.0.36.1
                SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
                                  &saddr->v6.sin6_addr);
                return;
-diff -NurpP --minimal linux-2.6.29.4/net/socket.c linux-2.6.29.4-vs2.3.0.36.14/net/socket.c
---- linux-2.6.29.4/net/socket.c        2009-03-24 14:22:48.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/socket.c  2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/socket.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/socket.c
+--- linux-2.6.30.1/net/socket.c        2009-06-11 17:13:32.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/socket.c     2009-07-04 01:11:39.000000000 +0200
 @@ -95,6 +95,10 @@
  
  #include <net/sock.h>
@@ -27771,7 +26548,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/socket.c linux-2.6.29.4-vs2.3.0.36.14/n
  
  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
-@@ -549,7 +553,7 @@ static inline int __sock_sendmsg(struct 
+@@ -559,7 +563,7 @@ static inline int __sock_sendmsg(struct 
                                 struct msghdr *msg, size_t size)
  {
        struct sock_iocb *si = kiocb_to_siocb(iocb);
@@ -27780,7 +26557,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/socket.c linux-2.6.29.4-vs2.3.0.36.14/n
  
        si->sock = sock;
        si->scm = NULL;
-@@ -560,7 +564,22 @@ static inline int __sock_sendmsg(struct 
+@@ -570,7 +574,22 @@ static inline int __sock_sendmsg(struct 
        if (err)
                return err;
  
@@ -27804,7 +26581,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/socket.c linux-2.6.29.4-vs2.3.0.36.14/n
  }
  
  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
-@@ -629,7 +648,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
+@@ -671,7 +690,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
                                 struct msghdr *msg, size_t size, int flags)
  {
@@ -27813,7 +26590,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/socket.c linux-2.6.29.4-vs2.3.0.36.14/n
        struct sock_iocb *si = kiocb_to_siocb(iocb);
  
        si->sock = sock;
-@@ -642,7 +661,18 @@ static inline int __sock_recvmsg(struct 
+@@ -684,7 +703,18 @@ static inline int __sock_recvmsg(struct 
        if (err)
                return err;
  
@@ -27833,7 +26610,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/socket.c linux-2.6.29.4-vs2.3.0.36.14/n
  }
  
  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
-@@ -1106,6 +1136,13 @@ static int __sock_create(struct net *net
+@@ -1155,6 +1185,13 @@ static int __sock_create(struct net *net
        if (type < 0 || type >= SOCK_MAX)
                return -EINVAL;
  
@@ -27847,7 +26624,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/socket.c linux-2.6.29.4-vs2.3.0.36.14/n
        /* Compatibility.
  
           This uglymoron is moved from INET layer to here to avoid
-@@ -1238,6 +1275,7 @@ SYSCALL_DEFINE3(socket, int, family, int
+@@ -1287,6 +1324,7 @@ SYSCALL_DEFINE3(socket, int, family, int
        if (retval < 0)
                goto out;
  
@@ -27855,7 +26632,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/socket.c linux-2.6.29.4-vs2.3.0.36.14/n
        retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
        if (retval < 0)
                goto out_release;
-@@ -1279,10 +1317,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
+@@ -1328,10 +1366,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
        err = sock_create(family, type, protocol, &sock1);
        if (err < 0)
                goto out;
@@ -27868,9 +26645,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/socket.c linux-2.6.29.4-vs2.3.0.36.14/n
  
        err = sock1->ops->socketpair(sock1, sock2);
        if (err < 0)
-diff -NurpP --minimal linux-2.6.29.4/net/sunrpc/auth.c linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/auth.c
---- linux-2.6.29.4/net/sunrpc/auth.c   2009-03-24 14:22:48.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/auth.c     2009-03-24 21:00:49.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/sunrpc/auth.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/sunrpc/auth.c
+--- linux-2.6.30.1/net/sunrpc/auth.c   2009-03-24 14:22:48.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/sunrpc/auth.c        2009-07-04 01:11:39.000000000 +0200
 @@ -14,6 +14,7 @@
  #include <linux/hash.h>
  #include <linux/sunrpc/clnt.h>
@@ -27895,9 +26672,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/sunrpc/auth.c linux-2.6.29.4-vs2.3.0.36
        };
        struct rpc_cred *ret;
  
-diff -NurpP --minimal linux-2.6.29.4/net/sunrpc/auth_unix.c linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/auth_unix.c
---- linux-2.6.29.4/net/sunrpc/auth_unix.c      2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/auth_unix.c        2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/sunrpc/auth_unix.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/sunrpc/auth_unix.c
+--- linux-2.6.30.1/net/sunrpc/auth_unix.c      2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/sunrpc/auth_unix.c   2009-07-04 01:11:39.000000000 +0200
 @@ -11,12 +11,14 @@
  #include <linux/module.h>
  #include <linux/sunrpc/clnt.h>
@@ -27956,9 +26733,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/sunrpc/auth_unix.c linux-2.6.29.4-vs2.3
        hold = p++;
        for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
                *p++ = htonl((u32) cred->uc_gids[i]);
-diff -NurpP --minimal linux-2.6.29.4/net/sunrpc/clnt.c linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/clnt.c
---- linux-2.6.29.4/net/sunrpc/clnt.c   2009-03-24 14:22:48.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/clnt.c     2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/sunrpc/clnt.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/sunrpc/clnt.c
+--- linux-2.6.30.1/net/sunrpc/clnt.c   2009-06-11 17:13:32.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/sunrpc/clnt.c        2009-07-04 01:11:39.000000000 +0200
 @@ -32,6 +32,7 @@
  #include <linux/utsname.h>
  #include <linux/workqueue.h>
@@ -27977,9 +26754,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/sunrpc/clnt.c linux-2.6.29.4-vs2.3.0.36
        return clnt;
  }
  EXPORT_SYMBOL_GPL(rpc_create);
-diff -NurpP --minimal linux-2.6.29.4/net/unix/af_unix.c linux-2.6.29.4-vs2.3.0.36.14/net/unix/af_unix.c
---- linux-2.6.29.4/net/unix/af_unix.c  2009-03-24 14:22:48.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/unix/af_unix.c    2009-03-24 14:48:37.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/net/unix/af_unix.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/unix/af_unix.c
+--- linux-2.6.30.1/net/unix/af_unix.c  2009-06-11 17:13:32.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/unix/af_unix.c       2009-07-04 01:11:39.000000000 +0200
 @@ -114,6 +114,8 @@
  #include <linux/mount.h>
  #include <net/checksum.h>
@@ -27998,7 +26775,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/unix/af_unix.c linux-2.6.29.4-vs2.3.0.3
                if (u->addr->len == len &&
                    !memcmp(u->addr->name, sunname, len))
                        goto found;
-@@ -2110,6 +2114,8 @@ static struct sock *unix_seq_idx(struct 
+@@ -2109,6 +2113,8 @@ static struct sock *unix_seq_idx(struct 
        for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
                if (sock_net(s) != seq_file_net(seq))
                        continue;
@@ -28007,7 +26784,7 @@ diff -NurpP --minimal linux-2.6.29.4/net/unix/af_unix.c linux-2.6.29.4-vs2.3.0.3
                if (off == pos)
                        return s;
                ++off;
-@@ -2134,7 +2140,8 @@ static void *unix_seq_next(struct seq_fi
+@@ -2133,7 +2139,8 @@ static void *unix_seq_next(struct seq_fi
                sk = first_unix_socket(&iter->i);
        else
                sk = next_unix_socket(&iter->i, sk);
@@ -28017,10 +26794,10 @@ diff -NurpP --minimal linux-2.6.29.4/net/unix/af_unix.c linux-2.6.29.4-vs2.3.0.3
                sk = next_unix_socket(&iter->i, sk);
        return sk;
  }
-diff -NurpP --minimal linux-2.6.29.4/net/x25/af_x25.c linux-2.6.29.4-vs2.3.0.36.14/net/x25/af_x25.c
---- linux-2.6.29.4/net/x25/af_x25.c    2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/net/x25/af_x25.c      2009-04-30 12:14:53.000000000 +0200
-@@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
+diff -NurpP --minimal linux-2.6.30.1/net/x25/af_x25.c linux-2.6.30.1-vs2.3.0.36.14-pre4/net/x25/af_x25.c
+--- linux-2.6.30.1/net/x25/af_x25.c    2009-07-03 20:12:09.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/net/x25/af_x25.c 2009-07-04 01:11:39.000000000 +0200
+@@ -519,7 +519,10 @@ static int x25_create(struct net *net, s
  
        x25 = x25_sk(sk);
  
@@ -28032,9 +26809,9 @@ diff -NurpP --minimal linux-2.6.29.4/net/x25/af_x25.c linux-2.6.29.4-vs2.3.0.36.
  
        x25_init_timers(sk);
  
-diff -NurpP --minimal linux-2.6.29.4/scripts/checksyscalls.sh linux-2.6.29.4-vs2.3.0.36.14/scripts/checksyscalls.sh
---- linux-2.6.29.4/scripts/checksyscalls.sh    2008-12-25 00:26:37.000000000 +0100
-+++ linux-2.6.29.4-vs2.3.0.36.14/scripts/checksyscalls.sh      2009-02-22 22:54:26.000000000 +0100
+diff -NurpP --minimal linux-2.6.30.1/scripts/checksyscalls.sh linux-2.6.30.1-vs2.3.0.36.14-pre4/scripts/checksyscalls.sh
+--- linux-2.6.30.1/scripts/checksyscalls.sh    2008-12-25 00:26:37.000000000 +0100
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/scripts/checksyscalls.sh 2009-07-04 01:11:39.000000000 +0200
 @@ -108,7 +108,6 @@ cat << EOF
  #define __IGNORE_afs_syscall
  #define __IGNORE_getpmsg
@@ -28043,9 +26820,9 @@ diff -NurpP --minimal linux-2.6.29.4/scripts/checksyscalls.sh linux-2.6.29.4-vs2
  EOF
  }
  
-diff -NurpP --minimal linux-2.6.29.4/security/commoncap.c linux-2.6.29.4-vs2.3.0.36.14/security/commoncap.c
---- linux-2.6.29.4/security/commoncap.c        2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/security/commoncap.c  2009-04-30 12:14:53.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/security/commoncap.c linux-2.6.30.1-vs2.3.0.36.14-pre4/security/commoncap.c
+--- linux-2.6.30.1/security/commoncap.c        2009-06-11 17:13:33.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/security/commoncap.c     2009-07-04 01:11:39.000000000 +0200
 @@ -27,10 +27,11 @@
  #include <linux/sched.h>
  #include <linux/prctl.h>
@@ -28115,9 +26892,9 @@ diff -NurpP --minimal linux-2.6.29.4/security/commoncap.c linux-2.6.29.4-vs2.3.0
        return __vm_enough_memory(mm, pages, cap_sys_admin);
  }
 +
-diff -NurpP --minimal linux-2.6.29.4/security/selinux/hooks.c linux-2.6.29.4-vs2.3.0.36.14/security/selinux/hooks.c
---- linux-2.6.29.4/security/selinux/hooks.c    2009-05-23 23:16:53.000000000 +0200
-+++ linux-2.6.29.4-vs2.3.0.36.14/security/selinux/hooks.c      2009-05-23 23:19:11.000000000 +0200
+diff -NurpP --minimal linux-2.6.30.1/security/selinux/hooks.c linux-2.6.30.1-vs2.3.0.36.14-pre4/security/selinux/hooks.c
+--- linux-2.6.30.1/security/selinux/hooks.c    2009-06-11 17:13:33.000000000 +0200
++++ linux-2.6.30.1-vs2.3.0.36.14-pre4/security/selinux/hooks.c 2009-07-04 01:11:39.000000000 +0200
 @@ -64,7 +64,6 @@
  #include <linux/dccp.h>
  #include <linux/quota.h>
index 7a2da38fb5f48b90febbd40a182a18058149beed..3089220f704d5569066b6c59cfa1c2d1ad3c057b 100644 (file)
  {
        return call_prom("getproplen", 2, 1, node, ADDR(pname));
  }
---- linux-2.6.20/include/linux/cpuset.h~       2007-02-04 19:44:54.000000000 +0100
-+++ linux-2.6.20/include/linux/cpuset.h        2007-04-10 02:06:13.121532000 +0200
-@@ -33,13 +33,13 @@
- extern int __cpuset_zone_allowed_softwall(struct zone *z, gfp_t gfp_mask);
- extern int __cpuset_zone_allowed_hardwall(struct zone *z, gfp_t gfp_mask);
--static int inline cpuset_zone_allowed_softwall(struct zone *z, gfp_t gfp_mask)
-+static inline int cpuset_zone_allowed_softwall(struct zone *z, gfp_t gfp_mask)
- {
-       return number_of_cpusets <= 1 ||
-               __cpuset_zone_allowed_softwall(z, gfp_mask);
- }
--static int inline cpuset_zone_allowed_hardwall(struct zone *z, gfp_t gfp_mask)
-+static inline int cpuset_zone_allowed_hardwall(struct zone *z, gfp_t gfp_mask)
- {
-       return number_of_cpusets <= 1 ||
-               __cpuset_zone_allowed_hardwall(z, gfp_mask);
 --- linux-2.6.24-rc8/fs/ocfs2/dir.c.org        2008-01-23 08:32:50.134566450 +0100
 +++ linux-2.6.24-rc8/fs/ocfs2/dir.c    2008-01-23 08:32:57.441604337 +0100
 @@ -126,7 +126,7 @@
index 4fec1f682dc65b442b0d7d3cd87a16d9a9d3df58..6d088260ca8946d7cc106f76431f07929e82884b 100644 (file)
 %define                have_pcmcia     0
 %endif
 
-%define                basever         2.6.29
-%define                postver         .4
-%define                rel             0.2
+%define                basever         2.6.30
+%define                postver         .2
+%define                rel             0.1
 
 %define                _enable_debug_packages                  0
 
@@ -158,10 +158,10 @@ Epoch:            3
 License:       GPL v2
 Group:         Base/Kernel
 Source0:       http://www.kernel.org/pub/linux/kernel/v2.6/linux-%{basever}.tar.bz2
-# Source0-md5: 64921b5ff5cdadbccfcd3820f03be7d8
+# Source0-md5: 7a80058a6382e5108cdb5554d1609615
 %if "%{postver}" != "%{nil}"
 Source1:       http://www.kernel.org/pub/linux/kernel/v2.6/patch-%{version}.bz2
-# Source1-md5: 03f1a0236cc37d8594d2f3c837d81c9d
+# Source1-md5: 3b566e7d970941846bcbe35cecf04e21
 %endif
 
 Source3:       kernel-autoconf.h
@@ -273,7 +273,7 @@ Patch58:    kernel-PF_RING.patch
 Patch59:       kernel-rndis_host-wm5.patch
 
 # Project suspend2 renamed to tuxonice
-# http://www.tuxonice.net/downloads/all/tuxonice-3.0.1-for-head.patch.bz2
+# http://www.tuxonice.net/downloads/all/current-tuxonice-for-2.6.30.patch-20090620-v1.bz2
 Patch69:       kernel-tuxonice.patch
 Patch70:       kernel-tuxonice-headers.patch
 
@@ -281,10 +281,10 @@ Patch70:  kernel-tuxonice-headers.patch
 # http://patches.aircrack-ng.org/hostap-kernel-2.6.18.patch
 Patch85:       kernel-hostap.patch
 
-# Taken from http://download.opensuse.org/factory/repo/src-oss/suse/src/kernel-source-2.6.27.7-3.1.src.rpm
+# Taken from http://download.opensuse.org/factory/repo/src-oss/suse/src/kernel-source-2.6.30-10.3.src.rpm
 Patch90:       kernel-mpt-fusion.patch
 
-# based on http://vserver.13thfloor.at/Experimental/patch-2.6.29-vs2.3.0.36.9-pre3.diff
+# based on http://vserver.13thfloor.at/Experimental/patch-2.6.30.1-vs2.3.0.36.14-pre4.diff
 Patch100:      kernel-vserver-2.3.patch
 Patch101:      kernel-vserver-fixes.patch
 
@@ -325,12 +325,11 @@ Patch2003:        kernel-regressions.patch
 # (only warnings, so just remove parts of this patch if conflics)
 Patch2500:     kernel-warnings.patch
 
-# based on https://forgesvn1.novell.com/svn/apparmor/trunk/kernel-patches/2.6.27 rev 1303
-# repatched and adapted for vserver/grsec changes in vfs API, experimental
+# git://kernel.ubuntu.com/jj/apparmor-karmic-tree.git
+# git diff 0c9f19b4dd23620fb32116922b0d93e8aca6c911..HEAD
 Patch5000:     kernel-apparmor.patch
 # with grsec_full version
 Patch5001:     kernel-apparmor-after-grsec_full.patch
-Patch5002:     kernel-apparmor-common.patch
 
 # tomoyo based on patch from ccs-patch-1.6.6-20090202 tarball
 Patch6000:     kernel-tomoyo-with-apparmor.patch
@@ -340,9 +339,6 @@ Patch6001:  kernel-tomoyo-without-apparmor.patch
 # based on http://ftp.leg.uct.ac.za/pub/linux/rip/inittmpfs-2.6.14.diff.gz
 Patch7000:     kernel-inittmpfs.patch
 
-# http://lkml.org/lkml/2009/3/26/267
-Patch7001:     kernel-bzip2-lzma.patch
-
 # not ready yet
 Patch9997:     kernel-pax_selinux_hooks.patch
 
@@ -762,10 +758,8 @@ install %{SOURCE5} Makefile.ppclibs
 
 # tuxonice:
 %if %{with tuxonice}
-##ifarch %{ix86} %{x8664} ia64 ppc alpha
 %patch69 -p1
 %patch70 -p1
-##endif
 %endif
 
 # XXX: 2.6.29 - need update
@@ -856,7 +850,8 @@ install %{SOURCE5} Makefile.ppclibs
 %patch85 -p1
 
 # LSI MPT Fusion driver update (by LSI via SUSE folks)
-%patch90 -p1
+# FIXME!
+#%patch90 -p1
 
 # vserver
 %if %{with vserver}
@@ -888,9 +883,6 @@ install %{SOURCE5} Makefile.ppclibs
 %patch7000 -p1
 %endif
 
-# merged into 2.6.30 git :)
-%patch7001 -p1
-
 # grsecurity & pax stuff
 #
 %if %{with pax_full}
@@ -936,10 +928,8 @@ install %{SOURCE5} Makefile.ppclibs
 %if %{with apparmor}
 %if %{with grsec_full} || %{with pax_full}
 %patch5001 -p1
-%patch5002 -p1
 %else
 %patch5000 -p1
-%patch5002 -p1
 %endif
 %endif
 
This page took 4.519728 seconds and 4 git commands to generate.