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