10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * PCI Express PEC implementation: 310Sstevel@tonic-gate * initialization 320Sstevel@tonic-gate * Bus error interrupt handler 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/types.h> 360Sstevel@tonic-gate #include <sys/kmem.h> 370Sstevel@tonic-gate #include <sys/spl.h> 380Sstevel@tonic-gate #include <sys/sysmacros.h> 390Sstevel@tonic-gate #include <sys/sunddi.h> 400Sstevel@tonic-gate #include <sys/machsystm.h> /* ldphysio() */ 410Sstevel@tonic-gate #include <sys/async.h> 420Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 430Sstevel@tonic-gate #include <sys/ontrap.h> 440Sstevel@tonic-gate #include <sys/membar.h> 450Sstevel@tonic-gate #include "px_obj.h" 460Sstevel@tonic-gate 470Sstevel@tonic-gate /*LINTLIBRARY*/ 480Sstevel@tonic-gate 490Sstevel@tonic-gate extern uint_t px_ranges_phi_mask; 500Sstevel@tonic-gate 5127Sjchu static uint_t px_pec_error_intr(caddr_t a); 520Sstevel@tonic-gate static int px_pec_msg_add_intr(px_t *px_p); 530Sstevel@tonic-gate static void px_pec_msg_rem_intr(px_t *px_p); 540Sstevel@tonic-gate 550Sstevel@tonic-gate int 560Sstevel@tonic-gate px_pec_attach(px_t *px_p) 570Sstevel@tonic-gate { 580Sstevel@tonic-gate px_pec_t *pec_p; 590Sstevel@tonic-gate int i, len; 600Sstevel@tonic-gate int nrange = px_p->px_ranges_length / sizeof (px_ranges_t); 610Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 620Sstevel@tonic-gate px_ranges_t *rangep = px_p->px_ranges_p; 630Sstevel@tonic-gate int ret; 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * Allocate a state structure for the PEC and cross-link it 670Sstevel@tonic-gate * to its per px node state structure. 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate pec_p = kmem_zalloc(sizeof (px_pec_t), KM_SLEEP); 700Sstevel@tonic-gate px_p->px_pec_p = pec_p; 710Sstevel@tonic-gate pec_p->pec_px_p = px_p; 720Sstevel@tonic-gate 730Sstevel@tonic-gate len = snprintf(pec_p->pec_nameinst_str, 740Sstevel@tonic-gate sizeof (pec_p->pec_nameinst_str), 750Sstevel@tonic-gate "%s%d", NAMEINST(dip)); 760Sstevel@tonic-gate pec_p->pec_nameaddr_str = pec_p->pec_nameinst_str + ++len; 770Sstevel@tonic-gate (void) snprintf(pec_p->pec_nameaddr_str, 780Sstevel@tonic-gate sizeof (pec_p->pec_nameinst_str) - len, 790Sstevel@tonic-gate "%s@%s", NAMEADDR(dip)); 800Sstevel@tonic-gate 810Sstevel@tonic-gate /* 820Sstevel@tonic-gate * Add interrupt handlers to process correctable/fatal/non fatal 830Sstevel@tonic-gate * PCIE messages. 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate if ((ret = px_pec_msg_add_intr(px_p)) != DDI_SUCCESS) { 860Sstevel@tonic-gate px_pec_msg_rem_intr(px_p); 870Sstevel@tonic-gate return (ret); 880Sstevel@tonic-gate } 890Sstevel@tonic-gate 900Sstevel@tonic-gate /* 910Sstevel@tonic-gate * Get this pec's mem32 and mem64 segments to determine whether 920Sstevel@tonic-gate * a dma object originates from ths pec. i.e. dev to dev dma 930Sstevel@tonic-gate */ 940Sstevel@tonic-gate for (i = 0; i < nrange; i++, rangep++) { 950Sstevel@tonic-gate uint64_t rng_addr, rng_size, *pfnbp, *pfnlp; 960Sstevel@tonic-gate uint32_t rng_type = rangep->child_high & PCI_ADDR_MASK; 970Sstevel@tonic-gate 980Sstevel@tonic-gate switch (rng_type) { 990Sstevel@tonic-gate case PCI_ADDR_MEM32: 1000Sstevel@tonic-gate pfnbp = &pec_p->pec_base32_pfn; 1010Sstevel@tonic-gate pfnlp = &pec_p->pec_last32_pfn; 1020Sstevel@tonic-gate break; 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate case PCI_ADDR_MEM64: 1050Sstevel@tonic-gate pfnbp = &pec_p->pec_base64_pfn; 1060Sstevel@tonic-gate pfnlp = &pec_p->pec_last64_pfn; 1070Sstevel@tonic-gate break; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate case PCI_ADDR_CONFIG: 1100Sstevel@tonic-gate case PCI_ADDR_IO: 1110Sstevel@tonic-gate default: 1120Sstevel@tonic-gate continue; 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate rng_addr = (uint64_t)(rangep->parent_high & 1150Sstevel@tonic-gate px_ranges_phi_mask) << 32; 1160Sstevel@tonic-gate rng_addr |= (uint64_t)rangep->parent_low; 1170Sstevel@tonic-gate rng_size = (uint64_t)rangep->size_high << 32; 1180Sstevel@tonic-gate rng_size |= (uint64_t)rangep->size_low; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate *pfnbp = mmu_btop(rng_addr); 1210Sstevel@tonic-gate *pfnlp = mmu_btop(rng_addr + rng_size); 1220Sstevel@tonic-gate } 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate /* 1250Sstevel@tonic-gate * Register a function to disable pec error interrupts during a panic. 1260Sstevel@tonic-gate * do in px_attach. bus_func_register(BF_TYPE_ERRDIS, 1270Sstevel@tonic-gate * (busfunc_t)pec_disable_pci_errors, pec_p); 1280Sstevel@tonic-gate */ 1290Sstevel@tonic-gate 13027Sjchu mutex_init(&pec_p->pec_pokefault_mutex, NULL, MUTEX_DRIVER, 13127Sjchu (void *)px_p->px_fm_ibc); 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate return (DDI_SUCCESS); 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate uint_t 1370Sstevel@tonic-gate pec_disable_px_errors(px_pec_t *pec_p) 1380Sstevel@tonic-gate { 1390Sstevel@tonic-gate px_t *px_p = pec_p->pec_px_p; 1400Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate /* 1430Sstevel@tonic-gate * Disable error interrupts via the interrupt mapping register. 1440Sstevel@tonic-gate */ 1450Sstevel@tonic-gate px_ib_intr_disable(ib_p, px_p->px_inos[PX_INTR_PEC], IB_INTR_NOWAIT); 1460Sstevel@tonic-gate return (BF_NONE); 1470Sstevel@tonic-gate } 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate void 1500Sstevel@tonic-gate px_pec_detach(px_t *px_p) 1510Sstevel@tonic-gate { 1520Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 1530Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p; 1540Sstevel@tonic-gate px_ib_t *ib_p = px_p->px_ib_p; 1550Sstevel@tonic-gate devino_t ino = px_p->px_inos[PX_INTR_PEC]; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* 1580Sstevel@tonic-gate * Free the pokefault mutex. 1590Sstevel@tonic-gate */ 1600Sstevel@tonic-gate DBG(DBG_DETACH, dip, "px_pec_detach:\n"); 1610Sstevel@tonic-gate mutex_destroy(&pec_p->pec_pokefault_mutex); 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 1640Sstevel@tonic-gate * Remove the pci error interrupt handler. 1650Sstevel@tonic-gate */ 1660Sstevel@tonic-gate px_ib_intr_disable(ib_p, ino, IB_INTR_WAIT); 1670Sstevel@tonic-gate ddi_remove_intr(dip, 0, NULL); 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate /* 1700Sstevel@tonic-gate * Remove the error disable function. 1710Sstevel@tonic-gate */ 1720Sstevel@tonic-gate bus_func_unregister(BF_TYPE_ERRDIS, 1730Sstevel@tonic-gate (busfunc_t)pec_disable_px_errors, pec_p); 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate /* 1760Sstevel@tonic-gate * Remove interrupt handlers to process correctable/fatal/non fatal 1770Sstevel@tonic-gate * PCIE messages. 1780Sstevel@tonic-gate */ 1790Sstevel@tonic-gate px_pec_msg_rem_intr(px_p); 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate /* 1820Sstevel@tonic-gate * Free the pec state structure. 1830Sstevel@tonic-gate */ 1840Sstevel@tonic-gate kmem_free(pec_p, sizeof (px_pec_t)); 1850Sstevel@tonic-gate px_p->px_pec_p = NULL; 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /* 1890Sstevel@tonic-gate * pec_msg_add_intr: 1900Sstevel@tonic-gate * 1910Sstevel@tonic-gate * Add interrupt handlers to process correctable/fatal/non fatal 1920Sstevel@tonic-gate * PCIE messages. 1930Sstevel@tonic-gate */ 1940Sstevel@tonic-gate static int 1950Sstevel@tonic-gate px_pec_msg_add_intr(px_t *px_p) 1960Sstevel@tonic-gate { 1970Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 1980Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p; 1990Sstevel@tonic-gate ddi_intr_handle_impl_t hdl; 2000Sstevel@tonic-gate int ret = DDI_SUCCESS; 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, "px_pec_msg_add_intr\n"); 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate /* Initilize handle */ 20527Sjchu hdl.ih_cb_func = (ddi_intr_handler_t *)px_err_fabric_intr; 20627Sjchu hdl.ih_cb_arg1 = NULL; 20727Sjchu hdl.ih_cb_arg2 = NULL; 2080Sstevel@tonic-gate hdl.ih_ver = DDI_INTR_VERSION; 2090Sstevel@tonic-gate hdl.ih_state = DDI_IHDL_STATE_ALLOC; 2100Sstevel@tonic-gate hdl.ih_dip = dip; 2110Sstevel@tonic-gate hdl.ih_inum = 0; 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* Add correctable error message handler */ 21427Sjchu hdl.ih_pri = PX_ERR_LOW_PIL; 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, dip, &hdl, 2170Sstevel@tonic-gate MSG_REC, (msgcode_t)PCIE_CORR_MSG, 2180Sstevel@tonic-gate &pec_p->pec_corr_msg_msiq_id)) != DDI_SUCCESS) { 2190Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, 2200Sstevel@tonic-gate "PCIE_CORR_MSG registration failed\n"); 2210Sstevel@tonic-gate return (DDI_FAILURE); 2220Sstevel@tonic-gate } 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate px_lib_msg_setmsiq(dip, PCIE_CORR_MSG, pec_p->pec_corr_msg_msiq_id); 2250Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_CORR_MSG, PCIE_MSG_VALID); 2260Sstevel@tonic-gate 227*909Segillett if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, 228*909Segillett hdl.ih_inum, px_msiqid_to_devino(px_p, pec_p->pec_corr_msg_msiq_id), 229*909Segillett PX_INTR_STATE_ENABLE, MSG_REC, PCIE_CORR_MSG)) != DDI_SUCCESS) { 230*909Segillett DBG(DBG_MSG, px_p->px_dip, 231*909Segillett "PCIE_CORR_MSG update interrupt state failed\n"); 232*909Segillett return (DDI_FAILURE); 233*909Segillett } 234*909Segillett 2350Sstevel@tonic-gate /* Add non-fatal error message handler */ 23627Sjchu hdl.ih_pri = PX_ERR_PIL; 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, dip, &hdl, 2390Sstevel@tonic-gate MSG_REC, (msgcode_t)PCIE_NONFATAL_MSG, 2400Sstevel@tonic-gate &pec_p->pec_non_fatal_msg_msiq_id)) != DDI_SUCCESS) { 2410Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, 2420Sstevel@tonic-gate "PCIE_NONFATAL_MSG registration failed\n"); 2430Sstevel@tonic-gate return (DDI_FAILURE); 2440Sstevel@tonic-gate } 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate px_lib_msg_setmsiq(dip, PCIE_NONFATAL_MSG, 2470Sstevel@tonic-gate pec_p->pec_non_fatal_msg_msiq_id); 2480Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_NONFATAL_MSG, PCIE_MSG_VALID); 2490Sstevel@tonic-gate 250*909Segillett if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, 251*909Segillett hdl.ih_inum, px_msiqid_to_devino(px_p, 252*909Segillett pec_p->pec_non_fatal_msg_msiq_id), PX_INTR_STATE_ENABLE, MSG_REC, 253*909Segillett PCIE_NONFATAL_MSG)) != DDI_SUCCESS) { 254*909Segillett DBG(DBG_MSG, px_p->px_dip, 255*909Segillett "PCIE_NONFATAL_MSG update interrupt state failed\n"); 256*909Segillett return (DDI_FAILURE); 257*909Segillett } 258*909Segillett 2590Sstevel@tonic-gate /* Add fatal error message handler */ 26027Sjchu hdl.ih_pri = PX_ERR_PIL; 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, dip, &hdl, 2630Sstevel@tonic-gate MSG_REC, (msgcode_t)PCIE_FATAL_MSG, 2640Sstevel@tonic-gate &pec_p->pec_fatal_msg_msiq_id)) != DDI_SUCCESS) { 2650Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, 2660Sstevel@tonic-gate "PCIE_FATAL_MSG registration failed\n"); 2670Sstevel@tonic-gate return (DDI_FAILURE); 2680Sstevel@tonic-gate } 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate px_lib_msg_setmsiq(dip, PCIE_FATAL_MSG, pec_p->pec_fatal_msg_msiq_id); 2710Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_FATAL_MSG, PCIE_MSG_VALID); 2720Sstevel@tonic-gate 273*909Segillett if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, 274*909Segillett hdl.ih_inum, px_msiqid_to_devino(px_p, 275*909Segillett pec_p->pec_fatal_msg_msiq_id), PX_INTR_STATE_ENABLE, MSG_REC, 276*909Segillett PCIE_FATAL_MSG)) != DDI_SUCCESS) { 277*909Segillett DBG(DBG_MSG, px_p->px_dip, 278*909Segillett "PCIE_FATAL_MSG update interrupt state failed\n"); 279*909Segillett return (DDI_FAILURE); 280*909Segillett } 281*909Segillett 2820Sstevel@tonic-gate return (ret); 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate /* 2860Sstevel@tonic-gate * px_pec_msg_rem_intr: 2870Sstevel@tonic-gate * 2880Sstevel@tonic-gate * Remove interrupt handlers to process correctable/fatal/non fatal 2890Sstevel@tonic-gate * PCIE messages. For now, all these PCIe messages are mapped to 2900Sstevel@tonic-gate * same MSIQ. 2910Sstevel@tonic-gate */ 2920Sstevel@tonic-gate static void 2930Sstevel@tonic-gate px_pec_msg_rem_intr(px_t *px_p) 2940Sstevel@tonic-gate { 2950Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 2960Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p; 2970Sstevel@tonic-gate ddi_intr_handle_impl_t hdl; 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, "px_pec_msg_rem_intr: dip 0x%p\n", dip); 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate /* Initilize handle */ 3020Sstevel@tonic-gate hdl.ih_ver = DDI_INTR_VERSION; 3030Sstevel@tonic-gate hdl.ih_state = DDI_IHDL_STATE_ALLOC; 3040Sstevel@tonic-gate hdl.ih_dip = dip; 3050Sstevel@tonic-gate hdl.ih_inum = 0; 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate if (pec_p->pec_corr_msg_msiq_id >= 0) { 3080Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_CORR_MSG, PCIE_MSG_INVALID); 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, 3110Sstevel@tonic-gate PCIE_CORR_MSG, pec_p->pec_corr_msg_msiq_id); 312*909Segillett 313*909Segillett (void) px_ib_update_intr_state(px_p, px_p->px_dip, 314*909Segillett hdl.ih_inum, px_msiqid_to_devino(px_p, 315*909Segillett pec_p->pec_corr_msg_msiq_id), 316*909Segillett PX_INTR_STATE_DISABLE, MSG_REC, PCIE_CORR_MSG); 317*909Segillett 3180Sstevel@tonic-gate pec_p->pec_corr_msg_msiq_id = -1; 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate if (pec_p->pec_non_fatal_msg_msiq_id >= 0) { 3220Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_NONFATAL_MSG, 3230Sstevel@tonic-gate PCIE_MSG_INVALID); 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, 3260Sstevel@tonic-gate PCIE_NONFATAL_MSG, pec_p->pec_non_fatal_msg_msiq_id); 3270Sstevel@tonic-gate 328*909Segillett (void) px_ib_update_intr_state(px_p, px_p->px_dip, 329*909Segillett hdl.ih_inum, px_msiqid_to_devino(px_p, 330*909Segillett pec_p->pec_non_fatal_msg_msiq_id), 331*909Segillett PX_INTR_STATE_DISABLE, MSG_REC, PCIE_NONFATAL_MSG); 332*909Segillett 3330Sstevel@tonic-gate pec_p->pec_non_fatal_msg_msiq_id = -1; 3340Sstevel@tonic-gate } 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate if (pec_p->pec_fatal_msg_msiq_id >= 0) { 3370Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_FATAL_MSG, PCIE_MSG_INVALID); 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, 3400Sstevel@tonic-gate PCIE_FATAL_MSG, pec_p->pec_fatal_msg_msiq_id); 3410Sstevel@tonic-gate 342*909Segillett (void) px_ib_update_intr_state(px_p, px_p->px_dip, 343*909Segillett hdl.ih_inum, px_msiqid_to_devino(px_p, 344*909Segillett pec_p->pec_fatal_msg_msiq_id), 345*909Segillett PX_INTR_STATE_DISABLE, MSG_REC, PCIE_FATAL_MSG); 346*909Segillett 3470Sstevel@tonic-gate pec_p->pec_fatal_msg_msiq_id = -1; 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate } 350