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 51725Segillett * Common Development and Distribution License (the "License"). 61725Segillett * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 221725Segillett * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * PCI Express PEC implementation: 300Sstevel@tonic-gate * initialization 310Sstevel@tonic-gate * Bus error interrupt handler 320Sstevel@tonic-gate */ 330Sstevel@tonic-gate 340Sstevel@tonic-gate #include <sys/types.h> 350Sstevel@tonic-gate #include <sys/kmem.h> 360Sstevel@tonic-gate #include <sys/spl.h> 370Sstevel@tonic-gate #include <sys/sysmacros.h> 380Sstevel@tonic-gate #include <sys/sunddi.h> 390Sstevel@tonic-gate #include <sys/machsystm.h> /* ldphysio() */ 400Sstevel@tonic-gate #include <sys/async.h> 410Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 420Sstevel@tonic-gate #include <sys/ontrap.h> 430Sstevel@tonic-gate #include <sys/membar.h> 440Sstevel@tonic-gate #include "px_obj.h" 450Sstevel@tonic-gate 460Sstevel@tonic-gate /*LINTLIBRARY*/ 470Sstevel@tonic-gate 480Sstevel@tonic-gate extern uint_t px_ranges_phi_mask; 490Sstevel@tonic-gate 5027Sjchu static uint_t px_pec_error_intr(caddr_t a); 510Sstevel@tonic-gate static int px_pec_msg_add_intr(px_t *px_p); 520Sstevel@tonic-gate static void px_pec_msg_rem_intr(px_t *px_p); 530Sstevel@tonic-gate 540Sstevel@tonic-gate int 550Sstevel@tonic-gate px_pec_attach(px_t *px_p) 560Sstevel@tonic-gate { 570Sstevel@tonic-gate px_pec_t *pec_p; 580Sstevel@tonic-gate int i, len; 590Sstevel@tonic-gate int nrange = px_p->px_ranges_length / sizeof (px_ranges_t); 600Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 610Sstevel@tonic-gate px_ranges_t *rangep = px_p->px_ranges_p; 620Sstevel@tonic-gate int ret; 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * Allocate a state structure for the PEC and cross-link it 660Sstevel@tonic-gate * to its per px node state structure. 670Sstevel@tonic-gate */ 680Sstevel@tonic-gate pec_p = kmem_zalloc(sizeof (px_pec_t), KM_SLEEP); 690Sstevel@tonic-gate px_p->px_pec_p = pec_p; 700Sstevel@tonic-gate pec_p->pec_px_p = px_p; 710Sstevel@tonic-gate 720Sstevel@tonic-gate len = snprintf(pec_p->pec_nameinst_str, 730Sstevel@tonic-gate sizeof (pec_p->pec_nameinst_str), 740Sstevel@tonic-gate "%s%d", NAMEINST(dip)); 750Sstevel@tonic-gate pec_p->pec_nameaddr_str = pec_p->pec_nameinst_str + ++len; 760Sstevel@tonic-gate (void) snprintf(pec_p->pec_nameaddr_str, 770Sstevel@tonic-gate sizeof (pec_p->pec_nameinst_str) - len, 780Sstevel@tonic-gate "%s@%s", NAMEADDR(dip)); 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* 810Sstevel@tonic-gate * Add interrupt handlers to process correctable/fatal/non fatal 820Sstevel@tonic-gate * PCIE messages. 830Sstevel@tonic-gate */ 840Sstevel@tonic-gate if ((ret = px_pec_msg_add_intr(px_p)) != DDI_SUCCESS) { 850Sstevel@tonic-gate px_pec_msg_rem_intr(px_p); 860Sstevel@tonic-gate return (ret); 870Sstevel@tonic-gate } 880Sstevel@tonic-gate 890Sstevel@tonic-gate /* 900Sstevel@tonic-gate * Get this pec's mem32 and mem64 segments to determine whether 910Sstevel@tonic-gate * a dma object originates from ths pec. i.e. dev to dev dma 920Sstevel@tonic-gate */ 930Sstevel@tonic-gate for (i = 0; i < nrange; i++, rangep++) { 940Sstevel@tonic-gate uint64_t rng_addr, rng_size, *pfnbp, *pfnlp; 950Sstevel@tonic-gate uint32_t rng_type = rangep->child_high & PCI_ADDR_MASK; 960Sstevel@tonic-gate 970Sstevel@tonic-gate switch (rng_type) { 980Sstevel@tonic-gate case PCI_ADDR_MEM32: 990Sstevel@tonic-gate pfnbp = &pec_p->pec_base32_pfn; 1000Sstevel@tonic-gate pfnlp = &pec_p->pec_last32_pfn; 1010Sstevel@tonic-gate break; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate case PCI_ADDR_MEM64: 1040Sstevel@tonic-gate pfnbp = &pec_p->pec_base64_pfn; 1050Sstevel@tonic-gate pfnlp = &pec_p->pec_last64_pfn; 1060Sstevel@tonic-gate break; 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate case PCI_ADDR_CONFIG: 1090Sstevel@tonic-gate case PCI_ADDR_IO: 1100Sstevel@tonic-gate default: 1110Sstevel@tonic-gate continue; 1120Sstevel@tonic-gate } 1130Sstevel@tonic-gate rng_addr = (uint64_t)(rangep->parent_high & 1140Sstevel@tonic-gate px_ranges_phi_mask) << 32; 1150Sstevel@tonic-gate rng_addr |= (uint64_t)rangep->parent_low; 1160Sstevel@tonic-gate rng_size = (uint64_t)rangep->size_high << 32; 1170Sstevel@tonic-gate rng_size |= (uint64_t)rangep->size_low; 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate *pfnbp = mmu_btop(rng_addr); 1200Sstevel@tonic-gate *pfnlp = mmu_btop(rng_addr + rng_size); 1210Sstevel@tonic-gate } 1220Sstevel@tonic-gate 12327Sjchu mutex_init(&pec_p->pec_pokefault_mutex, NULL, MUTEX_DRIVER, 12427Sjchu (void *)px_p->px_fm_ibc); 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate return (DDI_SUCCESS); 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate void 1300Sstevel@tonic-gate px_pec_detach(px_t *px_p) 1310Sstevel@tonic-gate { 1320Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 1330Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate /* 1360Sstevel@tonic-gate * Free the pokefault mutex. 1370Sstevel@tonic-gate */ 1380Sstevel@tonic-gate DBG(DBG_DETACH, dip, "px_pec_detach:\n"); 1390Sstevel@tonic-gate mutex_destroy(&pec_p->pec_pokefault_mutex); 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * Remove interrupt handlers to process correctable/fatal/non fatal 1430Sstevel@tonic-gate * PCIE messages. 1440Sstevel@tonic-gate */ 1450Sstevel@tonic-gate px_pec_msg_rem_intr(px_p); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1480Sstevel@tonic-gate * Free the pec state structure. 1490Sstevel@tonic-gate */ 1500Sstevel@tonic-gate kmem_free(pec_p, sizeof (px_pec_t)); 1510Sstevel@tonic-gate px_p->px_pec_p = NULL; 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * pec_msg_add_intr: 1560Sstevel@tonic-gate * 1570Sstevel@tonic-gate * Add interrupt handlers to process correctable/fatal/non fatal 1580Sstevel@tonic-gate * PCIE messages. 1590Sstevel@tonic-gate */ 1600Sstevel@tonic-gate static int 1610Sstevel@tonic-gate px_pec_msg_add_intr(px_t *px_p) 1620Sstevel@tonic-gate { 1630Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 1640Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p; 1650Sstevel@tonic-gate ddi_intr_handle_impl_t hdl; 1660Sstevel@tonic-gate int ret = DDI_SUCCESS; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, "px_pec_msg_add_intr\n"); 1690Sstevel@tonic-gate 1701725Segillett /* Initialize handle */ 1711725Segillett bzero(&hdl, sizeof (ddi_intr_handle_impl_t)); 17227Sjchu hdl.ih_cb_func = (ddi_intr_handler_t *)px_err_fabric_intr; 1730Sstevel@tonic-gate hdl.ih_ver = DDI_INTR_VERSION; 1740Sstevel@tonic-gate hdl.ih_state = DDI_IHDL_STATE_ALLOC; 1750Sstevel@tonic-gate hdl.ih_dip = dip; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate /* Add correctable error message handler */ 17827Sjchu hdl.ih_pri = PX_ERR_LOW_PIL; 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, dip, &hdl, 1810Sstevel@tonic-gate MSG_REC, (msgcode_t)PCIE_CORR_MSG, 1820Sstevel@tonic-gate &pec_p->pec_corr_msg_msiq_id)) != DDI_SUCCESS) { 1830Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, 1840Sstevel@tonic-gate "PCIE_CORR_MSG registration failed\n"); 1850Sstevel@tonic-gate return (DDI_FAILURE); 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate px_lib_msg_setmsiq(dip, PCIE_CORR_MSG, pec_p->pec_corr_msg_msiq_id); 1890Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_CORR_MSG, PCIE_MSG_VALID); 1900Sstevel@tonic-gate 191*2973Sgovinda if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum, 192*2973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_corr_msg_msiq_id), 193*2973Sgovinda PX_ERR_LOW_PIL, PX_INTR_STATE_ENABLE, MSG_REC, 194*2973Sgovinda PCIE_CORR_MSG)) != DDI_SUCCESS) { 195909Segillett DBG(DBG_MSG, px_p->px_dip, 196909Segillett "PCIE_CORR_MSG update interrupt state failed\n"); 197909Segillett return (DDI_FAILURE); 198909Segillett } 199909Segillett 2000Sstevel@tonic-gate /* Add non-fatal error message handler */ 20127Sjchu hdl.ih_pri = PX_ERR_PIL; 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, dip, &hdl, 2040Sstevel@tonic-gate MSG_REC, (msgcode_t)PCIE_NONFATAL_MSG, 2050Sstevel@tonic-gate &pec_p->pec_non_fatal_msg_msiq_id)) != DDI_SUCCESS) { 2060Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, 2070Sstevel@tonic-gate "PCIE_NONFATAL_MSG registration failed\n"); 2080Sstevel@tonic-gate return (DDI_FAILURE); 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate px_lib_msg_setmsiq(dip, PCIE_NONFATAL_MSG, 2120Sstevel@tonic-gate pec_p->pec_non_fatal_msg_msiq_id); 2130Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_NONFATAL_MSG, PCIE_MSG_VALID); 2140Sstevel@tonic-gate 215*2973Sgovinda if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum, 216*2973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_non_fatal_msg_msiq_id), 217*2973Sgovinda PX_ERR_PIL, PX_INTR_STATE_ENABLE, MSG_REC, 218909Segillett PCIE_NONFATAL_MSG)) != DDI_SUCCESS) { 219909Segillett DBG(DBG_MSG, px_p->px_dip, 220909Segillett "PCIE_NONFATAL_MSG update interrupt state failed\n"); 221909Segillett return (DDI_FAILURE); 222909Segillett } 223909Segillett 2240Sstevel@tonic-gate /* Add fatal error message handler */ 22527Sjchu hdl.ih_pri = PX_ERR_PIL; 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate if ((ret = px_add_msiq_intr(dip, dip, &hdl, 2280Sstevel@tonic-gate MSG_REC, (msgcode_t)PCIE_FATAL_MSG, 2290Sstevel@tonic-gate &pec_p->pec_fatal_msg_msiq_id)) != DDI_SUCCESS) { 2300Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, 2310Sstevel@tonic-gate "PCIE_FATAL_MSG registration failed\n"); 2320Sstevel@tonic-gate return (DDI_FAILURE); 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate px_lib_msg_setmsiq(dip, PCIE_FATAL_MSG, pec_p->pec_fatal_msg_msiq_id); 2360Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_FATAL_MSG, PCIE_MSG_VALID); 2370Sstevel@tonic-gate 238*2973Sgovinda if ((ret = px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum, 239*2973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_fatal_msg_msiq_id), PX_ERR_PIL, 240*2973Sgovinda PX_INTR_STATE_ENABLE, MSG_REC, PCIE_FATAL_MSG)) != DDI_SUCCESS) { 241909Segillett DBG(DBG_MSG, px_p->px_dip, 242909Segillett "PCIE_FATAL_MSG update interrupt state failed\n"); 243909Segillett return (DDI_FAILURE); 244909Segillett } 245909Segillett 2460Sstevel@tonic-gate return (ret); 2470Sstevel@tonic-gate } 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate /* 2500Sstevel@tonic-gate * px_pec_msg_rem_intr: 2510Sstevel@tonic-gate * 2520Sstevel@tonic-gate * Remove interrupt handlers to process correctable/fatal/non fatal 2530Sstevel@tonic-gate * PCIE messages. For now, all these PCIe messages are mapped to 2540Sstevel@tonic-gate * same MSIQ. 2550Sstevel@tonic-gate */ 2560Sstevel@tonic-gate static void 2570Sstevel@tonic-gate px_pec_msg_rem_intr(px_t *px_p) 2580Sstevel@tonic-gate { 2590Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 2600Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p; 2610Sstevel@tonic-gate ddi_intr_handle_impl_t hdl; 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate DBG(DBG_MSG, px_p->px_dip, "px_pec_msg_rem_intr: dip 0x%p\n", dip); 2640Sstevel@tonic-gate 2651725Segillett /* Initialize handle */ 2661725Segillett bzero(&hdl, sizeof (ddi_intr_handle_impl_t)); 2670Sstevel@tonic-gate hdl.ih_ver = DDI_INTR_VERSION; 2680Sstevel@tonic-gate hdl.ih_state = DDI_IHDL_STATE_ALLOC; 2690Sstevel@tonic-gate hdl.ih_dip = dip; 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate if (pec_p->pec_corr_msg_msiq_id >= 0) { 2720Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_CORR_MSG, PCIE_MSG_INVALID); 2730Sstevel@tonic-gate 2740Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, 2750Sstevel@tonic-gate PCIE_CORR_MSG, pec_p->pec_corr_msg_msiq_id); 276909Segillett 277*2973Sgovinda (void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum, 278*2973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_corr_msg_msiq_id), 279*2973Sgovinda PX_ERR_LOW_PIL, PX_INTR_STATE_DISABLE, MSG_REC, 280*2973Sgovinda PCIE_CORR_MSG); 281909Segillett 2822840Scarlsonj pec_p->pec_corr_msg_msiq_id = (msiqid_t)-1; 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate if (pec_p->pec_non_fatal_msg_msiq_id >= 0) { 2860Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_NONFATAL_MSG, 2870Sstevel@tonic-gate PCIE_MSG_INVALID); 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, 2900Sstevel@tonic-gate PCIE_NONFATAL_MSG, pec_p->pec_non_fatal_msg_msiq_id); 2910Sstevel@tonic-gate 292*2973Sgovinda (void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum, 293*2973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_non_fatal_msg_msiq_id), 294*2973Sgovinda PX_ERR_PIL, PX_INTR_STATE_DISABLE, MSG_REC, 295*2973Sgovinda PCIE_NONFATAL_MSG); 296909Segillett 2972840Scarlsonj pec_p->pec_non_fatal_msg_msiq_id = (msiqid_t)-1; 2980Sstevel@tonic-gate } 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate if (pec_p->pec_fatal_msg_msiq_id >= 0) { 3010Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_FATAL_MSG, PCIE_MSG_INVALID); 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, 3040Sstevel@tonic-gate PCIE_FATAL_MSG, pec_p->pec_fatal_msg_msiq_id); 3050Sstevel@tonic-gate 306*2973Sgovinda (void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum, 307*2973Sgovinda px_msiqid_to_devino(px_p, pec_p->pec_fatal_msg_msiq_id), 308*2973Sgovinda PX_ERR_PIL, PX_INTR_STATE_DISABLE, MSG_REC, PCIE_FATAL_MSG); 309909Segillett 3102840Scarlsonj pec_p->pec_fatal_msg_msiq_id = (msiqid_t)-1; 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate } 313