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