blob: 694bfb9d937882125597dce05504bf6f541a3e41 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
34static 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
83static struct IdentifyRta IdRta;
84static struct KillNeighbour KillUnit;
85
Andrew Morton8d8706e2006-01-11 12:17:49 -080086int RIOFoadRta(struct Host *HostP, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
88 struct CmdBlk *CmdBlkP;
89
Andrew Morton8d8706e2006-01-11 12:17:49 -080090 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 CmdBlkP = RIOGetCmdBlk();
93
Andrew Morton8d8706e2006-01-11 12:17:49 -080094 if (!CmdBlkP) {
95 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return -ENXIO;
97 }
98
99 CmdBlkP->Packet.dest_unit = MapP->ID;
100 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800101 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 Torvalds1da177e2005-04-16 15:20:36 -0700108
Andrew Morton8d8706e2006-01-11 12:17:49 -0800109 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
110 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: Failed to queue foad command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 return -EIO;
112 }
113 return 0;
114}
115
Andrew Morton8d8706e2006-01-11 12:17:49 -0800116int RIOZombieRta(struct Host *HostP, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
118 struct CmdBlk *CmdBlkP;
119
Andrew Morton8d8706e2006-01-11 12:17:49 -0800120 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 CmdBlkP = RIOGetCmdBlk();
123
Andrew Morton8d8706e2006-01-11 12:17:49 -0800124 if (!CmdBlkP) {
125 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 return -ENXIO;
127 }
128
129 CmdBlkP->Packet.dest_unit = MapP->ID;
130 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800131 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 Torvalds1da177e2005-04-16 15:20:36 -0700138
Andrew Morton8d8706e2006-01-11 12:17:49 -0800139 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
140 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: Failed to queue zombie command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return -EIO;
142 }
143 return 0;
144}
145
Andrew Morton8d8706e2006-01-11 12:17:49 -0800146int RIOCommandRta(struct rio_info *p, uint RtaUnique, int (*func) (struct Host * HostP, struct Map * MapP))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 uint Host;
149
Andrew Morton8d8706e2006-01-11 12:17:49 -0800150 rio_dprintk(RIO_DEBUG_CMD, "Command RTA 0x%x func 0x%x\n", RtaUnique, (int) func);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Andrew Morton8d8706e2006-01-11 12:17:49 -0800152 if (!RtaUnique)
153 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Andrew Morton8d8706e2006-01-11 12:17:49 -0800155 for (Host = 0; Host < p->RIONumHosts; Host++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 uint Rta;
157 struct Host *HostP = &p->RIOHosts[Host];
158
Andrew Morton8d8706e2006-01-11 12:17:49 -0800159 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 struct Map *MapP = &HostP->Mapping[Rta];
161
Andrew Morton8d8706e2006-01-11 12:17:49 -0800162 if (MapP->RtaUniqueNum == RtaUnique) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 uint Link;
164
165 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800166 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700174 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800175 ** Its worth trying the operation...
176 */
177 return (*func) (HostP, MapP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
179 }
180 }
181 }
182 }
183 return -ENXIO;
184}
185
186
Andrew Morton8d8706e2006-01-11 12:17:49 -0800187int RIOIdentifyRta(struct rio_info *p, caddr_t arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 uint Host;
190
Andrew Morton8d8706e2006-01-11 12:17:49 -0800191 if (copyin((int) arg, (caddr_t) & IdRta, sizeof(IdRta)) == COPYFAIL) {
192 rio_dprintk(RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 p->RIOError.Error = COPYIN_FAILED;
194 return -EFAULT;
195 }
196
Andrew Morton8d8706e2006-01-11 12:17:49 -0800197 for (Host = 0; Host < p->RIONumHosts; Host++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 uint Rta;
199 struct Host *HostP = &p->RIOHosts[Host];
200
Andrew Morton8d8706e2006-01-11 12:17:49 -0800201 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 struct Map *MapP = &HostP->Mapping[Rta];
203
Andrew Morton8d8706e2006-01-11 12:17:49 -0800204 if (MapP->RtaUniqueNum == IdRta.RtaUnique) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 uint Link;
206 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800207 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700215 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800216 ** Its worth trying the operation...
217 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 struct CmdBlk *CmdBlkP;
219
Andrew Morton8d8706e2006-01-11 12:17:49 -0800220 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 CmdBlkP = RIOGetCmdBlk();
223
Andrew Morton8d8706e2006-01-11 12:17:49 -0800224 if (!CmdBlkP) {
225 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 return -ENXIO;
227 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 CmdBlkP->Packet.dest_unit = MapP->ID;
230 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800231 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 Torvalds1da177e2005-04-16 15:20:36 -0700240 return -EIO;
241 }
242 return 0;
243 }
244 }
245 }
246 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return -ENOENT;
249}
250
251
Andrew Morton8d8706e2006-01-11 12:17:49 -0800252int RIOKillNeighbour(struct rio_info *p, caddr_t arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
254 uint Host;
255 uint ID;
256 struct Host *HostP;
257 struct CmdBlk *CmdBlkP;
258
Andrew Morton8d8706e2006-01-11 12:17:49 -0800259 rio_dprintk(RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Andrew Morton8d8706e2006-01-11 12:17:49 -0800261 if (copyin((int) arg, (caddr_t) & KillUnit, sizeof(KillUnit)) == COPYFAIL) {
262 rio_dprintk(RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 p->RIOError.Error = COPYIN_FAILED;
264 return -EFAULT;
265 }
266
Andrew Morton8d8706e2006-01-11 12:17:49 -0800267 if (KillUnit.Link > 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 return -ENXIO;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 CmdBlkP = RIOGetCmdBlk();
271
Andrew Morton8d8706e2006-01-11 12:17:49 -0800272 if (!CmdBlkP) {
273 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 return -ENXIO;
275 }
276
277 CmdBlkP->Packet.dest_unit = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800278 CmdBlkP->Packet.src_unit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800280 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 Torvalds1da177e2005-04-16 15:20:36 -0700286
Andrew Morton8d8706e2006-01-11 12:17:49 -0800287 for (Host = 0; Host < p->RIONumHosts; Host++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 ID = 0;
289 HostP = &p->RIOHosts[Host];
290
Andrew Morton8d8706e2006-01-11 12:17:49 -0800291 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 Torvalds1da177e2005-04-16 15:20:36 -0700294 return -EIO;
295 }
296 return 0;
297 }
298
Andrew Morton8d8706e2006-01-11 12:17:49 -0800299 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 Torvalds1da177e2005-04-16 15:20:36 -0700304 return -EIO;
305 }
306 return 0;
307 }
308 }
309 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800310 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 return -ENXIO;
312}
313
Andrew Morton8d8706e2006-01-11 12:17:49 -0800314int RIOSuspendBootRta(struct Host *HostP, int ID, int Link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 struct CmdBlk *CmdBlkP;
317
Andrew Morton8d8706e2006-01-11 12:17:49 -0800318 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA ID %d, link %c\n", ID, 'A' + Link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 CmdBlkP = RIOGetCmdBlk();
321
Andrew Morton8d8706e2006-01-11 12:17:49 -0800322 if (!CmdBlkP) {
323 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 return -ENXIO;
325 }
326
327 CmdBlkP->Packet.dest_unit = ID;
328 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800329 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 Torvalds1da177e2005-04-16 15:20:36 -0700336
Andrew Morton8d8706e2006-01-11 12:17:49 -0800337 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 Torvalds1da177e2005-04-16 15:20:36 -0700339 return -EIO;
340 }
341 return 0;
342}
343
Andrew Morton8d8706e2006-01-11 12:17:49 -0800344int RIOFoadWakeup(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
346 int port;
347 register struct Port *PortP;
348 unsigned long flags;
349
Andrew Morton8d8706e2006-01-11 12:17:49 -0800350 for (port = 0; port < RIO_PORTS; port++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 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 Morton8d8706e2006-01-11 12:17:49 -0800371 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
374/*
375** Incoming command on the COMMAND_RUP to be processed.
376*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800377static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800379 struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 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 Morton8d8706e2006-01-11 12:17:49 -0800388 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800391 ** 16 port RTA note:
392 ** Command rup packets coming from the RTA will have pkt->data[1] (which
393 ** translates to PktCmdP->PhbNum) set to the host port number for the
394 ** particular unit. To access the correct BaseSysPort for a 16 port RTA,
395 ** we can use PhbNum to get the rup number for the appropriate 8 port
396 ** block (for the first block, this should be equal to 'Rup').
397 */
398 rup = RBYTE(PktCmdP->PhbNum) / (ushort) PORTS_PER_RTA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 UnixRupP = &HostP->UnixRups[rup];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800400 SysPort = UnixRupP->BaseSysPort + (RBYTE(PktCmdP->PhbNum) % (ushort) PORTS_PER_RTA);
401 rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Andrew Morton8d8706e2006-01-11 12:17:49 -0800403 if (UnixRupP->BaseSysPort == NO_PORT) {
404 rio_dprintk(RIO_DEBUG_CMD, "OBSCURE ERROR!\n");
405 rio_dprintk(RIO_DEBUG_CMD, "Diagnostics follow. Please WRITE THESE DOWN and report them to Specialix Technical Support\n");
406 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Host number %d, name ``%s''\n", HostP - p->RIOHosts, HostP->Name);
407 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Andrew Morton8d8706e2006-01-11 12:17:49 -0800409 if (Rup >= (ushort) MAX_RUP) {
410 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for RTA ``%s''\n", HostP->Mapping[Rup].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 } else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800412 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 Torvalds1da177e2005-04-16 15:20:36 -0700413
Andrew Morton8d8706e2006-01-11 12:17:49 -0800414 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Destination 0x%x:0x%x\n", PacketP->dest_unit, PacketP->dest_port);
415 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Source 0x%x:0x%x\n", PacketP->src_unit, PacketP->src_port);
416 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Length 0x%x (%d)\n", PacketP->len, PacketP->len);
417 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Control 0x%x (%d)\n", PacketP->control, PacketP->control);
418 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Check 0x%x (%d)\n", PacketP->csum, PacketP->csum);
419 rio_dprintk(RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, " "Command Code 0x%x\n", PktCmdP->PhbNum, PktCmdP->Command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 return TRUE;
421 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800422 PortP = p->RIOPortp[SysPort];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 rio_spin_lock_irqsave(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800424 switch (RBYTE(PktCmdP->Command)) {
425 case BREAK_RECEIVED:
426 rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n");
427 /* If the current line disc. is not multi-threading and
428 the current processor is not the default, reset rup_intr
429 and return FALSE to ensure that the command packet is
430 not freed. */
431 /* Call tmgr HANGUP HERE */
432 /* Fix this later when every thing works !!!! RAMRAJ */
433 gs_got_break(&PortP->gs);
434 break;
435
436 case COMPLETE:
437 rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %d\n", RBYTE(PktCmdP->PhbNum), HostP - p->RIOHosts);
438 subCommand = 1;
439 switch (RBYTE(PktCmdP->SubCommand)) {
440 case MEMDUMP:
441 rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", RBYTE(PktCmdP->SubCommand), RWORD(PktCmdP->SubAddr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 break;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800443 case READ_REGISTER:
444 rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", RWORD(PktCmdP->SubAddr));
445 p->CdRegister = (RBYTE(PktCmdP->ModemStatus) & MSVR1_HOST);
446 break;
447 default:
448 subCommand = 0;
449 break;
450 }
451 if (subCommand)
452 break;
453 rio_dprintk(RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n", RBYTE(PktCmdP->PortStatus), PortP->PortState);
454 if (PortP->PortState != RBYTE(PktCmdP->PortStatus)) {
455 rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n");
456 PortP->PortState = RBYTE(PktCmdP->PortStatus);
457 /* What should we do here ...
458 wakeup( &PortP->PortState );
459 */
460 } else
461 rio_dprintk(RIO_DEBUG_CMD, "No change\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Andrew Morton8d8706e2006-01-11 12:17:49 -0800463 /* FALLTHROUGH */
464 case MODEM_STATUS:
465 /*
466 ** Knock out the tbusy and tstop bits, as these are not relevant
467 ** to the check for modem status change (they're just there because
468 ** it's a convenient place to put them!).
469 */
470 ReportedModemStatus = RBYTE(PktCmdP->ModemStatus);
471 if ((PortP->ModemState & MSVR1_HOST) == (ReportedModemStatus & MSVR1_HOST)) {
472 rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800474 ** Update ModemState just in case tbusy or tstop states have
475 ** changed.
476 */
477 PortP->ModemState = ReportedModemStatus;
478 } else {
479 rio_dprintk(RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n", PortP->ModemState, ReportedModemStatus);
480 PortP->ModemState = ReportedModemStatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481#ifdef MODEM_SUPPORT
Andrew Morton8d8706e2006-01-11 12:17:49 -0800482 if (PortP->Mapped) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 /***********************************************************\
484 *************************************************************
485 *** ***
486 *** M O D E M S T A T E C H A N G E ***
487 *** ***
488 *************************************************************
489 \***********************************************************/
490 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800491 ** If the device is a modem, then check the modem
492 ** carrier.
493 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 if (PortP->gs.tty == NULL)
495 break;
496 if (PortP->gs.tty->termios == NULL)
497 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Andrew Morton8d8706e2006-01-11 12:17:49 -0800499 if (!(PortP->gs.tty->termios->c_cflag & CLOCAL) && ((PortP->State & (RIO_MOPEN | RIO_WOPEN)))) {
500
501 rio_dprintk(RIO_DEBUG_CMD, "Is there a Carrier?\n");
502 /*
503 ** Is there a carrier?
504 */
505 if (PortP->ModemState & MSVR1_CD) {
506 /*
507 ** Has carrier just appeared?
508 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 if (!(PortP->State & RIO_CARR_ON)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800510 rio_dprintk(RIO_DEBUG_CMD, "Carrier just came up.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 PortP->State |= RIO_CARR_ON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800512 /*
513 ** wakeup anyone in WOPEN
514 */
515 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN))
516 wake_up_interruptible(&PortP->gs.open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517#ifdef STATS
Andrew Morton8d8706e2006-01-11 12:17:49 -0800518 PortP->Stat.ModemOnCnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800522 /*
523 ** Has carrier just dropped?
524 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 if (PortP->State & RIO_CARR_ON) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800526 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN | RIO_MOPEN))
527 tty_hangup(PortP->gs.tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 PortP->State &= ~RIO_CARR_ON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800529 rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530#ifdef STATS
Andrew Morton8d8706e2006-01-11 12:17:49 -0800531 PortP->Stat.ModemOffCnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800533 }
534 }
535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800538 }
539 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Andrew Morton8d8706e2006-01-11 12:17:49 -0800541 default:
542 rio_dprintk(RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %d\n", RBYTE(PktCmdP->Command), HostP - p->RIOHosts);
543 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 }
545 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
546
Andrew Morton8d8706e2006-01-11 12:17:49 -0800547 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 return TRUE;
550}
Andrew Morton8d8706e2006-01-11 12:17:49 -0800551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552/*
553** The command mechanism:
554** Each rup has a chain of commands associated with it.
555** This chain is maintained by routines in this file.
556** Periodically we are called and we run a quick check of all the
557** active chains to determine if there is a command to be executed,
558** and if the rup is ready to accept it.
559**
560*/
561
562/*
563** Allocate an empty command block.
564*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800565struct CmdBlk *RIOGetCmdBlk(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566{
567 struct CmdBlk *CmdBlkP;
568
Andrew Morton8d8706e2006-01-11 12:17:49 -0800569 CmdBlkP = (struct CmdBlk *) sysbrk(sizeof(struct CmdBlk));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 if (CmdBlkP)
571 bzero(CmdBlkP, sizeof(struct CmdBlk));
572
573 return CmdBlkP;
574}
575
576/*
577** Return a block to the head of the free list.
578*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800579void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800581 sysfree((void *) CmdBlkP, sizeof(struct CmdBlk));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582}
583
584/*
585** attach a command block to the list of commands to be performed for
586** a given rup.
587*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800588int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
590 struct CmdBlk **Base;
591 struct UnixRup *UnixRupP;
592 unsigned long flags;
593
Andrew Morton8d8706e2006-01-11 12:17:49 -0800594 if (Rup >= (ushort) (MAX_RUP + LINKS_PER_UNIT)) {
595 rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup);
596 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 return RIO_FAIL;
598 }
599
600 UnixRupP = &HostP->UnixRups[Rup];
601
602 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
603
604 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800605 ** If the RUP is currently inactive, then put the request
606 ** straight on the RUP....
607 */
608 if ((UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE) && (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP)
609 : TRUE)) {
610 rio_dprintk(RIO_DEBUG_CMD, "RUP inactive-placing command straight on. Cmd byte is 0x%x\n", CmdBlkP->Packet.data[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800613 ** Whammy! blat that pack!
614 */
615 HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800618 ** place command packet on the pending position.
619 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 UnixRupP->CmdPendingP = CmdBlkP;
621
622 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800623 ** set the command register
624 */
625 WWORD(UnixRupP->RupP->txcontrol, TX_PACKET_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
628
629 return RIO_SUCCESS;
630 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800631 rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Andrew Morton8d8706e2006-01-11 12:17:49 -0800633 if (UnixRupP->CmdsWaitingP != NULL)
634 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command waiting\n");
635 if (UnixRupP->CmdPendingP != NULL)
636 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command pending\n");
637 if (RWORD(UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE)
638 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 Base = &UnixRupP->CmdsWaitingP;
641
Andrew Morton8d8706e2006-01-11 12:17:49 -0800642 rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Andrew Morton8d8706e2006-01-11 12:17:49 -0800644 while (*Base) {
645 rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk 0x%x here\n", (int) (*Base));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 Base = &((*Base)->NextP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800647 rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
649
Andrew Morton8d8706e2006-01-11 12:17:49 -0800650 rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652 *Base = CmdBlkP;
653
654 CmdBlkP->NextP = NULL;
655
656 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
657
658 return RIO_SUCCESS;
659}
660
661/*
662** Here we go - if there is an empty rup, fill it!
663** must be called at splrio() or higher.
664*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800665void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
667 register struct CmdBlk *CmdBlkP;
668 register struct UnixRup *UnixRupP;
669 struct PKT *PacketP;
670 ushort Rup;
671 unsigned long flags;
672
673
Andrew Morton8d8706e2006-01-11 12:17:49 -0800674 Rup = MAX_RUP + LINKS_PER_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Andrew Morton8d8706e2006-01-11 12:17:49 -0800676 do { /* do this loop for each RUP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800678 ** locate the rup we are processing & lock it
679 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 UnixRupP = &HostP->UnixRups[--Rup];
681
682 spin_lock_irqsave(&UnixRupP->RupLock, flags);
683
684 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800685 ** First check for incoming commands:
686 */
687 if (RWORD(UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 int FreeMe;
689
Andrew Morton8d8706e2006-01-11 12:17:49 -0800690 PacketP = (PKT *) RIO_PTR(HostP->Caddr, RWORD(UnixRupP->RupP->rxpkt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Andrew Morton8d8706e2006-01-11 12:17:49 -0800692 ShowPacket(DBG_CMD, PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Andrew Morton8d8706e2006-01-11 12:17:49 -0800694 switch (RBYTE(PacketP->dest_port)) {
695 case BOOT_RUP:
696 rio_dprintk(RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n", RBYTE(PacketP->len) & 0x80 ? "Command" : "Data", RBYTE(PacketP->data[0]));
697 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
698 FreeMe = RIOBootRup(p, Rup, HostP, PacketP);
699 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
700 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Andrew Morton8d8706e2006-01-11 12:17:49 -0800702 case COMMAND_RUP:
703 /*
704 ** Free the RUP lock as loss of carrier causes a
705 ** ttyflush which will (eventually) call another
706 ** routine that uses the RUP lock.
707 */
708 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
709 FreeMe = RIOCommandRup(p, Rup, HostP, PacketP);
710 if (PacketP->data[5] == MEMDUMP) {
711 rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", *(ushort *) & (PacketP->data[6]));
712 HostP->Copy((caddr_t) & (PacketP->data[8]), (caddr_t) p->RIOMemDump, 32);
713 }
714 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
715 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Andrew Morton8d8706e2006-01-11 12:17:49 -0800717 case ROUTE_RUP:
718 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
719 FreeMe = RIORouteRup(p, Rup, HostP, PacketP);
720 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
721 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Andrew Morton8d8706e2006-01-11 12:17:49 -0800723 default:
724 rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", RBYTE(PacketP->dest_port));
725 FreeMe = 1;
726 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 }
728
Andrew Morton8d8706e2006-01-11 12:17:49 -0800729 if (FreeMe) {
730 rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n");
731 put_free_end(HostP, PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Andrew Morton8d8706e2006-01-11 12:17:49 -0800733 WWORD(UnixRupP->RupP->rxcontrol, RX_RUP_INACTIVE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Andrew Morton8d8706e2006-01-11 12:17:49 -0800735 if (RWORD(UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) {
736 rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup);
737 WWORD(UnixRupP->RupP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
739 }
740 }
741
742 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800743 ** IF a command was running on the port,
744 ** and it has completed, then tidy it up.
745 */
746 if ((CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */
747 (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800749 ** we are idle.
750 ** there is a command in pending.
751 ** Therefore, this command has finished.
752 ** So, wakeup whoever is waiting for it (and tell them
753 ** what happened).
754 */
755 if (CmdBlkP->Packet.dest_port == BOOT_RUP)
756 rio_dprintk(RIO_DEBUG_CMD, "Free Boot %s Command Block '%x'\n", CmdBlkP->Packet.len & 0x80 ? "Command" : "Data", CmdBlkP->Packet.data[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Andrew Morton8d8706e2006-01-11 12:17:49 -0800758 rio_dprintk(RIO_DEBUG_CMD, "Command 0x%x completed\n", (int) CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800761 ** Clear the Rup lock to prevent mutual exclusion.
762 */
763 if (CmdBlkP->PostFuncP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800765 (*CmdBlkP->PostFuncP) (CmdBlkP->PostArg, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
767 }
768
769 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800770 ** ....clear the pending flag....
771 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 UnixRupP->CmdPendingP = NULL;
773
774 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800775 ** ....and return the command block to the freelist.
776 */
777 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 }
779
780 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800781 ** If there is a command for this rup, and the rup
782 ** is idle, then process the command
783 */
784 if ((CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */
785 (UnixRupP->CmdPendingP == NULL) && (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800787 ** if the pre-function is non-zero, call it.
788 ** If it returns RIO_FAIL then don't
789 ** send this command yet!
790 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800791 if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : TRUE)) {
792 rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command 0x%x\n", (int) CmdBlkP);
793 } else {
794 rio_dprintk(RIO_DEBUG_CMD, "Start new command 0x%x Cmd byte is 0x%x\n", (int) CmdBlkP, CmdBlkP->Packet.data[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800796 ** Whammy! blat that pack!
797 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800798 HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800801 ** remove the command from the rup command queue...
802 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 UnixRupP->CmdsWaitingP = CmdBlkP->NextP;
804
805 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800806 ** ...and place it on the pending position.
807 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 UnixRupP->CmdPendingP = CmdBlkP;
809
810 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800811 ** set the command register
812 */
813 WWORD(UnixRupP->RupP->txcontrol, TX_PACKET_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800816 ** the command block will be freed
817 ** when the command has been processed.
818 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 }
820 }
821 spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800822 } while (Rup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
Andrew Morton8d8706e2006-01-11 12:17:49 -0800825int RIOWFlushMark(int iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800827 struct Port *PortP = (struct Port *) iPortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 unsigned long flags;
829
830 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 PortP->WflushFlag++;
832 PortP->MagicFlags |= MAGIC_FLUSH;
833 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800834 return RIOUnUse(iPortP, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835}
836
Andrew Morton8d8706e2006-01-11 12:17:49 -0800837int RIORFlushEnable(int iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800839 struct Port *PortP = (struct Port *) iPortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 PKT *PacketP;
841 unsigned long flags;
842
843 rio_spin_lock_irqsave(&PortP->portSem, flags);
844
Andrew Morton8d8706e2006-01-11 12:17:49 -0800845 while (can_remove_receive(&PacketP, PortP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 remove_receive(PortP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800847 ShowPacket(DBG_PROC, PacketP);
848 put_free_end(PortP->HostP, PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850
Andrew Morton8d8706e2006-01-11 12:17:49 -0800851 if (RWORD(PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800853 ** MAGIC! (Basically, handshake the RX buffer, so that
854 ** the RTAs upstream can be re-enabled.)
855 */
856 rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n");
857 WWORD(PortP->PhbP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 }
859 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800860 return RIOUnUse(iPortP, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861}
862
Andrew Morton8d8706e2006-01-11 12:17:49 -0800863int RIOUnUse(int iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800865 struct Port *PortP = (struct Port *) iPortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 unsigned long flags;
867
868 rio_spin_lock_irqsave(&PortP->portSem, flags);
869
Andrew Morton8d8706e2006-01-11 12:17:49 -0800870 rio_dprintk(RIO_DEBUG_CMD, "Decrement in use count for port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 if (PortP->InUse) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800873 if (--PortP->InUse != NOT_INUSE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
875 return 0;
876 }
877 }
878 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800879 ** While PortP->InUse is set (i.e. a preemptive command has been sent to
880 ** the RTA and is awaiting completion), any transmit data is prevented from
881 ** being transferred from the write queue into the transmit packets
882 ** (add_transmit) and no furthur transmit interrupt will be sent for that
883 ** data. The next interrupt will occur up to 500ms later (RIOIntr is called
884 ** twice a second as a saftey measure). This was the case when kermit was
885 ** used to send data into a RIO port. After each packet was sent, TCFLSH
886 ** was called to flush the read queue preemptively. PortP->InUse was
887 ** incremented, thereby blocking the 6 byte acknowledgement packet
888 ** transmitted back. This acknowledgment hung around for 500ms before
889 ** being sent, thus reducing input performance substantially!.
890 ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data
891 ** hanging around in the transmit buffer is sent immediately.
892 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 WWORD(PortP->HostP->ParmMapP->tx_intr, 1);
894 /* What to do here ..
Andrew Morton8d8706e2006-01-11 12:17:49 -0800895 wakeup( (caddr_t)&(PortP->InUse) );
896 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
898 return 0;
899}
900
Andrew Morton8d8706e2006-01-11 12:17:49 -0800901void ShowPacket(uint Flags, struct PKT *PacketP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
903}
904
905/*
906**
907** How to use this file:
908**
909** To send a command down a rup, you need to allocate a command block, fill
910** in the packet information, fill in the command number, fill in the pre-
911** and post- functions and arguments, and then add the command block to the
912** queue of command blocks for the port in question. When the port is idle,
913** then the pre-function will be called. If this returns RIO_FAIL then the
914** command will be re-queued and tried again at a later date (probably in one
915** clock tick). If the pre-function returns NOT RIO_FAIL, then the command
916** packet will be queued on the RUP, and the txcontrol field set to the
917** command number. When the txcontrol field has changed from being the
918** command number, then the post-function will be called, with the argument
919** specified earlier, a pointer to the command block, and the value of
920** txcontrol.
921**
922** To allocate a command block, call RIOGetCmdBlk(). This returns a pointer
923** to the command block structure allocated, or NULL if there aren't any.
924** The block will have been zeroed for you.
925**
926** The structure has the following fields:
927**
928** struct CmdBlk
929** {
930** struct CmdBlk *NextP; ** Pointer to next command block **
931** struct PKT Packet; ** A packet, to copy to the rup **
932** int (*PreFuncP)(); ** The func to call to check if OK **
933** int PreArg; ** The arg for the func **
934** int (*PostFuncP)(); ** The func to call when completed **
935** int PostArg; ** The arg for the func **
936** };
937**
938** You need to fill in ALL fields EXCEPT NextP, which is used to link the
939** blocks together either on the free list or on the Rup list.
940**
941** Packet is an actual packet structure to be filled in with the packet
942** information associated with the command. You need to fill in everything,
943** as the command processore doesn't process the command packet in any way.
944**
945** The PreFuncP is called before the packet is enqueued on the host rup.
946** PreFuncP is called as (*PreFuncP)(PreArg, CmdBlkP);. PreFuncP must
947** return !RIO_FAIL to have the packet queued on the rup, and RIO_FAIL
948** if the packet is NOT to be queued.
949**
950** The PostFuncP is called when the command has completed. It is called
951** as (*PostFuncP)(PostArg, CmdBlkP, txcontrol);. PostFuncP is not expected
952** to return a value. PostFuncP does NOT need to free the command block,
953** as this happens automatically after PostFuncP returns.
954**
955** Once the command block has been filled in, it is attached to the correct
956** queue by calling RIOQueueCmdBlk( HostP, Rup, CmdBlkP ) where HostP is
957** a pointer to the struct Host, Rup is the NUMBER of the rup (NOT a pointer
958** to it!), and CmdBlkP is the pointer to the command block allocated using
959** RIOGetCmdBlk().
960**
961*/