2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2001-2003 Silicon Graphics, Inc. All rights reserved.
9 #include <linux/types.h>
10 #include <linux/interrupt.h>
11 #include <asm/sn/sgi.h>
12 #include <asm/sn/addrs.h>
13 #include <asm/sn/iograph.h>
14 #include <asm/sn/pci/pciio.h>
15 #include <asm/sn/pci/pcibr.h>
16 #include <asm/sn/pci/pcibr_private.h>
17 #include <asm/sn/pci/pci_defs.h>
20 extern int hubii_check_widget_disabled(nasid_t
, int);
23 /* =====================================================================
29 #define BRIDGE_PIOERR_TIMEOUT 100 /* Timeout with ERROR_DEBUG defined */
31 #define BRIDGE_PIOERR_TIMEOUT 40 /* Timeout in debug mode */
34 #define BRIDGE_PIOERR_TIMEOUT 1 /* Timeout in non-debug mode */
39 uint64_t bridge_errors_to_dump
= ~BRIDGE_ISR_INT_MSK
;
41 uint64_t bridge_errors_to_dump
= BRIDGE_ISR_ERROR_DUMP
;
44 uint64_t bridge_errors_to_dump
= BRIDGE_ISR_ERROR_FATAL
|
45 BRIDGE_ISR_PCIBUS_PIOERR
;
48 int pcibr_pioerr_dump
= 1; /* always dump pio errors */
52 * map between numeric values and symbolic values
55 unsigned long long rv_value
;
60 * register descriptors are used for formatted prints of register values
61 * rd_mask and rd_shift must be defined, other entries may be null
64 unsigned long long rd_mask
; /* mask to extract field */
65 int rd_shift
; /* shift for extracted value, - >>, + << */
66 char *rd_name
; /* field name */
67 char *rd_format
; /* format to print field */
68 struct reg_values
*rd_values
; /* symbolic names of values */
71 /* Crosstalk Packet Types */
72 static struct reg_values xtalk_cmd_pactyp
[] =
76 {0x2, "WrReqWithResp"},
93 static struct reg_desc xtalk_cmd_bits
[] =
95 {WIDGET_DIDN
, -28, "DIDN", "%x"},
96 {WIDGET_SIDN
, -24, "SIDN", "%x"},
97 {WIDGET_PACTYP
, -20, "PACTYP", 0, xtalk_cmd_pactyp
},
98 {WIDGET_TNUM
, -15, "TNUM", "%x"},
99 {WIDGET_COHERENT
, 0, "COHERENT"},
100 {WIDGET_DS
, 0, "DS"},
101 {WIDGET_GBR
, 0, "GBR"},
102 {WIDGET_VBPM
, 0, "VBPM"},
103 {WIDGET_ERROR
, 0, "ERROR"},
104 {WIDGET_BARRIER
, 0, "BARRIER"},
108 #define F(s,n) { 1l<<(s),-(s), n }
110 char *pci_space
[] = {"NONE",
127 static char *pcibr_isr_errs
[] =
129 "", "", "", "", "", "", "", "",
130 "08: Reserved Bit 08",
131 "09: PCI to Crosstalk read request timeout",
132 "10: PCI retry operation count exhausted.",
133 "11: PCI bus device select timeout",
134 "12: PCI device reported parity error",
135 "13: PCI Address/Cmd parity error ",
136 "14: PCI Bridge detected parity error",
137 "15: PCI abort condition",
138 "16: Reserved Bit 16",
139 "17: LLP Transmitter Retry count wrapped", /* PIC ONLY */
140 "18: LLP Transmitter side required Retry", /* PIC ONLY */
141 "19: LLP Receiver retry count wrapped", /* PIC ONLY */
142 "20: LLP Receiver check bit error", /* PIC ONLY */
143 "21: LLP Receiver sequence number error", /* PIC ONLY */
144 "22: Request packet overflow",
145 "23: Request operation not supported by bridge",
146 "24: Request packet has invalid address for bridge widget",
147 "25: Incoming request xtalk command word error bit set or invalid sideband",
148 "26: Incoming response xtalk command word error bit set or invalid sideband",
149 "27: Framing error, request cmd data size does not match actual",
150 "28: Framing error, response cmd data size does not match actual",
151 "29: Unexpected response arrived",
152 "30: PMU Access Fault",
153 "31: Reserved Bit 31",
154 "32: PCI-X address or attribute cycle parity error",
155 "33: PCI-X data cycle parity error",
156 "34: PCI-X master timeout (ie. master abort)",
157 "35: PCI-X pio retry counter exhausted",
160 "38: PCI-X target abort",
161 "39: PCI-X read request timeout",
162 "40: PCI / PCI-X device requestin arbitration error",
163 "41: internal RAM parity error",
164 "42: PCI-X unexpected completion cycle to master",
165 "43: PCI-X split completion timeout",
166 "44: PCI-X split completion error message",
167 "45: PCI-X split completion message parity error",
171 * print_register() allows formatted printing of bit fields. individual
172 * bit fields are described by a struct reg_desc, multiple bit fields within
173 * a single word can be described by multiple reg_desc structures.
174 * %r outputs a string of the format "<bit field descriptions>"
175 * %R outputs a string of the format "0x%x<bit field descriptions>"
177 * The fields in a reg_desc are:
178 * unsigned long long rd_mask; An appropriate mask to isolate the bit field
179 * within a word, and'ed with val
181 * int rd_shift; A shift amount to be done to the isolated
182 * bit field. done before printing the isolate
183 * bit field with rd_format and before searching
184 * for symbolic value names in rd_values
186 * char *rd_name; If non-null, a bit field name to label any
187 * out from rd_format or searching rd_values.
188 * if neither rd_format or rd_values is non-null
189 * rd_name is printed only if the isolated
190 * bit field is non-null.
192 * char *rd_format; If non-null, the shifted bit field value
193 * is printed using this format.
195 * struct reg_values *rd_values; If non-null, a pointer to a table
196 * matching numeric values with symbolic names.
197 * rd_values are searched and the symbolic
198 * value is printed if a match is found, if no
199 * match is found "???" is printed.
204 print_register(unsigned long long reg
, struct reg_desc
*addr
)
206 register struct reg_desc
*rd
;
207 register struct reg_values
*rv
;
208 unsigned long long field
;
213 for (rd
= addr
; rd
->rd_mask
; rd
++) {
214 field
= reg
& rd
->rd_mask
;
215 field
= (rd
->rd_shift
> 0) ? field
<< rd
->rd_shift
: field
>> -rd
->rd_shift
;
216 if (any
&& (rd
->rd_format
|| rd
->rd_values
|| (rd
->rd_name
&& field
)))
219 if (rd
->rd_format
|| rd
->rd_values
|| field
) {
220 printk("%s", rd
->rd_name
);
223 if (rd
->rd_format
|| rd
->rd_values
) {
228 /* You can have any format so long as it is %x */
230 printk("%llx", field
);
237 for (rv
= rd
->rd_values
; rv
->rv_name
; rv
++) {
238 if (field
== rv
->rv_value
) {
239 printk("%s", rv
->rv_name
);
243 if (rv
->rv_name
== NULL
)
252 * display memory directory state
255 pcibr_show_dir_state(paddr_t paddr
, char *prefix
)
261 extern char *dir_state_str
[];
262 extern void get_dir_ent(paddr_t
, int *, uint64_t *, hubreg_t
*);
264 get_dir_ent(paddr
, &state
, &vec_ptr
, &elo
);
266 printf("%saddr 0x%lx: state 0x%x owner 0x%lx (%s)\n",
267 prefix
, (uint64_t)paddr
, state
, (uint64_t)vec_ptr
,
268 dir_state_str
[state
]);
269 #endif /* PCIBR_LATER */
274 print_bridge_errcmd(pcibr_soft_t pcibr_soft
, uint32_t cmdword
, char *errtype
)
277 "\t Bridge %sError Command Word Register ", errtype
);
278 print_register(cmdword
, xtalk_cmd_bits
);
283 * Dump relevant error information for Bridge error interrupts.
287 pcibr_error_dump(pcibr_soft_t pcibr_soft
)
294 int_status
= (pcireg_intr_status_get(pcibr_soft
) & ~BRIDGE_ISR_INT_MSK
);
297 /* No error bits set */
301 /* Check if dumping the same error information multiple times */
302 if ( pcibr_soft
->bs_errinfo
.bserr_intstat
== int_status
)
304 pcibr_soft
->bs_errinfo
.bserr_intstat
= int_status
;
306 printk(KERN_ALERT
"PCI BRIDGE ERROR: int_status is 0x%lx for %s\n"
307 " Dumping relevant %s registers for each bit set...\n",
308 int_status
, pcibr_soft
->bs_name
,
311 for (i
= PCIBR_ISR_ERR_START
; i
< 64; i
++) {
314 /* A number of int_status bits are only valid for PIC's bus0 */
315 if ((pcibr_soft
->bs_busnum
!= 0) &&
316 ((bit
== BRIDGE_ISR_UNSUPPORTED_XOP
) ||
317 (bit
== BRIDGE_ISR_LLP_REC_SNERR
) ||
318 (bit
== BRIDGE_ISR_LLP_REC_CBERR
) ||
319 (bit
== BRIDGE_ISR_LLP_RCTY
) ||
320 (bit
== BRIDGE_ISR_LLP_TX_RETRY
) ||
321 (bit
== BRIDGE_ISR_LLP_TCTY
))) {
325 if (int_status
& bit
) {
326 printk("\t%s\n", pcibr_isr_errs
[i
]);
330 case PIC_ISR_INT_RAM_PERR
: /* bit41 INT_RAM_PERR */
331 /* XXX: should breakdown meaning of bits in reg */
332 printk("\t Internal RAM Parity Error: 0x%lx\n",
333 pcireg_parity_err_get(pcibr_soft
));
336 case PIC_ISR_PCIX_ARB_ERR
: /* bit40 PCI_X_ARB_ERR */
337 /* XXX: should breakdown meaning of bits in reg */
338 printk("\t Arbitration Reg: 0x%lx\n",
339 pcireg_arbitration_get(pcibr_soft
));
342 case PIC_ISR_PCIX_REQ_TOUT
: /* bit39 PCI_X_REQ_TOUT */
343 /* XXX: should breakdown meaning of attribute bit */
345 "\t PCI-X DMA Request Error Address Reg: 0x%lx\n"
346 "\t PCI-X DMA Request Error Attribute Reg: 0x%lx\n",
347 pcireg_pcix_req_err_addr_get(pcibr_soft
),
348 pcireg_pcix_req_err_attr_get(pcibr_soft
));
351 case PIC_ISR_PCIX_SPLIT_MSG_PE
: /* bit45 PCI_X_SPLIT_MES_PE */
352 case PIC_ISR_PCIX_SPLIT_EMSG
: /* bit44 PCI_X_SPLIT_EMESS */
353 case PIC_ISR_PCIX_SPLIT_TO
: /* bit43 PCI_X_SPLIT_TO */
354 /* XXX: should breakdown meaning of attribute bit */
356 "\t PCI-X Split Request Address Reg: 0x%lx\n"
357 "\t PCI-X Split Request Attribute Reg: 0x%lx\n",
358 pcireg_pcix_pio_split_addr_get(pcibr_soft
),
359 pcireg_pcix_pio_split_attr_get(pcibr_soft
));
362 case PIC_ISR_PCIX_UNEX_COMP
: /* bit42 PCI_X_UNEX_COMP */
363 case PIC_ISR_PCIX_TABORT
: /* bit38 PCI_X_TABORT */
364 case PIC_ISR_PCIX_PERR
: /* bit37 PCI_X_PERR */
365 case PIC_ISR_PCIX_SERR
: /* bit36 PCI_X_SERR */
366 case PIC_ISR_PCIX_MRETRY
: /* bit35 PCI_X_MRETRY */
367 case PIC_ISR_PCIX_MTOUT
: /* bit34 PCI_X_MTOUT */
368 case PIC_ISR_PCIX_DA_PARITY
: /* bit33 PCI_X_DA_PARITY */
369 case PIC_ISR_PCIX_AD_PARITY
: /* bit32 PCI_X_AD_PARITY */
370 /* XXX: should breakdown meaning of attribute bit */
372 "\t PCI-X Bus Error Address Reg: 0x%lx\n"
373 "\t PCI-X Bus Error Attribute Reg: 0x%lx\n"
374 "\t PCI-X Bus Error Data Reg: 0x%lx\n",
375 pcireg_pcix_bus_err_addr_get(pcibr_soft
),
376 pcireg_pcix_bus_err_attr_get(pcibr_soft
),
377 pcireg_pcix_bus_err_data_get(pcibr_soft
));
380 case BRIDGE_ISR_PAGE_FAULT
: /* bit30 PMU_PAGE_FAULT */
381 printk("\t Map Fault Address Reg: 0x%lx\n",
382 pcireg_map_fault_get(pcibr_soft
));
385 case BRIDGE_ISR_UNEXP_RESP
: /* bit29 UNEXPECTED_RESP */
386 print_bridge_errcmd(pcibr_soft
,
387 pcireg_linkside_err_get(pcibr_soft
), "Aux ");
389 /* PIC in PCI-X mode, dump the PCIX DMA Request registers */
390 if (IS_PCIX(pcibr_soft
)) {
391 /* XXX: should breakdown meaning of attr bit */
393 "\t PCI-X DMA Request Error Addr Reg: 0x%lx\n"
394 "\t PCI-X DMA Request Error Attr Reg: 0x%lx\n",
395 pcireg_pcix_req_err_addr_get(pcibr_soft
),
396 pcireg_pcix_req_err_attr_get(pcibr_soft
));
400 case BRIDGE_ISR_BAD_XRESP_PKT
: /* bit28 BAD_RESP_PACKET */
401 case BRIDGE_ISR_RESP_XTLK_ERR
: /* bit26 RESP_XTALK_ERROR */
402 print_bridge_errcmd(pcibr_soft
,
403 pcireg_linkside_err_get(pcibr_soft
), "Aux ");
405 /* PCI-X mode, DMA Request Error registers are valid. But
406 * in PCI mode, Response Buffer Address register are valid.
408 if (IS_PCIX(pcibr_soft
)) {
409 /* XXX: should breakdown meaning of attribute bit */
411 "\t PCI-X DMA Request Error Addr Reg: 0x%lx\n"
412 "\t PCI-X DMA Request Error Attribute Reg: 0x%lx\n",
413 pcireg_pcix_req_err_addr_get(pcibr_soft
),
414 pcireg_pcix_req_err_attr_get(pcibr_soft
));
417 "\t Bridge Response Buf Error Addr Reg: 0x%lx\n"
418 "\t dev-num %d buff-num %d addr 0x%lx\n",
419 pcireg_resp_err_get(pcibr_soft
),
420 (int)pcireg_resp_err_dev_get(pcibr_soft
),
421 (int)pcireg_resp_err_buf_get(pcibr_soft
),
422 pcireg_resp_err_addr_get(pcibr_soft
));
423 if (bit
== BRIDGE_ISR_RESP_XTLK_ERR
) {
424 /* display memory directory associated with cacheline */
425 pcibr_show_dir_state(
426 pcireg_resp_err_get(pcibr_soft
), "\t ");
431 case BRIDGE_ISR_BAD_XREQ_PKT
: /* bit27 BAD_XREQ_PACKET */
432 case BRIDGE_ISR_REQ_XTLK_ERR
: /* bit25 REQ_XTALK_ERROR */
433 case BRIDGE_ISR_INVLD_ADDR
: /* bit24 INVALID_ADDRESS */
434 print_bridge_errcmd(pcibr_soft
,
435 pcireg_cmdword_err_get(pcibr_soft
), "");
437 "\t Bridge Error Address Register: 0x%lx\n"
438 "\t Bridge Error Address: 0x%lx\n",
439 pcireg_bus_err_get(pcibr_soft
),
440 pcireg_bus_err_get(pcibr_soft
));
443 case BRIDGE_ISR_UNSUPPORTED_XOP
: /* bit23 UNSUPPORTED_XOP */
444 print_bridge_errcmd(pcibr_soft
,
445 pcireg_linkside_err_get(pcibr_soft
), "Aux ");
446 printk("\t Address Holding Link Side Error Reg: 0x%lx\n",
447 pcireg_linkside_err_addr_get(pcibr_soft
));
450 case BRIDGE_ISR_XREQ_FIFO_OFLOW
: /* bit22 XREQ_FIFO_OFLOW */
451 print_bridge_errcmd(pcibr_soft
,
452 pcireg_linkside_err_get(pcibr_soft
), "Aux ");
453 printk("\t Address Holding Link Side Error Reg: 0x%lx\n",
454 pcireg_linkside_err_addr_get(pcibr_soft
));
457 case BRIDGE_ISR_PCI_ABORT
: /* bit15 PCI_ABORT */
458 case BRIDGE_ISR_PCI_PARITY
: /* bit14 PCI_PARITY */
459 case BRIDGE_ISR_PCI_SERR
: /* bit13 PCI_SERR */
460 case BRIDGE_ISR_PCI_PERR
: /* bit12 PCI_PERR */
461 case BRIDGE_ISR_PCI_MST_TIMEOUT
: /* bit11 PCI_MASTER_TOUT */
462 case BRIDGE_ISR_PCI_RETRY_CNT
: /* bit10 PCI_RETRY_CNT */
463 printk("\t PCI Error Address Register: 0x%lx\n"
464 "\t PCI Error Address: 0x%lx\n",
465 pcireg_pci_bus_addr_get(pcibr_soft
),
466 pcireg_pci_bus_addr_addr_get(pcibr_soft
));
469 case BRIDGE_ISR_XREAD_REQ_TIMEOUT
: /* bit09 XREAD_REQ_TOUT */
470 printk("\t Bridge Response Buf Error Addr Reg: 0x%lx\n"
471 "\t dev-num %d buff-num %d addr 0x%lx\n",
472 pcireg_resp_err_get(pcibr_soft
),
473 (int)pcireg_resp_err_dev_get(pcibr_soft
),
474 (int)pcireg_resp_err_buf_get(pcibr_soft
),
475 pcireg_resp_err_get(pcibr_soft
));
481 mult_int
= pcireg_intr_multiple_get(pcibr_soft
);
483 if (mult_int
& ~BRIDGE_ISR_INT_MSK
) {
484 printk(" %s Multiple Interrupt Register is 0x%lx\n",
485 pcibr_soft
->bs_asic_name
, mult_int
);
486 for (i
= PCIBR_ISR_ERR_START
; i
< 64; i
++) {
487 if (mult_int
& (1ull << i
))
488 printk( "\t%s\n", pcibr_isr_errs
[i
]);
493 /* pcibr_pioerr_check():
494 * Check to see if this pcibr has a PCI PIO
495 * TIMEOUT error; if so, bump the timeout-count
496 * on any piomaps that could cover the address.
499 pcibr_pioerr_check(pcibr_soft_t soft
)
510 int_status
= pcireg_intr_status_get(soft
);
512 if (int_status
& BRIDGE_ISR_PCIBUS_PIOERR
) {
513 pci_addr
= pcireg_pci_bus_addr_get(soft
);
515 slot
= PCIBR_NUM_SLOTS(soft
);
517 int nfunc
= soft
->bs_slot
[slot
].bss_ninfo
;
518 pcibr_info_h pcibr_infoh
= soft
->bs_slot
[slot
].bss_infos
;
520 for (func
= 0; func
< nfunc
; func
++) {
521 pcibr_info_t pcibr_info
= pcibr_infoh
[func
];
526 for (map
= pcibr_info
->f_piomap
;
527 map
!= NULL
; map
= map
->bp_next
) {
528 base
= map
->bp_pciaddr
;
529 size
= map
->bp_mapsz
;
530 win
= map
->bp_space
- PCIIO_SPACE_WIN(0);
532 base
+= soft
->bs_slot
[slot
].bss_window
[win
].bssw_base
;
533 else if (map
->bp_space
== PCIIO_SPACE_ROM
)
534 base
+= pcibr_info
->f_rbase
;
535 if ((pci_addr
>= base
) && (pci_addr
< (base
+ size
)))
536 atomic_inc(&map
->bp_toc
);
544 * PCI Bridge Error interrupt handler.
545 * This gets invoked, whenever a PCI bridge sends an error interrupt.
546 * Primarily this servers two purposes.
547 * - If an error can be handled (typically a PIO read/write
548 * error, we try to do it silently.
549 * - If an error cannot be handled, we die violently.
550 * Interrupt due to PIO errors:
551 * - Bridge sends an interrupt, whenever a PCI operation
552 * done by the bridge as the master fails. Operations could
553 * be either a PIO read or a PIO write.
554 * PIO Read operation also triggers a bus error, and it's
555 * We primarily ignore this interrupt in that context..
556 * For PIO write errors, this is the only indication.
557 * and we have to handle with the info from here.
559 * So, there is no way to distinguish if an interrupt is
560 * due to read or write error!.
564 pcibr_error_intr_handler(int irq
, void *arg
, struct pt_regs
*ep
)
566 pcibr_soft_t pcibr_soft
;
571 uint64_t disable_errintr_mask
= 0;
577 * Defensive code for linked pcibr_soft structs
580 extern pcibr_list_p pcibr_list
;
586 printk("pcibr_error_intr_handler: (0x%lx) is not a pcibr_soft!",
590 if ((intr_arg_t
) entry
->bl_soft
== arg
)
592 entry
= entry
->bl_next
;
595 #endif /* PCIBR_SOFT_LIST */
596 pcibr_soft
= (pcibr_soft_t
) arg
;
597 bridge
= pcibr_soft
->bs_base
;
600 * pcibr_error_intr_handler gets invoked whenever bridge encounters
601 * an error situation, and the interrupt for that error is enabled.
602 * This routine decides if the error is fatal or not, and takes
603 * action accordingly.
605 * In the case of PIO read/write timeouts, there is no way
606 * to know if it was a read or write request that timed out.
607 * If the error was due to a "read", a bus error will also occur
608 * and the bus error handling code takes care of it.
609 * If the error is due to a "write", the error is currently logged
610 * by this routine. For SN1 and SN0, if fire-and-forget mode is
611 * disabled, a write error response xtalk packet will be sent to
612 * the II, which will cause an II error interrupt. No write error
613 * recovery actions of any kind currently take place at the pcibr
614 * layer! (e.g., no panic on unrecovered write error)
616 * Prior to reading the Bridge int_status register we need to ensure
617 * that there are no error bits set in the lower layers (hubii)
618 * that have disabled PIO access to the widget. If so, there is nothing
619 * we can do until the bits clear, so we setup a timeout and try again
623 nasid
= NASID_GET(bridge
);
624 if (hubii_check_widget_disabled(nasid
, pcibr_soft
->bs_xid
)) {
625 DECLARE_WAIT_QUEUE_HEAD(wq
);
626 sleep_on_timeout(&wq
, BRIDGE_PIOERR_TIMEOUT
*HZ
); /* sleep */
627 pcibr_soft
->bs_errinfo
.bserr_toutcnt
++;
628 /* Let's go recursive */
629 return(pcibr_error_intr_handler(irq
, arg
, ep
));
632 int_status
= pcireg_intr_status_get(pcibr_soft
);
634 PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ERROR
, pcibr_soft
->bs_conn
,
635 "pcibr_error_intr_handler: int_status=0x%lx\n", int_status
));
637 /* int_status is which bits we have to clear;
638 * err_status is the bits we haven't handled yet.
640 err_status
= int_status
;
642 if (!(int_status
& ~BRIDGE_ISR_INT_MSK
)) {
644 * No error bit set!!.
649 * If we have a PCIBUS_PIOERR, hand it to the logger.
651 if (int_status
& BRIDGE_ISR_PCIBUS_PIOERR
) {
652 pcibr_pioerr_check(pcibr_soft
);
656 struct bs_errintr_stat_s
*bs_estat
;
657 bs_estat
= &pcibr_soft
->bs_errintr_stat
[PCIBR_ISR_ERR_START
];
659 for (i
= PCIBR_ISR_ERR_START
; i
< 64; i
++, bs_estat
++) {
660 if (err_status
& (1ull << i
)) {
661 uint32_t errrate
= 0;
662 uint32_t errcount
= 0;
663 uint32_t errinterval
= 0, current_tick
= 0;
664 int llp_tx_retry_errors
= 0;
665 int is_llp_tx_retry_intr
= 0;
667 bs_estat
->bs_errcount_total
++;
669 current_tick
= jiffies
;
670 errinterval
= (current_tick
- bs_estat
->bs_lasterr_timestamp
);
671 errcount
= (bs_estat
->bs_errcount_total
-
672 bs_estat
->bs_lasterr_snapshot
);
674 /* LLP interrrupt errors are only valid on BUS0 of the PIC */
675 if (pcibr_soft
->bs_busnum
== 0)
676 is_llp_tx_retry_intr
= (BRIDGE_ISR_LLP_TX_RETRY
==(1ull << i
));
678 /* Check for the divide by zero condition while
679 * calculating the error rates.
683 errrate
= errcount
/ errinterval
;
684 /* If able to calculate error rate
685 * on a LLP transmitter retry interrupt, check
686 * if the error rate is nonzero and we have seen
687 * a certain minimum number of errors.
689 * NOTE : errcount is being compared to
690 * PCIBR_ERRTIME_THRESHOLD to make sure that we are not
691 * seeing cases like x error interrupts per y ticks for
692 * very low x ,y (x > y ) which could result in a
695 if (is_llp_tx_retry_intr
&&
697 (errcount
>= PCIBR_ERRTIME_THRESHOLD
)) {
698 llp_tx_retry_errors
= 1;
702 /* Since we are not able to calculate the
703 * error rate check if we exceeded a certain
704 * minimum number of errors for LLP transmitter
705 * retries. Note that this can only happen
706 * within the first tick after the last snapshot.
708 if (is_llp_tx_retry_intr
&&
709 (errcount
>= PCIBR_ERRINTR_DISABLE_LEVEL
)) {
710 llp_tx_retry_errors
= 1;
715 * If a non-zero error rate (which is equivalent to
716 * to 100 errors/tick at least) for the LLP transmitter
717 * retry interrupt was seen, check if we should print
721 if (llp_tx_retry_errors
) {
722 static uint32_t last_printed_rate
;
724 if (errrate
> last_printed_rate
) {
725 last_printed_rate
= errrate
;
726 /* Print the warning only if the error rate
727 * for the transmitter retry interrupt
728 * exceeded the previously printed rate.
731 "%s: %s, Excessive error interrupts : %d/tick\n",
738 * Update snapshot, and time
740 bs_estat
->bs_lasterr_timestamp
= current_tick
;
741 bs_estat
->bs_lasterr_snapshot
=
742 bs_estat
->bs_errcount_total
;
746 * If the error rate is high enough, print the error rate.
748 if (errinterval
> PCIBR_ERRTIME_THRESHOLD
) {
750 if (errrate
> PCIBR_ERRRATE_THRESHOLD
) {
751 printk(KERN_NOTICE
"%s: %s, Error rate %d/tick",
756 * Update snapshot, and time
758 bs_estat
->bs_lasterr_timestamp
= current_tick
;
759 bs_estat
->bs_lasterr_snapshot
=
760 bs_estat
->bs_errcount_total
;
763 /* PIC BRINGUP WAR (PV# 856155):
764 * Dont disable PCI_X_ARB_ERR interrupts, we need the
765 * interrupt inorder to clear the DEV_BROKE bits in
766 * b_arb register to re-enable the device.
768 if (!(err_status
& PIC_ISR_PCIX_ARB_ERR
) &&
769 PCIBR_WAR_ENABLED(PV856155
, pcibr_soft
)) {
771 if (bs_estat
->bs_errcount_total
> PCIBR_ERRINTR_DISABLE_LEVEL
) {
773 * We have seen a fairly large number of errors of
774 * this type. Let's disable the interrupt. But flash
775 * a message about the interrupt being disabled.
778 "%s Disabling error interrupt type %s. Error count %d",
781 bs_estat
->bs_errcount_total
);
782 disable_errintr_mask
|= (1ull << i
);
784 } /* PIC: WAR for PV 856155 end-of-if */
789 if (disable_errintr_mask
) {
792 * Disable some high frequency errors as they
793 * could eat up too much cpu time.
795 s
= pcibr_lock(pcibr_soft
);
796 pcireg_intr_enable_bit_clr(pcibr_soft
, disable_errintr_mask
);
797 pcibr_unlock(pcibr_soft
, s
);
800 * If we leave the PROM cacheable, T5 might
801 * try to do a cache line sized writeback to it,
802 * which will cause a BRIDGE_ISR_INVLD_ADDR.
804 if ((err_status
& BRIDGE_ISR_INVLD_ADDR
) &&
805 (0x00C00000 == (pcireg_bus_err_get(pcibr_soft
) & 0xFFFFFFFFFFC00000)) &&
806 (0x00402000 == (0x00F07F00 & pcireg_cmdword_err_get(pcibr_soft
)))) {
807 err_status
&= ~BRIDGE_ISR_INVLD_ADDR
;
810 * pcibr_pioerr_dump is a systune that make be used to not
811 * print bridge registers for interrupts generated by pio-errors.
812 * Some customers do early probes and expect a lot of failed
815 if (!pcibr_pioerr_dump
) {
816 bridge_errors_to_dump
&= ~BRIDGE_ISR_PCIBUS_PIOERR
;
818 bridge_errors_to_dump
|= BRIDGE_ISR_PCIBUS_PIOERR
;
821 /* Dump/Log Bridge error interrupt info */
822 if (err_status
& bridge_errors_to_dump
) {
823 printk("BRIDGE ERR_STATUS 0x%lx\n", err_status
);
824 pcibr_error_dump(pcibr_soft
);
827 /* PIC BRINGUP WAR (PV# 867308):
828 * Make BRIDGE_ISR_LLP_REC_SNERR & BRIDGE_ISR_LLP_REC_CBERR fatal errors
829 * so we know we've hit the problem defined in PV 867308 that we believe
830 * has only been seen in simulation
832 if (PCIBR_WAR_ENABLED(PV867308
, pcibr_soft
) &&
833 (err_status
& (BRIDGE_ISR_LLP_REC_SNERR
| BRIDGE_ISR_LLP_REC_CBERR
))) {
834 printk("BRIDGE ERR_STATUS 0x%lx\n", err_status
);
835 pcibr_error_dump(pcibr_soft
);
836 /* machine_error_dump(""); */
837 panic("PCI Bridge Error interrupt killed the system");
840 if (err_status
& BRIDGE_ISR_ERROR_FATAL
) {
841 panic("PCI Bridge Error interrupt killed the system");
847 * We can't return without re-enabling the interrupt, since
848 * it would cause problems for devices like IOC3 (Lost
849 * interrupts ?.). So, just cleanup the interrupt, and
850 * use saved values later..
852 * PIC doesn't require groups of interrupts to be cleared...
854 pcireg_intr_reset_set(pcibr_soft
, (int_status
| BRIDGE_IRR_MULTI_CLR
));
856 /* PIC BRINGUP WAR (PV# 856155):
857 * On a PCI_X_ARB_ERR error interrupt clear the DEV_BROKE bits from
858 * the b_arb register to re-enable the device.
860 if ((err_status
& PIC_ISR_PCIX_ARB_ERR
) &&
861 PCIBR_WAR_ENABLED(PV856155
, pcibr_soft
)) {
862 pcireg_arbitration_bit_set(pcibr_soft
, (0xf << 20));
865 /* Zero out bserr_intstat field */
866 pcibr_soft
->bs_errinfo
.bserr_intstat
= 0;
872 * Given the 'pciaddr' find out which slot this address is
873 * allocated to, and return the slot number.
874 * While we have the info handy, construct the
875 * function number, space code and offset as well.
877 * NOTE: if this routine is called, we don't know whether
878 * the address is in CFG, MEM, or I/O space. We have to guess.
879 * This will be the case on PIO stores, where the only way
880 * we have of getting the address is to check the Bridge, which
881 * stores the PCI address but not the space and not the xtalk
882 * address (from which we could get it).
885 pcibr_addr_toslot(pcibr_soft_t pcibr_soft
,
887 pciio_space_t
*spacep
,
889 pciio_function_t
*funcp
)
894 pciio_piospace_t piosp
;
897 * Check if the address is in config space
900 if ((pciaddr
>= BRIDGE_CONFIG_BASE
) && (pciaddr
< BRIDGE_CONFIG_END
)) {
902 if (pciaddr
>= BRIDGE_CONFIG1_BASE
)
903 pciaddr
-= BRIDGE_CONFIG1_BASE
;
905 pciaddr
-= BRIDGE_CONFIG_BASE
;
907 s
= pciaddr
/ BRIDGE_CONFIG_SLOT_SIZE
;
908 pciaddr
%= BRIDGE_CONFIG_SLOT_SIZE
;
915 *spacep
= PCIIO_SPACE_CFG
;
923 for (s
= pcibr_soft
->bs_min_slot
; s
< PCIBR_NUM_SLOTS(pcibr_soft
); ++s
) {
924 int nf
= pcibr_soft
->bs_slot
[s
].bss_ninfo
;
925 pcibr_info_h pcibr_infoh
= pcibr_soft
->bs_slot
[s
].bss_infos
;
927 for (f
= 0; f
< nf
; f
++) {
928 pcibr_info_t pcibr_info
= pcibr_infoh
[f
];
932 for (w
= 0; w
< 6; w
++) {
933 if (pcibr_info
->f_window
[w
].w_space
934 == PCIIO_SPACE_NONE
) {
937 base
= pcibr_info
->f_window
[w
].w_base
;
938 size
= pcibr_info
->f_window
[w
].w_size
;
940 if ((pciaddr
>= base
) && (pciaddr
< (base
+ size
))) {
942 *spacep
= PCIIO_SPACE_WIN(w
);
944 *offsetp
= pciaddr
- base
;
954 * Check if the address was allocated as part of the
955 * pcibr_piospace_alloc calls.
957 for (s
= pcibr_soft
->bs_min_slot
; s
< PCIBR_NUM_SLOTS(pcibr_soft
); ++s
) {
958 int nf
= pcibr_soft
->bs_slot
[s
].bss_ninfo
;
959 pcibr_info_h pcibr_infoh
= pcibr_soft
->bs_slot
[s
].bss_infos
;
961 for (f
= 0; f
< nf
; f
++) {
962 pcibr_info_t pcibr_info
= pcibr_infoh
[f
];
966 piosp
= pcibr_info
->f_piospace
;
968 if ((piosp
->start
<= pciaddr
) &&
969 ((piosp
->count
+ piosp
->start
) > pciaddr
)) {
971 *spacep
= piosp
->space
;
973 *offsetp
= pciaddr
- piosp
->start
;
982 * Some other random address on the PCI bus ...
983 * we have no way of knowing whether this was
984 * a MEM or I/O access; so, for now, we just
985 * assume that the low 1G is MEM, the next
986 * 3G is I/O, and anything above the 4G limit
991 *spacep
= ((pciaddr
< (1ul << 30)) ? PCIIO_SPACE_MEM
:
992 (pciaddr
< (4ul << 30)) ? PCIIO_SPACE_IO
:
997 return PCIIO_SLOT_NONE
;
1002 pcibr_error_cleanup(pcibr_soft_t pcibr_soft
, int error_code
)
1004 uint64_t clr_bits
= BRIDGE_IRR_ALL_CLR
;
1006 ASSERT(error_code
& IOECODE_PIO
);
1007 error_code
= error_code
;
1009 pcireg_intr_reset_set(pcibr_soft
, clr_bits
);
1011 pcireg_tflush_get(pcibr_soft
); /* flushbus */
1016 * pcibr_error_extract
1017 * Given the 'pcibr vertex handle' find out which slot
1018 * the bridge status error address (from pcibr_soft info
1019 * hanging off the vertex)
1020 * allocated to, and return the slot number.
1021 * While we have the info handy, construct the
1022 * space code and offset as well.
1024 * NOTE: if this routine is called, we don't know whether
1025 * the address is in CFG, MEM, or I/O space. We have to guess.
1026 * This will be the case on PIO stores, where the only way
1027 * we have of getting the address is to check the Bridge, which
1028 * stores the PCI address but not the space and not the xtalk
1029 * address (from which we could get it).
1031 * XXX- this interface has no way to return the function
1032 * number on a multifunction card, even though that data
1037 pcibr_error_extract(vertex_hdl_t pcibr_vhdl
,
1038 pciio_space_t
*spacep
,
1041 pcibr_soft_t pcibr_soft
= 0;
1042 iopaddr_t bserr_addr
;
1043 pciio_slot_t slot
= PCIIO_SLOT_NONE
;
1044 arbitrary_info_t rev
;
1046 /* Do a sanity check as to whether we really got a
1047 * bridge vertex handle.
1049 if (hwgraph_info_get_LBL(pcibr_vhdl
, INFO_LBL_PCIBR_ASIC_REV
, &rev
) !=
1053 pcibr_soft
= pcibr_soft_get(pcibr_vhdl
);
1055 bserr_addr
= pcireg_pci_bus_addr_get(pcibr_soft
);
1056 slot
= pcibr_addr_toslot(pcibr_soft
, bserr_addr
,
1057 spacep
, offsetp
, NULL
);
1064 pcibr_device_disable(pcibr_soft_t pcibr_soft
, int devnum
)
1068 * Device failed to handle error. Take steps to
1069 * disable this device ? HOW TO DO IT ?
1071 * If there are any Read response buffers associated
1072 * with this device, it's time to get them back!!
1074 * We can disassociate any interrupt level associated
1075 * with this device, and disable that interrupt level
1077 * For now it's just a place holder
1083 * Handle PIO error that happened at the bridge pointed by pcibr_soft.
1085 * Queries the Bus interface attached to see if the device driver
1086 * mapping the device-number that caused error can handle the
1087 * situation. If so, it will clean up any error, and return
1088 * indicating the error was handled. If the device driver is unable
1089 * to handle the error, it expects the bus-interface to disable that
1090 * device, and takes any steps needed here to take away any resources
1091 * associated with this device.
1093 * A note about slots:
1095 * PIC-based bridges use zero-based device numbering when devices to
1096 * internal registers. However, the physical slots are numbered using a
1097 * one-based scheme because in PCI-X, device 0 is reserved (see comments
1098 * in pcibr_private.h for a better description).
1100 * When building up the hwgraph, we use the external (one-based) number
1101 * scheme when numbering slot components so that hwgraph more accuratly
1102 * reflects what is silkscreened on the bricks.
1104 * Since pciio_error_handler() needs to ultimatly be able to do a hwgraph
1105 * lookup, the ioerror that gets built up in pcibr_pioerror() encodes the
1106 * external (one-based) slot number. However, loops in pcibr_pioerror()
1107 * which attempt to translate the virtual address into the correct
1108 * PCI physical address use the device (zero-based) numbering when
1109 * walking through bridge structures.
1111 * To that end, pcibr_pioerror() uses device to denote the
1112 * zero-based device number, and external_slot to denote the corresponding
1113 * one-based slot number. Loop counters (eg. cs) are always device based.
1116 /* BEM_ADD_IOE doesn't dump the whole ioerror, it just
1117 * decodes the PCI specific portions -- we count on our
1118 * callers to dump the raw IOE data.
1120 #define BEM_ADD_IOE(ioe) \
1122 if (IOERROR_FIELDVALID(ioe, busspace)) { \
1126 iopaddr_t busaddr; \
1128 IOERROR_GETVALUE(spc, ioe, busspace); \
1129 win = spc - PCIIO_SPACE_WIN(0); \
1130 IOERROR_GETVALUE(busaddr, ioe, busaddr); \
1131 IOERROR_GETVALUE(widdev, ioe, widgetdev); \
1134 case PCIIO_SPACE_CFG: \
1135 printk("\tPCI Slot %d Func %d CFG space Offset 0x%lx\n",\
1136 pciio_widgetdev_slot_get(widdev), \
1137 pciio_widgetdev_func_get(widdev), \
1140 case PCIIO_SPACE_IO: \
1141 printk("\tPCI I/O space Offset 0x%lx\n", busaddr); \
1143 case PCIIO_SPACE_MEM: \
1144 case PCIIO_SPACE_MEM32: \
1145 case PCIIO_SPACE_MEM64: \
1146 printk("\tPCI MEM space Offset 0x%lx\n", busaddr); \
1150 printk("\tPCI Slot %d Func %d Window %ld Offset 0x%lx\n",\
1151 pciio_widgetdev_slot_get(widdev), \
1152 pciio_widgetdev_func_get(widdev), \
1164 pcibr_soft_t pcibr_soft
,
1166 ioerror_mode_t mode
,
1169 int retval
= IOERROR_HANDLED
;
1171 vertex_hdl_t pcibr_vhdl
= pcibr_soft
->bs_vhdl
;
1172 iopaddr_t bad_xaddr
;
1174 pciio_space_t raw_space
; /* raw PCI space */
1175 iopaddr_t raw_paddr
; /* raw PCI address */
1177 pciio_space_t space
; /* final PCI space */
1178 pciio_slot_t device
; /* final PCI device if appropriate */
1179 pciio_slot_t external_slot
;/* external slot for device */
1180 pciio_function_t func
; /* final PCI func, if appropriate */
1181 iopaddr_t offset
; /* final PCI offset */
1191 * We expect to have an "xtalkaddr" coming in,
1192 * and need to construct the slot/space/offset.
1195 IOERROR_GETVALUE(bad_xaddr
, ioe
, xtalkaddr
);
1197 PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ERROR_HDLR
, pcibr_soft
->bs_conn
,
1198 "pcibr_pioerror: pcibr_soft=0x%lx, bad_xaddr=0x%lx\n",
1199 pcibr_soft
, bad_xaddr
));
1201 device
= PCIIO_SLOT_NONE
;
1202 func
= PCIIO_FUNC_NONE
;
1203 raw_space
= PCIIO_SPACE_NONE
;
1206 if ((bad_xaddr
>= PCIBR_BUS_TYPE0_CFG_DEV(pcibr_soft
, 0)) &&
1207 (bad_xaddr
< PCIBR_TYPE1_CFG(pcibr_soft
))) {
1208 raw_paddr
= bad_xaddr
- PCIBR_BUS_TYPE0_CFG_DEV(pcibr_soft
, 0);
1209 device
= raw_paddr
/ BRIDGE_CONFIG_SLOT_SIZE
;
1210 raw_paddr
= raw_paddr
% BRIDGE_CONFIG_SLOT_SIZE
;
1211 raw_space
= PCIIO_SPACE_CFG
;
1213 if ((bad_xaddr
>= PCIBR_TYPE1_CFG(pcibr_soft
)) &&
1214 (bad_xaddr
< (PCIBR_TYPE1_CFG(pcibr_soft
) + 0x1000))) {
1215 /* Type 1 config space:
1216 * slot and function numbers not known.
1217 * Perhaps we can read them back?
1219 raw_paddr
= bad_xaddr
- PCIBR_TYPE1_CFG(pcibr_soft
);
1220 raw_space
= PCIIO_SPACE_CFG
;
1222 if ((bad_xaddr
>= PCIBR_BRIDGE_DEVIO(pcibr_soft
, 0)) &&
1223 (bad_xaddr
< PCIBR_BRIDGE_DEVIO(pcibr_soft
, BRIDGE_DEV_CNT
))) {
1226 raw_paddr
= bad_xaddr
- PCIBR_BRIDGE_DEVIO(pcibr_soft
, 0);
1227 x
= raw_paddr
/ BRIDGE_DEVIO_OFF
;
1228 raw_paddr
%= BRIDGE_DEVIO_OFF
;
1229 /* first two devio windows are double-sized */
1230 if ((x
== 1) || (x
== 3))
1231 raw_paddr
+= BRIDGE_DEVIO_OFF
;
1236 /* x is which devio reg; no guarantee
1237 * PCI slot x will be responding.
1238 * still need to figure out who decodes
1239 * space/offset on the bus.
1241 raw_space
= pcibr_soft
->bs_slot
[x
].bss_devio
.bssd_space
;
1242 if (raw_space
== PCIIO_SPACE_NONE
) {
1243 /* Someone got an error because they
1244 * accessed the PCI bus via a DevIO(x)
1245 * window that pcibr has not yet assigned
1246 * to any specific PCI address. It is
1247 * quite possible that the Device(x)
1248 * register has been changed since they
1249 * made their access, but we will give it
1250 * our best decode shot.
1252 raw_space
= pcibr_soft
->bs_slot
[x
].bss_device
1253 & BRIDGE_DEV_DEV_IO_MEM
1257 (pcibr_soft
->bs_slot
[x
].bss_device
&
1258 BRIDGE_DEV_OFF_MASK
) <<
1259 BRIDGE_DEV_OFF_ADDR_SHFT
;
1261 raw_paddr
+= pcibr_soft
->bs_slot
[x
].bss_devio
.bssd_base
;
1264 if (IS_PIC_BUSNUM_SOFT(pcibr_soft
, 0)) {
1265 if ((bad_xaddr
>= PICBRIDGE0_PCI_MEM32_BASE
) &&
1266 (bad_xaddr
<= PICBRIDGE0_PCI_MEM32_LIMIT
)) {
1267 raw_space
= PCIIO_SPACE_MEM32
;
1268 raw_paddr
= bad_xaddr
- PICBRIDGE0_PCI_MEM32_BASE
;
1270 if ((bad_xaddr
>= PICBRIDGE0_PCI_MEM64_BASE
) &&
1271 (bad_xaddr
<= PICBRIDGE0_PCI_MEM64_LIMIT
)) {
1272 raw_space
= PCIIO_SPACE_MEM64
;
1273 raw_paddr
= bad_xaddr
- PICBRIDGE0_PCI_MEM64_BASE
;
1275 } else if (IS_PIC_BUSNUM_SOFT(pcibr_soft
, 1)) {
1276 if ((bad_xaddr
>= PICBRIDGE1_PCI_MEM32_BASE
) &&
1277 (bad_xaddr
<= PICBRIDGE1_PCI_MEM32_LIMIT
)) {
1278 raw_space
= PCIIO_SPACE_MEM32
;
1279 raw_paddr
= bad_xaddr
- PICBRIDGE1_PCI_MEM32_BASE
;
1281 if ((bad_xaddr
>= PICBRIDGE1_PCI_MEM64_BASE
) &&
1282 (bad_xaddr
<= PICBRIDGE1_PCI_MEM64_LIMIT
)) {
1283 raw_space
= PCIIO_SPACE_MEM64
;
1284 raw_paddr
= bad_xaddr
- PICBRIDGE1_PCI_MEM64_BASE
;
1287 printk("pcibr_pioerror(): unknown bridge type");
1288 return IOERROR_UNHANDLED
;
1293 if ((device
== PCIIO_SLOT_NONE
) && (space
!= PCIIO_SPACE_NONE
)) {
1294 /* we've got a space/offset but not which
1295 * PCI slot decodes it. Check through our
1296 * notions of which devices decode where.
1298 * Yes, this "duplicates" some logic in
1299 * pcibr_addr_toslot; the difference is,
1300 * this code knows which space we are in,
1301 * and can really really tell what is
1302 * going on (no guessing).
1305 for (cs
= pcibr_soft
->bs_min_slot
;
1306 (cs
< PCIBR_NUM_SLOTS(pcibr_soft
)) &&
1307 (device
== PCIIO_SLOT_NONE
); cs
++) {
1308 int nf
= pcibr_soft
->bs_slot
[cs
].bss_ninfo
;
1309 pcibr_info_h pcibr_infoh
= pcibr_soft
->bs_slot
[cs
].bss_infos
;
1311 for (cf
= 0; (cf
< nf
) && (device
== PCIIO_SLOT_NONE
); cf
++) {
1312 pcibr_info_t pcibr_info
= pcibr_infoh
[cf
];
1316 for (cw
= 0; (cw
< 6) && (device
== PCIIO_SLOT_NONE
); ++cw
) {
1317 if (((wx
= pcibr_info
->f_window
[cw
].w_space
) != PCIIO_SPACE_NONE
) &&
1318 ((wb
= pcibr_info
->f_window
[cw
].w_base
) != 0) &&
1319 ((ws
= pcibr_info
->f_window
[cw
].w_size
) != 0) &&
1320 ((wl
= wb
+ ws
) > wb
) &&
1321 ((wb
<= offset
) && (wl
> offset
))) {
1322 /* MEM, MEM32 and MEM64 need to
1323 * compare as equal ...
1325 if ((wx
== space
) ||
1326 (((wx
== PCIIO_SPACE_MEM
) ||
1327 (wx
== PCIIO_SPACE_MEM32
) ||
1328 (wx
== PCIIO_SPACE_MEM64
)) &&
1329 ((space
== PCIIO_SPACE_MEM
) ||
1330 (space
== PCIIO_SPACE_MEM32
) ||
1331 (space
== PCIIO_SPACE_MEM64
)))) {
1334 space
= PCIIO_SPACE_WIN(cw
);
1336 } /* endif window space match */
1337 } /* endif window valid and addr match */
1338 } /* next window unless slot set */
1339 } /* next func unless slot set */
1340 } /* next slot unless slot set */
1341 /* XXX- if slot is still -1, no PCI devices are
1342 * decoding here using their standard PCI BASE
1343 * registers. This would be a really good place
1344 * to cross-coordinate with the pciio PCI
1345 * address space allocation routines, to find
1346 * out if this address is "allocated" by any of
1347 * our subsidiary devices.
1350 /* Scan all piomap records on this PCI bus to update
1351 * the TimeOut Counters on all matching maps. If we
1352 * don't already know the slot number, take it from
1353 * the first matching piomap. Note that we have to
1354 * compare maps against raw_space and raw_paddr
1355 * since space and offset could already be
1358 * There is a chance that one CPU could update
1359 * through this path, and another CPU could also
1360 * update due to an interrupt. Closing this hole
1361 * would only result in the possibility of some
1362 * errors never getting logged at all, and since the
1363 * use for bp_toc is as a logical test rather than a
1364 * strict count, the excess counts are not a
1367 for (cs
= pcibr_soft
->bs_min_slot
;
1368 cs
< PCIBR_NUM_SLOTS(pcibr_soft
); ++cs
) {
1369 int nf
= pcibr_soft
->bs_slot
[cs
].bss_ninfo
;
1370 pcibr_info_h pcibr_infoh
= pcibr_soft
->bs_slot
[cs
].bss_infos
;
1372 for (cf
= 0; cf
< nf
; cf
++) {
1373 pcibr_info_t pcibr_info
= pcibr_infoh
[cf
];
1379 for (map
= pcibr_info
->f_piomap
;
1380 map
!= NULL
; map
= map
->bp_next
) {
1382 wb
= map
->bp_pciaddr
;
1384 cw
= wx
- PCIIO_SPACE_WIN(0);
1385 if (cw
>= 0 && cw
< 6) {
1386 wb
+= pcibr_soft
->bs_slot
[cs
].bss_window
[cw
].bssw_base
;
1387 wx
= pcibr_soft
->bs_slot
[cs
].bss_window
[cw
].bssw_space
;
1389 if (wx
== PCIIO_SPACE_ROM
) {
1390 wb
+= pcibr_info
->f_rbase
;
1391 wx
= PCIIO_SPACE_MEM
;
1393 if ((wx
== PCIIO_SPACE_MEM32
) ||
1394 (wx
== PCIIO_SPACE_MEM64
))
1395 wx
= PCIIO_SPACE_MEM
;
1397 if ((wx
== raw_space
) && (raw_paddr
>= wb
) && (raw_paddr
< wl
)) {
1398 atomic_inc(&map
->bp_toc
);
1399 if (device
== PCIIO_SLOT_NONE
) {
1402 space
= map
->bp_space
;
1403 if (cw
>= 0 && cw
< 6)
1404 offset
-= pcibr_soft
->bs_slot
[device
].bss_window
[cw
].bssw_base
;
1413 PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ERROR_HDLR
, pcibr_soft
->bs_conn
,
1414 "pcibr_pioerror: space=%d, offset=0x%lx, dev=0x%x, func=0x%x\n",
1415 space
, offset
, device
, func
));
1417 if (space
!= PCIIO_SPACE_NONE
) {
1418 if (device
!= PCIIO_SLOT_NONE
) {
1419 external_slot
= PCIBR_DEVICE_TO_SLOT(pcibr_soft
, device
);
1421 if (func
!= PCIIO_FUNC_NONE
)
1422 IOERROR_SETVALUE(ioe
, widgetdev
,
1423 pciio_widgetdev_create(external_slot
,func
));
1425 IOERROR_SETVALUE(ioe
, widgetdev
,
1426 pciio_widgetdev_create(external_slot
,0));
1428 IOERROR_SETVALUE(ioe
, busspace
, space
);
1429 IOERROR_SETVALUE(ioe
, busaddr
, offset
);
1431 if (mode
== MODE_DEVPROBE
) {
1433 * During probing, we don't really care what the
1434 * error is. Clean up the error in Bridge, notify
1435 * subsidiary devices, and return success.
1437 pcibr_error_cleanup(pcibr_soft
, error_code
);
1439 /* if appropriate, give the error handler for this slot
1440 * a shot at this probe access as well.
1442 return (device
== PCIIO_SLOT_NONE
) ? IOERROR_HANDLED
:
1443 pciio_error_handler(pcibr_vhdl
, error_code
, mode
, ioe
);
1446 * If we don't know what "PCI SPACE" the access
1447 * was targeting, we may have problems at the
1448 * Bridge itself. Don't touch any bridge registers,
1449 * and do complain loudly.
1452 if (space
== PCIIO_SPACE_NONE
) {
1453 printk("XIO Bus Error at %s\n"
1454 "\taccess to XIO bus offset 0x%lx\n"
1455 "\tdoes not correspond to any PCI address\n",
1456 pcibr_soft
->bs_name
, bad_xaddr
);
1458 /* caller will dump contents of ioe struct */
1459 return IOERROR_XTALKLEVEL
;
1463 * Actual PCI Error handling situation.
1464 * Typically happens when a user level process accesses
1465 * PCI space, and it causes some error.
1467 * Due to PCI Bridge implementation, we get two indication
1468 * for a read error: an interrupt and a Bus error.
1469 * We like to handle read error in the bus error context.
1470 * But the interrupt comes and goes before bus error
1471 * could make much progress. (NOTE: interrupd does
1472 * come in _after_ bus error processing starts. But it's
1473 * completed by the time bus error code reaches PCI PIO
1475 * Similarly write error results in just an interrupt,
1476 * and error handling has to be done at interrupt level.
1477 * There is no way to distinguish at interrupt time, if an
1478 * error interrupt is due to read/write error..
1481 /* We know the xtalk addr, the raw PCI bus space,
1482 * the raw PCI bus address, the decoded PCI bus
1483 * space, the offset within that space, and the
1484 * decoded PCI slot (which may be "PCIIO_SLOT_NONE" if no slot
1485 * is known to be involved).
1489 * Hand the error off to the handler registered
1490 * for the slot that should have decoded the error,
1491 * or to generic PCI handling (if pciio decides that
1492 * such is appropriate).
1494 retval
= pciio_error_handler(pcibr_vhdl
, error_code
, mode
, ioe
);
1496 if (retval
!= IOERROR_HANDLED
) {
1498 /* Generate a generic message for IOERROR_UNHANDLED
1499 * since the subsidiary handlers were silent, and
1502 if (retval
== IOERROR_UNHANDLED
) {
1503 retval
= IOERROR_PANIC
;
1505 /* we may or may not want to print some of this,
1506 * depending on debug level and which error code.
1510 "PIO Error on PCI Bus %s",
1511 pcibr_soft
->bs_name
);
1516 * Since error could not be handled at lower level,
1517 * error data logged has not been cleared.
1518 * Clean up errors, and
1519 * re-enable bridge to interrupt on error conditions.
1520 * NOTE: Wheather we get the interrupt on PCI_ABORT or not is
1521 * dependent on INT_ENABLE register. This write just makes sure
1522 * that if the interrupt was enabled, we do get the interrupt.
1524 * CAUTION: Resetting bit BRIDGE_IRR_PCI_GRP_CLR, acknowledges
1525 * a group of interrupts. If while handling this error,
1526 * some other error has occurred, that would be
1527 * implicitly cleared by this write.
1528 * Need a way to ensure we don't inadvertently clear some
1531 if (IOERROR_FIELDVALID(ioe
, widgetdev
)) {
1533 IOERROR_GETVALUE(widdev
, ioe
, widgetdev
);
1534 external_slot
= pciio_widgetdev_slot_get(widdev
);
1535 device
= PCIBR_SLOT_TO_DEVICE(pcibr_soft
, external_slot
);
1536 pcibr_device_disable(pcibr_soft
, device
);
1538 if (mode
== MODE_DEVUSERERROR
)
1539 pcibr_error_cleanup(pcibr_soft
, error_code
);
1546 * Some error was identified in a DMA transaction.
1547 * This routine will identify the <device, address> that caused the error,
1548 * and try to invoke the appropriate bus service to handle this.
1553 pcibr_soft_t pcibr_soft
,
1555 ioerror_mode_t mode
,
1558 vertex_hdl_t pcibr_vhdl
= pcibr_soft
->bs_vhdl
;
1563 * In case of DMA errors, bridge should have logged the
1564 * address that caused the error.
1565 * Look up the address, in the bridge error registers, and
1566 * take appropriate action
1570 IOERROR_GETVALUE(tmp
, ioe
, widgetnum
);
1571 ASSERT(tmp
== pcibr_soft
->bs_xid
);
1575 * read error log registers
1577 bufnum
= pcireg_resp_err_buf_get(pcibr_soft
);
1578 device
= pcireg_resp_err_dev_get(pcibr_soft
);
1579 IOERROR_SETVALUE(ioe
, widgetdev
, pciio_widgetdev_create(device
, 0));
1580 IOERROR_SETVALUE(ioe
, busaddr
, pcireg_resp_err_get(pcibr_soft
));
1583 * need to ensure that the xtalk address in ioe
1584 * maps to PCI error address read from bridge.
1585 * How to convert PCI address back to Xtalk address ?
1586 * (better idea: convert XTalk address to PCI address
1587 * and then do the compare!)
1590 retval
= pciio_error_handler(pcibr_vhdl
, error_code
, mode
, ioe
);
1591 if (retval
!= IOERROR_HANDLED
) {
1593 IOERROR_GETVALUE(tmp
, ioe
, widgetdev
);
1594 pcibr_device_disable(pcibr_soft
, pciio_widgetdev_slot_get(tmp
));
1598 * Re-enable bridge to interrupt on BRIDGE_IRR_RESP_BUF_GRP_CLR
1599 * NOTE: Wheather we get the interrupt on BRIDGE_IRR_RESP_BUF_GRP_CLR or
1600 * not is dependent on INT_ENABLE register. This write just makes sure
1601 * that if the interrupt was enabled, we do get the interrupt.
1603 pcireg_intr_reset_set(pcibr_soft
, BRIDGE_IRR_RESP_BUF_GRP_CLR
);
1606 * Also, release the "bufnum" back to buffer pool that could be re-used.
1607 * This is done by "disabling" the buffer for a moment, then restoring
1608 * the original assignment.
1615 rrb_reg
= pcireg_rrb_get(pcibr_soft
, (bufnum
& 1));
1616 mask
= 0xF << ((bufnum
>> 1) * 4);
1617 pcireg_rrb_set(pcibr_soft
, (bufnum
& 1), (rrb_reg
& ~mask
));
1618 pcireg_rrb_set(pcibr_soft
, (bufnum
& 1), rrb_reg
);
1625 * pcibr_dmawr_error:
1626 * Handle a dma write error caused by a device attached to this bridge.
1628 * ioe has the widgetnum, widgetdev, and memaddr fields updated
1629 * But we don't know the PCI address that corresponds to "memaddr"
1630 * nor do we know which device driver is generating this address.
1632 * There is no easy way to find out the PCI address(es) that map
1633 * to a specific system memory address. Bus handling code is also
1634 * of not much help, since they don't keep track of the DMA mapping
1635 * that have been handed out.
1636 * So it's a dead-end at this time.
1638 * If translation is available, we could invoke the error handling
1639 * interface of the device driver.
1644 pcibr_soft_t pcibr_soft
,
1646 ioerror_mode_t mode
,
1649 vertex_hdl_t pcibr_vhdl
= pcibr_soft
->bs_vhdl
;
1652 retval
= pciio_error_handler(pcibr_vhdl
, error_code
, mode
, ioe
);
1654 if (retval
!= IOERROR_HANDLED
) {
1657 IOERROR_GETVALUE(tmp
, ioe
, widgetdev
);
1658 pcibr_device_disable(pcibr_soft
, pciio_widgetdev_slot_get(tmp
));
1664 * Bridge error handler.
1665 * Interface to handle all errors that involve bridge in some way.
1667 * This normally gets called from xtalk error handler.
1668 * ioe has different set of fields set depending on the error that
1669 * was encountered. So, we have a bit field indicating which of the
1672 * NOTE: This routine could be operating in interrupt context. So,
1673 * don't try to sleep here (till interrupt threads work!!)
1676 pcibr_error_handler(
1677 error_handler_arg_t einfo
,
1679 ioerror_mode_t mode
,
1682 pcibr_soft_t pcibr_soft
;
1683 int retval
= IOERROR_BADERRORCODE
;
1685 pcibr_soft
= (pcibr_soft_t
) einfo
;
1687 PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ERROR_HDLR
, pcibr_soft
->bs_conn
,
1688 "pcibr_error_handler: pcibr_soft=0x%lx, error_code=0x%x\n",
1689 pcibr_soft
, error_code
));
1691 #if DEBUG && ERROR_DEBUG
1692 printk( "%s: pcibr_error_handler\n", pcibr_soft
->bs_name
);
1695 ASSERT(pcibr_soft
!= NULL
);
1697 if (error_code
& IOECODE_PIO
)
1698 retval
= pcibr_pioerror(pcibr_soft
, error_code
, mode
, ioe
);
1700 if (error_code
& IOECODE_DMA
) {
1701 if (error_code
& IOECODE_READ
) {
1703 * DMA read error occurs when a device attached to the bridge
1704 * tries to read some data from system memory, and this
1705 * either results in a timeout or access error.
1706 * First case is indicated by the bit "XREAD_REQ_TOUT"
1707 * and second case by "RESP_XTALK_ERROR" bit in bridge error
1708 * interrupt status register.
1710 * pcibr_error_intr_handler would get invoked first, and it has
1711 * the responsibility of calling pcibr_error_handler with
1712 * suitable parameters.
1715 retval
= pcibr_dmard_error(pcibr_soft
, error_code
, MODE_DEVERROR
, ioe
);
1717 if (error_code
& IOECODE_WRITE
) {
1719 * A device attached to this bridge has been generating
1720 * bad DMA writes. Find out the device attached, and
1721 * slap on it's wrist.
1724 retval
= pcibr_dmawr_error(pcibr_soft
, error_code
, MODE_DEVERROR
, ioe
);
1732 * PIC has 2 busses under a single widget so pcibr_attach2 registers this
1733 * wrapper function rather than pcibr_error_handler() for PIC. It's upto
1734 * this wrapper to call pcibr_error_handler() with the correct pcibr_soft
1735 * struct (ie. the pcibr_soft struct for the bus that saw the error).
1737 * NOTE: this wrapper function is only registered for PIC ASICs and will
1738 * only be called for a PIC
1741 pcibr_error_handler_wrapper(
1742 error_handler_arg_t einfo
,
1744 ioerror_mode_t mode
,
1747 pcibr_soft_t pcibr_soft
= (pcibr_soft_t
) einfo
;
1748 int pio_retval
= -1;
1749 int dma_retval
= -1;
1751 PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ERROR_HDLR
, pcibr_soft
->bs_conn
,
1752 "pcibr_error_handler_wrapper: pcibr_soft=0x%lx, "
1753 "error_code=0x%x\n", pcibr_soft
, error_code
));
1756 * It is possible that both a IOECODE_PIO and a IOECODE_DMA, and both
1757 * IOECODE_READ and IOECODE_WRITE could be set in error_code so we must
1758 * process all. Since we are a wrapper for pcibr_error_handler(), and
1759 * will be calling it several times within this routine, we turn off the
1760 * error_code bits we don't want it to be processing during that call.
1763 * If the error was a result of a PIO, we tell what bus on the PIC saw
1764 * the error from the PIO address.
1767 if (error_code
& IOECODE_PIO
) {
1768 iopaddr_t bad_xaddr
;
1770 * PIC bus0 PIO space 0x000000 - 0x7fffff or 0x40000000 - 0xbfffffff
1771 * bus1 PIO space 0x800000 - 0xffffff or 0xc0000000 - 0x13fffffff
1773 IOERROR_GETVALUE(bad_xaddr
, ioe
, xtalkaddr
);
1774 if ((bad_xaddr
<= 0x7fffff) ||
1775 ((bad_xaddr
>= 0x40000000) && (bad_xaddr
<= 0xbfffffff))) {
1776 /* bus 0 saw the error */
1777 pio_retval
= pcibr_error_handler((error_handler_arg_t
)pcibr_soft
,
1778 (error_code
& ~IOECODE_DMA
), mode
, ioe
);
1779 } else if (((bad_xaddr
>= 0x800000) && (bad_xaddr
<= 0xffffff)) ||
1780 ((bad_xaddr
>= 0xc0000000) && (bad_xaddr
<= 0x13fffffff))) {
1781 /* bus 1 saw the error */
1782 pcibr_soft
= pcibr_soft
->bs_peers_soft
;
1785 printk(KERN_WARNING
"pcibr_error_handler: "
1786 "bs_peers_soft==NULL. bad_xaddr= 0x%lx mode= 0x%lx\n",
1789 pio_retval
= IOERROR_HANDLED
;
1791 pio_retval
= pcibr_error_handler((error_handler_arg_t
)pcibr_soft
,
1792 (error_code
& ~IOECODE_DMA
), mode
, ioe
);
1794 printk(KERN_WARNING
"pcibr_error_handler_wrapper(): IOECODE_PIO: "
1795 "saw an invalid pio address: 0x%lx\n", bad_xaddr
);
1796 pio_retval
= IOERROR_UNHANDLED
;
1801 * If the error was a result of a DMA Write, we tell what bus on the PIC
1802 * saw the error by looking at tnum.
1804 if ((error_code
& IOECODE_DMA
) && (error_code
& IOECODE_WRITE
)) {
1807 * For DMA writes [X]Bridge encodes the TNUM field of a Xtalk
1813 * BUT PIC needs the bus number so it does this:
1819 * Pull out the bus number from `tnum' and reset the `widgetdev'
1820 * since when hubiio_crb_error_handler() set `widgetdev' it had
1821 * no idea if it was a PIC or a BRIDGE ASIC so it set it based
1824 IOERROR_GETVALUE(tmp
, ioe
, tnum
);
1825 IOERROR_SETVALUE(ioe
, widgetdev
, (tmp
& 0x3));
1826 if ((tmp
& 0x4) == 0) {
1827 /* bus 0 saw the error. */
1828 dma_retval
= pcibr_error_handler((error_handler_arg_t
)pcibr_soft
,
1829 (error_code
& ~(IOECODE_PIO
|IOECODE_READ
)), mode
, ioe
);
1831 /* bus 1 saw the error */
1832 pcibr_soft
= pcibr_soft
->bs_peers_soft
;
1833 dma_retval
= pcibr_error_handler((error_handler_arg_t
)pcibr_soft
,
1834 (error_code
& ~(IOECODE_PIO
|IOECODE_READ
)), mode
, ioe
);
1839 * If the error was a result of a DMA READ, XXX ???
1841 if ((error_code
& IOECODE_DMA
) && (error_code
& IOECODE_READ
)) {
1843 * A DMA Read error will result in a BRIDGE_ISR_RESP_XTLK_ERR
1844 * or BRIDGE_ISR_BAD_XRESP_PKT bridge error interrupt which
1845 * are fatal interrupts (ie. BRIDGE_ISR_ERROR_FATAL) causing
1846 * pcibr_error_intr_handler() to panic the system. So is the
1847 * error handler even going to get called??? It appears that
1848 * the pcibr_dmard_error() attempts to clear the interrupts
1849 * so pcibr_error_intr_handler() won't see them, but there
1850 * appears to be nothing to prevent pcibr_error_intr_handler()
1851 * from running before pcibr_dmard_error() has a chance to
1852 * clear the interrupt.
1854 * Since we'll be panicing anyways, don't bother handling the
1855 * error for now until we can fix this race condition mentioned
1858 dma_retval
= IOERROR_UNHANDLED
;
1861 /* XXX: pcibr_error_handler() should probably do the same thing, it over-
1862 * write it's return value as it processes the different "error_code"s.
1864 if ((pio_retval
== -1) && (dma_retval
== -1)) {
1865 return IOERROR_BADERRORCODE
;
1866 } else if ((dma_retval
!= IOERROR_HANDLED
) && (dma_retval
!= -1)) {
1868 } else if ((pio_retval
!= IOERROR_HANDLED
) && (pio_retval
!= -1)) {
1871 return IOERROR_HANDLED
;