ia64/linux-2.6.18-xen.hg

annotate drivers/char/rio/rioctrl.c @ 893:f994bfe9b93b

linux/blktap2: reduce TLB flush scope

c/s 885 added very coarse TLB flushing. Since these flushes always
follow single page updates, single page flushes (when available) are
sufficient.

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