blob: d31aba62bb7f362d87d8e38961f0abc2ba197abc [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "pkt.h"
55#include "daemon.h"
56#include "rio.h"
57#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include "cmdpkt.h"
59#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include "phb.h"
73#include "link.h"
74#include "cmdblk.h"
75#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#include "cirrus.h"
77#include "rioioctl.h"
78
79
Andrew Morton8d8706e2006-01-11 12:17:49 -080080static struct LpbReq LpbReq;
81static struct RupReq RupReq;
82static struct PortReq PortReq;
83static struct HostReq HostReq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084static struct HostDpRam HostDpRam;
85static struct DebugCtrl DebugCtrl;
Andrew Morton8d8706e2006-01-11 12:17:49 -080086static struct Map MapEnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static struct PortSetup PortSetup;
Andrew Morton8d8706e2006-01-11 12:17:49 -080088static struct DownLoad DownLoad;
89static struct SendPack SendPack;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090/* static struct StreamInfo StreamInfo; */
91/* static char modemtable[RIO_PORTS]; */
92static struct SpecialRupCmd SpecialRupCmd;
93static struct PortParams PortParams;
94static struct portStats portStats;
95
96static struct SubCmdStruct {
Andrew Morton8d8706e2006-01-11 12:17:49 -080097 ushort Host;
98 ushort Rup;
99 ushort Port;
100 ushort Addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101} SubCmd;
102
103struct PortTty {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800104 uint port;
105 struct ttystatics Tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106};
107
Andrew Morton8d8706e2006-01-11 12:17:49 -0800108static struct PortTty PortTty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109typedef 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*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800119static int
120 (*RIOBootTable[MAX_PRODUCT]) (struct rio_info *, struct DownLoad *) = {
121 /* 0 */ RIOBootCodeHOST,
122 /* Host Card */
123 /* 1 */ RIOBootCodeRTA,
124 /* RTA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125};
126
127#define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
128
Andrew Morton8d8706e2006-01-11 12:17:49 -0800129int riocontrol(p, dev, cmd, arg, su)
130struct rio_info *p;
131dev_t dev;
132int cmd;
133caddr_t arg;
134int su;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800136 uint Host; /* leave me unsigned! */
137 uint port; /* and me! */
138 struct Host *HostP;
139 ushort loop;
140 int Entry;
141 struct Port *PortP;
Alan Cox554b7c82006-03-24 03:18:32 -0800142 struct PKT *PacketP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800143 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 unsigned long flags;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800145
146 func_enter();
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 /* Confuse the compiler to think that we've initialized these */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800149 Host = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 PortP = NULL;
151
Alan Cox554b7c82006-03-24 03:18:32 -0800152 rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 switch (cmd) {
155 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800156 ** RIO_SET_TIMER
157 **
158 ** Change the value of the host card interrupt timer.
159 ** If the host card number is -1 then all host cards are changed
160 ** otherwise just the specified host card will be changed.
161 */
162 case RIO_SET_TIMER:
Alan Cox3d336aa2006-03-24 03:18:29 -0800163 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", (unsigned long)arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800164 {
165 int host, value;
Alan Cox3d336aa2006-03-24 03:18:29 -0800166 host = ((unsigned long) arg >> 16) & 0x0000FFFF;
167 value = (unsigned long) arg & 0x0000ffff;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800168 if (host == -1) {
169 for (host = 0; host < p->RIONumHosts; host++) {
170 if (p->RIOHosts[host].Flags == RC_RUNNING) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800171 writew(value, &p->RIOHosts[host].ParmMapP->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
173 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800174 } else if (host >= p->RIONumHosts) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 return -EINVAL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800176 } else {
177 if (p->RIOHosts[host].Flags == RC_RUNNING) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800178 writew(value, &p->RIOHosts[host].ParmMapP->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800180 }
181 }
182 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Andrew Morton8d8706e2006-01-11 12:17:49 -0800184 case RIO_FOAD_RTA:
185 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800186 return RIOCommandRta(p, (unsigned long)arg, RIOFoadRta);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800187
188 case RIO_ZOMBIE_RTA:
189 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800190 return RIOCommandRta(p, (unsigned long)arg, RIOZombieRta);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800191
192 case RIO_IDENTIFY_RTA:
193 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
194 return RIOIdentifyRta(p, arg);
195
196 case RIO_KILL_NEIGHBOUR:
197 rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
198 return RIOKillNeighbour(p, arg);
199
200 case SPECIAL_RUP_CMD:
201 {
202 struct CmdBlk *CmdBlkP;
203
204 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800205 if (copy_from_user(&SpecialRupCmd, arg, sizeof(SpecialRupCmd))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800206 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
207 p->RIOError.Error = COPYIN_FAILED;
208 return -EFAULT;
209 }
210 CmdBlkP = RIOGetCmdBlk();
211 if (!CmdBlkP) {
212 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
213 return -ENXIO;
214 }
215 CmdBlkP->Packet = SpecialRupCmd.Packet;
216 if (SpecialRupCmd.Host >= p->RIONumHosts)
217 SpecialRupCmd.Host = 0;
218 rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
219 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800220 printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800221 }
222 return 0;
223 }
224
225 case RIO_DEBUG_MEM:
Alan Coxf4caf162006-01-16 17:27:38 +0000226 return -EPERM;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800227
228 case RIO_ALL_MODEM:
229 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
230 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
231 return -EINVAL;
232
233 case RIO_GET_TABLE:
234 /*
235 ** Read the routing table from the device driver to user space
236 */
237 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
238
239 if ((retval = RIOApel(p)) != 0)
240 return retval;
241
Alan Cox3d336aa2006-03-24 03:18:29 -0800242 if (copy_to_user(arg, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800243 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
244 p->RIOError.Error = COPYOUT_FAILED;
245 return -EFAULT;
246 }
247
248 {
249 int entry;
250 rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
251 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
252 if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
253 continue;
254
255 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
256 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
257 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
258 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
259 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
260 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
261 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
262 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
263 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
264 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
265 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
266 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
267 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
268 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
269 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
270 }
271 rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
272 }
273 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
274 return 0;
275
276 case RIO_PUT_TABLE:
277 /*
278 ** Write the routing table to the device driver from user space
279 */
280 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
281
282 if (!su) {
283 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
284 p->RIOError.Error = NOT_SUPER_USER;
285 return -EPERM;
286 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800287 if (copy_from_user(&p->RIOConnectTable[0], arg, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800288 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
289 p->RIOError.Error = COPYIN_FAILED;
290 return -EFAULT;
291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292/*
293***********************************
294 {
295 int entry;
296 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
297 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
298 {
299 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
300 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
301 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
302 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
303 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
304 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
305 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
306 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
307 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
308 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
309 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
310 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
311 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
312 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
313 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
314 }
315 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
316 }
317***********************************
318*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800319 return RIONewTable(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Andrew Morton8d8706e2006-01-11 12:17:49 -0800321 case RIO_GET_BINDINGS:
322 /*
323 ** Send bindings table, containing unique numbers of RTAs owned
324 ** by this system to user space
325 */
326 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Andrew Morton8d8706e2006-01-11 12:17:49 -0800328 if (!su) {
329 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
330 p->RIOError.Error = NOT_SUPER_USER;
331 return -EPERM;
332 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800333 if (copy_to_user(arg, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800334 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
335 p->RIOError.Error = COPYOUT_FAILED;
336 return -EFAULT;
337 }
338 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Andrew Morton8d8706e2006-01-11 12:17:49 -0800340 case RIO_PUT_BINDINGS:
341 /*
342 ** Receive a bindings table, containing unique numbers of RTAs owned
343 ** by this system
344 */
345 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
346
347 if (!su) {
348 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
349 p->RIOError.Error = NOT_SUPER_USER;
350 return -EPERM;
351 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800352 if (copy_from_user(&p->RIOBindTab[0], arg, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800353 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
354 p->RIOError.Error = COPYIN_FAILED;
355 return -EFAULT;
356 }
357 return 0;
358
359 case RIO_BIND_RTA:
360 {
361 int EmptySlot = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800363 ** Bind this RTA to host, so that it will be booted by
364 ** host in 'boot owned RTAs' mode.
365 */
366 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Andrew Morton8d8706e2006-01-11 12:17:49 -0800368 if (!su) {
369 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
370 p->RIOError.Error = NOT_SUPER_USER;
371 return -EPERM;
372 }
373 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
374 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
375 EmptySlot = Entry;
Alan Cox3d336aa2006-03-24 03:18:29 -0800376 else if (p->RIOBindTab[Entry] == (long)arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800378 ** Already exists - delete
379 */
380 p->RIOBindTab[Entry] = 0L;
Alan Cox3d336aa2006-03-24 03:18:29 -0800381 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", (unsigned long)arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 return 0;
383 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800384 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800386 ** Dosen't exist - add
387 */
388 if (EmptySlot != -1) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800389 p->RIOBindTab[EmptySlot] = (unsigned long)arg;
390 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", (unsigned long) arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800391 } else {
Alan Cox3d336aa2006-03-24 03:18:29 -0800392 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", (unsigned long) arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800393 return -ENOMEM;
394 }
395 return 0;
396 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Andrew Morton8d8706e2006-01-11 12:17:49 -0800398 case RIO_RESUME:
399 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800400 port = (unsigned long) arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800401 if ((port < 0) || (port > 511)) {
402 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
403 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
404 return -EINVAL;
405 }
406 PortP = p->RIOPortp[port];
407 if (!PortP->Mapped) {
408 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
409 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
410 return -EINVAL;
411 }
412 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
413 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
414 return -EINVAL;
415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Andrew Morton8d8706e2006-01-11 12:17:49 -0800417 rio_spin_lock_irqsave(&PortP->portSem, flags);
418 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) {
419 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
420 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
421 return -EBUSY;
422 } else {
423 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
424 PortP->State |= RIO_BUSY;
425 }
426 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
427 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Andrew Morton8d8706e2006-01-11 12:17:49 -0800429 case RIO_ASSIGN_RTA:
430 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
431 if (!su) {
432 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
433 p->RIOError.Error = NOT_SUPER_USER;
434 return -EPERM;
435 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800436 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800437 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
438 p->RIOError.Error = COPYIN_FAILED;
439 return -EFAULT;
440 }
441 return RIOAssignRta(p, &MapEnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Andrew Morton8d8706e2006-01-11 12:17:49 -0800443 case RIO_CHANGE_NAME:
444 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
445 if (!su) {
446 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
447 p->RIOError.Error = NOT_SUPER_USER;
448 return -EPERM;
449 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800450 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800451 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
452 p->RIOError.Error = COPYIN_FAILED;
453 return -EFAULT;
454 }
455 return RIOChangeName(p, &MapEnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Andrew Morton8d8706e2006-01-11 12:17:49 -0800457 case RIO_DELETE_RTA:
458 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
459 if (!su) {
460 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
461 p->RIOError.Error = NOT_SUPER_USER;
462 return -EPERM;
463 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800464 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800465 rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
466 p->RIOError.Error = COPYIN_FAILED;
467 return -EFAULT;
468 }
469 return RIODeleteRta(p, &MapEnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Andrew Morton8d8706e2006-01-11 12:17:49 -0800471 case RIO_QUICK_CHECK:
Alan Cox3d336aa2006-03-24 03:18:29 -0800472 if (copy_to_user(arg, &p->RIORtaDisCons, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800473 p->RIOError.Error = COPYOUT_FAILED;
474 return -EFAULT;
475 }
476 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Andrew Morton8d8706e2006-01-11 12:17:49 -0800478 case RIO_LAST_ERROR:
Alan Cox3d336aa2006-03-24 03:18:29 -0800479 if (copy_to_user(arg, &p->RIOError, sizeof(struct Error)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800480 return -EFAULT;
481 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Andrew Morton8d8706e2006-01-11 12:17:49 -0800483 case RIO_GET_LOG:
484 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800485 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Andrew Morton8d8706e2006-01-11 12:17:49 -0800487 case RIO_GET_MODTYPE:
Alan Cox3d336aa2006-03-24 03:18:29 -0800488 if (copy_from_user(&port, arg, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800489 p->RIOError.Error = COPYIN_FAILED;
490 return -EFAULT;
491 }
492 rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
493 if (port < 0 || port > 511) {
494 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
495 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
496 return -EINVAL;
497 }
498 PortP = (p->RIOPortp[port]);
499 if (!PortP->Mapped) {
500 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
501 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
502 return -EINVAL;
503 }
504 /*
505 ** Return module type of port
506 */
507 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
Alan Cox3d336aa2006-03-24 03:18:29 -0800508 if (copy_to_user(arg, &port, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800509 p->RIOError.Error = COPYOUT_FAILED;
510 return -EFAULT;
511 }
512 return (0);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800513 case RIO_BLOCK_OPENS:
514 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
515 for (Entry = 0; Entry < RIO_PORTS; Entry++) {
516 rio_spin_lock_irqsave(&PortP->portSem, flags);
517 p->RIOPortp[Entry]->WaitUntilBooted = 1;
518 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
519 }
520 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Andrew Morton8d8706e2006-01-11 12:17:49 -0800522 case RIO_SETUP_PORTS:
523 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800524 if (copy_from_user(&PortSetup, arg, sizeof(PortSetup))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800525 p->RIOError.Error = COPYIN_FAILED;
526 rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
527 return -EFAULT;
528 }
529 if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
530 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
531 rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
532 return -ENXIO;
533 }
534 if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
535 p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
536 rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
537 return -EINVAL;
538 }
539 if (!p->RIOPortp) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800540 printk(KERN_ERR "rio: No p->RIOPortp array!\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800541 rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
542 return -EIO;
543 }
544 rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
545 for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
546 rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800547 }
548 rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
549 rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
550 return retval;
551
552 case RIO_GET_PORT_SETUP:
553 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800554 if (copy_from_user(&PortSetup, arg, sizeof(PortSetup))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800555 p->RIOError.Error = COPYIN_FAILED;
556 return -EFAULT;
557 }
558 if (PortSetup.From >= RIO_PORTS) {
559 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
560 return -ENXIO;
561 }
562
563 port = PortSetup.To = PortSetup.From;
564 PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
565 PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
566 PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
567 PortSetup.Store = p->RIOPortp[port]->Store;
568 PortSetup.Lock = p->RIOPortp[port]->Lock;
569 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
Alan Cox554b7c82006-03-24 03:18:32 -0800570 memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN);
571 memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800572 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
573 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
574
Alan Cox3d336aa2006-03-24 03:18:29 -0800575 if (copy_to_user(arg, &PortSetup, sizeof(PortSetup))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800576 p->RIOError.Error = COPYOUT_FAILED;
577 return -EFAULT;
578 }
579 return retval;
580
581 case RIO_GET_PORT_PARAMS:
582 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800583 if (copy_from_user(&PortParams, arg, sizeof(struct PortParams))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800584 p->RIOError.Error = COPYIN_FAILED;
585 return -EFAULT;
586 }
587 if (PortParams.Port >= RIO_PORTS) {
588 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
589 return -ENXIO;
590 }
591 PortP = (p->RIOPortp[PortParams.Port]);
592 PortParams.Config = PortP->Config;
593 PortParams.State = PortP->State;
594 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
595
Alan Cox3d336aa2006-03-24 03:18:29 -0800596 if (copy_to_user(arg, &PortParams, sizeof(struct PortParams))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800597 p->RIOError.Error = COPYOUT_FAILED;
598 return -EFAULT;
599 }
600 return retval;
601
602 case RIO_GET_PORT_TTY:
603 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800604 if (copy_from_user(&PortTty, arg, sizeof(struct PortTty))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800605 p->RIOError.Error = COPYIN_FAILED;
606 return -EFAULT;
607 }
608 if (PortTty.port >= RIO_PORTS) {
609 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
610 return -ENXIO;
611 }
612
613 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
614 PortP = (p->RIOPortp[PortTty.port]);
Alan Cox3d336aa2006-03-24 03:18:29 -0800615 if (copy_to_user(arg, &PortTty, sizeof(struct PortTty))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800616 p->RIOError.Error = COPYOUT_FAILED;
617 return -EFAULT;
618 }
619 return retval;
620
621 case RIO_SET_PORT_TTY:
Alan Cox3d336aa2006-03-24 03:18:29 -0800622 if (copy_from_user(&PortTty, arg, sizeof(struct PortTty))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800623 p->RIOError.Error = COPYIN_FAILED;
624 return -EFAULT;
625 }
626 rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
627 if (PortTty.port >= (ushort) RIO_PORTS) {
628 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
629 return -ENXIO;
630 }
631 PortP = (p->RIOPortp[PortTty.port]);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800632 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
633 return retval;
634
635 case RIO_SET_PORT_PARAMS:
636 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800637 if (copy_from_user(&PortParams, arg, sizeof(PortParams))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800638 p->RIOError.Error = COPYIN_FAILED;
639 return -EFAULT;
640 }
641 if (PortParams.Port >= (ushort) RIO_PORTS) {
642 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
643 return -ENXIO;
644 }
645 PortP = (p->RIOPortp[PortParams.Port]);
646 rio_spin_lock_irqsave(&PortP->portSem, flags);
647 PortP->Config = PortParams.Config;
648 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
649 return retval;
650
651 case RIO_GET_PORT_STATS:
652 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800653 if (copy_from_user(&portStats, arg, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800654 p->RIOError.Error = COPYIN_FAILED;
655 return -EFAULT;
656 }
657 if (portStats.port >= RIO_PORTS) {
658 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
659 return -ENXIO;
660 }
661 PortP = (p->RIOPortp[portStats.port]);
662 portStats.gather = PortP->statsGather;
663 portStats.txchars = PortP->txchars;
664 portStats.rxchars = PortP->rxchars;
665 portStats.opens = PortP->opens;
666 portStats.closes = PortP->closes;
667 portStats.ioctls = PortP->ioctls;
Alan Cox3d336aa2006-03-24 03:18:29 -0800668 if (copy_to_user(arg, &portStats, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800669 p->RIOError.Error = COPYOUT_FAILED;
670 return -EFAULT;
671 }
672 return retval;
673
674 case RIO_RESET_PORT_STATS:
Alan Cox3d336aa2006-03-24 03:18:29 -0800675 port = (unsigned long) arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800676 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
677 if (port >= RIO_PORTS) {
678 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
679 return -ENXIO;
680 }
681 PortP = (p->RIOPortp[port]);
682 rio_spin_lock_irqsave(&PortP->portSem, flags);
683 PortP->txchars = 0;
684 PortP->rxchars = 0;
685 PortP->opens = 0;
686 PortP->closes = 0;
687 PortP->ioctls = 0;
688 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
689 return retval;
690
691 case RIO_GATHER_PORT_STATS:
692 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800693 if (copy_from_user(&portStats, arg, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800694 p->RIOError.Error = COPYIN_FAILED;
695 return -EFAULT;
696 }
697 if (portStats.port >= RIO_PORTS) {
698 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
699 return -ENXIO;
700 }
701 PortP = (p->RIOPortp[portStats.port]);
702 rio_spin_lock_irqsave(&PortP->portSem, flags);
703 PortP->statsGather = portStats.gather;
704 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
705 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Andrew Morton8d8706e2006-01-11 12:17:49 -0800707 case RIO_READ_CONFIG:
708 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800709 if (copy_to_user(arg, &p->RIOConf, sizeof(struct Conf))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800710 p->RIOError.Error = COPYOUT_FAILED;
711 return -EFAULT;
712 }
713 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Andrew Morton8d8706e2006-01-11 12:17:49 -0800715 case RIO_SET_CONFIG:
716 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
717 if (!su) {
718 p->RIOError.Error = NOT_SUPER_USER;
719 return -EPERM;
720 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800721 if (copy_from_user(&p->RIOConf, arg, sizeof(struct Conf))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800722 p->RIOError.Error = COPYIN_FAILED;
723 return -EFAULT;
724 }
725 /*
726 ** move a few value around
727 */
728 for (Host = 0; Host < p->RIONumHosts; Host++)
729 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
Alan Cox3d336aa2006-03-24 03:18:29 -0800730 writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800731 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Andrew Morton8d8706e2006-01-11 12:17:49 -0800733 case RIO_START_POLLER:
734 rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
735 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Andrew Morton8d8706e2006-01-11 12:17:49 -0800737 case RIO_STOP_POLLER:
738 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
739 if (!su) {
740 p->RIOError.Error = NOT_SUPER_USER;
741 return -EPERM;
742 }
743 p->RIOPolling = NOT_POLLING;
744 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Andrew Morton8d8706e2006-01-11 12:17:49 -0800746 case RIO_SETDEBUG:
747 case RIO_GETDEBUG:
748 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800749 if (copy_from_user(&DebugCtrl, arg, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800750 p->RIOError.Error = COPYIN_FAILED;
751 return -EFAULT;
752 }
753 if (DebugCtrl.SysPort == NO_PORT) {
754 if (cmd == RIO_SETDEBUG) {
755 if (!su) {
756 p->RIOError.Error = NOT_SUPER_USER;
757 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800759 p->rio_debug = DebugCtrl.Debug;
760 p->RIODebugWait = DebugCtrl.Wait;
761 rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
762 } else {
763 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
764 DebugCtrl.Debug = p->rio_debug;
765 DebugCtrl.Wait = p->RIODebugWait;
Alan Cox3d336aa2006-03-24 03:18:29 -0800766 if (copy_to_user(arg, &DebugCtrl, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800767 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
768 p->RIOError.Error = COPYOUT_FAILED;
769 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800771 }
772 } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
773 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
774 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
775 return -ENXIO;
776 } else if (cmd == RIO_SETDEBUG) {
777 if (!su) {
778 p->RIOError.Error = NOT_SUPER_USER;
779 return -EPERM;
780 }
781 rio_spin_lock_irqsave(&PortP->portSem, flags);
782 p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
783 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
784 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
785 } else {
786 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
787 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
Alan Cox3d336aa2006-03-24 03:18:29 -0800788 if (copy_to_user(arg, &DebugCtrl, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800789 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
790 p->RIOError.Error = COPYOUT_FAILED;
791 return -EFAULT;
792 }
793 }
794 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Andrew Morton8d8706e2006-01-11 12:17:49 -0800796 case RIO_VERSID:
797 /*
798 ** Enquire about the release and version.
799 ** We return MAX_VERSION_LEN bytes, being a
800 ** textual null terminated string.
801 */
802 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800803 if (copy_to_user(arg, RIOVersid(), sizeof(struct rioVersion))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800804 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
805 p->RIOError.Error = COPYOUT_FAILED;
806 return -EFAULT;
807 }
808 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Andrew Morton8d8706e2006-01-11 12:17:49 -0800810 case RIO_NUM_HOSTS:
811 /*
812 ** Enquire as to the number of hosts located
813 ** at init time.
814 */
815 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800816 if (copy_to_user(arg, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800817 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
818 p->RIOError.Error = COPYOUT_FAILED;
819 return -EFAULT;
820 }
821 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Andrew Morton8d8706e2006-01-11 12:17:49 -0800823 case RIO_HOST_FOAD:
824 /*
825 ** Kill host. This may not be in the final version...
826 */
Alan Cox3d336aa2006-03-24 03:18:29 -0800827 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", (unsigned long) arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800828 if (!su) {
829 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
830 p->RIOError.Error = NOT_SUPER_USER;
831 return -EPERM;
832 }
833 p->RIOHalted = 1;
834 p->RIOSystemUp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Andrew Morton8d8706e2006-01-11 12:17:49 -0800836 for (Host = 0; Host < p->RIONumHosts; Host++) {
837 (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
Alan Cox3d336aa2006-03-24 03:18:29 -0800838 memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800839 p->RIOHosts[Host].Flags = RC_WAITING;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800840 }
841 RIOFoadWakeup(p);
842 p->RIONumBootPkts = 0;
843 p->RIOBooting = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800844 printk("HEEEEELP!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Andrew Morton8d8706e2006-01-11 12:17:49 -0800846 for (loop = 0; loop < RIO_PORTS; loop++) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800847 spin_lock_init(&p->RIOPortp[loop]->portSem);
848 p->RIOPortp[loop]->InUse = NOT_INUSE;
849 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Andrew Morton8d8706e2006-01-11 12:17:49 -0800851 p->RIOSystemUp = 0;
852 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Andrew Morton8d8706e2006-01-11 12:17:49 -0800854 case RIO_DOWNLOAD:
855 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
856 if (!su) {
857 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
858 p->RIOError.Error = NOT_SUPER_USER;
859 return -EPERM;
860 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800861 if (copy_from_user(&DownLoad, arg, sizeof(DownLoad))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800862 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
863 p->RIOError.Error = COPYIN_FAILED;
864 return -EFAULT;
865 }
866 rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Andrew Morton8d8706e2006-01-11 12:17:49 -0800868 /*
869 ** It is important that the product code is an unsigned object!
870 */
871 if (DownLoad.ProductCode > MAX_PRODUCT) {
872 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
873 p->RIOError.Error = NO_SUCH_PRODUCT;
874 return -ENXIO;
875 }
876 /*
877 ** do something!
878 */
879 retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
880 /* <-- Panic */
881 p->RIOHalted = 0;
882 /*
883 ** and go back, content with a job well completed.
884 */
885 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Andrew Morton8d8706e2006-01-11 12:17:49 -0800887 case RIO_PARMS:
888 {
Alan Cox3d336aa2006-03-24 03:18:29 -0800889 unsigned int host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
Alan Cox3d336aa2006-03-24 03:18:29 -0800891 if (copy_from_user(&host, arg, sizeof(host))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800892 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
893 p->RIOError.Error = COPYIN_FAILED;
894 return -EFAULT;
895 }
896 /*
897 ** Fetch the parmmap
898 */
899 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800900 if (copy_to_user(arg, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800901 p->RIOError.Error = COPYOUT_FAILED;
902 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
903 return -EFAULT;
904 }
905 }
906 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Andrew Morton8d8706e2006-01-11 12:17:49 -0800908 case RIO_HOST_REQ:
909 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800910 if (copy_from_user(&HostReq, arg, sizeof(HostReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800911 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
912 p->RIOError.Error = COPYIN_FAILED;
913 return -EFAULT;
914 }
915 if (HostReq.HostNum >= p->RIONumHosts) {
916 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
917 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
918 return -ENXIO;
919 }
920 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Alan Cox3d336aa2006-03-24 03:18:29 -0800922 if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800923 p->RIOError.Error = COPYOUT_FAILED;
924 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
925 return -EFAULT;
926 }
927 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Andrew Morton8d8706e2006-01-11 12:17:49 -0800929 case RIO_HOST_DPRAM:
930 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800931 if (copy_from_user(&HostDpRam, arg, sizeof(HostDpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800932 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
933 p->RIOError.Error = COPYIN_FAILED;
934 return -EFAULT;
935 }
936 if (HostDpRam.HostNum >= p->RIONumHosts) {
937 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
938 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
939 return -ENXIO;
940 }
941 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Andrew Morton8d8706e2006-01-11 12:17:49 -0800943 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
944 int off;
945 /* It's hardware like this that really gets on my tits. */
946 static unsigned char copy[sizeof(struct DpRam)];
947 for (off = 0; off < sizeof(struct DpRam); off++)
Alan Cox3d336aa2006-03-24 03:18:29 -0800948 copy[off] = readb(&p->RIOHosts[HostDpRam.HostNum].Caddr[off]);
949 if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800950 p->RIOError.Error = COPYOUT_FAILED;
951 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
952 return -EFAULT;
953 }
Alan Cox3d336aa2006-03-24 03:18:29 -0800954 } else if (copy_to_user(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, 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 }
959 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Andrew Morton8d8706e2006-01-11 12:17:49 -0800961 case RIO_SET_BUSY:
962 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800963 if ((unsigned long) arg > 511) {
964 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", (unsigned long) arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800965 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
966 return -EINVAL;
967 }
968 rio_spin_lock_irqsave(&PortP->portSem, flags);
Alan Cox3d336aa2006-03-24 03:18:29 -0800969 p->RIOPortp[(unsigned long) arg]->State |= RIO_BUSY;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800970 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
971 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Andrew Morton8d8706e2006-01-11 12:17:49 -0800973 case RIO_HOST_PORT:
974 /*
975 ** The daemon want port information
976 ** (probably for debug reasons)
977 */
978 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
Alan Cox3d336aa2006-03-24 03:18:29 -0800979 if (copy_from_user(&PortReq, arg, sizeof(PortReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800980 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
981 p->RIOError.Error = COPYIN_FAILED;
982 return -EFAULT;
983 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Andrew Morton8d8706e2006-01-11 12:17:49 -0800985 if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
986 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
987 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
988 return -ENXIO;
989 }
990 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
Alan Cox3d336aa2006-03-24 03:18:29 -0800991 if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800992 p->RIOError.Error = COPYOUT_FAILED;
993 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
994 return -EFAULT;
995 }
996 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Andrew Morton8d8706e2006-01-11 12:17:49 -0800998 case RIO_HOST_RUP:
999 /*
1000 ** The daemon want rup information
1001 ** (probably for debug reasons)
1002 */
1003 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
Alan Cox3d336aa2006-03-24 03:18:29 -08001004 if (copy_from_user(&RupReq, arg, sizeof(RupReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001005 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1006 p->RIOError.Error = COPYIN_FAILED;
1007 return -EFAULT;
1008 }
1009 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1010 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
1011 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1012 return -ENXIO;
1013 }
1014 if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */
1015 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
1016 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1017 return -EINVAL;
1018 }
1019 HostP = &p->RIOHosts[RupReq.HostNum];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Andrew Morton8d8706e2006-01-11 12:17:49 -08001021 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1022 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
1023 p->RIOError.Error = HOST_NOT_RUNNING;
1024 return -EIO;
1025 }
1026 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Alan Cox3d336aa2006-03-24 03:18:29 -08001028 if (copy_to_user(HostP->UnixRups[RupReq.RupNum].RupP, RupReq.RupP, sizeof(struct RUP))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001029 p->RIOError.Error = COPYOUT_FAILED;
1030 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1031 return -EFAULT;
1032 }
1033 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
Andrew Morton8d8706e2006-01-11 12:17:49 -08001035 case RIO_HOST_LPB:
1036 /*
1037 ** The daemon want lpb information
1038 ** (probably for debug reasons)
1039 */
1040 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
Alan Cox3d336aa2006-03-24 03:18:29 -08001041 if (copy_from_user(&LpbReq, arg, sizeof(LpbReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001042 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1043 p->RIOError.Error = COPYIN_FAILED;
1044 return -EFAULT;
1045 }
1046 if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
1047 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
1048 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1049 return -ENXIO;
1050 }
1051 if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */
1052 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
1053 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1054 return -EINVAL;
1055 }
1056 HostP = &p->RIOHosts[LpbReq.Host];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Andrew Morton8d8706e2006-01-11 12:17:49 -08001058 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1059 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
1060 p->RIOError.Error = HOST_NOT_RUNNING;
1061 return -EIO;
1062 }
1063 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Alan Cox3d336aa2006-03-24 03:18:29 -08001065 if (copy_to_user(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001066 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1067 p->RIOError.Error = COPYOUT_FAILED;
1068 return -EFAULT;
1069 }
1070 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Andrew Morton8d8706e2006-01-11 12:17:49 -08001072 /*
1073 ** Here 3 IOCTL's that allow us to change the way in which
1074 ** rio logs errors. send them just to syslog or send them
1075 ** to both syslog and console or send them to just the console.
1076 **
1077 ** See RioStrBuf() in util.c for the other half.
1078 */
1079 case RIO_SYSLOG_ONLY:
1080 p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
1081 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Andrew Morton8d8706e2006-01-11 12:17:49 -08001083 case RIO_SYSLOG_CONS:
1084 p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */
1085 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Andrew Morton8d8706e2006-01-11 12:17:49 -08001087 case RIO_CONS_ONLY:
1088 p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
1089 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Andrew Morton8d8706e2006-01-11 12:17:49 -08001091 case RIO_SIGNALS_ON:
1092 if (p->RIOSignalProcess) {
1093 p->RIOError.Error = SIGNALS_ALREADY_SET;
1094 return -EBUSY;
1095 }
Alan Cox3d336aa2006-03-24 03:18:29 -08001096 /* FIXME: PID tracking */
1097 p->RIOSignalProcess = current->pid;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001098 p->RIOPrintDisabled = DONT_PRINT;
1099 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Andrew Morton8d8706e2006-01-11 12:17:49 -08001101 case RIO_SIGNALS_OFF:
Alan Cox3d336aa2006-03-24 03:18:29 -08001102 if (p->RIOSignalProcess != current->pid) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001103 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1104 return -EPERM;
1105 }
1106 rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
1107 p->RIOSignalProcess = 0;
1108 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Andrew Morton8d8706e2006-01-11 12:17:49 -08001110 case RIO_SET_BYTE_MODE:
1111 for (Host = 0; Host < p->RIONumHosts; Host++)
1112 if (p->RIOHosts[Host].Type == RIO_AT)
1113 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1114 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Andrew Morton8d8706e2006-01-11 12:17:49 -08001116 case RIO_SET_WORD_MODE:
1117 for (Host = 0; Host < p->RIONumHosts; Host++)
1118 if (p->RIOHosts[Host].Type == RIO_AT)
1119 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1120 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Andrew Morton8d8706e2006-01-11 12:17:49 -08001122 case RIO_SET_FAST_BUS:
1123 for (Host = 0; Host < p->RIONumHosts; Host++)
1124 if (p->RIOHosts[Host].Type == RIO_AT)
1125 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1126 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Andrew Morton8d8706e2006-01-11 12:17:49 -08001128 case RIO_SET_SLOW_BUS:
1129 for (Host = 0; Host < p->RIONumHosts; Host++)
1130 if (p->RIOHosts[Host].Type == RIO_AT)
1131 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1132 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Andrew Morton8d8706e2006-01-11 12:17:49 -08001134 case RIO_MAP_B50_TO_50:
1135 case RIO_MAP_B50_TO_57600:
1136 case RIO_MAP_B110_TO_110:
1137 case RIO_MAP_B110_TO_115200:
1138 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
Alan Cox3d336aa2006-03-24 03:18:29 -08001139 port = (unsigned long) arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001140 if (port < 0 || port > 511) {
1141 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1142 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1143 return -EINVAL;
1144 }
1145 rio_spin_lock_irqsave(&PortP->portSem, flags);
1146 switch (cmd) {
1147 case RIO_MAP_B50_TO_50:
1148 p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1149 break;
1150 case RIO_MAP_B50_TO_57600:
1151 p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1152 break;
1153 case RIO_MAP_B110_TO_110:
1154 p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1155 break;
1156 case RIO_MAP_B110_TO_115200:
1157 p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1158 break;
1159 }
1160 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1161 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Andrew Morton8d8706e2006-01-11 12:17:49 -08001163 case RIO_STREAM_INFO:
1164 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
1165 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Andrew Morton8d8706e2006-01-11 12:17:49 -08001167 case RIO_SEND_PACKET:
1168 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
Alan Cox3d336aa2006-03-24 03:18:29 -08001169 if (copy_from_user(&SendPack, arg, sizeof(SendPack))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001170 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1171 p->RIOError.Error = COPYIN_FAILED;
1172 return -EFAULT;
1173 }
1174 if (SendPack.PortNum >= 128) {
1175 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1176 return -ENXIO;
1177 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Andrew Morton8d8706e2006-01-11 12:17:49 -08001179 PortP = p->RIOPortp[SendPack.PortNum];
1180 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
Andrew Morton8d8706e2006-01-11 12:17:49 -08001182 if (!can_add_transmit(&PacketP, PortP)) {
1183 p->RIOError.Error = UNIT_IS_IN_USE;
1184 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1185 return -ENOSPC;
1186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Andrew Morton8d8706e2006-01-11 12:17:49 -08001188 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
Alan Cox3d336aa2006-03-24 03:18:29 -08001189 writeb(SendPack.Data[loop], &PacketP->data[loop]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Alan Cox3d336aa2006-03-24 03:18:29 -08001191 writeb(SendPack.Len, &PacketP->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Andrew Morton8d8706e2006-01-11 12:17:49 -08001193 add_transmit(PortP);
1194 /*
1195 ** Count characters transmitted for port statistics reporting
1196 */
1197 if (PortP->statsGather)
1198 PortP->txchars += (SendPack.Len & 127);
1199 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1200 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Andrew Morton8d8706e2006-01-11 12:17:49 -08001202 case RIO_NO_MESG:
1203 if (su)
1204 p->RIONoMessage = 1;
1205 return su ? 0 : -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Andrew Morton8d8706e2006-01-11 12:17:49 -08001207 case RIO_MESG:
1208 if (su)
1209 p->RIONoMessage = 0;
1210 return su ? 0 : -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Andrew Morton8d8706e2006-01-11 12:17:49 -08001212 case RIO_WHAT_MESG:
Alan Cox3d336aa2006-03-24 03:18:29 -08001213 if (copy_to_user(arg, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001214 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1215 p->RIOError.Error = COPYOUT_FAILED;
1216 return -EFAULT;
1217 }
1218 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
Andrew Morton8d8706e2006-01-11 12:17:49 -08001220 case RIO_MEM_DUMP:
Alan Cox3d336aa2006-03-24 03:18:29 -08001221 if (copy_from_user(&SubCmd, arg, sizeof(struct SubCmdStruct))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001222 p->RIOError.Error = COPYIN_FAILED;
1223 return -EFAULT;
1224 }
1225 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 -07001226
Andrew Morton8d8706e2006-01-11 12:17:49 -08001227 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1228 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1229 return -EINVAL;
1230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Andrew Morton8d8706e2006-01-11 12:17:49 -08001232 if (SubCmd.Host >= p->RIONumHosts) {
1233 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1234 return -EINVAL;
1235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Andrew Morton8d8706e2006-01-11 12:17:49 -08001237 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Andrew Morton8d8706e2006-01-11 12:17:49 -08001239 PortP = p->RIOPortp[port];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Andrew Morton8d8706e2006-01-11 12:17:49 -08001241 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Andrew Morton8d8706e2006-01-11 12:17:49 -08001243 if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) {
1244 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1245 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1246 return -EBUSY;
1247 } else
1248 PortP->State |= RIO_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Andrew Morton8d8706e2006-01-11 12:17:49 -08001250 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Alan Cox3d336aa2006-03-24 03:18:29 -08001251 if (copy_to_user(arg, p->RIOMemDump, MEMDUMP_SIZE)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001252 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1253 p->RIOError.Error = COPYOUT_FAILED;
1254 return -EFAULT;
1255 }
1256 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Andrew Morton8d8706e2006-01-11 12:17:49 -08001258 case RIO_TICK:
Alan Cox3d336aa2006-03-24 03:18:29 -08001259 if ((unsigned long) arg >= p->RIONumHosts)
Andrew Morton8d8706e2006-01-11 12:17:49 -08001260 return -EINVAL;
Alan Cox3d336aa2006-03-24 03:18:29 -08001261 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", (unsigned long) arg);
1262 writeb(0xFF, &p->RIOHosts[(unsigned long) arg].SetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001263 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Andrew Morton8d8706e2006-01-11 12:17:49 -08001265 case RIO_TOCK:
Alan Cox3d336aa2006-03-24 03:18:29 -08001266 if ((unsigned long) arg >= p->RIONumHosts)
Andrew Morton8d8706e2006-01-11 12:17:49 -08001267 return -EINVAL;
Alan Cox3d336aa2006-03-24 03:18:29 -08001268 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", (unsigned long) arg);
1269 writeb(0xFF, &p->RIOHosts[(unsigned long) arg].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001270 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Andrew Morton8d8706e2006-01-11 12:17:49 -08001272 case RIO_READ_CHECK:
1273 /* Check reads for pkts with data[0] the same */
1274 p->RIOReadCheck = !p->RIOReadCheck;
Alan Cox3d336aa2006-03-24 03:18:29 -08001275 if (copy_to_user(arg, &p->RIOReadCheck, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001276 p->RIOError.Error = COPYOUT_FAILED;
1277 return -EFAULT;
1278 }
1279 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Andrew Morton8d8706e2006-01-11 12:17:49 -08001281 case RIO_READ_REGISTER:
Alan Cox3d336aa2006-03-24 03:18:29 -08001282 if (copy_from_user(&SubCmd, arg, sizeof(struct SubCmdStruct))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001283 p->RIOError.Error = COPYIN_FAILED;
1284 return -EFAULT;
1285 }
1286 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER host %d rup %d port %d reg %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Port, SubCmd.Addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Andrew Morton8d8706e2006-01-11 12:17:49 -08001288 if (SubCmd.Port > 511) {
1289 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
1290 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1291 return -EINVAL;
1292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Andrew Morton8d8706e2006-01-11 12:17:49 -08001294 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1295 p->RIOError.Error = RUP_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.Host >= p->RIONumHosts) {
1300 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1301 return -EINVAL;
1302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Andrew Morton8d8706e2006-01-11 12:17:49 -08001304 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1305 PortP = p->RIOPortp[port];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Andrew Morton8d8706e2006-01-11 12:17:49 -08001307 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Andrew Morton8d8706e2006-01-11 12:17:49 -08001309 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
1310 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1311 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1312 return -EBUSY;
1313 } else
1314 PortP->State |= RIO_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Andrew Morton8d8706e2006-01-11 12:17:49 -08001316 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Alan Cox3d336aa2006-03-24 03:18:29 -08001317 if (copy_to_user(arg, &p->CdRegister, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001318 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1319 p->RIOError.Error = COPYOUT_FAILED;
1320 return -EFAULT;
1321 }
1322 return 0;
1323 /*
1324 ** rio_make_dev: given port number (0-511) ORed with port type
1325 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1326 ** value to pass to mknod to create the correct device node.
1327 */
1328 case RIO_MAKE_DEV:
1329 {
Alan Cox3d336aa2006-03-24 03:18:29 -08001330 unsigned int port = (unsigned long) arg & RIO_MODEM_MASK;
1331 unsigned int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Alan Cox3d336aa2006-03-24 03:18:29 -08001333 switch ((unsigned long) arg & RIO_DEV_MASK) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001334 case RIO_DEV_DIRECT:
Alan Cox3d336aa2006-03-24 03:18:29 -08001335 ret = drv_makedev(MAJOR(dev), port);
1336 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
1337 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001338 case RIO_DEV_MODEM:
Alan Cox3d336aa2006-03-24 03:18:29 -08001339 ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1340 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
1341 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001342 case RIO_DEV_XPRINT:
Alan Cox3d336aa2006-03-24 03:18:29 -08001343 ret = drv_makedev(MAJOR(dev), port);
1344 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
1345 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001346 }
1347 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1348 return -EINVAL;
1349 }
1350 /*
1351 ** rio_minor: given a dev_t from a stat() call, return
1352 ** the port number (0-511) ORed with the port type
1353 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1354 */
1355 case RIO_MINOR:
1356 {
1357 dev_t dv;
1358 int mino;
Alan Cox3d336aa2006-03-24 03:18:29 -08001359 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Alan Cox3d336aa2006-03-24 03:18:29 -08001361 dv = (dev_t) ((unsigned long) arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001362 mino = RIO_UNMODEM(dv);
1363
1364 if (RIO_ISMODEM(dv)) {
1365 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
Alan Cox3d336aa2006-03-24 03:18:29 -08001366 ret = mino | RIO_DEV_MODEM;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001367 } else {
1368 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
Alan Cox3d336aa2006-03-24 03:18:29 -08001369 ret = mino | RIO_DEV_DIRECT;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001370 }
Alan Cox3d336aa2006-03-24 03:18:29 -08001371 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 }
Andrew Morton8d8706e2006-01-11 12:17:49 -08001374 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1376
Andrew Morton8d8706e2006-01-11 12:17:49 -08001377 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 return -EINVAL;
1379}
1380
1381/*
1382** Pre-emptive commands go on RUPs and are only one byte long.
1383*/
Alan Cox3d336aa2006-03-24 03:18:29 -08001384int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385{
1386 struct CmdBlk *CmdBlkP;
1387 struct PktCmd_M *PktCmdP;
1388 int Ret;
1389 ushort rup;
1390 int port;
1391
Andrew Morton8d8706e2006-01-11 12:17:49 -08001392 if (PortP->State & RIO_DELETED) {
1393 rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 return RIO_FAIL;
1395 }
1396
Andrew Morton8d8706e2006-01-11 12:17:49 -08001397 if (((int) ((char) PortP->InUse) == -1) || !(CmdBlkP = RIOGetCmdBlk())) {
1398 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 -07001399 return RIO_FAIL;
1400 }
1401
Alan Cox554b7c82006-03-24 03:18:32 -08001402 rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n", CmdBlkP, PortP->InUse);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Andrew Morton8d8706e2006-01-11 12:17:49 -08001404 PktCmdP = (struct PktCmd_M *) &CmdBlkP->Packet.data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Andrew Morton8d8706e2006-01-11 12:17:49 -08001406 CmdBlkP->Packet.src_unit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 if (PortP->SecondBlock)
1408 rup = PortP->ID2;
1409 else
1410 rup = PortP->RupNum;
1411 CmdBlkP->Packet.dest_unit = rup;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001412 CmdBlkP->Packet.src_port = COMMAND_RUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 CmdBlkP->Packet.dest_port = COMMAND_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001414 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1415 CmdBlkP->PostFuncP = RIOUnUse;
Alan Cox3d336aa2006-03-24 03:18:29 -08001416 CmdBlkP->PostArg = (unsigned long) PortP;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001417 PktCmdP->Command = Cmd;
1418 port = PortP->HostPort % (ushort) PORTS_PER_RTA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -08001420 ** Index ports 8-15 for 2nd block of 16 port RTA.
1421 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 if (PortP->SecondBlock)
1423 port += (ushort) PORTS_PER_RTA;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001424 PktCmdP->PhbNum = port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Andrew Morton8d8706e2006-01-11 12:17:49 -08001426 switch (Cmd) {
1427 case MEMDUMP:
Alan Cox554b7c82006-03-24 03:18:32 -08001428 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p (addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001429 PktCmdP->SubCommand = MEMDUMP;
1430 PktCmdP->SubAddr = SubCmd.Addr;
1431 break;
1432 case FCLOSE:
Alan Cox554b7c82006-03-24 03:18:32 -08001433 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001434 break;
1435 case READ_REGISTER:
Alan Cox554b7c82006-03-24 03:18:32 -08001436 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001437 PktCmdP->SubCommand = READ_REGISTER;
1438 PktCmdP->SubAddr = SubCmd.Addr;
1439 break;
1440 case RESUME:
Alan Cox554b7c82006-03-24 03:18:32 -08001441 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001442 break;
1443 case RFLUSH:
Alan Cox554b7c82006-03-24 03:18:32 -08001444 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001445 CmdBlkP->PostFuncP = RIORFlushEnable;
1446 break;
1447 case SUSPEND:
Alan Cox554b7c82006-03-24 03:18:32 -08001448 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001449 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Andrew Morton8d8706e2006-01-11 12:17:49 -08001451 case MGET:
Alan Cox554b7c82006-03-24 03:18:32 -08001452 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001453 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Andrew Morton8d8706e2006-01-11 12:17:49 -08001455 case MSET:
1456 case MBIC:
1457 case MBIS:
1458 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
Alan Cox554b7c82006-03-24 03:18:32 -08001459 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001460 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Andrew Morton8d8706e2006-01-11 12:17:49 -08001462 case WFLUSH:
1463 /*
1464 ** If we have queued up the maximum number of Write flushes
1465 ** allowed then we should not bother sending any more to the
1466 ** RTA.
1467 */
1468 if ((int) ((char) PortP->WflushFlag) == (int) -1) {
1469 rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, WflushFlag about to wrap!");
1470 RIOFreeCmdBlk(CmdBlkP);
1471 return (RIO_FAIL);
1472 } else {
Alan Cox554b7c82006-03-24 03:18:32 -08001473 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001474 CmdBlkP->PostFuncP = RIOWFlushMark;
1475 }
1476 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 }
1478
1479 PortP->InUse++;
1480
Andrew Morton8d8706e2006-01-11 12:17:49 -08001481 Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
1483 return Ret;
1484}