ia64/linux-2.6.18-xen.hg

annotate drivers/char/rio/riocmd.c @ 893:f994bfe9b93b

linux/blktap2: reduce TLB flush scope

c/s 885 added very coarse TLB flushing. Since these flushes always
follow single page updates, single page flushes (when available) are
sufficient.

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