rioinit.c 13 KB

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