rioinit.c 13 KB

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