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");
314 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
315 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
320 ** Read the routing table from the device driver to user space
322 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
324 if ((retval = RIOApel(p)) != 0)
327 if (copyout((caddr_t) p->RIOConnectTable, (int) arg, TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) {
328 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
329 p->RIOError.Error = COPYOUT_FAILED;
335 rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
336 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
337 if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
340 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
341 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
342 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
343 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
344 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
345 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
346 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
347 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
348 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
349 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
350 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
351 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
352 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
353 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
354 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
356 rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
358 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
363 ** Write the routing table to the device driver from user space
365 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
368 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
369 p->RIOError.Error = NOT_SUPER_USER;
372 if (copyin((int) arg, (caddr_t) & p->RIOConnectTable[0], TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) {
373 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
374 p->RIOError.Error = COPYIN_FAILED;
378 ***********************************
381 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
382 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
384 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
385 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
386 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
387 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
388 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
389 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
390 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
391 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
392 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
393 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
394 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
395 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
396 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
397 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
398 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
400 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
402 ***********************************
404 return RIONewTable(p);
406 case RIO_GET_BINDINGS:
408 ** Send bindings table, containing unique numbers of RTAs owned
409 ** by this system to user space
411 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
414 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
415 p->RIOError.Error = NOT_SUPER_USER;
418 if (copyout((caddr_t) p->RIOBindTab, (int) arg, (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) {
419 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
420 p->RIOError.Error = COPYOUT_FAILED;
425 case RIO_PUT_BINDINGS:
427 ** Receive a bindings table, containing unique numbers of RTAs owned
430 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
433 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
434 p->RIOError.Error = NOT_SUPER_USER;
437 if (copyin((int) arg, (caddr_t) & p->RIOBindTab[0], (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) {
438 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
439 p->RIOError.Error = COPYIN_FAILED;
448 ** Bind this RTA to host, so that it will be booted by
449 ** host in 'boot owned RTAs' mode.
451 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
454 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
455 p->RIOError.Error = NOT_SUPER_USER;
458 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
459 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
461 else if (p->RIOBindTab[Entry] == (int) arg) {
463 ** Already exists - delete
465 p->RIOBindTab[Entry] = 0L;
466 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %x from p->RIOBindTab\n", (int) arg);
471 ** Dosen't exist - add
473 if (EmptySlot != -1) {
474 p->RIOBindTab[EmptySlot] = (int) arg;
475 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %x to p->RIOBindTab\n", (int) arg);
477 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %x not added\n", (int) arg);
484 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
486 if ((port < 0) || (port > 511)) {
487 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
488 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
491 PortP = p->RIOPortp[port];
492 if (!PortP->Mapped) {
493 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
494 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
497 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
498 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
502 rio_spin_lock_irqsave(&PortP->portSem, flags);
503 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) {
504 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
505 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
508 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
509 PortP->State |= RIO_BUSY;
511 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
515 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
517 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
518 p->RIOError.Error = NOT_SUPER_USER;
521 if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
523 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
524 p->RIOError.Error = COPYIN_FAILED;
527 return RIOAssignRta(p, &MapEnt);
529 case RIO_CHANGE_NAME:
530 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
532 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
533 p->RIOError.Error = NOT_SUPER_USER;
536 if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
538 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
539 p->RIOError.Error = COPYIN_FAILED;
542 return RIOChangeName(p, &MapEnt);
545 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
547 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
548 p->RIOError.Error = NOT_SUPER_USER;
551 if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
553 rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
554 p->RIOError.Error = COPYIN_FAILED;
557 return RIODeleteRta(p, &MapEnt);
559 case RIO_QUICK_CHECK:
561 ** 09.12.1998 ARG - ESIL 0776 part fix
562 ** A customer was using this to get the RTAs
563 ** connect/disconnect status.
564 ** RIOConCon() had been botched use RIOHalted
565 ** to keep track of RTA connections and
566 ** disconnections. That has been changed and
567 ** RIORtaDisCons in the rio_info struct now
568 ** does the job. So we need to return the value
569 ** of RIORtaCons instead of RIOHalted.
571 if (copyout((caddr_t)&p->RIOHalted,(int)arg,
572 sizeof(uint))==COPYFAIL) {
576 if (copyout((caddr_t) & p->RIORtaDisCons, (int) arg, sizeof(uint)) == COPYFAIL) {
577 p->RIOError.Error = COPYOUT_FAILED;
583 if (copyout((caddr_t) & p->RIOError, (int) arg, sizeof(struct Error)) == COPYFAIL)
588 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
591 case RIO_GET_MODTYPE:
592 if (copyin((int) arg, (caddr_t) & port, sizeof(uint)) == COPYFAIL) {
593 p->RIOError.Error = COPYIN_FAILED;
596 rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
597 if (port < 0 || port > 511) {
598 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
599 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
602 PortP = (p->RIOPortp[port]);
603 if (!PortP->Mapped) {
604 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
605 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
609 ** Return module type of port
611 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
612 if (copyout((caddr_t) & port, (int) arg, sizeof(uint)) == COPYFAIL) {
613 p->RIOError.Error = COPYOUT_FAILED;
618 ** 02.03.1999 ARG - ESIL 0820 fix
619 ** We are no longer using "Boot Mode", so these ioctls
620 ** are not required :
622 case RIO_GET_BOOT_MODE :
623 rio_dprint(RIO_DEBUG_CTRL, ("Get boot mode - %x\n", p->RIOBootMode));
625 ** Return boot state of system - BOOT_ALL, BOOT_OWN or BOOT_NONE
627 if (copyout((caddr_t)&p->RIOBootMode, (int)arg,
628 sizeof(p->RIOBootMode)) == COPYFAIL) {
629 p->RIOError.Error = COPYOUT_FAILED;
634 case RIO_SET_BOOT_MODE :
635 p->RIOBootMode = (uint) arg;
636 rio_dprint(RIO_DEBUG_CTRL, ("Set boot mode to 0x%x\n", p->RIOBootMode));
642 case RIO_BLOCK_OPENS:
643 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
644 for (Entry = 0; Entry < RIO_PORTS; Entry++) {
645 rio_spin_lock_irqsave(&PortP->portSem, flags);
646 p->RIOPortp[Entry]->WaitUntilBooted = 1;
647 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
651 case RIO_SETUP_PORTS:
652 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
653 if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup))
655 p->RIOError.Error = COPYIN_FAILED;
656 rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
659 if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
660 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
661 rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
664 if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
665 p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
666 rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
670 cprintf("No p->RIOPortp array!\n");
671 rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
674 rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
675 for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
676 rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
678 rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
679 rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
682 case RIO_GET_PORT_SETUP:
683 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
684 if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup))
686 p->RIOError.Error = COPYIN_FAILED;
689 if (PortSetup.From >= RIO_PORTS) {
690 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
694 port = PortSetup.To = PortSetup.From;
695 PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
696 PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
697 PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
698 PortSetup.Store = p->RIOPortp[port]->Store;
699 PortSetup.Lock = p->RIOPortp[port]->Lock;
700 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
701 bcopy(p->RIOPortp[port]->Xprint.XpOn, PortSetup.XpOn, MAX_XP_CTRL_LEN);
702 bcopy(p->RIOPortp[port]->Xprint.XpOff, PortSetup.XpOff, MAX_XP_CTRL_LEN);
703 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
704 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
706 if (copyout((caddr_t) & PortSetup, (int) arg, sizeof(PortSetup))
708 p->RIOError.Error = COPYOUT_FAILED;
713 case RIO_GET_PORT_PARAMS:
714 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
715 if (copyin((int) arg, (caddr_t) & PortParams, sizeof(struct PortParams)) == COPYFAIL) {
716 p->RIOError.Error = COPYIN_FAILED;
719 if (PortParams.Port >= RIO_PORTS) {
720 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
723 PortP = (p->RIOPortp[PortParams.Port]);
724 PortParams.Config = PortP->Config;
725 PortParams.State = PortP->State;
726 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
728 if (copyout((caddr_t) & PortParams, (int) arg, sizeof(struct PortParams)) == COPYFAIL) {
729 p->RIOError.Error = COPYOUT_FAILED;
734 case RIO_GET_PORT_TTY:
735 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
736 if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty))
738 p->RIOError.Error = COPYIN_FAILED;
741 if (PortTty.port >= RIO_PORTS) {
742 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
746 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
747 PortP = (p->RIOPortp[PortTty.port]);
748 if (copyout((caddr_t) & PortTty, (int) arg, sizeof(struct PortTty)) == COPYFAIL) {
749 p->RIOError.Error = COPYOUT_FAILED;
754 case RIO_SET_PORT_TTY:
755 if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty)) == COPYFAIL) {
756 p->RIOError.Error = COPYIN_FAILED;
759 rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
760 if (PortTty.port >= (ushort) RIO_PORTS) {
761 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
764 PortP = (p->RIOPortp[PortTty.port]);
765 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
768 case RIO_SET_PORT_PARAMS:
769 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
770 if (copyin((int) arg, (caddr_t) & PortParams, sizeof(PortParams))
772 p->RIOError.Error = COPYIN_FAILED;
775 if (PortParams.Port >= (ushort) RIO_PORTS) {
776 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
779 PortP = (p->RIOPortp[PortParams.Port]);
780 rio_spin_lock_irqsave(&PortP->portSem, flags);
781 PortP->Config = PortParams.Config;
782 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
785 case RIO_GET_PORT_STATS:
786 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
787 if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) {
788 p->RIOError.Error = COPYIN_FAILED;
791 if (portStats.port >= RIO_PORTS) {
792 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
795 PortP = (p->RIOPortp[portStats.port]);
796 portStats.gather = PortP->statsGather;
797 portStats.txchars = PortP->txchars;
798 portStats.rxchars = PortP->rxchars;
799 portStats.opens = PortP->opens;
800 portStats.closes = PortP->closes;
801 portStats.ioctls = PortP->ioctls;
802 if (copyout((caddr_t) & portStats, (int) arg, sizeof(struct portStats)) == COPYFAIL) {
803 p->RIOError.Error = COPYOUT_FAILED;
808 case RIO_RESET_PORT_STATS:
810 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
811 if (port >= RIO_PORTS) {
812 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
815 PortP = (p->RIOPortp[port]);
816 rio_spin_lock_irqsave(&PortP->portSem, flags);
822 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
825 case RIO_GATHER_PORT_STATS:
826 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
827 if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) {
828 p->RIOError.Error = COPYIN_FAILED;
831 if (portStats.port >= RIO_PORTS) {
832 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
835 PortP = (p->RIOPortp[portStats.port]);
836 rio_spin_lock_irqsave(&PortP->portSem, flags);
837 PortP->statsGather = portStats.gather;
838 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
841 case RIO_READ_CONFIG:
842 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
843 if (copyout((caddr_t) & p->RIOConf, (int) arg, sizeof(struct Conf)) == COPYFAIL) {
844 p->RIOError.Error = COPYOUT_FAILED;
850 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
852 p->RIOError.Error = NOT_SUPER_USER;
855 if (copyin((int) arg, (caddr_t) & p->RIOConf, sizeof(struct Conf))
857 p->RIOError.Error = COPYIN_FAILED;
861 ** move a few value around
863 for (Host = 0; Host < p->RIONumHosts; Host++)
864 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
865 WWORD(p->RIOHosts[Host].ParmMapP->timer, p->RIOConf.Timer);
868 case RIO_START_POLLER:
869 rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
872 case RIO_STOP_POLLER:
873 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
875 p->RIOError.Error = NOT_SUPER_USER;
878 p->RIOPolling = NOT_POLLING;
883 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
884 if (copyin((int) arg, (caddr_t) & DebugCtrl, sizeof(DebugCtrl))
886 p->RIOError.Error = COPYIN_FAILED;
889 if (DebugCtrl.SysPort == NO_PORT) {
890 if (cmd == RIO_SETDEBUG) {
892 p->RIOError.Error = NOT_SUPER_USER;
895 p->rio_debug = DebugCtrl.Debug;
896 p->RIODebugWait = DebugCtrl.Wait;
897 rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
899 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
900 DebugCtrl.Debug = p->rio_debug;
901 DebugCtrl.Wait = p->RIODebugWait;
902 if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) {
903 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
904 p->RIOError.Error = COPYOUT_FAILED;
908 } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
909 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
910 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
912 } else if (cmd == RIO_SETDEBUG) {
914 p->RIOError.Error = NOT_SUPER_USER;
917 rio_spin_lock_irqsave(&PortP->portSem, flags);
918 p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
919 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
920 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
922 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
923 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
924 if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) {
925 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
926 p->RIOError.Error = COPYOUT_FAILED;
934 ** Enquire about the release and version.
935 ** We return MAX_VERSION_LEN bytes, being a
936 ** textual null terminated string.
938 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
939 if (copyout((caddr_t) RIOVersid(), (int) arg, sizeof(struct rioVersion)) == COPYFAIL) {
940 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
941 p->RIOError.Error = COPYOUT_FAILED;
947 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
948 ** !! commented out previous 'RIO_VERSID' functionality !!
949 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
953 ** Enquire about the release and version.
954 ** We return MAX_VERSION_LEN bytes, being a textual null
955 ** terminated string.
957 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID\n"));
958 if (copyout((caddr_t)RIOVersid(),
959 (int)arg, MAX_VERSION_LEN ) == COPYFAIL ) {
960 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID: Bad copy to user space\n",Host));
961 p->RIOError.Error = COPYOUT_FAILED;
966 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
971 ** Enquire as to the number of hosts located
974 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
975 if (copyout((caddr_t) & p->RIONumHosts, (int) arg, sizeof(p->RIONumHosts)) == COPYFAIL) {
976 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
977 p->RIOError.Error = COPYOUT_FAILED;
984 ** Kill host. This may not be in the final version...
986 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %d\n", (int) arg);
988 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
989 p->RIOError.Error = NOT_SUPER_USER;
995 for (Host = 0; Host < p->RIONumHosts; Host++) {
996 (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
997 bzero((caddr_t) & p->RIOHosts[Host].Flags, ((int) &p->RIOHosts[Host].____end_marker____) - ((int) &p->RIOHosts[Host].Flags));
998 p->RIOHosts[Host].Flags = RC_WAITING;
1001 p->RIONumBootPkts = 0;
1003 printk("HEEEEELP!\n");
1005 for (loop = 0; loop < RIO_PORTS; loop++) {
1006 spin_lock_init(&p->RIOPortp[loop]->portSem);
1007 p->RIOPortp[loop]->InUse = NOT_INUSE;
1014 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
1016 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
1017 p->RIOError.Error = NOT_SUPER_USER;
1020 if (copyin((int) arg, (caddr_t) & DownLoad, sizeof(DownLoad)) == COPYFAIL) {
1021 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
1022 p->RIOError.Error = COPYIN_FAILED;
1025 rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
1028 ** It is important that the product code is an unsigned object!
1030 if (DownLoad.ProductCode > MAX_PRODUCT) {
1031 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
1032 p->RIOError.Error = NO_SUCH_PRODUCT;
1038 retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
1042 ** and go back, content with a job well completed.
1050 if (copyin((int) arg, (caddr_t) & host, sizeof(host)) == COPYFAIL) {
1051 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
1052 p->RIOError.Error = COPYIN_FAILED;
1056 ** Fetch the parmmap
1058 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
1059 if (copyout((caddr_t) p->RIOHosts[host].ParmMapP, (int) arg, sizeof(PARM_MAP)) == COPYFAIL) {
1060 p->RIOError.Error = COPYOUT_FAILED;
1061 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
1068 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
1069 if (copyin((int) arg, (caddr_t) & HostReq, sizeof(HostReq)) == COPYFAIL) {
1070 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
1071 p->RIOError.Error = COPYIN_FAILED;
1074 if (HostReq.HostNum >= p->RIONumHosts) {
1075 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1076 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
1079 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
1081 if (copyout((caddr_t) & p->RIOHosts[HostReq.HostNum], (int) HostReq.HostP, sizeof(struct Host)) == COPYFAIL) {
1082 p->RIOError.Error = COPYOUT_FAILED;
1083 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
1088 case RIO_HOST_DPRAM:
1089 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
1090 if (copyin((int) arg, (caddr_t) & HostDpRam, sizeof(HostDpRam)) == COPYFAIL) {
1091 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
1092 p->RIOError.Error = COPYIN_FAILED;
1095 if (HostDpRam.HostNum >= p->RIONumHosts) {
1096 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1097 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
1100 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
1102 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
1104 /* It's hardware like this that really gets on my tits. */
1105 static unsigned char copy[sizeof(struct DpRam)];
1106 for (off = 0; off < sizeof(struct DpRam); off++)
1107 copy[off] = p->RIOHosts[HostDpRam.HostNum].Caddr[off];
1108 if (copyout((caddr_t) copy, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) {
1109 p->RIOError.Error = COPYOUT_FAILED;
1110 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
1113 } else if (copyout((caddr_t) p->RIOHosts[HostDpRam.HostNum].Caddr, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) {
1114 p->RIOError.Error = COPYOUT_FAILED;
1115 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
1121 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
1122 if ((int) arg < 0 || (int) arg > 511) {
1123 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %d\n", (int) arg);
1124 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1127 rio_spin_lock_irqsave(&PortP->portSem, flags);
1128 p->RIOPortp[(int) arg]->State |= RIO_BUSY;
1129 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1134 ** The daemon want port information
1135 ** (probably for debug reasons)
1137 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
1138 if (copyin((int) arg, (caddr_t) & PortReq, sizeof(PortReq)) == COPYFAIL) {
1139 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
1140 p->RIOError.Error = COPYIN_FAILED;
1144 if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
1145 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
1146 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1149 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
1150 if (copyout((caddr_t) p->RIOPortp[PortReq.SysPort], (int) PortReq.PortP, sizeof(struct Port)) == COPYFAIL) {
1151 p->RIOError.Error = COPYOUT_FAILED;
1152 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
1159 ** The daemon want rup information
1160 ** (probably for debug reasons)
1162 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
1163 if (copyin((int) arg, (caddr_t) & RupReq, sizeof(RupReq)) == COPYFAIL) {
1164 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1165 p->RIOError.Error = COPYIN_FAILED;
1168 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1169 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
1170 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1173 if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */
1174 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
1175 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1178 HostP = &p->RIOHosts[RupReq.HostNum];
1180 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1181 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
1182 p->RIOError.Error = HOST_NOT_RUNNING;
1185 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
1187 if (copyout((caddr_t) HostP->UnixRups[RupReq.RupNum].RupP, (int) RupReq.RupP, sizeof(struct RUP)) == COPYFAIL) {
1188 p->RIOError.Error = COPYOUT_FAILED;
1189 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1196 ** The daemon want lpb information
1197 ** (probably for debug reasons)
1199 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
1200 if (copyin((int) arg, (caddr_t) & LpbReq, sizeof(LpbReq)) == COPYFAIL) {
1201 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1202 p->RIOError.Error = COPYIN_FAILED;
1205 if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
1206 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
1207 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1210 if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */
1211 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
1212 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1215 HostP = &p->RIOHosts[LpbReq.Host];
1217 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1218 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
1219 p->RIOError.Error = HOST_NOT_RUNNING;
1222 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
1224 if (copyout((caddr_t) & HostP->LinkStrP[LpbReq.Link], (int) LpbReq.LpbP, sizeof(struct LPB)) == COPYFAIL) {
1225 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1226 p->RIOError.Error = COPYOUT_FAILED;
1232 ** Here 3 IOCTL's that allow us to change the way in which
1233 ** rio logs errors. send them just to syslog or send them
1234 ** to both syslog and console or send them to just the console.
1236 ** See RioStrBuf() in util.c for the other half.
1238 case RIO_SYSLOG_ONLY:
1239 p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
1242 case RIO_SYSLOG_CONS:
1243 p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */
1247 p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
1250 case RIO_SIGNALS_ON:
1251 if (p->RIOSignalProcess) {
1252 p->RIOError.Error = SIGNALS_ALREADY_SET;
1255 p->RIOSignalProcess = getpid();
1256 p->RIOPrintDisabled = DONT_PRINT;
1259 case RIO_SIGNALS_OFF:
1260 if (p->RIOSignalProcess != getpid()) {
1261 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1264 rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
1265 p->RIOSignalProcess = 0;
1268 case RIO_SET_BYTE_MODE:
1269 for (Host = 0; Host < p->RIONumHosts; Host++)
1270 if (p->RIOHosts[Host].Type == RIO_AT)
1271 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1274 case RIO_SET_WORD_MODE:
1275 for (Host = 0; Host < p->RIONumHosts; Host++)
1276 if (p->RIOHosts[Host].Type == RIO_AT)
1277 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1280 case RIO_SET_FAST_BUS:
1281 for (Host = 0; Host < p->RIONumHosts; Host++)
1282 if (p->RIOHosts[Host].Type == RIO_AT)
1283 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1286 case RIO_SET_SLOW_BUS:
1287 for (Host = 0; Host < p->RIONumHosts; Host++)
1288 if (p->RIOHosts[Host].Type == RIO_AT)
1289 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1292 case RIO_MAP_B50_TO_50:
1293 case RIO_MAP_B50_TO_57600:
1294 case RIO_MAP_B110_TO_110:
1295 case RIO_MAP_B110_TO_115200:
1296 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
1298 if (port < 0 || port > 511) {
1299 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1300 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1303 rio_spin_lock_irqsave(&PortP->portSem, flags);
1305 case RIO_MAP_B50_TO_50:
1306 p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1308 case RIO_MAP_B50_TO_57600:
1309 p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1311 case RIO_MAP_B110_TO_110:
1312 p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1314 case RIO_MAP_B110_TO_115200:
1315 p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1318 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1321 case RIO_STREAM_INFO:
1322 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
1325 case RIO_SEND_PACKET:
1326 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
1327 if (copyin((int) arg, (caddr_t) & SendPack, sizeof(SendPack)) == COPYFAIL) {
1328 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1329 p->RIOError.Error = COPYIN_FAILED;
1332 if (SendPack.PortNum >= 128) {
1333 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1337 PortP = p->RIOPortp[SendPack.PortNum];
1338 rio_spin_lock_irqsave(&PortP->portSem, flags);
1340 if (!can_add_transmit(&PacketP, PortP)) {
1341 p->RIOError.Error = UNIT_IS_IN_USE;
1342 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1346 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
1347 WBYTE(PacketP->data[loop], SendPack.Data[loop]);
1349 WBYTE(PacketP->len, SendPack.Len);
1351 add_transmit(PortP);
1353 ** Count characters transmitted for port statistics reporting
1355 if (PortP->statsGather)
1356 PortP->txchars += (SendPack.Len & 127);
1357 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1362 p->RIONoMessage = 1;
1363 return su ? 0 : -EPERM;
1367 p->RIONoMessage = 0;
1368 return su ? 0 : -EPERM;
1371 if (copyout((caddr_t) & p->RIONoMessage, (int) arg, sizeof(p->RIONoMessage)) == COPYFAIL) {
1372 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1373 p->RIOError.Error = COPYOUT_FAILED;
1379 if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) {
1380 p->RIOError.Error = COPYIN_FAILED;
1383 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
1385 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1386 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1390 if (SubCmd.Host >= p->RIONumHosts) {
1391 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1395 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
1397 PortP = p->RIOPortp[port];
1399 rio_spin_lock_irqsave(&PortP->portSem, flags);
1401 if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) {
1402 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1403 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1406 PortP->State |= RIO_BUSY;
1408 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1409 if (copyout((caddr_t) p->RIOMemDump, (int) arg, MEMDUMP_SIZE) == COPYFAIL) {
1410 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1411 p->RIOError.Error = COPYOUT_FAILED;
1417 if ((int) arg < 0 || (int) arg >= p->RIONumHosts)
1419 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %d\n", (int) arg);
1420 WBYTE(p->RIOHosts[(int) arg].SetInt, 0xff);
1424 if ((int) arg < 0 || (int) arg >= p->RIONumHosts)
1426 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %d\n", (int) arg);
1427 WBYTE((p->RIOHosts[(int) arg].ResetInt), 0xff);
1430 case RIO_READ_CHECK:
1431 /* Check reads for pkts with data[0] the same */
1432 p->RIOReadCheck = !p->RIOReadCheck;
1433 if (copyout((caddr_t) & p->RIOReadCheck, (int) arg, sizeof(uint)) == COPYFAIL) {
1434 p->RIOError.Error = COPYOUT_FAILED;
1439 case RIO_READ_REGISTER:
1440 if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) {
1441 p->RIOError.Error = COPYIN_FAILED;
1444 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);
1446 if (SubCmd.Port > 511) {
1447 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
1448 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1452 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1453 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1457 if (SubCmd.Host >= p->RIONumHosts) {
1458 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1462 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1463 PortP = p->RIOPortp[port];
1465 rio_spin_lock_irqsave(&PortP->portSem, flags);
1467 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
1468 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1469 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1472 PortP->State |= RIO_BUSY;
1474 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1475 if (copyout((caddr_t) & p->CdRegister, (int) arg, sizeof(uint)) == COPYFAIL) {
1476 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1477 p->RIOError.Error = COPYOUT_FAILED;
1482 ** rio_make_dev: given port number (0-511) ORed with port type
1483 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1484 ** value to pass to mknod to create the correct device node.
1488 uint port = (uint) arg & RIO_MODEM_MASK;
1490 switch ((uint) arg & RIO_DEV_MASK) {
1491 case RIO_DEV_DIRECT:
1492 arg = (caddr_t) drv_makedev(MAJOR(dev), port);
1493 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, (int) arg);
1496 arg = (caddr_t) drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1497 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, (int) arg);
1499 case RIO_DEV_XPRINT:
1500 arg = (caddr_t) drv_makedev(MAJOR(dev), port);
1501 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, (int) arg);
1504 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1508 ** rio_minor: given a dev_t from a stat() call, return
1509 ** the port number (0-511) ORed with the port type
1510 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1517 dv = (dev_t) ((int) arg);
1518 mino = RIO_UNMODEM(dv);
1520 if (RIO_ISMODEM(dv)) {
1521 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
1522 arg = (caddr_t) (mino | RIO_DEV_MODEM);
1524 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
1525 arg = (caddr_t) (mino | RIO_DEV_DIRECT);
1530 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
1531 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1538 ** Pre-emptive commands go on RUPs and are only one byte long.
1540 int RIOPreemptiveCmd(p, PortP, Cmd)
1545 struct CmdBlk *CmdBlkP;
1546 struct PktCmd_M *PktCmdP;
1551 if (PortP->State & RIO_DELETED) {
1552 rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
1556 if (((int) ((char) PortP->InUse) == -1) || !(CmdBlkP = RIOGetCmdBlk())) {
1557 rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block for command %d on port %d\n", Cmd, PortP->PortNum);
1561 rio_dprintk(RIO_DEBUG_CTRL, "Command blk 0x%x - InUse now %d\n", (int) CmdBlkP, PortP->InUse);
1563 PktCmdP = (struct PktCmd_M *) &CmdBlkP->Packet.data[0];
1565 CmdBlkP->Packet.src_unit = 0;
1566 if (PortP->SecondBlock)
1569 rup = PortP->RupNum;
1570 CmdBlkP->Packet.dest_unit = rup;
1571 CmdBlkP->Packet.src_port = COMMAND_RUP;
1572 CmdBlkP->Packet.dest_port = COMMAND_RUP;
1573 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1574 CmdBlkP->PostFuncP = RIOUnUse;
1575 CmdBlkP->PostArg = (int) PortP;
1576 PktCmdP->Command = Cmd;
1577 port = PortP->HostPort % (ushort) PORTS_PER_RTA;
1579 ** Index ports 8-15 for 2nd block of 16 port RTA.
1581 if (PortP->SecondBlock)
1582 port += (ushort) PORTS_PER_RTA;
1583 PktCmdP->PhbNum = port;
1587 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk 0x%x (addr 0x%x)\n", (int) CmdBlkP, (int) SubCmd.Addr);
1588 PktCmdP->SubCommand = MEMDUMP;
1589 PktCmdP->SubAddr = SubCmd.Addr;
1592 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk 0x%x\n", (int) CmdBlkP);
1595 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk 0x%x\n", (int) SubCmd.Addr, (int) CmdBlkP);
1596 PktCmdP->SubCommand = READ_REGISTER;
1597 PktCmdP->SubAddr = SubCmd.Addr;
1600 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk 0x%x\n", (int) CmdBlkP);
1603 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk 0x%x\n", (int) CmdBlkP);
1604 CmdBlkP->PostFuncP = RIORFlushEnable;
1607 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk 0x%x\n", (int) CmdBlkP);
1611 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk 0x%x\n", (int) CmdBlkP);
1617 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
1618 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk 0x%x\n", (int) CmdBlkP);
1623 ** If we have queued up the maximum number of Write flushes
1624 ** allowed then we should not bother sending any more to the
1627 if ((int) ((char) PortP->WflushFlag) == (int) -1) {
1628 rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, WflushFlag about to wrap!");
1629 RIOFreeCmdBlk(CmdBlkP);
1632 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command blk 0x%x\n", (int) CmdBlkP);
1633 CmdBlkP->PostFuncP = RIOWFlushMark;
1640 Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);