blob: 245f03195b7c6da9ce7f664e974664617b4baf33 [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "pkt.h"
55#include "daemon.h"
56#include "rio.h"
57#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include "cmdpkt.h"
59#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include "rup.h"
61#include "port.h"
62#include "riodrvr.h"
63#include "rioinfo.h"
64#include "func.h"
65#include "errors.h"
66#include "pci.h"
67
68#include "parmmap.h"
69#include "unixrup.h"
70#include "board.h"
71#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include "phb.h"
73#include "link.h"
74#include "cmdblk.h"
75#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#include "cirrus.h"
77
78
79static struct IdentifyRta IdRta;
80static struct KillNeighbour KillUnit;
81
Andrew Morton8d8706e2006-01-11 12:17:49 -080082int RIOFoadRta(struct Host *HostP, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 struct CmdBlk *CmdBlkP;
85
Andrew Morton8d8706e2006-01-11 12:17:49 -080086 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 CmdBlkP = RIOGetCmdBlk();
89
Andrew Morton8d8706e2006-01-11 12:17:49 -080090 if (!CmdBlkP) {
91 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return -ENXIO;
93 }
94
95 CmdBlkP->Packet.dest_unit = MapP->ID;
96 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -080097 CmdBlkP->Packet.src_unit = 0;
98 CmdBlkP->Packet.src_port = BOOT_RUP;
99 CmdBlkP->Packet.len = 0x84;
100 CmdBlkP->Packet.data[0] = IFOAD;
101 CmdBlkP->Packet.data[1] = 0;
102 CmdBlkP->Packet.data[2] = IFOAD_MAGIC & 0xFF;
103 CmdBlkP->Packet.data[3] = (IFOAD_MAGIC >> 8) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Andrew Morton8d8706e2006-01-11 12:17:49 -0800105 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
106 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: Failed to queue foad command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 return -EIO;
108 }
109 return 0;
110}
111
Andrew Morton8d8706e2006-01-11 12:17:49 -0800112int RIOZombieRta(struct Host *HostP, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
114 struct CmdBlk *CmdBlkP;
115
Andrew Morton8d8706e2006-01-11 12:17:49 -0800116 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 CmdBlkP = RIOGetCmdBlk();
119
Andrew Morton8d8706e2006-01-11 12:17:49 -0800120 if (!CmdBlkP) {
121 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return -ENXIO;
123 }
124
125 CmdBlkP->Packet.dest_unit = MapP->ID;
126 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800127 CmdBlkP->Packet.src_unit = 0;
128 CmdBlkP->Packet.src_port = BOOT_RUP;
129 CmdBlkP->Packet.len = 0x84;
130 CmdBlkP->Packet.data[0] = ZOMBIE;
131 CmdBlkP->Packet.data[1] = 0;
132 CmdBlkP->Packet.data[2] = ZOMBIE_MAGIC & 0xFF;
133 CmdBlkP->Packet.data[3] = (ZOMBIE_MAGIC >> 8) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Andrew Morton8d8706e2006-01-11 12:17:49 -0800135 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
136 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: Failed to queue zombie command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return -EIO;
138 }
139 return 0;
140}
141
Alan Cox00d83a52006-03-24 03:18:28 -0800142int RIOCommandRta(struct rio_info *p, unsigned long RtaUnique, int (*func) (struct Host * HostP, struct Map * MapP))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Alan Cox00d83a52006-03-24 03:18:28 -0800144 unsigned int Host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Alan Cox554b7c82006-03-24 03:18:32 -0800146 rio_dprintk(RIO_DEBUG_CMD, "Command RTA 0x%lx func %p\n", RtaUnique, func);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Andrew Morton8d8706e2006-01-11 12:17:49 -0800148 if (!RtaUnique)
149 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Andrew Morton8d8706e2006-01-11 12:17:49 -0800151 for (Host = 0; Host < p->RIONumHosts; Host++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800152 unsigned int Rta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 struct Host *HostP = &p->RIOHosts[Host];
154
Andrew Morton8d8706e2006-01-11 12:17:49 -0800155 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 struct Map *MapP = &HostP->Mapping[Rta];
157
Andrew Morton8d8706e2006-01-11 12:17:49 -0800158 if (MapP->RtaUniqueNum == RtaUnique) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 uint Link;
160
161 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800162 ** now, lets just check we have a route to it...
163 ** IF the routing stuff is working, then one of the
164 ** topology entries for this unit will have a legit
165 ** route *somewhere*. We care not where - if its got
166 ** any connections, we can get to it.
167 */
168 for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800169 if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800171 ** Its worth trying the operation...
172 */
173 return (*func) (HostP, MapP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 }
175 }
176 }
177 }
178 }
179 return -ENXIO;
180}
181
182
Al Virod886cb52006-05-27 00:08:25 -0400183int RIOIdentifyRta(struct rio_info *p, void __user * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Alan Cox00d83a52006-03-24 03:18:28 -0800185 unsigned int Host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Alan Cox00d83a52006-03-24 03:18:28 -0800187 if (copy_from_user(&IdRta, arg, sizeof(IdRta))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800188 rio_dprintk(RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 p->RIOError.Error = COPYIN_FAILED;
190 return -EFAULT;
191 }
192
Andrew Morton8d8706e2006-01-11 12:17:49 -0800193 for (Host = 0; Host < p->RIONumHosts; Host++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800194 unsigned int Rta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 struct Host *HostP = &p->RIOHosts[Host];
196
Andrew Morton8d8706e2006-01-11 12:17:49 -0800197 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 struct Map *MapP = &HostP->Mapping[Rta];
199
Andrew Morton8d8706e2006-01-11 12:17:49 -0800200 if (MapP->RtaUniqueNum == IdRta.RtaUnique) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 uint Link;
202 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800203 ** now, lets just check we have a route to it...
204 ** IF the routing stuff is working, then one of the
205 ** topology entries for this unit will have a legit
206 ** route *somewhere*. We care not where - if its got
207 ** any connections, we can get to it.
208 */
209 for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800210 if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800212 ** Its worth trying the operation...
213 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 struct CmdBlk *CmdBlkP;
215
Andrew Morton8d8706e2006-01-11 12:17:49 -0800216 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218 CmdBlkP = RIOGetCmdBlk();
219
Andrew Morton8d8706e2006-01-11 12:17:49 -0800220 if (!CmdBlkP) {
221 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 return -ENXIO;
223 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 CmdBlkP->Packet.dest_unit = MapP->ID;
226 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800227 CmdBlkP->Packet.src_unit = 0;
228 CmdBlkP->Packet.src_port = BOOT_RUP;
229 CmdBlkP->Packet.len = 0x84;
230 CmdBlkP->Packet.data[0] = IDENTIFY;
231 CmdBlkP->Packet.data[1] = 0;
232 CmdBlkP->Packet.data[2] = IdRta.ID;
233
234 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
235 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: Failed to queue command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return -EIO;
237 }
238 return 0;
239 }
240 }
241 }
242 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800243 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return -ENOENT;
245}
246
247
Al Virod886cb52006-05-27 00:08:25 -0400248int RIOKillNeighbour(struct rio_info *p, void __user * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
250 uint Host;
251 uint ID;
252 struct Host *HostP;
253 struct CmdBlk *CmdBlkP;
254
Andrew Morton8d8706e2006-01-11 12:17:49 -0800255 rio_dprintk(RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Alan Cox00d83a52006-03-24 03:18:28 -0800257 if (copy_from_user(&KillUnit, arg, sizeof(KillUnit))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800258 rio_dprintk(RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 p->RIOError.Error = COPYIN_FAILED;
260 return -EFAULT;
261 }
262
Andrew Morton8d8706e2006-01-11 12:17:49 -0800263 if (KillUnit.Link > 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return -ENXIO;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 CmdBlkP = RIOGetCmdBlk();
267
Andrew Morton8d8706e2006-01-11 12:17:49 -0800268 if (!CmdBlkP) {
269 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 return -ENXIO;
271 }
272
273 CmdBlkP->Packet.dest_unit = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800274 CmdBlkP->Packet.src_unit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800276 CmdBlkP->Packet.src_port = BOOT_RUP;
277 CmdBlkP->Packet.len = 0x84;
278 CmdBlkP->Packet.data[0] = UFOAD;
279 CmdBlkP->Packet.data[1] = KillUnit.Link;
280 CmdBlkP->Packet.data[2] = UFOAD_MAGIC & 0xFF;
281 CmdBlkP->Packet.data[3] = (UFOAD_MAGIC >> 8) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Andrew Morton8d8706e2006-01-11 12:17:49 -0800283 for (Host = 0; Host < p->RIONumHosts; Host++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 ID = 0;
285 HostP = &p->RIOHosts[Host];
286
Andrew Morton8d8706e2006-01-11 12:17:49 -0800287 if (HostP->UniqueNum == KillUnit.UniqueNum) {
288 if (RIOQueueCmdBlk(HostP, RTAS_PER_HOST + KillUnit.Link, CmdBlkP) == RIO_FAIL) {
289 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 return -EIO;
291 }
292 return 0;
293 }
294
Andrew Morton8d8706e2006-01-11 12:17:49 -0800295 for (ID = 0; ID < RTAS_PER_HOST; ID++) {
296 if (HostP->Mapping[ID].RtaUniqueNum == KillUnit.UniqueNum) {
297 CmdBlkP->Packet.dest_unit = ID + 1;
298 if (RIOQueueCmdBlk(HostP, ID, CmdBlkP) == RIO_FAIL) {
299 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return -EIO;
301 }
302 return 0;
303 }
304 }
305 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800306 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 return -ENXIO;
308}
309
Andrew Morton8d8706e2006-01-11 12:17:49 -0800310int RIOSuspendBootRta(struct Host *HostP, int ID, int Link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
312 struct CmdBlk *CmdBlkP;
313
Andrew Morton8d8706e2006-01-11 12:17:49 -0800314 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA ID %d, link %c\n", ID, 'A' + Link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 CmdBlkP = RIOGetCmdBlk();
317
Andrew Morton8d8706e2006-01-11 12:17:49 -0800318 if (!CmdBlkP) {
319 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 return -ENXIO;
321 }
322
323 CmdBlkP->Packet.dest_unit = ID;
324 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800325 CmdBlkP->Packet.src_unit = 0;
326 CmdBlkP->Packet.src_port = BOOT_RUP;
327 CmdBlkP->Packet.len = 0x84;
328 CmdBlkP->Packet.data[0] = IWAIT;
329 CmdBlkP->Packet.data[1] = Link;
330 CmdBlkP->Packet.data[2] = IWAIT_MAGIC & 0xFF;
331 CmdBlkP->Packet.data[3] = (IWAIT_MAGIC >> 8) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Andrew Morton8d8706e2006-01-11 12:17:49 -0800333 if (RIOQueueCmdBlk(HostP, ID - 1, CmdBlkP) == RIO_FAIL) {
334 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: Failed to queue iwait command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 return -EIO;
336 }
337 return 0;
338}
339
Andrew Morton8d8706e2006-01-11 12:17:49 -0800340int RIOFoadWakeup(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
342 int port;
Alan Cox00d83a52006-03-24 03:18:28 -0800343 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 unsigned long flags;
345
Andrew Morton8d8706e2006-01-11 12:17:49 -0800346 for (port = 0; port < RIO_PORTS; port++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 PortP = p->RIOPortp[port];
348
349 rio_spin_lock_irqsave(&PortP->portSem, flags);
350 PortP->Config = 0;
351 PortP->State = 0;
352 PortP->InUse = NOT_INUSE;
353 PortP->PortState = 0;
354 PortP->FlushCmdBodge = 0;
355 PortP->ModemLines = 0;
356 PortP->ModemState = 0;
357 PortP->CookMode = 0;
358 PortP->ParamSem = 0;
359 PortP->Mapped = 0;
360 PortP->WflushFlag = 0;
361 PortP->MagicFlags = 0;
362 PortP->RxDataStart = 0;
363 PortP->TxBufferIn = 0;
364 PortP->TxBufferOut = 0;
365 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
366 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800367 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
370/*
371** Incoming command on the COMMAND_RUP to be processed.
372*/
Al Virod886cb52006-05-27 00:08:25 -0400373static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, struct PKT __iomem *PacketP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
Al Virod886cb52006-05-27 00:08:25 -0400375 struct PktCmd __iomem *PktCmdP = (struct PktCmd __iomem *)PacketP->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 struct Port *PortP;
377 struct UnixRup *UnixRupP;
Alan Cox00d83a52006-03-24 03:18:28 -0800378 unsigned short SysPort;
379 unsigned short ReportedModemStatus;
380 unsigned short rup;
381 unsigned short subCommand;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 unsigned long flags;
383
Andrew Morton8d8706e2006-01-11 12:17:49 -0800384 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800387 ** 16 port RTA note:
388 ** Command rup packets coming from the RTA will have pkt->data[1] (which
389 ** translates to PktCmdP->PhbNum) set to the host port number for the
390 ** particular unit. To access the correct BaseSysPort for a 16 port RTA,
391 ** we can use PhbNum to get the rup number for the appropriate 8 port
392 ** block (for the first block, this should be equal to 'Rup').
393 */
Alan Cox00d83a52006-03-24 03:18:28 -0800394 rup = readb(&PktCmdP->PhbNum) / (unsigned short) PORTS_PER_RTA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 UnixRupP = &HostP->UnixRups[rup];
Alan Cox00d83a52006-03-24 03:18:28 -0800396 SysPort = UnixRupP->BaseSysPort + (readb(&PktCmdP->PhbNum) % (unsigned short) PORTS_PER_RTA);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800397 rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Andrew Morton8d8706e2006-01-11 12:17:49 -0800399 if (UnixRupP->BaseSysPort == NO_PORT) {
400 rio_dprintk(RIO_DEBUG_CMD, "OBSCURE ERROR!\n");
401 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 -0800402 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 -0800403 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Alan Cox00d83a52006-03-24 03:18:28 -0800405 if (Rup >= (unsigned short) MAX_RUP) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800406 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 -0700407 } else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800408 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 -0700409
Al Viro92af11c2006-05-27 02:24:14 -0400410 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Destination 0x%x:0x%x\n", readb(&PacketP->dest_unit), readb(&PacketP->dest_port));
411 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Source 0x%x:0x%x\n", readb(&PacketP->src_unit), readb(&PacketP->src_port));
412 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Length 0x%x (%d)\n", readb(&PacketP->len), readb(&PacketP->len));
413 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Control 0x%x (%d)\n", readb(&PacketP->control), readb(&PacketP->control));
414 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Check 0x%x (%d)\n", readw(&PacketP->csum), readw(&PacketP->csum));
415 rio_dprintk(RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, " "Command Code 0x%x\n", readb(&PktCmdP->PhbNum), readb(&PktCmdP->Command));
Alan Cox554b7c82006-03-24 03:18:32 -0800416 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800418 PortP = p->RIOPortp[SysPort];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 rio_spin_lock_irqsave(&PortP->portSem, flags);
Alan Cox00d83a52006-03-24 03:18:28 -0800420 switch (readb(&PktCmdP->Command)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800421 case BREAK_RECEIVED:
422 rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n");
423 /* If the current line disc. is not multi-threading and
424 the current processor is not the default, reset rup_intr
Alan Cox554b7c82006-03-24 03:18:32 -0800425 and return 0 to ensure that the command packet is
Andrew Morton8d8706e2006-01-11 12:17:49 -0800426 not freed. */
427 /* Call tmgr HANGUP HERE */
428 /* Fix this later when every thing works !!!! RAMRAJ */
429 gs_got_break(&PortP->gs);
430 break;
431
432 case COMPLETE:
Alan Cox00d83a52006-03-24 03:18:28 -0800433 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 -0800434 subCommand = 1;
Alan Cox00d83a52006-03-24 03:18:28 -0800435 switch (readb(&PktCmdP->SubCommand)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800436 case MEMDUMP:
Alan Cox00d83a52006-03-24 03:18:28 -0800437 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 -0700438 break;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800439 case READ_REGISTER:
Alan Cox00d83a52006-03-24 03:18:28 -0800440 rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", readw(&PktCmdP->SubAddr));
441 p->CdRegister = (readb(&PktCmdP->ModemStatus) & MSVR1_HOST);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800442 break;
443 default:
444 subCommand = 0;
445 break;
446 }
447 if (subCommand)
448 break;
Alan Cox00d83a52006-03-24 03:18:28 -0800449 rio_dprintk(RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n", readb(&PktCmdP->PortStatus), PortP->PortState);
450 if (PortP->PortState != readb(&PktCmdP->PortStatus)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800451 rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800452 PortP->PortState = readb(&PktCmdP->PortStatus);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800453 /* What should we do here ...
454 wakeup( &PortP->PortState );
455 */
456 } else
457 rio_dprintk(RIO_DEBUG_CMD, "No change\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Andrew Morton8d8706e2006-01-11 12:17:49 -0800459 /* FALLTHROUGH */
460 case MODEM_STATUS:
461 /*
462 ** Knock out the tbusy and tstop bits, as these are not relevant
463 ** to the check for modem status change (they're just there because
464 ** it's a convenient place to put them!).
465 */
Alan Cox00d83a52006-03-24 03:18:28 -0800466 ReportedModemStatus = readb(&PktCmdP->ModemStatus);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800467 if ((PortP->ModemState & MSVR1_HOST) == (ReportedModemStatus & MSVR1_HOST)) {
468 rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800470 ** Update ModemState just in case tbusy or tstop states have
471 ** changed.
472 */
473 PortP->ModemState = ReportedModemStatus;
474 } else {
475 rio_dprintk(RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n", PortP->ModemState, ReportedModemStatus);
476 PortP->ModemState = ReportedModemStatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#ifdef MODEM_SUPPORT
Andrew Morton8d8706e2006-01-11 12:17:49 -0800478 if (PortP->Mapped) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 /***********************************************************\
480 *************************************************************
481 *** ***
482 *** M O D E M S T A T E C H A N G E ***
483 *** ***
484 *************************************************************
485 \***********************************************************/
486 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800487 ** If the device is a modem, then check the modem
488 ** carrier.
489 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 if (PortP->gs.tty == NULL)
491 break;
492 if (PortP->gs.tty->termios == NULL)
493 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Andrew Morton8d8706e2006-01-11 12:17:49 -0800495 if (!(PortP->gs.tty->termios->c_cflag & CLOCAL) && ((PortP->State & (RIO_MOPEN | RIO_WOPEN)))) {
496
497 rio_dprintk(RIO_DEBUG_CMD, "Is there a Carrier?\n");
498 /*
499 ** Is there a carrier?
500 */
501 if (PortP->ModemState & MSVR1_CD) {
502 /*
503 ** Has carrier just appeared?
504 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (!(PortP->State & RIO_CARR_ON)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800506 rio_dprintk(RIO_DEBUG_CMD, "Carrier just came up.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 PortP->State |= RIO_CARR_ON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800508 /*
509 ** wakeup anyone in WOPEN
510 */
511 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN))
512 wake_up_interruptible(&PortP->gs.open_wait);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800515 /*
516 ** Has carrier just dropped?
517 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 if (PortP->State & RIO_CARR_ON) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800519 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN | RIO_MOPEN))
520 tty_hangup(PortP->gs.tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 PortP->State &= ~RIO_CARR_ON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800522 rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800523 }
524 }
525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800528 }
529 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Andrew Morton8d8706e2006-01-11 12:17:49 -0800531 default:
Alan Cox00d83a52006-03-24 03:18:28 -0800532 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 -0800533 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
536
Andrew Morton8d8706e2006-01-11 12:17:49 -0800537 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Alan Cox554b7c82006-03-24 03:18:32 -0800539 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540}
Andrew Morton8d8706e2006-01-11 12:17:49 -0800541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542/*
543** The command mechanism:
544** Each rup has a chain of commands associated with it.
545** This chain is maintained by routines in this file.
546** Periodically we are called and we run a quick check of all the
547** active chains to determine if there is a command to be executed,
548** and if the rup is ready to accept it.
549**
550*/
551
552/*
553** Allocate an empty command block.
554*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800555struct CmdBlk *RIOGetCmdBlk(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
557 struct CmdBlk *CmdBlkP;
558
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800559 CmdBlkP = kmalloc(sizeof(struct CmdBlk), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 if (CmdBlkP)
Alan Cox00d83a52006-03-24 03:18:28 -0800561 memset(CmdBlkP, 0, sizeof(struct CmdBlk));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 return CmdBlkP;
563}
564
565/*
566** Return a block to the head of the free list.
567*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800568void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
Alan Cox00d83a52006-03-24 03:18:28 -0800570 kfree(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571}
572
573/*
574** attach a command block to the list of commands to be performed for
575** a given rup.
576*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800577int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
579 struct CmdBlk **Base;
580 struct UnixRup *UnixRupP;
581 unsigned long flags;
582
Alan Cox00d83a52006-03-24 03:18:28 -0800583 if (Rup >= (unsigned short) (MAX_RUP + LINKS_PER_UNIT)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800584 rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup);
585 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 return RIO_FAIL;
587 }
588
589 UnixRupP = &HostP->UnixRups[Rup];
590
591 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
592
593 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800594 ** If the RUP is currently inactive, then put the request
595 ** straight on the RUP....
596 */
Alan Cox00d83a52006-03-24 03:18:28 -0800597 if ((UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE) && (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP)
Alan Cox554b7c82006-03-24 03:18:32 -0800598 : 1)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800599 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 -0700600
601 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800602 ** Whammy! blat that pack!
603 */
Al Viro92af11c2006-05-27 02:24:14 -0400604 HostP->Copy(&CmdBlkP->Packet, RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->txpkt)), sizeof(struct PKT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800607 ** place command packet on the pending position.
608 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 UnixRupP->CmdPendingP = CmdBlkP;
610
611 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800612 ** set the command register
613 */
Alan Cox00d83a52006-03-24 03:18:28 -0800614 writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
617
Alan Cox554b7c82006-03-24 03:18:32 -0800618 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800620 rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Andrew Morton8d8706e2006-01-11 12:17:49 -0800622 if (UnixRupP->CmdsWaitingP != NULL)
623 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command waiting\n");
624 if (UnixRupP->CmdPendingP != NULL)
625 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command pending\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800626 if (readw(&UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800627 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629 Base = &UnixRupP->CmdsWaitingP;
630
Alan Cox554b7c82006-03-24 03:18:32 -0800631 rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk %p at %p\n", CmdBlkP, Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Andrew Morton8d8706e2006-01-11 12:17:49 -0800633 while (*Base) {
Alan Cox554b7c82006-03-24 03:18:32 -0800634 rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk %p here\n", *Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 Base = &((*Base)->NextP);
Alan Cox554b7c82006-03-24 03:18:32 -0800636 rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk %p at %p\n", CmdBlkP, Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638
Alan Cox554b7c82006-03-24 03:18:32 -0800639 rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk %p at %p\n", CmdBlkP, Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 *Base = CmdBlkP;
642
643 CmdBlkP->NextP = NULL;
644
645 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
646
Alan Cox554b7c82006-03-24 03:18:32 -0800647 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648}
649
650/*
651** Here we go - if there is an empty rup, fill it!
652** must be called at splrio() or higher.
653*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800654void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
Alan Cox00d83a52006-03-24 03:18:28 -0800656 struct CmdBlk *CmdBlkP;
657 struct UnixRup *UnixRupP;
Al Virod886cb52006-05-27 00:08:25 -0400658 struct PKT __iomem *PacketP;
Alan Cox00d83a52006-03-24 03:18:28 -0800659 unsigned short Rup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 unsigned long flags;
661
662
Andrew Morton8d8706e2006-01-11 12:17:49 -0800663 Rup = MAX_RUP + LINKS_PER_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Andrew Morton8d8706e2006-01-11 12:17:49 -0800665 do { /* do this loop for each RUP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800667 ** locate the rup we are processing & lock it
668 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 UnixRupP = &HostP->UnixRups[--Rup];
670
671 spin_lock_irqsave(&UnixRupP->RupLock, flags);
672
673 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800674 ** First check for incoming commands:
675 */
Alan Cox00d83a52006-03-24 03:18:28 -0800676 if (readw(&UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 int FreeMe;
678
Al Virod886cb52006-05-27 00:08:25 -0400679 PacketP = (struct PKT __iomem *) RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->rxpkt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Alan Cox00d83a52006-03-24 03:18:28 -0800681 switch (readb(&PacketP->dest_port)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800682 case BOOT_RUP:
Alan Cox00d83a52006-03-24 03:18:28 -0800683 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 -0800684 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
685 FreeMe = RIOBootRup(p, Rup, HostP, PacketP);
686 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
687 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Andrew Morton8d8706e2006-01-11 12:17:49 -0800689 case COMMAND_RUP:
690 /*
691 ** Free the RUP lock as loss of carrier causes a
692 ** ttyflush which will (eventually) call another
693 ** routine that uses the RUP lock.
694 */
695 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
696 FreeMe = RIOCommandRup(p, Rup, HostP, PacketP);
Al Viro92af11c2006-05-27 02:24:14 -0400697 if (readb(&PacketP->data[5]) == MEMDUMP) {
698 rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", readw(&(PacketP->data[6])));
Al Viro1bf08712006-05-27 01:55:52 -0400699 rio_memcpy_fromio(p->RIOMemDump, &(PacketP->data[8]), 32);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800700 }
701 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
702 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Andrew Morton8d8706e2006-01-11 12:17:49 -0800704 case ROUTE_RUP:
705 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
706 FreeMe = RIORouteRup(p, Rup, HostP, PacketP);
707 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
708 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Andrew Morton8d8706e2006-01-11 12:17:49 -0800710 default:
Alan Cox00d83a52006-03-24 03:18:28 -0800711 rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", readb(&PacketP->dest_port));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800712 FreeMe = 1;
713 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
715
Andrew Morton8d8706e2006-01-11 12:17:49 -0800716 if (FreeMe) {
717 rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n");
718 put_free_end(HostP, PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Alan Cox00d83a52006-03-24 03:18:28 -0800720 writew(RX_RUP_INACTIVE, &UnixRupP->RupP->rxcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Alan Cox00d83a52006-03-24 03:18:28 -0800722 if (readw(&UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800723 rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup);
Alan Cox00d83a52006-03-24 03:18:28 -0800724 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &UnixRupP->RupP->handshake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
726 }
727 }
728
729 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800730 ** IF a command was running on the port,
731 ** and it has completed, then tidy it up.
732 */
733 if ((CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */
Alan Cox00d83a52006-03-24 03:18:28 -0800734 (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800736 ** we are idle.
737 ** there is a command in pending.
738 ** Therefore, this command has finished.
739 ** So, wakeup whoever is waiting for it (and tell them
740 ** what happened).
741 */
742 if (CmdBlkP->Packet.dest_port == BOOT_RUP)
743 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 -0700744
Alan Cox554b7c82006-03-24 03:18:32 -0800745 rio_dprintk(RIO_DEBUG_CMD, "Command %p completed\n", CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800748 ** Clear the Rup lock to prevent mutual exclusion.
749 */
750 if (CmdBlkP->PostFuncP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800752 (*CmdBlkP->PostFuncP) (CmdBlkP->PostArg, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
754 }
755
756 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800757 ** ....clear the pending flag....
758 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 UnixRupP->CmdPendingP = NULL;
760
761 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800762 ** ....and return the command block to the freelist.
763 */
764 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 }
766
767 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800768 ** If there is a command for this rup, and the rup
769 ** is idle, then process the command
770 */
771 if ((CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */
Alan Cox00d83a52006-03-24 03:18:28 -0800772 (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800774 ** if the pre-function is non-zero, call it.
775 ** If it returns RIO_FAIL then don't
776 ** send this command yet!
777 */
Alan Cox554b7c82006-03-24 03:18:32 -0800778 if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : 1)) {
779 rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800780 } else {
Alan Cox554b7c82006-03-24 03:18:32 -0800781 rio_dprintk(RIO_DEBUG_CMD, "Start new command %p Cmd byte is 0x%x\n", CmdBlkP, CmdBlkP->Packet.data[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800783 ** Whammy! blat that pack!
784 */
Al Viro92af11c2006-05-27 02:24:14 -0400785 HostP->Copy(&CmdBlkP->Packet, RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->txpkt)), sizeof(struct PKT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800788 ** remove the command from the rup command queue...
789 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 UnixRupP->CmdsWaitingP = CmdBlkP->NextP;
791
792 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800793 ** ...and place it on the pending position.
794 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 UnixRupP->CmdPendingP = CmdBlkP;
796
797 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800798 ** set the command register
799 */
Alan Cox00d83a52006-03-24 03:18:28 -0800800 writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800803 ** the command block will be freed
804 ** when the command has been processed.
805 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 }
807 }
808 spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800809 } while (Rup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810}
811
Alan Cox00d83a52006-03-24 03:18:28 -0800812int RIOWFlushMark(unsigned long iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800814 struct Port *PortP = (struct Port *) iPortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 unsigned long flags;
816
817 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 PortP->WflushFlag++;
819 PortP->MagicFlags |= MAGIC_FLUSH;
820 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800821 return RIOUnUse(iPortP, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822}
823
Alan Cox00d83a52006-03-24 03:18:28 -0800824int RIORFlushEnable(unsigned long iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800826 struct Port *PortP = (struct Port *) iPortP;
Al Virod886cb52006-05-27 00:08:25 -0400827 struct PKT __iomem *PacketP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 unsigned long flags;
829
830 rio_spin_lock_irqsave(&PortP->portSem, flags);
831
Andrew Morton8d8706e2006-01-11 12:17:49 -0800832 while (can_remove_receive(&PacketP, PortP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 remove_receive(PortP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800834 put_free_end(PortP->HostP, PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836
Alan Cox00d83a52006-03-24 03:18:28 -0800837 if (readw(&PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800839 ** MAGIC! (Basically, handshake the RX buffer, so that
840 ** the RTAs upstream can be re-enabled.)
841 */
842 rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800843 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &PortP->PhbP->handshake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 }
845 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800846 return RIOUnUse(iPortP, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
Alan Cox00d83a52006-03-24 03:18:28 -0800849int RIOUnUse(unsigned long iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800851 struct Port *PortP = (struct Port *) iPortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 unsigned long flags;
853
854 rio_spin_lock_irqsave(&PortP->portSem, flags);
855
Andrew Morton8d8706e2006-01-11 12:17:49 -0800856 rio_dprintk(RIO_DEBUG_CMD, "Decrement in use count for port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 if (PortP->InUse) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800859 if (--PortP->InUse != NOT_INUSE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
861 return 0;
862 }
863 }
864 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800865 ** While PortP->InUse is set (i.e. a preemptive command has been sent to
866 ** the RTA and is awaiting completion), any transmit data is prevented from
867 ** being transferred from the write queue into the transmit packets
868 ** (add_transmit) and no furthur transmit interrupt will be sent for that
869 ** data. The next interrupt will occur up to 500ms later (RIOIntr is called
870 ** twice a second as a saftey measure). This was the case when kermit was
871 ** used to send data into a RIO port. After each packet was sent, TCFLSH
872 ** was called to flush the read queue preemptively. PortP->InUse was
873 ** incremented, thereby blocking the 6 byte acknowledgement packet
874 ** transmitted back. This acknowledgment hung around for 500ms before
875 ** being sent, thus reducing input performance substantially!.
876 ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data
877 ** hanging around in the transmit buffer is sent immediately.
878 */
Alan Cox00d83a52006-03-24 03:18:28 -0800879 writew(1, &PortP->HostP->ParmMapP->tx_intr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 /* What to do here ..
Andrew Morton8d8706e2006-01-11 12:17:49 -0800881 wakeup( (caddr_t)&(PortP->InUse) );
882 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
884 return 0;
885}
886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887/*
888**
889** How to use this file:
890**
891** To send a command down a rup, you need to allocate a command block, fill
892** in the packet information, fill in the command number, fill in the pre-
893** and post- functions and arguments, and then add the command block to the
894** queue of command blocks for the port in question. When the port is idle,
895** then the pre-function will be called. If this returns RIO_FAIL then the
896** command will be re-queued and tried again at a later date (probably in one
897** clock tick). If the pre-function returns NOT RIO_FAIL, then the command
898** packet will be queued on the RUP, and the txcontrol field set to the
899** command number. When the txcontrol field has changed from being the
900** command number, then the post-function will be called, with the argument
901** specified earlier, a pointer to the command block, and the value of
902** txcontrol.
903**
904** To allocate a command block, call RIOGetCmdBlk(). This returns a pointer
905** to the command block structure allocated, or NULL if there aren't any.
906** The block will have been zeroed for you.
907**
908** The structure has the following fields:
909**
910** struct CmdBlk
911** {
912** struct CmdBlk *NextP; ** Pointer to next command block **
913** struct PKT Packet; ** A packet, to copy to the rup **
914** int (*PreFuncP)(); ** The func to call to check if OK **
915** int PreArg; ** The arg for the func **
916** int (*PostFuncP)(); ** The func to call when completed **
917** int PostArg; ** The arg for the func **
918** };
919**
920** You need to fill in ALL fields EXCEPT NextP, which is used to link the
921** blocks together either on the free list or on the Rup list.
922**
923** Packet is an actual packet structure to be filled in with the packet
924** information associated with the command. You need to fill in everything,
Matt LaPlante0779bf22006-11-30 05:24:39 +0100925** as the command processor doesn't process the command packet in any way.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926**
927** The PreFuncP is called before the packet is enqueued on the host rup.
928** PreFuncP is called as (*PreFuncP)(PreArg, CmdBlkP);. PreFuncP must
929** return !RIO_FAIL to have the packet queued on the rup, and RIO_FAIL
930** if the packet is NOT to be queued.
931**
932** The PostFuncP is called when the command has completed. It is called
933** as (*PostFuncP)(PostArg, CmdBlkP, txcontrol);. PostFuncP is not expected
934** to return a value. PostFuncP does NOT need to free the command block,
935** as this happens automatically after PostFuncP returns.
936**
937** Once the command block has been filled in, it is attached to the correct
938** queue by calling RIOQueueCmdBlk( HostP, Rup, CmdBlkP ) where HostP is
939** a pointer to the struct Host, Rup is the NUMBER of the rup (NOT a pointer
940** to it!), and CmdBlkP is the pointer to the command block allocated using
941** RIOGetCmdBlk().
942**
943*/