voyager_cat.c 35 KB

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