rioinit.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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 : 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
  33. static char *_rioinit_c_sccs_ = "@(#)rioinit.c 1.3";
  34. #endif
  35. #include <linux/config.h>
  36. #include <linux/module.h>
  37. #include <linux/slab.h>
  38. #include <linux/errno.h>
  39. #include <linux/delay.h>
  40. #include <asm/io.h>
  41. #include <asm/system.h>
  42. #include <asm/string.h>
  43. #include <asm/semaphore.h>
  44. #include <asm/uaccess.h>
  45. #include <linux/termios.h>
  46. #include <linux/serial.h>
  47. #include <linux/generic_serial.h>
  48. #include "linux_compat.h"
  49. #include "typdef.h"
  50. #include "pkt.h"
  51. #include "daemon.h"
  52. #include "rio.h"
  53. #include "riospace.h"
  54. #include "top.h"
  55. #include "cmdpkt.h"
  56. #include "map.h"
  57. #include "riotypes.h"
  58. #include "rup.h"
  59. #include "port.h"
  60. #include "riodrvr.h"
  61. #include "rioinfo.h"
  62. #include "func.h"
  63. #include "errors.h"
  64. #include "pci.h"
  65. #include "parmmap.h"
  66. #include "unixrup.h"
  67. #include "board.h"
  68. #include "host.h"
  69. #include "error.h"
  70. #include "phb.h"
  71. #include "link.h"
  72. #include "cmdblk.h"
  73. #include "route.h"
  74. #include "control.h"
  75. #include "cirrus.h"
  76. #include "rioioctl.h"
  77. #include "rio_linux.h"
  78. #undef bcopy
  79. #define bcopy rio_pcicopy
  80. int RIOPCIinit(struct rio_info *p, int Mode);
  81. static int RIOScrub(int, BYTE *, int);
  82. /**
  83. ** RIOAssignAT :
  84. **
  85. ** Fill out the fields in the p->RIOHosts structure now we know we know
  86. ** we have a board present.
  87. **
  88. ** bits < 0 indicates 8 bit operation requested,
  89. ** bits > 0 indicates 16 bit operation.
  90. */
  91. int
  92. RIOAssignAT(p, Base, virtAddr, mode)
  93. struct rio_info * p;
  94. int Base;
  95. caddr_t virtAddr;
  96. int mode;
  97. {
  98. int bits;
  99. struct DpRam *cardp = (struct DpRam *)virtAddr;
  100. if ((Base < ONE_MEG) || (mode & BYTE_ACCESS_MODE))
  101. bits = BYTE_OPERATION;
  102. else
  103. bits = WORD_OPERATION;
  104. /*
  105. ** Board has passed its scrub test. Fill in all the
  106. ** transient stuff.
  107. */
  108. p->RIOHosts[p->RIONumHosts].Caddr = virtAddr;
  109. p->RIOHosts[p->RIONumHosts].CardP = (struct DpRam *)virtAddr;
  110. /*
  111. ** Revision 01 AT host cards don't support WORD operations,
  112. */
  113. if ( RBYTE(cardp->DpRevision) == 01 )
  114. bits = BYTE_OPERATION;
  115. p->RIOHosts[p->RIONumHosts].Type = RIO_AT;
  116. p->RIOHosts[p->RIONumHosts].Copy = bcopy;
  117. /* set this later */
  118. p->RIOHosts[p->RIONumHosts].Slot = -1;
  119. p->RIOHosts[p->RIONumHosts].Mode = SLOW_LINKS | SLOW_AT_BUS | bits;
  120. WBYTE(p->RIOHosts[p->RIONumHosts].Control,
  121. BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
  122. p->RIOHosts[p->RIONumHosts].Mode |
  123. INTERRUPT_DISABLE );
  124. WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
  125. WBYTE(p->RIOHosts[p->RIONumHosts].Control,
  126. BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
  127. p->RIOHosts[p->RIONumHosts].Mode |
  128. INTERRUPT_DISABLE );
  129. WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
  130. p->RIOHosts[p->RIONumHosts].UniqueNum =
  131. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0])&0xFF)<<0)|
  132. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1])&0xFF)<<8)|
  133. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2])&0xFF)<<16)|
  134. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3])&0xFF)<<24);
  135. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Uniquenum 0x%x\n",p->RIOHosts[p->RIONumHosts].UniqueNum);
  136. p->RIONumHosts++;
  137. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Tests Passed at 0x%x\n", Base);
  138. return(1);
  139. }
  140. static uchar val[] = {
  141. #ifdef VERY_LONG_TEST
  142. 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  143. 0xa5, 0xff, 0x5a, 0x00, 0xff, 0xc9, 0x36,
  144. #endif
  145. 0xff, 0x00, 0x00 };
  146. #define TEST_END sizeof(val)
  147. /*
  148. ** RAM test a board.
  149. ** Nothing too complicated, just enough to check it out.
  150. */
  151. int
  152. RIOBoardTest(paddr, caddr, type, slot)
  153. paddr_t paddr;
  154. caddr_t caddr;
  155. uchar type;
  156. int slot;
  157. {
  158. struct DpRam *DpRam = (struct DpRam *)caddr;
  159. char *ram[4];
  160. int size[4];
  161. int op, bank;
  162. int nbanks;
  163. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Reset host type=%d, DpRam=0x%x, slot=%d\n",
  164. type,(int)DpRam, slot);
  165. RIOHostReset(type, DpRam, slot);
  166. /*
  167. ** Scrub the memory. This comes in several banks:
  168. ** DPsram1 - 7000h bytes
  169. ** DPsram2 - 200h bytes
  170. ** DPsram3 - 7000h bytes
  171. ** scratch - 1000h bytes
  172. */
  173. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Setup ram/size arrays\n");
  174. size[0] = DP_SRAM1_SIZE;
  175. size[1] = DP_SRAM2_SIZE;
  176. size[2] = DP_SRAM3_SIZE;
  177. size[3] = DP_SCRATCH_SIZE;
  178. ram[0] = (char *)&DpRam->DpSram1[0];
  179. ram[1] = (char *)&DpRam->DpSram2[0];
  180. ram[2] = (char *)&DpRam->DpSram3[0];
  181. nbanks = (type == RIO_PCI) ? 3 : 4;
  182. if (nbanks == 4)
  183. ram[3] = (char *)&DpRam->DpScratch[0];
  184. if (nbanks == 3) {
  185. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Memory: 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x)\n",
  186. (int)ram[0], size[0], (int)ram[1], size[1], (int)ram[2], size[2]);
  187. } else {
  188. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x)\n",
  189. (int)ram[0], size[0], (int)ram[1], size[1], (int)ram[2], size[2], (int)ram[3],
  190. size[3]);
  191. }
  192. /*
  193. ** This scrub operation will test for crosstalk between
  194. ** banks. TEST_END is a magic number, and relates to the offset
  195. ** within the 'val' array used by Scrub.
  196. */
  197. for (op=0; op<TEST_END; op++) {
  198. for (bank=0; bank<nbanks; bank++) {
  199. if (RIOScrub(op, (BYTE *)ram[bank], size[bank]) == RIO_FAIL) {
  200. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: RIOScrub band %d, op %d failed\n",
  201. bank, op);
  202. return RIO_FAIL;
  203. }
  204. }
  205. }
  206. rio_dprintk (RIO_DEBUG_INIT, "Test completed\n");
  207. return RIO_SUCCESS;
  208. }
  209. /*
  210. ** Scrub an area of RAM.
  211. ** Define PRETEST and POSTTEST for a more thorough checking of the
  212. ** state of the memory.
  213. ** Call with op set to an index into the above 'val' array to determine
  214. ** which value will be written into memory.
  215. ** Call with op set to zero means that the RAM will not be read and checked
  216. ** before it is written.
  217. ** Call with op not zero, and the RAM will be read and compated with val[op-1]
  218. ** to check that the data from the previous phase was retained.
  219. */
  220. static int
  221. RIOScrub(op, ram, size)
  222. int op;
  223. BYTE * ram;
  224. int size;
  225. {
  226. int off;
  227. unsigned char oldbyte;
  228. unsigned char newbyte;
  229. unsigned char invbyte;
  230. unsigned short oldword;
  231. unsigned short newword;
  232. unsigned short invword;
  233. unsigned short swapword;
  234. if (op) {
  235. oldbyte = val[op-1];
  236. oldword = oldbyte | (oldbyte<<8);
  237. } else
  238. oldbyte = oldword = 0; /* Tell the compiler we've initilalized them. */
  239. newbyte = val[op];
  240. newword = newbyte | (newbyte<<8);
  241. invbyte = ~newbyte;
  242. invword = invbyte | (invbyte<<8);
  243. /*
  244. ** Check that the RAM contains the value that should have been left there
  245. ** by the previous test (not applicable for pass zero)
  246. */
  247. if (op) {
  248. for (off=0; off<size; off++) {
  249. if (RBYTE(ram[off]) != oldbyte) {
  250. 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]));
  251. return RIO_FAIL;
  252. }
  253. }
  254. for (off=0; off<size; off+=2) {
  255. if (*(ushort *)&ram[off] != oldword) {
  256. 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]);
  257. 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]));
  258. return RIO_FAIL;
  259. }
  260. }
  261. }
  262. /*
  263. ** Now write the INVERSE of the test data into every location, using
  264. ** BYTE write operations, first checking before each byte is written
  265. ** that the location contains the old value still, and checking after
  266. ** the write that the location contains the data specified - this is
  267. ** the BYTE read/write test.
  268. */
  269. for (off=0; off<size; off++) {
  270. if (op && (RBYTE(ram[off]) != oldbyte)) {
  271. 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]));
  272. return RIO_FAIL;
  273. }
  274. WBYTE(ram[off],invbyte);
  275. if (RBYTE(ram[off]) != invbyte) {
  276. 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]));
  277. return RIO_FAIL;
  278. }
  279. }
  280. /*
  281. ** now, use WORD operations to write the test value into every location,
  282. ** check as before that the location contains the previous test value
  283. ** before overwriting, and that it contains the data value written
  284. ** afterwards.
  285. ** This is the WORD operation test.
  286. */
  287. for (off=0; off<size; off+=2) {
  288. if (*(ushort *)&ram[off] != invword) {
  289. 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]);
  290. 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]));
  291. return RIO_FAIL;
  292. }
  293. *(ushort *)&ram[off] = newword;
  294. if ( *(ushort *)&ram[off] != newword ) {
  295. 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]);
  296. 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]));
  297. return RIO_FAIL;
  298. }
  299. }
  300. /*
  301. ** now run through the block of memory again, first in byte mode
  302. ** then in word mode, and check that all the locations contain the
  303. ** required test data.
  304. */
  305. for (off=0; off<size; off++) {
  306. if (RBYTE(ram[off]) != newbyte) {
  307. 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]));
  308. return RIO_FAIL;
  309. }
  310. }
  311. for (off=0; off<size; off+=2) {
  312. if ( *(ushort *)&ram[off] != newword ) {
  313. 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]);
  314. 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]));
  315. return RIO_FAIL;
  316. }
  317. }
  318. /*
  319. ** time to check out byte swapping errors
  320. */
  321. swapword = invbyte | (newbyte << 8);
  322. for (off=0; off<size; off+=2) {
  323. WBYTE(ram[off],invbyte);
  324. WBYTE(ram[off+1],newbyte);
  325. }
  326. for ( off=0; off<size; off+=2 ) {
  327. if (*(ushort *)&ram[off] != swapword) {
  328. 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]));
  329. 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]));
  330. return RIO_FAIL;
  331. }
  332. *((ushort *)&ram[off]) = ~swapword;
  333. }
  334. for (off=0; off<size; off+=2) {
  335. if (RBYTE(ram[off]) != newbyte) {
  336. 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]));
  337. return RIO_FAIL;
  338. }
  339. if (RBYTE(ram[off+1]) != invbyte) {
  340. 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]));
  341. return RIO_FAIL;
  342. }
  343. *((ushort *)&ram[off]) = newword;
  344. }
  345. return RIO_SUCCESS;
  346. }
  347. int
  348. RIODefaultName(p, HostP, UnitId)
  349. struct rio_info * p;
  350. struct Host * HostP;
  351. uint UnitId;
  352. {
  353. bcopy("UNKNOWN RTA X-XX",HostP->Mapping[UnitId].Name,17);
  354. HostP->Mapping[UnitId].Name[12]='1'+(HostP-p->RIOHosts);
  355. if ((UnitId+1) > 9) {
  356. HostP->Mapping[UnitId].Name[14]='0'+((UnitId+1)/10);
  357. HostP->Mapping[UnitId].Name[15]='0'+((UnitId+1)%10);
  358. }
  359. else {
  360. HostP->Mapping[UnitId].Name[14]='1'+UnitId;
  361. HostP->Mapping[UnitId].Name[15]=0;
  362. }
  363. return 0;
  364. }
  365. #define RIO_RELEASE "Linux"
  366. #define RELEASE_ID "1.0"
  367. static struct rioVersion stVersion;
  368. struct rioVersion *
  369. RIOVersid(void)
  370. {
  371. strlcpy(stVersion.version, "RIO driver for linux V1.0",
  372. sizeof(stVersion.version));
  373. strlcpy(stVersion.buildDate, __DATE__,
  374. sizeof(stVersion.buildDate));
  375. return &stVersion;
  376. }
  377. void
  378. RIOHostReset(Type, DpRamP, Slot)
  379. uint Type;
  380. volatile struct DpRam *DpRamP;
  381. uint Slot;
  382. {
  383. /*
  384. ** Reset the Tpu
  385. */
  386. rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: type 0x%x", Type);
  387. switch ( Type ) {
  388. case RIO_AT:
  389. rio_dprintk (RIO_DEBUG_INIT, " (RIO_AT)\n");
  390. WBYTE(DpRamP->DpControl, BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
  391. INTERRUPT_DISABLE | BYTE_OPERATION |
  392. SLOW_LINKS | SLOW_AT_BUS);
  393. WBYTE(DpRamP->DpResetTpu, 0xFF);
  394. udelay(3);
  395. rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: Don't know if it worked. Try reset again\n");
  396. WBYTE(DpRamP->DpControl, BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
  397. INTERRUPT_DISABLE | BYTE_OPERATION |
  398. SLOW_LINKS | SLOW_AT_BUS);
  399. WBYTE(DpRamP->DpResetTpu, 0xFF);
  400. udelay(3);
  401. break;
  402. case RIO_PCI:
  403. rio_dprintk (RIO_DEBUG_INIT, " (RIO_PCI)\n");
  404. DpRamP->DpControl = RIO_PCI_BOOT_FROM_RAM;
  405. DpRamP->DpResetInt = 0xFF;
  406. DpRamP->DpResetTpu = 0xFF;
  407. udelay(100);
  408. /* for (i=0; i<6000; i++); */
  409. /* suspend( 3 ); */
  410. break;
  411. default:
  412. rio_dprintk (RIO_DEBUG_INIT, " (UNKNOWN)\n");
  413. break;
  414. }
  415. return;
  416. }