linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / char / rio / rioctrl.c
index 052e812..fcf18a0 100644 (file)
@@ -51,12 +51,15 @@ static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c      1.3";
 
 #include "linux_compat.h"
 #include "rio_linux.h"
+#include "typdef.h"
 #include "pkt.h"
 #include "daemon.h"
 #include "rio.h"
 #include "riospace.h"
+#include "top.h"
 #include "cmdpkt.h"
 #include "map.h"
+#include "riotypes.h"
 #include "rup.h"
 #include "port.h"
 #include "riodrvr.h"
@@ -69,10 +72,12 @@ static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c      1.3";
 #include "unixrup.h"
 #include "board.h"
 #include "host.h"
+#include "error.h"
 #include "phb.h"
 #include "link.h"
 #include "cmdblk.h"
 #include "route.h"
+#include "control.h"
 #include "cirrus.h"
 #include "rioioctl.h"
 
@@ -80,7 +85,7 @@ static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c        1.3";
 static struct LpbReq LpbReq;
 static struct RupReq RupReq;
 static struct PortReq PortReq;
-static struct HostReq HostReq; /* oh really?  global?  and no locking? */
+static struct HostReq HostReq;
 static struct HostDpRam HostDpRam;
 static struct DebugCtrl DebugCtrl;
 static struct Map MapEnt;
@@ -126,19 +131,36 @@ static int
 
 #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
 
-static int copy_from_io(void __user *to, void __iomem *from, size_t size)
+int copyin(int arg, caddr_t dp, int siz)
 {
-       void *buf = kmalloc(size, GFP_KERNEL);
-       int res = -ENOMEM;
-       if (buf) {
-               rio_memcpy_fromio(buf, from, size);
-               res = copy_to_user(to, buf, size);
-               kfree(buf);
-       }
-       return res;
+       int rv;
+
+       rio_dprintk(RIO_DEBUG_CTRL, "Copying %d bytes from user %p to %p.\n", siz, (void *) arg, dp);
+       rv = copy_from_user(dp, (void *) arg, siz);
+       if (rv)
+               return COPYFAIL;
+       else
+               return rv;
+}
+
+static int copyout(caddr_t dp, int arg, int siz)
+{
+       int rv;
+
+       rio_dprintk(RIO_DEBUG_CTRL, "Copying %d bytes to user %p from %p.\n", siz, (void *) arg, dp);
+       rv = copy_to_user((void *) arg, dp, siz);
+       if (rv)
+               return COPYFAIL;
+       else
+               return rv;
 }
 
