blob: 01f2654d5a2ee514eebea3a32bce224a08c3b120 [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*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34#include <linux/module.h>
35#include <linux/slab.h>
36#include <linux/errno.h>
37#include <linux/tty.h>
38#include <asm/io.h>
39#include <asm/system.h>
40#include <asm/string.h>
Alan Cox00d83a52006-03-24 03:18:28 -080041#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include <linux/termios.h>
44#include <linux/serial.h>
45
46#include <linux/generic_serial.h>
47
48#include "linux_compat.h"
49#include "rio_linux.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include "pkt.h"
51#include "daemon.h"
52#include "rio.h"
53#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "cmdpkt.h"
55#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include "rup.h"
57#include "port.h"
58#include "riodrvr.h"
59#include "rioinfo.h"
60#include "func.h"
61#include "errors.h"
62#include "pci.h"
63
64#include "parmmap.h"
65#include "unixrup.h"
66#include "board.h"
67#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#include "phb.h"
69#include "link.h"
70#include "cmdblk.h"
71#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include "cirrus.h"
73
74
75static struct IdentifyRta IdRta;
76static struct KillNeighbour KillUnit;
77
Andrew Morton8d8706e2006-01-11 12:17:49 -080078int RIOFoadRta(struct Host *HostP, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 struct CmdBlk *CmdBlkP;
81
Andrew Morton8d8706e2006-01-11 12:17:49 -080082 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 CmdBlkP = RIOGetCmdBlk();
85
Andrew Morton8d8706e2006-01-11 12:17:49 -080086 if (!CmdBlkP) {
87 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 return -ENXIO;
89 }
90
91 CmdBlkP->Packet.dest_unit = MapP->ID;
92 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -080093 CmdBlkP->Packet.src_unit = 0;
94 CmdBlkP->Packet.src_port = BOOT_RUP;
95 CmdBlkP->Packet.len = 0x84;
96 CmdBlkP->Packet.data[0] = IFOAD;
97 CmdBlkP->Packet.data[1] = 0;
98 CmdBlkP->Packet.data[2] = IFOAD_MAGIC & 0xFF;
99 CmdBlkP->Packet.data[3] = (IFOAD_MAGIC >> 8) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Andrew Morton8d8706e2006-01-11 12:17:49 -0800101 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
102 rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: Failed to queue foad command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return -EIO;
104 }
105 return 0;
106}
107
Andrew Morton8d8706e2006-01-11 12:17:49 -0800108int RIOZombieRta(struct Host *HostP, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
110 struct CmdBlk *CmdBlkP;
111
Andrew Morton8d8706e2006-01-11 12:17:49 -0800112 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 CmdBlkP = RIOGetCmdBlk();
115
Andrew Morton8d8706e2006-01-11 12:17:49 -0800116 if (!CmdBlkP) {
117 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return -ENXIO;
119 }
120
121 CmdBlkP->Packet.dest_unit = MapP->ID;
122 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800123 CmdBlkP->Packet.src_unit = 0;
124 CmdBlkP->Packet.src_port = BOOT_RUP;
125 CmdBlkP->Packet.len = 0x84;
126 CmdBlkP->Packet.data[0] = ZOMBIE;
127 CmdBlkP->Packet.data[1] = 0;
128 CmdBlkP->Packet.data[2] = ZOMBIE_MAGIC & 0xFF;
129 CmdBlkP->Packet.data[3] = (ZOMBIE_MAGIC >> 8) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Andrew Morton8d8706e2006-01-11 12:17:49 -0800131 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
132 rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: Failed to queue zombie command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 return -EIO;
134 }
135 return 0;
136}
137
Alan Cox00d83a52006-03-24 03:18:28 -0800138int RIOCommandRta(struct rio_info *p, unsigned long RtaUnique, int (*func) (struct Host * HostP, struct Map * MapP))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Alan Cox00d83a52006-03-24 03:18:28 -0800140 unsigned int Host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Alan Cox554b7c82006-03-24 03:18:32 -0800142 rio_dprintk(RIO_DEBUG_CMD, "Command RTA 0x%lx func %p\n", RtaUnique, func);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Andrew Morton8d8706e2006-01-11 12:17:49 -0800144 if (!RtaUnique)
145 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Andrew Morton8d8706e2006-01-11 12:17:49 -0800147 for (Host = 0; Host < p->RIONumHosts; Host++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800148 unsigned int Rta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 struct Host *HostP = &p->RIOHosts[Host];
150
Andrew Morton8d8706e2006-01-11 12:17:49 -0800151 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 struct Map *MapP = &HostP->Mapping[Rta];
153
Andrew Morton8d8706e2006-01-11 12:17:49 -0800154 if (MapP->RtaUniqueNum == RtaUnique) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 uint Link;
156
157 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800158 ** now, lets just check we have a route to it...
159 ** IF the routing stuff is working, then one of the
160 ** topology entries for this unit will have a legit
161 ** route *somewhere*. We care not where - if its got
162 ** any connections, we can get to it.
163 */
164 for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800165 if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800167 ** Its worth trying the operation...
168 */
169 return (*func) (HostP, MapP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
171 }
172 }
173 }
174 }
175 return -ENXIO;
176}
177
178
Al Virod886cb52006-05-27 00:08:25 -0400179int RIOIdentifyRta(struct rio_info *p, void __user * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
Alan Cox00d83a52006-03-24 03:18:28 -0800181 unsigned int Host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Alan Cox00d83a52006-03-24 03:18:28 -0800183 if (copy_from_user(&IdRta, arg, sizeof(IdRta))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800184 rio_dprintk(RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 p->RIOError.Error = COPYIN_FAILED;
186 return -EFAULT;
187 }
188
Andrew Morton8d8706e2006-01-11 12:17:49 -0800189 for (Host = 0; Host < p->RIONumHosts; Host++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800190 unsigned int Rta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 struct Host *HostP = &p->RIOHosts[Host];
192
Andrew Morton8d8706e2006-01-11 12:17:49 -0800193 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 struct Map *MapP = &HostP->Mapping[Rta];
195
Andrew Morton8d8706e2006-01-11 12:17:49 -0800196 if (MapP->RtaUniqueNum == IdRta.RtaUnique) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 uint Link;
198 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800199 ** now, lets just check we have a route to it...
200 ** IF the routing stuff is working, then one of the
201 ** topology entries for this unit will have a legit
202 ** route *somewhere*. We care not where - if its got
203 ** any connections, we can get to it.
204 */
205 for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800206 if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800208 ** Its worth trying the operation...
209 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 struct CmdBlk *CmdBlkP;
211
Andrew Morton8d8706e2006-01-11 12:17:49 -0800212 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 CmdBlkP = RIOGetCmdBlk();
215
Andrew Morton8d8706e2006-01-11 12:17:49 -0800216 if (!CmdBlkP) {
217 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 return -ENXIO;
219 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 CmdBlkP->Packet.dest_unit = MapP->ID;
222 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800223 CmdBlkP->Packet.src_unit = 0;
224 CmdBlkP->Packet.src_port = BOOT_RUP;
225 CmdBlkP->Packet.len = 0x84;
226 CmdBlkP->Packet.data[0] = IDENTIFY;
227 CmdBlkP->Packet.data[1] = 0;
228 CmdBlkP->Packet.data[2] = IdRta.ID;
229
230 if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
231 rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: Failed to queue command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return -EIO;
233 }
234 return 0;
235 }
236 }
237 }
238 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 return -ENOENT;
241}
242
243
Al Virod886cb52006-05-27 00:08:25 -0400244int RIOKillNeighbour(struct rio_info *p, void __user * arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 uint Host;
247 uint ID;
248 struct Host *HostP;
249 struct CmdBlk *CmdBlkP;
250
Andrew Morton8d8706e2006-01-11 12:17:49 -0800251 rio_dprintk(RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Alan Cox00d83a52006-03-24 03:18:28 -0800253 if (copy_from_user(&KillUnit, arg, sizeof(KillUnit))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800254 rio_dprintk(RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 p->RIOError.Error = COPYIN_FAILED;
256 return -EFAULT;
257 }
258
Andrew Morton8d8706e2006-01-11 12:17:49 -0800259 if (KillUnit.Link > 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return -ENXIO;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 CmdBlkP = RIOGetCmdBlk();
263
Andrew Morton8d8706e2006-01-11 12:17:49 -0800264 if (!CmdBlkP) {
265 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 return -ENXIO;
267 }
268
269 CmdBlkP->Packet.dest_unit = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800270 CmdBlkP->Packet.src_unit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800272 CmdBlkP->Packet.src_port = BOOT_RUP;
273 CmdBlkP->Packet.len = 0x84;
274 CmdBlkP->Packet.data[0] = UFOAD;
275 CmdBlkP->Packet.data[1] = KillUnit.Link;
276 CmdBlkP->Packet.data[2] = UFOAD_MAGIC & 0xFF;
277 CmdBlkP->Packet.data[3] = (UFOAD_MAGIC >> 8) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Andrew Morton8d8706e2006-01-11 12:17:49 -0800279 for (Host = 0; Host < p->RIONumHosts; Host++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 ID = 0;
281 HostP = &p->RIOHosts[Host];
282
Andrew Morton8d8706e2006-01-11 12:17:49 -0800283 if (HostP->UniqueNum == KillUnit.UniqueNum) {
284 if (RIOQueueCmdBlk(HostP, RTAS_PER_HOST + KillUnit.Link, CmdBlkP) == RIO_FAIL) {
285 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 return -EIO;
287 }
288 return 0;
289 }
290
Andrew Morton8d8706e2006-01-11 12:17:49 -0800291 for (ID = 0; ID < RTAS_PER_HOST; ID++) {
292 if (HostP->Mapping[ID].RtaUniqueNum == KillUnit.UniqueNum) {
293 CmdBlkP->Packet.dest_unit = ID + 1;
294 if (RIOQueueCmdBlk(HostP, ID, CmdBlkP) == RIO_FAIL) {
295 rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 return -EIO;
297 }
298 return 0;
299 }
300 }
301 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800302 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 return -ENXIO;
304}
305
Andrew Morton8d8706e2006-01-11 12:17:49 -0800306int RIOSuspendBootRta(struct Host *HostP, int ID, int Link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
308 struct CmdBlk *CmdBlkP;
309
Andrew Morton8d8706e2006-01-11 12:17:49 -0800310 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA ID %d, link %c\n", ID, 'A' + Link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 CmdBlkP = RIOGetCmdBlk();
313
Andrew Morton8d8706e2006-01-11 12:17:49 -0800314 if (!CmdBlkP) {
315 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: GetCmdBlk failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return -ENXIO;
317 }
318
319 CmdBlkP->Packet.dest_unit = ID;
320 CmdBlkP->Packet.dest_port = BOOT_RUP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800321 CmdBlkP->Packet.src_unit = 0;
322 CmdBlkP->Packet.src_port = BOOT_RUP;
323 CmdBlkP->Packet.len = 0x84;
324 CmdBlkP->Packet.data[0] = IWAIT;
325 CmdBlkP->Packet.data[1] = Link;
326 CmdBlkP->Packet.data[2] = IWAIT_MAGIC & 0xFF;
327 CmdBlkP->Packet.data[3] = (IWAIT_MAGIC >> 8) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Andrew Morton8d8706e2006-01-11 12:17:49 -0800329 if (RIOQueueCmdBlk(HostP, ID - 1, CmdBlkP) == RIO_FAIL) {
330 rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: Failed to queue iwait command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 return -EIO;
332 }
333 return 0;
334}
335
Andrew Morton8d8706e2006-01-11 12:17:49 -0800336int RIOFoadWakeup(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 int port;
Alan Cox00d83a52006-03-24 03:18:28 -0800339 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 unsigned long flags;
341
Andrew Morton8d8706e2006-01-11 12:17:49 -0800342 for (port = 0; port < RIO_PORTS; port++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 PortP = p->RIOPortp[port];
344
345 rio_spin_lock_irqsave(&PortP->portSem, flags);
346 PortP->Config = 0;
347 PortP->State = 0;
348 PortP->InUse = NOT_INUSE;
349 PortP->PortState = 0;
350 PortP->FlushCmdBodge = 0;
351 PortP->ModemLines = 0;
352 PortP->ModemState = 0;
353 PortP->CookMode = 0;
354 PortP->ParamSem = 0;
355 PortP->Mapped = 0;
356 PortP->WflushFlag = 0;
357 PortP->MagicFlags = 0;
358 PortP->RxDataStart = 0;
359 PortP->TxBufferIn = 0;
360 PortP->TxBufferOut = 0;
361 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
362 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800363 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
366/*
367** Incoming command on the COMMAND_RUP to be processed.
368*/
Al Virod886cb52006-05-27 00:08:25 -0400369static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, struct PKT __iomem *PacketP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Al Virod886cb52006-05-27 00:08:25 -0400371 struct PktCmd __iomem *PktCmdP = (struct PktCmd __iomem *)PacketP->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 struct Port *PortP;
373 struct UnixRup *UnixRupP;
Alan Cox00d83a52006-03-24 03:18:28 -0800374 unsigned short SysPort;
375 unsigned short ReportedModemStatus;
376 unsigned short rup;
377 unsigned short subCommand;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 unsigned long flags;
379
Andrew Morton8d8706e2006-01-11 12:17:49 -0800380 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800383 ** 16 port RTA note:
384 ** Command rup packets coming from the RTA will have pkt->data[1] (which
385 ** translates to PktCmdP->PhbNum) set to the host port number for the
386 ** particular unit. To access the correct BaseSysPort for a 16 port RTA,
387 ** we can use PhbNum to get the rup number for the appropriate 8 port
388 ** block (for the first block, this should be equal to 'Rup').
389 */
Alan Cox00d83a52006-03-24 03:18:28 -0800390 rup = readb(&PktCmdP->PhbNum) / (unsigned short) PORTS_PER_RTA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 UnixRupP = &HostP->UnixRups[rup];
Alan Cox00d83a52006-03-24 03:18:28 -0800392 SysPort = UnixRupP->BaseSysPort + (readb(&PktCmdP->PhbNum) % (unsigned short) PORTS_PER_RTA);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800393 rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Andrew Morton8d8706e2006-01-11 12:17:49 -0800395 if (UnixRupP->BaseSysPort == NO_PORT) {
396 rio_dprintk(RIO_DEBUG_CMD, "OBSCURE ERROR!\n");
397 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 -0800398 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 -0800399 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Eric Sesterhenn / Snakebyte84ea7762007-05-10 22:22:48 -0700401 if (Rup < (unsigned short) MAX_RUP) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800402 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 -0700403 } else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800404 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 -0700405
Al Viro92af11c2006-05-27 02:24:14 -0400406 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Destination 0x%x:0x%x\n", readb(&PacketP->dest_unit), readb(&PacketP->dest_port));
407 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Source 0x%x:0x%x\n", readb(&PacketP->src_unit), readb(&PacketP->src_port));
408 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Length 0x%x (%d)\n", readb(&PacketP->len), readb(&PacketP->len));
409 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Control 0x%x (%d)\n", readb(&PacketP->control), readb(&PacketP->control));
410 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Check 0x%x (%d)\n", readw(&PacketP->csum), readw(&PacketP->csum));
411 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 -0800412 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800414 PortP = p->RIOPortp[SysPort];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 rio_spin_lock_irqsave(&PortP->portSem, flags);
Alan Cox00d83a52006-03-24 03:18:28 -0800416 switch (readb(&PktCmdP->Command)) {
Jiri Slabyd6f63412008-04-30 00:53:57 -0700417 case RIOC_BREAK_RECEIVED:
Andrew Morton8d8706e2006-01-11 12:17:49 -0800418 rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n");
419 /* If the current line disc. is not multi-threading and
420 the current processor is not the default, reset rup_intr
Alan Cox554b7c82006-03-24 03:18:32 -0800421 and return 0 to ensure that the command packet is
Andrew Morton8d8706e2006-01-11 12:17:49 -0800422 not freed. */
423 /* Call tmgr HANGUP HERE */
424 /* Fix this later when every thing works !!!! RAMRAJ */
425 gs_got_break(&PortP->gs);
426 break;
427
Jiri Slabyd6f63412008-04-30 00:53:57 -0700428 case RIOC_COMPLETE:
Alan Cox00d83a52006-03-24 03:18:28 -0800429 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 -0800430 subCommand = 1;
Alan Cox00d83a52006-03-24 03:18:28 -0800431 switch (readb(&PktCmdP->SubCommand)) {
Jiri Slabyd6f63412008-04-30 00:53:57 -0700432 case RIOC_MEMDUMP:
Alan Cox00d83a52006-03-24 03:18:28 -0800433 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 -0700434 break;
Jiri Slabyd6f63412008-04-30 00:53:57 -0700435 case RIOC_READ_REGISTER:
Alan Cox00d83a52006-03-24 03:18:28 -0800436 rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", readw(&PktCmdP->SubAddr));
Jiri Slabyd6f63412008-04-30 00:53:57 -0700437 p->CdRegister = (readb(&PktCmdP->ModemStatus) & RIOC_MSVR1_HOST);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800438 break;
439 default:
440 subCommand = 0;
441 break;
442 }
443 if (subCommand)
444 break;
Alan Cox00d83a52006-03-24 03:18:28 -0800445 rio_dprintk(RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n", readb(&PktCmdP->PortStatus), PortP->PortState);
446 if (PortP->PortState != readb(&PktCmdP->PortStatus)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800447 rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800448 PortP->PortState = readb(&PktCmdP->PortStatus);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800449 /* What should we do here ...
450 wakeup( &PortP->PortState );
451 */
452 } else
453 rio_dprintk(RIO_DEBUG_CMD, "No change\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Andrew Morton8d8706e2006-01-11 12:17:49 -0800455 /* FALLTHROUGH */
Jiri Slabyd6f63412008-04-30 00:53:57 -0700456 case RIOC_MODEM_STATUS:
Andrew Morton8d8706e2006-01-11 12:17:49 -0800457 /*
458 ** Knock out the tbusy and tstop bits, as these are not relevant
459 ** to the check for modem status change (they're just there because
460 ** it's a convenient place to put them!).
461 */
Alan Cox00d83a52006-03-24 03:18:28 -0800462 ReportedModemStatus = readb(&PktCmdP->ModemStatus);
Jiri Slabyd6f63412008-04-30 00:53:57 -0700463 if ((PortP->ModemState & RIOC_MSVR1_HOST) ==
464 (ReportedModemStatus & RIOC_MSVR1_HOST)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800465 rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800467 ** Update ModemState just in case tbusy or tstop states have
468 ** changed.
469 */
470 PortP->ModemState = ReportedModemStatus;
471 } else {
472 rio_dprintk(RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n", PortP->ModemState, ReportedModemStatus);
473 PortP->ModemState = ReportedModemStatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#ifdef MODEM_SUPPORT
Andrew Morton8d8706e2006-01-11 12:17:49 -0800475 if (PortP->Mapped) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 /***********************************************************\
477 *************************************************************
478 *** ***
479 *** M O D E M S T A T E C H A N G E ***
480 *** ***
481 *************************************************************
482 \***********************************************************/
483 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800484 ** If the device is a modem, then check the modem
485 ** carrier.
486 */
Alan Coxb5391e22008-07-16 21:55:20 +0100487 if (PortP->gs.port.tty == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 break;
Alan Coxb5391e22008-07-16 21:55:20 +0100489 if (PortP->gs.port.tty->termios == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Alan Coxb5391e22008-07-16 21:55:20 +0100492 if (!(PortP->gs.port.tty->termios->c_cflag & CLOCAL) && ((PortP->State & (RIO_MOPEN | RIO_WOPEN)))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800493
494 rio_dprintk(RIO_DEBUG_CMD, "Is there a Carrier?\n");
495 /*
496 ** Is there a carrier?
497 */
Jiri Slabyd6f63412008-04-30 00:53:57 -0700498 if (PortP->ModemState & RIOC_MSVR1_CD) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800499 /*
500 ** Has carrier just appeared?
501 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (!(PortP->State & RIO_CARR_ON)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800503 rio_dprintk(RIO_DEBUG_CMD, "Carrier just came up.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 PortP->State |= RIO_CARR_ON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800505 /*
506 ** wakeup anyone in WOPEN
507 */
508 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN))
Alan Coxb5391e22008-07-16 21:55:20 +0100509 wake_up_interruptible(&PortP->gs.port.open_wait);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800512 /*
513 ** Has carrier just dropped?
514 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (PortP->State & RIO_CARR_ON) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800516 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN | RIO_MOPEN))
Alan Coxb5391e22008-07-16 21:55:20 +0100517 tty_hangup(PortP->gs.port.tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 PortP->State &= ~RIO_CARR_ON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800519 rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800520 }
521 }
522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800525 }
526 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Andrew Morton8d8706e2006-01-11 12:17:49 -0800528 default:
Alan Cox00d83a52006-03-24 03:18:28 -0800529 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 -0800530 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 }
532 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
533
Andrew Morton8d8706e2006-01-11 12:17:49 -0800534 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Alan Cox554b7c82006-03-24 03:18:32 -0800536 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
Andrew Morton8d8706e2006-01-11 12:17:49 -0800538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539/*
540** The command mechanism:
541** Each rup has a chain of commands associated with it.
542** This chain is maintained by routines in this file.
543** Periodically we are called and we run a quick check of all the
544** active chains to determine if there is a command to be executed,
545** and if the rup is ready to accept it.
546**
547*/
548
549/*
550** Allocate an empty command block.
551*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800552struct CmdBlk *RIOGetCmdBlk(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
554 struct CmdBlk *CmdBlkP;
555
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700556 CmdBlkP = kzalloc(sizeof(struct CmdBlk), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 return CmdBlkP;
558}
559
560/*
561** Return a block to the head of the free list.
562*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800563void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Alan Cox00d83a52006-03-24 03:18:28 -0800565 kfree(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
567
568/*
569** attach a command block to the list of commands to be performed for
570** a given rup.
571*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800572int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
574 struct CmdBlk **Base;
575 struct UnixRup *UnixRupP;
576 unsigned long flags;
577
Alan Cox00d83a52006-03-24 03:18:28 -0800578 if (Rup >= (unsigned short) (MAX_RUP + LINKS_PER_UNIT)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800579 rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup);
580 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 return RIO_FAIL;
582 }
583
584 UnixRupP = &HostP->UnixRups[Rup];
585
586 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
587
588 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800589 ** If the RUP is currently inactive, then put the request
590 ** straight on the RUP....
591 */
Alan Cox00d83a52006-03-24 03:18:28 -0800592 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 -0800593 : 1)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800594 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 -0700595
596 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800597 ** Whammy! blat that pack!
598 */
Al Viro92af11c2006-05-27 02:24:14 -0400599 HostP->Copy(&CmdBlkP->Packet, RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->txpkt)), sizeof(struct PKT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800602 ** place command packet on the pending position.
603 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 UnixRupP->CmdPendingP = CmdBlkP;
605
606 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800607 ** set the command register
608 */
Alan Cox00d83a52006-03-24 03:18:28 -0800609 writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
612
Alan Cox554b7c82006-03-24 03:18:32 -0800613 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800615 rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Andrew Morton8d8706e2006-01-11 12:17:49 -0800617 if (UnixRupP->CmdsWaitingP != NULL)
618 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command waiting\n");
619 if (UnixRupP->CmdPendingP != NULL)
620 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command pending\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800621 if (readw(&UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800622 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 Base = &UnixRupP->CmdsWaitingP;
625
Alan Cox554b7c82006-03-24 03:18:32 -0800626 rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk %p at %p\n", CmdBlkP, Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Andrew Morton8d8706e2006-01-11 12:17:49 -0800628 while (*Base) {
Alan Cox554b7c82006-03-24 03:18:32 -0800629 rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk %p here\n", *Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 Base = &((*Base)->NextP);
Alan Cox554b7c82006-03-24 03:18:32 -0800631 rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk %p at %p\n", CmdBlkP, Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 }
633
Alan Cox554b7c82006-03-24 03:18:32 -0800634 rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk %p at %p\n", CmdBlkP, Base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636 *Base = CmdBlkP;
637
638 CmdBlkP->NextP = NULL;
639
640 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
641
Alan Cox554b7c82006-03-24 03:18:32 -0800642 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
644
645/*
646** Here we go - if there is an empty rup, fill it!
647** must be called at splrio() or higher.
648*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800649void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650{
Alan Cox00d83a52006-03-24 03:18:28 -0800651 struct CmdBlk *CmdBlkP;
652 struct UnixRup *UnixRupP;
Al Virod886cb52006-05-27 00:08:25 -0400653 struct PKT __iomem *PacketP;
Alan Cox00d83a52006-03-24 03:18:28 -0800654 unsigned short Rup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 unsigned long flags;
656
657
Andrew Morton8d8706e2006-01-11 12:17:49 -0800658 Rup = MAX_RUP + LINKS_PER_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Andrew Morton8d8706e2006-01-11 12:17:49 -0800660 do { /* do this loop for each RUP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800662 ** locate the rup we are processing & lock it
663 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 UnixRupP = &HostP->UnixRups[--Rup];
665
666 spin_lock_irqsave(&UnixRupP->RupLock, flags);
667
668 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800669 ** First check for incoming commands:
670 */
Alan Cox00d83a52006-03-24 03:18:28 -0800671 if (readw(&UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 int FreeMe;
673
Al Virod886cb52006-05-27 00:08:25 -0400674 PacketP = (struct PKT __iomem *) RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->rxpkt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Alan Cox00d83a52006-03-24 03:18:28 -0800676 switch (readb(&PacketP->dest_port)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800677 case BOOT_RUP:
Alan Cox00d83a52006-03-24 03:18:28 -0800678 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 -0800679 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
680 FreeMe = RIOBootRup(p, Rup, HostP, PacketP);
681 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
682 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Andrew Morton8d8706e2006-01-11 12:17:49 -0800684 case COMMAND_RUP:
685 /*
686 ** Free the RUP lock as loss of carrier causes a
687 ** ttyflush which will (eventually) call another
688 ** routine that uses the RUP lock.
689 */
690 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
691 FreeMe = RIOCommandRup(p, Rup, HostP, PacketP);
Jiri Slabyd6f63412008-04-30 00:53:57 -0700692 if (readb(&PacketP->data[5]) == RIOC_MEMDUMP) {
Al Viro92af11c2006-05-27 02:24:14 -0400693 rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", readw(&(PacketP->data[6])));
Al Viro1bf08712006-05-27 01:55:52 -0400694 rio_memcpy_fromio(p->RIOMemDump, &(PacketP->data[8]), 32);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800695 }
696 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
697 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Andrew Morton8d8706e2006-01-11 12:17:49 -0800699 case ROUTE_RUP:
700 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
701 FreeMe = RIORouteRup(p, Rup, HostP, PacketP);
702 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
703 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Andrew Morton8d8706e2006-01-11 12:17:49 -0800705 default:
Alan Cox00d83a52006-03-24 03:18:28 -0800706 rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", readb(&PacketP->dest_port));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800707 FreeMe = 1;
708 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 }
710
Andrew Morton8d8706e2006-01-11 12:17:49 -0800711 if (FreeMe) {
712 rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n");
713 put_free_end(HostP, PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Alan Cox00d83a52006-03-24 03:18:28 -0800715 writew(RX_RUP_INACTIVE, &UnixRupP->RupP->rxcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Alan Cox00d83a52006-03-24 03:18:28 -0800717 if (readw(&UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800718 rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup);
Alan Cox00d83a52006-03-24 03:18:28 -0800719 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &UnixRupP->RupP->handshake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721 }
722 }
723
724 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800725 ** IF a command was running on the port,
726 ** and it has completed, then tidy it up.
727 */
728 if ((CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */
Alan Cox00d83a52006-03-24 03:18:28 -0800729 (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800731 ** we are idle.
732 ** there is a command in pending.
733 ** Therefore, this command has finished.
734 ** So, wakeup whoever is waiting for it (and tell them
735 ** what happened).
736 */
737 if (CmdBlkP->Packet.dest_port == BOOT_RUP)
738 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 -0700739
Alan Cox554b7c82006-03-24 03:18:32 -0800740 rio_dprintk(RIO_DEBUG_CMD, "Command %p completed\n", CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800743 ** Clear the Rup lock to prevent mutual exclusion.
744 */
745 if (CmdBlkP->PostFuncP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800747 (*CmdBlkP->PostFuncP) (CmdBlkP->PostArg, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
749 }
750
751 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800752 ** ....clear the pending flag....
753 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 UnixRupP->CmdPendingP = NULL;
755
756 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800757 ** ....and return the command block to the freelist.
758 */
759 RIOFreeCmdBlk(CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
761
762 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800763 ** If there is a command for this rup, and the rup
764 ** is idle, then process the command
765 */
766 if ((CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */
Alan Cox00d83a52006-03-24 03:18:28 -0800767 (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800769 ** if the pre-function is non-zero, call it.
770 ** If it returns RIO_FAIL then don't
771 ** send this command yet!
772 */
Alan Cox554b7c82006-03-24 03:18:32 -0800773 if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : 1)) {
774 rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command %p\n", CmdBlkP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800775 } else {
Alan Cox554b7c82006-03-24 03:18:32 -0800776 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 -0700777 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800778 ** Whammy! blat that pack!
779 */
Al Viro92af11c2006-05-27 02:24:14 -0400780 HostP->Copy(&CmdBlkP->Packet, RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->txpkt)), sizeof(struct PKT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
782 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800783 ** remove the command from the rup command queue...
784 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 UnixRupP->CmdsWaitingP = CmdBlkP->NextP;
786
787 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800788 ** ...and place it on the pending position.
789 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 UnixRupP->CmdPendingP = CmdBlkP;
791
792 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800793 ** set the command register
794 */
Alan Cox00d83a52006-03-24 03:18:28 -0800795 writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800798 ** the command block will be freed
799 ** when the command has been processed.
800 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 }
802 }
803 spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800804 } while (Rup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805}
806
Alan Cox00d83a52006-03-24 03:18:28 -0800807int RIOWFlushMark(unsigned long iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800809 struct Port *PortP = (struct Port *) iPortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 unsigned long flags;
811
812 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 PortP->WflushFlag++;
814 PortP->MagicFlags |= MAGIC_FLUSH;
815 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800816 return RIOUnUse(iPortP, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817}
818
Alan Cox00d83a52006-03-24 03:18:28 -0800819int RIORFlushEnable(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;
Al Virod886cb52006-05-27 00:08:25 -0400822 struct PKT __iomem *PacketP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 unsigned long flags;
824
825 rio_spin_lock_irqsave(&PortP->portSem, flags);
826
Andrew Morton8d8706e2006-01-11 12:17:49 -0800827 while (can_remove_receive(&PacketP, PortP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 remove_receive(PortP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800829 put_free_end(PortP->HostP, PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 }
831
Alan Cox00d83a52006-03-24 03:18:28 -0800832 if (readw(&PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800834 ** MAGIC! (Basically, handshake the RX buffer, so that
835 ** the RTAs upstream can be re-enabled.)
836 */
837 rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800838 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &PortP->PhbP->handshake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 }
840 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800841 return RIOUnUse(iPortP, CmdBlkP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842}
843
Alan Cox00d83a52006-03-24 03:18:28 -0800844int RIOUnUse(unsigned long iPortP, struct CmdBlk *CmdBlkP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800846 struct Port *PortP = (struct Port *) iPortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 unsigned long flags;
848
849 rio_spin_lock_irqsave(&PortP->portSem, flags);
850
Andrew Morton8d8706e2006-01-11 12:17:49 -0800851 rio_dprintk(RIO_DEBUG_CMD, "Decrement in use count for port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 if (PortP->InUse) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800854 if (--PortP->InUse != NOT_INUSE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
856 return 0;
857 }
858 }
859 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800860 ** While PortP->InUse is set (i.e. a preemptive command has been sent to
861 ** the RTA and is awaiting completion), any transmit data is prevented from
862 ** being transferred from the write queue into the transmit packets
863 ** (add_transmit) and no furthur transmit interrupt will be sent for that
864 ** data. The next interrupt will occur up to 500ms later (RIOIntr is called
865 ** twice a second as a saftey measure). This was the case when kermit was
866 ** used to send data into a RIO port. After each packet was sent, TCFLSH
867 ** was called to flush the read queue preemptively. PortP->InUse was
868 ** incremented, thereby blocking the 6 byte acknowledgement packet
869 ** transmitted back. This acknowledgment hung around for 500ms before
870 ** being sent, thus reducing input performance substantially!.
871 ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data
872 ** hanging around in the transmit buffer is sent immediately.
873 */
Alan Cox00d83a52006-03-24 03:18:28 -0800874 writew(1, &PortP->HostP->ParmMapP->tx_intr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 /* What to do here ..
Andrew Morton8d8706e2006-01-11 12:17:49 -0800876 wakeup( (caddr_t)&(PortP->InUse) );
877 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
879 return 0;
880}
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882/*
883**
884** How to use this file:
885**
886** To send a command down a rup, you need to allocate a command block, fill
887** in the packet information, fill in the command number, fill in the pre-
888** and post- functions and arguments, and then add the command block to the
889** queue of command blocks for the port in question. When the port is idle,
890** then the pre-function will be called. If this returns RIO_FAIL then the
891** command will be re-queued and tried again at a later date (probably in one
892** clock tick). If the pre-function returns NOT RIO_FAIL, then the command
893** packet will be queued on the RUP, and the txcontrol field set to the
894** command number. When the txcontrol field has changed from being the
895** command number, then the post-function will be called, with the argument
896** specified earlier, a pointer to the command block, and the value of
897** txcontrol.
898**
899** To allocate a command block, call RIOGetCmdBlk(). This returns a pointer
900** to the command block structure allocated, or NULL if there aren't any.
901** The block will have been zeroed for you.
902**
903** The structure has the following fields:
904**
905** struct CmdBlk
906** {
907** struct CmdBlk *NextP; ** Pointer to next command block **
908** struct PKT Packet; ** A packet, to copy to the rup **
909** int (*PreFuncP)(); ** The func to call to check if OK **
910** int PreArg; ** The arg for the func **
911** int (*PostFuncP)(); ** The func to call when completed **
912** int PostArg; ** The arg for the func **
913** };
914**
915** You need to fill in ALL fields EXCEPT NextP, which is used to link the
916** blocks together either on the free list or on the Rup list.
917**
918** Packet is an actual packet structure to be filled in with the packet
919** information associated with the command. You need to fill in everything,
Matt LaPlante0779bf22006-11-30 05:24:39 +0100920** as the command processor doesn't process the command packet in any way.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921**
922** The PreFuncP is called before the packet is enqueued on the host rup.
923** PreFuncP is called as (*PreFuncP)(PreArg, CmdBlkP);. PreFuncP must
924** return !RIO_FAIL to have the packet queued on the rup, and RIO_FAIL
925** if the packet is NOT to be queued.
926**
927** The PostFuncP is called when the command has completed. It is called
928** as (*PostFuncP)(PostArg, CmdBlkP, txcontrol);. PostFuncP is not expected
929** to return a value. PostFuncP does NOT need to free the command block,
930** as this happens automatically after PostFuncP returns.
931**
932** Once the command block has been filled in, it is attached to the correct
933** queue by calling RIOQueueCmdBlk( HostP, Rup, CmdBlkP ) where HostP is
934** a pointer to the struct Host, Rup is the NUMBER of the rup (NOT a pointer
935** to it!), and CmdBlkP is the pointer to the command block allocated using
936** RIOGetCmdBlk().
937**
938*/