xref: /titanic_51/usr/src/uts/sun4/io/px/px_fm.c (revision bac8fa9cb4e49b18fc19e28fa7aeb18816da4f62)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * PX Fault Management Architecture
30  */
31 #include <sys/types.h>
32 #include <sys/sunndi.h>
33 #include <sys/sunddi.h>
34 #include <sys/fm/protocol.h>
35 #include <sys/fm/util.h>
36 #include <sys/membar.h>
37 #include "px_obj.h"
38 
39 #define	PX_PCIE_PANIC_BITS \
40 	(PCIE_AER_UCE_DLP | PCIE_AER_UCE_FCP | PCIE_AER_UCE_TO | \
41 	PCIE_AER_UCE_RO | PCIE_AER_UCE_MTLP | PCIE_AER_UCE_ECRC | \
42 	PCIE_AER_UCE_UR)
43 #define	PX_PCIE_NO_PANIC_BITS \
44 	(PCIE_AER_UCE_TRAINING | PCIE_AER_UCE_SD | PCIE_AER_UCE_CA | \
45 	PCIE_AER_UCE_UC)
46 
47 static void px_err_fill_pfd(dev_info_t *rpdip, px_err_pcie_t *regs);
48 static int px_pcie_ptlp(dev_info_t *dip, ddi_fm_error_t *derr,
49     px_err_pcie_t *regs);
50 
51 #if defined(DEBUG)
52 static void px_pcie_log(dev_info_t *dip, px_err_pcie_t *regs, int severity);
53 #else	/* DEBUG */
54 #define	px_pcie_log 0 &&
55 #endif	/* DEBUG */
56 
57 /* external functions */
58 extern int pci_xcap_locate(ddi_acc_handle_t h, uint16_t id, uint16_t *base_p);
59 extern int pci_lcap_locate(ddi_acc_handle_t h, uint8_t id, uint16_t *base_p);
60 
61 /*
62  * Initialize px FMA support
63  */
64 int
65 px_fm_attach(px_t *px_p)
66 {
67 	px_p->px_fm_cap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE |
68 		DDI_FM_ACCCHK_CAPABLE | DDI_FM_DMACHK_CAPABLE;
69 
70 	/*
71 	 * Initialize pci_target_queue for FMA handling of
72 	 * pci errors.
73 	 */
74 	pci_targetq_init();
75 
76 	/*
77 	 * check parents' capability
78 	 */
79 	ddi_fm_init(px_p->px_dip, &px_p->px_fm_cap, &px_p->px_fm_ibc);
80 
81 	/*
82 	 * parents need to be ereport and error handling capable
83 	 */
84 	ASSERT(px_p->px_fm_cap &&
85 	    (DDI_FM_ERRCB_CAPABLE | DDI_FM_EREPORT_CAPABLE));
86 
87 	/*
88 	 * Initialize lock to synchronize fabric error handling
89 	 */
90 	mutex_init(&px_p->px_fm_mutex, NULL, MUTEX_DRIVER,
91 	    (void *)px_p->px_fm_ibc);
92 
93 	/*
94 	 * register error callback in parent
95 	 */
96 	ddi_fm_handler_register(px_p->px_dip, px_fm_callback, px_p);
97 
98 	return (DDI_SUCCESS);
99 }
100 
101 /*
102  * Deregister FMA
103  */
104 void
105 px_fm_detach(px_t *px_p)
106 {
107 	ddi_fm_handler_unregister(px_p->px_dip);
108 	mutex_destroy(&px_p->px_fm_mutex);
109 	ddi_fm_fini(px_p->px_dip);
110 }
111 
112 /*
113  * Function used to setup access functions depending on level of desired
114  * protection.
115  */
116 void
117 px_fm_acc_setup(ddi_map_req_t *mp, dev_info_t *rdip)
118 {
119 	uchar_t fflag;
120 	ddi_acc_hdl_t *hp;
121 	ddi_acc_impl_t *ap;
122 
123 	hp = mp->map_handlep;
124 	ap = (ddi_acc_impl_t *)hp->ah_platform_private;
125 	fflag = ap->ahi_common.ah_acc.devacc_attr_access;
126 
127 	if (mp->map_op == DDI_MO_MAP_LOCKED) {
128 		ndi_fmc_insert(rdip, ACC_HANDLE, (void *)hp, NULL);
129 		switch (fflag) {
130 		case DDI_FLAGERR_ACC:
131 			ap->ahi_get8 = i_ddi_prot_get8;
132 			ap->ahi_get16 = i_ddi_prot_get16;
133 			ap->ahi_get32 = i_ddi_prot_get32;
134 			ap->ahi_get64 = i_ddi_prot_get64;
135 			ap->ahi_put8 = i_ddi_prot_put8;
136 			ap->ahi_put16 = i_ddi_prot_put16;
137 			ap->ahi_put32 = i_ddi_prot_put32;
138 			ap->ahi_put64 = i_ddi_prot_put64;
139 			ap->ahi_rep_get8 = i_ddi_prot_rep_get8;
140 			ap->ahi_rep_get16 = i_ddi_prot_rep_get16;
141 			ap->ahi_rep_get32 = i_ddi_prot_rep_get32;
142 			ap->ahi_rep_get64 = i_ddi_prot_rep_get64;
143 			ap->ahi_rep_put8 = i_ddi_prot_rep_put8;
144 			ap->ahi_rep_put16 = i_ddi_prot_rep_put16;
145 			ap->ahi_rep_put32 = i_ddi_prot_rep_put32;
146 			ap->ahi_rep_put64 = i_ddi_prot_rep_put64;
147 			break;
148 		case DDI_CAUTIOUS_ACC :
149 			ap->ahi_get8 = i_ddi_caut_get8;
150 			ap->ahi_get16 = i_ddi_caut_get16;
151 			ap->ahi_get32 = i_ddi_caut_get32;
152 			ap->ahi_get64 = i_ddi_caut_get64;
153 			ap->ahi_put8 = i_ddi_caut_put8;
154 			ap->ahi_put16 = i_ddi_caut_put16;
155 			ap->ahi_put32 = i_ddi_caut_put32;
156 			ap->ahi_put64 = i_ddi_caut_put64;
157 			ap->ahi_rep_get8 = i_ddi_caut_rep_get8;
158 			ap->ahi_rep_get16 = i_ddi_caut_rep_get16;
159 			ap->ahi_rep_get32 = i_ddi_caut_rep_get32;
160 			ap->ahi_rep_get64 = i_ddi_caut_rep_get64;
161 			ap->ahi_rep_put8 = i_ddi_caut_rep_put8;
162 			ap->ahi_rep_put16 = i_ddi_caut_rep_put16;
163 			ap->ahi_rep_put32 = i_ddi_caut_rep_put32;
164 			ap->ahi_rep_put64 = i_ddi_caut_rep_put64;
165 			break;
166 		default:
167 			break;
168 		}
169 	} else if (mp->map_op == DDI_MO_UNMAP) {
170 		ndi_fmc_remove(rdip, ACC_HANDLE, (void *)hp);
171 	}
172 }
173 
174 /*
175  * Function used to initialize FMA for our children nodes. Called
176  * through pci busops when child node calls ddi_fm_init.
177  */
178 /*ARGSUSED*/
179 int
180 px_fm_init_child(dev_info_t *dip, dev_info_t *cdip, int cap,
181     ddi_iblock_cookie_t *ibc_p)
182 {
183 	px_t *px_p = DIP_TO_STATE(dip);
184 
185 	ASSERT(ibc_p != NULL);
186 	*ibc_p = px_p->px_fm_ibc;
187 
188 	return (px_p->px_fm_cap);
189 }
190 
191 /*
192  * lock access for exclusive PCIe access
193  */
194 void
195 px_bus_enter(dev_info_t *dip, ddi_acc_handle_t handle)
196 {
197 	px_pec_t	*pec_p = ((px_t *)DIP_TO_STATE(dip))->px_pec_p;
198 
199 	/*
200 	 * Exclusive access has been used for cautious put/get,
201 	 * Both utilize i_ddi_ontrap which, on sparcv9, implements
202 	 * similar protection as what on_trap() does, and which calls
203 	 * membar  #Sync to flush out all cpu deferred errors
204 	 * prior to get/put operation, so here we're not calling
205 	 * membar  #Sync - a difference from what's in pci_bus_enter().
206 	 */
207 	mutex_enter(&pec_p->pec_pokefault_mutex);
208 	pec_p->pec_acc_hdl = handle;
209 }
210 
211 /*
212  * unlock access for exclusive PCIe access
213  */
214 /* ARGSUSED */
215 void
216 px_bus_exit(dev_info_t *dip, ddi_acc_handle_t handle)
217 {
218 	px_t		*px_p = DIP_TO_STATE(dip);
219 	px_pec_t	*pec_p = px_p->px_pec_p;
220 
221 	pec_p->pec_acc_hdl = NULL;
222 	mutex_exit(&pec_p->pec_pokefault_mutex);
223 }
224 
225 
226 /*
227  * PCI error callback which is registered with our parent to call
228  * for PCIe logging when the CPU traps due to PCIe Uncorrectable Errors
229  * and PCI BERR/TO/UE on IO Loads.
230  */
231 /*ARGSUSED*/
232 int
233 px_fm_callback(dev_info_t *dip, ddi_fm_error_t *derr, const void *impl_data)
234 {
235 	px_t		*px_p = (px_t *)impl_data;
236 	int		i, acc_type = 0;
237 	int		lookup, rc_err, fab_err = PF_NO_PANIC;
238 	uint32_t	addr, addr_high, addr_low;
239 	pcie_req_id_t	bdf;
240 	px_ranges_t	*ranges_p;
241 	int		range_len;
242 
243 	mutex_enter(&px_p->px_fm_mutex);
244 
245 	addr_high = (uint32_t)((uint64_t)derr->fme_bus_specific >> 32);
246 	addr_low = (uint32_t)((uint64_t)derr->fme_bus_specific);
247 
248 	/*
249 	 * Make sure this failed load came from this PCIe port.  Check by
250 	 * matching the upper 32 bits of the address with the ranges property.
251 	 */
252 	range_len = px_p->px_ranges_length / sizeof (px_ranges_t);
253 	i = 0;
254 	for (ranges_p = px_p->px_ranges_p; i < range_len; i++, ranges_p++) {
255 		if (ranges_p->parent_high == addr_high) {
256 			switch (ranges_p->child_high & PCI_ADDR_MASK) {
257 			case PCI_ADDR_CONFIG:
258 				acc_type = PF_CFG_ADDR;
259 				addr = NULL;
260 				bdf = (pcie_req_id_t)(addr_low >> 12);
261 				break;
262 			case PCI_ADDR_MEM32:
263 				acc_type = PF_DMA_ADDR;
264 				addr = addr_low;
265 				bdf = NULL;
266 				break;
267 			}
268 			break;
269 		}
270 	}
271 
272 	/* This address doesn't belong to this leaf, just return with OK */
273 	if (!acc_type) {
274 		mutex_exit(&px_p->px_fm_mutex);
275 		return (DDI_FM_OK);
276 	}
277 
278 	rc_err = px_err_cmn_intr(px_p, derr, PX_TRAP_CALL, PX_FM_BLOCK_ALL);
279 	lookup = pf_hdl_lookup(dip, derr->fme_ena, acc_type, addr, bdf);
280 
281 	if (!px_lib_is_in_drain_state(px_p)) {
282 		/*
283 		 * This is to ensure that device corresponding to the addr of
284 		 * the failed PIO/CFG load gets scanned.
285 		 */
286 		px_rp_en_q(px_p, bdf, addr,
287 		    (PCI_STAT_R_MAST_AB | PCI_STAT_R_TARG_AB));
288 		fab_err = pf_scan_fabric(dip, derr, px_p->px_dq_p,
289 		    &px_p->px_dq_tail);
290 	}
291 
292 	mutex_exit(&px_p->px_fm_mutex);
293 
294 	if ((rc_err & (PX_PANIC | PX_PROTECTED)) || (fab_err & PF_PANIC) ||
295 	    (lookup == PF_HDL_NOTFOUND))
296 		return (DDI_FM_FATAL);
297 	else if ((rc_err == PX_NO_ERROR) && (fab_err == PF_NO_ERROR))
298 		return (DDI_FM_OK);
299 
300 	return (DDI_FM_NONFATAL);
301 }
302 
303 /*
304  * px_err_fabric_intr:
305  * Interrupt handler for PCIE fabric block.
306  * o lock
307  * o create derr
308  * o px_err_cmn_intr(leaf, with jbc)
309  * o send ereport(fire fmri, derr, payload = BDF)
310  * o dispatch (leaf)
311  * o unlock
312  * o handle error: fatal? fm_panic() : return INTR_CLAIMED)
313  */
314 /* ARGSUSED */
315 uint_t
316 px_err_fabric_intr(px_t *px_p, msgcode_t msg_code, pcie_req_id_t rid)
317 {
318 	dev_info_t	*rpdip = px_p->px_dip;
319 	int		rc_err, fab_err = PF_NO_PANIC;
320 	ddi_fm_error_t	derr;
321 
322 	mutex_enter(&px_p->px_fm_mutex);
323 
324 	/* Create the derr */
325 	bzero(&derr, sizeof (ddi_fm_error_t));
326 	derr.fme_version = DDI_FME_VERSION;
327 	derr.fme_ena = fm_ena_generate(0, FM_ENA_FMT1);
328 	derr.fme_flag = DDI_FM_ERR_UNEXPECTED;
329 
330 	/* Ensure that the rid of the fabric message will get scanned. */
331 	px_rp_en_q(px_p, rid, NULL, NULL);
332 
333 	rc_err = px_err_cmn_intr(px_p, &derr, PX_INTR_CALL, PX_FM_BLOCK_PCIE);
334 
335 	/* call rootport dispatch */
336 	if (!px_lib_is_in_drain_state(px_p)) {
337 		fab_err = pf_scan_fabric(rpdip, &derr, px_p->px_dq_p,
338 		    &px_p->px_dq_tail);
339 	}
340 
341 	mutex_exit(&px_p->px_fm_mutex);
342 
343 	px_err_panic(rc_err, PX_RC, fab_err);
344 
345 	return (DDI_INTR_CLAIMED);
346 }
347 
348 /*
349  * px_err_safeacc_check:
350  * Check to see if a peek/poke and cautious access is currently being
351  * done on a particular leaf.
352  *
353  * Safe access reads induced fire errors will be handled by cpu trap handler
354  * which will call px_fm_callback() which calls this function. In that
355  * case, the derr fields will be set by trap handler with the correct values.
356  *
357  * Safe access writes induced errors will be handled by px interrupt
358  * handlers, this function will fill in the derr fields.
359  *
360  * If a cpu trap does occur, it will quiesce all other interrupts allowing
361  * the cpu trap error handling to finish before Fire receives an interrupt.
362  *
363  * If fire does indeed have an error when a cpu trap occurs as a result of
364  * a safe access, a trap followed by a Mondo/Fabric interrupt will occur.
365  * In which case derr will be initialized as "UNEXPECTED" by the interrupt
366  * handler and this function will need to find if this error occured in the
367  * middle of a safe access operation.
368  *
369  * @param px_p		leaf in which to check access
370  * @param derr		fm err data structure to be updated
371  */
372 void
373 px_err_safeacc_check(px_t *px_p, ddi_fm_error_t *derr)
374 {
375 	px_pec_t 	*pec_p = px_p->px_pec_p;
376 	int		acctype = pec_p->pec_safeacc_type;
377 
378 	ASSERT(MUTEX_HELD(&px_p->px_fm_mutex));
379 
380 	if (derr->fme_flag != DDI_FM_ERR_UNEXPECTED) {
381 		return;
382 	}
383 
384 	/* safe access checking */
385 	switch (acctype) {
386 	case DDI_FM_ERR_EXPECTED:
387 		/*
388 		 * cautious access protection, protected from all err.
389 		 */
390 		ddi_fm_acc_err_get(pec_p->pec_acc_hdl, derr,
391 		    DDI_FME_VERSION);
392 		derr->fme_flag = acctype;
393 		derr->fme_acc_handle = pec_p->pec_acc_hdl;
394 		break;
395 	case DDI_FM_ERR_POKE:
396 		/*
397 		 * ddi_poke protection, check nexus and children for
398 		 * expected errors.
399 		 */
400 		membar_sync();
401 		derr->fme_flag = acctype;
402 		break;
403 	case DDI_FM_ERR_PEEK:
404 		derr->fme_flag = acctype;
405 		break;
406 	}
407 }
408 
409 /*
410  * Suggest panic if any EQ (except CE q) has overflown.
411  */
412 int
413 px_err_check_eq(dev_info_t *dip)
414 {
415 	px_t			*px_p = DIP_TO_STATE(dip);
416 	px_msiq_state_t 	*msiq_state_p = &px_p->px_ib_p->ib_msiq_state;
417 	px_pec_t		*pec_p = px_p->px_pec_p;
418 	msiqid_t		eq_no = msiq_state_p->msiq_1st_msiq_id;
419 	pci_msiq_state_t	msiq_state;
420 	int			i;
421 
422 	for (i = 0; i < msiq_state_p->msiq_cnt; i++) {
423 		if (i + eq_no == pec_p->pec_corr_msg_msiq_id) /* skip CE q */
424 			continue;
425 		if ((px_lib_msiq_getstate(dip, i + eq_no, &msiq_state) !=
426 			DDI_SUCCESS) || msiq_state == PCI_MSIQ_STATE_ERROR)
427 			return (PX_PANIC);
428 	}
429 	return (PX_NO_PANIC);
430 }
431 
432 static void
433 px_err_fill_pfd(dev_info_t *rpdip, px_err_pcie_t *regs)
434 {
435 	px_t		*px_p = DIP_TO_STATE(rpdip);
436 	pf_data_t	pf_data = {0};
437 	pcie_req_id_t	fault_bdf = 0;
438 	uint32_t	fault_addr = 0;
439 	uint16_t	s_status = 0;
440 
441 	pf_data.rp_bdf = px_p->px_bdf;
442 
443 	/*
444 	 * set RC s_status in PCI term to coordinate with downstream fabric
445 	 * errors ananlysis.
446 	 */
447 	if (regs->primary_ue & PCIE_AER_UCE_UR)
448 		s_status = PCI_STAT_R_MAST_AB;
449 	if (regs->primary_ue & PCIE_AER_UCE_CA)
450 		s_status = PCI_STAT_R_TARG_AB;
451 	if (regs->primary_ue & (PCIE_AER_UCE_PTLP | PCIE_AER_UCE_ECRC))
452 		s_status = PCI_STAT_PERROR;
453 
454 	if (regs->primary_ue & (PCIE_AER_UCE_UR | PCIE_AER_UCE_CA)) {
455 		pf_data.aer_h0 = regs->rx_hdr1;
456 		pf_data.aer_h1 = regs->rx_hdr2;
457 		pf_data.aer_h2 = regs->rx_hdr3;
458 		pf_data.aer_h3 = regs->rx_hdr4;
459 
460 		pf_tlp_decode(rpdip, &pf_data, &fault_bdf, NULL, NULL);
461 	} else if (regs->primary_ue & PCIE_AER_UCE_PTLP) {
462 		pcie_tlp_hdr_t	*tlp_p;
463 
464 		pf_data.aer_h0 = regs->rx_hdr1;
465 		pf_data.aer_h1 = regs->rx_hdr2;
466 		pf_data.aer_h2 = regs->rx_hdr3;
467 		pf_data.aer_h3 = regs->rx_hdr4;
468 
469 		tlp_p = (pcie_tlp_hdr_t *)&pf_data.aer_h0;
470 		if (tlp_p->type == PCIE_TLP_TYPE_CPL)
471 			pf_tlp_decode(rpdip, &pf_data, &fault_bdf, NULL, NULL);
472 
473 		pf_data.aer_h0 = regs->tx_hdr1;
474 		pf_data.aer_h1 = regs->tx_hdr2;
475 		pf_data.aer_h2 = regs->tx_hdr3;
476 		pf_data.aer_h3 = regs->tx_hdr4;
477 
478 		pf_tlp_decode(rpdip, &pf_data, NULL, &fault_addr, NULL);
479 	}
480 
481 	px_rp_en_q(px_p, fault_bdf, fault_addr, s_status);
482 }
483 
484 int
485 px_err_check_pcie(dev_info_t *dip, ddi_fm_error_t *derr, px_err_pcie_t *regs)
486 {
487 	uint32_t ce_reg, ue_reg;
488 	int err = PX_NO_ERROR;
489 
490 	ce_reg = regs->ce_reg;
491 	if (ce_reg)
492 		err |= (ce_reg & px_fabric_die_rc_ce) ? PX_PANIC : PX_NO_ERROR;
493 
494 	ue_reg = regs->ue_reg;
495 	if (!ue_reg)
496 		goto done;
497 
498 	if (ue_reg & PCIE_AER_UCE_PTLP)
499 		err |= px_pcie_ptlp(dip, derr, regs);
500 
501 	if (ue_reg & PX_PCIE_PANIC_BITS)
502 		err |= PX_PANIC;
503 
504 	if (ue_reg & PX_PCIE_NO_PANIC_BITS)
505 		err |= PX_NO_PANIC;
506 
507 	/* Scan the fabric to clean up error bits, for the following errors. */
508 	if (ue_reg & (PCIE_AER_UCE_PTLP | PCIE_AER_UCE_CA | PCIE_AER_UCE_UR))
509 		px_err_fill_pfd(dip, regs);
510 done:
511 	px_pcie_log(dip, regs, err);
512 	return (err);
513 }
514 
515 #if defined(DEBUG)
516 static void
517 px_pcie_log(dev_info_t *dip, px_err_pcie_t *regs, int severity)
518 {
519 	DBG(DBG_ERR_INTR, dip,
520 	    "A PCIe RC error has occured with a severity of \"%s\"\n"
521 	    "\tCE: 0x%x UE: 0x%x Primary UE: 0x%x\n"
522 	    "\tTX Hdr: 0x%x 0x%x 0x%x 0x%x\n\tRX Hdr: 0x%x 0x%x 0x%x 0x%x\n",
523 	    (severity & PX_PANIC) ? "PANIC" : "NO PANIC", regs->ce_reg,
524 	    regs->ue_reg, regs->primary_ue, regs->tx_hdr1, regs->tx_hdr2,
525 	    regs->tx_hdr3, regs->tx_hdr4, regs->rx_hdr1, regs->rx_hdr2,
526 	    regs->rx_hdr3, regs->rx_hdr4);
527 }
528 #endif	/* DEBUG */
529 
530 /*
531  * look through poisoned TLP cases and suggest panic/no panic depend on
532  * handle lookup.
533  */
534 static int
535 px_pcie_ptlp(dev_info_t *dip, ddi_fm_error_t *derr, px_err_pcie_t *regs)
536 {
537 	px_t		*px_p = DIP_TO_STATE(dip);
538 	pf_data_t	pf_data;
539 	pcie_req_id_t	bdf;
540 	uint32_t	addr, trans_type;
541 	int		tlp_sts, tlp_cmd;
542 	int		sts = PF_HDL_NOTFOUND;
543 
544 	if (regs->primary_ue != PCIE_AER_UCE_PTLP)
545 		return (PX_PANIC);
546 
547 	if (!regs->rx_hdr1)
548 		goto done;
549 
550 	pf_data.rp_bdf = px_p->px_bdf;
551 	pf_data.aer_h0 = regs->rx_hdr1;
552 	pf_data.aer_h1 = regs->rx_hdr2;
553 	pf_data.aer_h2 = regs->rx_hdr3;
554 	pf_data.aer_h3 = regs->rx_hdr4;
555 
556 	tlp_sts = pf_tlp_decode(dip, &pf_data, &bdf, &addr, &trans_type);
557 	tlp_cmd = ((pcie_tlp_hdr_t *)(&pf_data.aer_h0))->type;
558 
559 	if (tlp_sts == DDI_FAILURE)
560 		goto done;
561 
562 	switch (tlp_cmd) {
563 	case PCIE_TLP_TYPE_CPL:
564 	case PCIE_TLP_TYPE_CPLLK:
565 		/*
566 		 * Usually a PTLP is a CPL with data.  Grab the completer BDF
567 		 * from the RX TLP, and the original address from the TX TLP.
568 		 */
569 		if (regs->tx_hdr1) {
570 			pf_data.aer_h0 = regs->tx_hdr1;
571 			pf_data.aer_h1 = regs->tx_hdr2;
572 			pf_data.aer_h2 = regs->tx_hdr3;
573 			pf_data.aer_h3 = regs->tx_hdr4;
574 
575 			sts = pf_tlp_decode(dip, &pf_data, NULL, &addr,
576 			    &trans_type);
577 		} /* FALLTHRU */
578 	case PCIE_TLP_TYPE_IO:
579 	case PCIE_TLP_TYPE_MEM:
580 	case PCIE_TLP_TYPE_MEMLK:
581 		sts = pf_hdl_lookup(dip, derr->fme_ena, trans_type, addr, bdf);
582 		break;
583 	default:
584 		sts = PF_HDL_NOTFOUND;
585 	}
586 done:
587 	return (sts == PF_HDL_NOTFOUND ? PX_PANIC : PX_NO_PANIC);
588 }
589 
590 /*
591  * This function appends a pf_data structure to the error q which is used later
592  * during PCIe fabric scan.  It signifies:
593  * o errs rcvd in RC, that may have been propagated to/from the fabric
594  * o the fabric scan code should scan the device path of fault bdf/addr
595  *
596  * fault_bdf: The bdf that caused the fault, which may have error bits set.
597  * fault_addr: The PIO addr that caused the fault, such as failed PIO, but not
598  *	       failed DMAs.
599  * s_status: Secondary Status equivalent to why the fault occured.
600  *	     (ie S-TA/MA, R-TA)
601  * Either the fault bdf or addr may be NULL, but not both.
602  */
603 int px_foo = 0;
604 void
605 px_rp_en_q(px_t *px_p, pcie_req_id_t fault_bdf, uint32_t fault_addr,
606     uint16_t s_status)
607 {
608 	pf_data_t pf_data = {0};
609 
610 	if (!fault_bdf && !fault_addr)
611 		return;
612 
613 	pf_data.dev_type = PCIE_PCIECAP_DEV_TYPE_ROOT;
614 	if (px_foo) {
615 		pf_data.fault_bdf = px_foo;
616 		px_foo = 0;
617 	} else
618 		pf_data.fault_bdf = fault_bdf;
619 
620 	pf_data.bdf = px_p->px_bdf;
621 	pf_data.rp_bdf = px_p->px_bdf;
622 	pf_data.fault_addr = fault_addr;
623 	pf_data.s_status = s_status;
624 	pf_data.send_erpt = PF_SEND_ERPT_NO;
625 
626 	(void) pf_en_dq(&pf_data, px_p->px_dq_p, &px_p->px_dq_tail, -1);
627 }
628 
629 /*
630  * Panic if the err tunable is set and that we are not already in the middle
631  * of panic'ing.
632  */
633 #define	MSZ (sizeof (fm_msg) -strlen(fm_msg) - 1)
634 void
635 px_err_panic(int err, int msg, int fab_err)
636 {
637 	char fm_msg[96] = "";
638 	int ferr = PX_NO_ERROR;
639 
640 	if (panicstr)
641 		return;
642 
643 	if (!(err & px_die))
644 		goto fabric;
645 	if (msg & PX_RC)
646 		(void) strncat(fm_msg, px_panic_rc_msg, MSZ);
647 	if (msg & PX_RP)
648 		(void) strncat(fm_msg, px_panic_rp_msg, MSZ);
649 	if (msg & PX_HB)
650 		(void) strncat(fm_msg, px_panic_hb_msg, MSZ);
651 
652 fabric:
653 	if (fab_err & PF_PANIC)
654 		ferr = PX_PANIC;
655 	if (fab_err & ~(PF_PANIC | PF_NO_ERROR))
656 		ferr = PX_NO_PANIC;
657 	if (ferr & px_die) {
658 		if (strlen(fm_msg))
659 			(void) strncat(fm_msg, " and", MSZ);
660 		(void) strncat(fm_msg, px_panic_fab_msg, MSZ);
661 	}
662 
663 	if (strlen(fm_msg))
664 		fm_panic("Fatal error has occured in:%s.", fm_msg);
665 }
666