[PATCH] Yet more rio cleaning (2 of 2)
[firewire-audio.git] / drivers / char / rio / rioctrl.c
blobd31aba62bb7f362d87d8e38961f0abc2ba197abc
1 /*
2 ** -----------------------------------------------------------------------------
3 **
4 ** Perle Specialix driver for Linux
5 ** Ported from existing RIO Driver for SCO sources.
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 ** Module : rioctrl.c
24 ** SID : 1.3
25 ** Last Modified : 11/6/98 10:33:42
26 ** Retrieved : 11/6/98 10:33:49
28 ** ident @(#)rioctrl.c 1.3
30 ** -----------------------------------------------------------------------------
32 #ifdef SCCS_LABELS
33 static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c 1.3";
34 #endif
37 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/errno.h>
40 #include <asm/io.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"
54 #include "pkt.h"
55 #include "daemon.h"
56 #include "rio.h"
57 #include "riospace.h"
58 #include "cmdpkt.h"
59 #include "map.h"
60 #include "rup.h"
61 #include "port.h"
62 #include "riodrvr.h"
63 #include "rioinfo.h"
64 #include "func.h"
65 #include "errors.h"
66 #include "pci.h"
68 #include "parmmap.h"
69 #include "unixrup.h"
70 #include "board.h"
71 #include "host.h"
72 #include "phb.h"
73 #include "link.h"
74 #include "cmdblk.h"
75 #include "route.h"
76 #include "cirrus.h"
77 #include "rioioctl.h"
80 static struct LpbReq LpbReq;
81 static struct RupReq RupReq;
82 static struct PortReq PortReq;
83 static struct HostReq HostReq;
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 {
97 ushort Host;
98 ushort Rup;
99 ushort Port;
100 ushort Addr;
101 } SubCmd;
103 struct PortTty {
104 uint port;
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
115 ** about the boot.
116 ** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
117 ** process to bog off.
119 static int
120 (*RIOBootTable[MAX_PRODUCT]) (struct rio_info *, struct DownLoad *) = {
121 /* 0 */ RIOBootCodeHOST,
122 /* Host Card */
123 /* 1 */ RIOBootCodeRTA,
124 /* RTA */
127 #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
129 int riocontrol(p, dev, cmd, arg, su)
130 struct rio_info *p;
131 dev_t dev;
132 int cmd;
133 caddr_t arg;
134 int su;
136 uint Host; /* leave me unsigned! */
137 uint port; /* and me! */
138 struct Host *HostP;
139 ushort loop;
140 int Entry;
141 struct Port *PortP;
142 struct PKT *PacketP;
143 int retval = 0;
144 unsigned long flags;
146 func_enter();
148 /* Confuse the compiler to think that we've initialized these */
149 Host = 0;
150 PortP = NULL;
152 rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, arg);
154 switch (cmd) {
156 ** RIO_SET_TIMER
158 ** Change the value of the host card interrupt timer.
159 ** If the host card number is -1 then all host cards are changed
160 ** otherwise just the specified host card will be changed.
162 case RIO_SET_TIMER:
163 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", (unsigned long)arg);
165 int host, value;
166 host = ((unsigned long) arg >> 16) & 0x0000FFFF;
167 value = (unsigned long) arg & 0x0000ffff;
168 if (host == -1) {
169 for (host = 0; host < p->RIONumHosts; host++) {
170 if (p->RIOHosts[host].Flags == RC_RUNNING) {
171 writew(value, &p->RIOHosts[host].ParmMapP->timer);
174 } else if (host >= p->RIONumHosts) {
175 return -EINVAL;
176 } else {
177 if (p->RIOHosts[host].Flags == RC_RUNNING) {
178 writew(value, &p->RIOHosts[host].ParmMapP->timer);
182 return 0;
184 case RIO_FOAD_RTA:
185 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
186 return RIOCommandRta(p, (unsigned long)arg, RIOFoadRta);
188 case RIO_ZOMBIE_RTA:
189 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
190 return RIOCommandRta(p, (unsigned long)arg, RIOZombieRta);
192 case RIO_IDENTIFY_RTA:
193 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
194 return RIOIdentifyRta(p, arg);
196 case RIO_KILL_NEIGHBOUR:
197 rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
198 return RIOKillNeighbour(p, arg);
200 case SPECIAL_RUP_CMD:
202 struct CmdBlk *CmdBlkP;
204 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
205 if (copy_from_user(&SpecialRupCmd, arg, sizeof(SpecialRupCmd))) {
206 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
207 p->RIOError.Error = COPYIN_FAILED;
208 return -EFAULT;
210 CmdBlkP = RIOGetCmdBlk();
211 if (!CmdBlkP) {
212 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
213 return -ENXIO;
215 CmdBlkP->Packet = SpecialRupCmd.Packet;
216 if (SpecialRupCmd.Host >= p->RIONumHosts)
217 SpecialRupCmd.Host = 0;
218 rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
219 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
220 printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
222 return 0;
225 case RIO_DEBUG_MEM:
226 return -EPERM;
228 case RIO_ALL_MODEM:
229 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
230 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
231 return -EINVAL;
233 case RIO_GET_TABLE:
235 ** Read the routing table from the device driver to user space
237 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
239 if ((retval = RIOApel(p)) != 0)
240 return retval;
242 if (copy_to_user(arg, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
243 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
244 p->RIOError.Error = COPYOUT_FAILED;
245 return -EFAULT;
249 int entry;
250 rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
251 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
252 if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
253 continue;
255 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
256 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
257 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
258 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
259 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
260 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
261 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
262 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
263 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
264 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
265 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
266 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
267 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
268 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
269 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
271 rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
273 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
274 return 0;
276 case RIO_PUT_TABLE:
278 ** Write the routing table to the device driver from user space
280 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
282 if (!su) {
283 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
284 p->RIOError.Error = NOT_SUPER_USER;
285 return -EPERM;
287 if (copy_from_user(&p->RIOConnectTable[0], arg, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
288 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
289 p->RIOError.Error = COPYIN_FAILED;
290 return -EFAULT;
293 ***********************************
295 int entry;
296 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
297 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
299 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
300 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
301 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
302 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
303 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
304 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
305 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
306 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
307 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
308 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
309 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
310 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
311 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
312 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
313 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
315 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
317 ***********************************
319 return RIONewTable(p);
321 case RIO_GET_BINDINGS:
323 ** Send bindings table, containing unique numbers of RTAs owned
324 ** by this system to user space
326 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
328 if (!su) {
329 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
330 p->RIOError.Error = NOT_SUPER_USER;
331 return -EPERM;
333 if (copy_to_user(arg, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
334 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
335 p->RIOError.Error = COPYOUT_FAILED;
336 return -EFAULT;
338 return 0;
340 case RIO_PUT_BINDINGS:
342 ** Receive a bindings table, containing unique numbers of RTAs owned
343 ** by this system
345 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
347 if (!su) {
348 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
349 p->RIOError.Error = NOT_SUPER_USER;
350 return -EPERM;
352 if (copy_from_user(&p->RIOBindTab[0], arg, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
353 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
354 p->RIOError.Error = COPYIN_FAILED;
355 return -EFAULT;
357 return 0;
359 case RIO_BIND_RTA:
361 int EmptySlot = -1;
363 ** Bind this RTA to host, so that it will be booted by
364 ** host in 'boot owned RTAs' mode.
366 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
368 if (!su) {
369 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
370 p->RIOError.Error = NOT_SUPER_USER;
371 return -EPERM;
373 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
374 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
375 EmptySlot = Entry;
376 else if (p->RIOBindTab[Entry] == (long)arg) {
378 ** Already exists - delete
380 p->RIOBindTab[Entry] = 0L;
381 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", (unsigned long)arg);
382 return 0;
386 ** Dosen't exist - add
388 if (EmptySlot != -1) {
389 p->RIOBindTab[EmptySlot] = (unsigned long)arg;
390 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", (unsigned long) arg);
391 } else {
392 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", (unsigned long) arg);
393 return -ENOMEM;
395 return 0;
398 case RIO_RESUME:
399 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
400 port = (unsigned long) arg;
401 if ((port < 0) || (port > 511)) {
402 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
403 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
404 return -EINVAL;
406 PortP = p->RIOPortp[port];
407 if (!PortP->Mapped) {
408 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
409 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
410 return -EINVAL;
412 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
413 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
414 return -EINVAL;
417 rio_spin_lock_irqsave(&PortP->portSem, flags);
418 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) {
419 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
420 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
421 return -EBUSY;
422 } else {
423 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
424 PortP->State |= RIO_BUSY;
426 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
427 return retval;
429 case RIO_ASSIGN_RTA:
430 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
431 if (!su) {
432 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
433 p->RIOError.Error = NOT_SUPER_USER;
434 return -EPERM;
436 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
437 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
438 p->RIOError.Error = COPYIN_FAILED;
439 return -EFAULT;
441 return RIOAssignRta(p, &MapEnt);
443 case RIO_CHANGE_NAME:
444 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
445 if (!su) {
446 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
447 p->RIOError.Error = NOT_SUPER_USER;
448 return -EPERM;
450 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
451 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
452 p->RIOError.Error = COPYIN_FAILED;
453 return -EFAULT;
455 return RIOChangeName(p, &MapEnt);
457 case RIO_DELETE_RTA:
458 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
459 if (!su) {
460 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
461 p->RIOError.Error = NOT_SUPER_USER;
462 return -EPERM;
464 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
465 rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
466 p->RIOError.Error = COPYIN_FAILED;
467 return -EFAULT;
469 return RIODeleteRta(p, &MapEnt);
471 case RIO_QUICK_CHECK:
472 if (copy_to_user(arg, &p->RIORtaDisCons, sizeof(unsigned int))) {
473 p->RIOError.Error = COPYOUT_FAILED;
474 return -EFAULT;
476 return 0;
478 case RIO_LAST_ERROR:
479 if (copy_to_user(arg, &p->RIOError, sizeof(struct Error)))
480 return -EFAULT;
481 return 0;
483 case RIO_GET_LOG:
484 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
485 return -EINVAL;
487 case RIO_GET_MODTYPE:
488 if (copy_from_user(&port, arg, sizeof(unsigned int))) {
489 p->RIOError.Error = COPYIN_FAILED;
490 return -EFAULT;
492 rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
493 if (port < 0 || port > 511) {
494 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
495 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
496 return -EINVAL;
498 PortP = (p->RIOPortp[port]);
499 if (!PortP->Mapped) {
500 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
501 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
502 return -EINVAL;
505 ** Return module type of port
507 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
508 if (copy_to_user(arg, &port, sizeof(unsigned int))) {
509 p->RIOError.Error = COPYOUT_FAILED;
510 return -EFAULT;
512 return (0);
513 case RIO_BLOCK_OPENS:
514 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
515 for (Entry = 0; Entry < RIO_PORTS; Entry++) {
516 rio_spin_lock_irqsave(&PortP->portSem, flags);
517 p->RIOPortp[Entry]->WaitUntilBooted = 1;
518 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
520 return 0;
522 case RIO_SETUP_PORTS:
523 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
524 if (copy_from_user(&PortSetup, arg, sizeof(PortSetup))) {
525 p->RIOError.Error = COPYIN_FAILED;
526 rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
527 return -EFAULT;
529 if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
530 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
531 rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
532 return -ENXIO;
534 if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
535 p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
536 rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
537 return -EINVAL;
539 if (!p->RIOPortp) {
540 printk(KERN_ERR "rio: No p->RIOPortp array!\n");
541 rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
542 return -EIO;
544 rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
545 for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
546 rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
548 rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
549 rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
550 return retval;
552 case RIO_GET_PORT_SETUP:
553 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
554 if (copy_from_user(&PortSetup, arg, sizeof(PortSetup))) {
555 p->RIOError.Error = COPYIN_FAILED;
556 return -EFAULT;
558 if (PortSetup.From >= RIO_PORTS) {
559 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
560 return -ENXIO;
563 port = PortSetup.To = PortSetup.From;
564 PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
565 PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
566 PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
567 PortSetup.Store = p->RIOPortp[port]->Store;
568 PortSetup.Lock = p->RIOPortp[port]->Lock;
569 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
570 memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN);
571 memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN);
572 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
573 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
575 if (copy_to_user(arg, &PortSetup, sizeof(PortSetup))) {
576 p->RIOError.Error = COPYOUT_FAILED;
577 return -EFAULT;
579 return retval;
581 case RIO_GET_PORT_PARAMS:
582 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
583 if (copy_from_user(&PortParams, arg, sizeof(struct PortParams))) {
584 p->RIOError.Error = COPYIN_FAILED;
585 return -EFAULT;
587 if (PortParams.Port >= RIO_PORTS) {
588 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
589 return -ENXIO;
591 PortP = (p->RIOPortp[PortParams.Port]);
592 PortParams.Config = PortP->Config;
593 PortParams.State = PortP->State;
594 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
596 if (copy_to_user(arg, &PortParams, sizeof(struct PortParams))) {
597 p->RIOError.Error = COPYOUT_FAILED;
598 return -EFAULT;
600 return retval;
602 case RIO_GET_PORT_TTY:
603 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
604 if (copy_from_user(&PortTty, arg, sizeof(struct PortTty))) {
605 p->RIOError.Error = COPYIN_FAILED;
606 return -EFAULT;
608 if (PortTty.port >= RIO_PORTS) {
609 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
610 return -ENXIO;
613 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
614 PortP = (p->RIOPortp[PortTty.port]);
615 if (copy_to_user(arg, &PortTty, sizeof(struct PortTty))) {
616 p->RIOError.Error = COPYOUT_FAILED;
617 return -EFAULT;
619 return retval;
621 case RIO_SET_PORT_TTY:
622 if (copy_from_user(&PortTty, arg, sizeof(struct PortTty))) {
623 p->RIOError.Error = COPYIN_FAILED;
624 return -EFAULT;
626 rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
627 if (PortTty.port >= (ushort) RIO_PORTS) {
628 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
629 return -ENXIO;
631 PortP = (p->RIOPortp[PortTty.port]);
632 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
633 return retval;
635 case RIO_SET_PORT_PARAMS:
636 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
637 if (copy_from_user(&PortParams, arg, sizeof(PortParams))) {
638 p->RIOError.Error = COPYIN_FAILED;
639 return -EFAULT;
641 if (PortParams.Port >= (ushort) RIO_PORTS) {
642 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
643 return -ENXIO;
645 PortP = (p->RIOPortp[PortParams.Port]);
646 rio_spin_lock_irqsave(&PortP->portSem, flags);
647 PortP->Config = PortParams.Config;
648 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
649 return retval;
651 case RIO_GET_PORT_STATS:
652 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
653 if (copy_from_user(&portStats, arg, sizeof(struct portStats))) {
654 p->RIOError.Error = COPYIN_FAILED;
655 return -EFAULT;
657 if (portStats.port >= RIO_PORTS) {
658 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
659 return -ENXIO;
661 PortP = (p->RIOPortp[portStats.port]);
662 portStats.gather = PortP->statsGather;
663 portStats.txchars = PortP->txchars;
664 portStats.rxchars = PortP->rxchars;
665 portStats.opens = PortP->opens;
666 portStats.closes = PortP->closes;
667 portStats.ioctls = PortP->ioctls;
668 if (copy_to_user(arg, &portStats, sizeof(struct portStats))) {
669 p->RIOError.Error = COPYOUT_FAILED;
670 return -EFAULT;
672 return retval;
674 case RIO_RESET_PORT_STATS:
675 port = (unsigned long) arg;
676 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
677 if (port >= RIO_PORTS) {
678 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
679 return -ENXIO;
681 PortP = (p->RIOPortp[port]);
682 rio_spin_lock_irqsave(&PortP->portSem, flags);
683 PortP->txchars = 0;
684 PortP->rxchars = 0;
685 PortP->opens = 0;
686 PortP->closes = 0;
687 PortP->ioctls = 0;
688 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
689 return retval;
691 case RIO_GATHER_PORT_STATS:
692 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
693 if (copy_from_user(&portStats, arg, sizeof(struct portStats))) {
694 p->RIOError.Error = COPYIN_FAILED;
695 return -EFAULT;
697 if (portStats.port >= RIO_PORTS) {
698 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
699 return -ENXIO;
701 PortP = (p->RIOPortp[portStats.port]);
702 rio_spin_lock_irqsave(&PortP->portSem, flags);
703 PortP->statsGather = portStats.gather;
704 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
705 return retval;
707 case RIO_READ_CONFIG:
708 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
709 if (copy_to_user(arg, &p->RIOConf, sizeof(struct Conf))) {
710 p->RIOError.Error = COPYOUT_FAILED;
711 return -EFAULT;
713 return retval;
715 case RIO_SET_CONFIG:
716 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
717 if (!su) {
718 p->RIOError.Error = NOT_SUPER_USER;
719 return -EPERM;
721 if (copy_from_user(&p->RIOConf, arg, sizeof(struct Conf))) {
722 p->RIOError.Error = COPYIN_FAILED;
723 return -EFAULT;
726 ** move a few value around
728 for (Host = 0; Host < p->RIONumHosts; Host++)
729 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
730 writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
731 return retval;
733 case RIO_START_POLLER:
734 rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
735 return -EINVAL;
737 case RIO_STOP_POLLER:
738 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
739 if (!su) {
740 p->RIOError.Error = NOT_SUPER_USER;
741 return -EPERM;
743 p->RIOPolling = NOT_POLLING;
744 return retval;
746 case RIO_SETDEBUG:
747 case RIO_GETDEBUG:
748 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
749 if (copy_from_user(&DebugCtrl, arg, sizeof(DebugCtrl))) {
750 p->RIOError.Error = COPYIN_FAILED;
751 return -EFAULT;
753 if (DebugCtrl.SysPort == NO_PORT) {
754 if (cmd == RIO_SETDEBUG) {
755 if (!su) {
756 p->RIOError.Error = NOT_SUPER_USER;
757 return -EPERM;
759 p->rio_debug = DebugCtrl.Debug;
760 p->RIODebugWait = DebugCtrl.Wait;
761 rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
762 } else {
763 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
764 DebugCtrl.Debug = p->rio_debug;
765 DebugCtrl.Wait = p->RIODebugWait;
766 if (copy_to_user(arg, &DebugCtrl, sizeof(DebugCtrl))) {
767 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
768 p->RIOError.Error = COPYOUT_FAILED;
769 return -EFAULT;
772 } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
773 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
774 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
775 return -ENXIO;
776 } else if (cmd == RIO_SETDEBUG) {
777 if (!su) {
778 p->RIOError.Error = NOT_SUPER_USER;
779 return -EPERM;
781 rio_spin_lock_irqsave(&PortP->portSem, flags);
782 p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
783 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
784 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
785 } else {
786 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
787 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
788 if (copy_to_user(arg, &DebugCtrl, sizeof(DebugCtrl))) {
789 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
790 p->RIOError.Error = COPYOUT_FAILED;
791 return -EFAULT;
794 return retval;
796 case RIO_VERSID:
798 ** Enquire about the release and version.
799 ** We return MAX_VERSION_LEN bytes, being a
800 ** textual null terminated string.
802 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
803 if (copy_to_user(arg, RIOVersid(), sizeof(struct rioVersion))) {
804 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
805 p->RIOError.Error = COPYOUT_FAILED;
806 return -EFAULT;
808 return retval;
810 case RIO_NUM_HOSTS:
812 ** Enquire as to the number of hosts located
813 ** at init time.
815 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
816 if (copy_to_user(arg, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
817 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
818 p->RIOError.Error = COPYOUT_FAILED;
819 return -EFAULT;
821 return retval;
823 case RIO_HOST_FOAD:
825 ** Kill host. This may not be in the final version...
827 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", (unsigned long) arg);
828 if (!su) {
829 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
830 p->RIOError.Error = NOT_SUPER_USER;
831 return -EPERM;
833 p->RIOHalted = 1;
834 p->RIOSystemUp = 0;
836 for (Host = 0; Host < p->RIONumHosts; Host++) {
837 (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
838 memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
839 p->RIOHosts[Host].Flags = RC_WAITING;
841 RIOFoadWakeup(p);
842 p->RIONumBootPkts = 0;
843 p->RIOBooting = 0;
844 printk("HEEEEELP!\n");
846 for (loop = 0; loop < RIO_PORTS; loop++) {
847 spin_lock_init(&p->RIOPortp[loop]->portSem);
848 p->RIOPortp[loop]->InUse = NOT_INUSE;
851 p->RIOSystemUp = 0;
852 return retval;
854 case RIO_DOWNLOAD:
855 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
856 if (!su) {
857 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
858 p->RIOError.Error = NOT_SUPER_USER;
859 return -EPERM;
861 if (copy_from_user(&DownLoad, arg, sizeof(DownLoad))) {
862 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
863 p->RIOError.Error = COPYIN_FAILED;
864 return -EFAULT;
866 rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
869 ** It is important that the product code is an unsigned object!
871 if (DownLoad.ProductCode > MAX_PRODUCT) {
872 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
873 p->RIOError.Error = NO_SUCH_PRODUCT;
874 return -ENXIO;
877 ** do something!
879 retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
880 /* <-- Panic */
881 p->RIOHalted = 0;
883 ** and go back, content with a job well completed.
885 return retval;
887 case RIO_PARMS:
889 unsigned int host;
891 if (copy_from_user(&host, arg, sizeof(host))) {
892 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
893 p->RIOError.Error = COPYIN_FAILED;
894 return -EFAULT;
897 ** Fetch the parmmap
899 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
900 if (copy_to_user(arg, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
901 p->RIOError.Error = COPYOUT_FAILED;
902 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
903 return -EFAULT;
906 return retval;
908 case RIO_HOST_REQ:
909 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
910 if (copy_from_user(&HostReq, arg, sizeof(HostReq))) {
911 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
912 p->RIOError.Error = COPYIN_FAILED;
913 return -EFAULT;
915 if (HostReq.HostNum >= p->RIONumHosts) {
916 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
917 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
918 return -ENXIO;
920 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
922 if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
923 p->RIOError.Error = COPYOUT_FAILED;
924 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
925 return -EFAULT;
927 return retval;
929 case RIO_HOST_DPRAM:
930 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
931 if (copy_from_user(&HostDpRam, arg, sizeof(HostDpRam))) {
932 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
933 p->RIOError.Error = COPYIN_FAILED;
934 return -EFAULT;
936 if (HostDpRam.HostNum >= p->RIONumHosts) {
937 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
938 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
939 return -ENXIO;
941 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
943 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
944 int off;
945 /* It's hardware like this that really gets on my tits. */
946 static unsigned char copy[sizeof(struct DpRam)];
947 for (off = 0; off < sizeof(struct DpRam); off++)
948 copy[off] = readb(&p->RIOHosts[HostDpRam.HostNum].Caddr[off]);
949 if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
950 p->RIOError.Error = COPYOUT_FAILED;
951 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
952 return -EFAULT;
954 } else if (copy_to_user(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
955 p->RIOError.Error = COPYOUT_FAILED;
956 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
957 return -EFAULT;
959 return retval;
961 case RIO_SET_BUSY:
962 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
963 if ((unsigned long) arg > 511) {
964 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", (unsigned long) arg);
965 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
966 return -EINVAL;
968 rio_spin_lock_irqsave(&PortP->portSem, flags);
969 p->RIOPortp[(unsigned long) arg]->State |= RIO_BUSY;
970 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
971 return retval;
973 case RIO_HOST_PORT:
975 ** The daemon want port information
976 ** (probably for debug reasons)
978 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
979 if (copy_from_user(&PortReq, arg, sizeof(PortReq))) {
980 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
981 p->RIOError.Error = COPYIN_FAILED;
982 return -EFAULT;
985 if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
986 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
987 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
988 return -ENXIO;
990 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
991 if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
992 p->RIOError.Error = COPYOUT_FAILED;
993 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
994 return -EFAULT;
996 return retval;
998 case RIO_HOST_RUP:
1000 ** The daemon want rup information
1001 ** (probably for debug reasons)
1003 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
1004 if (copy_from_user(&RupReq, arg, sizeof(RupReq))) {
1005 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1006 p->RIOError.Error = COPYIN_FAILED;
1007 return -EFAULT;
1009 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1010 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
1011 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1012 return -ENXIO;
1014 if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */
1015 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
1016 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1017 return -EINVAL;
1019 HostP = &p->RIOHosts[RupReq.HostNum];
1021 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1022 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
1023 p->RIOError.Error = HOST_NOT_RUNNING;
1024 return -EIO;
1026 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
1028 if (copy_to_user(HostP->UnixRups[RupReq.RupNum].RupP, RupReq.RupP, sizeof(struct RUP))) {
1029 p->RIOError.Error = COPYOUT_FAILED;
1030 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1031 return -EFAULT;
1033 return retval;
1035 case RIO_HOST_LPB:
1037 ** The daemon want lpb information
1038 ** (probably for debug reasons)
1040 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
1041 if (copy_from_user(&LpbReq, arg, sizeof(LpbReq))) {
1042 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1043 p->RIOError.Error = COPYIN_FAILED;
1044 return -EFAULT;
1046 if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
1047 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
1048 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1049 return -ENXIO;
1051 if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */
1052 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
1053 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1054 return -EINVAL;
1056 HostP = &p->RIOHosts[LpbReq.Host];
1058 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1059 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
1060 p->RIOError.Error = HOST_NOT_RUNNING;
1061 return -EIO;
1063 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
1065 if (copy_to_user(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
1066 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1067 p->RIOError.Error = COPYOUT_FAILED;
1068 return -EFAULT;
1070 return retval;
1073 ** Here 3 IOCTL's that allow us to change the way in which
1074 ** rio logs errors. send them just to syslog or send them
1075 ** to both syslog and console or send them to just the console.
1077 ** See RioStrBuf() in util.c for the other half.
1079 case RIO_SYSLOG_ONLY:
1080 p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
1081 return 0;
1083 case RIO_SYSLOG_CONS:
1084 p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */
1085 return 0;
1087 case RIO_CONS_ONLY:
1088 p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
1089 return 0;
1091 case RIO_SIGNALS_ON:
1092 if (p->RIOSignalProcess) {
1093 p->RIOError.Error = SIGNALS_ALREADY_SET;
1094 return -EBUSY;
1096 /* FIXME: PID tracking */
1097 p->RIOSignalProcess = current->pid;
1098 p->RIOPrintDisabled = DONT_PRINT;
1099 return retval;
1101 case RIO_SIGNALS_OFF:
1102 if (p->RIOSignalProcess != current->pid) {
1103 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1104 return -EPERM;
1106 rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
1107 p->RIOSignalProcess = 0;
1108 return retval;
1110 case RIO_SET_BYTE_MODE:
1111 for (Host = 0; Host < p->RIONumHosts; Host++)
1112 if (p->RIOHosts[Host].Type == RIO_AT)
1113 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1114 return retval;
1116 case RIO_SET_WORD_MODE:
1117 for (Host = 0; Host < p->RIONumHosts; Host++)
1118 if (p->RIOHosts[Host].Type == RIO_AT)
1119 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1120 return retval;
1122 case RIO_SET_FAST_BUS:
1123 for (Host = 0; Host < p->RIONumHosts; Host++)
1124 if (p->RIOHosts[Host].Type == RIO_AT)
1125 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1126 return retval;
1128 case RIO_SET_SLOW_BUS:
1129 for (Host = 0; Host < p->RIONumHosts; Host++)
1130 if (p->RIOHosts[Host].Type == RIO_AT)
1131 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1132 return retval;
1134 case RIO_MAP_B50_TO_50:
1135 case RIO_MAP_B50_TO_57600:
1136 case RIO_MAP_B110_TO_110:
1137 case RIO_MAP_B110_TO_115200:
1138 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
1139 port = (unsigned long) arg;
1140 if (port < 0 || port > 511) {
1141 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1142 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1143 return -EINVAL;
1145 rio_spin_lock_irqsave(&PortP->portSem, flags);
1146 switch (cmd) {
1147 case RIO_MAP_B50_TO_50:
1148 p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1149 break;
1150 case RIO_MAP_B50_TO_57600:
1151 p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1152 break;
1153 case RIO_MAP_B110_TO_110:
1154 p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1155 break;
1156 case RIO_MAP_B110_TO_115200:
1157 p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1158 break;
1160 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1161 return retval;
1163 case RIO_STREAM_INFO:
1164 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
1165 return -EINVAL;
1167 case RIO_SEND_PACKET:
1168 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
1169 if (copy_from_user(&SendPack, arg, sizeof(SendPack))) {
1170 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1171 p->RIOError.Error = COPYIN_FAILED;
1172 return -EFAULT;
1174 if (SendPack.PortNum >= 128) {
1175 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1176 return -ENXIO;
1179 PortP = p->RIOPortp[SendPack.PortNum];
1180 rio_spin_lock_irqsave(&PortP->portSem, flags);
1182 if (!can_add_transmit(&PacketP, PortP)) {
1183 p->RIOError.Error = UNIT_IS_IN_USE;
1184 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1185 return -ENOSPC;
1188 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
1189 writeb(SendPack.Data[loop], &PacketP->data[loop]);
1191 writeb(SendPack.Len, &PacketP->len);
1193 add_transmit(PortP);
1195 ** Count characters transmitted for port statistics reporting
1197 if (PortP->statsGather)
1198 PortP->txchars += (SendPack.Len & 127);
1199 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1200 return retval;
1202 case RIO_NO_MESG:
1203 if (su)
1204 p->RIONoMessage = 1;
1205 return su ? 0 : -EPERM;
1207 case RIO_MESG:
1208 if (su)
1209 p->RIONoMessage = 0;
1210 return su ? 0 : -EPERM;
1212 case RIO_WHAT_MESG:
1213 if (copy_to_user(arg, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
1214 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1215 p->RIOError.Error = COPYOUT_FAILED;
1216 return -EFAULT;
1218 return 0;
1220 case RIO_MEM_DUMP:
1221 if (copy_from_user(&SubCmd, arg, sizeof(struct SubCmdStruct))) {
1222 p->RIOError.Error = COPYIN_FAILED;
1223 return -EFAULT;
1225 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
1227 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1228 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1229 return -EINVAL;
1232 if (SubCmd.Host >= p->RIONumHosts) {
1233 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1234 return -EINVAL;
1237 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
1239 PortP = p->RIOPortp[port];
1241 rio_spin_lock_irqsave(&PortP->portSem, flags);
1243 if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) {
1244 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1245 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1246 return -EBUSY;
1247 } else
1248 PortP->State |= RIO_BUSY;
1250 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1251 if (copy_to_user(arg, p->RIOMemDump, MEMDUMP_SIZE)) {
1252 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1253 p->RIOError.Error = COPYOUT_FAILED;
1254 return -EFAULT;
1256 return 0;
1258 case RIO_TICK:
1259 if ((unsigned long) arg >= p->RIONumHosts)
1260 return -EINVAL;
1261 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", (unsigned long) arg);
1262 writeb(0xFF, &p->RIOHosts[(unsigned long) arg].SetInt);
1263 return 0;
1265 case RIO_TOCK:
1266 if ((unsigned long) arg >= p->RIONumHosts)
1267 return -EINVAL;
1268 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", (unsigned long) arg);
1269 writeb(0xFF, &p->RIOHosts[(unsigned long) arg].ResetInt);
1270 return 0;
1272 case RIO_READ_CHECK:
1273 /* Check reads for pkts with data[0] the same */
1274 p->RIOReadCheck = !p->RIOReadCheck;
1275 if (copy_to_user(arg, &p->RIOReadCheck, sizeof(unsigned int))) {
1276 p->RIOError.Error = COPYOUT_FAILED;
1277 return -EFAULT;
1279 return 0;
1281 case RIO_READ_REGISTER:
1282 if (copy_from_user(&SubCmd, arg, sizeof(struct SubCmdStruct))) {
1283 p->RIOError.Error = COPYIN_FAILED;
1284 return -EFAULT;
1286 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);
1288 if (SubCmd.Port > 511) {
1289 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
1290 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1291 return -EINVAL;
1294 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1295 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1296 return -EINVAL;
1299 if (SubCmd.Host >= p->RIONumHosts) {
1300 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1301 return -EINVAL;
1304 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1305 PortP = p->RIOPortp[port];
1307 rio_spin_lock_irqsave(&PortP->portSem, flags);
1309 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
1310 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1311 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1312 return -EBUSY;
1313 } else
1314 PortP->State |= RIO_BUSY;
1316 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1317 if (copy_to_user(arg, &p->CdRegister, sizeof(unsigned int))) {
1318 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1319 p->RIOError.Error = COPYOUT_FAILED;
1320 return -EFAULT;
1322 return 0;
1324 ** rio_make_dev: given port number (0-511) ORed with port type
1325 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1326 ** value to pass to mknod to create the correct device node.
1328 case RIO_MAKE_DEV:
1330 unsigned int port = (unsigned long) arg & RIO_MODEM_MASK;
1331 unsigned int ret;
1333 switch ((unsigned long) arg & RIO_DEV_MASK) {
1334 case RIO_DEV_DIRECT:
1335 ret = drv_makedev(MAJOR(dev), port);
1336 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
1337 return ret;
1338 case RIO_DEV_MODEM:
1339 ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1340 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
1341 return ret;
1342 case RIO_DEV_XPRINT:
1343 ret = drv_makedev(MAJOR(dev), port);
1344 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
1345 return ret;
1347 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1348 return -EINVAL;
1351 ** rio_minor: given a dev_t from a stat() call, return
1352 ** the port number (0-511) ORed with the port type
1353 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1355 case RIO_MINOR:
1357 dev_t dv;
1358 int mino;
1359 unsigned long ret;
1361 dv = (dev_t) ((unsigned long) arg);
1362 mino = RIO_UNMODEM(dv);
1364 if (RIO_ISMODEM(dv)) {
1365 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
1366 ret = mino | RIO_DEV_MODEM;
1367 } else {
1368 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
1369 ret = mino | RIO_DEV_DIRECT;
1371 return ret;
1374 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
1375 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1377 func_exit();
1378 return -EINVAL;
1382 ** Pre-emptive commands go on RUPs and are only one byte long.
1384 int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
1386 struct CmdBlk *CmdBlkP;
1387 struct PktCmd_M *PktCmdP;
1388 int Ret;
1389 ushort rup;
1390 int port;
1392 if (PortP->State & RIO_DELETED) {
1393 rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
1394 return RIO_FAIL;
1397 if (((int) ((char) PortP->InUse) == -1) || !(CmdBlkP = RIOGetCmdBlk())) {
1398 rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block for command %d on port %d\n", Cmd, PortP->PortNum);
1399 return RIO_FAIL;
1402 rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n", CmdBlkP, PortP->InUse);
1404 PktCmdP = (struct PktCmd_M *) &CmdBlkP->Packet.data[0];
1406 CmdBlkP->Packet.src_unit = 0;
1407 if (PortP->SecondBlock)
1408 rup = PortP->ID2;
1409 else
1410 rup = PortP->RupNum;
1411 CmdBlkP->Packet.dest_unit = rup;
1412 CmdBlkP->Packet.src_port = COMMAND_RUP;
1413 CmdBlkP->Packet.dest_port = COMMAND_RUP;
1414 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1415 CmdBlkP->PostFuncP = RIOUnUse;
1416 CmdBlkP->PostArg = (unsigned long) PortP;
1417 PktCmdP->Command = Cmd;
1418 port = PortP->HostPort % (ushort) PORTS_PER_RTA;
1420 ** Index ports 8-15 for 2nd block of 16 port RTA.
1422 if (PortP->SecondBlock)
1423 port += (ushort) PORTS_PER_RTA;
1424 PktCmdP->PhbNum = port;
1426 switch (Cmd) {
1427 case MEMDUMP:
1428 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p (addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
1429 PktCmdP->SubCommand = MEMDUMP;
1430 PktCmdP->SubAddr = SubCmd.Addr;
1431 break;
1432 case FCLOSE:
1433 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n", CmdBlkP);
1434 break;
1435 case READ_REGISTER:
1436 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
1437 PktCmdP->SubCommand = READ_REGISTER;
1438 PktCmdP->SubAddr = SubCmd.Addr;
1439 break;
1440 case RESUME:
1441 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n", CmdBlkP);
1442 break;
1443 case RFLUSH:
1444 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n", CmdBlkP);
1445 CmdBlkP->PostFuncP = RIORFlushEnable;
1446 break;
1447 case SUSPEND:
1448 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n", CmdBlkP);
1449 break;
1451 case MGET:
1452 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n", CmdBlkP);
1453 break;
1455 case MSET:
1456 case MBIC:
1457 case MBIS:
1458 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
1459 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk %p\n", CmdBlkP);
1460 break;
1462 case WFLUSH:
1464 ** If we have queued up the maximum number of Write flushes
1465 ** allowed then we should not bother sending any more to the
1466 ** RTA.
1468 if ((int) ((char) PortP->WflushFlag) == (int) -1) {
1469 rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, WflushFlag about to wrap!");
1470 RIOFreeCmdBlk(CmdBlkP);
1471 return (RIO_FAIL);
1472 } else {
1473 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command blk %p\n", CmdBlkP);
1474 CmdBlkP->PostFuncP = RIOWFlushMark;
1476 break;
1479 PortP->InUse++;
1481 Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);
1483 return Ret;