From 3d8f02bd535f005da9fe526a81744cc7999ef0b8 Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Thu, 25 Sep 2003 02:19:59 -0500 Subject: [PATCH] [PATCH] Generalize 32bit emulation support in MPT fusion The mptctl module has had sparc64 32bit emulation support for some time. This patch generalizes it to use the generic compat infrastructure. This makes it work on x86-64 too. I also removed one special case for sparc in the locking that didn't make any sense to me. --- drivers/message/fusion/mptctl.c | 57 ++++++++++----------------------- drivers/message/fusion/mptctl.h | 8 ++--- 2 files changed, 21 insertions(+), 44 deletions(-) diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c index 1be377f87f6ef..1e707d08165e3 100644 --- a/drivers/message/fusion/mptctl.c +++ b/drivers/message/fusion/mptctl.c @@ -207,14 +207,6 @@ mptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock) return -EBUSY; } -#if defined(__sparc__) && defined(__sparc_v9__) /*{*/ - if (!nonblock) { - if (down_interruptible(&mptctl_syscall_sem_ioc[ioc->id])) - rc = -ERESTARTSYS; - } else { - rc = -EPERM; - } -#else if (nonblock) { if (down_trylock(&mptctl_syscall_sem_ioc[ioc->id])) rc = -EAGAIN; @@ -222,7 +214,6 @@ mptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock) if (down_interruptible(&mptctl_syscall_sem_ioc[ioc->id])) rc = -ERESTARTSYS; } -#endif dctlprintk((KERN_INFO MYNAM "::mptctl_syscall_down return %d\n", rc)); return rc; } @@ -2733,28 +2724,19 @@ static struct miscdevice mptctl_miscdev = { /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ -#if defined(__sparc__) && defined(__sparc_v9__) /*{*/ +#ifdef CONFIG_COMPAT -/* The dynamic ioctl32 compat. registry only exists in >2.3.x sparc64 kernels */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0) /*{*/ -extern int register_ioctl32_conversion(unsigned int cmd, - int (*handler)(unsigned int, - unsigned int, - unsigned long, - struct file *)); -int unregister_ioctl32_conversion(unsigned int cmd); -extern asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, - unsigned long arg); +#include /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ -/* sparc32_XXX functions are used to provide a conversion between +/* compat_XXX functions are used to provide a conversion between * pointers and u32's. If the arg does not contain any pointers, then - * a specialized function (sparc32_XXX) is not needed. If the arg + * a specialized function (compat_XXX) is not needed. If the arg * does contain pointer(s), then the specialized function is used * to ensure the structure contents is properly processed by mptctl. */ static int -sparc32_mptfwxfer_ioctl(unsigned int fd, unsigned int cmd, +compat_mptfwxfer_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *filp) { struct mpt_fw_xfer32 kfw32; @@ -2764,7 +2746,7 @@ sparc32_mptfwxfer_ioctl(unsigned int fd, unsigned int cmd, int nonblock = (filp->f_flags & O_NONBLOCK); int ret; - dctlprintk((KERN_INFO MYNAM "::sparc32_mptfwxfer_ioctl() called\n")); + dctlprintk((KERN_INFO MYNAM "::compat_mptfwxfer_ioctl() called\n")); if (copy_from_user(&kfw32, (char *)arg, sizeof(kfw32))) return -EFAULT; @@ -2773,7 +2755,7 @@ sparc32_mptfwxfer_ioctl(unsigned int fd, unsigned int cmd, iocnumX = kfw32.iocnum & 0xFF; if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) || (iocp == NULL)) { - dctlprintk((KERN_ERR MYNAM "::sparc32_mptfwxfer_ioctl @%d - ioc%d not found!\n", + dctlprintk((KERN_ERR MYNAM "::compat_mptfwxfer_ioctl @%d - ioc%d not found!\n", __LINE__, iocnumX)); return -ENODEV; } @@ -2793,7 +2775,7 @@ sparc32_mptfwxfer_ioctl(unsigned int fd, unsigned int cmd, } static int -sparc32_mpt_command(unsigned int fd, unsigned int cmd, +compat_mpt_command(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *filp) { struct mpt_ioctl_command32 karg32; @@ -2804,7 +2786,7 @@ sparc32_mpt_command(unsigned int fd, unsigned int cmd, int nonblock = (filp->f_flags & O_NONBLOCK); int ret; - dctlprintk((KERN_INFO MYNAM "::sparc32_mpt_command() called\n")); + dctlprintk((KERN_INFO MYNAM "::compat_mpt_command() called\n")); if (copy_from_user(&karg32, (char *)arg, sizeof(karg32))) return -EFAULT; @@ -2813,7 +2795,7 @@ sparc32_mpt_command(unsigned int fd, unsigned int cmd, iocnumX = karg32.hdr.iocnum & 0xFF; if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) || (iocp == NULL)) { - dctlprintk((KERN_ERR MYNAM "::sparc32_mpt_command @%d - ioc%d not found!\n", + dctlprintk((KERN_ERR MYNAM "::compat_mpt_command @%d - ioc%d not found!\n", __LINE__, iocnumX)); return -ENODEV; } @@ -2846,8 +2828,7 @@ sparc32_mpt_command(unsigned int fd, unsigned int cmd, return ret; } -#endif /*} linux >= 2.3.x */ -#endif /*} sparc */ +#endif /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ int __init mptctl_init(void) @@ -2893,8 +2874,7 @@ int __init mptctl_init(void) } } -#if defined(__sparc__) && defined(__sparc_v9__) /*{*/ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0) /*{*/ +#ifdef CONFIG_COMPAT err = register_ioctl32_conversion(MPTIOCINFO, NULL); if (++where && err) goto out_fail; err = register_ioctl32_conversion(MPTIOCINFO1, NULL); @@ -2911,17 +2891,16 @@ int __init mptctl_init(void) if (++where && err) goto out_fail; err = register_ioctl32_conversion(MPTHARDRESET, NULL); if (++where && err) goto out_fail; - err = register_ioctl32_conversion(MPTCOMMAND32, sparc32_mpt_command); + err = register_ioctl32_conversion(MPTCOMMAND32, compat_mpt_command); if (++where && err) goto out_fail; err = register_ioctl32_conversion(MPTFWDOWNLOAD32, - sparc32_mptfwxfer_ioctl); + compat_mptfwxfer_ioctl); if (++where && err) goto out_fail; err = register_ioctl32_conversion(HP_GETHOSTINFO, NULL); if (++where && err) goto out_fail; err = register_ioctl32_conversion(HP_GETTARGETINFO, NULL); if (++where && err) goto out_fail; -#endif /*} linux >= 2.3.x */ -#endif /*} sparc */ +#endif /* Register this device */ err = misc_register(&mptctl_miscdev); @@ -2954,8 +2933,7 @@ int __init mptctl_init(void) out_fail: -#if defined(__sparc__) && defined(__sparc_v9__) /*{*/ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0) /*{*/ +#ifdef CONFIG_COMPAT printk(KERN_ERR MYNAM ": ERROR: Failed to register ioctl32_conversion!" " (%d:err=%d)\n", where, err); unregister_ioctl32_conversion(MPTIOCINFO); @@ -2970,8 +2948,7 @@ out_fail: unregister_ioctl32_conversion(MPTFWDOWNLOAD32); unregister_ioctl32_conversion(HP_GETHOSTINFO); unregister_ioctl32_conversion(HP_GETTARGETINFO); -#endif /*} linux >= 2.3.x */ -#endif /*} sparc */ +#endif for (i=0; i