]> err.no Git - linux-2.6/blob - drivers/char/rio/rioctrl.c
[PATCH] forgotten swap of copyout() arguments
[linux-2.6] / drivers / char / rio / rioctrl.c
1 /*
2 ** -----------------------------------------------------------------------------
3 **
4 **  Perle Specialix driver for Linux
5 **  Ported from existing RIO Driver for SCO sources.
6  *
7  *  (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
8  *
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.
13  *
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.
18  *
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.
22 **
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
27 **
28 **  ident @(#)rioctrl.c 1.3
29 **
30 ** -----------------------------------------------------------------------------
31 */
32 #ifdef SCCS_LABELS
33 static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c  1.3";
34 #endif
35
36
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>
45
46 #include <linux/termios.h>
47 #include <linux/serial.h>
48
49 #include <linux/generic_serial.h>
50
51
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"
67
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"
78
79
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;
95
96 static struct SubCmdStruct {
97         ushort Host;
98         ushort Rup;
99         ushort Port;
100         ushort Addr;
101 } SubCmd;
102
103 struct PortTty {
104         uint port;
105         struct ttystatics Tty;
106 };
107
108 static struct PortTty PortTty;
109 typedef struct ttystatics TERMIO;
110
111 /*
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.
118 */
119 static int
120  (*RIOBootTable[MAX_PRODUCT]) (struct rio_info *, struct DownLoad *) = {
121                                         /* 0 */ RIOBootCodeHOST,
122                                         /* Host Card */
123                                         /* 1 */ RIOBootCodeRTA,
124                                         /* RTA */
125 };
126
127 #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
128
129 int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su)
130 {
131         uint Host;              /* leave me unsigned! */
132         uint port;              /* and me! */
133         struct Host *HostP;
134         ushort loop;
135         int Entry;
136         struct Port *PortP;
137         struct PKT __iomem *PacketP;
138         int retval = 0;
139         unsigned long flags;
140         void __user *argp = (void __user *)arg;
141
142         func_enter();
143
144         /* Confuse the compiler to think that we've initialized these */
145         Host = 0;
146         PortP = NULL;
147
148         rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, argp);
149
150         switch (cmd) {
151                 /*
152                  ** RIO_SET_TIMER
153                  **
154                  ** Change the value of the host card interrupt timer.
155                  ** If the host card number is -1 then all host cards are changed
156                  ** otherwise just the specified host card will be changed.
157                  */
158         case RIO_SET_TIMER:
159                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", arg);
160                 {
161                         int host, value;
162                         host = (arg >> 16) & 0x0000FFFF;
163                         value = arg & 0x0000ffff;
164                         if (host == -1) {
165                                 for (host = 0; host < p->RIONumHosts; host++) {
166                                         if (p->RIOHosts[host].Flags == RC_RUNNING) {
167                                                 writew(value, &p->RIOHosts[host].ParmMapP->timer);
168                                         }
169                                 }
170                         } else if (host >= p->RIONumHosts) {
171                                 return -EINVAL;
172                         } else {
173                                 if (p->RIOHosts[host].Flags == RC_RUNNING) {
174                                         writew(value, &p->RIOHosts[host].ParmMapP->timer);
175                                 }
176                         }
177                 }
178                 return 0;
179
180         case RIO_FOAD_RTA:
181                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
182                 return RIOCommandRta(p, arg, RIOFoadRta);
183
184         case RIO_ZOMBIE_RTA:
185                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
186                 return RIOCommandRta(p, arg, RIOZombieRta);
187
188         case RIO_IDENTIFY_RTA:
189                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
190                 return RIOIdentifyRta(p, argp);
191
192         case RIO_KILL_NEIGHBOUR:
193                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
194                 return RIOKillNeighbour(p, argp);
195
196         case SPECIAL_RUP_CMD:
197                 {
198                         struct CmdBlk *CmdBlkP;
199
200                         rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
201                         if (copy_from_user(&SpecialRupCmd, argp, sizeof(SpecialRupCmd))) {
202                                 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
203                                 p->RIOError.Error = COPYIN_FAILED;
204                                 return -EFAULT;
205                         }
206                         CmdBlkP = RIOGetCmdBlk();
207                         if (!CmdBlkP) {
208                                 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
209                                 return -ENXIO;
210                         }
211                         CmdBlkP->Packet = SpecialRupCmd.Packet;
212                         if (SpecialRupCmd.Host >= p->RIONumHosts)
213                                 SpecialRupCmd.Host = 0;
214                         rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
215                         if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
216                                 printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
217                         }
218                         return 0;
219                 }
220
221         case RIO_DEBUG_MEM:
222                 return -EPERM;
223
224         case RIO_ALL_MODEM:
225                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
226                 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
227                 return -EINVAL;
228
229         case RIO_GET_TABLE:
230                 /*
231                  ** Read the routing table from the device driver to user space
232                  */
233                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
234
235                 if ((retval = RIOApel(p)) != 0)
236                         return retval;
237
238                 if (copy_to_user(argp, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
239                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
240                         p->RIOError.Error = COPYOUT_FAILED;
241                         return -EFAULT;
242                 }
243
244                 {
245                         int entry;
246                         rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
247                         for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
248                                 if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
249                                         continue;
250
251                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
252                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
253                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
254                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
255                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
256                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
257                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
258                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
259                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
260                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
261                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
262                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
263                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
264                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
265                                 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
266                         }
267                         rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
268                 }
269                 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
270                 return 0;
271
272         case RIO_PUT_TABLE:
273                 /*
274                  ** Write the routing table to the device driver from user space
275                  */
276                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
277
278                 if (!su) {
279                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
280                         p->RIOError.Error = NOT_SUPER_USER;
281                         return -EPERM;
282                 }
283                 if (copy_from_user(&p->RIOConnectTable[0], argp, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
284                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
285                         p->RIOError.Error = COPYIN_FAILED;
286                         return -EFAULT;
287                 }
288 /*
289 ***********************************
290                                 {
291                                         int entry;
292                                         rio_dprint(RIO_DEBUG_CTRL,  ("*****\nMAP ENTRIES\n") );
293                                         for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
294                                         {
295                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
296                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
297                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
298                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
299                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
300                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
301                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
302                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
303                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
304                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
305                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
306                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
307                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
308                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
309                                                 rio_dprint(RIO_DEBUG_CTRL,  ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
310                                         }
311                                         rio_dprint(RIO_DEBUG_CTRL,  ("*****\nEND MAP ENTRIES\n") );
312                                 }
313 ***********************************
314 */
315                 return RIONewTable(p);
316
317         case RIO_GET_BINDINGS:
318                 /*
319                  ** Send bindings table, containing unique numbers of RTAs owned
320                  ** by this system to user space
321                  */
322                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
323
324                 if (!su) {
325                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
326                         p->RIOError.Error = NOT_SUPER_USER;
327                         return -EPERM;
328                 }
329                 if (copy_to_user(argp, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
330                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
331                         p->RIOError.Error = COPYOUT_FAILED;
332                         return -EFAULT;
333                 }
334                 return 0;
335
336         case RIO_PUT_BINDINGS:
337                 /*
338                  ** Receive a bindings table, containing unique numbers of RTAs owned
339                  ** by this system
340                  */
341                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
342
343                 if (!su) {
344                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
345                         p->RIOError.Error = NOT_SUPER_USER;
346                         return -EPERM;
347                 }
348                 if (copy_from_user(&p->RIOBindTab[0], argp, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
349                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
350                         p->RIOError.Error = COPYIN_FAILED;
351                         return -EFAULT;
352                 }
353                 return 0;
354
355         case RIO_BIND_RTA:
356                 {
357                         int EmptySlot = -1;
358                         /*
359                          ** Bind this RTA to host, so that it will be booted by
360                          ** host in 'boot owned RTAs' mode.
361                          */
362                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
363
364                         if (!su) {
365                                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
366                                 p->RIOError.Error = NOT_SUPER_USER;
367                                 return -EPERM;
368                         }
369                         for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
370                                 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
371                                         EmptySlot = Entry;
372                                 else if (p->RIOBindTab[Entry] == arg) {
373                                         /*
374                                          ** Already exists - delete
375                                          */
376                                         p->RIOBindTab[Entry] = 0L;
377                                         rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", arg);
378                                         return 0;
379                                 }
380                         }
381                         /*
382                          ** Dosen't exist - add
383                          */
384                         if (EmptySlot != -1) {
385                                 p->RIOBindTab[EmptySlot] = arg;
386                                 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", arg);
387                         } else {
388                                 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", arg);
389                                 return -ENOMEM;
390                         }
391                         return 0;
392                 }
393
394         case RIO_RESUME:
395                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
396                 port = arg;
397                 if ((port < 0) || (port > 511)) {
398                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
399                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
400                         return -EINVAL;
401                 }
402                 PortP = p->RIOPortp[port];
403                 if (!PortP->Mapped) {
404                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
405                         p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
406                         return -EINVAL;
407                 }
408                 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
409                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
410                         return -EINVAL;
411                 }
412
413                 rio_spin_lock_irqsave(&PortP->portSem, flags);
414                 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) {
415                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
416                         rio_spin_unlock_irqrestore(&PortP->portSem, flags);
417                         return -EBUSY;
418                 } else {
419                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
420                         PortP->State |= RIO_BUSY;
421                 }
422                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
423                 return retval;
424
425         case RIO_ASSIGN_RTA:
426                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
427                 if (!su) {
428                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
429                         p->RIOError.Error = NOT_SUPER_USER;
430                         return -EPERM;
431                 }
432                 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
433                         rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
434                         p->RIOError.Error = COPYIN_FAILED;
435                         return -EFAULT;
436                 }
437                 return RIOAssignRta(p, &MapEnt);
438
439         case RIO_CHANGE_NAME:
440                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
441                 if (!su) {
442                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
443                         p->RIOError.Error = NOT_SUPER_USER;
444                         return -EPERM;
445                 }
446                 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
447                         rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
448                         p->RIOError.Error = COPYIN_FAILED;
449                         return -EFAULT;
450                 }
451                 return RIOChangeName(p, &MapEnt);
452
453         case RIO_DELETE_RTA:
454                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
455                 if (!su) {
456                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
457                         p->RIOError.Error = NOT_SUPER_USER;
458                         return -EPERM;
459                 }
460                 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
461                         rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
462                         p->RIOError.Error = COPYIN_FAILED;
463                         return -EFAULT;
464                 }
465                 return RIODeleteRta(p, &MapEnt);
466
467         case RIO_QUICK_CHECK:
468                 if (copy_to_user(argp, &p->RIORtaDisCons, sizeof(unsigned int))) {
469                         p->RIOError.Error = COPYOUT_FAILED;
470                         return -EFAULT;
471                 }
472                 return 0;
473
474         case RIO_LAST_ERROR:
475                 if (copy_to_user(argp, &p->RIOError, sizeof(struct Error)))
476                         return -EFAULT;
477                 return 0;
478
479         case RIO_GET_LOG:
480                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
481                 return -EINVAL;
482
483         case RIO_GET_MODTYPE:
484                 if (copy_from_user(&port, argp, sizeof(unsigned int))) {
485                         p->RIOError.Error = COPYIN_FAILED;
486                         return -EFAULT;
487                 }
488                 rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
489                 if (port < 0 || port > 511) {
490                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
491                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
492                         return -EINVAL;
493                 }
494                 PortP = (p->RIOPortp[port]);
495                 if (!PortP->Mapped) {
496                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
497                         p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
498                         return -EINVAL;
499                 }
500                 /*
501                  ** Return module type of port
502                  */
503                 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
504                 if (copy_to_user(argp, &port, sizeof(unsigned int))) {
505                         p->RIOError.Error = COPYOUT_FAILED;
506                         return -EFAULT;
507                 }
508                 return (0);
509         case RIO_BLOCK_OPENS:
510                 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
511                 for (Entry = 0; Entry < RIO_PORTS; Entry++) {
512                         rio_spin_lock_irqsave(&PortP->portSem, flags);
513                         p->RIOPortp[Entry]->WaitUntilBooted = 1;
514                         rio_spin_unlock_irqrestore(&PortP->portSem, flags);
515                 }
516                 return 0;
517
518         case RIO_SETUP_PORTS:
519                 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
520                 if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
521                         p->RIOError.Error = COPYIN_FAILED;
522                         rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
523                         return -EFAULT;
524                 }
525                 if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
526                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
527                         rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
528                         return -ENXIO;
529                 }
530                 if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
531                         p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
532                         rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
533                         return -EINVAL;
534                 }
535                 if (!p->RIOPortp) {
536                         printk(KERN_ERR "rio: No p->RIOPortp array!\n");
537                         rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
538                         return -EIO;
539                 }
540                 rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
541                 for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
542                         rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
543                 }
544                 rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
545                 rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
546                 return retval;
547
548         case RIO_GET_PORT_SETUP:
549                 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
550                 if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
551                         p->RIOError.Error = COPYIN_FAILED;
552                         return -EFAULT;
553                 }
554                 if (PortSetup.From >= RIO_PORTS) {
555                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
556                         return -ENXIO;
557                 }
558
559                 port = PortSetup.To = PortSetup.From;
560                 PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
561                 PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
562                 PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
563                 PortSetup.Store = p->RIOPortp[port]->Store;
564                 PortSetup.Lock = p->RIOPortp[port]->Lock;
565                 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
566                 memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN);
567                 memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN);
568                 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
569                 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
570
571                 if (copy_to_user(argp, &PortSetup, sizeof(PortSetup))) {
572                         p->RIOError.Error = COPYOUT_FAILED;
573                         return -EFAULT;
574                 }
575                 return retval;
576
577         case RIO_GET_PORT_PARAMS:
578                 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
579                 if (copy_from_user(&PortParams, argp, sizeof(struct PortParams))) {
580                         p->RIOError.Error = COPYIN_FAILED;
581                         return -EFAULT;
582                 }
583                 if (PortParams.Port >= RIO_PORTS) {
584                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
585                         return -ENXIO;
586                 }
587                 PortP = (p->RIOPortp[PortParams.Port]);
588                 PortParams.Config = PortP->Config;
589                 PortParams.State = PortP->State;
590                 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
591
592                 if (copy_to_user(argp, &PortParams, sizeof(struct PortParams))) {
593                         p->RIOError.Error = COPYOUT_FAILED;
594                         return -EFAULT;
595                 }
596                 return retval;
597
598         case RIO_GET_PORT_TTY:
599                 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
600                 if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
601                         p->RIOError.Error = COPYIN_FAILED;
602                         return -EFAULT;
603                 }
604                 if (PortTty.port >= RIO_PORTS) {
605                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
606                         return -ENXIO;
607                 }
608
609                 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
610                 PortP = (p->RIOPortp[PortTty.port]);
611                 if (copy_to_user(argp, &PortTty, sizeof(struct PortTty))) {
612                         p->RIOError.Error = COPYOUT_FAILED;
613                         return -EFAULT;
614                 }
615                 return retval;
616
617         case RIO_SET_PORT_TTY:
618                 if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
619                         p->RIOError.Error = COPYIN_FAILED;
620                         return -EFAULT;
621                 }
622                 rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
623                 if (PortTty.port >= (ushort) RIO_PORTS) {
624                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
625                         return -ENXIO;
626                 }
627                 PortP = (p->RIOPortp[PortTty.port]);
628                 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
629                 return retval;
630
631         case RIO_SET_PORT_PARAMS:
632                 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
633                 if (copy_from_user(&PortParams, argp, sizeof(PortParams))) {
634                         p->RIOError.Error = COPYIN_FAILED;
635                         return -EFAULT;
636                 }
637                 if (PortParams.Port >= (ushort) RIO_PORTS) {
638                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
639                         return -ENXIO;
640                 }
641                 PortP = (p->RIOPortp[PortParams.Port]);
642                 rio_spin_lock_irqsave(&PortP->portSem, flags);
643                 PortP->Config = PortParams.Config;
644                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
645                 return retval;
646
647         case RIO_GET_PORT_STATS:
648                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
649                 if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
650                         p->RIOError.Error = COPYIN_FAILED;
651                         return -EFAULT;
652                 }
653                 if (portStats.port >= RIO_PORTS) {
654                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
655                         return -ENXIO;
656                 }
657                 PortP = (p->RIOPortp[portStats.port]);
658                 portStats.gather = PortP->statsGather;
659                 portStats.txchars = PortP->txchars;
660                 portStats.rxchars = PortP->rxchars;
661                 portStats.opens = PortP->opens;
662                 portStats.closes = PortP->closes;
663                 portStats.ioctls = PortP->ioctls;
664                 if (copy_to_user(argp, &portStats, sizeof(struct portStats))) {
665                         p->RIOError.Error = COPYOUT_FAILED;
666                         return -EFAULT;
667                 }
668                 return retval;
669
670         case RIO_RESET_PORT_STATS:
671                 port = arg;
672                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
673                 if (port >= RIO_PORTS) {
674                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
675                         return -ENXIO;
676                 }
677                 PortP = (p->RIOPortp[port]);
678                 rio_spin_lock_irqsave(&PortP->portSem, flags);
679                 PortP->txchars = 0;
680                 PortP->rxchars = 0;
681                 PortP->opens = 0;
682                 PortP->closes = 0;
683                 PortP->ioctls = 0;
684                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
685                 return retval;
686
687         case RIO_GATHER_PORT_STATS:
688                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
689                 if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
690                         p->RIOError.Error = COPYIN_FAILED;
691                         return -EFAULT;
692                 }
693                 if (portStats.port >= RIO_PORTS) {
694                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
695                         return -ENXIO;
696                 }
697                 PortP = (p->RIOPortp[portStats.port]);
698                 rio_spin_lock_irqsave(&PortP->portSem, flags);
699                 PortP->statsGather = portStats.gather;
700                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
701                 return retval;
702
703         case RIO_READ_CONFIG:
704                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
705                 if (copy_to_user(argp, &p->RIOConf, sizeof(struct Conf))) {
706                         p->RIOError.Error = COPYOUT_FAILED;
707                         return -EFAULT;
708                 }
709                 return retval;
710
711         case RIO_SET_CONFIG:
712                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
713                 if (!su) {
714                         p->RIOError.Error = NOT_SUPER_USER;
715                         return -EPERM;
716                 }
717                 if (copy_from_user(&p->RIOConf, argp, sizeof(struct Conf))) {
718                         p->RIOError.Error = COPYIN_FAILED;
719                         return -EFAULT;
720                 }
721                 /*
722                  ** move a few value around
723                  */
724                 for (Host = 0; Host < p->RIONumHosts; Host++)
725                         if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
726                                 writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
727                 return retval;
728
729         case RIO_START_POLLER:
730                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
731                 return -EINVAL;
732
733         case RIO_STOP_POLLER:
734                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
735                 if (!su) {
736                         p->RIOError.Error = NOT_SUPER_USER;
737                         return -EPERM;
738                 }
739                 p->RIOPolling = NOT_POLLING;
740                 return retval;
741
742         case RIO_SETDEBUG:
743         case RIO_GETDEBUG:
744                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
745                 if (copy_from_user(&DebugCtrl, argp, sizeof(DebugCtrl))) {
746                         p->RIOError.Error = COPYIN_FAILED;
747                         return -EFAULT;
748                 }
749                 if (DebugCtrl.SysPort == NO_PORT) {
750                         if (cmd == RIO_SETDEBUG) {
751                                 if (!su) {
752                                         p->RIOError.Error = NOT_SUPER_USER;
753                                         return -EPERM;
754                                 }
755                                 p->rio_debug = DebugCtrl.Debug;
756                                 p->RIODebugWait = DebugCtrl.Wait;
757                                 rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
758                         } else {
759                                 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
760                                 DebugCtrl.Debug = p->rio_debug;
761                                 DebugCtrl.Wait = p->RIODebugWait;
762                                 if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
763                                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
764                                         p->RIOError.Error = COPYOUT_FAILED;
765                                         return -EFAULT;
766                                 }
767                         }
768                 } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
769                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
770                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
771                         return -ENXIO;
772                 } else if (cmd == RIO_SETDEBUG) {
773                         if (!su) {
774                                 p->RIOError.Error = NOT_SUPER_USER;
775                                 return -EPERM;
776                         }
777                         rio_spin_lock_irqsave(&PortP->portSem, flags);
778                         p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
779                         rio_spin_unlock_irqrestore(&PortP->portSem, flags);
780                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
781                 } else {
782                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
783                         DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
784                         if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
785                                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
786                                 p->RIOError.Error = COPYOUT_FAILED;
787                                 return -EFAULT;
788                         }
789                 }
790                 return retval;
791
792         case RIO_VERSID:
793                 /*
794                  ** Enquire about the release and version.
795                  ** We return MAX_VERSION_LEN bytes, being a
796                  ** textual null terminated string.
797                  */
798                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
799                 if (copy_to_user(argp, RIOVersid(), sizeof(struct rioVersion))) {
800                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
801                         p->RIOError.Error = COPYOUT_FAILED;
802                         return -EFAULT;
803                 }
804                 return retval;
805
806         case RIO_NUM_HOSTS:
807                 /*
808                  ** Enquire as to the number of hosts located
809                  ** at init time.
810                  */
811                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
812                 if (copy_to_user(argp, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
813                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
814                         p->RIOError.Error = COPYOUT_FAILED;
815                         return -EFAULT;
816                 }
817                 return retval;
818
819         case RIO_HOST_FOAD:
820                 /*
821                  ** Kill host. This may not be in the final version...
822                  */
823                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", arg);
824                 if (!su) {
825                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
826                         p->RIOError.Error = NOT_SUPER_USER;
827                         return -EPERM;
828                 }
829                 p->RIOHalted = 1;
830                 p->RIOSystemUp = 0;
831
832                 for (Host = 0; Host < p->RIONumHosts; Host++) {
833                         (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
834                         memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
835                         p->RIOHosts[Host].Flags = RC_WAITING;
836                 }
837                 RIOFoadWakeup(p);
838                 p->RIONumBootPkts = 0;
839                 p->RIOBooting = 0;
840                 printk("HEEEEELP!\n");
841
842                 for (loop = 0; loop < RIO_PORTS; loop++) {
843                         spin_lock_init(&p->RIOPortp[loop]->portSem);
844                         p->RIOPortp[loop]->InUse = NOT_INUSE;
845                 }
846
847                 p->RIOSystemUp = 0;
848                 return retval;
849
850         case RIO_DOWNLOAD:
851                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
852                 if (!su) {
853                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
854                         p->RIOError.Error = NOT_SUPER_USER;
855                         return -EPERM;
856                 }
857                 if (copy_from_user(&DownLoad, argp, sizeof(DownLoad))) {
858                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
859                         p->RIOError.Error = COPYIN_FAILED;
860                         return -EFAULT;
861                 }
862                 rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
863
864                 /*
865                  ** It is important that the product code is an unsigned object!
866                  */
867                 if (DownLoad.ProductCode > MAX_PRODUCT) {
868                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
869                         p->RIOError.Error = NO_SUCH_PRODUCT;
870                         return -ENXIO;
871                 }
872                 /*
873                  ** do something!
874                  */
875                 retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
876                 /* <-- Panic */
877                 p->RIOHalted = 0;
878                 /*
879                  ** and go back, content with a job well completed.
880                  */
881                 return retval;
882
883         case RIO_PARMS:
884                 {
885                         unsigned int host;
886
887                         if (copy_from_user(&host, argp, sizeof(host))) {
888                                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
889                                 p->RIOError.Error = COPYIN_FAILED;
890                                 return -EFAULT;
891                         }
892                         /*
893                          ** Fetch the parmmap
894                          */
895                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
896                         if (copy_to_user(argp, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
897                                 p->RIOError.Error = COPYOUT_FAILED;
898                                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
899                                 return -EFAULT;
900                         }
901                 }
902                 return retval;
903
904         case RIO_HOST_REQ:
905                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
906                 if (copy_from_user(&HostReq, argp, sizeof(HostReq))) {
907                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
908                         p->RIOError.Error = COPYIN_FAILED;
909                         return -EFAULT;
910                 }
911                 if (HostReq.HostNum >= p->RIONumHosts) {
912                         p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
913                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
914                         return -ENXIO;
915                 }
916                 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
917
918                 if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
919                         p->RIOError.Error = COPYOUT_FAILED;
920                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
921                         return -EFAULT;
922                 }
923                 return retval;
924
925         case RIO_HOST_DPRAM:
926                 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
927                 if (copy_from_user(&HostDpRam, argp, sizeof(HostDpRam))) {
928                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
929                         p->RIOError.Error = COPYIN_FAILED;
930                         return -EFAULT;
931                 }
932                 if (HostDpRam.HostNum >= p->RIONumHosts) {
933                         p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
934                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
935                         return -ENXIO;
936                 }
937                 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
938
939                 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
940                         int off;
941                         /* It's hardware like this that really gets on my tits. */
942                         static unsigned char copy[sizeof(struct DpRam)];
943                         for (off = 0; off < sizeof(struct DpRam); off++)
944                                 copy[off] = readb(p->RIOHosts[HostDpRam.HostNum].Caddr + off);
945                         if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
946                                 p->RIOError.Error = COPYOUT_FAILED;
947                                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
948                                 return -EFAULT;
949                         }
950                 } else if (copy_to_user(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
951                         p->RIOError.Error = COPYOUT_FAILED;
952                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
953                         return -EFAULT;
954                 }
955                 return retval;
956
957         case RIO_SET_BUSY:
958                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
959                 if (arg > 511) {
960                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", arg);
961                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
962                         return -EINVAL;
963                 }
964                 rio_spin_lock_irqsave(&PortP->portSem, flags);
965                 p->RIOPortp[arg]->State |= RIO_BUSY;
966                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
967                 return retval;
968
969         case RIO_HOST_PORT:
970                 /*
971                  ** The daemon want port information
972                  ** (probably for debug reasons)
973                  */
974                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
975                 if (copy_from_user(&PortReq, argp, sizeof(PortReq))) {
976                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
977                         p->RIOError.Error = COPYIN_FAILED;
978                         return -EFAULT;
979                 }
980
981                 if (PortReq.SysPort >= RIO_PORTS) {     /* SysPort is unsigned */
982                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
983                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
984                         return -ENXIO;
985                 }
986                 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
987                 if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
988                         p->RIOError.Error = COPYOUT_FAILED;
989                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
990                         return -EFAULT;
991                 }
992                 return retval;
993
994         case RIO_HOST_RUP:
995                 /*
996                  ** The daemon want rup information
997                  ** (probably for debug reasons)
998                  */
999                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
1000                 if (copy_from_user(&RupReq, argp, sizeof(RupReq))) {
1001                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1002                         p->RIOError.Error = COPYIN_FAILED;
1003                         return -EFAULT;
1004                 }
1005                 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1006                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
1007                         p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1008                         return -ENXIO;
1009                 }
1010                 if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) {        /* eek! */
1011                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
1012                         p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1013                         return -EINVAL;
1014                 }
1015                 HostP = &p->RIOHosts[RupReq.HostNum];
1016
1017                 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1018                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
1019                         p->RIOError.Error = HOST_NOT_RUNNING;
1020                         return -EIO;
1021                 }
1022                 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
1023
1024                 if (copy_to_user(RupReq.RupP, HostP->UnixRups[RupReq.RupNum].RupP, sizeof(struct RUP))) {
1025                         p->RIOError.Error = COPYOUT_FAILED;
1026                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1027                         return -EFAULT;
1028                 }
1029                 return retval;
1030
1031         case RIO_HOST_LPB:
1032                 /*
1033                  ** The daemon want lpb information
1034                  ** (probably for debug reasons)
1035                  */
1036                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
1037                 if (copy_from_user(&LpbReq, argp, sizeof(LpbReq))) {
1038                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1039                         p->RIOError.Error = COPYIN_FAILED;
1040                         return -EFAULT;
1041                 }
1042                 if (LpbReq.Host >= p->RIONumHosts) {    /* host is unsigned */
1043                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
1044                         p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1045                         return -ENXIO;
1046                 }
1047                 if (LpbReq.Link >= LINKS_PER_UNIT) {    /* eek! */
1048                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
1049                         p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1050                         return -EINVAL;
1051                 }
1052                 HostP = &p->RIOHosts[LpbReq.Host];
1053
1054                 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1055                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
1056                         p->RIOError.Error = HOST_NOT_RUNNING;
1057                         return -EIO;
1058                 }
1059                 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
1060
1061                 if (copy_to_user(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
1062                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1063                         p->RIOError.Error = COPYOUT_FAILED;
1064                         return -EFAULT;
1065                 }
1066                 return retval;
1067
1068                 /*
1069                  ** Here 3 IOCTL's that allow us to change the way in which
1070                  ** rio logs errors. send them just to syslog or send them
1071                  ** to both syslog and console or send them to just the console.
1072                  **
1073                  ** See RioStrBuf() in util.c for the other half.
1074                  */
1075         case RIO_SYSLOG_ONLY:
1076                 p->RIOPrintLogState = PRINT_TO_LOG;     /* Just syslog */
1077                 return 0;
1078
1079         case RIO_SYSLOG_CONS:
1080                 p->RIOPrintLogState = PRINT_TO_LOG_CONS;        /* syslog and console */
1081                 return 0;
1082
1083         case RIO_CONS_ONLY:
1084                 p->RIOPrintLogState = PRINT_TO_CONS;    /* Just console */
1085                 return 0;
1086
1087         case RIO_SIGNALS_ON:
1088                 if (p->RIOSignalProcess) {
1089                         p->RIOError.Error = SIGNALS_ALREADY_SET;
1090                         return -EBUSY;
1091                 }
1092                 /* FIXME: PID tracking */
1093                 p->RIOSignalProcess = current->pid;
1094                 p->RIOPrintDisabled = DONT_PRINT;
1095                 return retval;
1096
1097         case RIO_SIGNALS_OFF:
1098                 if (p->RIOSignalProcess != current->pid) {
1099                         p->RIOError.Error = NOT_RECEIVING_PROCESS;
1100                         return -EPERM;
1101                 }
1102                 rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
1103                 p->RIOSignalProcess = 0;
1104                 return retval;
1105
1106         case RIO_SET_BYTE_MODE:
1107                 for (Host = 0; Host < p->RIONumHosts; Host++)
1108                         if (p->RIOHosts[Host].Type == RIO_AT)
1109                                 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1110                 return retval;
1111
1112         case RIO_SET_WORD_MODE:
1113                 for (Host = 0; Host < p->RIONumHosts; Host++)
1114                         if (p->RIOHosts[Host].Type == RIO_AT)
1115                                 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1116                 return retval;
1117
1118         case RIO_SET_FAST_BUS:
1119                 for (Host = 0; Host < p->RIONumHosts; Host++)
1120                         if (p->RIOHosts[Host].Type == RIO_AT)
1121                                 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1122                 return retval;
1123
1124         case RIO_SET_SLOW_BUS:
1125                 for (Host = 0; Host < p->RIONumHosts; Host++)
1126                         if (p->RIOHosts[Host].Type == RIO_AT)
1127                                 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1128                 return retval;
1129
1130         case RIO_MAP_B50_TO_50:
1131         case RIO_MAP_B50_TO_57600:
1132         case RIO_MAP_B110_TO_110:
1133         case RIO_MAP_B110_TO_115200:
1134                 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
1135                 port = arg;
1136                 if (port < 0 || port > 511) {
1137                         rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1138                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1139                         return -EINVAL;
1140                 }
1141                 rio_spin_lock_irqsave(&PortP->portSem, flags);
1142                 switch (cmd) {
1143                 case RIO_MAP_B50_TO_50:
1144                         p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1145                         break;
1146                 case RIO_MAP_B50_TO_57600:
1147                         p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1148                         break;
1149                 case RIO_MAP_B110_TO_110:
1150                         p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1151                         break;
1152                 case RIO_MAP_B110_TO_115200:
1153                         p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1154                         break;
1155                 }
1156                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1157                 return retval;
1158
1159         case RIO_STREAM_INFO:
1160                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
1161                 return -EINVAL;
1162
1163         case RIO_SEND_PACKET:
1164                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
1165                 if (copy_from_user(&SendPack, argp, sizeof(SendPack))) {
1166                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1167                         p->RIOError.Error = COPYIN_FAILED;
1168                         return -EFAULT;
1169                 }
1170                 if (SendPack.PortNum >= 128) {
1171                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1172                         return -ENXIO;
1173                 }
1174
1175                 PortP = p->RIOPortp[SendPack.PortNum];
1176                 rio_spin_lock_irqsave(&PortP->portSem, flags);
1177
1178                 if (!can_add_transmit(&PacketP, PortP)) {
1179                         p->RIOError.Error = UNIT_IS_IN_USE;
1180                         rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1181                         return -ENOSPC;
1182                 }
1183
1184                 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
1185                         writeb(SendPack.Data[loop], &PacketP->data[loop]);
1186
1187                 writeb(SendPack.Len, &PacketP->len);
1188
1189                 add_transmit(PortP);
1190                 /*
1191                  ** Count characters transmitted for port statistics reporting
1192                  */
1193                 if (PortP->statsGather)
1194                         PortP->txchars += (SendPack.Len & 127);
1195                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1196                 return retval;
1197
1198         case RIO_NO_MESG:
1199                 if (su)
1200                         p->RIONoMessage = 1;
1201                 return su ? 0 : -EPERM;
1202
1203         case RIO_MESG:
1204                 if (su)
1205                         p->RIONoMessage = 0;
1206                 return su ? 0 : -EPERM;
1207
1208         case RIO_WHAT_MESG:
1209                 if (copy_to_user(argp, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
1210                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1211                         p->RIOError.Error = COPYOUT_FAILED;
1212                         return -EFAULT;
1213                 }
1214                 return 0;
1215
1216         case RIO_MEM_DUMP:
1217                 if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
1218                         p->RIOError.Error = COPYIN_FAILED;
1219                         return -EFAULT;
1220                 }
1221                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
1222
1223                 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1224                         p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1225                         return -EINVAL;
1226                 }
1227
1228                 if (SubCmd.Host >= p->RIONumHosts) {
1229                         p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1230                         return -EINVAL;
1231                 }
1232
1233                 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
1234
1235                 PortP = p->RIOPortp[port];
1236
1237                 rio_spin_lock_irqsave(&PortP->portSem, flags);
1238
1239                 if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) {
1240                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1241                         rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1242                         return -EBUSY;
1243                 } else
1244                         PortP->State |= RIO_BUSY;
1245
1246                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1247                 if (copy_to_user(argp, p->RIOMemDump, MEMDUMP_SIZE)) {
1248                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1249                         p->RIOError.Error = COPYOUT_FAILED;
1250                         return -EFAULT;
1251                 }
1252                 return 0;
1253
1254         case RIO_TICK:
1255                 if (arg >= p->RIONumHosts)
1256                         return -EINVAL;
1257                 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", arg);
1258                 writeb(0xFF, &p->RIOHosts[arg].SetInt);
1259                 return 0;
1260
1261         case RIO_TOCK:
1262                 if (arg >= p->RIONumHosts)
1263                         return -EINVAL;
1264                 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", arg);
1265                 writeb(0xFF, &p->RIOHosts[arg].ResetInt);
1266                 return 0;
1267
1268         case RIO_READ_CHECK:
1269                 /* Check reads for pkts with data[0] the same */
1270                 p->RIOReadCheck = !p->RIOReadCheck;
1271                 if (copy_to_user(argp, &p->RIOReadCheck, sizeof(unsigned int))) {
1272                         p->RIOError.Error = COPYOUT_FAILED;
1273                         return -EFAULT;
1274                 }
1275                 return 0;
1276
1277         case RIO_READ_REGISTER:
1278                 if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
1279                         p->RIOError.Error = COPYIN_FAILED;
1280                         return -EFAULT;
1281                 }
1282                 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER host %d rup %d port %d reg %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Port, SubCmd.Addr);
1283
1284                 if (SubCmd.Port > 511) {
1285                         rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
1286                         p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1287                         return -EINVAL;
1288                 }
1289
1290                 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1291                         p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1292                         return -EINVAL;
1293                 }
1294
1295                 if (SubCmd.Host >= p->RIONumHosts) {
1296                         p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1297                         return -EINVAL;
1298                 }
1299
1300                 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1301                 PortP = p->RIOPortp[port];
1302
1303                 rio_spin_lock_irqsave(&PortP->portSem, flags);
1304
1305                 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
1306                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1307                         rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1308                         return -EBUSY;
1309                 } else
1310                         PortP->State |= RIO_BUSY;
1311
1312                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1313                 if (copy_to_user(argp, &p->CdRegister, sizeof(unsigned int))) {
1314                         rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1315                         p->RIOError.Error = COPYOUT_FAILED;
1316                         return -EFAULT;
1317                 }
1318                 return 0;
1319                 /*
1320                  ** rio_make_dev: given port number (0-511) ORed with port type
1321                  ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1322                  ** value to pass to mknod to create the correct device node.
1323                  */
1324         case RIO_MAKE_DEV:
1325                 {
1326                         unsigned int port = arg & RIO_MODEM_MASK;
1327                         unsigned int ret;
1328
1329                         switch (arg & RIO_DEV_MASK) {
1330                         case RIO_DEV_DIRECT:
1331                                 ret = drv_makedev(MAJOR(dev), port);
1332                                 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
1333                                 return ret;
1334                         case RIO_DEV_MODEM:
1335                                 ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1336                                 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
1337                                 return ret;
1338                         case RIO_DEV_XPRINT:
1339                                 ret = drv_makedev(MAJOR(dev), port);
1340                                 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
1341                                 return ret;
1342                         }
1343                         rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1344                         return -EINVAL;
1345                 }
1346                 /*
1347                  ** rio_minor: given a dev_t from a stat() call, return
1348                  ** the port number (0-511) ORed with the port type
1349                  ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1350                  */
1351         case RIO_MINOR:
1352                 {
1353                         dev_t dv;
1354                         int mino;
1355                         unsigned long ret;
1356
1357                         dv = (dev_t) (arg);
1358                         mino = RIO_UNMODEM(dv);
1359
1360                         if (RIO_ISMODEM(dv)) {
1361                                 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
1362                                 ret = mino | RIO_DEV_MODEM;
1363                         } else {
1364                                 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
1365                                 ret = mino | RIO_DEV_DIRECT;
1366                         }
1367                         return ret;
1368                 }
1369         }
1370         rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
1371         p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1372
1373         func_exit();
1374         return -EINVAL;
1375 }
1376
1377 /*
1378 ** Pre-emptive commands go on RUPs and are only one byte long.
1379 */
1380 int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
1381 {
1382         struct CmdBlk *CmdBlkP;
1383         struct PktCmd_M *PktCmdP;
1384         int Ret;
1385         ushort rup;
1386         int port;
1387
1388         if (PortP->State & RIO_DELETED) {
1389                 rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
1390                 return RIO_FAIL;
1391         }
1392
1393         if ((PortP->InUse == (typeof(PortP->InUse))-1) ||
1394                         !(CmdBlkP = RIOGetCmdBlk())) {
1395                 rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block "
1396                         "for command %d on port %d\n", Cmd, PortP->PortNum);
1397                 return RIO_FAIL;
1398         }
1399
1400         rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n",
1401                         CmdBlkP, PortP->InUse);
1402
1403         PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
1404
1405         CmdBlkP->Packet.src_unit = 0;
1406         if (PortP->SecondBlock)
1407                 rup = PortP->ID2;
1408         else
1409                 rup = PortP->RupNum;
1410         CmdBlkP->Packet.dest_unit = rup;
1411         CmdBlkP->Packet.src_port = COMMAND_RUP;
1412         CmdBlkP->Packet.dest_port = COMMAND_RUP;
1413         CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1414         CmdBlkP->PostFuncP = RIOUnUse;
1415         CmdBlkP->PostArg = (unsigned long) PortP;
1416         PktCmdP->Command = Cmd;
1417         port = PortP->HostPort % (ushort) PORTS_PER_RTA;
1418         /*
1419          ** Index ports 8-15 for 2nd block of 16 port RTA.
1420          */
1421         if (PortP->SecondBlock)
1422                 port += (ushort) PORTS_PER_RTA;
1423         PktCmdP->PhbNum = port;
1424
1425         switch (Cmd) {
1426         case MEMDUMP:
1427                 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p "
1428                                 "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
1429                 PktCmdP->SubCommand = MEMDUMP;
1430                 PktCmdP->SubAddr = SubCmd.Addr;
1431                 break;
1432         case FCLOSE:
1433                 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n",
1434                                 CmdBlkP);
1435                 break;
1436         case READ_REGISTER:
1437                 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) "
1438                                 "command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
1439                 PktCmdP->SubCommand = READ_REGISTER;
1440                 PktCmdP->SubAddr = SubCmd.Addr;
1441                 break;
1442         case RESUME:
1443                 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n",
1444                                 CmdBlkP);
1445                 break;
1446         case RFLUSH:
1447                 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n",
1448                                 CmdBlkP);
1449                 CmdBlkP->PostFuncP = RIORFlushEnable;
1450                 break;
1451         case SUSPEND:
1452                 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n",
1453                                 CmdBlkP);
1454                 break;
1455
1456         case MGET:
1457                 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n",
1458                                 CmdBlkP);
1459                 break;
1460
1461         case MSET:
1462         case MBIC:
1463         case MBIS:
1464                 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
1465                 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command "
1466                                 "blk %p\n", CmdBlkP);
1467                 break;
1468
1469         case WFLUSH:
1470                 /*
1471                  ** If we have queued up the maximum number of Write flushes
1472                  ** allowed then we should not bother sending any more to the
1473                  ** RTA.
1474                  */
1475                 if (PortP->WflushFlag == (typeof(PortP->WflushFlag))-1) {
1476                         rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, "
1477                                         "WflushFlag about to wrap!");
1478                         RIOFreeCmdBlk(CmdBlkP);
1479                         return (RIO_FAIL);
1480                 } else {
1481                         rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command "
1482                                         "blk %p\n", CmdBlkP);
1483                         CmdBlkP->PostFuncP = RIOWFlushMark;
1484                 }
1485                 break;
1486         }
1487
1488         PortP->InUse++;
1489
1490         Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);
1491
1492         return Ret;
1493 }