voyager_cat.c 35 KB

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