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