blob: 7ce77619707cf2f4fa1db2480d1acaebaf968ca9 [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;
Al Virod886cb52006-05-27 00:08:25 -040083static struct HostReq HostReq; /* oh really? global? and no locking? */
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
Al Viro06458192006-05-27 02:11:12 -0400129static int copy_from_io(void __user *to, void __iomem *from, size_t size)
130{
131 void *buf = kmalloc(size, GFP_KERNEL);
132 int res = -ENOMEM;
133 if (buf) {
134 rio_memcpy_fromio(buf, from, size);
135 res = copy_to_user(to, buf, size);
136 kfree(buf);
137 }
138 return res;
139}
140
Al Virod886cb52006-05-27 00:08:25 -0400141int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800143 uint Host; /* leave me unsigned! */
144 uint port; /* and me! */
145 struct Host *HostP;
146 ushort loop;
147 int Entry;
148 struct Port *PortP;
Al Virod886cb52006-05-27 00:08:25 -0400149 struct PKT __iomem *PacketP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800150 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 unsigned long flags;
Al Virod886cb52006-05-27 00:08:25 -0400152 void __user *argp = (void __user *)arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800153
154 func_enter();
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 /* Confuse the compiler to think that we've initialized these */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800157 Host = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 PortP = NULL;
159
Al Virod886cb52006-05-27 00:08:25 -0400160 rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 switch (cmd) {
163 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800164 ** RIO_SET_TIMER
165 **
166 ** Change the value of the host card interrupt timer.
167 ** If the host card number is -1 then all host cards are changed
168 ** otherwise just the specified host card will be changed.
169 */
170 case RIO_SET_TIMER:
Al Virod886cb52006-05-27 00:08:25 -0400171 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800172 {
173 int host, value;
Al Virod886cb52006-05-27 00:08:25 -0400174 host = (arg >> 16) & 0x0000FFFF;
175 value = arg & 0x0000ffff;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800176 if (host == -1) {
177 for (host = 0; host < p->RIONumHosts; host++) {
178 if (p->RIOHosts[host].Flags == RC_RUNNING) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800179 writew(value, &p->RIOHosts[host].ParmMapP->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 }
181 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800182 } else if (host >= p->RIONumHosts) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return -EINVAL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800184 } else {
185 if (p->RIOHosts[host].Flags == RC_RUNNING) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800186 writew(value, &p->RIOHosts[host].ParmMapP->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800188 }
189 }
190 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Andrew Morton8d8706e2006-01-11 12:17:49 -0800192 case RIO_FOAD_RTA:
193 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
Al Virod886cb52006-05-27 00:08:25 -0400194 return RIOCommandRta(p, arg, RIOFoadRta);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800195
196 case RIO_ZOMBIE_RTA:
197 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
Al Virod886cb52006-05-27 00:08:25 -0400198 return RIOCommandRta(p, arg, RIOZombieRta);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800199
200 case RIO_IDENTIFY_RTA:
201 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
Al Virod886cb52006-05-27 00:08:25 -0400202 return RIOIdentifyRta(p, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800203
204 case RIO_KILL_NEIGHBOUR:
205 rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
Al Virod886cb52006-05-27 00:08:25 -0400206 return RIOKillNeighbour(p, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800207
208 case SPECIAL_RUP_CMD:
209 {
210 struct CmdBlk *CmdBlkP;
211
212 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
Al Virod886cb52006-05-27 00:08:25 -0400213 if (copy_from_user(&SpecialRupCmd, argp, sizeof(SpecialRupCmd))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800214 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
215 p->RIOError.Error = COPYIN_FAILED;
216 return -EFAULT;
217 }
218 CmdBlkP = RIOGetCmdBlk();
219 if (!CmdBlkP) {
220 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
221 return -ENXIO;
222 }
223 CmdBlkP->Packet = SpecialRupCmd.Packet;
224 if (SpecialRupCmd.Host >= p->RIONumHosts)
225 SpecialRupCmd.Host = 0;
226 rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
227 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800228 printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800229 }
230 return 0;
231 }
232
233 case RIO_DEBUG_MEM:
Alan Coxf4caf162006-01-16 17:27:38 +0000234 return -EPERM;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800235
236 case RIO_ALL_MODEM:
237 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
238 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
239 return -EINVAL;
240
241 case RIO_GET_TABLE:
242 /*
243 ** Read the routing table from the device driver to user space
244 */
245 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
246
247 if ((retval = RIOApel(p)) != 0)
248 return retval;
249
Al Virod886cb52006-05-27 00:08:25 -0400250 if (copy_to_user(argp, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800251 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
252 p->RIOError.Error = COPYOUT_FAILED;
253 return -EFAULT;
254 }
255
256 {
257 int entry;
258 rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
259 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
260 if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
261 continue;
262
263 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
264 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
265 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
266 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
267 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
268 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
269 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
270 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
271 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
272 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
273 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
274 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
275 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
276 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
277 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
278 }
279 rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
280 }
281 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
282 return 0;
283
284 case RIO_PUT_TABLE:
285 /*
286 ** Write the routing table to the device driver from user space
287 */
288 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
289
290 if (!su) {
291 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
292 p->RIOError.Error = NOT_SUPER_USER;
293 return -EPERM;
294 }
Al Virod886cb52006-05-27 00:08:25 -0400295 if (copy_from_user(&p->RIOConnectTable[0], argp, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800296 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
297 p->RIOError.Error = COPYIN_FAILED;
298 return -EFAULT;
299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300/*
301***********************************
302 {
303 int entry;
304 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
305 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
306 {
307 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
308 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
309 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
310 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
311 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
312 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
313 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
314 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
315 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
316 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
317 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
318 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
319 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
320 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
321 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
322 }
323 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
324 }
325***********************************
326*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800327 return RIONewTable(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Andrew Morton8d8706e2006-01-11 12:17:49 -0800329 case RIO_GET_BINDINGS:
330 /*
331 ** Send bindings table, containing unique numbers of RTAs owned
332 ** by this system to user space
333 */
334 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Andrew Morton8d8706e2006-01-11 12:17:49 -0800336 if (!su) {
337 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
338 p->RIOError.Error = NOT_SUPER_USER;
339 return -EPERM;
340 }
Al Virod886cb52006-05-27 00:08:25 -0400341 if (copy_to_user(argp, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800342 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
343 p->RIOError.Error = COPYOUT_FAILED;
344 return -EFAULT;
345 }
346 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Andrew Morton8d8706e2006-01-11 12:17:49 -0800348 case RIO_PUT_BINDINGS:
349 /*
350 ** Receive a bindings table, containing unique numbers of RTAs owned
351 ** by this system
352 */
353 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
354
355 if (!su) {
356 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
357 p->RIOError.Error = NOT_SUPER_USER;
358 return -EPERM;
359 }
Al Virod886cb52006-05-27 00:08:25 -0400360 if (copy_from_user(&p->RIOBindTab[0], argp, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800361 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
362 p->RIOError.Error = COPYIN_FAILED;
363 return -EFAULT;
364 }
365 return 0;
366
367 case RIO_BIND_RTA:
368 {
369 int EmptySlot = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800371 ** Bind this RTA to host, so that it will be booted by
372 ** host in 'boot owned RTAs' mode.
373 */
374 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Andrew Morton8d8706e2006-01-11 12:17:49 -0800376 if (!su) {
377 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
378 p->RIOError.Error = NOT_SUPER_USER;
379 return -EPERM;
380 }
381 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
382 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
383 EmptySlot = Entry;
Al Virod886cb52006-05-27 00:08:25 -0400384 else if (p->RIOBindTab[Entry] == arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800386 ** Already exists - delete
387 */
388 p->RIOBindTab[Entry] = 0L;
Al Virod886cb52006-05-27 00:08:25 -0400389 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return 0;
391 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800394 ** Dosen't exist - add
395 */
396 if (EmptySlot != -1) {
Al Virod886cb52006-05-27 00:08:25 -0400397 p->RIOBindTab[EmptySlot] = arg;
398 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800399 } else {
Al Virod886cb52006-05-27 00:08:25 -0400400 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800401 return -ENOMEM;
402 }
403 return 0;
404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Andrew Morton8d8706e2006-01-11 12:17:49 -0800406 case RIO_RESUME:
407 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
Al Virod886cb52006-05-27 00:08:25 -0400408 port = arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800409 if ((port < 0) || (port > 511)) {
410 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
411 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
412 return -EINVAL;
413 }
414 PortP = p->RIOPortp[port];
415 if (!PortP->Mapped) {
416 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
417 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
418 return -EINVAL;
419 }
420 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
421 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
422 return -EINVAL;
423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Andrew Morton8d8706e2006-01-11 12:17:49 -0800425 rio_spin_lock_irqsave(&PortP->portSem, flags);
426 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) {
427 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
428 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
429 return -EBUSY;
430 } else {
431 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
432 PortP->State |= RIO_BUSY;
433 }
434 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
435 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Andrew Morton8d8706e2006-01-11 12:17:49 -0800437 case RIO_ASSIGN_RTA:
438 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
439 if (!su) {
440 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
441 p->RIOError.Error = NOT_SUPER_USER;
442 return -EPERM;
443 }
Al Virod886cb52006-05-27 00:08:25 -0400444 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800445 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
446 p->RIOError.Error = COPYIN_FAILED;
447 return -EFAULT;
448 }
449 return RIOAssignRta(p, &MapEnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Andrew Morton8d8706e2006-01-11 12:17:49 -0800451 case RIO_CHANGE_NAME:
452 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
453 if (!su) {
454 rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
455 p->RIOError.Error = NOT_SUPER_USER;
456 return -EPERM;
457 }
Al Virod886cb52006-05-27 00:08:25 -0400458 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800459 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
460 p->RIOError.Error = COPYIN_FAILED;
461 return -EFAULT;
462 }
463 return RIOChangeName(p, &MapEnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Andrew Morton8d8706e2006-01-11 12:17:49 -0800465 case RIO_DELETE_RTA:
466 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
467 if (!su) {
468 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
469 p->RIOError.Error = NOT_SUPER_USER;
470 return -EPERM;
471 }
Al Virod886cb52006-05-27 00:08:25 -0400472 if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800473 rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
474 p->RIOError.Error = COPYIN_FAILED;
475 return -EFAULT;
476 }
477 return RIODeleteRta(p, &MapEnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Andrew Morton8d8706e2006-01-11 12:17:49 -0800479 case RIO_QUICK_CHECK:
Al Virod886cb52006-05-27 00:08:25 -0400480 if (copy_to_user(argp, &p->RIORtaDisCons, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800481 p->RIOError.Error = COPYOUT_FAILED;
482 return -EFAULT;
483 }
484 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Andrew Morton8d8706e2006-01-11 12:17:49 -0800486 case RIO_LAST_ERROR:
Al Virod886cb52006-05-27 00:08:25 -0400487 if (copy_to_user(argp, &p->RIOError, sizeof(struct Error)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800488 return -EFAULT;
489 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Andrew Morton8d8706e2006-01-11 12:17:49 -0800491 case RIO_GET_LOG:
492 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800493 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Andrew Morton8d8706e2006-01-11 12:17:49 -0800495 case RIO_GET_MODTYPE:
Al Virod886cb52006-05-27 00:08:25 -0400496 if (copy_from_user(&port, argp, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800497 p->RIOError.Error = COPYIN_FAILED;
498 return -EFAULT;
499 }
500 rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
501 if (port < 0 || port > 511) {
502 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
503 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
504 return -EINVAL;
505 }
506 PortP = (p->RIOPortp[port]);
507 if (!PortP->Mapped) {
508 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
509 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
510 return -EINVAL;
511 }
512 /*
513 ** Return module type of port
514 */
515 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
Al Virod886cb52006-05-27 00:08:25 -0400516 if (copy_to_user(argp, &port, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800517 p->RIOError.Error = COPYOUT_FAILED;
518 return -EFAULT;
519 }
520 return (0);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800521 case RIO_BLOCK_OPENS:
522 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
523 for (Entry = 0; Entry < RIO_PORTS; Entry++) {
524 rio_spin_lock_irqsave(&PortP->portSem, flags);
525 p->RIOPortp[Entry]->WaitUntilBooted = 1;
526 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
527 }
528 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Andrew Morton8d8706e2006-01-11 12:17:49 -0800530 case RIO_SETUP_PORTS:
531 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
Al Virod886cb52006-05-27 00:08:25 -0400532 if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800533 p->RIOError.Error = COPYIN_FAILED;
534 rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
535 return -EFAULT;
536 }
537 if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
538 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
539 rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
540 return -ENXIO;
541 }
542 if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
543 p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
544 rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
545 return -EINVAL;
546 }
547 if (!p->RIOPortp) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800548 printk(KERN_ERR "rio: No p->RIOPortp array!\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800549 rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
550 return -EIO;
551 }
552 rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
553 for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
554 rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800555 }
556 rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
557 rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
558 return retval;
559
560 case RIO_GET_PORT_SETUP:
561 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
Al Virod886cb52006-05-27 00:08:25 -0400562 if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800563 p->RIOError.Error = COPYIN_FAILED;
564 return -EFAULT;
565 }
566 if (PortSetup.From >= RIO_PORTS) {
567 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
568 return -ENXIO;
569 }
570
571 port = PortSetup.To = PortSetup.From;
572 PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
573 PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
574 PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
575 PortSetup.Store = p->RIOPortp[port]->Store;
576 PortSetup.Lock = p->RIOPortp[port]->Lock;
577 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
Alan Cox554b7c82006-03-24 03:18:32 -0800578 memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN);
579 memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800580 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
581 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
582
Al Virod886cb52006-05-27 00:08:25 -0400583 if (copy_to_user(argp, &PortSetup, sizeof(PortSetup))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800584 p->RIOError.Error = COPYOUT_FAILED;
585 return -EFAULT;
586 }
587 return retval;
588
589 case RIO_GET_PORT_PARAMS:
590 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
Al Virod886cb52006-05-27 00:08:25 -0400591 if (copy_from_user(&PortParams, argp, sizeof(struct PortParams))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800592 p->RIOError.Error = COPYIN_FAILED;
593 return -EFAULT;
594 }
595 if (PortParams.Port >= RIO_PORTS) {
596 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
597 return -ENXIO;
598 }
599 PortP = (p->RIOPortp[PortParams.Port]);
600 PortParams.Config = PortP->Config;
601 PortParams.State = PortP->State;
602 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
603
Al Virod886cb52006-05-27 00:08:25 -0400604 if (copy_to_user(argp, &PortParams, sizeof(struct PortParams))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800605 p->RIOError.Error = COPYOUT_FAILED;
606 return -EFAULT;
607 }
608 return retval;
609
610 case RIO_GET_PORT_TTY:
611 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
Al Virod886cb52006-05-27 00:08:25 -0400612 if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800613 p->RIOError.Error = COPYIN_FAILED;
614 return -EFAULT;
615 }
616 if (PortTty.port >= RIO_PORTS) {
617 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
618 return -ENXIO;
619 }
620
621 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
622 PortP = (p->RIOPortp[PortTty.port]);
Al Virod886cb52006-05-27 00:08:25 -0400623 if (copy_to_user(argp, &PortTty, sizeof(struct PortTty))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800624 p->RIOError.Error = COPYOUT_FAILED;
625 return -EFAULT;
626 }
627 return retval;
628
629 case RIO_SET_PORT_TTY:
Al Virod886cb52006-05-27 00:08:25 -0400630 if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800631 p->RIOError.Error = COPYIN_FAILED;
632 return -EFAULT;
633 }
634 rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
635 if (PortTty.port >= (ushort) RIO_PORTS) {
636 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
637 return -ENXIO;
638 }
639 PortP = (p->RIOPortp[PortTty.port]);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800640 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
641 return retval;
642
643 case RIO_SET_PORT_PARAMS:
644 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
Al Virod886cb52006-05-27 00:08:25 -0400645 if (copy_from_user(&PortParams, argp, sizeof(PortParams))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800646 p->RIOError.Error = COPYIN_FAILED;
647 return -EFAULT;
648 }
649 if (PortParams.Port >= (ushort) RIO_PORTS) {
650 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
651 return -ENXIO;
652 }
653 PortP = (p->RIOPortp[PortParams.Port]);
654 rio_spin_lock_irqsave(&PortP->portSem, flags);
655 PortP->Config = PortParams.Config;
656 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
657 return retval;
658
659 case RIO_GET_PORT_STATS:
660 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
Al Virod886cb52006-05-27 00:08:25 -0400661 if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800662 p->RIOError.Error = COPYIN_FAILED;
663 return -EFAULT;
664 }
Alan Cox9d90daf2006-10-16 16:28:44 +0100665 if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800666 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
667 return -ENXIO;
668 }
669 PortP = (p->RIOPortp[portStats.port]);
670 portStats.gather = PortP->statsGather;
671 portStats.txchars = PortP->txchars;
672 portStats.rxchars = PortP->rxchars;
673 portStats.opens = PortP->opens;
674 portStats.closes = PortP->closes;
675 portStats.ioctls = PortP->ioctls;
Al Virod886cb52006-05-27 00:08:25 -0400676 if (copy_to_user(argp, &portStats, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800677 p->RIOError.Error = COPYOUT_FAILED;
678 return -EFAULT;
679 }
680 return retval;
681
682 case RIO_RESET_PORT_STATS:
Al Virod886cb52006-05-27 00:08:25 -0400683 port = arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800684 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
685 if (port >= RIO_PORTS) {
686 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
687 return -ENXIO;
688 }
689 PortP = (p->RIOPortp[port]);
690 rio_spin_lock_irqsave(&PortP->portSem, flags);
691 PortP->txchars = 0;
692 PortP->rxchars = 0;
693 PortP->opens = 0;
694 PortP->closes = 0;
695 PortP->ioctls = 0;
696 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
697 return retval;
698
699 case RIO_GATHER_PORT_STATS:
700 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
Al Virod886cb52006-05-27 00:08:25 -0400701 if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800702 p->RIOError.Error = COPYIN_FAILED;
703 return -EFAULT;
704 }
Alan Cox9d90daf2006-10-16 16:28:44 +0100705 if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800706 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
707 return -ENXIO;
708 }
709 PortP = (p->RIOPortp[portStats.port]);
710 rio_spin_lock_irqsave(&PortP->portSem, flags);
711 PortP->statsGather = portStats.gather;
712 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
713 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Andrew Morton8d8706e2006-01-11 12:17:49 -0800715 case RIO_READ_CONFIG:
716 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
Al Virod886cb52006-05-27 00:08:25 -0400717 if (copy_to_user(argp, &p->RIOConf, sizeof(struct Conf))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800718 p->RIOError.Error = COPYOUT_FAILED;
719 return -EFAULT;
720 }
721 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Andrew Morton8d8706e2006-01-11 12:17:49 -0800723 case RIO_SET_CONFIG:
724 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
725 if (!su) {
726 p->RIOError.Error = NOT_SUPER_USER;
727 return -EPERM;
728 }
Al Virod886cb52006-05-27 00:08:25 -0400729 if (copy_from_user(&p->RIOConf, argp, sizeof(struct Conf))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800730 p->RIOError.Error = COPYIN_FAILED;
731 return -EFAULT;
732 }
733 /*
734 ** move a few value around
735 */
736 for (Host = 0; Host < p->RIONumHosts; Host++)
737 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
Alan Cox3d336aa2006-03-24 03:18:29 -0800738 writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800739 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Andrew Morton8d8706e2006-01-11 12:17:49 -0800741 case RIO_START_POLLER:
742 rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
743 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Andrew Morton8d8706e2006-01-11 12:17:49 -0800745 case RIO_STOP_POLLER:
746 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
747 if (!su) {
748 p->RIOError.Error = NOT_SUPER_USER;
749 return -EPERM;
750 }
751 p->RIOPolling = NOT_POLLING;
752 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Andrew Morton8d8706e2006-01-11 12:17:49 -0800754 case RIO_SETDEBUG:
755 case RIO_GETDEBUG:
756 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
Al Virod886cb52006-05-27 00:08:25 -0400757 if (copy_from_user(&DebugCtrl, argp, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800758 p->RIOError.Error = COPYIN_FAILED;
759 return -EFAULT;
760 }
761 if (DebugCtrl.SysPort == NO_PORT) {
762 if (cmd == RIO_SETDEBUG) {
763 if (!su) {
764 p->RIOError.Error = NOT_SUPER_USER;
765 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800767 p->rio_debug = DebugCtrl.Debug;
768 p->RIODebugWait = DebugCtrl.Wait;
769 rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
770 } else {
771 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
772 DebugCtrl.Debug = p->rio_debug;
773 DebugCtrl.Wait = p->RIODebugWait;
Al Virod886cb52006-05-27 00:08:25 -0400774 if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800775 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
776 p->RIOError.Error = COPYOUT_FAILED;
777 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800779 }
780 } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
781 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
782 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
783 return -ENXIO;
784 } else if (cmd == RIO_SETDEBUG) {
785 if (!su) {
786 p->RIOError.Error = NOT_SUPER_USER;
787 return -EPERM;
788 }
789 rio_spin_lock_irqsave(&PortP->portSem, flags);
790 p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
791 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
792 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
793 } else {
794 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
795 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
Al Virod886cb52006-05-27 00:08:25 -0400796 if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800797 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
798 p->RIOError.Error = COPYOUT_FAILED;
799 return -EFAULT;
800 }
801 }
802 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Andrew Morton8d8706e2006-01-11 12:17:49 -0800804 case RIO_VERSID:
805 /*
806 ** Enquire about the release and version.
807 ** We return MAX_VERSION_LEN bytes, being a
808 ** textual null terminated string.
809 */
810 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
Al Virod886cb52006-05-27 00:08:25 -0400811 if (copy_to_user(argp, RIOVersid(), sizeof(struct rioVersion))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800812 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
813 p->RIOError.Error = COPYOUT_FAILED;
814 return -EFAULT;
815 }
816 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Andrew Morton8d8706e2006-01-11 12:17:49 -0800818 case RIO_NUM_HOSTS:
819 /*
820 ** Enquire as to the number of hosts located
821 ** at init time.
822 */
823 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
Al Virod886cb52006-05-27 00:08:25 -0400824 if (copy_to_user(argp, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800825 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
826 p->RIOError.Error = COPYOUT_FAILED;
827 return -EFAULT;
828 }
829 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Andrew Morton8d8706e2006-01-11 12:17:49 -0800831 case RIO_HOST_FOAD:
832 /*
833 ** Kill host. This may not be in the final version...
834 */
Al Virod886cb52006-05-27 00:08:25 -0400835 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800836 if (!su) {
837 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
838 p->RIOError.Error = NOT_SUPER_USER;
839 return -EPERM;
840 }
841 p->RIOHalted = 1;
842 p->RIOSystemUp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Andrew Morton8d8706e2006-01-11 12:17:49 -0800844 for (Host = 0; Host < p->RIONumHosts; Host++) {
845 (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
Alan Cox3d336aa2006-03-24 03:18:29 -0800846 memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800847 p->RIOHosts[Host].Flags = RC_WAITING;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800848 }
849 RIOFoadWakeup(p);
850 p->RIONumBootPkts = 0;
851 p->RIOBooting = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800852 printk("HEEEEELP!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Andrew Morton8d8706e2006-01-11 12:17:49 -0800854 for (loop = 0; loop < RIO_PORTS; loop++) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800855 spin_lock_init(&p->RIOPortp[loop]->portSem);
856 p->RIOPortp[loop]->InUse = NOT_INUSE;
857 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Andrew Morton8d8706e2006-01-11 12:17:49 -0800859 p->RIOSystemUp = 0;
860 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Andrew Morton8d8706e2006-01-11 12:17:49 -0800862 case RIO_DOWNLOAD:
863 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
864 if (!su) {
865 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
866 p->RIOError.Error = NOT_SUPER_USER;
867 return -EPERM;
868 }
Al Virod886cb52006-05-27 00:08:25 -0400869 if (copy_from_user(&DownLoad, argp, sizeof(DownLoad))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800870 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
871 p->RIOError.Error = COPYIN_FAILED;
872 return -EFAULT;
873 }
874 rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Andrew Morton8d8706e2006-01-11 12:17:49 -0800876 /*
877 ** It is important that the product code is an unsigned object!
878 */
879 if (DownLoad.ProductCode > MAX_PRODUCT) {
880 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
881 p->RIOError.Error = NO_SUCH_PRODUCT;
882 return -ENXIO;
883 }
884 /*
885 ** do something!
886 */
887 retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
888 /* <-- Panic */
889 p->RIOHalted = 0;
890 /*
891 ** and go back, content with a job well completed.
892 */
893 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Andrew Morton8d8706e2006-01-11 12:17:49 -0800895 case RIO_PARMS:
896 {
Alan Cox3d336aa2006-03-24 03:18:29 -0800897 unsigned int host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Al Virod886cb52006-05-27 00:08:25 -0400899 if (copy_from_user(&host, argp, sizeof(host))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800900 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
901 p->RIOError.Error = COPYIN_FAILED;
902 return -EFAULT;
903 }
904 /*
905 ** Fetch the parmmap
906 */
907 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
Al Viro06458192006-05-27 02:11:12 -0400908 if (copy_from_io(argp, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800909 p->RIOError.Error = COPYOUT_FAILED;
910 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
911 return -EFAULT;
912 }
913 }
914 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Andrew Morton8d8706e2006-01-11 12:17:49 -0800916 case RIO_HOST_REQ:
917 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
Al Virod886cb52006-05-27 00:08:25 -0400918 if (copy_from_user(&HostReq, argp, sizeof(HostReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800919 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
920 p->RIOError.Error = COPYIN_FAILED;
921 return -EFAULT;
922 }
923 if (HostReq.HostNum >= p->RIONumHosts) {
924 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
925 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
926 return -ENXIO;
927 }
928 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Alan Cox3d336aa2006-03-24 03:18:29 -0800930 if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800931 p->RIOError.Error = COPYOUT_FAILED;
932 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
933 return -EFAULT;
934 }
935 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
Andrew Morton8d8706e2006-01-11 12:17:49 -0800937 case RIO_HOST_DPRAM:
938 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
Al Virod886cb52006-05-27 00:08:25 -0400939 if (copy_from_user(&HostDpRam, argp, sizeof(HostDpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800940 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
941 p->RIOError.Error = COPYIN_FAILED;
942 return -EFAULT;
943 }
944 if (HostDpRam.HostNum >= p->RIONumHosts) {
945 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
946 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
947 return -ENXIO;
948 }
949 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Andrew Morton8d8706e2006-01-11 12:17:49 -0800951 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
952 int off;
953 /* It's hardware like this that really gets on my tits. */
954 static unsigned char copy[sizeof(struct DpRam)];
955 for (off = 0; off < sizeof(struct DpRam); off++)
Al Virod886cb52006-05-27 00:08:25 -0400956 copy[off] = readb(p->RIOHosts[HostDpRam.HostNum].Caddr + off);
Alan Cox3d336aa2006-03-24 03:18:29 -0800957 if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800958 p->RIOError.Error = COPYOUT_FAILED;
959 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
960 return -EFAULT;
961 }
Al Viro06458192006-05-27 02:11:12 -0400962 } else if (copy_from_io(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800963 p->RIOError.Error = COPYOUT_FAILED;
964 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
965 return -EFAULT;
966 }
967 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Andrew Morton8d8706e2006-01-11 12:17:49 -0800969 case RIO_SET_BUSY:
970 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
Al Virod886cb52006-05-27 00:08:25 -0400971 if (arg > 511) {
972 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800973 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
974 return -EINVAL;
975 }
976 rio_spin_lock_irqsave(&PortP->portSem, flags);
Al Virod886cb52006-05-27 00:08:25 -0400977 p->RIOPortp[arg]->State |= RIO_BUSY;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800978 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
979 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Andrew Morton8d8706e2006-01-11 12:17:49 -0800981 case RIO_HOST_PORT:
982 /*
983 ** The daemon want port information
984 ** (probably for debug reasons)
985 */
986 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
Al Virod886cb52006-05-27 00:08:25 -0400987 if (copy_from_user(&PortReq, argp, sizeof(PortReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800988 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
989 p->RIOError.Error = COPYIN_FAILED;
990 return -EFAULT;
991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
Andrew Morton8d8706e2006-01-11 12:17:49 -0800993 if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
994 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
995 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
996 return -ENXIO;
997 }
998 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
Alan Cox3d336aa2006-03-24 03:18:29 -0800999 if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001000 p->RIOError.Error = COPYOUT_FAILED;
1001 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
1002 return -EFAULT;
1003 }
1004 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Andrew Morton8d8706e2006-01-11 12:17:49 -08001006 case RIO_HOST_RUP:
1007 /*
1008 ** The daemon want rup information
1009 ** (probably for debug reasons)
1010 */
1011 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
Al Virod886cb52006-05-27 00:08:25 -04001012 if (copy_from_user(&RupReq, argp, sizeof(RupReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001013 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1014 p->RIOError.Error = COPYIN_FAILED;
1015 return -EFAULT;
1016 }
1017 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1018 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
1019 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1020 return -ENXIO;
1021 }
1022 if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */
1023 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
1024 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1025 return -EINVAL;
1026 }
1027 HostP = &p->RIOHosts[RupReq.HostNum];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Andrew Morton8d8706e2006-01-11 12:17:49 -08001029 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1030 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
1031 p->RIOError.Error = HOST_NOT_RUNNING;
1032 return -EIO;
1033 }
1034 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Al Viro06458192006-05-27 02:11:12 -04001036 if (copy_from_io(RupReq.RupP, HostP->UnixRups[RupReq.RupNum].RupP, sizeof(struct RUP))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001037 p->RIOError.Error = COPYOUT_FAILED;
1038 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1039 return -EFAULT;
1040 }
1041 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Andrew Morton8d8706e2006-01-11 12:17:49 -08001043 case RIO_HOST_LPB:
1044 /*
1045 ** The daemon want lpb information
1046 ** (probably for debug reasons)
1047 */
1048 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
Al Virod886cb52006-05-27 00:08:25 -04001049 if (copy_from_user(&LpbReq, argp, sizeof(LpbReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001050 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1051 p->RIOError.Error = COPYIN_FAILED;
1052 return -EFAULT;
1053 }
1054 if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
1055 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
1056 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1057 return -ENXIO;
1058 }
1059 if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */
1060 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
1061 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1062 return -EINVAL;
1063 }
1064 HostP = &p->RIOHosts[LpbReq.Host];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Andrew Morton8d8706e2006-01-11 12:17:49 -08001066 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1067 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
1068 p->RIOError.Error = HOST_NOT_RUNNING;
1069 return -EIO;
1070 }
1071 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Al Viro06458192006-05-27 02:11:12 -04001073 if (copy_from_io(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001074 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1075 p->RIOError.Error = COPYOUT_FAILED;
1076 return -EFAULT;
1077 }
1078 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Andrew Morton8d8706e2006-01-11 12:17:49 -08001080 /*
1081 ** Here 3 IOCTL's that allow us to change the way in which
1082 ** rio logs errors. send them just to syslog or send them
1083 ** to both syslog and console or send them to just the console.
1084 **
1085 ** See RioStrBuf() in util.c for the other half.
1086 */
1087 case RIO_SYSLOG_ONLY:
1088 p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
1089 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Andrew Morton8d8706e2006-01-11 12:17:49 -08001091 case RIO_SYSLOG_CONS:
1092 p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */
1093 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
Andrew Morton8d8706e2006-01-11 12:17:49 -08001095 case RIO_CONS_ONLY:
1096 p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
1097 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Andrew Morton8d8706e2006-01-11 12:17:49 -08001099 case RIO_SIGNALS_ON:
1100 if (p->RIOSignalProcess) {
1101 p->RIOError.Error = SIGNALS_ALREADY_SET;
1102 return -EBUSY;
1103 }
Alan Cox3d336aa2006-03-24 03:18:29 -08001104 /* FIXME: PID tracking */
1105 p->RIOSignalProcess = current->pid;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001106 p->RIOPrintDisabled = DONT_PRINT;
1107 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Andrew Morton8d8706e2006-01-11 12:17:49 -08001109 case RIO_SIGNALS_OFF:
Alan Cox3d336aa2006-03-24 03:18:29 -08001110 if (p->RIOSignalProcess != current->pid) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001111 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1112 return -EPERM;
1113 }
1114 rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
1115 p->RIOSignalProcess = 0;
1116 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Andrew Morton8d8706e2006-01-11 12:17:49 -08001118 case RIO_SET_BYTE_MODE:
1119 for (Host = 0; Host < p->RIONumHosts; Host++)
1120 if (p->RIOHosts[Host].Type == RIO_AT)
1121 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1122 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Andrew Morton8d8706e2006-01-11 12:17:49 -08001124 case RIO_SET_WORD_MODE:
1125 for (Host = 0; Host < p->RIONumHosts; Host++)
1126 if (p->RIOHosts[Host].Type == RIO_AT)
1127 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1128 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Andrew Morton8d8706e2006-01-11 12:17:49 -08001130 case RIO_SET_FAST_BUS:
1131 for (Host = 0; Host < p->RIONumHosts; Host++)
1132 if (p->RIOHosts[Host].Type == RIO_AT)
1133 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1134 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Andrew Morton8d8706e2006-01-11 12:17:49 -08001136 case RIO_SET_SLOW_BUS:
1137 for (Host = 0; Host < p->RIONumHosts; Host++)
1138 if (p->RIOHosts[Host].Type == RIO_AT)
1139 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1140 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Andrew Morton8d8706e2006-01-11 12:17:49 -08001142 case RIO_MAP_B50_TO_50:
1143 case RIO_MAP_B50_TO_57600:
1144 case RIO_MAP_B110_TO_110:
1145 case RIO_MAP_B110_TO_115200:
1146 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
Al Virod886cb52006-05-27 00:08:25 -04001147 port = arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001148 if (port < 0 || port > 511) {
1149 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1150 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1151 return -EINVAL;
1152 }
1153 rio_spin_lock_irqsave(&PortP->portSem, flags);
1154 switch (cmd) {
1155 case RIO_MAP_B50_TO_50:
1156 p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1157 break;
1158 case RIO_MAP_B50_TO_57600:
1159 p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1160 break;
1161 case RIO_MAP_B110_TO_110:
1162 p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1163 break;
1164 case RIO_MAP_B110_TO_115200:
1165 p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1166 break;
1167 }
1168 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1169 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Andrew Morton8d8706e2006-01-11 12:17:49 -08001171 case RIO_STREAM_INFO:
1172 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
1173 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Andrew Morton8d8706e2006-01-11 12:17:49 -08001175 case RIO_SEND_PACKET:
1176 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
Al Virod886cb52006-05-27 00:08:25 -04001177 if (copy_from_user(&SendPack, argp, sizeof(SendPack))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001178 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1179 p->RIOError.Error = COPYIN_FAILED;
1180 return -EFAULT;
1181 }
1182 if (SendPack.PortNum >= 128) {
1183 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1184 return -ENXIO;
1185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
Andrew Morton8d8706e2006-01-11 12:17:49 -08001187 PortP = p->RIOPortp[SendPack.PortNum];
1188 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Andrew Morton8d8706e2006-01-11 12:17:49 -08001190 if (!can_add_transmit(&PacketP, PortP)) {
1191 p->RIOError.Error = UNIT_IS_IN_USE;
1192 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1193 return -ENOSPC;
1194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Andrew Morton8d8706e2006-01-11 12:17:49 -08001196 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
Alan Cox3d336aa2006-03-24 03:18:29 -08001197 writeb(SendPack.Data[loop], &PacketP->data[loop]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Alan Cox3d336aa2006-03-24 03:18:29 -08001199 writeb(SendPack.Len, &PacketP->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Andrew Morton8d8706e2006-01-11 12:17:49 -08001201 add_transmit(PortP);
1202 /*
1203 ** Count characters transmitted for port statistics reporting
1204 */
1205 if (PortP->statsGather)
1206 PortP->txchars += (SendPack.Len & 127);
1207 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1208 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Andrew Morton8d8706e2006-01-11 12:17:49 -08001210 case RIO_NO_MESG:
1211 if (su)
1212 p->RIONoMessage = 1;
1213 return su ? 0 : -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Andrew Morton8d8706e2006-01-11 12:17:49 -08001215 case RIO_MESG:
1216 if (su)
1217 p->RIONoMessage = 0;
1218 return su ? 0 : -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
Andrew Morton8d8706e2006-01-11 12:17:49 -08001220 case RIO_WHAT_MESG:
Al Virod886cb52006-05-27 00:08:25 -04001221 if (copy_to_user(argp, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001222 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1223 p->RIOError.Error = COPYOUT_FAILED;
1224 return -EFAULT;
1225 }
1226 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Andrew Morton8d8706e2006-01-11 12:17:49 -08001228 case RIO_MEM_DUMP:
Al Virod886cb52006-05-27 00:08:25 -04001229 if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001230 p->RIOError.Error = COPYIN_FAILED;
1231 return -EFAULT;
1232 }
1233 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 -07001234
Andrew Morton8d8706e2006-01-11 12:17:49 -08001235 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1236 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1237 return -EINVAL;
1238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Andrew Morton8d8706e2006-01-11 12:17:49 -08001240 if (SubCmd.Host >= p->RIONumHosts) {
1241 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1242 return -EINVAL;
1243 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Andrew Morton8d8706e2006-01-11 12:17:49 -08001245 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
Andrew Morton8d8706e2006-01-11 12:17:49 -08001247 PortP = p->RIOPortp[port];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Andrew Morton8d8706e2006-01-11 12:17:49 -08001249 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Andrew Morton8d8706e2006-01-11 12:17:49 -08001251 if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) {
1252 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1253 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1254 return -EBUSY;
1255 } else
1256 PortP->State |= RIO_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Andrew Morton8d8706e2006-01-11 12:17:49 -08001258 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Al Virod886cb52006-05-27 00:08:25 -04001259 if (copy_to_user(argp, p->RIOMemDump, MEMDUMP_SIZE)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001260 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1261 p->RIOError.Error = COPYOUT_FAILED;
1262 return -EFAULT;
1263 }
1264 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Andrew Morton8d8706e2006-01-11 12:17:49 -08001266 case RIO_TICK:
Al Virod886cb52006-05-27 00:08:25 -04001267 if (arg >= p->RIONumHosts)
Andrew Morton8d8706e2006-01-11 12:17:49 -08001268 return -EINVAL;
Al Virod886cb52006-05-27 00:08:25 -04001269 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", arg);
1270 writeb(0xFF, &p->RIOHosts[arg].SetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001271 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Andrew Morton8d8706e2006-01-11 12:17:49 -08001273 case RIO_TOCK:
Al Virod886cb52006-05-27 00:08:25 -04001274 if (arg >= p->RIONumHosts)
Andrew Morton8d8706e2006-01-11 12:17:49 -08001275 return -EINVAL;
Al Virod886cb52006-05-27 00:08:25 -04001276 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", arg);
1277 writeb(0xFF, &p->RIOHosts[arg].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001278 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Andrew Morton8d8706e2006-01-11 12:17:49 -08001280 case RIO_READ_CHECK:
1281 /* Check reads for pkts with data[0] the same */
1282 p->RIOReadCheck = !p->RIOReadCheck;
Al Virod886cb52006-05-27 00:08:25 -04001283 if (copy_to_user(argp, &p->RIOReadCheck, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001284 p->RIOError.Error = COPYOUT_FAILED;
1285 return -EFAULT;
1286 }
1287 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
Andrew Morton8d8706e2006-01-11 12:17:49 -08001289 case RIO_READ_REGISTER:
Al Virod886cb52006-05-27 00:08:25 -04001290 if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001291 p->RIOError.Error = COPYIN_FAILED;
1292 return -EFAULT;
1293 }
1294 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER host %d rup %d port %d reg %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Port, SubCmd.Addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Andrew Morton8d8706e2006-01-11 12:17:49 -08001296 if (SubCmd.Port > 511) {
1297 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
1298 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1299 return -EINVAL;
1300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Andrew Morton8d8706e2006-01-11 12:17:49 -08001302 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1303 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1304 return -EINVAL;
1305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Andrew Morton8d8706e2006-01-11 12:17:49 -08001307 if (SubCmd.Host >= p->RIONumHosts) {
1308 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1309 return -EINVAL;
1310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Andrew Morton8d8706e2006-01-11 12:17:49 -08001312 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1313 PortP = p->RIOPortp[port];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Andrew Morton8d8706e2006-01-11 12:17:49 -08001315 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
Andrew Morton8d8706e2006-01-11 12:17:49 -08001317 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
1318 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1319 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1320 return -EBUSY;
1321 } else
1322 PortP->State |= RIO_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Andrew Morton8d8706e2006-01-11 12:17:49 -08001324 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Al Virod886cb52006-05-27 00:08:25 -04001325 if (copy_to_user(argp, &p->CdRegister, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001326 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1327 p->RIOError.Error = COPYOUT_FAILED;
1328 return -EFAULT;
1329 }
1330 return 0;
1331 /*
1332 ** rio_make_dev: given port number (0-511) ORed with port type
1333 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1334 ** value to pass to mknod to create the correct device node.
1335 */
1336 case RIO_MAKE_DEV:
1337 {
Al Virod886cb52006-05-27 00:08:25 -04001338 unsigned int port = arg & RIO_MODEM_MASK;
Alan Cox3d336aa2006-03-24 03:18:29 -08001339 unsigned int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Al Virod886cb52006-05-27 00:08:25 -04001341 switch (arg & RIO_DEV_MASK) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001342 case RIO_DEV_DIRECT:
Alan Cox3d336aa2006-03-24 03:18:29 -08001343 ret = drv_makedev(MAJOR(dev), port);
1344 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
1345 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001346 case RIO_DEV_MODEM:
Alan Cox3d336aa2006-03-24 03:18:29 -08001347 ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1348 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
1349 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001350 case RIO_DEV_XPRINT:
Alan Cox3d336aa2006-03-24 03:18:29 -08001351 ret = drv_makedev(MAJOR(dev), port);
1352 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
1353 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001354 }
1355 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1356 return -EINVAL;
1357 }
1358 /*
1359 ** rio_minor: given a dev_t from a stat() call, return
1360 ** the port number (0-511) ORed with the port type
1361 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1362 */
1363 case RIO_MINOR:
1364 {
1365 dev_t dv;
1366 int mino;
Alan Cox3d336aa2006-03-24 03:18:29 -08001367 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
Al Virod886cb52006-05-27 00:08:25 -04001369 dv = (dev_t) (arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001370 mino = RIO_UNMODEM(dv);
1371
1372 if (RIO_ISMODEM(dv)) {
1373 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
Alan Cox3d336aa2006-03-24 03:18:29 -08001374 ret = mino | RIO_DEV_MODEM;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001375 } else {
1376 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
Alan Cox3d336aa2006-03-24 03:18:29 -08001377 ret = mino | RIO_DEV_DIRECT;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001378 }
Alan Cox3d336aa2006-03-24 03:18:29 -08001379 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 }
Andrew Morton8d8706e2006-01-11 12:17:49 -08001382 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1384
Andrew Morton8d8706e2006-01-11 12:17:49 -08001385 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 return -EINVAL;
1387}
1388
1389/*
1390** Pre-emptive commands go on RUPs and are only one byte long.
1391*/
Alan Cox3d336aa2006-03-24 03:18:29 -08001392int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393{
1394 struct CmdBlk *CmdBlkP;
1395 struct PktCmd_M *PktCmdP;
1396 int Ret;
1397 ushort rup;
1398 int port;
1399
Andrew Morton8d8706e2006-01-11 12:17:49 -08001400 if (PortP->State & RIO_DELETED) {
1401 rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 return RIO_FAIL;
1403 }
1404
Alan Cox655fdea2006-05-15 09:44:26 -07001405 if ((PortP->InUse == (typeof(PortP->InUse))-1) ||
1406 !(CmdBlkP = RIOGetCmdBlk())) {
1407 rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block "
1408 "for command %d on port %d\n", Cmd, PortP->PortNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 return RIO_FAIL;
1410 }
1411
Alan Cox655fdea2006-05-15 09:44:26 -07001412 rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n",
1413 CmdBlkP, PortP->InUse);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Alan Cox655fdea2006-05-15 09:44:26 -07001415 PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Andrew Morton8d8706e2006-01-11 12:17:49 -08001417 CmdBlkP->Packet.src_unit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 if (PortP->SecondBlock)
1419 rup = PortP->ID2;
1420 else
1421 rup = PortP->RupNum;
1422 CmdBlkP->Packet.dest_unit = rup;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001423 CmdBlkP->Packet.src_port = COMMAND_RUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 CmdBlkP->Packet.dest_port = COMMAND_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001425 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1426 CmdBlkP->PostFuncP = RIOUnUse;
Alan Cox3d336aa2006-03-24 03:18:29 -08001427 CmdBlkP->PostArg = (unsigned long) PortP;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001428 PktCmdP->Command = Cmd;
1429 port = PortP->HostPort % (ushort) PORTS_PER_RTA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -08001431 ** Index ports 8-15 for 2nd block of 16 port RTA.
1432 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 if (PortP->SecondBlock)
1434 port += (ushort) PORTS_PER_RTA;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001435 PktCmdP->PhbNum = port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Andrew Morton8d8706e2006-01-11 12:17:49 -08001437 switch (Cmd) {
1438 case MEMDUMP:
Alan Cox655fdea2006-05-15 09:44:26 -07001439 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p "
1440 "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001441 PktCmdP->SubCommand = MEMDUMP;
1442 PktCmdP->SubAddr = SubCmd.Addr;
1443 break;
1444 case FCLOSE:
Alan Cox655fdea2006-05-15 09:44:26 -07001445 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n",
1446 CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001447 break;
1448 case READ_REGISTER:
Alan Cox655fdea2006-05-15 09:44:26 -07001449 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) "
1450 "command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001451 PktCmdP->SubCommand = READ_REGISTER;
1452 PktCmdP->SubAddr = SubCmd.Addr;
1453 break;
1454 case RESUME:
Alan Cox655fdea2006-05-15 09:44:26 -07001455 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n",
1456 CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001457 break;
1458 case RFLUSH:
Alan Cox655fdea2006-05-15 09:44:26 -07001459 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n",
1460 CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001461 CmdBlkP->PostFuncP = RIORFlushEnable;
1462 break;
1463 case SUSPEND:
Alan Cox655fdea2006-05-15 09:44:26 -07001464 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n",
1465 CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001466 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Andrew Morton8d8706e2006-01-11 12:17:49 -08001468 case MGET:
Alan Cox655fdea2006-05-15 09:44:26 -07001469 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n",
1470 CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001471 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Andrew Morton8d8706e2006-01-11 12:17:49 -08001473 case MSET:
1474 case MBIC:
1475 case MBIS:
1476 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
Alan Cox655fdea2006-05-15 09:44:26 -07001477 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command "
1478 "blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001479 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Andrew Morton8d8706e2006-01-11 12:17:49 -08001481 case WFLUSH:
1482 /*
1483 ** If we have queued up the maximum number of Write flushes
1484 ** allowed then we should not bother sending any more to the
1485 ** RTA.
1486 */
Alan Cox655fdea2006-05-15 09:44:26 -07001487 if (PortP->WflushFlag == (typeof(PortP->WflushFlag))-1) {
1488 rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, "
1489 "WflushFlag about to wrap!");
Andrew Morton8d8706e2006-01-11 12:17:49 -08001490 RIOFreeCmdBlk(CmdBlkP);
1491 return (RIO_FAIL);
1492 } else {
Alan Cox655fdea2006-05-15 09:44:26 -07001493 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command "
1494 "blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001495 CmdBlkP->PostFuncP = RIOWFlushMark;
1496 }
1497 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 }
1499
1500 PortP->InUse++;
1501
Andrew Morton8d8706e2006-01-11 12:17:49 -08001502 Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
1504 return Ret;
1505}