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/types.h>
20 #include <linux/completion.h>
21 #include <linux/sched.h>
22 #include <asm/voyager.h>
24 #include <linux/ioport.h>
25 #include <linux/init.h>
26 #include <linux/slab.h>
27 #include <linux/delay.h>
30 #ifdef VOYAGER_CAT_DEBUG
31 #define CDEBUG(x) printk x
36 /* the CAT command port */
37 #define CAT_CMD (sspb + 0xe)
38 /* the CAT data port */
39 #define CAT_DATA (sspb + 0xd)
41 /* the internal cat functions */
42 static void cat_pack(__u8
*msg
, __u16 start_bit
, __u8
*data
,
44 static void cat_unpack(__u8
*msg
, __u16 start_bit
, __u8
*data
,
46 static void cat_build_header(__u8
*header
, const __u16 len
,
47 const __u16 smallest_reg_bits
,
48 const __u16 longest_reg_bits
);
49 static int cat_sendinst(voyager_module_t
*modp
, voyager_asic_t
*asicp
,
51 static int cat_getdata(voyager_module_t
*modp
, voyager_asic_t
*asicp
,
52 __u8 reg
, __u8
*value
);
53 static int cat_shiftout(__u8
*data
, __u16 data_bytes
, __u16 header_bytes
,
55 static int cat_write(voyager_module_t
*modp
, voyager_asic_t
*asicp
, __u8 reg
,
57 static int cat_read(voyager_module_t
*modp
, voyager_asic_t
*asicp
, __u8 reg
,
59 static int cat_subread(voyager_module_t
*modp
, voyager_asic_t
*asicp
,
60 __u16 offset
, __u16 len
, void *buf
);
61 static int cat_senddata(voyager_module_t
*modp
, voyager_asic_t
*asicp
,
62 __u8 reg
, __u8 value
);
63 static int cat_disconnect(voyager_module_t
*modp
, voyager_asic_t
*asicp
);
64 static int cat_connect(voyager_module_t
*modp
, voyager_asic_t
*asicp
);
66 static inline const char *
67 cat_module_name(int module_id
)
71 return "Processor Slot 0";
73 return "Processor Slot 1";
75 return "Processor Slot 2";
77 return "Processor Slot 4";
79 return "Memory Slot 0";
81 return "Memory Slot 1";
83 return "Primary Microchannel";
85 return "Secondary Microchannel";
87 return "Power Supply Interface";
89 return "Processor Slot 5";
91 return "Processor Slot 6";
93 return "Processor Slot 7";
95 return "Processor Slot 8";
97 return "Unknown Module";
101 static int sspb
= 0; /* stores the super port location */
102 int voyager_8slot
= 0; /* set to true if a 51xx monster */
104 voyager_module_t
*voyager_cat_list
;
106 /* the I/O port assignments for the VIC and QIC */
107 static struct resource vic_res
= {
108 .name
= "Voyager Interrupt Controller",
112 static struct resource qic_res
= {
113 .name
= "Quad Interrupt Controller",
118 /* This function is used to pack a data bit stream inside a message.
119 * It writes num_bits of the data buffer in msg starting at start_bit.
120 * Note: This function assumes that any unused bit in the data stream
121 * is set to zero so that the ors will work correctly */
123 cat_pack(__u8
*msg
, const __u16 start_bit
, __u8
*data
, const __u16 num_bits
)
125 /* compute initial shift needed */
126 const __u16 offset
= start_bit
% BITS_PER_BYTE
;
127 __u16 len
= num_bits
/ BITS_PER_BYTE
;
128 __u16 byte
= start_bit
/ BITS_PER_BYTE
;
129 __u16 residue
= (num_bits
% BITS_PER_BYTE
) + offset
;
132 /* adjust if we have more than a byte of residue */
133 if(residue
>= BITS_PER_BYTE
) {
134 residue
-= BITS_PER_BYTE
;
138 /* clear out the bits. We assume here that if len==0 then
139 * residue >= offset. This is always true for the catbus
141 msg
[byte
] &= 0xff << (BITS_PER_BYTE
- offset
);
142 msg
[byte
++] |= data
[0] >> offset
;
145 for(i
= 1; i
< len
; i
++)
146 msg
[byte
++] = (data
[i
-1] << (BITS_PER_BYTE
- offset
))
147 | (data
[i
] >> offset
);
149 __u8 mask
= 0xff >> residue
;
150 __u8 last_byte
= data
[i
-1] << (BITS_PER_BYTE
- offset
)
151 | (data
[i
] >> offset
);
155 msg
[byte
] |= last_byte
;
159 /* unpack the data again (same arguments as cat_pack()). data buffer
160 * must be zero populated.
162 * Function: given a message string move to start_bit and copy num_bits into
163 * data (starting at bit 0 in data).
166 cat_unpack(__u8
*msg
, const __u16 start_bit
, __u8
*data
, const __u16 num_bits
)
168 /* compute initial shift needed */
169 const __u16 offset
= start_bit
% BITS_PER_BYTE
;
170 __u16 len
= num_bits
/ BITS_PER_BYTE
;
171 const __u8 last_bits
= num_bits
% BITS_PER_BYTE
;
172 __u16 byte
= start_bit
/ BITS_PER_BYTE
;
178 /* special case: want < 8 bits from msg and we can get it from
179 * a single byte of the msg */
180 if(len
== 0 && BITS_PER_BYTE
- offset
>= num_bits
) {
181 data
[0] = msg
[byte
] << offset
;
182 data
[0] &= 0xff >> (BITS_PER_BYTE
- num_bits
);
185 for(i
= 0; i
< len
; i
++) {
186 /* this annoying if has to be done just in case a read of
187 * msg one beyond the array causes a panic */
189 data
[i
] = msg
[byte
++] << offset
;
190 data
[i
] |= msg
[byte
] >> (BITS_PER_BYTE
- offset
);
193 data
[i
] = msg
[byte
++];
196 /* do we need to truncate the final byte */
198 data
[i
-1] &= 0xff << (BITS_PER_BYTE
- last_bits
);
204 cat_build_header(__u8
*header
, const __u16 len
, const __u16 smallest_reg_bits
,
205 const __u16 longest_reg_bits
)
208 __u16 start_bit
= (smallest_reg_bits
- 1) % BITS_PER_BYTE
;
209 __u8
*last_byte
= &header
[len
- 1];
212 start_bit
= 1; /* must have at least one bit in the hdr */
214 for(i
=0; i
< len
; i
++)
217 for(i
= start_bit
; i
> 0; i
--)
218 *last_byte
= ((*last_byte
) << 1) + 1;
223 cat_sendinst(voyager_module_t
*modp
, voyager_asic_t
*asicp
, __u8 reg
, __u8 op
)
225 __u8 parity
, inst
, inst_buf
[4] = { 0 };
226 __u8 iseq
[VOYAGER_MAX_SCAN_PATH
], hseq
[VOYAGER_MAX_REG_SIZE
];
227 __u16 ibytes
, hbytes
, padbits
;
231 * Parity is the parity of the register number + 1 (READ_REGISTER
232 * and WRITE_REGISTER always add '1' to the number of bits == 1)
234 parity
= (__u8
)(1 + (reg
& 0x01) +
235 ((__u8
)(reg
& 0x02) >> 1) +
236 ((__u8
)(reg
& 0x04) >> 2) +
237 ((__u8
)(reg
& 0x08) >> 3)) % 2;
239 inst
= ((parity
<< 7) | (reg
<< 2) | op
);
241 outb(VOYAGER_CAT_IRCYC
, CAT_CMD
);
242 if(!modp
->scan_path_connected
) {
243 if(asicp
->asic_id
!= VOYAGER_CAT_ID
) {
244 printk("**WARNING***: cat_sendinst has disconnected scan path not to CAT asic\n");
247 outb(VOYAGER_CAT_HEADER
, CAT_DATA
);
248 outb(inst
, CAT_DATA
);
249 if(inb(CAT_DATA
) != VOYAGER_CAT_HEADER
) {
250 CDEBUG(("VOYAGER CAT: cat_sendinst failed to get CAT_HEADER\n"));
255 ibytes
= modp
->inst_bits
/ BITS_PER_BYTE
;
256 if((padbits
= modp
->inst_bits
% BITS_PER_BYTE
) != 0) {
257 padbits
= BITS_PER_BYTE
- padbits
;
260 hbytes
= modp
->largest_reg
/ BITS_PER_BYTE
;
261 if(modp
->largest_reg
% BITS_PER_BYTE
)
263 CDEBUG(("cat_sendinst: ibytes=%d, hbytes=%d\n", ibytes
, hbytes
));
264 /* initialise the instruction sequence to 0xff */
265 for(i
=0; i
< ibytes
+ hbytes
; i
++)
267 cat_build_header(hseq
, hbytes
, modp
->smallest_reg
, modp
->largest_reg
);
268 cat_pack(iseq
, modp
->inst_bits
, hseq
, hbytes
* BITS_PER_BYTE
);
270 inst_buf
[1] = 0xFF >> (modp
->largest_reg
% BITS_PER_BYTE
);
271 cat_pack(iseq
, asicp
->bit_location
, inst_buf
, asicp
->ireg_length
);
272 #ifdef VOYAGER_CAT_DEBUG
273 printk("ins = 0x%x, iseq: ", inst
);
274 for(i
=0; i
< ibytes
+ hbytes
; i
++)
275 printk("0x%x ", iseq
[i
]);
278 if(cat_shiftout(iseq
, ibytes
, hbytes
, padbits
)) {
279 CDEBUG(("VOYAGER CAT: cat_sendinst: cat_shiftout failed\n"));
282 CDEBUG(("CAT SHIFTOUT DONE\n"));
287 cat_getdata(voyager_module_t
*modp
, voyager_asic_t
*asicp
, __u8 reg
,
290 if(!modp
->scan_path_connected
) {
291 if(asicp
->asic_id
!= VOYAGER_CAT_ID
) {
292 CDEBUG(("VOYAGER CAT: ERROR: cat_getdata to CAT asic with scan path connected\n"));
295 if(reg
> VOYAGER_SUBADDRHI
)
296 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
297 outb(VOYAGER_CAT_DRCYC
, CAT_CMD
);
298 outb(VOYAGER_CAT_HEADER
, CAT_DATA
);
299 *value
= inb(CAT_DATA
);
300 outb(0xAA, CAT_DATA
);
301 if(inb(CAT_DATA
) != VOYAGER_CAT_HEADER
) {
302 CDEBUG(("cat_getdata: failed to get VOYAGER_CAT_HEADER\n"));
308 __u16 sbits
= modp
->num_asics
-1 + asicp
->ireg_length
;
309 __u16 sbytes
= sbits
/ BITS_PER_BYTE
;
311 __u8 string
[VOYAGER_MAX_SCAN_PATH
], trailer
[VOYAGER_MAX_REG_SIZE
];
315 outb(VOYAGER_CAT_DRCYC
, CAT_CMD
);
317 if((padbits
= sbits
% BITS_PER_BYTE
) != 0) {
318 padbits
= BITS_PER_BYTE
- padbits
;
321 tbytes
= asicp
->ireg_length
/ BITS_PER_BYTE
;
322 if(asicp
->ireg_length
% BITS_PER_BYTE
)
324 CDEBUG(("cat_getdata: tbytes = %d, sbytes = %d, padbits = %d\n",
325 tbytes
, sbytes
, padbits
));
326 cat_build_header(trailer
, tbytes
, 1, asicp
->ireg_length
);
329 for(i
= tbytes
- 1; i
>= 0; i
--) {
330 outb(trailer
[i
], CAT_DATA
);
331 string
[sbytes
+ i
] = inb(CAT_DATA
);
334 for(i
= sbytes
- 1; i
>= 0; i
--) {
335 outb(0xaa, CAT_DATA
);
336 string
[i
] = inb(CAT_DATA
);
339 cat_unpack(string
, padbits
+ (tbytes
* BITS_PER_BYTE
) + asicp
->asic_location
, value
, asicp
->ireg_length
);
340 #ifdef VOYAGER_CAT_DEBUG
341 printk("value=0x%x, string: ", *value
);
342 for(i
=0; i
< tbytes
+sbytes
; i
++)
343 printk("0x%x ", string
[i
]);
347 /* sanity check the rest of the return */
348 for(i
=0; i
< tbytes
; i
++) {
351 cat_unpack(string
, padbits
+ (i
* BITS_PER_BYTE
), &input
, BITS_PER_BYTE
);
352 if(trailer
[i
] != input
) {
353 CDEBUG(("cat_getdata: failed to sanity check rest of ret(%d) 0x%x != 0x%x\n", i
, input
, trailer
[i
]));
357 CDEBUG(("cat_getdata DONE\n"));
363 cat_shiftout(__u8
*data
, __u16 data_bytes
, __u16 header_bytes
, __u8 pad_bits
)
367 for(i
= data_bytes
+ header_bytes
- 1; i
>= header_bytes
; i
--)
368 outb(data
[i
], CAT_DATA
);
370 for(i
= header_bytes
- 1; i
>= 0; i
--) {
374 outb(data
[i
], CAT_DATA
);
375 input
= inb(CAT_DATA
);
376 CDEBUG(("cat_shiftout: returned 0x%x\n", input
));
377 cat_unpack(data
, ((data_bytes
+ i
) * BITS_PER_BYTE
) - pad_bits
,
378 &header
, BITS_PER_BYTE
);
379 if(input
!= header
) {
380 CDEBUG(("VOYAGER CAT: cat_shiftout failed to return header 0x%x != 0x%x\n", input
, header
));
388 cat_senddata(voyager_module_t
*modp
, voyager_asic_t
*asicp
,
389 __u8 reg
, __u8 value
)
391 outb(VOYAGER_CAT_DRCYC
, CAT_CMD
);
392 if(!modp
->scan_path_connected
) {
393 if(asicp
->asic_id
!= VOYAGER_CAT_ID
) {
394 CDEBUG(("VOYAGER CAT: ERROR: scan path disconnected when asic != CAT\n"));
397 outb(VOYAGER_CAT_HEADER
, CAT_DATA
);
398 outb(value
, CAT_DATA
);
399 if(inb(CAT_DATA
) != VOYAGER_CAT_HEADER
) {
400 CDEBUG(("cat_senddata: failed to get correct header response to sent data\n"));
403 if(reg
> VOYAGER_SUBADDRHI
) {
404 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
405 outb(VOYAGER_CAT_END
, CAT_CMD
);
406 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
412 __u16 hbytes
= asicp
->ireg_length
/ BITS_PER_BYTE
;
413 __u16 dbytes
= (modp
->num_asics
- 1 + asicp
->ireg_length
)/BITS_PER_BYTE
;
414 __u8 padbits
, dseq
[VOYAGER_MAX_SCAN_PATH
],
415 hseq
[VOYAGER_MAX_REG_SIZE
];
418 if((padbits
= (modp
->num_asics
- 1
419 + asicp
->ireg_length
) % BITS_PER_BYTE
) != 0) {
420 padbits
= BITS_PER_BYTE
- padbits
;
423 if(asicp
->ireg_length
% BITS_PER_BYTE
)
426 cat_build_header(hseq
, hbytes
, 1, asicp
->ireg_length
);
428 for(i
= 0; i
< dbytes
+ hbytes
; i
++)
430 CDEBUG(("cat_senddata: dbytes=%d, hbytes=%d, padbits=%d\n",
431 dbytes
, hbytes
, padbits
));
432 cat_pack(dseq
, modp
->num_asics
- 1 + asicp
->ireg_length
,
433 hseq
, hbytes
* BITS_PER_BYTE
);
434 cat_pack(dseq
, asicp
->asic_location
, &value
,
436 #ifdef VOYAGER_CAT_DEBUG
438 for(i
=0; i
<hbytes
+dbytes
; i
++) {
439 printk("0x%x ", dseq
[i
]);
443 return cat_shiftout(dseq
, dbytes
, hbytes
, padbits
);
448 cat_write(voyager_module_t
*modp
, voyager_asic_t
*asicp
, __u8 reg
,
451 if(cat_sendinst(modp
, asicp
, reg
, VOYAGER_WRITE_CONFIG
))
453 return cat_senddata(modp
, asicp
, reg
, value
);
457 cat_read(voyager_module_t
*modp
, voyager_asic_t
*asicp
, __u8 reg
,
460 if(cat_sendinst(modp
, asicp
, reg
, VOYAGER_READ_CONFIG
))
462 return cat_getdata(modp
, asicp
, reg
, value
);
466 cat_subaddrsetup(voyager_module_t
*modp
, voyager_asic_t
*asicp
, __u16 offset
,
472 /* set auto increment */
475 if(cat_read(modp
, asicp
, VOYAGER_AUTO_INC_REG
, &val
)) {
476 CDEBUG(("cat_subaddrsetup: read of VOYAGER_AUTO_INC_REG failed\n"));
479 CDEBUG(("cat_subaddrsetup: VOYAGER_AUTO_INC_REG = 0x%x\n", val
));
480 newval
= val
| VOYAGER_AUTO_INC
;
482 if(cat_write(modp
, asicp
, VOYAGER_AUTO_INC_REG
, val
)) {
483 CDEBUG(("cat_subaddrsetup: write to VOYAGER_AUTO_INC_REG failed\n"));
488 if(cat_write(modp
, asicp
, VOYAGER_SUBADDRLO
, (__u8
)(offset
&0xff))) {
489 CDEBUG(("cat_subaddrsetup: write to SUBADDRLO failed\n"));
492 if(asicp
->subaddr
> VOYAGER_SUBADDR_LO
) {
493 if(cat_write(modp
, asicp
, VOYAGER_SUBADDRHI
, (__u8
)(offset
>> 8))) {
494 CDEBUG(("cat_subaddrsetup: write to SUBADDRHI failed\n"));
497 cat_read(modp
, asicp
, VOYAGER_SUBADDRHI
, &val
);
498 CDEBUG(("cat_subaddrsetup: offset = %d, hi = %d\n", offset
, val
));
500 cat_read(modp
, asicp
, VOYAGER_SUBADDRLO
, &val
);
501 CDEBUG(("cat_subaddrsetup: offset = %d, lo = %d\n", offset
, val
));
506 cat_subwrite(voyager_module_t
*modp
, voyager_asic_t
*asicp
, __u16 offset
,
507 __u16 len
, void *buf
)
511 /* FIXME: need special actions for VOYAGER_CAT_ID here */
512 if(asicp
->asic_id
== VOYAGER_CAT_ID
) {
513 CDEBUG(("cat_subwrite: ATTEMPT TO WRITE TO CAT ASIC\n"));
514 /* FIXME -- This is supposed to be handled better
515 * There is a problem writing to the cat asic in the
516 * PSI. The 30us delay seems to work, though */
520 if((retval
= cat_subaddrsetup(modp
, asicp
, offset
, len
)) != 0) {
521 printk("cat_subwrite: cat_subaddrsetup FAILED\n");
525 if(cat_sendinst(modp
, asicp
, VOYAGER_SUBADDRDATA
, VOYAGER_WRITE_CONFIG
)) {
526 printk("cat_subwrite: cat_sendinst FAILED\n");
529 for(i
= 0; i
< len
; i
++) {
530 if(cat_senddata(modp
, asicp
, 0xFF, ((__u8
*)buf
)[i
])) {
531 printk("cat_subwrite: cat_sendata element at %d FAILED\n", i
);
538 cat_subread(voyager_module_t
*modp
, voyager_asic_t
*asicp
, __u16 offset
,
539 __u16 len
, void *buf
)
543 if((retval
= cat_subaddrsetup(modp
, asicp
, offset
, len
)) != 0) {
544 CDEBUG(("cat_subread: cat_subaddrsetup FAILED\n"));
548 if(cat_sendinst(modp
, asicp
, VOYAGER_SUBADDRDATA
, VOYAGER_READ_CONFIG
)) {
549 CDEBUG(("cat_subread: cat_sendinst failed\n"));
552 for(i
= 0; i
< len
; i
++) {
553 if(cat_getdata(modp
, asicp
, 0xFF,
554 &((__u8
*)buf
)[i
])) {
555 CDEBUG(("cat_subread: cat_getdata element %d failed\n", i
));
563 /* buffer for storing EPROM data read in during initialisation */
564 static __initdata __u8 eprom_buf
[0xFFFF];
565 static voyager_module_t
*voyager_initial_module
;
567 /* Initialise the cat bus components. We assume this is called by the
568 * boot cpu *after* all memory initialisation has been done (so we can
569 * use kmalloc) but before smp initialisation, so we can probe the SMP
570 * configuration and pick up necessary information. */
572 voyager_cat_init(void)
574 voyager_module_t
**modpp
= &voyager_initial_module
;
575 voyager_asic_t
**asicpp
;
576 voyager_asic_t
*qabc_asic
= NULL
;
578 unsigned long qic_addr
= 0;
579 __u8 qabc_data
[0x20];
580 __u8 num_submodules
, val
;
581 voyager_eprom_hdr_t
*eprom_hdr
= (voyager_eprom_hdr_t
*)&eprom_buf
[0];
586 /* initiallise the SUS mailbox */
587 for(i
=0; i
<sizeof(cmos
); i
++)
588 cmos
[i
] = voyager_extended_cmos_read(VOYAGER_DUMP_LOCATION
+ i
);
589 addr
= *(unsigned long *)cmos
;
590 if((addr
& 0xff000000) != 0xff000000) {
591 printk(KERN_ERR
"Voyager failed to get SUS mailbox (addr = 0x%lx\n", addr
);
593 static struct resource res
;
595 res
.name
= "voyager SUS";
597 res
.end
= addr
+0x3ff;
599 request_resource(&iomem_resource
, &res
);
600 voyager_SUS
= (struct voyager_SUS
*)
601 ioremap(addr
, 0x400);
602 printk(KERN_NOTICE
"Voyager SUS mailbox version 0x%x\n",
603 voyager_SUS
->SUS_version
);
604 voyager_SUS
->kernel_version
= VOYAGER_MAILBOX_VERSION
;
605 voyager_SUS
->kernel_flags
= VOYAGER_OS_HAS_SYSINT
;
608 /* clear the processor counts */
609 voyager_extended_vic_processors
= 0;
610 voyager_quad_processors
= 0;
614 printk("VOYAGER: beginning CAT bus probe\n");
615 /* set up the SuperSet Port Block which tells us where the
616 * CAT communication port is */
617 sspb
= inb(VOYAGER_SSPB_RELOCATION_PORT
) * 0x100;
618 VDEBUG(("VOYAGER DEBUG: sspb = 0x%x\n", sspb
));
620 /* now find out if were 8 slot or normal */
621 if((inb(VIC_PROC_WHO_AM_I
) & EIGHT_SLOT_IDENTIFIER
)
622 == EIGHT_SLOT_IDENTIFIER
) {
624 printk(KERN_NOTICE
"Voyager: Eight slot 51xx configuration detected\n");
627 for(i
= VOYAGER_MIN_MODULE
;
628 i
<= VOYAGER_MAX_MODULE
; i
++) {
634 outb(VOYAGER_CAT_DESELECT
, VOYAGER_CAT_CONFIG_PORT
);
635 outb(i
, VOYAGER_CAT_CONFIG_PORT
);
637 /* check the presence of the module */
638 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
639 outb(VOYAGER_CAT_IRCYC
, CAT_CMD
);
640 outb(VOYAGER_CAT_HEADER
, CAT_DATA
);
641 /* stream series of alternating 1's and 0's to stimulate
643 outb(0xAA, CAT_DATA
);
644 input
= inb(CAT_DATA
);
645 outb(VOYAGER_CAT_END
, CAT_CMD
);
646 if(input
!= VOYAGER_CAT_HEADER
) {
649 CDEBUG(("VOYAGER DEBUG: found module id 0x%x, %s\n", i
,
650 cat_module_name(i
)));
651 *modpp
= kmalloc(sizeof(voyager_module_t
), GFP_KERNEL
); /*&voyager_module_storage[cat_count++];*/
653 printk("**WARNING** kmalloc failure in cat_init\n");
656 memset(*modpp
, 0, sizeof(voyager_module_t
));
657 /* need temporary asic for cat_subread. It will be
658 * filled in correctly later */
659 (*modpp
)->asic
= kmalloc(sizeof(voyager_asic_t
), GFP_KERNEL
); /*&voyager_asic_storage[asic_count];*/
660 if((*modpp
)->asic
== NULL
) {
661 printk("**WARNING** kmalloc failure in cat_init\n");
664 memset((*modpp
)->asic
, 0, sizeof(voyager_asic_t
));
665 (*modpp
)->asic
->asic_id
= VOYAGER_CAT_ID
;
666 (*modpp
)->asic
->subaddr
= VOYAGER_SUBADDR_HI
;
667 (*modpp
)->module_addr
= i
;
668 (*modpp
)->scan_path_connected
= 0;
669 if(i
== VOYAGER_PSI
) {
670 /* Exception leg for modules with no EEPROM */
671 printk("Module \"%s\"\n", cat_module_name(i
));
675 CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i
, VOYAGER_XSUM_END_OFFSET
));
676 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
677 cat_disconnect(*modpp
, (*modpp
)->asic
);
678 if(cat_subread(*modpp
, (*modpp
)->asic
,
679 VOYAGER_XSUM_END_OFFSET
, sizeof(eprom_size
),
681 printk("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n", i
);
682 outb(VOYAGER_CAT_END
, CAT_CMD
);
685 if(eprom_size
> sizeof(eprom_buf
)) {
686 printk("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x. Need %d\n", i
, eprom_size
);
687 outb(VOYAGER_CAT_END
, CAT_CMD
);
690 outb(VOYAGER_CAT_END
, CAT_CMD
);
691 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
692 CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i
, eprom_size
));
693 if(cat_subread(*modpp
, (*modpp
)->asic
, 0,
694 eprom_size
, eprom_buf
)) {
695 outb(VOYAGER_CAT_END
, CAT_CMD
);
698 outb(VOYAGER_CAT_END
, CAT_CMD
);
699 printk("Module \"%s\", version 0x%x, tracer 0x%x, asics %d\n",
700 cat_module_name(i
), eprom_hdr
->version_id
,
701 *((__u32
*)eprom_hdr
->tracer
), eprom_hdr
->num_asics
);
702 (*modpp
)->ee_size
= eprom_hdr
->ee_size
;
703 (*modpp
)->num_asics
= eprom_hdr
->num_asics
;
704 asicpp
= &((*modpp
)->asic
);
705 sp_offset
= eprom_hdr
->scan_path_offset
;
706 /* All we really care about are the Quad cards. We
707 * identify them because they are in a processor slot
708 * and have only four asics */
709 if((i
< 0x10 || (i
>=0x14 && i
< 0x1c) || i
>0x1f)) {
710 modpp
= &((*modpp
)->next
);
713 /* Now we know it's in a processor slot, does it have
714 * a quad baseboard submodule */
715 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
716 cat_read(*modpp
, (*modpp
)->asic
, VOYAGER_SUBMODPRESENT
,
718 /* lowest two bits, active low */
719 num_submodules
= ~(0xfc | num_submodules
);
720 CDEBUG(("VOYAGER CAT: %d submodules present\n", num_submodules
));
721 if(num_submodules
== 0) {
722 /* fill in the dyadic extended processors */
725 printk("Module \"%s\": Dyadic Processor Card\n",
727 voyager_extended_vic_processors
|= (1<<cpu
);
729 voyager_extended_vic_processors
|= (1<<cpu
);
730 outb(VOYAGER_CAT_END
, CAT_CMD
);
734 /* now we want to read the asics on the first submodule,
735 * which should be the quad base board */
737 cat_read(*modpp
, (*modpp
)->asic
, VOYAGER_SUBMODSELECT
, &val
);
738 CDEBUG(("cat_init: SUBMODSELECT value = 0x%x\n", val
));
739 val
= (val
& 0x7c) | VOYAGER_QUAD_BASEBOARD
;
740 cat_write(*modpp
, (*modpp
)->asic
, VOYAGER_SUBMODSELECT
, val
);
742 outb(VOYAGER_CAT_END
, CAT_CMD
);
745 CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i
, VOYAGER_XSUM_END_OFFSET
));
746 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
747 cat_disconnect(*modpp
, (*modpp
)->asic
);
748 if(cat_subread(*modpp
, (*modpp
)->asic
,
749 VOYAGER_XSUM_END_OFFSET
, sizeof(eprom_size
),
751 printk("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n", i
);
752 outb(VOYAGER_CAT_END
, CAT_CMD
);
755 if(eprom_size
> sizeof(eprom_buf
)) {
756 printk("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x. Need %d\n", i
, eprom_size
);
757 outb(VOYAGER_CAT_END
, CAT_CMD
);
760 outb(VOYAGER_CAT_END
, CAT_CMD
);
761 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
762 CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i
, eprom_size
));
763 if(cat_subread(*modpp
, (*modpp
)->asic
, 0,
764 eprom_size
, eprom_buf
)) {
765 outb(VOYAGER_CAT_END
, CAT_CMD
);
768 outb(VOYAGER_CAT_END
, CAT_CMD
);
769 /* Now do everything for the QBB submodule 1 */
770 (*modpp
)->ee_size
= eprom_hdr
->ee_size
;
771 (*modpp
)->num_asics
= eprom_hdr
->num_asics
;
772 asicpp
= &((*modpp
)->asic
);
773 sp_offset
= eprom_hdr
->scan_path_offset
;
774 /* get rid of the dummy CAT asic and read the real one */
775 kfree((*modpp
)->asic
);
776 for(asic
=0; asic
< (*modpp
)->num_asics
; asic
++) {
778 voyager_asic_t
*asicp
= *asicpp
779 = kmalloc(sizeof(voyager_asic_t
), GFP_KERNEL
); /*&voyager_asic_storage[asic_count++];*/
780 voyager_sp_table_t
*sp_table
;
781 voyager_at_t
*asic_table
;
782 voyager_jtt_t
*jtag_table
;
785 printk("**WARNING** kmalloc failure in cat_init\n");
788 memset(asicp
, 0, sizeof(voyager_asic_t
));
789 asicpp
= &(asicp
->next
);
790 asicp
->asic_location
= asic
;
791 sp_table
= (voyager_sp_table_t
*)(eprom_buf
+ sp_offset
);
792 asicp
->asic_id
= sp_table
->asic_id
;
793 asic_table
= (voyager_at_t
*)(eprom_buf
+ sp_table
->asic_data_offset
);
795 asicp
->jtag_id
[j
] = asic_table
->jtag_id
[j
];
796 jtag_table
= (voyager_jtt_t
*)(eprom_buf
+ asic_table
->jtag_offset
);
797 asicp
->ireg_length
= jtag_table
->ireg_len
;
798 asicp
->bit_location
= (*modpp
)->inst_bits
;
799 (*modpp
)->inst_bits
+= asicp
->ireg_length
;
800 if(asicp
->ireg_length
> (*modpp
)->largest_reg
)
801 (*modpp
)->largest_reg
= asicp
->ireg_length
;
802 if (asicp
->ireg_length
< (*modpp
)->smallest_reg
||
803 (*modpp
)->smallest_reg
== 0)
804 (*modpp
)->smallest_reg
= asicp
->ireg_length
;
805 CDEBUG(("asic 0x%x, ireg_length=%d, bit_location=%d\n",
806 asicp
->asic_id
, asicp
->ireg_length
,
807 asicp
->bit_location
));
808 if(asicp
->asic_id
== VOYAGER_QUAD_QABC
) {
809 CDEBUG(("VOYAGER CAT: QABC ASIC found\n"));
812 sp_offset
+= sizeof(voyager_sp_table_t
);
814 CDEBUG(("Module inst_bits = %d, largest_reg = %d, smallest_reg=%d\n",
815 (*modpp
)->inst_bits
, (*modpp
)->largest_reg
,
816 (*modpp
)->smallest_reg
));
817 /* OK, now we have the QUAD ASICs set up, use them.
820 * 1. Find the Memory area for the Quad CPIs.
821 * 2. Find the Extended VIC processor
822 * 3. Configure a second extended VIC processor (This
823 * cannot be done for the 51xx.
825 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
826 cat_connect(*modpp
, (*modpp
)->asic
);
827 CDEBUG(("CAT CONNECTED!!\n"));
828 cat_subread(*modpp
, qabc_asic
, 0, sizeof(qabc_data
), qabc_data
);
829 qic_addr
= qabc_data
[5] << 8;
830 qic_addr
= (qic_addr
| qabc_data
[6]) << 8;
831 qic_addr
= (qic_addr
| qabc_data
[7]) << 8;
832 printk("Module \"%s\": Quad Processor Card; CPI 0x%lx, SET=0x%x\n",
833 cat_module_name(i
), qic_addr
, qabc_data
[8]);
834 #if 0 /* plumbing fails---FIXME */
835 if((qabc_data
[8] & 0xf0) == 0) {
836 /* FIXME: 32 way 8 CPU slot monster cannot be
837 * plumbed this way---need to check for it */
839 printk("Plumbing second Extended Quad Processor\n");
840 /* second VIC line hardwired to Quad CPU 1 */
841 qabc_data
[8] |= 0x20;
842 cat_subwrite(*modpp
, qabc_asic
, 8, 1, &qabc_data
[8]);
843 #ifdef VOYAGER_CAT_DEBUG
844 /* verify plumbing */
845 cat_subread(*modpp
, qabc_asic
, 8, 1, &qabc_data
[8]);
846 if((qabc_data
[8] & 0xf0) == 0) {
847 CDEBUG(("PLUMBING FAILED: 0x%x\n", qabc_data
[8]));
854 struct resource
*res
= kmalloc(sizeof(struct resource
),GFP_KERNEL
);
855 memset(res
, 0, sizeof(struct resource
));
856 res
->name
= kmalloc(128, GFP_KERNEL
);
857 sprintf((char *)res
->name
, "Voyager %s Quad CPI", cat_module_name(i
));
858 res
->start
= qic_addr
;
859 res
->end
= qic_addr
+ 0x3ff;
860 request_resource(&iomem_resource
, res
);
863 qic_addr
= (unsigned long)ioremap(qic_addr
, 0x400);
865 for(j
= 0; j
< 4; j
++) {
869 /* 8 slot has a different mapping,
870 * each slot has only one vic line, so
871 * 1 cpu in each slot must be < 8 */
872 cpu
= (i
& 0x07) + j
*8;
874 cpu
= (i
& 0x03) + j
*4;
876 if( (qabc_data
[8] & (1<<j
))) {
877 voyager_extended_vic_processors
|= (1<<cpu
);
879 if(qabc_data
[8] & (1<<(j
+4)) ) {
880 /* Second SET register plumbed: Quad
881 * card has two VIC connected CPUs.
882 * Secondary cannot be booted as a VIC
884 voyager_extended_vic_processors
|= (1<<cpu
);
885 voyager_allowed_boot_processors
&= (~(1<<cpu
));
888 voyager_quad_processors
|= (1<<cpu
);
889 voyager_quad_cpi_addr
[cpu
] = (struct voyager_qic_cpi
*)
891 CDEBUG(("CPU%d: CPI address 0x%lx\n", cpu
,
892 (unsigned long)voyager_quad_cpi_addr
[cpu
]));
894 outb(VOYAGER_CAT_END
, CAT_CMD
);
899 modpp
= &((*modpp
)->next
);
902 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
);
903 request_resource(&ioport_resource
, &vic_res
);
904 if(voyager_quad_processors
)
905 request_resource(&ioport_resource
, &qic_res
);
906 /* set up the front power switch */
910 voyager_cat_readb(__u8 module
, __u8 asic
, int reg
)
916 cat_disconnect(voyager_module_t
*modp
, voyager_asic_t
*asicp
)
921 if(!modp
->scan_path_connected
)
923 if(asicp
->asic_id
!= VOYAGER_CAT_ID
) {
924 CDEBUG(("cat_disconnect: ASIC is not CAT\n"));
927 err
= cat_read(modp
, asicp
, VOYAGER_SCANPATH
, &val
);
929 CDEBUG(("cat_disconnect: failed to read SCANPATH\n"));
932 val
&= VOYAGER_DISCONNECT_ASIC
;
933 err
= cat_write(modp
, asicp
, VOYAGER_SCANPATH
, val
);
935 CDEBUG(("cat_disconnect: failed to write SCANPATH\n"));
938 outb(VOYAGER_CAT_END
, CAT_CMD
);
939 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
940 modp
->scan_path_connected
= 0;
946 cat_connect(voyager_module_t
*modp
, voyager_asic_t
*asicp
)
951 if(modp
->scan_path_connected
)
953 if(asicp
->asic_id
!= VOYAGER_CAT_ID
) {
954 CDEBUG(("cat_connect: ASIC is not CAT\n"));
958 err
= cat_read(modp
, asicp
, VOYAGER_SCANPATH
, &val
);
960 CDEBUG(("cat_connect: failed to read SCANPATH\n"));
963 val
|= VOYAGER_CONNECT_ASIC
;
964 err
= cat_write(modp
, asicp
, VOYAGER_SCANPATH
, val
);
966 CDEBUG(("cat_connect: failed to write SCANPATH\n"));
969 outb(VOYAGER_CAT_END
, CAT_CMD
);
970 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
971 modp
->scan_path_connected
= 1;
977 voyager_cat_power_off(void)
979 /* Power the machine off by writing to the PSI over the CAT
982 voyager_module_t psi
= { 0 };
983 voyager_asic_t psi_asic
= { 0 };
985 psi
.asic
= &psi_asic
;
986 psi
.asic
->asic_id
= VOYAGER_CAT_ID
;
987 psi
.asic
->subaddr
= VOYAGER_SUBADDR_HI
;
988 psi
.module_addr
= VOYAGER_PSI
;
989 psi
.scan_path_connected
= 0;
991 outb(VOYAGER_CAT_END
, CAT_CMD
);
992 /* Connect the PSI to the CAT Bus */
993 outb(VOYAGER_CAT_DESELECT
, VOYAGER_CAT_CONFIG_PORT
);
994 outb(VOYAGER_PSI
, VOYAGER_CAT_CONFIG_PORT
);
995 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
996 cat_disconnect(&psi
, &psi_asic
);
997 /* Read the status */
998 cat_subread(&psi
, &psi_asic
, VOYAGER_PSI_GENERAL_REG
, 1, &data
);
999 outb(VOYAGER_CAT_END
, CAT_CMD
);
1000 CDEBUG(("PSI STATUS 0x%x\n", data
));
1001 /* These two writes are power off prep and perform */
1003 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
1004 cat_subwrite(&psi
, &psi_asic
, VOYAGER_PSI_GENERAL_REG
, 1, &data
);
1005 outb(VOYAGER_CAT_END
, CAT_CMD
);
1006 data
= PSI_POWER_DOWN
;
1007 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
1008 cat_subwrite(&psi
, &psi_asic
, VOYAGER_PSI_GENERAL_REG
, 1, &data
);
1009 outb(VOYAGER_CAT_END
, CAT_CMD
);
1012 struct voyager_status voyager_status
= { 0 };
1015 voyager_cat_psi(__u8 cmd
, __u16 reg
, __u8
*data
)
1017 voyager_module_t psi
= { 0 };
1018 voyager_asic_t psi_asic
= { 0 };
1020 psi
.asic
= &psi_asic
;
1021 psi
.asic
->asic_id
= VOYAGER_CAT_ID
;
1022 psi
.asic
->subaddr
= VOYAGER_SUBADDR_HI
;
1023 psi
.module_addr
= VOYAGER_PSI
;
1024 psi
.scan_path_connected
= 0;
1026 outb(VOYAGER_CAT_END
, CAT_CMD
);
1027 /* Connect the PSI to the CAT Bus */
1028 outb(VOYAGER_CAT_DESELECT
, VOYAGER_CAT_CONFIG_PORT
);
1029 outb(VOYAGER_PSI
, VOYAGER_CAT_CONFIG_PORT
);
1030 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
1031 cat_disconnect(&psi
, &psi_asic
);
1033 case VOYAGER_PSI_READ
:
1034 cat_read(&psi
, &psi_asic
, reg
, data
);
1036 case VOYAGER_PSI_WRITE
:
1037 cat_write(&psi
, &psi_asic
, reg
, *data
);
1039 case VOYAGER_PSI_SUBREAD
:
1040 cat_subread(&psi
, &psi_asic
, reg
, 1, data
);
1042 case VOYAGER_PSI_SUBWRITE
:
1043 cat_subwrite(&psi
, &psi_asic
, reg
, 1, data
);
1046 printk(KERN_ERR
"Voyager PSI, unrecognised command %d\n", cmd
);
1049 outb(VOYAGER_CAT_END
, CAT_CMD
);
1053 voyager_cat_do_common_interrupt(void)
1055 /* This is caused either by a memory parity error or something
1058 voyager_module_t psi
= { 0 };
1059 voyager_asic_t psi_asic
= { 0 };
1060 struct voyager_psi psi_reg
;
1063 psi
.asic
= &psi_asic
;
1064 psi
.asic
->asic_id
= VOYAGER_CAT_ID
;
1065 psi
.asic
->subaddr
= VOYAGER_SUBADDR_HI
;
1066 psi
.module_addr
= VOYAGER_PSI
;
1067 psi
.scan_path_connected
= 0;
1069 outb(VOYAGER_CAT_END
, CAT_CMD
);
1070 /* Connect the PSI to the CAT Bus */
1071 outb(VOYAGER_CAT_DESELECT
, VOYAGER_CAT_CONFIG_PORT
);
1072 outb(VOYAGER_PSI
, VOYAGER_CAT_CONFIG_PORT
);
1073 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
1074 cat_disconnect(&psi
, &psi_asic
);
1075 /* Read the status. NOTE: Need to read *all* the PSI regs here
1076 * otherwise the cmn int will be reasserted */
1077 for(i
= 0; i
< sizeof(psi_reg
.regs
); i
++) {
1078 cat_read(&psi
, &psi_asic
, i
, &((__u8
*)&psi_reg
.regs
)[i
]);
1080 outb(VOYAGER_CAT_END
, CAT_CMD
);
1081 if((psi_reg
.regs
.checkbit
& 0x02) == 0) {
1082 psi_reg
.regs
.checkbit
|= 0x02;
1083 cat_write(&psi
, &psi_asic
, 5, psi_reg
.regs
.checkbit
);
1084 printk("VOYAGER RE-READ PSI\n");
1087 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
1088 for(i
= 0; i
< sizeof(psi_reg
.subregs
); i
++) {
1089 /* This looks strange, but the PSI doesn't do auto increment
1091 cat_subread(&psi
, &psi_asic
, VOYAGER_PSI_SUPPLY_REG
+ i
,
1092 1, &((__u8
*)&psi_reg
.subregs
)[i
]);
1094 outb(VOYAGER_CAT_END
, CAT_CMD
);
1095 #ifdef VOYAGER_CAT_DEBUG
1096 printk("VOYAGER PSI: ");
1097 for(i
=0; i
<sizeof(psi_reg
.regs
); i
++)
1098 printk("%02x ", ((__u8
*)&psi_reg
.regs
)[i
]);
1100 for(i
=0; i
<sizeof(psi_reg
.subregs
); i
++)
1101 printk("%02x ", ((__u8
*)&psi_reg
.subregs
)[i
]);
1104 if(psi_reg
.regs
.intstatus
& PSI_MON
) {
1105 /* switch off or power fail */
1107 if(psi_reg
.subregs
.supply
& PSI_SWITCH_OFF
) {
1108 if(voyager_status
.switch_off
) {
1109 printk(KERN_ERR
"Voyager front panel switch turned off again---Immediate power off!\n");
1110 voyager_cat_power_off();
1113 printk(KERN_ERR
"Voyager front panel switch turned off\n");
1114 voyager_status
.switch_off
= 1;
1115 voyager_status
.request_from_kernel
= 1;
1118 /* Tell the hardware we're taking care of the
1119 * shutdown, otherwise it will power the box off
1120 * within 3 seconds of the switch being pressed and,
1121 * which is much more important to us, continue to
1122 * assert the common interrupt */
1123 data
= PSI_CLR_SWITCH_OFF
;
1124 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
1125 cat_subwrite(&psi
, &psi_asic
, VOYAGER_PSI_SUPPLY_REG
,
1127 outb(VOYAGER_CAT_END
, CAT_CMD
);
1130 VDEBUG(("Voyager ac fail reg 0x%x\n",
1131 psi_reg
.subregs
.ACfail
));
1132 if((psi_reg
.subregs
.ACfail
& AC_FAIL_STAT_CHANGE
) == 0) {
1133 /* No further update */
1137 /* Don't bother trying to find out who failed.
1138 * FIXME: This probably makes the code incorrect on
1139 * anything other than a 345x */
1140 for(i
=0; i
< 5; i
++) {
1141 if( psi_reg
.subregs
.ACfail
&(1<<i
)) {
1145 printk(KERN_NOTICE
"AC FAIL IN SUPPLY %d\n", i
);
1147 /* DON'T do this: it shuts down the AC PSI
1148 outb(VOYAGER_CAT_RUN, CAT_CMD);
1149 data = PSI_MASK_MASK | i;
1150 cat_subwrite(&psi, &psi_asic, VOYAGER_PSI_MASK,
1152 outb(VOYAGER_CAT_END, CAT_CMD);
1154 printk(KERN_ERR
"Voyager AC power failure\n");
1155 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
1156 data
= PSI_COLD_START
;
1157 cat_subwrite(&psi
, &psi_asic
, VOYAGER_PSI_GENERAL_REG
,
1159 outb(VOYAGER_CAT_END
, CAT_CMD
);
1160 voyager_status
.power_fail
= 1;
1161 voyager_status
.request_from_kernel
= 1;
1166 } else if(psi_reg
.regs
.intstatus
& PSI_FAULT
) {
1168 printk(KERN_ERR
"Voyager PSI Detected major fault, immediate power off!\n");
1169 voyager_cat_power_off();
1171 } else if(psi_reg
.regs
.intstatus
& (PSI_DC_FAIL
| PSI_ALARM
1172 | PSI_CURRENT
| PSI_DVM
1173 | PSI_PSCFAULT
| PSI_STAT_CHG
)) {
1174 /* other psi fault */
1176 printk(KERN_WARNING
"Voyager PSI status 0x%x\n", data
);
1177 /* clear the PSI fault */
1178 outb(VOYAGER_CAT_RUN
, CAT_CMD
);
1179 cat_write(&psi
, &psi_asic
, VOYAGER_PSI_STATUS_REG
, 0);
1180 outb(VOYAGER_CAT_END
, CAT_CMD
);