2 ** -----------------------------------------------------------------------------
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.
25 ** Last Modified : 11/6/98 10:33:42
26 ** Retrieved : 11/6/98 10:33:49
28 ** ident @(#)rioctrl.c 1.3
30 ** -----------------------------------------------------------------------------
33 static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c 1.3";
37 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/errno.h>
41 #include <asm/system.h>
42 #include <asm/string.h>
43 #include <asm/semaphore.h>
44 #include <asm/uaccess.h>
46 #include <linux/termios.h>
47 #include <linux/serial.h>
49 #include <linux/generic_serial.h>
52 #include "linux_compat.h"
53 #include "rio_linux.h"
85 static struct LpbReq LpbReq;
86 static struct RupReq RupReq;
87 static struct PortReq PortReq;
88 static struct HostReq HostReq;
89 static struct HostDpRam HostDpRam;
90 static struct DebugCtrl DebugCtrl;
91 static struct Map MapEnt;
92 static struct PortSetup PortSetup;
93 static struct DownLoad DownLoad;
94 static struct SendPack SendPack;
95 /* static struct StreamInfo StreamInfo; */
96 /* static char modemtable[RIO_PORTS]; */
97 static struct SpecialRupCmd SpecialRupCmd;
98 static struct PortParams PortParams;
99 static struct portStats portStats;
101 static struct SubCmdStruct {
110 struct ttystatics Tty;
113 static struct PortTty PortTty;
114 typedef struct ttystatics TERMIO;
117 ** This table is used when the config.rio downloads bin code to the
118 ** driver. We index the table using the product code, 0-F, and call
119 ** the function pointed to by the entry, passing the information
121 ** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
122 ** process to bog off.
125 (*RIOBootTable[MAX_PRODUCT]) (struct rio_info *, struct DownLoad *) = {
126 /* 0 */ RIOBootCodeHOST,
128 /* 1 */ RIOBootCodeRTA,
132 #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
134 int copyin(int arg, caddr_t dp, int siz)
138 rio_dprintk(RIO_DEBUG_CTRL, "Copying %d bytes from user %p to %p.\n", siz, (void *) arg, dp);
139 rv = copy_from_user(dp, (void *) arg, siz);
146 static int copyout(caddr_t dp, int arg, int siz)
150 rio_dprintk(RIO_DEBUG_CTRL, "Copying %d bytes to user %p from %p.\n", siz, (void *) arg, dp);
151 rv = copy_to_user((void *) arg, dp, siz);
158 int riocontrol(p, dev, cmd, arg, su)
165 uint Host; /* leave me unsigned! */
166 uint port; /* and me! */
177 /* Confuse the compiler to think that we've initialized these */
181 rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: 0x%x\n", cmd, (int) arg);
187 ** Change the value of the host card interrupt timer.
188 ** If the host card number is -1 then all host cards are changed
189 ** otherwise just the specified host card will be changed.
192 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %dms\n", (uint) arg);
195 host = (uint) arg >> 16;
196 value = (uint) arg & 0x0000ffff;
198 for (host = 0; host < p->RIONumHosts; host++) {
199 if (p->RIOHosts[host].Flags == RC_RUNNING) {
200 WWORD(p->RIOHosts[host].ParmMapP->timer, value);
203 } else if (host >= p->RIONumHosts) {
206 if (p->RIOHosts[host].Flags == RC_RUNNING) {
207 WWORD(p->RIOHosts[host].ParmMapP->timer, value);
213 case RIO_IDENTIFY_DRIVER:
215 ** 15.10.1998 ARG - ESIL 0760 part fix
216 ** Added driver ident string output.
218 #ifndef __THIS_RELEASE__
219 #warning Driver Version string not defined !
221 cprintf("%s %s %s %s\n",
224 __DATE__, __TIME__ );
228 case RIO_DISPLAY_HOST_CFG:
230 ** 15.10.1998 ARG - ESIL 0760 part fix
231 ** Added driver host card ident string output.
233 ** Note that the only types currently supported
234 ** are ISA and PCI. Also this driver does not
235 ** (yet) distinguish between the Old PCI card
236 ** and the Jet PCI card. In fact I think this
237 ** driver only supports JET PCI !
240 for (Host = 0; Host < p->RIONumHosts; Host++)
242 HostP = &(p->RIOHosts[Host]);
244 switch ( HostP->Type )
247 strcpy( host_type, RIO_AT_HOST_STR );
251 strcpy( host_type, RIO_PCI_HOST_STR );
255 strcpy( host_type, "Unknown" );
260 "RIO Host %d - Type:%s Addr:%X IRQ:%d\n",
263 (int)HostP->Ivec - 32 );
270 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
271 return RIOCommandRta(p, (uint) arg, RIOFoadRta);
274 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
275 return RIOCommandRta(p, (uint) arg, RIOZombieRta);
277 case RIO_IDENTIFY_RTA:
278 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
279 return RIOIdentifyRta(p, arg);
281 case RIO_KILL_NEIGHBOUR:
282 rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
283 return RIOKillNeighbour(p, arg);
285 case SPECIAL_RUP_CMD:
287 struct CmdBlk *CmdBlkP;
289 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
290 if (copyin((int) arg, (caddr_t) & SpecialRupCmd, sizeof(SpecialRupCmd)) == COPYFAIL) {
291 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
292 p->RIOError.Error = COPYIN_FAILED;
295 CmdBlkP = RIOGetCmdBlk();
297 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
300 CmdBlkP->Packet = SpecialRupCmd.Packet;
301 if (SpecialRupCmd.Host >= p->RIONumHosts)
302 SpecialRupCmd.Host = 0;
303 rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
304 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
305 cprintf("FAILED TO QUEUE SPECIAL RUP COMMAND\n");
311 #ifdef DEBUG_MEM_SUPPORT
312 RIO_DEBUG_CTRL, if (su)
313 return rio_RIODebugMemory(RIO_DEBUG_CTRL, arg);
319 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
320 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
325 ** Read the routing table from the device driver to user space
327 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
329 if ((retval = RIOApel(p)) != 0)
332 if (copyout((caddr_t) p->RIOConnectTable, (int) arg, TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) {
333 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
334 p->RIOError.Error = COPYOUT_FAILED;
340 rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
341 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
342 if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
345 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
346 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
347 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
348 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
349 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
350 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
351 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
352 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
353 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
354 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
355 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
356 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
357 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
358 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
359 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
361 rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
363 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
368 ** Write the routing table to the device driver from user space
370 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
373 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
374 p->RIOError.Error = NOT_SUPER_USER;
377 if (copyin((int) arg, (caddr_t) & p->RIOConnectTable[0], TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) {
378 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
379 p->RIOError.Error = COPYIN_FAILED;
383 ***********************************
386 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
387 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
389 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
390 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
391 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
392 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
393 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
394 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
395 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
396 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
397 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
398 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
399 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
400 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
401 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
402 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
403 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
405 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
407 ***********************************
409 return RIONewTable(p);
411 case RIO_GET_BINDINGS:
413 ** Send bindings table, containing unique numbers of RTAs owned
414 ** by this system to user space
416 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
419 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
420 p->RIOError.Error = NOT_SUPER_USER;
423 if (copyout((caddr_t) p->RIOBindTab, (int) arg, (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) {
424 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
425 p->RIOError.Error = COPYOUT_FAILED;
430 case RIO_PUT_BINDINGS:
432 ** Receive a bindings table, containing unique numbers of RTAs owned
435 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
438 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
439 p->RIOError.Error = NOT_SUPER_USER;
442 if (copyin((int) arg, (caddr_t) & p->RIOBindTab[0], (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) {
443 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
444 p->RIOError.Error = COPYIN_FAILED;
453 ** Bind this RTA to host, so that it will be booted by
454 ** host in 'boot owned RTAs' mode.
456 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
459 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
460 p->RIOError.Error = NOT_SUPER_USER;
463 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
464 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
466 else if (p->RIOBindTab[Entry] == (int) arg) {
468 ** Already exists - delete
470 p->RIOBindTab[Entry] = 0L;
471 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %x from p->RIOBindTab\n", (int) arg);
476 ** Dosen't exist - add
478 if (EmptySlot != -1) {
479 p->RIOBindTab[EmptySlot] = (int) arg;
480 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %x to p->RIOBindTab\n", (int) arg);
482 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %x not added\n", (int) arg);
489 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
491 if ((port < 0) || (port > 511)) {
492 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
493 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
496 PortP = p->RIOPortp[port];
497 if (!PortP->Mapped) {
498 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
499 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
502 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
503 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
507 rio_spin_lock_irqsave(&PortP->portSem, flags);
508 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) {
509 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
510 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
513 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
514 PortP->State |= RIO_BUSY;
516 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
520 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
522 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
523 p->RIOError.Error = NOT_SUPER_USER;
526 if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
528 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
529 p->RIOError.Error = COPYIN_FAILED;
532 return RIOAssignRta(p, &MapEnt);
534 case RIO_CHANGE_NAME:
535 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
537 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
538 p->RIOError.Error = NOT_SUPER_USER;
541 if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
543 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
544 p->RIOError.Error = COPYIN_FAILED;
547 return RIOChangeName(p, &MapEnt);
550 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
552 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
553 p->RIOError.Error = NOT_SUPER_USER;
556 if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
558 rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
559 p->RIOError.Error = COPYIN_FAILED;
562 return RIODeleteRta(p, &MapEnt);
564 case RIO_QUICK_CHECK:
566 ** 09.12.1998 ARG - ESIL 0776 part fix
567 ** A customer was using this to get the RTAs
568 ** connect/disconnect status.
569 ** RIOConCon() had been botched use RIOHalted
570 ** to keep track of RTA connections and
571 ** disconnections. That has been changed and
572 ** RIORtaDisCons in the rio_info struct now
573 ** does the job. So we need to return the value
574 ** of RIORtaCons instead of RIOHalted.
576 if (copyout((caddr_t)&p->RIOHalted,(int)arg,
577 sizeof(uint))==COPYFAIL) {
581 if (copyout((caddr_t) & p->RIORtaDisCons, (int) arg, sizeof(uint)) == COPYFAIL) {
582 p->RIOError.Error = COPYOUT_FAILED;
588 if (copyout((caddr_t) & p->RIOError, (int) arg, sizeof(struct Error)) == COPYFAIL)
593 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
601 case RIO_GET_MODTYPE:
602 if (copyin((int) arg, (caddr_t) & port, sizeof(uint)) == COPYFAIL) {
603 p->RIOError.Error = COPYIN_FAILED;
606 rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
607 if (port < 0 || port > 511) {
608 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
609 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
612 PortP = (p->RIOPortp[port]);
613 if (!PortP->Mapped) {
614 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
615 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
619 ** Return module type of port
621 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
622 if (copyout((caddr_t) & port, (int) arg, sizeof(uint)) == COPYFAIL) {
623 p->RIOError.Error = COPYOUT_FAILED;
628 ** 02.03.1999 ARG - ESIL 0820 fix
629 ** We are no longer using "Boot Mode", so these ioctls
630 ** are not required :
632 case RIO_GET_BOOT_MODE :
633 rio_dprint(RIO_DEBUG_CTRL, ("Get boot mode - %x\n", p->RIOBootMode));
635 ** Return boot state of system - BOOT_ALL, BOOT_OWN or BOOT_NONE
637 if (copyout((caddr_t)&p->RIOBootMode, (int)arg,
638 sizeof(p->RIOBootMode)) == COPYFAIL) {
639 p->RIOError.Error = COPYOUT_FAILED;
644 case RIO_SET_BOOT_MODE :
645 p->RIOBootMode = (uint) arg;
646 rio_dprint(RIO_DEBUG_CTRL, ("Set boot mode to 0x%x\n", p->RIOBootMode));
652 case RIO_BLOCK_OPENS:
653 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
654 for (Entry = 0; Entry < RIO_PORTS; Entry++) {
655 rio_spin_lock_irqsave(&PortP->portSem, flags);
656 p->RIOPortp[Entry]->WaitUntilBooted = 1;
657 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
661 case RIO_SETUP_PORTS:
662 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
663 if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup))
665 p->RIOError.Error = COPYIN_FAILED;
666 rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
669 if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
670 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
671 rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
674 if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
675 p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
676 rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
680 cprintf("No p->RIOPortp array!\n");
681 rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
684 rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
685 for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
686 rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
688 PortP = p->RIOPortp[loop];
690 PortP->TtyP = &p->channel[loop];
692 rio_spin_lock_irqsave(&PortP->portSem, flags);
694 PortP->Config |= RIO_IXANY;
696 PortP->Config &= ~RIO_IXANY;
698 PortP->Config |= RIO_IXON;
700 PortP->Config &= ~RIO_IXON;
703 ** If the port needs to wait for all a processes output
704 ** to drain before closing then this flag will be set.
706 if (PortSetup.Drain) {
707 PortP->Config |= RIO_WAITDRAIN;
709 PortP->Config &= ~RIO_WAITDRAIN;
712 ** Store settings if locking or unlocking port or if the
713 ** port is not locked, when setting the store option.
715 if (PortP->Mapped && ((PortSetup.Lock && !PortP->Lock) || (!PortP->Lock && (PortSetup.Store && !PortP->Store)))) {
716 PortP->StoredTty.iflag = PortP->TtyP->tm.c_iflag;
717 PortP->StoredTty.oflag = PortP->TtyP->tm.c_oflag;
718 PortP->StoredTty.cflag = PortP->TtyP->tm.c_cflag;
719 PortP->StoredTty.lflag = PortP->TtyP->tm.c_lflag;
720 PortP->StoredTty.line = PortP->TtyP->tm.c_line;
721 bcopy(PortP->TtyP->tm.c_cc, PortP->StoredTty.cc, NCC + 5);
723 PortP->Lock = PortSetup.Lock;
724 PortP->Store = PortSetup.Store;
725 PortP->Xprint.XpCps = PortSetup.XpCps;
726 bcopy(PortSetup.XpOn, PortP->Xprint.XpOn, MAX_XP_CTRL_LEN);
727 bcopy(PortSetup.XpOff, PortP->Xprint.XpOff, MAX_XP_CTRL_LEN);
728 PortP->Xprint.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
729 PortP->Xprint.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
730 PortP->Xprint.XpLen = RIOStrlen(PortP->Xprint.XpOn) + RIOStrlen(PortP->Xprint.XpOff);
731 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
734 rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
735 rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
738 case RIO_GET_PORT_SETUP:
739 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
740 if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup))
742 p->RIOError.Error = COPYIN_FAILED;
745 if (PortSetup.From >= RIO_PORTS) {
746 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
750 port = PortSetup.To = PortSetup.From;
751 PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
752 PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
753 PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
754 PortSetup.Store = p->RIOPortp[port]->Store;
755 PortSetup.Lock = p->RIOPortp[port]->Lock;
756 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
757 bcopy(p->RIOPortp[port]->Xprint.XpOn, PortSetup.XpOn, MAX_XP_CTRL_LEN);
758 bcopy(p->RIOPortp[port]->Xprint.XpOff, PortSetup.XpOff, MAX_XP_CTRL_LEN);
759 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
760 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
762 if (copyout((caddr_t) & PortSetup, (int) arg, sizeof(PortSetup))
764 p->RIOError.Error = COPYOUT_FAILED;
769 case RIO_GET_PORT_PARAMS:
770 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
771 if (copyin((int) arg, (caddr_t) & PortParams, sizeof(struct PortParams)) == COPYFAIL) {
772 p->RIOError.Error = COPYIN_FAILED;
775 if (PortParams.Port >= RIO_PORTS) {
776 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
779 PortP = (p->RIOPortp[PortParams.Port]);
780 PortParams.Config = PortP->Config;
781 PortParams.State = PortP->State;
782 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
784 if (copyout((caddr_t) & PortParams, (int) arg, sizeof(struct PortParams)) == COPYFAIL) {
785 p->RIOError.Error = COPYOUT_FAILED;
790 case RIO_GET_PORT_TTY:
791 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
792 if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty))
794 p->RIOError.Error = COPYIN_FAILED;
797 if (PortTty.port >= RIO_PORTS) {
798 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
802 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
803 PortP = (p->RIOPortp[PortTty.port]);
805 PortTty.Tty.tm.c_iflag = PortP->TtyP->tm.c_iflag;
806 PortTty.Tty.tm.c_oflag = PortP->TtyP->tm.c_oflag;
807 PortTty.Tty.tm.c_cflag = PortP->TtyP->tm.c_cflag;
808 PortTty.Tty.tm.c_lflag = PortP->TtyP->tm.c_lflag;
810 if (copyout((caddr_t) & PortTty, (int) arg, sizeof(struct PortTty)) == COPYFAIL) {
811 p->RIOError.Error = COPYOUT_FAILED;
816 case RIO_SET_PORT_TTY:
817 if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty)) == COPYFAIL) {
818 p->RIOError.Error = COPYIN_FAILED;
821 rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
822 if (PortTty.port >= (ushort) RIO_PORTS) {
823 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
826 PortP = (p->RIOPortp[PortTty.port]);
828 rio_spin_lock_irqsave(&PortP->portSem, flags);
829 PortP->TtyP->tm.c_iflag = PortTty.Tty.tm.c_iflag;
830 PortP->TtyP->tm.c_oflag = PortTty.Tty.tm.c_oflag;
831 PortP->TtyP->tm.c_cflag = PortTty.Tty.tm.c_cflag;
832 PortP->TtyP->tm.c_lflag = PortTty.Tty.tm.c_lflag;
833 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
836 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
839 case RIO_SET_PORT_PARAMS:
840 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
841 if (copyin((int) arg, (caddr_t) & PortParams, sizeof(PortParams))
843 p->RIOError.Error = COPYIN_FAILED;
846 if (PortParams.Port >= (ushort) RIO_PORTS) {
847 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
850 PortP = (p->RIOPortp[PortParams.Port]);
851 rio_spin_lock_irqsave(&PortP->portSem, flags);
852 PortP->Config = PortParams.Config;
853 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
856 case RIO_GET_PORT_STATS:
857 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
858 if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) {
859 p->RIOError.Error = COPYIN_FAILED;
862 if (portStats.port >= RIO_PORTS) {
863 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
866 PortP = (p->RIOPortp[portStats.port]);
867 portStats.gather = PortP->statsGather;
868 portStats.txchars = PortP->txchars;
869 portStats.rxchars = PortP->rxchars;
870 portStats.opens = PortP->opens;
871 portStats.closes = PortP->closes;
872 portStats.ioctls = PortP->ioctls;
873 if (copyout((caddr_t) & portStats, (int) arg, sizeof(struct portStats)) == COPYFAIL) {
874 p->RIOError.Error = COPYOUT_FAILED;
879 case RIO_RESET_PORT_STATS:
881 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
882 if (port >= RIO_PORTS) {
883 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
886 PortP = (p->RIOPortp[port]);
887 rio_spin_lock_irqsave(&PortP->portSem, flags);
893 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
896 case RIO_GATHER_PORT_STATS:
897 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
898 if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) {
899 p->RIOError.Error = COPYIN_FAILED;
902 if (portStats.port >= RIO_PORTS) {
903 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
906 PortP = (p->RIOPortp[portStats.port]);
907 rio_spin_lock_irqsave(&PortP->portSem, flags);
908 PortP->statsGather = portStats.gather;
909 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
912 #ifdef DEBUG_SUPPORTED
913 case RIO_READ_LEVELS:
916 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_LEVELS\n");
917 for (num = 0; RIODbInf[num].Flag; num++);
918 rio_dprintk(RIO_DEBUG_CTRL, "%d levels to copy\n", num);
919 if (copyout((caddr_t) RIODbInf, (int) arg, sizeof(struct DbInf) * (num + 1)) == COPYFAIL) {
920 rio_dprintk(RIO_DEBUG_CTRL, "ReadLevels Copy failed\n");
921 p->RIOError.Error = COPYOUT_FAILED;
924 rio_dprintk(RIO_DEBUG_CTRL, "%d levels to copied\n", num);
929 case RIO_READ_CONFIG:
930 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
931 if (copyout((caddr_t) & p->RIOConf, (int) arg, sizeof(struct Conf)) == COPYFAIL) {
932 p->RIOError.Error = COPYOUT_FAILED;
938 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
940 p->RIOError.Error = NOT_SUPER_USER;
943 if (copyin((int) arg, (caddr_t) & p->RIOConf, sizeof(struct Conf))
945 p->RIOError.Error = COPYIN_FAILED;
949 ** move a few value around
951 for (Host = 0; Host < p->RIONumHosts; Host++)
952 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
953 WWORD(p->RIOHosts[Host].ParmMapP->timer, p->RIOConf.Timer);
956 case RIO_START_POLLER:
957 rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
960 case RIO_STOP_POLLER:
961 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
963 p->RIOError.Error = NOT_SUPER_USER;
966 p->RIOPolling = NOT_POLLING;
971 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
972 if (copyin((int) arg, (caddr_t) & DebugCtrl, sizeof(DebugCtrl))
974 p->RIOError.Error = COPYIN_FAILED;
977 if (DebugCtrl.SysPort == NO_PORT) {
978 if (cmd == RIO_SETDEBUG) {
980 p->RIOError.Error = NOT_SUPER_USER;
983 p->rio_debug = DebugCtrl.Debug;
984 p->RIODebugWait = DebugCtrl.Wait;
985 rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
987 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
988 DebugCtrl.Debug = p->rio_debug;
989 DebugCtrl.Wait = p->RIODebugWait;
990 if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) {
991 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
992 p->RIOError.Error = COPYOUT_FAILED;
996 } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
997 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
998 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1000 } else if (cmd == RIO_SETDEBUG) {
1002 p->RIOError.Error = NOT_SUPER_USER;
1005 rio_spin_lock_irqsave(&PortP->portSem, flags);
1006 p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
1007 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1008 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
1010 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
1011 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
1012 if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) {
1013 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
1014 p->RIOError.Error = COPYOUT_FAILED;
1022 ** Enquire about the release and version.
1023 ** We return MAX_VERSION_LEN bytes, being a
1024 ** textual null terminated string.
1026 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
1027 if (copyout((caddr_t) RIOVersid(), (int) arg, sizeof(struct rioVersion)) == COPYFAIL) {
1028 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
1029 p->RIOError.Error = COPYOUT_FAILED;
1035 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1036 ** !! commented out previous 'RIO_VERSID' functionality !!
1037 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1041 ** Enquire about the release and version.
1042 ** We return MAX_VERSION_LEN bytes, being a textual null
1043 ** terminated string.
1045 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID\n"));
1046 if (copyout((caddr_t)RIOVersid(),
1047 (int)arg, MAX_VERSION_LEN ) == COPYFAIL ) {
1048 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID: Bad copy to user space\n",Host));
1049 p->RIOError.Error = COPYOUT_FAILED;
1054 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1059 ** Enquire as to the number of hosts located
1062 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
1063 if (copyout((caddr_t) & p->RIONumHosts, (int) arg, sizeof(p->RIONumHosts)) == COPYFAIL) {
1064 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
1065 p->RIOError.Error = COPYOUT_FAILED;
1072 ** Kill host. This may not be in the final version...
1074 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %d\n", (int) arg);
1076 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
1077 p->RIOError.Error = NOT_SUPER_USER;
1083 for (Host = 0; Host < p->RIONumHosts; Host++) {
1084 (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
1085 bzero((caddr_t) & p->RIOHosts[Host].Flags, ((int) &p->RIOHosts[Host].____end_marker____) - ((int) &p->RIOHosts[Host].Flags));
1086 p->RIOHosts[Host].Flags = RC_WAITING;
1088 RIOSetupDataStructs(p);
1092 p->RIONumBootPkts = 0;
1095 #ifdef RINGBUFFER_SUPPORT
1096 for (loop = 0; loop < RIO_PORTS; loop++)
1097 if (p->RIOPortp[loop]->TxRingBuffer)
1098 sysfree((void *) p->RIOPortp[loop]->TxRingBuffer, RIOBufferSize);
1101 bzero((caddr_t) & p->RIOPortp[0], RIO_PORTS * sizeof(struct Port));
1103 printk("HEEEEELP!\n");
1106 for (loop = 0; loop < RIO_PORTS; loop++) {
1108 p->RIOPortp[loop]->TtyP = &p->channel[loop];
1111 spin_lock_init(&p->RIOPortp[loop]->portSem);
1112 p->RIOPortp[loop]->InUse = NOT_INUSE;
1119 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
1121 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
1122 p->RIOError.Error = NOT_SUPER_USER;
1125 if (copyin((int) arg, (caddr_t) & DownLoad, sizeof(DownLoad)) == COPYFAIL) {
1126 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
1127 p->RIOError.Error = COPYIN_FAILED;
1130 rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
1133 ** It is important that the product code is an unsigned object!
1135 if (DownLoad.ProductCode > MAX_PRODUCT) {
1136 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
1137 p->RIOError.Error = NO_SUCH_PRODUCT;
1143 retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
1147 ** and go back, content with a job well completed.
1155 if (copyin((int) arg, (caddr_t) & host, sizeof(host)) == COPYFAIL) {
1156 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
1157 p->RIOError.Error = COPYIN_FAILED;
1161 ** Fetch the parmmap
1163 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
1164 if (copyout((caddr_t) p->RIOHosts[host].ParmMapP, (int) arg, sizeof(PARM_MAP)) == COPYFAIL) {
1165 p->RIOError.Error = COPYOUT_FAILED;
1166 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
1173 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
1174 if (copyin((int) arg, (caddr_t) & HostReq, sizeof(HostReq)) == COPYFAIL) {
1175 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
1176 p->RIOError.Error = COPYIN_FAILED;
1179 if (HostReq.HostNum >= p->RIONumHosts) {
1180 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1181 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
1184 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
1186 if (copyout((caddr_t) & p->RIOHosts[HostReq.HostNum], (int) HostReq.HostP, sizeof(struct Host)) == COPYFAIL) {
1187 p->RIOError.Error = COPYOUT_FAILED;
1188 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
1193 case RIO_HOST_DPRAM:
1194 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
1195 if (copyin((int) arg, (caddr_t) & HostDpRam, sizeof(HostDpRam)) == COPYFAIL) {
1196 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
1197 p->RIOError.Error = COPYIN_FAILED;
1200 if (HostDpRam.HostNum >= p->RIONumHosts) {
1201 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1202 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
1205 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
1207 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
1209 /* It's hardware like this that really gets on my tits. */
1210 static unsigned char copy[sizeof(struct DpRam)];
1211 for (off = 0; off < sizeof(struct DpRam); off++)
1212 copy[off] = p->RIOHosts[HostDpRam.HostNum].Caddr[off];
1213 if (copyout((caddr_t) copy, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) {
1214 p->RIOError.Error = COPYOUT_FAILED;
1215 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
1218 } else if (copyout((caddr_t) p->RIOHosts[HostDpRam.HostNum].Caddr, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) {
1219 p->RIOError.Error = COPYOUT_FAILED;
1220 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
1226 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
1227 if ((int) arg < 0 || (int) arg > 511) {
1228 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %d\n", (int) arg);
1229 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1232 rio_spin_lock_irqsave(&PortP->portSem, flags);
1233 p->RIOPortp[(int) arg]->State |= RIO_BUSY;
1234 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1239 ** The daemon want port information
1240 ** (probably for debug reasons)
1242 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
1243 if (copyin((int) arg, (caddr_t) & PortReq, sizeof(PortReq)) == COPYFAIL) {
1244 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
1245 p->RIOError.Error = COPYIN_FAILED;
1249 if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
1250 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
1251 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1254 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
1255 if (copyout((caddr_t) p->RIOPortp[PortReq.SysPort], (int) PortReq.PortP, sizeof(struct Port)) == COPYFAIL) {
1256 p->RIOError.Error = COPYOUT_FAILED;
1257 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
1264 ** The daemon want rup information
1265 ** (probably for debug reasons)
1267 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
1268 if (copyin((int) arg, (caddr_t) & RupReq, sizeof(RupReq)) == COPYFAIL) {
1269 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1270 p->RIOError.Error = COPYIN_FAILED;
1273 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1274 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
1275 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1278 if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */
1279 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
1280 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1283 HostP = &p->RIOHosts[RupReq.HostNum];
1285 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1286 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
1287 p->RIOError.Error = HOST_NOT_RUNNING;
1290 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
1292 if (copyout((caddr_t) HostP->UnixRups[RupReq.RupNum].RupP, (int) RupReq.RupP, sizeof(struct RUP)) == COPYFAIL) {
1293 p->RIOError.Error = COPYOUT_FAILED;
1294 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1301 ** The daemon want lpb information
1302 ** (probably for debug reasons)
1304 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
1305 if (copyin((int) arg, (caddr_t) & LpbReq, sizeof(LpbReq)) == COPYFAIL) {
1306 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1307 p->RIOError.Error = COPYIN_FAILED;
1310 if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
1311 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
1312 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1315 if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */
1316 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
1317 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1320 HostP = &p->RIOHosts[LpbReq.Host];
1322 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1323 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
1324 p->RIOError.Error = HOST_NOT_RUNNING;
1327 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
1329 if (copyout((caddr_t) & HostP->LinkStrP[LpbReq.Link], (int) LpbReq.LpbP, sizeof(struct LPB)) == COPYFAIL) {
1330 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1331 p->RIOError.Error = COPYOUT_FAILED;
1337 ** Here 3 IOCTL's that allow us to change the way in which
1338 ** rio logs errors. send them just to syslog or send them
1339 ** to both syslog and console or send them to just the console.
1341 ** See RioStrBuf() in util.c for the other half.
1343 case RIO_SYSLOG_ONLY:
1344 p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
1347 case RIO_SYSLOG_CONS:
1348 p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */
1352 p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
1355 case RIO_SIGNALS_ON:
1356 if (p->RIOSignalProcess) {
1357 p->RIOError.Error = SIGNALS_ALREADY_SET;
1360 p->RIOSignalProcess = getpid();
1361 p->RIOPrintDisabled = DONT_PRINT;
1364 case RIO_SIGNALS_OFF:
1365 if (p->RIOSignalProcess != getpid()) {
1366 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1369 rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
1370 p->RIOSignalProcess = 0;
1373 case RIO_SET_BYTE_MODE:
1374 for (Host = 0; Host < p->RIONumHosts; Host++)
1375 if (p->RIOHosts[Host].Type == RIO_AT)
1376 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1379 case RIO_SET_WORD_MODE:
1380 for (Host = 0; Host < p->RIONumHosts; Host++)
1381 if (p->RIOHosts[Host].Type == RIO_AT)
1382 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1385 case RIO_SET_FAST_BUS:
1386 for (Host = 0; Host < p->RIONumHosts; Host++)
1387 if (p->RIOHosts[Host].Type == RIO_AT)
1388 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1391 case RIO_SET_SLOW_BUS:
1392 for (Host = 0; Host < p->RIONumHosts; Host++)
1393 if (p->RIOHosts[Host].Type == RIO_AT)
1394 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1397 case RIO_MAP_B50_TO_50:
1398 case RIO_MAP_B50_TO_57600:
1399 case RIO_MAP_B110_TO_110:
1400 case RIO_MAP_B110_TO_115200:
1401 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
1403 if (port < 0 || port > 511) {
1404 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1405 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1408 rio_spin_lock_irqsave(&PortP->portSem, flags);
1410 case RIO_MAP_B50_TO_50:
1411 p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1413 case RIO_MAP_B50_TO_57600:
1414 p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1416 case RIO_MAP_B110_TO_110:
1417 p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1419 case RIO_MAP_B110_TO_115200:
1420 p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1423 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1426 case RIO_STREAM_INFO:
1427 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
1430 case RIO_SEND_PACKET:
1431 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
1432 if (copyin((int) arg, (caddr_t) & SendPack, sizeof(SendPack)) == COPYFAIL) {
1433 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1434 p->RIOError.Error = COPYIN_FAILED;
1437 if (SendPack.PortNum >= 128) {
1438 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1442 PortP = p->RIOPortp[SendPack.PortNum];
1443 rio_spin_lock_irqsave(&PortP->portSem, flags);
1445 if (!can_add_transmit(&PacketP, PortP)) {
1446 p->RIOError.Error = UNIT_IS_IN_USE;
1447 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1451 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
1452 WBYTE(PacketP->data[loop], SendPack.Data[loop]);
1454 WBYTE(PacketP->len, SendPack.Len);
1456 add_transmit(PortP);
1458 ** Count characters transmitted for port statistics reporting
1460 if (PortP->statsGather)
1461 PortP->txchars += (SendPack.Len & 127);
1462 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1467 p->RIONoMessage = 1;
1468 return su ? 0 : -EPERM;
1472 p->RIONoMessage = 0;
1473 return su ? 0 : -EPERM;
1476 if (copyout((caddr_t) & p->RIONoMessage, (int) arg, sizeof(p->RIONoMessage)) == COPYFAIL) {
1477 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1478 p->RIOError.Error = COPYOUT_FAILED;
1484 if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) {
1485 p->RIOError.Error = COPYIN_FAILED;
1488 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
1490 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1491 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1495 if (SubCmd.Host >= p->RIONumHosts) {
1496 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1500 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
1502 PortP = p->RIOPortp[port];
1504 rio_spin_lock_irqsave(&PortP->portSem, flags);
1506 if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) {
1507 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1508 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1511 PortP->State |= RIO_BUSY;
1513 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1514 if (copyout((caddr_t) p->RIOMemDump, (int) arg, MEMDUMP_SIZE) == COPYFAIL) {
1515 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1516 p->RIOError.Error = COPYOUT_FAILED;
1522 if ((int) arg < 0 || (int) arg >= p->RIONumHosts)
1524 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %d\n", (int) arg);
1525 WBYTE(p->RIOHosts[(int) arg].SetInt, 0xff);
1529 if ((int) arg < 0 || (int) arg >= p->RIONumHosts)
1531 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %d\n", (int) arg);
1532 WBYTE((p->RIOHosts[(int) arg].ResetInt), 0xff);
1535 case RIO_READ_CHECK:
1536 /* Check reads for pkts with data[0] the same */
1537 p->RIOReadCheck = !p->RIOReadCheck;
1538 if (copyout((caddr_t) & p->RIOReadCheck, (int) arg, sizeof(uint)) == COPYFAIL) {
1539 p->RIOError.Error = COPYOUT_FAILED;
1544 case RIO_READ_REGISTER:
1545 if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) {
1546 p->RIOError.Error = COPYIN_FAILED;
1549 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);
1551 if (SubCmd.Port > 511) {
1552 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
1553 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1557 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1558 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1562 if (SubCmd.Host >= p->RIONumHosts) {
1563 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1567 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1568 PortP = p->RIOPortp[port];
1570 rio_spin_lock_irqsave(&PortP->portSem, flags);
1572 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
1573 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1574 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1577 PortP->State |= RIO_BUSY;
1579 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1580 if (copyout((caddr_t) & p->CdRegister, (int) arg, sizeof(uint)) == COPYFAIL) {
1581 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1582 p->RIOError.Error = COPYOUT_FAILED;
1587 ** rio_make_dev: given port number (0-511) ORed with port type
1588 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1589 ** value to pass to mknod to create the correct device node.
1593 uint port = (uint) arg & RIO_MODEM_MASK;
1595 switch ((uint) arg & RIO_DEV_MASK) {
1596 case RIO_DEV_DIRECT:
1597 arg = (caddr_t) drv_makedev(MAJOR(dev), port);
1598 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, (int) arg);
1601 arg = (caddr_t) drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1602 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, (int) arg);
1604 case RIO_DEV_XPRINT:
1605 arg = (caddr_t) drv_makedev(MAJOR(dev), port);
1606 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, (int) arg);
1609 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1613 ** rio_minor: given a dev_t from a stat() call, return
1614 ** the port number (0-511) ORed with the port type
1615 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1622 dv = (dev_t) ((int) arg);
1623 mino = RIO_UNMODEM(dv);
1625 if (RIO_ISMODEM(dv)) {
1626 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
1627 arg = (caddr_t) (mino | RIO_DEV_MODEM);
1629 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
1630 arg = (caddr_t) (mino | RIO_DEV_DIRECT);
1635 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
1636 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1643 ** Pre-emptive commands go on RUPs and are only one byte long.
1645 int RIOPreemptiveCmd(p, PortP, Cmd)
1650 struct CmdBlk *CmdBlkP;
1651 struct PktCmd_M *PktCmdP;
1660 if (PortP->State & RIO_DELETED) {
1661 rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
1665 if (((int) ((char) PortP->InUse) == -1) || !(CmdBlkP = RIOGetCmdBlk())) {
1666 rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block for command %d on port %d\n", Cmd, PortP->PortNum);
1670 rio_dprintk(RIO_DEBUG_CTRL, "Command blk 0x%x - InUse now %d\n", (int) CmdBlkP, PortP->InUse);
1672 PktCmdP = (struct PktCmd_M *) &CmdBlkP->Packet.data[0];
1674 CmdBlkP->Packet.src_unit = 0;
1675 if (PortP->SecondBlock)
1678 rup = PortP->RupNum;
1679 CmdBlkP->Packet.dest_unit = rup;
1680 CmdBlkP->Packet.src_port = COMMAND_RUP;
1681 CmdBlkP->Packet.dest_port = COMMAND_RUP;
1682 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1683 CmdBlkP->PostFuncP = RIOUnUse;
1684 CmdBlkP->PostArg = (int) PortP;
1685 PktCmdP->Command = Cmd;
1686 port = PortP->HostPort % (ushort) PORTS_PER_RTA;
1688 ** Index ports 8-15 for 2nd block of 16 port RTA.
1690 if (PortP->SecondBlock)
1691 port += (ushort) PORTS_PER_RTA;
1692 PktCmdP->PhbNum = port;
1696 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk 0x%x (addr 0x%x)\n", (int) CmdBlkP, (int) SubCmd.Addr);
1697 PktCmdP->SubCommand = MEMDUMP;
1698 PktCmdP->SubAddr = SubCmd.Addr;
1701 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk 0x%x\n", (int) CmdBlkP);
1704 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk 0x%x\n", (int) SubCmd.Addr, (int) CmdBlkP);
1705 PktCmdP->SubCommand = READ_REGISTER;
1706 PktCmdP->SubAddr = SubCmd.Addr;
1709 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk 0x%x\n", (int) CmdBlkP);
1712 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk 0x%x\n", (int) CmdBlkP);
1713 CmdBlkP->PostFuncP = RIORFlushEnable;
1716 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk 0x%x\n", (int) CmdBlkP);
1720 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk 0x%x\n", (int) CmdBlkP);
1726 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
1727 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk 0x%x\n", (int) CmdBlkP);
1732 ** If we have queued up the maximum number of Write flushes
1733 ** allowed then we should not bother sending any more to the
1736 if ((int) ((char) PortP->WflushFlag) == (int) -1) {
1737 rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, WflushFlag about to wrap!");
1738 RIOFreeCmdBlk(CmdBlkP);
1741 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command blk 0x%x\n", (int) CmdBlkP);
1742 CmdBlkP->PostFuncP = RIOWFlushMark;
1749 Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);