-int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su)
+int riocontrol(p, dev, cmd, arg, su)
+struct rio_info *p;
+dev_t dev;
+int cmd;
+caddr_t arg;
+int su;
 {
        uint Host;              /* leave me unsigned! */
        uint port;              /* and me! */
@@ -146,10 +168,9 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
        ushort loop;
        int Entry;
        struct Port *PortP;
-       struct PKT __iomem *PacketP;
+       PKT *PacketP;
        int retval = 0;
        unsigned long flags;
-       void __user *argp = (void __user *)arg;
 
        func_enter();
 
@@ -157,7 +178,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
        Host = 0;
        PortP = NULL;
 
-       rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, argp);
+       rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: 0x%x\n", cmd, (int) arg);
 
        switch (cmd) {
                /*
@@ -168,49 +189,105 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                 ** otherwise just the specified host card will be changed.
                 */
        case RIO_SET_TIMER:
-               rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", arg);
+               rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %dms\n", (uint) arg);
                {
                        int host, value;
-                       host = (arg >> 16) & 0x0000FFFF;
-                       value = arg & 0x0000ffff;
+                       host = (uint) arg >> 16;
+                       value = (uint) arg & 0x0000ffff;
                        if (host == -1) {
                                for (host = 0; host < p->RIONumHosts; host++) {
                                        if (p->RIOHosts[host].Flags == RC_RUNNING) {
-                                               writew(value, &p->RIOHosts[host].ParmMapP->timer);
+                                               WWORD(p->RIOHosts[host].ParmMapP->timer, value);
                                        }
                                }
                        } else if (host >= p->RIONumHosts) {
                                return -EINVAL;
                        } else {
                                if (p->RIOHosts[host].Flags == RC_RUNNING) {
-                                       writew(value, &p->RIOHosts[host].ParmMapP->timer);
+                                       WWORD(p->RIOHosts[host].ParmMapP->timer, value);
                                }
                        }
                }
                return 0;
 
+       case RIO_IDENTIFY_DRIVER:
+               /*
+                ** 15.10.1998 ARG - ESIL 0760 part fix
+                ** Added driver ident string output.
+                **
+                #ifndef __THIS_RELEASE__
+                #warning Driver Version string not defined !
+                #endif
+                cprintf("%s %s %s %s\n",
+                RIO_DRV_STR,
+                __THIS_RELEASE__,
+                __DATE__, __TIME__ );
+
+                return 0;
+
+                case RIO_DISPLAY_HOST_CFG:
+                **
+                ** 15.10.1998 ARG - ESIL 0760 part fix
+                ** Added driver host card ident string output.
+                **
+                ** Note that the only types currently supported
+                ** are ISA and PCI. Also this driver does not
+                ** (yet) distinguish between the Old PCI card
+                ** and the Jet PCI card. In fact I think this
+                ** driver only supports JET PCI !
+                **
+
+                for (Host = 0; Host < p->RIONumHosts; Host++)
+                {
+                HostP = &(p->RIOHosts[Host]);
+
+                switch ( HostP->Type )
+                {
+                case RIO_AT :
+                strcpy( host_type, RIO_AT_HOST_STR );
+                break;
+
+                case RIO_PCI :
+                strcpy( host_type, RIO_PCI_HOST_STR );
+                break;
+
+                default :
+                strcpy( host_type, "Unknown" );
+                break;
+                }
+
+                cprintf(
+                "RIO Host %d - Type:%s Addr:%X IRQ:%d\n",
+                Host, host_type,
+                (uint)HostP->PaddrP,
+                (int)HostP->Ivec - 32  );
+                }
+                return 0;
+                **
+                */
+
        case RIO_FOAD_RTA:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
-               return RIOCommandRta(p, arg, RIOFoadRta);
+               return RIOCommandRta(p, (uint) arg, RIOFoadRta);
 
        case RIO_ZOMBIE_RTA:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
-               return RIOCommandRta(p, arg, RIOZombieRta);
+               return RIOCommandRta(p, (uint) arg, RIOZombieRta);
 
        case RIO_IDENTIFY_RTA:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
-               return RIOIdentifyRta(p, argp);
+               return RIOIdentifyRta(p, arg);
 
        case RIO_KILL_NEIGHBOUR:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
-               return RIOKillNeighbour(p, argp);
+               return RIOKillNeighbour(p, arg);
 
        case SPECIAL_RUP_CMD:
                {
                        struct CmdBlk *CmdBlkP;
 
                        rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
-                       if (copy_from_user(&SpecialRupCmd, argp, sizeof(SpecialRupCmd))) {
+                       if (copyin((int) arg, (caddr_t) & SpecialRupCmd, sizeof(SpecialRupCmd)) == COPYFAIL) {
                                rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
                                p->RIOError.Error = COPYIN_FAILED;
                                return -EFAULT;
@@ -225,7 +302,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                                SpecialRupCmd.Host = 0;
                        rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
                        if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
-                               printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
+                               cprintf("FAILED TO QUEUE SPECIAL RUP COMMAND\n");
                        }
                        return 0;
                }
@@ -247,7 +324,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                if ((retval = RIOApel(p)) != 0)
                        return retval;
 
-               if (copy_to_user(argp, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
+               if (copyout((caddr_t) p->RIOConnectTable, (int) arg, TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -292,7 +369,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copy_from_user(&p->RIOConnectTable[0], argp, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
+               if (copyin((int) arg, (caddr_t) & p->RIOConnectTable[0], TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -338,7 +415,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copy_to_user(argp, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
+               if (copyout((caddr_t) p->RIOBindTab, (int) arg, (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -357,7 +434,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copy_from_user(&p->RIOBindTab[0], argp, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
+               if (copyin((int) arg, (caddr_t) & p->RIOBindTab[0], (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -381,12 +458,12 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
                                if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
                                        EmptySlot = Entry;
-                               else if (p->RIOBindTab[Entry] == arg) {
+                               else if (p->RIOBindTab[Entry] == (int) arg) {
                                        /*
                                         ** Already exists - delete
                                         */
                                        p->RIOBindTab[Entry] = 0L;
-                                       rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", arg);
+                                       rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %x from p->RIOBindTab\n", (int) arg);
                                        return 0;
                                }
                        }
@@ -394,10 +471,10 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                         ** Dosen't exist - add
                         */
                        if (EmptySlot != -1) {
-                               p->RIOBindTab[EmptySlot] = arg;
-                               rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", arg);
+                               p->RIOBindTab[EmptySlot] = (int) arg;
+                               rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %x to p->RIOBindTab\n", (int) arg);
                        } else {
-                               rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", arg);
+                               rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %x not added\n", (int) arg);
                                return -ENOMEM;
                        }
                        return 0;
@@ -405,7 +482,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_RESUME:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
-               port = arg;
+               port = (uint) arg;
                if ((port < 0) || (port > 511)) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
                        p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
@@ -441,7 +518,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
+               if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
+                   == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -455,7 +533,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
+               if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
+                   == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -469,7 +548,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
+               if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
+                   == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -477,14 +557,30 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                return RIODeleteRta(p, &MapEnt);
 
        case RIO_QUICK_CHECK:
-               if (copy_to_user(argp, &p->RIORtaDisCons, sizeof(unsigned int))) {
+               /*
+                ** 09.12.1998 ARG - ESIL 0776 part fix
+                ** A customer was using this to get the RTAs
+                ** connect/disconnect status.
+                ** RIOConCon() had been botched use RIOHalted
+                ** to keep track of RTA connections and
+                ** disconnections. That has been changed and
+                ** RIORtaDisCons in the rio_info struct now
+                ** does the job. So we need to return the value
+                ** of RIORtaCons instead of RIOHalted.
+                **
+                if (copyout((caddr_t)&p->RIOHalted,(int)arg,
+                sizeof(uint))==COPYFAIL) {
+                **
+                */
+
+               if (copyout((caddr_t) & p->RIORtaDisCons, (int) arg, sizeof(uint)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return 0;
 
        case RIO_LAST_ERROR:
-               if (copy_to_user(argp, &p->RIOError, sizeof(struct Error)))
+               if (copyout((caddr_t) & p->RIOError, (int) arg, sizeof(struct Error)) == COPYFAIL)
                        return -EFAULT;
                return 0;
 
@@ -493,7 +589,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                return -EINVAL;
 
        case RIO_GET_MODTYPE:
-               if (copy_from_user(&port, argp, sizeof(unsigned int))) {
+               if (copyin((int) arg, (caddr_t) & port, sizeof(uint)) == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -513,11 +609,36 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                 ** Return module type of port
                 */
                port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
-               if (copy_to_user(argp, &port, sizeof(unsigned int))) {
+               if (copyout((caddr_t) & port, (int) arg, sizeof(uint)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return (0);
+               /*
+                ** 02.03.1999 ARG - ESIL 0820 fix
+                ** We are no longer using "Boot Mode", so these ioctls
+                ** are not required :
+                **
+                case RIO_GET_BOOT_MODE :
+                rio_dprint(RIO_DEBUG_CTRL, ("Get boot mode - %x\n", p->RIOBootMode));
+                **
+                ** Return boot state of system - BOOT_ALL, BOOT_OWN or BOOT_NONE
+                **
+                if (copyout((caddr_t)&p->RIOBootMode, (int)arg,
+                sizeof(p->RIOBootMode)) == COPYFAIL) {
+                p->RIOError.Error = COPYOUT_FAILED;
+                return -EFAULT;
+                }
+                return(0);
+
+                case RIO_SET_BOOT_MODE :
+                p->RIOBootMode = (uint) arg;
+                rio_dprint(RIO_DEBUG_CTRL, ("Set boot mode to 0x%x\n", p->RIOBootMode));
+                return(0);
+                **
+                ** End ESIL 0820 fix
+                */
+
        case RIO_BLOCK_OPENS:
                rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
                for (Entry = 0; Entry < RIO_PORTS; Entry++) {
@@ -529,7 +650,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_SETUP_PORTS:
                rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
-               if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
+               if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup))
+                   == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
                        return -EFAULT;
@@ -545,7 +667,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        return -EINVAL;
                }
                if (!p->RIOPortp) {
-                       printk(KERN_ERR "rio: No p->RIOPortp array!\n");
+                       cprintf("No p->RIOPortp array!\n");
                        rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
                        return -EIO;
                }
@@ -559,7 +681,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_GET_PORT_SETUP:
                rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
-               if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
+               if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup))
+                   == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -575,12 +698,13 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                PortSetup.Store = p->RIOPortp[port]->Store;
                PortSetup.Lock = p->RIOPortp[port]->Lock;
                PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
-               memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN);
-               memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN);
+               bcopy(p->RIOPortp[port]->Xprint.XpOn, PortSetup.XpOn, MAX_XP_CTRL_LEN);
+               bcopy(p->RIOPortp[port]->Xprint.XpOff, PortSetup.XpOff, MAX_XP_CTRL_LEN);
                PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
                PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
 
-               if (copy_to_user(argp, &PortSetup, sizeof(PortSetup))) {
+               if (copyout((caddr_t) & PortSetup, (int) arg, sizeof(PortSetup))
+                   == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
@@ -588,7 +712,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_GET_PORT_PARAMS:
                rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
-               if (copy_from_user(&PortParams, argp, sizeof(struct PortParams))) {
+               if (copyin((int) arg, (caddr_t) & PortParams, sizeof(struct PortParams)) == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -601,7 +725,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                PortParams.State = PortP->State;
                rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
 
-               if (copy_to_user(argp, &PortParams, sizeof(struct PortParams))) {
+               if (copyout((caddr_t) & PortParams, (int) arg, sizeof(struct PortParams)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
@@ -609,7 +733,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_GET_PORT_TTY:
                rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
-               if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
+               if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty))
+                   == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -620,14 +745,14 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
                rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
                PortP = (p->RIOPortp[PortTty.port]);
-               if (copy_to_user(argp, &PortTty, sizeof(struct PortTty))) {
+               if (copyout((caddr_t) & PortTty, (int) arg, sizeof(struct PortTty)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return retval;
 
        case RIO_SET_PORT_TTY:
-               if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
+               if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty)) == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -642,7 +767,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_SET_PORT_PARAMS:
                rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
-               if (copy_from_user(&PortParams, argp, sizeof(PortParams))) {
+               if (copyin((int) arg, (caddr_t) & PortParams, sizeof(PortParams))
+                   == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -658,7 +784,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_GET_PORT_STATS:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
-               if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
+               if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -673,14 +799,14 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                portStats.opens = PortP->opens;
                portStats.closes = PortP->closes;
                portStats.ioctls = PortP->ioctls;
-               if (copy_to_user(argp, &portStats, sizeof(struct portStats))) {
+               if (copyout((caddr_t) & portStats, (int) arg, sizeof(struct portStats)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return retval;
 
        case RIO_RESET_PORT_STATS:
-               port = arg;
+               port = (uint) arg;
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
                if (port >= RIO_PORTS) {
                        p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
@@ -698,7 +824,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_GATHER_PORT_STATS:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
-               if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
+               if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -714,7 +840,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_READ_CONFIG:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
-               if (copy_to_user(argp, &p->RIOConf, sizeof(struct Conf))) {
+               if (copyout((caddr_t) & p->RIOConf, (int) arg, sizeof(struct Conf)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
@@ -726,7 +852,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copy_from_user(&p->RIOConf, argp, sizeof(struct Conf))) {
+               if (copyin((int) arg, (caddr_t) & p->RIOConf, sizeof(struct Conf))
+                   == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -735,7 +862,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                 */
                for (Host = 0; Host < p->RIONumHosts; Host++)
                        if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
-                               writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
+                               WWORD(p->RIOHosts[Host].ParmMapP->timer, p->RIOConf.Timer);
                return retval;
 
        case RIO_START_POLLER:
@@ -754,7 +881,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
        case RIO_SETDEBUG:
        case RIO_GETDEBUG:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
-               if (copy_from_user(&DebugCtrl, argp, sizeof(DebugCtrl))) {
+               if (copyin((int) arg, (caddr_t) & DebugCtrl, sizeof(DebugCtrl))
+                   == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -771,7 +899,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                                rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
                                DebugCtrl.Debug = p->rio_debug;
                                DebugCtrl.Wait = p->RIODebugWait;
-                               if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
+                               if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) {
                                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
                                        p->RIOError.Error = COPYOUT_FAILED;
                                        return -EFAULT;
@@ -793,7 +921,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                } else {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
                        DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
-                       if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
+                       if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) {
                                rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
                                p->RIOError.Error = COPYOUT_FAILED;
                                return -EFAULT;
@@ -808,20 +936,43 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                 ** textual null terminated string.
                 */
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
-               if (copy_to_user(argp, RIOVersid(), sizeof(struct rioVersion))) {
+               if (copyout((caddr_t) RIOVersid(), (int) arg, sizeof(struct rioVersion)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return retval;
 
+               /*
+                ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+                ** !! commented out previous 'RIO_VERSID' functionality !!
+                ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+                **
+                case RIO_VERSID:
+                **
+                ** Enquire about the release and version.
+                ** We return MAX_VERSION_LEN bytes, being a textual null
+                ** terminated string.
+                **
+                rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID\n"));
+                if (copyout((caddr_t)RIOVersid(),
+                (int)arg, MAX_VERSION_LEN ) == COPYFAIL ) {
+                rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID: Bad copy to user space\n",Host));
+                p->RIOError.Error = COPYOUT_FAILED;
+                return -EFAULT;
+                }
+                return retval;
+                **
+                ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+                */
+
        case RIO_NUM_HOSTS:
                /*
                 ** Enquire as to the number of hosts located
                 ** at init time.
                 */
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
-               if (copy_to_user(argp, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
+               if (copyout((caddr_t) & p->RIONumHosts, (int) arg, sizeof(p->RIONumHosts)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -832,7 +983,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                /*
                 ** Kill host. This may not be in the final version...
                 */
-               rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", arg);
+               rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %d\n", (int) arg);
                if (!su) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
                        p->RIOError.Error = NOT_SUPER_USER;
@@ -843,7 +994,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
                for (Host = 0; Host < p->RIONumHosts; Host++) {
                        (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
-                       memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
+                       bzero((caddr_t) & p->RIOHosts[Host].Flags, ((int) &p->RIOHosts[Host].____end_marker____) - ((int) &p->RIOHosts[Host].Flags));
                        p->RIOHosts[Host].Flags = RC_WAITING;
                }
                RIOFoadWakeup(p);
@@ -866,7 +1017,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copy_from_user(&DownLoad, argp, sizeof(DownLoad))) {
+               if (copyin((int) arg, (caddr_t) & DownLoad, sizeof(DownLoad)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -894,9 +1045,9 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_PARMS:
                {
-                       unsigned int host;
+                       uint host;
 
-                       if (copy_from_user(&host, argp, sizeof(host))) {
+                       if (copyin((int) arg, (caddr_t) & host, sizeof(host)) == COPYFAIL) {
                                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
                                p->RIOError.Error = COPYIN_FAILED;
                                return -EFAULT;
@@ -905,7 +1056,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                         ** Fetch the parmmap
                         */
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
-                       if (copy_from_io(argp, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
+                       if (copyout((caddr_t) p->RIOHosts[host].ParmMapP, (int) arg, sizeof(PARM_MAP)) == COPYFAIL) {
                                p->RIOError.Error = COPYOUT_FAILED;
                                rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
                                return -EFAULT;
@@ -915,7 +1066,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_HOST_REQ:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
-               if (copy_from_user(&HostReq, argp, sizeof(HostReq))) {
+               if (copyin((int) arg, (caddr_t) & HostReq, sizeof(HostReq)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -927,7 +1078,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                }
                rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
 
-               if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
+               if (copyout((caddr_t) & p->RIOHosts[HostReq.HostNum], (int) HostReq.HostP, sizeof(struct Host)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
                        return -EFAULT;
@@ -936,7 +1087,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_HOST_DPRAM:
                rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
-               if (copy_from_user(&HostDpRam, argp, sizeof(HostDpRam))) {
+               if (copyin((int) arg, (caddr_t) & HostDpRam, sizeof(HostDpRam)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -953,13 +1104,13 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        /* It's hardware like this that really gets on my tits. */
                        static unsigned char copy[sizeof(struct DpRam)];
                        for (off = 0; off < sizeof(struct DpRam); off++)
-                               copy[off] = readb(p->RIOHosts[HostDpRam.HostNum].Caddr + off);
-                       if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
+                               copy[off] = p->RIOHosts[HostDpRam.HostNum].Caddr[off];
+                       if (copyout((caddr_t) copy, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) {
                                p->RIOError.Error = COPYOUT_FAILED;
                                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
                                return -EFAULT;
                        }
-               } else if (copy_from_io(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
+               } else if (copyout((caddr_t) p->RIOHosts[HostDpRam.HostNum].Caddr, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
                        return -EFAULT;
@@ -968,13 +1119,13 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_SET_BUSY:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
-               if (arg > 511) {
-                       rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", arg);
+               if ((int) arg < 0 || (int) arg > 511) {
+                       rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %d\n", (int) arg);
                        p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
                        return -EINVAL;
                }
                rio_spin_lock_irqsave(&PortP->portSem, flags);
-               p->RIOPortp[arg]->State |= RIO_BUSY;
+               p->RIOPortp[(int) arg]->State |= RIO_BUSY;
                rio_spin_unlock_irqrestore(&PortP->portSem, flags);
                return retval;
 
@@ -984,7 +1135,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                 ** (probably for debug reasons)
                 */
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
-               if (copy_from_user(&PortReq, argp, sizeof(PortReq))) {
+               if (copyin((int) arg, (caddr_t) & PortReq, sizeof(PortReq)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -996,7 +1147,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        return -ENXIO;
                }
                rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
-               if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
+               if (copyout((caddr_t) p->RIOPortp[PortReq.SysPort], (int) PortReq.PortP, sizeof(struct Port)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
                        return -EFAULT;
@@ -1009,7 +1160,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                 ** (probably for debug reasons)
                 */
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
-               if (copy_from_user(&RupReq, argp, sizeof(RupReq))) {
+               if (copyin((int) arg, (caddr_t) & RupReq, sizeof(RupReq)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -1033,7 +1184,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                }
                rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
 
-               if (copy_from_io(RupReq.RupP, HostP->UnixRups[RupReq.RupNum].RupP, sizeof(struct RUP))) {
+               if (copyout((caddr_t) HostP->UnixRups[RupReq.RupNum].RupP, (int) RupReq.RupP, sizeof(struct RUP)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
                        return -EFAULT;
@@ -1046,7 +1197,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                 ** (probably for debug reasons)
                 */
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
-               if (copy_from_user(&LpbReq, argp, sizeof(LpbReq))) {
+               if (copyin((int) arg, (caddr_t) & LpbReq, sizeof(LpbReq)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -1070,7 +1221,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                }
                rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
 
-               if (copy_from_io(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
+               if (copyout((caddr_t) & HostP->LinkStrP[LpbReq.Link], (int) LpbReq.LpbP, sizeof(struct LPB)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -1101,13 +1252,12 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        p->RIOError.Error = SIGNALS_ALREADY_SET;
                        return -EBUSY;
                }
-               /* FIXME: PID tracking */
-               p->RIOSignalProcess = current->pid;
+               p->RIOSignalProcess = getpid();
                p->RIOPrintDisabled = DONT_PRINT;
                return retval;
 
        case RIO_SIGNALS_OFF:
-               if (p->RIOSignalProcess != current->pid) {
+               if (p->RIOSignalProcess != getpid()) {
                        p->RIOError.Error = NOT_RECEIVING_PROCESS;
                        return -EPERM;
                }
@@ -1144,7 +1294,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
        case RIO_MAP_B110_TO_110:
        case RIO_MAP_B110_TO_115200:
                rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
-               port = arg;
+               port = (uint) arg;
                if (port < 0 || port > 511) {
                        rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
                        p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
@@ -1174,7 +1324,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 
        case RIO_SEND_PACKET:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
-               if (copy_from_user(&SendPack, argp, sizeof(SendPack))) {
+               if (copyin((int) arg, (caddr_t) & SendPack, sizeof(SendPack)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -1194,9 +1344,9 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                }
 
                for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
-                       writeb(SendPack.Data[loop], &PacketP->data[loop]);
+                       WBYTE(PacketP->data[loop], SendPack.Data[loop]);
 
-               writeb(SendPack.Len, &PacketP->len);
+               WBYTE(PacketP->len, SendPack.Len);
 
                add_transmit(PortP);
                /*
@@ -1218,7 +1368,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                return su ? 0 : -EPERM;
 
        case RIO_WHAT_MESG:
-               if (copy_to_user(argp, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
+               if (copyout((caddr_t) & p->RIONoMessage, (int) arg, sizeof(p->RIONoMessage)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -1226,7 +1376,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                return 0;
 
        case RIO_MEM_DUMP:
-               if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
+               if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -1256,7 +1406,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        PortP->State |= RIO_BUSY;
 
                rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-               if (copy_to_user(argp, p->RIOMemDump, MEMDUMP_SIZE)) {
+               if (copyout((caddr_t) p->RIOMemDump, (int) arg, MEMDUMP_SIZE) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -1264,30 +1414,30 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                return 0;
 
        case RIO_TICK:
-               if (arg >= p->RIONumHosts)
+               if ((int) arg < 0 || (int) arg >= p->RIONumHosts)
                        return -EINVAL;
-               rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", arg);
-               writeb(0xFF, &p->RIOHosts[arg].SetInt);
+               rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %d\n", (int) arg);
+               WBYTE(p->RIOHosts[(int) arg].SetInt, 0xff);
                return 0;
 
        case RIO_TOCK:
-               if (arg >= p->RIONumHosts)
+               if ((int) arg < 0 || (int) arg >= p->RIONumHosts)
                        return -EINVAL;
-               rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", arg);
-               writeb(0xFF, &p->RIOHosts[arg].ResetInt);
+               rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %d\n", (int) arg);
+               WBYTE((p->RIOHosts[(int) arg].ResetInt), 0xff);
                return 0;
 
        case RIO_READ_CHECK:
                /* Check reads for pkts with data[0] the same */
                p->RIOReadCheck = !p->RIOReadCheck;
-               if (copy_to_user(argp, &p->RIOReadCheck, sizeof(unsigned int))) {
+               if (copyout((caddr_t) & p->RIOReadCheck, (int) arg, sizeof(uint)) == COPYFAIL) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return 0;
 
        case RIO_READ_REGISTER:
-               if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
+               if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -1322,7 +1472,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                        PortP->State |= RIO_BUSY;
 
                rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-               if (copy_to_user(argp, &p->CdRegister, sizeof(unsigned int))) {
+               if (copyout((caddr_t) & p->CdRegister, (int) arg, sizeof(uint)) == COPYFAIL) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -1335,22 +1485,21 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                 */
        case RIO_MAKE_DEV:
                {
-                       unsigned int port = arg & RIO_MODEM_MASK;
-                       unsigned int ret;
+                       uint port = (uint) arg & RIO_MODEM_MASK;
 
-                       switch (arg & RIO_DEV_MASK) {
+                       switch ((uint) arg & RIO_DEV_MASK) {
                        case RIO_DEV_DIRECT:
-                               ret = drv_makedev(MAJOR(dev), port);
-                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
-                               return ret;
+                               arg = (caddr_t) drv_makedev(MAJOR(dev), port);
+                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, (int) arg);
+                               return (int) arg;
                        case RIO_DEV_MODEM:
-                               ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
-                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
-                               return ret;
+                               arg = (caddr_t) drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
+                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, (int) arg);
+                               return (int) arg;
                        case RIO_DEV_XPRINT:
-                               ret = drv_makedev(MAJOR(dev), port);
-                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
-                               return ret;
+                               arg = (caddr_t) drv_makedev(MAJOR(dev), port);
+                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, (int) arg);
+                               return (int) arg;
                        }
                        rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
                        return -EINVAL;
@@ -1364,19 +1513,18 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
                {
                        dev_t dv;
                        int mino;
-                       unsigned long ret;
 
-                       dv = (dev_t) (arg);
+                       dv = (dev_t) ((int) arg);
                        mino = RIO_UNMODEM(dv);
 
                        if (RIO_ISMODEM(dv)) {
                                rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
-                               ret = mino | RIO_DEV_MODEM;
+                               arg = (caddr_t) (mino | RIO_DEV_MODEM);
                        } else {
                                rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
-                               ret = mino | RIO_DEV_DIRECT;
+                               arg = (caddr_t) (mino | RIO_DEV_DIRECT);
                        }
-                       return ret;
+                       return (int) arg;
                }
        }
        rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
@@ -1389,7 +1537,10 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
 /*
 ** Pre-emptive commands go on RUPs and are only one byte long.
 */
-int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
+int RIOPreemptiveCmd(p, PortP, Cmd)
+struct rio_info *p;
+struct Port *PortP;
+uchar Cmd;
 {
        struct CmdBlk *CmdBlkP;
        struct PktCmd_M *PktCmdP;
@@ -1402,17 +1553,14 @@ int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
                return RIO_FAIL;
        }
 
-       if ((PortP->InUse == (typeof(PortP->InUse))-1) ||
-                       !(CmdBlkP = RIOGetCmdBlk())) {
-               rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block "
-                       "for command %d on port %d\n", Cmd, PortP->PortNum);
+       if (((int) ((char) PortP->InUse) == -1) || !(CmdBlkP = RIOGetCmdBlk())) {
+               rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block for command %d on port %d\n", Cmd, PortP->PortNum);
                return RIO_FAIL;
        }
 
-       rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n",
-                       CmdBlkP, PortP->InUse);
+       rio_dprintk(RIO_DEBUG_CTRL, "Command blk 0x%x - InUse now %d\n", (int) CmdBlkP, PortP->InUse);
 
-       PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
+       PktCmdP = (struct PktCmd_M *) &CmdBlkP->Packet.data[0];
 
        CmdBlkP->Packet.src_unit = 0;
        if (PortP->SecondBlock)
@@ -1424,7 +1572,7 @@ int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
        CmdBlkP->Packet.dest_port = COMMAND_RUP;
        CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
        CmdBlkP->PostFuncP = RIOUnUse;
-       CmdBlkP->PostArg = (unsigned long) PortP;
+       CmdBlkP->PostArg = (int) PortP;
        PktCmdP->Command = Cmd;
        port = PortP->HostPort % (ushort) PORTS_PER_RTA;
        /*
@@ -1436,46 +1584,38 @@ int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
 
        switch (Cmd) {
        case MEMDUMP:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p "
-                               "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk 0x%x (addr 0x%x)\n", (int) CmdBlkP, (int) SubCmd.Addr);
                PktCmdP->SubCommand = MEMDUMP;
                PktCmdP->SubAddr = SubCmd.Addr;
                break;
        case FCLOSE:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n",
-                               CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk 0x%x\n", (int) CmdBlkP);
                break;
        case READ_REGISTER:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) "
-                               "command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk 0x%x\n", (int) SubCmd.Addr, (int) CmdBlkP);
                PktCmdP->SubCommand = READ_REGISTER;
                PktCmdP->SubAddr = SubCmd.Addr;
                break;
        case RESUME:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n",
-                               CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk 0x%x\n", (int) CmdBlkP);
                break;
        case RFLUSH:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n",
-                               CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk 0x%x\n", (int) CmdBlkP);
                CmdBlkP->PostFuncP = RIORFlushEnable;
                break;
        case SUSPEND:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n",
-                               CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk 0x%x\n", (int) CmdBlkP);
                break;
 
        case MGET:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n",
-                               CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk 0x%x\n", (int) CmdBlkP);
                break;
 
        case MSET:
        case MBIC:
        case MBIS:
                CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command "
-                               "blk %p\n", CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk 0x%x\n", (int) CmdBlkP);
                break;
 
        case WFLUSH:
@@ -1484,14 +1624,12 @@ int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
                 ** allowed then we should not bother sending any more to the
                 ** RTA.
                 */
-               if (PortP->WflushFlag == (typeof(PortP->WflushFlag))-1) {
-                       rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, "
-                                       "WflushFlag about to wrap!");
+               if ((int) ((char) PortP->WflushFlag) == (int) -1) {
+                       rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, WflushFlag about to wrap!");
                        RIOFreeCmdBlk(CmdBlkP);
                        return (RIO_FAIL);
                } else {
-                       rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command "
-                                       "blk %p\n", CmdBlkP);
+                       rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command blk 0x%x\n", (int) CmdBlkP);
                        CmdBlkP->PostFuncP = RIOWFlushMark;
                }
                break;