voyager_cat.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. /* -*- mode: c; c-basic-offset: 8 -*- */
  2. /* Copyright (C) 1999,2001
  3. *
  4. * Author: J.E.J.Bottomley@HansenPartnership.com
  5. *
  6. * linux/arch/i386/kernel/voyager_cat.c
  7. *
  8. * This file contains all the logic for manipulating the CAT bus
  9. * in a level 5 machine.
  10. *
  11. * The CAT bus is a serial configuration and test bus. Its primary
  12. * uses are to probe the initial configuration of the system and to
  13. * diagnose error conditions when a system interrupt occurs. The low
  14. * level interface is fairly primitive, so most of this file consists
  15. * of bit shift manipulations to send and receive packets on the
  16. * serial bus */
  17. #include <linux/types.h>
  18. #include <linux/completion.h>
  19. #include <linux/sched.h>
  20. #include <asm/voyager.h>
  21. #include <asm/vic.h>
  22. #include <linux/ioport.h>
  23. #include <linux/init.h>
  24. #include <linux/slab.h>
  25. #include <linux/delay.h>
  26. #include <asm/io.h>
  27. #ifdef VOYAGER_CAT_DEBUG
  28. #define CDEBUG(x) printk x
  29. #else
  30. #define CDEBUG(x)
  31. #endif
  32. /* the CAT command port */
  33. #define CAT_CMD (sspb + 0xe)
  34. /* the CAT data port */
  35. #define CAT_DATA (sspb + 0xd)
  36. /* the internal cat functions */
  37. static void cat_pack(__u8 *msg, __u16 start_bit, __u8 *data,
  38. __u16 num_bits);
  39. static void cat_unpack(__u8 *msg, __u16 start_bit, __u8 *data,
  40. __u16 num_bits);
  41. static void cat_build_header(__u8 *header, const __u16 len,
  42. const __u16 smallest_reg_bits,
  43. const __u16 longest_reg_bits);
  44. static int cat_sendinst(voyager_module_t *modp, voyager_asic_t *asicp,
  45. __u8 reg, __u8 op);
  46. static int cat_getdata(voyager_module_t *modp, voyager_asic_t *asicp,
  47. __u8 reg, __u8 *value);
  48. static int cat_shiftout(__u8 *data, __u16 data_bytes, __u16 header_bytes,
  49. __u8 pad_bits);
  50. static int cat_write(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
  51. __u8 value);
  52. static int cat_read(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
  53. __u8 *value);
  54. static int cat_subread(voyager_module_t *modp, voyager_asic_t *asicp,
  55. __u16 offset, __u16 len, void *buf);
  56. static int cat_senddata(voyager_module_t *modp, voyager_asic_t *asicp,
  57. __u8 reg, __u8 value);
  58. static int cat_disconnect(voyager_module_t *modp, voyager_asic_t *asicp);
  59. static int cat_connect(voyager_module_t *modp, voyager_asic_t *asicp);
  60. static inline const char *
  61. cat_module_name(int module_id)
  62. {
  63. switch(module_id) {
  64. case 0x10:
  65. return "Processor Slot 0";
  66. case 0x11:
  67. return "Processor Slot 1";
  68. case 0x12:
  69. return "Processor Slot 2";
  70. case 0x13:
  71. return "Processor Slot 4";
  72. case 0x14:
  73. return "Memory Slot 0";
  74. case 0x15:
  75. return "Memory Slot 1";
  76. case 0x18:
  77. return "Primary Microchannel";
  78. case 0x19:
  79. return "Secondary Microchannel";
  80. case 0x1a:
  81. return "Power Supply Interface";
  82. case 0x1c:
  83. return "Processor Slot 5";
  84. case 0x1d:
  85. return "Processor Slot 6";
  86. case 0x1e:
  87. return "Processor Slot 7";
  88. case 0x1f:
  89. return "Processor Slot 8";
  90. default:
  91. return "Unknown Module";
  92. }
  93. }
  94. static int sspb = 0; /* stores the super port location */
  95. int voyager_8slot = 0; /* set to true if a 51xx monster */
  96. voyager_module_t *voyager_cat_list;
  97. /* the I/O port assignments for the VIC and QIC */
  98. static struct resource vic_res = {
  99. .name = "Voyager Interrupt Controller",
  100. .start = 0xFC00,
  101. .end = 0xFC6F
  102. };
  103. static struct resource qic_res = {
  104. .name = "Quad Interrupt Controller",
  105. .start = 0xFC70,
  106. .end = 0xFCFF
  107. };
  108. /* This function is used to pack a data bit stream inside a message.
  109. * It writes num_bits of the data buffer in msg starting at start_bit.
  110. * Note: This function assumes that any unused bit in the data stream
  111. * is set to zero so that the ors will work correctly */
  112. static void
  113. cat_pack(__u8 *msg, const __u16 start_bit, __u8 *data, const __u16 num_bits)
  114. {
  115. /* compute initial shift needed */
  116. const __u16 offset = start_bit % BITS_PER_BYTE;
  117. __u16 len = num_bits / BITS_PER_BYTE;
  118. __u16 byte = start_bit / BITS_PER_BYTE;
  119. __u16 residue = (num_bits % BITS_PER_BYTE) + offset;
  120. int i;
  121. /* adjust if we have more than a byte of residue */
  122. if(residue >= BITS_PER_BYTE) {
  123. residue -= BITS_PER_BYTE;
  124. len++;
  125. }
  126. /* clear out the bits. We assume here that if len==0 then
  127. * residue >= offset. This is always true for the catbus
  128. * operations */
  129. msg[byte] &= 0xff << (BITS_PER_BYTE - offset);
  130. msg[byte++] |= data[0] >> offset;
  131. if(len == 0)
  132. return;
  133. for(i = 1; i < len; i++)
  134. msg[byte++] = (data[i-1] << (BITS_PER_BYTE - offset))
  135. | (data[i] >> offset);
  136. if(residue != 0) {
  137. __u8 mask = 0xff >> residue;
  138. __u8 last_byte = data[i-1] << (BITS_PER_BYTE - offset)
  139. | (data[i] >> offset);
  140. last_byte &= ~mask;
  141. msg[byte] &= mask;
  142. msg[byte] |= last_byte;
  143. }
  144. return;
  145. }
  146. /* unpack the data again (same arguments as cat_pack()). data buffer
  147. * must be zero populated.
  148. *
  149. * Function: given a message string move to start_bit and copy num_bits into
  150. * data (starting at bit 0 in data).
  151. */
  152. static void
  153. cat_unpack(__u8 *msg, const __u16 start_bit, __u8 *data, const __u16 num_bits)
  154. {
  155. /* compute initial shift needed */
  156. const __u16 offset = start_bit % BITS_PER_BYTE;
  157. __u16 len = num_bits / BITS_PER_BYTE;
  158. const __u8 last_bits = num_bits % BITS_PER_BYTE;
  159. __u16 byte = start_bit / BITS_PER_BYTE;
  160. int i;
  161. if(last_bits != 0)
  162. len++;
  163. /* special case: want < 8 bits from msg and we can get it from
  164. * a single byte of the msg */
  165. if(len == 0 && BITS_PER_BYTE - offset >= num_bits) {
  166. data[0] = msg[byte] << offset;
  167. data[0] &= 0xff >> (BITS_PER_BYTE - num_bits);
  168. return;
  169. }
  170. for(i = 0; i < len; i++) {
  171. /* this annoying if has to be done just in case a read of
  172. * msg one beyond the array causes a panic */
  173. if(offset != 0) {
  174. data[i] = msg[byte++] << offset;
  175. data[i] |= msg[byte] >> (BITS_PER_BYTE - offset);
  176. }
  177. else {
  178. data[i] = msg[byte++];
  179. }
  180. }
  181. /* do we need to truncate the final byte */
  182. if(last_bits != 0) {
  183. data[i-1] &= 0xff << (BITS_PER_BYTE - last_bits);
  184. }
  185. return;
  186. }
  187. static void
  188. cat_build_header(__u8 *header, const __u16 len, const __u16 smallest_reg_bits,
  189. const __u16 longest_reg_bits)
  190. {
  191. int i;
  192. __u16 start_bit = (smallest_reg_bits - 1) % BITS_PER_BYTE;
  193. __u8 *last_byte = &header[len - 1];
  194. if(start_bit == 0)
  195. start_bit = 1; /* must have at least one bit in the hdr */
  196. for(i=0; i < len; i++)
  197. header[i] = 0;
  198. for(i = start_bit; i > 0; i--)
  199. *last_byte = ((*last_byte) << 1) + 1;
  200. }
  201. static int
  202. cat_sendinst(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg, __u8 op)
  203. {
  204. __u8 parity, inst, inst_buf[4] = { 0 };
  205. __u8 iseq[VOYAGER_MAX_SCAN_PATH], hseq[VOYAGER_MAX_REG_SIZE];
  206. __u16 ibytes, hbytes, padbits;
  207. int i;
  208. /*
  209. * Parity is the parity of the register number + 1 (READ_REGISTER
  210. * and WRITE_REGISTER always add '1' to the number of bits == 1)
  211. */
  212. parity = (__u8)(1 + (reg & 0x01) +
  213. ((__u8)(reg & 0x02) >> 1) +
  214. ((__u8)(reg & 0x04) >> 2) +
  215. ((__u8)(reg & 0x08) >> 3)) % 2;
  216. inst = ((parity << 7) | (reg << 2) | op);
  217. outb(VOYAGER_CAT_IRCYC, CAT_CMD);
  218. if(!modp->scan_path_connected) {
  219. if(asicp->asic_id != VOYAGER_CAT_ID) {
  220. printk("**WARNING***: cat_sendinst has disconnected scan path not to CAT asic\n");
  221. return 1;
  222. }
  223. outb(VOYAGER_CAT_HEADER, CAT_DATA);
  224. outb(inst, CAT_DATA);
  225. if(inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
  226. CDEBUG(("VOYAGER CAT: cat_sendinst failed to get CAT_HEADER\n"));
  227. return 1;
  228. }
  229. return 0;
  230. }
  231. ibytes = modp->inst_bits / BITS_PER_BYTE;
  232. if((padbits = modp->inst_bits % BITS_PER_BYTE) != 0) {
  233. padbits = BITS_PER_BYTE - padbits;
  234. ibytes++;
  235. }
  236. hbytes = modp->largest_reg / BITS_PER_BYTE;
  237. if(modp->largest_reg % BITS_PER_BYTE)
  238. hbytes++;
  239. CDEBUG(("cat_sendinst: ibytes=%d, hbytes=%d\n", ibytes, hbytes));
  240. /* initialise the instruction sequence to 0xff */
  241. for(i=0; i < ibytes + hbytes; i++)
  242. iseq[i] = 0xff;
  243. cat_build_header(hseq, hbytes, modp->smallest_reg, modp->largest_reg);
  244. cat_pack(iseq, modp->inst_bits, hseq, hbytes * BITS_PER_BYTE);
  245. inst_buf[0] = inst;
  246. inst_buf[1] = 0xFF >> (modp->largest_reg % BITS_PER_BYTE);
  247. cat_pack(iseq, asicp->bit_location, inst_buf, asicp->ireg_length);
  248. #ifdef VOYAGER_CAT_DEBUG
  249. printk("ins = 0x%x, iseq: ", inst);
  250. for(i=0; i< ibytes + hbytes; i++)
  251. printk("0x%x ", iseq[i]);
  252. printk("\n");
  253. #endif
  254. if(cat_shiftout(iseq, ibytes, hbytes, padbits)) {
  255. CDEBUG(("VOYAGER CAT: cat_sendinst: cat_shiftout failed\n"));
  256. return 1;
  257. }
  258. CDEBUG(("CAT SHIFTOUT DONE\n"));
  259. return 0;
  260. }
  261. static int
  262. cat_getdata(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
  263. __u8 *value)
  264. {
  265. if(!modp->scan_path_connected) {
  266. if(asicp->asic_id != VOYAGER_CAT_ID) {
  267. CDEBUG(("VOYAGER CAT: ERROR: cat_getdata to CAT asic with scan path connected\n"));
  268. return 1;
  269. }
  270. if(reg > VOYAGER_SUBADDRHI)
  271. outb(VOYAGER_CAT_RUN, CAT_CMD);
  272. outb(VOYAGER_CAT_DRCYC, CAT_CMD);
  273. outb(VOYAGER_CAT_HEADER, CAT_DATA);
  274. *value = inb(CAT_DATA);
  275. outb(0xAA, CAT_DATA);
  276. if(inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
  277. CDEBUG(("cat_getdata: failed to get VOYAGER_CAT_HEADER\n"));
  278. return 1;
  279. }
  280. return 0;
  281. }
  282. else {
  283. __u16 sbits = modp->num_asics -1 + asicp->ireg_length;
  284. __u16 sbytes = sbits / BITS_PER_BYTE;
  285. __u16 tbytes;
  286. __u8 string[VOYAGER_MAX_SCAN_PATH], trailer[VOYAGER_MAX_REG_SIZE];
  287. __u8 padbits;
  288. int i;
  289. outb(VOYAGER_CAT_DRCYC, CAT_CMD);
  290. if((padbits = sbits % BITS_PER_BYTE) != 0) {
  291. padbits = BITS_PER_BYTE - padbits;
  292. sbytes++;
  293. }
  294. tbytes = asicp->ireg_length / BITS_PER_BYTE;
  295. if(asicp->ireg_length % BITS_PER_BYTE)
  296. tbytes++;
  297. CDEBUG(("cat_getdata: tbytes = %d, sbytes = %d, padbits = %d\n",
  298. tbytes, sbytes, padbits));
  299. cat_build_header(trailer, tbytes, 1, asicp->ireg_length);
  300. for(i = tbytes - 1; i >= 0; i--) {
  301. outb(trailer[i], CAT_DATA);
  302. string[sbytes + i] = inb(CAT_DATA);
  303. }
  304. for(i = sbytes - 1; i >= 0; i--) {
  305. outb(0xaa, CAT_DATA);
  306. string[i] = inb(CAT_DATA);
  307. }
  308. *value = 0;
  309. cat_unpack(string, padbits + (tbytes * BITS_PER_BYTE) + asicp->asic_location, value, asicp->ireg_length);
  310. #ifdef VOYAGER_CAT_DEBUG
  311. printk("value=0x%x, string: ", *value);
  312. for(i=0; i< tbytes+sbytes; i++)
  313. printk("0x%x ", string[i]);
  314. printk("\n");
  315. #endif
  316. /* sanity check the rest of the return */
  317. for(i=0; i < tbytes; i++) {
  318. __u8 input = 0;
  319. cat_unpack(string, padbits + (i * BITS_PER_BYTE), &input, BITS_PER_BYTE);
  320. if(trailer[i] != input) {
  321. CDEBUG(("cat_getdata: failed to sanity check rest of ret(%d) 0x%x != 0x%x\n", i, input, trailer[i]));
  322. return 1;
  323. }
  324. }
  325. CDEBUG(("cat_getdata DONE\n"));
  326. return 0;
  327. }
  328. }
  329. static int
  330. cat_shiftout(__u8 *data, __u16 data_bytes, __u16 header_bytes, __u8 pad_bits)
  331. {
  332. int i;
  333. for(i = data_bytes + header_bytes - 1; i >= header_bytes; i--)
  334. outb(data[i], CAT_DATA);
  335. for(i = header_bytes - 1; i >= 0; i--) {
  336. __u8 header = 0;
  337. __u8 input;
  338. outb(data[i], CAT_DATA);
  339. input = inb(CAT_DATA);
  340. CDEBUG(("cat_shiftout: returned 0x%x\n", input));
  341. cat_unpack(data, ((data_bytes + i) * BITS_PER_BYTE) - pad_bits,
  342. &header, BITS_PER_BYTE);
  343. if(input != header) {
  344. CDEBUG(("VOYAGER CAT: cat_shiftout failed to return header 0x%x != 0x%x\n", input, header));
  345. return 1;
  346. }
  347. }
  348. return 0;
  349. }
  350. static int
  351. cat_senddata(voyager_module_t *modp, voyager_asic_t *asicp,
  352. __u8 reg, __u8 value)
  353. {
  354. outb(VOYAGER_CAT_DRCYC, CAT_CMD);
  355. if(!modp->scan_path_connected) {
  356. if(asicp->asic_id != VOYAGER_CAT_ID) {
  357. CDEBUG(("VOYAGER CAT: ERROR: scan path disconnected when asic != CAT\n"));
  358. return 1;
  359. }
  360. outb(VOYAGER_CAT_HEADER, CAT_DATA);
  361. outb(value, CAT_DATA);
  362. if(inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
  363. CDEBUG(("cat_senddata: failed to get correct header response to sent data\n"));
  364. return 1;
  365. }
  366. if(reg > VOYAGER_SUBADDRHI) {
  367. outb(VOYAGER_CAT_RUN, CAT_CMD);
  368. outb(VOYAGER_CAT_END, CAT_CMD);
  369. outb(VOYAGER_CAT_RUN, CAT_CMD);
  370. }
  371. return 0;
  372. }
  373. else {
  374. __u16 hbytes = asicp->ireg_length / BITS_PER_BYTE;
  375. __u16 dbytes = (modp->num_asics - 1 + asicp->ireg_length)/BITS_PER_BYTE;
  376. __u8 padbits, dseq[VOYAGER_MAX_SCAN_PATH],
  377. hseq[VOYAGER_MAX_REG_SIZE];
  378. int i;
  379. if((padbits = (modp->num_asics - 1
  380. + asicp->ireg_length) % BITS_PER_BYTE) != 0) {
  381. padbits = BITS_PER_BYTE - padbits;
  382. dbytes++;
  383. }
  384. if(asicp->ireg_length % BITS_PER_BYTE)
  385. hbytes++;
  386. cat_build_header(hseq, hbytes, 1, asicp->ireg_length);
  387. for(i = 0; i < dbytes + hbytes; i++)
  388. dseq[i] = 0xff;
  389. CDEBUG(("cat_senddata: dbytes=%d, hbytes=%d, padbits=%d\n",
  390. dbytes, hbytes, padbits));
  391. cat_pack(dseq, modp->num_asics - 1 + asicp->ireg_length,
  392. hseq, hbytes * BITS_PER_BYTE);
  393. cat_pack(dseq, asicp->asic_location, &value,
  394. asicp->ireg_length);
  395. #ifdef VOYAGER_CAT_DEBUG
  396. printk("dseq ");
  397. for(i=0; i<hbytes+dbytes; i++) {
  398. printk("0x%x ", dseq[i]);
  399. }
  400. printk("\n");
  401. #endif
  402. return cat_shiftout(dseq, dbytes, hbytes, padbits);
  403. }
  404. }
  405. static int
  406. cat_write(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
  407. __u8 value)
  408. {
  409. if(cat_sendinst(modp, asicp, reg, VOYAGER_WRITE_CONFIG))
  410. return 1;
  411. return cat_senddata(modp, asicp, reg, value);
  412. }
  413. static int
  414. cat_read(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
  415. __u8 *value)
  416. {
  417. if(cat_sendinst(modp, asicp, reg, VOYAGER_READ_CONFIG))
  418. return 1;
  419. return cat_getdata(modp, asicp, reg, value);
  420. }
  421. static int
  422. cat_subaddrsetup(voyager_module_t *modp, voyager_asic_t *asicp, __u16 offset,
  423. __u16 len)
  424. {
  425. __u8 val;
  426. if(len > 1) {
  427. /* set auto increment */
  428. __u8 newval;
  429. if(cat_read(modp, asicp, VOYAGER_AUTO_INC_REG, &val)) {
  430. CDEBUG(("cat_subaddrsetup: read of VOYAGER_AUTO_INC_REG failed\n"));
  431. return 1;
  432. }
  433. CDEBUG(("cat_subaddrsetup: VOYAGER_AUTO_INC_REG = 0x%x\n", val));
  434. newval = val | VOYAGER_AUTO_INC;
  435. if(newval != val) {
  436. if(cat_write(modp, asicp, VOYAGER_AUTO_INC_REG, val)) {
  437. CDEBUG(("cat_subaddrsetup: write to VOYAGER_AUTO_INC_REG failed\n"));
  438. return 1;
  439. }
  440. }
  441. }
  442. if(cat_write(modp, asicp, VOYAGER_SUBADDRLO, (__u8)(offset &0xff))) {
  443. CDEBUG(("cat_subaddrsetup: write to SUBADDRLO failed\n"));
  444. return 1;
  445. }
  446. if(asicp->subaddr > VOYAGER_SUBADDR_LO) {
  447. if(cat_write(modp, asicp, VOYAGER_SUBADDRHI, (__u8)(offset >> 8))) {
  448. CDEBUG(("cat_subaddrsetup: write to SUBADDRHI failed\n"));
  449. return 1;
  450. }
  451. cat_read(modp, asicp, VOYAGER_SUBADDRHI, &val);
  452. CDEBUG(("cat_subaddrsetup: offset = %d, hi = %d\n", offset, val));
  453. }
  454. cat_read(modp, asicp, VOYAGER_SUBADDRLO, &val);
  455. CDEBUG(("cat_subaddrsetup: offset = %d, lo = %d\n", offset, val));
  456. return 0;
  457. }
  458. static int
  459. cat_subwrite(voyager_module_t *modp, voyager_asic_t *asicp, __u16 offset,
  460. __u16 len, void *buf)
  461. {
  462. int i, retval;
  463. /* FIXME: need special actions for VOYAGER_CAT_ID here */
  464. if(asicp->asic_id == VOYAGER_CAT_ID) {
  465. CDEBUG(("cat_subwrite: ATTEMPT TO WRITE TO CAT ASIC\n"));
  466. /* FIXME -- This is supposed to be handled better
  467. * There is a problem writing to the cat asic in the
  468. * PSI. The 30us delay seems to work, though */
  469. udelay(30);
  470. }
  471. if((retval = cat_subaddrsetup(modp, asicp, offset, len)) != 0) {
  472. printk("cat_subwrite: cat_subaddrsetup FAILED\n");
  473. return retval;
  474. }
  475. if(cat_sendinst(modp, asicp, VOYAGER_SUBADDRDATA, VOYAGER_WRITE_CONFIG)) {
  476. printk("cat_subwrite: cat_sendinst FAILED\n");
  477. return 1;
  478. }
  479. for(i = 0; i < len; i++) {
  480. if(cat_senddata(modp, asicp, 0xFF, ((__u8 *)buf)[i])) {
  481. printk("cat_subwrite: cat_sendata element at %d FAILED\n", i);
  482. return 1;
  483. }
  484. }
  485. return 0;
  486. }
  487. static int
  488. cat_subread(voyager_module_t *modp, voyager_asic_t *asicp, __u16 offset,
  489. __u16 len, void *buf)
  490. {
  491. int i, retval;
  492. if((retval = cat_subaddrsetup(modp, asicp, offset, len)) != 0) {
  493. CDEBUG(("cat_subread: cat_subaddrsetup FAILED\n"));
  494. return retval;
  495. }
  496. if(cat_sendinst(modp, asicp, VOYAGER_SUBADDRDATA, VOYAGER_READ_CONFIG)) {
  497. CDEBUG(("cat_subread: cat_sendinst failed\n"));
  498. return 1;
  499. }
  500. for(i = 0; i < len; i++) {
  501. if(cat_getdata(modp, asicp, 0xFF,
  502. &((__u8 *)buf)[i])) {
  503. CDEBUG(("cat_subread: cat_getdata element %d failed\n", i));
  504. return 1;
  505. }
  506. }
  507. return 0;
  508. }
  509. /* buffer for storing EPROM data read in during initialisation */
  510. static __initdata __u8 eprom_buf[0xFFFF];
  511. static voyager_module_t *voyager_initial_module;
  512. /* Initialise the cat bus components. We assume this is called by the
  513. * boot cpu *after* all memory initialisation has been done (so we can
  514. * use kmalloc) but before smp initialisation, so we can probe the SMP
  515. * configuration and pick up necessary information. */
  516. void
  517. voyager_cat_init(void)
  518. {
  519. voyager_module_t **modpp = &voyager_initial_module;
  520. voyager_asic_t **asicpp;
  521. voyager_asic_t *qabc_asic = NULL;
  522. int i, j;
  523. unsigned long qic_addr = 0;
  524. __u8 qabc_data[0x20];
  525. __u8 num_submodules, val;
  526. voyager_eprom_hdr_t *eprom_hdr = (voyager_eprom_hdr_t *)&eprom_buf[0];
  527. __u8 cmos[4];
  528. unsigned long addr;
  529. /* initiallise the SUS mailbox */
  530. for(i=0; i<sizeof(cmos); i++)
  531. cmos[i] = voyager_extended_cmos_read(VOYAGER_DUMP_LOCATION + i);
  532. addr = *(unsigned long *)cmos;
  533. if((addr & 0xff000000) != 0xff000000) {
  534. printk(KERN_ERR "Voyager failed to get SUS mailbox (addr = 0x%lx\n", addr);
  535. } else {
  536. static struct resource res;
  537. res.name = "voyager SUS";
  538. res.start = addr;
  539. res.end = addr+0x3ff;
  540. request_resource(&iomem_resource, &res);
  541. voyager_SUS = (struct voyager_SUS *)
  542. ioremap(addr, 0x400);
  543. printk(KERN_NOTICE "Voyager SUS mailbox version 0x%x\n",
  544. voyager_SUS->SUS_version);
  545. voyager_SUS->kernel_version = VOYAGER_MAILBOX_VERSION;
  546. voyager_SUS->kernel_flags = VOYAGER_OS_HAS_SYSINT;
  547. }
  548. /* clear the processor counts */
  549. voyager_extended_vic_processors = 0;
  550. voyager_quad_processors = 0;
  551. printk("VOYAGER: beginning CAT bus probe\n");
  552. /* set up the SuperSet Port Block which tells us where the
  553. * CAT communication port is */
  554. sspb = inb(VOYAGER_SSPB_RELOCATION_PORT) * 0x100;
  555. VDEBUG(("VOYAGER DEBUG: sspb = 0x%x\n", sspb));
  556. /* now find out if were 8 slot or normal */
  557. if((inb(VIC_PROC_WHO_AM_I) & EIGHT_SLOT_IDENTIFIER)
  558. == EIGHT_SLOT_IDENTIFIER) {
  559. voyager_8slot = 1;
  560. printk(KERN_NOTICE "Voyager: Eight slot 51xx configuration detected\n");
  561. }
  562. for(i = VOYAGER_MIN_MODULE;
  563. i <= VOYAGER_MAX_MODULE; i++) {
  564. __u8 input;
  565. int asic;
  566. __u16 eprom_size;
  567. __u16 sp_offset;
  568. outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
  569. outb(i, VOYAGER_CAT_CONFIG_PORT);
  570. /* check the presence of the module */
  571. outb(VOYAGER_CAT_RUN, CAT_CMD);
  572. outb(VOYAGER_CAT_IRCYC, CAT_CMD);
  573. outb(VOYAGER_CAT_HEADER, CAT_DATA);
  574. /* stream series of alternating 1's and 0's to stimulate
  575. * response */
  576. outb(0xAA, CAT_DATA);
  577. input = inb(CAT_DATA);
  578. outb(VOYAGER_CAT_END, CAT_CMD);
  579. if(input != VOYAGER_CAT_HEADER) {
  580. continue;
  581. }
  582. CDEBUG(("VOYAGER DEBUG: found module id 0x%x, %s\n", i,
  583. cat_module_name(i)));
  584. *modpp = kmalloc(sizeof(voyager_module_t), GFP_KERNEL); /*&voyager_module_storage[cat_count++];*/
  585. if(*modpp == NULL) {
  586. printk("**WARNING** kmalloc failure in cat_init\n");
  587. continue;
  588. }
  589. memset(*modpp, 0, sizeof(voyager_module_t));
  590. /* need temporary asic for cat_subread. It will be
  591. * filled in correctly later */
  592. (*modpp)->asic = kmalloc(sizeof(voyager_asic_t), GFP_KERNEL); /*&voyager_asic_storage[asic_count];*/
  593. if((*modpp)->asic == NULL) {
  594. printk("**WARNING** kmalloc failure in cat_init\n");
  595. continue;
  596. }
  597. memset((*modpp)->asic, 0, sizeof(voyager_asic_t));
  598. (*modpp)->asic->asic_id = VOYAGER_CAT_ID;
  599. (*modpp)->asic->subaddr = VOYAGER_SUBADDR_HI;
  600. (*modpp)->module_addr = i;
  601. (*modpp)->scan_path_connected = 0;
  602. if(i == VOYAGER_PSI) {
  603. /* Exception leg for modules with no EEPROM */
  604. printk("Module \"%s\"\n", cat_module_name(i));
  605. continue;
  606. }
  607. CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i, VOYAGER_XSUM_END_OFFSET));
  608. outb(VOYAGER_CAT_RUN, CAT_CMD);
  609. cat_disconnect(*modpp, (*modpp)->asic);
  610. if(cat_subread(*modpp, (*modpp)->asic,
  611. VOYAGER_XSUM_END_OFFSET, sizeof(eprom_size),
  612. &eprom_size)) {
  613. printk("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n", i);
  614. outb(VOYAGER_CAT_END, CAT_CMD);
  615. continue;
  616. }
  617. if(eprom_size > sizeof(eprom_buf)) {
  618. printk("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x. Need %d\n", i, eprom_size);
  619. outb(VOYAGER_CAT_END, CAT_CMD);
  620. continue;
  621. }
  622. outb(VOYAGER_CAT_END, CAT_CMD);
  623. outb(VOYAGER_CAT_RUN, CAT_CMD);
  624. CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i, eprom_size));
  625. if(cat_subread(*modpp, (*modpp)->asic, 0,
  626. eprom_size, eprom_buf)) {
  627. outb(VOYAGER_CAT_END, CAT_CMD);
  628. continue;
  629. }
  630. outb(VOYAGER_CAT_END, CAT_CMD);
  631. printk("Module \"%s\", version 0x%x, tracer 0x%x, asics %d\n",
  632. cat_module_name(i), eprom_hdr->version_id,
  633. *((__u32 *)eprom_hdr->tracer), eprom_hdr->num_asics);
  634. (*modpp)->ee_size = eprom_hdr->ee_size;
  635. (*modpp)->num_asics = eprom_hdr->num_asics;
  636. asicpp = &((*modpp)->asic);
  637. sp_offset = eprom_hdr->scan_path_offset;
  638. /* All we really care about are the Quad cards. We
  639. * identify them because they are in a processor slot
  640. * and have only four asics */
  641. if((i < 0x10 || (i>=0x14 && i < 0x1c) || i>0x1f)) {
  642. modpp = &((*modpp)->next);
  643. continue;
  644. }
  645. /* Now we know it's in a processor slot, does it have
  646. * a quad baseboard submodule */
  647. outb(VOYAGER_CAT_RUN, CAT_CMD);
  648. cat_read(*modpp, (*modpp)->asic, VOYAGER_SUBMODPRESENT,
  649. &num_submodules);
  650. /* lowest two bits, active low */
  651. num_submodules = ~(0xfc | num_submodules);
  652. CDEBUG(("VOYAGER CAT: %d submodules present\n", num_submodules));
  653. if(num_submodules == 0) {
  654. /* fill in the dyadic extended processors */
  655. __u8 cpu = i & 0x07;
  656. printk("Module \"%s\": Dyadic Processor Card\n",
  657. cat_module_name(i));
  658. voyager_extended_vic_processors |= (1<<cpu);
  659. cpu += 4;
  660. voyager_extended_vic_processors |= (1<<cpu);
  661. outb(VOYAGER_CAT_END, CAT_CMD);
  662. continue;
  663. }
  664. /* now we want to read the asics on the first submodule,
  665. * which should be the quad base board */
  666. cat_read(*modpp, (*modpp)->asic, VOYAGER_SUBMODSELECT, &val);
  667. CDEBUG(("cat_init: SUBMODSELECT value = 0x%x\n", val));
  668. val = (val & 0x7c) | VOYAGER_QUAD_BASEBOARD;
  669. cat_write(*modpp, (*modpp)->asic, VOYAGER_SUBMODSELECT, val);
  670. outb(VOYAGER_CAT_END, CAT_CMD);
  671. CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i, VOYAGER_XSUM_END_OFFSET));
  672. outb(VOYAGER_CAT_RUN, CAT_CMD);
  673. cat_disconnect(*modpp, (*modpp)->asic);
  674. if(cat_subread(*modpp, (*modpp)->asic,
  675. VOYAGER_XSUM_END_OFFSET, sizeof(eprom_size),
  676. &eprom_size)) {
  677. printk("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n", i);
  678. outb(VOYAGER_CAT_END, CAT_CMD);
  679. continue;
  680. }
  681. if(eprom_size > sizeof(eprom_buf)) {
  682. printk("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x. Need %d\n", i, eprom_size);
  683. outb(VOYAGER_CAT_END, CAT_CMD);
  684. continue;
  685. }
  686. outb(VOYAGER_CAT_END, CAT_CMD);
  687. outb(VOYAGER_CAT_RUN, CAT_CMD);
  688. CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i, eprom_size));
  689. if(cat_subread(*modpp, (*modpp)->asic, 0,
  690. eprom_size, eprom_buf)) {
  691. outb(VOYAGER_CAT_END, CAT_CMD);
  692. continue;
  693. }
  694. outb(VOYAGER_CAT_END, CAT_CMD);
  695. /* Now do everything for the QBB submodule 1 */
  696. (*modpp)->ee_size = eprom_hdr->ee_size;
  697. (*modpp)->num_asics = eprom_hdr->num_asics;
  698. asicpp = &((*modpp)->asic);
  699. sp_offset = eprom_hdr->scan_path_offset;
  700. /* get rid of the dummy CAT asic and read the real one */
  701. kfree((*modpp)->asic);
  702. for(asic=0; asic < (*modpp)->num_asics; asic++) {
  703. int j;
  704. voyager_asic_t *asicp = *asicpp
  705. = kzalloc(sizeof(voyager_asic_t), GFP_KERNEL); /*&voyager_asic_storage[asic_count++];*/
  706. voyager_sp_table_t *sp_table;
  707. voyager_at_t *asic_table;
  708. voyager_jtt_t *jtag_table;
  709. if(asicp == NULL) {
  710. printk("**WARNING** kmalloc failure in cat_init\n");
  711. continue;
  712. }
  713. asicpp = &(asicp->next);
  714. asicp->asic_location = asic;
  715. sp_table = (voyager_sp_table_t *)(eprom_buf + sp_offset);
  716. asicp->asic_id = sp_table->asic_id;
  717. asic_table = (voyager_at_t *)(eprom_buf + sp_table->asic_data_offset);
  718. for(j=0; j<4; j++)
  719. asicp->jtag_id[j] = asic_table->jtag_id[j];
  720. jtag_table = (voyager_jtt_t *)(eprom_buf + asic_table->jtag_offset);
  721. asicp->ireg_length = jtag_table->ireg_len;
  722. asicp->bit_location = (*modpp)->inst_bits;
  723. (*modpp)->inst_bits += asicp->ireg_length;
  724. if(asicp->ireg_length > (*modpp)->largest_reg)
  725. (*modpp)->largest_reg = asicp->ireg_length;
  726. if (asicp->ireg_length < (*modpp)->smallest_reg ||
  727. (*modpp)->smallest_reg == 0)
  728. (*modpp)->smallest_reg = asicp->ireg_length;
  729. CDEBUG(("asic 0x%x, ireg_length=%d, bit_location=%d\n",
  730. asicp->asic_id, asicp->ireg_length,
  731. asicp->bit_location));
  732. if(asicp->asic_id == VOYAGER_QUAD_QABC) {
  733. CDEBUG(("VOYAGER CAT: QABC ASIC found\n"));
  734. qabc_asic = asicp;
  735. }
  736. sp_offset += sizeof(voyager_sp_table_t);
  737. }
  738. CDEBUG(("Module inst_bits = %d, largest_reg = %d, smallest_reg=%d\n",
  739. (*modpp)->inst_bits, (*modpp)->largest_reg,
  740. (*modpp)->smallest_reg));
  741. /* OK, now we have the QUAD ASICs set up, use them.
  742. * we need to:
  743. *
  744. * 1. Find the Memory area for the Quad CPIs.
  745. * 2. Find the Extended VIC processor
  746. * 3. Configure a second extended VIC processor (This
  747. * cannot be done for the 51xx.
  748. * */
  749. outb(VOYAGER_CAT_RUN, CAT_CMD);
  750. cat_connect(*modpp, (*modpp)->asic);
  751. CDEBUG(("CAT CONNECTED!!\n"));
  752. cat_subread(*modpp, qabc_asic, 0, sizeof(qabc_data), qabc_data);
  753. qic_addr = qabc_data[5] << 8;
  754. qic_addr = (qic_addr | qabc_data[6]) << 8;
  755. qic_addr = (qic_addr | qabc_data[7]) << 8;
  756. printk("Module \"%s\": Quad Processor Card; CPI 0x%lx, SET=0x%x\n",
  757. cat_module_name(i), qic_addr, qabc_data[8]);
  758. #if 0 /* plumbing fails---FIXME */
  759. if((qabc_data[8] & 0xf0) == 0) {
  760. /* FIXME: 32 way 8 CPU slot monster cannot be
  761. * plumbed this way---need to check for it */
  762. printk("Plumbing second Extended Quad Processor\n");
  763. /* second VIC line hardwired to Quad CPU 1 */
  764. qabc_data[8] |= 0x20;
  765. cat_subwrite(*modpp, qabc_asic, 8, 1, &qabc_data[8]);
  766. #ifdef VOYAGER_CAT_DEBUG
  767. /* verify plumbing */
  768. cat_subread(*modpp, qabc_asic, 8, 1, &qabc_data[8]);
  769. if((qabc_data[8] & 0xf0) == 0) {
  770. CDEBUG(("PLUMBING FAILED: 0x%x\n", qabc_data[8]));
  771. }
  772. #endif
  773. }
  774. #endif
  775. {
  776. struct resource *res = kzalloc(sizeof(struct resource),GFP_KERNEL);
  777. res->name = kmalloc(128, GFP_KERNEL);
  778. sprintf((char *)res->name, "Voyager %s Quad CPI", cat_module_name(i));
  779. res->start = qic_addr;
  780. res->end = qic_addr + 0x3ff;
  781. request_resource(&iomem_resource, res);
  782. }
  783. qic_addr = (unsigned long)ioremap(qic_addr, 0x400);
  784. for(j = 0; j < 4; j++) {
  785. __u8 cpu;
  786. if(voyager_8slot) {
  787. /* 8 slot has a different mapping,
  788. * each slot has only one vic line, so
  789. * 1 cpu in each slot must be < 8 */
  790. cpu = (i & 0x07) + j*8;
  791. } else {
  792. cpu = (i & 0x03) + j*4;
  793. }
  794. if( (qabc_data[8] & (1<<j))) {
  795. voyager_extended_vic_processors |= (1<<cpu);
  796. }
  797. if(qabc_data[8] & (1<<(j+4)) ) {
  798. /* Second SET register plumbed: Quad
  799. * card has two VIC connected CPUs.
  800. * Secondary cannot be booted as a VIC
  801. * CPU */
  802. voyager_extended_vic_processors |= (1<<cpu);
  803. voyager_allowed_boot_processors &= (~(1<<cpu));
  804. }
  805. voyager_quad_processors |= (1<<cpu);
  806. voyager_quad_cpi_addr[cpu] = (struct voyager_qic_cpi *)
  807. (qic_addr+(j<<8));
  808. CDEBUG(("CPU%d: CPI address 0x%lx\n", cpu,
  809. (unsigned long)voyager_quad_cpi_addr[cpu]));
  810. }
  811. outb(VOYAGER_CAT_END, CAT_CMD);
  812. *asicpp = NULL;
  813. modpp = &((*modpp)->next);
  814. }
  815. *modpp = NULL;
  816. printk("CAT Bus Initialisation finished: extended procs 0x%x, quad procs 0x%x, allowed vic boot = 0x%x\n", voyager_extended_vic_processors, voyager_quad_processors, voyager_allowed_boot_processors);
  817. request_resource(&ioport_resource, &vic_res);
  818. if(voyager_quad_processors)
  819. request_resource(&ioport_resource, &qic_res);
  820. /* set up the front power switch */
  821. }
  822. int
  823. voyager_cat_readb(__u8 module, __u8 asic, int reg)
  824. {
  825. return 0;
  826. }
  827. static int
  828. cat_disconnect(voyager_module_t *modp, voyager_asic_t *asicp)
  829. {
  830. __u8 val;
  831. int err = 0;
  832. if(!modp->scan_path_connected)
  833. return 0;
  834. if(asicp->asic_id != VOYAGER_CAT_ID) {
  835. CDEBUG(("cat_disconnect: ASIC is not CAT\n"));
  836. return 1;
  837. }
  838. err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val);
  839. if(err) {
  840. CDEBUG(("cat_disconnect: failed to read SCANPATH\n"));
  841. return err;
  842. }
  843. val &= VOYAGER_DISCONNECT_ASIC;
  844. err = cat_write(modp, asicp, VOYAGER_SCANPATH, val);
  845. if(err) {
  846. CDEBUG(("cat_disconnect: failed to write SCANPATH\n"));
  847. return err;
  848. }
  849. outb(VOYAGER_CAT_END, CAT_CMD);
  850. outb(VOYAGER_CAT_RUN, CAT_CMD);
  851. modp->scan_path_connected = 0;
  852. return 0;
  853. }
  854. static int
  855. cat_connect(voyager_module_t *modp, voyager_asic_t *asicp)
  856. {
  857. __u8 val;
  858. int err = 0;
  859. if(modp->scan_path_connected)
  860. return 0;
  861. if(asicp->asic_id != VOYAGER_CAT_ID) {
  862. CDEBUG(("cat_connect: ASIC is not CAT\n"));
  863. return 1;
  864. }
  865. err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val);
  866. if(err) {
  867. CDEBUG(("cat_connect: failed to read SCANPATH\n"));
  868. return err;
  869. }
  870. val |= VOYAGER_CONNECT_ASIC;
  871. err = cat_write(modp, asicp, VOYAGER_SCANPATH, val);
  872. if(err) {
  873. CDEBUG(("cat_connect: failed to write SCANPATH\n"));
  874. return err;
  875. }
  876. outb(VOYAGER_CAT_END, CAT_CMD);
  877. outb(VOYAGER_CAT_RUN, CAT_CMD);
  878. modp->scan_path_connected = 1;
  879. return 0;
  880. }
  881. void
  882. voyager_cat_power_off(void)
  883. {
  884. /* Power the machine off by writing to the PSI over the CAT
  885. * bus */
  886. __u8 data;
  887. voyager_module_t psi = { 0 };
  888. voyager_asic_t psi_asic = { 0 };
  889. psi.asic = &psi_asic;
  890. psi.asic->asic_id = VOYAGER_CAT_ID;
  891. psi.asic->subaddr = VOYAGER_SUBADDR_HI;
  892. psi.module_addr = VOYAGER_PSI;
  893. psi.scan_path_connected = 0;
  894. outb(VOYAGER_CAT_END, CAT_CMD);
  895. /* Connect the PSI to the CAT Bus */
  896. outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
  897. outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
  898. outb(VOYAGER_CAT_RUN, CAT_CMD);
  899. cat_disconnect(&psi, &psi_asic);
  900. /* Read the status */
  901. cat_subread(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
  902. outb(VOYAGER_CAT_END, CAT_CMD);
  903. CDEBUG(("PSI STATUS 0x%x\n", data));
  904. /* These two writes are power off prep and perform */
  905. data = PSI_CLEAR;
  906. outb(VOYAGER_CAT_RUN, CAT_CMD);
  907. cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
  908. outb(VOYAGER_CAT_END, CAT_CMD);
  909. data = PSI_POWER_DOWN;
  910. outb(VOYAGER_CAT_RUN, CAT_CMD);
  911. cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
  912. outb(VOYAGER_CAT_END, CAT_CMD);
  913. }
  914. struct voyager_status voyager_status = { 0 };
  915. void
  916. voyager_cat_psi(__u8 cmd, __u16 reg, __u8 *data)
  917. {
  918. voyager_module_t psi = { 0 };
  919. voyager_asic_t psi_asic = { 0 };
  920. psi.asic = &psi_asic;
  921. psi.asic->asic_id = VOYAGER_CAT_ID;
  922. psi.asic->subaddr = VOYAGER_SUBADDR_HI;
  923. psi.module_addr = VOYAGER_PSI;
  924. psi.scan_path_connected = 0;
  925. outb(VOYAGER_CAT_END, CAT_CMD);
  926. /* Connect the PSI to the CAT Bus */
  927. outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
  928. outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
  929. outb(VOYAGER_CAT_RUN, CAT_CMD);
  930. cat_disconnect(&psi, &psi_asic);
  931. switch(cmd) {
  932. case VOYAGER_PSI_READ:
  933. cat_read(&psi, &psi_asic, reg, data);
  934. break;
  935. case VOYAGER_PSI_WRITE:
  936. cat_write(&psi, &psi_asic, reg, *data);
  937. break;
  938. case VOYAGER_PSI_SUBREAD:
  939. cat_subread(&psi, &psi_asic, reg, 1, data);
  940. break;
  941. case VOYAGER_PSI_SUBWRITE:
  942. cat_subwrite(&psi, &psi_asic, reg, 1, data);
  943. break;
  944. default:
  945. printk(KERN_ERR "Voyager PSI, unrecognised command %d\n", cmd);
  946. break;
  947. }
  948. outb(VOYAGER_CAT_END, CAT_CMD);
  949. }
  950. void
  951. voyager_cat_do_common_interrupt(void)
  952. {
  953. /* This is caused either by a memory parity error or something
  954. * in the PSI */
  955. __u8 data;
  956. voyager_module_t psi = { 0 };
  957. voyager_asic_t psi_asic = { 0 };
  958. struct voyager_psi psi_reg;
  959. int i;
  960. re_read:
  961. psi.asic = &psi_asic;
  962. psi.asic->asic_id = VOYAGER_CAT_ID;
  963. psi.asic->subaddr = VOYAGER_SUBADDR_HI;
  964. psi.module_addr = VOYAGER_PSI;
  965. psi.scan_path_connected = 0;
  966. outb(VOYAGER_CAT_END, CAT_CMD);
  967. /* Connect the PSI to the CAT Bus */
  968. outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
  969. outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
  970. outb(VOYAGER_CAT_RUN, CAT_CMD);
  971. cat_disconnect(&psi, &psi_asic);
  972. /* Read the status. NOTE: Need to read *all* the PSI regs here
  973. * otherwise the cmn int will be reasserted */
  974. for(i = 0; i < sizeof(psi_reg.regs); i++) {
  975. cat_read(&psi, &psi_asic, i, &((__u8 *)&psi_reg.regs)[i]);
  976. }
  977. outb(VOYAGER_CAT_END, CAT_CMD);
  978. if((psi_reg.regs.checkbit & 0x02) == 0) {
  979. psi_reg.regs.checkbit |= 0x02;
  980. cat_write(&psi, &psi_asic, 5, psi_reg.regs.checkbit);
  981. printk("VOYAGER RE-READ PSI\n");
  982. goto re_read;
  983. }
  984. outb(VOYAGER_CAT_RUN, CAT_CMD);
  985. for(i = 0; i < sizeof(psi_reg.subregs); i++) {
  986. /* This looks strange, but the PSI doesn't do auto increment
  987. * correctly */
  988. cat_subread(&psi, &psi_asic, VOYAGER_PSI_SUPPLY_REG + i,
  989. 1, &((__u8 *)&psi_reg.subregs)[i]);
  990. }
  991. outb(VOYAGER_CAT_END, CAT_CMD);
  992. #ifdef VOYAGER_CAT_DEBUG
  993. printk("VOYAGER PSI: ");
  994. for(i=0; i<sizeof(psi_reg.regs); i++)
  995. printk("%02x ", ((__u8 *)&psi_reg.regs)[i]);
  996. printk("\n ");
  997. for(i=0; i<sizeof(psi_reg.subregs); i++)
  998. printk("%02x ", ((__u8 *)&psi_reg.subregs)[i]);
  999. printk("\n");
  1000. #endif
  1001. if(psi_reg.regs.intstatus & PSI_MON) {
  1002. /* switch off or power fail */
  1003. if(psi_reg.subregs.supply & PSI_SWITCH_OFF) {
  1004. if(voyager_status.switch_off) {
  1005. printk(KERN_ERR "Voyager front panel switch turned off again---Immediate power off!\n");
  1006. voyager_cat_power_off();
  1007. /* not reached */
  1008. } else {
  1009. printk(KERN_ERR "Voyager front panel switch turned off\n");
  1010. voyager_status.switch_off = 1;
  1011. voyager_status.request_from_kernel = 1;
  1012. wake_up_process(voyager_thread);
  1013. }
  1014. /* Tell the hardware we're taking care of the
  1015. * shutdown, otherwise it will power the box off
  1016. * within 3 seconds of the switch being pressed and,
  1017. * which is much more important to us, continue to
  1018. * assert the common interrupt */
  1019. data = PSI_CLR_SWITCH_OFF;
  1020. outb(VOYAGER_CAT_RUN, CAT_CMD);
  1021. cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_SUPPLY_REG,
  1022. 1, &data);
  1023. outb(VOYAGER_CAT_END, CAT_CMD);
  1024. } else {
  1025. VDEBUG(("Voyager ac fail reg 0x%x\n",
  1026. psi_reg.subregs.ACfail));
  1027. if((psi_reg.subregs.ACfail & AC_FAIL_STAT_CHANGE) == 0) {
  1028. /* No further update */
  1029. return;
  1030. }
  1031. #if 0
  1032. /* Don't bother trying to find out who failed.
  1033. * FIXME: This probably makes the code incorrect on
  1034. * anything other than a 345x */
  1035. for(i=0; i< 5; i++) {
  1036. if( psi_reg.subregs.ACfail &(1<<i)) {
  1037. break;
  1038. }
  1039. }
  1040. printk(KERN_NOTICE "AC FAIL IN SUPPLY %d\n", i);
  1041. #endif
  1042. /* DON'T do this: it shuts down the AC PSI
  1043. outb(VOYAGER_CAT_RUN, CAT_CMD);
  1044. data = PSI_MASK_MASK | i;
  1045. cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_MASK,
  1046. 1, &data);
  1047. outb(VOYAGER_CAT_END, CAT_CMD);
  1048. */
  1049. printk(KERN_ERR "Voyager AC power failure\n");
  1050. outb(VOYAGER_CAT_RUN, CAT_CMD);
  1051. data = PSI_COLD_START;
  1052. cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG,
  1053. 1, &data);
  1054. outb(VOYAGER_CAT_END, CAT_CMD);
  1055. voyager_status.power_fail = 1;
  1056. voyager_status.request_from_kernel = 1;
  1057. wake_up_process(voyager_thread);
  1058. }
  1059. } else if(psi_reg.regs.intstatus & PSI_FAULT) {
  1060. /* Major fault! */
  1061. printk(KERN_ERR "Voyager PSI Detected major fault, immediate power off!\n");
  1062. voyager_cat_power_off();
  1063. /* not reached */
  1064. } else if(psi_reg.regs.intstatus & (PSI_DC_FAIL | PSI_ALARM
  1065. | PSI_CURRENT | PSI_DVM
  1066. | PSI_PSCFAULT | PSI_STAT_CHG)) {
  1067. /* other psi fault */
  1068. printk(KERN_WARNING "Voyager PSI status 0x%x\n", data);
  1069. /* clear the PSI fault */
  1070. outb(VOYAGER_CAT_RUN, CAT_CMD);
  1071. cat_write(&psi, &psi_asic, VOYAGER_PSI_STATUS_REG, 0);
  1072. outb(VOYAGER_CAT_END, CAT_CMD);
  1073. }
  1074. }