1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * Schizo specifics implementation: 31*0Sstevel@tonic-gate * interrupt mapping register 32*0Sstevel@tonic-gate * PBM configuration 33*0Sstevel@tonic-gate * ECC and PBM error handling 34*0Sstevel@tonic-gate * Iommu mapping handling 35*0Sstevel@tonic-gate * Streaming Cache flushing 36*0Sstevel@tonic-gate */ 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate #include <sys/types.h> 39*0Sstevel@tonic-gate #include <sys/kmem.h> 40*0Sstevel@tonic-gate #include <sys/sysmacros.h> 41*0Sstevel@tonic-gate #include <sys/async.h> 42*0Sstevel@tonic-gate #include <sys/ivintr.h> 43*0Sstevel@tonic-gate #include <sys/systm.h> 44*0Sstevel@tonic-gate #include <sys/intr.h> 45*0Sstevel@tonic-gate #include <sys/machsystm.h> /* lddphys() */ 46*0Sstevel@tonic-gate #include <sys/machsystm.h> /* lddphys, intr_dist_add */ 47*0Sstevel@tonic-gate #include <sys/iommutsb.h> 48*0Sstevel@tonic-gate #include <sys/promif.h> /* prom_printf */ 49*0Sstevel@tonic-gate #include <sys/map.h> 50*0Sstevel@tonic-gate #include <sys/ddi.h> 51*0Sstevel@tonic-gate #include <sys/sunddi.h> 52*0Sstevel@tonic-gate #include <sys/sunndi.h> 53*0Sstevel@tonic-gate #include <sys/spl.h> 54*0Sstevel@tonic-gate #include <sys/fm/util.h> 55*0Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 56*0Sstevel@tonic-gate #include <sys/fm/protocol.h> 57*0Sstevel@tonic-gate #include <sys/fm/io/sun4upci.h> 58*0Sstevel@tonic-gate #include <sys/fm/io/ddi.h> 59*0Sstevel@tonic-gate #include <sys/fm/io/pci.h> 60*0Sstevel@tonic-gate #include <sys/pci/pci_obj.h> 61*0Sstevel@tonic-gate #include <sys/pci/pcisch.h> 62*0Sstevel@tonic-gate #include <sys/pci/pcisch_asm.h> 63*0Sstevel@tonic-gate #include <sys/x_call.h> /* XCALL_PIL */ 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate /*LINTLIBRARY*/ 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate extern uint8_t ldstub(uint8_t *); 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate #define IOMMU_CTX_BITMAP_SIZE (1 << (12 - 3)) 70*0Sstevel@tonic-gate static void iommu_ctx_free(iommu_t *); 71*0Sstevel@tonic-gate static int iommu_tlb_scrub(iommu_t *, int); 72*0Sstevel@tonic-gate static uint32_t pci_identity_init(pci_t *); 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate static void pci_cb_clear_error(cb_t *, cb_errstate_t *); 75*0Sstevel@tonic-gate static void pci_clear_error(pci_t *, pbm_errstate_t *); 76*0Sstevel@tonic-gate static uint32_t pci_identity_init(pci_t *pci_p); 77*0Sstevel@tonic-gate static int pci_intr_setup(pci_t *pci_p); 78*0Sstevel@tonic-gate static void iommu_ereport_post(dev_info_t *, uint64_t, pbm_errstate_t *); 79*0Sstevel@tonic-gate static void cb_ereport_post(dev_info_t *, uint64_t, cb_errstate_t *); 80*0Sstevel@tonic-gate static void pcix_ereport_post(dev_info_t *, uint64_t, pbm_errstate_t *); 81*0Sstevel@tonic-gate static void pci_format_ecc_addr(dev_info_t *dip, uint64_t *afar, 82*0Sstevel@tonic-gate ecc_region_t region); 83*0Sstevel@tonic-gate static void pci_pbm_errstate_get(pci_t *pci_p, pbm_errstate_t *pbm_err_p); 84*0Sstevel@tonic-gate static void tm_vmem_free(ddi_dma_impl_t *mp, iommu_t *iommu_p, 85*0Sstevel@tonic-gate dvma_addr_t dvma_pg, int npages); 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate static int pcix_ma_behind_bridge(pbm_errstate_t *pbm_err_p); 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gate static pci_ksinfo_t *pci_name_kstat; 90*0Sstevel@tonic-gate static pci_ksinfo_t *saf_name_kstat; 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate extern void pcix_set_cmd_reg(dev_info_t *child, uint16_t value); 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate /* called by pci_attach() DDI_ATTACH to initialize pci objects */ 95*0Sstevel@tonic-gate int 96*0Sstevel@tonic-gate pci_obj_setup(pci_t *pci_p) 97*0Sstevel@tonic-gate { 98*0Sstevel@tonic-gate pci_common_t *cmn_p; 99*0Sstevel@tonic-gate uint32_t chip_id = pci_identity_init(pci_p); 100*0Sstevel@tonic-gate uint32_t cmn_id = PCI_CMN_ID(ID_CHIP_TYPE(chip_id), pci_p->pci_id); 101*0Sstevel@tonic-gate int ret; 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate /* Perform allocations first to avoid delicate unwinding. */ 104*0Sstevel@tonic-gate if (pci_alloc_tsb(pci_p) != DDI_SUCCESS) 105*0Sstevel@tonic-gate return (DDI_FAILURE); 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate mutex_enter(&pci_global_mutex); 108*0Sstevel@tonic-gate cmn_p = get_pci_common_soft_state(cmn_id); 109*0Sstevel@tonic-gate if (cmn_p == NULL) { 110*0Sstevel@tonic-gate if (alloc_pci_common_soft_state(cmn_id) != DDI_SUCCESS) { 111*0Sstevel@tonic-gate mutex_exit(&pci_global_mutex); 112*0Sstevel@tonic-gate pci_free_tsb(pci_p); 113*0Sstevel@tonic-gate return (DDI_FAILURE); 114*0Sstevel@tonic-gate } 115*0Sstevel@tonic-gate cmn_p = get_pci_common_soft_state(cmn_id); 116*0Sstevel@tonic-gate cmn_p->pci_common_id = cmn_id; 117*0Sstevel@tonic-gate cmn_p->pci_common_tsb_cookie = IOMMU_TSB_COOKIE_NONE; 118*0Sstevel@tonic-gate } 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate ASSERT((pci_p->pci_side == 0) || (pci_p->pci_side == 1)); 121*0Sstevel@tonic-gate if (cmn_p->pci_p[pci_p->pci_side]) { 122*0Sstevel@tonic-gate /* second side attach */ 123*0Sstevel@tonic-gate pci_p->pci_side = PCI_OTHER_SIDE(pci_p->pci_side); 124*0Sstevel@tonic-gate ASSERT(cmn_p->pci_p[pci_p->pci_side] == NULL); 125*0Sstevel@tonic-gate } 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate cmn_p->pci_p[pci_p->pci_side] = pci_p; 128*0Sstevel@tonic-gate pci_p->pci_common_p = cmn_p; 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate if (cmn_p->pci_common_refcnt == 0) 131*0Sstevel@tonic-gate cmn_p->pci_chip_id = chip_id; 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate ib_create(pci_p); 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate /* 136*0Sstevel@tonic-gate * The initialization of cb internal interrupts depends on ib 137*0Sstevel@tonic-gate */ 138*0Sstevel@tonic-gate if (cmn_p->pci_common_refcnt == 0) { 139*0Sstevel@tonic-gate cb_create(pci_p); 140*0Sstevel@tonic-gate cmn_p->pci_common_cb_p = pci_p->pci_cb_p; 141*0Sstevel@tonic-gate } else 142*0Sstevel@tonic-gate pci_p->pci_cb_p = cmn_p->pci_common_cb_p; 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate iommu_create(pci_p); 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate if (cmn_p->pci_common_refcnt == 0) { 147*0Sstevel@tonic-gate ecc_create(pci_p); 148*0Sstevel@tonic-gate cmn_p->pci_common_ecc_p = pci_p->pci_ecc_p; 149*0Sstevel@tonic-gate } else 150*0Sstevel@tonic-gate pci_p->pci_ecc_p = cmn_p->pci_common_ecc_p; 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate pbm_create(pci_p); 153*0Sstevel@tonic-gate sc_create(pci_p); 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate pci_fm_create(pci_p); 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate if ((ret = pci_intr_setup(pci_p)) != DDI_SUCCESS) 158*0Sstevel@tonic-gate goto done; 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate pci_kstat_create(pci_p); 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate cmn_p->pci_common_attachcnt++; 163*0Sstevel@tonic-gate cmn_p->pci_common_refcnt++; 164*0Sstevel@tonic-gate done: 165*0Sstevel@tonic-gate mutex_exit(&pci_global_mutex); 166*0Sstevel@tonic-gate if (ret != DDI_SUCCESS) 167*0Sstevel@tonic-gate cmn_err(CE_WARN, "pci_obj_setup failed %x", ret); 168*0Sstevel@tonic-gate return (ret); 169*0Sstevel@tonic-gate } 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate /* called by pci_detach() DDI_DETACH to destroy pci objects */ 172*0Sstevel@tonic-gate void 173*0Sstevel@tonic-gate pci_obj_destroy(pci_t *pci_p) 174*0Sstevel@tonic-gate { 175*0Sstevel@tonic-gate pci_common_t *cmn_p; 176*0Sstevel@tonic-gate mutex_enter(&pci_global_mutex); 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate cmn_p = pci_p->pci_common_p; 179*0Sstevel@tonic-gate cmn_p->pci_common_refcnt--; 180*0Sstevel@tonic-gate cmn_p->pci_common_attachcnt--; 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate pci_kstat_destroy(pci_p); 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate /* schizo non-shared objects */ 185*0Sstevel@tonic-gate pci_fm_destroy(pci_p); 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate sc_destroy(pci_p); 188*0Sstevel@tonic-gate pbm_destroy(pci_p); 189*0Sstevel@tonic-gate iommu_destroy(pci_p); 190*0Sstevel@tonic-gate ib_destroy(pci_p); 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gate if (cmn_p->pci_common_refcnt != 0) { 193*0Sstevel@tonic-gate pci_intr_teardown(pci_p); 194*0Sstevel@tonic-gate cmn_p->pci_p[pci_p->pci_side] = NULL; 195*0Sstevel@tonic-gate mutex_exit(&pci_global_mutex); 196*0Sstevel@tonic-gate return; 197*0Sstevel@tonic-gate } 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate /* schizo shared objects - uses cmn_p, must be destroyed before cmn */ 200*0Sstevel@tonic-gate ecc_destroy(pci_p); 201*0Sstevel@tonic-gate cb_destroy(pci_p); 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gate free_pci_common_soft_state(cmn_p->pci_common_id); 204*0Sstevel@tonic-gate pci_intr_teardown(pci_p); 205*0Sstevel@tonic-gate mutex_exit(&pci_global_mutex); 206*0Sstevel@tonic-gate } 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate /* called by pci_attach() DDI_RESUME to (re)initialize pci objects */ 209*0Sstevel@tonic-gate void 210*0Sstevel@tonic-gate pci_obj_resume(pci_t *pci_p) 211*0Sstevel@tonic-gate { 212*0Sstevel@tonic-gate pci_common_t *cmn_p = pci_p->pci_common_p; 213*0Sstevel@tonic-gate 214*0Sstevel@tonic-gate mutex_enter(&pci_global_mutex); 215*0Sstevel@tonic-gate 216*0Sstevel@tonic-gate ib_configure(pci_p->pci_ib_p); 217*0Sstevel@tonic-gate iommu_configure(pci_p->pci_iommu_p); 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate if (cmn_p->pci_common_attachcnt == 0) 220*0Sstevel@tonic-gate ecc_configure(pci_p); 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate ib_resume(pci_p->pci_ib_p); 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate pbm_configure(pci_p->pci_pbm_p); 225*0Sstevel@tonic-gate sc_configure(pci_p->pci_sc_p); 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate if (cmn_p->pci_common_attachcnt == 0) 228*0Sstevel@tonic-gate cb_resume(pci_p->pci_cb_p); 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate pbm_resume(pci_p->pci_pbm_p); 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate cmn_p->pci_common_attachcnt++; 233*0Sstevel@tonic-gate mutex_exit(&pci_global_mutex); 234*0Sstevel@tonic-gate } 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate /* called by pci_detach() DDI_SUSPEND to suspend pci objects */ 237*0Sstevel@tonic-gate void 238*0Sstevel@tonic-gate pci_obj_suspend(pci_t *pci_p) 239*0Sstevel@tonic-gate { 240*0Sstevel@tonic-gate mutex_enter(&pci_global_mutex); 241*0Sstevel@tonic-gate 242*0Sstevel@tonic-gate pbm_suspend(pci_p->pci_pbm_p); 243*0Sstevel@tonic-gate ib_suspend(pci_p->pci_ib_p); 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate if (!--pci_p->pci_common_p->pci_common_attachcnt) 246*0Sstevel@tonic-gate cb_suspend(pci_p->pci_cb_p); 247*0Sstevel@tonic-gate 248*0Sstevel@tonic-gate mutex_exit(&pci_global_mutex); 249*0Sstevel@tonic-gate } 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate /* 252*0Sstevel@tonic-gate * add an additional 0x35 or 0x36 ino interrupt on platforms don't have them 253*0Sstevel@tonic-gate * This routine has multiple places that assumes interrupt takes one cell 254*0Sstevel@tonic-gate * each and cell size is same as integer size. 255*0Sstevel@tonic-gate */ 256*0Sstevel@tonic-gate static int 257*0Sstevel@tonic-gate pci_intr_setup(pci_t *pci_p) 258*0Sstevel@tonic-gate { 259*0Sstevel@tonic-gate dev_info_t *dip = pci_p->pci_dip; 260*0Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p; 261*0Sstevel@tonic-gate cb_t *cb_p = pci_p->pci_cb_p; 262*0Sstevel@tonic-gate uint32_t *intr_buf, *new_intr_buf; 263*0Sstevel@tonic-gate int intr_len, intr_cnt, ret; 264*0Sstevel@tonic-gate 265*0Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS, 266*0Sstevel@tonic-gate "interrupts", (caddr_t)&intr_buf, &intr_len) != DDI_SUCCESS) 267*0Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: no interrupts property\n", 268*0Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 269*0Sstevel@tonic-gate 270*0Sstevel@tonic-gate intr_cnt = BYTES_TO_1275_CELLS(intr_len); 271*0Sstevel@tonic-gate if (intr_cnt < CBNINTR_CDMA) /* CBNINTR_CDMA is 0 based */ 272*0Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: <%d interrupts", ddi_driver_name(dip), 273*0Sstevel@tonic-gate ddi_get_instance(dip), CBNINTR_CDMA); 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate if (intr_cnt == CBNINTR_CDMA) 276*0Sstevel@tonic-gate intr_cnt++; 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate new_intr_buf = kmem_alloc(CELLS_1275_TO_BYTES(intr_cnt), KM_SLEEP); 279*0Sstevel@tonic-gate bcopy(intr_buf, new_intr_buf, intr_len); 280*0Sstevel@tonic-gate kmem_free(intr_buf, intr_len); 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gate new_intr_buf[CBNINTR_CDMA] = PBM_CDMA_INO_BASE + pci_p->pci_side; 283*0Sstevel@tonic-gate pci_p->pci_inos = new_intr_buf; 284*0Sstevel@tonic-gate pci_p->pci_inos_len = CELLS_1275_TO_BYTES(intr_cnt); 285*0Sstevel@tonic-gate 286*0Sstevel@tonic-gate if (ndi_prop_update_int_array(DDI_DEV_T_NONE, dip, "interrupts", 287*0Sstevel@tonic-gate (int *)new_intr_buf, intr_cnt)) 288*0Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: cannot update interrupts property\n", 289*0Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 290*0Sstevel@tonic-gate 291*0Sstevel@tonic-gate if (pci_p->pci_common_p->pci_common_refcnt == 0) { 292*0Sstevel@tonic-gate cb_p->cb_no_of_inos = intr_cnt; 293*0Sstevel@tonic-gate if (ret = cb_register_intr(pci_p)) 294*0Sstevel@tonic-gate goto teardown; 295*0Sstevel@tonic-gate if (ret = ecc_register_intr(pci_p)) 296*0Sstevel@tonic-gate goto teardown; 297*0Sstevel@tonic-gate 298*0Sstevel@tonic-gate intr_dist_add(cb_intr_dist, cb_p); 299*0Sstevel@tonic-gate cb_enable_intr(pci_p); 300*0Sstevel@tonic-gate ecc_enable_intr(pci_p); 301*0Sstevel@tonic-gate } 302*0Sstevel@tonic-gate 303*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) != PCI_CHIP_SCHIZO) 304*0Sstevel@tonic-gate pbm_p->pbm_sync_ino = pci_p->pci_inos[CBNINTR_PBM]; 305*0Sstevel@tonic-gate if (ret = pbm_register_intr(pbm_p)) { 306*0Sstevel@tonic-gate if (pci_p->pci_common_p->pci_common_refcnt == 0) 307*0Sstevel@tonic-gate intr_dist_rem(cb_intr_dist, cb_p); 308*0Sstevel@tonic-gate goto teardown; 309*0Sstevel@tonic-gate } 310*0Sstevel@tonic-gate intr_dist_add(pbm_intr_dist, pbm_p); 311*0Sstevel@tonic-gate ib_intr_enable(pci_p, pci_p->pci_inos[CBNINTR_PBM]); 312*0Sstevel@tonic-gate ib_intr_enable(pci_p, pci_p->pci_inos[CBNINTR_CDMA]); 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gate intr_dist_add_weighted(ib_intr_dist_all, pci_p->pci_ib_p); 315*0Sstevel@tonic-gate return (DDI_SUCCESS); 316*0Sstevel@tonic-gate teardown: 317*0Sstevel@tonic-gate pci_intr_teardown(pci_p); 318*0Sstevel@tonic-gate return (ret); 319*0Sstevel@tonic-gate } 320*0Sstevel@tonic-gate 321*0Sstevel@tonic-gate uint64_t 322*0Sstevel@tonic-gate pci_sc_configure(pci_t *pci_p) 323*0Sstevel@tonic-gate { 324*0Sstevel@tonic-gate int instance; 325*0Sstevel@tonic-gate dev_info_t *dip = pci_p->pci_dip; 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gate instance = ddi_get_instance(dip); 328*0Sstevel@tonic-gate if ((pci_xmits_sc_max_prf & (1 << instance)) && 329*0Sstevel@tonic-gate (CHIP_TYPE(pci_p) == PCI_CHIP_XMITS)) 330*0Sstevel@tonic-gate return (XMITS_SC_MAX_PRF); 331*0Sstevel@tonic-gate else 332*0Sstevel@tonic-gate return (0); 333*0Sstevel@tonic-gate } 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gate static void 336*0Sstevel@tonic-gate pci_schizo_cdma_sync(pbm_t *pbm_p) 337*0Sstevel@tonic-gate { 338*0Sstevel@tonic-gate pci_t *pci_p = pbm_p->pbm_pci_p; 339*0Sstevel@tonic-gate hrtime_t start_time; 340*0Sstevel@tonic-gate volatile uint64_t *clr_p = ib_clear_intr_reg_addr(pci_p->pci_ib_p, 341*0Sstevel@tonic-gate pci_p->pci_inos[CBNINTR_CDMA]); 342*0Sstevel@tonic-gate uint32_t fail_cnt = pci_cdma_intr_count; 343*0Sstevel@tonic-gate 344*0Sstevel@tonic-gate mutex_enter(&pbm_p->pbm_sync_mutex); 345*0Sstevel@tonic-gate #ifdef PBM_CDMA_DEBUG 346*0Sstevel@tonic-gate pbm_p->pbm_cdma_req_cnt++; 347*0Sstevel@tonic-gate #endif /* PBM_CDMA_DEBUG */ 348*0Sstevel@tonic-gate pbm_p->pbm_cdma_flag = PBM_CDMA_PEND; 349*0Sstevel@tonic-gate IB_INO_INTR_TRIG(clr_p); 350*0Sstevel@tonic-gate wait: 351*0Sstevel@tonic-gate start_time = gethrtime(); 352*0Sstevel@tonic-gate while (pbm_p->pbm_cdma_flag != PBM_CDMA_DONE) { 353*0Sstevel@tonic-gate if (gethrtime() - start_time <= pci_cdma_intr_timeout) 354*0Sstevel@tonic-gate continue; 355*0Sstevel@tonic-gate if (--fail_cnt > 0) 356*0Sstevel@tonic-gate goto wait; 357*0Sstevel@tonic-gate if (pbm_p->pbm_cdma_flag == PBM_CDMA_DONE) 358*0Sstevel@tonic-gate break; 359*0Sstevel@tonic-gate cmn_err(CE_PANIC, "%s (%s): consistent dma sync timeout", 360*0Sstevel@tonic-gate pbm_p->pbm_nameinst_str, pbm_p->pbm_nameaddr_str); 361*0Sstevel@tonic-gate } 362*0Sstevel@tonic-gate #ifdef PBM_CDMA_DEBUG 363*0Sstevel@tonic-gate if (pbm_p->pbm_cdma_flag != PBM_CDMA_DONE) 364*0Sstevel@tonic-gate pbm_p->pbm_cdma_to_cnt++; 365*0Sstevel@tonic-gate else { 366*0Sstevel@tonic-gate start_time = gethrtime() - start_time; 367*0Sstevel@tonic-gate pbm_p->pbm_cdma_success_cnt++; 368*0Sstevel@tonic-gate pbm_p->pbm_cdma_latency_sum += start_time; 369*0Sstevel@tonic-gate if (start_time > pbm_p->pbm_cdma_latency_max) 370*0Sstevel@tonic-gate pbm_p->pbm_cdma_latency_max = start_time; 371*0Sstevel@tonic-gate } 372*0Sstevel@tonic-gate #endif /* PBM_CDMA_DEBUG */ 373*0Sstevel@tonic-gate mutex_exit(&pbm_p->pbm_sync_mutex); 374*0Sstevel@tonic-gate } 375*0Sstevel@tonic-gate 376*0Sstevel@tonic-gate #if !defined(lint) 377*0Sstevel@tonic-gate #include <sys/cpuvar.h> 378*0Sstevel@tonic-gate #endif 379*0Sstevel@tonic-gate 380*0Sstevel@tonic-gate #define SYNC_HW_BUSY(pa, mask) (lddphysio(pa) & (mask)) 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gate /* 383*0Sstevel@tonic-gate * Consistent DMA Sync/Flush 384*0Sstevel@tonic-gate * 385*0Sstevel@tonic-gate * XMITS and Tomatillo use multi-threaded sync/flush register. 386*0Sstevel@tonic-gate * Called from interrupt wrapper: the associated ino is used to index 387*0Sstevel@tonic-gate * the distinctive register bit. 388*0Sstevel@tonic-gate * Called from pci_dma_sync(): the bit belongs to PBM is shared 389*0Sstevel@tonic-gate * for all calls from pci_dma_sync(). Xmits requires serialization 390*0Sstevel@tonic-gate * while Tomatillo does not. 391*0Sstevel@tonic-gate */ 392*0Sstevel@tonic-gate void 393*0Sstevel@tonic-gate pci_pbm_dma_sync(pbm_t *pbm_p, ib_ino_t ino) 394*0Sstevel@tonic-gate { 395*0Sstevel@tonic-gate pci_t *pci_p = pbm_p->pbm_pci_p; 396*0Sstevel@tonic-gate hrtime_t start_time; 397*0Sstevel@tonic-gate uint64_t ino_mask, sync_reg_pa; 398*0Sstevel@tonic-gate volatile uint64_t flag_val; 399*0Sstevel@tonic-gate uint32_t locked, chip_type = CHIP_TYPE(pci_p); 400*0Sstevel@tonic-gate int i; 401*0Sstevel@tonic-gate 402*0Sstevel@tonic-gate if (chip_type == PCI_CHIP_SCHIZO) { 403*0Sstevel@tonic-gate pci_schizo_cdma_sync(pbm_p); 404*0Sstevel@tonic-gate return; 405*0Sstevel@tonic-gate } 406*0Sstevel@tonic-gate 407*0Sstevel@tonic-gate sync_reg_pa = pbm_p->pbm_sync_reg_pa; 408*0Sstevel@tonic-gate 409*0Sstevel@tonic-gate locked = 0; 410*0Sstevel@tonic-gate if (((chip_type == PCI_CHIP_XMITS) && (ino == pbm_p->pbm_sync_ino)) || 411*0Sstevel@tonic-gate pci_sync_lock) { 412*0Sstevel@tonic-gate locked = 1; 413*0Sstevel@tonic-gate mutex_enter(&pbm_p->pbm_sync_mutex); 414*0Sstevel@tonic-gate } 415*0Sstevel@tonic-gate ino_mask = 1ull << ino; 416*0Sstevel@tonic-gate stdphysio(sync_reg_pa, ino_mask); 417*0Sstevel@tonic-gate 418*0Sstevel@tonic-gate for (i = 0; i < 5; i++) { 419*0Sstevel@tonic-gate if ((flag_val = SYNC_HW_BUSY(sync_reg_pa, ino_mask)) == 0) 420*0Sstevel@tonic-gate goto done; 421*0Sstevel@tonic-gate } 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate start_time = gethrtime(); 424*0Sstevel@tonic-gate for (; (flag_val = SYNC_HW_BUSY(sync_reg_pa, ino_mask)) != 0; i++) { 425*0Sstevel@tonic-gate if (gethrtime() - start_time > pci_sync_buf_timeout) 426*0Sstevel@tonic-gate break; 427*0Sstevel@tonic-gate } 428*0Sstevel@tonic-gate 429*0Sstevel@tonic-gate if (flag_val && SYNC_HW_BUSY(sync_reg_pa, ino_mask) && !panicstr) 430*0Sstevel@tonic-gate cmn_err(CE_PANIC, "%s: pbm dma sync %llx,%llx timeout!", 431*0Sstevel@tonic-gate pbm_p->pbm_nameaddr_str, sync_reg_pa, flag_val); 432*0Sstevel@tonic-gate done: 433*0Sstevel@tonic-gate /* optional: stdphysio(sync_reg_pa - 8, ino_mask); */ 434*0Sstevel@tonic-gate if (locked) 435*0Sstevel@tonic-gate mutex_exit(&pbm_p->pbm_sync_mutex); 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gate if (tomatillo_store_store_wrka) { 438*0Sstevel@tonic-gate #if !defined(lint) 439*0Sstevel@tonic-gate kpreempt_disable(); 440*0Sstevel@tonic-gate #endif 441*0Sstevel@tonic-gate tomatillo_store_store_order(); 442*0Sstevel@tonic-gate #if !defined(lint) 443*0Sstevel@tonic-gate kpreempt_enable(); 444*0Sstevel@tonic-gate #endif 445*0Sstevel@tonic-gate } 446*0Sstevel@tonic-gate 447*0Sstevel@tonic-gate } 448*0Sstevel@tonic-gate 449*0Sstevel@tonic-gate /*ARGSUSED*/ 450*0Sstevel@tonic-gate void 451*0Sstevel@tonic-gate pci_fix_ranges(pci_ranges_t *rng_p, int rng_entries) 452*0Sstevel@tonic-gate { 453*0Sstevel@tonic-gate } 454*0Sstevel@tonic-gate 455*0Sstevel@tonic-gate /* 456*0Sstevel@tonic-gate * map_pci_registers 457*0Sstevel@tonic-gate * 458*0Sstevel@tonic-gate * This function is called from the attach routine to map the registers 459*0Sstevel@tonic-gate * accessed by this driver. 460*0Sstevel@tonic-gate * 461*0Sstevel@tonic-gate * used by: pci_attach() 462*0Sstevel@tonic-gate * 463*0Sstevel@tonic-gate * return value: DDI_FAILURE on failure 464*0Sstevel@tonic-gate */ 465*0Sstevel@tonic-gate int 466*0Sstevel@tonic-gate map_pci_registers(pci_t *pci_p, dev_info_t *dip) 467*0Sstevel@tonic-gate { 468*0Sstevel@tonic-gate ddi_device_acc_attr_t attr; 469*0Sstevel@tonic-gate int len; 470*0Sstevel@tonic-gate 471*0Sstevel@tonic-gate attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 472*0Sstevel@tonic-gate attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 473*0Sstevel@tonic-gate 474*0Sstevel@tonic-gate attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC; 475*0Sstevel@tonic-gate /* 476*0Sstevel@tonic-gate * Register set 0 is PCI CSR Base 477*0Sstevel@tonic-gate */ 478*0Sstevel@tonic-gate if (ddi_regs_map_setup(dip, 0, &pci_p->pci_address[0], 0, 0, 479*0Sstevel@tonic-gate &attr, &pci_p->pci_ac[0]) != DDI_SUCCESS) { 480*0Sstevel@tonic-gate len = 0; 481*0Sstevel@tonic-gate goto fail; 482*0Sstevel@tonic-gate } 483*0Sstevel@tonic-gate /* 484*0Sstevel@tonic-gate * Register set 1 is Schizo CSR Base 485*0Sstevel@tonic-gate */ 486*0Sstevel@tonic-gate if (ddi_regs_map_setup(dip, 1, &pci_p->pci_address[1], 0, 0, 487*0Sstevel@tonic-gate &attr, &pci_p->pci_ac[1]) != DDI_SUCCESS) { 488*0Sstevel@tonic-gate len = 1; 489*0Sstevel@tonic-gate goto fail; 490*0Sstevel@tonic-gate } 491*0Sstevel@tonic-gate 492*0Sstevel@tonic-gate /* 493*0Sstevel@tonic-gate * The third register set contains the bridge's configuration 494*0Sstevel@tonic-gate * header. This header is at the very beginning of the bridge's 495*0Sstevel@tonic-gate * configuration space. This space has litte-endian byte order. 496*0Sstevel@tonic-gate */ 497*0Sstevel@tonic-gate attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC; 498*0Sstevel@tonic-gate if (ddi_regs_map_setup(dip, 2, &pci_p->pci_address[2], 0, 499*0Sstevel@tonic-gate PCI_CONF_HDR_SIZE, &attr, &pci_p->pci_ac[2]) != DDI_SUCCESS) { 500*0Sstevel@tonic-gate len = 2; 501*0Sstevel@tonic-gate goto fail; 502*0Sstevel@tonic-gate } 503*0Sstevel@tonic-gate 504*0Sstevel@tonic-gate if (ddi_getproplen(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS, 505*0Sstevel@tonic-gate "reg", &len) || (len / sizeof (pci_nexus_regspec_t) < 4)) 506*0Sstevel@tonic-gate goto done; 507*0Sstevel@tonic-gate 508*0Sstevel@tonic-gate /* 509*0Sstevel@tonic-gate * The optional fourth register bank points to the 510*0Sstevel@tonic-gate * interrupt concentrator registers. 511*0Sstevel@tonic-gate */ 512*0Sstevel@tonic-gate attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC; 513*0Sstevel@tonic-gate if (ddi_regs_map_setup(dip, 3, &pci_p->pci_address[3], 0, 514*0Sstevel@tonic-gate 0, &attr, &pci_p->pci_ac[3]) != DDI_SUCCESS) { 515*0Sstevel@tonic-gate len = 3; 516*0Sstevel@tonic-gate goto fail; 517*0Sstevel@tonic-gate } 518*0Sstevel@tonic-gate 519*0Sstevel@tonic-gate done: 520*0Sstevel@tonic-gate DEBUG4(DBG_ATTACH, dip, "address (%p,%p,%p,%p)\n", 521*0Sstevel@tonic-gate pci_p->pci_address[0], pci_p->pci_address[1], 522*0Sstevel@tonic-gate pci_p->pci_address[2], pci_p->pci_address[3]); 523*0Sstevel@tonic-gate 524*0Sstevel@tonic-gate return (DDI_SUCCESS); 525*0Sstevel@tonic-gate 526*0Sstevel@tonic-gate 527*0Sstevel@tonic-gate fail: 528*0Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: unable to map reg entry %d\n", 529*0Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), len); 530*0Sstevel@tonic-gate for (; len--; ddi_regs_map_free(&pci_p->pci_ac[len])); 531*0Sstevel@tonic-gate return (DDI_FAILURE); 532*0Sstevel@tonic-gate } 533*0Sstevel@tonic-gate 534*0Sstevel@tonic-gate /* 535*0Sstevel@tonic-gate * unmap_pci_registers: 536*0Sstevel@tonic-gate * 537*0Sstevel@tonic-gate * This routine unmap the registers mapped by map_pci_registers. 538*0Sstevel@tonic-gate * 539*0Sstevel@tonic-gate * used by: pci_detach() 540*0Sstevel@tonic-gate * 541*0Sstevel@tonic-gate * return value: none 542*0Sstevel@tonic-gate */ 543*0Sstevel@tonic-gate void 544*0Sstevel@tonic-gate unmap_pci_registers(pci_t *pci_p) 545*0Sstevel@tonic-gate { 546*0Sstevel@tonic-gate int i; 547*0Sstevel@tonic-gate 548*0Sstevel@tonic-gate for (i = 0; i < 4; i++) { 549*0Sstevel@tonic-gate if (pci_p->pci_ac[i]) 550*0Sstevel@tonic-gate ddi_regs_map_free(&pci_p->pci_ac[i]); 551*0Sstevel@tonic-gate } 552*0Sstevel@tonic-gate } 553*0Sstevel@tonic-gate 554*0Sstevel@tonic-gate uint64_t 555*0Sstevel@tonic-gate ib_get_map_reg(ib_mondo_t mondo, uint32_t cpu_id) 556*0Sstevel@tonic-gate { 557*0Sstevel@tonic-gate uint32_t agent_id; 558*0Sstevel@tonic-gate uint32_t node_id; 559*0Sstevel@tonic-gate 560*0Sstevel@tonic-gate /* ensure that cpu_id is only 10 bits. */ 561*0Sstevel@tonic-gate ASSERT((cpu_id & ~0x3ff) == 0); 562*0Sstevel@tonic-gate 563*0Sstevel@tonic-gate agent_id = cpu_id & 0x1f; 564*0Sstevel@tonic-gate node_id = (cpu_id >> 5) & 0x1f; 565*0Sstevel@tonic-gate 566*0Sstevel@tonic-gate return ((mondo) | (agent_id << COMMON_INTR_MAP_REG_TID_SHIFT) | 567*0Sstevel@tonic-gate (node_id << SCHIZO_INTR_MAP_REG_NID_SHIFT) | 568*0Sstevel@tonic-gate COMMON_INTR_MAP_REG_VALID); 569*0Sstevel@tonic-gate } 570*0Sstevel@tonic-gate 571*0Sstevel@tonic-gate uint32_t 572*0Sstevel@tonic-gate ib_map_reg_get_cpu(volatile uint64_t reg) 573*0Sstevel@tonic-gate { 574*0Sstevel@tonic-gate return (((reg & COMMON_INTR_MAP_REG_TID) >> 575*0Sstevel@tonic-gate COMMON_INTR_MAP_REG_TID_SHIFT) | 576*0Sstevel@tonic-gate ((reg & SCHIZO_INTR_MAP_REG_NID) >> 577*0Sstevel@tonic-gate (SCHIZO_INTR_MAP_REG_NID_SHIFT-5))); 578*0Sstevel@tonic-gate } 579*0Sstevel@tonic-gate 580*0Sstevel@tonic-gate uint64_t * 581*0Sstevel@tonic-gate ib_intr_map_reg_addr(ib_t *ib_p, ib_ino_t ino) 582*0Sstevel@tonic-gate { 583*0Sstevel@tonic-gate /* 584*0Sstevel@tonic-gate * Schizo maps all interrupts in one contiguous area. 585*0Sstevel@tonic-gate * (PCI_CSRBase + 0x00.1000 + INO * 8). 586*0Sstevel@tonic-gate */ 587*0Sstevel@tonic-gate return ((uint64_t *)(ib_p->ib_intr_map_regs) + (ino & 0x3f)); 588*0Sstevel@tonic-gate } 589*0Sstevel@tonic-gate 590*0Sstevel@tonic-gate uint64_t * 591*0Sstevel@tonic-gate ib_clear_intr_reg_addr(ib_t *ib_p, ib_ino_t ino) /* XXX - needs work */ 592*0Sstevel@tonic-gate { 593*0Sstevel@tonic-gate /* 594*0Sstevel@tonic-gate * Schizo maps clear intr. registers in contiguous area. 595*0Sstevel@tonic-gate * (PCI_CSRBase + 0x00.1400 + INO * 8). 596*0Sstevel@tonic-gate */ 597*0Sstevel@tonic-gate return ((uint64_t *)(ib_p->ib_slot_clear_intr_regs) + (ino & 0x3f)); 598*0Sstevel@tonic-gate } 599*0Sstevel@tonic-gate 600*0Sstevel@tonic-gate /* 601*0Sstevel@tonic-gate * schizo does not have mapping register per slot, so no sharing 602*0Sstevel@tonic-gate * is done. 603*0Sstevel@tonic-gate */ 604*0Sstevel@tonic-gate /*ARGSUSED*/ 605*0Sstevel@tonic-gate void 606*0Sstevel@tonic-gate ib_ino_map_reg_share(ib_t *ib_p, ib_ino_t ino, ib_ino_info_t *ino_p) 607*0Sstevel@tonic-gate { 608*0Sstevel@tonic-gate } 609*0Sstevel@tonic-gate 610*0Sstevel@tonic-gate /* 611*0Sstevel@tonic-gate * return true if there are interrupts using this mapping register 612*0Sstevel@tonic-gate */ 613*0Sstevel@tonic-gate /*ARGSUSED*/ 614*0Sstevel@tonic-gate int 615*0Sstevel@tonic-gate ib_ino_map_reg_unshare(ib_t *ib_p, ib_ino_t ino, ib_ino_info_t *ino_p) 616*0Sstevel@tonic-gate { 617*0Sstevel@tonic-gate return (ino_p->ino_ih_size); 618*0Sstevel@tonic-gate } 619*0Sstevel@tonic-gate 620*0Sstevel@tonic-gate void 621*0Sstevel@tonic-gate pci_pbm_intr_dist(pbm_t *pbm_p) 622*0Sstevel@tonic-gate { 623*0Sstevel@tonic-gate pci_t *pci_p = pbm_p->pbm_pci_p; 624*0Sstevel@tonic-gate ib_t *ib_p = pci_p->pci_ib_p; 625*0Sstevel@tonic-gate ib_ino_t ino = IB_MONDO_TO_INO(pci_p->pci_inos[CBNINTR_CDMA]); 626*0Sstevel@tonic-gate 627*0Sstevel@tonic-gate mutex_enter(&pbm_p->pbm_sync_mutex); 628*0Sstevel@tonic-gate ib_intr_dist_nintr(ib_p, ino, ib_intr_map_reg_addr(ib_p, ino)); 629*0Sstevel@tonic-gate mutex_exit(&pbm_p->pbm_sync_mutex); 630*0Sstevel@tonic-gate } 631*0Sstevel@tonic-gate 632*0Sstevel@tonic-gate uint32_t 633*0Sstevel@tonic-gate pci_xlate_intr(dev_info_t *dip, dev_info_t *rdip, ib_t *ib_p, uint32_t intr) 634*0Sstevel@tonic-gate { 635*0Sstevel@tonic-gate return (IB_INO_TO_MONDO(ib_p, intr)); 636*0Sstevel@tonic-gate } 637*0Sstevel@tonic-gate 638*0Sstevel@tonic-gate 639*0Sstevel@tonic-gate /* 640*0Sstevel@tonic-gate * Return the cpuid to to be used for an ino. We have no special cpu 641*0Sstevel@tonic-gate * assignment constraints for this nexus, so just call intr_dist_cpuid(). 642*0Sstevel@tonic-gate */ 643*0Sstevel@tonic-gate /* ARGSUSED */ 644*0Sstevel@tonic-gate uint32_t 645*0Sstevel@tonic-gate pci_intr_dist_cpuid(ib_t *ib_p, ib_ino_info_t *ino_p) 646*0Sstevel@tonic-gate { 647*0Sstevel@tonic-gate return (intr_dist_cpuid()); 648*0Sstevel@tonic-gate } 649*0Sstevel@tonic-gate 650*0Sstevel@tonic-gate void 651*0Sstevel@tonic-gate pci_cb_teardown(pci_t *pci_p) 652*0Sstevel@tonic-gate { 653*0Sstevel@tonic-gate cb_t *cb_p = pci_p->pci_cb_p; 654*0Sstevel@tonic-gate uint32_t mondo; 655*0Sstevel@tonic-gate 656*0Sstevel@tonic-gate if (!pci_buserr_interrupt) 657*0Sstevel@tonic-gate return; 658*0Sstevel@tonic-gate 659*0Sstevel@tonic-gate mondo = ((pci_p->pci_cb_p->cb_ign << PCI_INO_BITS) | 660*0Sstevel@tonic-gate pci_p->pci_inos[CBNINTR_BUS_ERROR]); 661*0Sstevel@tonic-gate mondo = CB_MONDO_TO_XMONDO(pci_p->pci_cb_p, mondo); 662*0Sstevel@tonic-gate 663*0Sstevel@tonic-gate cb_disable_nintr(cb_p, CBNINTR_BUS_ERROR, IB_INTR_WAIT); 664*0Sstevel@tonic-gate rem_ivintr(mondo, NULL); 665*0Sstevel@tonic-gate } 666*0Sstevel@tonic-gate 667*0Sstevel@tonic-gate int 668*0Sstevel@tonic-gate cb_register_intr(pci_t *pci_p) 669*0Sstevel@tonic-gate { 670*0Sstevel@tonic-gate uint32_t mondo; 671*0Sstevel@tonic-gate 672*0Sstevel@tonic-gate if (!pci_buserr_interrupt) 673*0Sstevel@tonic-gate return (DDI_SUCCESS); 674*0Sstevel@tonic-gate 675*0Sstevel@tonic-gate mondo = ((pci_p->pci_cb_p->cb_ign << PCI_INO_BITS) | 676*0Sstevel@tonic-gate pci_p->pci_inos[CBNINTR_BUS_ERROR]); 677*0Sstevel@tonic-gate mondo = CB_MONDO_TO_XMONDO(pci_p->pci_cb_p, mondo); 678*0Sstevel@tonic-gate 679*0Sstevel@tonic-gate VERIFY(add_ivintr(mondo, pci_pil[CBNINTR_BUS_ERROR], 680*0Sstevel@tonic-gate cb_buserr_intr, (caddr_t)pci_p->pci_cb_p, NULL) == 0); 681*0Sstevel@tonic-gate 682*0Sstevel@tonic-gate return (PCI_ATTACH_RETCODE(PCI_CB_OBJ, PCI_OBJ_INTR_ADD, DDI_SUCCESS)); 683*0Sstevel@tonic-gate } 684*0Sstevel@tonic-gate 685*0Sstevel@tonic-gate void 686*0Sstevel@tonic-gate cb_enable_intr(pci_t *pci_p) 687*0Sstevel@tonic-gate { 688*0Sstevel@tonic-gate if (pci_buserr_interrupt) 689*0Sstevel@tonic-gate cb_enable_nintr(pci_p, CBNINTR_BUS_ERROR); 690*0Sstevel@tonic-gate } 691*0Sstevel@tonic-gate 692*0Sstevel@tonic-gate uint64_t 693*0Sstevel@tonic-gate cb_ino_to_map_pa(cb_t *cb_p, ib_ino_t ino) 694*0Sstevel@tonic-gate { 695*0Sstevel@tonic-gate return (cb_p->cb_map_pa + (ino << 3)); 696*0Sstevel@tonic-gate } 697*0Sstevel@tonic-gate 698*0Sstevel@tonic-gate uint64_t 699*0Sstevel@tonic-gate cb_ino_to_clr_pa(cb_t *cb_p, ib_ino_t ino) 700*0Sstevel@tonic-gate { 701*0Sstevel@tonic-gate return (cb_p->cb_clr_pa + (ino << 3)); 702*0Sstevel@tonic-gate } 703*0Sstevel@tonic-gate 704*0Sstevel@tonic-gate /* 705*0Sstevel@tonic-gate * Useful on psycho only. 706*0Sstevel@tonic-gate */ 707*0Sstevel@tonic-gate int 708*0Sstevel@tonic-gate cb_remove_xintr(pci_t *pci_p, dev_info_t *dip, dev_info_t *rdip, ib_ino_t ino, 709*0Sstevel@tonic-gate ib_mondo_t mondo) 710*0Sstevel@tonic-gate { 711*0Sstevel@tonic-gate return (DDI_FAILURE); 712*0Sstevel@tonic-gate } 713*0Sstevel@tonic-gate 714*0Sstevel@tonic-gate void 715*0Sstevel@tonic-gate pbm_configure(pbm_t *pbm_p) 716*0Sstevel@tonic-gate { 717*0Sstevel@tonic-gate pci_t *pci_p = pbm_p->pbm_pci_p; 718*0Sstevel@tonic-gate dev_info_t *dip = pbm_p->pbm_pci_p->pci_dip; 719*0Sstevel@tonic-gate int instance = ddi_get_instance(dip); 720*0Sstevel@tonic-gate uint64_t l; 721*0Sstevel@tonic-gate uint64_t mask = 1ll << instance; 722*0Sstevel@tonic-gate ushort_t s = 0; 723*0Sstevel@tonic-gate 724*0Sstevel@tonic-gate l = *pbm_p->pbm_ctrl_reg; /* save control register state */ 725*0Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, "pbm_configure: ctrl reg=%llx\n", l); 726*0Sstevel@tonic-gate 727*0Sstevel@tonic-gate /* 728*0Sstevel@tonic-gate * See if any SERR# signals are asserted. We'll clear them later. 729*0Sstevel@tonic-gate */ 730*0Sstevel@tonic-gate if (l & COMMON_PCI_CTRL_SERR) 731*0Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: SERR asserted on pci bus\n", 732*0Sstevel@tonic-gate ddi_driver_name(dip), instance); 733*0Sstevel@tonic-gate 734*0Sstevel@tonic-gate /* 735*0Sstevel@tonic-gate * Determine if PCI bus is running at 33 or 66 mhz. 736*0Sstevel@tonic-gate */ 737*0Sstevel@tonic-gate if (l & COMMON_PCI_CTRL_SPEED) 738*0Sstevel@tonic-gate pbm_p->pbm_speed = PBM_SPEED_66MHZ; 739*0Sstevel@tonic-gate else 740*0Sstevel@tonic-gate pbm_p->pbm_speed = PBM_SPEED_33MHZ; 741*0Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, "pbm_configure: %d mhz\n", 742*0Sstevel@tonic-gate pbm_p->pbm_speed == PBM_SPEED_66MHZ ? 66 : 33); 743*0Sstevel@tonic-gate 744*0Sstevel@tonic-gate if (pci_set_dto_value & mask) { 745*0Sstevel@tonic-gate l &= ~(3ull << SCHIZO_PCI_CTRL_PTO_SHIFT); 746*0Sstevel@tonic-gate l |= pci_dto_value << SCHIZO_PCI_CTRL_PTO_SHIFT; 747*0Sstevel@tonic-gate } else if (PCI_CHIP_ID(pci_p) >= TOMATILLO_VER_21) { 748*0Sstevel@tonic-gate l |= (3ull << SCHIZO_PCI_CTRL_PTO_SHIFT); 749*0Sstevel@tonic-gate } 750*0Sstevel@tonic-gate 751*0Sstevel@tonic-gate /* 752*0Sstevel@tonic-gate * Enable error interrupts. 753*0Sstevel@tonic-gate */ 754*0Sstevel@tonic-gate if (pci_error_intr_enable & mask) 755*0Sstevel@tonic-gate l |= SCHIZO_PCI_CTRL_ERR_INT_EN; 756*0Sstevel@tonic-gate else 757*0Sstevel@tonic-gate l &= ~SCHIZO_PCI_CTRL_ERR_INT_EN; 758*0Sstevel@tonic-gate 759*0Sstevel@tonic-gate /* 760*0Sstevel@tonic-gate * Enable pci streaming byte errors and error interrupts. 761*0Sstevel@tonic-gate */ 762*0Sstevel@tonic-gate if (pci_sbh_error_intr_enable & mask) 763*0Sstevel@tonic-gate l |= SCHIZO_PCI_CTRL_SBH_INT_EN; 764*0Sstevel@tonic-gate else 765*0Sstevel@tonic-gate l &= ~SCHIZO_PCI_CTRL_SBH_INT_EN; 766*0Sstevel@tonic-gate 767*0Sstevel@tonic-gate /* 768*0Sstevel@tonic-gate * Enable pci discard timeout error interrupt. 769*0Sstevel@tonic-gate */ 770*0Sstevel@tonic-gate if (pci_mmu_error_intr_enable & mask) 771*0Sstevel@tonic-gate l |= SCHIZO_PCI_CTRL_MMU_INT_EN; 772*0Sstevel@tonic-gate else 773*0Sstevel@tonic-gate l &= ~SCHIZO_PCI_CTRL_MMU_INT_EN; 774*0Sstevel@tonic-gate 775*0Sstevel@tonic-gate /* 776*0Sstevel@tonic-gate * Enable PCI-X error interrupts. 777*0Sstevel@tonic-gate */ 778*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) == PCI_CHIP_XMITS) { 779*0Sstevel@tonic-gate 780*0Sstevel@tonic-gate if (xmits_error_intr_enable & mask) 781*0Sstevel@tonic-gate l |= XMITS_PCI_CTRL_X_ERRINT_EN; 782*0Sstevel@tonic-gate else 783*0Sstevel@tonic-gate l &= ~XMITS_PCI_CTRL_X_ERRINT_EN; 784*0Sstevel@tonic-gate /* 785*0Sstevel@tonic-gate * Panic if older XMITS hardware is found. 786*0Sstevel@tonic-gate */ 787*0Sstevel@tonic-gate if (*pbm_p->pbm_ctrl_reg & XMITS_PCI_CTRL_X_MODE) 788*0Sstevel@tonic-gate if (PCI_CHIP_ID(pci_p) <= XMITS_VER_10) 789*0Sstevel@tonic-gate cmn_err(CE_PANIC, "%s (%s): PCIX mode " 790*0Sstevel@tonic-gate "unsupported on XMITS version %d\n", 791*0Sstevel@tonic-gate pbm_p->pbm_nameinst_str, 792*0Sstevel@tonic-gate pbm_p->pbm_nameaddr_str, CHIP_VER(pci_p)); 793*0Sstevel@tonic-gate 794*0Sstevel@tonic-gate if (xmits_perr_recov_int_enable) { 795*0Sstevel@tonic-gate if (PCI_CHIP_ID(pci_p) >= XMITS_VER_30) { 796*0Sstevel@tonic-gate uint64_t pcix_err; 797*0Sstevel@tonic-gate /* 798*0Sstevel@tonic-gate * Enable interrupt on PERR 799*0Sstevel@tonic-gate */ 800*0Sstevel@tonic-gate pcix_err = *pbm_p->pbm_pcix_err_stat_reg; 801*0Sstevel@tonic-gate pcix_err |= XMITS_PCIX_STAT_PERR_RECOV_INT_EN; 802*0Sstevel@tonic-gate pcix_err &= ~XMITS_PCIX_STAT_SERR_ON_PERR; 803*0Sstevel@tonic-gate *pbm_p->pbm_pcix_err_stat_reg = pcix_err; 804*0Sstevel@tonic-gate } 805*0Sstevel@tonic-gate } 806*0Sstevel@tonic-gate 807*0Sstevel@tonic-gate /* 808*0Sstevel@tonic-gate * Enable parity error detection on internal memories 809*0Sstevel@tonic-gate */ 810*0Sstevel@tonic-gate *pbm_p->pbm_pci_ped_ctrl = 0x3fff; 811*0Sstevel@tonic-gate } 812*0Sstevel@tonic-gate 813*0Sstevel@tonic-gate /* 814*0Sstevel@tonic-gate * Enable/disable bus parking. 815*0Sstevel@tonic-gate */ 816*0Sstevel@tonic-gate if ((pci_bus_parking_enable & mask) && 817*0Sstevel@tonic-gate !ddi_prop_exists(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 818*0Sstevel@tonic-gate "no-bus-parking")) 819*0Sstevel@tonic-gate l |= SCHIZO_PCI_CTRL_ARB_PARK; 820*0Sstevel@tonic-gate else 821*0Sstevel@tonic-gate l &= ~SCHIZO_PCI_CTRL_ARB_PARK; 822*0Sstevel@tonic-gate 823*0Sstevel@tonic-gate /* 824*0Sstevel@tonic-gate * Enable arbitration. 825*0Sstevel@tonic-gate */ 826*0Sstevel@tonic-gate l |= PCI_CHIP_ID(pci_p) == XMITS_VER_10 ? XMITS10_PCI_CTRL_ARB_EN_MASK : 827*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_ARB_EN_MASK; 828*0Sstevel@tonic-gate 829*0Sstevel@tonic-gate /* 830*0Sstevel@tonic-gate * Make sure SERR is clear 831*0Sstevel@tonic-gate */ 832*0Sstevel@tonic-gate l |= COMMON_PCI_CTRL_SERR; 833*0Sstevel@tonic-gate 834*0Sstevel@tonic-gate 835*0Sstevel@tonic-gate /* 836*0Sstevel@tonic-gate * Enable DTO interrupt, if desired. 837*0Sstevel@tonic-gate */ 838*0Sstevel@tonic-gate 839*0Sstevel@tonic-gate if (PCI_CHIP_ID(pci_p) <= TOMATILLO_VER_20 || (pci_dto_intr_enable & 840*0Sstevel@tonic-gate mask)) 841*0Sstevel@tonic-gate l |= (TOMATILLO_PCI_CTRL_DTO_INT_EN); 842*0Sstevel@tonic-gate else 843*0Sstevel@tonic-gate l &= ~(TOMATILLO_PCI_CTRL_DTO_INT_EN); 844*0Sstevel@tonic-gate 845*0Sstevel@tonic-gate l |= TOMATILLO_PCI_CTRL_PEN_RD_MLTPL | 846*0Sstevel@tonic-gate TOMATILLO_PCI_CTRL_PEN_RD_ONE | 847*0Sstevel@tonic-gate TOMATILLO_PCI_CTRL_PEN_RD_LINE; 848*0Sstevel@tonic-gate 849*0Sstevel@tonic-gate /* 850*0Sstevel@tonic-gate * Now finally write the control register with the appropriate value. 851*0Sstevel@tonic-gate */ 852*0Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, "pbm_configure: ctrl reg=%llx\n", l); 853*0Sstevel@tonic-gate *pbm_p->pbm_ctrl_reg = l; 854*0Sstevel@tonic-gate 855*0Sstevel@tonic-gate /* 856*0Sstevel@tonic-gate * Enable IO Prefetch on Tomatillo 857*0Sstevel@tonic-gate */ 858*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) == PCI_CHIP_TOMATILLO) { 859*0Sstevel@tonic-gate volatile uint64_t *ioc_csr_p = pbm_p->pbm_ctrl_reg + 860*0Sstevel@tonic-gate ((TOMATILLO_IOC_CSR_OFF - 861*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_REG_OFFSET) >> 3); 862*0Sstevel@tonic-gate *ioc_csr_p = TOMATILLO_WRT_PEN | 863*0Sstevel@tonic-gate (1 << TOMATILLO_POFFSET_SHIFT) | 864*0Sstevel@tonic-gate TOMATILLO_C_PEN_RD_MLTPL | 865*0Sstevel@tonic-gate TOMATILLO_C_PEN_RD_ONE | 866*0Sstevel@tonic-gate TOMATILLO_C_PEN_RD_LINE; 867*0Sstevel@tonic-gate } 868*0Sstevel@tonic-gate 869*0Sstevel@tonic-gate /* 870*0Sstevel@tonic-gate * Allow DMA write parity errors to generate an interrupt. 871*0Sstevel@tonic-gate * This is implemented on Schizo 2.5 and greater and XMITS 3.0 872*0Sstevel@tonic-gate * and greater. Setting this on earlier versions of XMITS 3.0 873*0Sstevel@tonic-gate * has no affect. 874*0Sstevel@tonic-gate */ 875*0Sstevel@tonic-gate if (((CHIP_TYPE(pci_p) == PCI_CHIP_SCHIZO) && 876*0Sstevel@tonic-gate PCI_CHIP_ID(pci_p) >= SCHIZO_VER_25) || 877*0Sstevel@tonic-gate (CHIP_TYPE(pci_p) == PCI_CHIP_XMITS)) { 878*0Sstevel@tonic-gate volatile uint64_t *pbm_icd = pbm_p->pbm_ctrl_reg + 879*0Sstevel@tonic-gate ((SCHIZO_PERF_PCI_ICD_OFFSET - 880*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_REG_OFFSET) >> 3); 881*0Sstevel@tonic-gate 882*0Sstevel@tonic-gate *pbm_icd |= SCHIZO_PERF_PCI_ICD_DMAW_PARITY_INT_ENABLE; 883*0Sstevel@tonic-gate } 884*0Sstevel@tonic-gate 885*0Sstevel@tonic-gate /* 886*0Sstevel@tonic-gate * Clear any PBM errors. 887*0Sstevel@tonic-gate */ 888*0Sstevel@tonic-gate l = (SCHIZO_PCI_AFSR_E_MASK << SCHIZO_PCI_AFSR_PE_SHIFT) | 889*0Sstevel@tonic-gate (SCHIZO_PCI_AFSR_E_MASK << SCHIZO_PCI_AFSR_SE_SHIFT); 890*0Sstevel@tonic-gate *pbm_p->pbm_async_flt_status_reg = l; 891*0Sstevel@tonic-gate 892*0Sstevel@tonic-gate /* 893*0Sstevel@tonic-gate * Allow the diag register to be set based upon variable that 894*0Sstevel@tonic-gate * can be configured via /etc/system. 895*0Sstevel@tonic-gate */ 896*0Sstevel@tonic-gate l = *pbm_p->pbm_diag_reg; 897*0Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, "pbm_configure: PCI diag reg=%llx\n", l); 898*0Sstevel@tonic-gate 899*0Sstevel@tonic-gate /* 900*0Sstevel@tonic-gate * Enable/disable retry limit. 901*0Sstevel@tonic-gate */ 902*0Sstevel@tonic-gate if (pci_retry_disable & mask) 903*0Sstevel@tonic-gate l |= COMMON_PCI_DIAG_DIS_RETRY; 904*0Sstevel@tonic-gate else 905*0Sstevel@tonic-gate l &= ~COMMON_PCI_DIAG_DIS_RETRY; 906*0Sstevel@tonic-gate 907*0Sstevel@tonic-gate /* 908*0Sstevel@tonic-gate * Enable/disable DMA write/interrupt synchronization. 909*0Sstevel@tonic-gate */ 910*0Sstevel@tonic-gate if (pci_intsync_disable & mask) 911*0Sstevel@tonic-gate l |= COMMON_PCI_DIAG_DIS_INTSYNC; 912*0Sstevel@tonic-gate else 913*0Sstevel@tonic-gate l &= ~COMMON_PCI_DIAG_DIS_INTSYNC; 914*0Sstevel@tonic-gate 915*0Sstevel@tonic-gate /* 916*0Sstevel@tonic-gate * Enable/disable retry arbitration priority. 917*0Sstevel@tonic-gate */ 918*0Sstevel@tonic-gate if (pci_enable_retry_arb & mask) 919*0Sstevel@tonic-gate l &= ~SCHIZO_PCI_DIAG_DIS_RTRY_ARB; 920*0Sstevel@tonic-gate else 921*0Sstevel@tonic-gate l |= SCHIZO_PCI_DIAG_DIS_RTRY_ARB; 922*0Sstevel@tonic-gate 923*0Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, "pbm_configure: PCI diag reg=%llx\n", l); 924*0Sstevel@tonic-gate *pbm_p->pbm_diag_reg = l; 925*0Sstevel@tonic-gate 926*0Sstevel@tonic-gate /* 927*0Sstevel@tonic-gate * Enable SERR# and parity reporting via command register. 928*0Sstevel@tonic-gate */ 929*0Sstevel@tonic-gate s = pci_perr_enable & mask ? PCI_COMM_PARITY_DETECT : 0; 930*0Sstevel@tonic-gate s |= pci_serr_enable & mask ? PCI_COMM_SERR_ENABLE : 0; 931*0Sstevel@tonic-gate 932*0Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, "pbm_configure: conf command reg=%x\n", s); 933*0Sstevel@tonic-gate pbm_p->pbm_config_header->ch_command_reg = s; 934*0Sstevel@tonic-gate 935*0Sstevel@tonic-gate /* 936*0Sstevel@tonic-gate * Clear error bits in configuration status register. 937*0Sstevel@tonic-gate */ 938*0Sstevel@tonic-gate s = PCI_STAT_PERROR | PCI_STAT_S_PERROR | 939*0Sstevel@tonic-gate PCI_STAT_R_MAST_AB | PCI_STAT_R_TARG_AB | 940*0Sstevel@tonic-gate PCI_STAT_S_TARG_AB | PCI_STAT_S_PERROR; 941*0Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, "pbm_configure: conf status reg=%x\n", s); 942*0Sstevel@tonic-gate pbm_p->pbm_config_header->ch_status_reg = s; 943*0Sstevel@tonic-gate 944*0Sstevel@tonic-gate /* 945*0Sstevel@tonic-gate * The current versions of the obp are suppose to set the latency 946*0Sstevel@tonic-gate * timer register but do not. Bug 1234181 is open against this 947*0Sstevel@tonic-gate * problem. Until this bug is fixed we check to see if the obp 948*0Sstevel@tonic-gate * has attempted to set the latency timer register by checking 949*0Sstevel@tonic-gate * for the existence of a "latency-timer" property. 950*0Sstevel@tonic-gate */ 951*0Sstevel@tonic-gate if (pci_set_latency_timer_register) { 952*0Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, 953*0Sstevel@tonic-gate "pbm_configure: set schizo latency timer to %x\n", 954*0Sstevel@tonic-gate pci_latency_timer); 955*0Sstevel@tonic-gate pbm_p->pbm_config_header->ch_latency_timer_reg = 956*0Sstevel@tonic-gate pci_latency_timer; 957*0Sstevel@tonic-gate } 958*0Sstevel@tonic-gate 959*0Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_ANY, dip, "latency-timer", 960*0Sstevel@tonic-gate (int)pbm_p->pbm_config_header->ch_latency_timer_reg); 961*0Sstevel@tonic-gate } 962*0Sstevel@tonic-gate 963*0Sstevel@tonic-gate uint_t 964*0Sstevel@tonic-gate pbm_disable_pci_errors(pbm_t *pbm_p) 965*0Sstevel@tonic-gate { 966*0Sstevel@tonic-gate pci_t *pci_p = pbm_p->pbm_pci_p; 967*0Sstevel@tonic-gate ib_t *ib_p = pci_p->pci_ib_p; 968*0Sstevel@tonic-gate 969*0Sstevel@tonic-gate /* 970*0Sstevel@tonic-gate * Disable error and streaming byte hole interrupts via the 971*0Sstevel@tonic-gate * PBM control register. 972*0Sstevel@tonic-gate */ 973*0Sstevel@tonic-gate *pbm_p->pbm_ctrl_reg &= 974*0Sstevel@tonic-gate ~(SCHIZO_PCI_CTRL_ERR_INT_EN | SCHIZO_PCI_CTRL_SBH_INT_EN | 975*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_MMU_INT_EN); 976*0Sstevel@tonic-gate 977*0Sstevel@tonic-gate /* 978*0Sstevel@tonic-gate * Disable error interrupts via the interrupt mapping register. 979*0Sstevel@tonic-gate */ 980*0Sstevel@tonic-gate ib_intr_disable(ib_p, pci_p->pci_inos[CBNINTR_PBM], IB_INTR_NOWAIT); 981*0Sstevel@tonic-gate return (BF_NONE); 982*0Sstevel@tonic-gate } 983*0Sstevel@tonic-gate 984*0Sstevel@tonic-gate /* 985*0Sstevel@tonic-gate * Layout of the dvma context bucket bitmap entry: 986*0Sstevel@tonic-gate * 987*0Sstevel@tonic-gate * 63 - 56 55 - 0 988*0Sstevel@tonic-gate * 8-bit lock 56-bit, each represent one context 989*0Sstevel@tonic-gate * DCB_LOCK_BITS DCB_BMAP_BITS 990*0Sstevel@tonic-gate */ 991*0Sstevel@tonic-gate #define DCB_LOCK_BITS 8 992*0Sstevel@tonic-gate #define DCB_BMAP_BITS (64 - DCB_LOCK_BITS) 993*0Sstevel@tonic-gate 994*0Sstevel@tonic-gate dvma_context_t 995*0Sstevel@tonic-gate pci_iommu_get_dvma_context(iommu_t *iommu_p, dvma_addr_t dvma_pg_index) 996*0Sstevel@tonic-gate { 997*0Sstevel@tonic-gate dvma_context_t ctx; 998*0Sstevel@tonic-gate int i = (dvma_pg_index >> 6) & 0x1f; /* 5 bit index within bucket */ 999*0Sstevel@tonic-gate uint64_t ctx_mask, test = 1ull << i; 1000*0Sstevel@tonic-gate uint32_t bucket_no = dvma_pg_index & 0x3f; 1001*0Sstevel@tonic-gate uint64_t *bucket_ptr = iommu_p->iommu_ctx_bitmap + bucket_no; 1002*0Sstevel@tonic-gate 1003*0Sstevel@tonic-gate uint32_t spl = ddi_enter_critical(); /* block interrupts */ 1004*0Sstevel@tonic-gate if (ldstub((uint8_t *)bucket_ptr)) { /* try lock */ 1005*0Sstevel@tonic-gate ddi_exit_critical(spl); /* unblock interrupt */ 1006*0Sstevel@tonic-gate pci_iommu_ctx_lock_failure++; 1007*0Sstevel@tonic-gate return (0); 1008*0Sstevel@tonic-gate } 1009*0Sstevel@tonic-gate 1010*0Sstevel@tonic-gate /* clear lock bits */ 1011*0Sstevel@tonic-gate ctx_mask = (*bucket_ptr << DCB_LOCK_BITS) >> DCB_LOCK_BITS; 1012*0Sstevel@tonic-gate ASSERT(*bucket_ptr >> DCB_BMAP_BITS == 0xff); 1013*0Sstevel@tonic-gate ASSERT(ctx_mask >> DCB_BMAP_BITS == 0); 1014*0Sstevel@tonic-gate 1015*0Sstevel@tonic-gate if (ctx_mask & test) /* quick check i bit */ 1016*0Sstevel@tonic-gate for (i = 0, test = 1ull; test & ctx_mask; test <<= 1, i++); 1017*0Sstevel@tonic-gate if (i < DCB_BMAP_BITS) 1018*0Sstevel@tonic-gate ctx_mask |= test; 1019*0Sstevel@tonic-gate *bucket_ptr = ctx_mask; /* unlock */ 1020*0Sstevel@tonic-gate ddi_exit_critical(spl); /* unblock interrupts */ 1021*0Sstevel@tonic-gate 1022*0Sstevel@tonic-gate ctx = i < DCB_BMAP_BITS ? (bucket_no << 6) | i : 0; 1023*0Sstevel@tonic-gate DEBUG3(DBG_DMA_MAP, iommu_p->iommu_pci_p->pci_dip, 1024*0Sstevel@tonic-gate "get_dvma_context: ctx_mask=0x%x.%x ctx=0x%x\n", 1025*0Sstevel@tonic-gate (uint32_t)(ctx_mask >> 32), (uint32_t)ctx_mask, ctx); 1026*0Sstevel@tonic-gate return (ctx); 1027*0Sstevel@tonic-gate } 1028*0Sstevel@tonic-gate 1029*0Sstevel@tonic-gate void 1030*0Sstevel@tonic-gate pci_iommu_free_dvma_context(iommu_t *iommu_p, dvma_context_t ctx) 1031*0Sstevel@tonic-gate { 1032*0Sstevel@tonic-gate uint64_t ctx_mask; 1033*0Sstevel@tonic-gate uint32_t spl, bucket_no = ctx >> 6; 1034*0Sstevel@tonic-gate int bit_no = ctx & 0x3f; 1035*0Sstevel@tonic-gate uint64_t *bucket_ptr = iommu_p->iommu_ctx_bitmap + bucket_no; 1036*0Sstevel@tonic-gate 1037*0Sstevel@tonic-gate DEBUG1(DBG_DMA_MAP, iommu_p->iommu_pci_p->pci_dip, 1038*0Sstevel@tonic-gate "free_dvma_context: ctx=0x%x\n", ctx); 1039*0Sstevel@tonic-gate 1040*0Sstevel@tonic-gate spl = ddi_enter_critical(); /* block interrupts */ 1041*0Sstevel@tonic-gate while (ldstub((uint8_t *)bucket_ptr)); /* spin lock */ 1042*0Sstevel@tonic-gate ctx_mask = (*bucket_ptr << DCB_LOCK_BITS) >> DCB_LOCK_BITS; 1043*0Sstevel@tonic-gate /* clear lock bits */ 1044*0Sstevel@tonic-gate ASSERT(ctx_mask & (1ull << bit_no)); 1045*0Sstevel@tonic-gate *bucket_ptr = ctx_mask ^ (1ull << bit_no); /* clear & unlock */ 1046*0Sstevel@tonic-gate ddi_exit_critical(spl); /* unblock interrupt */ 1047*0Sstevel@tonic-gate } 1048*0Sstevel@tonic-gate 1049*0Sstevel@tonic-gate int 1050*0Sstevel@tonic-gate pci_sc_ctx_inv(dev_info_t *dip, sc_t *sc_p, ddi_dma_impl_t *mp) 1051*0Sstevel@tonic-gate { 1052*0Sstevel@tonic-gate dvma_context_t ctx = MP2CTX(mp); 1053*0Sstevel@tonic-gate volatile uint64_t *reg_addr = sc_p->sc_ctx_match_reg + ctx; 1054*0Sstevel@tonic-gate uint64_t matchreg; 1055*0Sstevel@tonic-gate 1056*0Sstevel@tonic-gate if (!*reg_addr) { 1057*0Sstevel@tonic-gate DEBUG1(DBG_SC, dip, "ctx=%x no match\n", ctx); 1058*0Sstevel@tonic-gate return (DDI_SUCCESS); 1059*0Sstevel@tonic-gate } 1060*0Sstevel@tonic-gate 1061*0Sstevel@tonic-gate *sc_p->sc_ctx_invl_reg = ctx; /* 1st flush write */ 1062*0Sstevel@tonic-gate matchreg = *reg_addr; /* re-fetch after 1st flush */ 1063*0Sstevel@tonic-gate if (!matchreg) 1064*0Sstevel@tonic-gate return (DDI_SUCCESS); 1065*0Sstevel@tonic-gate 1066*0Sstevel@tonic-gate matchreg = (matchreg << SC_ENT_SHIFT) >> SC_ENT_SHIFT; /* low 16-bit */ 1067*0Sstevel@tonic-gate do { 1068*0Sstevel@tonic-gate if (matchreg & 1) 1069*0Sstevel@tonic-gate *sc_p->sc_ctx_invl_reg = ctx; 1070*0Sstevel@tonic-gate matchreg >>= 1; 1071*0Sstevel@tonic-gate } while (matchreg); 1072*0Sstevel@tonic-gate 1073*0Sstevel@tonic-gate if (pci_ctx_no_compat || !*reg_addr) /* compat: active ctx flush */ 1074*0Sstevel@tonic-gate return (DDI_SUCCESS); 1075*0Sstevel@tonic-gate 1076*0Sstevel@tonic-gate pci_ctx_unsuccess_count++; 1077*0Sstevel@tonic-gate if (pci_ctx_flush_warn) 1078*0Sstevel@tonic-gate cmn_err(pci_ctx_flush_warn, "%s%d: ctx flush unsuccessful\n", 1079*0Sstevel@tonic-gate NAMEINST(dip)); 1080*0Sstevel@tonic-gate return (DDI_FAILURE); 1081*0Sstevel@tonic-gate } 1082*0Sstevel@tonic-gate 1083*0Sstevel@tonic-gate void 1084*0Sstevel@tonic-gate pci_cb_setup(pci_t *pci_p) 1085*0Sstevel@tonic-gate { 1086*0Sstevel@tonic-gate dev_info_t *dip = pci_p->pci_dip; 1087*0Sstevel@tonic-gate cb_t *cb_p = pci_p->pci_cb_p; 1088*0Sstevel@tonic-gate uint64_t pa; 1089*0Sstevel@tonic-gate uint32_t chip_id = PCI_CHIP_ID(pci_p); 1090*0Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, "cb_create: chip id %d\n", chip_id); 1091*0Sstevel@tonic-gate 1092*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) == PCI_CHIP_TOMATILLO) { 1093*0Sstevel@tonic-gate if ((!tm_mtlb_gc_manual) && 1094*0Sstevel@tonic-gate (PCI_CHIP_ID(pci_p) <= TOMATILLO_VER_24)) 1095*0Sstevel@tonic-gate tm_mtlb_gc = 1; 1096*0Sstevel@tonic-gate 1097*0Sstevel@tonic-gate if (PCI_CHIP_ID(pci_p) <= TOMATILLO_VER_23) { 1098*0Sstevel@tonic-gate extern int ignore_invalid_vecintr; 1099*0Sstevel@tonic-gate ignore_invalid_vecintr = 1; 1100*0Sstevel@tonic-gate tomatillo_store_store_wrka = 1; 1101*0Sstevel@tonic-gate tomatillo_disallow_bypass = 1; 1102*0Sstevel@tonic-gate if (pci_spurintr_msgs == PCI_SPURINTR_MSG_DEFAULT) 1103*0Sstevel@tonic-gate pci_spurintr_msgs = 0; 1104*0Sstevel@tonic-gate } 1105*0Sstevel@tonic-gate } 1106*0Sstevel@tonic-gate 1107*0Sstevel@tonic-gate if (chip_id == TOMATILLO_VER_20 || chip_id == TOMATILLO_VER_21) 1108*0Sstevel@tonic-gate cmn_err(CE_WARN, "Unsupported Tomatillo rev (%x)", chip_id); 1109*0Sstevel@tonic-gate 1110*0Sstevel@tonic-gate if (chip_id < SCHIZO_VER_23) 1111*0Sstevel@tonic-gate pci_ctx_no_active_flush = 1; 1112*0Sstevel@tonic-gate 1113*0Sstevel@tonic-gate cb_p->cb_node_id = PCI_ID_TO_NODEID(pci_p->pci_id); 1114*0Sstevel@tonic-gate cb_p->cb_ign = PCI_ID_TO_IGN(pci_p->pci_id); 1115*0Sstevel@tonic-gate 1116*0Sstevel@tonic-gate /* 1117*0Sstevel@tonic-gate * schizo control status reg bank is on the 2nd "reg" property entry 1118*0Sstevel@tonic-gate * interrupt mapping/clear/state regs are on the 1st "reg" entry. 1119*0Sstevel@tonic-gate * 1120*0Sstevel@tonic-gate * ALL internal interrupts except pbm interrupts are shared by both 1121*0Sstevel@tonic-gate * sides, 1st-side-attached is used as *the* owner. 1122*0Sstevel@tonic-gate */ 1123*0Sstevel@tonic-gate pa = (uint64_t)hat_getpfnum(kas.a_hat, pci_p->pci_address[1]); 1124*0Sstevel@tonic-gate cb_p->cb_base_pa = pa << MMU_PAGESHIFT; 1125*0Sstevel@tonic-gate 1126*0Sstevel@tonic-gate pa = pci_p->pci_address[3] ? 1127*0Sstevel@tonic-gate (uint64_t)hat_getpfnum(kas.a_hat, pci_p->pci_address[3]) : 0; 1128*0Sstevel@tonic-gate cb_p->cb_icbase_pa = (pa == PFN_INVALID) ? 0 : pa << MMU_PAGESHIFT; 1129*0Sstevel@tonic-gate 1130*0Sstevel@tonic-gate pa = (uint64_t)hat_getpfnum(kas.a_hat, pci_p->pci_address[0]) 1131*0Sstevel@tonic-gate << MMU_PAGESHIFT; 1132*0Sstevel@tonic-gate cb_p->cb_map_pa = pa + SCHIZO_IB_INTR_MAP_REG_OFFSET; 1133*0Sstevel@tonic-gate cb_p->cb_clr_pa = pa + SCHIZO_IB_CLEAR_INTR_REG_OFFSET; 1134*0Sstevel@tonic-gate cb_p->cb_obsta_pa = pa + COMMON_IB_OBIO_INTR_STATE_DIAG_REG; 1135*0Sstevel@tonic-gate } 1136*0Sstevel@tonic-gate 1137*0Sstevel@tonic-gate void 1138*0Sstevel@tonic-gate pci_ecc_setup(ecc_t *ecc_p) 1139*0Sstevel@tonic-gate { 1140*0Sstevel@tonic-gate ecc_p->ecc_ue.ecc_errpndg_mask = SCHIZO_ECC_UE_AFSR_ERRPNDG; 1141*0Sstevel@tonic-gate ecc_p->ecc_ue.ecc_offset_mask = SCHIZO_ECC_UE_AFSR_QW_OFFSET; 1142*0Sstevel@tonic-gate ecc_p->ecc_ue.ecc_offset_shift = SCHIZO_ECC_UE_AFSR_QW_OFFSET_SHIFT; 1143*0Sstevel@tonic-gate ecc_p->ecc_ue.ecc_size_log2 = 4; 1144*0Sstevel@tonic-gate 1145*0Sstevel@tonic-gate ecc_p->ecc_ce.ecc_errpndg_mask = SCHIZO_ECC_CE_AFSR_ERRPNDG; 1146*0Sstevel@tonic-gate ecc_p->ecc_ce.ecc_offset_mask = SCHIZO_ECC_CE_AFSR_QW_OFFSET; 1147*0Sstevel@tonic-gate ecc_p->ecc_ce.ecc_offset_shift = SCHIZO_ECC_CE_AFSR_QW_OFFSET_SHIFT; 1148*0Sstevel@tonic-gate ecc_p->ecc_ce.ecc_size_log2 = 4; 1149*0Sstevel@tonic-gate } 1150*0Sstevel@tonic-gate 1151*0Sstevel@tonic-gate ushort_t 1152*0Sstevel@tonic-gate pci_ecc_get_synd(uint64_t afsr) 1153*0Sstevel@tonic-gate { 1154*0Sstevel@tonic-gate return ((ushort_t)((afsr & SCHIZO_ECC_CE_AFSR_SYND) >> 1155*0Sstevel@tonic-gate SCHIZO_ECC_CE_AFSR_SYND_SHIFT)); 1156*0Sstevel@tonic-gate } 1157*0Sstevel@tonic-gate 1158*0Sstevel@tonic-gate /* 1159*0Sstevel@tonic-gate * overwrite dvma end address (only on virtual-dma systems) 1160*0Sstevel@tonic-gate * initialize tsb size 1161*0Sstevel@tonic-gate * reset context bits 1162*0Sstevel@tonic-gate * return: IOMMU CSR bank base address (VA) 1163*0Sstevel@tonic-gate */ 1164*0Sstevel@tonic-gate 1165*0Sstevel@tonic-gate uintptr_t 1166*0Sstevel@tonic-gate pci_iommu_setup(iommu_t *iommu_p) 1167*0Sstevel@tonic-gate { 1168*0Sstevel@tonic-gate pci_dvma_range_prop_t *dvma_prop; 1169*0Sstevel@tonic-gate int dvma_prop_len; 1170*0Sstevel@tonic-gate 1171*0Sstevel@tonic-gate uintptr_t a; 1172*0Sstevel@tonic-gate pci_t *pci_p = iommu_p->iommu_pci_p; 1173*0Sstevel@tonic-gate dev_info_t *dip = pci_p->pci_dip; 1174*0Sstevel@tonic-gate uint_t tsb_size = iommu_tsb_cookie_to_size(pci_p->pci_tsb_cookie); 1175*0Sstevel@tonic-gate 1176*0Sstevel@tonic-gate /* 1177*0Sstevel@tonic-gate * Initializations for Tomatillo's micro TLB bug. errata #82 1178*0Sstevel@tonic-gate */ 1179*0Sstevel@tonic-gate if (tm_mtlb_gc) { 1180*0Sstevel@tonic-gate iommu_p->iommu_mtlb_nreq = 0; 1181*0Sstevel@tonic-gate iommu_p->iommu_mtlb_npgs = 0; 1182*0Sstevel@tonic-gate iommu_p->iommu_mtlb_maxpgs = tm_mtlb_maxpgs; 1183*0Sstevel@tonic-gate iommu_p->iommu_mtlb_req_p = (dvma_unbind_req_t *) 1184*0Sstevel@tonic-gate kmem_zalloc(sizeof (dvma_unbind_req_t) * 1185*0Sstevel@tonic-gate (tm_mtlb_maxpgs + 1), KM_SLEEP); 1186*0Sstevel@tonic-gate mutex_init(&iommu_p->iommu_mtlb_lock, NULL, MUTEX_DRIVER, NULL); 1187*0Sstevel@tonic-gate } 1188*0Sstevel@tonic-gate 1189*0Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 1190*0Sstevel@tonic-gate "virtual-dma", (caddr_t)&dvma_prop, &dvma_prop_len) != 1191*0Sstevel@tonic-gate DDI_PROP_SUCCESS) 1192*0Sstevel@tonic-gate goto tsb_done; 1193*0Sstevel@tonic-gate 1194*0Sstevel@tonic-gate if (dvma_prop_len != sizeof (pci_dvma_range_prop_t)) { 1195*0Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: invalid virtual-dma property", 1196*0Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 1197*0Sstevel@tonic-gate goto tsb_end; 1198*0Sstevel@tonic-gate } 1199*0Sstevel@tonic-gate iommu_p->iommu_dvma_end = dvma_prop->dvma_base + 1200*0Sstevel@tonic-gate (dvma_prop->dvma_len - 1); 1201*0Sstevel@tonic-gate tsb_end: 1202*0Sstevel@tonic-gate kmem_free(dvma_prop, dvma_prop_len); 1203*0Sstevel@tonic-gate tsb_done: 1204*0Sstevel@tonic-gate iommu_p->iommu_tsb_size = iommu_tsb_size_encode(tsb_size); 1205*0Sstevel@tonic-gate iommu_p->iommu_ctx_bitmap = 1206*0Sstevel@tonic-gate kmem_zalloc(IOMMU_CTX_BITMAP_SIZE, KM_SLEEP); 1207*0Sstevel@tonic-gate *iommu_p->iommu_ctx_bitmap = 1ull; /* reserve context 0 */ 1208*0Sstevel@tonic-gate 1209*0Sstevel@tonic-gate /* 1210*0Sstevel@tonic-gate * Determine the virtual address of the register block 1211*0Sstevel@tonic-gate * containing the iommu control registers and determine 1212*0Sstevel@tonic-gate * the virtual address of schizo specific iommu registers. 1213*0Sstevel@tonic-gate */ 1214*0Sstevel@tonic-gate a = (uintptr_t)pci_p->pci_address[0]; 1215*0Sstevel@tonic-gate iommu_p->iommu_flush_ctx_reg = 1216*0Sstevel@tonic-gate (uint64_t *)(a + SCHIZO_IOMMU_FLUSH_CTX_REG_OFFSET); 1217*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) == PCI_CHIP_TOMATILLO) 1218*0Sstevel@tonic-gate iommu_p->iommu_tfar_reg = 1219*0Sstevel@tonic-gate (uint64_t *)(a + TOMATILLO_IOMMU_ERR_TFAR_OFFSET); 1220*0Sstevel@tonic-gate return (a); /* PCICSRBase */ 1221*0Sstevel@tonic-gate } 1222*0Sstevel@tonic-gate 1223*0Sstevel@tonic-gate void 1224*0Sstevel@tonic-gate pci_iommu_teardown(iommu_t *iommu_p) 1225*0Sstevel@tonic-gate { 1226*0Sstevel@tonic-gate if (pci_use_contexts) 1227*0Sstevel@tonic-gate iommu_ctx_free(iommu_p); 1228*0Sstevel@tonic-gate if (iommu_p->iommu_mtlb_req_p) { 1229*0Sstevel@tonic-gate kmem_free(iommu_p->iommu_mtlb_req_p, 1230*0Sstevel@tonic-gate sizeof (dvma_unbind_req_t) * (tm_mtlb_maxpgs + 1)); 1231*0Sstevel@tonic-gate mutex_destroy(&iommu_p->iommu_mtlb_lock); 1232*0Sstevel@tonic-gate iommu_p->iommu_mtlb_req_p = NULL; 1233*0Sstevel@tonic-gate iommu_p->iommu_mtlb_nreq = 0; 1234*0Sstevel@tonic-gate iommu_p->iommu_mtlb_npgs = iommu_p->iommu_mtlb_maxpgs = 0; 1235*0Sstevel@tonic-gate } 1236*0Sstevel@tonic-gate } 1237*0Sstevel@tonic-gate 1238*0Sstevel@tonic-gate uintptr_t 1239*0Sstevel@tonic-gate get_pbm_reg_base(pci_t *pci_p) 1240*0Sstevel@tonic-gate { 1241*0Sstevel@tonic-gate return ((uintptr_t) 1242*0Sstevel@tonic-gate (pci_p->pci_address[0] + SCHIZO_PCI_CTRL_REG_OFFSET)); 1243*0Sstevel@tonic-gate } 1244*0Sstevel@tonic-gate 1245*0Sstevel@tonic-gate /* ARGSUSED */ 1246*0Sstevel@tonic-gate static boolean_t 1247*0Sstevel@tonic-gate pci_pbm_panic_callb(void *arg, int code) 1248*0Sstevel@tonic-gate { 1249*0Sstevel@tonic-gate pbm_t *pbm_p = (pbm_t *)arg; 1250*0Sstevel@tonic-gate volatile uint64_t *ctrl_reg_p; 1251*0Sstevel@tonic-gate 1252*0Sstevel@tonic-gate if (pbm_p->pbm_quiesce_count > 0) { 1253*0Sstevel@tonic-gate ctrl_reg_p = pbm_p->pbm_ctrl_reg; 1254*0Sstevel@tonic-gate *ctrl_reg_p = pbm_p->pbm_saved_ctrl_reg; 1255*0Sstevel@tonic-gate } 1256*0Sstevel@tonic-gate 1257*0Sstevel@tonic-gate return (B_TRUE); 1258*0Sstevel@tonic-gate } 1259*0Sstevel@tonic-gate 1260*0Sstevel@tonic-gate static boolean_t 1261*0Sstevel@tonic-gate pci_pbm_debug_callb(void *arg, int code) 1262*0Sstevel@tonic-gate { 1263*0Sstevel@tonic-gate pbm_t *pbm_p = (pbm_t *)arg; 1264*0Sstevel@tonic-gate volatile uint64_t *ctrl_reg_p; 1265*0Sstevel@tonic-gate uint64_t ctrl_reg; 1266*0Sstevel@tonic-gate 1267*0Sstevel@tonic-gate if (pbm_p->pbm_quiesce_count > 0) { 1268*0Sstevel@tonic-gate ctrl_reg_p = pbm_p->pbm_ctrl_reg; 1269*0Sstevel@tonic-gate if (code == 0) { 1270*0Sstevel@tonic-gate *ctrl_reg_p = pbm_p->pbm_saved_ctrl_reg; 1271*0Sstevel@tonic-gate } else { 1272*0Sstevel@tonic-gate ctrl_reg = pbm_p->pbm_saved_ctrl_reg; 1273*0Sstevel@tonic-gate ctrl_reg &= ~(SCHIZO_PCI_CTRL_ARB_EN_MASK | 1274*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_ARB_PARK); 1275*0Sstevel@tonic-gate *ctrl_reg_p = ctrl_reg; 1276*0Sstevel@tonic-gate } 1277*0Sstevel@tonic-gate } 1278*0Sstevel@tonic-gate 1279*0Sstevel@tonic-gate return (B_TRUE); 1280*0Sstevel@tonic-gate } 1281*0Sstevel@tonic-gate 1282*0Sstevel@tonic-gate void 1283*0Sstevel@tonic-gate pci_pbm_setup(pbm_t *pbm_p) 1284*0Sstevel@tonic-gate { 1285*0Sstevel@tonic-gate pci_t *pci_p = pbm_p->pbm_pci_p; 1286*0Sstevel@tonic-gate caddr_t a = pci_p->pci_address[0]; /* PBM block base VA */ 1287*0Sstevel@tonic-gate uint64_t pa = va_to_pa(a); 1288*0Sstevel@tonic-gate extern int segkmem_reloc; 1289*0Sstevel@tonic-gate 1290*0Sstevel@tonic-gate mutex_init(&pbm_p->pbm_sync_mutex, NULL, MUTEX_DRIVER, 1291*0Sstevel@tonic-gate (void *)ipltospl(XCALL_PIL)); 1292*0Sstevel@tonic-gate 1293*0Sstevel@tonic-gate pbm_p->pbm_config_header = (config_header_t *)pci_p->pci_address[2]; 1294*0Sstevel@tonic-gate pbm_p->pbm_ctrl_reg = (uint64_t *)(a + SCHIZO_PCI_CTRL_REG_OFFSET); 1295*0Sstevel@tonic-gate pbm_p->pbm_diag_reg = (uint64_t *)(a + SCHIZO_PCI_DIAG_REG_OFFSET); 1296*0Sstevel@tonic-gate pbm_p->pbm_async_flt_status_reg = 1297*0Sstevel@tonic-gate (uint64_t *)(a + SCHIZO_PCI_ASYNC_FLT_STATUS_REG_OFFSET); 1298*0Sstevel@tonic-gate pbm_p->pbm_async_flt_addr_reg = 1299*0Sstevel@tonic-gate (uint64_t *)(a + SCHIZO_PCI_ASYNC_FLT_ADDR_REG_OFFSET); 1300*0Sstevel@tonic-gate pbm_p->pbm_estar_reg = (uint64_t *)(a + SCHIZO_PCI_ESTAR_REG_OFFSET); 1301*0Sstevel@tonic-gate pbm_p->pbm_pcix_err_stat_reg = (uint64_t *)(a + 1302*0Sstevel@tonic-gate XMITS_PCI_X_ERROR_STATUS_REG_OFFSET); 1303*0Sstevel@tonic-gate pbm_p->pbm_pci_ped_ctrl = (uint64_t *)(a + 1304*0Sstevel@tonic-gate XMITS_PARITY_DETECT_REG_OFFSET); 1305*0Sstevel@tonic-gate 1306*0Sstevel@tonic-gate /* 1307*0Sstevel@tonic-gate * Create a property to indicate that this node supports DVMA 1308*0Sstevel@tonic-gate * page relocation. 1309*0Sstevel@tonic-gate */ 1310*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) != PCI_CHIP_TOMATILLO && segkmem_reloc != 0) { 1311*0Sstevel@tonic-gate pci_dvma_remap_enabled = 1; 1312*0Sstevel@tonic-gate (void) ndi_prop_create_boolean(DDI_DEV_T_NONE, 1313*0Sstevel@tonic-gate pci_p->pci_dip, "dvma-remap-supported"); 1314*0Sstevel@tonic-gate } 1315*0Sstevel@tonic-gate 1316*0Sstevel@tonic-gate /* 1317*0Sstevel@tonic-gate * Register a panic callback so we can unquiesce this bus 1318*0Sstevel@tonic-gate * if it has been placed in the quiesced state. 1319*0Sstevel@tonic-gate */ 1320*0Sstevel@tonic-gate pbm_p->pbm_panic_cb_id = callb_add(pci_pbm_panic_callb, 1321*0Sstevel@tonic-gate (void *)pbm_p, CB_CL_PANIC, "pci_panic"); 1322*0Sstevel@tonic-gate pbm_p->pbm_debug_cb_id = callb_add(pci_pbm_panic_callb, 1323*0Sstevel@tonic-gate (void *)pbm_p, CB_CL_ENTER_DEBUGGER, "pci_debug_enter"); 1324*0Sstevel@tonic-gate 1325*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) != PCI_CHIP_SCHIZO) 1326*0Sstevel@tonic-gate goto non_schizo; 1327*0Sstevel@tonic-gate 1328*0Sstevel@tonic-gate if (PCI_CHIP_ID(pci_p) >= SCHIZO_VER_23) { 1329*0Sstevel@tonic-gate 1330*0Sstevel@tonic-gate pbm_p->pbm_sync_reg_pa = pa + SCHIZO_PBM_DMA_SYNC_REG_OFFSET; 1331*0Sstevel@tonic-gate 1332*0Sstevel@tonic-gate /* 1333*0Sstevel@tonic-gate * This is a software workaround to fix schizo hardware bug. 1334*0Sstevel@tonic-gate * Create a boolean property and its existence means consistent 1335*0Sstevel@tonic-gate * dma sync should not be done while in prom. The usb polled 1336*0Sstevel@tonic-gate * code (OHCI,EHCI) will check for this property and will not 1337*0Sstevel@tonic-gate * do dma sync if this property exist. 1338*0Sstevel@tonic-gate */ 1339*0Sstevel@tonic-gate (void) ndi_prop_create_boolean(DDI_DEV_T_NONE, 1340*0Sstevel@tonic-gate pci_p->pci_dip, "no-prom-cdma-sync"); 1341*0Sstevel@tonic-gate } 1342*0Sstevel@tonic-gate return; 1343*0Sstevel@tonic-gate non_schizo: 1344*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) == PCI_CHIP_TOMATILLO) { 1345*0Sstevel@tonic-gate pci_dvma_sync_before_unmap = 1; 1346*0Sstevel@tonic-gate pa = pci_p->pci_cb_p->cb_icbase_pa; 1347*0Sstevel@tonic-gate } 1348*0Sstevel@tonic-gate pbm_p->pbm_sync_reg_pa = pa + PBM_DMA_SYNC_PEND_REG_OFFSET; 1349*0Sstevel@tonic-gate } 1350*0Sstevel@tonic-gate 1351*0Sstevel@tonic-gate void 1352*0Sstevel@tonic-gate pci_pbm_teardown(pbm_t *pbm_p) 1353*0Sstevel@tonic-gate { 1354*0Sstevel@tonic-gate (void) callb_delete(pbm_p->pbm_panic_cb_id); 1355*0Sstevel@tonic-gate (void) callb_delete(pbm_p->pbm_debug_cb_id); 1356*0Sstevel@tonic-gate } 1357*0Sstevel@tonic-gate 1358*0Sstevel@tonic-gate uintptr_t 1359*0Sstevel@tonic-gate pci_ib_setup(ib_t *ib_p) 1360*0Sstevel@tonic-gate { 1361*0Sstevel@tonic-gate /* 1362*0Sstevel@tonic-gate * Determine virtual addresses of bridge specific registers, 1363*0Sstevel@tonic-gate */ 1364*0Sstevel@tonic-gate pci_t *pci_p = ib_p->ib_pci_p; 1365*0Sstevel@tonic-gate uintptr_t a = (uintptr_t)pci_p->pci_address[0]; 1366*0Sstevel@tonic-gate 1367*0Sstevel@tonic-gate ib_p->ib_ign = PCI_ID_TO_IGN(pci_p->pci_id); 1368*0Sstevel@tonic-gate ib_p->ib_max_ino = SCHIZO_MAX_INO; 1369*0Sstevel@tonic-gate ib_p->ib_slot_intr_map_regs = a + SCHIZO_IB_SLOT_INTR_MAP_REG_OFFSET; 1370*0Sstevel@tonic-gate ib_p->ib_intr_map_regs = a + SCHIZO_IB_INTR_MAP_REG_OFFSET; 1371*0Sstevel@tonic-gate ib_p->ib_slot_clear_intr_regs = 1372*0Sstevel@tonic-gate a + SCHIZO_IB_CLEAR_INTR_REG_OFFSET; 1373*0Sstevel@tonic-gate return (a); 1374*0Sstevel@tonic-gate } 1375*0Sstevel@tonic-gate 1376*0Sstevel@tonic-gate void 1377*0Sstevel@tonic-gate pci_sc_setup(sc_t *sc_p) 1378*0Sstevel@tonic-gate { 1379*0Sstevel@tonic-gate pci_t *pci_p = sc_p->sc_pci_p; 1380*0Sstevel@tonic-gate uintptr_t a; 1381*0Sstevel@tonic-gate 1382*0Sstevel@tonic-gate /* 1383*0Sstevel@tonic-gate * Determine the virtual addresses of the stream cache 1384*0Sstevel@tonic-gate * control/status and flush registers. 1385*0Sstevel@tonic-gate */ 1386*0Sstevel@tonic-gate a = (uintptr_t)pci_p->pci_address[0]; /* PCICSRBase */ 1387*0Sstevel@tonic-gate sc_p->sc_ctrl_reg = (uint64_t *)(a + SCHIZO_SC_CTRL_REG_OFFSET); 1388*0Sstevel@tonic-gate sc_p->sc_invl_reg = (uint64_t *)(a + SCHIZO_SC_INVL_REG_OFFSET); 1389*0Sstevel@tonic-gate sc_p->sc_sync_reg = (uint64_t *)(a + SCHIZO_SC_SYNC_REG_OFFSET); 1390*0Sstevel@tonic-gate sc_p->sc_ctx_invl_reg = (uint64_t *)(a + SCHIZO_SC_CTX_INVL_REG_OFFSET); 1391*0Sstevel@tonic-gate sc_p->sc_ctx_match_reg = 1392*0Sstevel@tonic-gate (uint64_t *)(a + SCHIZO_SC_CTX_MATCH_REG_OFFSET); 1393*0Sstevel@tonic-gate 1394*0Sstevel@tonic-gate /* 1395*0Sstevel@tonic-gate * Determine the virtual addresses of the streaming cache 1396*0Sstevel@tonic-gate * diagnostic access registers. 1397*0Sstevel@tonic-gate */ 1398*0Sstevel@tonic-gate sc_p->sc_data_diag_acc = (uint64_t *)(a + SCHIZO_SC_DATA_DIAG_OFFSET); 1399*0Sstevel@tonic-gate sc_p->sc_tag_diag_acc = (uint64_t *)(a + SCHIZO_SC_TAG_DIAG_OFFSET); 1400*0Sstevel@tonic-gate sc_p->sc_ltag_diag_acc = (uint64_t *)(a + SCHIZO_SC_LTAG_DIAG_OFFSET); 1401*0Sstevel@tonic-gate } 1402*0Sstevel@tonic-gate 1403*0Sstevel@tonic-gate /*ARGSUSED*/ 1404*0Sstevel@tonic-gate int 1405*0Sstevel@tonic-gate pci_get_numproxy(dev_info_t *dip) 1406*0Sstevel@tonic-gate { 1407*0Sstevel@tonic-gate /* 1408*0Sstevel@tonic-gate * Schizo does not support interrupt proxies. 1409*0Sstevel@tonic-gate */ 1410*0Sstevel@tonic-gate return (0); 1411*0Sstevel@tonic-gate } 1412*0Sstevel@tonic-gate 1413*0Sstevel@tonic-gate /* 1414*0Sstevel@tonic-gate * pcisch error handling 101: 1415*0Sstevel@tonic-gate * 1416*0Sstevel@tonic-gate * The various functions below are responsible for error handling. Given 1417*0Sstevel@tonic-gate * a particular error, they must gather the appropriate state, report all 1418*0Sstevel@tonic-gate * errors with correct payload, and attempt recovery where ever possible. 1419*0Sstevel@tonic-gate * 1420*0Sstevel@tonic-gate * Recovery in the context of this driver is being able notify a leaf device 1421*0Sstevel@tonic-gate * of the failed transaction. This leaf device may either be the master or 1422*0Sstevel@tonic-gate * target for this transaction and may have already received an error 1423*0Sstevel@tonic-gate * notification via a PCI interrupt. Notification is done via DMA and access 1424*0Sstevel@tonic-gate * handles. If we capture an address for the transaction then we can map it 1425*0Sstevel@tonic-gate * to a handle(if the leaf device is fma-compliant) and fault the handle as 1426*0Sstevel@tonic-gate * well as call the device driver registered callback. 1427*0Sstevel@tonic-gate * 1428*0Sstevel@tonic-gate * The hardware can either interrupt or trap upon detection of an error, in 1429*0Sstevel@tonic-gate * some rare cases it also causes a fatal reset. 1430*0Sstevel@tonic-gate * 1431*0Sstevel@tonic-gate * cb_buserr_intr() is responsible for handling control block 1432*0Sstevel@tonic-gate * errors(errors which stem from the host bus side of the bridge). Since 1433*0Sstevel@tonic-gate * we support multiple chips and host bus standards, cb_buserr_intr will 1434*0Sstevel@tonic-gate * call a bus specific error handler to report and handle the detected 1435*0Sstevel@tonic-gate * error. Since this error can either affect or orginate from either of the 1436*0Sstevel@tonic-gate * two PCI busses which are connected to the bridge, we need to call 1437*0Sstevel@tonic-gate * pci_pbm_err_handler() for each bus as well to report their errors. We 1438*0Sstevel@tonic-gate * also need to gather possible errors which have been detected by their 1439*0Sstevel@tonic-gate * compliant children(via ndi_fm_handler_dispatch()). 1440*0Sstevel@tonic-gate * 1441*0Sstevel@tonic-gate * pbm_error_intr() and ecc_intr() are responsible for PCI Block Module 1442*0Sstevel@tonic-gate * errors(generic PCI + bridge specific) and ECC errors, respectively. They 1443*0Sstevel@tonic-gate * are common between pcisch and pcipsy and therefore exist in pci_pbm.c and 1444*0Sstevel@tonic-gate * pci_ecc.c. To support error handling certain chip specific handlers 1445*0Sstevel@tonic-gate * must exist and they are defined below. 1446*0Sstevel@tonic-gate * 1447*0Sstevel@tonic-gate * cpu_deferred_error() and cpu_async_error(), handle the traps that may 1448*0Sstevel@tonic-gate * have originated from IO space. They call into the registered IO callbacks 1449*0Sstevel@tonic-gate * to report and handle errors that may have caused the trap. 1450*0Sstevel@tonic-gate * 1451*0Sstevel@tonic-gate * pci_pbm_err_handler() is called by pbm_error_intr() or pci_err_callback() 1452*0Sstevel@tonic-gate * (generic fma callback for pcipsy/pcisch, pci_fm.c). pci_err_callback() is 1453*0Sstevel@tonic-gate * called when the CPU has trapped because of a possible IO error(TO/BERR/UE). 1454*0Sstevel@tonic-gate * It will call pci_pbm_err_handler() to report and handle all PCI/PBM/IOMMU 1455*0Sstevel@tonic-gate * related errors which are detected by the chip. 1456*0Sstevel@tonic-gate * 1457*0Sstevel@tonic-gate * pci_pbm_err_handler() calls a generic interface pbm_afsr_report()(pci_pbm.c) 1458*0Sstevel@tonic-gate * to report the pbm specific errors and attempt to map the failed address 1459*0Sstevel@tonic-gate * (if captured) to a device instance. pbm_afsr_report() calls a chip specific 1460*0Sstevel@tonic-gate * interface to interpret the afsr bits pci_pbm_classify()(pcisch.c/pcipsy.c). 1461*0Sstevel@tonic-gate * pci_pbm_err_handler() also calls iommu_err_handler() to handle IOMMU related 1462*0Sstevel@tonic-gate * errors. 1463*0Sstevel@tonic-gate * 1464*0Sstevel@tonic-gate * iommu_err_handler() can recover from most errors, as long as the requesting 1465*0Sstevel@tonic-gate * device is notified and the iommu can be flushed. If an IOMMU error occurs 1466*0Sstevel@tonic-gate * due to a UE then it will be passed on to the ecc_err_handler() for 1467*0Sstevel@tonic-gate * subsequent handling. 1468*0Sstevel@tonic-gate * 1469*0Sstevel@tonic-gate * ecc_err_handler()(pci_ecc.c) also calls a chip specific interface to 1470*0Sstevel@tonic-gate * interpret the afsr, pci_ecc_classify(). ecc_err_handler() also calls 1471*0Sstevel@tonic-gate * pci_pbm_err_handler() to report any pbm errors detected. 1472*0Sstevel@tonic-gate * 1473*0Sstevel@tonic-gate * To make sure that the trap code and the interrupt code are not going 1474*0Sstevel@tonic-gate * to step on each others toes we have a per chip pci_fm_mutex. This also 1475*0Sstevel@tonic-gate * makes it necessary for us to be caution while we are at a high PIL, so 1476*0Sstevel@tonic-gate * that we do not cause a subsequent trap that causes us to hang. 1477*0Sstevel@tonic-gate * 1478*0Sstevel@tonic-gate * The attempt to commonize code was meant to keep in line with the current 1479*0Sstevel@tonic-gate * pci driver implementation and it was not meant to confuse. If you are 1480*0Sstevel@tonic-gate * confused then don't worry, I was too. 1481*0Sstevel@tonic-gate * 1482*0Sstevel@tonic-gate */ 1483*0Sstevel@tonic-gate static void 1484*0Sstevel@tonic-gate pci_cb_errstate_get(cb_t *cb_p, cb_errstate_t *cb_err_p) 1485*0Sstevel@tonic-gate { 1486*0Sstevel@tonic-gate uint64_t pa = cb_p->cb_base_pa; 1487*0Sstevel@tonic-gate int i; 1488*0Sstevel@tonic-gate 1489*0Sstevel@tonic-gate bzero(cb_err_p, sizeof (cb_errstate_t)); 1490*0Sstevel@tonic-gate 1491*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cb_p->cb_pci_cmn_p->pci_fm_mutex)); 1492*0Sstevel@tonic-gate 1493*0Sstevel@tonic-gate cb_err_p->cb_bridge_type = PCI_BRIDGE_TYPE(cb_p->cb_pci_cmn_p); 1494*0Sstevel@tonic-gate 1495*0Sstevel@tonic-gate cb_err_p->cb_csr = lddphysio(pa + SCHIZO_CB_CSR_OFFSET); 1496*0Sstevel@tonic-gate cb_err_p->cb_err = lddphysio(pa + SCHIZO_CB_ERRCTRL_OFFSET); 1497*0Sstevel@tonic-gate cb_err_p->cb_intr = lddphysio(pa + SCHIZO_CB_INTCTRL_OFFSET); 1498*0Sstevel@tonic-gate cb_err_p->cb_elog = lddphysio(pa + SCHIZO_CB_ERRLOG_OFFSET); 1499*0Sstevel@tonic-gate cb_err_p->cb_ecc = lddphysio(pa + SCHIZO_CB_ECCCTRL_OFFSET); 1500*0Sstevel@tonic-gate cb_err_p->cb_ue_afsr = lddphysio(pa + SCHIZO_CB_UEAFSR_OFFSET); 1501*0Sstevel@tonic-gate cb_err_p->cb_ue_afar = lddphysio(pa + SCHIZO_CB_UEAFAR_OFFSET); 1502*0Sstevel@tonic-gate cb_err_p->cb_ce_afsr = lddphysio(pa + SCHIZO_CB_CEAFSR_OFFSET); 1503*0Sstevel@tonic-gate cb_err_p->cb_ce_afar = lddphysio(pa + SCHIZO_CB_CEAFAR_OFFSET); 1504*0Sstevel@tonic-gate 1505*0Sstevel@tonic-gate if ((CB_CHIP_TYPE((cb_t *)cb_p)) == PCI_CHIP_XMITS) { 1506*0Sstevel@tonic-gate cb_err_p->cb_first_elog = lddphysio(pa + 1507*0Sstevel@tonic-gate XMITS_CB_FIRST_ERROR_LOG); 1508*0Sstevel@tonic-gate cb_err_p->cb_first_eaddr = lddphysio(pa + 1509*0Sstevel@tonic-gate XMITS_CB_FIRST_ERROR_ADDR); 1510*0Sstevel@tonic-gate cb_err_p->cb_leaf_status = lddphysio(pa + 1511*0Sstevel@tonic-gate XMITS_CB_FIRST_ERROR_ADDR); 1512*0Sstevel@tonic-gate } 1513*0Sstevel@tonic-gate 1514*0Sstevel@tonic-gate /* Gather PBM state information for both sides of this chip */ 1515*0Sstevel@tonic-gate for (i = 0; i < 2; i++) { 1516*0Sstevel@tonic-gate if (cb_p->cb_pci_cmn_p->pci_p[i] == NULL) 1517*0Sstevel@tonic-gate continue; 1518*0Sstevel@tonic-gate pci_pbm_errstate_get(((cb_t *)cb_p)->cb_pci_cmn_p-> 1519*0Sstevel@tonic-gate pci_p[i], &cb_err_p->cb_pbm[i]); 1520*0Sstevel@tonic-gate } 1521*0Sstevel@tonic-gate } 1522*0Sstevel@tonic-gate 1523*0Sstevel@tonic-gate static void 1524*0Sstevel@tonic-gate pci_cb_clear_error(cb_t *cb_p, cb_errstate_t *cb_err_p) 1525*0Sstevel@tonic-gate { 1526*0Sstevel@tonic-gate uint64_t pa = ((cb_t *)cb_p)->cb_base_pa; 1527*0Sstevel@tonic-gate 1528*0Sstevel@tonic-gate stdphysio(pa + SCHIZO_CB_ERRLOG_OFFSET, cb_err_p->cb_elog); 1529*0Sstevel@tonic-gate } 1530*0Sstevel@tonic-gate 1531*0Sstevel@tonic-gate static cb_fm_err_t safari_err_tbl[] = { 1532*0Sstevel@tonic-gate SAFARI_BAD_CMD, SCHIZO_CB_ELOG_BAD_CMD, CB_FATAL, 1533*0Sstevel@tonic-gate SAFARI_SSM_DIS, SCHIZO_CB_ELOG_SSM_DIS, CB_FATAL, 1534*0Sstevel@tonic-gate SAFARI_BAD_CMD_PCIA, SCHIZO_CB_ELOG_BAD_CMD_PCIA, CB_FATAL, 1535*0Sstevel@tonic-gate SAFARI_BAD_CMD_PCIB, SCHIZO_CB_ELOG_BAD_CMD_PCIB, CB_FATAL, 1536*0Sstevel@tonic-gate SAFARI_PAR_ERR_INT_PCIB, XMITS_CB_ELOG_PAR_ERR_INT_PCIB, CB_FATAL, 1537*0Sstevel@tonic-gate SAFARI_PAR_ERR_INT_PCIA, XMITS_CB_ELOG_PAR_ERR_INT_PCIA, CB_FATAL, 1538*0Sstevel@tonic-gate SAFARI_PAR_ERR_INT_SAF, XMITS_CB_ELOG_PAR_ERR_INT_SAF, CB_FATAL, 1539*0Sstevel@tonic-gate SAFARI_PLL_ERR_PCIB, XMITS_CB_ELOG_PLL_ERR_PCIB, CB_FATAL, 1540*0Sstevel@tonic-gate SAFARI_PLL_ERR_PCIA, XMITS_CB_ELOG_PLL_ERR_PCIA, CB_FATAL, 1541*0Sstevel@tonic-gate SAFARI_PLL_ERR_SAF, XMITS_CB_ELOG_PLL_ERR_SAF, CB_FATAL, 1542*0Sstevel@tonic-gate SAFARI_SAF_CIQ_TO, SCHIZO_CB_ELOG_SAF_CIQ_TO, CB_FATAL, 1543*0Sstevel@tonic-gate SAFARI_SAF_LPQ_TO, SCHIZO_CB_ELOG_SAF_LPQ_TO, CB_FATAL, 1544*0Sstevel@tonic-gate SAFARI_SAF_SFPQ_TO, SCHIZO_CB_ELOG_SAF_SFPQ_TO, CB_FATAL, 1545*0Sstevel@tonic-gate SAFARI_APERR, SCHIZO_CB_ELOG_ADDR_PAR_ERR, CB_FATAL, 1546*0Sstevel@tonic-gate SAFARI_UNMAP_ERR, SCHIZO_CB_ELOG_UNMAP_ERR, CB_FATAL, 1547*0Sstevel@tonic-gate SAFARI_BUS_ERR, SCHIZO_CB_ELOG_BUS_ERR, CB_FATAL, 1548*0Sstevel@tonic-gate SAFARI_TO_ERR, SCHIZO_CB_ELOG_TO_ERR, CB_FATAL, 1549*0Sstevel@tonic-gate SAFARI_DSTAT_ERR, SCHIZO_CB_ELOG_DSTAT_ERR, CB_FATAL, 1550*0Sstevel@tonic-gate SAFARI_SAF_UFPQ_TO, SCHIZO_CB_ELOG_SAF_UFPQ_TO, CB_FATAL, 1551*0Sstevel@tonic-gate SAFARI_CPU0_PAR_SINGLE, SCHIZO_CB_ELOG_CPU0_PAR_SINGLE, CB_FATAL, 1552*0Sstevel@tonic-gate SAFARI_CPU0_PAR_BIDI, SCHIZO_CB_ELOG_CPU0_PAR_BIDI, CB_FATAL, 1553*0Sstevel@tonic-gate SAFARI_CPU1_PAR_SINGLE, SCHIZO_CB_ELOG_CPU1_PAR_SINGLE, CB_FATAL, 1554*0Sstevel@tonic-gate SAFARI_CPU1_PAR_BIDI, SCHIZO_CB_ELOG_CPU1_PAR_BIDI, CB_FATAL, 1555*0Sstevel@tonic-gate NULL, NULL, NULL, 1556*0Sstevel@tonic-gate }; 1557*0Sstevel@tonic-gate 1558*0Sstevel@tonic-gate /* 1559*0Sstevel@tonic-gate * Function used to handle and log Safari bus errors. 1560*0Sstevel@tonic-gate */ 1561*0Sstevel@tonic-gate static int 1562*0Sstevel@tonic-gate safari_err_handler(dev_info_t *dip, uint64_t fme_ena, 1563*0Sstevel@tonic-gate cb_errstate_t *cb_err_p) 1564*0Sstevel@tonic-gate { 1565*0Sstevel@tonic-gate int i; 1566*0Sstevel@tonic-gate int fatal = 0; 1567*0Sstevel@tonic-gate pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip)); 1568*0Sstevel@tonic-gate pci_common_t *cmn_p = pci_p->pci_common_p; 1569*0Sstevel@tonic-gate 1570*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cmn_p->pci_fm_mutex)); 1571*0Sstevel@tonic-gate 1572*0Sstevel@tonic-gate for (i = 0; safari_err_tbl[i].cb_err_class != NULL; i++) { 1573*0Sstevel@tonic-gate if (cb_err_p->cb_elog & safari_err_tbl[i].cb_reg_bit) { 1574*0Sstevel@tonic-gate cb_err_p->cb_err_class = safari_err_tbl[i].cb_err_class; 1575*0Sstevel@tonic-gate cb_ereport_post(dip, fme_ena, cb_err_p); 1576*0Sstevel@tonic-gate fatal += safari_err_tbl[i].cb_fatal; 1577*0Sstevel@tonic-gate } 1578*0Sstevel@tonic-gate } 1579*0Sstevel@tonic-gate 1580*0Sstevel@tonic-gate if (fatal) 1581*0Sstevel@tonic-gate return (DDI_FM_FATAL); 1582*0Sstevel@tonic-gate return (DDI_FM_OK); 1583*0Sstevel@tonic-gate 1584*0Sstevel@tonic-gate } 1585*0Sstevel@tonic-gate 1586*0Sstevel@tonic-gate /* 1587*0Sstevel@tonic-gate * Check pbm va log register for captured errant address, and fail handle 1588*0Sstevel@tonic-gate * if in per device cache. 1589*0Sstevel@tonic-gate * Called from jbus_err_handler. 1590*0Sstevel@tonic-gate */ 1591*0Sstevel@tonic-gate static int 1592*0Sstevel@tonic-gate jbus_check_va_log(cb_t *cb_p, uint64_t fme_ena, 1593*0Sstevel@tonic-gate cb_errstate_t *cb_err_p) 1594*0Sstevel@tonic-gate { 1595*0Sstevel@tonic-gate int i; 1596*0Sstevel@tonic-gate int ret = DDI_FM_FATAL; 1597*0Sstevel@tonic-gate pci_common_t *cmn_p = cb_p->cb_pci_cmn_p; 1598*0Sstevel@tonic-gate 1599*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cmn_p->pci_fm_mutex)); 1600*0Sstevel@tonic-gate /* 1601*0Sstevel@tonic-gate * Check VA log register for address associated with error, 1602*0Sstevel@tonic-gate * if no address is registered then return failure 1603*0Sstevel@tonic-gate */ 1604*0Sstevel@tonic-gate for (i = 0; i < 2; i++) { 1605*0Sstevel@tonic-gate 1606*0Sstevel@tonic-gate if (cb_p->cb_pci_cmn_p->pci_p[i] == NULL) 1607*0Sstevel@tonic-gate continue; 1608*0Sstevel@tonic-gate /* 1609*0Sstevel@tonic-gate * Look up and fault handle associated with 1610*0Sstevel@tonic-gate * logged DMA address 1611*0Sstevel@tonic-gate */ 1612*0Sstevel@tonic-gate if (cb_err_p->cb_pbm[i].pbm_va_log) { 1613*0Sstevel@tonic-gate ret = pci_handle_lookup(cb_p->cb_pci_cmn_p->pci_p[i]-> 1614*0Sstevel@tonic-gate pci_dip, DMA_HANDLE, fme_ena, 1615*0Sstevel@tonic-gate (void *)&cb_err_p->cb_pbm[i]. 1616*0Sstevel@tonic-gate pbm_va_log); 1617*0Sstevel@tonic-gate if (ret == DDI_FM_NONFATAL) 1618*0Sstevel@tonic-gate break; 1619*0Sstevel@tonic-gate } 1620*0Sstevel@tonic-gate } 1621*0Sstevel@tonic-gate return (ret); 1622*0Sstevel@tonic-gate } 1623*0Sstevel@tonic-gate 1624*0Sstevel@tonic-gate static cb_fm_err_t jbus_err_tbl[] = { 1625*0Sstevel@tonic-gate JBUS_APERR, SCHIZO_CB_ELOG_ADDR_PAR_ERR, CB_FATAL, 1626*0Sstevel@tonic-gate JBUS_PWR_DATA_PERR, TOMATILLO_CB_ELOG_WR_DATA_PAR_ERR, CB_FATAL, 1627*0Sstevel@tonic-gate JBUS_DRD_DATA_PERR, TOMATILLO_CB_ELOG_RD_DATA_PAR_ERR, CB_NONFATAL, 1628*0Sstevel@tonic-gate JBUS_CTL_PERR, TOMATILLO_CB_ELOG_CTL_PAR_ERR, CB_FATAL, 1629*0Sstevel@tonic-gate JBUS_ILL_BYTE_EN, TOMATILLO_CB_ELOG_ILL_BYTE_EN, CB_FATAL, 1630*0Sstevel@tonic-gate JBUS_ILL_COH_IN, TOMATILLO_CB_ELOG_ILL_COH_IN, CB_FATAL, 1631*0Sstevel@tonic-gate JBUS_SNOOP_ERR_RD, TOMATILLO_CB_ELOG_SNOOP_ERR_RD, CB_FATAL, 1632*0Sstevel@tonic-gate JBUS_SNOOP_ERR_RDS, TOMATILLO_CB_ELOG_SNOOP_ERR_RDS, CB_FATAL, 1633*0Sstevel@tonic-gate JBUS_SNOOP_ERR_RDSA, TOMATILLO_CB_ELOG_SNOOP_ERR_RDSA, CB_FATAL, 1634*0Sstevel@tonic-gate JBUS_SNOOP_ERR_OWN, TOMATILLO_CB_ELOG_SNOOP_ERR_OWN, CB_FATAL, 1635*0Sstevel@tonic-gate JBUS_SNOOP_ERR_RDO, TOMATILLO_CB_ELOG_SNOOP_ERR_RDO, CB_FATAL, 1636*0Sstevel@tonic-gate JBUS_SNOOP_ERR_PCI, TOMATILLO_CB_ELOG_SNOOP_ERR_PCI, CB_FATAL, 1637*0Sstevel@tonic-gate JBUS_SNOOP_ERR_GR, TOMATILLO_CB_ELOG_SNOOP_ERR_GR, CB_FATAL, 1638*0Sstevel@tonic-gate JBUS_SNOOP_ERR, TOMATILLO_CB_ELOG_SNOOP_ERR, CB_FATAL, 1639*0Sstevel@tonic-gate JBUS_BAD_CMD, SCHIZO_CB_ELOG_BAD_CMD, CB_FATAL, 1640*0Sstevel@tonic-gate JBUS_UNMAP_ERR, SCHIZO_CB_ELOG_UNMAP_ERR, CB_NONFATAL, 1641*0Sstevel@tonic-gate JBUS_TO_EXP_ERR, TOMATILLO_CB_ELOG_TO_EXP_ERR, CB_NONFATAL, 1642*0Sstevel@tonic-gate JBUS_TO_ERR, SCHIZO_CB_ELOG_TO_ERR, CB_NONFATAL, 1643*0Sstevel@tonic-gate JBUS_BUS_ERR, SCHIZO_CB_ELOG_BUS_ERR, CB_NONFATAL, 1644*0Sstevel@tonic-gate NULL, NULL, NULL, 1645*0Sstevel@tonic-gate }; 1646*0Sstevel@tonic-gate 1647*0Sstevel@tonic-gate /* 1648*0Sstevel@tonic-gate * Function used to handle and log Jbus errors. 1649*0Sstevel@tonic-gate */ 1650*0Sstevel@tonic-gate static int 1651*0Sstevel@tonic-gate jbus_err_handler(dev_info_t *dip, uint64_t fme_ena, 1652*0Sstevel@tonic-gate cb_errstate_t *cb_err_p) 1653*0Sstevel@tonic-gate { 1654*0Sstevel@tonic-gate int fatal = 0; 1655*0Sstevel@tonic-gate int nonfatal = 0; 1656*0Sstevel@tonic-gate int i; 1657*0Sstevel@tonic-gate pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip)); 1658*0Sstevel@tonic-gate cb_t *cb_p = pci_p->pci_cb_p; 1659*0Sstevel@tonic-gate 1660*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pci_p->pci_common_p->pci_fm_mutex)); 1661*0Sstevel@tonic-gate 1662*0Sstevel@tonic-gate for (i = 0; jbus_err_tbl[i].cb_err_class != NULL; i++) { 1663*0Sstevel@tonic-gate if (!(cb_err_p->cb_elog & jbus_err_tbl[i].cb_reg_bit)) 1664*0Sstevel@tonic-gate continue; 1665*0Sstevel@tonic-gate cb_err_p->cb_err_class = jbus_err_tbl[i].cb_err_class; 1666*0Sstevel@tonic-gate if (jbus_err_tbl[i].cb_fatal) { 1667*0Sstevel@tonic-gate fatal += jbus_err_tbl[i].cb_fatal; 1668*0Sstevel@tonic-gate continue; 1669*0Sstevel@tonic-gate } 1670*0Sstevel@tonic-gate if (jbus_check_va_log(cb_p, fme_ena, cb_err_p) 1671*0Sstevel@tonic-gate != DDI_FM_NONFATAL) { 1672*0Sstevel@tonic-gate fatal++; 1673*0Sstevel@tonic-gate } 1674*0Sstevel@tonic-gate cb_ereport_post(dip, fme_ena, cb_err_p); 1675*0Sstevel@tonic-gate } 1676*0Sstevel@tonic-gate 1677*0Sstevel@tonic-gate return (fatal ? DDI_FM_FATAL : (nonfatal ? DDI_FM_NONFATAL : 1678*0Sstevel@tonic-gate DDI_FM_OK)); 1679*0Sstevel@tonic-gate } 1680*0Sstevel@tonic-gate 1681*0Sstevel@tonic-gate /* 1682*0Sstevel@tonic-gate * Control Block error interrupt handler. 1683*0Sstevel@tonic-gate */ 1684*0Sstevel@tonic-gate uint_t 1685*0Sstevel@tonic-gate cb_buserr_intr(caddr_t a) 1686*0Sstevel@tonic-gate { 1687*0Sstevel@tonic-gate cb_t *cb_p = (cb_t *)a; 1688*0Sstevel@tonic-gate pci_common_t *cmn_p = cb_p->cb_pci_cmn_p; 1689*0Sstevel@tonic-gate pci_t *pci_p = cmn_p->pci_p[0]; 1690*0Sstevel@tonic-gate cb_errstate_t cb_err; 1691*0Sstevel@tonic-gate ddi_fm_error_t derr; 1692*0Sstevel@tonic-gate int ret = DDI_FM_FATAL; 1693*0Sstevel@tonic-gate int i; 1694*0Sstevel@tonic-gate 1695*0Sstevel@tonic-gate if (pci_p == NULL) 1696*0Sstevel@tonic-gate pci_p = cmn_p->pci_p[1]; 1697*0Sstevel@tonic-gate 1698*0Sstevel@tonic-gate bzero(&derr, sizeof (ddi_fm_error_t)); 1699*0Sstevel@tonic-gate derr.fme_version = DDI_FME_VERSION; 1700*0Sstevel@tonic-gate derr.fme_ena = fm_ena_generate(0, FM_ENA_FMT1); 1701*0Sstevel@tonic-gate 1702*0Sstevel@tonic-gate mutex_enter(&cmn_p->pci_fm_mutex); 1703*0Sstevel@tonic-gate 1704*0Sstevel@tonic-gate pci_cb_errstate_get(cb_p, &cb_err); 1705*0Sstevel@tonic-gate 1706*0Sstevel@tonic-gate if (CB_CHIP_TYPE(cb_p) == PCI_CHIP_TOMATILLO) 1707*0Sstevel@tonic-gate ret = jbus_err_handler(pci_p->pci_dip, derr.fme_ena, &cb_err); 1708*0Sstevel@tonic-gate else if ((CB_CHIP_TYPE(cb_p) == PCI_CHIP_SCHIZO) || 1709*0Sstevel@tonic-gate (CB_CHIP_TYPE(cb_p) == PCI_CHIP_XMITS)) 1710*0Sstevel@tonic-gate ret = safari_err_handler(pci_p->pci_dip, derr.fme_ena, 1711*0Sstevel@tonic-gate &cb_err); 1712*0Sstevel@tonic-gate 1713*0Sstevel@tonic-gate /* 1714*0Sstevel@tonic-gate * Check for related errors in PBM and IOMMU. The IOMMU could cause 1715*0Sstevel@tonic-gate * a timeout on the jbus due to an IOMMU miss, so we need to check and 1716*0Sstevel@tonic-gate * log the IOMMU error registers. 1717*0Sstevel@tonic-gate */ 1718*0Sstevel@tonic-gate for (i = 0; i < 2; i++) { 1719*0Sstevel@tonic-gate if (cmn_p->pci_p[i] == NULL) 1720*0Sstevel@tonic-gate continue; 1721*0Sstevel@tonic-gate if (pci_pbm_err_handler(cmn_p->pci_p[i]->pci_dip, &derr, 1722*0Sstevel@tonic-gate (void *)cmn_p->pci_p[i], PCI_CB_CALL) == DDI_FM_FATAL) 1723*0Sstevel@tonic-gate ret = DDI_FM_FATAL; 1724*0Sstevel@tonic-gate } 1725*0Sstevel@tonic-gate 1726*0Sstevel@tonic-gate /* Cleanup and reset error bits */ 1727*0Sstevel@tonic-gate (void) pci_cb_clear_error(cb_p, &cb_err); 1728*0Sstevel@tonic-gate mutex_exit(&cmn_p->pci_fm_mutex); 1729*0Sstevel@tonic-gate 1730*0Sstevel@tonic-gate if (ret == DDI_FM_FATAL) { 1731*0Sstevel@tonic-gate fm_panic("Fatal System Bus Error has occurred\n"); 1732*0Sstevel@tonic-gate } 1733*0Sstevel@tonic-gate 1734*0Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 1735*0Sstevel@tonic-gate } 1736*0Sstevel@tonic-gate 1737*0Sstevel@tonic-gate static ecc_fm_err_t ecc_err_tbl[] = { 1738*0Sstevel@tonic-gate PCI_ECC_PIO_UE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_UE, 1739*0Sstevel@tonic-gate PBM_PRIMARY, SCHIZO_ECC_AFAR_PIOW_UPA64S, SCH_REG_UPA, 1740*0Sstevel@tonic-gate ACC_HANDLE, 1741*0Sstevel@tonic-gate 1742*0Sstevel@tonic-gate PCI_ECC_PIO_UE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_UE, 1743*0Sstevel@tonic-gate PBM_PRIMARY, SCHIZO_ECC_AFAR_PIOW_PCIA_REG, SCH_REG_PCIA_REG, 1744*0Sstevel@tonic-gate ACC_HANDLE, 1745*0Sstevel@tonic-gate 1746*0Sstevel@tonic-gate PCI_ECC_PIO_UE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_UE, 1747*0Sstevel@tonic-gate PBM_PRIMARY, SCHIZO_ECC_AFAR_PIOW_PCIA_MEM, SCH_REG_PCIA_MEM, 1748*0Sstevel@tonic-gate ACC_HANDLE, 1749*0Sstevel@tonic-gate 1750*0Sstevel@tonic-gate PCI_ECC_PIO_UE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_UE, 1751*0Sstevel@tonic-gate PBM_PRIMARY, SCHIZO_ECC_AFAR_PIOW_PCIA_CFGIO, SCH_REG_PCIA_CFGIO, 1752*0Sstevel@tonic-gate ACC_HANDLE, 1753*0Sstevel@tonic-gate 1754*0Sstevel@tonic-gate PCI_ECC_PIO_UE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_UE, 1755*0Sstevel@tonic-gate PBM_PRIMARY, SCHIZO_ECC_AFAR_PIOW_PCIB_REG, SCH_REG_PCIB_REG, 1756*0Sstevel@tonic-gate ACC_HANDLE, 1757*0Sstevel@tonic-gate 1758*0Sstevel@tonic-gate PCI_ECC_PIO_UE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_UE, 1759*0Sstevel@tonic-gate PBM_PRIMARY, SCHIZO_ECC_AFAR_PIOW_PCIB_MEM, SCH_REG_PCIB_MEM, 1760*0Sstevel@tonic-gate ACC_HANDLE, 1761*0Sstevel@tonic-gate 1762*0Sstevel@tonic-gate PCI_ECC_PIO_UE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_UE, 1763*0Sstevel@tonic-gate PBM_PRIMARY, SCHIZO_ECC_AFAR_PIOW_PCIB_CFGIO, SCH_REG_PCIB_CFGIO, 1764*0Sstevel@tonic-gate ACC_HANDLE, 1765*0Sstevel@tonic-gate 1766*0Sstevel@tonic-gate PCI_ECC_PIO_UE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_UE, 1767*0Sstevel@tonic-gate PBM_PRIMARY, SCHIZO_ECC_AFAR_PIOW_SAFARI_REGS, SCH_REG_SAFARI_REGS, 1768*0Sstevel@tonic-gate ACC_HANDLE, 1769*0Sstevel@tonic-gate 1770*0Sstevel@tonic-gate PCI_ECC_SEC_PIO_UE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_UE, 1771*0Sstevel@tonic-gate PBM_SECONDARY, NULL, NULL, ACC_HANDLE, 1772*0Sstevel@tonic-gate 1773*0Sstevel@tonic-gate PCI_ECC_PIO_CE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_CE, 1774*0Sstevel@tonic-gate PBM_PRIMARY, NULL, NULL, ACC_HANDLE, 1775*0Sstevel@tonic-gate 1776*0Sstevel@tonic-gate PCI_ECC_SEC_PIO_CE, COMMON_ECC_UE_AFSR_E_PIO, CBNINTR_CE, 1777*0Sstevel@tonic-gate PBM_SECONDARY, NULL, NULL, ACC_HANDLE, 1778*0Sstevel@tonic-gate 1779*0Sstevel@tonic-gate PCI_ECC_DRD_UE, COMMON_ECC_UE_AFSR_E_DRD, CBNINTR_UE, 1780*0Sstevel@tonic-gate PBM_PRIMARY, NULL, NULL, DMA_HANDLE, 1781*0Sstevel@tonic-gate 1782*0Sstevel@tonic-gate PCI_ECC_SEC_DRD_UE, COMMON_ECC_UE_AFSR_E_DRD, CBNINTR_UE, 1783*0Sstevel@tonic-gate PBM_SECONDARY, NULL, NULL, DMA_HANDLE, 1784*0Sstevel@tonic-gate 1785*0Sstevel@tonic-gate PCI_ECC_DRD_CE, COMMON_ECC_UE_AFSR_E_DRD, CBNINTR_CE, 1786*0Sstevel@tonic-gate PBM_PRIMARY, NULL, NULL, DMA_HANDLE, 1787*0Sstevel@tonic-gate 1788*0Sstevel@tonic-gate PCI_ECC_SEC_DRD_CE, COMMON_ECC_UE_AFSR_E_DRD, CBNINTR_CE, 1789*0Sstevel@tonic-gate PBM_SECONDARY, NULL, NULL, DMA_HANDLE, 1790*0Sstevel@tonic-gate 1791*0Sstevel@tonic-gate PCI_ECC_DWR_UE, COMMON_ECC_UE_AFSR_E_DWR, CBNINTR_UE, 1792*0Sstevel@tonic-gate PBM_PRIMARY, NULL, NULL, DMA_HANDLE, 1793*0Sstevel@tonic-gate 1794*0Sstevel@tonic-gate PCI_ECC_SEC_DWR_UE, COMMON_ECC_UE_AFSR_E_DWR, CBNINTR_UE, 1795*0Sstevel@tonic-gate PBM_SECONDARY, NULL, NULL, DMA_HANDLE, 1796*0Sstevel@tonic-gate 1797*0Sstevel@tonic-gate PCI_ECC_DWR_CE, COMMON_ECC_UE_AFSR_E_DWR, CBNINTR_CE, 1798*0Sstevel@tonic-gate PBM_PRIMARY, NULL, NULL, DMA_HANDLE, 1799*0Sstevel@tonic-gate 1800*0Sstevel@tonic-gate PCI_ECC_SEC_DWR_CE, COMMON_ECC_UE_AFSR_E_DWR, CBNINTR_CE, 1801*0Sstevel@tonic-gate PBM_SECONDARY, NULL, NULL, DMA_HANDLE, 1802*0Sstevel@tonic-gate 1803*0Sstevel@tonic-gate NULL, NULL, NULL, NULL, NULL, NULL, 1804*0Sstevel@tonic-gate }; 1805*0Sstevel@tonic-gate 1806*0Sstevel@tonic-gate /* 1807*0Sstevel@tonic-gate * pci_ecc_classify, called by ecc_handler to classify ecc errors 1808*0Sstevel@tonic-gate * and determine if we should panic or not. 1809*0Sstevel@tonic-gate */ 1810*0Sstevel@tonic-gate void 1811*0Sstevel@tonic-gate pci_ecc_classify(uint64_t err, ecc_errstate_t *ecc_err_p) 1812*0Sstevel@tonic-gate { 1813*0Sstevel@tonic-gate struct async_flt *ecc_p = &ecc_err_p->ecc_aflt; 1814*0Sstevel@tonic-gate uint64_t region, afar = ecc_p->flt_addr; 1815*0Sstevel@tonic-gate int i, j, ret = 0; 1816*0Sstevel@tonic-gate int flag, fatal = 0; 1817*0Sstevel@tonic-gate pci_common_t *cmn_p = ecc_err_p->ecc_ii_p.ecc_p->ecc_pci_cmn_p; 1818*0Sstevel@tonic-gate pci_t *pci_p = cmn_p->pci_p[0]; 1819*0Sstevel@tonic-gate 1820*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cmn_p->pci_fm_mutex)); 1821*0Sstevel@tonic-gate 1822*0Sstevel@tonic-gate ecc_err_p->ecc_bridge_type = PCI_BRIDGE_TYPE(cmn_p); 1823*0Sstevel@tonic-gate 1824*0Sstevel@tonic-gate if (pci_p == NULL) 1825*0Sstevel@tonic-gate pci_p = cmn_p->pci_p[1]; 1826*0Sstevel@tonic-gate 1827*0Sstevel@tonic-gate ecc_err_p->ecc_ctrl = lddphysio(ecc_err_p->ecc_ii_p.ecc_p->ecc_csr_pa); 1828*0Sstevel@tonic-gate ecc_err_p->ecc_err_addr = afar; 1829*0Sstevel@tonic-gate region = afar & SCHIZO_ECC_AFAR_PIOW_MASK; 1830*0Sstevel@tonic-gate 1831*0Sstevel@tonic-gate for (i = 0; ecc_err_tbl[i].ecc_err_class != NULL; i++) { 1832*0Sstevel@tonic-gate if (!(err & ecc_err_tbl[i].ecc_reg_bit) || 1833*0Sstevel@tonic-gate (ecc_err_p->ecc_ii_p.ecc_type != 1834*0Sstevel@tonic-gate ecc_err_tbl[i].ecc_type) || 1835*0Sstevel@tonic-gate (ecc_err_p->ecc_pri != ecc_err_tbl[i].ecc_pri)) 1836*0Sstevel@tonic-gate continue; 1837*0Sstevel@tonic-gate 1838*0Sstevel@tonic-gate ecc_p->flt_erpt_class = ecc_err_tbl[i].ecc_err_class; 1839*0Sstevel@tonic-gate flag = ecc_err_tbl[i].ecc_flag; 1840*0Sstevel@tonic-gate 1841*0Sstevel@tonic-gate if (!ecc_err_tbl[i].ecc_pri || 1842*0Sstevel@tonic-gate (ecc_err_tbl[i].ecc_type == CBNINTR_CE)) { 1843*0Sstevel@tonic-gate fatal += (ecc_err_tbl[i].ecc_type == CBNINTR_UE) ? 1844*0Sstevel@tonic-gate 1 : 0; 1845*0Sstevel@tonic-gate break; 1846*0Sstevel@tonic-gate } 1847*0Sstevel@tonic-gate 1848*0Sstevel@tonic-gate if (flag == ACC_HANDLE && 1849*0Sstevel@tonic-gate (region & ecc_err_tbl[i].ecc_region_bits)) { 1850*0Sstevel@tonic-gate ecc_err_p->ecc_region = ecc_err_tbl[i].ecc_region; 1851*0Sstevel@tonic-gate pci_format_ecc_addr(pci_p->pci_dip, 1852*0Sstevel@tonic-gate &ecc_err_p->ecc_err_addr, 1853*0Sstevel@tonic-gate ecc_err_p->ecc_region); 1854*0Sstevel@tonic-gate } 1855*0Sstevel@tonic-gate 1856*0Sstevel@tonic-gate /* 1857*0Sstevel@tonic-gate * Lookup and fault errant handle 1858*0Sstevel@tonic-gate */ 1859*0Sstevel@tonic-gate for (j = 0; j < 2; ++j) { 1860*0Sstevel@tonic-gate ret = DDI_FM_UNKNOWN; 1861*0Sstevel@tonic-gate if (cmn_p->pci_p[j] == NULL) 1862*0Sstevel@tonic-gate continue; 1863*0Sstevel@tonic-gate ret = pci_handle_lookup(cmn_p->pci_p[j]->pci_dip, 1864*0Sstevel@tonic-gate flag, ecc_err_p->ecc_ena, 1865*0Sstevel@tonic-gate (void *)&ecc_err_p->ecc_err_addr); 1866*0Sstevel@tonic-gate if (ret == DDI_FM_NONFATAL) { 1867*0Sstevel@tonic-gate fatal = 0; 1868*0Sstevel@tonic-gate break; 1869*0Sstevel@tonic-gate } else 1870*0Sstevel@tonic-gate fatal++; 1871*0Sstevel@tonic-gate } 1872*0Sstevel@tonic-gate break; 1873*0Sstevel@tonic-gate } 1874*0Sstevel@tonic-gate 1875*0Sstevel@tonic-gate if (fatal) 1876*0Sstevel@tonic-gate ecc_p->flt_panic = 1; 1877*0Sstevel@tonic-gate else if (flag != ACC_HANDLE) 1878*0Sstevel@tonic-gate ecc_err_p->ecc_pg_ret = 1; 1879*0Sstevel@tonic-gate } 1880*0Sstevel@tonic-gate 1881*0Sstevel@tonic-gate /* 1882*0Sstevel@tonic-gate * Tables to define PCI-X Split Completion errors 1883*0Sstevel@tonic-gate */ 1884*0Sstevel@tonic-gate 1885*0Sstevel@tonic-gate pcix_err_msg_rec_t pcix_completer_errs[] = { 1886*0Sstevel@tonic-gate {PCIX_CPLT_OUT_OF_RANGE, "pcix", "oor" }, 1887*0Sstevel@tonic-gate }; 1888*0Sstevel@tonic-gate 1889*0Sstevel@tonic-gate pcix_err_tbl_t pcix_split_errs_tbl[] = { 1890*0Sstevel@tonic-gate {PCIX_CLASS_CPLT, 1891*0Sstevel@tonic-gate sizeof (pcix_completer_errs)/sizeof (pcix_err_msg_rec_t), 1892*0Sstevel@tonic-gate pcix_completer_errs }, 1893*0Sstevel@tonic-gate }; 1894*0Sstevel@tonic-gate 1895*0Sstevel@tonic-gate /* 1896*0Sstevel@tonic-gate * Tables for the PCI-X error status messages 1897*0Sstevel@tonic-gate */ 1898*0Sstevel@tonic-gate pcix_err_msg_rec_t pcix_stat_errs[] = { 1899*0Sstevel@tonic-gate {XMITS_PCIX_STAT_SC_DSCRD, "pcix", "discard" }, 1900*0Sstevel@tonic-gate {XMITS_PCIX_STAT_SC_TTO, "xmits.pbmx", "tato" }, 1901*0Sstevel@tonic-gate {XMITS_PCIX_STAT_SMMU, "xmits.pbmx", "stmmu" }, 1902*0Sstevel@tonic-gate {XMITS_PCIX_STAT_SDSTAT, "xmits.pbmx", "stdst" }, 1903*0Sstevel@tonic-gate {XMITS_PCIX_STAT_CMMU, "xmits.pbmx", "cnmmu" }, 1904*0Sstevel@tonic-gate {XMITS_PCIX_STAT_CDSTAT, "xmits.pbmx", "cndst" } 1905*0Sstevel@tonic-gate }; 1906*0Sstevel@tonic-gate 1907*0Sstevel@tonic-gate pcix_err_tbl_t pcix_stat_errs_tbl = 1908*0Sstevel@tonic-gate {PCIX_NO_CLASS, 1909*0Sstevel@tonic-gate sizeof (pcix_stat_errs)/sizeof (pcix_err_msg_rec_t), 1910*0Sstevel@tonic-gate pcix_stat_errs }; 1911*0Sstevel@tonic-gate 1912*0Sstevel@tonic-gate 1913*0Sstevel@tonic-gate /* 1914*0Sstevel@tonic-gate * walk thru a table of error messages, printing as appropriate 1915*0Sstevel@tonic-gate * 1916*0Sstevel@tonic-gate * t - the table of messages to parse 1917*0Sstevel@tonic-gate * err - the error to match against 1918*0Sstevel@tonic-gate * multi - flag, sometimes multiple error bits may be set/desired 1919*0Sstevel@tonic-gate */ 1920*0Sstevel@tonic-gate static int 1921*0Sstevel@tonic-gate pcix_lookup_err_msgs(dev_info_t *dip, uint64_t ena, pcix_err_tbl_t t, 1922*0Sstevel@tonic-gate pbm_errstate_t *pbm_err_p) 1923*0Sstevel@tonic-gate { 1924*0Sstevel@tonic-gate uint32_t err_bits = pbm_err_p->pbm_err & XMITS_PCIX_MSG_INDEX_MASK; 1925*0Sstevel@tonic-gate int nerr = 0; 1926*0Sstevel@tonic-gate int j; 1927*0Sstevel@tonic-gate char buf[FM_MAX_CLASS]; 1928*0Sstevel@tonic-gate 1929*0Sstevel@tonic-gate for (j = 0; j < t.err_rec_num; j++) { 1930*0Sstevel@tonic-gate uint32_t msg_key = t.err_msg_tbl[j].msg_key; 1931*0Sstevel@tonic-gate if (pbm_err_p->pbm_multi ? !(err_bits & msg_key) : err_bits 1932*0Sstevel@tonic-gate != msg_key) 1933*0Sstevel@tonic-gate continue; 1934*0Sstevel@tonic-gate 1935*0Sstevel@tonic-gate (void) snprintf(buf, FM_MAX_CLASS, "%s.%s%s", 1936*0Sstevel@tonic-gate t.err_msg_tbl[j].msg_class, 1937*0Sstevel@tonic-gate pbm_err_p->pbm_pri ? "" : PCIX_SECONDARY, 1938*0Sstevel@tonic-gate t.err_msg_tbl[j].msg_str); 1939*0Sstevel@tonic-gate 1940*0Sstevel@tonic-gate pbm_err_p->pbm_err_class = buf; 1941*0Sstevel@tonic-gate pcix_ereport_post(dip, ena, pbm_err_p); 1942*0Sstevel@tonic-gate nerr++; 1943*0Sstevel@tonic-gate } 1944*0Sstevel@tonic-gate return (nerr ? DDI_FM_FATAL : DDI_FM_OK); 1945*0Sstevel@tonic-gate } 1946*0Sstevel@tonic-gate 1947*0Sstevel@tonic-gate /* 1948*0Sstevel@tonic-gate * Decodes primary(bit 27-24) or secondary(bit 15-12) PCI-X split 1949*0Sstevel@tonic-gate * completion error message class and index in PBM AFSR. 1950*0Sstevel@tonic-gate */ 1951*0Sstevel@tonic-gate static void 1952*0Sstevel@tonic-gate pcix_log_split_err(dev_info_t *dip, uint64_t ena, pbm_errstate_t *pbm_err_p) 1953*0Sstevel@tonic-gate { 1954*0Sstevel@tonic-gate uint32_t class = pbm_err_p->pbm_err & XMITS_PCIX_MSG_CLASS_MASK; 1955*0Sstevel@tonic-gate uint32_t num_classes = sizeof (pcix_split_errs_tbl) / 1956*0Sstevel@tonic-gate sizeof (struct pcix_err_tbl); 1957*0Sstevel@tonic-gate int i; 1958*0Sstevel@tonic-gate 1959*0Sstevel@tonic-gate for (i = 0; i < num_classes; i++) { 1960*0Sstevel@tonic-gate if (class == pcix_split_errs_tbl[i].err_class) { 1961*0Sstevel@tonic-gate pbm_err_p->pbm_multi = PCIX_SINGLE_ERR; 1962*0Sstevel@tonic-gate (void) pcix_lookup_err_msgs(dip, ena, 1963*0Sstevel@tonic-gate pcix_split_errs_tbl[i], pbm_err_p); 1964*0Sstevel@tonic-gate break; 1965*0Sstevel@tonic-gate } 1966*0Sstevel@tonic-gate } 1967*0Sstevel@tonic-gate } 1968*0Sstevel@tonic-gate 1969*0Sstevel@tonic-gate /* 1970*0Sstevel@tonic-gate * Report PBM PCI-X Error Status Register if in PCI-X mode 1971*0Sstevel@tonic-gate * 1972*0Sstevel@tonic-gate * Once a PCI-X fault tree is constructed, the code below may need to 1973*0Sstevel@tonic-gate * change. 1974*0Sstevel@tonic-gate */ 1975*0Sstevel@tonic-gate static int 1976*0Sstevel@tonic-gate pcix_log_pbm(pci_t *pci_p, uint64_t ena, pbm_errstate_t *pbm_err_p) 1977*0Sstevel@tonic-gate { 1978*0Sstevel@tonic-gate int fatal = 0; 1979*0Sstevel@tonic-gate int nonfatal = 0; 1980*0Sstevel@tonic-gate uint32_t e; 1981*0Sstevel@tonic-gate 1982*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pci_p->pci_common_p->pci_fm_mutex)); 1983*0Sstevel@tonic-gate 1984*0Sstevel@tonic-gate DEBUG3(DBG_ERR_INTR, pci_p->pci_dip, "pcix_log_pbm: chip_type=%d " 1985*0Sstevel@tonic-gate "ctr_stat=%lx afsr = 0x%lx", CHIP_TYPE(pci_p), 1986*0Sstevel@tonic-gate pbm_err_p->pbm_ctl_stat, pbm_err_p->pbm_afsr); 1987*0Sstevel@tonic-gate 1988*0Sstevel@tonic-gate if (!(CHIP_TYPE(pci_p) == PCI_CHIP_XMITS) || 1989*0Sstevel@tonic-gate !(pbm_err_p->pbm_ctl_stat & XMITS_PCI_CTRL_X_MODE)) 1990*0Sstevel@tonic-gate return (DDI_FM_OK); 1991*0Sstevel@tonic-gate 1992*0Sstevel@tonic-gate if (pbm_err_p->pbm_afsr & XMITS_PCI_X_AFSR_P_SC_ERR) { 1993*0Sstevel@tonic-gate pbm_err_p->pbm_err = PBM_AFSR_TO_PRISPLIT(pbm_err_p->pbm_afsr); 1994*0Sstevel@tonic-gate pbm_err_p->pbm_pri = PBM_PRIMARY; 1995*0Sstevel@tonic-gate pcix_log_split_err(pci_p->pci_dip, ena, pbm_err_p); 1996*0Sstevel@tonic-gate nonfatal++; 1997*0Sstevel@tonic-gate } 1998*0Sstevel@tonic-gate if (pbm_err_p->pbm_afsr & XMITS_PCI_X_AFSR_S_SC_ERR) { 1999*0Sstevel@tonic-gate pbm_err_p->pbm_err = PBM_AFSR_TO_PRISPLIT(pbm_err_p->pbm_afsr); 2000*0Sstevel@tonic-gate pbm_err_p->pbm_pri = PBM_PRIMARY; 2001*0Sstevel@tonic-gate pcix_log_split_err(pci_p->pci_dip, ena, pbm_err_p); 2002*0Sstevel@tonic-gate nonfatal++; 2003*0Sstevel@tonic-gate } 2004*0Sstevel@tonic-gate 2005*0Sstevel@tonic-gate e = PBM_PCIX_TO_PRIERR(pbm_err_p->pbm_pcix_stat); 2006*0Sstevel@tonic-gate if (e) { 2007*0Sstevel@tonic-gate pbm_err_p->pbm_pri = PBM_PRIMARY; 2008*0Sstevel@tonic-gate pbm_err_p->pbm_err = e; 2009*0Sstevel@tonic-gate pbm_err_p->pbm_multi = PCIX_MULTI_ERR; 2010*0Sstevel@tonic-gate if (pcix_lookup_err_msgs(pci_p->pci_dip, ena, 2011*0Sstevel@tonic-gate pcix_stat_errs_tbl, pbm_err_p) == DDI_FM_FATAL) 2012*0Sstevel@tonic-gate fatal++; 2013*0Sstevel@tonic-gate else 2014*0Sstevel@tonic-gate nonfatal++; 2015*0Sstevel@tonic-gate } 2016*0Sstevel@tonic-gate 2017*0Sstevel@tonic-gate e = PBM_PCIX_TO_SECERR(pbm_err_p->pbm_pcix_stat); 2018*0Sstevel@tonic-gate if (e) { 2019*0Sstevel@tonic-gate pbm_err_p->pbm_pri = PBM_SECONDARY; 2020*0Sstevel@tonic-gate pbm_err_p->pbm_err = e; 2021*0Sstevel@tonic-gate pbm_err_p->pbm_multi = PCIX_MULTI_ERR; 2022*0Sstevel@tonic-gate if (pcix_lookup_err_msgs(pci_p->pci_dip, ena, 2023*0Sstevel@tonic-gate pcix_stat_errs_tbl, pbm_err_p) == DDI_FM_FATAL) 2024*0Sstevel@tonic-gate fatal++; 2025*0Sstevel@tonic-gate else 2026*0Sstevel@tonic-gate nonfatal++; 2027*0Sstevel@tonic-gate } 2028*0Sstevel@tonic-gate 2029*0Sstevel@tonic-gate if (!fatal && !nonfatal) 2030*0Sstevel@tonic-gate return (DDI_FM_OK); 2031*0Sstevel@tonic-gate else if (fatal) 2032*0Sstevel@tonic-gate return (DDI_FM_FATAL); 2033*0Sstevel@tonic-gate return (DDI_FM_NONFATAL); 2034*0Sstevel@tonic-gate } 2035*0Sstevel@tonic-gate 2036*0Sstevel@tonic-gate static pbm_fm_err_t pbm_err_tbl[] = { 2037*0Sstevel@tonic-gate PCI_MA, SCHIZO_PCI_AFSR_E_MA, PBM_PRIMARY, 2038*0Sstevel@tonic-gate FM_LOG_PCI, PCI_TARG_MA, 2039*0Sstevel@tonic-gate 2040*0Sstevel@tonic-gate PCI_SEC_MA, SCHIZO_PCI_AFSR_E_MA, PBM_SECONDARY, 2041*0Sstevel@tonic-gate FM_LOG_PBM, NULL, 2042*0Sstevel@tonic-gate 2043*0Sstevel@tonic-gate PCI_REC_TA, SCHIZO_PCI_AFSR_E_TA, PBM_PRIMARY, 2044*0Sstevel@tonic-gate FM_LOG_PCI, PCI_TARG_REC_TA, 2045*0Sstevel@tonic-gate 2046*0Sstevel@tonic-gate PCI_SEC_REC_TA, SCHIZO_PCI_AFSR_E_TA, PBM_SECONDARY, 2047*0Sstevel@tonic-gate FM_LOG_PBM, NULL, 2048*0Sstevel@tonic-gate 2049*0Sstevel@tonic-gate PCI_PBM_RETRY, SCHIZO_PCI_AFSR_E_RTRY, PBM_PRIMARY, 2050*0Sstevel@tonic-gate FM_LOG_PBM, PCI_PBM_TARG_RETRY, 2051*0Sstevel@tonic-gate 2052*0Sstevel@tonic-gate PCI_SEC_PBM_RETRY, SCHIZO_PCI_AFSR_E_RTRY, PBM_SECONDARY, 2053*0Sstevel@tonic-gate FM_LOG_PBM, NULL, 2054*0Sstevel@tonic-gate 2055*0Sstevel@tonic-gate PCI_MDPE, SCHIZO_PCI_AFSR_E_PERR, PBM_PRIMARY, 2056*0Sstevel@tonic-gate FM_LOG_PCI, PCI_TARG_MDPE, 2057*0Sstevel@tonic-gate 2058*0Sstevel@tonic-gate PCI_SEC_MDPE, SCHIZO_PCI_AFSR_E_PERR, PBM_SECONDARY, 2059*0Sstevel@tonic-gate FM_LOG_PBM, NULL, 2060*0Sstevel@tonic-gate 2061*0Sstevel@tonic-gate PCI_PBM_TTO, SCHIZO_PCI_AFSR_E_TTO, PBM_PRIMARY, 2062*0Sstevel@tonic-gate FM_LOG_PBM, PCI_PBM_TARG_TTO, 2063*0Sstevel@tonic-gate 2064*0Sstevel@tonic-gate PCI_SEC_PBM_TTO, SCHIZO_PCI_AFSR_E_TTO, PBM_SECONDARY, 2065*0Sstevel@tonic-gate FM_LOG_PBM, NULL, 2066*0Sstevel@tonic-gate 2067*0Sstevel@tonic-gate PCI_SCH_BUS_UNUSABLE_ERR, SCHIZO_PCI_AFSR_E_UNUSABLE, PBM_PRIMARY, 2068*0Sstevel@tonic-gate FM_LOG_PBM, NULL, 2069*0Sstevel@tonic-gate 2070*0Sstevel@tonic-gate PCI_SEC_SCH_BUS_UNUSABLE_ERR, SCHIZO_PCI_AFSR_E_UNUSABLE, PBM_SECONDARY, 2071*0Sstevel@tonic-gate FM_LOG_PBM, NULL, 2072*0Sstevel@tonic-gate 2073*0Sstevel@tonic-gate NULL, NULL, NULL, 2074*0Sstevel@tonic-gate NULL, NULL, 2075*0Sstevel@tonic-gate }; 2076*0Sstevel@tonic-gate 2077*0Sstevel@tonic-gate 2078*0Sstevel@tonic-gate /* 2079*0Sstevel@tonic-gate * pci_pbm_classify, called by pbm_afsr_report to classify piow afsr. 2080*0Sstevel@tonic-gate */ 2081*0Sstevel@tonic-gate int 2082*0Sstevel@tonic-gate pci_pbm_classify(pbm_errstate_t *pbm_err_p) 2083*0Sstevel@tonic-gate { 2084*0Sstevel@tonic-gate uint32_t err; 2085*0Sstevel@tonic-gate int nerr = 0; 2086*0Sstevel@tonic-gate int i; 2087*0Sstevel@tonic-gate 2088*0Sstevel@tonic-gate err = pbm_err_p->pbm_pri ? PBM_AFSR_TO_PRIERR(pbm_err_p->pbm_afsr): 2089*0Sstevel@tonic-gate PBM_AFSR_TO_SECERR(pbm_err_p->pbm_afsr); 2090*0Sstevel@tonic-gate 2091*0Sstevel@tonic-gate for (i = 0; pbm_err_tbl[i].pbm_err_class != NULL; i++) { 2092*0Sstevel@tonic-gate if ((err & pbm_err_tbl[i].pbm_reg_bit) && 2093*0Sstevel@tonic-gate (pbm_err_p->pbm_pri == pbm_err_tbl[i].pbm_pri)) { 2094*0Sstevel@tonic-gate if (pbm_err_tbl[i].pbm_flag == FM_LOG_PCI) 2095*0Sstevel@tonic-gate pbm_err_p->pbm_pci.pci_err_class = 2096*0Sstevel@tonic-gate pbm_err_tbl[i].pbm_err_class; 2097*0Sstevel@tonic-gate else 2098*0Sstevel@tonic-gate pbm_err_p->pbm_err_class = 2099*0Sstevel@tonic-gate pbm_err_tbl[i].pbm_err_class; 2100*0Sstevel@tonic-gate 2101*0Sstevel@tonic-gate pbm_err_p->pbm_terr_class = 2102*0Sstevel@tonic-gate pbm_err_tbl[i].pbm_terr_class; 2103*0Sstevel@tonic-gate pbm_err_p->pbm_log = pbm_err_tbl[i].pbm_flag; 2104*0Sstevel@tonic-gate nerr++; 2105*0Sstevel@tonic-gate break; 2106*0Sstevel@tonic-gate } 2107*0Sstevel@tonic-gate } 2108*0Sstevel@tonic-gate 2109*0Sstevel@tonic-gate return (nerr); 2110*0Sstevel@tonic-gate } 2111*0Sstevel@tonic-gate 2112*0Sstevel@tonic-gate /* 2113*0Sstevel@tonic-gate * Function used to handle and log IOMMU errors. Called by pci_pbm_err_handler, 2114*0Sstevel@tonic-gate * with pci_fm_mutex held. 2115*0Sstevel@tonic-gate */ 2116*0Sstevel@tonic-gate static int 2117*0Sstevel@tonic-gate iommu_err_handler(dev_info_t *dip, uint64_t ena, pbm_errstate_t *pbm_err_p) 2118*0Sstevel@tonic-gate { 2119*0Sstevel@tonic-gate pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip)); 2120*0Sstevel@tonic-gate iommu_t *iommu_p = pci_p->pci_iommu_p; 2121*0Sstevel@tonic-gate ecc_t *ecc_p = pci_p->pci_ecc_p; 2122*0Sstevel@tonic-gate uint64_t stat; 2123*0Sstevel@tonic-gate ushort_t ta_signalled; 2124*0Sstevel@tonic-gate int err = 0; 2125*0Sstevel@tonic-gate int fatal = 0; 2126*0Sstevel@tonic-gate int nonfatal = 0; 2127*0Sstevel@tonic-gate int ret; 2128*0Sstevel@tonic-gate 2129*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ecc_p->ecc_pci_cmn_p->pci_fm_mutex)); 2130*0Sstevel@tonic-gate if (!((stat = *iommu_p->iommu_ctrl_reg) & TOMATILLO_IOMMU_ERR)) { 2131*0Sstevel@tonic-gate pbm_err_p->pbm_err_class = PCI_SCH_MMU_ERR; 2132*0Sstevel@tonic-gate iommu_ereport_post(dip, ena, pbm_err_p); 2133*0Sstevel@tonic-gate return (DDI_FM_NONFATAL); 2134*0Sstevel@tonic-gate } 2135*0Sstevel@tonic-gate 2136*0Sstevel@tonic-gate /* 2137*0Sstevel@tonic-gate * Need to make sure a Target Abort was signalled to the device if 2138*0Sstevel@tonic-gate * we have any hope of recovering. Tomatillo does not send a TA for 2139*0Sstevel@tonic-gate * DMA Writes that result in a Translation Error, thus fooling the 2140*0Sstevel@tonic-gate * device into believing everything is as it expects. Ignorance 2141*0Sstevel@tonic-gate * is bliss, but knowledge is power. 2142*0Sstevel@tonic-gate */ 2143*0Sstevel@tonic-gate ta_signalled = pbm_err_p->pbm_pci.pci_cfg_stat & 2144*0Sstevel@tonic-gate PCI_STAT_S_TARG_AB; 2145*0Sstevel@tonic-gate 2146*0Sstevel@tonic-gate if (stat & TOMATILLO_IOMMU_ERR_ILLTSBTBW) { 2147*0Sstevel@tonic-gate pbm_err_p->pbm_err_class = PCI_TOM_MMU_BAD_TSBTBW; 2148*0Sstevel@tonic-gate err = 1; 2149*0Sstevel@tonic-gate iommu_ereport_post(dip, ena, pbm_err_p); 2150*0Sstevel@tonic-gate if (!ta_signalled) 2151*0Sstevel@tonic-gate fatal++; 2152*0Sstevel@tonic-gate else 2153*0Sstevel@tonic-gate nonfatal++; 2154*0Sstevel@tonic-gate } 2155*0Sstevel@tonic-gate 2156*0Sstevel@tonic-gate if (stat & TOMATILLO_IOMMU_ERR_BAD_VA) { 2157*0Sstevel@tonic-gate pbm_err_p->pbm_err_class = PCI_TOM_MMU_BAD_VA; 2158*0Sstevel@tonic-gate err = 1; 2159*0Sstevel@tonic-gate iommu_ereport_post(dip, ena, pbm_err_p); 2160*0Sstevel@tonic-gate if (!ta_signalled) 2161*0Sstevel@tonic-gate fatal++; 2162*0Sstevel@tonic-gate else 2163*0Sstevel@tonic-gate nonfatal++; 2164*0Sstevel@tonic-gate } 2165*0Sstevel@tonic-gate 2166*0Sstevel@tonic-gate if (!err) { 2167*0Sstevel@tonic-gate stat = ((stat & TOMATILLO_IOMMU_ERRSTS) >> 2168*0Sstevel@tonic-gate TOMATILLO_IOMMU_ERRSTS_SHIFT); 2169*0Sstevel@tonic-gate switch (stat) { 2170*0Sstevel@tonic-gate case TOMATILLO_IOMMU_PROTECTION_ERR: 2171*0Sstevel@tonic-gate pbm_err_p->pbm_err_class = PCI_TOM_MMU_PROT_ERR; 2172*0Sstevel@tonic-gate iommu_ereport_post(dip, ena, pbm_err_p); 2173*0Sstevel@tonic-gate fatal++; 2174*0Sstevel@tonic-gate break; 2175*0Sstevel@tonic-gate case TOMATILLO_IOMMU_INVALID_ERR: 2176*0Sstevel@tonic-gate pbm_err_p->pbm_err_class = PCI_TOM_MMU_INVAL_ERR; 2177*0Sstevel@tonic-gate /* 2178*0Sstevel@tonic-gate * Fault the address in iommu_tfar 2179*0Sstevel@tonic-gate * register to inform target driver of error 2180*0Sstevel@tonic-gate */ 2181*0Sstevel@tonic-gate ret = pci_handle_lookup(pci_p->pci_dip, DMA_HANDLE, 2182*0Sstevel@tonic-gate ena, (void *)&pbm_err_p->pbm_iommu.iommu_tfar); 2183*0Sstevel@tonic-gate 2184*0Sstevel@tonic-gate if (ret == DDI_FM_NONFATAL) 2185*0Sstevel@tonic-gate if (ta_signalled) 2186*0Sstevel@tonic-gate nonfatal++; 2187*0Sstevel@tonic-gate else 2188*0Sstevel@tonic-gate fatal++; 2189*0Sstevel@tonic-gate else 2190*0Sstevel@tonic-gate fatal++; 2191*0Sstevel@tonic-gate iommu_ereport_post(dip, ena, pbm_err_p); 2192*0Sstevel@tonic-gate break; 2193*0Sstevel@tonic-gate case TOMATILLO_IOMMU_TIMEOUT_ERR: 2194*0Sstevel@tonic-gate pbm_err_p->pbm_err_class = PCI_TOM_MMU_TO_ERR; 2195*0Sstevel@tonic-gate fatal++; 2196*0Sstevel@tonic-gate iommu_ereport_post(dip, ena, pbm_err_p); 2197*0Sstevel@tonic-gate break; 2198*0Sstevel@tonic-gate case TOMATILLO_IOMMU_ECC_ERR: 2199*0Sstevel@tonic-gate pbm_err_p->pbm_err_class = PCI_TOM_MMU_UE; 2200*0Sstevel@tonic-gate iommu_ereport_post(dip, ena, pbm_err_p); 2201*0Sstevel@tonic-gate break; 2202*0Sstevel@tonic-gate } 2203*0Sstevel@tonic-gate } 2204*0Sstevel@tonic-gate 2205*0Sstevel@tonic-gate if (fatal) 2206*0Sstevel@tonic-gate return (DDI_FM_FATAL); 2207*0Sstevel@tonic-gate else if (nonfatal) 2208*0Sstevel@tonic-gate return (DDI_FM_NONFATAL); 2209*0Sstevel@tonic-gate 2210*0Sstevel@tonic-gate return (DDI_FM_OK); 2211*0Sstevel@tonic-gate } 2212*0Sstevel@tonic-gate 2213*0Sstevel@tonic-gate int 2214*0Sstevel@tonic-gate pci_check_error(pci_t *pci_p) 2215*0Sstevel@tonic-gate { 2216*0Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p; 2217*0Sstevel@tonic-gate uint16_t pci_cfg_stat; 2218*0Sstevel@tonic-gate uint64_t pbm_ctl_stat, pbm_afsr, pbm_pcix_stat; 2219*0Sstevel@tonic-gate caddr_t a = pci_p->pci_address[0]; 2220*0Sstevel@tonic-gate uint64_t *pbm_pcix_stat_reg; 2221*0Sstevel@tonic-gate 2222*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pci_p->pci_common_p->pci_fm_mutex)); 2223*0Sstevel@tonic-gate 2224*0Sstevel@tonic-gate pci_cfg_stat = pbm_p->pbm_config_header->ch_status_reg; 2225*0Sstevel@tonic-gate pbm_ctl_stat = *pbm_p->pbm_ctrl_reg; 2226*0Sstevel@tonic-gate pbm_afsr = *pbm_p->pbm_async_flt_status_reg; 2227*0Sstevel@tonic-gate 2228*0Sstevel@tonic-gate if ((pci_cfg_stat & (PCI_STAT_S_PERROR | PCI_STAT_S_TARG_AB | 2229*0Sstevel@tonic-gate PCI_STAT_R_TARG_AB | PCI_STAT_R_MAST_AB | 2230*0Sstevel@tonic-gate PCI_STAT_S_SYSERR | PCI_STAT_PERROR)) || 2231*0Sstevel@tonic-gate (pbm_ctl_stat & (SCHIZO_PCI_CTRL_BUS_UNUSABLE | 2232*0Sstevel@tonic-gate TOMATILLO_PCI_CTRL_PCI_DTO_ERR | 2233*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_PCI_TTO_ERR | 2234*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_PCI_RTRY_ERR | 2235*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_PCI_MMU_ERR | 2236*0Sstevel@tonic-gate COMMON_PCI_CTRL_SBH_ERR | 2237*0Sstevel@tonic-gate COMMON_PCI_CTRL_SERR)) || 2238*0Sstevel@tonic-gate (PBM_AFSR_TO_PRIERR(pbm_afsr))) 2239*0Sstevel@tonic-gate return (1); 2240*0Sstevel@tonic-gate 2241*0Sstevel@tonic-gate if ((CHIP_TYPE(pci_p) == PCI_CHIP_XMITS) && 2242*0Sstevel@tonic-gate (pbm_ctl_stat & XMITS_PCI_CTRL_X_MODE)) { 2243*0Sstevel@tonic-gate 2244*0Sstevel@tonic-gate pbm_pcix_stat_reg = (uint64_t *)(a + 2245*0Sstevel@tonic-gate XMITS_PCI_X_ERROR_STATUS_REG_OFFSET); 2246*0Sstevel@tonic-gate 2247*0Sstevel@tonic-gate pbm_pcix_stat = *pbm_pcix_stat_reg; 2248*0Sstevel@tonic-gate 2249*0Sstevel@tonic-gate if (PBM_PCIX_TO_PRIERR(pbm_pcix_stat)) 2250*0Sstevel@tonic-gate return (1); 2251*0Sstevel@tonic-gate 2252*0Sstevel@tonic-gate if (pbm_pcix_stat & XMITS_PCIX_STAT_PERR_RECOV_INT) 2253*0Sstevel@tonic-gate return (1); 2254*0Sstevel@tonic-gate } 2255*0Sstevel@tonic-gate 2256*0Sstevel@tonic-gate return (0); 2257*0Sstevel@tonic-gate 2258*0Sstevel@tonic-gate } 2259*0Sstevel@tonic-gate 2260*0Sstevel@tonic-gate static pbm_fm_err_t pci_pbm_err_tbl[] = { 2261*0Sstevel@tonic-gate PCI_PBM_RETRY, SCHIZO_PCI_CTRL_PCI_RTRY_ERR, 2262*0Sstevel@tonic-gate NULL, PBM_NONFATAL, PCI_PBM_TARG_RETRY, 2263*0Sstevel@tonic-gate 2264*0Sstevel@tonic-gate PCI_PBM_TTO, SCHIZO_PCI_CTRL_PCI_TTO_ERR, 2265*0Sstevel@tonic-gate NULL, PBM_NONFATAL, PCI_PBM_TARG_TTO, 2266*0Sstevel@tonic-gate 2267*0Sstevel@tonic-gate PCI_SCH_BUS_UNUSABLE_ERR, SCHIZO_PCI_CTRL_BUS_UNUSABLE, 2268*0Sstevel@tonic-gate NULL, PBM_NONFATAL, NULL, 2269*0Sstevel@tonic-gate 2270*0Sstevel@tonic-gate NULL, NULL, 2271*0Sstevel@tonic-gate NULL, NULL, NULL 2272*0Sstevel@tonic-gate }; 2273*0Sstevel@tonic-gate 2274*0Sstevel@tonic-gate /* 2275*0Sstevel@tonic-gate * Function used to log all PCI/PBM/IOMMU errors found in the system. 2276*0Sstevel@tonic-gate * It is called by the pbm_error_intr as well as the pci_err_callback(trap 2277*0Sstevel@tonic-gate * callback). To protect access we hold the pci_fm_mutex when calling 2278*0Sstevel@tonic-gate * this function. 2279*0Sstevel@tonic-gate */ 2280*0Sstevel@tonic-gate int 2281*0Sstevel@tonic-gate pci_pbm_err_handler(dev_info_t *dip, ddi_fm_error_t *derr, 2282*0Sstevel@tonic-gate const void *impl_data, int caller) 2283*0Sstevel@tonic-gate { 2284*0Sstevel@tonic-gate int fatal = 0; 2285*0Sstevel@tonic-gate int nonfatal = 0; 2286*0Sstevel@tonic-gate int unknown = 0; 2287*0Sstevel@tonic-gate int rserr = 0; 2288*0Sstevel@tonic-gate uint32_t prierr, secerr; 2289*0Sstevel@tonic-gate pbm_errstate_t pbm_err; 2290*0Sstevel@tonic-gate char buf[FM_MAX_CLASS]; 2291*0Sstevel@tonic-gate pci_t *pci_p = (pci_t *)impl_data; 2292*0Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p; 2293*0Sstevel@tonic-gate pci_target_err_t tgt_err; 2294*0Sstevel@tonic-gate int i, ret = 0; 2295*0Sstevel@tonic-gate 2296*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pci_p->pci_common_p->pci_fm_mutex)); 2297*0Sstevel@tonic-gate pci_pbm_errstate_get(pci_p, &pbm_err); 2298*0Sstevel@tonic-gate 2299*0Sstevel@tonic-gate derr->fme_ena = derr->fme_ena ? derr->fme_ena : 2300*0Sstevel@tonic-gate fm_ena_generate(0, FM_ENA_FMT1); 2301*0Sstevel@tonic-gate 2302*0Sstevel@tonic-gate prierr = PBM_AFSR_TO_PRIERR(pbm_err.pbm_afsr); 2303*0Sstevel@tonic-gate secerr = PBM_AFSR_TO_SECERR(pbm_err.pbm_afsr); 2304*0Sstevel@tonic-gate 2305*0Sstevel@tonic-gate if (derr->fme_flag == DDI_FM_ERR_EXPECTED) { 2306*0Sstevel@tonic-gate if (caller == PCI_TRAP_CALL) { 2307*0Sstevel@tonic-gate /* 2308*0Sstevel@tonic-gate * For ddi_caut_get treat all events as nonfatal. 2309*0Sstevel@tonic-gate * The trampoline will set err_ena = 0, err_status = 2310*0Sstevel@tonic-gate * NONFATAL. We only really call this function so that 2311*0Sstevel@tonic-gate * pci_clear_error() and ndi_fm_handler_dispatch() will 2312*0Sstevel@tonic-gate * get called. 2313*0Sstevel@tonic-gate */ 2314*0Sstevel@tonic-gate derr->fme_status = DDI_FM_NONFATAL; 2315*0Sstevel@tonic-gate nonfatal++; 2316*0Sstevel@tonic-gate goto done; 2317*0Sstevel@tonic-gate } else { 2318*0Sstevel@tonic-gate /* 2319*0Sstevel@tonic-gate * For ddi_caut_put treat all events as nonfatal. Here 2320*0Sstevel@tonic-gate * we have the handle and can call ndi_fm_acc_err_set(). 2321*0Sstevel@tonic-gate */ 2322*0Sstevel@tonic-gate derr->fme_status = DDI_FM_NONFATAL; 2323*0Sstevel@tonic-gate ndi_fm_acc_err_set(pbm_p->pbm_excl_handle, derr); 2324*0Sstevel@tonic-gate nonfatal++; 2325*0Sstevel@tonic-gate goto done; 2326*0Sstevel@tonic-gate } 2327*0Sstevel@tonic-gate } else if (derr->fme_flag == DDI_FM_ERR_PEEK) { 2328*0Sstevel@tonic-gate /* 2329*0Sstevel@tonic-gate * For ddi_peek treat all events as nonfatal. We only 2330*0Sstevel@tonic-gate * really call this function so that pci_clear_error() 2331*0Sstevel@tonic-gate * and ndi_fm_handler_dispatch() will get called. 2332*0Sstevel@tonic-gate */ 2333*0Sstevel@tonic-gate nonfatal++; 2334*0Sstevel@tonic-gate goto done; 2335*0Sstevel@tonic-gate } else if (derr->fme_flag == DDI_FM_ERR_POKE) { 2336*0Sstevel@tonic-gate /* 2337*0Sstevel@tonic-gate * For ddi_poke we can treat as nonfatal if the 2338*0Sstevel@tonic-gate * following conditions are met : 2339*0Sstevel@tonic-gate * 1. Make sure only primary error is MA/TA 2340*0Sstevel@tonic-gate * 2. Make sure no secondary error bits set 2341*0Sstevel@tonic-gate * 3. check pci config header stat reg to see MA/TA is 2342*0Sstevel@tonic-gate * logged. We cannot verify only MA/TA is recorded 2343*0Sstevel@tonic-gate * since it gets much more complicated when a 2344*0Sstevel@tonic-gate * PCI-to-PCI bridge is present. 2345*0Sstevel@tonic-gate */ 2346*0Sstevel@tonic-gate if ((prierr == SCHIZO_PCI_AFSR_E_MA) && !secerr && 2347*0Sstevel@tonic-gate (pbm_err.pbm_pci.pci_cfg_stat & PCI_STAT_R_MAST_AB)) { 2348*0Sstevel@tonic-gate nonfatal++; 2349*0Sstevel@tonic-gate goto done; 2350*0Sstevel@tonic-gate } else if ((*pbm_p->pbm_ctrl_reg & XMITS_PCI_CTRL_X_MODE) && 2351*0Sstevel@tonic-gate pcix_ma_behind_bridge(&pbm_err)) { 2352*0Sstevel@tonic-gate /* 2353*0Sstevel@tonic-gate * MAs behind a PCI-X bridge get sent back to 2354*0Sstevel@tonic-gate * the host as a Split Completion Error Message. 2355*0Sstevel@tonic-gate * We handle this the same as the above check. 2356*0Sstevel@tonic-gate */ 2357*0Sstevel@tonic-gate nonfatal++; 2358*0Sstevel@tonic-gate goto done; 2359*0Sstevel@tonic-gate } 2360*0Sstevel@tonic-gate if ((prierr == SCHIZO_PCI_AFSR_E_TA) && !secerr && 2361*0Sstevel@tonic-gate (pbm_err.pbm_pci.pci_cfg_stat & PCI_STAT_R_TARG_AB)) { 2362*0Sstevel@tonic-gate nonfatal++; 2363*0Sstevel@tonic-gate goto done; 2364*0Sstevel@tonic-gate } 2365*0Sstevel@tonic-gate } 2366*0Sstevel@tonic-gate 2367*0Sstevel@tonic-gate DEBUG2(DBG_ERR_INTR, dip, "pci_pbm_err_handler: prierr=0x%x " 2368*0Sstevel@tonic-gate "secerr=0x%x", prierr, secerr); 2369*0Sstevel@tonic-gate 2370*0Sstevel@tonic-gate if (prierr || secerr) { 2371*0Sstevel@tonic-gate ret = pbm_afsr_report(dip, derr->fme_ena, &pbm_err); 2372*0Sstevel@tonic-gate if (ret == DDI_FM_FATAL) 2373*0Sstevel@tonic-gate fatal++; 2374*0Sstevel@tonic-gate else 2375*0Sstevel@tonic-gate nonfatal++; 2376*0Sstevel@tonic-gate } 2377*0Sstevel@tonic-gate if ((ret = pcix_log_pbm(pci_p, derr->fme_ena, &pbm_err)) 2378*0Sstevel@tonic-gate == DDI_FM_FATAL) 2379*0Sstevel@tonic-gate fatal++; 2380*0Sstevel@tonic-gate else if (ret == DDI_FM_NONFATAL) 2381*0Sstevel@tonic-gate nonfatal++; 2382*0Sstevel@tonic-gate 2383*0Sstevel@tonic-gate if ((ret = pci_cfg_report(dip, derr, &pbm_err.pbm_pci, caller, prierr)) 2384*0Sstevel@tonic-gate == DDI_FM_FATAL) 2385*0Sstevel@tonic-gate fatal++; 2386*0Sstevel@tonic-gate else if (ret == DDI_FM_NONFATAL) 2387*0Sstevel@tonic-gate nonfatal++; 2388*0Sstevel@tonic-gate 2389*0Sstevel@tonic-gate for (i = 0; pci_pbm_err_tbl[i].pbm_err_class != NULL; i++) { 2390*0Sstevel@tonic-gate if ((pbm_err.pbm_ctl_stat & pci_pbm_err_tbl[i].pbm_reg_bit) && 2391*0Sstevel@tonic-gate !prierr) { 2392*0Sstevel@tonic-gate pbm_err.pbm_err_class = 2393*0Sstevel@tonic-gate pci_pbm_err_tbl[i].pbm_err_class; 2394*0Sstevel@tonic-gate pbm_ereport_post(dip, derr->fme_ena, &pbm_err); 2395*0Sstevel@tonic-gate if (pci_pbm_err_tbl[i].pbm_flag) 2396*0Sstevel@tonic-gate fatal++; 2397*0Sstevel@tonic-gate else 2398*0Sstevel@tonic-gate nonfatal++; 2399*0Sstevel@tonic-gate if (caller == PCI_TRAP_CALL && 2400*0Sstevel@tonic-gate pci_pbm_err_tbl[i].pbm_terr_class) { 2401*0Sstevel@tonic-gate tgt_err.tgt_err_ena = derr->fme_ena; 2402*0Sstevel@tonic-gate tgt_err.tgt_err_class = 2403*0Sstevel@tonic-gate pci_pbm_err_tbl[i].pbm_terr_class; 2404*0Sstevel@tonic-gate tgt_err.tgt_bridge_type = 2405*0Sstevel@tonic-gate pbm_err.pbm_bridge_type; 2406*0Sstevel@tonic-gate tgt_err.tgt_err_addr = 2407*0Sstevel@tonic-gate (uint64_t)derr->fme_bus_specific; 2408*0Sstevel@tonic-gate errorq_dispatch(pci_target_queue, 2409*0Sstevel@tonic-gate (void *)&tgt_err, sizeof (pci_target_err_t), 2410*0Sstevel@tonic-gate ERRORQ_ASYNC); 2411*0Sstevel@tonic-gate } 2412*0Sstevel@tonic-gate } 2413*0Sstevel@tonic-gate } 2414*0Sstevel@tonic-gate 2415*0Sstevel@tonic-gate if ((pbm_err.pbm_ctl_stat & COMMON_PCI_CTRL_SBH_ERR) && 2416*0Sstevel@tonic-gate (CHIP_TYPE(pci_p) != PCI_CHIP_TOMATILLO)) { 2417*0Sstevel@tonic-gate pbm_err.pbm_err_class = PCI_SCH_SBH; 2418*0Sstevel@tonic-gate pbm_ereport_post(dip, derr->fme_ena, &pbm_err); 2419*0Sstevel@tonic-gate if (pci_panic_on_sbh_errors) 2420*0Sstevel@tonic-gate fatal++; 2421*0Sstevel@tonic-gate else 2422*0Sstevel@tonic-gate nonfatal++; 2423*0Sstevel@tonic-gate } 2424*0Sstevel@tonic-gate 2425*0Sstevel@tonic-gate /* 2426*0Sstevel@tonic-gate * PBM Received System Error - During any transaction, or 2427*0Sstevel@tonic-gate * at any point on the bus, some device may detect a critical 2428*0Sstevel@tonic-gate * error and signal a system error to the system. 2429*0Sstevel@tonic-gate */ 2430*0Sstevel@tonic-gate if (pbm_err.pbm_ctl_stat & COMMON_PCI_CTRL_SERR) { 2431*0Sstevel@tonic-gate /* 2432*0Sstevel@tonic-gate * may be expected (master abort from pci-pci bridge during 2433*0Sstevel@tonic-gate * poke will generate SERR) 2434*0Sstevel@tonic-gate */ 2435*0Sstevel@tonic-gate if (derr->fme_flag != DDI_FM_ERR_POKE) { 2436*0Sstevel@tonic-gate DEBUG1(DBG_ERR_INTR, dip, "pci_pbm_err_handler: " 2437*0Sstevel@tonic-gate "ereport_post: %s", buf); 2438*0Sstevel@tonic-gate (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", 2439*0Sstevel@tonic-gate PCI_ERROR_SUBCLASS, PCI_REC_SERR); 2440*0Sstevel@tonic-gate ddi_fm_ereport_post(dip, buf, derr->fme_ena, 2441*0Sstevel@tonic-gate DDI_NOSLEEP, FM_VERSION, DATA_TYPE_UINT8, 0, 2442*0Sstevel@tonic-gate PCI_CONFIG_STATUS, DATA_TYPE_UINT16, 2443*0Sstevel@tonic-gate pbm_err.pbm_pci.pci_cfg_stat, PCI_CONFIG_COMMAND, 2444*0Sstevel@tonic-gate DATA_TYPE_UINT16, pbm_err.pbm_pci.pci_cfg_comm, 2445*0Sstevel@tonic-gate PCI_PA, DATA_TYPE_UINT64, (uint64_t)0, NULL); 2446*0Sstevel@tonic-gate } 2447*0Sstevel@tonic-gate rserr++; 2448*0Sstevel@tonic-gate } 2449*0Sstevel@tonic-gate 2450*0Sstevel@tonic-gate /* 2451*0Sstevel@tonic-gate * PCI Retry Timeout - Device fails to retry deferred 2452*0Sstevel@tonic-gate * transaction within timeout. Only Tomatillo 2453*0Sstevel@tonic-gate */ 2454*0Sstevel@tonic-gate if (pbm_err.pbm_ctl_stat & TOMATILLO_PCI_CTRL_PCI_DTO_ERR) { 2455*0Sstevel@tonic-gate if (pci_dto_fault_warn == CE_PANIC) 2456*0Sstevel@tonic-gate fatal++; 2457*0Sstevel@tonic-gate else 2458*0Sstevel@tonic-gate nonfatal++; 2459*0Sstevel@tonic-gate 2460*0Sstevel@tonic-gate (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", 2461*0Sstevel@tonic-gate PCI_ERROR_SUBCLASS, PCI_DTO); 2462*0Sstevel@tonic-gate ddi_fm_ereport_post(dip, buf, derr->fme_ena, DDI_NOSLEEP, 2463*0Sstevel@tonic-gate FM_VERSION, DATA_TYPE_UINT8, 0, 2464*0Sstevel@tonic-gate PCI_CONFIG_STATUS, DATA_TYPE_UINT16, 2465*0Sstevel@tonic-gate pbm_err.pbm_pci.pci_cfg_stat, 2466*0Sstevel@tonic-gate PCI_CONFIG_COMMAND, DATA_TYPE_UINT16, 2467*0Sstevel@tonic-gate pbm_err.pbm_pci.pci_cfg_comm, 2468*0Sstevel@tonic-gate PCI_PA, DATA_TYPE_UINT64, (uint64_t)0, NULL); 2469*0Sstevel@tonic-gate } 2470*0Sstevel@tonic-gate 2471*0Sstevel@tonic-gate /* 2472*0Sstevel@tonic-gate * PBM Detected Data Parity Error - DPE detected during a DMA Write 2473*0Sstevel@tonic-gate * or PIO Read. Later case is taken care of by cpu_deferred_error 2474*0Sstevel@tonic-gate * and sent here to be logged. 2475*0Sstevel@tonic-gate */ 2476*0Sstevel@tonic-gate if ((pbm_err.pbm_pci.pci_cfg_stat & PCI_STAT_PERROR) && 2477*0Sstevel@tonic-gate !(pbm_err.pbm_pci.pci_cfg_stat & PCI_STAT_S_SYSERR)) { 2478*0Sstevel@tonic-gate /* 2479*0Sstevel@tonic-gate * If we have an address then fault 2480*0Sstevel@tonic-gate * it, if not probe for errant device 2481*0Sstevel@tonic-gate */ 2482*0Sstevel@tonic-gate ret = DDI_FM_FATAL; 2483*0Sstevel@tonic-gate if (caller != PCI_TRAP_CALL) { 2484*0Sstevel@tonic-gate if (pbm_err.pbm_va_log) 2485*0Sstevel@tonic-gate ret = pci_handle_lookup(dip, DMA_HANDLE, 2486*0Sstevel@tonic-gate derr->fme_ena, 2487*0Sstevel@tonic-gate (void *)&pbm_err.pbm_va_log); 2488*0Sstevel@tonic-gate if (ret == DDI_FM_NONFATAL) 2489*0Sstevel@tonic-gate nonfatal++; 2490*0Sstevel@tonic-gate else 2491*0Sstevel@tonic-gate fatal++; 2492*0Sstevel@tonic-gate } else 2493*0Sstevel@tonic-gate nonfatal++; 2494*0Sstevel@tonic-gate 2495*0Sstevel@tonic-gate } 2496*0Sstevel@tonic-gate 2497*0Sstevel@tonic-gate /* PBM Detected IOMMU Error */ 2498*0Sstevel@tonic-gate if (pbm_err.pbm_ctl_stat & SCHIZO_PCI_CTRL_PCI_MMU_ERR) { 2499*0Sstevel@tonic-gate if (iommu_err_handler(dip, derr->fme_ena, &pbm_err) 2500*0Sstevel@tonic-gate == DDI_FM_FATAL) 2501*0Sstevel@tonic-gate fatal++; 2502*0Sstevel@tonic-gate else 2503*0Sstevel@tonic-gate nonfatal++; 2504*0Sstevel@tonic-gate } 2505*0Sstevel@tonic-gate 2506*0Sstevel@tonic-gate done: 2507*0Sstevel@tonic-gate ret = ndi_fm_handler_dispatch(dip, NULL, derr); 2508*0Sstevel@tonic-gate if (ret == DDI_FM_FATAL) { 2509*0Sstevel@tonic-gate fatal++; 2510*0Sstevel@tonic-gate } else if (ret == DDI_FM_NONFATAL) { 2511*0Sstevel@tonic-gate nonfatal++; 2512*0Sstevel@tonic-gate } else if (ret == DDI_FM_UNKNOWN) { 2513*0Sstevel@tonic-gate unknown++; 2514*0Sstevel@tonic-gate } 2515*0Sstevel@tonic-gate 2516*0Sstevel@tonic-gate /* 2517*0Sstevel@tonic-gate * RSERR not claimed as nonfatal by a child is considered fatal 2518*0Sstevel@tonic-gate */ 2519*0Sstevel@tonic-gate if (rserr && ret != DDI_FM_NONFATAL) 2520*0Sstevel@tonic-gate fatal++; 2521*0Sstevel@tonic-gate 2522*0Sstevel@tonic-gate /* Cleanup and reset error bits */ 2523*0Sstevel@tonic-gate pci_clear_error(pci_p, &pbm_err); 2524*0Sstevel@tonic-gate 2525*0Sstevel@tonic-gate return (fatal ? DDI_FM_FATAL : (nonfatal ? DDI_FM_NONFATAL : 2526*0Sstevel@tonic-gate (unknown ? DDI_FM_UNKNOWN : DDI_FM_OK))); 2527*0Sstevel@tonic-gate } 2528*0Sstevel@tonic-gate 2529*0Sstevel@tonic-gate /* 2530*0Sstevel@tonic-gate * Function returns TRUE if a Primary error is Split Completion Error 2531*0Sstevel@tonic-gate * that indicates a Master Abort occured behind a PCI-X bridge. 2532*0Sstevel@tonic-gate * This function should only be called for busses running in PCI-X mode. 2533*0Sstevel@tonic-gate */ 2534*0Sstevel@tonic-gate static int 2535*0Sstevel@tonic-gate pcix_ma_behind_bridge(pbm_errstate_t *pbm_err_p) 2536*0Sstevel@tonic-gate { 2537*0Sstevel@tonic-gate uint64_t msg; 2538*0Sstevel@tonic-gate 2539*0Sstevel@tonic-gate if (pbm_err_p->pbm_afsr & XMITS_PCI_X_AFSR_S_SC_ERR) 2540*0Sstevel@tonic-gate return (0); 2541*0Sstevel@tonic-gate 2542*0Sstevel@tonic-gate if (pbm_err_p->pbm_afsr & XMITS_PCI_X_AFSR_P_SC_ERR) { 2543*0Sstevel@tonic-gate msg = (pbm_err_p->pbm_afsr >> XMITS_PCI_X_P_MSG_SHIFT) & 2544*0Sstevel@tonic-gate XMITS_PCIX_MSG_MASK; 2545*0Sstevel@tonic-gate if (msg & PCIX_CLASS_BRIDGE) 2546*0Sstevel@tonic-gate if (msg & PCIX_BRIDGE_MASTER_ABORT) { 2547*0Sstevel@tonic-gate return (1); 2548*0Sstevel@tonic-gate } 2549*0Sstevel@tonic-gate } 2550*0Sstevel@tonic-gate 2551*0Sstevel@tonic-gate return (0); 2552*0Sstevel@tonic-gate } 2553*0Sstevel@tonic-gate 2554*0Sstevel@tonic-gate /* 2555*0Sstevel@tonic-gate * Function used to gather PBM/PCI/IOMMU error state for the 2556*0Sstevel@tonic-gate * pci_pbm_err_handler and the cb_buserr_intr. This function must be 2557*0Sstevel@tonic-gate * called while pci_fm_mutex is held. 2558*0Sstevel@tonic-gate */ 2559*0Sstevel@tonic-gate static void 2560*0Sstevel@tonic-gate pci_pbm_errstate_get(pci_t *pci_p, pbm_errstate_t *pbm_err_p) 2561*0Sstevel@tonic-gate { 2562*0Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p; 2563*0Sstevel@tonic-gate iommu_t *iommu_p = pci_p->pci_iommu_p; 2564*0Sstevel@tonic-gate caddr_t a = pci_p->pci_address[0]; 2565*0Sstevel@tonic-gate uint64_t *pbm_pcix_stat_reg; 2566*0Sstevel@tonic-gate 2567*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pci_p->pci_common_p->pci_fm_mutex)); 2568*0Sstevel@tonic-gate bzero(pbm_err_p, sizeof (pbm_errstate_t)); 2569*0Sstevel@tonic-gate 2570*0Sstevel@tonic-gate /* 2571*0Sstevel@tonic-gate * Capture all pbm error state for later logging 2572*0Sstevel@tonic-gate */ 2573*0Sstevel@tonic-gate pbm_err_p->pbm_bridge_type = PCI_BRIDGE_TYPE(pci_p->pci_common_p); 2574*0Sstevel@tonic-gate 2575*0Sstevel@tonic-gate pbm_err_p->pbm_pci.pci_cfg_stat = 2576*0Sstevel@tonic-gate pbm_p->pbm_config_header->ch_status_reg; 2577*0Sstevel@tonic-gate pbm_err_p->pbm_ctl_stat = *pbm_p->pbm_ctrl_reg; 2578*0Sstevel@tonic-gate pbm_err_p->pbm_afsr = *pbm_p->pbm_async_flt_status_reg; 2579*0Sstevel@tonic-gate pbm_err_p->pbm_afar = *pbm_p->pbm_async_flt_addr_reg; 2580*0Sstevel@tonic-gate pbm_err_p->pbm_iommu.iommu_stat = *iommu_p->iommu_ctrl_reg; 2581*0Sstevel@tonic-gate pbm_err_p->pbm_pci.pci_cfg_comm = 2582*0Sstevel@tonic-gate pbm_p->pbm_config_header->ch_command_reg; 2583*0Sstevel@tonic-gate pbm_err_p->pbm_pci.pci_pa = *pbm_p->pbm_async_flt_addr_reg; 2584*0Sstevel@tonic-gate 2585*0Sstevel@tonic-gate /* 2586*0Sstevel@tonic-gate * Record errant slot for Xmits and Schizo 2587*0Sstevel@tonic-gate * Not stored in Tomatillo 2588*0Sstevel@tonic-gate */ 2589*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) == PCI_CHIP_XMITS || 2590*0Sstevel@tonic-gate CHIP_TYPE(pci_p) == PCI_CHIP_SCHIZO) { 2591*0Sstevel@tonic-gate pbm_err_p->pbm_err_sl = (pbm_err_p->pbm_ctl_stat & 2592*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_ERR_SLOT) >> 2593*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_ERR_SLOT_SHIFT; 2594*0Sstevel@tonic-gate 2595*0Sstevel@tonic-gate /* 2596*0Sstevel@tonic-gate * The bit 51 on XMITS rev1.0 is same as 2597*0Sstevel@tonic-gate * SCHIZO_PCI_CTRL_ERR_SLOT_LOCK on schizo2.3. But 2598*0Sstevel@tonic-gate * this bit needs to be cleared to be able to latch 2599*0Sstevel@tonic-gate * the slot info on next fault. 2600*0Sstevel@tonic-gate * But in XMITS Rev2.0, this bit indicates a DMA Write 2601*0Sstevel@tonic-gate * Parity error. 2602*0Sstevel@tonic-gate */ 2603*0Sstevel@tonic-gate if (pbm_err_p->pbm_ctl_stat & XMITS_PCI_CTRL_DMA_WR_PERR) { 2604*0Sstevel@tonic-gate if ((PCI_CHIP_ID(pci_p) == XMITS_VER_10) || 2605*0Sstevel@tonic-gate (PCI_CHIP_ID(pci_p) <= SCHIZO_VER_23)) { 2606*0Sstevel@tonic-gate /* 2607*0Sstevel@tonic-gate * top 32 bits are W1C and we just want to 2608*0Sstevel@tonic-gate * clear SLOT_LOCK. Leave bottom 32 bits 2609*0Sstevel@tonic-gate * unchanged 2610*0Sstevel@tonic-gate */ 2611*0Sstevel@tonic-gate *pbm_p->pbm_ctrl_reg = 2612*0Sstevel@tonic-gate pbm_err_p->pbm_ctl_stat & 2613*0Sstevel@tonic-gate (SCHIZO_PCI_CTRL_ERR_SLOT_LOCK | 2614*0Sstevel@tonic-gate 0xffffffff); 2615*0Sstevel@tonic-gate pbm_err_p->pbm_ctl_stat = 2616*0Sstevel@tonic-gate *pbm_p->pbm_ctrl_reg; 2617*0Sstevel@tonic-gate } 2618*0Sstevel@tonic-gate } 2619*0Sstevel@tonic-gate } 2620*0Sstevel@tonic-gate 2621*0Sstevel@tonic-gate /* 2622*0Sstevel@tonic-gate * Tomatillo specific registers 2623*0Sstevel@tonic-gate */ 2624*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) == PCI_CHIP_TOMATILLO) { 2625*0Sstevel@tonic-gate pbm_err_p->pbm_va_log = (uint64_t)va_to_pa((void *)*(a + 2626*0Sstevel@tonic-gate TOMATILLO_TGT_ERR_VALOG_OFFSET)); 2627*0Sstevel@tonic-gate pbm_err_p->pbm_iommu.iommu_tfar = *iommu_p->iommu_tfar_reg; 2628*0Sstevel@tonic-gate } 2629*0Sstevel@tonic-gate 2630*0Sstevel@tonic-gate /* 2631*0Sstevel@tonic-gate * Xmits PCI-X register 2632*0Sstevel@tonic-gate */ 2633*0Sstevel@tonic-gate if ((CHIP_TYPE(pci_p) == PCI_CHIP_XMITS) && 2634*0Sstevel@tonic-gate (pbm_err_p->pbm_ctl_stat & XMITS_PCI_CTRL_X_MODE)) { 2635*0Sstevel@tonic-gate 2636*0Sstevel@tonic-gate pbm_pcix_stat_reg = (uint64_t *)(a + 2637*0Sstevel@tonic-gate XMITS_PCI_X_ERROR_STATUS_REG_OFFSET); 2638*0Sstevel@tonic-gate 2639*0Sstevel@tonic-gate pbm_err_p->pbm_pcix_stat = *pbm_pcix_stat_reg; 2640*0Sstevel@tonic-gate pbm_err_p->pbm_pcix_pfar = pbm_err_p->pbm_pcix_stat & 2641*0Sstevel@tonic-gate XMITS_PCI_X_STATUS_PFAR_MASK; 2642*0Sstevel@tonic-gate } 2643*0Sstevel@tonic-gate } 2644*0Sstevel@tonic-gate 2645*0Sstevel@tonic-gate /* 2646*0Sstevel@tonic-gate * Function used to clear PBM/PCI/IOMMU error state after error handling 2647*0Sstevel@tonic-gate * is complete. Only clearing error bits which have been logged. Called by 2648*0Sstevel@tonic-gate * pci_pbm_err_handler and pci_bus_exit. 2649*0Sstevel@tonic-gate */ 2650*0Sstevel@tonic-gate static void 2651*0Sstevel@tonic-gate pci_clear_error(pci_t *pci_p, pbm_errstate_t *pbm_err_p) 2652*0Sstevel@tonic-gate { 2653*0Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p; 2654*0Sstevel@tonic-gate iommu_t *iommu_p = pci_p->pci_iommu_p; 2655*0Sstevel@tonic-gate 2656*0Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pbm_p->pbm_pci_p->pci_common_p->pci_fm_mutex)); 2657*0Sstevel@tonic-gate 2658*0Sstevel@tonic-gate if (*pbm_p->pbm_ctrl_reg & SCHIZO_PCI_CTRL_PCI_MMU_ERR) { 2659*0Sstevel@tonic-gate iommu_tlb_scrub(pci_p->pci_iommu_p, 1); 2660*0Sstevel@tonic-gate } 2661*0Sstevel@tonic-gate pbm_p->pbm_config_header->ch_status_reg = 2662*0Sstevel@tonic-gate pbm_err_p->pbm_pci.pci_cfg_stat; 2663*0Sstevel@tonic-gate *pbm_p->pbm_ctrl_reg = pbm_err_p->pbm_ctl_stat; 2664*0Sstevel@tonic-gate *pbm_p->pbm_async_flt_status_reg = pbm_err_p->pbm_afsr; 2665*0Sstevel@tonic-gate *iommu_p->iommu_ctrl_reg = pbm_err_p->pbm_iommu.iommu_stat; 2666*0Sstevel@tonic-gate } 2667*0Sstevel@tonic-gate 2668*0Sstevel@tonic-gate void 2669*0Sstevel@tonic-gate pbm_clear_error(pbm_t *pbm_p) 2670*0Sstevel@tonic-gate { 2671*0Sstevel@tonic-gate uint64_t pbm_afsr, pbm_ctl_stat; 2672*0Sstevel@tonic-gate 2673*0Sstevel@tonic-gate /* 2674*0Sstevel@tonic-gate * for poke() support - called from POKE_FLUSH. Spin waiting 2675*0Sstevel@tonic-gate * for MA, TA or SERR to be cleared by a pbm_error_intr(). 2676*0Sstevel@tonic-gate * We have to wait for SERR too in case the device is beyond 2677*0Sstevel@tonic-gate * a pci-pci bridge. 2678*0Sstevel@tonic-gate */ 2679*0Sstevel@tonic-gate pbm_ctl_stat = *pbm_p->pbm_ctrl_reg; 2680*0Sstevel@tonic-gate pbm_afsr = *pbm_p->pbm_async_flt_status_reg; 2681*0Sstevel@tonic-gate while (((pbm_afsr >> SCHIZO_PCI_AFSR_PE_SHIFT) & 2682*0Sstevel@tonic-gate (SCHIZO_PCI_AFSR_E_MA | SCHIZO_PCI_AFSR_E_TA)) || 2683*0Sstevel@tonic-gate (pbm_ctl_stat & COMMON_PCI_CTRL_SERR)) { 2684*0Sstevel@tonic-gate pbm_ctl_stat = *pbm_p->pbm_ctrl_reg; 2685*0Sstevel@tonic-gate pbm_afsr = *pbm_p->pbm_async_flt_status_reg; 2686*0Sstevel@tonic-gate } 2687*0Sstevel@tonic-gate } 2688*0Sstevel@tonic-gate 2689*0Sstevel@tonic-gate /* 2690*0Sstevel@tonic-gate * Function used to convert the 32 bit captured PCI error address 2691*0Sstevel@tonic-gate * to the full Safari or Jbus address. This is so we can look this address 2692*0Sstevel@tonic-gate * up in our handle caches. 2693*0Sstevel@tonic-gate */ 2694*0Sstevel@tonic-gate void 2695*0Sstevel@tonic-gate pci_format_addr(dev_info_t *dip, uint64_t *afar, uint64_t afsr) 2696*0Sstevel@tonic-gate { 2697*0Sstevel@tonic-gate pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip)); 2698*0Sstevel@tonic-gate pci_ranges_t *io_range, *mem_range; 2699*0Sstevel@tonic-gate uint64_t err_pa = 0; 2700*0Sstevel@tonic-gate 2701*0Sstevel@tonic-gate if (afsr & SCHIZO_PCI_AFSR_CONF_SPACE) { 2702*0Sstevel@tonic-gate err_pa |= pci_p->pci_ranges->parent_high; 2703*0Sstevel@tonic-gate err_pa = err_pa << 32; 2704*0Sstevel@tonic-gate err_pa |= pci_p->pci_ranges->parent_low; 2705*0Sstevel@tonic-gate } else if (afsr & SCHIZO_PCI_AFSR_IO_SPACE) { 2706*0Sstevel@tonic-gate io_range = pci_p->pci_ranges + 1; 2707*0Sstevel@tonic-gate err_pa |= io_range->parent_high; 2708*0Sstevel@tonic-gate err_pa = err_pa << 32; 2709*0Sstevel@tonic-gate err_pa |= io_range->parent_low; 2710*0Sstevel@tonic-gate } else if (afsr & SCHIZO_PCI_AFSR_MEM_SPACE) { 2711*0Sstevel@tonic-gate mem_range = pci_p->pci_ranges + 2; 2712*0Sstevel@tonic-gate err_pa |= mem_range->parent_high; 2713*0Sstevel@tonic-gate err_pa = err_pa << 32; 2714*0Sstevel@tonic-gate err_pa |= mem_range->parent_low; 2715*0Sstevel@tonic-gate } 2716*0Sstevel@tonic-gate *afar |= err_pa; 2717*0Sstevel@tonic-gate } 2718*0Sstevel@tonic-gate 2719*0Sstevel@tonic-gate static ecc_format_t ecc_format_tbl[] = { 2720*0Sstevel@tonic-gate SCH_REG_UPA, NULL, NULL, 2721*0Sstevel@tonic-gate SCH_REG_PCIA_REG, SCHIZO_PCI_AFSR_CONF_SPACE, PCI_SIDEA, 2722*0Sstevel@tonic-gate SCH_REG_PCIA_MEM, SCHIZO_PCI_AFSR_MEM_SPACE, PCI_SIDEA, 2723*0Sstevel@tonic-gate SCH_REG_PCIA_CFGIO, SCHIZO_PCI_AFSR_IO_SPACE, PCI_SIDEA, 2724*0Sstevel@tonic-gate SCH_REG_PCIB_REG, SCHIZO_PCI_AFSR_CONF_SPACE, PCI_SIDEB, 2725*0Sstevel@tonic-gate SCH_REG_PCIB_MEM, SCHIZO_PCI_AFSR_MEM_SPACE, PCI_SIDEB, 2726*0Sstevel@tonic-gate SCH_REG_PCIB_CFGIO, SCHIZO_PCI_AFSR_IO_SPACE, PCI_SIDEB, 2727*0Sstevel@tonic-gate SCH_REG_SAFARI_REGS, NULL, NULL, 2728*0Sstevel@tonic-gate NULL, NULL, NULL, 2729*0Sstevel@tonic-gate }; 2730*0Sstevel@tonic-gate 2731*0Sstevel@tonic-gate /* 2732*0Sstevel@tonic-gate * Function used to convert the 32 bit PIO address captured for a 2733*0Sstevel@tonic-gate * Safari Bus UE(during PIO Rd/Wr) to a full Safari Bus Address. 2734*0Sstevel@tonic-gate */ 2735*0Sstevel@tonic-gate static void 2736*0Sstevel@tonic-gate pci_format_ecc_addr(dev_info_t *dip, uint64_t *afar, ecc_region_t region) 2737*0Sstevel@tonic-gate { 2738*0Sstevel@tonic-gate pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip)); 2739*0Sstevel@tonic-gate pci_common_t *cmn_p = pci_p->pci_common_p; 2740*0Sstevel@tonic-gate cb_t *cb_p = pci_p->pci_cb_p; 2741*0Sstevel@tonic-gate int i, pci_side = 0; 2742*0Sstevel@tonic-gate int swap = 0; 2743*0Sstevel@tonic-gate uint64_t pa = cb_p->cb_base_pa; 2744*0Sstevel@tonic-gate uint64_t flag, schizo_base, pci_csr_base; 2745*0Sstevel@tonic-gate 2746*0Sstevel@tonic-gate if (pci_p == NULL) 2747*0Sstevel@tonic-gate return; 2748*0Sstevel@tonic-gate 2749*0Sstevel@tonic-gate pci_csr_base = va_to_pa(pci_p->pci_address[0]); 2750*0Sstevel@tonic-gate 2751*0Sstevel@tonic-gate /* 2752*0Sstevel@tonic-gate * Using the csr_base address to determine which side 2753*0Sstevel@tonic-gate * we are on. 2754*0Sstevel@tonic-gate */ 2755*0Sstevel@tonic-gate if (pci_csr_base & PCI_SIDE_ADDR_MASK) 2756*0Sstevel@tonic-gate pci_side = 1; 2757*0Sstevel@tonic-gate else 2758*0Sstevel@tonic-gate pci_side = 0; 2759*0Sstevel@tonic-gate 2760*0Sstevel@tonic-gate schizo_base = pa - PBM_CTRL_OFFSET; 2761*0Sstevel@tonic-gate 2762*0Sstevel@tonic-gate for (i = 0; ecc_format_tbl[i].ecc_region != NULL; i++) { 2763*0Sstevel@tonic-gate if (region == ecc_format_tbl[i].ecc_region) { 2764*0Sstevel@tonic-gate flag = ecc_format_tbl[i].ecc_space; 2765*0Sstevel@tonic-gate if (ecc_format_tbl[i].ecc_side != pci_side) 2766*0Sstevel@tonic-gate swap = 1; 2767*0Sstevel@tonic-gate if (region == SCH_REG_SAFARI_REGS) 2768*0Sstevel@tonic-gate *afar |= schizo_base; 2769*0Sstevel@tonic-gate break; 2770*0Sstevel@tonic-gate } 2771*0Sstevel@tonic-gate } 2772*0Sstevel@tonic-gate 2773*0Sstevel@tonic-gate if (swap) { 2774*0Sstevel@tonic-gate pci_p = cmn_p->pci_p[PCI_OTHER_SIDE(pci_p->pci_side)]; 2775*0Sstevel@tonic-gate 2776*0Sstevel@tonic-gate if (pci_p == NULL) 2777*0Sstevel@tonic-gate return; 2778*0Sstevel@tonic-gate } 2779*0Sstevel@tonic-gate pci_format_addr(pci_p->pci_dip, afar, flag); 2780*0Sstevel@tonic-gate } 2781*0Sstevel@tonic-gate 2782*0Sstevel@tonic-gate /* 2783*0Sstevel@tonic-gate * Function used to post control block specific ereports. 2784*0Sstevel@tonic-gate */ 2785*0Sstevel@tonic-gate static void 2786*0Sstevel@tonic-gate cb_ereport_post(dev_info_t *dip, uint64_t ena, cb_errstate_t *cb_err) 2787*0Sstevel@tonic-gate { 2788*0Sstevel@tonic-gate pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip)); 2789*0Sstevel@tonic-gate char buf[FM_MAX_CLASS], dev_path[MAXPATHLEN], *ptr; 2790*0Sstevel@tonic-gate struct i_ddi_fmhdl *fmhdl = DEVI(dip)->devi_fmhdl; 2791*0Sstevel@tonic-gate nvlist_t *ereport, *detector; 2792*0Sstevel@tonic-gate errorq_elem_t *eqep; 2793*0Sstevel@tonic-gate nv_alloc_t *nva; 2794*0Sstevel@tonic-gate 2795*0Sstevel@tonic-gate DEBUG1(DBG_ATTACH, dip, "cb_ereport_post: elog 0x%lx", 2796*0Sstevel@tonic-gate cb_err->cb_elog); 2797*0Sstevel@tonic-gate 2798*0Sstevel@tonic-gate /* 2799*0Sstevel@tonic-gate * We do not use ddi_fm_ereport_post because we need to set a 2800*0Sstevel@tonic-gate * special detector here. Since we do not have a device path for 2801*0Sstevel@tonic-gate * the bridge chip we use what we think it should be to aid in 2802*0Sstevel@tonic-gate * diagnosis. 2803*0Sstevel@tonic-gate */ 2804*0Sstevel@tonic-gate (void) snprintf(buf, FM_MAX_CLASS, "%s.%s.%s", DDI_IO_CLASS, 2805*0Sstevel@tonic-gate cb_err->cb_bridge_type, cb_err->cb_err_class); 2806*0Sstevel@tonic-gate 2807*0Sstevel@tonic-gate ena = ena ? ena : fm_ena_generate(0, FM_ENA_FMT1); 2808*0Sstevel@tonic-gate 2809*0Sstevel@tonic-gate eqep = errorq_reserve(fmhdl->fh_errorq); 2810*0Sstevel@tonic-gate if (eqep == NULL) 2811*0Sstevel@tonic-gate return; 2812*0Sstevel@tonic-gate 2813*0Sstevel@tonic-gate ereport = errorq_elem_nvl(fmhdl->fh_errorq, eqep); 2814*0Sstevel@tonic-gate nva = errorq_elem_nva(fmhdl->fh_errorq, eqep); 2815*0Sstevel@tonic-gate detector = fm_nvlist_create(nva); 2816*0Sstevel@tonic-gate 2817*0Sstevel@tonic-gate ASSERT(ereport); 2818*0Sstevel@tonic-gate ASSERT(nva); 2819*0Sstevel@tonic-gate ASSERT(detector); 2820*0Sstevel@tonic-gate 2821*0Sstevel@tonic-gate ddi_pathname(dip, dev_path); 2822*0Sstevel@tonic-gate ptr = strrchr(dev_path, (int)','); 2823*0Sstevel@tonic-gate 2824*0Sstevel@tonic-gate if (ptr) 2825*0Sstevel@tonic-gate *ptr = '\0'; 2826*0Sstevel@tonic-gate 2827*0Sstevel@tonic-gate fm_fmri_dev_set(detector, FM_DEV_SCHEME_VERSION, NULL, dev_path, NULL); 2828*0Sstevel@tonic-gate 2829*0Sstevel@tonic-gate DEBUG1(DBG_ERR_INTR, dip, "cb_ereport_post: ereport_set: %s", buf); 2830*0Sstevel@tonic-gate 2831*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) == PCI_CHIP_SCHIZO || 2832*0Sstevel@tonic-gate CHIP_TYPE(pci_p) == PCI_CHIP_XMITS) { 2833*0Sstevel@tonic-gate fm_ereport_set(ereport, FM_EREPORT_VERSION, buf, ena, detector, 2834*0Sstevel@tonic-gate SAFARI_CSR, DATA_TYPE_UINT64, cb_err->cb_csr, 2835*0Sstevel@tonic-gate SAFARI_ERR, DATA_TYPE_UINT64, cb_err->cb_err, 2836*0Sstevel@tonic-gate SAFARI_INTR, DATA_TYPE_UINT64, cb_err->cb_intr, 2837*0Sstevel@tonic-gate SAFARI_ELOG, DATA_TYPE_UINT64, cb_err->cb_elog, 2838*0Sstevel@tonic-gate SAFARI_PCR, DATA_TYPE_UINT64, cb_err->cb_pcr, 2839*0Sstevel@tonic-gate NULL); 2840*0Sstevel@tonic-gate } else if (CHIP_TYPE(pci_p) == PCI_CHIP_TOMATILLO) { 2841*0Sstevel@tonic-gate fm_ereport_set(ereport, FM_EREPORT_VERSION, buf, ena, detector, 2842*0Sstevel@tonic-gate JBUS_CSR, DATA_TYPE_UINT64, cb_err->cb_csr, 2843*0Sstevel@tonic-gate JBUS_ERR, DATA_TYPE_UINT64, cb_err->cb_err, 2844*0Sstevel@tonic-gate JBUS_INTR, DATA_TYPE_UINT64, cb_err->cb_intr, 2845*0Sstevel@tonic-gate JBUS_ELOG, DATA_TYPE_UINT64, cb_err->cb_elog, 2846*0Sstevel@tonic-gate JBUS_PCR, DATA_TYPE_UINT64, cb_err->cb_pcr, 2847*0Sstevel@tonic-gate NULL); 2848*0Sstevel@tonic-gate } 2849*0Sstevel@tonic-gate errorq_commit(fmhdl->fh_errorq, eqep, ERRORQ_ASYNC); 2850*0Sstevel@tonic-gate } 2851*0Sstevel@tonic-gate 2852*0Sstevel@tonic-gate /* 2853*0Sstevel@tonic-gate * Function used to post IOMMU specific ereports. 2854*0Sstevel@tonic-gate */ 2855*0Sstevel@tonic-gate static void 2856*0Sstevel@tonic-gate iommu_ereport_post(dev_info_t *dip, uint64_t ena, pbm_errstate_t *pbm_err) 2857*0Sstevel@tonic-gate { 2858*0Sstevel@tonic-gate char buf[FM_MAX_CLASS]; 2859*0Sstevel@tonic-gate 2860*0Sstevel@tonic-gate (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", 2861*0Sstevel@tonic-gate pbm_err->pbm_bridge_type, pbm_err->pbm_err_class); 2862*0Sstevel@tonic-gate 2863*0Sstevel@tonic-gate ena = ena ? ena : fm_ena_generate(0, FM_ENA_FMT1); 2864*0Sstevel@tonic-gate 2865*0Sstevel@tonic-gate DEBUG1(DBG_ERR_INTR, dip, "iommu_ereport_post: ereport_set: %s", buf); 2866*0Sstevel@tonic-gate 2867*0Sstevel@tonic-gate ddi_fm_ereport_post(dip, buf, ena, DDI_NOSLEEP, 2868*0Sstevel@tonic-gate FM_VERSION, DATA_TYPE_UINT8, 0, 2869*0Sstevel@tonic-gate PCI_CONFIG_STATUS, DATA_TYPE_UINT16, pbm_err->pbm_pci.pci_cfg_stat, 2870*0Sstevel@tonic-gate PCI_CONFIG_COMMAND, DATA_TYPE_UINT16, pbm_err->pbm_pci.pci_cfg_comm, 2871*0Sstevel@tonic-gate PCI_PBM_CSR, DATA_TYPE_UINT64, pbm_err->pbm_ctl_stat, 2872*0Sstevel@tonic-gate PCI_PBM_IOMMU_CTRL, DATA_TYPE_UINT64, pbm_err->pbm_iommu.iommu_stat, 2873*0Sstevel@tonic-gate PCI_PBM_IOMMU_TFAR, DATA_TYPE_UINT64, pbm_err->pbm_iommu.iommu_tfar, 2874*0Sstevel@tonic-gate PCI_PBM_SLOT, DATA_TYPE_UINT64, pbm_err->pbm_err_sl, 2875*0Sstevel@tonic-gate PCI_PBM_VALOG, DATA_TYPE_UINT64, pbm_err->pbm_va_log, 2876*0Sstevel@tonic-gate NULL); 2877*0Sstevel@tonic-gate } 2878*0Sstevel@tonic-gate 2879*0Sstevel@tonic-gate /* 2880*0Sstevel@tonic-gate * Function used to post PCI-X generic ereports. 2881*0Sstevel@tonic-gate * This function needs to be fixed once the Fault Boundary Analysis 2882*0Sstevel@tonic-gate * for PCI-X is conducted. The payload should be made more generic. 2883*0Sstevel@tonic-gate */ 2884*0Sstevel@tonic-gate static void 2885*0Sstevel@tonic-gate pcix_ereport_post(dev_info_t *dip, uint64_t ena, pbm_errstate_t *pbm_err) 2886*0Sstevel@tonic-gate { 2887*0Sstevel@tonic-gate char buf[FM_MAX_CLASS]; 2888*0Sstevel@tonic-gate 2889*0Sstevel@tonic-gate ena = ena ? ena : fm_ena_generate(0, FM_ENA_FMT1); 2890*0Sstevel@tonic-gate 2891*0Sstevel@tonic-gate DEBUG1(DBG_ERR_INTR, dip, "pcix_ereport_post: ereport_post: %s", buf); 2892*0Sstevel@tonic-gate 2893*0Sstevel@tonic-gate ddi_fm_ereport_post(dip, pbm_err->pbm_err_class, ena, DDI_NOSLEEP, 2894*0Sstevel@tonic-gate FM_VERSION, DATA_TYPE_UINT8, 0, 2895*0Sstevel@tonic-gate PCI_CONFIG_STATUS, DATA_TYPE_UINT16, pbm_err->pbm_pci.pci_cfg_stat, 2896*0Sstevel@tonic-gate PCI_CONFIG_COMMAND, DATA_TYPE_UINT16, pbm_err->pbm_pci.pci_cfg_comm, 2897*0Sstevel@tonic-gate PCI_PBM_CSR, DATA_TYPE_UINT64, pbm_err->pbm_ctl_stat, 2898*0Sstevel@tonic-gate PCI_PBM_AFSR, DATA_TYPE_UINT64, pbm_err->pbm_afsr, 2899*0Sstevel@tonic-gate PCI_PBM_AFAR, DATA_TYPE_UINT64, pbm_err->pbm_afar, 2900*0Sstevel@tonic-gate PCI_PBM_SLOT, DATA_TYPE_UINT64, pbm_err->pbm_err_sl, 2901*0Sstevel@tonic-gate PCIX_STAT, DATA_TYPE_UINT64, pbm_err->pbm_pcix_stat, 2902*0Sstevel@tonic-gate PCIX_PFAR, DATA_TYPE_UINT32, pbm_err->pbm_pcix_pfar, 2903*0Sstevel@tonic-gate NULL); 2904*0Sstevel@tonic-gate } 2905*0Sstevel@tonic-gate 2906*0Sstevel@tonic-gate static void 2907*0Sstevel@tonic-gate iommu_ctx_free(iommu_t *iommu_p) 2908*0Sstevel@tonic-gate { 2909*0Sstevel@tonic-gate kmem_free(iommu_p->iommu_ctx_bitmap, IOMMU_CTX_BITMAP_SIZE); 2910*0Sstevel@tonic-gate } 2911*0Sstevel@tonic-gate 2912*0Sstevel@tonic-gate /* 2913*0Sstevel@tonic-gate * iommu_tlb_scrub(): 2914*0Sstevel@tonic-gate * Exam TLB entries through TLB diagnostic registers and look for errors. 2915*0Sstevel@tonic-gate * scrub = 1 : cleanup all error bits in tlb, called in FAULT_RESET case 2916*0Sstevel@tonic-gate * scrub = 0 : log all error conditions to console, FAULT_LOG case 2917*0Sstevel@tonic-gate * In both cases, it returns number of errors found in tlb entries. 2918*0Sstevel@tonic-gate */ 2919*0Sstevel@tonic-gate static int 2920*0Sstevel@tonic-gate iommu_tlb_scrub(iommu_t *iommu_p, int scrub) 2921*0Sstevel@tonic-gate { 2922*0Sstevel@tonic-gate int i, nerr = 0; 2923*0Sstevel@tonic-gate dev_info_t *dip = iommu_p->iommu_pci_p->pci_dip; 2924*0Sstevel@tonic-gate char *neg = "not "; 2925*0Sstevel@tonic-gate 2926*0Sstevel@tonic-gate uint64_t base = (uint64_t)iommu_p->iommu_ctrl_reg - 2927*0Sstevel@tonic-gate COMMON_IOMMU_CTRL_REG_OFFSET; 2928*0Sstevel@tonic-gate 2929*0Sstevel@tonic-gate volatile uint64_t *tlb_tag = (volatile uint64_t *) 2930*0Sstevel@tonic-gate (base + COMMON_IOMMU_TLB_TAG_DIAG_ACC_OFFSET); 2931*0Sstevel@tonic-gate volatile uint64_t *tlb_data = (volatile uint64_t *) 2932*0Sstevel@tonic-gate (base + COMMON_IOMMU_TLB_DATA_DIAG_ACC_OFFSET); 2933*0Sstevel@tonic-gate for (i = 0; i < IOMMU_TLB_ENTRIES; i++) { 2934*0Sstevel@tonic-gate uint64_t tag = tlb_tag[i]; 2935*0Sstevel@tonic-gate uint64_t data = tlb_data[i]; 2936*0Sstevel@tonic-gate uint32_t errstat; 2937*0Sstevel@tonic-gate iopfn_t pfn; 2938*0Sstevel@tonic-gate 2939*0Sstevel@tonic-gate if (!(tag & TLBTAG_ERR_BIT)) 2940*0Sstevel@tonic-gate continue; 2941*0Sstevel@tonic-gate 2942*0Sstevel@tonic-gate pfn = (iopfn_t)(data & TLBDATA_MEMPA_BITS); 2943*0Sstevel@tonic-gate errstat = (uint32_t) 2944*0Sstevel@tonic-gate ((tag & TLBTAG_ERRSTAT_BITS) >> TLBTAG_ERRSTAT_SHIFT); 2945*0Sstevel@tonic-gate if (errstat == TLBTAG_ERRSTAT_INVALID) { 2946*0Sstevel@tonic-gate if (scrub) 2947*0Sstevel@tonic-gate tlb_tag[i] = tlb_data[i] = 0ull; 2948*0Sstevel@tonic-gate } else 2949*0Sstevel@tonic-gate nerr++; 2950*0Sstevel@tonic-gate 2951*0Sstevel@tonic-gate if (scrub) 2952*0Sstevel@tonic-gate continue; 2953*0Sstevel@tonic-gate 2954*0Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: Error %x on IOMMU TLB entry %x:\n" 2955*0Sstevel@tonic-gate "\tContext=%x %sWritable %sStreamable\n" 2956*0Sstevel@tonic-gate "\tPCI Page Size=%sk Address in page %x\n", 2957*0Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), errstat, i, 2958*0Sstevel@tonic-gate (tag & TLBTAG_CONTEXT_BITS) >> TLBTAG_CONTEXT_SHIFT, 2959*0Sstevel@tonic-gate (tag & TLBTAG_WRITABLE_BIT) ? "" : neg, 2960*0Sstevel@tonic-gate (tag & TLBTAG_STREAM_BIT) ? "" : neg, 2961*0Sstevel@tonic-gate (tag & TLBTAG_PGSIZE_BIT) ? "64" : "8", 2962*0Sstevel@tonic-gate (tag & TLBTAG_PCIVPN_BITS) << 13); 2963*0Sstevel@tonic-gate cmn_err(CE_CONT, "Memory: %sValid %sCacheable Page Frame=%x\n", 2964*0Sstevel@tonic-gate (data & TLBDATA_VALID_BIT) ? "" : neg, 2965*0Sstevel@tonic-gate (data & TLBDATA_CACHE_BIT) ? "" : neg, pfn); 2966*0Sstevel@tonic-gate } 2967*0Sstevel@tonic-gate return (nerr); 2968*0Sstevel@tonic-gate } 2969*0Sstevel@tonic-gate 2970*0Sstevel@tonic-gate /* 2971*0Sstevel@tonic-gate * pci_iommu_disp: calculates the displacement needed in tomatillo's 2972*0Sstevel@tonic-gate * iommu control register and modifies the control value template 2973*0Sstevel@tonic-gate * from caller. It also clears any error status bit that are new 2974*0Sstevel@tonic-gate * in tomatillo. 2975*0Sstevel@tonic-gate * return value: an 8-bit mask to enable corresponding 512 MB segments 2976*0Sstevel@tonic-gate * suitable for tomatillo's target address register. 2977*0Sstevel@tonic-gate * 0x00: no programming is needed, use existing value from prom 2978*0Sstevel@tonic-gate * 0x60: use segment 5 and 6 to form a 1GB dvma range 2979*0Sstevel@tonic-gate */ 2980*0Sstevel@tonic-gate static uint64_t 2981*0Sstevel@tonic-gate pci_iommu_disp(iommu_t *iommu_p, uint64_t *ctl_p) 2982*0Sstevel@tonic-gate { 2983*0Sstevel@tonic-gate uint64_t ctl_old; 2984*0Sstevel@tonic-gate if (CHIP_TYPE(iommu_p->iommu_pci_p) != PCI_CHIP_TOMATILLO) 2985*0Sstevel@tonic-gate return (0); 2986*0Sstevel@tonic-gate 2987*0Sstevel@tonic-gate ctl_old = *iommu_p->iommu_ctrl_reg; 2988*0Sstevel@tonic-gate /* iommu ctrl reg error bits are W1C */ 2989*0Sstevel@tonic-gate if (ctl_old >> TOMATIILO_IOMMU_ERR_REG_SHIFT) { 2990*0Sstevel@tonic-gate cmn_err(CE_WARN, "Tomatillo iommu err: %x", ctl_old); 2991*0Sstevel@tonic-gate *ctl_p |= (ctl_old >> TOMATIILO_IOMMU_ERR_REG_SHIFT) 2992*0Sstevel@tonic-gate << TOMATIILO_IOMMU_ERR_REG_SHIFT; 2993*0Sstevel@tonic-gate } 2994*0Sstevel@tonic-gate 2995*0Sstevel@tonic-gate if (iommu_p->iommu_tsb_size != TOMATILLO_IOMMU_TSB_MAX) 2996*0Sstevel@tonic-gate return (0); 2997*0Sstevel@tonic-gate 2998*0Sstevel@tonic-gate /* Tomatillo 2.0 and later, and 1GB DVMA range */ 2999*0Sstevel@tonic-gate *ctl_p |= 1 << TOMATILLO_IOMMU_SEG_DISP_SHIFT; 3000*0Sstevel@tonic-gate return (3 << (iommu_p->iommu_dvma_base >> (32 - 3))); 3001*0Sstevel@tonic-gate } 3002*0Sstevel@tonic-gate 3003*0Sstevel@tonic-gate void 3004*0Sstevel@tonic-gate pci_iommu_config(iommu_t *iommu_p, uint64_t iommu_ctl, uint64_t cfgpa) 3005*0Sstevel@tonic-gate { 3006*0Sstevel@tonic-gate uintptr_t pbm_regbase = get_pbm_reg_base(iommu_p->iommu_pci_p); 3007*0Sstevel@tonic-gate volatile uint64_t *pbm_csr_p = (volatile uint64_t *)pbm_regbase; 3008*0Sstevel@tonic-gate volatile uint64_t *tgt_space_p = (volatile uint64_t *)(pbm_regbase | 3009*0Sstevel@tonic-gate (TOMATILLO_TGT_ADDR_SPACE_OFFSET - SCHIZO_PCI_CTRL_REG_OFFSET)); 3010*0Sstevel@tonic-gate volatile uint64_t pbm_ctl = *pbm_csr_p; 3011*0Sstevel@tonic-gate 3012*0Sstevel@tonic-gate volatile uint64_t *iommu_ctl_p = iommu_p->iommu_ctrl_reg; 3013*0Sstevel@tonic-gate volatile uint64_t tsb_bar_val = iommu_p->iommu_tsb_paddr; 3014*0Sstevel@tonic-gate volatile uint64_t *tsb_bar_p = iommu_p->iommu_tsb_base_addr_reg; 3015*0Sstevel@tonic-gate uint64_t mask = pci_iommu_disp(iommu_p, &iommu_ctl); 3016*0Sstevel@tonic-gate 3017*0Sstevel@tonic-gate DEBUG2(DBG_ATTACH, iommu_p->iommu_pci_p->pci_dip, 3018*0Sstevel@tonic-gate "\npci_iommu_config: pbm_csr_p=%llx pbm_ctl=%llx", 3019*0Sstevel@tonic-gate pbm_csr_p, pbm_ctl); 3020*0Sstevel@tonic-gate DEBUG2(DBG_ATTACH|DBG_CONT, iommu_p->iommu_pci_p->pci_dip, 3021*0Sstevel@tonic-gate "\n\tiommu_ctl_p=%llx iommu_ctl=%llx", 3022*0Sstevel@tonic-gate iommu_ctl_p, iommu_ctl); 3023*0Sstevel@tonic-gate DEBUG4(DBG_ATTACH|DBG_CONT, iommu_p->iommu_pci_p->pci_dip, 3024*0Sstevel@tonic-gate "\n\tcfgpa=%llx tgt_space_p=%llx mask=%x tsb=%llx\n", 3025*0Sstevel@tonic-gate cfgpa, tgt_space_p, mask, tsb_bar_val); 3026*0Sstevel@tonic-gate 3027*0Sstevel@tonic-gate if (!cfgpa) 3028*0Sstevel@tonic-gate goto reprog; 3029*0Sstevel@tonic-gate 3030*0Sstevel@tonic-gate /* disable PBM arbiters - turn off bits 0-7 */ 3031*0Sstevel@tonic-gate *pbm_csr_p = (pbm_ctl >> 8) << 8; 3032*0Sstevel@tonic-gate 3033*0Sstevel@tonic-gate /* 3034*0Sstevel@tonic-gate * For non-XMITS, flush any previous writes. This is only 3035*0Sstevel@tonic-gate * necessary for host bridges that may have a USB keywboard 3036*0Sstevel@tonic-gate * attached. XMITS does not. 3037*0Sstevel@tonic-gate */ 3038*0Sstevel@tonic-gate if (!(CHIP_TYPE(iommu_p->iommu_pci_p) == PCI_CHIP_XMITS)) 3039*0Sstevel@tonic-gate (void) ldphysio(cfgpa); 3040*0Sstevel@tonic-gate 3041*0Sstevel@tonic-gate reprog: 3042*0Sstevel@tonic-gate if (mask) 3043*0Sstevel@tonic-gate *tgt_space_p = mask; 3044*0Sstevel@tonic-gate 3045*0Sstevel@tonic-gate *tsb_bar_p = tsb_bar_val; 3046*0Sstevel@tonic-gate *iommu_ctl_p = iommu_ctl; 3047*0Sstevel@tonic-gate 3048*0Sstevel@tonic-gate *pbm_csr_p = pbm_ctl; /* re-enable bus arbitration */ 3049*0Sstevel@tonic-gate pbm_ctl = *pbm_csr_p; /* flush all prev writes */ 3050*0Sstevel@tonic-gate } 3051*0Sstevel@tonic-gate 3052*0Sstevel@tonic-gate 3053*0Sstevel@tonic-gate int 3054*0Sstevel@tonic-gate pci_get_portid(dev_info_t *dip) 3055*0Sstevel@tonic-gate { 3056*0Sstevel@tonic-gate return (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 3057*0Sstevel@tonic-gate "portid", -1)); 3058*0Sstevel@tonic-gate } 3059*0Sstevel@tonic-gate 3060*0Sstevel@tonic-gate /* 3061*0Sstevel@tonic-gate * Schizo Safari Performance Events. 3062*0Sstevel@tonic-gate */ 3063*0Sstevel@tonic-gate pci_kev_mask_t 3064*0Sstevel@tonic-gate schizo_saf_events[] = { 3065*0Sstevel@tonic-gate {"saf_bus_cycles", 0x1}, {"saf_pause_asserted_cycles", 0x2}, 3066*0Sstevel@tonic-gate {"saf_frn_coherent_cmds", 0x3}, {"saf_frn_coherent_hits", 0x4}, 3067*0Sstevel@tonic-gate {"saf_my_coherent_cmds", 0x5}, {"saf_my_coherent_hits", 0x6}, 3068*0Sstevel@tonic-gate {"saf_frn_io_cmds", 0x7}, {"saf_frn_io_hits", 0x8}, 3069*0Sstevel@tonic-gate {"merge_buffer", 0x9}, {"interrupts", 0xa}, 3070*0Sstevel@tonic-gate {"csr_pios", 0xc}, {"upa_pios", 0xd}, 3071*0Sstevel@tonic-gate {"pcia_pios", 0xe}, {"pcib_pios", 0xf}, 3072*0Sstevel@tonic-gate {"saf_pause_seen_cycles", 0x11}, {"dvma_reads", 0x12}, 3073*0Sstevel@tonic-gate {"dvma_writes", 0x13}, {"saf_orq_full_cycles", 0x14}, 3074*0Sstevel@tonic-gate {"saf_data_in_cycles", 0x15}, {"saf_data_out_cycles", 0x16}, 3075*0Sstevel@tonic-gate {"clear_pic", 0x1f} 3076*0Sstevel@tonic-gate }; 3077*0Sstevel@tonic-gate 3078*0Sstevel@tonic-gate 3079*0Sstevel@tonic-gate /* 3080*0Sstevel@tonic-gate * Schizo PCI Performance Events. 3081*0Sstevel@tonic-gate */ 3082*0Sstevel@tonic-gate pci_kev_mask_t 3083*0Sstevel@tonic-gate schizo_pci_events[] = { 3084*0Sstevel@tonic-gate {"dvma_stream_rd", 0x0}, {"dvma_stream_wr", 0x1}, 3085*0Sstevel@tonic-gate {"dvma_const_rd", 0x2}, {"dvma_const_wr", 0x3}, 3086*0Sstevel@tonic-gate {"dvma_stream_buf_mis", 0x4}, {"dvma_cycles", 0x5}, 3087*0Sstevel@tonic-gate {"dvma_wd_xfr", 0x6}, {"pio_cycles", 0x7}, 3088*0Sstevel@tonic-gate {"dvma_tlb_misses", 0x10}, {"interrupts", 0x11}, 3089*0Sstevel@tonic-gate {"saf_inter_nack", 0x12}, {"pio_reads", 0x13}, 3090*0Sstevel@tonic-gate {"pio_writes", 0x14}, {"dvma_rd_buf_timeout", 0x15}, 3091*0Sstevel@tonic-gate {"dvma_rd_rtry_stc", 0x16}, {"dvma_wr_rtry_stc", 0x17}, 3092*0Sstevel@tonic-gate {"dvma_rd_rtry_nonstc", 0x18}, {"dvma_wr_rtry_nonstc", 0x19}, 3093*0Sstevel@tonic-gate {"E*_slow_transitions", 0x1a}, {"E*_slow_cycles_per_64", 0x1b}, 3094*0Sstevel@tonic-gate {"clear_pic", 0x1f} 3095*0Sstevel@tonic-gate }; 3096*0Sstevel@tonic-gate 3097*0Sstevel@tonic-gate 3098*0Sstevel@tonic-gate /* 3099*0Sstevel@tonic-gate * Create the picN kstats for the pci 3100*0Sstevel@tonic-gate * and safari events. 3101*0Sstevel@tonic-gate */ 3102*0Sstevel@tonic-gate void 3103*0Sstevel@tonic-gate pci_kstat_init() 3104*0Sstevel@tonic-gate { 3105*0Sstevel@tonic-gate pci_name_kstat = (pci_ksinfo_t *)kmem_alloc(sizeof (pci_ksinfo_t), 3106*0Sstevel@tonic-gate KM_NOSLEEP); 3107*0Sstevel@tonic-gate 3108*0Sstevel@tonic-gate if (pci_name_kstat == NULL) { 3109*0Sstevel@tonic-gate cmn_err(CE_WARN, "pcisch : no space for kstat\n"); 3110*0Sstevel@tonic-gate } else { 3111*0Sstevel@tonic-gate pci_name_kstat->pic_no_evs = 3112*0Sstevel@tonic-gate sizeof (schizo_pci_events) / sizeof (pci_kev_mask_t); 3113*0Sstevel@tonic-gate pci_name_kstat->pic_shift[0] = SCHIZO_SHIFT_PIC0; 3114*0Sstevel@tonic-gate pci_name_kstat->pic_shift[1] = SCHIZO_SHIFT_PIC1; 3115*0Sstevel@tonic-gate pci_create_name_kstat("pcis", 3116*0Sstevel@tonic-gate pci_name_kstat, schizo_pci_events); 3117*0Sstevel@tonic-gate } 3118*0Sstevel@tonic-gate 3119*0Sstevel@tonic-gate saf_name_kstat = (pci_ksinfo_t *)kmem_alloc(sizeof (pci_ksinfo_t), 3120*0Sstevel@tonic-gate KM_NOSLEEP); 3121*0Sstevel@tonic-gate if (saf_name_kstat == NULL) { 3122*0Sstevel@tonic-gate cmn_err(CE_WARN, "pcisch : no space for kstat\n"); 3123*0Sstevel@tonic-gate } else { 3124*0Sstevel@tonic-gate saf_name_kstat->pic_no_evs = 3125*0Sstevel@tonic-gate sizeof (schizo_saf_events) / sizeof (pci_kev_mask_t); 3126*0Sstevel@tonic-gate saf_name_kstat->pic_shift[0] = SCHIZO_SHIFT_PIC0; 3127*0Sstevel@tonic-gate saf_name_kstat->pic_shift[1] = SCHIZO_SHIFT_PIC1; 3128*0Sstevel@tonic-gate pci_create_name_kstat("saf", saf_name_kstat, schizo_saf_events); 3129*0Sstevel@tonic-gate } 3130*0Sstevel@tonic-gate } 3131*0Sstevel@tonic-gate 3132*0Sstevel@tonic-gate void 3133*0Sstevel@tonic-gate pci_kstat_fini() 3134*0Sstevel@tonic-gate { 3135*0Sstevel@tonic-gate if (pci_name_kstat != NULL) { 3136*0Sstevel@tonic-gate pci_delete_name_kstat(pci_name_kstat); 3137*0Sstevel@tonic-gate kmem_free(pci_name_kstat, sizeof (pci_ksinfo_t)); 3138*0Sstevel@tonic-gate pci_name_kstat = NULL; 3139*0Sstevel@tonic-gate } 3140*0Sstevel@tonic-gate 3141*0Sstevel@tonic-gate if (saf_name_kstat != NULL) { 3142*0Sstevel@tonic-gate pci_delete_name_kstat(saf_name_kstat); 3143*0Sstevel@tonic-gate kmem_free(saf_name_kstat, sizeof (pci_ksinfo_t)); 3144*0Sstevel@tonic-gate saf_name_kstat = NULL; 3145*0Sstevel@tonic-gate } 3146*0Sstevel@tonic-gate } 3147*0Sstevel@tonic-gate 3148*0Sstevel@tonic-gate /* 3149*0Sstevel@tonic-gate * Create 'counters' kstat for pci events. 3150*0Sstevel@tonic-gate */ 3151*0Sstevel@tonic-gate void 3152*0Sstevel@tonic-gate pci_add_pci_kstat(pci_t *pci_p) 3153*0Sstevel@tonic-gate { 3154*0Sstevel@tonic-gate pci_cntr_addr_t *cntr_addr_p = &pci_p->pci_ks_addr; 3155*0Sstevel@tonic-gate uintptr_t regbase = (uintptr_t)pci_p->pci_address[0]; 3156*0Sstevel@tonic-gate 3157*0Sstevel@tonic-gate cntr_addr_p->pcr_addr = (uint64_t *) 3158*0Sstevel@tonic-gate (regbase + SCHIZO_PERF_PCI_PCR_OFFSET); 3159*0Sstevel@tonic-gate cntr_addr_p->pic_addr = (uint64_t *) 3160*0Sstevel@tonic-gate (regbase + SCHIZO_PERF_PCI_PIC_OFFSET); 3161*0Sstevel@tonic-gate 3162*0Sstevel@tonic-gate pci_p->pci_ksp = pci_create_cntr_kstat(pci_p, "pcis", 3163*0Sstevel@tonic-gate NUM_OF_PICS, pci_cntr_kstat_update, cntr_addr_p); 3164*0Sstevel@tonic-gate 3165*0Sstevel@tonic-gate if (pci_p->pci_ksp == NULL) { 3166*0Sstevel@tonic-gate cmn_err(CE_WARN, "pcisch : cannot create counter kstat"); 3167*0Sstevel@tonic-gate } 3168*0Sstevel@tonic-gate } 3169*0Sstevel@tonic-gate 3170*0Sstevel@tonic-gate void 3171*0Sstevel@tonic-gate pci_rem_pci_kstat(pci_t *pci_p) 3172*0Sstevel@tonic-gate { 3173*0Sstevel@tonic-gate if (pci_p->pci_ksp != NULL) 3174*0Sstevel@tonic-gate kstat_delete(pci_p->pci_ksp); 3175*0Sstevel@tonic-gate pci_p->pci_ksp = NULL; 3176*0Sstevel@tonic-gate } 3177*0Sstevel@tonic-gate 3178*0Sstevel@tonic-gate void 3179*0Sstevel@tonic-gate pci_add_upstream_kstat(pci_t *pci_p) 3180*0Sstevel@tonic-gate { 3181*0Sstevel@tonic-gate pci_common_t *cmn_p = pci_p->pci_common_p; 3182*0Sstevel@tonic-gate pci_cntr_pa_t *cntr_pa_p = &cmn_p->pci_cmn_uks_pa; 3183*0Sstevel@tonic-gate uint64_t regbase = va_to_pa(pci_p->pci_address[1]); 3184*0Sstevel@tonic-gate 3185*0Sstevel@tonic-gate cntr_pa_p->pcr_pa = 3186*0Sstevel@tonic-gate regbase + SCHIZO_PERF_SAF_PCR_OFFSET; 3187*0Sstevel@tonic-gate cntr_pa_p->pic_pa = 3188*0Sstevel@tonic-gate regbase + SCHIZO_PERF_SAF_PIC_OFFSET; 3189*0Sstevel@tonic-gate 3190*0Sstevel@tonic-gate cmn_p->pci_common_uksp = pci_create_cntr_kstat(pci_p, "saf", 3191*0Sstevel@tonic-gate NUM_OF_PICS, pci_cntr_kstat_pa_update, cntr_pa_p); 3192*0Sstevel@tonic-gate } 3193*0Sstevel@tonic-gate 3194*0Sstevel@tonic-gate /* 3195*0Sstevel@tonic-gate * Extract the drivers binding name to identify which chip 3196*0Sstevel@tonic-gate * we're binding to. Whenever a new bus bridge is created, the driver alias 3197*0Sstevel@tonic-gate * entry should be added here to identify the device if needed. If a device 3198*0Sstevel@tonic-gate * isn't added, the identity defaults to PCI_CHIP_UNIDENTIFIED. 3199*0Sstevel@tonic-gate */ 3200*0Sstevel@tonic-gate static uint32_t 3201*0Sstevel@tonic-gate pci_identity_init(pci_t *pci_p) 3202*0Sstevel@tonic-gate { 3203*0Sstevel@tonic-gate dev_info_t *dip = pci_p->pci_dip; 3204*0Sstevel@tonic-gate char *name = ddi_binding_name(dip); 3205*0Sstevel@tonic-gate uint32_t ver = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 3206*0Sstevel@tonic-gate "version#", 0); 3207*0Sstevel@tonic-gate 3208*0Sstevel@tonic-gate if (strcmp(name, "pci108e,a801") == 0) 3209*0Sstevel@tonic-gate return (CHIP_ID(PCI_CHIP_TOMATILLO, ver, 0x00)); 3210*0Sstevel@tonic-gate 3211*0Sstevel@tonic-gate if (strcmp(name, "pci108e,8001") == 0) 3212*0Sstevel@tonic-gate return (CHIP_ID(PCI_CHIP_SCHIZO, ver, 0x00)); 3213*0Sstevel@tonic-gate 3214*0Sstevel@tonic-gate if (strcmp(name, "pci108e,8002") == 0) { 3215*0Sstevel@tonic-gate uint32_t mod_rev = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 3216*0Sstevel@tonic-gate DDI_PROP_DONTPASS, "module-revision#", 0); 3217*0Sstevel@tonic-gate return (CHIP_ID(PCI_CHIP_XMITS, ver, mod_rev)); 3218*0Sstevel@tonic-gate } 3219*0Sstevel@tonic-gate 3220*0Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: Unknown PCI Host bridge %s %x\n", 3221*0Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), name, ver); 3222*0Sstevel@tonic-gate 3223*0Sstevel@tonic-gate return (PCI_CHIP_UNIDENTIFIED); 3224*0Sstevel@tonic-gate } 3225*0Sstevel@tonic-gate 3226*0Sstevel@tonic-gate /* 3227*0Sstevel@tonic-gate * Setup a physical pointer to one leaf config space area. This 3228*0Sstevel@tonic-gate * is used in several places in order to do a dummy read which 3229*0Sstevel@tonic-gate * guarantees the nexus (and not a bus master) has gained control 3230*0Sstevel@tonic-gate * of the bus. 3231*0Sstevel@tonic-gate */ 3232*0Sstevel@tonic-gate static void 3233*0Sstevel@tonic-gate pci_setup_cfgpa(pci_t *pci_p) 3234*0Sstevel@tonic-gate { 3235*0Sstevel@tonic-gate dev_info_t *dip = pci_p->pci_dip; 3236*0Sstevel@tonic-gate dev_info_t *cdip; 3237*0Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p; 3238*0Sstevel@tonic-gate uint64_t cfgpa = pci_get_cfg_pabase(pci_p); 3239*0Sstevel@tonic-gate uint32_t *reg_p; 3240*0Sstevel@tonic-gate int reg_len; 3241*0Sstevel@tonic-gate 3242*0Sstevel@tonic-gate for (cdip = ddi_get_child(dip); cdip != NULL; 3243*0Sstevel@tonic-gate cdip = ddi_get_next_sibling(cdip)) { 3244*0Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_NONE, cdip, DDI_PROP_DONTPASS, 3245*0Sstevel@tonic-gate "reg", (caddr_t)®_p, ®_len) != DDI_PROP_SUCCESS) 3246*0Sstevel@tonic-gate continue; 3247*0Sstevel@tonic-gate cfgpa += (*reg_p) & (PCI_CONF_ADDR_MASK ^ PCI_REG_REG_M); 3248*0Sstevel@tonic-gate kmem_free(reg_p, reg_len); 3249*0Sstevel@tonic-gate break; 3250*0Sstevel@tonic-gate } 3251*0Sstevel@tonic-gate pbm_p->pbm_anychild_cfgpa = cfgpa; 3252*0Sstevel@tonic-gate } 3253*0Sstevel@tonic-gate 3254*0Sstevel@tonic-gate void 3255*0Sstevel@tonic-gate pci_post_init_child(pci_t *pci_p, dev_info_t *child) 3256*0Sstevel@tonic-gate { 3257*0Sstevel@tonic-gate volatile uint64_t *ctrl_reg_p; 3258*0Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p; 3259*0Sstevel@tonic-gate 3260*0Sstevel@tonic-gate pci_setup_cfgpa(pci_p); 3261*0Sstevel@tonic-gate 3262*0Sstevel@tonic-gate /* 3263*0Sstevel@tonic-gate * This is a hack for skyhawk/casinni combination to address 3264*0Sstevel@tonic-gate * hardware problems between the request and grant signals which 3265*0Sstevel@tonic-gate * causes a bus hang. One workaround, which is applied here, 3266*0Sstevel@tonic-gate * is to disable bus parking if the child contains the property 3267*0Sstevel@tonic-gate * pci-req-removal. Note that if the bus is quiesced we must mask 3268*0Sstevel@tonic-gate * off the parking bit in the saved control registers, since the 3269*0Sstevel@tonic-gate * quiesce operation temporarily turns off PCI bus parking. 3270*0Sstevel@tonic-gate */ 3271*0Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 3272*0Sstevel@tonic-gate "pci-req-removal") == 1) { 3273*0Sstevel@tonic-gate 3274*0Sstevel@tonic-gate if (pbm_p->pbm_quiesce_count > 0) { 3275*0Sstevel@tonic-gate pbm_p->pbm_saved_ctrl_reg &= ~SCHIZO_PCI_CTRL_ARB_PARK; 3276*0Sstevel@tonic-gate } else { 3277*0Sstevel@tonic-gate ctrl_reg_p = pbm_p->pbm_ctrl_reg; 3278*0Sstevel@tonic-gate *ctrl_reg_p &= ~SCHIZO_PCI_CTRL_ARB_PARK; 3279*0Sstevel@tonic-gate } 3280*0Sstevel@tonic-gate } 3281*0Sstevel@tonic-gate 3282*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) == PCI_CHIP_XMITS) { 3283*0Sstevel@tonic-gate if (*pbm_p->pbm_ctrl_reg & XMITS_PCI_CTRL_X_MODE) { 3284*0Sstevel@tonic-gate int value; 3285*0Sstevel@tonic-gate 3286*0Sstevel@tonic-gate /* 3287*0Sstevel@tonic-gate * Due to a XMITS bug, we need to set the outstanding 3288*0Sstevel@tonic-gate * split transactions to 1 for all PCI-X functions 3289*0Sstevel@tonic-gate * behind the leaf. 3290*0Sstevel@tonic-gate */ 3291*0Sstevel@tonic-gate value = (xmits_max_transactions << 4) | 3292*0Sstevel@tonic-gate (xmits_max_read_bytes << 2); 3293*0Sstevel@tonic-gate 3294*0Sstevel@tonic-gate DEBUG1(DBG_INIT_CLD, child, "Turning on XMITS NCPQ " 3295*0Sstevel@tonic-gate "Workaround: value = %x\n", value); 3296*0Sstevel@tonic-gate 3297*0Sstevel@tonic-gate pcix_set_cmd_reg(child, value); 3298*0Sstevel@tonic-gate 3299*0Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, 3300*0Sstevel@tonic-gate child, "pcix-update-cmd-reg", value); 3301*0Sstevel@tonic-gate } 3302*0Sstevel@tonic-gate } 3303*0Sstevel@tonic-gate } 3304*0Sstevel@tonic-gate 3305*0Sstevel@tonic-gate void 3306*0Sstevel@tonic-gate pci_post_uninit_child(pci_t *pci_p) 3307*0Sstevel@tonic-gate { 3308*0Sstevel@tonic-gate pci_setup_cfgpa(pci_p); 3309*0Sstevel@tonic-gate } 3310*0Sstevel@tonic-gate 3311*0Sstevel@tonic-gate static int 3312*0Sstevel@tonic-gate pci_tom_nbintr_op(pci_t *pci_p, uint32_t inum, intrfunc f, caddr_t arg, 3313*0Sstevel@tonic-gate int flag) 3314*0Sstevel@tonic-gate { 3315*0Sstevel@tonic-gate uint32_t ino = pci_p->pci_inos[inum]; 3316*0Sstevel@tonic-gate uint32_t mondo = IB_INO_TO_NBMONDO(pci_p->pci_ib_p, ino); 3317*0Sstevel@tonic-gate int ret = DDI_SUCCESS; 3318*0Sstevel@tonic-gate 3319*0Sstevel@tonic-gate mondo = CB_MONDO_TO_XMONDO(pci_p->pci_cb_p, mondo); /* no op on tom */ 3320*0Sstevel@tonic-gate 3321*0Sstevel@tonic-gate switch (flag) { 3322*0Sstevel@tonic-gate case PCI_OBJ_INTR_ADD: 3323*0Sstevel@tonic-gate VERIFY(add_ivintr(mondo, pci_pil[inum], f, arg, NULL) == 0); 3324*0Sstevel@tonic-gate break; 3325*0Sstevel@tonic-gate case PCI_OBJ_INTR_REMOVE: 3326*0Sstevel@tonic-gate rem_ivintr(mondo, NULL); 3327*0Sstevel@tonic-gate break; 3328*0Sstevel@tonic-gate default: 3329*0Sstevel@tonic-gate ret = DDI_FAILURE; 3330*0Sstevel@tonic-gate break; 3331*0Sstevel@tonic-gate } 3332*0Sstevel@tonic-gate 3333*0Sstevel@tonic-gate return (ret); 3334*0Sstevel@tonic-gate } 3335*0Sstevel@tonic-gate 3336*0Sstevel@tonic-gate int 3337*0Sstevel@tonic-gate pci_ecc_add_intr(pci_t *pci_p, int inum, ecc_intr_info_t *eii_p) 3338*0Sstevel@tonic-gate { 3339*0Sstevel@tonic-gate uint32_t mondo; 3340*0Sstevel@tonic-gate int r; 3341*0Sstevel@tonic-gate 3342*0Sstevel@tonic-gate mondo = ((pci_p->pci_cb_p->cb_ign << PCI_INO_BITS) | 3343*0Sstevel@tonic-gate pci_p->pci_inos[inum]); 3344*0Sstevel@tonic-gate mondo = CB_MONDO_TO_XMONDO(pci_p->pci_cb_p, mondo); 3345*0Sstevel@tonic-gate 3346*0Sstevel@tonic-gate VERIFY(add_ivintr(mondo, pci_pil[inum], ecc_intr, 3347*0Sstevel@tonic-gate (caddr_t)eii_p, NULL) == 0); 3348*0Sstevel@tonic-gate 3349*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) != PCI_CHIP_TOMATILLO) 3350*0Sstevel@tonic-gate return (PCI_ATTACH_RETCODE(PCI_ECC_OBJ, PCI_OBJ_INTR_ADD, 3351*0Sstevel@tonic-gate DDI_SUCCESS)); 3352*0Sstevel@tonic-gate 3353*0Sstevel@tonic-gate r = pci_tom_nbintr_op(pci_p, inum, ecc_intr, 3354*0Sstevel@tonic-gate (caddr_t)eii_p, PCI_OBJ_INTR_ADD); 3355*0Sstevel@tonic-gate return (PCI_ATTACH_RETCODE(PCI_ECC_OBJ, PCI_OBJ_INTR_ADD, r)); 3356*0Sstevel@tonic-gate } 3357*0Sstevel@tonic-gate 3358*0Sstevel@tonic-gate void 3359*0Sstevel@tonic-gate pci_ecc_rem_intr(pci_t *pci_p, int inum, ecc_intr_info_t *eii_p) 3360*0Sstevel@tonic-gate { 3361*0Sstevel@tonic-gate uint32_t mondo; 3362*0Sstevel@tonic-gate 3363*0Sstevel@tonic-gate mondo = ((pci_p->pci_cb_p->cb_ign << PCI_INO_BITS) | 3364*0Sstevel@tonic-gate pci_p->pci_inos[inum]); 3365*0Sstevel@tonic-gate mondo = CB_MONDO_TO_XMONDO(pci_p->pci_cb_p, mondo); 3366*0Sstevel@tonic-gate 3367*0Sstevel@tonic-gate rem_ivintr(mondo, NULL); 3368*0Sstevel@tonic-gate 3369*0Sstevel@tonic-gate if (CHIP_TYPE(pci_p) == PCI_CHIP_TOMATILLO) 3370*0Sstevel@tonic-gate pci_tom_nbintr_op(pci_p, inum, ecc_intr, 3371*0Sstevel@tonic-gate (caddr_t)eii_p, PCI_OBJ_INTR_REMOVE); 3372*0Sstevel@tonic-gate } 3373*0Sstevel@tonic-gate 3374*0Sstevel@tonic-gate static uint_t 3375*0Sstevel@tonic-gate pci_pbm_cdma_intr(caddr_t a) 3376*0Sstevel@tonic-gate { 3377*0Sstevel@tonic-gate pbm_t *pbm_p = (pbm_t *)a; 3378*0Sstevel@tonic-gate pbm_p->pbm_cdma_flag = PBM_CDMA_DONE; 3379*0Sstevel@tonic-gate #ifdef PBM_CDMA_DEBUG 3380*0Sstevel@tonic-gate pbm_p->pbm_cdma_intr_cnt++; 3381*0Sstevel@tonic-gate #endif /* PBM_CDMA_DEBUG */ 3382*0Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 3383*0Sstevel@tonic-gate } 3384*0Sstevel@tonic-gate 3385*0Sstevel@tonic-gate int 3386*0Sstevel@tonic-gate pci_pbm_add_intr(pci_t *pci_p) 3387*0Sstevel@tonic-gate { 3388*0Sstevel@tonic-gate uint32_t mondo; 3389*0Sstevel@tonic-gate 3390*0Sstevel@tonic-gate mondo = IB_INO_TO_MONDO(pci_p->pci_ib_p, pci_p->pci_inos[CBNINTR_CDMA]); 3391*0Sstevel@tonic-gate mondo = CB_MONDO_TO_XMONDO(pci_p->pci_cb_p, mondo); 3392*0Sstevel@tonic-gate 3393*0Sstevel@tonic-gate VERIFY(add_ivintr(mondo, pci_pil[CBNINTR_CDMA], 3394*0Sstevel@tonic-gate pci_pbm_cdma_intr, (caddr_t)pci_p->pci_pbm_p, NULL) == 0); 3395*0Sstevel@tonic-gate 3396*0Sstevel@tonic-gate return (DDI_SUCCESS); 3397*0Sstevel@tonic-gate } 3398*0Sstevel@tonic-gate 3399*0Sstevel@tonic-gate void 3400*0Sstevel@tonic-gate pci_pbm_rem_intr(pci_t *pci_p) 3401*0Sstevel@tonic-gate { 3402*0Sstevel@tonic-gate ib_t *ib_p = pci_p->pci_ib_p; 3403*0Sstevel@tonic-gate uint32_t mondo; 3404*0Sstevel@tonic-gate 3405*0Sstevel@tonic-gate mondo = IB_INO_TO_MONDO(pci_p->pci_ib_p, pci_p->pci_inos[CBNINTR_CDMA]); 3406*0Sstevel@tonic-gate mondo = CB_MONDO_TO_XMONDO(pci_p->pci_cb_p, mondo); 3407*0Sstevel@tonic-gate 3408*0Sstevel@tonic-gate ib_intr_disable(ib_p, pci_p->pci_inos[CBNINTR_CDMA], IB_INTR_NOWAIT); 3409*0Sstevel@tonic-gate rem_ivintr(mondo, NULL); 3410*0Sstevel@tonic-gate } 3411*0Sstevel@tonic-gate 3412*0Sstevel@tonic-gate void 3413*0Sstevel@tonic-gate pci_pbm_suspend(pci_t *pci_p) 3414*0Sstevel@tonic-gate { 3415*0Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p; 3416*0Sstevel@tonic-gate ib_ino_t ino = pci_p->pci_inos[CBNINTR_CDMA]; 3417*0Sstevel@tonic-gate 3418*0Sstevel@tonic-gate /* Save CDMA interrupt state */ 3419*0Sstevel@tonic-gate pbm_p->pbm_cdma_imr_save = *ib_intr_map_reg_addr(pci_p->pci_ib_p, ino); 3420*0Sstevel@tonic-gate } 3421*0Sstevel@tonic-gate 3422*0Sstevel@tonic-gate void 3423*0Sstevel@tonic-gate pci_pbm_resume(pci_t *pci_p) 3424*0Sstevel@tonic-gate { 3425*0Sstevel@tonic-gate pbm_t *pbm_p = pci_p->pci_pbm_p; 3426*0Sstevel@tonic-gate ib_ino_t ino = pci_p->pci_inos[CBNINTR_CDMA]; 3427*0Sstevel@tonic-gate 3428*0Sstevel@tonic-gate /* Restore CDMA interrupt state */ 3429*0Sstevel@tonic-gate *ib_intr_map_reg_addr(pci_p->pci_ib_p, ino) = pbm_p->pbm_cdma_imr_save; 3430*0Sstevel@tonic-gate } 3431*0Sstevel@tonic-gate 3432*0Sstevel@tonic-gate /* 3433*0Sstevel@tonic-gate * pci_bus_quiesce 3434*0Sstevel@tonic-gate * 3435*0Sstevel@tonic-gate * This function is called as the corresponding control ops routine 3436*0Sstevel@tonic-gate * to a DDI_CTLOPS_QUIESCE command. Its mission is to halt all DMA 3437*0Sstevel@tonic-gate * activity on the bus by disabling arbitration/parking. 3438*0Sstevel@tonic-gate */ 3439*0Sstevel@tonic-gate int 3440*0Sstevel@tonic-gate pci_bus_quiesce(pci_t *pci_p, dev_info_t *dip, void *result) 3441*0Sstevel@tonic-gate { 3442*0Sstevel@tonic-gate volatile uint64_t *ctrl_reg_p; 3443*0Sstevel@tonic-gate volatile uint64_t ctrl_reg; 3444*0Sstevel@tonic-gate pbm_t *pbm_p; 3445*0Sstevel@tonic-gate 3446*0Sstevel@tonic-gate pbm_p = pci_p->pci_pbm_p; 3447*0Sstevel@tonic-gate ctrl_reg_p = pbm_p->pbm_ctrl_reg; 3448*0Sstevel@tonic-gate 3449*0Sstevel@tonic-gate if (pbm_p->pbm_quiesce_count++ == 0) { 3450*0Sstevel@tonic-gate 3451*0Sstevel@tonic-gate DEBUG0(DBG_PWR, dip, "quiescing bus\n"); 3452*0Sstevel@tonic-gate 3453*0Sstevel@tonic-gate ctrl_reg = *ctrl_reg_p; 3454*0Sstevel@tonic-gate pbm_p->pbm_saved_ctrl_reg = ctrl_reg; 3455*0Sstevel@tonic-gate ctrl_reg &= ~(SCHIZO_PCI_CTRL_ARB_EN_MASK | 3456*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_ARB_PARK); 3457*0Sstevel@tonic-gate *ctrl_reg_p = ctrl_reg; 3458*0Sstevel@tonic-gate #ifdef DEBUG 3459*0Sstevel@tonic-gate ctrl_reg = *ctrl_reg_p; 3460*0Sstevel@tonic-gate if ((ctrl_reg & (SCHIZO_PCI_CTRL_ARB_EN_MASK | 3461*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_ARB_PARK)) != 0) 3462*0Sstevel@tonic-gate panic("ctrl_reg didn't quiesce: 0x%x\n", ctrl_reg); 3463*0Sstevel@tonic-gate #endif 3464*0Sstevel@tonic-gate if (pbm_p->pbm_anychild_cfgpa) 3465*0Sstevel@tonic-gate (void) ldphysio(pbm_p->pbm_anychild_cfgpa); 3466*0Sstevel@tonic-gate } 3467*0Sstevel@tonic-gate 3468*0Sstevel@tonic-gate return (DDI_SUCCESS); 3469*0Sstevel@tonic-gate } 3470*0Sstevel@tonic-gate 3471*0Sstevel@tonic-gate /* 3472*0Sstevel@tonic-gate * pci_bus_unquiesce 3473*0Sstevel@tonic-gate * 3474*0Sstevel@tonic-gate * This function is called as the corresponding control ops routine 3475*0Sstevel@tonic-gate * to a DDI_CTLOPS_UNQUIESCE command. Its mission is to resume paused 3476*0Sstevel@tonic-gate * DMA activity on the bus by re-enabling arbitration (and maybe parking). 3477*0Sstevel@tonic-gate */ 3478*0Sstevel@tonic-gate int 3479*0Sstevel@tonic-gate pci_bus_unquiesce(pci_t *pci_p, dev_info_t *dip, void *result) 3480*0Sstevel@tonic-gate { 3481*0Sstevel@tonic-gate volatile uint64_t *ctrl_reg_p; 3482*0Sstevel@tonic-gate pbm_t *pbm_p; 3483*0Sstevel@tonic-gate #ifdef DEBUG 3484*0Sstevel@tonic-gate volatile uint64_t ctrl_reg; 3485*0Sstevel@tonic-gate #endif 3486*0Sstevel@tonic-gate 3487*0Sstevel@tonic-gate pbm_p = pci_p->pci_pbm_p; 3488*0Sstevel@tonic-gate ctrl_reg_p = pbm_p->pbm_ctrl_reg; 3489*0Sstevel@tonic-gate 3490*0Sstevel@tonic-gate ASSERT(pbm_p->pbm_quiesce_count > 0); 3491*0Sstevel@tonic-gate if (--pbm_p->pbm_quiesce_count == 0) { 3492*0Sstevel@tonic-gate *ctrl_reg_p = pbm_p->pbm_saved_ctrl_reg; 3493*0Sstevel@tonic-gate #ifdef DEBUG 3494*0Sstevel@tonic-gate ctrl_reg = *ctrl_reg_p; 3495*0Sstevel@tonic-gate if ((ctrl_reg & (SCHIZO_PCI_CTRL_ARB_EN_MASK | 3496*0Sstevel@tonic-gate SCHIZO_PCI_CTRL_ARB_PARK)) == 0) 3497*0Sstevel@tonic-gate panic("ctrl_reg didn't unquiesce: 0x%x\n", ctrl_reg); 3498*0Sstevel@tonic-gate #endif 3499*0Sstevel@tonic-gate } 3500*0Sstevel@tonic-gate 3501*0Sstevel@tonic-gate return (DDI_SUCCESS); 3502*0Sstevel@tonic-gate } 3503*0Sstevel@tonic-gate 3504*0Sstevel@tonic-gate static void 3505*0Sstevel@tonic-gate tm_vmem_free(ddi_dma_impl_t *mp, iommu_t *iommu_p, dvma_addr_t dvma_pg, 3506*0Sstevel@tonic-gate int npages) 3507*0Sstevel@tonic-gate { 3508*0Sstevel@tonic-gate uint32_t dur_max, dur_base; 3509*0Sstevel@tonic-gate dvma_unbind_req_t *req_p, *req_max_p; 3510*0Sstevel@tonic-gate dvma_unbind_req_t *req_base_p = iommu_p->iommu_mtlb_req_p; 3511*0Sstevel@tonic-gate uint32_t tlb_vpn[IOMMU_TLB_ENTRIES]; 3512*0Sstevel@tonic-gate caddr_t reg_base; 3513*0Sstevel@tonic-gate volatile uint64_t *tag_p; 3514*0Sstevel@tonic-gate int i, preserv_count = 0; 3515*0Sstevel@tonic-gate 3516*0Sstevel@tonic-gate mutex_enter(&iommu_p->iommu_mtlb_lock); 3517*0Sstevel@tonic-gate 3518*0Sstevel@tonic-gate iommu_p->iommu_mtlb_npgs += npages; 3519*0Sstevel@tonic-gate req_max_p = req_base_p + iommu_p->iommu_mtlb_nreq++; 3520*0Sstevel@tonic-gate req_max_p->dur_npg = npages; 3521*0Sstevel@tonic-gate req_max_p->dur_base = dvma_pg; 3522*0Sstevel@tonic-gate req_max_p->dur_flags = mp->dmai_flags & DMAI_FLAGS_VMEMCACHE; 3523*0Sstevel@tonic-gate 3524*0Sstevel@tonic-gate 3525*0Sstevel@tonic-gate if (iommu_p->iommu_mtlb_npgs <= iommu_p->iommu_mtlb_maxpgs) 3526*0Sstevel@tonic-gate goto done; 3527*0Sstevel@tonic-gate 3528*0Sstevel@tonic-gate /* read TLB */ 3529*0Sstevel@tonic-gate reg_base = iommu_p->iommu_pci_p->pci_address[0]; 3530*0Sstevel@tonic-gate tag_p = (volatile uint64_t *) 3531*0Sstevel@tonic-gate (reg_base + COMMON_IOMMU_TLB_TAG_DIAG_ACC_OFFSET); 3532*0Sstevel@tonic-gate 3533*0Sstevel@tonic-gate for (i = 0; i < IOMMU_TLB_ENTRIES; i++) 3534*0Sstevel@tonic-gate tlb_vpn[i] = tag_p[i] & SCHIZO_VPN_MASK; 3535*0Sstevel@tonic-gate 3536*0Sstevel@tonic-gate /* for each request search the TLB for a matching address */ 3537*0Sstevel@tonic-gate for (req_p = req_base_p; req_p <= req_max_p; req_p++) { 3538*0Sstevel@tonic-gate dur_base = req_p->dur_base; 3539*0Sstevel@tonic-gate dur_max = req_p->dur_base + req_p->dur_npg; 3540*0Sstevel@tonic-gate 3541*0Sstevel@tonic-gate for (i = 0; i < IOMMU_TLB_ENTRIES; i++) { 3542*0Sstevel@tonic-gate uint_t vpn = tlb_vpn[i]; 3543*0Sstevel@tonic-gate if (vpn >= dur_base && vpn < dur_max) 3544*0Sstevel@tonic-gate break; 3545*0Sstevel@tonic-gate } 3546*0Sstevel@tonic-gate if (i >= IOMMU_TLB_ENTRIES) { 3547*0Sstevel@tonic-gate pci_vmem_do_free(iommu_p, 3548*0Sstevel@tonic-gate (void *)IOMMU_PTOB(req_p->dur_base), 3549*0Sstevel@tonic-gate req_p->dur_npg, req_p->dur_flags); 3550*0Sstevel@tonic-gate iommu_p->iommu_mtlb_npgs -= req_p->dur_npg; 3551*0Sstevel@tonic-gate continue; 3552*0Sstevel@tonic-gate } 3553*0Sstevel@tonic-gate /* if an empty slot exists */ 3554*0Sstevel@tonic-gate if ((req_p - req_base_p) != preserv_count) 3555*0Sstevel@tonic-gate *(req_base_p + preserv_count) = *req_p; 3556*0Sstevel@tonic-gate preserv_count++; 3557*0Sstevel@tonic-gate } 3558*0Sstevel@tonic-gate 3559*0Sstevel@tonic-gate iommu_p->iommu_mtlb_nreq = preserv_count; 3560*0Sstevel@tonic-gate done: 3561*0Sstevel@tonic-gate mutex_exit(&iommu_p->iommu_mtlb_lock); 3562*0Sstevel@tonic-gate } 3563*0Sstevel@tonic-gate 3564*0Sstevel@tonic-gate void 3565*0Sstevel@tonic-gate pci_vmem_free(iommu_t *iommu_p, ddi_dma_impl_t *mp, void *dvma_addr, 3566*0Sstevel@tonic-gate size_t npages) 3567*0Sstevel@tonic-gate { 3568*0Sstevel@tonic-gate if (tm_mtlb_gc) 3569*0Sstevel@tonic-gate tm_vmem_free(mp, iommu_p, 3570*0Sstevel@tonic-gate (dvma_addr_t)IOMMU_BTOP((dvma_addr_t)dvma_addr), npages); 3571*0Sstevel@tonic-gate else 3572*0Sstevel@tonic-gate pci_vmem_do_free(iommu_p, dvma_addr, npages, 3573*0Sstevel@tonic-gate (mp->dmai_flags & DMAI_FLAGS_VMEMCACHE)); 3574*0Sstevel@tonic-gate } 3575