2 ** -----------------------------------------------------------------------------
4 ** Perle Specialix driver for Linux
5 ** ported from the existing SCO driver source
8 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
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.
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.
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.
26 ** Last Modified : 11/6/98 10:33:41
27 ** Retrieved : 11/6/98 10:33:49
29 ** ident @(#)riocmd.c 1.2
31 ** -----------------------------------------------------------------------------
34 static char *_riocmd_c_sccs_ = "@(#)riocmd.c 1.2";
37 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/errno.h>
40 #include <linux/tty.h>
42 #include <asm/system.h>
43 #include <asm/string.h>
44 #include <asm/semaphore.h>
45 #include <asm/uaccess.h>
47 #include <linux/termios.h>
48 #include <linux/serial.h>
50 #include <linux/generic_serial.h>
52 #include "linux_compat.h"
53 #include "rio_linux.h"
84 static struct IdentifyRta IdRta;
85 static struct KillNeighbour KillUnit;
87 int RIOFoadRta(struct Host *HostP, struct Map *MapP)
89 struct CmdBlk *CmdBlkP;
91 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA\n");
93 CmdBlkP = RIOGetCmdBlk();
96 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: GetCmdBlk failed\n");
100 CmdBlkP->Packet.dest_unit = MapP->ID;
101 CmdBlkP->Packet.dest_port = BOOT_RUP;
102 CmdBlkP->Packet.src_unit = 0;
103 CmdBlkP->Packet.src_port = BOOT_RUP;
104 CmdBlkP->Packet.len = 0x84;
105 CmdBlkP->Packet.data[0] = IFOAD;
106 CmdBlkP->Packet.data[1] = 0;
107 CmdBlkP->Packet.data[2] = IFOAD_MAGIC & 0xFF;
108 CmdBlkP->Packet.data[3] = (IFOAD_MAGIC >> 8) & 0xFF;
110 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
111 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: Failed to queue foad command\n");
117 int RIOZombieRta(struct Host *HostP, struct Map *MapP)
119 struct CmdBlk *CmdBlkP;
121 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA\n");
123 CmdBlkP = RIOGetCmdBlk();
126 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: GetCmdBlk failed\n");
130 CmdBlkP->Packet.dest_unit = MapP->ID;
131 CmdBlkP->Packet.dest_port = BOOT_RUP;
132 CmdBlkP->Packet.src_unit = 0;
133 CmdBlkP->Packet.src_port = BOOT_RUP;
134 CmdBlkP->Packet.len = 0x84;
135 CmdBlkP->Packet.data[0] = ZOMBIE;
136 CmdBlkP->Packet.data[1] = 0;
137 CmdBlkP->Packet.data[2] = ZOMBIE_MAGIC & 0xFF;
138 CmdBlkP->Packet.data[3] = (ZOMBIE_MAGIC >> 8) & 0xFF;
140 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
141 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: Failed to queue zombie command\n");
147 int RIOCommandRta(struct rio_info *p, unsigned long RtaUnique, int (*func) (struct Host * HostP, struct Map * MapP))
151 rio_dprintk(RIO_DEBUG_CMD, "Command RTA 0x%lx func 0x%p\n", RtaUnique, func);
156 for (Host = 0; Host < p->RIONumHosts; Host++) {
158 struct Host *HostP = &p->RIOHosts[Host];
160 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
161 struct Map *MapP = &HostP->Mapping[Rta];
163 if (MapP->RtaUniqueNum == RtaUnique) {
167 ** now, lets just check we have a route to it...
168 ** IF the routing stuff is working, then one of the
169 ** topology entries for this unit will have a legit
170 ** route *somewhere*. We care not where - if its got
171 ** any connections, we can get to it.
173 for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
174 if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) {
176 ** Its worth trying the operation...
178 return (*func) (HostP, MapP);
188 int RIOIdentifyRta(struct rio_info *p, void * arg)
192 if (copy_from_user(&IdRta, arg, sizeof(IdRta))) {
193 rio_dprintk(RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n");
194 p->RIOError.Error = COPYIN_FAILED;
198 for (Host = 0; Host < p->RIONumHosts; Host++) {
200 struct Host *HostP = &p->RIOHosts[Host];
202 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
203 struct Map *MapP = &HostP->Mapping[Rta];
205 if (MapP->RtaUniqueNum == IdRta.RtaUnique) {
208 ** now, lets just check we have a route to it...
209 ** IF the routing stuff is working, then one of the
210 ** topology entries for this unit will have a legit
211 ** route *somewhere*. We care not where - if its got
212 ** any connections, we can get to it.
214 for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
215 if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) {
217 ** Its worth trying the operation...
219 struct CmdBlk *CmdBlkP;
221 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA\n");
223 CmdBlkP = RIOGetCmdBlk();
226 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: GetCmdBlk failed\n");
230 CmdBlkP->Packet.dest_unit = MapP->ID;
231 CmdBlkP->Packet.dest_port = BOOT_RUP;
232 CmdBlkP->Packet.src_unit = 0;
233 CmdBlkP->Packet.src_port = BOOT_RUP;
234 CmdBlkP->Packet.len = 0x84;
235 CmdBlkP->Packet.data[0] = IDENTIFY;
236 CmdBlkP->Packet.data[1] = 0;
237 CmdBlkP->Packet.data[2] = IdRta.ID;
239 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
240 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: Failed to queue command\n");
253 int RIOKillNeighbour(struct rio_info *p, void * arg)
258 struct CmdBlk *CmdBlkP;
260 rio_dprintk(RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n");
262 if (copy_from_user(&KillUnit, arg, sizeof(KillUnit))) {
263 rio_dprintk(RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n");
264 p->RIOError.Error = COPYIN_FAILED;
268 if (KillUnit.Link > 3)
271 CmdBlkP = RIOGetCmdBlk();
274 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: GetCmdBlk failed\n");
278 CmdBlkP->Packet.dest_unit = 0;
279 CmdBlkP->Packet.src_unit = 0;
280 CmdBlkP->Packet.dest_port = BOOT_RUP;
281 CmdBlkP->Packet.src_port = BOOT_RUP;
282 CmdBlkP->Packet.len = 0x84;
283 CmdBlkP->Packet.data[0] = UFOAD;
284 CmdBlkP->Packet.data[1] = KillUnit.Link;
285 CmdBlkP->Packet.data[2] = UFOAD_MAGIC & 0xFF;
286 CmdBlkP->Packet.data[3] = (UFOAD_MAGIC >> 8) & 0xFF;
288 for (Host = 0; Host < p->RIONumHosts; Host++) {
290 HostP = &p->RIOHosts[Host];
292 if (HostP->UniqueNum == KillUnit.UniqueNum) {
293 if (RIOQueueCmdBlk(HostP, RTAS_PER_HOST + KillUnit.Link, CmdBlkP) == RIO_FAIL) {
294 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
300 for (ID = 0; ID < RTAS_PER_HOST; ID++) {
301 if (HostP->Mapping[ID].RtaUniqueNum == KillUnit.UniqueNum) {
302 CmdBlkP->Packet.dest_unit = ID + 1;
303 if (RIOQueueCmdBlk(HostP, ID, CmdBlkP) == RIO_FAIL) {
304 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
311 RIOFreeCmdBlk(CmdBlkP);
315 int RIOSuspendBootRta(struct Host *HostP, int ID, int Link)
317 struct CmdBlk *CmdBlkP;
319 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA ID %d, link %c\n", ID, 'A' + Link);
321 CmdBlkP = RIOGetCmdBlk();
324 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: GetCmdBlk failed\n");
328 CmdBlkP->Packet.dest_unit = ID;
329 CmdBlkP->Packet.dest_port = BOOT_RUP;
330 CmdBlkP->Packet.src_unit = 0;
331 CmdBlkP->Packet.src_port = BOOT_RUP;
332 CmdBlkP->Packet.len = 0x84;
333 CmdBlkP->Packet.data[0] = IWAIT;
334 CmdBlkP->Packet.data[1] = Link;
335 CmdBlkP->Packet.data[2] = IWAIT_MAGIC & 0xFF;
336 CmdBlkP->Packet.data[3] = (IWAIT_MAGIC >> 8) & 0xFF;
338 if (RIOQueueCmdBlk(HostP, ID - 1, CmdBlkP) == RIO_FAIL) {
339 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: Failed to queue iwait command\n");
345 int RIOFoadWakeup(struct rio_info *p)
351 for (port = 0; port < RIO_PORTS; port++) {
352 PortP = p->RIOPortp[port];
354 rio_spin_lock_irqsave(&PortP->portSem, flags);
357 PortP->InUse = NOT_INUSE;
358 PortP->PortState = 0;
359 PortP->FlushCmdBodge = 0;
360 PortP->ModemLines = 0;
361 PortP->ModemState = 0;
365 PortP->WflushFlag = 0;
366 PortP->MagicFlags = 0;
367 PortP->RxDataStart = 0;
368 PortP->TxBufferIn = 0;
369 PortP->TxBufferOut = 0;
370 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
376 ** Incoming command on the COMMAND_RUP to be processed.
378 static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
380 struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
382 struct UnixRup *UnixRupP;
383 unsigned short SysPort;
384 unsigned short ReportedModemStatus;
386 unsigned short subCommand;
393 ** Command rup packets coming from the RTA will have pkt->data[1] (which
394 ** translates to PktCmdP->PhbNum) set to the host port number for the
395 ** particular unit. To access the correct BaseSysPort for a 16 port RTA,
396 ** we can use PhbNum to get the rup number for the appropriate 8 port
397 ** block (for the first block, this should be equal to 'Rup').
399 rup = readb(&PktCmdP->PhbNum) / (unsigned short) PORTS_PER_RTA;
400 UnixRupP = &HostP->UnixRups[rup];
401 SysPort = UnixRupP->BaseSysPort + (readb(&PktCmdP->PhbNum) % (unsigned short) PORTS_PER_RTA);
402 rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort);
404 if (UnixRupP->BaseSysPort == NO_PORT) {
405 rio_dprintk(RIO_DEBUG_CMD, "OBSCURE ERROR!\n");
406 rio_dprintk(RIO_DEBUG_CMD, "Diagnostics follow. Please WRITE THESE DOWN and report them to Specialix Technical Support\n");
407 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Host number %Zd, name ``%s''\n", HostP - p->RIOHosts, HostP->Name);
408 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup);
410 if (Rup >= (unsigned short) MAX_RUP) {
411 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for RTA ``%s''\n", HostP->Mapping[Rup].Name);
413 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for link ``%c'' of host ``%s''\n", ('A' + Rup - MAX_RUP), HostP->Name);
415 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Destination 0x%x:0x%x\n", PacketP->dest_unit, PacketP->dest_port);
416 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Source 0x%x:0x%x\n", PacketP->src_unit, PacketP->src_port);
417 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Length 0x%x (%d)\n", PacketP->len, PacketP->len);
418 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Control 0x%x (%d)\n", PacketP->control, PacketP->control);
419 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Check 0x%x (%d)\n", PacketP->csum, PacketP->csum);
420 rio_dprintk(RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, " "Command Code 0x%x\n", PktCmdP->PhbNum, PktCmdP->Command);
423 PortP = p->RIOPortp[SysPort];
424 rio_spin_lock_irqsave(&PortP->portSem, flags);
425 switch (readb(&PktCmdP->Command)) {
427 rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n");
428 /* If the current line disc. is not multi-threading and
429 the current processor is not the default, reset rup_intr
430 and return FALSE to ensure that the command packet is
432 /* Call tmgr HANGUP HERE */
433 /* Fix this later when every thing works !!!! RAMRAJ */
434 gs_got_break(&PortP->gs);
438 rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %Zd\n", readb(&PktCmdP->PhbNum), HostP - p->RIOHosts);
440 switch (readb(&PktCmdP->SubCommand)) {
442 rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", readb(&PktCmdP->SubCommand), readw(&PktCmdP->SubAddr));
445 rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", readw(&PktCmdP->SubAddr));
446 p->CdRegister = (readb(&PktCmdP->ModemStatus) & MSVR1_HOST);
454 rio_dprintk(RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n", readb(&PktCmdP->PortStatus), PortP->PortState);
455 if (PortP->PortState != readb(&PktCmdP->PortStatus)) {
456 rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n");
457 PortP->PortState = readb(&PktCmdP->PortStatus);
458 /* What should we do here ...
459 wakeup( &PortP->PortState );
462 rio_dprintk(RIO_DEBUG_CMD, "No change\n");
467 ** Knock out the tbusy and tstop bits, as these are not relevant
468 ** to the check for modem status change (they're just there because
469 ** it's a convenient place to put them!).
471 ReportedModemStatus = readb(&PktCmdP->ModemStatus);
472 if ((PortP->ModemState & MSVR1_HOST) == (ReportedModemStatus & MSVR1_HOST)) {
473 rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
475 ** Update ModemState just in case tbusy or tstop states have
478 PortP->ModemState = ReportedModemStatus;
480 rio_dprintk(RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n", PortP->ModemState, ReportedModemStatus);
481 PortP->ModemState = ReportedModemStatus;
484 /***********************************************************\
485 *************************************************************
487 *** M O D E M S T A T E C H A N G E ***
489 *************************************************************
490 \***********************************************************/
492 ** If the device is a modem, then check the modem
495 if (PortP->gs.tty == NULL)
497 if (PortP->gs.tty->termios == NULL)
500 if (!(PortP->gs.tty->termios->c_cflag & CLOCAL) && ((PortP->State & (RIO_MOPEN | RIO_WOPEN)))) {
502 rio_dprintk(RIO_DEBUG_CMD, "Is there a Carrier?\n");
504 ** Is there a carrier?
506 if (PortP->ModemState & MSVR1_CD) {
508 ** Has carrier just appeared?
510 if (!(PortP->State & RIO_CARR_ON)) {
511 rio_dprintk(RIO_DEBUG_CMD, "Carrier just came up.\n");
512 PortP->State |= RIO_CARR_ON;
514 ** wakeup anyone in WOPEN
516 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN))
517 wake_up_interruptible(&PortP->gs.open_wait);
521 ** Has carrier just dropped?
523 if (PortP->State & RIO_CARR_ON) {
524 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN | RIO_MOPEN))
525 tty_hangup(PortP->gs.tty);
526 PortP->State &= ~RIO_CARR_ON;
527 rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n");
537 rio_dprintk(RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %Zd\n", readb(&PktCmdP->Command), HostP - p->RIOHosts);
540 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
548 ** The command mechanism:
549 ** Each rup has a chain of commands associated with it.
550 ** This chain is maintained by routines in this file.
551 ** Periodically we are called and we run a quick check of all the
552 ** active chains to determine if there is a command to be executed,
553 ** and if the rup is ready to accept it.
558 ** Allocate an empty command block.
560 struct CmdBlk *RIOGetCmdBlk(void)
562 struct CmdBlk *CmdBlkP;
564 CmdBlkP = (struct CmdBlk *)kmalloc(sizeof(struct CmdBlk), GFP_ATOMIC);
566 memset(CmdBlkP, 0, sizeof(struct CmdBlk));
571 ** Return a block to the head of the free list.
573 void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP)
579 ** attach a command block to the list of commands to be performed for
582 int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
584 struct CmdBlk **Base;
585 struct UnixRup *UnixRupP;
588 if (Rup >= (unsigned short) (MAX_RUP + LINKS_PER_UNIT)) {
589 rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup);
590 RIOFreeCmdBlk(CmdBlkP);
594 UnixRupP = &HostP->UnixRups[Rup];
596 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
599 ** If the RUP is currently inactive, then put the request
600 ** straight on the RUP....
602 if ((UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE) && (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP)
604 rio_dprintk(RIO_DEBUG_CMD, "RUP inactive-placing command straight on. Cmd byte is 0x%x\n", CmdBlkP->Packet.data[0]);
607 ** Whammy! blat that pack!
609 HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
612 ** place command packet on the pending position.
614 UnixRupP->CmdPendingP = CmdBlkP;
617 ** set the command register
619 writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol);
621 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
625 rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n");
627 if (UnixRupP->CmdsWaitingP != NULL)
628 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command waiting\n");
629 if (UnixRupP->CmdPendingP != NULL)
630 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command pending\n");
631 if (readw(&UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE)
632 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n");
634 Base = &UnixRupP->CmdsWaitingP;
636 rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk 0x%p at 0x%p\n", CmdBlkP, Base);
639 rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk 0x%p here\n", *Base);
640 Base = &((*Base)->NextP);
641 rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk 0x%p at 0x%p\n", CmdBlkP, Base);
644 rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk 0x%p at 0x%p\n", CmdBlkP, Base);
648 CmdBlkP->NextP = NULL;
650 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
656 ** Here we go - if there is an empty rup, fill it!
657 ** must be called at splrio() or higher.
659 void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
661 struct CmdBlk *CmdBlkP;
662 struct UnixRup *UnixRupP;
668 Rup = MAX_RUP + LINKS_PER_UNIT;
670 do { /* do this loop for each RUP */
672 ** locate the rup we are processing & lock it
674 UnixRupP = &HostP->UnixRups[--Rup];
676 spin_lock_irqsave(&UnixRupP->RupLock, flags);
679 ** First check for incoming commands:
681 if (readw(&UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) {
684 PacketP = (PKT *) RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->rxpkt));
686 ShowPacket(DBG_CMD, PacketP);
688 switch (readb(&PacketP->dest_port)) {
690 rio_dprintk(RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n", readb(&PacketP->len) & 0x80 ? "Command" : "Data", readb(&PacketP->data[0]));
691 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
692 FreeMe = RIOBootRup(p, Rup, HostP, PacketP);
693 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
698 ** Free the RUP lock as loss of carrier causes a
699 ** ttyflush which will (eventually) call another
700 ** routine that uses the RUP lock.
702 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
703 FreeMe = RIOCommandRup(p, Rup, HostP, PacketP);
704 if (PacketP->data[5] == MEMDUMP) {
705 rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", *(unsigned short *) & (PacketP->data[6]));
706 HostP->Copy((caddr_t) & (PacketP->data[8]), (caddr_t) p->RIOMemDump, 32);
708 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
712 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
713 FreeMe = RIORouteRup(p, Rup, HostP, PacketP);
714 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
718 rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", readb(&PacketP->dest_port));
724 rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n");
725 put_free_end(HostP, PacketP);
727 writew(RX_RUP_INACTIVE, &UnixRupP->RupP->rxcontrol);
729 if (readw(&UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) {
730 rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup);
731 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &UnixRupP->RupP->handshake);
737 ** IF a command was running on the port,
738 ** and it has completed, then tidy it up.
740 if ((CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */
741 (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
744 ** there is a command in pending.
745 ** Therefore, this command has finished.
746 ** So, wakeup whoever is waiting for it (and tell them
749 if (CmdBlkP->Packet.dest_port == BOOT_RUP)
750 rio_dprintk(RIO_DEBUG_CMD, "Free Boot %s Command Block '%x'\n", CmdBlkP->Packet.len & 0x80 ? "Command" : "Data", CmdBlkP->Packet.data[0]);
752 rio_dprintk(RIO_DEBUG_CMD, "Command 0x%p completed\n", CmdBlkP);
755 ** Clear the Rup lock to prevent mutual exclusion.
757 if (CmdBlkP->PostFuncP) {
758 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
759 (*CmdBlkP->PostFuncP) (CmdBlkP->PostArg, CmdBlkP);
760 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
764 ** ....clear the pending flag....
766 UnixRupP->CmdPendingP = NULL;
769 ** ....and return the command block to the freelist.
771 RIOFreeCmdBlk(CmdBlkP);
775 ** If there is a command for this rup, and the rup
776 ** is idle, then process the command
778 if ((CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */
779 (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
781 ** if the pre-function is non-zero, call it.
782 ** If it returns RIO_FAIL then don't
783 ** send this command yet!
785 if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : TRUE)) {
786 rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command 0x%p\n", CmdBlkP);
788 rio_dprintk(RIO_DEBUG_CMD, "Start new command 0x%p Cmd byte is 0x%x\n", CmdBlkP, CmdBlkP->Packet.data[0]);
790 ** Whammy! blat that pack!
792 HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
795 ** remove the command from the rup command queue...
797 UnixRupP->CmdsWaitingP = CmdBlkP->NextP;
800 ** ...and place it on the pending position.
802 UnixRupP->CmdPendingP = CmdBlkP;
805 ** set the command register
807 writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol);
810 ** the command block will be freed
811 ** when the command has been processed.
815 spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
819 int RIOWFlushMark(unsigned long iPortP, struct CmdBlk *CmdBlkP)
821 struct Port *PortP = (struct Port *) iPortP;
824 rio_spin_lock_irqsave(&PortP->portSem, flags);
826 PortP->MagicFlags |= MAGIC_FLUSH;
827 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
828 return RIOUnUse(iPortP, CmdBlkP);
831 int RIORFlushEnable(unsigned long iPortP, struct CmdBlk *CmdBlkP)
833 struct Port *PortP = (struct Port *) iPortP;
837 rio_spin_lock_irqsave(&PortP->portSem, flags);
839 while (can_remove_receive(&PacketP, PortP)) {
840 remove_receive(PortP);
841 ShowPacket(DBG_PROC, PacketP);
842 put_free_end(PortP->HostP, PacketP);
845 if (readw(&PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) {
847 ** MAGIC! (Basically, handshake the RX buffer, so that
848 ** the RTAs upstream can be re-enabled.)
850 rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n");
851 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &PortP->PhbP->handshake);
853 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
854 return RIOUnUse(iPortP, CmdBlkP);
857 int RIOUnUse(unsigned long iPortP, struct CmdBlk *CmdBlkP)
859 struct Port *PortP = (struct Port *) iPortP;
862 rio_spin_lock_irqsave(&PortP->portSem, flags);
864 rio_dprintk(RIO_DEBUG_CMD, "Decrement in use count for port\n");
867 if (--PortP->InUse != NOT_INUSE) {
868 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
873 ** While PortP->InUse is set (i.e. a preemptive command has been sent to
874 ** the RTA and is awaiting completion), any transmit data is prevented from
875 ** being transferred from the write queue into the transmit packets
876 ** (add_transmit) and no furthur transmit interrupt will be sent for that
877 ** data. The next interrupt will occur up to 500ms later (RIOIntr is called
878 ** twice a second as a saftey measure). This was the case when kermit was
879 ** used to send data into a RIO port. After each packet was sent, TCFLSH
880 ** was called to flush the read queue preemptively. PortP->InUse was
881 ** incremented, thereby blocking the 6 byte acknowledgement packet
882 ** transmitted back. This acknowledgment hung around for 500ms before
883 ** being sent, thus reducing input performance substantially!.
884 ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data
885 ** hanging around in the transmit buffer is sent immediately.
887 writew(1, &PortP->HostP->ParmMapP->tx_intr);
888 /* What to do here ..
889 wakeup( (caddr_t)&(PortP->InUse) );
891 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
895 void ShowPacket(uint Flags, struct PKT *PacketP)
901 ** How to use this file:
903 ** To send a command down a rup, you need to allocate a command block, fill
904 ** in the packet information, fill in the command number, fill in the pre-
905 ** and post- functions and arguments, and then add the command block to the
906 ** queue of command blocks for the port in question. When the port is idle,
907 ** then the pre-function will be called. If this returns RIO_FAIL then the
908 ** command will be re-queued and tried again at a later date (probably in one
909 ** clock tick). If the pre-function returns NOT RIO_FAIL, then the command
910 ** packet will be queued on the RUP, and the txcontrol field set to the
911 ** command number. When the txcontrol field has changed from being the
912 ** command number, then the post-function will be called, with the argument
913 ** specified earlier, a pointer to the command block, and the value of
916 ** To allocate a command block, call RIOGetCmdBlk(). This returns a pointer
917 ** to the command block structure allocated, or NULL if there aren't any.
918 ** The block will have been zeroed for you.
920 ** The structure has the following fields:
924 ** struct CmdBlk *NextP; ** Pointer to next command block **
925 ** struct PKT Packet; ** A packet, to copy to the rup **
926 ** int (*PreFuncP)(); ** The func to call to check if OK **
927 ** int PreArg; ** The arg for the func **
928 ** int (*PostFuncP)(); ** The func to call when completed **
929 ** int PostArg; ** The arg for the func **
932 ** You need to fill in ALL fields EXCEPT NextP, which is used to link the
933 ** blocks together either on the free list or on the Rup list.
935 ** Packet is an actual packet structure to be filled in with the packet
936 ** information associated with the command. You need to fill in everything,
937 ** as the command processore doesn't process the command packet in any way.
939 ** The PreFuncP is called before the packet is enqueued on the host rup.
940 ** PreFuncP is called as (*PreFuncP)(PreArg, CmdBlkP);. PreFuncP must
941 ** return !RIO_FAIL to have the packet queued on the rup, and RIO_FAIL
942 ** if the packet is NOT to be queued.
944 ** The PostFuncP is called when the command has completed. It is called
945 ** as (*PostFuncP)(PostArg, CmdBlkP, txcontrol);. PostFuncP is not expected
946 ** to return a value. PostFuncP does NOT need to free the command block,
947 ** as this happens automatically after PostFuncP returns.
949 ** Once the command block has been filled in, it is attached to the correct
950 ** queue by calling RIOQueueCmdBlk( HostP, Rup, CmdBlkP ) where HostP is
951 ** a pointer to the struct Host, Rup is the NUMBER of the rup (NOT a pointer
952 ** to it!), and CmdBlkP is the pointer to the command block allocated using