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