1 /* -*- mode: c; c-basic-offset: 8 -*- */
3 /* Copyright (C) 1999,2001
5 * Author: J.E.J.Bottomley@HansenPartnership.com
7 * linux/arch/i386/kernel/voyager_cat.c
9 * This file contains all the logic for manipulating the CAT bus
10 * in a level 5 machine.
12 * The CAT bus is a serial configuration and test bus. Its primary
13 * uses are to probe the initial configuration of the system and to
14 * diagnose error conditions when a system interrupt occurs. The low
15 * level interface is fairly primitive, so most of this file consists
16 * of bit shift manipulations to send and receive packets on the
19 #include <linux/config.h>
20 #include <linux/types.h>
21 #include <linux/completion.h>
22 #include <linux/sched.h>
23 #include <asm/voyager.h>
25 #include <linux/ioport.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <linux/delay.h>
31 #ifdef VOYAGER_CAT_DEBUG
32 #define CDEBUG(x) printk x
37 /* the CAT command port */
38 #define CAT_CMD (sspb + 0xe)
39 /* the CAT data port */
40 #define CAT_DATA (sspb + 0xd)
42 /* the internal cat functions */
43 static void cat_pack(__u8 *msg, __u16 start_bit, __u8 *data,
45 static void cat_unpack(__u8 *msg, __u16 start_bit, __u8 *data,
47 static void cat_build_header(__u8 *header, const __u16 len,
48 const __u16 smallest_reg_bits,
49 const __u16 longest_reg_bits);
50 static int cat_sendinst(voyager_module_t *modp, voyager_asic_t *asicp,
52 static int cat_getdata(voyager_module_t *modp, voyager_asic_t *asicp,
53 __u8 reg, __u8 *value);
54 static int cat_shiftout(__u8 *data, __u16 data_bytes, __u16 header_bytes,
56 static int cat_write(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
58 static int cat_read(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
60 static int cat_subread(voyager_module_t *modp, voyager_asic_t *asicp,
61 __u16 offset, __u16 len, void *buf);
62 static int cat_senddata(voyager_module_t *modp, voyager_asic_t *asicp,
63 __u8 reg, __u8 value);
64 static int cat_disconnect(voyager_module_t *modp, voyager_asic_t *asicp);
65 static int cat_connect(voyager_module_t *modp, voyager_asic_t *asicp);
67 static inline const char *
68 cat_module_name(int module_id)
72 return "Processor Slot 0";
74 return "Processor Slot 1";
76 return "Processor Slot 2";
78 return "Processor Slot 4";
80 return "Memory Slot 0";
82 return "Memory Slot 1";
84 return "Primary Microchannel";
86 return "Secondary Microchannel";
88 return "Power Supply Interface";
90 return "Processor Slot 5";
92 return "Processor Slot 6";
94 return "Processor Slot 7";
96 return "Processor Slot 8";
98 return "Unknown Module";
102 static int sspb = 0; /* stores the super port location */
103 int voyager_8slot = 0; /* set to true if a 51xx monster */
105 voyager_module_t *voyager_cat_list;
107 /* the I/O port assignments for the VIC and QIC */
108 static struct resource vic_res = {
109 .name = "Voyager Interrupt Controller",
113 static struct resource qic_res = {
114 .name = "Quad Interrupt Controller",
119 /* This function is used to pack a data bit stream inside a message.
120 * It writes num_bits of the data buffer in msg starting at start_bit.
121 * Note: This function assumes that any unused bit in the data stream
122 * is set to zero so that the ors will work correctly */
124 cat_pack(__u8 *msg, const __u16 start_bit, __u8 *data, const __u16 num_bits)
126 /* compute initial shift needed */
127 const __u16 offset = start_bit % BITS_PER_BYTE;
128 __u16 len = num_bits / BITS_PER_BYTE;
129 __u16 byte = start_bit / BITS_PER_BYTE;
130 __u16 residue = (num_bits % BITS_PER_BYTE) + offset;
133 /* adjust if we have more than a byte of residue */
134 if(residue >= BITS_PER_BYTE) {
135 residue -= BITS_PER_BYTE;
139 /* clear out the bits. We assume here that if len==0 then
140 * residue >= offset. This is always true for the catbus
142 msg[byte] &= 0xff << (BITS_PER_BYTE - offset);
143 msg[byte++] |= data[0] >> offset;
146 for(i = 1; i < len; i++)
147 msg[byte++] = (data[i-1] << (BITS_PER_BYTE - offset))
148 | (data[i] >> offset);
150 __u8 mask = 0xff >> residue;
151 __u8 last_byte = data[i-1] << (BITS_PER_BYTE - offset)
152 | (data[i] >> offset);
156 msg[byte] |= last_byte;
160 /* unpack the data again (same arguments as cat_pack()). data buffer
161 * must be zero populated.
163 * Function: given a message string move to start_bit and copy num_bits into
164 * data (starting at bit 0 in data).
167 cat_unpack(__u8 *msg, const __u16 start_bit, __u8 *data, const __u16 num_bits)
169 /* compute initial shift needed */
170 const __u16 offset = start_bit % BITS_PER_BYTE;
171 __u16 len = num_bits / BITS_PER_BYTE;
172 const __u8 last_bits = num_bits % BITS_PER_BYTE;
173 __u16 byte = start_bit / BITS_PER_BYTE;
179 /* special case: want < 8 bits from msg and we can get it from
180 * a single byte of the msg */
181 if(len == 0 && BITS_PER_BYTE - offset >= num_bits) {
182 data[0] = msg[byte] << offset;
183 data[0] &= 0xff >> (BITS_PER_BYTE - num_bits);
186 for(i = 0; i < len; i++) {
187 /* this annoying if has to be done just in case a read of
188 * msg one beyond the array causes a panic */
190 data[i] = msg[byte++] << offset;
191 data[i] |= msg[byte] >> (BITS_PER_BYTE - offset);
194 data[i] = msg[byte++];
197 /* do we need to truncate the final byte */
199 data[i-1] &= 0xff << (BITS_PER_BYTE - last_bits);
205 cat_build_header(__u8 *header, const __u16 len, const __u16 smallest_reg_bits,
206 const __u16 longest_reg_bits)
209 __u16 start_bit = (smallest_reg_bits - 1) % BITS_PER_BYTE;
210 __u8 *last_byte = &header[len - 1];
213 start_bit = 1; /* must have at least one bit in the hdr */
215 for(i=0; i < len; i++)
218 for(i = start_bit; i > 0; i--)
219 *last_byte = ((*last_byte) << 1) + 1;
224 cat_sendinst(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg, __u8 op)
226 __u8 parity, inst, inst_buf[4] = { 0 };
227 __u8 iseq[VOYAGER_MAX_SCAN_PATH], hseq[VOYAGER_MAX_REG_SIZE];
228 __u16 ibytes, hbytes, padbits;
232 * Parity is the parity of the register number + 1 (READ_REGISTER
233 * and WRITE_REGISTER always add '1' to the number of bits == 1)
235 parity = (__u8)(1 + (reg & 0x01) +
236 ((__u8)(reg & 0x02) >> 1) +
237 ((__u8)(reg & 0x04) >> 2) +
238 ((__u8)(reg & 0x08) >> 3)) % 2;
240 inst = ((parity << 7) | (reg << 2) | op);
242 outb(VOYAGER_CAT_IRCYC, CAT_CMD);
243 if(!modp->scan_path_connected) {
244 if(asicp->asic_id != VOYAGER_CAT_ID) {
245 printk("**WARNING***: cat_sendinst has disconnected scan path not to CAT asic\n");
248 outb(VOYAGER_CAT_HEADER, CAT_DATA);
249 outb(inst, CAT_DATA);
250 if(inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
251 CDEBUG(("VOYAGER CAT: cat_sendinst failed to get CAT_HEADER\n"));
256 ibytes = modp->inst_bits / BITS_PER_BYTE;
257 if((padbits = modp->inst_bits % BITS_PER_BYTE) != 0) {
258 padbits = BITS_PER_BYTE - padbits;
261 hbytes = modp->largest_reg / BITS_PER_BYTE;
262 if(modp->largest_reg % BITS_PER_BYTE)
264 CDEBUG(("cat_sendinst: ibytes=%d, hbytes=%d\n", ibytes, hbytes));
265 /* initialise the instruction sequence to 0xff */
266 for(i=0; i < ibytes + hbytes; i++)
268 cat_build_header(hseq, hbytes, modp->smallest_reg, modp->largest_reg);
269 cat_pack(iseq, modp->inst_bits, hseq, hbytes * BITS_PER_BYTE);
271 inst_buf[1] = 0xFF >> (modp->largest_reg % BITS_PER_BYTE);
272 cat_pack(iseq, asicp->bit_location, inst_buf, asicp->ireg_length);
273 #ifdef VOYAGER_CAT_DEBUG
274 printk("ins = 0x%x, iseq: ", inst);
275 for(i=0; i< ibytes + hbytes; i++)
276 printk("0x%x ", iseq[i]);
279 if(cat_shiftout(iseq, ibytes, hbytes, padbits)) {
280 CDEBUG(("VOYAGER CAT: cat_sendinst: cat_shiftout failed\n"));
283 CDEBUG(("CAT SHIFTOUT DONE\n"));
288 cat_getdata(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
291 if(!modp->scan_path_connected) {
292 if(asicp->asic_id != VOYAGER_CAT_ID) {
293 CDEBUG(("VOYAGER CAT: ERROR: cat_getdata to CAT asic with scan path connected\n"));
296 if(reg > VOYAGER_SUBADDRHI)
297 outb(VOYAGER_CAT_RUN, CAT_CMD);
298 outb(VOYAGER_CAT_DRCYC, CAT_CMD);
299 outb(VOYAGER_CAT_HEADER, CAT_DATA);
300 *value = inb(CAT_DATA);
301 outb(0xAA, CAT_DATA);
302 if(inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
303 CDEBUG(("cat_getdata: failed to get VOYAGER_CAT_HEADER\n"));
309 __u16 sbits = modp->num_asics -1 + asicp->ireg_length;
310 __u16 sbytes = sbits / BITS_PER_BYTE;
312 __u8 string[VOYAGER_MAX_SCAN_PATH], trailer[VOYAGER_MAX_REG_SIZE];
316 outb(VOYAGER_CAT_DRCYC, CAT_CMD);
318 if((padbits = sbits % BITS_PER_BYTE) != 0) {
319 padbits = BITS_PER_BYTE - padbits;
322 tbytes = asicp->ireg_length / BITS_PER_BYTE;
323 if(asicp->ireg_length % BITS_PER_BYTE)
325 CDEBUG(("cat_getdata: tbytes = %d, sbytes = %d, padbits = %d\n",
326 tbytes, sbytes, padbits));
327 cat_build_header(trailer, tbytes, 1, asicp->ireg_length);
330 for(i = tbytes - 1; i >= 0; i--) {
331 outb(trailer[i], CAT_DATA);
332 string[sbytes + i] = inb(CAT_DATA);
335 for(i = sbytes - 1; i >= 0; i--) {
336 outb(0xaa, CAT_DATA);
337 string[i] = inb(CAT_DATA);
340 cat_unpack(string, padbits + (tbytes * BITS_PER_BYTE) + asicp->asic_location, value, asicp->ireg_length);
341 #ifdef VOYAGER_CAT_DEBUG
342 printk("value=0x%x, string: ", *value);
343 for(i=0; i< tbytes+sbytes; i++)
344 printk("0x%x ", string[i]);
348 /* sanity check the rest of the return */
349 for(i=0; i < tbytes; i++) {
352 cat_unpack(string, padbits + (i * BITS_PER_BYTE), &input, BITS_PER_BYTE);
353 if(trailer[i] != input) {
354 CDEBUG(("cat_getdata: failed to sanity check rest of ret(%d) 0x%x != 0x%x\n", i, input, trailer[i]));
358 CDEBUG(("cat_getdata DONE\n"));
364 cat_shiftout(__u8 *data, __u16 data_bytes, __u16 header_bytes, __u8 pad_bits)
368 for(i = data_bytes + header_bytes - 1; i >= header_bytes; i--)
369 outb(data[i], CAT_DATA);
371 for(i = header_bytes - 1; i >= 0; i--) {
375 outb(data[i], CAT_DATA);
376 input = inb(CAT_DATA);
377 CDEBUG(("cat_shiftout: returned 0x%x\n", input));
378 cat_unpack(data, ((data_bytes + i) * BITS_PER_BYTE) - pad_bits,
379 &header, BITS_PER_BYTE);
380 if(input != header) {
381 CDEBUG(("VOYAGER CAT: cat_shiftout failed to return header 0x%x != 0x%x\n", input, header));
389 cat_senddata(voyager_module_t *modp, voyager_asic_t *asicp,
390 __u8 reg, __u8 value)
392 outb(VOYAGER_CAT_DRCYC, CAT_CMD);
393 if(!modp->scan_path_connected) {
394 if(asicp->asic_id != VOYAGER_CAT_ID) {
395 CDEBUG(("VOYAGER CAT: ERROR: scan path disconnected when asic != CAT\n"));
398 outb(VOYAGER_CAT_HEADER, CAT_DATA);
399 outb(value, CAT_DATA);
400 if(inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
401 CDEBUG(("cat_senddata: failed to get correct header response to sent data\n"));
404 if(reg > VOYAGER_SUBADDRHI) {
405 outb(VOYAGER_CAT_RUN, CAT_CMD);
406 outb(VOYAGER_CAT_END, CAT_CMD);
407 outb(VOYAGER_CAT_RUN, CAT_CMD);
413 __u16 hbytes = asicp->ireg_length / BITS_PER_BYTE;
414 __u16 dbytes = (modp->num_asics - 1 + asicp->ireg_length)/BITS_PER_BYTE;
415 __u8 padbits, dseq[VOYAGER_MAX_SCAN_PATH],
416 hseq[VOYAGER_MAX_REG_SIZE];
419 if((padbits = (modp->num_asics - 1
420 + asicp->ireg_length) % BITS_PER_BYTE) != 0) {
421 padbits = BITS_PER_BYTE - padbits;
424 if(asicp->ireg_length % BITS_PER_BYTE)
427 cat_build_header(hseq, hbytes, 1, asicp->ireg_length);
429 for(i = 0; i < dbytes + hbytes; i++)
431 CDEBUG(("cat_senddata: dbytes=%d, hbytes=%d, padbits=%d\n",
432 dbytes, hbytes, padbits));
433 cat_pack(dseq, modp->num_asics - 1 + asicp->ireg_length,
434 hseq, hbytes * BITS_PER_BYTE);
435 cat_pack(dseq, asicp->asic_location, &value,
437 #ifdef VOYAGER_CAT_DEBUG
439 for(i=0; i<hbytes+dbytes; i++) {
440 printk("0x%x ", dseq[i]);
444 return cat_shiftout(dseq, dbytes, hbytes, padbits);
449 cat_write(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
452 if(cat_sendinst(modp, asicp, reg, VOYAGER_WRITE_CONFIG))
454 return cat_senddata(modp, asicp, reg, value);
458 cat_read(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
461 if(cat_sendinst(modp, asicp, reg, VOYAGER_READ_CONFIG))
463 return cat_getdata(modp, asicp, reg, value);
467 cat_subaddrsetup(voyager_module_t *modp, voyager_asic_t *asicp, __u16 offset,
473 /* set auto increment */
476 if(cat_read(modp, asicp, VOYAGER_AUTO_INC_REG, &val)) {
477 CDEBUG(("cat_subaddrsetup: read of VOYAGER_AUTO_INC_REG failed\n"));
480 CDEBUG(("cat_subaddrsetup: VOYAGER_AUTO_INC_REG = 0x%x\n", val));
481 newval = val | VOYAGER_AUTO_INC;
483 if(cat_write(modp, asicp, VOYAGER_AUTO_INC_REG, val)) {
484 CDEBUG(("cat_subaddrsetup: write to VOYAGER_AUTO_INC_REG failed\n"));
489 if(cat_write(modp, asicp, VOYAGER_SUBADDRLO, (__u8)(offset &0xff))) {
490 CDEBUG(("cat_subaddrsetup: write to SUBADDRLO failed\n"));
493 if(asicp->subaddr > VOYAGER_SUBADDR_LO) {
494 if(cat_write(modp, asicp, VOYAGER_SUBADDRHI, (__u8)(offset >> 8))) {
495 CDEBUG(("cat_subaddrsetup: write to SUBADDRHI failed\n"));
498 cat_read(modp, asicp, VOYAGER_SUBADDRHI, &val);
499 CDEBUG(("cat_subaddrsetup: offset = %d, hi = %d\n", offset, val));
501 cat_read(modp, asicp, VOYAGER_SUBADDRLO, &val);
502 CDEBUG(("cat_subaddrsetup: offset = %d, lo = %d\n", offset, val));
507 cat_subwrite(voyager_module_t *modp, voyager_asic_t *asicp, __u16 offset,
508 __u16 len, void *buf)
512 /* FIXME: need special actions for VOYAGER_CAT_ID here */
513 if(asicp->asic_id == VOYAGER_CAT_ID) {
514 CDEBUG(("cat_subwrite: ATTEMPT TO WRITE TO CAT ASIC\n"));
515 /* FIXME -- This is supposed to be handled better
516 * There is a problem writing to the cat asic in the
517 * PSI. The 30us delay seems to work, though */
521 if((retval = cat_subaddrsetup(modp, asicp, offset, len)) != 0) {
522 printk("cat_subwrite: cat_subaddrsetup FAILED\n");
526 if(cat_sendinst(modp, asicp, VOYAGER_SUBADDRDATA, VOYAGER_WRITE_CONFIG)) {
527 printk("cat_subwrite: cat_sendinst FAILED\n");
530 for(i = 0; i < len; i++) {
531 if(cat_senddata(modp, asicp, 0xFF, ((__u8 *)buf)[i])) {
532 printk("cat_subwrite: cat_sendata element at %d FAILED\n", i);
539 cat_subread(voyager_module_t *modp, voyager_asic_t *asicp, __u16 offset,
540 __u16 len, void *buf)
544 if((retval = cat_subaddrsetup(modp, asicp, offset, len)) != 0) {
545 CDEBUG(("cat_subread: cat_subaddrsetup FAILED\n"));
549 if(cat_sendinst(modp, asicp, VOYAGER_SUBADDRDATA, VOYAGER_READ_CONFIG)) {
550 CDEBUG(("cat_subread: cat_sendinst failed\n"));
553 for(i = 0; i < len; i++) {
554 if(cat_getdata(modp, asicp, 0xFF,
555 &((__u8 *)buf)[i])) {
556 CDEBUG(("cat_subread: cat_getdata element %d failed\n", i));
564 /* buffer for storing EPROM data read in during initialisation */
565 static __initdata __u8 eprom_buf[0xFFFF];
566 static voyager_module_t *voyager_initial_module;
568 /* Initialise the cat bus components. We assume this is called by the
569 * boot cpu *after* all memory initialisation has been done (so we can
570 * use kmalloc) but before smp initialisation, so we can probe the SMP
571 * configuration and pick up necessary information. */
573 voyager_cat_init(void)
575 voyager_module_t **modpp = &voyager_initial_module;
576 voyager_asic_t **asicpp;
577 voyager_asic_t *qabc_asic = NULL;
579 unsigned long qic_addr = 0;
580 __u8 qabc_data[0x20];
581 __u8 num_submodules, val;
582 voyager_eprom_hdr_t *eprom_hdr = (voyager_eprom_hdr_t *)&eprom_buf[0];
587 /* initiallise the SUS mailbox */
588 for(i=0; i<sizeof(cmos); i++)
589 cmos[i] = voyager_extended_cmos_read(VOYAGER_DUMP_LOCATION + i);
590 addr = *(unsigned long *)cmos;
591 if((addr & 0xff000000) != 0xff000000) {
592 printk(KERN_ERR "Voyager failed to get SUS mailbox (addr = 0x%lx\n", addr);
594 static struct resource res;
596 res.name = "voyager SUS";
598 res.end = addr+0x3ff;
600 request_resource(&iomem_resource, &res);
601 voyager_SUS = (struct voyager_SUS *)
602 ioremap(addr, 0x400);
603 printk(KERN_NOTICE "Voyager SUS mailbox version 0x%x\n",
604 voyager_SUS->SUS_version);
605 voyager_SUS->kernel_version = VOYAGER_MAILBOX_VERSION;
606 voyager_SUS->kernel_flags = VOYAGER_OS_HAS_SYSINT;
609 /* clear the processor counts */
610 voyager_extended_vic_processors = 0;
611 voyager_quad_processors = 0;
615 printk("VOYAGER: beginning CAT bus probe\n");
616 /* set up the SuperSet Port Block which tells us where the
617 * CAT communication port is */
618 sspb = inb(VOYAGER_SSPB_RELOCATION_PORT) * 0x100;
619 VDEBUG(("VOYAGER DEBUG: sspb = 0x%x\n", sspb));
621 /* now find out if were 8 slot or normal */
622 if((inb(VIC_PROC_WHO_AM_I) & EIGHT_SLOT_IDENTIFIER)
623 == EIGHT_SLOT_IDENTIFIER) {
625 printk(KERN_NOTICE "Voyager: Eight slot 51xx configuration detected\n");
628 for(i = VOYAGER_MIN_MODULE;
629 i <= VOYAGER_MAX_MODULE; i++) {
635 outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
636 outb(i, VOYAGER_CAT_CONFIG_PORT);
638 /* check the presence of the module */
639 outb(VOYAGER_CAT_RUN, CAT_CMD);
640 outb(VOYAGER_CAT_IRCYC, CAT_CMD);
641 outb(VOYAGER_CAT_HEADER, CAT_DATA);
642 /* stream series of alternating 1's and 0's to stimulate
644 outb(0xAA, CAT_DATA);
645 input = inb(CAT_DATA);
646 outb(VOYAGER_CAT_END, CAT_CMD);
647 if(input != VOYAGER_CAT_HEADER) {
650 CDEBUG(("VOYAGER DEBUG: found module id 0x%x, %s\n", i,
651 cat_module_name(i)));
652 *modpp = kmalloc(sizeof(voyager_module_t), GFP_KERNEL); /*&voyager_module_storage[cat_count++];*/
654 printk("**WARNING** kmalloc failure in cat_init\n");
657 memset(*modpp, 0, sizeof(voyager_module_t));
658 /* need temporary asic for cat_subread. It will be
659 * filled in correctly later */
660 (*modpp)->asic = kmalloc(sizeof(voyager_asic_t), GFP_KERNEL); /*&voyager_asic_storage[asic_count];*/
661 if((*modpp)->asic == NULL) {
662 printk("**WARNING** kmalloc failure in cat_init\n");
665 memset((*modpp)->asic, 0, sizeof(voyager_asic_t));
666 (*modpp)->asic->asic_id = VOYAGER_CAT_ID;
667 (*modpp)->asic->subaddr = VOYAGER_SUBADDR_HI;
668 (*modpp)->module_addr = i;
669 (*modpp)->scan_path_connected = 0;
670 if(i == VOYAGER_PSI) {
671 /* Exception leg for modules with no EEPROM */
672 printk("Module \"%s\"\n", cat_module_name(i));
676 CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i, VOYAGER_XSUM_END_OFFSET));
677 outb(VOYAGER_CAT_RUN, CAT_CMD);
678 cat_disconnect(*modpp, (*modpp)->asic);
679 if(cat_subread(*modpp, (*modpp)->asic,
680 VOYAGER_XSUM_END_OFFSET, sizeof(eprom_size),
682 printk("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n", i);
683 outb(VOYAGER_CAT_END, CAT_CMD);
686 if(eprom_size > sizeof(eprom_buf)) {
687 printk("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x. Need %d\n", i, eprom_size);
688 outb(VOYAGER_CAT_END, CAT_CMD);
691 outb(VOYAGER_CAT_END, CAT_CMD);
692 outb(VOYAGER_CAT_RUN, CAT_CMD);
693 CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i, eprom_size));
694 if(cat_subread(*modpp, (*modpp)->asic, 0,
695 eprom_size, eprom_buf)) {
696 outb(VOYAGER_CAT_END, CAT_CMD);
699 outb(VOYAGER_CAT_END, CAT_CMD);
700 printk("Module \"%s\", version 0x%x, tracer 0x%x, asics %d\n",
701 cat_module_name(i), eprom_hdr->version_id,
702 *((__u32 *)eprom_hdr->tracer), eprom_hdr->num_asics);
703 (*modpp)->ee_size = eprom_hdr->ee_size;
704 (*modpp)->num_asics = eprom_hdr->num_asics;
705 asicpp = &((*modpp)->asic);
706 sp_offset = eprom_hdr->scan_path_offset;
707 /* All we really care about are the Quad cards. We
708 * identify them because they are in a processor slot
709 * and have only four asics */
710 if((i < 0x10 || (i>=0x14 && i < 0x1c) || i>0x1f)) {
711 modpp = &((*modpp)->next);
714 /* Now we know it's in a processor slot, does it have
715 * a quad baseboard submodule */
716 outb(VOYAGER_CAT_RUN, CAT_CMD);
717 cat_read(*modpp, (*modpp)->asic, VOYAGER_SUBMODPRESENT,
719 /* lowest two bits, active low */
720 num_submodules = ~(0xfc | num_submodules);
721 CDEBUG(("VOYAGER CAT: %d submodules present\n", num_submodules));
722 if(num_submodules == 0) {
723 /* fill in the dyadic extended processors */
726 printk("Module \"%s\": Dyadic Processor Card\n",
728 voyager_extended_vic_processors |= (1<<cpu);
730 voyager_extended_vic_processors |= (1<<cpu);
731 outb(VOYAGER_CAT_END, CAT_CMD);
735 /* now we want to read the asics on the first submodule,
736 * which should be the quad base board */
738 cat_read(*modpp, (*modpp)->asic, VOYAGER_SUBMODSELECT, &val);
739 CDEBUG(("cat_init: SUBMODSELECT value = 0x%x\n", val));
740 val = (val & 0x7c) | VOYAGER_QUAD_BASEBOARD;
741 cat_write(*modpp, (*modpp)->asic, VOYAGER_SUBMODSELECT, val);
743 outb(VOYAGER_CAT_END, CAT_CMD);
746 CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i, VOYAGER_XSUM_END_OFFSET));
747 outb(VOYAGER_CAT_RUN, CAT_CMD);
748 cat_disconnect(*modpp, (*modpp)->asic);
749 if(cat_subread(*modpp, (*modpp)->asic,
750 VOYAGER_XSUM_END_OFFSET, sizeof(eprom_size),
752 printk("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n", i);
753 outb(VOYAGER_CAT_END, CAT_CMD);
756 if(eprom_size > sizeof(eprom_buf)) {
757 printk("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x. Need %d\n", i, eprom_size);
758 outb(VOYAGER_CAT_END, CAT_CMD);
761 outb(VOYAGER_CAT_END, CAT_CMD);
762 outb(VOYAGER_CAT_RUN, CAT_CMD);
763 CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i, eprom_size));
764 if(cat_subread(*modpp, (*modpp)->asic, 0,
765 eprom_size, eprom_buf)) {
766 outb(VOYAGER_CAT_END, CAT_CMD);
769 outb(VOYAGER_CAT_END, CAT_CMD);
770 /* Now do everything for the QBB submodule 1 */
771 (*modpp)->ee_size = eprom_hdr->ee_size;
772 (*modpp)->num_asics = eprom_hdr->num_asics;
773 asicpp = &((*modpp)->asic);
774 sp_offset = eprom_hdr->scan_path_offset;
775 /* get rid of the dummy CAT asic and read the real one */
776 kfree((*modpp)->asic);
777 for(asic=0; asic < (*modpp)->num_asics; asic++) {
779 voyager_asic_t *asicp = *asicpp
780 = kmalloc(sizeof(voyager_asic_t), GFP_KERNEL); /*&voyager_asic_storage[asic_count++];*/
781 voyager_sp_table_t *sp_table;
782 voyager_at_t *asic_table;
783 voyager_jtt_t *jtag_table;
786 printk("**WARNING** kmalloc failure in cat_init\n");
789 memset(asicp, 0, sizeof(voyager_asic_t));
790 asicpp = &(asicp->next);
791 asicp->asic_location = asic;
792 sp_table = (voyager_sp_table_t *)(eprom_buf + sp_offset);
793 asicp->asic_id = sp_table->asic_id;
794 asic_table = (voyager_at_t *)(eprom_buf + sp_table->asic_data_offset);
796 asicp->jtag_id[j] = asic_table->jtag_id[j];
797 jtag_table = (voyager_jtt_t *)(eprom_buf + asic_table->jtag_offset);
798 asicp->ireg_length = jtag_table->ireg_len;
799 asicp->bit_location = (*modpp)->inst_bits;
800 (*modpp)->inst_bits += asicp->ireg_length;
801 if(asicp->ireg_length > (*modpp)->largest_reg)
802 (*modpp)->largest_reg = asicp->ireg_length;
803 if (asicp->ireg_length < (*modpp)->smallest_reg ||
804 (*modpp)->smallest_reg == 0)
805 (*modpp)->smallest_reg = asicp->ireg_length;
806 CDEBUG(("asic 0x%x, ireg_length=%d, bit_location=%d\n",
807 asicp->asic_id, asicp->ireg_length,
808 asicp->bit_location));
809 if(asicp->asic_id == VOYAGER_QUAD_QABC) {
810 CDEBUG(("VOYAGER CAT: QABC ASIC found\n"));
813 sp_offset += sizeof(voyager_sp_table_t);
815 CDEBUG(("Module inst_bits = %d, largest_reg = %d, smallest_reg=%d\n",
816 (*modpp)->inst_bits, (*modpp)->largest_reg,
817 (*modpp)->smallest_reg));
818 /* OK, now we have the QUAD ASICs set up, use them.
821 * 1. Find the Memory area for the Quad CPIs.
822 * 2. Find the Extended VIC processor
823 * 3. Configure a second extended VIC processor (This
824 * cannot be done for the 51xx.
826 outb(VOYAGER_CAT_RUN, CAT_CMD);
827 cat_connect(*modpp, (*modpp)->asic);
828 CDEBUG(("CAT CONNECTED!!\n"));
829 cat_subread(*modpp, qabc_asic, 0, sizeof(qabc_data), qabc_data);
830 qic_addr = qabc_data[5] << 8;
831 qic_addr = (qic_addr | qabc_data[6]) << 8;
832 qic_addr = (qic_addr | qabc_data[7]) << 8;
833 printk("Module \"%s\": Quad Processor Card; CPI 0x%lx, SET=0x%x\n",
834 cat_module_name(i), qic_addr, qabc_data[8]);
835 #if 0 /* plumbing fails---FIXME */
836 if((qabc_data[8] & 0xf0) == 0) {
837 /* FIXME: 32 way 8 CPU slot monster cannot be
838 * plumbed this way---need to check for it */
840 printk("Plumbing second Extended Quad Processor\n");
841 /* second VIC line hardwired to Quad CPU 1 */
842 qabc_data[8] |= 0x20;
843 cat_subwrite(*modpp, qabc_asic, 8, 1, &qabc_data[8]);
844 #ifdef VOYAGER_CAT_DEBUG
845 /* verify plumbing */
846 cat_subread(*modpp, qabc_asic, 8, 1, &qabc_data[8]);
847 if((qabc_data[8] & 0xf0) == 0) {
848 CDEBUG(("PLUMBING FAILED: 0x%x\n", qabc_data[8]));
855 struct resource *res = kmalloc(sizeof(struct resource),GFP_KERNEL);
856 memset(res, 0, sizeof(struct resource));
857 res->name = kmalloc(128, GFP_KERNEL);
858 sprintf((char *)res->name, "Voyager %s Quad CPI", cat_module_name(i));
859 res->start = qic_addr;
860 res->end = qic_addr + 0x3ff;
861 request_resource(&iomem_resource, res);
864 qic_addr = (unsigned long)ioremap(qic_addr, 0x400);
866 for(j = 0; j < 4; j++) {
870 /* 8 slot has a different mapping,
871 * each slot has only one vic line, so
872 * 1 cpu in each slot must be < 8 */
873 cpu = (i & 0x07) + j*8;
875 cpu = (i & 0x03) + j*4;
877 if( (qabc_data[8] & (1<<j))) {
878 voyager_extended_vic_processors |= (1<<cpu);
880 if(qabc_data[8] & (1<<(j+4)) ) {
881 /* Second SET register plumbed: Quad
882 * card has two VIC connected CPUs.
883 * Secondary cannot be booted as a VIC
885 voyager_extended_vic_processors |= (1<<cpu);
886 voyager_allowed_boot_processors &= (~(1<<cpu));
889 voyager_quad_processors |= (1<<cpu);
890 voyager_quad_cpi_addr[cpu] = (struct voyager_qic_cpi *)
892 CDEBUG(("CPU%d: CPI address 0x%lx\n", cpu,
893 (unsigned long)voyager_quad_cpi_addr[cpu]));
895 outb(VOYAGER_CAT_END, CAT_CMD);
900 modpp = &((*modpp)->next);
903 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);
904 request_resource(&ioport_resource, &vic_res);
905 if(voyager_quad_processors)
906 request_resource(&ioport_resource, &qic_res);
907 /* set up the front power switch */
911 voyager_cat_readb(__u8 module, __u8 asic, int reg)
917 cat_disconnect(voyager_module_t *modp, voyager_asic_t *asicp)
922 if(!modp->scan_path_connected)
924 if(asicp->asic_id != VOYAGER_CAT_ID) {
925 CDEBUG(("cat_disconnect: ASIC is not CAT\n"));
928 err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val);
930 CDEBUG(("cat_disconnect: failed to read SCANPATH\n"));
933 val &= VOYAGER_DISCONNECT_ASIC;
934 err = cat_write(modp, asicp, VOYAGER_SCANPATH, val);
936 CDEBUG(("cat_disconnect: failed to write SCANPATH\n"));
939 outb(VOYAGER_CAT_END, CAT_CMD);
940 outb(VOYAGER_CAT_RUN, CAT_CMD);
941 modp->scan_path_connected = 0;
947 cat_connect(voyager_module_t *modp, voyager_asic_t *asicp)
952 if(modp->scan_path_connected)
954 if(asicp->asic_id != VOYAGER_CAT_ID) {
955 CDEBUG(("cat_connect: ASIC is not CAT\n"));
959 err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val);
961 CDEBUG(("cat_connect: failed to read SCANPATH\n"));
964 val |= VOYAGER_CONNECT_ASIC;
965 err = cat_write(modp, asicp, VOYAGER_SCANPATH, val);
967 CDEBUG(("cat_connect: failed to write SCANPATH\n"));
970 outb(VOYAGER_CAT_END, CAT_CMD);
971 outb(VOYAGER_CAT_RUN, CAT_CMD);
972 modp->scan_path_connected = 1;
978 voyager_cat_power_off(void)
980 /* Power the machine off by writing to the PSI over the CAT
983 voyager_module_t psi = { 0 };
984 voyager_asic_t psi_asic = { 0 };
986 psi.asic = &psi_asic;
987 psi.asic->asic_id = VOYAGER_CAT_ID;
988 psi.asic->subaddr = VOYAGER_SUBADDR_HI;
989 psi.module_addr = VOYAGER_PSI;
990 psi.scan_path_connected = 0;
992 outb(VOYAGER_CAT_END, CAT_CMD);
993 /* Connect the PSI to the CAT Bus */
994 outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
995 outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
996 outb(VOYAGER_CAT_RUN, CAT_CMD);
997 cat_disconnect(&psi, &psi_asic);
998 /* Read the status */
999 cat_subread(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
1000 outb(VOYAGER_CAT_END, CAT_CMD);
1001 CDEBUG(("PSI STATUS 0x%x\n", data));
1002 /* These two writes are power off prep and perform */
1004 outb(VOYAGER_CAT_RUN, CAT_CMD);
1005 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
1006 outb(VOYAGER_CAT_END, CAT_CMD);
1007 data = PSI_POWER_DOWN;
1008 outb(VOYAGER_CAT_RUN, CAT_CMD);
1009 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG, 1, &data);
1010 outb(VOYAGER_CAT_END, CAT_CMD);
1013 struct voyager_status voyager_status = { 0 };
1016 voyager_cat_psi(__u8 cmd, __u16 reg, __u8 *data)
1018 voyager_module_t psi = { 0 };
1019 voyager_asic_t psi_asic = { 0 };
1021 psi.asic = &psi_asic;
1022 psi.asic->asic_id = VOYAGER_CAT_ID;
1023 psi.asic->subaddr = VOYAGER_SUBADDR_HI;
1024 psi.module_addr = VOYAGER_PSI;
1025 psi.scan_path_connected = 0;
1027 outb(VOYAGER_CAT_END, CAT_CMD);
1028 /* Connect the PSI to the CAT Bus */
1029 outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
1030 outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
1031 outb(VOYAGER_CAT_RUN, CAT_CMD);
1032 cat_disconnect(&psi, &psi_asic);
1034 case VOYAGER_PSI_READ:
1035 cat_read(&psi, &psi_asic, reg, data);
1037 case VOYAGER_PSI_WRITE:
1038 cat_write(&psi, &psi_asic, reg, *data);
1040 case VOYAGER_PSI_SUBREAD:
1041 cat_subread(&psi, &psi_asic, reg, 1, data);
1043 case VOYAGER_PSI_SUBWRITE:
1044 cat_subwrite(&psi, &psi_asic, reg, 1, data);
1047 printk(KERN_ERR "Voyager PSI, unrecognised command %d\n", cmd);
1050 outb(VOYAGER_CAT_END, CAT_CMD);
1054 voyager_cat_do_common_interrupt(void)
1056 /* This is caused either by a memory parity error or something
1059 voyager_module_t psi = { 0 };
1060 voyager_asic_t psi_asic = { 0 };
1061 struct voyager_psi psi_reg;
1064 psi.asic = &psi_asic;
1065 psi.asic->asic_id = VOYAGER_CAT_ID;
1066 psi.asic->subaddr = VOYAGER_SUBADDR_HI;
1067 psi.module_addr = VOYAGER_PSI;
1068 psi.scan_path_connected = 0;
1070 outb(VOYAGER_CAT_END, CAT_CMD);
1071 /* Connect the PSI to the CAT Bus */
1072 outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
1073 outb(VOYAGER_PSI, VOYAGER_CAT_CONFIG_PORT);
1074 outb(VOYAGER_CAT_RUN, CAT_CMD);
1075 cat_disconnect(&psi, &psi_asic);
1076 /* Read the status. NOTE: Need to read *all* the PSI regs here
1077 * otherwise the cmn int will be reasserted */
1078 for(i = 0; i < sizeof(psi_reg.regs); i++) {
1079 cat_read(&psi, &psi_asic, i, &((__u8 *)&psi_reg.regs)[i]);
1081 outb(VOYAGER_CAT_END, CAT_CMD);
1082 if((psi_reg.regs.checkbit & 0x02) == 0) {
1083 psi_reg.regs.checkbit |= 0x02;
1084 cat_write(&psi, &psi_asic, 5, psi_reg.regs.checkbit);
1085 printk("VOYAGER RE-READ PSI\n");
1088 outb(VOYAGER_CAT_RUN, CAT_CMD);
1089 for(i = 0; i < sizeof(psi_reg.subregs); i++) {
1090 /* This looks strange, but the PSI doesn't do auto increment
1092 cat_subread(&psi, &psi_asic, VOYAGER_PSI_SUPPLY_REG + i,
1093 1, &((__u8 *)&psi_reg.subregs)[i]);
1095 outb(VOYAGER_CAT_END, CAT_CMD);
1096 #ifdef VOYAGER_CAT_DEBUG
1097 printk("VOYAGER PSI: ");
1098 for(i=0; i<sizeof(psi_reg.regs); i++)
1099 printk("%02x ", ((__u8 *)&psi_reg.regs)[i]);
1101 for(i=0; i<sizeof(psi_reg.subregs); i++)
1102 printk("%02x ", ((__u8 *)&psi_reg.subregs)[i]);
1105 if(psi_reg.regs.intstatus & PSI_MON) {
1106 /* switch off or power fail */
1108 if(psi_reg.subregs.supply & PSI_SWITCH_OFF) {
1109 if(voyager_status.switch_off) {
1110 printk(KERN_ERR "Voyager front panel switch turned off again---Immediate power off!\n");
1111 voyager_cat_power_off();
1114 printk(KERN_ERR "Voyager front panel switch turned off\n");
1115 voyager_status.switch_off = 1;
1116 voyager_status.request_from_kernel = 1;
1119 /* Tell the hardware we're taking care of the
1120 * shutdown, otherwise it will power the box off
1121 * within 3 seconds of the switch being pressed and,
1122 * which is much more important to us, continue to
1123 * assert the common interrupt */
1124 data = PSI_CLR_SWITCH_OFF;
1125 outb(VOYAGER_CAT_RUN, CAT_CMD);
1126 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_SUPPLY_REG,
1128 outb(VOYAGER_CAT_END, CAT_CMD);
1131 VDEBUG(("Voyager ac fail reg 0x%x\n",
1132 psi_reg.subregs.ACfail));
1133 if((psi_reg.subregs.ACfail & AC_FAIL_STAT_CHANGE) == 0) {
1134 /* No further update */
1138 /* Don't bother trying to find out who failed.
1139 * FIXME: This probably makes the code incorrect on
1140 * anything other than a 345x */
1141 for(i=0; i< 5; i++) {
1142 if( psi_reg.subregs.ACfail &(1<<i)) {
1146 printk(KERN_NOTICE "AC FAIL IN SUPPLY %d\n", i);
1148 /* DON'T do this: it shuts down the AC PSI
1149 outb(VOYAGER_CAT_RUN, CAT_CMD);
1150 data = PSI_MASK_MASK | i;
1151 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_MASK,
1153 outb(VOYAGER_CAT_END, CAT_CMD);
1155 printk(KERN_ERR "Voyager AC power failure\n");
1156 outb(VOYAGER_CAT_RUN, CAT_CMD);
1157 data = PSI_COLD_START;
1158 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_GENERAL_REG,
1160 outb(VOYAGER_CAT_END, CAT_CMD);
1161 voyager_status.power_fail = 1;
1162 voyager_status.request_from_kernel = 1;
1167 } else if(psi_reg.regs.intstatus & PSI_FAULT) {
1169 printk(KERN_ERR "Voyager PSI Detected major fault, immediate power off!\n");
1170 voyager_cat_power_off();
1172 } else if(psi_reg.regs.intstatus & (PSI_DC_FAIL | PSI_ALARM
1173 | PSI_CURRENT | PSI_DVM
1174 | PSI_PSCFAULT | PSI_STAT_CHG)) {
1175 /* other psi fault */
1177 printk(KERN_WARNING "Voyager PSI status 0x%x\n", data);
1178 /* clear the PSI fault */
1179 outb(VOYAGER_CAT_RUN, CAT_CMD);
1180 cat_write(&psi, &psi_asic, VOYAGER_PSI_STATUS_REG, 0);
1181 outb(VOYAGER_CAT_END, CAT_CMD);