[XFS] fix unaligned access in readdir
[wrt350n-kernel.git] / drivers / char / rio / rioctrl.c
blob7ce77619707cf2f4fa1db2480d1acaebaf968ca9
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; /* 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 {
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 static int copy_from_io(void __user *to, void __iomem *from, size_t size)
131 void *buf = kmalloc(size, GFP_KERNEL);
132 int res = -ENOMEM;
133 if (buf) {
134 rio_memcpy_fromio(buf, from, size);
135 res = copy_to_user(to, buf, size);
136 kfree(buf);
138 return res;
141 int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su)
143 uint Host; /* leave me unsigned! */
144 uint port; /* and me! */
145 struct Host *HostP;
146 ushort loop;
147 int Entry;
148 struct Port *PortP;
149 struct PKT __iomem *PacketP;
150 int retval = 0;
151 unsigned long flags;
152 void __user *argp = (void __user *)arg;
154 func_enter();
156 /* Confuse the compiler to think that we've initialized these */
157 Host = 0;
158 PortP = NULL;
160 rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, argp);
162 switch (cmd) {
164 ** RIO_SET_TIMER
166 ** Change the value of the host card interrupt timer.
167 ** If the host card number is -1 then all host cards are changed
168 ** otherwise just the specified host card will be changed.
170 case RIO_SET_TIMER:
171 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", arg);
173 int host, value;
174 host = (arg >> 16) & 0x0000FFFF;
175 value = arg & 0x0000ffff;
176 if (host == -1) {
177 for (host = 0; host < p->RIONumHosts; host++) {
178 if (p->RIOHosts[host].Flags == RC_RUNNING) {
179 writew(value, &p->RIOHosts[host].ParmMapP->timer);
182 } else if (host >= p->RIONumHosts) {
183 return -EINVAL;
184 } else {
185 if (p->RIOHosts[host].Flags == RC_RUNNING) {
186 writew(value, &p->RIOHosts[host].ParmMapP->timer);
190 return 0;
192 case RIO_FOAD_RTA:
193 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
194 return RIOCommandRta(p, arg, RIOFoadRta);
196 case RIO_ZOMBIE_RTA:
197 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
198 return RIOCommandRta(p, arg, RIOZombieRta);
200 case RIO_IDENTIFY_RTA:
201 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
202 return RIOIdentifyRta(p, argp);
204 case RIO_KILL_NEIGHBOUR:
205 rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
206 return RIOKillNeighbour(p, argp);
208 case SPECIAL_RUP_CMD:
210 struct CmdBlk *CmdBlkP;
212 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
213 if (copy_from_user(&SpecialRupCmd, argp, sizeof(SpecialRupCmd))) {
214 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
215 p->RIOError.Error = COPYIN_FAILED;
216 return -EFAULT;
218 CmdBlkP = RIOGetCmdBlk();
219 if (!CmdBlkP) {
220 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
221 return -ENXIO;
223 CmdBlkP->Packet = SpecialRupCmd.Packet;
224 if (SpecialRupCmd.Host >= p->RIONumHosts)
225 SpecialRupCmd.Host = 0;
226 rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
227 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
228 printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
230 return 0;
233 case RIO_DEBUG_MEM:
234 return -EPERM;
236 case RIO_ALL_MODEM:
237 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
238 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
239 return -EINVAL;
241 case RIO_GET_TABLE:
243 ** Read the routing table from the device driver to user space
245 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
247 if ((retval = RIOApel(p)) != 0)
248 return retval;
250 if (copy_to_user(argp, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
251 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
252 p->RIOError.Error = COPYOUT_FAILED;
253 return -EFAULT;
257 int entry;
258 rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
259 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
260 if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
261 continue;
263 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
264 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
265 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
266 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
267 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
268 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
269 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
270 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
271 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
272 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
273 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
274 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
275 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
276 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
277 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
279 rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
281 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
282 return 0;
284 case RIO_PUT_TABLE:
286 ** Write the routing table to the device driver from user space
288 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
290 if (!su) {
291 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
292 p->RIOError.Error = NOT_SUPER_USER;
293 return -EPERM;
295 if (copy_from_user(&p->RIOConnectTable[0], argp, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
296 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
297 p->RIOError.Error = COPYIN_FAILED;
298 return -EFAULT;
301 ***********************************
303 int entry;
304 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
305 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
307 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
308 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
309 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
310 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
311 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
312 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
313 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
314 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
315 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
316 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
317 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
318 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
319 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
320 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
321 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
323 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
325 ***********************************
327 return RIONewTable(p);
329 case RIO_GET_BINDINGS:
331 ** Send bindings table, containing unique numbers of RTAs owned
332 ** by this system to user space
334 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
336 if (!su) {
337 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
338 p->RIOError.Error = NOT_SUPER_USER;
339 return -EPERM;
341 if (copy_to_user(argp, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
342 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
343 p->RIOError.Error = COPYOUT_FAILED;
344 return -EFAULT;
346 return 0;
348 case RIO_PUT_BINDINGS:
350 ** Receive a bindings table, containing unique numbers of RTAs owned
351 ** by this system
353 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
355 if (!su) {
356 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
357 p->RIOError.Error = NOT_SUPER_USER;
358 return -EPERM;
360 if (copy_from_user(&p->RIOBindTab[0], argp, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
361 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
362 p->RIOError.Error = COPYIN_FAILED;
363 return -EFAULT;
365 return 0;
367 case RIO_BIND_RTA:
369 int EmptySlot = -1;
371 ** Bind this RTA to host, so that it will be booted by
372 ** host in 'boot owned RTAs' mode.
374 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
376 if (!su) {
377 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
378 p->RIOError.Error = NOT_SUPER_USER;
379 return -EPERM;
381 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
382 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
383 EmptySlot = Entry;
384 else if (p->RIOBindTab[Entry] == arg) {
386 ** Already exists - delete
388 p->RIOBindTab[Entry] = 0L;
389 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", arg);
390 return 0;
394 ** Dosen't exist - add
396 if (EmptySlot != -1) {
397 p->RIOBindTab[EmptySlot] = arg;
398 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", arg);
399 } else {
400 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", arg);
401 return -ENOMEM;
403 return 0;
406 case RIO_RESUME:
407 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
408 port = arg;
409 if ((port < 0) || (port > 511)) {
410 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
411 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
412 return -EINVAL;
414 PortP = p->RIOPortp[port];
415 if (!PortP->Mapped) {
416 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
417 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
418 return -EINVAL;
420 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
421 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
422 return -EINVAL;
425 rio_spin_lock_irqsave(&PortP->portSem, flags);
426 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) {
427 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
428 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
429 return -EBUSY;
430 } else {
431 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
432 PortP->State |= RIO_BUSY;
434 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
435 return retval;
437 case RIO_ASSIGN_RTA:
438 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
439 if (!su) {
440 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
441 p->RIOError.Error = NOT_SUPER_USER;
442 return -EPERM;
444 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
445 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
446 p->RIOError.Error = COPYIN_FAILED;
447 return -EFAULT;
449 return RIOAssignRta(p, &MapEnt);
451 case RIO_CHANGE_NAME:
452 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
453 if (!su) {
454 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
455 p->RIOError.Error = NOT_SUPER_USER;
456 return -EPERM;
458 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
459 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
460 p->RIOError.Error = COPYIN_FAILED;
461 return -EFAULT;
463 return RIOChangeName(p, &MapEnt);
465 case RIO_DELETE_RTA:
466 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
467 if (!su) {
468 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
469 p->RIOError.Error = NOT_SUPER_USER;
470 return -EPERM;
472 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
473 rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
474 p->RIOError.Error = COPYIN_FAILED;
475 return -EFAULT;
477 return RIODeleteRta(p, &MapEnt);
479 case RIO_QUICK_CHECK:
480 if (copy_to_user(argp, &p->RIORtaDisCons, sizeof(unsigned int))) {
481 p->RIOError.Error = COPYOUT_FAILED;
482 return -EFAULT;
484 return 0;
486 case RIO_LAST_ERROR:
487 if (copy_to_user(argp, &p->RIOError, sizeof(struct Error)))
488 return -EFAULT;
489 return 0;
491 case RIO_GET_LOG:
492 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
493 return -EINVAL;
495 case RIO_GET_MODTYPE:
496 if (copy_from_user(&port, argp, sizeof(unsigned int))) {
497 p->RIOError.Error = COPYIN_FAILED;
498 return -EFAULT;
500 rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
501 if (port < 0 || port > 511) {
502 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
503 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
504 return -EINVAL;
506 PortP = (p->RIOPortp[port]);
507 if (!PortP->Mapped) {
508 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
509 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
510 return -EINVAL;
513 ** Return module type of port
515 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
516 if (copy_to_user(argp, &port, sizeof(unsigned int))) {
517 p->RIOError.Error = COPYOUT_FAILED;
518 return -EFAULT;
520 return (0);
521 case RIO_BLOCK_OPENS:
522 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
523 for (Entry = 0; Entry < RIO_PORTS; Entry++) {
524 rio_spin_lock_irqsave(&PortP->portSem, flags);
525 p->RIOPortp[Entry]->WaitUntilBooted = 1;
526 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
528 return 0;
530 case RIO_SETUP_PORTS:
531 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
532 if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
533 p->RIOError.Error = COPYIN_FAILED;
534 rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
535 return -EFAULT;
537 if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
538 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
539 rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
540 return -ENXIO;
542 if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
543 p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
544 rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
545 return -EINVAL;
547 if (!p->RIOPortp) {
548 printk(KERN_ERR "rio: No p->RIOPortp array!\n");
549 rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
550 return -EIO;
552 rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
553 for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
554 rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
556 rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
557 rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
558 return retval;
560 case RIO_GET_PORT_SETUP:
561 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
562 if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
563 p->RIOError.Error = COPYIN_FAILED;
564 return -EFAULT;
566 if (PortSetup.From >= RIO_PORTS) {
567 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
568 return -ENXIO;
571 port = PortSetup.To = PortSetup.From;
572 PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
573 PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
574 PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
575 PortSetup.Store = p->RIOPortp[port]->Store;
576 PortSetup.Lock = p->RIOPortp[port]->Lock;
577 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
578 memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN);
579 memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN);
580 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
581 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
583 if (copy_to_user(argp, &PortSetup, sizeof(PortSetup))) {
584 p->RIOError.Error = COPYOUT_FAILED;
585 return -EFAULT;
587 return retval;
589 case RIO_GET_PORT_PARAMS:
590 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
591 if (copy_from_user(&PortParams, argp, sizeof(struct PortParams))) {
592 p->RIOError.Error = COPYIN_FAILED;
593 return -EFAULT;
595 if (PortParams.Port >= RIO_PORTS) {
596 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
597 return -ENXIO;
599 PortP = (p->RIOPortp[PortParams.Port]);
600 PortParams.Config = PortP->Config;
601 PortParams.State = PortP->State;
602 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
604 if (copy_to_user(argp, &PortParams, sizeof(struct PortParams))) {
605 p->RIOError.Error = COPYOUT_FAILED;
606 return -EFAULT;
608 return retval;
610 case RIO_GET_PORT_TTY:
611 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
612 if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
613 p->RIOError.Error = COPYIN_FAILED;
614 return -EFAULT;
616 if (PortTty.port >= RIO_PORTS) {
617 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
618 return -ENXIO;
621 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
622 PortP = (p->RIOPortp[PortTty.port]);
623 if (copy_to_user(argp, &PortTty, sizeof(struct PortTty))) {
624 p->RIOError.Error = COPYOUT_FAILED;
625 return -EFAULT;
627 return retval;
629 case RIO_SET_PORT_TTY:
630 if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
631 p->RIOError.Error = COPYIN_FAILED;
632 return -EFAULT;
634 rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
635 if (PortTty.port >= (ushort) RIO_PORTS) {
636 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
637 return -ENXIO;
639 PortP = (p->RIOPortp[PortTty.port]);
640 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
641 return retval;
643 case RIO_SET_PORT_PARAMS:
644 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
645 if (copy_from_user(&PortParams, argp, sizeof(PortParams))) {
646 p->RIOError.Error = COPYIN_FAILED;
647 return -EFAULT;
649 if (PortParams.Port >= (ushort) RIO_PORTS) {
650 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
651 return -ENXIO;
653 PortP = (p->RIOPortp[PortParams.Port]);
654 rio_spin_lock_irqsave(&PortP->portSem, flags);
655 PortP->Config = PortParams.Config;
656 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
657 return retval;
659 case RIO_GET_PORT_STATS:
660 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
661 if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
662 p->RIOError.Error = COPYIN_FAILED;
663 return -EFAULT;
665 if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
666 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
667 return -ENXIO;
669 PortP = (p->RIOPortp[portStats.port]);
670 portStats.gather = PortP->statsGather;
671 portStats.txchars = PortP->txchars;
672 portStats.rxchars = PortP->rxchars;
673 portStats.opens = PortP->opens;
674 portStats.closes = PortP->closes;
675 portStats.ioctls = PortP->ioctls;
676 if (copy_to_user(argp, &portStats, sizeof(struct portStats))) {
677 p->RIOError.Error = COPYOUT_FAILED;
678 return -EFAULT;
680 return retval;
682 case RIO_RESET_PORT_STATS:
683 port = arg;
684 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
685 if (port >= RIO_PORTS) {
686 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
687 return -ENXIO;
689 PortP = (p->RIOPortp[port]);
690 rio_spin_lock_irqsave(&PortP->portSem, flags);
691 PortP->txchars = 0;
692 PortP->rxchars = 0;
693 PortP->opens = 0;
694 PortP->closes = 0;
695 PortP->ioctls = 0;
696 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
697 return retval;
699 case RIO_GATHER_PORT_STATS:
700 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
701 if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
702 p->RIOError.Error = COPYIN_FAILED;
703 return -EFAULT;
705 if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
706 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
707 return -ENXIO;
709 PortP = (p->RIOPortp[portStats.port]);
710 rio_spin_lock_irqsave(&PortP->portSem, flags);
711 PortP->statsGather = portStats.gather;
712 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
713 return retval;
715 case RIO_READ_CONFIG:
716 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
717 if (copy_to_user(argp, &p->RIOConf, sizeof(struct Conf))) {
718 p->RIOError.Error = COPYOUT_FAILED;
719 return -EFAULT;
721 return retval;
723 case RIO_SET_CONFIG:
724 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
725 if (!su) {
726 p->RIOError.Error = NOT_SUPER_USER;
727 return -EPERM;
729 if (copy_from_user(&p->RIOConf, argp, sizeof(struct Conf))) {
730 p->RIOError.Error = COPYIN_FAILED;
731 return -EFAULT;
734 ** move a few value around
736 for (Host = 0; Host < p->RIONumHosts; Host++)
737 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
738 writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
739 return retval;
741 case RIO_START_POLLER:
742 rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
743 return -EINVAL;
745 case RIO_STOP_POLLER:
746 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
747 if (!su) {
748 p->RIOError.Error = NOT_SUPER_USER;
749 return -EPERM;
751 p->RIOPolling = NOT_POLLING;
752 return retval;
754 case RIO_SETDEBUG:
755 case RIO_GETDEBUG:
756 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
757 if (copy_from_user(&DebugCtrl, argp, sizeof(DebugCtrl))) {
758 p->RIOError.Error = COPYIN_FAILED;
759 return -EFAULT;
761 if (DebugCtrl.SysPort == NO_PORT) {
762 if (cmd == RIO_SETDEBUG) {
763 if (!su) {
764 p->RIOError.Error = NOT_SUPER_USER;
765 return -EPERM;
767 p->rio_debug = DebugCtrl.Debug;
768 p->RIODebugWait = DebugCtrl.Wait;
769 rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
770 } else {
771 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
772 DebugCtrl.Debug = p->rio_debug;
773 DebugCtrl.Wait = p->RIODebugWait;
774 if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
775 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
776 p->RIOError.Error = COPYOUT_FAILED;
777 return -EFAULT;
780 } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
781 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
782 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
783 return -ENXIO;
784 } else if (cmd == RIO_SETDEBUG) {
785 if (!su) {
786 p->RIOError.Error = NOT_SUPER_USER;
787 return -EPERM;
789 rio_spin_lock_irqsave(&PortP->portSem, flags);
790 p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
791 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
792 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
793 } else {
794 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
795 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
796 if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
797 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
798 p->RIOError.Error = COPYOUT_FAILED;
799 return -EFAULT;
802 return retval;
804 case RIO_VERSID:
806 ** Enquire about the release and version.
807 ** We return MAX_VERSION_LEN bytes, being a
808 ** textual null terminated string.
810 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
811 if (copy_to_user(argp, RIOVersid(), sizeof(struct rioVersion))) {
812 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
813 p->RIOError.Error = COPYOUT_FAILED;
814 return -EFAULT;
816 return retval;
818 case RIO_NUM_HOSTS:
820 ** Enquire as to the number of hosts located
821 ** at init time.
823 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
824 if (copy_to_user(argp, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
825 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
826 p->RIOError.Error = COPYOUT_FAILED;
827 return -EFAULT;
829 return retval;
831 case RIO_HOST_FOAD:
833 ** Kill host. This may not be in the final version...
835 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", arg);
836 if (!su) {
837 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
838 p->RIOError.Error = NOT_SUPER_USER;
839 return -EPERM;
841 p->RIOHalted = 1;
842 p->RIOSystemUp = 0;
844 for (Host = 0; Host < p->RIONumHosts; Host++) {
845 (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
846 memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
847 p->RIOHosts[Host].Flags = RC_WAITING;
849 RIOFoadWakeup(p);
850 p->RIONumBootPkts = 0;
851 p->RIOBooting = 0;
852 printk("HEEEEELP!\n");
854 for (loop = 0; loop < RIO_PORTS; loop++) {
855 spin_lock_init(&p->RIOPortp[loop]->portSem);
856 p->RIOPortp[loop]->InUse = NOT_INUSE;
859 p->RIOSystemUp = 0;
860 return retval;
862 case RIO_DOWNLOAD:
863 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
864 if (!su) {
865 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
866 p->RIOError.Error = NOT_SUPER_USER;
867 return -EPERM;
869 if (copy_from_user(&DownLoad, argp, sizeof(DownLoad))) {
870 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
871 p->RIOError.Error = COPYIN_FAILED;
872 return -EFAULT;
874 rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
877 ** It is important that the product code is an unsigned object!
879 if (DownLoad.ProductCode > MAX_PRODUCT) {
880 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
881 p->RIOError.Error = NO_SUCH_PRODUCT;
882 return -ENXIO;
885 ** do something!
887 retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
888 /* <-- Panic */
889 p->RIOHalted = 0;
891 ** and go back, content with a job well completed.
893 return retval;
895 case RIO_PARMS:
897 unsigned int host;
899 if (copy_from_user(&host, argp, sizeof(host))) {
900 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
901 p->RIOError.Error = COPYIN_FAILED;
902 return -EFAULT;
905 ** Fetch the parmmap
907 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
908 if (copy_from_io(argp, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
909 p->RIOError.Error = COPYOUT_FAILED;
910 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
911 return -EFAULT;
914 return retval;
916 case RIO_HOST_REQ:
917 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
918 if (copy_from_user(&HostReq, argp, sizeof(HostReq))) {
919 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
920 p->RIOError.Error = COPYIN_FAILED;
921 return -EFAULT;
923 if (HostReq.HostNum >= p->RIONumHosts) {
924 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
925 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
926 return -ENXIO;
928 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
930 if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
931 p->RIOError.Error = COPYOUT_FAILED;
932 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
933 return -EFAULT;
935 return retval;
937 case RIO_HOST_DPRAM:
938 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
939 if (copy_from_user(&HostDpRam, argp, sizeof(HostDpRam))) {
940 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
941 p->RIOError.Error = COPYIN_FAILED;
942 return -EFAULT;
944 if (HostDpRam.HostNum >= p->RIONumHosts) {
945 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
946 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
947 return -ENXIO;
949 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
951 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
952 int off;
953 /* It's hardware like this that really gets on my tits. */
954 static unsigned char copy[sizeof(struct DpRam)];
955 for (off = 0; off < sizeof(struct DpRam); off++)
956 copy[off] = readb(p->RIOHosts[HostDpRam.HostNum].Caddr + off);
957 if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
958 p->RIOError.Error = COPYOUT_FAILED;
959 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
960 return -EFAULT;
962 } else if (copy_from_io(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
963 p->RIOError.Error = COPYOUT_FAILED;
964 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
965 return -EFAULT;
967 return retval;
969 case RIO_SET_BUSY:
970 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
971 if (arg > 511) {
972 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", arg);
973 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
974 return -EINVAL;
976 rio_spin_lock_irqsave(&PortP->portSem, flags);
977 p->RIOPortp[arg]->State |= RIO_BUSY;
978 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
979 return retval;
981 case RIO_HOST_PORT:
983 ** The daemon want port information
984 ** (probably for debug reasons)
986 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
987 if (copy_from_user(&PortReq, argp, sizeof(PortReq))) {
988 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
989 p->RIOError.Error = COPYIN_FAILED;
990 return -EFAULT;
993 if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
994 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
995 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
996 return -ENXIO;
998 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
999 if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
1000 p->RIOError.Error = COPYOUT_FAILED;
1001 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
1002 return -EFAULT;
1004 return retval;
1006 case RIO_HOST_RUP:
1008 ** The daemon want rup information
1009 ** (probably for debug reasons)
1011 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
1012 if (copy_from_user(&RupReq, argp, sizeof(RupReq))) {
1013 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1014 p->RIOError.Error = COPYIN_FAILED;
1015 return -EFAULT;
1017 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1018 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
1019 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1020 return -ENXIO;
1022 if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */
1023 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
1024 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1025 return -EINVAL;
1027 HostP = &p->RIOHosts[RupReq.HostNum];
1029 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1030 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
1031 p->RIOError.Error = HOST_NOT_RUNNING;
1032 return -EIO;
1034 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
1036 if (copy_from_io(RupReq.RupP, HostP->UnixRups[RupReq.RupNum].RupP, sizeof(struct RUP))) {
1037 p->RIOError.Error = COPYOUT_FAILED;
1038 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1039 return -EFAULT;
1041 return retval;
1043 case RIO_HOST_LPB:
1045 ** The daemon want lpb information
1046 ** (probably for debug reasons)
1048 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
1049 if (copy_from_user(&LpbReq, argp, sizeof(LpbReq))) {
1050 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1051 p->RIOError.Error = COPYIN_FAILED;
1052 return -EFAULT;
1054 if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
1055 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
1056 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1057 return -ENXIO;
1059 if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */
1060 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
1061 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1062 return -EINVAL;
1064 HostP = &p->RIOHosts[LpbReq.Host];
1066 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1067 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
1068 p->RIOError.Error = HOST_NOT_RUNNING;
1069 return -EIO;
1071 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
1073 if (copy_from_io(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
1074 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1075 p->RIOError.Error = COPYOUT_FAILED;
1076 return -EFAULT;
1078 return retval;
1081 ** Here 3 IOCTL's that allow us to change the way in which
1082 ** rio logs errors. send them just to syslog or send them
1083 ** to both syslog and console or send them to just the console.
1085 ** See RioStrBuf() in util.c for the other half.
1087 case RIO_SYSLOG_ONLY:
1088 p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
1089 return 0;
1091 case RIO_SYSLOG_CONS:
1092 p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */
1093 return 0;
1095 case RIO_CONS_ONLY:
1096 p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
1097 return 0;
1099 case RIO_SIGNALS_ON:
1100 if (p->RIOSignalProcess) {
1101 p->RIOError.Error = SIGNALS_ALREADY_SET;
1102 return -EBUSY;
1104 /* FIXME: PID tracking */
1105 p->RIOSignalProcess = current->pid;
1106 p->RIOPrintDisabled = DONT_PRINT;
1107 return retval;
1109 case RIO_SIGNALS_OFF:
1110 if (p->RIOSignalProcess != current->pid) {
1111 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1112 return -EPERM;
1114 rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
1115 p->RIOSignalProcess = 0;
1116 return retval;
1118 case RIO_SET_BYTE_MODE:
1119 for (Host = 0; Host < p->RIONumHosts; Host++)
1120 if (p->RIOHosts[Host].Type == RIO_AT)
1121 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1122 return retval;
1124 case RIO_SET_WORD_MODE:
1125 for (Host = 0; Host < p->RIONumHosts; Host++)
1126 if (p->RIOHosts[Host].Type == RIO_AT)
1127 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1128 return retval;
1130 case RIO_SET_FAST_BUS:
1131 for (Host = 0; Host < p->RIONumHosts; Host++)
1132 if (p->RIOHosts[Host].Type == RIO_AT)
1133 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1134 return retval;
1136 case RIO_SET_SLOW_BUS:
1137 for (Host = 0; Host < p->RIONumHosts; Host++)
1138 if (p->RIOHosts[Host].Type == RIO_AT)
1139 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1140 return retval;
1142 case RIO_MAP_B50_TO_50:
1143 case RIO_MAP_B50_TO_57600:
1144 case RIO_MAP_B110_TO_110:
1145 case RIO_MAP_B110_TO_115200:
1146 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
1147 port = arg;
1148 if (port < 0 || port > 511) {
1149 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1150 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1151 return -EINVAL;
1153 rio_spin_lock_irqsave(&PortP->portSem, flags);
1154 switch (cmd) {
1155 case RIO_MAP_B50_TO_50:
1156 p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1157 break;
1158 case RIO_MAP_B50_TO_57600:
1159 p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1160 break;
1161 case RIO_MAP_B110_TO_110:
1162 p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1163 break;
1164 case RIO_MAP_B110_TO_115200:
1165 p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1166 break;
1168 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1169 return retval;
1171 case RIO_STREAM_INFO:
1172 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
1173 return -EINVAL;
1175 case RIO_SEND_PACKET:
1176 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
1177 if (copy_from_user(&SendPack, argp, sizeof(SendPack))) {
1178 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1179 p->RIOError.Error = COPYIN_FAILED;
1180 return -EFAULT;
1182 if (SendPack.PortNum >= 128) {
1183 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1184 return -ENXIO;
1187 PortP = p->RIOPortp[SendPack.PortNum];
1188 rio_spin_lock_irqsave(&PortP->portSem, flags);
1190 if (!can_add_transmit(&PacketP, PortP)) {
1191 p->RIOError.Error = UNIT_IS_IN_USE;
1192 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1193 return -ENOSPC;
1196 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
1197 writeb(SendPack.Data[loop], &PacketP->data[loop]);
1199 writeb(SendPack.Len, &PacketP->len);
1201 add_transmit(PortP);
1203 ** Count characters transmitted for port statistics reporting
1205 if (PortP->statsGather)
1206 PortP->txchars += (SendPack.Len & 127);
1207 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1208 return retval;
1210 case RIO_NO_MESG:
1211 if (su)
1212 p->RIONoMessage = 1;
1213 return su ? 0 : -EPERM;
1215 case RIO_MESG:
1216 if (su)
1217 p->RIONoMessage = 0;
1218 return su ? 0 : -EPERM;
1220 case RIO_WHAT_MESG:
1221 if (copy_to_user(argp, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
1222 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1223 p->RIOError.Error = COPYOUT_FAILED;
1224 return -EFAULT;
1226 return 0;
1228 case RIO_MEM_DUMP:
1229 if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
1230 p->RIOError.Error = COPYIN_FAILED;
1231 return -EFAULT;
1233 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
1235 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1236 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1237 return -EINVAL;
1240 if (SubCmd.Host >= p->RIONumHosts) {
1241 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1242 return -EINVAL;
1245 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
1247 PortP = p->RIOPortp[port];
1249 rio_spin_lock_irqsave(&PortP->portSem, flags);
1251 if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) {
1252 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1253 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1254 return -EBUSY;
1255 } else
1256 PortP->State |= RIO_BUSY;
1258 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1259 if (copy_to_user(argp, p->RIOMemDump, MEMDUMP_SIZE)) {
1260 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1261 p->RIOError.Error = COPYOUT_FAILED;
1262 return -EFAULT;
1264 return 0;
1266 case RIO_TICK:
1267 if (arg >= p->RIONumHosts)
1268 return -EINVAL;
1269 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", arg);
1270 writeb(0xFF, &p->RIOHosts[arg].SetInt);
1271 return 0;
1273 case RIO_TOCK:
1274 if (arg >= p->RIONumHosts)
1275 return -EINVAL;
1276 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", arg);
1277 writeb(0xFF, &p->RIOHosts[arg].ResetInt);
1278 return 0;
1280 case RIO_READ_CHECK:
1281 /* Check reads for pkts with data[0] the same */
1282 p->RIOReadCheck = !p->RIOReadCheck;
1283 if (copy_to_user(argp, &p->RIOReadCheck, sizeof(unsigned int))) {
1284 p->RIOError.Error = COPYOUT_FAILED;
1285 return -EFAULT;
1287 return 0;
1289 case RIO_READ_REGISTER:
1290 if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
1291 p->RIOError.Error = COPYIN_FAILED;
1292 return -EFAULT;
1294 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);
1296 if (SubCmd.Port > 511) {
1297 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
1298 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1299 return -EINVAL;
1302 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1303 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1304 return -EINVAL;
1307 if (SubCmd.Host >= p->RIONumHosts) {
1308 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1309 return -EINVAL;
1312 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1313 PortP = p->RIOPortp[port];
1315 rio_spin_lock_irqsave(&PortP->portSem, flags);
1317 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
1318 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1319 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1320 return -EBUSY;
1321 } else
1322 PortP->State |= RIO_BUSY;
1324 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1325 if (copy_to_user(argp, &p->CdRegister, sizeof(unsigned int))) {
1326 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1327 p->RIOError.Error = COPYOUT_FAILED;
1328 return -EFAULT;
1330 return 0;
1332 ** rio_make_dev: given port number (0-511) ORed with port type
1333 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1334 ** value to pass to mknod to create the correct device node.
1336 case RIO_MAKE_DEV:
1338 unsigned int port = arg & RIO_MODEM_MASK;
1339 unsigned int ret;
1341 switch (arg & RIO_DEV_MASK) {
1342 case RIO_DEV_DIRECT:
1343 ret = drv_makedev(MAJOR(dev), port);
1344 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
1345 return ret;
1346 case RIO_DEV_MODEM:
1347 ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1348 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
1349 return ret;
1350 case RIO_DEV_XPRINT:
1351 ret = drv_makedev(MAJOR(dev), port);
1352 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
1353 return ret;
1355 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1356 return -EINVAL;
1359 ** rio_minor: given a dev_t from a stat() call, return
1360 ** the port number (0-511) ORed with the port type
1361 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1363 case RIO_MINOR:
1365 dev_t dv;
1366 int mino;
1367 unsigned long ret;
1369 dv = (dev_t) (arg);
1370 mino = RIO_UNMODEM(dv);
1372 if (RIO_ISMODEM(dv)) {
1373 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
1374 ret = mino | RIO_DEV_MODEM;
1375 } else {
1376 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
1377 ret = mino | RIO_DEV_DIRECT;
1379 return ret;
1382 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
1383 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1385 func_exit();
1386 return -EINVAL;
1390 ** Pre-emptive commands go on RUPs and are only one byte long.
1392 int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
1394 struct CmdBlk *CmdBlkP;
1395 struct PktCmd_M *PktCmdP;
1396 int Ret;
1397 ushort rup;
1398 int port;
1400 if (PortP->State & RIO_DELETED) {
1401 rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
1402 return RIO_FAIL;
1405 if ((PortP->InUse == (typeof(PortP->InUse))-1) ||
1406 !(CmdBlkP = RIOGetCmdBlk())) {
1407 rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block "
1408 "for command %d on port %d\n", Cmd, PortP->PortNum);
1409 return RIO_FAIL;
1412 rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n",
1413 CmdBlkP, PortP->InUse);
1415 PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
1417 CmdBlkP->Packet.src_unit = 0;
1418 if (PortP->SecondBlock)
1419 rup = PortP->ID2;
1420 else
1421 rup = PortP->RupNum;
1422 CmdBlkP->Packet.dest_unit = rup;
1423 CmdBlkP->Packet.src_port = COMMAND_RUP;
1424 CmdBlkP->Packet.dest_port = COMMAND_RUP;
1425 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1426 CmdBlkP->PostFuncP = RIOUnUse;
1427 CmdBlkP->PostArg = (unsigned long) PortP;
1428 PktCmdP->Command = Cmd;
1429 port = PortP->HostPort % (ushort) PORTS_PER_RTA;
1431 ** Index ports 8-15 for 2nd block of 16 port RTA.
1433 if (PortP->SecondBlock)
1434 port += (ushort) PORTS_PER_RTA;
1435 PktCmdP->PhbNum = port;
1437 switch (Cmd) {
1438 case MEMDUMP:
1439 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p "
1440 "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
1441 PktCmdP->SubCommand = MEMDUMP;
1442 PktCmdP->SubAddr = SubCmd.Addr;
1443 break;
1444 case FCLOSE:
1445 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n",
1446 CmdBlkP);
1447 break;
1448 case READ_REGISTER:
1449 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) "
1450 "command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
1451 PktCmdP->SubCommand = READ_REGISTER;
1452 PktCmdP->SubAddr = SubCmd.Addr;
1453 break;
1454 case RESUME:
1455 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n",
1456 CmdBlkP);
1457 break;
1458 case RFLUSH:
1459 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n",
1460 CmdBlkP);
1461 CmdBlkP->PostFuncP = RIORFlushEnable;
1462 break;
1463 case SUSPEND:
1464 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n",
1465 CmdBlkP);
1466 break;
1468 case MGET:
1469 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n",
1470 CmdBlkP);
1471 break;
1473 case MSET:
1474 case MBIC:
1475 case MBIS:
1476 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
1477 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command "
1478 "blk %p\n", CmdBlkP);
1479 break;
1481 case WFLUSH:
1483 ** If we have queued up the maximum number of Write flushes
1484 ** allowed then we should not bother sending any more to the
1485 ** RTA.
1487 if (PortP->WflushFlag == (typeof(PortP->WflushFlag))-1) {
1488 rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, "
1489 "WflushFlag about to wrap!");
1490 RIOFreeCmdBlk(CmdBlkP);
1491 return (RIO_FAIL);
1492 } else {
1493 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command "
1494 "blk %p\n", CmdBlkP);
1495 CmdBlkP->PostFuncP = RIOWFlushMark;
1497 break;
1500 PortP->InUse++;
1502 Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);
1504 return Ret;