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
;
84 static struct HostDpRam HostDpRam
;
85 static struct DebugCtrl DebugCtrl
;
86 static struct Map MapEnt
;
87 static struct PortSetup PortSetup
;
88 static struct DownLoad DownLoad
;
89 static struct SendPack SendPack
;
90 /* static struct StreamInfo StreamInfo; */
91 /* static char modemtable[RIO_PORTS]; */
92 static struct SpecialRupCmd SpecialRupCmd
;
93 static struct PortParams PortParams
;
94 static struct portStats portStats
;
96 static struct SubCmdStruct
{
105 struct ttystatics Tty
;
108 static struct PortTty PortTty
;
109 typedef struct ttystatics TERMIO
;
112 ** This table is used when the config.rio downloads bin code to the
113 ** driver. We index the table using the product code, 0-F, and call
114 ** the function pointed to by the entry, passing the information
116 ** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
117 ** process to bog off.
120 (*RIOBootTable
[MAX_PRODUCT
]) (struct rio_info
*, struct DownLoad
*) = {
121 /* 0 */ RIOBootCodeHOST
,
123 /* 1 */ RIOBootCodeRTA
,
127 #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
129 int riocontrol(p
, dev
, cmd
, arg
, su
)
136 uint Host
; /* leave me unsigned! */
137 uint port
; /* and me! */
148 /* Confuse the compiler to think that we've initialized these */
152 rio_dprintk(RIO_DEBUG_CTRL
, "control ioctl cmd: 0x%x arg: %p\n", cmd
, arg
);
158 ** Change the value of the host card interrupt timer.
159 ** If the host card number is -1 then all host cards are changed
160 ** otherwise just the specified host card will be changed.
163 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SET_TIMER to %ldms\n", (unsigned long)arg
);
166 host
= ((unsigned long) arg
>> 16) & 0x0000FFFF;
167 value
= (unsigned long) arg
& 0x0000ffff;
169 for (host
= 0; host
< p
->RIONumHosts
; host
++) {
170 if (p
->RIOHosts
[host
].Flags
== RC_RUNNING
) {
171 writew(value
, &p
->RIOHosts
[host
].ParmMapP
->timer
);
174 } else if (host
>= p
->RIONumHosts
) {
177 if (p
->RIOHosts
[host
].Flags
== RC_RUNNING
) {
178 writew(value
, &p
->RIOHosts
[host
].ParmMapP
->timer
);
185 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_FOAD_RTA\n");
186 return RIOCommandRta(p
, (unsigned long)arg
, RIOFoadRta
);
189 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_ZOMBIE_RTA\n");
190 return RIOCommandRta(p
, (unsigned long)arg
, RIOZombieRta
);
192 case RIO_IDENTIFY_RTA
:
193 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_IDENTIFY_RTA\n");
194 return RIOIdentifyRta(p
, arg
);
196 case RIO_KILL_NEIGHBOUR
:
197 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_KILL_NEIGHBOUR\n");
198 return RIOKillNeighbour(p
, arg
);
200 case SPECIAL_RUP_CMD
:
202 struct CmdBlk
*CmdBlkP
;
204 rio_dprintk(RIO_DEBUG_CTRL
, "SPECIAL_RUP_CMD\n");
205 if (copy_from_user(&SpecialRupCmd
, arg
, sizeof(SpecialRupCmd
))) {
206 rio_dprintk(RIO_DEBUG_CTRL
, "SPECIAL_RUP_CMD copy failed\n");
207 p
->RIOError
.Error
= COPYIN_FAILED
;
210 CmdBlkP
= RIOGetCmdBlk();
212 rio_dprintk(RIO_DEBUG_CTRL
, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
215 CmdBlkP
->Packet
= SpecialRupCmd
.Packet
;
216 if (SpecialRupCmd
.Host
>= p
->RIONumHosts
)
217 SpecialRupCmd
.Host
= 0;
218 rio_dprintk(RIO_DEBUG_CTRL
, "Queue special rup command for host %d rup %d\n", SpecialRupCmd
.Host
, SpecialRupCmd
.RupNum
);
219 if (RIOQueueCmdBlk(&p
->RIOHosts
[SpecialRupCmd
.Host
], SpecialRupCmd
.RupNum
, CmdBlkP
) == RIO_FAIL
) {
220 printk(KERN_WARNING
"rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
229 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_ALL_MODEM\n");
230 p
->RIOError
.Error
= IOCTL_COMMAND_UNKNOWN
;
235 ** Read the routing table from the device driver to user space
237 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_TABLE\n");
239 if ((retval
= RIOApel(p
)) != 0)
242 if (copy_to_user(arg
, p
->RIOConnectTable
, TOTAL_MAP_ENTRIES
* sizeof(struct Map
))) {
243 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_TABLE copy failed\n");
244 p
->RIOError
.Error
= COPYOUT_FAILED
;
250 rio_dprintk(RIO_DEBUG_CTRL
, "*****\nMAP ENTRIES\n");
251 for (entry
= 0; entry
< TOTAL_MAP_ENTRIES
; entry
++) {
252 if ((p
->RIOConnectTable
[entry
].ID
== 0) && (p
->RIOConnectTable
[entry
].HostUniqueNum
== 0) && (p
->RIOConnectTable
[entry
].RtaUniqueNum
== 0))
255 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.HostUniqueNum = 0x%x\n", entry
, p
->RIOConnectTable
[entry
].HostUniqueNum
);
256 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.RtaUniqueNum = 0x%x\n", entry
, p
->RIOConnectTable
[entry
].RtaUniqueNum
);
257 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.ID = 0x%x\n", entry
, p
->RIOConnectTable
[entry
].ID
);
258 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.ID2 = 0x%x\n", entry
, p
->RIOConnectTable
[entry
].ID2
);
259 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.Flags = 0x%x\n", entry
, (int) p
->RIOConnectTable
[entry
].Flags
);
260 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.SysPort = 0x%x\n", entry
, (int) p
->RIOConnectTable
[entry
].SysPort
);
261 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.Top[0].Unit = %x\n", entry
, p
->RIOConnectTable
[entry
].Topology
[0].Unit
);
262 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.Top[0].Link = %x\n", entry
, p
->RIOConnectTable
[entry
].Topology
[0].Link
);
263 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.Top[1].Unit = %x\n", entry
, p
->RIOConnectTable
[entry
].Topology
[1].Unit
);
264 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.Top[1].Link = %x\n", entry
, p
->RIOConnectTable
[entry
].Topology
[1].Link
);
265 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.Top[2].Unit = %x\n", entry
, p
->RIOConnectTable
[entry
].Topology
[2].Unit
);
266 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.Top[2].Link = %x\n", entry
, p
->RIOConnectTable
[entry
].Topology
[2].Link
);
267 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.Top[3].Unit = %x\n", entry
, p
->RIOConnectTable
[entry
].Topology
[3].Unit
);
268 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.Top[4].Link = %x\n", entry
, p
->RIOConnectTable
[entry
].Topology
[3].Link
);
269 rio_dprintk(RIO_DEBUG_CTRL
, "Map entry %d.Name = %s\n", entry
, p
->RIOConnectTable
[entry
].Name
);
271 rio_dprintk(RIO_DEBUG_CTRL
, "*****\nEND MAP ENTRIES\n");
273 p
->RIOQuickCheck
= NOT_CHANGED
; /* a table has been gotten */
278 ** Write the routing table to the device driver from user space
280 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PUT_TABLE\n");
283 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PUT_TABLE !Root\n");
284 p
->RIOError
.Error
= NOT_SUPER_USER
;
287 if (copy_from_user(&p
->RIOConnectTable
[0], arg
, TOTAL_MAP_ENTRIES
* sizeof(struct Map
))) {
288 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PUT_TABLE copy failed\n");
289 p
->RIOError
.Error
= COPYIN_FAILED
;
293 ***********************************
296 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
297 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
299 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
300 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
301 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
302 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
303 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
304 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
305 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
306 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
307 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
308 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
309 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
310 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
311 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
312 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
313 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
315 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
317 ***********************************
319 return RIONewTable(p
);
321 case RIO_GET_BINDINGS
:
323 ** Send bindings table, containing unique numbers of RTAs owned
324 ** by this system to user space
326 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_BINDINGS\n");
329 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_BINDINGS !Root\n");
330 p
->RIOError
.Error
= NOT_SUPER_USER
;
333 if (copy_to_user(arg
, p
->RIOBindTab
, (sizeof(ulong
) * MAX_RTA_BINDINGS
))) {
334 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_BINDINGS copy failed\n");
335 p
->RIOError
.Error
= COPYOUT_FAILED
;
340 case RIO_PUT_BINDINGS
:
342 ** Receive a bindings table, containing unique numbers of RTAs owned
345 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PUT_BINDINGS\n");
348 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PUT_BINDINGS !Root\n");
349 p
->RIOError
.Error
= NOT_SUPER_USER
;
352 if (copy_from_user(&p
->RIOBindTab
[0], arg
, (sizeof(ulong
) * MAX_RTA_BINDINGS
))) {
353 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PUT_BINDINGS copy failed\n");
354 p
->RIOError
.Error
= COPYIN_FAILED
;
363 ** Bind this RTA to host, so that it will be booted by
364 ** host in 'boot owned RTAs' mode.
366 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_BIND_RTA\n");
369 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_BIND_RTA !Root\n");
370 p
->RIOError
.Error
= NOT_SUPER_USER
;
373 for (Entry
= 0; Entry
< MAX_RTA_BINDINGS
; Entry
++) {
374 if ((EmptySlot
== -1) && (p
->RIOBindTab
[Entry
] == 0L))
376 else if (p
->RIOBindTab
[Entry
] == (long)arg
) {
378 ** Already exists - delete
380 p
->RIOBindTab
[Entry
] = 0L;
381 rio_dprintk(RIO_DEBUG_CTRL
, "Removing Rta %ld from p->RIOBindTab\n", (unsigned long)arg
);
386 ** Dosen't exist - add
388 if (EmptySlot
!= -1) {
389 p
->RIOBindTab
[EmptySlot
] = (unsigned long)arg
;
390 rio_dprintk(RIO_DEBUG_CTRL
, "Adding Rta %lx to p->RIOBindTab\n", (unsigned long) arg
);
392 rio_dprintk(RIO_DEBUG_CTRL
, "p->RIOBindTab full! - Rta %lx not added\n", (unsigned long) arg
);
399 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_RESUME\n");
400 port
= (unsigned long) arg
;
401 if ((port
< 0) || (port
> 511)) {
402 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_RESUME: Bad port number %d\n", port
);
403 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
406 PortP
= p
->RIOPortp
[port
];
407 if (!PortP
->Mapped
) {
408 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_RESUME: Port %d not mapped\n", port
);
409 p
->RIOError
.Error
= PORT_NOT_MAPPED_INTO_SYSTEM
;
412 if (!(PortP
->State
& (RIO_LOPEN
| RIO_MOPEN
))) {
413 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_RESUME: Port %d not open\n", port
);
417 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
418 if (RIOPreemptiveCmd(p
, (p
->RIOPortp
[port
]), RESUME
) == RIO_FAIL
) {
419 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_RESUME failed\n");
420 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
423 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_RESUME: Port %d resumed\n", port
);
424 PortP
->State
|= RIO_BUSY
;
426 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
430 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_ASSIGN_RTA\n");
432 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_ASSIGN_RTA !Root\n");
433 p
->RIOError
.Error
= NOT_SUPER_USER
;
436 if (copy_from_user(&MapEnt
, arg
, sizeof(MapEnt
))) {
437 rio_dprintk(RIO_DEBUG_CTRL
, "Copy from user space failed\n");
438 p
->RIOError
.Error
= COPYIN_FAILED
;
441 return RIOAssignRta(p
, &MapEnt
);
443 case RIO_CHANGE_NAME
:
444 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_CHANGE_NAME\n");
446 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_CHANGE_NAME !Root\n");
447 p
->RIOError
.Error
= NOT_SUPER_USER
;
450 if (copy_from_user(&MapEnt
, arg
, sizeof(MapEnt
))) {
451 rio_dprintk(RIO_DEBUG_CTRL
, "Copy from user space failed\n");
452 p
->RIOError
.Error
= COPYIN_FAILED
;
455 return RIOChangeName(p
, &MapEnt
);
458 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_DELETE_RTA\n");
460 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_DELETE_RTA !Root\n");
461 p
->RIOError
.Error
= NOT_SUPER_USER
;
464 if (copy_from_user(&MapEnt
, arg
, sizeof(MapEnt
))) {
465 rio_dprintk(RIO_DEBUG_CTRL
, "Copy from data space failed\n");
466 p
->RIOError
.Error
= COPYIN_FAILED
;
469 return RIODeleteRta(p
, &MapEnt
);
471 case RIO_QUICK_CHECK
:
472 if (copy_to_user(arg
, &p
->RIORtaDisCons
, sizeof(unsigned int))) {
473 p
->RIOError
.Error
= COPYOUT_FAILED
;
479 if (copy_to_user(arg
, &p
->RIOError
, sizeof(struct Error
)))
484 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_LOG\n");
487 case RIO_GET_MODTYPE
:
488 if (copy_from_user(&port
, arg
, sizeof(unsigned int))) {
489 p
->RIOError
.Error
= COPYIN_FAILED
;
492 rio_dprintk(RIO_DEBUG_CTRL
, "Get module type for port %d\n", port
);
493 if (port
< 0 || port
> 511) {
494 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_MODTYPE: Bad port number %d\n", port
);
495 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
498 PortP
= (p
->RIOPortp
[port
]);
499 if (!PortP
->Mapped
) {
500 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_MODTYPE: Port %d not mapped\n", port
);
501 p
->RIOError
.Error
= PORT_NOT_MAPPED_INTO_SYSTEM
;
505 ** Return module type of port
507 port
= PortP
->HostP
->UnixRups
[PortP
->RupNum
].ModTypes
;
508 if (copy_to_user(arg
, &port
, sizeof(unsigned int))) {
509 p
->RIOError
.Error
= COPYOUT_FAILED
;
513 case RIO_BLOCK_OPENS
:
514 rio_dprintk(RIO_DEBUG_CTRL
, "Opens block until booted\n");
515 for (Entry
= 0; Entry
< RIO_PORTS
; Entry
++) {
516 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
517 p
->RIOPortp
[Entry
]->WaitUntilBooted
= 1;
518 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
522 case RIO_SETUP_PORTS
:
523 rio_dprintk(RIO_DEBUG_CTRL
, "Setup ports\n");
524 if (copy_from_user(&PortSetup
, arg
, sizeof(PortSetup
))) {
525 p
->RIOError
.Error
= COPYIN_FAILED
;
526 rio_dprintk(RIO_DEBUG_CTRL
, "EFAULT");
529 if (PortSetup
.From
> PortSetup
.To
|| PortSetup
.To
>= RIO_PORTS
) {
530 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
531 rio_dprintk(RIO_DEBUG_CTRL
, "ENXIO");
534 if (PortSetup
.XpCps
> p
->RIOConf
.MaxXpCps
|| PortSetup
.XpCps
< p
->RIOConf
.MinXpCps
) {
535 p
->RIOError
.Error
= XPRINT_CPS_OUT_OF_RANGE
;
536 rio_dprintk(RIO_DEBUG_CTRL
, "EINVAL");
540 printk(KERN_ERR
"rio: No p->RIOPortp array!\n");
541 rio_dprintk(RIO_DEBUG_CTRL
, "No p->RIOPortp array!\n");
544 rio_dprintk(RIO_DEBUG_CTRL
, "entering loop (%d %d)!\n", PortSetup
.From
, PortSetup
.To
);
545 for (loop
= PortSetup
.From
; loop
<= PortSetup
.To
; loop
++) {
546 rio_dprintk(RIO_DEBUG_CTRL
, "in loop (%d)!\n", loop
);
548 rio_dprintk(RIO_DEBUG_CTRL
, "after loop (%d)!\n", loop
);
549 rio_dprintk(RIO_DEBUG_CTRL
, "Retval:%x\n", retval
);
552 case RIO_GET_PORT_SETUP
:
553 rio_dprintk(RIO_DEBUG_CTRL
, "Get port setup\n");
554 if (copy_from_user(&PortSetup
, arg
, sizeof(PortSetup
))) {
555 p
->RIOError
.Error
= COPYIN_FAILED
;
558 if (PortSetup
.From
>= RIO_PORTS
) {
559 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
563 port
= PortSetup
.To
= PortSetup
.From
;
564 PortSetup
.IxAny
= (p
->RIOPortp
[port
]->Config
& RIO_IXANY
) ? 1 : 0;
565 PortSetup
.IxOn
= (p
->RIOPortp
[port
]->Config
& RIO_IXON
) ? 1 : 0;
566 PortSetup
.Drain
= (p
->RIOPortp
[port
]->Config
& RIO_WAITDRAIN
) ? 1 : 0;
567 PortSetup
.Store
= p
->RIOPortp
[port
]->Store
;
568 PortSetup
.Lock
= p
->RIOPortp
[port
]->Lock
;
569 PortSetup
.XpCps
= p
->RIOPortp
[port
]->Xprint
.XpCps
;
570 memcpy(PortSetup
.XpOn
, p
->RIOPortp
[port
]->Xprint
.XpOn
, MAX_XP_CTRL_LEN
);
571 memcpy(PortSetup
.XpOff
, p
->RIOPortp
[port
]->Xprint
.XpOff
, MAX_XP_CTRL_LEN
);
572 PortSetup
.XpOn
[MAX_XP_CTRL_LEN
- 1] = '\0';
573 PortSetup
.XpOff
[MAX_XP_CTRL_LEN
- 1] = '\0';
575 if (copy_to_user(arg
, &PortSetup
, sizeof(PortSetup
))) {
576 p
->RIOError
.Error
= COPYOUT_FAILED
;
581 case RIO_GET_PORT_PARAMS
:
582 rio_dprintk(RIO_DEBUG_CTRL
, "Get port params\n");
583 if (copy_from_user(&PortParams
, arg
, sizeof(struct PortParams
))) {
584 p
->RIOError
.Error
= COPYIN_FAILED
;
587 if (PortParams
.Port
>= RIO_PORTS
) {
588 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
591 PortP
= (p
->RIOPortp
[PortParams
.Port
]);
592 PortParams
.Config
= PortP
->Config
;
593 PortParams
.State
= PortP
->State
;
594 rio_dprintk(RIO_DEBUG_CTRL
, "Port %d\n", PortParams
.Port
);
596 if (copy_to_user(arg
, &PortParams
, sizeof(struct PortParams
))) {
597 p
->RIOError
.Error
= COPYOUT_FAILED
;
602 case RIO_GET_PORT_TTY
:
603 rio_dprintk(RIO_DEBUG_CTRL
, "Get port tty\n");
604 if (copy_from_user(&PortTty
, arg
, sizeof(struct PortTty
))) {
605 p
->RIOError
.Error
= COPYIN_FAILED
;
608 if (PortTty
.port
>= RIO_PORTS
) {
609 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
613 rio_dprintk(RIO_DEBUG_CTRL
, "Port %d\n", PortTty
.port
);
614 PortP
= (p
->RIOPortp
[PortTty
.port
]);
615 if (copy_to_user(arg
, &PortTty
, sizeof(struct PortTty
))) {
616 p
->RIOError
.Error
= COPYOUT_FAILED
;
621 case RIO_SET_PORT_TTY
:
622 if (copy_from_user(&PortTty
, arg
, sizeof(struct PortTty
))) {
623 p
->RIOError
.Error
= COPYIN_FAILED
;
626 rio_dprintk(RIO_DEBUG_CTRL
, "Set port %d tty\n", PortTty
.port
);
627 if (PortTty
.port
>= (ushort
) RIO_PORTS
) {
628 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
631 PortP
= (p
->RIOPortp
[PortTty
.port
]);
632 RIOParam(PortP
, CONFIG
, PortP
->State
& RIO_MODEM
, OK_TO_SLEEP
);
635 case RIO_SET_PORT_PARAMS
:
636 rio_dprintk(RIO_DEBUG_CTRL
, "Set port params\n");
637 if (copy_from_user(&PortParams
, arg
, sizeof(PortParams
))) {
638 p
->RIOError
.Error
= COPYIN_FAILED
;
641 if (PortParams
.Port
>= (ushort
) RIO_PORTS
) {
642 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
645 PortP
= (p
->RIOPortp
[PortParams
.Port
]);
646 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
647 PortP
->Config
= PortParams
.Config
;
648 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
651 case RIO_GET_PORT_STATS
:
652 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GET_PORT_STATS\n");
653 if (copy_from_user(&portStats
, arg
, sizeof(struct portStats
))) {
654 p
->RIOError
.Error
= COPYIN_FAILED
;
657 if (portStats
.port
>= RIO_PORTS
) {
658 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
661 PortP
= (p
->RIOPortp
[portStats
.port
]);
662 portStats
.gather
= PortP
->statsGather
;
663 portStats
.txchars
= PortP
->txchars
;
664 portStats
.rxchars
= PortP
->rxchars
;
665 portStats
.opens
= PortP
->opens
;
666 portStats
.closes
= PortP
->closes
;
667 portStats
.ioctls
= PortP
->ioctls
;
668 if (copy_to_user(arg
, &portStats
, sizeof(struct portStats
))) {
669 p
->RIOError
.Error
= COPYOUT_FAILED
;
674 case RIO_RESET_PORT_STATS
:
675 port
= (unsigned long) arg
;
676 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_RESET_PORT_STATS\n");
677 if (port
>= RIO_PORTS
) {
678 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
681 PortP
= (p
->RIOPortp
[port
]);
682 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
688 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
691 case RIO_GATHER_PORT_STATS
:
692 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GATHER_PORT_STATS\n");
693 if (copy_from_user(&portStats
, arg
, sizeof(struct portStats
))) {
694 p
->RIOError
.Error
= COPYIN_FAILED
;
697 if (portStats
.port
>= RIO_PORTS
) {
698 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
701 PortP
= (p
->RIOPortp
[portStats
.port
]);
702 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
703 PortP
->statsGather
= portStats
.gather
;
704 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
707 case RIO_READ_CONFIG
:
708 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_READ_CONFIG\n");
709 if (copy_to_user(arg
, &p
->RIOConf
, sizeof(struct Conf
))) {
710 p
->RIOError
.Error
= COPYOUT_FAILED
;
716 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SET_CONFIG\n");
718 p
->RIOError
.Error
= NOT_SUPER_USER
;
721 if (copy_from_user(&p
->RIOConf
, arg
, sizeof(struct Conf
))) {
722 p
->RIOError
.Error
= COPYIN_FAILED
;
726 ** move a few value around
728 for (Host
= 0; Host
< p
->RIONumHosts
; Host
++)
729 if ((p
->RIOHosts
[Host
].Flags
& RUN_STATE
) == RC_RUNNING
)
730 writew(p
->RIOConf
.Timer
, &p
->RIOHosts
[Host
].ParmMapP
->timer
);
733 case RIO_START_POLLER
:
734 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_START_POLLER\n");
737 case RIO_STOP_POLLER
:
738 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_STOP_POLLER\n");
740 p
->RIOError
.Error
= NOT_SUPER_USER
;
743 p
->RIOPolling
= NOT_POLLING
;
748 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SETDEBUG/RIO_GETDEBUG\n");
749 if (copy_from_user(&DebugCtrl
, arg
, sizeof(DebugCtrl
))) {
750 p
->RIOError
.Error
= COPYIN_FAILED
;
753 if (DebugCtrl
.SysPort
== NO_PORT
) {
754 if (cmd
== RIO_SETDEBUG
) {
756 p
->RIOError
.Error
= NOT_SUPER_USER
;
759 p
->rio_debug
= DebugCtrl
.Debug
;
760 p
->RIODebugWait
= DebugCtrl
.Wait
;
761 rio_dprintk(RIO_DEBUG_CTRL
, "Set global debug to 0x%x set wait to 0x%x\n", p
->rio_debug
, p
->RIODebugWait
);
763 rio_dprintk(RIO_DEBUG_CTRL
, "Get global debug 0x%x wait 0x%x\n", p
->rio_debug
, p
->RIODebugWait
);
764 DebugCtrl
.Debug
= p
->rio_debug
;
765 DebugCtrl
.Wait
= p
->RIODebugWait
;
766 if (copy_to_user(arg
, &DebugCtrl
, sizeof(DebugCtrl
))) {
767 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl
.SysPort
);
768 p
->RIOError
.Error
= COPYOUT_FAILED
;
772 } else if (DebugCtrl
.SysPort
>= RIO_PORTS
&& DebugCtrl
.SysPort
!= NO_PORT
) {
773 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl
.SysPort
);
774 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
776 } else if (cmd
== RIO_SETDEBUG
) {
778 p
->RIOError
.Error
= NOT_SUPER_USER
;
781 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
782 p
->RIOPortp
[DebugCtrl
.SysPort
]->Debug
= DebugCtrl
.Debug
;
783 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
784 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SETDEBUG 0x%x\n", p
->RIOPortp
[DebugCtrl
.SysPort
]->Debug
);
786 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GETDEBUG 0x%x\n", p
->RIOPortp
[DebugCtrl
.SysPort
]->Debug
);
787 DebugCtrl
.Debug
= p
->RIOPortp
[DebugCtrl
.SysPort
]->Debug
;
788 if (copy_to_user(arg
, &DebugCtrl
, sizeof(DebugCtrl
))) {
789 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_GETDEBUG: Bad copy to user space\n");
790 p
->RIOError
.Error
= COPYOUT_FAILED
;
798 ** Enquire about the release and version.
799 ** We return MAX_VERSION_LEN bytes, being a
800 ** textual null terminated string.
802 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_VERSID\n");
803 if (copy_to_user(arg
, RIOVersid(), sizeof(struct rioVersion
))) {
804 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host
);
805 p
->RIOError
.Error
= COPYOUT_FAILED
;
812 ** Enquire as to the number of hosts located
815 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_NUM_HOSTS\n");
816 if (copy_to_user(arg
, &p
->RIONumHosts
, sizeof(p
->RIONumHosts
))) {
817 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_NUM_HOSTS: Bad copy to user space\n");
818 p
->RIOError
.Error
= COPYOUT_FAILED
;
825 ** Kill host. This may not be in the final version...
827 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_FOAD %ld\n", (unsigned long) arg
);
829 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_FOAD: Not super user\n");
830 p
->RIOError
.Error
= NOT_SUPER_USER
;
836 for (Host
= 0; Host
< p
->RIONumHosts
; Host
++) {
837 (void) RIOBoardTest(p
->RIOHosts
[Host
].PaddrP
, p
->RIOHosts
[Host
].Caddr
, p
->RIOHosts
[Host
].Type
, p
->RIOHosts
[Host
].Slot
);
838 memset(&p
->RIOHosts
[Host
].Flags
, 0, ((char *) &p
->RIOHosts
[Host
].____end_marker____
) - ((char *) &p
->RIOHosts
[Host
].Flags
));
839 p
->RIOHosts
[Host
].Flags
= RC_WAITING
;
842 p
->RIONumBootPkts
= 0;
844 printk("HEEEEELP!\n");
846 for (loop
= 0; loop
< RIO_PORTS
; loop
++) {
847 spin_lock_init(&p
->RIOPortp
[loop
]->portSem
);
848 p
->RIOPortp
[loop
]->InUse
= NOT_INUSE
;
855 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_DOWNLOAD\n");
857 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_DOWNLOAD: Not super user\n");
858 p
->RIOError
.Error
= NOT_SUPER_USER
;
861 if (copy_from_user(&DownLoad
, arg
, sizeof(DownLoad
))) {
862 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_DOWNLOAD: Copy in from user space failed\n");
863 p
->RIOError
.Error
= COPYIN_FAILED
;
866 rio_dprintk(RIO_DEBUG_CTRL
, "Copied in download code for product code 0x%x\n", DownLoad
.ProductCode
);
869 ** It is important that the product code is an unsigned object!
871 if (DownLoad
.ProductCode
> MAX_PRODUCT
) {
872 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad
.ProductCode
);
873 p
->RIOError
.Error
= NO_SUCH_PRODUCT
;
879 retval
= (*(RIOBootTable
[DownLoad
.ProductCode
])) (p
, &DownLoad
);
883 ** and go back, content with a job well completed.
891 if (copy_from_user(&host
, arg
, sizeof(host
))) {
892 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_REQ: Copy in from user space failed\n");
893 p
->RIOError
.Error
= COPYIN_FAILED
;
899 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PARMS\n");
900 if (copy_to_user(arg
, p
->RIOHosts
[host
].ParmMapP
, sizeof(PARM_MAP
))) {
901 p
->RIOError
.Error
= COPYOUT_FAILED
;
902 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_PARMS: Copy out to user space failed\n");
909 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_REQ\n");
910 if (copy_from_user(&HostReq
, arg
, sizeof(HostReq
))) {
911 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_REQ: Copy in from user space failed\n");
912 p
->RIOError
.Error
= COPYIN_FAILED
;
915 if (HostReq
.HostNum
>= p
->RIONumHosts
) {
916 p
->RIOError
.Error
= HOST_NUMBER_OUT_OF_RANGE
;
917 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_REQ: Illegal host number %d\n", HostReq
.HostNum
);
920 rio_dprintk(RIO_DEBUG_CTRL
, "Request for host %d\n", HostReq
.HostNum
);
922 if (copy_to_user(HostReq
.HostP
, &p
->RIOHosts
[HostReq
.HostNum
], sizeof(struct Host
))) {
923 p
->RIOError
.Error
= COPYOUT_FAILED
;
924 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_REQ: Bad copy to user space\n");
930 rio_dprintk(RIO_DEBUG_CTRL
, "Request for DPRAM\n");
931 if (copy_from_user(&HostDpRam
, arg
, sizeof(HostDpRam
))) {
932 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_DPRAM: Copy in from user space failed\n");
933 p
->RIOError
.Error
= COPYIN_FAILED
;
936 if (HostDpRam
.HostNum
>= p
->RIONumHosts
) {
937 p
->RIOError
.Error
= HOST_NUMBER_OUT_OF_RANGE
;
938 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam
.HostNum
);
941 rio_dprintk(RIO_DEBUG_CTRL
, "Request for host %d\n", HostDpRam
.HostNum
);
943 if (p
->RIOHosts
[HostDpRam
.HostNum
].Type
== RIO_PCI
) {
945 /* It's hardware like this that really gets on my tits. */
946 static unsigned char copy
[sizeof(struct DpRam
)];
947 for (off
= 0; off
< sizeof(struct DpRam
); off
++)
948 copy
[off
] = readb(&p
->RIOHosts
[HostDpRam
.HostNum
].Caddr
[off
]);
949 if (copy_to_user(HostDpRam
.DpRamP
, copy
, sizeof(struct DpRam
))) {
950 p
->RIOError
.Error
= COPYOUT_FAILED
;
951 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_DPRAM: Bad copy to user space\n");
954 } else if (copy_to_user(HostDpRam
.DpRamP
, p
->RIOHosts
[HostDpRam
.HostNum
].Caddr
, sizeof(struct DpRam
))) {
955 p
->RIOError
.Error
= COPYOUT_FAILED
;
956 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_DPRAM: Bad copy to user space\n");
962 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SET_BUSY\n");
963 if ((unsigned long) arg
> 511) {
964 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SET_BUSY: Bad port number %ld\n", (unsigned long) arg
);
965 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
968 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
969 p
->RIOPortp
[(unsigned long) arg
]->State
|= RIO_BUSY
;
970 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
975 ** The daemon want port information
976 ** (probably for debug reasons)
978 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_PORT\n");
979 if (copy_from_user(&PortReq
, arg
, sizeof(PortReq
))) {
980 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_PORT: Copy in from user space failed\n");
981 p
->RIOError
.Error
= COPYIN_FAILED
;
985 if (PortReq
.SysPort
>= RIO_PORTS
) { /* SysPort is unsigned */
986 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_PORT: Illegal port number %d\n", PortReq
.SysPort
);
987 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
990 rio_dprintk(RIO_DEBUG_CTRL
, "Request for port %d\n", PortReq
.SysPort
);
991 if (copy_to_user(PortReq
.PortP
, p
->RIOPortp
[PortReq
.SysPort
], sizeof(struct Port
))) {
992 p
->RIOError
.Error
= COPYOUT_FAILED
;
993 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_PORT: Bad copy to user space\n");
1000 ** The daemon want rup information
1001 ** (probably for debug reasons)
1003 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_RUP\n");
1004 if (copy_from_user(&RupReq
, arg
, sizeof(RupReq
))) {
1005 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_RUP: Copy in from user space failed\n");
1006 p
->RIOError
.Error
= COPYIN_FAILED
;
1009 if (RupReq
.HostNum
>= p
->RIONumHosts
) { /* host is unsigned */
1010 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_RUP: Illegal host number %d\n", RupReq
.HostNum
);
1011 p
->RIOError
.Error
= HOST_NUMBER_OUT_OF_RANGE
;
1014 if (RupReq
.RupNum
>= MAX_RUP
+ LINKS_PER_UNIT
) { /* eek! */
1015 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq
.RupNum
);
1016 p
->RIOError
.Error
= RUP_NUMBER_OUT_OF_RANGE
;
1019 HostP
= &p
->RIOHosts
[RupReq
.HostNum
];
1021 if ((HostP
->Flags
& RUN_STATE
) != RC_RUNNING
) {
1022 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_RUP: Host %d not running\n", RupReq
.HostNum
);
1023 p
->RIOError
.Error
= HOST_NOT_RUNNING
;
1026 rio_dprintk(RIO_DEBUG_CTRL
, "Request for rup %d from host %d\n", RupReq
.RupNum
, RupReq
.HostNum
);
1028 if (copy_to_user(HostP
->UnixRups
[RupReq
.RupNum
].RupP
, RupReq
.RupP
, sizeof(struct RUP
))) {
1029 p
->RIOError
.Error
= COPYOUT_FAILED
;
1030 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_RUP: Bad copy to user space\n");
1037 ** The daemon want lpb information
1038 ** (probably for debug reasons)
1040 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_LPB\n");
1041 if (copy_from_user(&LpbReq
, arg
, sizeof(LpbReq
))) {
1042 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_LPB: Bad copy from user space\n");
1043 p
->RIOError
.Error
= COPYIN_FAILED
;
1046 if (LpbReq
.Host
>= p
->RIONumHosts
) { /* host is unsigned */
1047 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq
.Host
);
1048 p
->RIOError
.Error
= HOST_NUMBER_OUT_OF_RANGE
;
1051 if (LpbReq
.Link
>= LINKS_PER_UNIT
) { /* eek! */
1052 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq
.Link
);
1053 p
->RIOError
.Error
= LINK_NUMBER_OUT_OF_RANGE
;
1056 HostP
= &p
->RIOHosts
[LpbReq
.Host
];
1058 if ((HostP
->Flags
& RUN_STATE
) != RC_RUNNING
) {
1059 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_LPB: Host %d not running\n", LpbReq
.Host
);
1060 p
->RIOError
.Error
= HOST_NOT_RUNNING
;
1063 rio_dprintk(RIO_DEBUG_CTRL
, "Request for lpb %d from host %d\n", LpbReq
.Link
, LpbReq
.Host
);
1065 if (copy_to_user(LpbReq
.LpbP
, &HostP
->LinkStrP
[LpbReq
.Link
], sizeof(struct LPB
))) {
1066 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_HOST_LPB: Bad copy to user space\n");
1067 p
->RIOError
.Error
= COPYOUT_FAILED
;
1073 ** Here 3 IOCTL's that allow us to change the way in which
1074 ** rio logs errors. send them just to syslog or send them
1075 ** to both syslog and console or send them to just the console.
1077 ** See RioStrBuf() in util.c for the other half.
1079 case RIO_SYSLOG_ONLY
:
1080 p
->RIOPrintLogState
= PRINT_TO_LOG
; /* Just syslog */
1083 case RIO_SYSLOG_CONS
:
1084 p
->RIOPrintLogState
= PRINT_TO_LOG_CONS
; /* syslog and console */
1088 p
->RIOPrintLogState
= PRINT_TO_CONS
; /* Just console */
1091 case RIO_SIGNALS_ON
:
1092 if (p
->RIOSignalProcess
) {
1093 p
->RIOError
.Error
= SIGNALS_ALREADY_SET
;
1096 /* FIXME: PID tracking */
1097 p
->RIOSignalProcess
= current
->pid
;
1098 p
->RIOPrintDisabled
= DONT_PRINT
;
1101 case RIO_SIGNALS_OFF
:
1102 if (p
->RIOSignalProcess
!= current
->pid
) {
1103 p
->RIOError
.Error
= NOT_RECEIVING_PROCESS
;
1106 rio_dprintk(RIO_DEBUG_CTRL
, "Clear signal process to zero\n");
1107 p
->RIOSignalProcess
= 0;
1110 case RIO_SET_BYTE_MODE
:
1111 for (Host
= 0; Host
< p
->RIONumHosts
; Host
++)
1112 if (p
->RIOHosts
[Host
].Type
== RIO_AT
)
1113 p
->RIOHosts
[Host
].Mode
&= ~WORD_OPERATION
;
1116 case RIO_SET_WORD_MODE
:
1117 for (Host
= 0; Host
< p
->RIONumHosts
; Host
++)
1118 if (p
->RIOHosts
[Host
].Type
== RIO_AT
)
1119 p
->RIOHosts
[Host
].Mode
|= WORD_OPERATION
;
1122 case RIO_SET_FAST_BUS
:
1123 for (Host
= 0; Host
< p
->RIONumHosts
; Host
++)
1124 if (p
->RIOHosts
[Host
].Type
== RIO_AT
)
1125 p
->RIOHosts
[Host
].Mode
|= FAST_AT_BUS
;
1128 case RIO_SET_SLOW_BUS
:
1129 for (Host
= 0; Host
< p
->RIONumHosts
; Host
++)
1130 if (p
->RIOHosts
[Host
].Type
== RIO_AT
)
1131 p
->RIOHosts
[Host
].Mode
&= ~FAST_AT_BUS
;
1134 case RIO_MAP_B50_TO_50
:
1135 case RIO_MAP_B50_TO_57600
:
1136 case RIO_MAP_B110_TO_110
:
1137 case RIO_MAP_B110_TO_115200
:
1138 rio_dprintk(RIO_DEBUG_CTRL
, "Baud rate mapping\n");
1139 port
= (unsigned long) arg
;
1140 if (port
< 0 || port
> 511) {
1141 rio_dprintk(RIO_DEBUG_CTRL
, "Baud rate mapping: Bad port number %d\n", port
);
1142 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
1145 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
1147 case RIO_MAP_B50_TO_50
:
1148 p
->RIOPortp
[port
]->Config
|= RIO_MAP_50_TO_50
;
1150 case RIO_MAP_B50_TO_57600
:
1151 p
->RIOPortp
[port
]->Config
&= ~RIO_MAP_50_TO_50
;
1153 case RIO_MAP_B110_TO_110
:
1154 p
->RIOPortp
[port
]->Config
|= RIO_MAP_110_TO_110
;
1156 case RIO_MAP_B110_TO_115200
:
1157 p
->RIOPortp
[port
]->Config
&= ~RIO_MAP_110_TO_110
;
1160 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
1163 case RIO_STREAM_INFO
:
1164 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_STREAM_INFO\n");
1167 case RIO_SEND_PACKET
:
1168 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SEND_PACKET\n");
1169 if (copy_from_user(&SendPack
, arg
, sizeof(SendPack
))) {
1170 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_SEND_PACKET: Bad copy from user space\n");
1171 p
->RIOError
.Error
= COPYIN_FAILED
;
1174 if (SendPack
.PortNum
>= 128) {
1175 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
1179 PortP
= p
->RIOPortp
[SendPack
.PortNum
];
1180 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
1182 if (!can_add_transmit(&PacketP
, PortP
)) {
1183 p
->RIOError
.Error
= UNIT_IS_IN_USE
;
1184 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
1188 for (loop
= 0; loop
< (ushort
) (SendPack
.Len
& 127); loop
++)
1189 writeb(SendPack
.Data
[loop
], &PacketP
->data
[loop
]);
1191 writeb(SendPack
.Len
, &PacketP
->len
);
1193 add_transmit(PortP
);
1195 ** Count characters transmitted for port statistics reporting
1197 if (PortP
->statsGather
)
1198 PortP
->txchars
+= (SendPack
.Len
& 127);
1199 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
1204 p
->RIONoMessage
= 1;
1205 return su
? 0 : -EPERM
;
1209 p
->RIONoMessage
= 0;
1210 return su
? 0 : -EPERM
;
1213 if (copy_to_user(arg
, &p
->RIONoMessage
, sizeof(p
->RIONoMessage
))) {
1214 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_WHAT_MESG: Bad copy to user space\n");
1215 p
->RIOError
.Error
= COPYOUT_FAILED
;
1221 if (copy_from_user(&SubCmd
, arg
, sizeof(struct SubCmdStruct
))) {
1222 p
->RIOError
.Error
= COPYIN_FAILED
;
1225 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd
.Host
, SubCmd
.Rup
, SubCmd
.Addr
);
1227 if (SubCmd
.Rup
>= MAX_RUP
+ LINKS_PER_UNIT
) {
1228 p
->RIOError
.Error
= RUP_NUMBER_OUT_OF_RANGE
;
1232 if (SubCmd
.Host
>= p
->RIONumHosts
) {
1233 p
->RIOError
.Error
= HOST_NUMBER_OUT_OF_RANGE
;
1237 port
= p
->RIOHosts
[SubCmd
.Host
].UnixRups
[SubCmd
.Rup
].BaseSysPort
;
1239 PortP
= p
->RIOPortp
[port
];
1241 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
1243 if (RIOPreemptiveCmd(p
, PortP
, MEMDUMP
) == RIO_FAIL
) {
1244 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_MEM_DUMP failed\n");
1245 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
1248 PortP
->State
|= RIO_BUSY
;
1250 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
1251 if (copy_to_user(arg
, p
->RIOMemDump
, MEMDUMP_SIZE
)) {
1252 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_MEM_DUMP copy failed\n");
1253 p
->RIOError
.Error
= COPYOUT_FAILED
;
1259 if ((unsigned long) arg
>= p
->RIONumHosts
)
1261 rio_dprintk(RIO_DEBUG_CTRL
, "Set interrupt for host %ld\n", (unsigned long) arg
);
1262 writeb(0xFF, &p
->RIOHosts
[(unsigned long) arg
].SetInt
);
1266 if ((unsigned long) arg
>= p
->RIONumHosts
)
1268 rio_dprintk(RIO_DEBUG_CTRL
, "Clear interrupt for host %ld\n", (unsigned long) arg
);
1269 writeb(0xFF, &p
->RIOHosts
[(unsigned long) arg
].ResetInt
);
1272 case RIO_READ_CHECK
:
1273 /* Check reads for pkts with data[0] the same */
1274 p
->RIOReadCheck
= !p
->RIOReadCheck
;
1275 if (copy_to_user(arg
, &p
->RIOReadCheck
, sizeof(unsigned int))) {
1276 p
->RIOError
.Error
= COPYOUT_FAILED
;
1281 case RIO_READ_REGISTER
:
1282 if (copy_from_user(&SubCmd
, arg
, sizeof(struct SubCmdStruct
))) {
1283 p
->RIOError
.Error
= COPYIN_FAILED
;
1286 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_READ_REGISTER host %d rup %d port %d reg %x\n", SubCmd
.Host
, SubCmd
.Rup
, SubCmd
.Port
, SubCmd
.Addr
);
1288 if (SubCmd
.Port
> 511) {
1289 rio_dprintk(RIO_DEBUG_CTRL
, "Baud rate mapping: Bad port number %d\n", SubCmd
.Port
);
1290 p
->RIOError
.Error
= PORT_NUMBER_OUT_OF_RANGE
;
1294 if (SubCmd
.Rup
>= MAX_RUP
+ LINKS_PER_UNIT
) {
1295 p
->RIOError
.Error
= RUP_NUMBER_OUT_OF_RANGE
;
1299 if (SubCmd
.Host
>= p
->RIONumHosts
) {
1300 p
->RIOError
.Error
= HOST_NUMBER_OUT_OF_RANGE
;
1304 port
= p
->RIOHosts
[SubCmd
.Host
].UnixRups
[SubCmd
.Rup
].BaseSysPort
+ SubCmd
.Port
;
1305 PortP
= p
->RIOPortp
[port
];
1307 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
1309 if (RIOPreemptiveCmd(p
, PortP
, READ_REGISTER
) == RIO_FAIL
) {
1310 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_READ_REGISTER failed\n");
1311 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
1314 PortP
->State
|= RIO_BUSY
;
1316 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
1317 if (copy_to_user(arg
, &p
->CdRegister
, sizeof(unsigned int))) {
1318 rio_dprintk(RIO_DEBUG_CTRL
, "RIO_READ_REGISTER copy failed\n");
1319 p
->RIOError
.Error
= COPYOUT_FAILED
;
1324 ** rio_make_dev: given port number (0-511) ORed with port type
1325 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1326 ** value to pass to mknod to create the correct device node.
1330 unsigned int port
= (unsigned long) arg
& RIO_MODEM_MASK
;
1333 switch ((unsigned long) arg
& RIO_DEV_MASK
) {
1334 case RIO_DEV_DIRECT
:
1335 ret
= drv_makedev(MAJOR(dev
), port
);
1336 rio_dprintk(RIO_DEBUG_CTRL
, "Makedev direct 0x%x is 0x%x\n", port
, ret
);
1339 ret
= drv_makedev(MAJOR(dev
), (port
| RIO_MODEM_BIT
));
1340 rio_dprintk(RIO_DEBUG_CTRL
, "Makedev modem 0x%x is 0x%x\n", port
, ret
);
1342 case RIO_DEV_XPRINT
:
1343 ret
= drv_makedev(MAJOR(dev
), port
);
1344 rio_dprintk(RIO_DEBUG_CTRL
, "Makedev printer 0x%x is 0x%x\n", port
, ret
);
1347 rio_dprintk(RIO_DEBUG_CTRL
, "MAKE Device is called\n");
1351 ** rio_minor: given a dev_t from a stat() call, return
1352 ** the port number (0-511) ORed with the port type
1353 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1361 dv
= (dev_t
) ((unsigned long) arg
);
1362 mino
= RIO_UNMODEM(dv
);
1364 if (RIO_ISMODEM(dv
)) {
1365 rio_dprintk(RIO_DEBUG_CTRL
, "Minor for device 0x%x: modem %d\n", dv
, mino
);
1366 ret
= mino
| RIO_DEV_MODEM
;
1368 rio_dprintk(RIO_DEBUG_CTRL
, "Minor for device 0x%x: direct %d\n", dv
, mino
);
1369 ret
= mino
| RIO_DEV_DIRECT
;
1374 rio_dprintk(RIO_DEBUG_CTRL
, "INVALID DAEMON IOCTL 0x%x\n", cmd
);
1375 p
->RIOError
.Error
= IOCTL_COMMAND_UNKNOWN
;
1382 ** Pre-emptive commands go on RUPs and are only one byte long.
1384 int RIOPreemptiveCmd(struct rio_info
*p
, struct Port
*PortP
, u8 Cmd
)
1386 struct CmdBlk
*CmdBlkP
;
1387 struct PktCmd_M
*PktCmdP
;
1392 if (PortP
->State
& RIO_DELETED
) {
1393 rio_dprintk(RIO_DEBUG_CTRL
, "Preemptive command to deleted RTA ignored\n");
1397 if ((PortP
->InUse
== (typeof(PortP
->InUse
))-1) ||
1398 !(CmdBlkP
= RIOGetCmdBlk())) {
1399 rio_dprintk(RIO_DEBUG_CTRL
, "Cannot allocate command block "
1400 "for command %d on port %d\n", Cmd
, PortP
->PortNum
);
1404 rio_dprintk(RIO_DEBUG_CTRL
, "Command blk %p - InUse now %d\n",
1405 CmdBlkP
, PortP
->InUse
);
1407 PktCmdP
= (struct PktCmd_M
*)&CmdBlkP
->Packet
.data
[0];
1409 CmdBlkP
->Packet
.src_unit
= 0;
1410 if (PortP
->SecondBlock
)
1413 rup
= PortP
->RupNum
;
1414 CmdBlkP
->Packet
.dest_unit
= rup
;
1415 CmdBlkP
->Packet
.src_port
= COMMAND_RUP
;
1416 CmdBlkP
->Packet
.dest_port
= COMMAND_RUP
;
1417 CmdBlkP
->Packet
.len
= PKT_CMD_BIT
| 2;
1418 CmdBlkP
->PostFuncP
= RIOUnUse
;
1419 CmdBlkP
->PostArg
= (unsigned long) PortP
;
1420 PktCmdP
->Command
= Cmd
;
1421 port
= PortP
->HostPort
% (ushort
) PORTS_PER_RTA
;
1423 ** Index ports 8-15 for 2nd block of 16 port RTA.
1425 if (PortP
->SecondBlock
)
1426 port
+= (ushort
) PORTS_PER_RTA
;
1427 PktCmdP
->PhbNum
= port
;
1431 rio_dprintk(RIO_DEBUG_CTRL
, "Queue MEMDUMP command blk %p "
1432 "(addr 0x%x)\n", CmdBlkP
, (int) SubCmd
.Addr
);
1433 PktCmdP
->SubCommand
= MEMDUMP
;
1434 PktCmdP
->SubAddr
= SubCmd
.Addr
;
1437 rio_dprintk(RIO_DEBUG_CTRL
, "Queue FCLOSE command blk %p\n",
1441 rio_dprintk(RIO_DEBUG_CTRL
, "Queue READ_REGISTER (0x%x) "
1442 "command blk %p\n", (int) SubCmd
.Addr
, CmdBlkP
);
1443 PktCmdP
->SubCommand
= READ_REGISTER
;
1444 PktCmdP
->SubAddr
= SubCmd
.Addr
;
1447 rio_dprintk(RIO_DEBUG_CTRL
, "Queue RESUME command blk %p\n",
1451 rio_dprintk(RIO_DEBUG_CTRL
, "Queue RFLUSH command blk %p\n",
1453 CmdBlkP
->PostFuncP
= RIORFlushEnable
;
1456 rio_dprintk(RIO_DEBUG_CTRL
, "Queue SUSPEND command blk %p\n",
1461 rio_dprintk(RIO_DEBUG_CTRL
, "Queue MGET command blk %p\n",
1468 CmdBlkP
->Packet
.data
[4] = (char) PortP
->ModemLines
;
1469 rio_dprintk(RIO_DEBUG_CTRL
, "Queue MSET/MBIC/MBIS command "
1470 "blk %p\n", CmdBlkP
);
1475 ** If we have queued up the maximum number of Write flushes
1476 ** allowed then we should not bother sending any more to the
1479 if (PortP
->WflushFlag
== (typeof(PortP
->WflushFlag
))-1) {
1480 rio_dprintk(RIO_DEBUG_CTRL
, "Trashed WFLUSH, "
1481 "WflushFlag about to wrap!");
1482 RIOFreeCmdBlk(CmdBlkP
);
1485 rio_dprintk(RIO_DEBUG_CTRL
, "Queue WFLUSH command "
1486 "blk %p\n", CmdBlkP
);
1487 CmdBlkP
->PostFuncP
= RIOWFlushMark
;
1494 Ret
= RIOQueueCmdBlk(PortP
->HostP
, rup
, CmdBlkP
);