blob: d65ceb9a434a49191cc84fa70355aab5fd964397 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/uaccess.h>
44
45#include <linux/termios.h>
46#include <linux/serial.h>
47
48#include <linux/generic_serial.h>
49
50
51#include "linux_compat.h"
52#include "rio_linux.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include "pkt.h"
54#include "daemon.h"
55#include "rio.h"
56#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include "cmdpkt.h"
58#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include "rup.h"
60#include "port.h"
61#include "riodrvr.h"
62#include "rioinfo.h"
63#include "func.h"
64#include "errors.h"
65#include "pci.h"
66
67#include "parmmap.h"
68#include "unixrup.h"
69#include "board.h"
70#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#include "phb.h"
72#include "link.h"
73#include "cmdblk.h"
74#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#include "cirrus.h"
76#include "rioioctl.h"
77
78
Andrew Morton8d8706e2006-01-11 12:17:49 -080079static struct LpbReq LpbReq;
80static struct RupReq RupReq;
81static struct PortReq PortReq;
Al Virod886cb52006-05-27 00:08:25 -040082static struct HostReq HostReq; /* oh really? global? and no locking? */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static struct HostDpRam HostDpRam;
84static struct DebugCtrl DebugCtrl;
Andrew Morton8d8706e2006-01-11 12:17:49 -080085static struct Map MapEnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086static struct PortSetup PortSetup;
Andrew Morton8d8706e2006-01-11 12:17:49 -080087static struct DownLoad DownLoad;
88static struct SendPack SendPack;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/* static struct StreamInfo StreamInfo; */
90/* static char modemtable[RIO_PORTS]; */
91static struct SpecialRupCmd SpecialRupCmd;
92static struct PortParams PortParams;
93static struct portStats portStats;
94
95static struct SubCmdStruct {
Andrew Morton8d8706e2006-01-11 12:17:49 -080096 ushort Host;
97 ushort Rup;
98 ushort Port;
99 ushort Addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100} SubCmd;
101
102struct PortTty {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800103 uint port;
104 struct ttystatics Tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105};
106
Andrew Morton8d8706e2006-01-11 12:17:49 -0800107static struct PortTty PortTty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108typedef struct ttystatics TERMIO;
109
110/*
111** This table is used when the config.rio downloads bin code to the
112** driver. We index the table using the product code, 0-F, and call
113** the function pointed to by the entry, passing the information
114** about the boot.
115** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
116** process to bog off.
117*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800118static int
119 (*RIOBootTable[MAX_PRODUCT]) (struct rio_info *, struct DownLoad *) = {
120 /* 0 */ RIOBootCodeHOST,
121 /* Host Card */
122 /* 1 */ RIOBootCodeRTA,
123 /* RTA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124};
125
126#define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
127
Al Viro06458192006-05-27 02:11:12 -0400128static int copy_from_io(void __user *to, void __iomem *from, size_t size)
129{
130 void *buf = kmalloc(size, GFP_KERNEL);
131 int res = -ENOMEM;
132 if (buf) {
133 rio_memcpy_fromio(buf, from, size);
134 res = copy_to_user(to, buf, size);
135 kfree(buf);
136 }
137 return res;
138}
139
Al Virod886cb52006-05-27 00:08:25 -0400140int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800142 uint Host; /* leave me unsigned! */
143 uint port; /* and me! */
144 struct Host *HostP;
145 ushort loop;
146 int Entry;
147 struct Port *PortP;
Al Virod886cb52006-05-27 00:08:25 -0400148 struct PKT __iomem *PacketP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800149 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 unsigned long flags;
Al Virod886cb52006-05-27 00:08:25 -0400151 void __user *argp = (void __user *)arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800152
153 func_enter();
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 /* Confuse the compiler to think that we've initialized these */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800156 Host = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 PortP = NULL;
158
Al Virod886cb52006-05-27 00:08:25 -0400159 rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 switch (cmd) {
162 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800163 ** RIO_SET_TIMER
164 **
165 ** Change the value of the host card interrupt timer.
166 ** If the host card number is -1 then all host cards are changed
167 ** otherwise just the specified host card will be changed.
168 */
169 case RIO_SET_TIMER:
Al Virod886cb52006-05-27 00:08:25 -0400170 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800171 {
172 int host, value;
Al Virod886cb52006-05-27 00:08:25 -0400173 host = (arg >> 16) & 0x0000FFFF;
174 value = arg & 0x0000ffff;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800175 if (host == -1) {
176 for (host = 0; host < p->RIONumHosts; host++) {
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 }
180 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800181 } else if (host >= p->RIONumHosts) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 return -EINVAL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800183 } else {
184 if (p->RIOHosts[host].Flags == RC_RUNNING) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800185 writew(value, &p->RIOHosts[host].ParmMapP->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800187 }
188 }
189 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Andrew Morton8d8706e2006-01-11 12:17:49 -0800191 case RIO_FOAD_RTA:
192 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
Al Virod886cb52006-05-27 00:08:25 -0400193 return RIOCommandRta(p, arg, RIOFoadRta);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800194
195 case RIO_ZOMBIE_RTA:
196 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
Al Virod886cb52006-05-27 00:08:25 -0400197 return RIOCommandRta(p, arg, RIOZombieRta);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800198
199 case RIO_IDENTIFY_RTA:
200 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
Al Virod886cb52006-05-27 00:08:25 -0400201 return RIOIdentifyRta(p, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800202
203 case RIO_KILL_NEIGHBOUR:
204 rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
Al Virod886cb52006-05-27 00:08:25 -0400205 return RIOKillNeighbour(p, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800206
207 case SPECIAL_RUP_CMD:
208 {
209 struct CmdBlk *CmdBlkP;
210
211 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
Al Virod886cb52006-05-27 00:08:25 -0400212 if (copy_from_user(&SpecialRupCmd, argp, sizeof(SpecialRupCmd))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800213 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
214 p->RIOError.Error = COPYIN_FAILED;
215 return -EFAULT;
216 }
217 CmdBlkP = RIOGetCmdBlk();
218 if (!CmdBlkP) {
219 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
220 return -ENXIO;
221 }
222 CmdBlkP->Packet = SpecialRupCmd.Packet;
223 if (SpecialRupCmd.Host >= p->RIONumHosts)
224 SpecialRupCmd.Host = 0;
225 rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
226 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
Alan Cox3d336aa2006-03-24 03:18:29 -0800227 printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800228 }
229 return 0;
230 }
231
232 case RIO_DEBUG_MEM:
Alan Coxf4caf162006-01-16 17:27:38 +0000233 return -EPERM;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800234
235 case RIO_ALL_MODEM:
236 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
237 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
238 return -EINVAL;
239
240 case RIO_GET_TABLE:
241 /*
242 ** Read the routing table from the device driver to user space
243 */
244 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
245
246 if ((retval = RIOApel(p)) != 0)
247 return retval;
248
Al Virod886cb52006-05-27 00:08:25 -0400249 if (copy_to_user(argp, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800250 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
251 p->RIOError.Error = COPYOUT_FAILED;
252 return -EFAULT;
253 }
254
255 {
256 int entry;
257 rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
258 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
259 if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
260 continue;
261
262 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
263 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
264 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
265 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
266 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
267 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
268 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
269 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
270 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
271 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
272 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
273 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
274 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
275 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
276 rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
277 }
278 rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
279 }
280 p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
281 return 0;
282
283 case RIO_PUT_TABLE:
284 /*
285 ** Write the routing table to the device driver from user space
286 */
287 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
288
289 if (!su) {
290 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
291 p->RIOError.Error = NOT_SUPER_USER;
292 return -EPERM;
293 }
Al Virod886cb52006-05-27 00:08:25 -0400294 if (copy_from_user(&p->RIOConnectTable[0], argp, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800295 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
296 p->RIOError.Error = COPYIN_FAILED;
297 return -EFAULT;
298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299/*
300***********************************
301 {
302 int entry;
303 rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
304 for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
305 {
306 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
307 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
308 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
309 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
310 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
311 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
312 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
313 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
314 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
315 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
316 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
317 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
318 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
319 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
320 rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
321 }
322 rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
323 }
324***********************************
325*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800326 return RIONewTable(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Andrew Morton8d8706e2006-01-11 12:17:49 -0800328 case RIO_GET_BINDINGS:
329 /*
330 ** Send bindings table, containing unique numbers of RTAs owned
331 ** by this system to user space
332 */
333 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Andrew Morton8d8706e2006-01-11 12:17:49 -0800335 if (!su) {
336 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
337 p->RIOError.Error = NOT_SUPER_USER;
338 return -EPERM;
339 }
Al Virod886cb52006-05-27 00:08:25 -0400340 if (copy_to_user(argp, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800341 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
342 p->RIOError.Error = COPYOUT_FAILED;
343 return -EFAULT;
344 }
345 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Andrew Morton8d8706e2006-01-11 12:17:49 -0800347 case RIO_PUT_BINDINGS:
348 /*
349 ** Receive a bindings table, containing unique numbers of RTAs owned
350 ** by this system
351 */
352 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
353
354 if (!su) {
355 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
356 p->RIOError.Error = NOT_SUPER_USER;
357 return -EPERM;
358 }
Al Virod886cb52006-05-27 00:08:25 -0400359 if (copy_from_user(&p->RIOBindTab[0], argp, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800360 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
361 p->RIOError.Error = COPYIN_FAILED;
362 return -EFAULT;
363 }
364 return 0;
365
366 case RIO_BIND_RTA:
367 {
368 int EmptySlot = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800370 ** Bind this RTA to host, so that it will be booted by
371 ** host in 'boot owned RTAs' mode.
372 */
373 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Andrew Morton8d8706e2006-01-11 12:17:49 -0800375 if (!su) {
376 rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
377 p->RIOError.Error = NOT_SUPER_USER;
378 return -EPERM;
379 }
380 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
381 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
382 EmptySlot = Entry;
Al Virod886cb52006-05-27 00:08:25 -0400383 else if (p->RIOBindTab[Entry] == arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800385 ** Already exists - delete
386 */
387 p->RIOBindTab[Entry] = 0L;
Al Virod886cb52006-05-27 00:08:25 -0400388 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 return 0;
390 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800393 ** Dosen't exist - add
394 */
395 if (EmptySlot != -1) {
Al Virod886cb52006-05-27 00:08:25 -0400396 p->RIOBindTab[EmptySlot] = arg;
397 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800398 } else {
Al Virod886cb52006-05-27 00:08:25 -0400399 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800400 return -ENOMEM;
401 }
402 return 0;
403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Andrew Morton8d8706e2006-01-11 12:17:49 -0800405 case RIO_RESUME:
406 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
Al Virod886cb52006-05-27 00:08:25 -0400407 port = arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800408 if ((port < 0) || (port > 511)) {
409 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
410 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
411 return -EINVAL;
412 }
413 PortP = p->RIOPortp[port];
414 if (!PortP->Mapped) {
415 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
416 p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
417 return -EINVAL;
418 }
419 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
420 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
421 return -EINVAL;
422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Andrew Morton8d8706e2006-01-11 12:17:49 -0800424 rio_spin_lock_irqsave(&PortP->portSem, flags);
Jiri Slabyd6f63412008-04-30 00:53:57 -0700425 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RIOC_RESUME) ==
426 RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800427 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]);
Jiri Slabyd6f63412008-04-30 00:53:57 -0700640 RIOParam(PortP, RIOC_CONFIG, PortP->State & RIO_MODEM,
641 OK_TO_SLEEP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800642 return retval;
643
644 case RIO_SET_PORT_PARAMS:
645 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
Al Virod886cb52006-05-27 00:08:25 -0400646 if (copy_from_user(&PortParams, argp, sizeof(PortParams))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800647 p->RIOError.Error = COPYIN_FAILED;
648 return -EFAULT;
649 }
650 if (PortParams.Port >= (ushort) RIO_PORTS) {
651 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
652 return -ENXIO;
653 }
654 PortP = (p->RIOPortp[PortParams.Port]);
655 rio_spin_lock_irqsave(&PortP->portSem, flags);
656 PortP->Config = PortParams.Config;
657 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
658 return retval;
659
660 case RIO_GET_PORT_STATS:
661 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
Al Virod886cb52006-05-27 00:08:25 -0400662 if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800663 p->RIOError.Error = COPYIN_FAILED;
664 return -EFAULT;
665 }
Alan Cox9d90daf2006-10-16 16:28:44 +0100666 if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800667 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
668 return -ENXIO;
669 }
670 PortP = (p->RIOPortp[portStats.port]);
671 portStats.gather = PortP->statsGather;
672 portStats.txchars = PortP->txchars;
673 portStats.rxchars = PortP->rxchars;
674 portStats.opens = PortP->opens;
675 portStats.closes = PortP->closes;
676 portStats.ioctls = PortP->ioctls;
Al Virod886cb52006-05-27 00:08:25 -0400677 if (copy_to_user(argp, &portStats, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800678 p->RIOError.Error = COPYOUT_FAILED;
679 return -EFAULT;
680 }
681 return retval;
682
683 case RIO_RESET_PORT_STATS:
Al Virod886cb52006-05-27 00:08:25 -0400684 port = arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800685 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
686 if (port >= RIO_PORTS) {
687 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
688 return -ENXIO;
689 }
690 PortP = (p->RIOPortp[port]);
691 rio_spin_lock_irqsave(&PortP->portSem, flags);
692 PortP->txchars = 0;
693 PortP->rxchars = 0;
694 PortP->opens = 0;
695 PortP->closes = 0;
696 PortP->ioctls = 0;
697 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
698 return retval;
699
700 case RIO_GATHER_PORT_STATS:
701 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
Al Virod886cb52006-05-27 00:08:25 -0400702 if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800703 p->RIOError.Error = COPYIN_FAILED;
704 return -EFAULT;
705 }
Alan Cox9d90daf2006-10-16 16:28:44 +0100706 if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800707 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
708 return -ENXIO;
709 }
710 PortP = (p->RIOPortp[portStats.port]);
711 rio_spin_lock_irqsave(&PortP->portSem, flags);
712 PortP->statsGather = portStats.gather;
713 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
714 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Andrew Morton8d8706e2006-01-11 12:17:49 -0800716 case RIO_READ_CONFIG:
717 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
Al Virod886cb52006-05-27 00:08:25 -0400718 if (copy_to_user(argp, &p->RIOConf, sizeof(struct Conf))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800719 p->RIOError.Error = COPYOUT_FAILED;
720 return -EFAULT;
721 }
722 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
Andrew Morton8d8706e2006-01-11 12:17:49 -0800724 case RIO_SET_CONFIG:
725 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
726 if (!su) {
727 p->RIOError.Error = NOT_SUPER_USER;
728 return -EPERM;
729 }
Al Virod886cb52006-05-27 00:08:25 -0400730 if (copy_from_user(&p->RIOConf, argp, sizeof(struct Conf))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800731 p->RIOError.Error = COPYIN_FAILED;
732 return -EFAULT;
733 }
734 /*
735 ** move a few value around
736 */
737 for (Host = 0; Host < p->RIONumHosts; Host++)
738 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
Alan Cox3d336aa2006-03-24 03:18:29 -0800739 writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800740 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Andrew Morton8d8706e2006-01-11 12:17:49 -0800742 case RIO_START_POLLER:
743 rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
744 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Andrew Morton8d8706e2006-01-11 12:17:49 -0800746 case RIO_STOP_POLLER:
747 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
748 if (!su) {
749 p->RIOError.Error = NOT_SUPER_USER;
750 return -EPERM;
751 }
752 p->RIOPolling = NOT_POLLING;
753 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Andrew Morton8d8706e2006-01-11 12:17:49 -0800755 case RIO_SETDEBUG:
756 case RIO_GETDEBUG:
757 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
Al Virod886cb52006-05-27 00:08:25 -0400758 if (copy_from_user(&DebugCtrl, argp, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800759 p->RIOError.Error = COPYIN_FAILED;
760 return -EFAULT;
761 }
762 if (DebugCtrl.SysPort == NO_PORT) {
763 if (cmd == RIO_SETDEBUG) {
764 if (!su) {
765 p->RIOError.Error = NOT_SUPER_USER;
766 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800768 p->rio_debug = DebugCtrl.Debug;
769 p->RIODebugWait = DebugCtrl.Wait;
770 rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
771 } else {
772 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
773 DebugCtrl.Debug = p->rio_debug;
774 DebugCtrl.Wait = p->RIODebugWait;
Al Virod886cb52006-05-27 00:08:25 -0400775 if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800776 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
777 p->RIOError.Error = COPYOUT_FAILED;
778 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800780 }
781 } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
782 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
783 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
784 return -ENXIO;
785 } else if (cmd == RIO_SETDEBUG) {
786 if (!su) {
787 p->RIOError.Error = NOT_SUPER_USER;
788 return -EPERM;
789 }
790 rio_spin_lock_irqsave(&PortP->portSem, flags);
791 p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
792 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
793 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
794 } else {
795 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
796 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
Al Virod886cb52006-05-27 00:08:25 -0400797 if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800798 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
799 p->RIOError.Error = COPYOUT_FAILED;
800 return -EFAULT;
801 }
802 }
803 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Andrew Morton8d8706e2006-01-11 12:17:49 -0800805 case RIO_VERSID:
806 /*
807 ** Enquire about the release and version.
808 ** We return MAX_VERSION_LEN bytes, being a
809 ** textual null terminated string.
810 */
811 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
Al Virod886cb52006-05-27 00:08:25 -0400812 if (copy_to_user(argp, RIOVersid(), sizeof(struct rioVersion))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800813 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
814 p->RIOError.Error = COPYOUT_FAILED;
815 return -EFAULT;
816 }
817 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Andrew Morton8d8706e2006-01-11 12:17:49 -0800819 case RIO_NUM_HOSTS:
820 /*
821 ** Enquire as to the number of hosts located
822 ** at init time.
823 */
824 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
Al Virod886cb52006-05-27 00:08:25 -0400825 if (copy_to_user(argp, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800826 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
827 p->RIOError.Error = COPYOUT_FAILED;
828 return -EFAULT;
829 }
830 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Andrew Morton8d8706e2006-01-11 12:17:49 -0800832 case RIO_HOST_FOAD:
833 /*
834 ** Kill host. This may not be in the final version...
835 */
Al Virod886cb52006-05-27 00:08:25 -0400836 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800837 if (!su) {
838 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
839 p->RIOError.Error = NOT_SUPER_USER;
840 return -EPERM;
841 }
842 p->RIOHalted = 1;
843 p->RIOSystemUp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
Andrew Morton8d8706e2006-01-11 12:17:49 -0800845 for (Host = 0; Host < p->RIONumHosts; Host++) {
846 (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 -0800847 memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800848 p->RIOHosts[Host].Flags = RC_WAITING;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800849 }
850 RIOFoadWakeup(p);
851 p->RIONumBootPkts = 0;
852 p->RIOBooting = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800853 printk("HEEEEELP!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Andrew Morton8d8706e2006-01-11 12:17:49 -0800855 for (loop = 0; loop < RIO_PORTS; loop++) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800856 spin_lock_init(&p->RIOPortp[loop]->portSem);
857 p->RIOPortp[loop]->InUse = NOT_INUSE;
858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Andrew Morton8d8706e2006-01-11 12:17:49 -0800860 p->RIOSystemUp = 0;
861 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Andrew Morton8d8706e2006-01-11 12:17:49 -0800863 case RIO_DOWNLOAD:
864 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
865 if (!su) {
866 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
867 p->RIOError.Error = NOT_SUPER_USER;
868 return -EPERM;
869 }
Al Virod886cb52006-05-27 00:08:25 -0400870 if (copy_from_user(&DownLoad, argp, sizeof(DownLoad))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800871 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
872 p->RIOError.Error = COPYIN_FAILED;
873 return -EFAULT;
874 }
875 rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Andrew Morton8d8706e2006-01-11 12:17:49 -0800877 /*
878 ** It is important that the product code is an unsigned object!
879 */
880 if (DownLoad.ProductCode > MAX_PRODUCT) {
881 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
882 p->RIOError.Error = NO_SUCH_PRODUCT;
883 return -ENXIO;
884 }
885 /*
886 ** do something!
887 */
888 retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
889 /* <-- Panic */
890 p->RIOHalted = 0;
891 /*
892 ** and go back, content with a job well completed.
893 */
894 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Andrew Morton8d8706e2006-01-11 12:17:49 -0800896 case RIO_PARMS:
897 {
Alan Cox3d336aa2006-03-24 03:18:29 -0800898 unsigned int host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Al Virod886cb52006-05-27 00:08:25 -0400900 if (copy_from_user(&host, argp, sizeof(host))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800901 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
902 p->RIOError.Error = COPYIN_FAILED;
903 return -EFAULT;
904 }
905 /*
906 ** Fetch the parmmap
907 */
908 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
Al Viro06458192006-05-27 02:11:12 -0400909 if (copy_from_io(argp, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800910 p->RIOError.Error = COPYOUT_FAILED;
911 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
912 return -EFAULT;
913 }
914 }
915 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Andrew Morton8d8706e2006-01-11 12:17:49 -0800917 case RIO_HOST_REQ:
918 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
Al Virod886cb52006-05-27 00:08:25 -0400919 if (copy_from_user(&HostReq, argp, sizeof(HostReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800920 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
921 p->RIOError.Error = COPYIN_FAILED;
922 return -EFAULT;
923 }
924 if (HostReq.HostNum >= p->RIONumHosts) {
925 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
926 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
927 return -ENXIO;
928 }
929 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Alan Cox3d336aa2006-03-24 03:18:29 -0800931 if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800932 p->RIOError.Error = COPYOUT_FAILED;
933 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
934 return -EFAULT;
935 }
936 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Andrew Morton8d8706e2006-01-11 12:17:49 -0800938 case RIO_HOST_DPRAM:
939 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
Al Virod886cb52006-05-27 00:08:25 -0400940 if (copy_from_user(&HostDpRam, argp, sizeof(HostDpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800941 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
942 p->RIOError.Error = COPYIN_FAILED;
943 return -EFAULT;
944 }
945 if (HostDpRam.HostNum >= p->RIONumHosts) {
946 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
947 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
948 return -ENXIO;
949 }
950 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Andrew Morton8d8706e2006-01-11 12:17:49 -0800952 if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
953 int off;
954 /* It's hardware like this that really gets on my tits. */
955 static unsigned char copy[sizeof(struct DpRam)];
956 for (off = 0; off < sizeof(struct DpRam); off++)
Al Virod886cb52006-05-27 00:08:25 -0400957 copy[off] = readb(p->RIOHosts[HostDpRam.HostNum].Caddr + off);
Alan Cox3d336aa2006-03-24 03:18:29 -0800958 if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800959 p->RIOError.Error = COPYOUT_FAILED;
960 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
961 return -EFAULT;
962 }
Al Viro06458192006-05-27 02:11:12 -0400963 } else if (copy_from_io(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800964 p->RIOError.Error = COPYOUT_FAILED;
965 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
966 return -EFAULT;
967 }
968 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Andrew Morton8d8706e2006-01-11 12:17:49 -0800970 case RIO_SET_BUSY:
971 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
Al Virod886cb52006-05-27 00:08:25 -0400972 if (arg > 511) {
973 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800974 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
975 return -EINVAL;
976 }
977 rio_spin_lock_irqsave(&PortP->portSem, flags);
Al Virod886cb52006-05-27 00:08:25 -0400978 p->RIOPortp[arg]->State |= RIO_BUSY;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800979 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
980 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Andrew Morton8d8706e2006-01-11 12:17:49 -0800982 case RIO_HOST_PORT:
983 /*
984 ** The daemon want port information
985 ** (probably for debug reasons)
986 */
987 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
Al Virod886cb52006-05-27 00:08:25 -0400988 if (copy_from_user(&PortReq, argp, sizeof(PortReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800989 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
990 p->RIOError.Error = COPYIN_FAILED;
991 return -EFAULT;
992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Andrew Morton8d8706e2006-01-11 12:17:49 -0800994 if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
995 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
996 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
997 return -ENXIO;
998 }
999 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
Alan Cox3d336aa2006-03-24 03:18:29 -08001000 if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001001 p->RIOError.Error = COPYOUT_FAILED;
1002 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
1003 return -EFAULT;
1004 }
1005 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Andrew Morton8d8706e2006-01-11 12:17:49 -08001007 case RIO_HOST_RUP:
1008 /*
1009 ** The daemon want rup information
1010 ** (probably for debug reasons)
1011 */
1012 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
Al Virod886cb52006-05-27 00:08:25 -04001013 if (copy_from_user(&RupReq, argp, sizeof(RupReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001014 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1015 p->RIOError.Error = COPYIN_FAILED;
1016 return -EFAULT;
1017 }
1018 if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
1019 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
1020 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1021 return -ENXIO;
1022 }
1023 if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */
1024 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
1025 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1026 return -EINVAL;
1027 }
1028 HostP = &p->RIOHosts[RupReq.HostNum];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Andrew Morton8d8706e2006-01-11 12:17:49 -08001030 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1031 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
1032 p->RIOError.Error = HOST_NOT_RUNNING;
1033 return -EIO;
1034 }
1035 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Al Viro06458192006-05-27 02:11:12 -04001037 if (copy_from_io(RupReq.RupP, HostP->UnixRups[RupReq.RupNum].RupP, sizeof(struct RUP))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001038 p->RIOError.Error = COPYOUT_FAILED;
1039 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1040 return -EFAULT;
1041 }
1042 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Andrew Morton8d8706e2006-01-11 12:17:49 -08001044 case RIO_HOST_LPB:
1045 /*
1046 ** The daemon want lpb information
1047 ** (probably for debug reasons)
1048 */
1049 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
Al Virod886cb52006-05-27 00:08:25 -04001050 if (copy_from_user(&LpbReq, argp, sizeof(LpbReq))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001051 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1052 p->RIOError.Error = COPYIN_FAILED;
1053 return -EFAULT;
1054 }
1055 if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
1056 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
1057 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1058 return -ENXIO;
1059 }
1060 if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */
1061 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
1062 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
1063 return -EINVAL;
1064 }
1065 HostP = &p->RIOHosts[LpbReq.Host];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Andrew Morton8d8706e2006-01-11 12:17:49 -08001067 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
1068 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
1069 p->RIOError.Error = HOST_NOT_RUNNING;
1070 return -EIO;
1071 }
1072 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Al Viro06458192006-05-27 02:11:12 -04001074 if (copy_from_io(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001075 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1076 p->RIOError.Error = COPYOUT_FAILED;
1077 return -EFAULT;
1078 }
1079 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Andrew Morton8d8706e2006-01-11 12:17:49 -08001081 /*
1082 ** Here 3 IOCTL's that allow us to change the way in which
1083 ** rio logs errors. send them just to syslog or send them
1084 ** to both syslog and console or send them to just the console.
1085 **
1086 ** See RioStrBuf() in util.c for the other half.
1087 */
1088 case RIO_SYSLOG_ONLY:
1089 p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
1090 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Andrew Morton8d8706e2006-01-11 12:17:49 -08001092 case RIO_SYSLOG_CONS:
1093 p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */
1094 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Andrew Morton8d8706e2006-01-11 12:17:49 -08001096 case RIO_CONS_ONLY:
1097 p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
1098 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Andrew Morton8d8706e2006-01-11 12:17:49 -08001100 case RIO_SIGNALS_ON:
1101 if (p->RIOSignalProcess) {
1102 p->RIOError.Error = SIGNALS_ALREADY_SET;
1103 return -EBUSY;
1104 }
Alan Cox3d336aa2006-03-24 03:18:29 -08001105 /* FIXME: PID tracking */
1106 p->RIOSignalProcess = current->pid;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001107 p->RIOPrintDisabled = DONT_PRINT;
1108 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Andrew Morton8d8706e2006-01-11 12:17:49 -08001110 case RIO_SIGNALS_OFF:
Alan Cox3d336aa2006-03-24 03:18:29 -08001111 if (p->RIOSignalProcess != current->pid) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001112 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1113 return -EPERM;
1114 }
1115 rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
1116 p->RIOSignalProcess = 0;
1117 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Andrew Morton8d8706e2006-01-11 12:17:49 -08001119 case RIO_SET_BYTE_MODE:
1120 for (Host = 0; Host < p->RIONumHosts; Host++)
1121 if (p->RIOHosts[Host].Type == RIO_AT)
1122 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
1123 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Andrew Morton8d8706e2006-01-11 12:17:49 -08001125 case RIO_SET_WORD_MODE:
1126 for (Host = 0; Host < p->RIONumHosts; Host++)
1127 if (p->RIOHosts[Host].Type == RIO_AT)
1128 p->RIOHosts[Host].Mode |= WORD_OPERATION;
1129 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Andrew Morton8d8706e2006-01-11 12:17:49 -08001131 case RIO_SET_FAST_BUS:
1132 for (Host = 0; Host < p->RIONumHosts; Host++)
1133 if (p->RIOHosts[Host].Type == RIO_AT)
1134 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
1135 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Andrew Morton8d8706e2006-01-11 12:17:49 -08001137 case RIO_SET_SLOW_BUS:
1138 for (Host = 0; Host < p->RIONumHosts; Host++)
1139 if (p->RIOHosts[Host].Type == RIO_AT)
1140 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
1141 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Andrew Morton8d8706e2006-01-11 12:17:49 -08001143 case RIO_MAP_B50_TO_50:
1144 case RIO_MAP_B50_TO_57600:
1145 case RIO_MAP_B110_TO_110:
1146 case RIO_MAP_B110_TO_115200:
1147 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
Al Virod886cb52006-05-27 00:08:25 -04001148 port = arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001149 if (port < 0 || port > 511) {
1150 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1151 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1152 return -EINVAL;
1153 }
1154 rio_spin_lock_irqsave(&PortP->portSem, flags);
1155 switch (cmd) {
1156 case RIO_MAP_B50_TO_50:
1157 p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
1158 break;
1159 case RIO_MAP_B50_TO_57600:
1160 p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
1161 break;
1162 case RIO_MAP_B110_TO_110:
1163 p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
1164 break;
1165 case RIO_MAP_B110_TO_115200:
1166 p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
1167 break;
1168 }
1169 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1170 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Andrew Morton8d8706e2006-01-11 12:17:49 -08001172 case RIO_STREAM_INFO:
1173 rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
1174 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Andrew Morton8d8706e2006-01-11 12:17:49 -08001176 case RIO_SEND_PACKET:
1177 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
Al Virod886cb52006-05-27 00:08:25 -04001178 if (copy_from_user(&SendPack, argp, sizeof(SendPack))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001179 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1180 p->RIOError.Error = COPYIN_FAILED;
1181 return -EFAULT;
1182 }
1183 if (SendPack.PortNum >= 128) {
1184 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1185 return -ENXIO;
1186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Andrew Morton8d8706e2006-01-11 12:17:49 -08001188 PortP = p->RIOPortp[SendPack.PortNum];
1189 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Andrew Morton8d8706e2006-01-11 12:17:49 -08001191 if (!can_add_transmit(&PacketP, PortP)) {
1192 p->RIOError.Error = UNIT_IS_IN_USE;
1193 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1194 return -ENOSPC;
1195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Andrew Morton8d8706e2006-01-11 12:17:49 -08001197 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
Alan Cox3d336aa2006-03-24 03:18:29 -08001198 writeb(SendPack.Data[loop], &PacketP->data[loop]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Alan Cox3d336aa2006-03-24 03:18:29 -08001200 writeb(SendPack.Len, &PacketP->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Andrew Morton8d8706e2006-01-11 12:17:49 -08001202 add_transmit(PortP);
1203 /*
1204 ** Count characters transmitted for port statistics reporting
1205 */
1206 if (PortP->statsGather)
1207 PortP->txchars += (SendPack.Len & 127);
1208 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1209 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Andrew Morton8d8706e2006-01-11 12:17:49 -08001211 case RIO_NO_MESG:
1212 if (su)
1213 p->RIONoMessage = 1;
1214 return su ? 0 : -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Andrew Morton8d8706e2006-01-11 12:17:49 -08001216 case RIO_MESG:
1217 if (su)
1218 p->RIONoMessage = 0;
1219 return su ? 0 : -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
Andrew Morton8d8706e2006-01-11 12:17:49 -08001221 case RIO_WHAT_MESG:
Al Virod886cb52006-05-27 00:08:25 -04001222 if (copy_to_user(argp, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001223 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1224 p->RIOError.Error = COPYOUT_FAILED;
1225 return -EFAULT;
1226 }
1227 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
Andrew Morton8d8706e2006-01-11 12:17:49 -08001229 case RIO_MEM_DUMP:
Al Virod886cb52006-05-27 00:08:25 -04001230 if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001231 p->RIOError.Error = COPYIN_FAILED;
1232 return -EFAULT;
1233 }
1234 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 -07001235
Andrew Morton8d8706e2006-01-11 12:17:49 -08001236 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1237 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1238 return -EINVAL;
1239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Andrew Morton8d8706e2006-01-11 12:17:49 -08001241 if (SubCmd.Host >= p->RIONumHosts) {
1242 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1243 return -EINVAL;
1244 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Andrew Morton8d8706e2006-01-11 12:17:49 -08001246 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Andrew Morton8d8706e2006-01-11 12:17:49 -08001248 PortP = p->RIOPortp[port];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Andrew Morton8d8706e2006-01-11 12:17:49 -08001250 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Jiri Slabyd6f63412008-04-30 00:53:57 -07001252 if (RIOPreemptiveCmd(p, PortP, RIOC_MEMDUMP) == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001253 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1254 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1255 return -EBUSY;
1256 } else
1257 PortP->State |= RIO_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Andrew Morton8d8706e2006-01-11 12:17:49 -08001259 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Al Virod886cb52006-05-27 00:08:25 -04001260 if (copy_to_user(argp, p->RIOMemDump, MEMDUMP_SIZE)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001261 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1262 p->RIOError.Error = COPYOUT_FAILED;
1263 return -EFAULT;
1264 }
1265 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Andrew Morton8d8706e2006-01-11 12:17:49 -08001267 case RIO_TICK:
Al Virod886cb52006-05-27 00:08:25 -04001268 if (arg >= p->RIONumHosts)
Andrew Morton8d8706e2006-01-11 12:17:49 -08001269 return -EINVAL;
Al Virod886cb52006-05-27 00:08:25 -04001270 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", arg);
1271 writeb(0xFF, &p->RIOHosts[arg].SetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001272 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
Andrew Morton8d8706e2006-01-11 12:17:49 -08001274 case RIO_TOCK:
Al Virod886cb52006-05-27 00:08:25 -04001275 if (arg >= p->RIONumHosts)
Andrew Morton8d8706e2006-01-11 12:17:49 -08001276 return -EINVAL;
Al Virod886cb52006-05-27 00:08:25 -04001277 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", arg);
1278 writeb(0xFF, &p->RIOHosts[arg].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001279 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Andrew Morton8d8706e2006-01-11 12:17:49 -08001281 case RIO_READ_CHECK:
1282 /* Check reads for pkts with data[0] the same */
1283 p->RIOReadCheck = !p->RIOReadCheck;
Al Virod886cb52006-05-27 00:08:25 -04001284 if (copy_to_user(argp, &p->RIOReadCheck, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001285 p->RIOError.Error = COPYOUT_FAILED;
1286 return -EFAULT;
1287 }
1288 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Andrew Morton8d8706e2006-01-11 12:17:49 -08001290 case RIO_READ_REGISTER:
Al Virod886cb52006-05-27 00:08:25 -04001291 if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001292 p->RIOError.Error = COPYIN_FAILED;
1293 return -EFAULT;
1294 }
1295 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 -07001296
Andrew Morton8d8706e2006-01-11 12:17:49 -08001297 if (SubCmd.Port > 511) {
1298 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
1299 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1300 return -EINVAL;
1301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Andrew Morton8d8706e2006-01-11 12:17:49 -08001303 if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
1304 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
1305 return -EINVAL;
1306 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Andrew Morton8d8706e2006-01-11 12:17:49 -08001308 if (SubCmd.Host >= p->RIONumHosts) {
1309 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
1310 return -EINVAL;
1311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Andrew Morton8d8706e2006-01-11 12:17:49 -08001313 port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
1314 PortP = p->RIOPortp[port];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Andrew Morton8d8706e2006-01-11 12:17:49 -08001316 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Jiri Slabyd6f63412008-04-30 00:53:57 -07001318 if (RIOPreemptiveCmd(p, PortP, RIOC_READ_REGISTER) ==
1319 RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001320 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1321 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1322 return -EBUSY;
1323 } else
1324 PortP->State |= RIO_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Andrew Morton8d8706e2006-01-11 12:17:49 -08001326 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Al Virod886cb52006-05-27 00:08:25 -04001327 if (copy_to_user(argp, &p->CdRegister, sizeof(unsigned int))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001328 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1329 p->RIOError.Error = COPYOUT_FAILED;
1330 return -EFAULT;
1331 }
1332 return 0;
1333 /*
1334 ** rio_make_dev: given port number (0-511) ORed with port type
1335 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
1336 ** value to pass to mknod to create the correct device node.
1337 */
1338 case RIO_MAKE_DEV:
1339 {
Al Virod886cb52006-05-27 00:08:25 -04001340 unsigned int port = arg & RIO_MODEM_MASK;
Alan Cox3d336aa2006-03-24 03:18:29 -08001341 unsigned int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Al Virod886cb52006-05-27 00:08:25 -04001343 switch (arg & RIO_DEV_MASK) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001344 case RIO_DEV_DIRECT:
Alan Cox3d336aa2006-03-24 03:18:29 -08001345 ret = drv_makedev(MAJOR(dev), port);
1346 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
1347 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001348 case RIO_DEV_MODEM:
Alan Cox3d336aa2006-03-24 03:18:29 -08001349 ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1350 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
1351 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001352 case RIO_DEV_XPRINT:
Alan Cox3d336aa2006-03-24 03:18:29 -08001353 ret = drv_makedev(MAJOR(dev), port);
1354 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
1355 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001356 }
1357 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1358 return -EINVAL;
1359 }
1360 /*
1361 ** rio_minor: given a dev_t from a stat() call, return
1362 ** the port number (0-511) ORed with the port type
1363 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
1364 */
1365 case RIO_MINOR:
1366 {
1367 dev_t dv;
1368 int mino;
Alan Cox3d336aa2006-03-24 03:18:29 -08001369 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Al Virod886cb52006-05-27 00:08:25 -04001371 dv = (dev_t) (arg);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001372 mino = RIO_UNMODEM(dv);
1373
1374 if (RIO_ISMODEM(dv)) {
1375 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
Alan Cox3d336aa2006-03-24 03:18:29 -08001376 ret = mino | RIO_DEV_MODEM;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001377 } else {
1378 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
Alan Cox3d336aa2006-03-24 03:18:29 -08001379 ret = mino | RIO_DEV_DIRECT;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001380 }
Alan Cox3d336aa2006-03-24 03:18:29 -08001381 return ret;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 }
Andrew Morton8d8706e2006-01-11 12:17:49 -08001384 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
1386
Andrew Morton8d8706e2006-01-11 12:17:49 -08001387 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 return -EINVAL;
1389}
1390
1391/*
1392** Pre-emptive commands go on RUPs and are only one byte long.
1393*/
Alan Cox3d336aa2006-03-24 03:18:29 -08001394int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
1396 struct CmdBlk *CmdBlkP;
1397 struct PktCmd_M *PktCmdP;
1398 int Ret;
1399 ushort rup;
1400 int port;
1401
Andrew Morton8d8706e2006-01-11 12:17:49 -08001402 if (PortP->State & RIO_DELETED) {
1403 rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 return RIO_FAIL;
1405 }
1406
Alan Cox655fdea2006-05-15 09:44:26 -07001407 if ((PortP->InUse == (typeof(PortP->InUse))-1) ||
1408 !(CmdBlkP = RIOGetCmdBlk())) {
1409 rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block "
1410 "for command %d on port %d\n", Cmd, PortP->PortNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 return RIO_FAIL;
1412 }
1413
Alan Cox655fdea2006-05-15 09:44:26 -07001414 rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n",
1415 CmdBlkP, PortP->InUse);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Alan Cox655fdea2006-05-15 09:44:26 -07001417 PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Andrew Morton8d8706e2006-01-11 12:17:49 -08001419 CmdBlkP->Packet.src_unit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 if (PortP->SecondBlock)
1421 rup = PortP->ID2;
1422 else
1423 rup = PortP->RupNum;
1424 CmdBlkP->Packet.dest_unit = rup;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001425 CmdBlkP->Packet.src_port = COMMAND_RUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 CmdBlkP->Packet.dest_port = COMMAND_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001427 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1428 CmdBlkP->PostFuncP = RIOUnUse;
Alan Cox3d336aa2006-03-24 03:18:29 -08001429 CmdBlkP->PostArg = (unsigned long) PortP;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001430 PktCmdP->Command = Cmd;
1431 port = PortP->HostPort % (ushort) PORTS_PER_RTA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -08001433 ** Index ports 8-15 for 2nd block of 16 port RTA.
1434 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 if (PortP->SecondBlock)
1436 port += (ushort) PORTS_PER_RTA;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001437 PktCmdP->PhbNum = port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Andrew Morton8d8706e2006-01-11 12:17:49 -08001439 switch (Cmd) {
Jiri Slabyd6f63412008-04-30 00:53:57 -07001440 case RIOC_MEMDUMP:
Alan Cox655fdea2006-05-15 09:44:26 -07001441 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p "
1442 "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
Jiri Slabyd6f63412008-04-30 00:53:57 -07001443 PktCmdP->SubCommand = RIOC_MEMDUMP;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001444 PktCmdP->SubAddr = SubCmd.Addr;
1445 break;
Jiri Slabyd6f63412008-04-30 00:53:57 -07001446 case RIOC_FCLOSE:
Alan Cox655fdea2006-05-15 09:44:26 -07001447 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n",
1448 CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001449 break;
Jiri Slabyd6f63412008-04-30 00:53:57 -07001450 case RIOC_READ_REGISTER:
Alan Cox655fdea2006-05-15 09:44:26 -07001451 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) "
1452 "command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
Jiri Slabyd6f63412008-04-30 00:53:57 -07001453 PktCmdP->SubCommand = RIOC_READ_REGISTER;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001454 PktCmdP->SubAddr = SubCmd.Addr;
1455 break;
Jiri Slabyd6f63412008-04-30 00:53:57 -07001456 case RIOC_RESUME:
Alan Cox655fdea2006-05-15 09:44:26 -07001457 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n",
1458 CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001459 break;
Jiri Slabyd6f63412008-04-30 00:53:57 -07001460 case RIOC_RFLUSH:
Alan Cox655fdea2006-05-15 09:44:26 -07001461 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n",
1462 CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001463 CmdBlkP->PostFuncP = RIORFlushEnable;
1464 break;
Jiri Slabyd6f63412008-04-30 00:53:57 -07001465 case RIOC_SUSPEND:
Alan Cox655fdea2006-05-15 09:44:26 -07001466 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n",
1467 CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001468 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Jiri Slabyd6f63412008-04-30 00:53:57 -07001470 case RIOC_MGET:
Alan Cox655fdea2006-05-15 09:44:26 -07001471 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n",
1472 CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001473 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Jiri Slabyd6f63412008-04-30 00:53:57 -07001475 case RIOC_MSET:
1476 case RIOC_MBIC:
1477 case RIOC_MBIS:
Andrew Morton8d8706e2006-01-11 12:17:49 -08001478 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
Alan Cox655fdea2006-05-15 09:44:26 -07001479 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command "
1480 "blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001481 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Jiri Slabyd6f63412008-04-30 00:53:57 -07001483 case RIOC_WFLUSH:
Andrew Morton8d8706e2006-01-11 12:17:49 -08001484 /*
1485 ** If we have queued up the maximum number of Write flushes
1486 ** allowed then we should not bother sending any more to the
1487 ** RTA.
1488 */
Alan Cox655fdea2006-05-15 09:44:26 -07001489 if (PortP->WflushFlag == (typeof(PortP->WflushFlag))-1) {
1490 rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, "
1491 "WflushFlag about to wrap!");
Andrew Morton8d8706e2006-01-11 12:17:49 -08001492 RIOFreeCmdBlk(CmdBlkP);
1493 return (RIO_FAIL);
1494 } else {
Alan Cox655fdea2006-05-15 09:44:26 -07001495 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command "
1496 "blk %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001497 CmdBlkP->PostFuncP = RIOWFlushMark;
1498 }
1499 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 }
1501
1502 PortP->InUse++;
1503
Andrew Morton8d8706e2006-01-11 12:17:49 -08001504 Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
1506 return Ret;
1507}