Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** ----------------------------------------------------------------------------- |
| 3 | ** |
| 4 | ** Perle Specialix driver for Linux |
| 5 | ** Ported from existing RIO Driver for SCO sources. |
| 6 | * |
| 7 | * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | ** |
| 23 | ** Module : rioctrl.c |
| 24 | ** SID : 1.3 |
| 25 | ** Last Modified : 11/6/98 10:33:42 |
| 26 | ** Retrieved : 11/6/98 10:33:49 |
| 27 | ** |
| 28 | ** ident @(#)rioctrl.c 1.3 |
| 29 | ** |
| 30 | ** ----------------------------------------------------------------------------- |
| 31 | */ |
| 32 | #ifdef SCCS_LABELS |
| 33 | static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c 1.3"; |
| 34 | #endif |
| 35 | |
| 36 | |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/slab.h> |
| 39 | #include <linux/errno.h> |
| 40 | #include <asm/io.h> |
| 41 | #include <asm/system.h> |
| 42 | #include <asm/string.h> |
| 43 | #include <asm/semaphore.h> |
| 44 | #include <asm/uaccess.h> |
| 45 | |
| 46 | #include <linux/termios.h> |
| 47 | #include <linux/serial.h> |
| 48 | |
| 49 | #include <linux/generic_serial.h> |
| 50 | |
| 51 | |
| 52 | #include "linux_compat.h" |
| 53 | #include "rio_linux.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include "pkt.h" |
| 55 | #include "daemon.h" |
| 56 | #include "rio.h" |
| 57 | #include "riospace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include "cmdpkt.h" |
| 59 | #include "map.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "rup.h" |
| 61 | #include "port.h" |
| 62 | #include "riodrvr.h" |
| 63 | #include "rioinfo.h" |
| 64 | #include "func.h" |
| 65 | #include "errors.h" |
| 66 | #include "pci.h" |
| 67 | |
| 68 | #include "parmmap.h" |
| 69 | #include "unixrup.h" |
| 70 | #include "board.h" |
| 71 | #include "host.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #include "phb.h" |
| 73 | #include "link.h" |
| 74 | #include "cmdblk.h" |
| 75 | #include "route.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #include "cirrus.h" |
| 77 | #include "rioioctl.h" |
| 78 | |
| 79 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 80 | static struct LpbReq LpbReq; |
| 81 | static struct RupReq RupReq; |
| 82 | static struct PortReq PortReq; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 83 | static struct HostReq HostReq; /* oh really? global? and no locking? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | static struct HostDpRam HostDpRam; |
| 85 | static struct DebugCtrl DebugCtrl; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 86 | static struct Map MapEnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | static struct PortSetup PortSetup; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 88 | static struct DownLoad DownLoad; |
| 89 | static struct SendPack SendPack; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* static struct StreamInfo StreamInfo; */ |
| 91 | /* static char modemtable[RIO_PORTS]; */ |
| 92 | static struct SpecialRupCmd SpecialRupCmd; |
| 93 | static struct PortParams PortParams; |
| 94 | static struct portStats portStats; |
| 95 | |
| 96 | static struct SubCmdStruct { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 97 | ushort Host; |
| 98 | ushort Rup; |
| 99 | ushort Port; |
| 100 | ushort Addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } SubCmd; |
| 102 | |
| 103 | struct PortTty { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 104 | uint port; |
| 105 | struct ttystatics Tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 108 | static struct PortTty PortTty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | typedef struct ttystatics TERMIO; |
| 110 | |
| 111 | /* |
| 112 | ** This table is used when the config.rio downloads bin code to the |
| 113 | ** driver. We index the table using the product code, 0-F, and call |
| 114 | ** the function pointed to by the entry, passing the information |
| 115 | ** about the boot. |
| 116 | ** The RIOBootCodeUNKNOWN entry is there to politely tell the calling |
| 117 | ** process to bog off. |
| 118 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 119 | static int |
| 120 | (*RIOBootTable[MAX_PRODUCT]) (struct rio_info *, struct DownLoad *) = { |
| 121 | /* 0 */ RIOBootCodeHOST, |
| 122 | /* Host Card */ |
| 123 | /* 1 */ RIOBootCodeRTA, |
| 124 | /* RTA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff)) |
| 128 | |
Al Viro | 0645819 | 2006-05-27 02:11:12 -0400 | [diff] [blame] | 129 | static int copy_from_io(void __user *to, void __iomem *from, size_t size) |
| 130 | { |
| 131 | void *buf = kmalloc(size, GFP_KERNEL); |
| 132 | int res = -ENOMEM; |
| 133 | if (buf) { |
| 134 | rio_memcpy_fromio(buf, from, size); |
| 135 | res = copy_to_user(to, buf, size); |
| 136 | kfree(buf); |
| 137 | } |
| 138 | return res; |
| 139 | } |
| 140 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 141 | int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 143 | uint Host; /* leave me unsigned! */ |
| 144 | uint port; /* and me! */ |
| 145 | struct Host *HostP; |
| 146 | ushort loop; |
| 147 | int Entry; |
| 148 | struct Port *PortP; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 149 | struct PKT __iomem *PacketP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 150 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | unsigned long flags; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 152 | void __user *argp = (void __user *)arg; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 153 | |
| 154 | func_enter(); |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* Confuse the compiler to think that we've initialized these */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 157 | Host = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | PortP = NULL; |
| 159 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 160 | rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | switch (cmd) { |
| 163 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 164 | ** RIO_SET_TIMER |
| 165 | ** |
| 166 | ** Change the value of the host card interrupt timer. |
| 167 | ** If the host card number is -1 then all host cards are changed |
| 168 | ** otherwise just the specified host card will be changed. |
| 169 | */ |
| 170 | case RIO_SET_TIMER: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 171 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", arg); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 172 | { |
| 173 | int host, value; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 174 | host = (arg >> 16) & 0x0000FFFF; |
| 175 | value = arg & 0x0000ffff; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 176 | if (host == -1) { |
| 177 | for (host = 0; host < p->RIONumHosts; host++) { |
| 178 | if (p->RIOHosts[host].Flags == RC_RUNNING) { |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 179 | writew(value, &p->RIOHosts[host].ParmMapP->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 182 | } else if (host >= p->RIONumHosts) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | return -EINVAL; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 184 | } else { |
| 185 | if (p->RIOHosts[host].Flags == RC_RUNNING) { |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 186 | writew(value, &p->RIOHosts[host].ParmMapP->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 192 | case RIO_FOAD_RTA: |
| 193 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 194 | return RIOCommandRta(p, arg, RIOFoadRta); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 195 | |
| 196 | case RIO_ZOMBIE_RTA: |
| 197 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 198 | return RIOCommandRta(p, arg, RIOZombieRta); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 199 | |
| 200 | case RIO_IDENTIFY_RTA: |
| 201 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 202 | return RIOIdentifyRta(p, argp); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 203 | |
| 204 | case RIO_KILL_NEIGHBOUR: |
| 205 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 206 | return RIOKillNeighbour(p, argp); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 207 | |
| 208 | case SPECIAL_RUP_CMD: |
| 209 | { |
| 210 | struct CmdBlk *CmdBlkP; |
| 211 | |
| 212 | rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 213 | if (copy_from_user(&SpecialRupCmd, argp, sizeof(SpecialRupCmd))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 214 | rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n"); |
| 215 | p->RIOError.Error = COPYIN_FAILED; |
| 216 | return -EFAULT; |
| 217 | } |
| 218 | CmdBlkP = RIOGetCmdBlk(); |
| 219 | if (!CmdBlkP) { |
| 220 | rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n"); |
| 221 | return -ENXIO; |
| 222 | } |
| 223 | CmdBlkP->Packet = SpecialRupCmd.Packet; |
| 224 | if (SpecialRupCmd.Host >= p->RIONumHosts) |
| 225 | SpecialRupCmd.Host = 0; |
| 226 | rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum); |
| 227 | if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) { |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 228 | printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n"); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 229 | } |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | case RIO_DEBUG_MEM: |
Alan Cox | f4caf16 | 2006-01-16 17:27:38 +0000 | [diff] [blame] | 234 | return -EPERM; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 235 | |
| 236 | case RIO_ALL_MODEM: |
| 237 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n"); |
| 238 | p->RIOError.Error = IOCTL_COMMAND_UNKNOWN; |
| 239 | return -EINVAL; |
| 240 | |
| 241 | case RIO_GET_TABLE: |
| 242 | /* |
| 243 | ** Read the routing table from the device driver to user space |
| 244 | */ |
| 245 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n"); |
| 246 | |
| 247 | if ((retval = RIOApel(p)) != 0) |
| 248 | return retval; |
| 249 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 250 | if (copy_to_user(argp, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 251 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n"); |
| 252 | p->RIOError.Error = COPYOUT_FAILED; |
| 253 | return -EFAULT; |
| 254 | } |
| 255 | |
| 256 | { |
| 257 | int entry; |
| 258 | rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n"); |
| 259 | for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) { |
| 260 | if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0)) |
| 261 | continue; |
| 262 | |
| 263 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum); |
| 264 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum); |
| 265 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID); |
| 266 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2); |
| 267 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags); |
| 268 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort); |
| 269 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit); |
| 270 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link); |
| 271 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit); |
| 272 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link); |
| 273 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit); |
| 274 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link); |
| 275 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit); |
| 276 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link); |
| 277 | rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name); |
| 278 | } |
| 279 | rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n"); |
| 280 | } |
| 281 | p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */ |
| 282 | return 0; |
| 283 | |
| 284 | case RIO_PUT_TABLE: |
| 285 | /* |
| 286 | ** Write the routing table to the device driver from user space |
| 287 | */ |
| 288 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n"); |
| 289 | |
| 290 | if (!su) { |
| 291 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n"); |
| 292 | p->RIOError.Error = NOT_SUPER_USER; |
| 293 | return -EPERM; |
| 294 | } |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 295 | if (copy_from_user(&p->RIOConnectTable[0], argp, TOTAL_MAP_ENTRIES * sizeof(struct Map))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 296 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n"); |
| 297 | p->RIOError.Error = COPYIN_FAILED; |
| 298 | return -EFAULT; |
| 299 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | /* |
| 301 | *********************************** |
| 302 | { |
| 303 | int entry; |
| 304 | rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") ); |
| 305 | for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ ) |
| 306 | { |
| 307 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) ); |
| 308 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) ); |
| 309 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) ); |
| 310 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) ); |
| 311 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) ); |
| 312 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) ); |
| 313 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) ); |
| 314 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) ); |
| 315 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) ); |
| 316 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) ); |
| 317 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) ); |
| 318 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) ); |
| 319 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) ); |
| 320 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) ); |
| 321 | rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) ); |
| 322 | } |
| 323 | rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") ); |
| 324 | } |
| 325 | *********************************** |
| 326 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 327 | return RIONewTable(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 329 | case RIO_GET_BINDINGS: |
| 330 | /* |
| 331 | ** Send bindings table, containing unique numbers of RTAs owned |
| 332 | ** by this system to user space |
| 333 | */ |
| 334 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 336 | if (!su) { |
| 337 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n"); |
| 338 | p->RIOError.Error = NOT_SUPER_USER; |
| 339 | return -EPERM; |
| 340 | } |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 341 | if (copy_to_user(argp, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 342 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n"); |
| 343 | p->RIOError.Error = COPYOUT_FAILED; |
| 344 | return -EFAULT; |
| 345 | } |
| 346 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 348 | case RIO_PUT_BINDINGS: |
| 349 | /* |
| 350 | ** Receive a bindings table, containing unique numbers of RTAs owned |
| 351 | ** by this system |
| 352 | */ |
| 353 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n"); |
| 354 | |
| 355 | if (!su) { |
| 356 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n"); |
| 357 | p->RIOError.Error = NOT_SUPER_USER; |
| 358 | return -EPERM; |
| 359 | } |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 360 | if (copy_from_user(&p->RIOBindTab[0], argp, (sizeof(ulong) * MAX_RTA_BINDINGS))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 361 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n"); |
| 362 | p->RIOError.Error = COPYIN_FAILED; |
| 363 | return -EFAULT; |
| 364 | } |
| 365 | return 0; |
| 366 | |
| 367 | case RIO_BIND_RTA: |
| 368 | { |
| 369 | int EmptySlot = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 371 | ** Bind this RTA to host, so that it will be booted by |
| 372 | ** host in 'boot owned RTAs' mode. |
| 373 | */ |
| 374 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 376 | if (!su) { |
| 377 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n"); |
| 378 | p->RIOError.Error = NOT_SUPER_USER; |
| 379 | return -EPERM; |
| 380 | } |
| 381 | for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) { |
| 382 | if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L)) |
| 383 | EmptySlot = Entry; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 384 | else if (p->RIOBindTab[Entry] == arg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 386 | ** Already exists - delete |
| 387 | */ |
| 388 | p->RIOBindTab[Entry] = 0L; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 389 | rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | return 0; |
| 391 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 392 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 394 | ** Dosen't exist - add |
| 395 | */ |
| 396 | if (EmptySlot != -1) { |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 397 | p->RIOBindTab[EmptySlot] = arg; |
| 398 | rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", arg); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 399 | } else { |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 400 | rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", arg); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 401 | return -ENOMEM; |
| 402 | } |
| 403 | return 0; |
| 404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 406 | case RIO_RESUME: |
| 407 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 408 | port = arg; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 409 | if ((port < 0) || (port > 511)) { |
| 410 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port); |
| 411 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | PortP = p->RIOPortp[port]; |
| 415 | if (!PortP->Mapped) { |
| 416 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port); |
| 417 | p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM; |
| 418 | return -EINVAL; |
| 419 | } |
| 420 | if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) { |
| 421 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port); |
| 422 | return -EINVAL; |
| 423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 425 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 426 | if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) { |
| 427 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n"); |
| 428 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 429 | return -EBUSY; |
| 430 | } else { |
| 431 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port); |
| 432 | PortP->State |= RIO_BUSY; |
| 433 | } |
| 434 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 435 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 437 | case RIO_ASSIGN_RTA: |
| 438 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n"); |
| 439 | if (!su) { |
| 440 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n"); |
| 441 | p->RIOError.Error = NOT_SUPER_USER; |
| 442 | return -EPERM; |
| 443 | } |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 444 | if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 445 | rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n"); |
| 446 | p->RIOError.Error = COPYIN_FAILED; |
| 447 | return -EFAULT; |
| 448 | } |
| 449 | return RIOAssignRta(p, &MapEnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 451 | case RIO_CHANGE_NAME: |
| 452 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n"); |
| 453 | if (!su) { |
| 454 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n"); |
| 455 | p->RIOError.Error = NOT_SUPER_USER; |
| 456 | return -EPERM; |
| 457 | } |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 458 | if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 459 | rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n"); |
| 460 | p->RIOError.Error = COPYIN_FAILED; |
| 461 | return -EFAULT; |
| 462 | } |
| 463 | return RIOChangeName(p, &MapEnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 465 | case RIO_DELETE_RTA: |
| 466 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n"); |
| 467 | if (!su) { |
| 468 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n"); |
| 469 | p->RIOError.Error = NOT_SUPER_USER; |
| 470 | return -EPERM; |
| 471 | } |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 472 | if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 473 | rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n"); |
| 474 | p->RIOError.Error = COPYIN_FAILED; |
| 475 | return -EFAULT; |
| 476 | } |
| 477 | return RIODeleteRta(p, &MapEnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 479 | case RIO_QUICK_CHECK: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 480 | if (copy_to_user(argp, &p->RIORtaDisCons, sizeof(unsigned int))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 481 | p->RIOError.Error = COPYOUT_FAILED; |
| 482 | return -EFAULT; |
| 483 | } |
| 484 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 486 | case RIO_LAST_ERROR: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 487 | if (copy_to_user(argp, &p->RIOError, sizeof(struct Error))) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 488 | return -EFAULT; |
| 489 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 491 | case RIO_GET_LOG: |
| 492 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n"); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 493 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 495 | case RIO_GET_MODTYPE: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 496 | if (copy_from_user(&port, argp, sizeof(unsigned int))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 497 | p->RIOError.Error = COPYIN_FAILED; |
| 498 | return -EFAULT; |
| 499 | } |
| 500 | rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port); |
| 501 | if (port < 0 || port > 511) { |
| 502 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port); |
| 503 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 504 | return -EINVAL; |
| 505 | } |
| 506 | PortP = (p->RIOPortp[port]); |
| 507 | if (!PortP->Mapped) { |
| 508 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port); |
| 509 | p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM; |
| 510 | return -EINVAL; |
| 511 | } |
| 512 | /* |
| 513 | ** Return module type of port |
| 514 | */ |
| 515 | port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 516 | if (copy_to_user(argp, &port, sizeof(unsigned int))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 517 | p->RIOError.Error = COPYOUT_FAILED; |
| 518 | return -EFAULT; |
| 519 | } |
| 520 | return (0); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 521 | case RIO_BLOCK_OPENS: |
| 522 | rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n"); |
| 523 | for (Entry = 0; Entry < RIO_PORTS; Entry++) { |
| 524 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 525 | p->RIOPortp[Entry]->WaitUntilBooted = 1; |
| 526 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 527 | } |
| 528 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 530 | case RIO_SETUP_PORTS: |
| 531 | rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 532 | if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 533 | p->RIOError.Error = COPYIN_FAILED; |
| 534 | rio_dprintk(RIO_DEBUG_CTRL, "EFAULT"); |
| 535 | return -EFAULT; |
| 536 | } |
| 537 | if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) { |
| 538 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 539 | rio_dprintk(RIO_DEBUG_CTRL, "ENXIO"); |
| 540 | return -ENXIO; |
| 541 | } |
| 542 | if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) { |
| 543 | p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE; |
| 544 | rio_dprintk(RIO_DEBUG_CTRL, "EINVAL"); |
| 545 | return -EINVAL; |
| 546 | } |
| 547 | if (!p->RIOPortp) { |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 548 | printk(KERN_ERR "rio: No p->RIOPortp array!\n"); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 549 | rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n"); |
| 550 | return -EIO; |
| 551 | } |
| 552 | rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To); |
| 553 | for (loop = PortSetup.From; loop <= PortSetup.To; loop++) { |
| 554 | rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 555 | } |
| 556 | rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop); |
| 557 | rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval); |
| 558 | return retval; |
| 559 | |
| 560 | case RIO_GET_PORT_SETUP: |
| 561 | rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 562 | if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 563 | p->RIOError.Error = COPYIN_FAILED; |
| 564 | return -EFAULT; |
| 565 | } |
| 566 | if (PortSetup.From >= RIO_PORTS) { |
| 567 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 568 | return -ENXIO; |
| 569 | } |
| 570 | |
| 571 | port = PortSetup.To = PortSetup.From; |
| 572 | PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0; |
| 573 | PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0; |
| 574 | PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0; |
| 575 | PortSetup.Store = p->RIOPortp[port]->Store; |
| 576 | PortSetup.Lock = p->RIOPortp[port]->Lock; |
| 577 | PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps; |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 578 | memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN); |
| 579 | memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 580 | PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0'; |
| 581 | PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0'; |
| 582 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 583 | if (copy_to_user(argp, &PortSetup, sizeof(PortSetup))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 584 | p->RIOError.Error = COPYOUT_FAILED; |
| 585 | return -EFAULT; |
| 586 | } |
| 587 | return retval; |
| 588 | |
| 589 | case RIO_GET_PORT_PARAMS: |
| 590 | rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 591 | if (copy_from_user(&PortParams, argp, sizeof(struct PortParams))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 592 | p->RIOError.Error = COPYIN_FAILED; |
| 593 | return -EFAULT; |
| 594 | } |
| 595 | if (PortParams.Port >= RIO_PORTS) { |
| 596 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 597 | return -ENXIO; |
| 598 | } |
| 599 | PortP = (p->RIOPortp[PortParams.Port]); |
| 600 | PortParams.Config = PortP->Config; |
| 601 | PortParams.State = PortP->State; |
| 602 | rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port); |
| 603 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 604 | if (copy_to_user(argp, &PortParams, sizeof(struct PortParams))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 605 | p->RIOError.Error = COPYOUT_FAILED; |
| 606 | return -EFAULT; |
| 607 | } |
| 608 | return retval; |
| 609 | |
| 610 | case RIO_GET_PORT_TTY: |
| 611 | rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 612 | if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 613 | p->RIOError.Error = COPYIN_FAILED; |
| 614 | return -EFAULT; |
| 615 | } |
| 616 | if (PortTty.port >= RIO_PORTS) { |
| 617 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 618 | return -ENXIO; |
| 619 | } |
| 620 | |
| 621 | rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port); |
| 622 | PortP = (p->RIOPortp[PortTty.port]); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 623 | if (copy_to_user(argp, &PortTty, sizeof(struct PortTty))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 624 | p->RIOError.Error = COPYOUT_FAILED; |
| 625 | return -EFAULT; |
| 626 | } |
| 627 | return retval; |
| 628 | |
| 629 | case RIO_SET_PORT_TTY: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 630 | if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 631 | p->RIOError.Error = COPYIN_FAILED; |
| 632 | return -EFAULT; |
| 633 | } |
| 634 | rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port); |
| 635 | if (PortTty.port >= (ushort) RIO_PORTS) { |
| 636 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 637 | return -ENXIO; |
| 638 | } |
| 639 | PortP = (p->RIOPortp[PortTty.port]); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 640 | RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP); |
| 641 | return retval; |
| 642 | |
| 643 | case RIO_SET_PORT_PARAMS: |
| 644 | rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 645 | if (copy_from_user(&PortParams, argp, sizeof(PortParams))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 646 | p->RIOError.Error = COPYIN_FAILED; |
| 647 | return -EFAULT; |
| 648 | } |
| 649 | if (PortParams.Port >= (ushort) RIO_PORTS) { |
| 650 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 651 | return -ENXIO; |
| 652 | } |
| 653 | PortP = (p->RIOPortp[PortParams.Port]); |
| 654 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 655 | PortP->Config = PortParams.Config; |
| 656 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 657 | return retval; |
| 658 | |
| 659 | case RIO_GET_PORT_STATS: |
| 660 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 661 | if (copy_from_user(&portStats, argp, sizeof(struct portStats))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 662 | p->RIOError.Error = COPYIN_FAILED; |
| 663 | return -EFAULT; |
| 664 | } |
Alan Cox | 9d90daf | 2006-10-16 16:28:44 +0100 | [diff] [blame] | 665 | if (portStats.port < 0 || portStats.port >= RIO_PORTS) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 666 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 667 | return -ENXIO; |
| 668 | } |
| 669 | PortP = (p->RIOPortp[portStats.port]); |
| 670 | portStats.gather = PortP->statsGather; |
| 671 | portStats.txchars = PortP->txchars; |
| 672 | portStats.rxchars = PortP->rxchars; |
| 673 | portStats.opens = PortP->opens; |
| 674 | portStats.closes = PortP->closes; |
| 675 | portStats.ioctls = PortP->ioctls; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 676 | if (copy_to_user(argp, &portStats, sizeof(struct portStats))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 677 | p->RIOError.Error = COPYOUT_FAILED; |
| 678 | return -EFAULT; |
| 679 | } |
| 680 | return retval; |
| 681 | |
| 682 | case RIO_RESET_PORT_STATS: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 683 | port = arg; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 684 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n"); |
| 685 | if (port >= RIO_PORTS) { |
| 686 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 687 | return -ENXIO; |
| 688 | } |
| 689 | PortP = (p->RIOPortp[port]); |
| 690 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 691 | PortP->txchars = 0; |
| 692 | PortP->rxchars = 0; |
| 693 | PortP->opens = 0; |
| 694 | PortP->closes = 0; |
| 695 | PortP->ioctls = 0; |
| 696 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 697 | return retval; |
| 698 | |
| 699 | case RIO_GATHER_PORT_STATS: |
| 700 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 701 | if (copy_from_user(&portStats, argp, sizeof(struct portStats))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 702 | p->RIOError.Error = COPYIN_FAILED; |
| 703 | return -EFAULT; |
| 704 | } |
Alan Cox | 9d90daf | 2006-10-16 16:28:44 +0100 | [diff] [blame] | 705 | if (portStats.port < 0 || portStats.port >= RIO_PORTS) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 706 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 707 | return -ENXIO; |
| 708 | } |
| 709 | PortP = (p->RIOPortp[portStats.port]); |
| 710 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 711 | PortP->statsGather = portStats.gather; |
| 712 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 713 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 715 | case RIO_READ_CONFIG: |
| 716 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 717 | if (copy_to_user(argp, &p->RIOConf, sizeof(struct Conf))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 718 | p->RIOError.Error = COPYOUT_FAILED; |
| 719 | return -EFAULT; |
| 720 | } |
| 721 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 723 | case RIO_SET_CONFIG: |
| 724 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n"); |
| 725 | if (!su) { |
| 726 | p->RIOError.Error = NOT_SUPER_USER; |
| 727 | return -EPERM; |
| 728 | } |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 729 | if (copy_from_user(&p->RIOConf, argp, sizeof(struct Conf))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 730 | p->RIOError.Error = COPYIN_FAILED; |
| 731 | return -EFAULT; |
| 732 | } |
| 733 | /* |
| 734 | ** move a few value around |
| 735 | */ |
| 736 | for (Host = 0; Host < p->RIONumHosts; Host++) |
| 737 | if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING) |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 738 | writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 739 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 741 | case RIO_START_POLLER: |
| 742 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n"); |
| 743 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 745 | case RIO_STOP_POLLER: |
| 746 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n"); |
| 747 | if (!su) { |
| 748 | p->RIOError.Error = NOT_SUPER_USER; |
| 749 | return -EPERM; |
| 750 | } |
| 751 | p->RIOPolling = NOT_POLLING; |
| 752 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 754 | case RIO_SETDEBUG: |
| 755 | case RIO_GETDEBUG: |
| 756 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 757 | if (copy_from_user(&DebugCtrl, argp, sizeof(DebugCtrl))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 758 | p->RIOError.Error = COPYIN_FAILED; |
| 759 | return -EFAULT; |
| 760 | } |
| 761 | if (DebugCtrl.SysPort == NO_PORT) { |
| 762 | if (cmd == RIO_SETDEBUG) { |
| 763 | if (!su) { |
| 764 | p->RIOError.Error = NOT_SUPER_USER; |
| 765 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 767 | p->rio_debug = DebugCtrl.Debug; |
| 768 | p->RIODebugWait = DebugCtrl.Wait; |
| 769 | rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait); |
| 770 | } else { |
| 771 | rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait); |
| 772 | DebugCtrl.Debug = p->rio_debug; |
| 773 | DebugCtrl.Wait = p->RIODebugWait; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 774 | if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 775 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort); |
| 776 | p->RIOError.Error = COPYOUT_FAILED; |
| 777 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 779 | } |
| 780 | } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) { |
| 781 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort); |
| 782 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 783 | return -ENXIO; |
| 784 | } else if (cmd == RIO_SETDEBUG) { |
| 785 | if (!su) { |
| 786 | p->RIOError.Error = NOT_SUPER_USER; |
| 787 | return -EPERM; |
| 788 | } |
| 789 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 790 | p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug; |
| 791 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 792 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug); |
| 793 | } else { |
| 794 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug); |
| 795 | DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 796 | if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 797 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n"); |
| 798 | p->RIOError.Error = COPYOUT_FAILED; |
| 799 | return -EFAULT; |
| 800 | } |
| 801 | } |
| 802 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 804 | case RIO_VERSID: |
| 805 | /* |
| 806 | ** Enquire about the release and version. |
| 807 | ** We return MAX_VERSION_LEN bytes, being a |
| 808 | ** textual null terminated string. |
| 809 | */ |
| 810 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 811 | if (copy_to_user(argp, RIOVersid(), sizeof(struct rioVersion))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 812 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host); |
| 813 | p->RIOError.Error = COPYOUT_FAILED; |
| 814 | return -EFAULT; |
| 815 | } |
| 816 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 818 | case RIO_NUM_HOSTS: |
| 819 | /* |
| 820 | ** Enquire as to the number of hosts located |
| 821 | ** at init time. |
| 822 | */ |
| 823 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 824 | if (copy_to_user(argp, &p->RIONumHosts, sizeof(p->RIONumHosts))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 825 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n"); |
| 826 | p->RIOError.Error = COPYOUT_FAILED; |
| 827 | return -EFAULT; |
| 828 | } |
| 829 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 831 | case RIO_HOST_FOAD: |
| 832 | /* |
| 833 | ** Kill host. This may not be in the final version... |
| 834 | */ |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 835 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", arg); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 836 | if (!su) { |
| 837 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n"); |
| 838 | p->RIOError.Error = NOT_SUPER_USER; |
| 839 | return -EPERM; |
| 840 | } |
| 841 | p->RIOHalted = 1; |
| 842 | p->RIOSystemUp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 844 | for (Host = 0; Host < p->RIONumHosts; Host++) { |
| 845 | (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot); |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 846 | memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags)); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 847 | p->RIOHosts[Host].Flags = RC_WAITING; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 848 | } |
| 849 | RIOFoadWakeup(p); |
| 850 | p->RIONumBootPkts = 0; |
| 851 | p->RIOBooting = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 852 | printk("HEEEEELP!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 854 | for (loop = 0; loop < RIO_PORTS; loop++) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 855 | spin_lock_init(&p->RIOPortp[loop]->portSem); |
| 856 | p->RIOPortp[loop]->InUse = NOT_INUSE; |
| 857 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 859 | p->RIOSystemUp = 0; |
| 860 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 862 | case RIO_DOWNLOAD: |
| 863 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n"); |
| 864 | if (!su) { |
| 865 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n"); |
| 866 | p->RIOError.Error = NOT_SUPER_USER; |
| 867 | return -EPERM; |
| 868 | } |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 869 | if (copy_from_user(&DownLoad, argp, sizeof(DownLoad))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 870 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n"); |
| 871 | p->RIOError.Error = COPYIN_FAILED; |
| 872 | return -EFAULT; |
| 873 | } |
| 874 | rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 876 | /* |
| 877 | ** It is important that the product code is an unsigned object! |
| 878 | */ |
| 879 | if (DownLoad.ProductCode > MAX_PRODUCT) { |
| 880 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode); |
| 881 | p->RIOError.Error = NO_SUCH_PRODUCT; |
| 882 | return -ENXIO; |
| 883 | } |
| 884 | /* |
| 885 | ** do something! |
| 886 | */ |
| 887 | retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad); |
| 888 | /* <-- Panic */ |
| 889 | p->RIOHalted = 0; |
| 890 | /* |
| 891 | ** and go back, content with a job well completed. |
| 892 | */ |
| 893 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 895 | case RIO_PARMS: |
| 896 | { |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 897 | unsigned int host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 899 | if (copy_from_user(&host, argp, sizeof(host))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 900 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n"); |
| 901 | p->RIOError.Error = COPYIN_FAILED; |
| 902 | return -EFAULT; |
| 903 | } |
| 904 | /* |
| 905 | ** Fetch the parmmap |
| 906 | */ |
| 907 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n"); |
Al Viro | 0645819 | 2006-05-27 02:11:12 -0400 | [diff] [blame] | 908 | if (copy_from_io(argp, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 909 | p->RIOError.Error = COPYOUT_FAILED; |
| 910 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n"); |
| 911 | return -EFAULT; |
| 912 | } |
| 913 | } |
| 914 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 916 | case RIO_HOST_REQ: |
| 917 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 918 | if (copy_from_user(&HostReq, argp, sizeof(HostReq))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 919 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n"); |
| 920 | p->RIOError.Error = COPYIN_FAILED; |
| 921 | return -EFAULT; |
| 922 | } |
| 923 | if (HostReq.HostNum >= p->RIONumHosts) { |
| 924 | p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE; |
| 925 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum); |
| 926 | return -ENXIO; |
| 927 | } |
| 928 | rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 930 | if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 931 | p->RIOError.Error = COPYOUT_FAILED; |
| 932 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n"); |
| 933 | return -EFAULT; |
| 934 | } |
| 935 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 937 | case RIO_HOST_DPRAM: |
| 938 | rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 939 | if (copy_from_user(&HostDpRam, argp, sizeof(HostDpRam))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 940 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n"); |
| 941 | p->RIOError.Error = COPYIN_FAILED; |
| 942 | return -EFAULT; |
| 943 | } |
| 944 | if (HostDpRam.HostNum >= p->RIONumHosts) { |
| 945 | p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE; |
| 946 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum); |
| 947 | return -ENXIO; |
| 948 | } |
| 949 | rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 951 | if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) { |
| 952 | int off; |
| 953 | /* It's hardware like this that really gets on my tits. */ |
| 954 | static unsigned char copy[sizeof(struct DpRam)]; |
| 955 | for (off = 0; off < sizeof(struct DpRam); off++) |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 956 | copy[off] = readb(p->RIOHosts[HostDpRam.HostNum].Caddr + off); |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 957 | if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 958 | p->RIOError.Error = COPYOUT_FAILED; |
| 959 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n"); |
| 960 | return -EFAULT; |
| 961 | } |
Al Viro | 0645819 | 2006-05-27 02:11:12 -0400 | [diff] [blame] | 962 | } else if (copy_from_io(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 963 | p->RIOError.Error = COPYOUT_FAILED; |
| 964 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n"); |
| 965 | return -EFAULT; |
| 966 | } |
| 967 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 969 | case RIO_SET_BUSY: |
| 970 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 971 | if (arg > 511) { |
| 972 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", arg); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 973 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 974 | return -EINVAL; |
| 975 | } |
| 976 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 977 | p->RIOPortp[arg]->State |= RIO_BUSY; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 978 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 979 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 981 | case RIO_HOST_PORT: |
| 982 | /* |
| 983 | ** The daemon want port information |
| 984 | ** (probably for debug reasons) |
| 985 | */ |
| 986 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 987 | if (copy_from_user(&PortReq, argp, sizeof(PortReq))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 988 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n"); |
| 989 | p->RIOError.Error = COPYIN_FAILED; |
| 990 | return -EFAULT; |
| 991 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 993 | if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */ |
| 994 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort); |
| 995 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 996 | return -ENXIO; |
| 997 | } |
| 998 | rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort); |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 999 | if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1000 | p->RIOError.Error = COPYOUT_FAILED; |
| 1001 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n"); |
| 1002 | return -EFAULT; |
| 1003 | } |
| 1004 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1006 | case RIO_HOST_RUP: |
| 1007 | /* |
| 1008 | ** The daemon want rup information |
| 1009 | ** (probably for debug reasons) |
| 1010 | */ |
| 1011 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1012 | if (copy_from_user(&RupReq, argp, sizeof(RupReq))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1013 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n"); |
| 1014 | p->RIOError.Error = COPYIN_FAILED; |
| 1015 | return -EFAULT; |
| 1016 | } |
| 1017 | if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */ |
| 1018 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum); |
| 1019 | p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE; |
| 1020 | return -ENXIO; |
| 1021 | } |
| 1022 | if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */ |
| 1023 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum); |
| 1024 | p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE; |
| 1025 | return -EINVAL; |
| 1026 | } |
| 1027 | HostP = &p->RIOHosts[RupReq.HostNum]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1029 | if ((HostP->Flags & RUN_STATE) != RC_RUNNING) { |
| 1030 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum); |
| 1031 | p->RIOError.Error = HOST_NOT_RUNNING; |
| 1032 | return -EIO; |
| 1033 | } |
| 1034 | rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
Al Viro | 0645819 | 2006-05-27 02:11:12 -0400 | [diff] [blame] | 1036 | if (copy_from_io(RupReq.RupP, HostP->UnixRups[RupReq.RupNum].RupP, sizeof(struct RUP))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1037 | p->RIOError.Error = COPYOUT_FAILED; |
| 1038 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n"); |
| 1039 | return -EFAULT; |
| 1040 | } |
| 1041 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1043 | case RIO_HOST_LPB: |
| 1044 | /* |
| 1045 | ** The daemon want lpb information |
| 1046 | ** (probably for debug reasons) |
| 1047 | */ |
| 1048 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1049 | if (copy_from_user(&LpbReq, argp, sizeof(LpbReq))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1050 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n"); |
| 1051 | p->RIOError.Error = COPYIN_FAILED; |
| 1052 | return -EFAULT; |
| 1053 | } |
| 1054 | if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */ |
| 1055 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host); |
| 1056 | p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE; |
| 1057 | return -ENXIO; |
| 1058 | } |
| 1059 | if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */ |
| 1060 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link); |
| 1061 | p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE; |
| 1062 | return -EINVAL; |
| 1063 | } |
| 1064 | HostP = &p->RIOHosts[LpbReq.Host]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1066 | if ((HostP->Flags & RUN_STATE) != RC_RUNNING) { |
| 1067 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host); |
| 1068 | p->RIOError.Error = HOST_NOT_RUNNING; |
| 1069 | return -EIO; |
| 1070 | } |
| 1071 | rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
Al Viro | 0645819 | 2006-05-27 02:11:12 -0400 | [diff] [blame] | 1073 | if (copy_from_io(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1074 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n"); |
| 1075 | p->RIOError.Error = COPYOUT_FAILED; |
| 1076 | return -EFAULT; |
| 1077 | } |
| 1078 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1080 | /* |
| 1081 | ** Here 3 IOCTL's that allow us to change the way in which |
| 1082 | ** rio logs errors. send them just to syslog or send them |
| 1083 | ** to both syslog and console or send them to just the console. |
| 1084 | ** |
| 1085 | ** See RioStrBuf() in util.c for the other half. |
| 1086 | */ |
| 1087 | case RIO_SYSLOG_ONLY: |
| 1088 | p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */ |
| 1089 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1091 | case RIO_SYSLOG_CONS: |
| 1092 | p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */ |
| 1093 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1095 | case RIO_CONS_ONLY: |
| 1096 | p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */ |
| 1097 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1099 | case RIO_SIGNALS_ON: |
| 1100 | if (p->RIOSignalProcess) { |
| 1101 | p->RIOError.Error = SIGNALS_ALREADY_SET; |
| 1102 | return -EBUSY; |
| 1103 | } |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1104 | /* FIXME: PID tracking */ |
| 1105 | p->RIOSignalProcess = current->pid; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1106 | p->RIOPrintDisabled = DONT_PRINT; |
| 1107 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1109 | case RIO_SIGNALS_OFF: |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1110 | if (p->RIOSignalProcess != current->pid) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1111 | p->RIOError.Error = NOT_RECEIVING_PROCESS; |
| 1112 | return -EPERM; |
| 1113 | } |
| 1114 | rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n"); |
| 1115 | p->RIOSignalProcess = 0; |
| 1116 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1118 | case RIO_SET_BYTE_MODE: |
| 1119 | for (Host = 0; Host < p->RIONumHosts; Host++) |
| 1120 | if (p->RIOHosts[Host].Type == RIO_AT) |
| 1121 | p->RIOHosts[Host].Mode &= ~WORD_OPERATION; |
| 1122 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1124 | case RIO_SET_WORD_MODE: |
| 1125 | for (Host = 0; Host < p->RIONumHosts; Host++) |
| 1126 | if (p->RIOHosts[Host].Type == RIO_AT) |
| 1127 | p->RIOHosts[Host].Mode |= WORD_OPERATION; |
| 1128 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1130 | case RIO_SET_FAST_BUS: |
| 1131 | for (Host = 0; Host < p->RIONumHosts; Host++) |
| 1132 | if (p->RIOHosts[Host].Type == RIO_AT) |
| 1133 | p->RIOHosts[Host].Mode |= FAST_AT_BUS; |
| 1134 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1136 | case RIO_SET_SLOW_BUS: |
| 1137 | for (Host = 0; Host < p->RIONumHosts; Host++) |
| 1138 | if (p->RIOHosts[Host].Type == RIO_AT) |
| 1139 | p->RIOHosts[Host].Mode &= ~FAST_AT_BUS; |
| 1140 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1142 | case RIO_MAP_B50_TO_50: |
| 1143 | case RIO_MAP_B50_TO_57600: |
| 1144 | case RIO_MAP_B110_TO_110: |
| 1145 | case RIO_MAP_B110_TO_115200: |
| 1146 | rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1147 | port = arg; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1148 | if (port < 0 || port > 511) { |
| 1149 | rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port); |
| 1150 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 1151 | return -EINVAL; |
| 1152 | } |
| 1153 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 1154 | switch (cmd) { |
| 1155 | case RIO_MAP_B50_TO_50: |
| 1156 | p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50; |
| 1157 | break; |
| 1158 | case RIO_MAP_B50_TO_57600: |
| 1159 | p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50; |
| 1160 | break; |
| 1161 | case RIO_MAP_B110_TO_110: |
| 1162 | p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110; |
| 1163 | break; |
| 1164 | case RIO_MAP_B110_TO_115200: |
| 1165 | p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110; |
| 1166 | break; |
| 1167 | } |
| 1168 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1169 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1171 | case RIO_STREAM_INFO: |
| 1172 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n"); |
| 1173 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1175 | case RIO_SEND_PACKET: |
| 1176 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n"); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1177 | if (copy_from_user(&SendPack, argp, sizeof(SendPack))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1178 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n"); |
| 1179 | p->RIOError.Error = COPYIN_FAILED; |
| 1180 | return -EFAULT; |
| 1181 | } |
| 1182 | if (SendPack.PortNum >= 128) { |
| 1183 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 1184 | return -ENXIO; |
| 1185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1187 | PortP = p->RIOPortp[SendPack.PortNum]; |
| 1188 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1190 | if (!can_add_transmit(&PacketP, PortP)) { |
| 1191 | p->RIOError.Error = UNIT_IS_IN_USE; |
| 1192 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1193 | return -ENOSPC; |
| 1194 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1196 | for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++) |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1197 | writeb(SendPack.Data[loop], &PacketP->data[loop]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1199 | writeb(SendPack.Len, &PacketP->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1201 | add_transmit(PortP); |
| 1202 | /* |
| 1203 | ** Count characters transmitted for port statistics reporting |
| 1204 | */ |
| 1205 | if (PortP->statsGather) |
| 1206 | PortP->txchars += (SendPack.Len & 127); |
| 1207 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1208 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1210 | case RIO_NO_MESG: |
| 1211 | if (su) |
| 1212 | p->RIONoMessage = 1; |
| 1213 | return su ? 0 : -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1215 | case RIO_MESG: |
| 1216 | if (su) |
| 1217 | p->RIONoMessage = 0; |
| 1218 | return su ? 0 : -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1220 | case RIO_WHAT_MESG: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1221 | if (copy_to_user(argp, &p->RIONoMessage, sizeof(p->RIONoMessage))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1222 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n"); |
| 1223 | p->RIOError.Error = COPYOUT_FAILED; |
| 1224 | return -EFAULT; |
| 1225 | } |
| 1226 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1228 | case RIO_MEM_DUMP: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1229 | if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1230 | p->RIOError.Error = COPYIN_FAILED; |
| 1231 | return -EFAULT; |
| 1232 | } |
| 1233 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1235 | if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) { |
| 1236 | p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE; |
| 1237 | return -EINVAL; |
| 1238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1240 | if (SubCmd.Host >= p->RIONumHosts) { |
| 1241 | p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE; |
| 1242 | return -EINVAL; |
| 1243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1245 | port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1247 | PortP = p->RIOPortp[port]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1249 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1251 | if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) { |
| 1252 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n"); |
| 1253 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1254 | return -EBUSY; |
| 1255 | } else |
| 1256 | PortP->State |= RIO_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1258 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1259 | if (copy_to_user(argp, p->RIOMemDump, MEMDUMP_SIZE)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1260 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n"); |
| 1261 | p->RIOError.Error = COPYOUT_FAILED; |
| 1262 | return -EFAULT; |
| 1263 | } |
| 1264 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1266 | case RIO_TICK: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1267 | if (arg >= p->RIONumHosts) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1268 | return -EINVAL; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1269 | rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", arg); |
| 1270 | writeb(0xFF, &p->RIOHosts[arg].SetInt); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1271 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1273 | case RIO_TOCK: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1274 | if (arg >= p->RIONumHosts) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1275 | return -EINVAL; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1276 | rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", arg); |
| 1277 | writeb(0xFF, &p->RIOHosts[arg].ResetInt); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1278 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1280 | case RIO_READ_CHECK: |
| 1281 | /* Check reads for pkts with data[0] the same */ |
| 1282 | p->RIOReadCheck = !p->RIOReadCheck; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1283 | if (copy_to_user(argp, &p->RIOReadCheck, sizeof(unsigned int))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1284 | p->RIOError.Error = COPYOUT_FAILED; |
| 1285 | return -EFAULT; |
| 1286 | } |
| 1287 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1289 | case RIO_READ_REGISTER: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1290 | if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1291 | p->RIOError.Error = COPYIN_FAILED; |
| 1292 | return -EFAULT; |
| 1293 | } |
| 1294 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER host %d rup %d port %d reg %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Port, SubCmd.Addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1296 | if (SubCmd.Port > 511) { |
| 1297 | rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port); |
| 1298 | p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; |
| 1299 | return -EINVAL; |
| 1300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1302 | if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) { |
| 1303 | p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE; |
| 1304 | return -EINVAL; |
| 1305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1307 | if (SubCmd.Host >= p->RIONumHosts) { |
| 1308 | p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE; |
| 1309 | return -EINVAL; |
| 1310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1312 | port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port; |
| 1313 | PortP = p->RIOPortp[port]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1315 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1317 | if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) { |
| 1318 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n"); |
| 1319 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1320 | return -EBUSY; |
| 1321 | } else |
| 1322 | PortP->State |= RIO_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1324 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1325 | if (copy_to_user(argp, &p->CdRegister, sizeof(unsigned int))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1326 | rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n"); |
| 1327 | p->RIOError.Error = COPYOUT_FAILED; |
| 1328 | return -EFAULT; |
| 1329 | } |
| 1330 | return 0; |
| 1331 | /* |
| 1332 | ** rio_make_dev: given port number (0-511) ORed with port type |
| 1333 | ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t |
| 1334 | ** value to pass to mknod to create the correct device node. |
| 1335 | */ |
| 1336 | case RIO_MAKE_DEV: |
| 1337 | { |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1338 | unsigned int port = arg & RIO_MODEM_MASK; |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1339 | unsigned int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1341 | switch (arg & RIO_DEV_MASK) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1342 | case RIO_DEV_DIRECT: |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1343 | ret = drv_makedev(MAJOR(dev), port); |
| 1344 | rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret); |
| 1345 | return ret; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1346 | case RIO_DEV_MODEM: |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1347 | ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT)); |
| 1348 | rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret); |
| 1349 | return ret; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1350 | case RIO_DEV_XPRINT: |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1351 | ret = drv_makedev(MAJOR(dev), port); |
| 1352 | rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret); |
| 1353 | return ret; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1354 | } |
| 1355 | rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n"); |
| 1356 | return -EINVAL; |
| 1357 | } |
| 1358 | /* |
| 1359 | ** rio_minor: given a dev_t from a stat() call, return |
| 1360 | ** the port number (0-511) ORed with the port type |
| 1361 | ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT ) |
| 1362 | */ |
| 1363 | case RIO_MINOR: |
| 1364 | { |
| 1365 | dev_t dv; |
| 1366 | int mino; |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1367 | unsigned long ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1369 | dv = (dev_t) (arg); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1370 | mino = RIO_UNMODEM(dv); |
| 1371 | |
| 1372 | if (RIO_ISMODEM(dv)) { |
| 1373 | rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino); |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1374 | ret = mino | RIO_DEV_MODEM; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1375 | } else { |
| 1376 | rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino); |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1377 | ret = mino | RIO_DEV_DIRECT; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1378 | } |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1379 | return ret; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1382 | rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | p->RIOError.Error = IOCTL_COMMAND_UNKNOWN; |
| 1384 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1385 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | return -EINVAL; |
| 1387 | } |
| 1388 | |
| 1389 | /* |
| 1390 | ** Pre-emptive commands go on RUPs and are only one byte long. |
| 1391 | */ |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1392 | int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | { |
| 1394 | struct CmdBlk *CmdBlkP; |
| 1395 | struct PktCmd_M *PktCmdP; |
| 1396 | int Ret; |
| 1397 | ushort rup; |
| 1398 | int port; |
| 1399 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1400 | if (PortP->State & RIO_DELETED) { |
| 1401 | rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | return RIO_FAIL; |
| 1403 | } |
| 1404 | |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1405 | if ((PortP->InUse == (typeof(PortP->InUse))-1) || |
| 1406 | !(CmdBlkP = RIOGetCmdBlk())) { |
| 1407 | rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block " |
| 1408 | "for command %d on port %d\n", Cmd, PortP->PortNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | return RIO_FAIL; |
| 1410 | } |
| 1411 | |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1412 | rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n", |
| 1413 | CmdBlkP, PortP->InUse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1415 | PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1417 | CmdBlkP->Packet.src_unit = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | if (PortP->SecondBlock) |
| 1419 | rup = PortP->ID2; |
| 1420 | else |
| 1421 | rup = PortP->RupNum; |
| 1422 | CmdBlkP->Packet.dest_unit = rup; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1423 | CmdBlkP->Packet.src_port = COMMAND_RUP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | CmdBlkP->Packet.dest_port = COMMAND_RUP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1425 | CmdBlkP->Packet.len = PKT_CMD_BIT | 2; |
| 1426 | CmdBlkP->PostFuncP = RIOUnUse; |
Alan Cox | 3d336aa | 2006-03-24 03:18:29 -0800 | [diff] [blame] | 1427 | CmdBlkP->PostArg = (unsigned long) PortP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1428 | PktCmdP->Command = Cmd; |
| 1429 | port = PortP->HostPort % (ushort) PORTS_PER_RTA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1431 | ** Index ports 8-15 for 2nd block of 16 port RTA. |
| 1432 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | if (PortP->SecondBlock) |
| 1434 | port += (ushort) PORTS_PER_RTA; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1435 | PktCmdP->PhbNum = port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1437 | switch (Cmd) { |
| 1438 | case MEMDUMP: |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1439 | rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p " |
| 1440 | "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1441 | PktCmdP->SubCommand = MEMDUMP; |
| 1442 | PktCmdP->SubAddr = SubCmd.Addr; |
| 1443 | break; |
| 1444 | case FCLOSE: |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1445 | rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n", |
| 1446 | CmdBlkP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1447 | break; |
| 1448 | case READ_REGISTER: |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1449 | rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) " |
| 1450 | "command blk %p\n", (int) SubCmd.Addr, CmdBlkP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1451 | PktCmdP->SubCommand = READ_REGISTER; |
| 1452 | PktCmdP->SubAddr = SubCmd.Addr; |
| 1453 | break; |
| 1454 | case RESUME: |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1455 | rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n", |
| 1456 | CmdBlkP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1457 | break; |
| 1458 | case RFLUSH: |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1459 | rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n", |
| 1460 | CmdBlkP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1461 | CmdBlkP->PostFuncP = RIORFlushEnable; |
| 1462 | break; |
| 1463 | case SUSPEND: |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1464 | rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n", |
| 1465 | CmdBlkP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1466 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1468 | case MGET: |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1469 | rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n", |
| 1470 | CmdBlkP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1471 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1473 | case MSET: |
| 1474 | case MBIC: |
| 1475 | case MBIS: |
| 1476 | CmdBlkP->Packet.data[4] = (char) PortP->ModemLines; |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1477 | rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command " |
| 1478 | "blk %p\n", CmdBlkP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1479 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1481 | case WFLUSH: |
| 1482 | /* |
| 1483 | ** If we have queued up the maximum number of Write flushes |
| 1484 | ** allowed then we should not bother sending any more to the |
| 1485 | ** RTA. |
| 1486 | */ |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1487 | if (PortP->WflushFlag == (typeof(PortP->WflushFlag))-1) { |
| 1488 | rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, " |
| 1489 | "WflushFlag about to wrap!"); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1490 | RIOFreeCmdBlk(CmdBlkP); |
| 1491 | return (RIO_FAIL); |
| 1492 | } else { |
Alan Cox | 655fdea | 2006-05-15 09:44:26 -0700 | [diff] [blame] | 1493 | rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command " |
| 1494 | "blk %p\n", CmdBlkP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1495 | CmdBlkP->PostFuncP = RIOWFlushMark; |
| 1496 | } |
| 1497 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | PortP->InUse++; |
| 1501 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1502 | Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
| 1504 | return Ret; |
| 1505 | } |