blob: 08fcac1f12de03a93b8151f44fb032354e2b9bd4 [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>
Alan Cox00d83a52006-03-24 03:18:28 -080045#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47#include <linux/termios.h>
48#include <linux/serial.h>
49
50#include <linux/generic_serial.h>
51
52#include "linux_compat.h"
53#include "rio_linux.h"
54#include "typdef.h"
55#include "pkt.h"
56#include "daemon.h"
57#include "rio.h"
58#include "riospace.h"
59#include "top.h"
60#include "cmdpkt.h"
61#include "map.h"
62#include "riotypes.h"
63#include "rup.h"
64#include "port.h"
65#include "riodrvr.h"
66#include "rioinfo.h"
67#include "func.h"
68#include "errors.h"
69#include "pci.h"
70
71#include "parmmap.h"
72#include "unixrup.h"
73#include "board.h"
74#include "host.h"
75#include "error.h"
76#include "phb.h"
77#include "link.h"
78#include "cmdblk.h"
79#include "route.h"
80#include "control.h"
81#include "cirrus.h"
82
83
84static struct IdentifyRta IdRta;
85static struct KillNeighbour KillUnit;
86
Andrew Morton8d8706e2006-01-11 12:17:49 -080087int RIOFoadRta(struct Host *HostP, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
89 struct CmdBlk *CmdBlkP;
90
Andrew Morton8d8706e2006-01-11 12:17:49 -080091 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 CmdBlkP = RIOGetCmdBlk();
94
Andrew Morton8d8706e2006-01-11 12:17:49 -080095 if (!CmdBlkP) {
96 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return -ENXIO;
98 }
99
100 CmdBlkP->Packet.dest_unit = MapP->ID;
101 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800102 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Andrew Morton8d8706e2006-01-11 12:17:49 -0800110 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
111 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: Failed to queue foad command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return -EIO;
113 }
114 return 0;
115}
116
Andrew Morton8d8706e2006-01-11 12:17:49 -0800117int RIOZombieRta(struct Host *HostP, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
119 struct CmdBlk *CmdBlkP;
120
Andrew Morton8d8706e2006-01-11 12:17:49 -0800121 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123 CmdBlkP = RIOGetCmdBlk();
124
Andrew Morton8d8706e2006-01-11 12:17:49 -0800125 if (!CmdBlkP) {
126 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return -ENXIO;
128 }
129
130 CmdBlkP->Packet.dest_unit = MapP->ID;
131 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800132 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Andrew Morton8d8706e2006-01-11 12:17:49 -0800140 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
141 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: Failed to queue zombie command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return -EIO;
143 }
144 return 0;
145}
146
Alan Cox00d83a52006-03-24 03:18:28 -0800147int RIOCommandRta(struct rio_info *p, unsigned long RtaUnique, int (*func) (struct Host * HostP, struct Map * MapP))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Alan Cox00d83a52006-03-24 03:18:28 -0800149 unsigned int Host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Alan Cox00d83a52006-03-24 03:18:28 -0800151 rio_dprintk(RIO_DEBUG_CMD, "Command RTA 0x%lx func 0x%p\n", RtaUnique, func);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Andrew Morton8d8706e2006-01-11 12:17:49 -0800153 if (!RtaUnique)
154 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Andrew Morton8d8706e2006-01-11 12:17:49 -0800156 for (Host = 0; Host < p->RIONumHosts; Host++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800157 unsigned int Rta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 struct Host *HostP = &p->RIOHosts[Host];
159
Andrew Morton8d8706e2006-01-11 12:17:49 -0800160 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 struct Map *MapP = &HostP->Mapping[Rta];
162
Andrew Morton8d8706e2006-01-11 12:17:49 -0800163 if (MapP->RtaUniqueNum == RtaUnique) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 uint Link;
165
166 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800167 ** 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.
172 */
173 for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800174 if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800176 ** Its worth trying the operation...
177 */
178 return (*func) (HostP, MapP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180 }
181 }
182 }
183 }
184 return -ENXIO;
185}
186
187
Alan Cox00d83a52006-03-24 03:18:28 -0800188int RIOIdentifyRta(struct rio_info *p, void * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
Alan Cox00d83a52006-03-24 03:18:28 -0800190 unsigned int Host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Alan Cox00d83a52006-03-24 03:18:28 -0800192 if (copy_from_user(&IdRta, arg, sizeof(IdRta))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800193 rio_dprintk(RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 p->RIOError.Error = COPYIN_FAILED;
195 return -EFAULT;
196 }
197
Andrew Morton8d8706e2006-01-11 12:17:49 -0800198 for (Host = 0; Host < p->RIONumHosts; Host++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800199 unsigned int Rta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 struct Host *HostP = &p->RIOHosts[Host];
201
Andrew Morton8d8706e2006-01-11 12:17:49 -0800202 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 struct Map *MapP = &HostP->Mapping[Rta];
204
Andrew Morton8d8706e2006-01-11 12:17:49 -0800205 if (MapP->RtaUniqueNum == IdRta.RtaUnique) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 uint Link;
207 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800208 ** 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.
213 */
214 for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800215 if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800217 ** Its worth trying the operation...
218 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 struct CmdBlk *CmdBlkP;
220
Andrew Morton8d8706e2006-01-11 12:17:49 -0800221 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 CmdBlkP = RIOGetCmdBlk();
224
Andrew Morton8d8706e2006-01-11 12:17:49 -0800225 if (!CmdBlkP) {
226 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 return -ENXIO;
228 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 CmdBlkP->Packet.dest_unit = MapP->ID;
231 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800232 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;
238
239 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
240 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: Failed to queue command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return -EIO;
242 }
243 return 0;
244 }
245 }
246 }
247 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 return -ENOENT;
250}
251
252
Alan Cox00d83a52006-03-24 03:18:28 -0800253int RIOKillNeighbour(struct rio_info *p, void * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 uint Host;
256 uint ID;
257 struct Host *HostP;
258 struct CmdBlk *CmdBlkP;
259
Andrew Morton8d8706e2006-01-11 12:17:49 -0800260 rio_dprintk(RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Alan Cox00d83a52006-03-24 03:18:28 -0800262 if (copy_from_user(&KillUnit, arg, sizeof(KillUnit))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800263 rio_dprintk(RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 p->RIOError.Error = COPYIN_FAILED;
265 return -EFAULT;
266 }
267
Andrew Morton8d8706e2006-01-11 12:17:49 -0800268 if (KillUnit.Link > 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 return -ENXIO;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 CmdBlkP = RIOGetCmdBlk();
272
Andrew Morton8d8706e2006-01-11 12:17:49 -0800273 if (!CmdBlkP) {
274 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 return -ENXIO;
276 }
277
278 CmdBlkP->Packet.dest_unit = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800279 CmdBlkP->Packet.src_unit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800281 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Andrew Morton8d8706e2006-01-11 12:17:49 -0800288 for (Host = 0; Host < p->RIONumHosts; Host++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 ID = 0;
290 HostP = &p->RIOHosts[Host];
291
Andrew Morton8d8706e2006-01-11 12:17:49 -0800292 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");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 return -EIO;
296 }
297 return 0;
298 }
299
Andrew Morton8d8706e2006-01-11 12:17:49 -0800300 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");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 return -EIO;
306 }
307 return 0;
308 }
309 }
310 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800311 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 return -ENXIO;
313}
314
Andrew Morton8d8706e2006-01-11 12:17:49 -0800315int RIOSuspendBootRta(struct Host *HostP, int ID, int Link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
317 struct CmdBlk *CmdBlkP;
318
Andrew Morton8d8706e2006-01-11 12:17:49 -0800319 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA ID %d, link %c\n", ID, 'A' + Link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 CmdBlkP = RIOGetCmdBlk();
322
Andrew Morton8d8706e2006-01-11 12:17:49 -0800323 if (!CmdBlkP) {
324 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 return -ENXIO;
326 }
327
328 CmdBlkP->Packet.dest_unit = ID;
329 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800330 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Andrew Morton8d8706e2006-01-11 12:17:49 -0800338 if (RIOQueueCmdBlk(HostP, ID - 1, CmdBlkP) == RIO_FAIL) {
339 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: Failed to queue iwait command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return -EIO;
341 }
342 return 0;
343}
344
Andrew Morton8d8706e2006-01-11 12:17:49 -0800345int RIOFoadWakeup(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
347 int port;
Alan Cox00d83a52006-03-24 03:18:28 -0800348 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 unsigned long flags;
350
Andrew Morton8d8706e2006-01-11 12:17:49 -0800351 for (port = 0; port < RIO_PORTS; port++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 PortP = p->RIOPortp[port];
353
354 rio_spin_lock_irqsave(&PortP->portSem, flags);
355 PortP->Config = 0;
356 PortP->State = 0;
357 PortP->InUse = NOT_INUSE;
358 PortP->PortState = 0;
359 PortP->FlushCmdBodge = 0;
360 PortP->ModemLines = 0;
361 PortP->ModemState = 0;
362 PortP->CookMode = 0;
363 PortP->ParamSem = 0;
364 PortP->Mapped = 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);
371 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800372 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
375/*
376** Incoming command on the COMMAND_RUP to be processed.
377*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800378static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800380 struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 struct Port *PortP;
382 struct UnixRup *UnixRupP;
Alan Cox00d83a52006-03-24 03:18:28 -0800383 unsigned short SysPort;
384 unsigned short ReportedModemStatus;
385 unsigned short rup;
386 unsigned short subCommand;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 unsigned long flags;
388
Andrew Morton8d8706e2006-01-11 12:17:49 -0800389 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800392 ** 16 port RTA note:
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').
398 */
Alan Cox00d83a52006-03-24 03:18:28 -0800399 rup = readb(&PktCmdP->PhbNum) / (unsigned short) PORTS_PER_RTA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 UnixRupP = &HostP->UnixRups[rup];
Alan Cox00d83a52006-03-24 03:18:28 -0800401 SysPort = UnixRupP->BaseSysPort + (readb(&PktCmdP->PhbNum) % (unsigned short) PORTS_PER_RTA);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800402 rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Andrew Morton8d8706e2006-01-11 12:17:49 -0800404 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");
Alan Cox00d83a52006-03-24 03:18:28 -0800407 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Host number %Zd, name ``%s''\n", HostP - p->RIOHosts, HostP->Name);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800408 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Alan Cox00d83a52006-03-24 03:18:28 -0800410 if (Rup >= (unsigned short) MAX_RUP) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800411 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 -0700412 } else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800413 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 -0700414
Andrew Morton8d8706e2006-01-11 12:17:49 -0800415 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return TRUE;
422 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800423 PortP = p->RIOPortp[SysPort];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 rio_spin_lock_irqsave(&PortP->portSem, flags);
Alan Cox00d83a52006-03-24 03:18:28 -0800425 switch (readb(&PktCmdP->Command)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800426 case BREAK_RECEIVED:
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
431 not freed. */
432 /* Call tmgr HANGUP HERE */
433 /* Fix this later when every thing works !!!! RAMRAJ */
434 gs_got_break(&PortP->gs);
435 break;
436
437 case COMPLETE:
Alan Cox00d83a52006-03-24 03:18:28 -0800438 rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %Zd\n", readb(&PktCmdP->PhbNum), HostP - p->RIOHosts);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800439 subCommand = 1;
Alan Cox00d83a52006-03-24 03:18:28 -0800440 switch (readb(&PktCmdP->SubCommand)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800441 case MEMDUMP:
Alan Cox00d83a52006-03-24 03:18:28 -0800442 rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", readb(&PktCmdP->SubCommand), readw(&PktCmdP->SubAddr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 break;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800444 case READ_REGISTER:
Alan Cox00d83a52006-03-24 03:18:28 -0800445 rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", readw(&PktCmdP->SubAddr));
446 p->CdRegister = (readb(&PktCmdP->ModemStatus) & MSVR1_HOST);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800447 break;
448 default:
449 subCommand = 0;
450 break;
451 }
452 if (subCommand)
453 break;
Alan Cox00d83a52006-03-24 03:18:28 -0800454 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)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800456 rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800457 PortP->PortState = readb(&PktCmdP->PortStatus);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800458 /* What should we do here ...
459 wakeup( &PortP->PortState );
460 */
461 } else
462 rio_dprintk(RIO_DEBUG_CMD, "No change\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Andrew Morton8d8706e2006-01-11 12:17:49 -0800464 /* FALLTHROUGH */
465 case MODEM_STATUS:
466 /*
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!).
470 */
Alan Cox00d83a52006-03-24 03:18:28 -0800471 ReportedModemStatus = readb(&PktCmdP->ModemStatus);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800472 if ((PortP->ModemState & MSVR1_HOST) == (ReportedModemStatus & MSVR1_HOST)) {
473 rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800475 ** Update ModemState just in case tbusy or tstop states have
476 ** changed.
477 */
478 PortP->ModemState = ReportedModemStatus;
479 } else {
480 rio_dprintk(RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n", PortP->ModemState, ReportedModemStatus);
481 PortP->ModemState = ReportedModemStatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482#ifdef MODEM_SUPPORT
Andrew Morton8d8706e2006-01-11 12:17:49 -0800483 if (PortP->Mapped) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 /***********************************************************\
485 *************************************************************
486 *** ***
487 *** M O D E M S T A T E C H A N G E ***
488 *** ***
489 *************************************************************
490 \***********************************************************/
491 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800492 ** If the device is a modem, then check the modem
493 ** carrier.
494 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (PortP->gs.tty == NULL)
496 break;
497 if (PortP->gs.tty->termios == NULL)
498 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Andrew Morton8d8706e2006-01-11 12:17:49 -0800500 if (!(PortP->gs.tty->termios->c_cflag & CLOCAL) && ((PortP->State & (RIO_MOPEN | RIO_WOPEN)))) {
501
502 rio_dprintk(RIO_DEBUG_CMD, "Is there a Carrier?\n");
503 /*
504 ** Is there a carrier?
505 */
506 if (PortP->ModemState & MSVR1_CD) {
507 /*
508 ** Has carrier just appeared?
509 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 if (!(PortP->State & RIO_CARR_ON)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800511 rio_dprintk(RIO_DEBUG_CMD, "Carrier just came up.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 PortP->State |= RIO_CARR_ON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800513 /*
514 ** wakeup anyone in WOPEN
515 */
516 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN))
517 wake_up_interruptible(&PortP->gs.open_wait);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800520 /*
521 ** Has carrier just dropped?
522 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 if (PortP->State & RIO_CARR_ON) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800524 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN | RIO_MOPEN))
525 tty_hangup(PortP->gs.tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 PortP->State &= ~RIO_CARR_ON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800527 rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800528 }
529 }
530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800533 }
534 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Andrew Morton8d8706e2006-01-11 12:17:49 -0800536 default:
Alan Cox00d83a52006-03-24 03:18:28 -0800537 rio_dprintk(RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %Zd\n", readb(&PktCmdP->Command), HostP - p->RIOHosts);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800538 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 }
540 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
541
Andrew Morton8d8706e2006-01-11 12:17:49 -0800542 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 return TRUE;
545}
Andrew Morton8d8706e2006-01-11 12:17:49 -0800546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547/*
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.
554**
555*/
556
557/*
558** Allocate an empty command block.
559*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800560struct CmdBlk *RIOGetCmdBlk(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
562 struct CmdBlk *CmdBlkP;
563
Alan Cox00d83a52006-03-24 03:18:28 -0800564 CmdBlkP = (struct CmdBlk *)kmalloc(sizeof(struct CmdBlk), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 if (CmdBlkP)
Alan Cox00d83a52006-03-24 03:18:28 -0800566 memset(CmdBlkP, 0, sizeof(struct CmdBlk));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 return CmdBlkP;
568}
569
570/*
571** Return a block to the head of the free list.
572*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800573void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
Alan Cox00d83a52006-03-24 03:18:28 -0800575 kfree(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}
577
578/*
579** attach a command block to the list of commands to be performed for
580** a given rup.
581*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800582int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
584 struct CmdBlk **Base;
585 struct UnixRup *UnixRupP;
586 unsigned long flags;
587
Alan Cox00d83a52006-03-24 03:18:28 -0800588 if (Rup >= (unsigned short) (MAX_RUP + LINKS_PER_UNIT)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800589 rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup);
590 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 return RIO_FAIL;
592 }
593
594 UnixRupP = &HostP->UnixRups[Rup];
595
596 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
597
598 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800599 ** If the RUP is currently inactive, then put the request
600 ** straight on the RUP....
601 */
Alan Cox00d83a52006-03-24 03:18:28 -0800602 if ((UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE) && (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800603 : TRUE)) {
604 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 -0700605
606 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800607 ** Whammy! blat that pack!
608 */
609 HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800612 ** place command packet on the pending position.
613 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 UnixRupP->CmdPendingP = CmdBlkP;
615
616 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800617 ** set the command register
618 */
Alan Cox00d83a52006-03-24 03:18:28 -0800619 writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
622
623 return RIO_SUCCESS;
624 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800625 rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Andrew Morton8d8706e2006-01-11 12:17:49 -0800627 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");
Alan Cox00d83a52006-03-24 03:18:28 -0800631 if (readw(&UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800632 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 Base = &UnixRupP->CmdsWaitingP;
635
Alan Cox00d83a52006-03-24 03:18:28 -0800636 rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk 0x%p at 0x%p\n", CmdBlkP, Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Andrew Morton8d8706e2006-01-11 12:17:49 -0800638 while (*Base) {
Alan Cox00d83a52006-03-24 03:18:28 -0800639 rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk 0x%p here\n", *Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 Base = &((*Base)->NextP);
Alan Cox00d83a52006-03-24 03:18:28 -0800641 rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk 0x%p at 0x%p\n", CmdBlkP, Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643
Alan Cox00d83a52006-03-24 03:18:28 -0800644 rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk 0x%p at 0x%p\n", CmdBlkP, Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 *Base = CmdBlkP;
647
648 CmdBlkP->NextP = NULL;
649
650 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
651
652 return RIO_SUCCESS;
653}
654
655/*
656** Here we go - if there is an empty rup, fill it!
657** must be called at splrio() or higher.
658*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800659void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
Alan Cox00d83a52006-03-24 03:18:28 -0800661 struct CmdBlk *CmdBlkP;
662 struct UnixRup *UnixRupP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 struct PKT *PacketP;
Alan Cox00d83a52006-03-24 03:18:28 -0800664 unsigned short Rup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 unsigned long flags;
666
667
Andrew Morton8d8706e2006-01-11 12:17:49 -0800668 Rup = MAX_RUP + LINKS_PER_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Andrew Morton8d8706e2006-01-11 12:17:49 -0800670 do { /* do this loop for each RUP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800672 ** locate the rup we are processing & lock it
673 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 UnixRupP = &HostP->UnixRups[--Rup];
675
676 spin_lock_irqsave(&UnixRupP->RupLock, flags);
677
678 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800679 ** First check for incoming commands:
680 */
Alan Cox00d83a52006-03-24 03:18:28 -0800681 if (readw(&UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 int FreeMe;
683
Alan Cox00d83a52006-03-24 03:18:28 -0800684 PacketP = (PKT *) RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->rxpkt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Andrew Morton8d8706e2006-01-11 12:17:49 -0800686 ShowPacket(DBG_CMD, PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Alan Cox00d83a52006-03-24 03:18:28 -0800688 switch (readb(&PacketP->dest_port)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800689 case BOOT_RUP:
Alan Cox00d83a52006-03-24 03:18:28 -0800690 rio_dprintk(RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n", readb(&PacketP->len) & 0x80 ? "Command" : "Data", readb(&PacketP->data[0]));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800691 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
692 FreeMe = RIOBootRup(p, Rup, HostP, PacketP);
693 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
694 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Andrew Morton8d8706e2006-01-11 12:17:49 -0800696 case COMMAND_RUP:
697 /*
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.
701 */
702 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
703 FreeMe = RIOCommandRup(p, Rup, HostP, PacketP);
704 if (PacketP->data[5] == MEMDUMP) {
Alan Cox00d83a52006-03-24 03:18:28 -0800705 rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", *(unsigned short *) & (PacketP->data[6]));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800706 HostP->Copy((caddr_t) & (PacketP->data[8]), (caddr_t) p->RIOMemDump, 32);
707 }
708 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
709 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Andrew Morton8d8706e2006-01-11 12:17:49 -0800711 case ROUTE_RUP:
712 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
713 FreeMe = RIORouteRup(p, Rup, HostP, PacketP);
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 default:
Alan Cox00d83a52006-03-24 03:18:28 -0800718 rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", readb(&PacketP->dest_port));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800719 FreeMe = 1;
720 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722
Andrew Morton8d8706e2006-01-11 12:17:49 -0800723 if (FreeMe) {
724 rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n");
725 put_free_end(HostP, PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
Alan Cox00d83a52006-03-24 03:18:28 -0800727 writew(RX_RUP_INACTIVE, &UnixRupP->RupP->rxcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Alan Cox00d83a52006-03-24 03:18:28 -0800729 if (readw(&UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800730 rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup);
Alan Cox00d83a52006-03-24 03:18:28 -0800731 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &UnixRupP->RupP->handshake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 }
733 }
734 }
735
736 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800737 ** IF a command was running on the port,
738 ** and it has completed, then tidy it up.
739 */
740 if ((CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */
Alan Cox00d83a52006-03-24 03:18:28 -0800741 (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800743 ** we are idle.
744 ** there is a command in pending.
745 ** Therefore, this command has finished.
746 ** So, wakeup whoever is waiting for it (and tell them
747 ** what happened).
748 */
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]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Alan Cox00d83a52006-03-24 03:18:28 -0800752 rio_dprintk(RIO_DEBUG_CMD, "Command 0x%p completed\n", CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800755 ** Clear the Rup lock to prevent mutual exclusion.
756 */
757 if (CmdBlkP->PostFuncP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800759 (*CmdBlkP->PostFuncP) (CmdBlkP->PostArg, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
761 }
762
763 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800764 ** ....clear the pending flag....
765 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 UnixRupP->CmdPendingP = NULL;
767
768 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800769 ** ....and return the command block to the freelist.
770 */
771 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 }
773
774 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800775 ** If there is a command for this rup, and the rup
776 ** is idle, then process the command
777 */
778 if ((CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */
Alan Cox00d83a52006-03-24 03:18:28 -0800779 (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800781 ** if the pre-function is non-zero, call it.
782 ** If it returns RIO_FAIL then don't
783 ** send this command yet!
784 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800785 if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : TRUE)) {
Alan Cox00d83a52006-03-24 03:18:28 -0800786 rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command 0x%p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800787 } else {
Alan Cox00d83a52006-03-24 03:18:28 -0800788 rio_dprintk(RIO_DEBUG_CMD, "Start new command 0x%p Cmd byte is 0x%x\n", CmdBlkP, CmdBlkP->Packet.data[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800790 ** Whammy! blat that pack!
791 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800792 HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800795 ** remove the command from the rup command queue...
796 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 UnixRupP->CmdsWaitingP = CmdBlkP->NextP;
798
799 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800800 ** ...and place it on the pending position.
801 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 UnixRupP->CmdPendingP = CmdBlkP;
803
804 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800805 ** set the command register
806 */
Alan Cox00d83a52006-03-24 03:18:28 -0800807 writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800810 ** the command block will be freed
811 ** when the command has been processed.
812 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 }
814 }
815 spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800816 } while (Rup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817}
818
Alan Cox00d83a52006-03-24 03:18:28 -0800819int RIOWFlushMark(unsigned long iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800821 struct Port *PortP = (struct Port *) iPortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 unsigned long flags;
823
824 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 PortP->WflushFlag++;
826 PortP->MagicFlags |= MAGIC_FLUSH;
827 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800828 return RIOUnUse(iPortP, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829}
830
Alan Cox00d83a52006-03-24 03:18:28 -0800831int RIORFlushEnable(unsigned long iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800833 struct Port *PortP = (struct Port *) iPortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 PKT *PacketP;
835 unsigned long flags;
836
837 rio_spin_lock_irqsave(&PortP->portSem, flags);
838
Andrew Morton8d8706e2006-01-11 12:17:49 -0800839 while (can_remove_receive(&PacketP, PortP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 remove_receive(PortP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800841 ShowPacket(DBG_PROC, PacketP);
842 put_free_end(PortP->HostP, PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 }
844
Alan Cox00d83a52006-03-24 03:18:28 -0800845 if (readw(&PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800847 ** MAGIC! (Basically, handshake the RX buffer, so that
848 ** the RTAs upstream can be re-enabled.)
849 */
850 rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800851 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &PortP->PhbP->handshake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 }
853 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800854 return RIOUnUse(iPortP, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
856
Alan Cox00d83a52006-03-24 03:18:28 -0800857int RIOUnUse(unsigned long iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800859 struct Port *PortP = (struct Port *) iPortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 unsigned long flags;
861
862 rio_spin_lock_irqsave(&PortP->portSem, flags);
863
Andrew Morton8d8706e2006-01-11 12:17:49 -0800864 rio_dprintk(RIO_DEBUG_CMD, "Decrement in use count for port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 if (PortP->InUse) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800867 if (--PortP->InUse != NOT_INUSE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
869 return 0;
870 }
871 }
872 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800873 ** 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.
886 */
Alan Cox00d83a52006-03-24 03:18:28 -0800887 writew(1, &PortP->HostP->ParmMapP->tx_intr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 /* What to do here ..
Andrew Morton8d8706e2006-01-11 12:17:49 -0800889 wakeup( (caddr_t)&(PortP->InUse) );
890 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
892 return 0;
893}
894
Andrew Morton8d8706e2006-01-11 12:17:49 -0800895void ShowPacket(uint Flags, struct PKT *PacketP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
897}
898
899/*
900**
901** How to use this file:
902**
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
914** txcontrol.
915**
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.
919**
920** The structure has the following fields:
921**
922** struct CmdBlk
923** {
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 **
930** };
931**
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.
934**
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.
938**
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.
943**
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.
948**
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
953** RIOGetCmdBlk().
954**
955*/