Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | |
34 | static 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> | |
00d83a54 | 45 | #include <asm/uaccess.h> |
1da177e4 LT |
46 | |
47 | #include <linux/termios.h> | |
48 | #include <linux/serial.h> | |
49 | ||
50 | #include <linux/generic_serial.h> | |
51 | ||
52 | #include "linux_compat.h" | |
53 | #include "rio_linux.h" | |
54 | #include "typdef.h" | |
55 | #include "pkt.h" | |
56 | #include "daemon.h" | |
57 | #include "rio.h" | |
58 | #include "riospace.h" | |
59 | #include "top.h" | |
60 | #include "cmdpkt.h" | |
61 | #include "map.h" | |
62 | #include "riotypes.h" | |
63 | #include "rup.h" | |
64 | #include "port.h" | |
65 | #include "riodrvr.h" | |
66 | #include "rioinfo.h" | |
67 | #include "func.h" | |
68 | #include "errors.h" | |
69 | #include "pci.h" | |
70 | ||
71 | #include "parmmap.h" | |
72 | #include "unixrup.h" | |
73 | #include "board.h" | |
74 | #include "host.h" | |
75 | #include "error.h" | |
76 | #include "phb.h" | |
77 | #include "link.h" | |
78 | #include "cmdblk.h" | |
79 | #include "route.h" | |
80 | #include "control.h" | |
81 | #include "cirrus.h" | |
82 | ||
83 | ||
84 | static struct IdentifyRta IdRta; | |
85 | static struct KillNeighbour KillUnit; | |
86 | ||
8d8706e2 | 87 | int RIOFoadRta(struct Host *HostP, struct Map *MapP) |
1da177e4 LT |
88 | { |
89 | struct CmdBlk *CmdBlkP; | |
90 | ||
8d8706e2 | 91 | rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA\n"); |
1da177e4 LT |
92 | |
93 | CmdBlkP = RIOGetCmdBlk(); | |
94 | ||
8d8706e2 AM |
95 | if (!CmdBlkP) { |
96 | rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: GetCmdBlk failed\n"); | |
1da177e4 LT |
97 | return -ENXIO; |
98 | } | |
99 | ||
100 | CmdBlkP->Packet.dest_unit = MapP->ID; | |
101 | CmdBlkP->Packet.dest_port = BOOT_RUP; | |
8d8706e2 AM |
102 | CmdBlkP->Packet.src_unit = 0; |
103 | CmdBlkP->Packet.src_port = BOOT_RUP; | |
104 | CmdBlkP->Packet.len = 0x84; | |
105 | CmdBlkP->Packet.data[0] = IFOAD; | |
106 | CmdBlkP->Packet.data[1] = 0; | |
107 | CmdBlkP->Packet.data[2] = IFOAD_MAGIC & 0xFF; | |
108 | CmdBlkP->Packet.data[3] = (IFOAD_MAGIC >> 8) & 0xFF; | |
109 | ||
110 | if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) { | |
111 | rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: Failed to queue foad command\n"); | |
1da177e4 LT |
112 | return -EIO; |
113 | } | |
114 | return 0; | |
115 | } | |
116 | ||
8d8706e2 | 117 | int RIOZombieRta(struct Host *HostP, struct Map *MapP) |
1da177e4 LT |
118 | { |
119 | struct CmdBlk *CmdBlkP; | |
120 | ||
8d8706e2 | 121 | rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA\n"); |
1da177e4 LT |
122 | |
123 | CmdBlkP = RIOGetCmdBlk(); | |
124 | ||
8d8706e2 AM |
125 | if (!CmdBlkP) { |
126 | rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: GetCmdBlk failed\n"); | |
1da177e4 LT |
127 | return -ENXIO; |
128 | } | |
129 | ||
130 | CmdBlkP->Packet.dest_unit = MapP->ID; | |
131 | CmdBlkP->Packet.dest_port = BOOT_RUP; | |
8d8706e2 AM |
132 | CmdBlkP->Packet.src_unit = 0; |
133 | CmdBlkP->Packet.src_port = BOOT_RUP; | |
134 | CmdBlkP->Packet.len = 0x84; | |
135 | CmdBlkP->Packet.data[0] = ZOMBIE; | |
136 | CmdBlkP->Packet.data[1] = 0; | |
137 | CmdBlkP->Packet.data[2] = ZOMBIE_MAGIC & 0xFF; | |
138 | CmdBlkP->Packet.data[3] = (ZOMBIE_MAGIC >> 8) & 0xFF; | |
139 | ||
140 | if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) { | |
141 | rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: Failed to queue zombie command\n"); | |
1da177e4 LT |
142 | return -EIO; |
143 | } | |
144 | return 0; | |
145 | } | |
146 | ||
00d83a54 | 147 | int RIOCommandRta(struct rio_info *p, unsigned long RtaUnique, int (*func) (struct Host * HostP, struct Map * MapP)) |
1da177e4 | 148 | { |
00d83a54 | 149 | unsigned int Host; |
1da177e4 | 150 | |
00d83a54 | 151 | rio_dprintk(RIO_DEBUG_CMD, "Command RTA 0x%lx func 0x%p\n", RtaUnique, func); |
1da177e4 | 152 | |
8d8706e2 AM |
153 | if (!RtaUnique) |
154 | return (0); | |
1da177e4 | 155 | |
8d8706e2 | 156 | for (Host = 0; Host < p->RIONumHosts; Host++) { |
00d83a54 | 157 | unsigned int Rta; |
1da177e4 LT |
158 | struct Host *HostP = &p->RIOHosts[Host]; |
159 | ||
8d8706e2 | 160 | for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) { |
1da177e4 LT |
161 | struct Map *MapP = &HostP->Mapping[Rta]; |
162 | ||
8d8706e2 | 163 | if (MapP->RtaUniqueNum == RtaUnique) { |
1da177e4 LT |
164 | uint Link; |
165 | ||
166 | /* | |
8d8706e2 AM |
167 | ** now, lets just check we have a route to it... |
168 | ** IF the routing stuff is working, then one of the | |
169 | ** topology entries for this unit will have a legit | |
170 | ** route *somewhere*. We care not where - if its got | |
171 | ** any connections, we can get to it. | |
172 | */ | |
173 | for (Link = 0; Link < LINKS_PER_UNIT; Link++) { | |
00d83a54 | 174 | if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) { |
1da177e4 | 175 | /* |
8d8706e2 AM |
176 | ** Its worth trying the operation... |
177 | */ | |
178 | return (*func) (HostP, MapP); | |
1da177e4 LT |
179 | } |
180 | } | |
181 | } | |
182 | } | |
183 | } | |
184 | return -ENXIO; | |
185 | } | |
186 | ||
187 | ||
00d83a54 | 188 | int RIOIdentifyRta(struct rio_info *p, void * arg) |
1da177e4 | 189 | { |
00d83a54 | 190 | unsigned int Host; |
1da177e4 | 191 | |
00d83a54 | 192 | if (copy_from_user(&IdRta, arg, sizeof(IdRta))) { |
8d8706e2 | 193 | rio_dprintk(RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n"); |
1da177e4 LT |
194 | p->RIOError.Error = COPYIN_FAILED; |
195 | return -EFAULT; | |
196 | } | |
197 | ||
8d8706e2 | 198 | for (Host = 0; Host < p->RIONumHosts; Host++) { |
00d83a54 | 199 | unsigned int Rta; |
1da177e4 LT |
200 | struct Host *HostP = &p->RIOHosts[Host]; |
201 | ||
8d8706e2 | 202 | for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) { |
1da177e4 LT |
203 | struct Map *MapP = &HostP->Mapping[Rta]; |
204 | ||
8d8706e2 | 205 | if (MapP->RtaUniqueNum == IdRta.RtaUnique) { |
1da177e4 LT |
206 | uint Link; |
207 | /* | |
8d8706e2 AM |
208 | ** now, lets just check we have a route to it... |
209 | ** IF the routing stuff is working, then one of the | |
210 | ** topology entries for this unit will have a legit | |
211 | ** route *somewhere*. We care not where - if its got | |
212 | ** any connections, we can get to it. | |
213 | */ | |
214 | for (Link = 0; Link < LINKS_PER_UNIT; Link++) { | |
00d83a54 | 215 | if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) { |
1da177e4 | 216 | /* |
8d8706e2 AM |
217 | ** Its worth trying the operation... |
218 | */ | |
1da177e4 LT |
219 | struct CmdBlk *CmdBlkP; |
220 | ||
8d8706e2 | 221 | rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA\n"); |
1da177e4 LT |
222 | |
223 | CmdBlkP = RIOGetCmdBlk(); | |
224 | ||
8d8706e2 AM |
225 | if (!CmdBlkP) { |
226 | rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: GetCmdBlk failed\n"); | |
1da177e4 LT |
227 | return -ENXIO; |
228 | } | |
8d8706e2 | 229 | |
1da177e4 LT |
230 | CmdBlkP->Packet.dest_unit = MapP->ID; |
231 | CmdBlkP->Packet.dest_port = BOOT_RUP; | |
8d8706e2 AM |
232 | CmdBlkP->Packet.src_unit = 0; |
233 | CmdBlkP->Packet.src_port = BOOT_RUP; | |
234 | CmdBlkP->Packet.len = 0x84; | |
235 | CmdBlkP->Packet.data[0] = IDENTIFY; | |
236 | CmdBlkP->Packet.data[1] = 0; | |
237 | CmdBlkP->Packet.data[2] = IdRta.ID; | |
238 | ||
239 | if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) { | |
240 | rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: Failed to queue command\n"); | |
1da177e4 LT |
241 | return -EIO; |
242 | } | |
243 | return 0; | |
244 | } | |
245 | } | |
246 | } | |
247 | } | |
8d8706e2 | 248 | } |
1da177e4 LT |
249 | return -ENOENT; |
250 | } | |
251 | ||
252 | ||
00d83a54 | 253 | int RIOKillNeighbour(struct rio_info *p, void * arg) |
1da177e4 LT |
254 | { |
255 | uint Host; | |
256 | uint ID; | |
257 | struct Host *HostP; | |
258 | struct CmdBlk *CmdBlkP; | |
259 | ||
8d8706e2 | 260 | rio_dprintk(RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n"); |
1da177e4 | 261 | |
00d83a54 | 262 | if (copy_from_user(&KillUnit, arg, sizeof(KillUnit))) { |
8d8706e2 | 263 | rio_dprintk(RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n"); |
1da177e4 LT |
264 | p->RIOError.Error = COPYIN_FAILED; |
265 | return -EFAULT; | |
266 | } | |
267 | ||
8d8706e2 | 268 | if (KillUnit.Link > 3) |
1da177e4 | 269 | return -ENXIO; |
8d8706e2 | 270 | |
1da177e4 LT |
271 | CmdBlkP = RIOGetCmdBlk(); |
272 | ||
8d8706e2 AM |
273 | if (!CmdBlkP) { |
274 | rio_dprintk(RIO_DEBUG_CMD, "UFOAD: GetCmdBlk failed\n"); | |
1da177e4 LT |
275 | return -ENXIO; |
276 | } | |
277 | ||
278 | CmdBlkP->Packet.dest_unit = 0; | |
8d8706e2 | 279 | CmdBlkP->Packet.src_unit = 0; |
1da177e4 | 280 | CmdBlkP->Packet.dest_port = BOOT_RUP; |
8d8706e2 AM |
281 | CmdBlkP->Packet.src_port = BOOT_RUP; |
282 | CmdBlkP->Packet.len = 0x84; | |
283 | CmdBlkP->Packet.data[0] = UFOAD; | |
284 | CmdBlkP->Packet.data[1] = KillUnit.Link; | |
285 | CmdBlkP->Packet.data[2] = UFOAD_MAGIC & 0xFF; | |
286 | CmdBlkP->Packet.data[3] = (UFOAD_MAGIC >> 8) & 0xFF; | |
287 | ||
288 | for (Host = 0; Host < p->RIONumHosts; Host++) { | |
1da177e4 LT |
289 | ID = 0; |
290 | HostP = &p->RIOHosts[Host]; | |
291 | ||
8d8706e2 AM |
292 | if (HostP->UniqueNum == KillUnit.UniqueNum) { |
293 | if (RIOQueueCmdBlk(HostP, RTAS_PER_HOST + KillUnit.Link, CmdBlkP) == RIO_FAIL) { | |
294 | rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n"); | |
1da177e4 LT |
295 | return -EIO; |
296 | } | |
297 | return 0; | |
298 | } | |
299 | ||
8d8706e2 AM |
300 | for (ID = 0; ID < RTAS_PER_HOST; ID++) { |
301 | if (HostP->Mapping[ID].RtaUniqueNum == KillUnit.UniqueNum) { | |
302 | CmdBlkP->Packet.dest_unit = ID + 1; | |
303 | if (RIOQueueCmdBlk(HostP, ID, CmdBlkP) == RIO_FAIL) { | |
304 | rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n"); | |
1da177e4 LT |
305 | return -EIO; |
306 | } | |
307 | return 0; | |
308 | } | |
309 | } | |
310 | } | |
8d8706e2 | 311 | RIOFreeCmdBlk(CmdBlkP); |
1da177e4 LT |
312 | return -ENXIO; |
313 | } | |
314 | ||
8d8706e2 | 315 | int RIOSuspendBootRta(struct Host *HostP, int ID, int Link) |
1da177e4 LT |
316 | { |
317 | struct CmdBlk *CmdBlkP; | |
318 | ||
8d8706e2 | 319 | rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA ID %d, link %c\n", ID, 'A' + Link); |
1da177e4 LT |
320 | |
321 | CmdBlkP = RIOGetCmdBlk(); | |
322 | ||
8d8706e2 AM |
323 | if (!CmdBlkP) { |
324 | rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: GetCmdBlk failed\n"); | |
1da177e4 LT |
325 | return -ENXIO; |
326 | } | |
327 | ||
328 | CmdBlkP->Packet.dest_unit = ID; | |
329 | CmdBlkP->Packet.dest_port = BOOT_RUP; | |
8d8706e2 AM |
330 | CmdBlkP->Packet.src_unit = 0; |
331 | CmdBlkP->Packet.src_port = BOOT_RUP; | |
332 | CmdBlkP->Packet.len = 0x84; | |
333 | CmdBlkP->Packet.data[0] = IWAIT; | |
334 | CmdBlkP->Packet.data[1] = Link; | |
335 | CmdBlkP->Packet.data[2] = IWAIT_MAGIC & 0xFF; | |
336 | CmdBlkP->Packet.data[3] = (IWAIT_MAGIC >> 8) & 0xFF; | |
337 | ||
338 | if (RIOQueueCmdBlk(HostP, ID - 1, CmdBlkP) == RIO_FAIL) { | |
339 | rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: Failed to queue iwait command\n"); | |
1da177e4 LT |
340 | return -EIO; |
341 | } | |
342 | return 0; | |
343 | } | |
344 | ||
8d8706e2 | 345 | int RIOFoadWakeup(struct rio_info *p) |
1da177e4 LT |
346 | { |
347 | int port; | |
00d83a54 | 348 | struct Port *PortP; |
1da177e4 LT |
349 | unsigned long flags; |
350 | ||
8d8706e2 | 351 | for (port = 0; port < RIO_PORTS; port++) { |
1da177e4 LT |
352 | PortP = p->RIOPortp[port]; |
353 | ||
354 | rio_spin_lock_irqsave(&PortP->portSem, flags); | |
355 | PortP->Config = 0; | |
356 | PortP->State = 0; | |
357 | PortP->InUse = NOT_INUSE; | |
358 | PortP->PortState = 0; | |
359 | PortP->FlushCmdBodge = 0; | |
360 | PortP->ModemLines = 0; | |
361 | PortP->ModemState = 0; | |
362 | PortP->CookMode = 0; | |
363 | PortP->ParamSem = 0; | |
364 | PortP->Mapped = 0; | |
365 | PortP->WflushFlag = 0; | |
366 | PortP->MagicFlags = 0; | |
367 | PortP->RxDataStart = 0; | |
368 | PortP->TxBufferIn = 0; | |
369 | PortP->TxBufferOut = 0; | |
370 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); | |
371 | } | |
8d8706e2 | 372 | return (0); |
1da177e4 LT |
373 | } |
374 | ||
375 | /* | |
376 | ** Incoming command on the COMMAND_RUP to be processed. | |
377 | */ | |
8d8706e2 | 378 | static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP) |
1da177e4 | 379 | { |
8d8706e2 | 380 | struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data; |
1da177e4 LT |
381 | struct Port *PortP; |
382 | struct UnixRup *UnixRupP; | |
00d83a54 AC |
383 | unsigned short SysPort; |
384 | unsigned short ReportedModemStatus; | |
385 | unsigned short rup; | |
386 | unsigned short subCommand; | |
1da177e4 LT |
387 | unsigned long flags; |
388 | ||
8d8706e2 | 389 | func_enter(); |
1da177e4 | 390 | |
1da177e4 | 391 | /* |
8d8706e2 AM |
392 | ** 16 port RTA note: |
393 | ** Command rup packets coming from the RTA will have pkt->data[1] (which | |
394 | ** translates to PktCmdP->PhbNum) set to the host port number for the | |
395 | ** particular unit. To access the correct BaseSysPort for a 16 port RTA, | |
396 | ** we can use PhbNum to get the rup number for the appropriate 8 port | |
397 | ** block (for the first block, this should be equal to 'Rup'). | |
398 | */ | |
00d83a54 | 399 | rup = readb(&PktCmdP->PhbNum) / (unsigned short) PORTS_PER_RTA; |
1da177e4 | 400 | UnixRupP = &HostP->UnixRups[rup]; |
00d83a54 | 401 | SysPort = UnixRupP->BaseSysPort + (readb(&PktCmdP->PhbNum) % (unsigned short) PORTS_PER_RTA); |
8d8706e2 | 402 | rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort); |
1da177e4 | 403 | |
8d8706e2 AM |
404 | if (UnixRupP->BaseSysPort == NO_PORT) { |
405 | rio_dprintk(RIO_DEBUG_CMD, "OBSCURE ERROR!\n"); | |
406 | rio_dprintk(RIO_DEBUG_CMD, "Diagnostics follow. Please WRITE THESE DOWN and report them to Specialix Technical Support\n"); | |
00d83a54 | 407 | rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Host number %Zd, name ``%s''\n", HostP - p->RIOHosts, HostP->Name); |
8d8706e2 AM |
408 | rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup); |
409 | ||
00d83a54 | 410 | if (Rup >= (unsigned short) MAX_RUP) { |
8d8706e2 | 411 | rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for RTA ``%s''\n", HostP->Mapping[Rup].Name); |
1da177e4 | 412 | } else |
8d8706e2 AM |
413 | rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for link ``%c'' of host ``%s''\n", ('A' + Rup - MAX_RUP), HostP->Name); |
414 | ||
415 | rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Destination 0x%x:0x%x\n", PacketP->dest_unit, PacketP->dest_port); | |
416 | rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Source 0x%x:0x%x\n", PacketP->src_unit, PacketP->src_port); | |
417 | rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Length 0x%x (%d)\n", PacketP->len, PacketP->len); | |
418 | rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Control 0x%x (%d)\n", PacketP->control, PacketP->control); | |
419 | rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Check 0x%x (%d)\n", PacketP->csum, PacketP->csum); | |
420 | rio_dprintk(RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, " "Command Code 0x%x\n", PktCmdP->PhbNum, PktCmdP->Command); | |
1da177e4 LT |
421 | return TRUE; |
422 | } | |
8d8706e2 | 423 | PortP = p->RIOPortp[SysPort]; |
1da177e4 | 424 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
00d83a54 | 425 | switch (readb(&PktCmdP->Command)) { |
8d8706e2 AM |
426 | case BREAK_RECEIVED: |
427 | rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n"); | |
428 | /* If the current line disc. is not multi-threading and | |
429 | the current processor is not the default, reset rup_intr | |
430 | and return FALSE to ensure that the command packet is | |
431 | not freed. */ | |
432 | /* Call tmgr HANGUP HERE */ | |
433 | /* Fix this later when every thing works !!!! RAMRAJ */ | |
434 | gs_got_break(&PortP->gs); | |
435 | break; | |
436 | ||
437 | case COMPLETE: | |
00d83a54 | 438 | rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %Zd\n", readb(&PktCmdP->PhbNum), HostP - p->RIOHosts); |
8d8706e2 | 439 | subCommand = 1; |
00d83a54 | 440 | switch (readb(&PktCmdP->SubCommand)) { |
8d8706e2 | 441 | case MEMDUMP: |
00d83a54 | 442 | rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", readb(&PktCmdP->SubCommand), readw(&PktCmdP->SubAddr)); |
1da177e4 | 443 | break; |
8d8706e2 | 444 | case READ_REGISTER: |
00d83a54 AC |
445 | rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", readw(&PktCmdP->SubAddr)); |
446 | p->CdRegister = (readb(&PktCmdP->ModemStatus) & MSVR1_HOST); | |
8d8706e2 AM |
447 | break; |
448 | default: | |
449 | subCommand = 0; | |
450 | break; | |
451 | } | |
452 | if (subCommand) | |
453 | break; | |
00d83a54 AC |
454 | rio_dprintk(RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n", readb(&PktCmdP->PortStatus), PortP->PortState); |
455 | if (PortP->PortState != readb(&PktCmdP->PortStatus)) { | |
8d8706e2 | 456 | rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n"); |
00d83a54 | 457 | PortP->PortState = readb(&PktCmdP->PortStatus); |
8d8706e2 AM |
458 | /* What should we do here ... |
459 | wakeup( &PortP->PortState ); | |
460 | */ | |
461 | } else | |
462 | rio_dprintk(RIO_DEBUG_CMD, "No change\n"); | |
1da177e4 | 463 | |
8d8706e2 AM |
464 | /* FALLTHROUGH */ |
465 | case MODEM_STATUS: | |
466 | /* | |
467 | ** Knock out the tbusy and tstop bits, as these are not relevant | |
468 | ** to the check for modem status change (they're just there because | |
469 | ** it's a convenient place to put them!). | |
470 | */ | |
00d83a54 | 471 | ReportedModemStatus = readb(&PktCmdP->ModemStatus); |
8d8706e2 AM |
472 | if ((PortP->ModemState & MSVR1_HOST) == (ReportedModemStatus & MSVR1_HOST)) { |
473 | rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState); | |
1da177e4 | 474 | /* |
8d8706e2 AM |
475 | ** Update ModemState just in case tbusy or tstop states have |
476 | ** changed. | |
477 | */ | |
478 | PortP->ModemState = ReportedModemStatus; | |
479 | } else { | |
480 | rio_dprintk(RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n", PortP->ModemState, ReportedModemStatus); | |
481 | PortP->ModemState = ReportedModemStatus; | |
1da177e4 | 482 | #ifdef MODEM_SUPPORT |
8d8706e2 | 483 | if (PortP->Mapped) { |
1da177e4 LT |
484 | /***********************************************************\ |
485 | ************************************************************* | |
486 | *** *** | |
487 | *** M O D E M S T A T E C H A N G E *** | |
488 | *** *** | |
489 | ************************************************************* | |
490 | \***********************************************************/ | |
491 | /* | |
8d8706e2 AM |
492 | ** If the device is a modem, then check the modem |
493 | ** carrier. | |
494 | */ | |
1da177e4 LT |
495 | if (PortP->gs.tty == NULL) |
496 | break; | |
497 | if (PortP->gs.tty->termios == NULL) | |
498 | break; | |
1da177e4 | 499 | |
8d8706e2 AM |
500 | if (!(PortP->gs.tty->termios->c_cflag & CLOCAL) && ((PortP->State & (RIO_MOPEN | RIO_WOPEN)))) { |
501 | ||
502 | rio_dprintk(RIO_DEBUG_CMD, "Is there a Carrier?\n"); | |
503 | /* | |
504 | ** Is there a carrier? | |
505 | */ | |
506 | if (PortP->ModemState & MSVR1_CD) { | |
507 | /* | |
508 | ** Has carrier just appeared? | |
509 | */ | |
1da177e4 | 510 | if (!(PortP->State & RIO_CARR_ON)) { |
8d8706e2 | 511 | rio_dprintk(RIO_DEBUG_CMD, "Carrier just came up.\n"); |
1da177e4 | 512 | PortP->State |= RIO_CARR_ON; |
8d8706e2 AM |
513 | /* |
514 | ** wakeup anyone in WOPEN | |
515 | */ | |
516 | if (PortP->State & (PORT_ISOPEN | RIO_WOPEN)) | |
517 | wake_up_interruptible(&PortP->gs.open_wait); | |
8d8706e2 | 518 | } |
1da177e4 | 519 | } else { |
8d8706e2 AM |
520 | /* |
521 | ** Has carrier just dropped? | |
522 | */ | |
1da177e4 | 523 | if (PortP->State & RIO_CARR_ON) { |
8d8706e2 AM |
524 | if (PortP->State & (PORT_ISOPEN | RIO_WOPEN | RIO_MOPEN)) |
525 | tty_hangup(PortP->gs.tty); | |
1da177e4 | 526 | PortP->State &= ~RIO_CARR_ON; |
8d8706e2 | 527 | rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n"); |
8d8706e2 AM |
528 | } |
529 | } | |
530 | } | |
1da177e4 | 531 | } |
1da177e4 | 532 | #endif |
8d8706e2 AM |
533 | } |
534 | break; | |
1da177e4 | 535 | |
8d8706e2 | 536 | default: |
00d83a54 | 537 | rio_dprintk(RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %Zd\n", readb(&PktCmdP->Command), HostP - p->RIOHosts); |
8d8706e2 | 538 | break; |
1da177e4 LT |
539 | } |
540 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); | |
541 | ||
8d8706e2 | 542 | func_exit(); |
1da177e4 LT |
543 | |
544 | return TRUE; | |
545 | } | |
8d8706e2 | 546 | |
1da177e4 LT |
547 | /* |
548 | ** The command mechanism: | |
549 | ** Each rup has a chain of commands associated with it. | |
550 | ** This chain is maintained by routines in this file. | |
551 | ** Periodically we are called and we run a quick check of all the | |
552 | ** active chains to determine if there is a command to be executed, | |
553 | ** and if the rup is ready to accept it. | |
554 | ** | |
555 | */ | |
556 | ||
557 | /* | |
558 | ** Allocate an empty command block. | |
559 | */ | |
8d8706e2 | 560 | struct CmdBlk *RIOGetCmdBlk(void) |
1da177e4 LT |
561 | { |
562 | struct CmdBlk *CmdBlkP; | |
563 | ||
00d83a54 | 564 | CmdBlkP = (struct CmdBlk *)kmalloc(sizeof(struct CmdBlk), GFP_ATOMIC); |
1da177e4 | 565 | if (CmdBlkP) |
00d83a54 | 566 | memset(CmdBlkP, 0, sizeof(struct CmdBlk)); |
1da177e4 LT |
567 | return CmdBlkP; |
568 | } | |
569 | ||
570 | /* | |
571 | ** Return a block to the head of the free list. | |
572 | */ | |
8d8706e2 | 573 | void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP) |
1da177e4 | 574 | { |
00d83a54 | 575 | kfree(CmdBlkP); |
1da177e4 LT |
576 | } |
577 | ||
578 | /* | |
579 | ** attach a command block to the list of commands to be performed for | |
580 | ** a given rup. | |
581 | */ | |
8d8706e2 | 582 | int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP) |
1da177e4 LT |
583 | { |
584 | struct CmdBlk **Base; | |
585 | struct UnixRup *UnixRupP; | |
586 | unsigned long flags; | |
587 | ||
00d83a54 | 588 | if (Rup >= (unsigned short) (MAX_RUP + LINKS_PER_UNIT)) { |
8d8706e2 AM |
589 | rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup); |
590 | RIOFreeCmdBlk(CmdBlkP); | |
1da177e4 LT |
591 | return RIO_FAIL; |
592 | } | |
593 | ||
594 | UnixRupP = &HostP->UnixRups[Rup]; | |
595 | ||
596 | rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); | |
597 | ||
598 | /* | |
8d8706e2 AM |
599 | ** If the RUP is currently inactive, then put the request |
600 | ** straight on the RUP.... | |
601 | */ | |
00d83a54 | 602 | if ((UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE) && (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) |
8d8706e2 AM |
603 | : TRUE)) { |
604 | rio_dprintk(RIO_DEBUG_CMD, "RUP inactive-placing command straight on. Cmd byte is 0x%x\n", CmdBlkP->Packet.data[0]); | |
1da177e4 LT |
605 | |
606 | /* | |
8d8706e2 AM |
607 | ** Whammy! blat that pack! |
608 | */ | |
609 | HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT)); | |
1da177e4 LT |
610 | |
611 | /* | |
8d8706e2 AM |
612 | ** place command packet on the pending position. |
613 | */ | |
1da177e4 LT |
614 | UnixRupP->CmdPendingP = CmdBlkP; |
615 | ||
616 | /* | |
8d8706e2 AM |
617 | ** set the command register |
618 | */ | |
00d83a54 | 619 | writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol); |
1da177e4 LT |
620 | |
621 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); | |
622 | ||
623 | return RIO_SUCCESS; | |
624 | } | |
8d8706e2 | 625 | rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n"); |
1da177e4 | 626 | |
8d8706e2 AM |
627 | if (UnixRupP->CmdsWaitingP != NULL) |
628 | rio_dprintk(RIO_DEBUG_CMD, "Rup active - command waiting\n"); | |
629 | if (UnixRupP->CmdPendingP != NULL) | |
630 | rio_dprintk(RIO_DEBUG_CMD, "Rup active - command pending\n"); | |
00d83a54 | 631 | if (readw(&UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE) |
8d8706e2 | 632 | rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n"); |
1da177e4 LT |
633 | |
634 | Base = &UnixRupP->CmdsWaitingP; | |
635 | ||
00d83a54 | 636 | rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk 0x%p at 0x%p\n", CmdBlkP, Base); |
1da177e4 | 637 | |
8d8706e2 | 638 | while (*Base) { |
00d83a54 | 639 | rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk 0x%p here\n", *Base); |
1da177e4 | 640 | Base = &((*Base)->NextP); |
00d83a54 | 641 | rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk 0x%p at 0x%p\n", CmdBlkP, Base); |
1da177e4 LT |
642 | } |
643 | ||
00d83a54 | 644 | rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk 0x%p at 0x%p\n", CmdBlkP, Base); |
1da177e4 LT |
645 | |
646 | *Base = CmdBlkP; | |
647 | ||
648 | CmdBlkP->NextP = NULL; | |
649 | ||
650 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); | |
651 | ||
652 | return RIO_SUCCESS; | |
653 | } | |
654 | ||
655 | /* | |
656 | ** Here we go - if there is an empty rup, fill it! | |
657 | ** must be called at splrio() or higher. | |
658 | */ | |
8d8706e2 | 659 | void RIOPollHostCommands(struct rio_info *p, struct Host *HostP) |
1da177e4 | 660 | { |
00d83a54 AC |
661 | struct CmdBlk *CmdBlkP; |
662 | struct UnixRup *UnixRupP; | |
1da177e4 | 663 | struct PKT *PacketP; |
00d83a54 | 664 | unsigned short Rup; |
1da177e4 LT |
665 | unsigned long flags; |
666 | ||
667 | ||
8d8706e2 | 668 | Rup = MAX_RUP + LINKS_PER_UNIT; |
1da177e4 | 669 | |
8d8706e2 | 670 | do { /* do this loop for each RUP */ |
1da177e4 | 671 | /* |
8d8706e2 AM |
672 | ** locate the rup we are processing & lock it |
673 | */ | |
1da177e4 LT |
674 | UnixRupP = &HostP->UnixRups[--Rup]; |
675 | ||
676 | spin_lock_irqsave(&UnixRupP->RupLock, flags); | |
677 | ||
678 | /* | |
8d8706e2 AM |
679 | ** First check for incoming commands: |
680 | */ | |
00d83a54 | 681 | if (readw(&UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) { |
1da177e4 LT |
682 | int FreeMe; |
683 | ||
00d83a54 | 684 | PacketP = (PKT *) RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->rxpkt)); |
1da177e4 | 685 | |
8d8706e2 | 686 | ShowPacket(DBG_CMD, PacketP); |
1da177e4 | 687 | |
00d83a54 | 688 | switch (readb(&PacketP->dest_port)) { |
8d8706e2 | 689 | case BOOT_RUP: |
00d83a54 | 690 | rio_dprintk(RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n", readb(&PacketP->len) & 0x80 ? "Command" : "Data", readb(&PacketP->data[0])); |
8d8706e2 AM |
691 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); |
692 | FreeMe = RIOBootRup(p, Rup, HostP, PacketP); | |
693 | rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); | |
694 | break; | |
1da177e4 | 695 | |
8d8706e2 AM |
696 | case COMMAND_RUP: |
697 | /* | |
698 | ** Free the RUP lock as loss of carrier causes a | |
699 | ** ttyflush which will (eventually) call another | |
700 | ** routine that uses the RUP lock. | |
701 | */ | |
702 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); | |
703 | FreeMe = RIOCommandRup(p, Rup, HostP, PacketP); | |
704 | if (PacketP->data[5] == MEMDUMP) { | |
00d83a54 | 705 | rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", *(unsigned short *) & (PacketP->data[6])); |
8d8706e2 AM |
706 | HostP->Copy((caddr_t) & (PacketP->data[8]), (caddr_t) p->RIOMemDump, 32); |
707 | } | |
708 | rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); | |
709 | break; | |
1da177e4 | 710 | |
8d8706e2 AM |
711 | case ROUTE_RUP: |
712 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); | |
713 | FreeMe = RIORouteRup(p, Rup, HostP, PacketP); | |
714 | rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); | |
715 | break; | |
1da177e4 | 716 | |
8d8706e2 | 717 | default: |
00d83a54 | 718 | rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", readb(&PacketP->dest_port)); |
8d8706e2 AM |
719 | FreeMe = 1; |
720 | break; | |
1da177e4 LT |
721 | } |
722 | ||
8d8706e2 AM |
723 | if (FreeMe) { |
724 | rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n"); | |
725 | put_free_end(HostP, PacketP); | |
1da177e4 | 726 | |
00d83a54 | 727 | writew(RX_RUP_INACTIVE, &UnixRupP->RupP->rxcontrol); |
1da177e4 | 728 | |
00d83a54 | 729 | if (readw(&UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) { |
8d8706e2 | 730 | rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup); |
00d83a54 | 731 | writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &UnixRupP->RupP->handshake); |
1da177e4 LT |
732 | } |
733 | } | |
734 | } | |
735 | ||
736 | /* | |
8d8706e2 AM |
737 | ** IF a command was running on the port, |
738 | ** and it has completed, then tidy it up. | |
739 | */ | |
740 | if ((CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */ | |
00d83a54 | 741 | (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) { |
1da177e4 | 742 | /* |
8d8706e2 AM |
743 | ** we are idle. |
744 | ** there is a command in pending. | |
745 | ** Therefore, this command has finished. | |
746 | ** So, wakeup whoever is waiting for it (and tell them | |
747 | ** what happened). | |
748 | */ | |
749 | if (CmdBlkP->Packet.dest_port == BOOT_RUP) | |
750 | rio_dprintk(RIO_DEBUG_CMD, "Free Boot %s Command Block '%x'\n", CmdBlkP->Packet.len & 0x80 ? "Command" : "Data", CmdBlkP->Packet.data[0]); | |
751 | ||
00d83a54 | 752 | rio_dprintk(RIO_DEBUG_CMD, "Command 0x%p completed\n", CmdBlkP); |
1da177e4 LT |
753 | |
754 | /* | |
8d8706e2 AM |
755 | ** Clear the Rup lock to prevent mutual exclusion. |
756 | */ | |
757 | if (CmdBlkP->PostFuncP) { | |
1da177e4 | 758 | rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); |
8d8706e2 | 759 | (*CmdBlkP->PostFuncP) (CmdBlkP->PostArg, CmdBlkP); |
1da177e4 LT |
760 | rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); |
761 | } | |
762 | ||
763 | /* | |
8d8706e2 AM |
764 | ** ....clear the pending flag.... |
765 | */ | |
1da177e4 LT |
766 | UnixRupP->CmdPendingP = NULL; |
767 | ||
768 | /* | |
8d8706e2 AM |
769 | ** ....and return the command block to the freelist. |
770 | */ | |
771 | RIOFreeCmdBlk(CmdBlkP); | |
1da177e4 LT |
772 | } |
773 | ||
774 | /* | |
8d8706e2 AM |
775 | ** If there is a command for this rup, and the rup |
776 | ** is idle, then process the command | |
777 | */ | |
778 | if ((CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */ | |
00d83a54 | 779 | (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) { |
1da177e4 | 780 | /* |
8d8706e2 AM |
781 | ** if the pre-function is non-zero, call it. |
782 | ** If it returns RIO_FAIL then don't | |
783 | ** send this command yet! | |
784 | */ | |
8d8706e2 | 785 | if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : TRUE)) { |
00d83a54 | 786 | rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command 0x%p\n", CmdBlkP); |
8d8706e2 | 787 | } else { |
00d83a54 | 788 | rio_dprintk(RIO_DEBUG_CMD, "Start new command 0x%p Cmd byte is 0x%x\n", CmdBlkP, CmdBlkP->Packet.data[0]); |
1da177e4 | 789 | /* |
8d8706e2 AM |
790 | ** Whammy! blat that pack! |
791 | */ | |
8d8706e2 | 792 | HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT)); |
1da177e4 LT |
793 | |
794 | /* | |
8d8706e2 AM |
795 | ** remove the command from the rup command queue... |
796 | */ | |
1da177e4 LT |
797 | UnixRupP->CmdsWaitingP = CmdBlkP->NextP; |
798 | ||
799 | /* | |
8d8706e2 AM |
800 | ** ...and place it on the pending position. |
801 | */ | |
1da177e4 LT |
802 | UnixRupP->CmdPendingP = CmdBlkP; |
803 | ||
804 | /* | |
8d8706e2 AM |
805 | ** set the command register |
806 | */ | |
00d83a54 | 807 | writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol); |
1da177e4 LT |
808 | |
809 | /* | |
8d8706e2 AM |
810 | ** the command block will be freed |
811 | ** when the command has been processed. | |
812 | */ | |
1da177e4 LT |
813 | } |
814 | } | |
815 | spin_unlock_irqrestore(&UnixRupP->RupLock, flags); | |
8d8706e2 | 816 | } while (Rup); |
1da177e4 LT |
817 | } |
818 | ||
00d83a54 | 819 | int RIOWFlushMark(unsigned long iPortP, struct CmdBlk *CmdBlkP) |
1da177e4 | 820 | { |
8d8706e2 | 821 | struct Port *PortP = (struct Port *) iPortP; |
1da177e4 LT |
822 | unsigned long flags; |
823 | ||
824 | rio_spin_lock_irqsave(&PortP->portSem, flags); | |
1da177e4 LT |
825 | PortP->WflushFlag++; |
826 | PortP->MagicFlags |= MAGIC_FLUSH; | |
827 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); | |
8d8706e2 | 828 | return RIOUnUse(iPortP, CmdBlkP); |
1da177e4 LT |
829 | } |
830 | ||
00d83a54 | 831 | int RIORFlushEnable(unsigned long iPortP, struct CmdBlk *CmdBlkP) |
1da177e4 | 832 | { |
8d8706e2 | 833 | struct Port *PortP = (struct Port *) iPortP; |
1da177e4 LT |
834 | PKT *PacketP; |
835 | unsigned long flags; | |
836 | ||
837 | rio_spin_lock_irqsave(&PortP->portSem, flags); | |
838 | ||
8d8706e2 | 839 | while (can_remove_receive(&PacketP, PortP)) { |
1da177e4 | 840 | remove_receive(PortP); |
8d8706e2 AM |
841 | ShowPacket(DBG_PROC, PacketP); |
842 | put_free_end(PortP->HostP, PacketP); | |
1da177e4 LT |
843 | } |
844 | ||
00d83a54 | 845 | if (readw(&PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) { |
1da177e4 | 846 | /* |
8d8706e2 AM |
847 | ** MAGIC! (Basically, handshake the RX buffer, so that |
848 | ** the RTAs upstream can be re-enabled.) | |
849 | */ | |
850 | rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n"); | |
00d83a54 | 851 | writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &PortP->PhbP->handshake); |
1da177e4 LT |
852 | } |
853 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); | |
8d8706e2 | 854 | return RIOUnUse(iPortP, CmdBlkP); |
1da177e4 LT |
855 | } |
856 | ||
00d83a54 | 857 | int RIOUnUse(unsigned long iPortP, struct CmdBlk *CmdBlkP) |
1da177e4 | 858 | { |
8d8706e2 | 859 | struct Port *PortP = (struct Port *) iPortP; |
1da177e4 LT |
860 | unsigned long flags; |
861 | ||
862 | rio_spin_lock_irqsave(&PortP->portSem, flags); | |
863 | ||
8d8706e2 | 864 | rio_dprintk(RIO_DEBUG_CMD, "Decrement in use count for port\n"); |
1da177e4 LT |
865 | |
866 | if (PortP->InUse) { | |
8d8706e2 | 867 | if (--PortP->InUse != NOT_INUSE) { |
1da177e4 LT |
868 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
869 | return 0; | |
870 | } | |
871 | } | |
872 | /* | |
8d8706e2 AM |
873 | ** While PortP->InUse is set (i.e. a preemptive command has been sent to |
874 | ** the RTA and is awaiting completion), any transmit data is prevented from | |
875 | ** being transferred from the write queue into the transmit packets | |
876 | ** (add_transmit) and no furthur transmit interrupt will be sent for that | |
877 | ** data. The next interrupt will occur up to 500ms later (RIOIntr is called | |
878 | ** twice a second as a saftey measure). This was the case when kermit was | |
879 | ** used to send data into a RIO port. After each packet was sent, TCFLSH | |
880 | ** was called to flush the read queue preemptively. PortP->InUse was | |
881 | ** incremented, thereby blocking the 6 byte acknowledgement packet | |
882 | ** transmitted back. This acknowledgment hung around for 500ms before | |
883 | ** being sent, thus reducing input performance substantially!. | |
884 | ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data | |
885 | ** hanging around in the transmit buffer is sent immediately. | |
886 | */ | |
00d83a54 | 887 | writew(1, &PortP->HostP->ParmMapP->tx_intr); |
1da177e4 | 888 | /* What to do here .. |
8d8706e2 AM |
889 | wakeup( (caddr_t)&(PortP->InUse) ); |
890 | */ | |
1da177e4 LT |
891 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
892 | return 0; | |
893 | } | |
894 | ||
8d8706e2 | 895 | void ShowPacket(uint Flags, struct PKT *PacketP) |
1da177e4 LT |
896 | { |
897 | } | |
898 | ||
899 | /* | |
900 | ** | |
901 | ** How to use this file: | |
902 | ** | |
903 | ** To send a command down a rup, you need to allocate a command block, fill | |
904 | ** in the packet information, fill in the command number, fill in the pre- | |
905 | ** and post- functions and arguments, and then add the command block to the | |
906 | ** queue of command blocks for the port in question. When the port is idle, | |
907 | ** then the pre-function will be called. If this returns RIO_FAIL then the | |
908 | ** command will be re-queued and tried again at a later date (probably in one | |
909 | ** clock tick). If the pre-function returns NOT RIO_FAIL, then the command | |
910 | ** packet will be queued on the RUP, and the txcontrol field set to the | |
911 | ** command number. When the txcontrol field has changed from being the | |
912 | ** command number, then the post-function will be called, with the argument | |
913 | ** specified earlier, a pointer to the command block, and the value of | |
914 | ** txcontrol. | |
915 | ** | |
916 | ** To allocate a command block, call RIOGetCmdBlk(). This returns a pointer | |
917 | ** to the command block structure allocated, or NULL if there aren't any. | |
918 | ** The block will have been zeroed for you. | |
919 | ** | |
920 | ** The structure has the following fields: | |
921 | ** | |
922 | ** struct CmdBlk | |
923 | ** { | |
924 | ** struct CmdBlk *NextP; ** Pointer to next command block ** | |
925 | ** struct PKT Packet; ** A packet, to copy to the rup ** | |
926 | ** int (*PreFuncP)(); ** The func to call to check if OK ** | |
927 | ** int PreArg; ** The arg for the func ** | |
928 | ** int (*PostFuncP)(); ** The func to call when completed ** | |
929 | ** int PostArg; ** The arg for the func ** | |
930 | ** }; | |
931 | ** | |
932 | ** You need to fill in ALL fields EXCEPT NextP, which is used to link the | |
933 | ** blocks together either on the free list or on the Rup list. | |
934 | ** | |
935 | ** Packet is an actual packet structure to be filled in with the packet | |
936 | ** information associated with the command. You need to fill in everything, | |
937 | ** as the command processore doesn't process the command packet in any way. | |
938 | ** | |
939 | ** The PreFuncP is called before the packet is enqueued on the host rup. | |
940 | ** PreFuncP is called as (*PreFuncP)(PreArg, CmdBlkP);. PreFuncP must | |
941 | ** return !RIO_FAIL to have the packet queued on the rup, and RIO_FAIL | |
942 | ** if the packet is NOT to be queued. | |
943 | ** | |
944 | ** The PostFuncP is called when the command has completed. It is called | |
945 | ** as (*PostFuncP)(PostArg, CmdBlkP, txcontrol);. PostFuncP is not expected | |
946 | ** to return a value. PostFuncP does NOT need to free the command block, | |
947 | ** as this happens automatically after PostFuncP returns. | |
948 | ** | |
949 | ** Once the command block has been filled in, it is attached to the correct | |
950 | ** queue by calling RIOQueueCmdBlk( HostP, Rup, CmdBlkP ) where HostP is | |
951 | ** a pointer to the struct Host, Rup is the NUMBER of the rup (NOT a pointer | |
952 | ** to it!), and CmdBlkP is the pointer to the command block allocated using | |
953 | ** RIOGetCmdBlk(). | |
954 | ** | |
955 | */ |