Import 2.3.99pre7-9
[davej-history.git] / drivers / char / rio / rioctrl.c
blob27b46398aa7420613f3aeb7aabcd705956c9cab8
1 /*
2 ** -----------------------------------------------------------------------------
3 **
4 ** Perle Specialix driver for Linux
5 ** Ported from existing RIO Driver for SCO sources.
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
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.
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.
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.
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
28 ** ident @(#)rioctrl.c 1.3
30 ** -----------------------------------------------------------------------------
32 #ifdef SCCS_LABELS
33 static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c 1.3";
34 #endif
37 #define __NO_VERSION__
38 #include <linux/module.h>
39 #include <linux/malloc.h>
40 #include <linux/errno.h>
41 #include <asm/io.h>
42 #include <asm/system.h>
43 #include <asm/string.h>
44 #include <asm/semaphore.h>
45 #include <asm/uaccess.h>
47 #include <linux/termios.h>
48 #include <linux/serial.h>
50 #include <linux/compatmac.h>
51 #include <linux/generic_serial.h>
54 #include "linux_compat.h"
55 #include "rio_linux.h"
56 #include "typdef.h"
57 #include "pkt.h"
58 #include "daemon.h"
59 #include "rio.h"
60 #include "riospace.h"
61 #include "top.h"
62 #include "cmdpkt.h"
63 #include "map.h"
64 #include "riotypes.h"
65 #include "rup.h"
66 #include "port.h"
67 #include "riodrvr.h"
68 #include "rioinfo.h"
69 #include "func.h"
70 #include "errors.h"
71 #include "pci.h"
73 #include "parmmap.h"
74 #include "unixrup.h"
75 #include "board.h"
76 #include "host.h"
77 #include "error.h"
78 #include "phb.h"
79 #include "link.h"
80 #include "cmdblk.h"
81 #include "route.h"
82 #include "control.h"
83 #include "cirrus.h"
84 #include "rioioctl.h"
87 static struct LpbReq LpbReq;
88 static struct RupReq RupReq;
89 static struct PortReq PortReq;
90 static struct HostReq HostReq;
91 static struct HostDpRam HostDpRam;
92 static struct DebugCtrl DebugCtrl;
93 static struct Map MapEnt;
94 static struct PortSetup PortSetup;
95 static struct DownLoad DownLoad;
96 static struct SendPack SendPack;
97 /* static struct StreamInfo StreamInfo; */
98 /* static char modemtable[RIO_PORTS]; */
99 static struct SpecialRupCmd SpecialRupCmd;
100 static struct PortParams PortParams;
101 static struct portStats portStats;
103 static struct SubCmdStruct {
104 ushort Host;
105 ushort Rup;
106 ushort Port;
107 ushort Addr;
108 } SubCmd;
110 struct PortTty {
111 uint port;
112 struct ttystatics Tty;
115 static struct PortTty PortTty;
116 typedef struct ttystatics TERMIO;
119 ** This table is used when the config.rio downloads bin code to the
120 ** driver. We index the table using the product code, 0-F, and call
121 ** the function pointed to by the entry, passing the information
122 ** about the boot.
123 ** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
124 ** process to bog off.
126 static int
127 (*RIOBootTable[MAX_PRODUCT])(struct rio_info *, struct DownLoad *) =
129 /* 0 */ RIOBootCodeHOST, /* Host Card */
130 /* 1 */ RIOBootCodeRTA, /* RTA */
133 #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
135 #ifdef linux
136 int copyin (int arg, caddr_t dp, int siz)
138 int rv;
140 rio_dprint (RIO_DEBUG_CTRL, ("Copying %d bytes from user %p to %p.\n", siz, (void *) arg, dp));
141 rv = copy_from_user (dp, (void *)arg, siz);
142 if (rv < 0) return COPYFAIL;
143 else return rv;
147 int copyout (caddr_t dp, int arg, int siz)
149 int rv;
151 rio_dprint (RIO_DEBUG_CTRL, ("Copying %d bytes to user %p from %p.\n", siz, (void *) arg, dp));
152 rv = copy_to_user ((void *)arg, dp, siz);
153 if (rv < 0) return COPYFAIL;
154 else return rv;
157 #else
160 copyin(arg, dp, siz)
161 int arg;
162 caddr_t dp;
163 int siz;
165 if (rbounds ((unsigned long) arg) >= siz) {
166 bcopy ( arg, dp, siz );
167 return OK;
168 } else
169 return ( COPYFAIL );
173 copyout (dp, arg, siz)
174 caddr_t dp;
175 int arg;
176 int siz;
178 if (wbounds ((unsigned long) arg) >= siz ) {
179 bcopy ( dp, arg, siz );
180 return OK;
181 } else
182 return ( COPYFAIL );
184 #endif
187 riocontrol(p, dev, cmd, arg, su)
188 struct rio_info * p;
189 dev_t dev;
190 int cmd;
191 caddr_t arg;
192 int su;
194 uint Host; /* leave me unsigned! */
195 uint port; /* and me! */
196 struct Host *HostP;
197 ushort loop;
198 int Entry;
199 struct Port *PortP;
200 PKT *PacketP;
201 int retval = 0;
202 unsigned long flags;
204 /* Confuse teh compiler to think that we've initialized these */
205 Host=0;
206 PortP = NULL;
208 rio_dprint(RIO_DEBUG_CTRL, ("control ioctl cmd: 0x%x arg: 0x%x\n", cmd, (int)arg));
210 switch (cmd) {
212 ** RIO_SET_TIMER
214 ** Change the value of the host card interrupt timer.
215 ** If the host card number is -1 then all host cards are changed
216 ** otherwise just the specified host card will be changed.
218 case RIO_SET_TIMER:
219 rio_dprint(RIO_DEBUG_CTRL, ("RIO_SET_TIMER to %dms\n", (uint)arg));
221 int host, value;
222 host = (uint)arg >> 16;
223 value = (uint)arg & 0x0000ffff;
224 if (host == -1) {
225 for (host = 0; host < p->RIONumHosts; host++) {
226 if (p->RIOHosts[host].Flags == RC_RUNNING) {
227 WWORD(p->RIOHosts[host].ParmMapP->timer , value);
230 } else if (host >= p->RIONumHosts) {
231 return EINVAL;
232 } else {
233 if ( p->RIOHosts[host].Flags == RC_RUNNING ) {
234 WWORD(p->RIOHosts[host].ParmMapP->timer , value);
238 return 0;
240 case RIO_IDENTIFY_DRIVER:
242 ** 15.10.1998 ARG - ESIL 0760 part fix
243 ** Added driver ident string output.
245 #ifndef __THIS_RELEASE__
246 #warning Driver Version string not defined !
247 #endif
248 cprintf("%s %s %s %s\n",
249 RIO_DRV_STR,
250 __THIS_RELEASE__,
251 __DATE__, __TIME__ );
253 return 0;
255 case RIO_DISPLAY_HOST_CFG:
257 ** 15.10.1998 ARG - ESIL 0760 part fix
258 ** Added driver host card ident string output.
260 ** Note that the only types currently supported
261 ** are ISA and PCI. Also this driver does not
262 ** (yet) distinguish between the Old PCI card
263 ** and the Jet PCI card. In fact I think this
264 ** driver only supports JET PCI !
267 for (Host = 0; Host < p->RIONumHosts; Host++)
269 HostP = &(p->RIOHosts[Host]);
271 switch ( HostP->Type )
273 case RIO_AT :
274 strcpy( host_type, RIO_AT_HOST_STR );
275 break;
277 case RIO_PCI :
278 strcpy( host_type, RIO_PCI_HOST_STR );
279 break;
281 default :
282 strcpy( host_type, "Unknown" );
283 break;
286 cprintf(
287 "RIO Host %d - Type:%s Addr:%X IRQ:%d\n",
288 Host, host_type,
289 (uint)HostP->PaddrP,
290 (int)HostP->Ivec - 32 );
292 return 0;
296 case RIO_FOAD_RTA:
297 rio_dprint(RIO_DEBUG_CTRL, ("RIO_FOAD_RTA\n"));
298 return RIOCommandRta(p, (uint)arg, RIOFoadRta);
300 case RIO_ZOMBIE_RTA:
301 rio_dprint(RIO_DEBUG_CTRL, ("RIO_ZOMBIE_RTA\n"));
302 return RIOCommandRta(p, (uint)arg, RIOZombieRta);
304 case RIO_IDENTIFY_RTA:
305 rio_dprint(RIO_DEBUG_CTRL, ("RIO_IDENTIFY_RTA\n"));
306 return RIOIdentifyRta(p, arg);
308 case RIO_KILL_NEIGHBOUR:
309 rio_dprint(RIO_DEBUG_CTRL, ("RIO_KILL_NEIGHBOUR\n"));
310 return RIOKillNeighbour(p, arg);
312 case SPECIAL_RUP_CMD:
314 struct CmdBlk *CmdBlkP;
316 rio_dprint(RIO_DEBUG_CTRL, ("SPECIAL_RUP_CMD\n"));
317 if (copyin((int)arg, (caddr_t)&SpecialRupCmd,
318 sizeof(SpecialRupCmd)) == COPYFAIL ) {
319 rio_dprint(RIO_DEBUG_CTRL, ("SPECIAL_RUP_CMD copy failed\n"));
320 p->RIOError.Error = COPYIN_FAILED;
321 return EFAULT;
323 CmdBlkP = RIOGetCmdBlk();
324 if ( !CmdBlkP ) {
325 rio_dprint(RIO_DEBUG_CTRL, ("SPECIAL_RUP_CMD GetCmdBlk failed\n"));
326 return ENXIO;
328 CmdBlkP->Packet = SpecialRupCmd.Packet;
329 if ( SpecialRupCmd.Host >= p->RIONumHosts )
330 SpecialRupCmd.Host = 0;
331 rio_dprint(RIO_DEBUG_CTRL, ("Queue special rup command for host %d rup %d\n",
332 SpecialRupCmd.Host, SpecialRupCmd.RupNum));
333 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host],
334 SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
335 cprintf("FAILED TO QUEUE SPECIAL RUP COMMAND\n");
337 return 0;
340 case RIO_DEBUG_MEM:
341 #ifdef DEBUG_MEM_SUPPORT
342 RIO_DEBUG_CTRL, if (su)
343 return rio_RIODebugMemory(RIO_DEBUG_CTRL, arg);
344 else
345 #endif
346 return EPERM;
348 case RIO_ALL_MODEM:
349 rio_dprint(RIO_DEBUG_CTRL, ("RIO_ALL_MODEM\n"));
350 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
351 return EINVAL;
353 case RIO_GET_TABLE:
355 ** Read the routing table from the device driver to user space
357 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GET_TABLE\n"));
359 if ((retval = RIOApel(p)) != 0)
360 return retval;
362 if (copyout((caddr_t)p->RIOConnectTable, (int)arg,
363 TOTAL_MAP_ENTRIES*sizeof(struct Map)) == COPYFAIL) {
364 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GET_TABLE copy failed\n"));
365 p->RIOError.Error = COPYOUT_FAILED;
366 return EFAULT;
370 int entry;
371 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
372 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
374 if ((p->RIOConnectTable[entry].ID == 0) &&
375 (p->RIOConnectTable[entry].HostUniqueNum == 0) &&
376 (p->RIOConnectTable[entry].RtaUniqueNum == 0)) continue;
378 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
379 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
380 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
381 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
382 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, (int)p->RIOConnectTable[entry].Flags ) );
383 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, (int)p->RIOConnectTable[entry].SysPort ) );
384 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
385 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
386 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
387 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
388 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
389 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
390 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
391 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
392 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
394 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
396 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
397 return 0;
399 case RIO_PUT_TABLE:
401 ** Write the routing table to the device driver from user space
403 rio_dprint(RIO_DEBUG_CTRL, ("RIO_PUT_TABLE\n"));
405 if ( !su ) {
406 rio_dprint(RIO_DEBUG_CTRL, ("RIO_PUT_TABLE !Root\n"));
407 p->RIOError.Error = NOT_SUPER_USER;
408 return EPERM;
410 if ( copyin((int)arg, (caddr_t)&p->RIOConnectTable[0],
411 TOTAL_MAP_ENTRIES*sizeof(struct Map) ) == COPYFAIL ) {
412 rio_dprint(RIO_DEBUG_CTRL, ("RIO_PUT_TABLE copy failed\n"));
413 p->RIOError.Error = COPYIN_FAILED;
414 return EFAULT;
417 ***********************************
419 int entry;
420 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
421 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
423 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
424 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
425 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
426 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
427 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
428 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
429 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
430 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
431 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
432 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
433 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
434 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
435 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
436 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
437 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
439 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
441 ***********************************
443 return RIONewTable(p);
445 case RIO_GET_BINDINGS :
447 ** Send bindings table, containing unique numbers of RTAs owned
448 ** by this system to user space
450 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GET_BINDINGS\n"));
452 if ( !su )
454 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GET_BINDINGS !Root\n"));
455 p->RIOError.Error = NOT_SUPER_USER;
456 return EPERM;
458 if (copyout((caddr_t) p->RIOBindTab, (int)arg,
459 (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL ) {
460 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GET_BINDINGS copy failed\n"));
461 p->RIOError.Error = COPYOUT_FAILED;
462 return EFAULT;
464 return 0;
466 case RIO_PUT_BINDINGS :
468 ** Receive a bindings table, containing unique numbers of RTAs owned
469 ** by this system
471 rio_dprint(RIO_DEBUG_CTRL, ("RIO_PUT_BINDINGS\n"));
473 if ( !su )
475 rio_dprint(RIO_DEBUG_CTRL, ("RIO_PUT_BINDINGS !Root\n"));
476 p->RIOError.Error = NOT_SUPER_USER;
477 return EPERM;
479 if (copyin((int)arg, (caddr_t)&p->RIOBindTab[0],
480 (sizeof(ulong) * MAX_RTA_BINDINGS))==COPYFAIL ) {
481 rio_dprint(RIO_DEBUG_CTRL, ("RIO_PUT_BINDINGS copy failed\n"));
482 p->RIOError.Error = COPYIN_FAILED;
483 return EFAULT;
485 return 0;
487 case RIO_BIND_RTA :
489 int EmptySlot = -1;
491 ** Bind this RTA to host, so that it will be booted by
492 ** host in 'boot owned RTAs' mode.
494 rio_dprint(RIO_DEBUG_CTRL, ("RIO_BIND_RTA\n"));
496 if ( !su ) {
497 rio_dprint(RIO_DEBUG_CTRL, ("RIO_BIND_RTA !Root\n"));
498 p->RIOError.Error = NOT_SUPER_USER;
499 return EPERM;
501 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
502 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
503 EmptySlot = Entry;
504 else if (p->RIOBindTab[Entry] == (int) arg) {
506 ** Already exists - delete
508 p->RIOBindTab[Entry] = 0L;
509 rio_dprint(RIO_DEBUG_CTRL, ("Removing Rta %x from p->RIOBindTab\n",
510 (int) arg));
511 return 0;
515 ** Dosen't exist - add
517 if (EmptySlot != -1) {
518 p->RIOBindTab[EmptySlot] = (int) arg;
519 rio_dprint(RIO_DEBUG_CTRL, ("Adding Rta %x to p->RIOBindTab\n",
520 (int) arg));
522 else {
523 rio_dprint(RIO_DEBUG_CTRL, ("p->RIOBindTab full! - Rta %x not added\n",
524 (int) arg));
525 return 1;
527 return 0;
530 case RIO_RESUME :
531 rio_dprint(RIO_DEBUG_CTRL, ("RIO_RESUME\n"));
532 port = (uint) arg;
533 if ((port < 0) || (port > 511)) {
534 rio_dprint(RIO_DEBUG_CTRL, ("RIO_RESUME: Bad port number %d\n", port));
535 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
536 return EINVAL;
538 PortP = p->RIOPortp[port];
539 if (!PortP->Mapped) {
540 rio_dprint(RIO_DEBUG_CTRL, ("RIO_RESUME: Port %d not mapped\n", port));
541 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
542 return EINVAL;
544 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
545 rio_dprint(RIO_DEBUG_CTRL, ("RIO_RESUME: Port %d not open\n", port));
546 return EINVAL;
549 rio_spin_lock_irqsave(&PortP->portSem, flags);
550 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) ==
551 RIO_FAIL) {
552 rio_dprint(RIO_DEBUG_CTRL, ("RIO_RESUME failed\n"));
553 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
554 return EBUSY;
556 else {
557 rio_dprint(RIO_DEBUG_CTRL, ("RIO_RESUME: Port %d resumed\n", port));
558 PortP->State |= RIO_BUSY;
560 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
561 return retval;
563 case RIO_ASSIGN_RTA:
564 rio_dprint(RIO_DEBUG_CTRL, ("RIO_ASSIGN_RTA\n"));
565 if ( !su ) {
566 rio_dprint(RIO_DEBUG_CTRL, ("RIO_ASSIGN_RTA !Root\n"));
567 p->RIOError.Error = NOT_SUPER_USER;
568 return EPERM;
570 if (copyin((int)arg, (caddr_t)&MapEnt, sizeof(MapEnt))
571 == COPYFAIL) {
572 rio_dprint(RIO_DEBUG_CTRL, ("Copy from user space failed\n"));
573 p->RIOError.Error = COPYIN_FAILED;
574 return EFAULT;
576 return RIOAssignRta(p, &MapEnt);
578 case RIO_CHANGE_NAME:
579 rio_dprint(RIO_DEBUG_CTRL, ("RIO_CHANGE_NAME\n"));
580 if ( !su ) {
581 rio_dprint(RIO_DEBUG_CTRL, ("RIO_CHANGE_NAME !Root\n"));
582 p->RIOError.Error = NOT_SUPER_USER;
583 return EPERM;
585 if (copyin((int)arg, (caddr_t)&MapEnt, sizeof(MapEnt))
586 == COPYFAIL) {
587 rio_dprint(RIO_DEBUG_CTRL, ("Copy from user space failed\n"));
588 p->RIOError.Error = COPYIN_FAILED;
589 return EFAULT;
591 return RIOChangeName(p, &MapEnt);
593 case RIO_DELETE_RTA:
594 rio_dprint(RIO_DEBUG_CTRL, ("RIO_DELETE_RTA\n"));
595 if ( !su ) {
596 rio_dprint(RIO_DEBUG_CTRL, ("RIO_DELETE_RTA !Root\n"));
597 p->RIOError.Error = NOT_SUPER_USER;
598 return EPERM;
600 if (copyin((int)arg, (caddr_t)&MapEnt, sizeof(MapEnt))
601 == COPYFAIL ) {
602 rio_dprint(RIO_DEBUG_CTRL, ("Copy from data space failed\n"));
603 p->RIOError.Error = COPYIN_FAILED;
604 return EFAULT;
606 return RIODeleteRta(p, &MapEnt);
608 case RIO_QUICK_CHECK:
610 ** 09.12.1998 ARG - ESIL 0776 part fix
611 ** A customer was using this to get the RTAs
612 ** connect/disconnect status.
613 ** RIOConCon() had been botched use RIOHalted
614 ** to keep track of RTA connections and
615 ** disconnections. That has been changed and
616 ** RIORtaDisCons in the rio_info struct now
617 ** does the job. So we need to return the value
618 ** of RIORtaCons instead of RIOHalted.
620 if (copyout((caddr_t)&p->RIOHalted,(int)arg,
621 sizeof(uint))==COPYFAIL) {
625 if (copyout((caddr_t)&p->RIORtaDisCons,(int)arg,
626 sizeof(uint))==COPYFAIL) {
627 p->RIOError.Error = COPYOUT_FAILED;
628 return EFAULT;
630 return 0;
632 case RIO_LAST_ERROR:
633 if (copyout((caddr_t)&p->RIOError, (int)arg,
634 sizeof(struct Error)) ==COPYFAIL )
635 return EFAULT;
636 return 0;
638 case RIO_GET_LOG:
639 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GET_LOG\n"));
640 #ifdef LOGGING
641 RIOGetLog(arg);
642 return 0;
643 #else
644 return EINVAL;
645 #endif
647 case RIO_GET_MODTYPE:
648 if ( copyin( (int)arg, (caddr_t)&port,
649 sizeof(uint)) == COPYFAIL )
651 p->RIOError.Error = COPYIN_FAILED;
652 return EFAULT;
654 rio_dprint(RIO_DEBUG_CTRL, ("Get module type for port %d\n", port));
655 if ( port < 0 || port > 511 )
657 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GET_MODTYPE: Bad port number %d\n", port));
658 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
659 return EINVAL;
661 PortP = (p->RIOPortp[port]);
662 if (!PortP->Mapped)
664 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GET_MODTYPE: Port %d not mapped\n", port));
665 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
666 return EINVAL;
669 ** Return module type of port
671 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
672 if (copyout((caddr_t)&port, (int)arg,
673 sizeof(uint)) == COPYFAIL) {
674 p->RIOError.Error = COPYOUT_FAILED;
675 return EFAULT;
677 return(0);
679 ** 02.03.1999 ARG - ESIL 0820 fix
680 ** We are no longer using "Boot Mode", so these ioctls
681 ** are not required :
683 case RIO_GET_BOOT_MODE :
684 rio_dprint(RIO_DEBUG_CTRL, ("Get boot mode - %x\n", p->RIOBootMode));
686 ** Return boot state of system - BOOT_ALL, BOOT_OWN or BOOT_NONE
688 if (copyout((caddr_t)&p->RIOBootMode, (int)arg,
689 sizeof(p->RIOBootMode)) == COPYFAIL) {
690 p->RIOError.Error = COPYOUT_FAILED;
691 return EFAULT;
693 return(0);
695 case RIO_SET_BOOT_MODE :
696 p->RIOBootMode = (uint) arg;
697 rio_dprint(RIO_DEBUG_CTRL, ("Set boot mode to 0x%x\n", p->RIOBootMode));
698 return(0);
700 ** End ESIL 0820 fix
703 case RIO_BLOCK_OPENS:
704 rio_dprint(RIO_DEBUG_CTRL, ("Opens block until booted\n"));
705 for ( Entry=0; Entry < RIO_PORTS; Entry++ ) {
706 rio_spin_lock_irqsave(&PortP->portSem, flags);
707 p->RIOPortp[Entry]->WaitUntilBooted = 1;
708 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
710 return 0;
712 case RIO_SETUP_PORTS:
713 rio_dprint(RIO_DEBUG_CTRL, ("Setup ports\n"));
714 if (copyin((int)arg, (caddr_t)&PortSetup, sizeof(PortSetup))
715 == COPYFAIL ) {
716 p->RIOError.Error = COPYIN_FAILED;
717 rio_dprint(RIO_DEBUG_CTRL, ("EFAULT"));
718 return EFAULT;
720 if ( PortSetup.From > PortSetup.To ||
721 PortSetup.To >= RIO_PORTS ) {
722 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
723 rio_dprint(RIO_DEBUG_CTRL, ("ENXIO"));
724 return ENXIO;
726 if ( PortSetup.XpCps > p->RIOConf.MaxXpCps ||
727 PortSetup.XpCps < p->RIOConf.MinXpCps ) {
728 p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
729 rio_dprint(RIO_DEBUG_CTRL, ("EINVAL"));
730 return EINVAL;
732 if ( !p->RIOPortp ) {
733 cprintf("No p->RIOPortp array!\n");
734 rio_dprint(RIO_DEBUG_CTRL, ("No p->RIOPortp array!\n"));
735 return EIO;
737 rio_dprint(RIO_DEBUG_CTRL, ("entering loop (%d %d)!\n", PortSetup.From, PortSetup.To));
738 for (loop=PortSetup.From; loop<=PortSetup.To; loop++) {
739 rio_dprint(RIO_DEBUG_CTRL, ("in loop (%d)!\n", loop));
740 #if 0
741 PortP = p->RIOPortp[loop];
742 if ( !PortP->TtyP )
743 PortP->TtyP = &p->channel[loop];
745 rio_spin_lock_irqsave(&PortP->portSem, flags);
746 if ( PortSetup.IxAny )
747 PortP->Config |= RIO_IXANY;
748 else
749 PortP->Config &= ~RIO_IXANY;
750 if ( PortSetup.IxOn )
751 PortP->Config |= RIO_IXON;
752 else
753 PortP->Config &= ~RIO_IXON;
756 ** If the port needs to wait for all a processes output
757 ** to drain before closing then this flag will be set.
759 if (PortSetup.Drain) {
760 PortP->Config |= RIO_WAITDRAIN;
761 } else {
762 PortP->Config &= ~RIO_WAITDRAIN;
765 ** Store setings if locking or unlocking port or if the
766 ** port is not locked, when setting the store option.
768 if (PortP->Mapped &&
769 ((PortSetup.Lock && !PortP->Lock) ||
770 (!PortP->Lock &&
771 (PortSetup.Store && !PortP->Store)))) {
772 PortP->StoredTty.iflag = PortP->TtyP->tm.c_iflag;
773 PortP->StoredTty.oflag = PortP->TtyP->tm.c_oflag;
774 PortP->StoredTty.cflag = PortP->TtyP->tm.c_cflag;
775 PortP->StoredTty.lflag = PortP->TtyP->tm.c_lflag;
776 PortP->StoredTty.line = PortP->TtyP->tm.c_line;
777 bcopy(PortP->TtyP->tm.c_cc, PortP->StoredTty.cc,
778 NCC + 5);
780 PortP->Lock = PortSetup.Lock;
781 PortP->Store = PortSetup.Store;
782 PortP->Xprint.XpCps = PortSetup.XpCps;
783 bcopy(PortSetup.XpOn,PortP->Xprint.XpOn,MAX_XP_CTRL_LEN);
784 bcopy(PortSetup.XpOff,PortP->Xprint.XpOff,MAX_XP_CTRL_LEN);
785 PortP->Xprint.XpOn[MAX_XP_CTRL_LEN-1] = '\0';
786 PortP->Xprint.XpOff[MAX_XP_CTRL_LEN-1] = '\0';
787 PortP->Xprint.XpLen = RIOStrlen(PortP->Xprint.XpOn)+
788 RIOStrlen(PortP->Xprint.XpOff);
789 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
790 #endif
792 rio_dprint(RIO_DEBUG_CTRL, ("after loop (%d)!\n", loop));
793 rio_dprint(RIO_DEBUG_CTRL, ("Retval:%x\n", retval ) );
794 return retval;
796 case RIO_GET_PORT_SETUP :
797 rio_dprint(RIO_DEBUG_CTRL, ("Get port setup\n"));
798 if (copyin((int)arg, (caddr_t)&PortSetup, sizeof(PortSetup))
799 == COPYFAIL ) {
800 p->RIOError.Error = COPYIN_FAILED;
801 return EFAULT;
803 if ( PortSetup.From >= RIO_PORTS ) {
804 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
805 return ENXIO;
808 port = PortSetup.To = PortSetup.From;
809 PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ?
810 1 : 0;
811 PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ?
812 1 : 0;
813 PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ?
814 1 : 0;
815 PortSetup.Store = p->RIOPortp[port]->Store;
816 PortSetup.Lock = p->RIOPortp[port]->Lock;
817 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
818 bcopy(p->RIOPortp[port]->Xprint.XpOn, PortSetup.XpOn,
819 MAX_XP_CTRL_LEN);
820 bcopy(p->RIOPortp[port]->Xprint.XpOff, PortSetup.XpOff,
821 MAX_XP_CTRL_LEN);
822 PortSetup.XpOn[MAX_XP_CTRL_LEN-1] = '\0';
823 PortSetup.XpOff[MAX_XP_CTRL_LEN-1] = '\0';
825 if ( copyout((caddr_t)&PortSetup,(int)arg,sizeof(PortSetup))
826 ==COPYFAIL ) {
827 p->RIOError.Error = COPYOUT_FAILED;
828 return EFAULT;
830 return retval;
832 case RIO_GET_PORT_PARAMS :
833 rio_dprint(RIO_DEBUG_CTRL, ("Get port params\n"));
834 if (copyin( (int)arg, (caddr_t)&PortParams,
835 sizeof(struct PortParams)) == COPYFAIL) {
836 p->RIOError.Error = COPYIN_FAILED;
837 return EFAULT;
839 if (PortParams.Port >= RIO_PORTS) {
840 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
841 return ENXIO;
843 PortP = (p->RIOPortp[PortParams.Port]);
844 PortParams.Config = PortP->Config;
845 PortParams.State = PortP->State;
846 rio_dprint(RIO_DEBUG_CTRL, ("Port %d\n", PortParams.Port));
848 if (copyout((caddr_t)&PortParams, (int)arg,
849 sizeof(struct PortParams)) == COPYFAIL ) {
850 p->RIOError.Error = COPYOUT_FAILED;
851 return EFAULT;
853 return retval;
855 case RIO_GET_PORT_TTY :
856 rio_dprint(RIO_DEBUG_CTRL, ("Get port tty\n"));
857 if (copyin((int)arg, (caddr_t)&PortTty, sizeof(struct PortTty))
858 == COPYFAIL) {
859 p->RIOError.Error = COPYIN_FAILED;
860 return EFAULT;
862 if ( PortTty.port >= RIO_PORTS ) {
863 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
864 return ENXIO;
867 rio_dprint(RIO_DEBUG_CTRL, ("Port %d\n", PortTty.port));
868 PortP = (p->RIOPortp[PortTty.port]);
869 #if 0
870 PortTty.Tty.tm.c_iflag = PortP->TtyP->tm.c_iflag;
871 PortTty.Tty.tm.c_oflag = PortP->TtyP->tm.c_oflag;
872 PortTty.Tty.tm.c_cflag = PortP->TtyP->tm.c_cflag;
873 PortTty.Tty.tm.c_lflag = PortP->TtyP->tm.c_lflag;
874 #endif
875 if (copyout((caddr_t)&PortTty, (int)arg,
876 sizeof(struct PortTty)) == COPYFAIL) {
877 p->RIOError.Error = COPYOUT_FAILED;
878 return EFAULT;
880 return retval;
882 case RIO_SET_PORT_TTY :
883 if (copyin((int)arg, (caddr_t)&PortTty,
884 sizeof(struct PortTty)) == COPYFAIL) {
885 p->RIOError.Error = COPYIN_FAILED;
886 return EFAULT;
888 rio_dprint(RIO_DEBUG_CTRL, ("Set port %d tty\n", PortTty.port));
889 if (PortTty.port >= (ushort) RIO_PORTS) {
890 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
891 return ENXIO;
893 PortP = (p->RIOPortp[PortTty.port]);
894 #if 0
895 rio_spin_lock_irqsave(&PortP->portSem, flags);
896 PortP->TtyP->tm.c_iflag = PortTty.Tty.tm.c_iflag;
897 PortP->TtyP->tm.c_oflag = PortTty.Tty.tm.c_oflag;
898 PortP->TtyP->tm.c_cflag = PortTty.Tty.tm.c_cflag;
899 PortP->TtyP->tm.c_lflag = PortTty.Tty.tm.c_lflag;
900 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
901 #endif
903 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
904 return retval;
906 case RIO_SET_PORT_PARAMS :
907 rio_dprint(RIO_DEBUG_CTRL, ("Set port params\n"));
908 if ( copyin((int)arg, (caddr_t)&PortParams, sizeof(PortParams))
909 == COPYFAIL ) {
910 p->RIOError.Error = COPYIN_FAILED;
911 return EFAULT;
913 if (PortParams.Port >= (ushort) RIO_PORTS) {
914 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
915 return ENXIO;
917 PortP = (p->RIOPortp[PortParams.Port]);
918 rio_spin_lock_irqsave(&PortP->portSem, flags);
919 PortP->Config = PortParams.Config;
920 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
921 return retval;
923 case RIO_GET_PORT_STATS :
924 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GET_PORT_STATS\n"));
925 if ( copyin((int)arg, (caddr_t)&portStats,
926 sizeof(struct portStats)) == COPYFAIL ) {
927 p->RIOError.Error = COPYIN_FAILED;
928 return EFAULT;
930 if ( portStats.port >= RIO_PORTS ) {
931 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
932 return ENXIO;
934 PortP = (p->RIOPortp[portStats.port]);
935 portStats.gather = PortP->statsGather;
936 portStats.txchars = PortP->txchars;
937 portStats.rxchars = PortP->rxchars;
938 portStats.opens = PortP->opens;
939 portStats.closes = PortP->closes;
940 portStats.ioctls = PortP->ioctls;
941 if ( copyout((caddr_t)&portStats, (int)arg,
942 sizeof(struct portStats)) == COPYFAIL ) {
943 p->RIOError.Error = COPYOUT_FAILED;
944 return EFAULT;
946 return retval;
948 case RIO_RESET_PORT_STATS :
949 port = (uint) arg;
950 rio_dprint(RIO_DEBUG_CTRL, ("RIO_RESET_PORT_STATS\n"));
951 if ( port >= RIO_PORTS ) {
952 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
953 return ENXIO;
955 PortP = (p->RIOPortp[port]);
956 rio_spin_lock_irqsave(&PortP->portSem, flags);
957 PortP->txchars = 0;
958 PortP->rxchars = 0;
959 PortP->opens = 0;
960 PortP->closes = 0;
961 PortP->ioctls = 0;
962 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
963 return retval;
965 case RIO_GATHER_PORT_STATS :
966 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GATHER_PORT_STATS\n"));
967 if ( copyin( (int)arg, (caddr_t)&portStats,
968 sizeof(struct portStats)) == COPYFAIL ) {
969 p->RIOError.Error = COPYIN_FAILED;
970 return EFAULT;
972 if ( portStats.port >= RIO_PORTS ) {
973 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
974 return ENXIO;
976 PortP = (p->RIOPortp[portStats.port]);
977 rio_spin_lock_irqsave(&PortP->portSem, flags);
978 PortP->statsGather = portStats.gather;
979 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
980 return retval;
982 #ifdef DEBUG_SUPPORTED
983 case RIO_READ_LEVELS:
985 int num;
986 rio_dprint(RIO_DEBUG_CTRL, ("RIO_READ_LEVELS\n"));
987 for ( num=0; RIODbInf[num].Flag; num++ ) ;
988 rio_dprint(RIO_DEBUG_CTRL, ("%d levels to copy\n",num));
989 if (copyout((caddr_t)RIODbInf,(int)arg,
990 sizeof(struct DbInf)*(num+1))==COPYFAIL) {
991 rio_dprint(RIO_DEBUG_CTRL, ("ReadLevels Copy failed\n"));
992 p->RIOError.Error = COPYOUT_FAILED;
993 return EFAULT;
995 rio_dprint(RIO_DEBUG_CTRL, ("%d levels to copied\n",num));
996 return retval;
998 #endif
1000 case RIO_READ_CONFIG:
1001 rio_dprint(RIO_DEBUG_CTRL, ("RIO_READ_CONFIG\n"));
1002 if (copyout((caddr_t)&p->RIOConf, (int)arg,
1003 sizeof(struct Conf)) ==COPYFAIL ) {
1004 p->RIOError.Error = COPYOUT_FAILED;
1005 return EFAULT;
1007 return retval;
1009 case RIO_SET_CONFIG:
1010 rio_dprint(RIO_DEBUG_CTRL, ("RIO_SET_CONFIG\n"));
1011 if ( !su ) {
1012 p->RIOError.Error = NOT_SUPER_USER;
1013 return EPERM;
1015 if ( copyin((int)arg, (caddr_t)&p->RIOConf, sizeof(struct Conf) )
1016 ==COPYFAIL ) {
1017 p->RIOError.Error = COPYIN_FAILED;
1018 return EFAULT;
1021 ** move a few value around
1023 for (Host=0; Host < p->RIONumHosts; Host++)
1024 if ( (p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING )
1025 WWORD(p->RIOHosts[Host].ParmMapP->timer ,
1026 p->RIOConf.Timer);
1027 return retval;
1029 case RIO_START_POLLER:
1030 rio_dprint(RIO_DEBUG_CTRL, ("RIO_START_POLLER\n"));
1031 return EINVAL;
1033 case RIO_STOP_POLLER:
1034 rio_dprint(RIO_DEBUG_CTRL, ("RIO_STOP_POLLER\n"));
1035 if ( !su ) {
1036 p->RIOError.Error = NOT_SUPER_USER;
1037 return EPERM;
1039 p->RIOPolling = NOT_POLLING;
1040 return retval;
1042 case RIO_SETDEBUG:
1043 case RIO_GETDEBUG:
1044 rio_dprint(RIO_DEBUG_CTRL, ("RIO_SETDEBUG/RIO_GETDEBUG\n"));
1045 if ( copyin( (int)arg, (caddr_t)&DebugCtrl, sizeof(DebugCtrl) )
1046 ==COPYFAIL ) {
1047 p->RIOError.Error = COPYIN_FAILED;
1048 return EFAULT;
1050 if ( DebugCtrl.SysPort == NO_PORT ) {
1051 if ( cmd == RIO_SETDEBUG ) {
1052 if ( !su ) {
1053 p->RIOError.Error = NOT_SUPER_USER;
1054 return EPERM;
1056 p->rio_debug = DebugCtrl.Debug;
1057 p->RIODebugWait = DebugCtrl.Wait;
1058 rio_dprint(RIO_DEBUG_CTRL, ("Set global debug to 0x%x set wait to 0x%x\n",
1059 p->rio_debug,p->RIODebugWait));
1061 else {
1062 rio_dprint(RIO_DEBUG_CTRL, ("Get global debug 0x%x wait 0x%x\n",
1063 p->rio_debug,p->RIODebugWait));
1064 DebugCtrl.Debug = p->rio_debug;
1065 DebugCtrl.Wait = p->RIODebugWait;
1066 if ( copyout((caddr_t)&DebugCtrl,(int)arg,
1067 sizeof(DebugCtrl)) == COPYFAIL ) {
1068 rio_dprint(RIO_DEBUG_CTRL, ("RIO_SET/GET DEBUG: bad port number %d\n",
1069 DebugCtrl.SysPort));
1070 p->RIOError.Error = COPYOUT_FAILED;
1071 return EFAULT;
1075 else if ( DebugCtrl.SysPort >= RIO_PORTS &&
1076 DebugCtrl.SysPort != NO_PORT ) {
1077 rio_dprint(RIO_DEBUG_CTRL, ("RIO_SET/GET DEBUG: bad port number %d\n",
1078 DebugCtrl.SysPort));
1079 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1080 return ENXIO;
1082 else if ( cmd == RIO_SETDEBUG ) {
1083 if ( !su ) {
1084 p->RIOError.Error = NOT_SUPER_USER;
1085 return EPERM;
1087 rio_spin_lock_irqsave(&PortP->portSem, flags);
1088 p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
1089 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
1090 rio_dprint(RIO_DEBUG_CTRL, ("RIO_SETDEBUG 0x%x\n",
1091 p->RIOPortp[DebugCtrl.SysPort]->Debug));
1093 else {
1094 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GETDEBUG 0x%x\n",
1095 p->RIOPortp[DebugCtrl.SysPort]->Debug));
1096 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
1097 if ( copyout((caddr_t)&DebugCtrl,(int)arg,
1098 sizeof(DebugCtrl))==COPYFAIL ) {
1099 rio_dprint(RIO_DEBUG_CTRL, ("RIO_GETDEBUG: Bad copy to user space\n"));
1100 p->RIOError.Error = COPYOUT_FAILED;
1101 return EFAULT;
1104 return retval;
1106 case RIO_VERSID:
1108 ** Enquire about the release and version.
1109 ** We return MAX_VERSION_LEN bytes, being a
1110 ** textual null terminated string.
1112 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID\n") );
1113 if ( copyout( (caddr_t)RIOVersid(),
1114 (int)arg,
1115 sizeof(struct rioVersion) ) == COPYFAIL )
1117 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID: Bad copy to user space (host=%d)\n",Host) );
1118 p->RIOError.Error = COPYOUT_FAILED;
1119 return EFAULT;
1121 return retval;
1124 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1125 ** !! commented out previous 'RIO_VERSID' functionality !!
1126 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1128 case RIO_VERSID:
1130 ** Enquire about the release and version.
1131 ** We return MAX_VERSION_LEN bytes, being a textual null
1132 ** terminated string.
1134 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID\n"));
1135 if (copyout((caddr_t)RIOVersid(),
1136 (int)arg, MAX_VERSION_LEN ) == COPYFAIL ) {
1137 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID: Bad copy to user space\n",Host));
1138 p->RIOError.Error = COPYOUT_FAILED;
1139 return EFAULT;
1141 return retval;
1143 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1146 case RIO_NUM_HOSTS:
1148 ** Enquire as to the number of hosts located
1149 ** at init time.
1151 rio_dprint(RIO_DEBUG_CTRL, ("RIO_NUM_HOSTS\n"));
1152 if (copyout((caddr_t)&p->RIONumHosts, (int)arg,
1153 sizeof(p->RIONumHosts) )==COPYFAIL ) {
1154 rio_dprint(RIO_DEBUG_CTRL, ("RIO_NUM_HOSTS: Bad copy to user space\n"));
1155 p->RIOError.Error = COPYOUT_FAILED;
1156 return EFAULT;
1158 return retval;
1160 case RIO_HOST_FOAD:
1162 ** Kill host. This may not be in the final version...
1164 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_FOAD %d\n", (int)arg));
1165 if ( !su ) {
1166 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_FOAD: Not super user\n"));
1167 p->RIOError.Error = NOT_SUPER_USER;
1168 return EPERM;
1170 p->RIOHalted = 1;
1171 p->RIOSystemUp = 0;
1173 for ( Host=0; Host<p->RIONumHosts; Host++ ) {
1174 (void)RIOBoardTest( p->RIOHosts[Host].PaddrP,
1175 p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type,
1176 p->RIOHosts[Host].Slot );
1177 bzero( (caddr_t)&p->RIOHosts[Host].Flags,
1178 ((int)&p->RIOHosts[Host].____end_marker____) -
1179 ((int)&p->RIOHosts[Host].Flags) );
1180 p->RIOHosts[Host].Flags = RC_WAITING;
1181 #if 0
1182 RIOSetupDataStructs(p);
1183 #endif
1185 RIOFoadWakeup(p);
1186 p->RIONumBootPkts = 0;
1187 p->RIOBooting = 0;
1189 #ifdef RINGBUFFER_SUPPORT
1190 for( loop=0; loop<RIO_PORTS; loop++ )
1191 if ( p->RIOPortp[loop]->TxRingBuffer )
1192 sysfree((void *)p->RIOPortp[loop]->TxRingBuffer,
1193 RIOBufferSize );
1194 #endif
1195 #if 0
1196 bzero((caddr_t)&p->RIOPortp[0],RIO_PORTS*sizeof(struct Port));
1197 #else
1198 printk ("HEEEEELP!\n");
1199 #endif
1201 for( loop=0; loop<RIO_PORTS; loop++ ) {
1202 #if 0
1203 p->RIOPortp[loop]->TtyP = &p->channel[loop];
1204 #endif
1206 p->RIOPortp[loop]->portSem = SPIN_LOCK_UNLOCKED;
1207 p->RIOPortp[loop]->InUse = NOT_INUSE;
1210 p->RIOSystemUp = 0;
1211 return retval;
1213 case RIO_DOWNLOAD:
1214 rio_dprint(RIO_DEBUG_CTRL, ("RIO_DOWNLOAD\n"));
1215 if ( !su ) {
1216 rio_dprint(RIO_DEBUG_CTRL, ("RIO_DOWNLOAD: Not super user\n"));
1217 p->RIOError.Error = NOT_SUPER_USER;
1218 return EPERM;
1220 if ( copyin((int)arg, (caddr_t)&DownLoad,
1221 sizeof(DownLoad) )==COPYFAIL ) {
1222 rio_dprint(RIO_DEBUG_CTRL, ("RIO_DOWNLOAD: Copy in from user space failed\n"));
1223 p->RIOError.Error = COPYIN_FAILED;
1224 return EFAULT;
1226 rio_dprint(RIO_DEBUG_CTRL, ("Copied in download code for product code 0x%x\n",
1227 DownLoad.ProductCode ) );
1230 ** It is important that the product code is an unsigned object!
1232 if ( DownLoad.ProductCode > MAX_PRODUCT ) {
1233 rio_dprint(RIO_DEBUG_CTRL, ("RIO_DOWNLOAD: Bad product code %d passed\n",
1234 DownLoad.ProductCode));
1235 p->RIOError.Error = NO_SUCH_PRODUCT;
1236 return ENXIO;
1239 ** do something!
1241 retval = (*(RIOBootTable[DownLoad.ProductCode]))(p, &DownLoad);
1242 /* <-- Panic */
1243 p->RIOHalted = 0;
1245 ** and go back, content with a job well completed.
1247 return retval;
1249 case RIO_PARMS:
1251 uint host;
1253 if (copyin((int)arg, (caddr_t)&host,
1254 sizeof(host) ) == COPYFAIL ) {
1255 rio_dprint(RIO_DEBUG_CTRL, (
1256 "RIO_HOST_REQ: Copy in from user space failed\n"));
1257 p->RIOError.Error = COPYIN_FAILED;
1258 return EFAULT;
1261 ** Fetch the parmmap
1263 rio_dprint(RIO_DEBUG_CTRL, ("RIO_PARMS\n"));
1264 if ( copyout( (caddr_t)p->RIOHosts[host].ParmMapP,
1265 (int)arg, sizeof(PARM_MAP) )==COPYFAIL ) {
1266 p->RIOError.Error = COPYOUT_FAILED;
1267 rio_dprint(RIO_DEBUG_CTRL, ("RIO_PARMS: Copy out to user space failed\n"));
1268 return EFAULT;
1271 return retval;
1273 case RIO_HOST_REQ:
1274 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_REQ\n"));
1275 if (copyin((int)arg, (caddr_t)&HostReq,
1276 sizeof(HostReq) )==COPYFAIL ) {
1277 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_REQ: Copy in from user space failed\n"));
1278 p->RIOError.Error = COPYIN_FAILED;
1279 return EFAULT;
1281 if ( HostReq.HostNum >= p->RIONumHosts ) {
1282 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1283 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_REQ: Illegal host number %d\n",
1284 HostReq.HostNum));
1285 return ENXIO;
1287 rio_dprint(RIO_DEBUG_CTRL, ("Request for host %d\n", HostReq.HostNum));
1289 if (copyout((caddr_t)&p->RIOHosts[HostReq.HostNum],
1290 (int)HostReq.HostP,sizeof(struct Host) ) == COPYFAIL) {
1291 p->RIOError.Error = COPYOUT_FAILED;
1292 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_REQ: Bad copy to user space\n"));
1293 return EFAULT;
1295 return retval;
1297 case RIO_HOST_DPRAM:
1298 rio_dprint(RIO_DEBUG_CTRL, ("Request for DPRAM\n"));
1299 if ( copyin( (int)arg, (caddr_t)&HostDpRam,
1300 sizeof(HostDpRam) )==COPYFAIL ) {
1301 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_DPRAM: Copy in from user space failed\n"));
1302 p->RIOError.Error = COPYIN_FAILED;
1303 return EFAULT;
1305 if ( HostDpRam.HostNum >= p->RIONumHosts ) {
1306 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1307 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_DPRAM: Illegal host number %d\n",
1308 HostDpRam.HostNum));
1309 return ENXIO;
1311 rio_dprint(RIO_DEBUG_CTRL, ("Request for host %d\n", HostDpRam.HostNum));
1313 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
1314 int off;
1315 /* It's hardware like this that really gets on my tits. */
1316 static unsigned char copy[sizeof(struct DpRam)];
1317 for ( off=0; off<sizeof(struct DpRam); off++ )
1318 copy[off] = p->RIOHosts[HostDpRam.HostNum].Caddr[off];
1319 if ( copyout( (caddr_t)copy, (int)HostDpRam.DpRamP,
1320 sizeof(struct DpRam) ) == COPYFAIL ) {
1321 p->RIOError.Error = COPYOUT_FAILED;
1322 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_DPRAM: Bad copy to user space\n"));
1323 return EFAULT;
1326 else if (copyout((caddr_t)p->RIOHosts[HostDpRam.HostNum].Caddr,
1327 (int)HostDpRam.DpRamP,
1328 sizeof(struct DpRam) ) == COPYFAIL ) {
1329 p->RIOError.Error = COPYOUT_FAILED;
1330 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_DPRAM: Bad copy to user space\n"));
1331 return EFAULT;
1333 return retval;
1335 case RIO_SET_BUSY:
1336 rio_dprint(RIO_DEBUG_CTRL, ("RIO_SET_BUSY\n"));
1337 if ( (int)arg < 0 || (int)arg > 511 ) {
1338 rio_dprint(RIO_DEBUG_CTRL, ("RIO_SET_BUSY: Bad port number %d\n",(int)arg));
1339 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1340 return EINVAL;
1342 rio_spin_lock_irqsave(&PortP->portSem, flags);
1343 p->RIOPortp[(int)arg]->State |= RIO_BUSY;
1344 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
1345 return retval;
1347 case RIO_HOST_PORT:
1349 ** The daemon want port information
1350 ** (probably for debug reasons)
1352 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_PORT\n"));
1353 if ( copyin((int)arg, (caddr_t)&PortReq,
1354 sizeof(PortReq) )==COPYFAIL ) {
1355 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_PORT: Copy in from user space failed\n"));
1356 p->RIOError.Error = COPYIN_FAILED;
1357 return EFAULT;
1360 if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
1361 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_PORT: Illegal port number %d\n",
1362 PortReq.SysPort));
1363 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1364 return ENXIO;
1366 rio_dprint(RIO_DEBUG_CTRL, ("Request for port %d\n", PortReq.SysPort));
1367 if (copyout((caddr_t)p->RIOPortp[PortReq.SysPort],
1368 (int)PortReq.PortP,
1369 sizeof(struct Port) ) == COPYFAIL) {
1370 p->RIOError.Error = COPYOUT_FAILED;
1371 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_PORT: Bad copy to user space\n"));
1372 return EFAULT;
1374 return retval;
1376 case RIO_HOST_RUP:
1378 ** The daemon want rup information
1379 ** (probably for debug reasons)
1381 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_RUP\n"));
1382 if (copyin((int)arg, (caddr_t)&RupReq,
1383 sizeof(RupReq) )==COPYFAIL ) {
1384 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_RUP: Copy in from user space failed\n"));
1385 p->RIOError.Error = COPYIN_FAILED;
1386 return EFAULT;
1388 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1389 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_RUP: Illegal host number %d\n",
1390 RupReq.HostNum));
1391 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1392 return ENXIO;
1394 if ( RupReq.RupNum >= MAX_RUP+LINKS_PER_UNIT ) { /* eek! */
1395 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_RUP: Illegal rup number %d\n",
1396 RupReq.RupNum));
1397 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1398 return EINVAL;
1400 HostP = &p->RIOHosts[RupReq.HostNum];
1402 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1403 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_RUP: Host %d not running\n",
1404 RupReq.HostNum));
1405 p->RIOError.Error = HOST_NOT_RUNNING;
1406 return EIO;
1408 rio_dprint(RIO_DEBUG_CTRL, ("Request for rup %d from host %d\n",
1409 RupReq.RupNum,RupReq.HostNum));
1411 if (copyout((caddr_t)HostP->UnixRups[RupReq.RupNum].RupP,
1412 (int)RupReq.RupP,sizeof(struct RUP) ) == COPYFAIL) {
1413 p->RIOError.Error = COPYOUT_FAILED;
1414 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_RUP: Bad copy to user space\n"));
1415 return EFAULT;
1417 return retval;
1419 case RIO_HOST_LPB:
1421 ** The daemon want lpb information
1422 ** (probably for debug reasons)
1424 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_LPB\n"));
1425 if (copyin((int)arg, (caddr_t)&LpbReq,
1426 sizeof(LpbReq) )==COPYFAIL ) {
1427 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_LPB: Bad copy from user space\n"));
1428 p->RIOError.Error = COPYIN_FAILED;
1429 return EFAULT;
1431 if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
1432 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_LPB: Illegal host number %d\n",
1433 LpbReq.Host));
1434 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1435 return ENXIO;
1437 if ( LpbReq.Link >= LINKS_PER_UNIT ) { /* eek! */
1438 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_LPB: Illegal link number %d\n",
1439 LpbReq.Link));
1440 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1441 return EINVAL;
1443 HostP = &p->RIOHosts[LpbReq.Host];
1445 if ( (HostP->Flags & RUN_STATE) != RC_RUNNING ) {
1446 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_LPB: Host %d not running\n",
1447 LpbReq.Host));
1448 p->RIOError.Error = HOST_NOT_RUNNING;
1449 return EIO;
1451 rio_dprint(RIO_DEBUG_CTRL, ("Request for lpb %d from host %d\n",
1452 LpbReq.Link, LpbReq.Host));
1454 if (copyout((caddr_t)&HostP->LinkStrP[LpbReq.Link],
1455 (int)LpbReq.LpbP,sizeof(struct LPB) ) == COPYFAIL) {
1456 rio_dprint(RIO_DEBUG_CTRL, ("RIO_HOST_LPB: Bad copy to user space\n"));
1457 p->RIOError.Error = COPYOUT_FAILED;
1458 return EFAULT;
1460 return retval;
1463 ** Here 3 IOCTL's that allow us to change the way in which
1464 ** rio logs errors. send them just to syslog or send them
1465 ** to both syslog and console or send them to just the console.
1467 ** See RioStrBuf() in util.c for the other half.
1469 case RIO_SYSLOG_ONLY:
1470 p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
1471 return 0;
1473 case RIO_SYSLOG_CONS:
1474 p->RIOPrintLogState = PRINT_TO_LOG_CONS;/* syslog and console */
1475 return 0;
1477 case RIO_CONS_ONLY:
1478 p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
1479 return 0;
1481 case RIO_SIGNALS_ON:
1482 if ( p->RIOSignalProcess ) {
1483 p->RIOError.Error = SIGNALS_ALREADY_SET;
1484 return EBUSY;
1486 p->RIOSignalProcess = getpid();
1487 p->RIOPrintDisabled = DONT_PRINT;
1488 return retval;
1490 case RIO_SIGNALS_OFF:
1491 if ( p->RIOSignalProcess != getpid() ) {
1492 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1493 return EPERM;
1495 rio_dprint(RIO_DEBUG_CTRL, ("Clear signal process to zero\n"));
1496 p->RIOSignalProcess = 0;
1497 return retval;
1499 case RIO_SET_BYTE_MODE:
1500 for ( Host=0; Host<p->RIONumHosts; Host++ )
1501 if ( p->RIOHosts[Host].Type == RIO_AT )
1502 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1503 return retval;
1505 case RIO_SET_WORD_MODE:
1506 for ( Host=0; Host<p->RIONumHosts; Host++ )
1507 if ( p->RIOHosts[Host].Type == RIO_AT )
1508 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1509 return retval;
1511 case RIO_SET_FAST_BUS:
1512 for ( Host=0; Host<p->RIONumHosts; Host++ )
1513 if ( p->RIOHosts[Host].Type == RIO_AT )
1514 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1515 return retval;
1517 case RIO_SET_SLOW_BUS:
1518 for ( Host=0; Host<p->RIONumHosts; Host++ )
1519 if ( p->RIOHosts[Host].Type == RIO_AT )
1520 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1521 return retval;
1523 case RIO_MAP_B50_TO_50:
1524 case RIO_MAP_B50_TO_57600:
1525 case RIO_MAP_B110_TO_110:
1526 case RIO_MAP_B110_TO_115200:
1527 rio_dprint(RIO_DEBUG_CTRL, ("Baud rate mapping\n"));
1528 port = (uint) arg;
1529 if ( port < 0 || port > 511 ) {
1530 rio_dprint(RIO_DEBUG_CTRL, ("Baud rate mapping: Bad port number %d\n", port));
1531 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1532 return EINVAL;
1534 rio_spin_lock_irqsave(&PortP->portSem, flags);
1535 switch( cmd )
1537 case RIO_MAP_B50_TO_50 :
1538 p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1539 break;
1540 case RIO_MAP_B50_TO_57600 :
1541 p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1542 break;
1543 case RIO_MAP_B110_TO_110 :
1544 p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1545 break;
1546 case RIO_MAP_B110_TO_115200 :
1547 p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1548 break;
1550 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
1551 return retval;
1553 case RIO_STREAM_INFO:
1554 rio_dprint(RIO_DEBUG_CTRL, ("RIO_STREAM_INFO\n"));
1555 return EINVAL;
1557 case RIO_SEND_PACKET:
1558 rio_dprint(RIO_DEBUG_CTRL, ("RIO_SEND_PACKET\n"));
1559 if ( copyin( (int)arg, (caddr_t)&SendPack,
1560 sizeof(SendPack) )==COPYFAIL ) {
1561 rio_dprint(RIO_DEBUG_CTRL, ("RIO_SEND_PACKET: Bad copy from user space\n"));
1562 p->RIOError.Error = COPYIN_FAILED;
1563 return EFAULT;
1565 if ( SendPack.PortNum >= 128 ) {
1566 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1567 return ENXIO;
1570 PortP = p->RIOPortp[SendPack.PortNum];
1571 rio_spin_lock_irqsave(&PortP->portSem, flags);
1573 if ( !can_add_transmit(&PacketP,PortP) ) {
1574 p->RIOError.Error = UNIT_IS_IN_USE;
1575 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
1576 return ENOSPC;
1579 for ( loop=0; loop<(ushort)(SendPack.Len & 127); loop++ )
1580 WBYTE(PacketP->data[loop], SendPack.Data[loop] );
1582 WBYTE(PacketP->len, SendPack.Len);
1584 add_transmit( PortP );
1586 ** Count characters transmitted for port statistics reporting
1588 if (PortP->statsGather)
1589 PortP->txchars += (SendPack.Len & 127);
1590 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
1591 return retval;
1593 case RIO_NO_MESG:
1594 if ( su )
1595 p->RIONoMessage = 1;
1596 return su ? 0 : EPERM;
1598 case RIO_MESG:
1599 if ( su )
1600 p->RIONoMessage = 0;
1601 return su ? 0 : EPERM;
1603 case RIO_WHAT_MESG:
1604 if ( copyout( (caddr_t)&p->RIONoMessage, (int)arg,
1605 sizeof(p->RIONoMessage) )==COPYFAIL ) {
1606 rio_dprint(RIO_DEBUG_CTRL, ("RIO_WHAT_MESG: Bad copy to user space\n"));
1607 p->RIOError.Error = COPYOUT_FAILED;
1608 return EFAULT;
1610 return 0;
1612 case RIO_MEM_DUMP :
1613 if (copyin((int)arg, (caddr_t)&SubCmd,
1614 sizeof(struct SubCmdStruct)) == COPYFAIL) {
1615 p->RIOError.Error = COPYIN_FAILED;
1616 return EFAULT;
1618 rio_dprint(RIO_DEBUG_CTRL, ("RIO_MEM_DUMP host %d rup %d addr %x\n",
1619 SubCmd.Host, SubCmd.Rup, SubCmd.Addr));
1621 if (SubCmd.Rup >= MAX_RUP+LINKS_PER_UNIT ) {
1622 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1623 return EINVAL;
1626 if (SubCmd.Host >= p->RIONumHosts ) {
1627 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1628 return EINVAL;
1631 port = p->RIOHosts[SubCmd.Host].
1632 UnixRups[SubCmd.Rup].BaseSysPort;
1634 PortP = p->RIOPortp[port];
1636 rio_spin_lock_irqsave(&PortP->portSem, flags);
1638 if ( RIOPreemptiveCmd(p, PortP, MEMDUMP ) == RIO_FAIL ) {
1639 rio_dprint(RIO_DEBUG_CTRL, ("RIO_MEM_DUMP failed\n"));
1640 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
1641 return EBUSY;
1643 else
1644 PortP->State |= RIO_BUSY;
1646 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
1647 if ( copyout( (caddr_t)p->RIOMemDump, (int)arg,
1648 MEMDUMP_SIZE) == COPYFAIL ) {
1649 rio_dprint(RIO_DEBUG_CTRL, ("RIO_MEM_DUMP copy failed\n"));
1650 p->RIOError.Error = COPYOUT_FAILED;
1651 return EFAULT;
1653 return 0;
1655 case RIO_TICK:
1656 if ((int)arg < 0 || (int)arg >= p->RIONumHosts)
1657 return EINVAL;
1658 rio_dprint(RIO_DEBUG_CTRL, ("Set interrupt for host %d\n", (int)arg ));
1659 WBYTE(p->RIOHosts[(int)arg].SetInt , 0xff);
1660 return 0;
1662 case RIO_TOCK:
1663 if ((int)arg < 0 || (int)arg >= p->RIONumHosts)
1664 return EINVAL;
1665 rio_dprint(RIO_DEBUG_CTRL, ("Clear interrupt for host %d\n", (int)arg ));
1666 WBYTE((p->RIOHosts[(int)arg].ResetInt) , 0xff);
1667 return 0;
1669 case RIO_READ_CHECK:
1670 /* Check reads for pkts with data[0] the same */
1671 p->RIOReadCheck = !p->RIOReadCheck;
1672 if (copyout((caddr_t)&p->RIOReadCheck,(int)arg,
1673 sizeof(uint))== COPYFAIL) {
1674 p->RIOError.Error = COPYOUT_FAILED;
1675 return EFAULT;
1677 return 0;
1679 case RIO_READ_REGISTER :
1680 if (copyin((int)arg, (caddr_t)&SubCmd,
1681 sizeof(struct SubCmdStruct)) == COPYFAIL) {
1682 p->RIOError.Error = COPYIN_FAILED;
1683 return EFAULT;
1685 rio_dprint(RIO_DEBUG_CTRL, ("RIO_READ_REGISTER host %d rup %d port %d reg %x\n",
1686 SubCmd.Host, SubCmd.Rup, SubCmd.Port, SubCmd.Addr));
1688 if (SubCmd.Port > 511) {
1689 rio_dprint(RIO_DEBUG_CTRL, ("Baud rate mapping: Bad port number %d\n",
1690 SubCmd.Port));
1691 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1692 return EINVAL;
1695 if (SubCmd.Rup >= MAX_RUP+LINKS_PER_UNIT ) {
1696 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1697 return EINVAL;
1700 if (SubCmd.Host >= p->RIONumHosts ) {
1701 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1702 return EINVAL;
1705 port = p->RIOHosts[SubCmd.Host].
1706 UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1707 PortP = p->RIOPortp[port];
1709 rio_spin_lock_irqsave(&PortP->portSem, flags);
1711 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
1712 rio_dprint(RIO_DEBUG_CTRL, ("RIO_READ_REGISTER failed\n"));
1713 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
1714 return EBUSY;
1716 else
1717 PortP->State |= RIO_BUSY;
1719 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
1720 if (copyout((caddr_t)&p->CdRegister, (int)arg,
1721 sizeof(uint)) == COPYFAIL ) {
1722 rio_dprint(RIO_DEBUG_CTRL, ("RIO_READ_REGISTER copy failed\n"));
1723 p->RIOError.Error = COPYOUT_FAILED;
1724 return EFAULT;
1726 return 0;
1728 ** rio_make_dev: given port number (0-511) ORed with port type
1729 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1730 ** value to pass to mknod to create the correct device node.
1732 case RIO_MAKE_DEV:
1734 uint port = (uint)arg & RIO_MODEM_MASK;
1736 switch ( (uint)arg & RIO_DEV_MASK ) {
1737 case RIO_DEV_DIRECT:
1738 arg = (caddr_t)drv_makedev(major(dev), port);
1739 rio_dprint(RIO_DEBUG_CTRL, ("Makedev direct 0x%x is 0x%x\n",port, (int)arg ));
1740 return (int)arg;
1741 case RIO_DEV_MODEM:
1742 arg = (caddr_t)drv_makedev(major(dev), (port|RIO_MODEM_BIT) );
1743 rio_dprint(RIO_DEBUG_CTRL, ("Makedev modem 0x%x is 0x%x\n",port, (int)arg ));
1744 return (int)arg;
1745 case RIO_DEV_XPRINT:
1746 arg = (caddr_t)drv_makedev(major(dev), port);
1747 rio_dprint(RIO_DEBUG_CTRL, ("Makedev printer 0x%x is 0x%x\n",port, (int)arg ));
1748 return (int)arg;
1750 rio_dprint(RIO_DEBUG_CTRL, ("MAKE Device is called\n"));
1751 return EINVAL;
1754 ** rio_minor: given a dev_t from a stat() call, return
1755 ** the port number (0-511) ORed with the port type
1756 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1758 case RIO_MINOR:
1760 dev_t dv;
1761 int mino;
1763 dv = (dev_t)((int)arg);
1764 mino = RIO_UNMODEM(dv);
1766 if ( RIO_ISMODEM(dv) ) {
1767 rio_dprint(RIO_DEBUG_CTRL, ("Minor for device 0x%x: modem %d\n", dv, mino));
1768 arg = (caddr_t)(mino | RIO_DEV_MODEM);
1770 else {
1771 rio_dprint(RIO_DEBUG_CTRL, ("Minor for device 0x%x: direct %d\n", dv, mino));
1772 arg = (caddr_t)(mino | RIO_DEV_DIRECT);
1774 return (int)arg;
1777 rio_dprint(RIO_DEBUG_CTRL, ("INVALID DAEMON IOCTL 0x%x\n",cmd));
1778 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1779 return EINVAL;
1783 ** Pre-emptive commands go on RUPs and are only one byte long.
1786 RIOPreemptiveCmd(p, PortP, Cmd)
1787 struct rio_info * p;
1788 struct Port *PortP;
1789 uchar Cmd;
1791 struct CmdBlk *CmdBlkP;
1792 struct PktCmd_M *PktCmdP;
1793 int Ret;
1794 ushort rup;
1795 int port;
1797 #ifdef CHECK
1798 CheckPortP( PortP );
1799 #endif
1801 if ( PortP->State & RIO_DELETED ) {
1802 rio_dprint(RIO_DEBUG_CTRL, ("Preemptive command to deleted RTA ignored\n"));
1803 return RIO_FAIL;
1806 if (((int)((char)PortP->InUse) == -1) || ! (CmdBlkP = RIOGetCmdBlk()) ) {
1807 rio_dprint(RIO_DEBUG_CTRL, ("Cannot allocate command block for command %d on port %d\n",
1808 Cmd, PortP->PortNum));
1809 return RIO_FAIL;
1812 rio_dprint(RIO_DEBUG_CTRL, ("Command blk 0x%x - InUse now %d\n",
1813 (int)CmdBlkP,PortP->InUse));
1815 PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
1817 CmdBlkP->Packet.src_unit = 0;
1818 if (PortP->SecondBlock)
1819 rup = PortP->ID2;
1820 else
1821 rup = PortP->RupNum;
1822 CmdBlkP->Packet.dest_unit = rup;
1823 CmdBlkP->Packet.src_port = COMMAND_RUP;
1824 CmdBlkP->Packet.dest_port = COMMAND_RUP;
1825 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1826 CmdBlkP->PostFuncP = RIOUnUse;
1827 CmdBlkP->PostArg = (int)PortP;
1828 PktCmdP->Command = Cmd;
1829 port = PortP->HostPort % (ushort)PORTS_PER_RTA;
1831 ** Index ports 8-15 for 2nd block of 16 port RTA.
1833 if (PortP->SecondBlock)
1834 port += (ushort) PORTS_PER_RTA;
1835 PktCmdP->PhbNum = port;
1837 switch ( Cmd ) {
1838 case MEMDUMP:
1839 rio_dprint(RIO_DEBUG_CTRL, ("Queue MEMDUMP command blk 0x%x (addr 0x%x)\n",
1840 (int)CmdBlkP, (int)SubCmd.Addr));
1841 PktCmdP->SubCommand = MEMDUMP;
1842 PktCmdP->SubAddr = SubCmd.Addr;
1843 break;
1844 case FCLOSE:
1845 rio_dprint(RIO_DEBUG_CTRL, ("Queue FCLOSE command blk 0x%x\n",(int)CmdBlkP));
1846 break;
1847 case READ_REGISTER:
1848 rio_dprint(RIO_DEBUG_CTRL, ("Queue READ_REGISTER (0x%x) command blk 0x%x\n",
1849 (int)SubCmd.Addr, (int)CmdBlkP));
1850 PktCmdP->SubCommand = READ_REGISTER;
1851 PktCmdP->SubAddr = SubCmd.Addr;
1852 break;
1853 case RESUME:
1854 rio_dprint(RIO_DEBUG_CTRL, ("Queue RESUME command blk 0x%x\n",(int)CmdBlkP));
1855 break;
1856 case RFLUSH:
1857 rio_dprint(RIO_DEBUG_CTRL, ("Queue RFLUSH command blk 0x%x\n",(int)CmdBlkP));
1858 CmdBlkP->PostFuncP = RIORFlushEnable;
1859 break;
1860 case SUSPEND:
1861 rio_dprint(RIO_DEBUG_CTRL, ("Queue SUSPEND command blk 0x%x\n",(int)CmdBlkP));
1862 break;
1864 case MGET :
1865 rio_dprint(RIO_DEBUG_CTRL, ("Queue MGET command blk 0x%x\n", (int)CmdBlkP));
1866 break;
1868 case MSET :
1869 case MBIC :
1870 case MBIS :
1871 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
1872 rio_dprint(RIO_DEBUG_CTRL, ("Queue MSET/MBIC/MBIS command blk 0x%x\n", (int)CmdBlkP));
1873 break;
1875 case WFLUSH:
1877 ** If we have queued up the maximum number of Write flushes
1878 ** allowed then we should not bother sending any more to the
1879 ** RTA.
1881 if ((int)((char)PortP->WflushFlag) == (int)-1) {
1882 rio_dprint(RIO_DEBUG_CTRL, ("Trashed WFLUSH, WflushFlag about to wrap!"));
1883 RIOFreeCmdBlk(CmdBlkP);
1884 return(RIO_FAIL);
1885 } else {
1886 rio_dprint(RIO_DEBUG_CTRL, ("Queue WFLUSH command blk 0x%x\n",
1887 (int)CmdBlkP));
1888 CmdBlkP->PostFuncP = RIOWFlushMark;
1890 break;
1893 PortP->InUse++;
1895 Ret = RIOQueueCmdBlk( PortP->HostP, rup, CmdBlkP );
1897 return Ret;