blob: f6a19aae1044ed712f6dd86b8dc92d3cfe361d9a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
33static 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 "typdef.h"
55#include "pkt.h"
56#include "daemon.h"
57#include "rio.h"
58#include "riospace.h"
59#include "top.h"
60#include "cmdpkt.h"
61#include "map.h"
62#include "riotypes.h"
63#include "rup.h"
64#include "port.h"
65#include "riodrvr.h"
66#include "rioinfo.h"
67#include "func.h"
68#include "errors.h"
69#include "pci.h"
70
71#include "parmmap.h"
72#include "unixrup.h"
73#include "board.h"
74#include "host.h"
75#include "error.h"
76#include "phb.h"
77#include "link.h"
78#include "cmdblk.h"
79#include "route.h"
80#include "control.h"
81#include "cirrus.h"
82#include "rioioctl.h"
83
84
Andrew Morton8d8706e2006-01-11 12:17:49 -080085static struct LpbReq LpbReq;
86static struct RupReq RupReq;
87static struct PortReq PortReq;
88static struct HostReq HostReq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static struct HostDpRam HostDpRam;
90static struct DebugCtrl DebugCtrl;
Andrew Morton8d8706e2006-01-11 12:17:49 -080091static struct Map MapEnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092static struct PortSetup PortSetup;
Andrew Morton8d8706e2006-01-11 12:17:49 -080093static struct DownLoad DownLoad;
94static struct SendPack SendPack;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095/* static struct StreamInfo StreamInfo; */
96/* static char modemtable[RIO_PORTS]; */
97static struct SpecialRupCmd SpecialRupCmd;
98static struct PortParams PortParams;
99static struct portStats portStats;
100
101static struct SubCmdStruct {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800102 ushort Host;
103 ushort Rup;
104 ushort Port;
105 ushort Addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106} SubCmd;
107
108struct PortTty {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800109 uint port;
110 struct ttystatics Tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
Andrew Morton8d8706e2006-01-11 12:17:49 -0800113static struct PortTty PortTty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114typedef struct ttystatics TERMIO;
115
116/*
117** This table is used when the config.rio downloads bin code to the
118** driver. We index the table using the product code, 0-F, and call
119** the function pointed to by the entry, passing the information
120** about the boot.
121** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
122** process to bog off.
123*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800124static int
125 (*RIOBootTable[MAX_PRODUCT]) (struct rio_info *, struct DownLoad *) = {
126 /* 0 */ RIOBootCodeHOST,
127 /* Host Card */
128 /* 1 */ RIOBootCodeRTA,
129 /* RTA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130};
131
132#define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
133
Andrew Morton8d8706e2006-01-11 12:17:49 -0800134int riocontrol(p, dev, cmd, arg, su)
135struct rio_info *p;
136dev_t dev;
137int cmd;
138caddr_t arg;
139int su;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800141 uint Host; /* leave me unsigned! */
142 uint port; /* and me! */
143 struct Host *HostP;
144 ushort loop;
145 int Entry;
146 struct Port *PortP;
147 PKT *PacketP;
148 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 unsigned long flags;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800150
151 func_enter();
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 /* Confuse the compiler to think that we've initialized these */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800154 Host = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 PortP = NULL;
156
Alan Cox3d336aa2006-03-24 03:18:29 -0800157 rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: 0x%p\n", cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 switch (cmd) {
160 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800161 ** RIO_SET_TIMER
162 **
163 ** Change the value of the host card interrupt timer.
164 ** If the host card number is -1 then all host cards are changed
165 ** otherwise just the specified host card will be changed.
166 */
167 case RIO_SET_TIMER:
Alan Cox3d336aa2006-03-24 03:18:29 -0800168 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", (unsigned long)arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800169 {
170 int host, value;
Alan Cox3d336aa2006-03-24 03:18:29 -0800171 host = ((unsigned long) arg >> 16) & 0x0000FFFF;
172 value = (unsigned long) arg & 0x0000ffff;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800173 if (host == -1) {
174 for (host = 0; host < p->RIONumHosts; host++) {
175 if (p->RIOHosts[host].Flags == RC_RUNNING) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800176 writew(value, &p->RIOHosts[host].ParmMapP->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800179 } else if (host >= p->RIONumHosts) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 return -EINVAL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800181 } else {
182 if (p->RIOHosts[host].Flags == RC_RUNNING) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800183 writew(value, &p->RIOHosts[host].ParmMapP->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800185 }
186 }
187 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Andrew Morton8d8706e2006-01-11 12:17:49 -0800189 case RIO_FOAD_RTA:
190 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800191 return RIOCommandRta(p, (unsigned long)arg, RIOFoadRta);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800192
193 case RIO_ZOMBIE_RTA:
194 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800195 return RIOCommandRta(p, (unsigned long)arg, RIOZombieRta);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800196
197 case RIO_IDENTIFY_RTA:
198 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
199 return RIOIdentifyRta(p, arg);
200
201 case RIO_KILL_NEIGHBOUR:
202 rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
203 return RIOKillNeighbour(p, arg);
204
205 case SPECIAL_RUP_CMD:
206 {
207 struct CmdBlk *CmdBlkP;
208
209 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800210 if (copy_from_user(&SpecialRupCmd, arg, sizeof(SpecialRupCmd))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800211 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
212 p->RIOError.Error = COPYIN_FAILED;
213 return -EFAULT;
214 }
215 CmdBlkP = RIOGetCmdBlk();
216 if (!CmdBlkP) {
217 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
218 return -ENXIO;
219 }
220 CmdBlkP->Packet = SpecialRupCmd.Packet;
221 if (SpecialRupCmd.Host >= p->RIONumHosts)
222 SpecialRupCmd.Host = 0;
223 rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
224 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800225 printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800226 }
227 return 0;
228 }
229
230 case RIO_DEBUG_MEM:
Alan Coxf4caf162006-01-16 17:27:38 +0000231 return -EPERM;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800232
233 case RIO_ALL_MODEM:
234 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
235 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
236 return -EINVAL;
237
238 case RIO_GET_TABLE:
239 /*
240 ** Read the routing table from the device driver to user space
241 */
242 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
243
244 if ((retval = RIOApel(p)) != 0)
245 return retval;
246
Alan Cox3d336aa2006-03-24 03:18:29 -0800247 if (copy_to_user(arg, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800248 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
249 p->RIOError.Error = COPYOUT_FAILED;
250 return -EFAULT;
251 }
252
253 {
254 int entry;
255 rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
256 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
257 if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
258 continue;
259
260 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
261 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
262 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
263 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
264 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
265 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
266 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
267 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
268 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
269 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
270 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
271 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
272 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
273 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
274 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
275 }
276 rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
277 }
278 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
279 return 0;
280
281 case RIO_PUT_TABLE:
282 /*
283 ** Write the routing table to the device driver from user space
284 */
285 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
286
287 if (!su) {
288 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
289 p->RIOError.Error = NOT_SUPER_USER;
290 return -EPERM;
291 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800292 if (copy_from_user(&p->RIOConnectTable[0], arg, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800293 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
294 p->RIOError.Error = COPYIN_FAILED;
295 return -EFAULT;
296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297/*
298***********************************
299 {
300 int entry;
301 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
302 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
303 {
304 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
305 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
306 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
307 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
308 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
309 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
310 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
311 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
312 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
313 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
314 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
315 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
316 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
317 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
318 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
319 }
320 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
321 }
322***********************************
323*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800324 return RIONewTable(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Andrew Morton8d8706e2006-01-11 12:17:49 -0800326 case RIO_GET_BINDINGS:
327 /*
328 ** Send bindings table, containing unique numbers of RTAs owned
329 ** by this system to user space
330 */
331 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Andrew Morton8d8706e2006-01-11 12:17:49 -0800333 if (!su) {
334 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
335 p->RIOError.Error = NOT_SUPER_USER;
336 return -EPERM;
337 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800338 if (copy_to_user(arg, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800339 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
340 p->RIOError.Error = COPYOUT_FAILED;
341 return -EFAULT;
342 }
343 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Andrew Morton8d8706e2006-01-11 12:17:49 -0800345 case RIO_PUT_BINDINGS:
346 /*
347 ** Receive a bindings table, containing unique numbers of RTAs owned
348 ** by this system
349 */
350 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
351
352 if (!su) {
353 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
354 p->RIOError.Error = NOT_SUPER_USER;
355 return -EPERM;
356 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800357 if (copy_from_user(&p->RIOBindTab[0], arg, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800358 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
359 p->RIOError.Error = COPYIN_FAILED;
360 return -EFAULT;
361 }
362 return 0;
363
364 case RIO_BIND_RTA:
365 {
366 int EmptySlot = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800368 ** Bind this RTA to host, so that it will be booted by
369 ** host in 'boot owned RTAs' mode.
370 */
371 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Andrew Morton8d8706e2006-01-11 12:17:49 -0800373 if (!su) {
374 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
375 p->RIOError.Error = NOT_SUPER_USER;
376 return -EPERM;
377 }
378 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
379 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
380 EmptySlot = Entry;
Alan Cox3d336aa2006-03-24 03:18:29 -0800381 else if (p->RIOBindTab[Entry] == (long)arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800383 ** Already exists - delete
384 */
385 p->RIOBindTab[Entry] = 0L;
Alan Cox3d336aa2006-03-24 03:18:29 -0800386 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", (unsigned long)arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 return 0;
388 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800389 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800391 ** Dosen't exist - add
392 */
393 if (EmptySlot != -1) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800394 p->RIOBindTab[EmptySlot] = (unsigned long)arg;
395 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", (unsigned long) arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800396 } else {
Alan Cox3d336aa2006-03-24 03:18:29 -0800397 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", (unsigned long) arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800398 return -ENOMEM;
399 }
400 return 0;
401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Andrew Morton8d8706e2006-01-11 12:17:49 -0800403 case RIO_RESUME:
404 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800405 port = (unsigned long) arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800406 if ((port < 0) || (port > 511)) {
407 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
408 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
409 return -EINVAL;
410 }
411 PortP = p->RIOPortp[port];
412 if (!PortP->Mapped) {
413 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
414 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
415 return -EINVAL;
416 }
417 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
418 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
419 return -EINVAL;
420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Andrew Morton8d8706e2006-01-11 12:17:49 -0800422 rio_spin_lock_irqsave(&PortP->portSem, flags);
423 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) {
424 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
425 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
426 return -EBUSY;
427 } else {
428 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
429 PortP->State |= RIO_BUSY;
430 }
431 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
432 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Andrew Morton8d8706e2006-01-11 12:17:49 -0800434 case RIO_ASSIGN_RTA:
435 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
436 if (!su) {
437 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
438 p->RIOError.Error = NOT_SUPER_USER;
439 return -EPERM;
440 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800441 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800442 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
443 p->RIOError.Error = COPYIN_FAILED;
444 return -EFAULT;
445 }
446 return RIOAssignRta(p, &MapEnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Andrew Morton8d8706e2006-01-11 12:17:49 -0800448 case RIO_CHANGE_NAME:
449 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
450 if (!su) {
451 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
452 p->RIOError.Error = NOT_SUPER_USER;
453 return -EPERM;
454 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800455 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800456 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
457 p->RIOError.Error = COPYIN_FAILED;
458 return -EFAULT;
459 }
460 return RIOChangeName(p, &MapEnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Andrew Morton8d8706e2006-01-11 12:17:49 -0800462 case RIO_DELETE_RTA:
463 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
464 if (!su) {
465 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
466 p->RIOError.Error = NOT_SUPER_USER;
467 return -EPERM;
468 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800469 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800470 rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
471 p->RIOError.Error = COPYIN_FAILED;
472 return -EFAULT;
473 }
474 return RIODeleteRta(p, &MapEnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Andrew Morton8d8706e2006-01-11 12:17:49 -0800476 case RIO_QUICK_CHECK:
Alan Cox3d336aa2006-03-24 03:18:29 -0800477 if (copy_to_user(arg, &p->RIORtaDisCons, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800478 p->RIOError.Error = COPYOUT_FAILED;
479 return -EFAULT;
480 }
481 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Andrew Morton8d8706e2006-01-11 12:17:49 -0800483 case RIO_LAST_ERROR:
Alan Cox3d336aa2006-03-24 03:18:29 -0800484 if (copy_to_user(arg, &p->RIOError, sizeof(struct Error)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800485 return -EFAULT;
486 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Andrew Morton8d8706e2006-01-11 12:17:49 -0800488 case RIO_GET_LOG:
489 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800490 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Andrew Morton8d8706e2006-01-11 12:17:49 -0800492 case RIO_GET_MODTYPE:
Alan Cox3d336aa2006-03-24 03:18:29 -0800493 if (copy_from_user(&port, arg, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800494 p->RIOError.Error = COPYIN_FAILED;
495 return -EFAULT;
496 }
497 rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
498 if (port < 0 || port > 511) {
499 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
500 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
501 return -EINVAL;
502 }
503 PortP = (p->RIOPortp[port]);
504 if (!PortP->Mapped) {
505 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
506 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
507 return -EINVAL;
508 }
509 /*
510 ** Return module type of port
511 */
512 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
Alan Cox3d336aa2006-03-24 03:18:29 -0800513 if (copy_to_user(arg, &port, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800514 p->RIOError.Error = COPYOUT_FAILED;
515 return -EFAULT;
516 }
517 return (0);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800518 case RIO_BLOCK_OPENS:
519 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
520 for (Entry = 0; Entry < RIO_PORTS; Entry++) {
521 rio_spin_lock_irqsave(&PortP->portSem, flags);
522 p->RIOPortp[Entry]->WaitUntilBooted = 1;
523 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
524 }
525 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Andrew Morton8d8706e2006-01-11 12:17:49 -0800527 case RIO_SETUP_PORTS:
528 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800529 if (copy_from_user(&PortSetup, arg, sizeof(PortSetup))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800530 p->RIOError.Error = COPYIN_FAILED;
531 rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
532 return -EFAULT;
533 }
534 if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
535 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
536 rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
537 return -ENXIO;
538 }
539 if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
540 p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
541 rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
542 return -EINVAL;
543 }
544 if (!p->RIOPortp) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800545 printk(KERN_ERR "rio: No p->RIOPortp array!\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800546 rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
547 return -EIO;
548 }
549 rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
550 for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
551 rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800552 }
553 rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
554 rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
555 return retval;
556
557 case RIO_GET_PORT_SETUP:
558 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800559 if (copy_from_user(&PortSetup, arg, sizeof(PortSetup))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800560 p->RIOError.Error = COPYIN_FAILED;
561 return -EFAULT;
562 }
563 if (PortSetup.From >= RIO_PORTS) {
564 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
565 return -ENXIO;
566 }
567
568 port = PortSetup.To = PortSetup.From;
569 PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
570 PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
571 PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
572 PortSetup.Store = p->RIOPortp[port]->Store;
573 PortSetup.Lock = p->RIOPortp[port]->Lock;
574 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
575 bcopy(p->RIOPortp[port]->Xprint.XpOn, PortSetup.XpOn, MAX_XP_CTRL_LEN);
576 bcopy(p->RIOPortp[port]->Xprint.XpOff, PortSetup.XpOff, MAX_XP_CTRL_LEN);
577 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
578 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
579
Alan Cox3d336aa2006-03-24 03:18:29 -0800580 if (copy_to_user(arg, &PortSetup, sizeof(PortSetup))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800581 p->RIOError.Error = COPYOUT_FAILED;
582 return -EFAULT;
583 }
584 return retval;
585
586 case RIO_GET_PORT_PARAMS:
587 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800588 if (copy_from_user(&PortParams, arg, sizeof(struct PortParams))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800589 p->RIOError.Error = COPYIN_FAILED;
590 return -EFAULT;
591 }
592 if (PortParams.Port >= RIO_PORTS) {
593 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
594 return -ENXIO;
595 }
596 PortP = (p->RIOPortp[PortParams.Port]);
597 PortParams.Config = PortP->Config;
598 PortParams.State = PortP->State;
599 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
600
Alan Cox3d336aa2006-03-24 03:18:29 -0800601 if (copy_to_user(arg, &PortParams, sizeof(struct PortParams))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800602 p->RIOError.Error = COPYOUT_FAILED;
603 return -EFAULT;
604 }
605 return retval;
606
607 case RIO_GET_PORT_TTY:
608 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800609 if (copy_from_user(&PortTty, arg, sizeof(struct PortTty))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800610 p->RIOError.Error = COPYIN_FAILED;
611 return -EFAULT;
612 }
613 if (PortTty.port >= RIO_PORTS) {
614 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
615 return -ENXIO;
616 }
617
618 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
619 PortP = (p->RIOPortp[PortTty.port]);
Alan Cox3d336aa2006-03-24 03:18:29 -0800620 if (copy_to_user(arg, &PortTty, sizeof(struct PortTty))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800621 p->RIOError.Error = COPYOUT_FAILED;
622 return -EFAULT;
623 }
624 return retval;
625
626 case RIO_SET_PORT_TTY:
Alan Cox3d336aa2006-03-24 03:18:29 -0800627 if (copy_from_user(&PortTty, arg, sizeof(struct PortTty))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800628 p->RIOError.Error = COPYIN_FAILED;
629 return -EFAULT;
630 }
631 rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
632 if (PortTty.port >= (ushort) RIO_PORTS) {
633 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
634 return -ENXIO;
635 }
636 PortP = (p->RIOPortp[PortTty.port]);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800637 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
638 return retval;
639
640 case RIO_SET_PORT_PARAMS:
641 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800642 if (copy_from_user(&PortParams, arg, sizeof(PortParams))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800643 p->RIOError.Error = COPYIN_FAILED;
644 return -EFAULT;
645 }
646 if (PortParams.Port >= (ushort) RIO_PORTS) {
647 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
648 return -ENXIO;
649 }
650 PortP = (p->RIOPortp[PortParams.Port]);
651 rio_spin_lock_irqsave(&PortP->portSem, flags);
652 PortP->Config = PortParams.Config;
653 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
654 return retval;
655
656 case RIO_GET_PORT_STATS:
657 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800658 if (copy_from_user(&portStats, arg, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800659 p->RIOError.Error = COPYIN_FAILED;
660 return -EFAULT;
661 }
662 if (portStats.port >= RIO_PORTS) {
663 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
664 return -ENXIO;
665 }
666 PortP = (p->RIOPortp[portStats.port]);
667 portStats.gather = PortP->statsGather;
668 portStats.txchars = PortP->txchars;
669 portStats.rxchars = PortP->rxchars;
670 portStats.opens = PortP->opens;
671 portStats.closes = PortP->closes;
672 portStats.ioctls = PortP->ioctls;
Alan Cox3d336aa2006-03-24 03:18:29 -0800673 if (copy_to_user(arg, &portStats, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800674 p->RIOError.Error = COPYOUT_FAILED;
675 return -EFAULT;
676 }
677 return retval;
678
679 case RIO_RESET_PORT_STATS:
Alan Cox3d336aa2006-03-24 03:18:29 -0800680 port = (unsigned long) arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800681 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
682 if (port >= RIO_PORTS) {
683 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
684 return -ENXIO;
685 }
686 PortP = (p->RIOPortp[port]);
687 rio_spin_lock_irqsave(&PortP->portSem, flags);
688 PortP->txchars = 0;
689 PortP->rxchars = 0;
690 PortP->opens = 0;
691 PortP->closes = 0;
692 PortP->ioctls = 0;
693 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
694 return retval;
695
696 case RIO_GATHER_PORT_STATS:
697 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800698 if (copy_from_user(&portStats, arg, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800699 p->RIOError.Error = COPYIN_FAILED;
700 return -EFAULT;
701 }
702 if (portStats.port >= RIO_PORTS) {
703 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
704 return -ENXIO;
705 }
706 PortP = (p->RIOPortp[portStats.port]);
707 rio_spin_lock_irqsave(&PortP->portSem, flags);
708 PortP->statsGather = portStats.gather;
709 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
710 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Andrew Morton8d8706e2006-01-11 12:17:49 -0800712 case RIO_READ_CONFIG:
713 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800714 if (copy_to_user(arg, &p->RIOConf, sizeof(struct Conf))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800715 p->RIOError.Error = COPYOUT_FAILED;
716 return -EFAULT;
717 }
718 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Andrew Morton8d8706e2006-01-11 12:17:49 -0800720 case RIO_SET_CONFIG:
721 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
722 if (!su) {
723 p->RIOError.Error = NOT_SUPER_USER;
724 return -EPERM;
725 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800726 if (copy_from_user(&p->RIOConf, arg, sizeof(struct Conf))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800727 p->RIOError.Error = COPYIN_FAILED;
728 return -EFAULT;
729 }
730 /*
731 ** move a few value around
732 */
733 for (Host = 0; Host < p->RIONumHosts; Host++)
734 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
Alan Cox3d336aa2006-03-24 03:18:29 -0800735 writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800736 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Andrew Morton8d8706e2006-01-11 12:17:49 -0800738 case RIO_START_POLLER:
739 rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
740 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Andrew Morton8d8706e2006-01-11 12:17:49 -0800742 case RIO_STOP_POLLER:
743 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
744 if (!su) {
745 p->RIOError.Error = NOT_SUPER_USER;
746 return -EPERM;
747 }
748 p->RIOPolling = NOT_POLLING;
749 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Andrew Morton8d8706e2006-01-11 12:17:49 -0800751 case RIO_SETDEBUG:
752 case RIO_GETDEBUG:
753 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800754 if (copy_from_user(&DebugCtrl, arg, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800755 p->RIOError.Error = COPYIN_FAILED;
756 return -EFAULT;
757 }
758 if (DebugCtrl.SysPort == NO_PORT) {
759 if (cmd == RIO_SETDEBUG) {
760 if (!su) {
761 p->RIOError.Error = NOT_SUPER_USER;
762 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800764 p->rio_debug = DebugCtrl.Debug;
765 p->RIODebugWait = DebugCtrl.Wait;
766 rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
767 } else {
768 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
769 DebugCtrl.Debug = p->rio_debug;
770 DebugCtrl.Wait = p->RIODebugWait;
Alan Cox3d336aa2006-03-24 03:18:29 -0800771 if (copy_to_user(arg, &DebugCtrl, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800772 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
773 p->RIOError.Error = COPYOUT_FAILED;
774 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800776 }
777 } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
778 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
779 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
780 return -ENXIO;
781 } else if (cmd == RIO_SETDEBUG) {
782 if (!su) {
783 p->RIOError.Error = NOT_SUPER_USER;
784 return -EPERM;
785 }
786 rio_spin_lock_irqsave(&PortP->portSem, flags);
787 p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
788 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
789 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
790 } else {
791 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
792 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
Alan Cox3d336aa2006-03-24 03:18:29 -0800793 if (copy_to_user(arg, &DebugCtrl, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800794 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
795 p->RIOError.Error = COPYOUT_FAILED;
796 return -EFAULT;
797 }
798 }
799 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Andrew Morton8d8706e2006-01-11 12:17:49 -0800801 case RIO_VERSID:
802 /*
803 ** Enquire about the release and version.
804 ** We return MAX_VERSION_LEN bytes, being a
805 ** textual null terminated string.
806 */
807 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800808 if (copy_to_user(arg, RIOVersid(), sizeof(struct rioVersion))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800809 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
810 p->RIOError.Error = COPYOUT_FAILED;
811 return -EFAULT;
812 }
813 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Andrew Morton8d8706e2006-01-11 12:17:49 -0800815 case RIO_NUM_HOSTS:
816 /*
817 ** Enquire as to the number of hosts located
818 ** at init time.
819 */
820 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800821 if (copy_to_user(arg, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800822 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
823 p->RIOError.Error = COPYOUT_FAILED;
824 return -EFAULT;
825 }
826 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Andrew Morton8d8706e2006-01-11 12:17:49 -0800828 case RIO_HOST_FOAD:
829 /*
830 ** Kill host. This may not be in the final version...
831 */
Alan Cox3d336aa2006-03-24 03:18:29 -0800832 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", (unsigned long) arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800833 if (!su) {
834 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
835 p->RIOError.Error = NOT_SUPER_USER;
836 return -EPERM;
837 }
838 p->RIOHalted = 1;
839 p->RIOSystemUp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Andrew Morton8d8706e2006-01-11 12:17:49 -0800841 for (Host = 0; Host < p->RIONumHosts; Host++) {
842 (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
Alan Cox3d336aa2006-03-24 03:18:29 -0800843 memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800844 p->RIOHosts[Host].Flags = RC_WAITING;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800845 }
846 RIOFoadWakeup(p);
847 p->RIONumBootPkts = 0;
848 p->RIOBooting = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800849 printk("HEEEEELP!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Andrew Morton8d8706e2006-01-11 12:17:49 -0800851 for (loop = 0; loop < RIO_PORTS; loop++) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800852 spin_lock_init(&p->RIOPortp[loop]->portSem);
853 p->RIOPortp[loop]->InUse = NOT_INUSE;
854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Andrew Morton8d8706e2006-01-11 12:17:49 -0800856 p->RIOSystemUp = 0;
857 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Andrew Morton8d8706e2006-01-11 12:17:49 -0800859 case RIO_DOWNLOAD:
860 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
861 if (!su) {
862 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
863 p->RIOError.Error = NOT_SUPER_USER;
864 return -EPERM;
865 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800866 if (copy_from_user(&DownLoad, arg, sizeof(DownLoad))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800867 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
868 p->RIOError.Error = COPYIN_FAILED;
869 return -EFAULT;
870 }
871 rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Andrew Morton8d8706e2006-01-11 12:17:49 -0800873 /*
874 ** It is important that the product code is an unsigned object!
875 */
876 if (DownLoad.ProductCode > MAX_PRODUCT) {
877 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
878 p->RIOError.Error = NO_SUCH_PRODUCT;
879 return -ENXIO;
880 }
881 /*
882 ** do something!
883 */
884 retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
885 /* <-- Panic */
886 p->RIOHalted = 0;
887 /*
888 ** and go back, content with a job well completed.
889 */
890 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Andrew Morton8d8706e2006-01-11 12:17:49 -0800892 case RIO_PARMS:
893 {
Alan Cox3d336aa2006-03-24 03:18:29 -0800894 unsigned int host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Alan Cox3d336aa2006-03-24 03:18:29 -0800896 if (copy_from_user(&host, arg, sizeof(host))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800897 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
898 p->RIOError.Error = COPYIN_FAILED;
899 return -EFAULT;
900 }
901 /*
902 ** Fetch the parmmap
903 */
904 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800905 if (copy_to_user(arg, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800906 p->RIOError.Error = COPYOUT_FAILED;
907 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
908 return -EFAULT;
909 }
910 }
911 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Andrew Morton8d8706e2006-01-11 12:17:49 -0800913 case RIO_HOST_REQ:
914 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800915 if (copy_from_user(&HostReq, arg, sizeof(HostReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800916 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
917 p->RIOError.Error = COPYIN_FAILED;
918 return -EFAULT;
919 }
920 if (HostReq.HostNum >= p->RIONumHosts) {
921 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
922 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
923 return -ENXIO;
924 }
925 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
Alan Cox3d336aa2006-03-24 03:18:29 -0800927 if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800928 p->RIOError.Error = COPYOUT_FAILED;
929 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
930 return -EFAULT;
931 }
932 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Andrew Morton8d8706e2006-01-11 12:17:49 -0800934 case RIO_HOST_DPRAM:
935 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800936 if (copy_from_user(&HostDpRam, arg, sizeof(HostDpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800937 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
938 p->RIOError.Error = COPYIN_FAILED;
939 return -EFAULT;
940 }
941 if (HostDpRam.HostNum >= p->RIONumHosts) {
942 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
943 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
944 return -ENXIO;
945 }
946 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Andrew Morton8d8706e2006-01-11 12:17:49 -0800948 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
949 int off;
950 /* It's hardware like this that really gets on my tits. */
951 static unsigned char copy[sizeof(struct DpRam)];
952 for (off = 0; off < sizeof(struct DpRam); off++)
Alan Cox3d336aa2006-03-24 03:18:29 -0800953 copy[off] = readb(&p->RIOHosts[HostDpRam.HostNum].Caddr[off]);
954 if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800955 p->RIOError.Error = COPYOUT_FAILED;
956 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
957 return -EFAULT;
958 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800959 } else if (copy_to_user(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800960 p->RIOError.Error = COPYOUT_FAILED;
961 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
962 return -EFAULT;
963 }
964 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Andrew Morton8d8706e2006-01-11 12:17:49 -0800966 case RIO_SET_BUSY:
967 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800968 if ((unsigned long) arg > 511) {
969 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", (unsigned long) arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800970 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
971 return -EINVAL;
972 }
973 rio_spin_lock_irqsave(&PortP->portSem, flags);
Alan Cox3d336aa2006-03-24 03:18:29 -0800974 p->RIOPortp[(unsigned long) arg]->State |= RIO_BUSY;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800975 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
976 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Andrew Morton8d8706e2006-01-11 12:17:49 -0800978 case RIO_HOST_PORT:
979 /*
980 ** The daemon want port information
981 ** (probably for debug reasons)
982 */
983 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800984 if (copy_from_user(&PortReq, arg, sizeof(PortReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800985 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
986 p->RIOError.Error = COPYIN_FAILED;
987 return -EFAULT;
988 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
Andrew Morton8d8706e2006-01-11 12:17:49 -0800990 if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
991 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
992 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
993 return -ENXIO;
994 }
995 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
Alan Cox3d336aa2006-03-24 03:18:29 -0800996 if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800997 p->RIOError.Error = COPYOUT_FAILED;
998 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
999 return -EFAULT;
1000 }
1001 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Andrew Morton8d8706e2006-01-11 12:17:49 -08001003 case RIO_HOST_RUP:
1004 /*
1005 ** The daemon want rup information
1006 ** (probably for debug reasons)
1007 */
1008 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
Alan Cox3d336aa2006-03-24 03:18:29 -08001009 if (copy_from_user(&RupReq, arg, sizeof(RupReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001010 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1011 p->RIOError.Error = COPYIN_FAILED;
1012 return -EFAULT;
1013 }
1014 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1015 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
1016 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1017 return -ENXIO;
1018 }
1019 if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */
1020 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
1021 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1022 return -EINVAL;
1023 }
1024 HostP = &p->RIOHosts[RupReq.HostNum];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Andrew Morton8d8706e2006-01-11 12:17:49 -08001026 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1027 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
1028 p->RIOError.Error = HOST_NOT_RUNNING;
1029 return -EIO;
1030 }
1031 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
Alan Cox3d336aa2006-03-24 03:18:29 -08001033 if (copy_to_user(HostP->UnixRups[RupReq.RupNum].RupP, RupReq.RupP, sizeof(struct RUP))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001034 p->RIOError.Error = COPYOUT_FAILED;
1035 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1036 return -EFAULT;
1037 }
1038 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Andrew Morton8d8706e2006-01-11 12:17:49 -08001040 case RIO_HOST_LPB:
1041 /*
1042 ** The daemon want lpb information
1043 ** (probably for debug reasons)
1044 */
1045 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
Alan Cox3d336aa2006-03-24 03:18:29 -08001046 if (copy_from_user(&LpbReq, arg, sizeof(LpbReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001047 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1048 p->RIOError.Error = COPYIN_FAILED;
1049 return -EFAULT;
1050 }
1051 if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
1052 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
1053 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1054 return -ENXIO;
1055 }
1056 if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */
1057 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
1058 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1059 return -EINVAL;
1060 }
1061 HostP = &p->RIOHosts[LpbReq.Host];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Andrew Morton8d8706e2006-01-11 12:17:49 -08001063 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1064 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
1065 p->RIOError.Error = HOST_NOT_RUNNING;
1066 return -EIO;
1067 }
1068 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Alan Cox3d336aa2006-03-24 03:18:29 -08001070 if (copy_to_user(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001071 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1072 p->RIOError.Error = COPYOUT_FAILED;
1073 return -EFAULT;
1074 }
1075 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Andrew Morton8d8706e2006-01-11 12:17:49 -08001077 /*
1078 ** Here 3 IOCTL's that allow us to change the way in which
1079 ** rio logs errors. send them just to syslog or send them
1080 ** to both syslog and console or send them to just the console.
1081 **
1082 ** See RioStrBuf() in util.c for the other half.
1083 */
1084 case RIO_SYSLOG_ONLY:
1085 p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
1086 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Andrew Morton8d8706e2006-01-11 12:17:49 -08001088 case RIO_SYSLOG_CONS:
1089 p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */
1090 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Andrew Morton8d8706e2006-01-11 12:17:49 -08001092 case RIO_CONS_ONLY:
1093 p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
1094 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Andrew Morton8d8706e2006-01-11 12:17:49 -08001096 case RIO_SIGNALS_ON:
1097 if (p->RIOSignalProcess) {
1098 p->RIOError.Error = SIGNALS_ALREADY_SET;
1099 return -EBUSY;
1100 }
Alan Cox3d336aa2006-03-24 03:18:29 -08001101 /* FIXME: PID tracking */
1102 p->RIOSignalProcess = current->pid;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001103 p->RIOPrintDisabled = DONT_PRINT;
1104 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Andrew Morton8d8706e2006-01-11 12:17:49 -08001106 case RIO_SIGNALS_OFF:
Alan Cox3d336aa2006-03-24 03:18:29 -08001107 if (p->RIOSignalProcess != current->pid) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001108 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1109 return -EPERM;
1110 }
1111 rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
1112 p->RIOSignalProcess = 0;
1113 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Andrew Morton8d8706e2006-01-11 12:17:49 -08001115 case RIO_SET_BYTE_MODE:
1116 for (Host = 0; Host < p->RIONumHosts; Host++)
1117 if (p->RIOHosts[Host].Type == RIO_AT)
1118 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1119 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
Andrew Morton8d8706e2006-01-11 12:17:49 -08001121 case RIO_SET_WORD_MODE:
1122 for (Host = 0; Host < p->RIONumHosts; Host++)
1123 if (p->RIOHosts[Host].Type == RIO_AT)
1124 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1125 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Andrew Morton8d8706e2006-01-11 12:17:49 -08001127 case RIO_SET_FAST_BUS:
1128 for (Host = 0; Host < p->RIONumHosts; Host++)
1129 if (p->RIOHosts[Host].Type == RIO_AT)
1130 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1131 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Andrew Morton8d8706e2006-01-11 12:17:49 -08001133 case RIO_SET_SLOW_BUS:
1134 for (Host = 0; Host < p->RIONumHosts; Host++)
1135 if (p->RIOHosts[Host].Type == RIO_AT)
1136 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1137 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Andrew Morton8d8706e2006-01-11 12:17:49 -08001139 case RIO_MAP_B50_TO_50:
1140 case RIO_MAP_B50_TO_57600:
1141 case RIO_MAP_B110_TO_110:
1142 case RIO_MAP_B110_TO_115200:
1143 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
Alan Cox3d336aa2006-03-24 03:18:29 -08001144 port = (unsigned long) arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001145 if (port < 0 || port > 511) {
1146 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1147 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1148 return -EINVAL;
1149 }
1150 rio_spin_lock_irqsave(&PortP->portSem, flags);
1151 switch (cmd) {
1152 case RIO_MAP_B50_TO_50:
1153 p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1154 break;
1155 case RIO_MAP_B50_TO_57600:
1156 p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1157 break;
1158 case RIO_MAP_B110_TO_110:
1159 p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1160 break;
1161 case RIO_MAP_B110_TO_115200:
1162 p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1163 break;
1164 }
1165 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1166 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Andrew Morton8d8706e2006-01-11 12:17:49 -08001168 case RIO_STREAM_INFO:
1169 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
1170 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Andrew Morton8d8706e2006-01-11 12:17:49 -08001172 case RIO_SEND_PACKET:
1173 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
Alan Cox3d336aa2006-03-24 03:18:29 -08001174 if (copy_from_user(&SendPack, arg, sizeof(SendPack))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001175 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1176 p->RIOError.Error = COPYIN_FAILED;
1177 return -EFAULT;
1178 }
1179 if (SendPack.PortNum >= 128) {
1180 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1181 return -ENXIO;
1182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Andrew Morton8d8706e2006-01-11 12:17:49 -08001184 PortP = p->RIOPortp[SendPack.PortNum];
1185 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
Andrew Morton8d8706e2006-01-11 12:17:49 -08001187 if (!can_add_transmit(&PacketP, PortP)) {
1188 p->RIOError.Error = UNIT_IS_IN_USE;
1189 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1190 return -ENOSPC;
1191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Andrew Morton8d8706e2006-01-11 12:17:49 -08001193 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
Alan Cox3d336aa2006-03-24 03:18:29 -08001194 writeb(SendPack.Data[loop], &PacketP->data[loop]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Alan Cox3d336aa2006-03-24 03:18:29 -08001196 writeb(SendPack.Len, &PacketP->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Andrew Morton8d8706e2006-01-11 12:17:49 -08001198 add_transmit(PortP);
1199 /*
1200 ** Count characters transmitted for port statistics reporting
1201 */
1202 if (PortP->statsGather)
1203 PortP->txchars += (SendPack.Len & 127);
1204 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1205 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Andrew Morton8d8706e2006-01-11 12:17:49 -08001207 case RIO_NO_MESG:
1208 if (su)
1209 p->RIONoMessage = 1;
1210 return su ? 0 : -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Andrew Morton8d8706e2006-01-11 12:17:49 -08001212 case RIO_MESG:
1213 if (su)
1214 p->RIONoMessage = 0;
1215 return su ? 0 : -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Andrew Morton8d8706e2006-01-11 12:17:49 -08001217 case RIO_WHAT_MESG:
Alan Cox3d336aa2006-03-24 03:18:29 -08001218 if (copy_to_user(arg, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001219 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1220 p->RIOError.Error = COPYOUT_FAILED;
1221 return -EFAULT;
1222 }
1223 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Andrew Morton8d8706e2006-01-11 12:17:49 -08001225 case RIO_MEM_DUMP:
Alan Cox3d336aa2006-03-24 03:18:29 -08001226 if (copy_from_user(&SubCmd, arg, sizeof(struct SubCmdStruct))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001227 p->RIOError.Error = COPYIN_FAILED;
1228 return -EFAULT;
1229 }
1230 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Andrew Morton8d8706e2006-01-11 12:17:49 -08001232 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1233 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1234 return -EINVAL;
1235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Andrew Morton8d8706e2006-01-11 12:17:49 -08001237 if (SubCmd.Host >= p->RIONumHosts) {
1238 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1239 return -EINVAL;
1240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Andrew Morton8d8706e2006-01-11 12:17:49 -08001242 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
Andrew Morton8d8706e2006-01-11 12:17:49 -08001244 PortP = p->RIOPortp[port];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Andrew Morton8d8706e2006-01-11 12:17:49 -08001246 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Andrew Morton8d8706e2006-01-11 12:17:49 -08001248 if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) {
1249 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1250 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1251 return -EBUSY;
1252 } else
1253 PortP->State |= RIO_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Andrew Morton8d8706e2006-01-11 12:17:49 -08001255 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Alan Cox3d336aa2006-03-24 03:18:29 -08001256 if (copy_to_user(arg, p->RIOMemDump, MEMDUMP_SIZE)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001257 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1258 p->RIOError.Error = COPYOUT_FAILED;
1259 return -EFAULT;
1260 }
1261 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Andrew Morton8d8706e2006-01-11 12:17:49 -08001263 case RIO_TICK:
Alan Cox3d336aa2006-03-24 03:18:29 -08001264 if ((unsigned long) arg >= p->RIONumHosts)
Andrew Morton8d8706e2006-01-11 12:17:49 -08001265 return -EINVAL;
Alan Cox3d336aa2006-03-24 03:18:29 -08001266 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", (unsigned long) arg);
1267 writeb(0xFF, &p->RIOHosts[(unsigned long) arg].SetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001268 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Andrew Morton8d8706e2006-01-11 12:17:49 -08001270 case RIO_TOCK:
Alan Cox3d336aa2006-03-24 03:18:29 -08001271 if ((unsigned long) arg >= p->RIONumHosts)
Andrew Morton8d8706e2006-01-11 12:17:49 -08001272 return -EINVAL;
Alan Cox3d336aa2006-03-24 03:18:29 -08001273 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", (unsigned long) arg);
1274 writeb(0xFF, &p->RIOHosts[(unsigned long) arg].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001275 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Andrew Morton8d8706e2006-01-11 12:17:49 -08001277 case RIO_READ_CHECK:
1278 /* Check reads for pkts with data[0] the same */
1279 p->RIOReadCheck = !p->RIOReadCheck;
Alan Cox3d336aa2006-03-24 03:18:29 -08001280 if (copy_to_user(arg, &p->RIOReadCheck, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001281 p->RIOError.Error = COPYOUT_FAILED;
1282 return -EFAULT;
1283 }
1284 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
Andrew Morton8d8706e2006-01-11 12:17:49 -08001286 case RIO_READ_REGISTER:
Alan Cox3d336aa2006-03-24 03:18:29 -08001287 if (copy_from_user(&SubCmd, arg, sizeof(struct SubCmdStruct))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001288 p->RIOError.Error = COPYIN_FAILED;
1289 return -EFAULT;
1290 }
1291 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Andrew Morton8d8706e2006-01-11 12:17:49 -08001293 if (SubCmd.Port > 511) {
1294 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
1295 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1296 return -EINVAL;
1297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Andrew Morton8d8706e2006-01-11 12:17:49 -08001299 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1300 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1301 return -EINVAL;
1302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Andrew Morton8d8706e2006-01-11 12:17:49 -08001304 if (SubCmd.Host >= p->RIONumHosts) {
1305 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1306 return -EINVAL;
1307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Andrew Morton8d8706e2006-01-11 12:17:49 -08001309 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1310 PortP = p->RIOPortp[port];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Andrew Morton8d8706e2006-01-11 12:17:49 -08001312 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Andrew Morton8d8706e2006-01-11 12:17:49 -08001314 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
1315 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1316 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1317 return -EBUSY;
1318 } else
1319 PortP->State |= RIO_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Andrew Morton8d8706e2006-01-11 12:17:49 -08001321 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Alan Cox3d336aa2006-03-24 03:18:29 -08001322 if (copy_to_user(arg, &p->CdRegister, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001323 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1324 p->RIOError.Error = COPYOUT_FAILED;
1325 return -EFAULT;
1326 }
1327 return 0;
1328 /*
1329 ** rio_make_dev: given port number (0-511) ORed with port type
1330 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1331 ** value to pass to mknod to create the correct device node.
1332 */
1333 case RIO_MAKE_DEV:
1334 {
Alan Cox3d336aa2006-03-24 03:18:29 -08001335 unsigned int port = (unsigned long) arg & RIO_MODEM_MASK;
1336 unsigned int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Alan Cox3d336aa2006-03-24 03:18:29 -08001338 switch ((unsigned long) arg & RIO_DEV_MASK) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001339 case RIO_DEV_DIRECT:
Alan Cox3d336aa2006-03-24 03:18:29 -08001340 ret = drv_makedev(MAJOR(dev), port);
1341 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
1342 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001343 case RIO_DEV_MODEM:
Alan Cox3d336aa2006-03-24 03:18:29 -08001344 ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1345 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
1346 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001347 case RIO_DEV_XPRINT:
Alan Cox3d336aa2006-03-24 03:18:29 -08001348 ret = drv_makedev(MAJOR(dev), port);
1349 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
1350 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001351 }
1352 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1353 return -EINVAL;
1354 }
1355 /*
1356 ** rio_minor: given a dev_t from a stat() call, return
1357 ** the port number (0-511) ORed with the port type
1358 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1359 */
1360 case RIO_MINOR:
1361 {
1362 dev_t dv;
1363 int mino;
Alan Cox3d336aa2006-03-24 03:18:29 -08001364 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Alan Cox3d336aa2006-03-24 03:18:29 -08001366 dv = (dev_t) ((unsigned long) arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001367 mino = RIO_UNMODEM(dv);
1368
1369 if (RIO_ISMODEM(dv)) {
1370 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
Alan Cox3d336aa2006-03-24 03:18:29 -08001371 ret = mino | RIO_DEV_MODEM;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001372 } else {
1373 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
Alan Cox3d336aa2006-03-24 03:18:29 -08001374 ret = mino | RIO_DEV_DIRECT;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001375 }
Alan Cox3d336aa2006-03-24 03:18:29 -08001376 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 }
Andrew Morton8d8706e2006-01-11 12:17:49 -08001379 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1381
Andrew Morton8d8706e2006-01-11 12:17:49 -08001382 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 return -EINVAL;
1384}
1385
1386/*
1387** Pre-emptive commands go on RUPs and are only one byte long.
1388*/
Alan Cox3d336aa2006-03-24 03:18:29 -08001389int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
1391 struct CmdBlk *CmdBlkP;
1392 struct PktCmd_M *PktCmdP;
1393 int Ret;
1394 ushort rup;
1395 int port;
1396
Andrew Morton8d8706e2006-01-11 12:17:49 -08001397 if (PortP->State & RIO_DELETED) {
1398 rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 return RIO_FAIL;
1400 }
1401
Andrew Morton8d8706e2006-01-11 12:17:49 -08001402 if (((int) ((char) PortP->InUse) == -1) || !(CmdBlkP = RIOGetCmdBlk())) {
1403 rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block for command %d on port %d\n", Cmd, PortP->PortNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 return RIO_FAIL;
1405 }
1406
Alan Cox3d336aa2006-03-24 03:18:29 -08001407 rio_dprintk(RIO_DEBUG_CTRL, "Command blk 0x%p - InUse now %d\n", CmdBlkP, PortP->InUse);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Andrew Morton8d8706e2006-01-11 12:17:49 -08001409 PktCmdP = (struct PktCmd_M *) &CmdBlkP->Packet.data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Andrew Morton8d8706e2006-01-11 12:17:49 -08001411 CmdBlkP->Packet.src_unit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 if (PortP->SecondBlock)
1413 rup = PortP->ID2;
1414 else
1415 rup = PortP->RupNum;
1416 CmdBlkP->Packet.dest_unit = rup;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001417 CmdBlkP->Packet.src_port = COMMAND_RUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 CmdBlkP->Packet.dest_port = COMMAND_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001419 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1420 CmdBlkP->PostFuncP = RIOUnUse;
Alan Cox3d336aa2006-03-24 03:18:29 -08001421 CmdBlkP->PostArg = (unsigned long) PortP;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001422 PktCmdP->Command = Cmd;
1423 port = PortP->HostPort % (ushort) PORTS_PER_RTA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -08001425 ** Index ports 8-15 for 2nd block of 16 port RTA.
1426 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 if (PortP->SecondBlock)
1428 port += (ushort) PORTS_PER_RTA;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001429 PktCmdP->PhbNum = port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Andrew Morton8d8706e2006-01-11 12:17:49 -08001431 switch (Cmd) {
1432 case MEMDUMP:
Alan Cox3d336aa2006-03-24 03:18:29 -08001433 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk 0x%p (addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001434 PktCmdP->SubCommand = MEMDUMP;
1435 PktCmdP->SubAddr = SubCmd.Addr;
1436 break;
1437 case FCLOSE:
Alan Cox3d336aa2006-03-24 03:18:29 -08001438 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk 0x%p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001439 break;
1440 case READ_REGISTER:
Alan Cox3d336aa2006-03-24 03:18:29 -08001441 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk 0x%p\n", (int) SubCmd.Addr, CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001442 PktCmdP->SubCommand = READ_REGISTER;
1443 PktCmdP->SubAddr = SubCmd.Addr;
1444 break;
1445 case RESUME:
Alan Cox3d336aa2006-03-24 03:18:29 -08001446 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk 0x%p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001447 break;
1448 case RFLUSH:
Alan Cox3d336aa2006-03-24 03:18:29 -08001449 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk 0x%p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001450 CmdBlkP->PostFuncP = RIORFlushEnable;
1451 break;
1452 case SUSPEND:
Alan Cox3d336aa2006-03-24 03:18:29 -08001453 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk 0x%p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001454 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Andrew Morton8d8706e2006-01-11 12:17:49 -08001456 case MGET:
Alan Cox3d336aa2006-03-24 03:18:29 -08001457 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk 0x%p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001458 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Andrew Morton8d8706e2006-01-11 12:17:49 -08001460 case MSET:
1461 case MBIC:
1462 case MBIS:
1463 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
Alan Cox3d336aa2006-03-24 03:18:29 -08001464 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk 0x%p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001465 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Andrew Morton8d8706e2006-01-11 12:17:49 -08001467 case WFLUSH:
1468 /*
1469 ** If we have queued up the maximum number of Write flushes
1470 ** allowed then we should not bother sending any more to the
1471 ** RTA.
1472 */
1473 if ((int) ((char) PortP->WflushFlag) == (int) -1) {
1474 rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, WflushFlag about to wrap!");
1475 RIOFreeCmdBlk(CmdBlkP);
1476 return (RIO_FAIL);
1477 } else {
Alan Cox3d336aa2006-03-24 03:18:29 -08001478 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command blk 0x%p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001479 CmdBlkP->PostFuncP = RIOWFlushMark;
1480 }
1481 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 }
1483
1484 PortP->InUse++;
1485
Andrew Morton8d8706e2006-01-11 12:17:49 -08001486 Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
1488 return Ret;
1489}