voyager_cat.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  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. = kmalloc(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. memset(asicp, 0, sizeof(voyager_asic_t));
  714. asicpp = &(asicp->next);
  715. asicp->asic_location = asic;
  716. sp_table = (voyager_sp_table_t *)(eprom_buf + sp_offset);
  717. asicp->asic_id = sp_table->asic_id;
  718. asic_table = (voyager_at_t *)(eprom_buf + sp_table->asic_data_offset);
  719. for(j=0; j<4; j++)
  720. asicp->jtag_id[j] = asic_table->jtag_id[j];
  721. jtag_table = (voyager_jtt_t *)(eprom_buf + asic_table->jtag_offset);
  722. asicp->ireg_length = jtag_table->ireg_len;
  723. asicp->bit_location = (*modpp)->inst_bits;
  724. (*modpp)->inst_bits += asicp->ireg_length;
  725. if(asicp->ireg_length > (*modpp)->largest_reg)
  726. (*modpp)->largest_reg = asicp->ireg_length;
  727. if (asicp->ireg_length < (*modpp)->smallest_reg ||
  728. (*modpp)->smallest_reg == 0)
  729. (*modpp)->smallest_reg = asicp->ireg_length;
  730. CDEBUG(("asic 0x%x, ireg_length=%d, bit_location=%d\n",
  731. asicp->asic_id, asicp->ireg_length,
  732. asicp->bit_location));
  733. if(asicp->asic_id == VOYAGER_QUAD_QABC) {
  734. CDEBUG(("VOYAGER CAT: QABC ASIC found\n"));
  735. qabc_asic = asicp;
  736. }
  737. sp_offset += sizeof(voyager_sp_table_t);
  738. }
  739. CDEBUG(("Module inst_bits = %d, largest_reg = %d, smallest_reg=%d\n",
  740. (*modpp)->inst_bits, (*modpp)->largest_reg,
  741. (*modpp)->smallest_reg));
  742. /* OK, now we have the QUAD ASICs set up, use them.
  743. * we need to:
  744. *
  745. * 1. Find the Memory area for the Quad CPIs.
  746. * 2. Find the Extended VIC processor
  747. * 3. Configure a second extended VIC processor (This
  748. * cannot be done for the 51xx.
  749. * */
  750. outb(VOYAGER_CAT_RUN, CAT_CMD);
  751. cat_connect(*modpp, (*modpp)->asic);
  752. CDEBUG(("CAT CONNECTED!!\n"));
  753. cat_subread(*modpp, qabc_asic, 0, sizeof(qabc_data), qabc_data);
  754. qic_addr = qabc_data[5] << 8;
  755. qic_addr = (qic_addr | qabc_data[6]) << 8;
  756. qic_addr = (qic_addr | qabc_data[7]) << 8;
  757. printk("Module \"%s\": Quad Processor Card; CPI 0x%lx, SET=0x%x\n",
  758. cat_module_name(i), qic_addr, qabc_data[8]);
  759. #if 0 /* plumbing fails---FIXME */
  760. if((qabc_data[8] & 0xf0) == 0) {
  761. /* FIXME: 32 way 8 CPU slot monster cannot be
  762. * plumbed this way---need to check for it */
  763. printk("Plumbing second Extended Quad Processor\n");
  764. /* second VIC line hardwired to Quad CPU 1 */
  765. qabc_data[8] |= 0x20;
  766. cat_subwrite(*modpp, qabc_asic, 8, 1, &qabc_data[8]);
  767. #ifdef VOYAGER_CAT_DEBUG
  768. /* verify plumbing */
  769. cat_subread(*modpp, qabc_asic, 8, 1, &qabc_data[8]);
  770. if((qabc_data[8] & 0xf0) == 0) {
  771. CDEBUG(("PLUMBING FAILED: 0x%x\n", qabc_data[8]));
  772. }
  773. #endif
  774. }
  775. #endif
  776. {
  777. struct resource *res = kmalloc(sizeof(struct resource),GFP_KERNEL);
  778. memset(res, 0, sizeof(struct resource));
  779. res->name = kmalloc(128, GFP_KERNEL);
  780. sprintf((char *)res->name, "Voyager %s Quad CPI", cat_module_name(i));
  781. res->start = qic_addr;
  782. res->end = qic_addr + 0x3ff;
  783. request_resource(&iomem_resource, res);
  784. }
  785. qic_addr = (unsigned long)ioremap(qic_addr, 0x400);
  786. for(j = 0; j < 4; j++) {
  787. __u8 cpu;
  788. if(voyager_8slot) {
  789. /* 8 slot has a different mapping,
  790. * each slot has only one vic line, so
  791. * 1 cpu in each slot must be < 8 */
  792. cpu = (i & 0x07) + j*8;
  793. } else {
  794. cpu = (i & 0x03) + j*4;
  795. }
  796. if( (qabc_data[8] & (1<<j))) {
  797. voyager_extended_vic_processors |= (1<<cpu);
  798. }
  799. if(qabc_data[8] & (1<<(j+4)) ) {
  800. /* Second SET register plumbed: Quad
  801. * card has two VIC connected CPUs.
  802. * Secondary cannot be booted as a VIC
  803. * CPU */
  804. voyager_extended_vic_processors |= (1<<cpu);
  805. voyager_allowed_boot_processors &= (~(1<<cpu));
  806. }
  807. voyager_quad_processors |= (1<<cpu);
  808. voyager_quad_cpi_addr[cpu] = (struct voyager_qic_cpi *)
  809. (qic_addr+(j<<8));
  810. CDEBUG(("CPU%d: CPI address 0x%lx\n", cpu,
  811. (unsigned long)voyager_quad_cpi_addr[cpu]));
  812. }
  813. outb(VOYAGER_CAT_END, CAT_CMD);
  814. *asicpp = NULL;
  815. modpp = &((*modpp)->next);
  816. }
  817. *modpp = NULL;
  818. 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);
  819. request_resource(&ioport_resource, &vic_res);
  820. if(voyager_quad_processors)
  821. request_resource(&ioport_resource, &qic_res);
  822. /* set up the front power switch */
  823. }
  824. int
  825. voyager_cat_readb(__u8 module, __u8 asic, int reg)
  826. {
  827. return 0;
  828. }
  829. static int
  830. cat_disconnect(voyager_module_t *modp, voyager_asic_t *asicp)
  831. {
  832. __u8 val;
  833. int err = 0;
  834. if(!modp->scan_path_connected)
  835. return 0;
  836. if(asicp->asic_id != VOYAGER_CAT_ID) {
  837. CDEBUG(("cat_disconnect: ASIC is not CAT\n"));
  838. return 1;
  839. }
  840. err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val);
  841. if(err) {
  842. CDEBUG(("cat_disconnect: failed to read SCANPATH\n"));
  843. return err;
  844. }
  845. val &= VOYAGER_DISCONNECT_ASIC;
  846. err = cat_write(modp, asicp, VOYAGER_SCANPATH, val);
  847. if(err) {
  848. CDEBUG(("cat_disconnect: failed to write SCANPATH\n"));
  849. return err;
  850. }
  851. outb(VOYAGER_CAT_END, CAT_CMD);
  852. outb(VOYAGER_CAT_RUN, CAT_CMD);
  853. modp->scan_path_connected = 0;
  854. return 0;
  855. }
  856. static int
  857. cat_connect(voyager_module_t *modp, voyager_asic_t *asicp)
  858. {
  859. __u8 val;
  860. int err = 0;
  861. if(modp->scan_path_connected)
  862. return 0;
  863. if(asicp->asic_id != VOYAGER_CAT_ID) {
  864. CDEBUG(("cat_connect: ASIC is not CAT\n"));
  865. return 1;
  866. }
  867. err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val);
  868. if(err) {
  869. CDEBUG(("cat_connect: failed to read SCANPATH\n"));
  870. return err;
  871. }
  872. val |= VOYAGER_CONNECT_ASIC;
  873. err = cat_write(modp, asicp, VOYAGER_SCANPATH, val);
  874. if(err) {
  875. CDEBUG(("cat_connect: failed to write SCANPATH\n"));
  876. return err;
  877. }
  878. outb(VOYAGER_CAT_END, CAT_CMD);
  879. outb(VOYAGER_CAT_RUN, CAT_CMD);
  880. modp->scan_path_connected = 1;
  881. return 0;
  882. }
  883. void
  884. voyager_cat_power_off(void)
  885. {
  886. /* Power the machine off by writing to the PSI over the CAT
  887. * bus */
  888. __u8 data;
  889. voyager_module_t psi = { 0 };
  890. voyager_asic_t psi_asic = { 0 };
  891. psi.asic = &psi_asic;
  892. psi.asic->asic_id = VOYAGER_CAT_ID;
  893. psi.asic->subaddr = VOYAGER_SUBADDR_HI;
  894. psi.module_addr = VOYAGER_PSI;
  895. psi.scan_path_connected = 0;
  896. outb(VOYAGER_CAT_END, CAT_CMD);
  897. /* Connect the PSI to the CAT Bus */
  898. outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
  899. outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
  900. outb(VOYAGER_CAT_RUN, CAT_CMD);
  901. cat_disconnect(&psi, &psi_asic);
  902. /* Read the status */
  903. cat_subread(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
  904. outb(VOYAGER_CAT_END, CAT_CMD);
  905. CDEBUG(("PSI STATUS 0x%x\n", data));
  906. /* These two writes are power off prep and perform */
  907. data = PSI_CLEAR;
  908. outb(VOYAGER_CAT_RUN, CAT_CMD);
  909. cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
  910. outb(VOYAGER_CAT_END, CAT_CMD);
  911. data = PSI_POWER_DOWN;
  912. outb(VOYAGER_CAT_RUN, CAT_CMD);
  913. cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
  914. outb(VOYAGER_CAT_END, CAT_CMD);
  915. }
  916. struct voyager_status voyager_status = { 0 };
  917. void
  918. voyager_cat_psi(__u8 cmd, __u16 reg, __u8 *data)
  919. {
  920. voyager_module_t psi = { 0 };
  921. voyager_asic_t psi_asic = { 0 };
  922. psi.asic = &psi_asic;
  923. psi.asic->asic_id = VOYAGER_CAT_ID;
  924. psi.asic->subaddr = VOYAGER_SUBADDR_HI;
  925. psi.module_addr = VOYAGER_PSI;
  926. psi.scan_path_connected = 0;
  927. outb(VOYAGER_CAT_END, CAT_CMD);
  928. /* Connect the PSI to the CAT Bus */
  929. outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
  930. outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
  931. outb(VOYAGER_CAT_RUN, CAT_CMD);
  932. cat_disconnect(&psi, &psi_asic);
  933. switch(cmd) {
  934. case VOYAGER_PSI_READ:
  935. cat_read(&psi, &psi_asic, reg, data);
  936. break;
  937. case VOYAGER_PSI_WRITE:
  938. cat_write(&psi, &psi_asic, reg, *data);
  939. break;
  940. case VOYAGER_PSI_SUBREAD:
  941. cat_subread(&psi, &psi_asic, reg, 1, data);
  942. break;
  943. case VOYAGER_PSI_SUBWRITE:
  944. cat_subwrite(&psi, &psi_asic, reg, 1, data);
  945. break;
  946. default:
  947. printk(KERN_ERR "Voyager PSI, unrecognised command %d\n", cmd);
  948. break;
  949. }
  950. outb(VOYAGER_CAT_END, CAT_CMD);
  951. }
  952. void
  953. voyager_cat_do_common_interrupt(void)
  954. {
  955. /* This is caused either by a memory parity error or something
  956. * in the PSI */
  957. __u8 data;
  958. voyager_module_t psi = { 0 };
  959. voyager_asic_t psi_asic = { 0 };
  960. struct voyager_psi psi_reg;
  961. int i;
  962. re_read:
  963. psi.asic = &psi_asic;
  964. psi.asic->asic_id = VOYAGER_CAT_ID;
  965. psi.asic->subaddr = VOYAGER_SUBADDR_HI;
  966. psi.module_addr = VOYAGER_PSI;
  967. psi.scan_path_connected = 0;
  968. outb(VOYAGER_CAT_END, CAT_CMD);
  969. /* Connect the PSI to the CAT Bus */
  970. outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
  971. outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
  972. outb(VOYAGER_CAT_RUN, CAT_CMD);
  973. cat_disconnect(&psi, &psi_asic);
  974. /* Read the status. NOTE: Need to read *all* the PSI regs here
  975. * otherwise the cmn int will be reasserted */
  976. for(i = 0; i < sizeof(psi_reg.regs); i++) {
  977. cat_read(&psi, &psi_asic, i, &((__u8 *)&psi_reg.regs)[i]);
  978. }
  979. outb(VOYAGER_CAT_END, CAT_CMD);
  980. if((psi_reg.regs.checkbit & 0x02) == 0) {
  981. psi_reg.regs.checkbit |= 0x02;
  982. cat_write(&psi, &psi_asic, 5, psi_reg.regs.checkbit);
  983. printk("VOYAGER RE-READ PSI\n");
  984. goto re_read;
  985. }
  986. outb(VOYAGER_CAT_RUN, CAT_CMD);
  987. for(i = 0; i < sizeof(psi_reg.subregs); i++) {
  988. /* This looks strange, but the PSI doesn't do auto increment
  989. * correctly */
  990. cat_subread(&psi, &psi_asic, VOYAGER_PSI_SUPPLY_REG + i,
  991. 1, &((__u8 *)&psi_reg.subregs)[i]);
  992. }
  993. outb(VOYAGER_CAT_END, CAT_CMD);
  994. #ifdef VOYAGER_CAT_DEBUG
  995. printk("VOYAGER PSI: ");
  996. for(i=0; i<sizeof(psi_reg.regs); i++)
  997. printk("%02x ", ((__u8 *)&psi_reg.regs)[i]);
  998. printk("\n ");
  999. for(i=0; i<sizeof(psi_reg.subregs); i++)
  1000. printk("%02x ", ((__u8 *)&psi_reg.subregs)[i]);
  1001. printk("\n");
  1002. #endif
  1003. if(psi_reg.regs.intstatus & PSI_MON) {
  1004. /* switch off or power fail */
  1005. if(psi_reg.subregs.supply & PSI_SWITCH_OFF) {
  1006. if(voyager_status.switch_off) {
  1007. printk(KERN_ERR "Voyager front panel switch turned off again---Immediate power off!\n");
  1008. voyager_cat_power_off();
  1009. /* not reached */
  1010. } else {
  1011. printk(KERN_ERR "Voyager front panel switch turned off\n");
  1012. voyager_status.switch_off = 1;
  1013. voyager_status.request_from_kernel = 1;
  1014. up(&kvoyagerd_sem);
  1015. }
  1016. /* Tell the hardware we're taking care of the
  1017. * shutdown, otherwise it will power the box off
  1018. * within 3 seconds of the switch being pressed and,
  1019. * which is much more important to us, continue to
  1020. * assert the common interrupt */
  1021. data = PSI_CLR_SWITCH_OFF;
  1022. outb(VOYAGER_CAT_RUN, CAT_CMD);
  1023. cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_SUPPLY_REG,
  1024. 1, &data);
  1025. outb(VOYAGER_CAT_END, CAT_CMD);
  1026. } else {
  1027. VDEBUG(("Voyager ac fail reg 0x%x\n",
  1028. psi_reg.subregs.ACfail));
  1029. if((psi_reg.subregs.ACfail & AC_FAIL_STAT_CHANGE) == 0) {
  1030. /* No further update */
  1031. return;
  1032. }
  1033. #if 0
  1034. /* Don't bother trying to find out who failed.
  1035. * FIXME: This probably makes the code incorrect on
  1036. * anything other than a 345x */
  1037. for(i=0; i< 5; i++) {
  1038. if( psi_reg.subregs.ACfail &(1<<i)) {
  1039. break;
  1040. }
  1041. }
  1042. printk(KERN_NOTICE "AC FAIL IN SUPPLY %d\n", i);
  1043. #endif
  1044. /* DON'T do this: it shuts down the AC PSI
  1045. outb(VOYAGER_CAT_RUN, CAT_CMD);
  1046. data = PSI_MASK_MASK | i;
  1047. cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_MASK,
  1048. 1, &data);
  1049. outb(VOYAGER_CAT_END, CAT_CMD);
  1050. */
  1051. printk(KERN_ERR "Voyager AC power failure\n");
  1052. outb(VOYAGER_CAT_RUN, CAT_CMD);
  1053. data = PSI_COLD_START;
  1054. cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG,
  1055. 1, &data);
  1056. outb(VOYAGER_CAT_END, CAT_CMD);
  1057. voyager_status.power_fail = 1;
  1058. voyager_status.request_from_kernel = 1;
  1059. up(&kvoyagerd_sem);
  1060. }
  1061. } else if(psi_reg.regs.intstatus & PSI_FAULT) {
  1062. /* Major fault! */
  1063. printk(KERN_ERR "Voyager PSI Detected major fault, immediate power off!\n");
  1064. voyager_cat_power_off();
  1065. /* not reached */
  1066. } else if(psi_reg.regs.intstatus & (PSI_DC_FAIL | PSI_ALARM
  1067. | PSI_CURRENT | PSI_DVM
  1068. | PSI_PSCFAULT | PSI_STAT_CHG)) {
  1069. /* other psi fault */
  1070. printk(KERN_WARNING "Voyager PSI status 0x%x\n", data);
  1071. /* clear the PSI fault */
  1072. outb(VOYAGER_CAT_RUN, CAT_CMD);
  1073. cat_write(&psi, &psi_asic, VOYAGER_PSI_STATUS_REG, 0);
  1074. outb(VOYAGER_CAT_END, CAT_CMD);
  1075. }
  1076. }