rioinit.c 13 KB

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