rioinit.c 13 KB

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