rioinit.c 13 KB

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