2 ** -----------------------------------------------------------------------------
4 ** Perle Specialix driver for Linux
5 ** Ported from existing RIO Driver for SCO sources.
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 ** Last Modified : 11/6/98 10:33:42
26 ** Retrieved : 11/6/98 10:33:49
28 ** ident @(#)rioctrl.c 1.3
30 ** -----------------------------------------------------------------------------
33 static char *_rioctrl_c_sccs_
= "@(#)rioctrl.c 1.3";
37 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/errno.h>
41 #include <asm/system.h>
42 #include <asm/string.h>
43 #include <asm/semaphore.h>
44 #include <asm/uaccess.h>
46 #include <linux/termios.h>
47 #include <linux/serial.h>
49 #include <linux/generic_serial.h>
52 #include "linux_compat.h"
53 #include "rio_linux.h"
80 static struct LpbReq LpbReq
;
81 static struct RupReq RupReq
;
82 static struct PortReq PortReq
;
83 static struct HostReq HostReq
; /* oh really? global? and no locking? */
84 static struct HostDpRam HostDpRam
;
85 static struct DebugCtrl DebugCtrl
;
86 static struct Map MapEnt
;
87 static struct PortSetup PortSetup
;
88 static struct DownLoad DownLoad
;
89 static struct SendPack SendPack
;
90 /* static struct StreamInfo StreamInfo; */
91 /* static char modemtable[RIO_PORTS]; */
92 static struct SpecialRupCmd SpecialRupCmd
;
93 static struct PortParams PortParams
;
94 static struct portStats portStats
;
96 static struct SubCmdStruct
{
105 struct ttystatics Tty
;
108 static struct PortTty PortTty
;
109 typedef struct ttystatics TERMIO
;
112 ** This table is used when the config.rio downloads bin code to the
113 ** driver. We index the table using the product code, 0-F, and call
114 ** the function pointed to by the entry, passing the information
116 ** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
117 ** process to bog off.
120 (*RIOBootTable
[MAX_PRODUCT
]) (struct rio_info
*, struct DownLoad
*) = {
121 /* 0 */ RIOBootCodeHOST
,
123 /* 1 */ RIOBootCodeRTA
,
127 #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
129 static int copy_from_io(void __user
*to
, void __iomem
*from
, size_t size
)
131 void *buf
= kmalloc(size
, GFP_KERNEL
);
134 rio_memcpy_fromio(buf
, from
, size
);
135 res
= copy_to_user(to
, buf
, size
);
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! */
149 struct PKT __iomem
*PacketP
;
152 void __user
*argp
= (void __user
*)arg
;
156 /* Confuse the compiler to think that we've initialized these */
160 rio_dprintk(RIO_DEBUG_CTRL
, "control ioctl cmd: 0x%x arg: %p\n", cmd
, argp
);
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.
171 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SET_TIMER to %ldms\n", arg
);
174 host
= (arg
>> 16) & 0x0000FFFF;
175 value
= arg
& 0x0000ffff;
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
) {
185 if (p
->RIOHosts
[host
].Flags
== RC_RUNNING
) {
186 writew(value
, &p
->RIOHosts
[host
].ParmMapP
->timer
);
193 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_FOAD_RTA\n");
194 return RIOCommandRta(p
, arg
, RIOFoadRta
);
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
;
218 CmdBlkP
= RIOGetCmdBlk();
220 rio_dprintk(RIO_DEBUG_CTRL
, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
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");
237 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_ALL_MODEM\n");
238 p
->RIOError
.Error
= IOCTL_COMMAND_UNKNOWN
;
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)
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
;
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))
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 */
286 ** Write the routing table to the device driver from user space
288 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PUT_TABLE\n");
291 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PUT_TABLE !Root\n");
292 p
->RIOError
.Error
= NOT_SUPER_USER
;
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
;
301 ***********************************
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");
337 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_BINDINGS !Root\n");
338 p
->RIOError
.Error
= NOT_SUPER_USER
;
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
;
348 case RIO_PUT_BINDINGS
:
350 ** Receive a bindings table, containing unique numbers of RTAs owned
353 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PUT_BINDINGS\n");
356 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PUT_BINDINGS !Root\n");
357 p
->RIOError
.Error
= NOT_SUPER_USER
;
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
;
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");
377 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_BIND_RTA !Root\n");
378 p
->RIOError
.Error
= NOT_SUPER_USER
;
381 for (Entry
= 0; Entry
< MAX_RTA_BINDINGS
; Entry
++) {
382 if ((EmptySlot
== -1) && (p
->RIOBindTab
[Entry
] == 0L))
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
);
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
);
400 rio_dprintk(RIO_DEBUG_CTRL
, "p->RIOBindTab full! - Rta %lx not added\n", arg
);
407 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_RESUME\n");
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
;
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
;
420 if (!(PortP
->State
& (RIO_LOPEN
| RIO_MOPEN
))) {
421 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_RESUME: Port %d not open\n", port
);
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
);
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
);
438 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_ASSIGN_RTA\n");
440 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_ASSIGN_RTA !Root\n");
441 p
->RIOError
.Error
= NOT_SUPER_USER
;
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
;
449 return RIOAssignRta(p
, &MapEnt
);
451 case RIO_CHANGE_NAME
:
452 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_CHANGE_NAME\n");
454 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_CHANGE_NAME !Root\n");
455 p
->RIOError
.Error
= NOT_SUPER_USER
;
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
;
463 return RIOChangeName(p
, &MapEnt
);
466 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_DELETE_RTA\n");
468 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_DELETE_RTA !Root\n");
469 p
->RIOError
.Error
= NOT_SUPER_USER
;
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
;
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
;
487 if (copy_to_user(argp
, &p
->RIOError
, sizeof(struct Error
)))
492 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_LOG\n");
495 case RIO_GET_MODTYPE
:
496 if (copy_from_user(&port
, argp
, sizeof(unsigned int))) {
497 p
->RIOError
.Error
= COPYIN_FAILED
;
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
;
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
;
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
;
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
);
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");
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");
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");
548 printk(KERN_ERR
"rio: No p->RIOPortp array!\n");
549 rio_dprintk(RIO_DEBUG_CTRL
, "No p->RIOPortp array!\n");
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
);
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
;
566 if (PortSetup
.From
>= RIO_PORTS
) {
567 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
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
;
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
;
595 if (PortParams
.Port
>= RIO_PORTS
) {
596 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
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
;
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
;
616 if (PortTty
.port
>= RIO_PORTS
) {
617 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
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
;
629 case RIO_SET_PORT_TTY
:
630 if (copy_from_user(&PortTty
, argp
, sizeof(struct PortTty
))) {
631 p
->RIOError
.Error
= COPYIN_FAILED
;
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
;
639 PortP
= (p
->RIOPortp
[PortTty
.port
]);
640 RIOParam(PortP
, CONFIG
, PortP
->State
& RIO_MODEM
, OK_TO_SLEEP
);
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
;
649 if (PortParams
.Port
>= (ushort
) RIO_PORTS
) {
650 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
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
);
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
;
665 if (portStats
.port
>= RIO_PORTS
) {
666 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
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
;
682 case RIO_RESET_PORT_STATS
:
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
;
689 PortP
= (p
->RIOPortp
[port
]);
690 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
696 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
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
;
705 if (portStats
.port
>= RIO_PORTS
) {
706 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
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
);
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
;
724 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SET_CONFIG\n");
726 p
->RIOError
.Error
= NOT_SUPER_USER
;
729 if (copy_from_user(&p
->RIOConf
, argp
, sizeof(struct Conf
))) {
730 p
->RIOError
.Error
= COPYIN_FAILED
;
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
);
741 case RIO_START_POLLER
:
742 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_START_POLLER\n");
745 case RIO_STOP_POLLER
:
746 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_STOP_POLLER\n");
748 p
->RIOError
.Error
= NOT_SUPER_USER
;
751 p
->RIOPolling
= NOT_POLLING
;
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
;
761 if (DebugCtrl
.SysPort
== NO_PORT
) {
762 if (cmd
== RIO_SETDEBUG
) {
764 p
->RIOError
.Error
= NOT_SUPER_USER
;
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
);
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
;
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
;
784 } else if (cmd
== RIO_SETDEBUG
) {
786 p
->RIOError
.Error
= NOT_SUPER_USER
;
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
);
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
;
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
;
820 ** Enquire as to the number of hosts located
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
;
833 ** Kill host. This may not be in the final version...
835 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_FOAD %ld\n", arg
);
837 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_FOAD: Not super user\n");
838 p
->RIOError
.Error
= NOT_SUPER_USER
;
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
;
850 p
->RIONumBootPkts
= 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
;
863 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_DOWNLOAD\n");
865 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_DOWNLOAD: Not super user\n");
866 p
->RIOError
.Error
= NOT_SUPER_USER
;
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
;
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
;
887 retval
= (*(RIOBootTable
[DownLoad
.ProductCode
])) (p
, &DownLoad
);
891 ** and go back, content with a job well completed.
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
;
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");
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
;
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
);
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");
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
;
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
);
949 rio_dprintk(RIO_DEBUG_CTRL
, "Request for host %d\n", HostDpRam
.HostNum
);
951 if (p
->RIOHosts
[HostDpRam
.HostNum
].Type
== RIO_PCI
) {
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");
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");
970 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SET_BUSY\n");
972 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SET_BUSY: Bad port number %ld\n", arg
);
973 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
976 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
977 p
->RIOPortp
[arg
]->State
|= RIO_BUSY
;
978 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
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
;
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
;
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");
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
;
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
;
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
;
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
;
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");
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
;
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
;
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
;
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
;
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
;
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 */
1091 case RIO_SYSLOG_CONS
:
1092 p
->RIOPrintLogState
= PRINT_TO_LOG_CONS
; /* syslog and console */
1096 p
->RIOPrintLogState
= PRINT_TO_CONS
; /* Just console */
1099 case RIO_SIGNALS_ON
:
1100 if (p
->RIOSignalProcess
) {
1101 p
->RIOError
.Error
= SIGNALS_ALREADY_SET
;
1104 /* FIXME: PID tracking */
1105 p
->RIOSignalProcess
= current
->pid
;
1106 p
->RIOPrintDisabled
= DONT_PRINT
;
1109 case RIO_SIGNALS_OFF
:
1110 if (p
->RIOSignalProcess
!= current
->pid
) {
1111 p
->RIOError
.Error
= NOT_RECEIVING_PROCESS
;
1114 rio_dprintk(RIO_DEBUG_CTRL
, "Clear signal process to zero\n");
1115 p
->RIOSignalProcess
= 0;
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
;
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
;
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
;
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
;
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");
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
;
1153 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
1155 case RIO_MAP_B50_TO_50
:
1156 p
->RIOPortp
[port
]->Config
|= RIO_MAP_50_TO_50
;
1158 case RIO_MAP_B50_TO_57600
:
1159 p
->RIOPortp
[port
]->Config
&= ~RIO_MAP_50_TO_50
;
1161 case RIO_MAP_B110_TO_110
:
1162 p
->RIOPortp
[port
]->Config
|= RIO_MAP_110_TO_110
;
1164 case RIO_MAP_B110_TO_115200
:
1165 p
->RIOPortp
[port
]->Config
&= ~RIO_MAP_110_TO_110
;
1168 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
1171 case RIO_STREAM_INFO
:
1172 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_STREAM_INFO\n");
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
;
1182 if (SendPack
.PortNum
>= 128) {
1183 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
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
);
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
);
1212 p
->RIONoMessage
= 1;
1213 return su
? 0 : -EPERM
;
1217 p
->RIONoMessage
= 0;
1218 return su
? 0 : -EPERM
;
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
;
1229 if (copy_from_user(&SubCmd
, argp
, sizeof(struct SubCmdStruct
))) {
1230 p
->RIOError
.Error
= COPYIN_FAILED
;
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
;
1240 if (SubCmd
.Host
>= p
->RIONumHosts
) {
1241 p
->RIOError
.Error
= HOST_NUMBER_OUT_OF_RANGE
;
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
);
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
;
1267 if (arg
>= p
->RIONumHosts
)
1269 rio_dprintk(RIO_DEBUG_CTRL
, "Set interrupt for host %ld\n", arg
);
1270 writeb(0xFF, &p
->RIOHosts
[arg
].SetInt
);
1274 if (arg
>= p
->RIONumHosts
)
1276 rio_dprintk(RIO_DEBUG_CTRL
, "Clear interrupt for host %ld\n", arg
);
1277 writeb(0xFF, &p
->RIOHosts
[arg
].ResetInt
);
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
;
1289 case RIO_READ_REGISTER
:
1290 if (copy_from_user(&SubCmd
, argp
, sizeof(struct SubCmdStruct
))) {
1291 p
->RIOError
.Error
= COPYIN_FAILED
;
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
;
1302 if (SubCmd
.Rup
>= MAX_RUP
+ LINKS_PER_UNIT
) {
1303 p
->RIOError
.Error
= RUP_NUMBER_OUT_OF_RANGE
;
1307 if (SubCmd
.Host
>= p
->RIONumHosts
) {
1308 p
->RIOError
.Error
= HOST_NUMBER_OUT_OF_RANGE
;
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
);
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
;
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.
1338 unsigned int port
= arg
& RIO_MODEM_MASK
;
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
);
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
);
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
);
1355 rio_dprintk(RIO_DEBUG_CTRL
, "MAKE Device is called\n");
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 )
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
;
1376 rio_dprintk(RIO_DEBUG_CTRL
, "Minor for device 0x%x: direct %d\n", dv
, mino
);
1377 ret
= mino
| RIO_DEV_DIRECT
;
1382 rio_dprintk(RIO_DEBUG_CTRL
, "INVALID DAEMON IOCTL 0x%x\n", cmd
);
1383 p
->RIOError
.Error
= IOCTL_COMMAND_UNKNOWN
;
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
;
1400 if (PortP
->State
& RIO_DELETED
) {
1401 rio_dprintk(RIO_DEBUG_CTRL
, "Preemptive command to deleted RTA ignored\n");
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
);
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
)
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
;
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
;
1445 rio_dprintk(RIO_DEBUG_CTRL
, "Queue FCLOSE command blk %p\n",
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
;
1455 rio_dprintk(RIO_DEBUG_CTRL
, "Queue RESUME command blk %p\n",
1459 rio_dprintk(RIO_DEBUG_CTRL
, "Queue RFLUSH command blk %p\n",
1461 CmdBlkP
->PostFuncP
= RIORFlushEnable
;
1464 rio_dprintk(RIO_DEBUG_CTRL
, "Queue SUSPEND command blk %p\n",
1469 rio_dprintk(RIO_DEBUG_CTRL
, "Queue MGET command blk %p\n",
1476 CmdBlkP
->Packet
.data
[4] = (char) PortP
->ModemLines
;
1477 rio_dprintk(RIO_DEBUG_CTRL
, "Queue MSET/MBIC/MBIS command "
1478 "blk %p\n", CmdBlkP
);
1483 ** If we have queued up the maximum number of Write flushes
1484 ** allowed then we should not bother sending any more to the
1487 if (PortP
->WflushFlag
== (typeof(PortP
->WflushFlag
))-1) {
1488 rio_dprintk(RIO_DEBUG_CTRL
, "Trashed WFLUSH, "
1489 "WflushFlag about to wrap!");
1490 RIOFreeCmdBlk(CmdBlkP
);
1493 rio_dprintk(RIO_DEBUG_CTRL
, "Queue WFLUSH command "
1494 "blk %p\n", CmdBlkP
);
1495 CmdBlkP
->PostFuncP
= RIOWFlushMark
;
1502 Ret
= RIOQueueCmdBlk(PortP
->HostP
, rup
, CmdBlkP
);