voyager_cat.c 35 KB

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