[NETFILTER]: Move ip6_masked_addrcmp to include/net/ipv6.h
[linux-2.6/verdex.git] / drivers / char / rio / rioinit.c
blob0d44ef464e6b28c5cdfcd5532b3d01ab6f28d3b6
1 /*
2 ** -----------------------------------------------------------------------------
3 **
4 ** Perle Specialix driver for Linux
5 ** Ported from existing RIO Driver for SCO sources.
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
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.
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.
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.
23 ** Module : rioinit.c
24 ** SID : 1.3
25 ** Last Modified : 11/6/98 10:33:43
26 ** Retrieved : 11/6/98 10:33:49
28 ** ident @(#)rioinit.c 1.3
30 ** -----------------------------------------------------------------------------
32 #ifdef SCCS_LABELS
33 static char *_rioinit_c_sccs_ = "@(#)rioinit.c 1.3";
34 #endif
36 #include <linux/config.h>
37 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/errno.h>
40 #include <linux/delay.h>
41 #include <asm/io.h>
42 #include <asm/system.h>
43 #include <asm/string.h>
44 #include <asm/semaphore.h>
45 #include <asm/uaccess.h>
47 #include <linux/termios.h>
48 #include <linux/serial.h>
50 #include <linux/generic_serial.h>
53 #include "linux_compat.h"
54 #include "typdef.h"
55 #include "pkt.h"
56 #include "daemon.h"
57 #include "rio.h"
58 #include "riospace.h"
59 #include "top.h"
60 #include "cmdpkt.h"
61 #include "map.h"
62 #include "riotypes.h"
63 #include "rup.h"
64 #include "port.h"
65 #include "riodrvr.h"
66 #include "rioinfo.h"
67 #include "func.h"
68 #include "errors.h"
69 #include "pci.h"
71 #include "parmmap.h"
72 #include "unixrup.h"
73 #include "board.h"
74 #include "host.h"
75 #include "error.h"
76 #include "phb.h"
77 #include "link.h"
78 #include "cmdblk.h"
79 #include "route.h"
80 #include "control.h"
81 #include "cirrus.h"
82 #include "rioioctl.h"
83 #include "rio_linux.h"
85 #undef bcopy
86 #define bcopy rio_pcicopy
88 int RIOPCIinit(struct rio_info *p, int Mode);
90 static int RIOScrub(int, BYTE *, int);
93 /**
94 ** RIOAssignAT :
96 ** Fill out the fields in the p->RIOHosts structure now we know we know
97 ** we have a board present.
99 ** bits < 0 indicates 8 bit operation requested,
100 ** bits > 0 indicates 16 bit operation.
103 RIOAssignAT(p, Base, virtAddr, mode)
104 struct rio_info * p;
105 int Base;
106 caddr_t virtAddr;
107 int mode;
109 int bits;
110 struct DpRam *cardp = (struct DpRam *)virtAddr;
112 if ((Base < ONE_MEG) || (mode & BYTE_ACCESS_MODE))
113 bits = BYTE_OPERATION;
114 else
115 bits = WORD_OPERATION;
118 ** Board has passed its scrub test. Fill in all the
119 ** transient stuff.
121 p->RIOHosts[p->RIONumHosts].Caddr = virtAddr;
122 p->RIOHosts[p->RIONumHosts].CardP = (struct DpRam *)virtAddr;
125 ** Revision 01 AT host cards don't support WORD operations,
127 if ( RBYTE(cardp->DpRevision) == 01 )
128 bits = BYTE_OPERATION;
130 p->RIOHosts[p->RIONumHosts].Type = RIO_AT;
131 p->RIOHosts[p->RIONumHosts].Copy = bcopy;
132 /* set this later */
133 p->RIOHosts[p->RIONumHosts].Slot = -1;
134 p->RIOHosts[p->RIONumHosts].Mode = SLOW_LINKS | SLOW_AT_BUS | bits;
135 WBYTE(p->RIOHosts[p->RIONumHosts].Control,
136 BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
137 p->RIOHosts[p->RIONumHosts].Mode |
138 INTERRUPT_DISABLE );
139 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
140 WBYTE(p->RIOHosts[p->RIONumHosts].Control,
141 BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
142 p->RIOHosts[p->RIONumHosts].Mode |
143 INTERRUPT_DISABLE );
144 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
145 p->RIOHosts[p->RIONumHosts].UniqueNum =
146 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0])&0xFF)<<0)|
147 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1])&0xFF)<<8)|
148 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2])&0xFF)<<16)|
149 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3])&0xFF)<<24);
150 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Uniquenum 0x%x\n",p->RIOHosts[p->RIONumHosts].UniqueNum);
152 p->RIONumHosts++;
153 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Tests Passed at 0x%x\n", Base);
154 return(1);
157 static uchar val[] = {
158 #ifdef VERY_LONG_TEST
159 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
160 0xa5, 0xff, 0x5a, 0x00, 0xff, 0xc9, 0x36,
161 #endif
162 0xff, 0x00, 0x00 };
164 #define TEST_END sizeof(val)
167 ** RAM test a board.
168 ** Nothing too complicated, just enough to check it out.
171 RIOBoardTest(paddr, caddr, type, slot)
172 paddr_t paddr;
173 caddr_t caddr;
174 uchar type;
175 int slot;
177 struct DpRam *DpRam = (struct DpRam *)caddr;
178 char *ram[4];
179 int size[4];
180 int op, bank;
181 int nbanks;
183 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Reset host type=%d, DpRam=0x%x, slot=%d\n",
184 type,(int)DpRam, slot);
186 RIOHostReset(type, DpRam, slot);
189 ** Scrub the memory. This comes in several banks:
190 ** DPsram1 - 7000h bytes
191 ** DPsram2 - 200h bytes
192 ** DPsram3 - 7000h bytes
193 ** scratch - 1000h bytes
196 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Setup ram/size arrays\n");
198 size[0] = DP_SRAM1_SIZE;
199 size[1] = DP_SRAM2_SIZE;
200 size[2] = DP_SRAM3_SIZE;
201 size[3] = DP_SCRATCH_SIZE;
203 ram[0] = (char *)&DpRam->DpSram1[0];
204 ram[1] = (char *)&DpRam->DpSram2[0];
205 ram[2] = (char *)&DpRam->DpSram3[0];
206 nbanks = (type == RIO_PCI) ? 3 : 4;
207 if (nbanks == 4)
208 ram[3] = (char *)&DpRam->DpScratch[0];
211 if (nbanks == 3) {
212 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Memory: 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x)\n",
213 (int)ram[0], size[0], (int)ram[1], size[1], (int)ram[2], size[2]);
214 } else {
215 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x)\n",
216 (int)ram[0], size[0], (int)ram[1], size[1], (int)ram[2], size[2], (int)ram[3],
217 size[3]);
221 ** This scrub operation will test for crosstalk between
222 ** banks. TEST_END is a magic number, and relates to the offset
223 ** within the 'val' array used by Scrub.
225 for (op=0; op<TEST_END; op++) {
226 for (bank=0; bank<nbanks; bank++) {
227 if (RIOScrub(op, (BYTE *)ram[bank], size[bank]) == RIO_FAIL) {
228 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: RIOScrub band %d, op %d failed\n",
229 bank, op);
230 return RIO_FAIL;
235 rio_dprintk (RIO_DEBUG_INIT, "Test completed\n");
236 return RIO_SUCCESS;
241 ** Scrub an area of RAM.
242 ** Define PRETEST and POSTTEST for a more thorough checking of the
243 ** state of the memory.
244 ** Call with op set to an index into the above 'val' array to determine
245 ** which value will be written into memory.
246 ** Call with op set to zero means that the RAM will not be read and checked
247 ** before it is written.
248 ** Call with op not zero, and the RAM will be read and compated with val[op-1]
249 ** to check that the data from the previous phase was retained.
251 static int
252 RIOScrub(op, ram, size)
253 int op;
254 BYTE * ram;
255 int size;
257 int off;
258 unsigned char oldbyte;
259 unsigned char newbyte;
260 unsigned char invbyte;
261 unsigned short oldword;
262 unsigned short newword;
263 unsigned short invword;
264 unsigned short swapword;
266 if (op) {
267 oldbyte = val[op-1];
268 oldword = oldbyte | (oldbyte<<8);
269 } else
270 oldbyte = oldword = 0; /* Tell the compiler we've initilalized them. */
271 newbyte = val[op];
272 newword = newbyte | (newbyte<<8);
273 invbyte = ~newbyte;
274 invword = invbyte | (invbyte<<8);
277 ** Check that the RAM contains the value that should have been left there
278 ** by the previous test (not applicable for pass zero)
280 if (op) {
281 for (off=0; off<size; off++) {
282 if (RBYTE(ram[off]) != oldbyte) {
283 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Pre Check 1: BYTE at offset 0x%x should have been=%x, was=%x\n", off, oldbyte, RBYTE(ram[off]));
284 return RIO_FAIL;
287 for (off=0; off<size; off+=2) {
288 if (*(ushort *)&ram[off] != oldword) {
289 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: WORD at offset 0x%x should have been=%x, was=%x\n",off,oldword,*(ushort *)&ram[off]);
290 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
291 return RIO_FAIL;
297 ** Now write the INVERSE of the test data into every location, using
298 ** BYTE write operations, first checking before each byte is written
299 ** that the location contains the old value still, and checking after
300 ** the write that the location contains the data specified - this is
301 ** the BYTE read/write test.
303 for (off=0; off<size; off++) {
304 if (op && (RBYTE(ram[off]) != oldbyte)) {
305 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Pre Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, oldbyte, RBYTE(ram[off]));
306 return RIO_FAIL;
308 WBYTE(ram[off],invbyte);
309 if (RBYTE(ram[off]) != invbyte) {
310 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Inv Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, invbyte, RBYTE(ram[off]));
311 return RIO_FAIL;
316 ** now, use WORD operations to write the test value into every location,
317 ** check as before that the location contains the previous test value
318 ** before overwriting, and that it contains the data value written
319 ** afterwards.
320 ** This is the WORD operation test.
322 for (off=0; off<size; off+=2) {
323 if (*(ushort *)&ram[off] != invword) {
324 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: WORD at offset 0x%x should have been=%x, was=%x\n", off, invword, *(ushort *)&ram[off]);
325 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
326 return RIO_FAIL;
329 *(ushort *)&ram[off] = newword;
330 if ( *(ushort *)&ram[off] != newword ) {
331 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, newword, *(ushort *)&ram[off]);
332 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 1: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
333 return RIO_FAIL;
338 ** now run through the block of memory again, first in byte mode
339 ** then in word mode, and check that all the locations contain the
340 ** required test data.
342 for (off=0; off<size; off++) {
343 if (RBYTE(ram[off]) != newbyte) {
344 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Byte Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, RBYTE(ram[off]));
345 return RIO_FAIL;
349 for (off=0; off<size; off+=2) {
350 if ( *(ushort *)&ram[off] != newword ) {
351 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 2: WORD at offset 0x%x should have been=%x, was=%x\n", off, newword, *(ushort *)&ram[off]);
352 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 2: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
353 return RIO_FAIL;
358 ** time to check out byte swapping errors
360 swapword = invbyte | (newbyte << 8);
362 for (off=0; off<size; off+=2) {
363 WBYTE(ram[off],invbyte);
364 WBYTE(ram[off+1],newbyte);
367 for ( off=0; off<size; off+=2 ) {
368 if (*(ushort *)&ram[off] != swapword) {
369 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, swapword, *((ushort *)&ram[off]));
370 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
371 return RIO_FAIL;
373 *((ushort *)&ram[off]) = ~swapword;
376 for (off=0; off<size; off+=2) {
377 if (RBYTE(ram[off]) != newbyte) {
378 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, RBYTE(ram[off]));
379 return RIO_FAIL;
381 if (RBYTE(ram[off+1]) != invbyte) {
382 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off+1, invbyte, RBYTE(ram[off+1]));
383 return RIO_FAIL;
385 *((ushort *)&ram[off]) = newword;
387 return RIO_SUCCESS;
392 RIODefaultName(p, HostP, UnitId)
393 struct rio_info * p;
394 struct Host * HostP;
395 uint UnitId;
397 bcopy("UNKNOWN RTA X-XX",HostP->Mapping[UnitId].Name,17);
398 HostP->Mapping[UnitId].Name[12]='1'+(HostP-p->RIOHosts);
399 if ((UnitId+1) > 9) {
400 HostP->Mapping[UnitId].Name[14]='0'+((UnitId+1)/10);
401 HostP->Mapping[UnitId].Name[15]='0'+((UnitId+1)%10);
403 else {
404 HostP->Mapping[UnitId].Name[14]='1'+UnitId;
405 HostP->Mapping[UnitId].Name[15]=0;
407 return 0;
410 #define RIO_RELEASE "Linux"
411 #define RELEASE_ID "1.0"
413 static struct rioVersion stVersion;
415 struct rioVersion *
416 RIOVersid(void)
418 strlcpy(stVersion.version, "RIO driver for linux V1.0",
419 sizeof(stVersion.version));
420 strlcpy(stVersion.buildDate, __DATE__,
421 sizeof(stVersion.buildDate));
423 return &stVersion;
426 void
427 RIOHostReset(Type, DpRamP, Slot)
428 uint Type;
429 volatile struct DpRam *DpRamP;
430 uint Slot;
433 ** Reset the Tpu
435 rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: type 0x%x", Type);
436 switch ( Type ) {
437 case RIO_AT:
438 rio_dprintk (RIO_DEBUG_INIT, " (RIO_AT)\n");
439 WBYTE(DpRamP->DpControl, BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
440 INTERRUPT_DISABLE | BYTE_OPERATION |
441 SLOW_LINKS | SLOW_AT_BUS);
442 WBYTE(DpRamP->DpResetTpu, 0xFF);
443 udelay(3);
445 rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: Don't know if it worked. Try reset again\n");
446 WBYTE(DpRamP->DpControl, BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
447 INTERRUPT_DISABLE | BYTE_OPERATION |
448 SLOW_LINKS | SLOW_AT_BUS);
449 WBYTE(DpRamP->DpResetTpu, 0xFF);
450 udelay(3);
451 break;
452 case RIO_PCI:
453 rio_dprintk (RIO_DEBUG_INIT, " (RIO_PCI)\n");
454 DpRamP->DpControl = RIO_PCI_BOOT_FROM_RAM;
455 DpRamP->DpResetInt = 0xFF;
456 DpRamP->DpResetTpu = 0xFF;
457 udelay(100);
458 /* for (i=0; i<6000; i++); */
459 /* suspend( 3 ); */
460 break;
461 default:
462 rio_dprintk (RIO_DEBUG_INIT, " (UNKNOWN)\n");
463 break;
465 return;