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