blob: 1d73c4646bbd2a322066741f6d2101d79fb2b787 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 : rioinit.c
24** SID : 1.3
25** Last Modified : 11/6/98 10:33:43
26** Retrieved : 11/6/98 10:33:49
27**
28** ident @(#)rioinit.c 1.3
29**
30** -----------------------------------------------------------------------------
31*/
32#ifdef SCCS_LABELS
33static char *_rioinit_c_sccs_ = "@(#)rioinit.c 1.3";
34#endif
35
36#include <linux/config.h>
37#include <linux/module.h>
38#include <linux/slab.h>
39#include <linux/errno.h>
Adrian Bunk97998d8f2005-06-25 14:59:35 -070040#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/io.h>
42#include <asm/system.h>
43#include <asm/string.h>
44#include <asm/semaphore.h>
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 "typdef.h"
55#include "pkt.h"
56#include "daemon.h"
57#include "rio.h"
58#include "riospace.h"
59#include "top.h"
60#include "cmdpkt.h"
61#include "map.h"
62#include "riotypes.h"
63#include "rup.h"
64#include "port.h"
65#include "riodrvr.h"
66#include "rioinfo.h"
67#include "func.h"
68#include "errors.h"
69#include "pci.h"
70
71#include "parmmap.h"
72#include "unixrup.h"
73#include "board.h"
74#include "host.h"
75#include "error.h"
76#include "phb.h"
77#include "link.h"
78#include "cmdblk.h"
79#include "route.h"
80#include "control.h"
81#include "cirrus.h"
82#include "rioioctl.h"
83#include "rio_linux.h"
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085int RIOPCIinit(struct rio_info *p, int Mode);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static int RIOScrub(int, BYTE *, int);
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90/**
91** RIOAssignAT :
92**
93** Fill out the fields in the p->RIOHosts structure now we know we know
94** we have a board present.
95**
96** bits < 0 indicates 8 bit operation requested,
97** bits > 0 indicates 16 bit operation.
98*/
Alan Cox00d83a52006-03-24 03:18:28 -080099
100int RIOAssignAT(struct rio_info *p, int Base, caddr_t virtAddr, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 int bits;
103 struct DpRam *cardp = (struct DpRam *)virtAddr;
104
105 if ((Base < ONE_MEG) || (mode & BYTE_ACCESS_MODE))
106 bits = BYTE_OPERATION;
107 else
108 bits = WORD_OPERATION;
109
110 /*
111 ** Board has passed its scrub test. Fill in all the
112 ** transient stuff.
113 */
114 p->RIOHosts[p->RIONumHosts].Caddr = virtAddr;
115 p->RIOHosts[p->RIONumHosts].CardP = (struct DpRam *)virtAddr;
116
117 /*
118 ** Revision 01 AT host cards don't support WORD operations,
119 */
Alan Cox00d83a52006-03-24 03:18:28 -0800120 if (readb(&cardp->DpRevision) == 01)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 bits = BYTE_OPERATION;
122
123 p->RIOHosts[p->RIONumHosts].Type = RIO_AT;
Alan Cox00d83a52006-03-24 03:18:28 -0800124 p->RIOHosts[p->RIONumHosts].Copy = rio_copy_to_card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 /* set this later */
126 p->RIOHosts[p->RIONumHosts].Slot = -1;
127 p->RIOHosts[p->RIONumHosts].Mode = SLOW_LINKS | SLOW_AT_BUS | bits;
Alan Cox00d83a52006-03-24 03:18:28 -0800128 writeb(BOOT_FROM_RAM | EXTERNAL_BUS_OFF | p->RIOHosts[p->RIONumHosts].Mode | INTERRUPT_DISABLE ,
129 &p->RIOHosts[p->RIONumHosts].Control);
130 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
131 writeb(BOOT_FROM_RAM | EXTERNAL_BUS_OFF | p->RIOHosts[p->RIONumHosts].Mode | INTERRUPT_DISABLE,
132 &p->RIOHosts[p->RIONumHosts].Control);
133 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -0800135 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0])&0xFF)<<0)|
136 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1])&0xFF)<<8)|
137 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2])&0xFF)<<16)|
138 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3])&0xFF)<<24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Uniquenum 0x%x\n",p->RIOHosts[p->RIONumHosts].UniqueNum);
140
141 p->RIONumHosts++;
142 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Tests Passed at 0x%x\n", Base);
143 return(1);
144}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Alan Cox00d83a52006-03-24 03:18:28 -0800146static u8 val[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#ifdef VERY_LONG_TEST
148 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
149 0xa5, 0xff, 0x5a, 0x00, 0xff, 0xc9, 0x36,
150#endif
151 0xff, 0x00, 0x00 };
152
153#define TEST_END sizeof(val)
154
155/*
156** RAM test a board.
157** Nothing too complicated, just enough to check it out.
158*/
Alan Cox00d83a52006-03-24 03:18:28 -0800159int RIOBoardTest(paddr_t paddr, caddr_t caddr, unsigned char type, int slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
161 struct DpRam *DpRam = (struct DpRam *)caddr;
162 char *ram[4];
163 int size[4];
164 int op, bank;
165 int nbanks;
166
Alan Cox00d83a52006-03-24 03:18:28 -0800167 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Reset host type=%d, DpRam=0x%p, slot=%d\n",
168 type, DpRam, slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 RIOHostReset(type, DpRam, slot);
171
172 /*
173 ** Scrub the memory. This comes in several banks:
174 ** DPsram1 - 7000h bytes
175 ** DPsram2 - 200h bytes
176 ** DPsram3 - 7000h bytes
177 ** scratch - 1000h bytes
178 */
179
180 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Setup ram/size arrays\n");
181
182 size[0] = DP_SRAM1_SIZE;
183 size[1] = DP_SRAM2_SIZE;
184 size[2] = DP_SRAM3_SIZE;
185 size[3] = DP_SCRATCH_SIZE;
186
187 ram[0] = (char *)&DpRam->DpSram1[0];
188 ram[1] = (char *)&DpRam->DpSram2[0];
189 ram[2] = (char *)&DpRam->DpSram3[0];
190 nbanks = (type == RIO_PCI) ? 3 : 4;
191 if (nbanks == 4)
192 ram[3] = (char *)&DpRam->DpScratch[0];
193
194
195 if (nbanks == 3) {
Alan Cox00d83a52006-03-24 03:18:28 -0800196 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Memory: 0x%p(0x%x), 0x%p(0x%x), 0x%p(0x%x)\n",
197 ram[0], size[0], ram[1], size[1], ram[2], size[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 } else {
Alan Cox00d83a52006-03-24 03:18:28 -0800199 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: 0x%p(0x%x), 0x%p(0x%x), 0x%p(0x%x), 0x%p(0x%x)\n",
200 ram[0], size[0], ram[1], size[1], ram[2], size[2], ram[3], size[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
202
203 /*
204 ** This scrub operation will test for crosstalk between
205 ** banks. TEST_END is a magic number, and relates to the offset
206 ** within the 'val' array used by Scrub.
207 */
208 for (op=0; op<TEST_END; op++) {
209 for (bank=0; bank<nbanks; bank++) {
210 if (RIOScrub(op, (BYTE *)ram[bank], size[bank]) == RIO_FAIL) {
211 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: RIOScrub band %d, op %d failed\n",
212 bank, op);
213 return RIO_FAIL;
214 }
215 }
216 }
217
218 rio_dprintk (RIO_DEBUG_INIT, "Test completed\n");
219 return RIO_SUCCESS;
220}
221
222
223/*
224** Scrub an area of RAM.
225** Define PRETEST and POSTTEST for a more thorough checking of the
226** state of the memory.
227** Call with op set to an index into the above 'val' array to determine
228** which value will be written into memory.
229** Call with op set to zero means that the RAM will not be read and checked
230** before it is written.
231** Call with op not zero, and the RAM will be read and compated with val[op-1]
232** to check that the data from the previous phase was retained.
233*/
Alan Cox00d83a52006-03-24 03:18:28 -0800234
235static int RIOScrub(int op, BYTE *ram, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Alan Cox00d83a52006-03-24 03:18:28 -0800237 int off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 unsigned char oldbyte;
239 unsigned char newbyte;
240 unsigned char invbyte;
241 unsigned short oldword;
242 unsigned short newword;
243 unsigned short invword;
244 unsigned short swapword;
245
246 if (op) {
247 oldbyte = val[op-1];
248 oldword = oldbyte | (oldbyte<<8);
249 } else
250 oldbyte = oldword = 0; /* Tell the compiler we've initilalized them. */
251 newbyte = val[op];
252 newword = newbyte | (newbyte<<8);
253 invbyte = ~newbyte;
254 invword = invbyte | (invbyte<<8);
255
256 /*
257 ** Check that the RAM contains the value that should have been left there
258 ** by the previous test (not applicable for pass zero)
259 */
260 if (op) {
261 for (off=0; off<size; off++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800262 if (readb(ram + off) != oldbyte) {
263 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, readb(ram + off));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return RIO_FAIL;
265 }
266 }
267 for (off=0; off<size; off+=2) {
Alan Cox00d83a52006-03-24 03:18:28 -0800268 if (readw(ram + off) != oldword) {
269 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: WORD at offset 0x%x should have been=%x, was=%x\n",off,oldword, readw(ram + off));
270 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, readb(ram + off), off+1, readb(ram+off+1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 return RIO_FAIL;
272 }
273 }
274 }
275
276 /*
277 ** Now write the INVERSE of the test data into every location, using
278 ** BYTE write operations, first checking before each byte is written
279 ** that the location contains the old value still, and checking after
280 ** the write that the location contains the data specified - this is
281 ** the BYTE read/write test.
282 */
283 for (off=0; off<size; off++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800284 if (op && (readb(ram + off) != oldbyte)) {
285 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, readb(ram + off));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 return RIO_FAIL;
287 }
Alan Cox00d83a52006-03-24 03:18:28 -0800288 writeb(invbyte, ram + off);
289 if (readb(ram + off) != invbyte) {
290 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Inv Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, invbyte, readb(ram + off));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 return RIO_FAIL;
292 }
293 }
294
295 /*
296 ** now, use WORD operations to write the test value into every location,
297 ** check as before that the location contains the previous test value
298 ** before overwriting, and that it contains the data value written
299 ** afterwards.
300 ** This is the WORD operation test.
301 */
302 for (off=0; off<size; off+=2) {
Alan Cox00d83a52006-03-24 03:18:28 -0800303 if (readw(ram + off) != invword) {
304 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: WORD at offset 0x%x should have been=%x, was=%x\n", off, invword, readw(ram + off));
305 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, readb(ram + off), off+1, readb(ram+off+1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 return RIO_FAIL;
307 }
308
Alan Cox00d83a52006-03-24 03:18:28 -0800309 writew(newword, ram + off);
310 if ( readw(ram + off) != newword ) {
311 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, readw(ram + off));
312 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, readb(ram + off), off+1, readb(ram + off + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 return RIO_FAIL;
314 }
315 }
316
317 /*
318 ** now run through the block of memory again, first in byte mode
319 ** then in word mode, and check that all the locations contain the
320 ** required test data.
321 */
322 for (off=0; off<size; off++) {
Alan Cox00d83a52006-03-24 03:18:28 -0800323 if (readb(ram + off) != newbyte) {
324 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Byte Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, readb(ram + off));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 return RIO_FAIL;
326 }
327 }
328
329 for (off=0; off<size; off+=2) {
Alan Cox00d83a52006-03-24 03:18:28 -0800330 if (readw(ram + off) != newword ) {
331 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, readw(ram + off));
332 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, readb(ram + off), off+1, readb(ram + off + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 return RIO_FAIL;
334 }
335 }
336
337 /*
338 ** time to check out byte swapping errors
339 */
340 swapword = invbyte | (newbyte << 8);
341
342 for (off=0; off<size; off+=2) {
Alan Cox00d83a52006-03-24 03:18:28 -0800343 writeb(invbyte, &ram[off]);
344 writeb(newbyte, &ram[off+1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346
347 for ( off=0; off<size; off+=2 ) {
Alan Cox00d83a52006-03-24 03:18:28 -0800348 if (readw(ram + off) != swapword) {
349 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, swapword, readw(ram + off));
350 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, readb(ram + off), off+1, readb(ram + off + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 return RIO_FAIL;
352 }
Alan Cox00d83a52006-03-24 03:18:28 -0800353 writew(~swapword, ram + off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
355
356 for (off=0; off<size; off+=2) {
Alan Cox00d83a52006-03-24 03:18:28 -0800357 if (readb(ram + off) != newbyte) {
358 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, readb(ram + off));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 return RIO_FAIL;
360 }
Alan Cox00d83a52006-03-24 03:18:28 -0800361 if (readb(ram + off + 1) != invbyte) {
362 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, readb(ram + off + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 return RIO_FAIL;
364 }
Alan Cox00d83a52006-03-24 03:18:28 -0800365 writew(newword, ram + off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
367 return RIO_SUCCESS;
368}
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Alan Cox00d83a52006-03-24 03:18:28 -0800371int RIODefaultName(struct rio_info *p, struct Host *HostP, unsigned int UnitId)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
Alan Cox00d83a52006-03-24 03:18:28 -0800373 memcpy(HostP->Mapping[UnitId].Name, "UNKNOWN RTA X-XX", 17);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 HostP->Mapping[UnitId].Name[12]='1'+(HostP-p->RIOHosts);
375 if ((UnitId+1) > 9) {
376 HostP->Mapping[UnitId].Name[14]='0'+((UnitId+1)/10);
377 HostP->Mapping[UnitId].Name[15]='0'+((UnitId+1)%10);
378 }
379 else {
380 HostP->Mapping[UnitId].Name[14]='1'+UnitId;
381 HostP->Mapping[UnitId].Name[15]=0;
382 }
383 return 0;
384}
385
386#define RIO_RELEASE "Linux"
387#define RELEASE_ID "1.0"
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389static struct rioVersion stVersion;
390
Alan Cox00d83a52006-03-24 03:18:28 -0800391struct rioVersion *RIOVersid(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
393 strlcpy(stVersion.version, "RIO driver for linux V1.0",
394 sizeof(stVersion.version));
395 strlcpy(stVersion.buildDate, __DATE__,
396 sizeof(stVersion.buildDate));
397
398 return &stVersion;
399}
400
Alan Cox00d83a52006-03-24 03:18:28 -0800401void RIOHostReset(unsigned int Type, struct DpRam *DpRamP, unsigned int Slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
403 /*
404 ** Reset the Tpu
405 */
406 rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: type 0x%x", Type);
407 switch ( Type ) {
Alan Cox00d83a52006-03-24 03:18:28 -0800408 case RIO_AT:
409 rio_dprintk (RIO_DEBUG_INIT, " (RIO_AT)\n");
410 writeb(BOOT_FROM_RAM | EXTERNAL_BUS_OFF | INTERRUPT_DISABLE | BYTE_OPERATION |
411 SLOW_LINKS | SLOW_AT_BUS, &DpRamP->DpControl);
412 writeb(0xFF, &DpRamP->DpResetTpu);
413 udelay(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: Don't know if it worked. Try reset again\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800415 writeb(BOOT_FROM_RAM | EXTERNAL_BUS_OFF | INTERRUPT_DISABLE |
416 BYTE_OPERATION | SLOW_LINKS | SLOW_AT_BUS, &DpRamP->DpControl);
417 writeb(0xFF, &DpRamP->DpResetTpu);
418 udelay(3);
419 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 case RIO_PCI:
421 rio_dprintk (RIO_DEBUG_INIT, " (RIO_PCI)\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800422 writeb(RIO_PCI_BOOT_FROM_RAM, &DpRamP->DpControl);
423 writeb(0xFF, &DpRamP->DpResetInt);
424 writeb(0xFF, &DpRamP->DpResetTpu);
Adrian Bunk97998d8f2005-06-25 14:59:35 -0700425 udelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 default:
428 rio_dprintk (RIO_DEBUG_INIT, " (UNKNOWN)\n");
429 break;
430 }
431 return;
432}