voyager_cat.c 35 KB

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