Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** ----------------------------------------------------------------------------- |
| 3 | ** |
| 4 | ** Perle Specialix driver for Linux |
| 5 | ** Ported from existing RIO Driver for SCO sources. |
| 6 | * |
| 7 | * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | ** |
| 23 | ** Module : riotable.c |
| 24 | ** SID : 1.2 |
| 25 | ** Last Modified : 11/6/98 10:33:47 |
| 26 | ** Retrieved : 11/6/98 10:33:50 |
| 27 | ** |
| 28 | ** ident @(#)riotable.c 1.2 |
| 29 | ** |
| 30 | ** ----------------------------------------------------------------------------- |
| 31 | */ |
| 32 | #ifdef SCCS_LABELS |
| 33 | static char *_riotable_c_sccs_ = "@(#)riotable.c 1.2"; |
| 34 | #endif |
| 35 | |
| 36 | #include <linux/module.h> |
| 37 | #include <linux/slab.h> |
| 38 | #include <linux/errno.h> |
| 39 | #include <linux/interrupt.h> |
| 40 | #include <linux/string.h> |
| 41 | |
| 42 | #include <asm/io.h> |
| 43 | #include <asm/system.h> |
| 44 | #include <asm/string.h> |
| 45 | #include <asm/semaphore.h> |
| 46 | #include <asm/uaccess.h> |
| 47 | |
| 48 | #include <linux/termios.h> |
| 49 | #include <linux/serial.h> |
| 50 | |
| 51 | #include <linux/generic_serial.h> |
| 52 | |
| 53 | |
| 54 | #include "linux_compat.h" |
| 55 | #include "rio_linux.h" |
| 56 | #include "typdef.h" |
| 57 | #include "pkt.h" |
| 58 | #include "daemon.h" |
| 59 | #include "rio.h" |
| 60 | #include "riospace.h" |
| 61 | #include "top.h" |
| 62 | #include "cmdpkt.h" |
| 63 | #include "map.h" |
| 64 | #include "riotypes.h" |
| 65 | #include "rup.h" |
| 66 | #include "port.h" |
| 67 | #include "riodrvr.h" |
| 68 | #include "rioinfo.h" |
| 69 | #include "func.h" |
| 70 | #include "errors.h" |
| 71 | #include "pci.h" |
| 72 | |
| 73 | #include "parmmap.h" |
| 74 | #include "unixrup.h" |
| 75 | #include "board.h" |
| 76 | #include "host.h" |
| 77 | #include "error.h" |
| 78 | #include "phb.h" |
| 79 | #include "link.h" |
| 80 | #include "cmdblk.h" |
| 81 | #include "route.h" |
| 82 | #include "control.h" |
| 83 | #include "cirrus.h" |
| 84 | #include "rioioctl.h" |
| 85 | #include "param.h" |
| 86 | #include "list.h" |
| 87 | #include "sam.h" |
| 88 | #include "protsts.h" |
| 89 | |
| 90 | /* |
| 91 | ** A configuration table has been loaded. It is now up to us |
| 92 | ** to sort it out and use the information contained therein. |
| 93 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 94 | int RIONewTable(struct rio_info *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | int Host, Host1, Host2, NameIsUnique, Entry, SubEnt; |
| 97 | struct Map *MapP; |
| 98 | struct Map *HostMapP; |
| 99 | struct Host *HostP; |
| 100 | |
| 101 | char *cptr; |
| 102 | |
| 103 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 104 | ** We have been sent a new table to install. We need to break |
| 105 | ** it down into little bits and spread it around a bit to see |
| 106 | ** what we have got. |
| 107 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 109 | ** Things to check: |
| 110 | ** (things marked 'xx' aren't checked any more!) |
| 111 | ** (1) That there are no booted Hosts/RTAs out there. |
| 112 | ** (2) That the names are properly formed |
| 113 | ** (3) That blank entries really are. |
| 114 | ** xx (4) That hosts mentioned in the table actually exist. xx |
| 115 | ** (5) That the IDs are unique (per host). |
| 116 | ** (6) That host IDs are zero |
| 117 | ** (7) That port numbers are valid |
| 118 | ** (8) That port numbers aren't duplicated |
| 119 | ** (9) That names aren't duplicated |
| 120 | ** xx (10) That hosts that actually exist are mentioned in the table. xx |
| 121 | */ |
| 122 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n"); |
| 123 | if (p->RIOSystemUp) { /* (1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | p->RIOError.Error = HOST_HAS_ALREADY_BEEN_BOOTED; |
| 125 | return -EBUSY; |
| 126 | } |
| 127 | |
| 128 | p->RIOError.Error = NOTHING_WRONG_AT_ALL; |
| 129 | p->RIOError.Entry = -1; |
| 130 | p->RIOError.Other = -1; |
| 131 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 132 | for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | MapP = &p->RIOConnectTable[Entry]; |
| 134 | if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 135 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n"); |
| 136 | cptr = MapP->Name; /* (2) */ |
| 137 | cptr[MAX_NAME_LEN - 1] = '\0'; |
| 138 | if (cptr[0] == '\0') { |
| 139 | bcopy(MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", MapP->Name, 8); |
| 140 | MapP->Name[5] = '0' + Entry / 10; |
| 141 | MapP->Name[6] = '0' + Entry % 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 143 | while (*cptr) { |
| 144 | if (*cptr < ' ' || *cptr > '~') { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | p->RIOError.Error = BAD_CHARACTER_IN_NAME; |
| 146 | p->RIOError.Entry = Entry; |
| 147 | return -ENXIO; |
| 148 | } |
| 149 | cptr++; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 154 | ** If the entry saved was a tentative entry then just forget |
| 155 | ** about it. |
| 156 | */ |
| 157 | if (MapP->Flags & SLOT_TENTATIVE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | MapP->HostUniqueNum = 0; |
| 159 | MapP->RtaUniqueNum = 0; |
| 160 | continue; |
| 161 | } |
| 162 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 163 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n"); |
| 164 | if (!MapP->RtaUniqueNum && !MapP->HostUniqueNum) { /* (3) */ |
| 165 | if (MapP->ID || MapP->SysPort || MapP->Flags) { |
| 166 | rio_dprintk(RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n", MapP->Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL; |
| 168 | p->RIOError.Entry = Entry; |
| 169 | return -ENXIO; |
| 170 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 171 | rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | continue; |
| 173 | } |
| 174 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 175 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n"); |
| 176 | for (Host = 0; Host < p->RIONumHosts; Host++) { /* (4) */ |
| 177 | if (p->RIOHosts[Host].UniqueNum == MapP->HostUniqueNum) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | HostP = &p->RIOHosts[Host]; |
| 179 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 180 | ** having done the lookup, we don't really want to do |
| 181 | ** it again, so hang the host number in a safe place |
| 182 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | MapP->Topology[0].Unit = Host; |
| 184 | break; |
| 185 | } |
| 186 | } |
| 187 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 188 | if (Host >= p->RIONumHosts) { |
| 189 | rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n", MapP->Name, MapP->HostUniqueNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | MapP->HostUniqueNum = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 191 | /* MapP->RtaUniqueNum = 0; */ |
| 192 | /* MapP->ID = 0; */ |
| 193 | /* MapP->Flags = 0; */ |
| 194 | /* MapP->SysPort = 0; */ |
| 195 | /* MapP->Name[0] = 0; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | continue; |
| 197 | } |
| 198 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 199 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n"); |
| 200 | if (MapP->RtaUniqueNum) { /* (5) */ |
| 201 | if (!MapP->ID) { |
| 202 | rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name); |
| 203 | p->RIOError.Error = ZERO_RTA_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | p->RIOError.Entry = Entry; |
| 205 | return -ENXIO; |
| 206 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 207 | if (MapP->ID > MAX_RUP) { |
| 208 | rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an invalid ID %d\n", MapP->Name, MapP->ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE; |
| 210 | p->RIOError.Entry = Entry; |
| 211 | return -ENXIO; |
| 212 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 213 | for (SubEnt = 0; SubEnt < Entry; SubEnt++) { |
| 214 | if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) { |
| 215 | rio_dprintk(RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n", MapP->Name, p->RIOConnectTable[SubEnt].Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | p->RIOError.Error = DUPLICATED_RTA_ID; |
| 217 | p->RIOError.Entry = Entry; |
| 218 | p->RIOError.Other = SubEnt; |
| 219 | return -ENXIO; |
| 220 | } |
| 221 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 222 | ** If the RtaUniqueNum is the same, it may be looking at both |
| 223 | ** entries for a 16 port RTA, so check the ids |
| 224 | */ |
| 225 | if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum) |
| 226 | && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) { |
| 227 | rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name); |
| 228 | rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER; |
| 230 | p->RIOError.Entry = Entry; |
| 231 | p->RIOError.Other = SubEnt; |
| 232 | return -ENXIO; |
| 233 | } |
| 234 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 235 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | /* (7a) */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 237 | if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) { |
| 238 | rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d-RTA %s is not a multiple of %d!\n", (int) MapP->SysPort, MapP->Name, PORTS_PER_RTA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; |
| 240 | p->RIOError.Entry = Entry; |
| 241 | return -ENXIO; |
| 242 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 243 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | /* (7b) */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 245 | if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) { |
| 246 | rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n", (int) MapP->SysPort, MapP->Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; |
| 248 | p->RIOError.Entry = Entry; |
| 249 | return -ENXIO; |
| 250 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 251 | for (SubEnt = 0; SubEnt < Entry; SubEnt++) { |
| 252 | if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT) |
| 253 | continue; |
| 254 | if (p->RIOConnectTable[SubEnt].RtaUniqueNum) { |
| 255 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | /* (8) */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 257 | if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) { |
| 258 | rio_dprintk(RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n", MapP->Name, p->RIOConnectTable[SubEnt].Name, (int) MapP->SysPort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | p->RIOError.Error = TTY_NUMBER_IN_USE; |
| 260 | p->RIOError.Entry = Entry; |
| 261 | p->RIOError.Other = SubEnt; |
| 262 | return -ENXIO; |
| 263 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 264 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n"); |
| 265 | if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */ |
| 266 | rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | p->RIOError.Error = NAME_USED_TWICE; |
| 268 | p->RIOError.Entry = Entry; |
| 269 | p->RIOError.Other = SubEnt; |
| 270 | return -ENXIO; |
| 271 | } |
| 272 | } |
| 273 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 274 | } else { /* (6) */ |
| 275 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n"); |
| 276 | if (MapP->ID) { |
| 277 | rio_dprintk(RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n", MapP->Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | p->RIOError.Error = HOST_ID_NOT_ZERO; |
| 279 | p->RIOError.Entry = Entry; |
| 280 | return -ENXIO; |
| 281 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 282 | if (MapP->SysPort != NO_PORT) { |
| 283 | rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | p->RIOError.Error = HOST_SYSPORT_BAD; |
| 285 | p->RIOError.Entry = Entry; |
| 286 | return -ENXIO; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 292 | ** wow! if we get here then it's a goody! |
| 293 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 296 | ** Zero the (old) entries for each host... |
| 297 | */ |
| 298 | for (Host = 0; Host < RIO_HOSTS; Host++) { |
| 299 | for (Entry = 0; Entry < MAX_RUP; Entry++) { |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 300 | memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 302 | memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 306 | ** Copy in the new table entries |
| 307 | */ |
| 308 | for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) { |
| 309 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | MapP = &p->RIOConnectTable[Entry]; |
| 311 | |
| 312 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 313 | ** Now, if it is an empty slot ignore it! |
| 314 | */ |
| 315 | if (MapP->HostUniqueNum == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | continue; |
| 317 | |
| 318 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 319 | ** we saved the host number earlier, so grab it back |
| 320 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | HostP = &p->RIOHosts[MapP->Topology[0].Unit]; |
| 322 | |
| 323 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 324 | ** If it is a host, then we only need to fill in the name field. |
| 325 | */ |
| 326 | if (MapP->ID == 0) { |
| 327 | rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name); |
| 328 | bcopy(MapP->Name, HostP->Name, MAX_NAME_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | continue; |
| 330 | } |
| 331 | |
| 332 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 333 | ** Its an RTA entry, so fill in the host mapping entries for it |
| 334 | ** and the port mapping entries. Notice that entry zero is for |
| 335 | ** ID one. |
| 336 | */ |
| 337 | HostMapP = &HostP->Mapping[MapP->ID - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | if (MapP->Flags & SLOT_IN_USE) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 340 | rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 342 | ** structure assign, then sort out the bits we shouldn't have done |
| 343 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | *HostMapP = *MapP; |
| 345 | |
| 346 | HostMapP->Flags = SLOT_IN_USE; |
| 347 | if (MapP->Flags & RTA16_SECOND_SLOT) |
| 348 | HostMapP->Flags |= RTA16_SECOND_SLOT; |
| 349 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 350 | RIOReMapPorts(p, HostP, HostMapP); |
| 351 | } else { |
| 352 | rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 356 | for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry]; |
| 358 | } |
| 359 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 360 | for (Host = 0; Host < p->RIONumHosts; Host++) { |
| 361 | for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT; |
| 363 | p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK; |
| 364 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 365 | for (Entry = 0; Entry < MAX_RUP; Entry++) { |
| 366 | for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) { |
| 367 | p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT; |
| 368 | p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 371 | if (!p->RIOHosts[Host].Name[0]) { |
| 372 | bcopy("HOST 1", p->RIOHosts[Host].Name, 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | p->RIOHosts[Host].Name[5] += Host; |
| 374 | } |
| 375 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 376 | ** Check that default name assigned is unique. |
| 377 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | Host1 = Host; |
| 379 | NameIsUnique = 0; |
| 380 | while (!NameIsUnique) { |
| 381 | NameIsUnique = 1; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 382 | for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | if (Host2 == Host) |
| 384 | continue; |
| 385 | if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 386 | == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | NameIsUnique = 0; |
| 388 | Host1++; |
| 389 | if (Host1 >= p->RIONumHosts) |
| 390 | Host1 = 0; |
| 391 | p->RIOHosts[Host].Name[5] = '1' + Host1; |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 396 | ** Rename host if name already used. |
| 397 | */ |
| 398 | if (Host1 != Host) { |
| 399 | rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name); |
| 400 | bcopy("HOST 1", p->RIOHosts[Host].Name, 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | p->RIOHosts[Host].Name[5] += Host1; |
| 402 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 403 | rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | ** User process needs the config table - build it from first |
| 410 | ** principles. |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 411 | ** |
| 412 | * FIXME: SMP locking |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 414 | int RIOApel(struct rio_info *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
| 416 | int Host; |
| 417 | int link; |
| 418 | int Rup; |
| 419 | int Next = 0; |
| 420 | struct Map *MapP; |
| 421 | struct Host *HostP; |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 422 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 424 | rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 426 | memset(&p->RIOConnectTable[0], 0, sizeof(struct Map) * TOTAL_MAP_ENTRIES); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 427 | |
| 428 | for (Host = 0; Host < RIO_HOSTS; Host++) { |
| 429 | rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | HostP = &p->RIOHosts[Host]; |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 431 | rio_spin_lock_irqsave(&HostP->HostLock, flags); |
| 432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | MapP = &p->RIOConnectTable[Next++]; |
| 434 | MapP->HostUniqueNum = HostP->UniqueNum; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 435 | if ((HostP->Flags & RUN_STATE) != RC_RUNNING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | continue; |
| 437 | MapP->RtaUniqueNum = 0; |
| 438 | MapP->ID = 0; |
| 439 | MapP->Flags = SLOT_IN_USE; |
| 440 | MapP->SysPort = NO_PORT; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 441 | for (link = 0; link < LINKS_PER_UNIT; link++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | MapP->Topology[link] = HostP->Topology[link]; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 443 | bcopy(HostP->Name, MapP->Name, MAX_NAME_LEN); |
| 444 | for (Rup = 0; Rup < MAX_RUP; Rup++) { |
| 445 | if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | p->RIOConnectTable[Next] = HostP->Mapping[Rup]; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 447 | if (HostP->Mapping[Rup].Flags & SLOT_IN_USE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | p->RIOConnectTable[Next].Flags |= SLOT_IN_USE; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 449 | if (HostP->Mapping[Rup].Flags & SLOT_TENTATIVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 451 | if (HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT; |
| 453 | Next++; |
| 454 | } |
| 455 | } |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 456 | rio_spin_unlock_irqrestore(&HostP->HostLock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | /* |
| 462 | ** config.rio has taken a dislike to one of the gross maps entries. |
| 463 | ** if the entry is suitably inactive, then we can gob on it and remove |
| 464 | ** it from the table. |
| 465 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 466 | int RIODeleteRta(struct rio_info *p, struct Map *MapP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
| 468 | int host, entry, port, link; |
| 469 | int SysPort; |
| 470 | struct Host *HostP; |
| 471 | struct Map *HostMapP; |
| 472 | struct Port *PortP; |
| 473 | int work_done = 0; |
| 474 | unsigned long lock_flags, sem_flags; |
| 475 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 476 | rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 478 | for (host = 0; host < p->RIONumHosts; host++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | HostP = &p->RIOHosts[host]; |
| 480 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 481 | rio_spin_lock_irqsave(&HostP->HostLock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 483 | if ((HostP->Flags & RUN_STATE) != RC_RUNNING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags); |
| 485 | continue; |
| 486 | } |
| 487 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 488 | for (entry = 0; entry < MAX_RUP; entry++) { |
| 489 | if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | HostMapP = &HostP->Mapping[entry]; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 491 | rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 494 | ** Check all four links of the unit are disconnected |
| 495 | */ |
| 496 | for (link = 0; link < LINKS_PER_UNIT; link++) { |
| 497 | if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) { |
| 498 | rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | p->RIOError.Error = UNIT_IS_IN_USE; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 500 | rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | return -EBUSY; |
| 502 | } |
| 503 | } |
| 504 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 505 | ** Slot has been allocated, BUT not booted/routed/ |
| 506 | ** connected/selected or anything else-ed |
| 507 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | SysPort = HostMapP->SysPort; |
| 509 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 510 | if (SysPort != NO_PORT) { |
| 511 | for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | PortP = p->RIOPortp[port]; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 513 | rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 515 | rio_spin_lock_irqsave(&PortP->portSem, sem_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
| 517 | PortP->Mapped = 0; |
| 518 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 519 | if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 521 | rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | PortP->TxBufferIn = PortP->TxBufferOut = 0; |
| 523 | /* What should I do |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 524 | wakeup( &PortP->TxBufferIn ); |
| 525 | wakeup( &PortP->TxBufferOut); |
| 526 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | PortP->InUse = NOT_INUSE; |
| 528 | /* What should I do |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 529 | wakeup( &PortP->InUse ); |
| 530 | signal(PortP->TtyP->t_pgrp,SIGKILL); |
| 531 | ttyflush(PortP->TtyP,(FREAD|FWRITE)); |
| 532 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | PortP->State |= RIO_CLOSING | RIO_DELETED; |
| 534 | } |
| 535 | |
| 536 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 537 | ** For the second slot of a 16 port RTA, the |
| 538 | ** driver needs to reset the changes made to |
| 539 | ** the phb to port mappings in RIORouteRup. |
| 540 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | if (PortP->SecondBlock) { |
| 542 | ushort dest_unit = HostMapP->ID; |
| 543 | ushort dest_port = port - SysPort; |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 544 | u16 *TxPktP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 545 | PKT *Pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 547 | for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 549 | ** *TxPktP is the pointer to the |
| 550 | ** transmit packet on the host card. |
| 551 | ** This needs to be translated into |
| 552 | ** a 32 bit pointer so it can be |
| 553 | ** accessed from the driver. |
| 554 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 555 | Pkt = (PKT *) RIO_PTR(HostP->Caddr, readw(&*TxPktP)); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 556 | rio_dprintk(RIO_DEBUG_TABLE, "Tx packet (%x) destination: Old %x:%x New %x:%x\n", *TxPktP, Pkt->dest_unit, Pkt->dest_port, dest_unit, dest_port); |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 557 | writew(dest_unit, &Pkt->dest_unit); |
| 558 | writew(dest_port, &Pkt->dest_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 560 | rio_dprintk(RIO_DEBUG_TABLE, "Port %d phb destination: Old %x:%x New %x:%x\n", port, PortP->PhbP->destination & 0xff, (PortP->PhbP->destination >> 8) & 0xff, dest_unit, dest_port); |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 561 | writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | } |
| 563 | rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags); |
| 564 | } |
| 565 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 566 | rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n"); |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 567 | memset(HostMapP, 0, sizeof(struct Map)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | work_done++; |
| 569 | } |
| 570 | } |
| 571 | rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags); |
| 572 | } |
| 573 | |
| 574 | /* XXXXX lock me up */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 575 | for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) { |
| 576 | if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) { |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 577 | memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | work_done++; |
| 579 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 580 | if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) { |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 581 | memset(&p->RIOConnectTable[entry], 0, sizeof(struct Map)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | work_done++; |
| 583 | } |
| 584 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 585 | if (work_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | return 0; |
| 587 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 588 | rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | p->RIOError.Error = COULDNT_FIND_ENTRY; |
| 590 | return -ENXIO; |
| 591 | } |
| 592 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 593 | int RIOAssignRta(struct rio_info *p, struct Map *MapP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 595 | int host; |
| 596 | struct Map *HostMapP; |
| 597 | char *sptr; |
| 598 | int link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
| 600 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 601 | rio_dprintk(RIO_DEBUG_TABLE, "Assign entry on host %x, rta %x, ID %d, Sysport %d\n", MapP->HostUniqueNum, MapP->RtaUniqueNum, MapP->ID, (int) MapP->SysPort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 603 | if ((MapP->ID != (ushort) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) { |
| 604 | rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n"); |
| 605 | p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE; |
| 606 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 608 | if (MapP->RtaUniqueNum == 0) { |
| 609 | rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n"); |
| 610 | p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO; |
| 611 | return -EINVAL; |
| 612 | } |
| 613 | if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) { |
| 614 | rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA); |
| 615 | p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; |
| 616 | return -EINVAL; |
| 617 | } |
| 618 | if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) { |
| 619 | rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort); |
| 620 | p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; |
| 621 | return -EINVAL; |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | ** Copy the name across to the map entry. |
| 626 | */ |
| 627 | MapP->Name[MAX_NAME_LEN - 1] = '\0'; |
| 628 | sptr = MapP->Name; |
| 629 | while (*sptr) { |
| 630 | if (*sptr < ' ' || *sptr > '~') { |
| 631 | rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n"); |
| 632 | p->RIOError.Error = BAD_CHARACTER_IN_NAME; |
| 633 | return -EINVAL; |
| 634 | } |
| 635 | sptr++; |
| 636 | } |
| 637 | |
| 638 | for (host = 0; host < p->RIONumHosts; host++) { |
| 639 | if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) { |
| 640 | if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) { |
| 641 | p->RIOError.Error = HOST_NOT_RUNNING; |
| 642 | return -ENXIO; |
| 643 | } |
| 644 | |
| 645 | /* |
| 646 | ** Now we have a host we need to allocate an ID |
| 647 | ** if the entry does not already have one. |
| 648 | */ |
| 649 | if (MapP->ID == (ushort) - 1) { |
| 650 | int nNewID; |
| 651 | |
| 652 | rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name); |
| 653 | /* |
| 654 | ** The idea here is to allow RTA's to be assigned |
| 655 | ** before they actually appear on the network. |
| 656 | ** This allows the addition of RTA's without having |
| 657 | ** to plug them in. |
| 658 | ** What we do is: |
| 659 | ** - Find a free ID and allocate it to the RTA. |
| 660 | ** - If this map entry is the second half of a |
| 661 | ** 16 port entry then find the other half and |
| 662 | ** make sure the 2 cross reference each other. |
| 663 | */ |
| 664 | if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) { |
| 665 | p->RIOError.Error = COULDNT_FIND_ENTRY; |
| 666 | return -EBUSY; |
| 667 | } |
| 668 | MapP->ID = (ushort) nNewID + 1; |
| 669 | rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID); |
| 670 | HostMapP = &p->RIOHosts[host].Mapping[nNewID]; |
| 671 | HostMapP->RtaUniqueNum = MapP->RtaUniqueNum; |
| 672 | HostMapP->HostUniqueNum = MapP->HostUniqueNum; |
| 673 | HostMapP->ID = MapP->ID; |
| 674 | for (link = 0; link < LINKS_PER_UNIT; link++) { |
| 675 | HostMapP->Topology[link].Unit = ROUTE_DISCONNECT; |
| 676 | HostMapP->Topology[link].Link = NO_LINK; |
| 677 | } |
| 678 | if (MapP->Flags & RTA16_SECOND_SLOT) { |
| 679 | int unit; |
| 680 | |
| 681 | for (unit = 0; unit < MAX_RUP; unit++) |
| 682 | if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum) |
| 683 | break; |
| 684 | if (unit == MAX_RUP) { |
| 685 | p->RIOError.Error = COULDNT_FIND_ENTRY; |
| 686 | return -EBUSY; |
| 687 | } |
| 688 | HostMapP->Flags |= RTA16_SECOND_SLOT; |
| 689 | HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID; |
| 690 | p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID; |
| 691 | rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1]; |
| 696 | |
| 697 | if (HostMapP->Flags & SLOT_IN_USE) { |
| 698 | rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID); |
| 699 | p->RIOError.Error = ID_ALREADY_IN_USE; |
| 700 | return -EBUSY; |
| 701 | } |
| 702 | |
| 703 | /* |
| 704 | ** Assign the sys ports and the name, and mark the slot as |
| 705 | ** being in use. |
| 706 | */ |
| 707 | HostMapP->SysPort = MapP->SysPort; |
| 708 | if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) |
| 709 | CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN); |
| 710 | HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED; |
| 711 | #ifdef NEED_TO_FIX |
| 712 | RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]); |
| 713 | #endif |
| 714 | if (MapP->Flags & RTA16_SECOND_SLOT) |
| 715 | HostMapP->Flags |= RTA16_SECOND_SLOT; |
| 716 | |
| 717 | RIOReMapPorts(p, &p->RIOHosts[host], HostMapP); |
| 718 | /* |
| 719 | ** Adjust 2nd block of 8 phbs |
| 720 | */ |
| 721 | if (MapP->Flags & RTA16_SECOND_SLOT) |
| 722 | RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1); |
| 723 | |
| 724 | if (HostMapP->SysPort != NO_PORT) { |
| 725 | if (HostMapP->SysPort < p->RIOFirstPortsBooted) |
| 726 | p->RIOFirstPortsBooted = HostMapP->SysPort; |
| 727 | if (HostMapP->SysPort > p->RIOLastPortsBooted) |
| 728 | p->RIOLastPortsBooted = HostMapP->SysPort; |
| 729 | } |
| 730 | if (MapP->Flags & RTA16_SECOND_SLOT) |
| 731 | rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name); |
| 732 | else |
| 733 | rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name); |
| 734 | return 0; |
| 735 | } |
| 736 | } |
| 737 | p->RIOError.Error = UNKNOWN_HOST_NUMBER; |
| 738 | rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum); |
| 739 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 743 | int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | { |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 745 | struct Port *PortP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | uint SubEnt; |
| 747 | uint HostPort; |
| 748 | uint SysPort; |
| 749 | ushort RtaType; |
| 750 | unsigned long flags; |
| 751 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 752 | rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 755 | ** We need to tell the UnixRups which sysport the rup corresponds to |
| 756 | */ |
| 757 | HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 759 | if (HostMapP->SysPort == NO_PORT) |
| 760 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
| 762 | RtaType = GetUnitType(HostMapP->RtaUniqueNum); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 763 | rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n", (int) HostMapP->SysPort, (int) HostMapP->SysPort + PORTS_PER_RTA - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
| 765 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 766 | ** now map each of its eight ports |
| 767 | */ |
| 768 | for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) { |
| 769 | rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort); |
| 770 | SysPort = HostMapP->SysPort + SubEnt; /* portnumber within system */ |
| 771 | /* portnumber on host */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 773 | HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt; |
| 774 | |
| 775 | rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | PortP = p->RIOPortp[SysPort]; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 777 | rio_dprintk(RIO_DEBUG_TABLE, "Map port\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
| 779 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 780 | ** Point at all the real neat data structures |
| 781 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 783 | PortP->HostP = HostP; |
| 784 | PortP->Caddr = HostP->Caddr; |
| 785 | |
| 786 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 787 | ** The PhbP cannot be filled in yet |
| 788 | ** unless the host has been booted |
| 789 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | if ((HostP->Flags & RUN_STATE) == RC_RUNNING) { |
| 791 | struct PHB *PhbP = PortP->PhbP = &HostP->PhbP[HostPort]; |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 792 | PortP->TxAdd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_add)); |
| 793 | PortP->TxStart = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_start)); |
| 794 | PortP->TxEnd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_end)); |
| 795 | PortP->RxRemove = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_remove)); |
| 796 | PortP->RxStart = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_start)); |
| 797 | PortP->RxEnd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_end)); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 798 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | PortP->PhbP = NULL; |
| 800 | |
| 801 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 802 | ** port related flags |
| 803 | */ |
| 804 | PortP->HostPort = HostPort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 806 | ** For each part of a 16 port RTA, RupNum is ID - 1. |
| 807 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | PortP->RupNum = HostMapP->ID - 1; |
| 809 | if (HostMapP->Flags & RTA16_SECOND_SLOT) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 810 | PortP->ID2 = HostMapP->ID2 - 1; |
| 811 | PortP->SecondBlock = TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } else { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 813 | PortP->ID2 = 0; |
| 814 | PortP->SecondBlock = FALSE; |
| 815 | } |
| 816 | PortP->RtaUniqueNum = HostMapP->RtaUniqueNum; |
| 817 | |
| 818 | /* |
| 819 | ** If the port was already mapped then thats all we need to do. |
| 820 | */ |
| 821 | if (PortP->Mapped) { |
| 822 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 823 | continue; |
| 824 | } else |
| 825 | HostMapP->Flags &= ~RTA_NEWBOOT; |
| 826 | |
| 827 | PortP->State = 0; |
| 828 | PortP->Config = 0; |
| 829 | /* |
| 830 | ** Check out the module type - if it is special (read only etc.) |
| 831 | ** then we need to set flags in the PortP->Config. |
| 832 | ** Note: For 16 port RTA, all ports are of the same type. |
| 833 | */ |
| 834 | if (RtaType == TYPE_RTA16) { |
| 835 | PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE]; |
| 836 | } else { |
| 837 | if (SubEnt < PORTS_PER_MODULE) |
| 838 | PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | else |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 840 | PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 844 | ** more port related flags |
| 845 | */ |
| 846 | PortP->PortState = 0; |
| 847 | PortP->ModemLines = 0; |
| 848 | PortP->ModemState = 0; |
| 849 | PortP->CookMode = COOK_WELL; |
| 850 | PortP->ParamSem = 0; |
| 851 | PortP->FlushCmdBodge = 0; |
| 852 | PortP->WflushFlag = 0; |
| 853 | PortP->MagicFlags = 0; |
| 854 | PortP->Lock = 0; |
| 855 | PortP->Store = 0; |
| 856 | PortP->FirstOpen = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
| 858 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 859 | ** Buffers 'n things |
| 860 | */ |
| 861 | PortP->RxDataStart = 0; |
| 862 | PortP->Cor2Copy = 0; |
| 863 | PortP->Name = &HostMapP->Name[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | PortP->statsGather = 0; |
| 865 | PortP->txchars = 0; |
| 866 | PortP->rxchars = 0; |
| 867 | PortP->opens = 0; |
| 868 | PortP->closes = 0; |
| 869 | PortP->ioctls = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 870 | if (PortP->TxRingBuffer) |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 871 | memset(PortP->TxRingBuffer, 0, p->RIOBufferSize); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 872 | else if (p->RIOBufferSize) { |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 873 | PortP->TxRingBuffer = kmalloc(p->RIOBufferSize, GFP_KERNEL); |
| 874 | memset(PortP->TxRingBuffer, 0, p->RIOBufferSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 876 | PortP->TxBufferOut = 0; |
| 877 | PortP->TxBufferIn = 0; |
| 878 | PortP->Debug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 880 | ** LastRxTgl stores the state of the rx toggle bit for this |
| 881 | ** port, to be compared with the state of the next pkt received. |
| 882 | ** If the same, we have received the same rx pkt from the RTA |
| 883 | ** twice. Initialise to a value not equal to PHB_RX_TGL or 0. |
| 884 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 885 | PortP->LastRxTgl = ~(u8) PHB_RX_TGL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
| 887 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 888 | ** and mark the port as usable |
| 889 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | PortP->Mapped = 1; |
| 891 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 892 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 893 | if (HostMapP->SysPort < p->RIOFirstPortsMapped) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | p->RIOFirstPortsMapped = HostMapP->SysPort; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 895 | if (HostMapP->SysPort > p->RIOLastPortsMapped) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | p->RIOLastPortsMapped = HostMapP->SysPort; |
| 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 901 | int RIOChangeName(struct rio_info *p, struct Map *MapP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | { |
| 903 | int host; |
| 904 | struct Map *HostMapP; |
| 905 | char *sptr; |
| 906 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 907 | rio_dprintk(RIO_DEBUG_TABLE, "Change name entry on host %x, rta %x, ID %d, Sysport %d\n", MapP->HostUniqueNum, MapP->RtaUniqueNum, MapP->ID, (int) MapP->SysPort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 909 | if (MapP->ID > MAX_RUP) { |
| 910 | rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE; |
| 912 | return -EINVAL; |
| 913 | } |
| 914 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 915 | MapP->Name[MAX_NAME_LEN - 1] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | sptr = MapP->Name; |
| 917 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 918 | while (*sptr) { |
| 919 | if (*sptr < ' ' || *sptr > '~') { |
| 920 | rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | p->RIOError.Error = BAD_CHARACTER_IN_NAME; |
| 922 | return -EINVAL; |
| 923 | } |
| 924 | sptr++; |
| 925 | } |
| 926 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 927 | for (host = 0; host < p->RIONumHosts; host++) { |
| 928 | if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) { |
| 929 | if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | p->RIOError.Error = HOST_NOT_RUNNING; |
| 931 | return -ENXIO; |
| 932 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 933 | if (MapP->ID == 0) { |
| 934 | CCOPY(MapP->Name, p->RIOHosts[host].Name, MAX_NAME_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | return 0; |
| 936 | } |
| 937 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 938 | HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 940 | if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | p->RIOError.Error = RTA_NUMBER_WRONG; |
| 942 | return -ENXIO; |
| 943 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 944 | CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | return 0; |
| 946 | } |
| 947 | } |
| 948 | p->RIOError.Error = UNKNOWN_HOST_NUMBER; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 949 | rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | return -ENXIO; |
| 951 | } |