Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** ----------------------------------------------------------------------------- |
| 3 | ** |
| 4 | ** Perle Specialix driver for Linux |
| 5 | ** ported from the existing SCO driver source |
| 6 | ** |
| 7 | * |
| 8 | * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | ** |
| 24 | ** Module : riocmd.c |
| 25 | ** SID : 1.2 |
| 26 | ** Last Modified : 11/6/98 10:33:41 |
| 27 | ** Retrieved : 11/6/98 10:33:49 |
| 28 | ** |
| 29 | ** ident @(#)riocmd.c 1.2 |
| 30 | ** |
| 31 | ** ----------------------------------------------------------------------------- |
| 32 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #include <linux/module.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 35 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/slab.h> |
| 37 | #include <linux/errno.h> |
| 38 | #include <linux/tty.h> |
| 39 | #include <asm/io.h> |
| 40 | #include <asm/system.h> |
| 41 | #include <asm/string.h> |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 42 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #include <linux/termios.h> |
| 45 | #include <linux/serial.h> |
| 46 | |
| 47 | #include <linux/generic_serial.h> |
| 48 | |
| 49 | #include "linux_compat.h" |
| 50 | #include "rio_linux.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include "pkt.h" |
| 52 | #include "daemon.h" |
| 53 | #include "rio.h" |
| 54 | #include "riospace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include "cmdpkt.h" |
| 56 | #include "map.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include "rup.h" |
| 58 | #include "port.h" |
| 59 | #include "riodrvr.h" |
| 60 | #include "rioinfo.h" |
| 61 | #include "func.h" |
| 62 | #include "errors.h" |
| 63 | #include "pci.h" |
| 64 | |
| 65 | #include "parmmap.h" |
| 66 | #include "unixrup.h" |
| 67 | #include "board.h" |
| 68 | #include "host.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #include "phb.h" |
| 70 | #include "link.h" |
| 71 | #include "cmdblk.h" |
| 72 | #include "route.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #include "cirrus.h" |
| 74 | |
| 75 | |
| 76 | static struct IdentifyRta IdRta; |
| 77 | static struct KillNeighbour KillUnit; |
| 78 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 79 | int RIOFoadRta(struct Host *HostP, struct Map *MapP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
| 81 | struct CmdBlk *CmdBlkP; |
| 82 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 83 | rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | CmdBlkP = RIOGetCmdBlk(); |
| 86 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 87 | if (!CmdBlkP) { |
| 88 | rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: GetCmdBlk failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | return -ENXIO; |
| 90 | } |
| 91 | |
| 92 | CmdBlkP->Packet.dest_unit = MapP->ID; |
| 93 | CmdBlkP->Packet.dest_port = BOOT_RUP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 94 | CmdBlkP->Packet.src_unit = 0; |
| 95 | CmdBlkP->Packet.src_port = BOOT_RUP; |
| 96 | CmdBlkP->Packet.len = 0x84; |
| 97 | CmdBlkP->Packet.data[0] = IFOAD; |
| 98 | CmdBlkP->Packet.data[1] = 0; |
| 99 | CmdBlkP->Packet.data[2] = IFOAD_MAGIC & 0xFF; |
| 100 | CmdBlkP->Packet.data[3] = (IFOAD_MAGIC >> 8) & 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 102 | if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) { |
| 103 | rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: Failed to queue foad command\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | return -EIO; |
| 105 | } |
| 106 | return 0; |
| 107 | } |
| 108 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 109 | int RIOZombieRta(struct Host *HostP, struct Map *MapP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | struct CmdBlk *CmdBlkP; |
| 112 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 113 | rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | CmdBlkP = RIOGetCmdBlk(); |
| 116 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 117 | if (!CmdBlkP) { |
| 118 | rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: GetCmdBlk failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | return -ENXIO; |
| 120 | } |
| 121 | |
| 122 | CmdBlkP->Packet.dest_unit = MapP->ID; |
| 123 | CmdBlkP->Packet.dest_port = BOOT_RUP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 124 | CmdBlkP->Packet.src_unit = 0; |
| 125 | CmdBlkP->Packet.src_port = BOOT_RUP; |
| 126 | CmdBlkP->Packet.len = 0x84; |
| 127 | CmdBlkP->Packet.data[0] = ZOMBIE; |
| 128 | CmdBlkP->Packet.data[1] = 0; |
| 129 | CmdBlkP->Packet.data[2] = ZOMBIE_MAGIC & 0xFF; |
| 130 | CmdBlkP->Packet.data[3] = (ZOMBIE_MAGIC >> 8) & 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 132 | if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) { |
| 133 | rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: Failed to queue zombie command\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | return -EIO; |
| 135 | } |
| 136 | return 0; |
| 137 | } |
| 138 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 139 | int RIOCommandRta(struct rio_info *p, unsigned long RtaUnique, int (*func) (struct Host * HostP, struct Map * MapP)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 141 | unsigned int Host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 143 | rio_dprintk(RIO_DEBUG_CMD, "Command RTA 0x%lx func %p\n", RtaUnique, func); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 145 | if (!RtaUnique) |
| 146 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 148 | for (Host = 0; Host < p->RIONumHosts; Host++) { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 149 | unsigned int Rta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | struct Host *HostP = &p->RIOHosts[Host]; |
| 151 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 152 | for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | struct Map *MapP = &HostP->Mapping[Rta]; |
| 154 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 155 | if (MapP->RtaUniqueNum == RtaUnique) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | uint Link; |
| 157 | |
| 158 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 159 | ** now, lets just check we have a route to it... |
| 160 | ** IF the routing stuff is working, then one of the |
| 161 | ** topology entries for this unit will have a legit |
| 162 | ** route *somewhere*. We care not where - if its got |
| 163 | ** any connections, we can get to it. |
| 164 | */ |
| 165 | for (Link = 0; Link < LINKS_PER_UNIT; Link++) { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 166 | if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 168 | ** Its worth trying the operation... |
| 169 | */ |
| 170 | return (*func) (HostP, MapP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | return -ENXIO; |
| 177 | } |
| 178 | |
| 179 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 180 | int RIOIdentifyRta(struct rio_info *p, void __user * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 182 | unsigned int Host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 184 | if (copy_from_user(&IdRta, arg, sizeof(IdRta))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 185 | rio_dprintk(RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | p->RIOError.Error = COPYIN_FAILED; |
| 187 | return -EFAULT; |
| 188 | } |
| 189 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 190 | for (Host = 0; Host < p->RIONumHosts; Host++) { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 191 | unsigned int Rta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | struct Host *HostP = &p->RIOHosts[Host]; |
| 193 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 194 | for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | struct Map *MapP = &HostP->Mapping[Rta]; |
| 196 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 197 | if (MapP->RtaUniqueNum == IdRta.RtaUnique) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | uint Link; |
| 199 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 200 | ** now, lets just check we have a route to it... |
| 201 | ** IF the routing stuff is working, then one of the |
| 202 | ** topology entries for this unit will have a legit |
| 203 | ** route *somewhere*. We care not where - if its got |
| 204 | ** any connections, we can get to it. |
| 205 | */ |
| 206 | for (Link = 0; Link < LINKS_PER_UNIT; Link++) { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 207 | if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 209 | ** Its worth trying the operation... |
| 210 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | struct CmdBlk *CmdBlkP; |
| 212 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 213 | rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | CmdBlkP = RIOGetCmdBlk(); |
| 216 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 217 | if (!CmdBlkP) { |
| 218 | rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: GetCmdBlk failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return -ENXIO; |
| 220 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | CmdBlkP->Packet.dest_unit = MapP->ID; |
| 223 | CmdBlkP->Packet.dest_port = BOOT_RUP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 224 | CmdBlkP->Packet.src_unit = 0; |
| 225 | CmdBlkP->Packet.src_port = BOOT_RUP; |
| 226 | CmdBlkP->Packet.len = 0x84; |
| 227 | CmdBlkP->Packet.data[0] = IDENTIFY; |
| 228 | CmdBlkP->Packet.data[1] = 0; |
| 229 | CmdBlkP->Packet.data[2] = IdRta.ID; |
| 230 | |
| 231 | if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) { |
| 232 | rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: Failed to queue command\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | return -EIO; |
| 234 | } |
| 235 | return 0; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 240 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | return -ENOENT; |
| 242 | } |
| 243 | |
| 244 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 245 | int RIOKillNeighbour(struct rio_info *p, void __user * arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
| 247 | uint Host; |
| 248 | uint ID; |
| 249 | struct Host *HostP; |
| 250 | struct CmdBlk *CmdBlkP; |
| 251 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 252 | rio_dprintk(RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 254 | if (copy_from_user(&KillUnit, arg, sizeof(KillUnit))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 255 | rio_dprintk(RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | p->RIOError.Error = COPYIN_FAILED; |
| 257 | return -EFAULT; |
| 258 | } |
| 259 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 260 | if (KillUnit.Link > 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | return -ENXIO; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | CmdBlkP = RIOGetCmdBlk(); |
| 264 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 265 | if (!CmdBlkP) { |
| 266 | rio_dprintk(RIO_DEBUG_CMD, "UFOAD: GetCmdBlk failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | return -ENXIO; |
| 268 | } |
| 269 | |
| 270 | CmdBlkP->Packet.dest_unit = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 271 | CmdBlkP->Packet.src_unit = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | CmdBlkP->Packet.dest_port = BOOT_RUP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 273 | CmdBlkP->Packet.src_port = BOOT_RUP; |
| 274 | CmdBlkP->Packet.len = 0x84; |
| 275 | CmdBlkP->Packet.data[0] = UFOAD; |
| 276 | CmdBlkP->Packet.data[1] = KillUnit.Link; |
| 277 | CmdBlkP->Packet.data[2] = UFOAD_MAGIC & 0xFF; |
| 278 | CmdBlkP->Packet.data[3] = (UFOAD_MAGIC >> 8) & 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 280 | for (Host = 0; Host < p->RIONumHosts; Host++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | ID = 0; |
| 282 | HostP = &p->RIOHosts[Host]; |
| 283 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 284 | if (HostP->UniqueNum == KillUnit.UniqueNum) { |
| 285 | if (RIOQueueCmdBlk(HostP, RTAS_PER_HOST + KillUnit.Link, CmdBlkP) == RIO_FAIL) { |
| 286 | rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return -EIO; |
| 288 | } |
| 289 | return 0; |
| 290 | } |
| 291 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 292 | for (ID = 0; ID < RTAS_PER_HOST; ID++) { |
| 293 | if (HostP->Mapping[ID].RtaUniqueNum == KillUnit.UniqueNum) { |
| 294 | CmdBlkP->Packet.dest_unit = ID + 1; |
| 295 | if (RIOQueueCmdBlk(HostP, ID, CmdBlkP) == RIO_FAIL) { |
| 296 | rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | return -EIO; |
| 298 | } |
| 299 | return 0; |
| 300 | } |
| 301 | } |
| 302 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 303 | RIOFreeCmdBlk(CmdBlkP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return -ENXIO; |
| 305 | } |
| 306 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 307 | int RIOSuspendBootRta(struct Host *HostP, int ID, int Link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
| 309 | struct CmdBlk *CmdBlkP; |
| 310 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 311 | rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA ID %d, link %c\n", ID, 'A' + Link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | CmdBlkP = RIOGetCmdBlk(); |
| 314 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 315 | if (!CmdBlkP) { |
| 316 | rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: GetCmdBlk failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return -ENXIO; |
| 318 | } |
| 319 | |
| 320 | CmdBlkP->Packet.dest_unit = ID; |
| 321 | CmdBlkP->Packet.dest_port = BOOT_RUP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 322 | CmdBlkP->Packet.src_unit = 0; |
| 323 | CmdBlkP->Packet.src_port = BOOT_RUP; |
| 324 | CmdBlkP->Packet.len = 0x84; |
| 325 | CmdBlkP->Packet.data[0] = IWAIT; |
| 326 | CmdBlkP->Packet.data[1] = Link; |
| 327 | CmdBlkP->Packet.data[2] = IWAIT_MAGIC & 0xFF; |
| 328 | CmdBlkP->Packet.data[3] = (IWAIT_MAGIC >> 8) & 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 330 | if (RIOQueueCmdBlk(HostP, ID - 1, CmdBlkP) == RIO_FAIL) { |
| 331 | rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: Failed to queue iwait command\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | return -EIO; |
| 333 | } |
| 334 | return 0; |
| 335 | } |
| 336 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 337 | int RIOFoadWakeup(struct rio_info *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
| 339 | int port; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 340 | struct Port *PortP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | unsigned long flags; |
| 342 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 343 | for (port = 0; port < RIO_PORTS; port++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | PortP = p->RIOPortp[port]; |
| 345 | |
| 346 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 347 | PortP->Config = 0; |
| 348 | PortP->State = 0; |
| 349 | PortP->InUse = NOT_INUSE; |
| 350 | PortP->PortState = 0; |
| 351 | PortP->FlushCmdBodge = 0; |
| 352 | PortP->ModemLines = 0; |
| 353 | PortP->ModemState = 0; |
| 354 | PortP->CookMode = 0; |
| 355 | PortP->ParamSem = 0; |
| 356 | PortP->Mapped = 0; |
| 357 | PortP->WflushFlag = 0; |
| 358 | PortP->MagicFlags = 0; |
| 359 | PortP->RxDataStart = 0; |
| 360 | PortP->TxBufferIn = 0; |
| 361 | PortP->TxBufferOut = 0; |
| 362 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 363 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 364 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /* |
| 368 | ** Incoming command on the COMMAND_RUP to be processed. |
| 369 | */ |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 370 | static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, struct PKT __iomem *PacketP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 372 | struct PktCmd __iomem *PktCmdP = (struct PktCmd __iomem *)PacketP->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | struct Port *PortP; |
| 374 | struct UnixRup *UnixRupP; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 375 | unsigned short SysPort; |
| 376 | unsigned short ReportedModemStatus; |
| 377 | unsigned short rup; |
| 378 | unsigned short subCommand; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | unsigned long flags; |
| 380 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 381 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 384 | ** 16 port RTA note: |
| 385 | ** Command rup packets coming from the RTA will have pkt->data[1] (which |
| 386 | ** translates to PktCmdP->PhbNum) set to the host port number for the |
| 387 | ** particular unit. To access the correct BaseSysPort for a 16 port RTA, |
| 388 | ** we can use PhbNum to get the rup number for the appropriate 8 port |
| 389 | ** block (for the first block, this should be equal to 'Rup'). |
| 390 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 391 | rup = readb(&PktCmdP->PhbNum) / (unsigned short) PORTS_PER_RTA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | UnixRupP = &HostP->UnixRups[rup]; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 393 | SysPort = UnixRupP->BaseSysPort + (readb(&PktCmdP->PhbNum) % (unsigned short) PORTS_PER_RTA); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 394 | rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 396 | if (UnixRupP->BaseSysPort == NO_PORT) { |
| 397 | rio_dprintk(RIO_DEBUG_CMD, "OBSCURE ERROR!\n"); |
| 398 | rio_dprintk(RIO_DEBUG_CMD, "Diagnostics follow. Please WRITE THESE DOWN and report them to Specialix Technical Support\n"); |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 399 | rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Host number %Zd, name ``%s''\n", HostP - p->RIOHosts, HostP->Name); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 400 | rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
Eric Sesterhenn / Snakebyte | 84ea776 | 2007-05-10 22:22:48 -0700 | [diff] [blame] | 402 | if (Rup < (unsigned short) MAX_RUP) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 403 | rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for RTA ``%s''\n", HostP->Mapping[Rup].Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } else |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 405 | rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for link ``%c'' of host ``%s''\n", ('A' + Rup - MAX_RUP), HostP->Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Al Viro | 92af11c | 2006-05-27 02:24:14 -0400 | [diff] [blame] | 407 | rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Destination 0x%x:0x%x\n", readb(&PacketP->dest_unit), readb(&PacketP->dest_port)); |
| 408 | rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Source 0x%x:0x%x\n", readb(&PacketP->src_unit), readb(&PacketP->src_port)); |
| 409 | rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Length 0x%x (%d)\n", readb(&PacketP->len), readb(&PacketP->len)); |
| 410 | rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Control 0x%x (%d)\n", readb(&PacketP->control), readb(&PacketP->control)); |
| 411 | rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Check 0x%x (%d)\n", readw(&PacketP->csum), readw(&PacketP->csum)); |
| 412 | rio_dprintk(RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, " "Command Code 0x%x\n", readb(&PktCmdP->PhbNum), readb(&PktCmdP->Command)); |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 413 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 415 | PortP = p->RIOPortp[SysPort]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 417 | switch (readb(&PktCmdP->Command)) { |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 418 | case RIOC_BREAK_RECEIVED: |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 419 | rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n"); |
| 420 | /* If the current line disc. is not multi-threading and |
| 421 | the current processor is not the default, reset rup_intr |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 422 | and return 0 to ensure that the command packet is |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 423 | not freed. */ |
| 424 | /* Call tmgr HANGUP HERE */ |
| 425 | /* Fix this later when every thing works !!!! RAMRAJ */ |
| 426 | gs_got_break(&PortP->gs); |
| 427 | break; |
| 428 | |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 429 | case RIOC_COMPLETE: |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 430 | rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %Zd\n", readb(&PktCmdP->PhbNum), HostP - p->RIOHosts); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 431 | subCommand = 1; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 432 | switch (readb(&PktCmdP->SubCommand)) { |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 433 | case RIOC_MEMDUMP: |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 434 | rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", readb(&PktCmdP->SubCommand), readw(&PktCmdP->SubAddr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | break; |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 436 | case RIOC_READ_REGISTER: |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 437 | rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", readw(&PktCmdP->SubAddr)); |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 438 | p->CdRegister = (readb(&PktCmdP->ModemStatus) & RIOC_MSVR1_HOST); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 439 | break; |
| 440 | default: |
| 441 | subCommand = 0; |
| 442 | break; |
| 443 | } |
| 444 | if (subCommand) |
| 445 | break; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 446 | rio_dprintk(RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n", readb(&PktCmdP->PortStatus), PortP->PortState); |
| 447 | if (PortP->PortState != readb(&PktCmdP->PortStatus)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 448 | rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n"); |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 449 | PortP->PortState = readb(&PktCmdP->PortStatus); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 450 | /* What should we do here ... |
| 451 | wakeup( &PortP->PortState ); |
| 452 | */ |
| 453 | } else |
| 454 | rio_dprintk(RIO_DEBUG_CMD, "No change\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 456 | /* FALLTHROUGH */ |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 457 | case RIOC_MODEM_STATUS: |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 458 | /* |
| 459 | ** Knock out the tbusy and tstop bits, as these are not relevant |
| 460 | ** to the check for modem status change (they're just there because |
| 461 | ** it's a convenient place to put them!). |
| 462 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 463 | ReportedModemStatus = readb(&PktCmdP->ModemStatus); |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 464 | if ((PortP->ModemState & RIOC_MSVR1_HOST) == |
| 465 | (ReportedModemStatus & RIOC_MSVR1_HOST)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 466 | rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 468 | ** Update ModemState just in case tbusy or tstop states have |
| 469 | ** changed. |
| 470 | */ |
| 471 | PortP->ModemState = ReportedModemStatus; |
| 472 | } else { |
| 473 | rio_dprintk(RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n", PortP->ModemState, ReportedModemStatus); |
| 474 | PortP->ModemState = ReportedModemStatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | #ifdef MODEM_SUPPORT |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 476 | if (PortP->Mapped) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | /***********************************************************\ |
| 478 | ************************************************************* |
| 479 | *** *** |
| 480 | *** M O D E M S T A T E C H A N G E *** |
| 481 | *** *** |
| 482 | ************************************************************* |
| 483 | \***********************************************************/ |
| 484 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 485 | ** If the device is a modem, then check the modem |
| 486 | ** carrier. |
| 487 | */ |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 488 | if (PortP->gs.port.tty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | break; |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 490 | if (PortP->gs.port.tty->termios == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 493 | if (!(PortP->gs.port.tty->termios->c_cflag & CLOCAL) && ((PortP->State & (RIO_MOPEN | RIO_WOPEN)))) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 494 | |
| 495 | rio_dprintk(RIO_DEBUG_CMD, "Is there a Carrier?\n"); |
| 496 | /* |
| 497 | ** Is there a carrier? |
| 498 | */ |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 499 | if (PortP->ModemState & RIOC_MSVR1_CD) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 500 | /* |
| 501 | ** Has carrier just appeared? |
| 502 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | if (!(PortP->State & RIO_CARR_ON)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 504 | rio_dprintk(RIO_DEBUG_CMD, "Carrier just came up.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | PortP->State |= RIO_CARR_ON; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 506 | /* |
| 507 | ** wakeup anyone in WOPEN |
| 508 | */ |
| 509 | if (PortP->State & (PORT_ISOPEN | RIO_WOPEN)) |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 510 | wake_up_interruptible(&PortP->gs.port.open_wait); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 511 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } else { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 513 | /* |
| 514 | ** Has carrier just dropped? |
| 515 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | if (PortP->State & RIO_CARR_ON) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 517 | if (PortP->State & (PORT_ISOPEN | RIO_WOPEN | RIO_MOPEN)) |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 518 | tty_hangup(PortP->gs.port.tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | PortP->State &= ~RIO_CARR_ON; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 520 | rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n"); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | #endif |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 526 | } |
| 527 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 529 | default: |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 530 | rio_dprintk(RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %Zd\n", readb(&PktCmdP->Command), HostP - p->RIOHosts); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 531 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 534 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 535 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 537 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | /* |
| 541 | ** The command mechanism: |
| 542 | ** Each rup has a chain of commands associated with it. |
| 543 | ** This chain is maintained by routines in this file. |
| 544 | ** Periodically we are called and we run a quick check of all the |
| 545 | ** active chains to determine if there is a command to be executed, |
| 546 | ** and if the rup is ready to accept it. |
| 547 | ** |
| 548 | */ |
| 549 | |
| 550 | /* |
| 551 | ** Allocate an empty command block. |
| 552 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 553 | struct CmdBlk *RIOGetCmdBlk(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | { |
| 555 | struct CmdBlk *CmdBlkP; |
| 556 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 557 | CmdBlkP = kzalloc(sizeof(struct CmdBlk), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | return CmdBlkP; |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | ** Return a block to the head of the free list. |
| 563 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 564 | void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 566 | kfree(CmdBlkP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /* |
| 570 | ** attach a command block to the list of commands to be performed for |
| 571 | ** a given rup. |
| 572 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 573 | int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
| 575 | struct CmdBlk **Base; |
| 576 | struct UnixRup *UnixRupP; |
| 577 | unsigned long flags; |
| 578 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 579 | if (Rup >= (unsigned short) (MAX_RUP + LINKS_PER_UNIT)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 580 | rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup); |
| 581 | RIOFreeCmdBlk(CmdBlkP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | return RIO_FAIL; |
| 583 | } |
| 584 | |
| 585 | UnixRupP = &HostP->UnixRups[Rup]; |
| 586 | |
| 587 | rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); |
| 588 | |
| 589 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 590 | ** If the RUP is currently inactive, then put the request |
| 591 | ** straight on the RUP.... |
| 592 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 593 | if ((UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE) && (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 594 | : 1)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 595 | rio_dprintk(RIO_DEBUG_CMD, "RUP inactive-placing command straight on. Cmd byte is 0x%x\n", CmdBlkP->Packet.data[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
| 597 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 598 | ** Whammy! blat that pack! |
| 599 | */ |
Al Viro | 92af11c | 2006-05-27 02:24:14 -0400 | [diff] [blame] | 600 | HostP->Copy(&CmdBlkP->Packet, RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->txpkt)), sizeof(struct PKT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 603 | ** place command packet on the pending position. |
| 604 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | UnixRupP->CmdPendingP = CmdBlkP; |
| 606 | |
| 607 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 608 | ** set the command register |
| 609 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 610 | writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
| 612 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); |
| 613 | |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 614 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 616 | rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 618 | if (UnixRupP->CmdsWaitingP != NULL) |
| 619 | rio_dprintk(RIO_DEBUG_CMD, "Rup active - command waiting\n"); |
| 620 | if (UnixRupP->CmdPendingP != NULL) |
| 621 | rio_dprintk(RIO_DEBUG_CMD, "Rup active - command pending\n"); |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 622 | if (readw(&UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 623 | rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | Base = &UnixRupP->CmdsWaitingP; |
| 626 | |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 627 | rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk %p at %p\n", CmdBlkP, Base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 629 | while (*Base) { |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 630 | rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk %p here\n", *Base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | Base = &((*Base)->NextP); |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 632 | rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk %p at %p\n", CmdBlkP, Base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 635 | rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk %p at %p\n", CmdBlkP, Base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
| 637 | *Base = CmdBlkP; |
| 638 | |
| 639 | CmdBlkP->NextP = NULL; |
| 640 | |
| 641 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); |
| 642 | |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 643 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | /* |
| 647 | ** Here we go - if there is an empty rup, fill it! |
| 648 | ** must be called at splrio() or higher. |
| 649 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 650 | void RIOPollHostCommands(struct rio_info *p, struct Host *HostP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 652 | struct CmdBlk *CmdBlkP; |
| 653 | struct UnixRup *UnixRupP; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 654 | struct PKT __iomem *PacketP; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 655 | unsigned short Rup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | unsigned long flags; |
| 657 | |
| 658 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 659 | Rup = MAX_RUP + LINKS_PER_UNIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 661 | do { /* do this loop for each RUP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 663 | ** locate the rup we are processing & lock it |
| 664 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | UnixRupP = &HostP->UnixRups[--Rup]; |
| 666 | |
| 667 | spin_lock_irqsave(&UnixRupP->RupLock, flags); |
| 668 | |
| 669 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 670 | ** First check for incoming commands: |
| 671 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 672 | if (readw(&UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | int FreeMe; |
| 674 | |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 675 | PacketP = (struct PKT __iomem *) RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->rxpkt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 677 | switch (readb(&PacketP->dest_port)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 678 | case BOOT_RUP: |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 679 | rio_dprintk(RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n", readb(&PacketP->len) & 0x80 ? "Command" : "Data", readb(&PacketP->data[0])); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 680 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); |
| 681 | FreeMe = RIOBootRup(p, Rup, HostP, PacketP); |
| 682 | rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); |
| 683 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 685 | case COMMAND_RUP: |
| 686 | /* |
| 687 | ** Free the RUP lock as loss of carrier causes a |
| 688 | ** ttyflush which will (eventually) call another |
| 689 | ** routine that uses the RUP lock. |
| 690 | */ |
| 691 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); |
| 692 | FreeMe = RIOCommandRup(p, Rup, HostP, PacketP); |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 693 | if (readb(&PacketP->data[5]) == RIOC_MEMDUMP) { |
Al Viro | 92af11c | 2006-05-27 02:24:14 -0400 | [diff] [blame] | 694 | rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", readw(&(PacketP->data[6]))); |
Al Viro | 1bf0871 | 2006-05-27 01:55:52 -0400 | [diff] [blame] | 695 | rio_memcpy_fromio(p->RIOMemDump, &(PacketP->data[8]), 32); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 696 | } |
| 697 | rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); |
| 698 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 700 | case ROUTE_RUP: |
| 701 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); |
| 702 | FreeMe = RIORouteRup(p, Rup, HostP, PacketP); |
| 703 | rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); |
| 704 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 706 | default: |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 707 | rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", readb(&PacketP->dest_port)); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 708 | FreeMe = 1; |
| 709 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 712 | if (FreeMe) { |
| 713 | rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n"); |
| 714 | put_free_end(HostP, PacketP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 716 | writew(RX_RUP_INACTIVE, &UnixRupP->RupP->rxcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 718 | if (readw(&UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 719 | rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup); |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 720 | writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &UnixRupP->RupP->handshake); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 726 | ** IF a command was running on the port, |
| 727 | ** and it has completed, then tidy it up. |
| 728 | */ |
| 729 | if ((CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 730 | (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 732 | ** we are idle. |
| 733 | ** there is a command in pending. |
| 734 | ** Therefore, this command has finished. |
| 735 | ** So, wakeup whoever is waiting for it (and tell them |
| 736 | ** what happened). |
| 737 | */ |
| 738 | if (CmdBlkP->Packet.dest_port == BOOT_RUP) |
| 739 | rio_dprintk(RIO_DEBUG_CMD, "Free Boot %s Command Block '%x'\n", CmdBlkP->Packet.len & 0x80 ? "Command" : "Data", CmdBlkP->Packet.data[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 741 | rio_dprintk(RIO_DEBUG_CMD, "Command %p completed\n", CmdBlkP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
| 743 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 744 | ** Clear the Rup lock to prevent mutual exclusion. |
| 745 | */ |
| 746 | if (CmdBlkP->PostFuncP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 748 | (*CmdBlkP->PostFuncP) (CmdBlkP->PostArg, CmdBlkP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); |
| 750 | } |
| 751 | |
| 752 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 753 | ** ....clear the pending flag.... |
| 754 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | UnixRupP->CmdPendingP = NULL; |
| 756 | |
| 757 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 758 | ** ....and return the command block to the freelist. |
| 759 | */ |
| 760 | RIOFreeCmdBlk(CmdBlkP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 764 | ** If there is a command for this rup, and the rup |
| 765 | ** is idle, then process the command |
| 766 | */ |
| 767 | if ((CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 768 | (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 770 | ** if the pre-function is non-zero, call it. |
| 771 | ** If it returns RIO_FAIL then don't |
| 772 | ** send this command yet! |
| 773 | */ |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 774 | if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : 1)) { |
| 775 | rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command %p\n", CmdBlkP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 776 | } else { |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 777 | rio_dprintk(RIO_DEBUG_CMD, "Start new command %p Cmd byte is 0x%x\n", CmdBlkP, CmdBlkP->Packet.data[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 779 | ** Whammy! blat that pack! |
| 780 | */ |
Al Viro | 92af11c | 2006-05-27 02:24:14 -0400 | [diff] [blame] | 781 | HostP->Copy(&CmdBlkP->Packet, RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->txpkt)), sizeof(struct PKT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
| 783 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 784 | ** remove the command from the rup command queue... |
| 785 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | UnixRupP->CmdsWaitingP = CmdBlkP->NextP; |
| 787 | |
| 788 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 789 | ** ...and place it on the pending position. |
| 790 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | UnixRupP->CmdPendingP = CmdBlkP; |
| 792 | |
| 793 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 794 | ** set the command register |
| 795 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 796 | writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
| 798 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 799 | ** the command block will be freed |
| 800 | ** when the command has been processed. |
| 801 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | spin_unlock_irqrestore(&UnixRupP->RupLock, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 805 | } while (Rup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 808 | int RIOWFlushMark(unsigned long iPortP, struct CmdBlk *CmdBlkP) |
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 | struct Port *PortP = (struct Port *) iPortP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | unsigned long flags; |
| 812 | |
| 813 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | PortP->WflushFlag++; |
| 815 | PortP->MagicFlags |= MAGIC_FLUSH; |
| 816 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 817 | return RIOUnUse(iPortP, CmdBlkP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 820 | int RIORFlushEnable(unsigned long iPortP, struct CmdBlk *CmdBlkP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 822 | struct Port *PortP = (struct Port *) iPortP; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 823 | struct PKT __iomem *PacketP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | unsigned long flags; |
| 825 | |
| 826 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 827 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 828 | while (can_remove_receive(&PacketP, PortP)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | remove_receive(PortP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 830 | put_free_end(PortP->HostP, PacketP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 833 | if (readw(&PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 835 | ** MAGIC! (Basically, handshake the RX buffer, so that |
| 836 | ** the RTAs upstream can be re-enabled.) |
| 837 | */ |
| 838 | rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n"); |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 839 | writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &PortP->PhbP->handshake); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } |
| 841 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 842 | return RIOUnUse(iPortP, CmdBlkP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 845 | int RIOUnUse(unsigned long iPortP, struct CmdBlk *CmdBlkP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 847 | struct Port *PortP = (struct Port *) iPortP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | unsigned long flags; |
| 849 | |
| 850 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 851 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 852 | rio_dprintk(RIO_DEBUG_CMD, "Decrement in use count for port\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
| 854 | if (PortP->InUse) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 855 | if (--PortP->InUse != NOT_INUSE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 857 | return 0; |
| 858 | } |
| 859 | } |
| 860 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 861 | ** While PortP->InUse is set (i.e. a preemptive command has been sent to |
| 862 | ** the RTA and is awaiting completion), any transmit data is prevented from |
| 863 | ** being transferred from the write queue into the transmit packets |
| 864 | ** (add_transmit) and no furthur transmit interrupt will be sent for that |
| 865 | ** data. The next interrupt will occur up to 500ms later (RIOIntr is called |
| 866 | ** twice a second as a saftey measure). This was the case when kermit was |
| 867 | ** used to send data into a RIO port. After each packet was sent, TCFLSH |
| 868 | ** was called to flush the read queue preemptively. PortP->InUse was |
| 869 | ** incremented, thereby blocking the 6 byte acknowledgement packet |
| 870 | ** transmitted back. This acknowledgment hung around for 500ms before |
| 871 | ** being sent, thus reducing input performance substantially!. |
| 872 | ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data |
| 873 | ** hanging around in the transmit buffer is sent immediately. |
| 874 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 875 | writew(1, &PortP->HostP->ParmMapP->tx_intr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | /* What to do here .. |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 877 | wakeup( (caddr_t)&(PortP->InUse) ); |
| 878 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 880 | return 0; |
| 881 | } |
| 882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | /* |
| 884 | ** |
| 885 | ** How to use this file: |
| 886 | ** |
| 887 | ** To send a command down a rup, you need to allocate a command block, fill |
| 888 | ** in the packet information, fill in the command number, fill in the pre- |
| 889 | ** and post- functions and arguments, and then add the command block to the |
| 890 | ** queue of command blocks for the port in question. When the port is idle, |
| 891 | ** then the pre-function will be called. If this returns RIO_FAIL then the |
| 892 | ** command will be re-queued and tried again at a later date (probably in one |
| 893 | ** clock tick). If the pre-function returns NOT RIO_FAIL, then the command |
| 894 | ** packet will be queued on the RUP, and the txcontrol field set to the |
| 895 | ** command number. When the txcontrol field has changed from being the |
| 896 | ** command number, then the post-function will be called, with the argument |
| 897 | ** specified earlier, a pointer to the command block, and the value of |
| 898 | ** txcontrol. |
| 899 | ** |
| 900 | ** To allocate a command block, call RIOGetCmdBlk(). This returns a pointer |
| 901 | ** to the command block structure allocated, or NULL if there aren't any. |
| 902 | ** The block will have been zeroed for you. |
| 903 | ** |
| 904 | ** The structure has the following fields: |
| 905 | ** |
| 906 | ** struct CmdBlk |
| 907 | ** { |
| 908 | ** struct CmdBlk *NextP; ** Pointer to next command block ** |
| 909 | ** struct PKT Packet; ** A packet, to copy to the rup ** |
| 910 | ** int (*PreFuncP)(); ** The func to call to check if OK ** |
| 911 | ** int PreArg; ** The arg for the func ** |
| 912 | ** int (*PostFuncP)(); ** The func to call when completed ** |
| 913 | ** int PostArg; ** The arg for the func ** |
| 914 | ** }; |
| 915 | ** |
| 916 | ** You need to fill in ALL fields EXCEPT NextP, which is used to link the |
| 917 | ** blocks together either on the free list or on the Rup list. |
| 918 | ** |
| 919 | ** Packet is an actual packet structure to be filled in with the packet |
| 920 | ** information associated with the command. You need to fill in everything, |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 921 | ** as the command processor doesn't process the command packet in any way. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | ** |
| 923 | ** The PreFuncP is called before the packet is enqueued on the host rup. |
| 924 | ** PreFuncP is called as (*PreFuncP)(PreArg, CmdBlkP);. PreFuncP must |
| 925 | ** return !RIO_FAIL to have the packet queued on the rup, and RIO_FAIL |
| 926 | ** if the packet is NOT to be queued. |
| 927 | ** |
| 928 | ** The PostFuncP is called when the command has completed. It is called |
| 929 | ** as (*PostFuncP)(PostArg, CmdBlkP, txcontrol);. PostFuncP is not expected |
| 930 | ** to return a value. PostFuncP does NOT need to free the command block, |
| 931 | ** as this happens automatically after PostFuncP returns. |
| 932 | ** |
| 933 | ** Once the command block has been filled in, it is attached to the correct |
| 934 | ** queue by calling RIOQueueCmdBlk( HostP, Rup, CmdBlkP ) where HostP is |
| 935 | ** a pointer to the struct Host, Rup is the NUMBER of the rup (NOT a pointer |
| 936 | ** to it!), and CmdBlkP is the pointer to the command block allocated using |
| 937 | ** RIOGetCmdBlk(). |
| 938 | ** |
| 939 | */ |