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"
80 static struct LpbReq LpbReq;
81 static struct RupReq RupReq;
82 static struct PortReq PortReq;
83 static struct HostReq HostReq; /* oh really? global? and no locking? */
84 static struct HostDpRam HostDpRam;
85 static struct DebugCtrl DebugCtrl;
86 static struct Map MapEnt;
87 static struct PortSetup PortSetup;
88 static struct DownLoad DownLoad;
89 static struct SendPack SendPack;
90 /* static struct StreamInfo StreamInfo; */
91 /* static char modemtable[RIO_PORTS]; */
92 static struct SpecialRupCmd SpecialRupCmd;
93 static struct PortParams PortParams;
94 static struct portStats portStats;
96 static struct SubCmdStruct {
105 struct ttystatics Tty;
108 static struct PortTty PortTty;
109 typedef struct ttystatics TERMIO;
112 ** This table is used when the config.rio downloads bin code to the
113 ** driver. We index the table using the product code, 0-F, and call
114 ** the function pointed to by the entry, passing the information
116 ** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
117 ** process to bog off.
120 (*RIOBootTable[MAX_PRODUCT]) (struct rio_info *, struct DownLoad *) = {
121 /* 0 */ RIOBootCodeHOST,
123 /* 1 */ RIOBootCodeRTA,
127 #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
129 int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su)
131 uint Host; /* leave me unsigned! */
132 uint port; /* and me! */
137 struct PKT __iomem *PacketP;
140 void __user *argp = (void __user *)arg;
144 /* Confuse the compiler to think that we've initialized these */
148 rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, argp);
154 ** Change the value of the host card interrupt timer.
155 ** If the host card number is -1 then all host cards are changed
156 ** otherwise just the specified host card will be changed.
159 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", arg);
162 host = (arg >> 16) & 0x0000FFFF;
163 value = arg & 0x0000ffff;
165 for (host = 0; host < p->RIONumHosts; host++) {
166 if (p->RIOHosts[host].Flags == RC_RUNNING) {
167 writew(value, &p->RIOHosts[host].ParmMapP->timer);
170 } else if (host >= p->RIONumHosts) {
173 if (p->RIOHosts[host].Flags == RC_RUNNING) {
174 writew(value, &p->RIOHosts[host].ParmMapP->timer);
181 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
182 return RIOCommandRta(p, arg, RIOFoadRta);
185 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
186 return RIOCommandRta(p, arg, RIOZombieRta);
188 case RIO_IDENTIFY_RTA:
189 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
190 return RIOIdentifyRta(p, argp);
192 case RIO_KILL_NEIGHBOUR:
193 rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
194 return RIOKillNeighbour(p, argp);
196 case SPECIAL_RUP_CMD:
198 struct CmdBlk *CmdBlkP;
200 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
201 if (copy_from_user(&SpecialRupCmd, argp, sizeof(SpecialRupCmd))) {
202 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
203 p->RIOError.Error = COPYIN_FAILED;
206 CmdBlkP = RIOGetCmdBlk();
208 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
211 CmdBlkP->Packet = SpecialRupCmd.Packet;
212 if (SpecialRupCmd.Host >= p->RIONumHosts)
213 SpecialRupCmd.Host = 0;
214 rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
215 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
216 printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
225 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
226 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
231 ** Read the routing table from the device driver to user space
233 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
235 if ((retval = RIOApel(p)) != 0)
238 if (copy_to_user(argp, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
239 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
240 p->RIOError.Error = COPYOUT_FAILED;
246 rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
247 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
248 if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
251 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
252 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
253 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
254 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
255 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
256 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
257 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
258 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
259 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
260 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
261 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
262 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
263 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
264 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
265 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
267 rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
269 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
274 ** Write the routing table to the device driver from user space
276 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
279 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
280 p->RIOError.Error = NOT_SUPER_USER;
283 if (copy_from_user(&p->RIOConnectTable[0], argp, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
284 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
285 p->RIOError.Error = COPYIN_FAILED;
289 ***********************************
292 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
293 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
295 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
296 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
297 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
298 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
299 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
300 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
301 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
302 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
303 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
304 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
305 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
306 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
307 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
308 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
309 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
311 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
313 ***********************************
315 return RIONewTable(p);
317 case RIO_GET_BINDINGS:
319 ** Send bindings table, containing unique numbers of RTAs owned
320 ** by this system to user space
322 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
325 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
326 p->RIOError.Error = NOT_SUPER_USER;
329 if (copy_to_user(argp, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
330 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
331 p->RIOError.Error = COPYOUT_FAILED;
336 case RIO_PUT_BINDINGS:
338 ** Receive a bindings table, containing unique numbers of RTAs owned
341 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
344 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
345 p->RIOError.Error = NOT_SUPER_USER;
348 if (copy_from_user(&p->RIOBindTab[0], argp, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
349 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
350 p->RIOError.Error = COPYIN_FAILED;
359 ** Bind this RTA to host, so that it will be booted by
360 ** host in 'boot owned RTAs' mode.
362 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
365 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
366 p->RIOError.Error = NOT_SUPER_USER;
369 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
370 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
372 else if (p->RIOBindTab[Entry] == arg) {
374 ** Already exists - delete
376 p->RIOBindTab[Entry] = 0L;
377 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", arg);
382 ** Dosen't exist - add
384 if (EmptySlot != -1) {
385 p->RIOBindTab[EmptySlot] = arg;
386 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", arg);
388 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", arg);
395 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
397 if ((port < 0) || (port > 511)) {
398 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
399 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
402 PortP = p->RIOPortp[port];
403 if (!PortP->Mapped) {
404 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
405 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
408 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
409 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
413 rio_spin_lock_irqsave(&PortP->portSem, flags);
414 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) {
415 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
416 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
419 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
420 PortP->State |= RIO_BUSY;
422 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
426 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
428 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
429 p->RIOError.Error = NOT_SUPER_USER;
432 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
433 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
434 p->RIOError.Error = COPYIN_FAILED;
437 return RIOAssignRta(p, &MapEnt);
439 case RIO_CHANGE_NAME:
440 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
442 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
443 p->RIOError.Error = NOT_SUPER_USER;
446 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
447 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
448 p->RIOError.Error = COPYIN_FAILED;
451 return RIOChangeName(p, &MapEnt);
454 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
456 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
457 p->RIOError.Error = NOT_SUPER_USER;
460 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
461 rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
462 p->RIOError.Error = COPYIN_FAILED;
465 return RIODeleteRta(p, &MapEnt);
467 case RIO_QUICK_CHECK:
468 if (copy_to_user(argp, &p->RIORtaDisCons, sizeof(unsigned int))) {
469 p->RIOError.Error = COPYOUT_FAILED;
475 if (copy_to_user(argp, &p->RIOError, sizeof(struct Error)))
480 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
483 case RIO_GET_MODTYPE:
484 if (copy_from_user(&port, argp, sizeof(unsigned int))) {
485 p->RIOError.Error = COPYIN_FAILED;
488 rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
489 if (port < 0 || port > 511) {
490 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
491 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
494 PortP = (p->RIOPortp[port]);
495 if (!PortP->Mapped) {
496 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
497 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
501 ** Return module type of port
503 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
504 if (copy_to_user(argp, &port, sizeof(unsigned int))) {
505 p->RIOError.Error = COPYOUT_FAILED;
509 case RIO_BLOCK_OPENS:
510 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
511 for (Entry = 0; Entry < RIO_PORTS; Entry++) {
512 rio_spin_lock_irqsave(&PortP->portSem, flags);
513 p->RIOPortp[Entry]->WaitUntilBooted = 1;
514 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
518 case RIO_SETUP_PORTS:
519 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
520 if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
521 p->RIOError.Error = COPYIN_FAILED;
522 rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
525 if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
526 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
527 rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
530 if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
531 p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
532 rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
536 printk(KERN_ERR "rio: No p->RIOPortp array!\n");
537 rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
540 rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
541 for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
542 rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
544 rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
545 rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
548 case RIO_GET_PORT_SETUP:
549 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
550 if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
551 p->RIOError.Error = COPYIN_FAILED;
554 if (PortSetup.From >= RIO_PORTS) {
555 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
559 port = PortSetup.To = PortSetup.From;
560 PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
561 PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
562 PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
563 PortSetup.Store = p->RIOPortp[port]->Store;
564 PortSetup.Lock = p->RIOPortp[port]->Lock;
565 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
566 memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN);
567 memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN);
568 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
569 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
571 if (copy_to_user(argp, &PortSetup, sizeof(PortSetup))) {
572 p->RIOError.Error = COPYOUT_FAILED;
577 case RIO_GET_PORT_PARAMS:
578 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
579 if (copy_from_user(&PortParams, argp, sizeof(struct PortParams))) {
580 p->RIOError.Error = COPYIN_FAILED;
583 if (PortParams.Port >= RIO_PORTS) {
584 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
587 PortP = (p->RIOPortp[PortParams.Port]);
588 PortParams.Config = PortP->Config;
589 PortParams.State = PortP->State;
590 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
592 if (copy_to_user(argp, &PortParams, sizeof(struct PortParams))) {
593 p->RIOError.Error = COPYOUT_FAILED;
598 case RIO_GET_PORT_TTY:
599 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
600 if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
601 p->RIOError.Error = COPYIN_FAILED;
604 if (PortTty.port >= RIO_PORTS) {
605 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
609 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
610 PortP = (p->RIOPortp[PortTty.port]);
611 if (copy_to_user(argp, &PortTty, sizeof(struct PortTty))) {
612 p->RIOError.Error = COPYOUT_FAILED;
617 case RIO_SET_PORT_TTY:
618 if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
619 p->RIOError.Error = COPYIN_FAILED;
622 rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
623 if (PortTty.port >= (ushort) RIO_PORTS) {
624 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
627 PortP = (p->RIOPortp[PortTty.port]);
628 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
631 case RIO_SET_PORT_PARAMS:
632 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
633 if (copy_from_user(&PortParams, argp, sizeof(PortParams))) {
634 p->RIOError.Error = COPYIN_FAILED;
637 if (PortParams.Port >= (ushort) RIO_PORTS) {
638 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
641 PortP = (p->RIOPortp[PortParams.Port]);
642 rio_spin_lock_irqsave(&PortP->portSem, flags);
643 PortP->Config = PortParams.Config;
644 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
647 case RIO_GET_PORT_STATS:
648 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
649 if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
650 p->RIOError.Error = COPYIN_FAILED;
653 if (portStats.port >= RIO_PORTS) {
654 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
657 PortP = (p->RIOPortp[portStats.port]);
658 portStats.gather = PortP->statsGather;
659 portStats.txchars = PortP->txchars;
660 portStats.rxchars = PortP->rxchars;
661 portStats.opens = PortP->opens;
662 portStats.closes = PortP->closes;
663 portStats.ioctls = PortP->ioctls;
664 if (copy_to_user(argp, &portStats, sizeof(struct portStats))) {
665 p->RIOError.Error = COPYOUT_FAILED;
670 case RIO_RESET_PORT_STATS:
672 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
673 if (port >= RIO_PORTS) {
674 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
677 PortP = (p->RIOPortp[port]);
678 rio_spin_lock_irqsave(&PortP->portSem, flags);
684 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
687 case RIO_GATHER_PORT_STATS:
688 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
689 if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
690 p->RIOError.Error = COPYIN_FAILED;
693 if (portStats.port >= RIO_PORTS) {
694 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
697 PortP = (p->RIOPortp[portStats.port]);
698 rio_spin_lock_irqsave(&PortP->portSem, flags);
699 PortP->statsGather = portStats.gather;
700 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
703 case RIO_READ_CONFIG:
704 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
705 if (copy_to_user(argp, &p->RIOConf, sizeof(struct Conf))) {
706 p->RIOError.Error = COPYOUT_FAILED;
712 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
714 p->RIOError.Error = NOT_SUPER_USER;
717 if (copy_from_user(&p->RIOConf, argp, sizeof(struct Conf))) {
718 p->RIOError.Error = COPYIN_FAILED;
722 ** move a few value around
724 for (Host = 0; Host < p->RIONumHosts; Host++)
725 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
726 writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
729 case RIO_START_POLLER:
730 rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
733 case RIO_STOP_POLLER:
734 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
736 p->RIOError.Error = NOT_SUPER_USER;
739 p->RIOPolling = NOT_POLLING;
744 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
745 if (copy_from_user(&DebugCtrl, argp, sizeof(DebugCtrl))) {
746 p->RIOError.Error = COPYIN_FAILED;
749 if (DebugCtrl.SysPort == NO_PORT) {
750 if (cmd == RIO_SETDEBUG) {
752 p->RIOError.Error = NOT_SUPER_USER;
755 p->rio_debug = DebugCtrl.Debug;
756 p->RIODebugWait = DebugCtrl.Wait;
757 rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
759 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
760 DebugCtrl.Debug = p->rio_debug;
761 DebugCtrl.Wait = p->RIODebugWait;
762 if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
763 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
764 p->RIOError.Error = COPYOUT_FAILED;
768 } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
769 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
770 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
772 } else if (cmd == RIO_SETDEBUG) {
774 p->RIOError.Error = NOT_SUPER_USER;
777 rio_spin_lock_irqsave(&PortP->portSem, flags);
778 p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
779 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
780 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
782 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
783 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
784 if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
785 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
786 p->RIOError.Error = COPYOUT_FAILED;
794 ** Enquire about the release and version.
795 ** We return MAX_VERSION_LEN bytes, being a
796 ** textual null terminated string.
798 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
799 if (copy_to_user(argp, RIOVersid(), sizeof(struct rioVersion))) {
800 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
801 p->RIOError.Error = COPYOUT_FAILED;
808 ** Enquire as to the number of hosts located
811 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
812 if (copy_to_user(argp, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
813 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
814 p->RIOError.Error = COPYOUT_FAILED;
821 ** Kill host. This may not be in the final version...
823 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", arg);
825 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
826 p->RIOError.Error = NOT_SUPER_USER;
832 for (Host = 0; Host < p->RIONumHosts; Host++) {
833 (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
834 memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
835 p->RIOHosts[Host].Flags = RC_WAITING;
838 p->RIONumBootPkts = 0;
840 printk("HEEEEELP!\n");
842 for (loop = 0; loop < RIO_PORTS; loop++) {
843 spin_lock_init(&p->RIOPortp[loop]->portSem);
844 p->RIOPortp[loop]->InUse = NOT_INUSE;
851 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
853 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
854 p->RIOError.Error = NOT_SUPER_USER;
857 if (copy_from_user(&DownLoad, argp, sizeof(DownLoad))) {
858 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
859 p->RIOError.Error = COPYIN_FAILED;
862 rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
865 ** It is important that the product code is an unsigned object!
867 if (DownLoad.ProductCode > MAX_PRODUCT) {
868 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
869 p->RIOError.Error = NO_SUCH_PRODUCT;
875 retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
879 ** and go back, content with a job well completed.
887 if (copy_from_user(&host, argp, sizeof(host))) {
888 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
889 p->RIOError.Error = COPYIN_FAILED;
895 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
896 if (copy_to_user(argp, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
897 p->RIOError.Error = COPYOUT_FAILED;
898 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
905 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
906 if (copy_from_user(&HostReq, argp, sizeof(HostReq))) {
907 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
908 p->RIOError.Error = COPYIN_FAILED;
911 if (HostReq.HostNum >= p->RIONumHosts) {
912 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
913 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
916 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
918 if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
919 p->RIOError.Error = COPYOUT_FAILED;
920 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
926 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
927 if (copy_from_user(&HostDpRam, argp, sizeof(HostDpRam))) {
928 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
929 p->RIOError.Error = COPYIN_FAILED;
932 if (HostDpRam.HostNum >= p->RIONumHosts) {
933 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
934 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
937 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
939 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
941 /* It's hardware like this that really gets on my tits. */
942 static unsigned char copy[sizeof(struct DpRam)];
943 for (off = 0; off < sizeof(struct DpRam); off++)
944 copy[off] = readb(p->RIOHosts[HostDpRam.HostNum].Caddr + off);
945 if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
946 p->RIOError.Error = COPYOUT_FAILED;
947 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
950 } else if (copy_to_user(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
951 p->RIOError.Error = COPYOUT_FAILED;
952 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
958 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
960 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", arg);
961 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
964 rio_spin_lock_irqsave(&PortP->portSem, flags);
965 p->RIOPortp[arg]->State |= RIO_BUSY;
966 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
971 ** The daemon want port information
972 ** (probably for debug reasons)
974 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
975 if (copy_from_user(&PortReq, argp, sizeof(PortReq))) {
976 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
977 p->RIOError.Error = COPYIN_FAILED;
981 if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
982 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
983 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
986 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
987 if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
988 p->RIOError.Error = COPYOUT_FAILED;
989 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
996 ** The daemon want rup information
997 ** (probably for debug reasons)
999 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
1000 if (copy_from_user(&RupReq, argp, sizeof(RupReq))) {
1001 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1002 p->RIOError.Error = COPYIN_FAILED;
1005 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1006 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
1007 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1010 if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */
1011 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
1012 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1015 HostP = &p->RIOHosts[RupReq.HostNum];
1017 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1018 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
1019 p->RIOError.Error = HOST_NOT_RUNNING;
1022 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
1024 if (copy_to_user(RupReq.RupP, HostP->UnixRups[RupReq.RupNum].RupP, sizeof(struct RUP))) {
1025 p->RIOError.Error = COPYOUT_FAILED;
1026 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1033 ** The daemon want lpb information
1034 ** (probably for debug reasons)
1036 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
1037 if (copy_from_user(&LpbReq, argp, sizeof(LpbReq))) {
1038 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1039 p->RIOError.Error = COPYIN_FAILED;
1042 if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
1043 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
1044 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1047 if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */
1048 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
1049 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1052 HostP = &p->RIOHosts[LpbReq.Host];
1054 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1055 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
1056 p->RIOError.Error = HOST_NOT_RUNNING;
1059 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
1061 if (copy_to_user(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
1062 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1063 p->RIOError.Error = COPYOUT_FAILED;
1069 ** Here 3 IOCTL's that allow us to change the way in which
1070 ** rio logs errors. send them just to syslog or send them
1071 ** to both syslog and console or send them to just the console.
1073 ** See RioStrBuf() in util.c for the other half.
1075 case RIO_SYSLOG_ONLY:
1076 p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
1079 case RIO_SYSLOG_CONS:
1080 p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */
1084 p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
1087 case RIO_SIGNALS_ON:
1088 if (p->RIOSignalProcess) {
1089 p->RIOError.Error = SIGNALS_ALREADY_SET;
1092 /* FIXME: PID tracking */
1093 p->RIOSignalProcess = current->pid;
1094 p->RIOPrintDisabled = DONT_PRINT;
1097 case RIO_SIGNALS_OFF:
1098 if (p->RIOSignalProcess != current->pid) {
1099 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1102 rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
1103 p->RIOSignalProcess = 0;
1106 case RIO_SET_BYTE_MODE:
1107 for (Host = 0; Host < p->RIONumHosts; Host++)
1108 if (p->RIOHosts[Host].Type == RIO_AT)
1109 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1112 case RIO_SET_WORD_MODE:
1113 for (Host = 0; Host < p->RIONumHosts; Host++)
1114 if (p->RIOHosts[Host].Type == RIO_AT)
1115 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1118 case RIO_SET_FAST_BUS:
1119 for (Host = 0; Host < p->RIONumHosts; Host++)
1120 if (p->RIOHosts[Host].Type == RIO_AT)
1121 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1124 case RIO_SET_SLOW_BUS:
1125 for (Host = 0; Host < p->RIONumHosts; Host++)
1126 if (p->RIOHosts[Host].Type == RIO_AT)
1127 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1130 case RIO_MAP_B50_TO_50:
1131 case RIO_MAP_B50_TO_57600:
1132 case RIO_MAP_B110_TO_110:
1133 case RIO_MAP_B110_TO_115200:
1134 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
1136 if (port < 0 || port > 511) {
1137 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1138 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1141 rio_spin_lock_irqsave(&PortP->portSem, flags);
1143 case RIO_MAP_B50_TO_50:
1144 p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1146 case RIO_MAP_B50_TO_57600:
1147 p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1149 case RIO_MAP_B110_TO_110:
1150 p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1152 case RIO_MAP_B110_TO_115200:
1153 p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1156 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1159 case RIO_STREAM_INFO:
1160 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
1163 case RIO_SEND_PACKET:
1164 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
1165 if (copy_from_user(&SendPack, argp, sizeof(SendPack))) {
1166 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1167 p->RIOError.Error = COPYIN_FAILED;
1170 if (SendPack.PortNum >= 128) {
1171 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1175 PortP = p->RIOPortp[SendPack.PortNum];
1176 rio_spin_lock_irqsave(&PortP->portSem, flags);
1178 if (!can_add_transmit(&PacketP, PortP)) {
1179 p->RIOError.Error = UNIT_IS_IN_USE;
1180 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1184 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
1185 writeb(SendPack.Data[loop], &PacketP->data[loop]);
1187 writeb(SendPack.Len, &PacketP->len);
1189 add_transmit(PortP);
1191 ** Count characters transmitted for port statistics reporting
1193 if (PortP->statsGather)
1194 PortP->txchars += (SendPack.Len & 127);
1195 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1200 p->RIONoMessage = 1;
1201 return su ? 0 : -EPERM;
1205 p->RIONoMessage = 0;
1206 return su ? 0 : -EPERM;
1209 if (copy_to_user(argp, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
1210 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1211 p->RIOError.Error = COPYOUT_FAILED;
1217 if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
1218 p->RIOError.Error = COPYIN_FAILED;
1221 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
1223 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1224 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1228 if (SubCmd.Host >= p->RIONumHosts) {
1229 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1233 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
1235 PortP = p->RIOPortp[port];
1237 rio_spin_lock_irqsave(&PortP->portSem, flags);
1239 if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) {
1240 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1241 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1244 PortP->State |= RIO_BUSY;
1246 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1247 if (copy_to_user(argp, p->RIOMemDump, MEMDUMP_SIZE)) {
1248 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1249 p->RIOError.Error = COPYOUT_FAILED;
1255 if (arg >= p->RIONumHosts)
1257 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", arg);
1258 writeb(0xFF, &p->RIOHosts[arg].SetInt);
1262 if (arg >= p->RIONumHosts)
1264 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", arg);
1265 writeb(0xFF, &p->RIOHosts[arg].ResetInt);
1268 case RIO_READ_CHECK:
1269 /* Check reads for pkts with data[0] the same */
1270 p->RIOReadCheck = !p->RIOReadCheck;
1271 if (copy_to_user(argp, &p->RIOReadCheck, sizeof(unsigned int))) {
1272 p->RIOError.Error = COPYOUT_FAILED;
1277 case RIO_READ_REGISTER:
1278 if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
1279 p->RIOError.Error = COPYIN_FAILED;
1282 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);
1284 if (SubCmd.Port > 511) {
1285 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
1286 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1290 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1291 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1295 if (SubCmd.Host >= p->RIONumHosts) {
1296 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1300 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1301 PortP = p->RIOPortp[port];
1303 rio_spin_lock_irqsave(&PortP->portSem, flags);
1305 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
1306 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1307 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1310 PortP->State |= RIO_BUSY;
1312 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1313 if (copy_to_user(argp, &p->CdRegister, sizeof(unsigned int))) {
1314 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1315 p->RIOError.Error = COPYOUT_FAILED;
1320 ** rio_make_dev: given port number (0-511) ORed with port type
1321 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1322 ** value to pass to mknod to create the correct device node.
1326 unsigned int port = arg & RIO_MODEM_MASK;
1329 switch (arg & RIO_DEV_MASK) {
1330 case RIO_DEV_DIRECT:
1331 ret = drv_makedev(MAJOR(dev), port);
1332 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
1335 ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1336 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
1338 case RIO_DEV_XPRINT:
1339 ret = drv_makedev(MAJOR(dev), port);
1340 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
1343 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1347 ** rio_minor: given a dev_t from a stat() call, return
1348 ** the port number (0-511) ORed with the port type
1349 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1358 mino = RIO_UNMODEM(dv);
1360 if (RIO_ISMODEM(dv)) {
1361 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
1362 ret = mino | RIO_DEV_MODEM;
1364 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
1365 ret = mino | RIO_DEV_DIRECT;
1370 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
1371 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1378 ** Pre-emptive commands go on RUPs and are only one byte long.
1380 int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
1382 struct CmdBlk *CmdBlkP;
1383 struct PktCmd_M *PktCmdP;
1388 if (PortP->State & RIO_DELETED) {
1389 rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
1393 if ((PortP->InUse == (typeof(PortP->InUse))-1) ||
1394 !(CmdBlkP = RIOGetCmdBlk())) {
1395 rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block "
1396 "for command %d on port %d\n", Cmd, PortP->PortNum);
1400 rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n",
1401 CmdBlkP, PortP->InUse);
1403 PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
1405 CmdBlkP->Packet.src_unit = 0;
1406 if (PortP->SecondBlock)
1409 rup = PortP->RupNum;
1410 CmdBlkP->Packet.dest_unit = rup;
1411 CmdBlkP->Packet.src_port = COMMAND_RUP;
1412 CmdBlkP->Packet.dest_port = COMMAND_RUP;
1413 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1414 CmdBlkP->PostFuncP = RIOUnUse;
1415 CmdBlkP->PostArg = (unsigned long) PortP;
1416 PktCmdP->Command = Cmd;
1417 port = PortP->HostPort % (ushort) PORTS_PER_RTA;
1419 ** Index ports 8-15 for 2nd block of 16 port RTA.
1421 if (PortP->SecondBlock)
1422 port += (ushort) PORTS_PER_RTA;
1423 PktCmdP->PhbNum = port;
1427 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p "
1428 "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
1429 PktCmdP->SubCommand = MEMDUMP;
1430 PktCmdP->SubAddr = SubCmd.Addr;
1433 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n",
1437 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) "
1438 "command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
1439 PktCmdP->SubCommand = READ_REGISTER;
1440 PktCmdP->SubAddr = SubCmd.Addr;
1443 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n",
1447 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n",
1449 CmdBlkP->PostFuncP = RIORFlushEnable;
1452 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n",
1457 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n",
1464 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
1465 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command "
1466 "blk %p\n", CmdBlkP);
1471 ** If we have queued up the maximum number of Write flushes
1472 ** allowed then we should not bother sending any more to the
1475 if (PortP->WflushFlag == (typeof(PortP->WflushFlag))-1) {
1476 rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, "
1477 "WflushFlag about to wrap!");
1478 RIOFreeCmdBlk(CmdBlkP);
1481 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command "
1482 "blk %p\n", CmdBlkP);
1483 CmdBlkP->PostFuncP = RIOWFlushMark;
1490 Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);